blob: 82005b8ad95777becb2c8b914fefa406a4d1917c [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>
James Smart0d878412009-10-02 15:16:56 -040026#include <linux/aer.h>
dea31012005-04-17 16:05:31 -050027
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040028#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050029#include <scsi/scsi_device.h>
30#include <scsi/scsi_host.h>
31#include <scsi/scsi_tcq.h>
32#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040033#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050034
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050036#include "lpfc_hw.h"
37#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040038#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040039#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050040#include "lpfc_disc.h"
41#include "lpfc_scsi.h"
42#include "lpfc.h"
43#include "lpfc_logmsg.h"
44#include "lpfc_version.h"
45#include "lpfc_compat.h"
46#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050047#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050048
James Smartc01f3202006-08-18 17:47:08 -040049#define LPFC_DEF_DEVLOSS_TMO 30
50#define LPFC_MIN_DEVLOSS_TMO 1
51#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050052
James Smart83108bd2008-01-11 01:53:09 -050053#define LPFC_MAX_LINK_SPEED 8
54#define LPFC_LINK_SPEED_BITMAP 0x00000117
55#define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
56
James Smarte59058c2008-08-24 21:49:00 -040057/**
James Smart3621a712009-04-06 18:47:14 -040058 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040059 * @incr: integer to convert.
60 * @hdw: ascii string holding converted integer plus a string terminator.
61 *
62 * Description:
63 * JEDEC Joint Electron Device Engineering Council.
64 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
65 * character string. The string is then terminated with a NULL in byte 9.
66 * Hex 0-9 becomes ascii '0' to '9'.
67 * Hex a-f becomes ascii '=' to 'B' capital B.
68 *
69 * Notes:
70 * Coded for 32 bit integers only.
71 **/
dea31012005-04-17 16:05:31 -050072static void
73lpfc_jedec_to_ascii(int incr, char hdw[])
74{
75 int i, j;
76 for (i = 0; i < 8; i++) {
77 j = (incr & 0xf);
78 if (j <= 9)
79 hdw[7 - i] = 0x30 + j;
80 else
81 hdw[7 - i] = 0x61 + j - 10;
82 incr = (incr >> 4);
83 }
84 hdw[8] = 0;
85 return;
86}
87
James Smarte59058c2008-08-24 21:49:00 -040088/**
James Smart3621a712009-04-06 18:47:14 -040089 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -040090 * @dev: class unused variable.
91 * @attr: device attribute, not used.
92 * @buf: on return contains the module description text.
93 *
94 * Returns: size of formatted string.
95 **/
dea31012005-04-17 16:05:31 -050096static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +010097lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
98 char *buf)
dea31012005-04-17 16:05:31 -050099{
100 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
101}
102
James Smart81301a92008-12-04 22:39:46 -0500103static ssize_t
104lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
105 char *buf)
106{
107 struct Scsi_Host *shost = class_to_shost(dev);
108 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
109 struct lpfc_hba *phba = vport->phba;
110
111 if (phba->cfg_enable_bg)
112 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
113 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
114 else
115 return snprintf(buf, PAGE_SIZE,
116 "BlockGuard Not Supported\n");
117 else
118 return snprintf(buf, PAGE_SIZE,
119 "BlockGuard Disabled\n");
120}
121
122static ssize_t
123lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
124 char *buf)
125{
126 struct Scsi_Host *shost = class_to_shost(dev);
127 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
128 struct lpfc_hba *phba = vport->phba;
129
James Smart87b5c322008-12-16 10:34:09 -0500130 return snprintf(buf, PAGE_SIZE, "%llu\n",
131 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500132}
133
134static ssize_t
135lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
136 char *buf)
137{
138 struct Scsi_Host *shost = class_to_shost(dev);
139 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
140 struct lpfc_hba *phba = vport->phba;
141
James Smart87b5c322008-12-16 10:34:09 -0500142 return snprintf(buf, PAGE_SIZE, "%llu\n",
143 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500144}
145
146static ssize_t
147lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
148 char *buf)
149{
150 struct Scsi_Host *shost = class_to_shost(dev);
151 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
152 struct lpfc_hba *phba = vport->phba;
153
James Smart87b5c322008-12-16 10:34:09 -0500154 return snprintf(buf, PAGE_SIZE, "%llu\n",
155 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500156}
157
James Smarte59058c2008-08-24 21:49:00 -0400158/**
James Smart3621a712009-04-06 18:47:14 -0400159 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400160 * @dev: class converted to a Scsi_host structure.
161 * @attr: device attribute, not used.
162 * @buf: on return contains the formatted text from lpfc_info().
163 *
164 * Returns: size of formatted string.
165 **/
dea31012005-04-17 16:05:31 -0500166static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100167lpfc_info_show(struct device *dev, struct device_attribute *attr,
168 char *buf)
dea31012005-04-17 16:05:31 -0500169{
Tony Jonesee959b02008-02-22 00:13:36 +0100170 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500171
dea31012005-04-17 16:05:31 -0500172 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
173}
174
James Smarte59058c2008-08-24 21:49:00 -0400175/**
James Smart3621a712009-04-06 18:47:14 -0400176 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400177 * @dev: class converted to a Scsi_host structure.
178 * @attr: device attribute, not used.
179 * @buf: on return contains the formatted text serial number.
180 *
181 * Returns: size of formatted string.
182 **/
dea31012005-04-17 16:05:31 -0500183static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100184lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
185 char *buf)
dea31012005-04-17 16:05:31 -0500186{
Tony Jonesee959b02008-02-22 00:13:36 +0100187 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500188 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
189 struct lpfc_hba *phba = vport->phba;
190
dea31012005-04-17 16:05:31 -0500191 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
192}
193
James Smarte59058c2008-08-24 21:49:00 -0400194/**
James Smart3621a712009-04-06 18:47:14 -0400195 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400196 * @dev: class converted to a Scsi_host structure.
197 * @attr: device attribute, not used.
198 * @buf: on return contains the formatted support level.
199 *
200 * Description:
201 * Returns a number indicating the temperature sensor level currently
202 * supported, zero or one in ascii.
203 *
204 * Returns: size of formatted string.
205 **/
dea31012005-04-17 16:05:31 -0500206static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100207lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
208 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400209{
Tony Jonesee959b02008-02-22 00:13:36 +0100210 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400211 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
212 struct lpfc_hba *phba = vport->phba;
213 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
214}
215
James Smarte59058c2008-08-24 21:49:00 -0400216/**
James Smart3621a712009-04-06 18:47:14 -0400217 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400218 * @dev: class converted to a Scsi_host structure.
219 * @attr: device attribute, not used.
220 * @buf: on return contains the scsi vpd model description.
221 *
222 * Returns: size of formatted string.
223 **/
James Smart57127f12007-10-27 13:37:05 -0400224static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100225lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
226 char *buf)
dea31012005-04-17 16:05:31 -0500227{
Tony Jonesee959b02008-02-22 00:13:36 +0100228 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500229 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
230 struct lpfc_hba *phba = vport->phba;
231
dea31012005-04-17 16:05:31 -0500232 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
233}
234
James Smarte59058c2008-08-24 21:49:00 -0400235/**
James Smart3621a712009-04-06 18:47:14 -0400236 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400237 * @dev: class converted to a Scsi_host structure.
238 * @attr: device attribute, not used.
239 * @buf: on return contains the scsi vpd model name.
240 *
241 * Returns: size of formatted string.
242 **/
dea31012005-04-17 16:05:31 -0500243static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100244lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
245 char *buf)
dea31012005-04-17 16:05:31 -0500246{
Tony Jonesee959b02008-02-22 00:13:36 +0100247 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500248 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
249 struct lpfc_hba *phba = vport->phba;
250
dea31012005-04-17 16:05:31 -0500251 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
252}
253
James Smarte59058c2008-08-24 21:49:00 -0400254/**
James Smart3621a712009-04-06 18:47:14 -0400255 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400256 * @dev: class converted to a Scsi_host structure.
257 * @attr: device attribute, not used.
258 * @buf: on return contains the scsi vpd program type.
259 *
260 * Returns: size of formatted string.
261 **/
dea31012005-04-17 16:05:31 -0500262static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100263lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
264 char *buf)
dea31012005-04-17 16:05:31 -0500265{
Tony Jonesee959b02008-02-22 00:13:36 +0100266 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500267 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
268 struct lpfc_hba *phba = vport->phba;
269
dea31012005-04-17 16:05:31 -0500270 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
271}
272
James Smarte59058c2008-08-24 21:49:00 -0400273/**
James Smart3621a712009-04-06 18:47:14 -0400274 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400275 * @dev: class converted to a Scsi_host structure.
276 * @attr: device attribute, not used.
277 * @buf: on return contains the Menlo Maintenance sli flag.
278 *
279 * Returns: size of formatted string.
280 **/
281static ssize_t
282lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
283{
284 struct Scsi_Host *shost = class_to_shost(dev);
285 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
286 struct lpfc_hba *phba = vport->phba;
287
288 return snprintf(buf, PAGE_SIZE, "%d\n",
289 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
290}
291
292/**
James Smart3621a712009-04-06 18:47:14 -0400293 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400294 * @dev: class converted to a Scsi_host structure.
295 * @attr: device attribute, not used.
296 * @buf: on return contains scsi vpd program type.
297 *
298 * Returns: size of formatted string.
299 **/
dea31012005-04-17 16:05:31 -0500300static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100301lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
302 char *buf)
dea31012005-04-17 16:05:31 -0500303{
Tony Jonesee959b02008-02-22 00:13:36 +0100304 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500305 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
306 struct lpfc_hba *phba = vport->phba;
307
dea31012005-04-17 16:05:31 -0500308 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
309}
310
James Smarte59058c2008-08-24 21:49:00 -0400311/**
James Smart3621a712009-04-06 18:47:14 -0400312 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400313 * @dev: class converted to a Scsi_host structure.
314 * @attr: device attribute, not used.
315 * @buf: on return contains the scsi vpd program type.
316 *
317 * Returns: size of formatted string.
318 **/
dea31012005-04-17 16:05:31 -0500319static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100320lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
321 char *buf)
dea31012005-04-17 16:05:31 -0500322{
Tony Jonesee959b02008-02-22 00:13:36 +0100323 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500324 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
325 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500326 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500327
dea31012005-04-17 16:05:31 -0500328 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500329 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500330}
331
James Smarte59058c2008-08-24 21:49:00 -0400332/**
James Smart3621a712009-04-06 18:47:14 -0400333 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400334 * @dev: class converted to a Scsi_host structure.
335 * @attr: device attribute, not used.
336 * @buf: on return contains the scsi vpd program type.
337 *
338 * Returns: size of formatted string.
339 **/
dea31012005-04-17 16:05:31 -0500340static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100341lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500342{
343 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100344 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500345 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
346 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500347 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500348
dea31012005-04-17 16:05:31 -0500349 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
350 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
351}
James Smarte59058c2008-08-24 21:49:00 -0400352
353/**
James Smart3621a712009-04-06 18:47:14 -0400354 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400355 * @dev: class converted to a Scsi_host structure.
356 * @attr: device attribute, not used.
357 * @buf: on return contains the ROM and FCode ascii strings.
358 *
359 * Returns: size of formatted string.
360 **/
dea31012005-04-17 16:05:31 -0500361static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100362lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
363 char *buf)
dea31012005-04-17 16:05:31 -0500364{
Tony Jonesee959b02008-02-22 00:13:36 +0100365 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500366 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
367 struct lpfc_hba *phba = vport->phba;
368
dea31012005-04-17 16:05:31 -0500369 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
370}
James Smarte59058c2008-08-24 21:49:00 -0400371
372/**
James Smart3621a712009-04-06 18:47:14 -0400373 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400374 * @dev: class converted to a Scsi_host structure.
375 * @attr: device attribute, not used.
376 * @buf: on return contains text describing the state of the link.
377 *
378 * Notes:
379 * The switch statement has no default so zero will be returned.
380 *
381 * Returns: size of formatted string.
382 **/
dea31012005-04-17 16:05:31 -0500383static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100384lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
385 char *buf)
dea31012005-04-17 16:05:31 -0500386{
Tony Jonesee959b02008-02-22 00:13:36 +0100387 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500388 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
389 struct lpfc_hba *phba = vport->phba;
390 int len = 0;
391
392 switch (phba->link_state) {
393 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500394 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500395 case LPFC_INIT_START:
396 case LPFC_INIT_MBX_CMDS:
397 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500398 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400399 if (phba->hba_flag & LINK_DISABLED)
400 len += snprintf(buf + len, PAGE_SIZE-len,
401 "Link Down - User disabled\n");
402 else
403 len += snprintf(buf + len, PAGE_SIZE-len,
404 "Link Down\n");
dea31012005-04-17 16:05:31 -0500405 break;
406 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500407 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500408 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400409 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500410
411 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500412 case LPFC_LOCAL_CFG_LINK:
413 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500414 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500415 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500416 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500417 case LPFC_FLOGI:
418 case LPFC_FABRIC_CFG_LINK:
419 case LPFC_NS_REG:
420 case LPFC_NS_QRY:
421 case LPFC_BUILD_DISC_LIST:
422 case LPFC_DISC_AUTH:
423 len += snprintf(buf + len, PAGE_SIZE - len,
424 "Discovery\n");
425 break;
426 case LPFC_VPORT_READY:
427 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
428 break;
429
James Smart92d7f7b2007-06-17 19:56:38 -0500430 case LPFC_VPORT_FAILED:
431 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
432 break;
433
434 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500435 len += snprintf(buf + len, PAGE_SIZE - len,
436 "Unknown\n");
437 break;
438 }
James Smart84774a42008-08-24 21:50:06 -0400439 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
440 len += snprintf(buf + len, PAGE_SIZE-len,
441 " Menlo Maint Mode\n");
442 else if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500443 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500444 len += snprintf(buf + len, PAGE_SIZE-len,
445 " Public Loop\n");
446 else
447 len += snprintf(buf + len, PAGE_SIZE-len,
448 " Private Loop\n");
449 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500450 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500451 len += snprintf(buf + len, PAGE_SIZE-len,
452 " Fabric\n");
453 else
454 len += snprintf(buf + len, PAGE_SIZE-len,
455 " Point-2-Point\n");
456 }
457 }
James Smart2e0fef82007-06-17 19:56:36 -0500458
dea31012005-04-17 16:05:31 -0500459 return len;
460}
461
James Smarte59058c2008-08-24 21:49:00 -0400462/**
James Smart3621a712009-04-06 18:47:14 -0400463 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400464 * @dev: class device that is converted into a Scsi_host.
465 * @attr: device attribute, not used.
466 * @buf: on return contains the sum of fc mapped and unmapped.
467 *
468 * Description:
469 * Returns the ascii text number of the sum of the fc mapped and unmapped
470 * vport counts.
471 *
472 * Returns: size of formatted string.
473 **/
dea31012005-04-17 16:05:31 -0500474static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100475lpfc_num_discovered_ports_show(struct device *dev,
476 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500477{
Tony Jonesee959b02008-02-22 00:13:36 +0100478 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500479 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
480
481 return snprintf(buf, PAGE_SIZE, "%d\n",
482 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500483}
484
James Smarte59058c2008-08-24 21:49:00 -0400485/**
James Smart3621a712009-04-06 18:47:14 -0400486 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400487 * @shost: Scsi_Host pointer.
488 *
489 * Description:
490 * Bring the link down gracefully then re-init the link. The firmware will
491 * re-init the fiber channel interface as required. Does not issue a LIP.
492 *
493 * Returns:
494 * -EPERM port offline or management commands are being blocked
495 * -ENOMEM cannot allocate memory for the mailbox command
496 * -EIO error sending the mailbox command
497 * zero for success
498 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700499static int
James Smart2e0fef82007-06-17 19:56:36 -0500500lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500501{
James Smart2e0fef82007-06-17 19:56:36 -0500502 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
503 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500504 LPFC_MBOXQ_t *pmboxq;
505 int mbxstatus = MBXERR_ERROR;
506
James Smart2e0fef82007-06-17 19:56:36 -0500507 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500508 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500509 return -EPERM;
510
511 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
512
513 if (!pmboxq)
514 return -ENOMEM;
515
516 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400517 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
518 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400519
James Smart33ccf8d2006-08-17 11:57:58 -0400520 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500521
James Smart04c68492009-05-22 14:52:52 -0400522 if ((mbxstatus == MBX_SUCCESS) &&
523 (pmboxq->u.mb.mbxStatus == 0 ||
524 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400525 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
526 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
527 phba->cfg_link_speed);
528 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
529 phba->fc_ratov * 2);
530 }
531
James Smart5b8bd0c2007-04-25 09:52:49 -0400532 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500533 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400534 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500535
536 if (mbxstatus == MBXERR_ERROR)
537 return -EIO;
538
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700539 return 0;
dea31012005-04-17 16:05:31 -0500540}
541
James Smarte59058c2008-08-24 21:49:00 -0400542/**
James Smart3621a712009-04-06 18:47:14 -0400543 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400544 * @phba: lpfc_hba pointer.
545 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
546 *
547 * Notes:
548 * Assumes any error from lpfc_do_offline() will be negative.
549 * Can wait up to 5 seconds for the port ring buffers count
550 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400551 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400552 *
553 * Returns:
554 * -EIO error posting the event
555 * zero for success
556 **/
James Smart40496f02006-07-06 15:50:22 -0400557static int
James Smart46fa3112007-04-25 09:51:45 -0400558lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
559{
560 struct completion online_compl;
561 struct lpfc_sli_ring *pring;
562 struct lpfc_sli *psli;
563 int status = 0;
564 int cnt = 0;
565 int i;
566
567 init_completion(&online_compl);
568 lpfc_workq_post_event(phba, &status, &online_compl,
569 LPFC_EVT_OFFLINE_PREP);
570 wait_for_completion(&online_compl);
571
572 if (status != 0)
573 return -EIO;
574
575 psli = &phba->sli;
576
James Smart09372822008-01-11 01:52:54 -0500577 /* Wait a little for things to settle down, but not
578 * long enough for dev loss timeout to expire.
579 */
James Smart46fa3112007-04-25 09:51:45 -0400580 for (i = 0; i < psli->num_rings; i++) {
581 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400582 while (pring->txcmplq_cnt) {
583 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500584 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400585 lpfc_printf_log(phba,
586 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400587 "0466 Outstanding IO when "
588 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400589 break;
590 }
591 }
592 }
593
594 init_completion(&online_compl);
595 lpfc_workq_post_event(phba, &status, &online_compl, type);
596 wait_for_completion(&online_compl);
597
598 if (status != 0)
599 return -EIO;
600
601 return 0;
602}
603
James Smarte59058c2008-08-24 21:49:00 -0400604/**
James Smart3621a712009-04-06 18:47:14 -0400605 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400606 * @phba: lpfc_hba pointer.
607 *
608 * Description:
609 * If the port is configured to allow a reset then the hba is brought
610 * offline then online.
611 *
612 * Notes:
613 * Assumes any error from lpfc_do_offline() will be negative.
614 *
615 * Returns:
616 * lpfc_do_offline() return code if not zero
617 * -EIO reset not configured or error posting the event
618 * zero for success
619 **/
James Smart46fa3112007-04-25 09:51:45 -0400620static int
James Smart40496f02006-07-06 15:50:22 -0400621lpfc_selective_reset(struct lpfc_hba *phba)
622{
623 struct completion online_compl;
624 int status = 0;
625
James Smart13815c82008-01-11 01:52:48 -0500626 if (!phba->cfg_enable_hba_reset)
627 return -EIO;
628
James Smart46fa3112007-04-25 09:51:45 -0400629 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400630
631 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400632 return status;
James Smart40496f02006-07-06 15:50:22 -0400633
634 init_completion(&online_compl);
635 lpfc_workq_post_event(phba, &status, &online_compl,
636 LPFC_EVT_ONLINE);
637 wait_for_completion(&online_compl);
638
639 if (status != 0)
640 return -EIO;
641
642 return 0;
643}
644
James Smarte59058c2008-08-24 21:49:00 -0400645/**
James Smart3621a712009-04-06 18:47:14 -0400646 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400647 * @dev: class device that is converted into a Scsi_host.
648 * @attr: device attribute, not used.
649 * @buf: containing the string "selective".
650 * @count: unused variable.
651 *
652 * Description:
653 * If the buf contains the string "selective" then lpfc_selective_reset()
654 * is called to perform the reset.
655 *
656 * Notes:
657 * Assumes any error from lpfc_selective_reset() will be negative.
658 * If lpfc_selective_reset() returns zero then the length of the buffer
659 * is returned which indicates succcess
660 *
661 * Returns:
662 * -EINVAL if the buffer does not contain the string "selective"
663 * length of buf if lpfc-selective_reset() if the call succeeds
664 * return value of lpfc_selective_reset() if the call fails
665**/
James Smart40496f02006-07-06 15:50:22 -0400666static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100667lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
668 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400669{
Tony Jonesee959b02008-02-22 00:13:36 +0100670 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500671 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
672 struct lpfc_hba *phba = vport->phba;
673
James Smart40496f02006-07-06 15:50:22 -0400674 int status = -EINVAL;
675
676 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
677 status = lpfc_selective_reset(phba);
678
679 if (status == 0)
680 return strlen(buf);
681 else
682 return status;
683}
684
James Smarte59058c2008-08-24 21:49:00 -0400685/**
James Smart3621a712009-04-06 18:47:14 -0400686 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -0400687 * @dev: class device that is converted into a Scsi_host.
688 * @attr: device attribute, not used.
689 * @buf: on return contains the ascii number of nport events.
690 *
691 * Returns: size of formatted string.
692 **/
dea31012005-04-17 16:05:31 -0500693static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100694lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
695 char *buf)
dea31012005-04-17 16:05:31 -0500696{
Tony Jonesee959b02008-02-22 00:13:36 +0100697 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500698 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
699 struct lpfc_hba *phba = vport->phba;
700
dea31012005-04-17 16:05:31 -0500701 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
702}
703
James Smarte59058c2008-08-24 21:49:00 -0400704/**
James Smart3621a712009-04-06 18:47:14 -0400705 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -0400706 * @dev: class device that is converted into a Scsi_host.
707 * @attr: device attribute, not used.
708 * @buf: on return contains the state of the adapter.
709 *
710 * Returns: size of formatted string.
711 **/
dea31012005-04-17 16:05:31 -0500712static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100713lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
714 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500715{
Tony Jonesee959b02008-02-22 00:13:36 +0100716 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500717 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
718 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500719 char * state;
720
James Smart2e0fef82007-06-17 19:56:36 -0500721 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500722 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500723 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500724 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500725 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500726 state = "offline";
727 else
728 state = "online";
729
730 return snprintf(buf, PAGE_SIZE, "%s\n", state);
731}
732
James Smarte59058c2008-08-24 21:49:00 -0400733/**
James Smart3621a712009-04-06 18:47:14 -0400734 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -0400735 * @dev: class device that is converted into a Scsi_host.
736 * @attr: device attribute, not used.
737 * @buf: containing one of the strings "online", "offline", "warm" or "error".
738 * @count: unused variable.
739 *
740 * Returns:
741 * -EACCES if enable hba reset not enabled
742 * -EINVAL if the buffer does not contain a valid string (see above)
743 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
744 * buf length greater than zero indicates success
745 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500746static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100747lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
748 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500749{
Tony Jonesee959b02008-02-22 00:13:36 +0100750 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500751 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
752 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500753 struct completion online_compl;
754 int status=0;
755
James Smart13815c82008-01-11 01:52:48 -0500756 if (!phba->cfg_enable_hba_reset)
757 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500758 init_completion(&online_compl);
759
James Smart46fa3112007-04-25 09:51:45 -0400760 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500761 lpfc_workq_post_event(phba, &status, &online_compl,
762 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400763 wait_for_completion(&online_compl);
764 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
765 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500766 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400767 if (phba->sli_rev == LPFC_SLI_REV4)
768 return -EINVAL;
769 else
770 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -0400771 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -0400772 if (phba->sli_rev == LPFC_SLI_REV4)
773 return -EINVAL;
774 else
775 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500776 else
777 return -EINVAL;
778
Jamie Wellnitz41415862006-02-28 19:25:27 -0500779 if (!status)
780 return strlen(buf);
781 else
782 return -EIO;
783}
784
James Smarte59058c2008-08-24 21:49:00 -0400785/**
James Smart3621a712009-04-06 18:47:14 -0400786 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -0400787 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -0400788 * @mxri: max xri count.
789 * @axri: available xri count.
790 * @mrpi: max rpi count.
791 * @arpi: available rpi count.
792 * @mvpi: max vpi count.
793 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -0400794 *
795 * Description:
796 * If an integer pointer for an count is not null then the value for the
797 * count is returned.
798 *
799 * Returns:
800 * zero on error
801 * one for success
802 **/
James Smart311464e2007-08-02 11:10:37 -0400803static int
James Smart858c9f62007-06-17 19:56:39 -0500804lpfc_get_hba_info(struct lpfc_hba *phba,
805 uint32_t *mxri, uint32_t *axri,
806 uint32_t *mrpi, uint32_t *arpi,
807 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500808{
James Smart04c68492009-05-22 14:52:52 -0400809 struct lpfc_sli *psli = &phba->sli;
810 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -0500811 LPFC_MBOXQ_t *pmboxq;
812 MAILBOX_t *pmb;
813 int rc = 0;
814
815 /*
816 * prevent udev from issuing mailbox commands until the port is
817 * configured.
818 */
819 if (phba->link_state < LPFC_LINK_DOWN ||
820 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -0400821 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -0500822 return 0;
823
824 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
825 return 0;
826
827 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
828 if (!pmboxq)
829 return 0;
830 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
831
James Smart04c68492009-05-22 14:52:52 -0400832 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500833 pmb->mbxCommand = MBX_READ_CONFIG;
834 pmb->mbxOwner = OWN_HOST;
835 pmboxq->context1 = NULL;
836
837 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -0400838 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart92d7f7b2007-06-17 19:56:38 -0500839 rc = MBX_NOT_FINISHED;
840 else
841 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
842
843 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500844 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500845 mempool_free(pmboxq, phba->mbox_mem_pool);
846 return 0;
847 }
848
James Smartda0436e2009-05-22 14:51:39 -0400849 if (phba->sli_rev == LPFC_SLI_REV4) {
850 rd_config = &pmboxq->u.mqe.un.rd_config;
851 if (mrpi)
852 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
853 if (arpi)
854 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
855 phba->sli4_hba.max_cfg_param.rpi_used;
856 if (mxri)
857 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
858 if (axri)
859 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
860 phba->sli4_hba.max_cfg_param.xri_used;
861 if (mvpi)
862 *mvpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
863 if (avpi)
864 *avpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) -
865 phba->sli4_hba.max_cfg_param.vpi_used;
866 } else {
867 if (mrpi)
868 *mrpi = pmb->un.varRdConfig.max_rpi;
869 if (arpi)
870 *arpi = pmb->un.varRdConfig.avail_rpi;
871 if (mxri)
872 *mxri = pmb->un.varRdConfig.max_xri;
873 if (axri)
874 *axri = pmb->un.varRdConfig.avail_xri;
875 if (mvpi)
876 *mvpi = pmb->un.varRdConfig.max_vpi;
877 if (avpi)
878 *avpi = pmb->un.varRdConfig.avail_vpi;
879 }
James Smart92d7f7b2007-06-17 19:56:38 -0500880
881 mempool_free(pmboxq, phba->mbox_mem_pool);
882 return 1;
883}
884
James Smarte59058c2008-08-24 21:49:00 -0400885/**
James Smart3621a712009-04-06 18:47:14 -0400886 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -0400887 * @dev: class device that is converted into a Scsi_host.
888 * @attr: device attribute, not used.
889 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
890 *
891 * Description:
892 * Calls lpfc_get_hba_info() asking for just the mrpi count.
893 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
894 * to "Unknown" and the buffer length is returned, therefore the caller
895 * must check for "Unknown" in the buffer to detect a failure.
896 *
897 * Returns: size of formatted string.
898 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500899static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100900lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
901 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500902{
Tony Jonesee959b02008-02-22 00:13:36 +0100903 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500904 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
905 struct lpfc_hba *phba = vport->phba;
906 uint32_t cnt;
907
James Smart858c9f62007-06-17 19:56:39 -0500908 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500909 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
910 return snprintf(buf, PAGE_SIZE, "Unknown\n");
911}
912
James Smarte59058c2008-08-24 21:49:00 -0400913/**
James Smart3621a712009-04-06 18:47:14 -0400914 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -0400915 * @dev: class device that is converted into a Scsi_host.
916 * @attr: device attribute, not used.
917 * @buf: containing the used rpi count in decimal or "Unknown".
918 *
919 * Description:
920 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
921 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
922 * to "Unknown" and the buffer length is returned, therefore the caller
923 * must check for "Unknown" in the buffer to detect a failure.
924 *
925 * Returns: size of formatted string.
926 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500927static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100928lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
929 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500930{
Tony Jonesee959b02008-02-22 00:13:36 +0100931 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500932 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
933 struct lpfc_hba *phba = vport->phba;
934 uint32_t cnt, acnt;
935
James Smart858c9f62007-06-17 19:56:39 -0500936 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500937 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
938 return snprintf(buf, PAGE_SIZE, "Unknown\n");
939}
940
James Smarte59058c2008-08-24 21:49:00 -0400941/**
James Smart3621a712009-04-06 18:47:14 -0400942 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -0400943 * @dev: class device that is converted into a Scsi_host.
944 * @attr: device attribute, not used.
945 * @buf: on return contains the maximum xri count in decimal or "Unknown".
946 *
947 * Description:
948 * Calls lpfc_get_hba_info() asking for just the mrpi count.
949 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
950 * to "Unknown" and the buffer length is returned, therefore the caller
951 * must check for "Unknown" in the buffer to detect a failure.
952 *
953 * Returns: size of formatted string.
954 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500955static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100956lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
957 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500958{
Tony Jonesee959b02008-02-22 00:13:36 +0100959 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500960 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
961 struct lpfc_hba *phba = vport->phba;
962 uint32_t cnt;
963
James Smart858c9f62007-06-17 19:56:39 -0500964 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500965 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
966 return snprintf(buf, PAGE_SIZE, "Unknown\n");
967}
968
James Smarte59058c2008-08-24 21:49:00 -0400969/**
James Smart3621a712009-04-06 18:47:14 -0400970 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -0400971 * @dev: class device that is converted into a Scsi_host.
972 * @attr: device attribute, not used.
973 * @buf: on return contains the used xri count in decimal or "Unknown".
974 *
975 * Description:
976 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
977 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
978 * to "Unknown" and the buffer length is returned, therefore the caller
979 * must check for "Unknown" in the buffer to detect a failure.
980 *
981 * Returns: size of formatted string.
982 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500983static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100984lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
985 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500986{
Tony Jonesee959b02008-02-22 00:13:36 +0100987 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500988 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
989 struct lpfc_hba *phba = vport->phba;
990 uint32_t cnt, acnt;
991
James Smart858c9f62007-06-17 19:56:39 -0500992 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
993 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
994 return snprintf(buf, PAGE_SIZE, "Unknown\n");
995}
996
James Smarte59058c2008-08-24 21:49:00 -0400997/**
James Smart3621a712009-04-06 18:47:14 -0400998 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -0400999 * @dev: class device that is converted into a Scsi_host.
1000 * @attr: device attribute, not used.
1001 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1002 *
1003 * Description:
1004 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1005 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1006 * to "Unknown" and the buffer length is returned, therefore the caller
1007 * must check for "Unknown" in the buffer to detect a failure.
1008 *
1009 * Returns: size of formatted string.
1010 **/
James Smart858c9f62007-06-17 19:56:39 -05001011static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001012lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1013 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001014{
Tony Jonesee959b02008-02-22 00:13:36 +01001015 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001016 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1017 struct lpfc_hba *phba = vport->phba;
1018 uint32_t cnt;
1019
1020 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1021 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1022 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1023}
1024
James Smarte59058c2008-08-24 21:49:00 -04001025/**
James Smart3621a712009-04-06 18:47:14 -04001026 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001027 * @dev: class device that is converted into a Scsi_host.
1028 * @attr: device attribute, not used.
1029 * @buf: on return contains the used vpi count in decimal or "Unknown".
1030 *
1031 * Description:
1032 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1033 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1034 * to "Unknown" and the buffer length is returned, therefore the caller
1035 * must check for "Unknown" in the buffer to detect a failure.
1036 *
1037 * Returns: size of formatted string.
1038 **/
James Smart858c9f62007-06-17 19:56:39 -05001039static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001040lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1041 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001042{
Tony Jonesee959b02008-02-22 00:13:36 +01001043 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001044 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1045 struct lpfc_hba *phba = vport->phba;
1046 uint32_t cnt, acnt;
1047
1048 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001049 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1050 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1051}
1052
James Smarte59058c2008-08-24 21:49:00 -04001053/**
James Smart3621a712009-04-06 18:47:14 -04001054 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001055 * @dev: class device that is converted into a Scsi_host.
1056 * @attr: device attribute, not used.
1057 * @buf: text that must be interpreted to determine if npiv is supported.
1058 *
1059 * Description:
1060 * Buffer will contain text indicating npiv is not suppoerted on the port,
1061 * the port is an NPIV physical port, or it is an npiv virtual port with
1062 * the id of the vport.
1063 *
1064 * Returns: size of formatted string.
1065 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001066static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001067lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1068 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001069{
Tony Jonesee959b02008-02-22 00:13:36 +01001070 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001071 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1072 struct lpfc_hba *phba = vport->phba;
1073
1074 if (!(phba->max_vpi))
1075 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1076 if (vport->port_type == LPFC_PHYSICAL_PORT)
1077 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1078 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1079}
1080
James Smarte59058c2008-08-24 21:49:00 -04001081/**
James Smart3621a712009-04-06 18:47:14 -04001082 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001083 * @dev: class device that is converted into a Scsi_host.
1084 * @attr: device attribute, not used.
1085 * @buf: on return contains the cfg_poll in hex.
1086 *
1087 * Notes:
1088 * cfg_poll should be a lpfc_polling_flags type.
1089 *
1090 * Returns: size of formatted string.
1091 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001092static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001093lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1094 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001095{
Tony Jonesee959b02008-02-22 00:13:36 +01001096 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001097 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1098 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001099
1100 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1101}
1102
James Smarte59058c2008-08-24 21:49:00 -04001103/**
James Smart3621a712009-04-06 18:47:14 -04001104 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001105 * @dev: class device that is converted into a Scsi_host.
1106 * @attr: device attribute, not used.
1107 * @buf: one or more lpfc_polling_flags values.
1108 * @count: not used.
1109 *
1110 * Notes:
1111 * buf contents converted to integer and checked for a valid value.
1112 *
1113 * Returns:
1114 * -EINVAL if the buffer connot be converted or is out of range
1115 * length of the buf on success
1116 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001117static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001118lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1119 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001120{
Tony Jonesee959b02008-02-22 00:13:36 +01001121 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001122 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1123 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001124 uint32_t creg_val;
1125 uint32_t old_val;
1126 int val=0;
1127
1128 if (!isdigit(buf[0]))
1129 return -EINVAL;
1130
1131 if (sscanf(buf, "%i", &val) != 1)
1132 return -EINVAL;
1133
1134 if ((val & 0x3) != val)
1135 return -EINVAL;
1136
James Smart2e0fef82007-06-17 19:56:36 -05001137 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001138
1139 old_val = phba->cfg_poll;
1140
1141 if (val & ENABLE_FCP_RING_POLLING) {
1142 if ((val & DISABLE_FCP_RING_INT) &&
1143 !(old_val & DISABLE_FCP_RING_INT)) {
1144 creg_val = readl(phba->HCregaddr);
1145 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1146 writel(creg_val, phba->HCregaddr);
1147 readl(phba->HCregaddr); /* flush */
1148
1149 lpfc_poll_start_timer(phba);
1150 }
1151 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001152 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001153 return -EINVAL;
1154 }
1155
1156 if (!(val & DISABLE_FCP_RING_INT) &&
1157 (old_val & DISABLE_FCP_RING_INT))
1158 {
James Smart2e0fef82007-06-17 19:56:36 -05001159 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001160 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001161 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001162 creg_val = readl(phba->HCregaddr);
1163 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1164 writel(creg_val, phba->HCregaddr);
1165 readl(phba->HCregaddr); /* flush */
1166 }
1167
1168 phba->cfg_poll = val;
1169
James Smart2e0fef82007-06-17 19:56:36 -05001170 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001171
1172 return strlen(buf);
1173}
dea31012005-04-17 16:05:31 -05001174
James Smarte59058c2008-08-24 21:49:00 -04001175/**
James Smart3621a712009-04-06 18:47:14 -04001176 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001177 *
1178 * Description:
1179 * Macro that given an attr e.g. hba_queue_depth expands
1180 * into a function with the name lpfc_hba_queue_depth_show.
1181 *
1182 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1183 * @dev: class device that is converted into a Scsi_host.
1184 * @attr: device attribute, not used.
1185 * @buf: on return contains the attribute value in decimal.
1186 *
1187 * Returns: size of formatted string.
1188 **/
dea31012005-04-17 16:05:31 -05001189#define lpfc_param_show(attr) \
1190static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001191lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1192 char *buf) \
dea31012005-04-17 16:05:31 -05001193{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001194 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001195 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1196 struct lpfc_hba *phba = vport->phba;\
dea31012005-04-17 16:05:31 -05001197 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001198 val = phba->cfg_##attr;\
1199 return snprintf(buf, PAGE_SIZE, "%d\n",\
1200 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001201}
1202
James Smarte59058c2008-08-24 21:49:00 -04001203/**
James Smart3621a712009-04-06 18:47:14 -04001204 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001205 *
1206 * Description:
1207 * Macro that given an attr e.g. hba_queue_depth expands
1208 * into a function with the name lpfc_hba_queue_depth_show
1209 *
1210 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1211 * @dev: class device that is converted into a Scsi_host.
1212 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001213 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001214 *
1215 * Returns: size of formatted string.
1216 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001217#define lpfc_param_hex_show(attr) \
1218static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001219lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1220 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001221{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001222 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001223 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1224 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001225 int val = 0;\
1226 val = phba->cfg_##attr;\
1227 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1228 phba->cfg_##attr);\
1229}
1230
James Smarte59058c2008-08-24 21:49:00 -04001231/**
James Smart3621a712009-04-06 18:47:14 -04001232 * lpfc_param_init - Intializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001233 *
1234 * Description:
1235 * Macro that given an attr e.g. hba_queue_depth expands
1236 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1237 * takes a default argument, a minimum and maximum argument.
1238 *
1239 * lpfc_##attr##_init: Initializes an attribute.
1240 * @phba: pointer the the adapter structure.
1241 * @val: integer attribute value.
1242 *
1243 * Validates the min and max values then sets the adapter config field
1244 * accordingly, or uses the default if out of range and prints an error message.
1245 *
1246 * Returns:
1247 * zero on success
1248 * -EINVAL if default used
1249 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001250#define lpfc_param_init(attr, default, minval, maxval) \
1251static int \
1252lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
1253{ \
1254 if (val >= minval && val <= maxval) {\
1255 phba->cfg_##attr = val;\
1256 return 0;\
1257 }\
1258 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001259 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1260 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001261 phba->cfg_##attr = default;\
1262 return -EINVAL;\
1263}
1264
James Smarte59058c2008-08-24 21:49:00 -04001265/**
James Smart3621a712009-04-06 18:47:14 -04001266 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001267 *
1268 * Description:
1269 * Macro that given an attr e.g. hba_queue_depth expands
1270 * into a function with the name lpfc_hba_queue_depth_set
1271 *
1272 * lpfc_##attr##_set: Sets an attribute value.
1273 * @phba: pointer the the adapter structure.
1274 * @val: integer attribute value.
1275 *
1276 * Description:
1277 * Validates the min and max values then sets the
1278 * adapter config field if in the valid range. prints error message
1279 * and does not set the parameter if invalid.
1280 *
1281 * Returns:
1282 * zero on success
1283 * -EINVAL if val is invalid
1284 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001285#define lpfc_param_set(attr, default, minval, maxval) \
1286static int \
1287lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
1288{ \
1289 if (val >= minval && val <= maxval) {\
1290 phba->cfg_##attr = val;\
1291 return 0;\
1292 }\
1293 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001294 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1295 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001296 return -EINVAL;\
1297}
1298
James Smarte59058c2008-08-24 21:49:00 -04001299/**
James Smart3621a712009-04-06 18:47:14 -04001300 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001301 *
1302 * Description:
1303 * Macro that given an attr e.g. hba_queue_depth expands
1304 * into a function with the name lpfc_hba_queue_depth_store.
1305 *
1306 * lpfc_##attr##_store: Set an sttribute value.
1307 * @dev: class device that is converted into a Scsi_host.
1308 * @attr: device attribute, not used.
1309 * @buf: contains the attribute value in ascii.
1310 * @count: not used.
1311 *
1312 * Description:
1313 * Convert the ascii text number to an integer, then
1314 * use the lpfc_##attr##_set function to set the value.
1315 *
1316 * Returns:
1317 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1318 * length of buffer upon success.
1319 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001320#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001321static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001322lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1323 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001324{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001325 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001326 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1327 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001328 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001329 if (!isdigit(buf[0]))\
1330 return -EINVAL;\
1331 if (sscanf(buf, "%i", &val) != 1)\
1332 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001333 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001334 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001335 else \
1336 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001337}
1338
James Smarte59058c2008-08-24 21:49:00 -04001339/**
James Smart3621a712009-04-06 18:47:14 -04001340 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001341 *
1342 * Description:
1343 * Macro that given an attr e.g. hba_queue_depth expands
1344 * into a function with the name lpfc_hba_queue_depth_show
1345 *
1346 * lpfc_##attr##_show: prints the attribute value in decimal.
1347 * @dev: class device that is converted into a Scsi_host.
1348 * @attr: device attribute, not used.
1349 * @buf: on return contains the attribute value in decimal.
1350 *
1351 * Returns: length of formatted string.
1352 **/
James Smart3de2a652007-08-02 11:09:59 -04001353#define lpfc_vport_param_show(attr) \
1354static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001355lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1356 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001357{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001358 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001359 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1360 int val = 0;\
1361 val = vport->cfg_##attr;\
1362 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1363}
1364
James Smarte59058c2008-08-24 21:49:00 -04001365/**
James Smart3621a712009-04-06 18:47:14 -04001366 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001367 *
1368 * Description:
1369 * Macro that given an attr e.g.
1370 * hba_queue_depth expands into a function with the name
1371 * lpfc_hba_queue_depth_show
1372 *
James Smart3621a712009-04-06 18:47:14 -04001373 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001374 * @dev: class device that is converted into a Scsi_host.
1375 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001376 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001377 *
1378 * Returns: length of formatted string.
1379 **/
James Smart3de2a652007-08-02 11:09:59 -04001380#define lpfc_vport_param_hex_show(attr) \
1381static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001382lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1383 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001384{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001385 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1387 int val = 0;\
1388 val = vport->cfg_##attr;\
1389 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1390}
1391
James Smarte59058c2008-08-24 21:49:00 -04001392/**
James Smart3621a712009-04-06 18:47:14 -04001393 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001394 *
1395 * Description:
1396 * Macro that given an attr e.g. hba_queue_depth expands
1397 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1398 * takes a default argument, a minimum and maximum argument.
1399 *
1400 * lpfc_##attr##_init: validates the min and max values then sets the
1401 * adapter config field accordingly, or uses the default if out of range
1402 * and prints an error message.
1403 * @phba: pointer the the adapter structure.
1404 * @val: integer attribute value.
1405 *
1406 * Returns:
1407 * zero on success
1408 * -EINVAL if default used
1409 **/
James Smart3de2a652007-08-02 11:09:59 -04001410#define lpfc_vport_param_init(attr, default, minval, maxval) \
1411static int \
1412lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
1413{ \
1414 if (val >= minval && val <= maxval) {\
1415 vport->cfg_##attr = val;\
1416 return 0;\
1417 }\
James Smarte8b62012007-08-02 11:10:09 -04001418 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001419 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001420 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001421 vport->cfg_##attr = default;\
1422 return -EINVAL;\
1423}
1424
James Smarte59058c2008-08-24 21:49:00 -04001425/**
James Smart3621a712009-04-06 18:47:14 -04001426 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001427 *
1428 * Description:
1429 * Macro that given an attr e.g. hba_queue_depth expands
1430 * into a function with the name lpfc_hba_queue_depth_set
1431 *
1432 * lpfc_##attr##_set: validates the min and max values then sets the
1433 * adapter config field if in the valid range. prints error message
1434 * and does not set the parameter if invalid.
1435 * @phba: pointer the the adapter structure.
1436 * @val: integer attribute value.
1437 *
1438 * Returns:
1439 * zero on success
1440 * -EINVAL if val is invalid
1441 **/
James Smart3de2a652007-08-02 11:09:59 -04001442#define lpfc_vport_param_set(attr, default, minval, maxval) \
1443static int \
1444lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
1445{ \
1446 if (val >= minval && val <= maxval) {\
1447 vport->cfg_##attr = val;\
1448 return 0;\
1449 }\
James Smarte8b62012007-08-02 11:10:09 -04001450 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001451 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001452 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001453 return -EINVAL;\
1454}
1455
James Smarte59058c2008-08-24 21:49:00 -04001456/**
James Smart3621a712009-04-06 18:47:14 -04001457 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04001458 *
1459 * Description:
1460 * Macro that given an attr e.g. hba_queue_depth
1461 * expands into a function with the name lpfc_hba_queue_depth_store
1462 *
1463 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1464 * use the lpfc_##attr##_set function to set the value.
1465 * @cdev: class device that is converted into a Scsi_host.
1466 * @buf: contains the attribute value in decimal.
1467 * @count: not used.
1468 *
1469 * Returns:
1470 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1471 * length of buffer upon success.
1472 **/
James Smart3de2a652007-08-02 11:09:59 -04001473#define lpfc_vport_param_store(attr) \
1474static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001475lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1476 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001477{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001478 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001479 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1480 int val=0;\
1481 if (!isdigit(buf[0]))\
1482 return -EINVAL;\
1483 if (sscanf(buf, "%i", &val) != 1)\
1484 return -EINVAL;\
1485 if (lpfc_##attr##_set(vport, val) == 0) \
1486 return strlen(buf);\
1487 else \
1488 return -EINVAL;\
1489}
1490
1491
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001492#define LPFC_ATTR(name, defval, minval, maxval, desc) \
1493static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -05001494module_param(lpfc_##name, int, 0);\
1495MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001496lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001497
1498#define LPFC_ATTR_R(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)\
Tony Jonesee959b02008-02-22 00:13:36 +01001504static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001505
1506#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1507static int lpfc_##name = defval;\
1508module_param(lpfc_##name, int, 0);\
1509MODULE_PARM_DESC(lpfc_##name, desc);\
1510lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001511lpfc_param_init(name, defval, minval, maxval)\
1512lpfc_param_set(name, defval, minval, maxval)\
1513lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001514static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1515 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001516
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001517#define LPFC_ATTR_HEX_R(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)\
Tony Jonesee959b02008-02-22 00:13:36 +01001523static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001524
1525#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1526static int lpfc_##name = defval;\
1527module_param(lpfc_##name, int, 0);\
1528MODULE_PARM_DESC(lpfc_##name, desc);\
1529lpfc_param_hex_show(name)\
1530lpfc_param_init(name, defval, minval, maxval)\
1531lpfc_param_set(name, defval, minval, maxval)\
1532lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001533static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1534 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001535
James Smart3de2a652007-08-02 11:09:59 -04001536#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1537static int lpfc_##name = defval;\
1538module_param(lpfc_##name, int, 0);\
1539MODULE_PARM_DESC(lpfc_##name, desc);\
1540lpfc_vport_param_init(name, defval, minval, maxval)
1541
1542#define LPFC_VPORT_ATTR_R(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)\
Tony Jonesee959b02008-02-22 00:13:36 +01001548static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001549
1550#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1551static int lpfc_##name = defval;\
1552module_param(lpfc_##name, int, 0);\
1553MODULE_PARM_DESC(lpfc_##name, desc);\
1554lpfc_vport_param_show(name)\
1555lpfc_vport_param_init(name, defval, minval, maxval)\
1556lpfc_vport_param_set(name, defval, minval, maxval)\
1557lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001558static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1559 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001560
1561#define LPFC_VPORT_ATTR_HEX_R(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)\
Tony Jonesee959b02008-02-22 00:13:36 +01001567static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001568
1569#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1570static int lpfc_##name = defval;\
1571module_param(lpfc_##name, int, 0);\
1572MODULE_PARM_DESC(lpfc_##name, desc);\
1573lpfc_vport_param_hex_show(name)\
1574lpfc_vport_param_init(name, defval, minval, maxval)\
1575lpfc_vport_param_set(name, defval, minval, maxval)\
1576lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001577static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1578 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001579
James Smart81301a92008-12-04 22:39:46 -05001580static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1581static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1582static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1583static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001584static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1585static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1586static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1587static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1588static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1589static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1590static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1591static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001592static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001593static DEVICE_ATTR(option_rom_version, S_IRUGO,
1594 lpfc_option_rom_version_show, NULL);
1595static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1596 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001597static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001598static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1599static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1600static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1601 lpfc_board_mode_show, lpfc_board_mode_store);
1602static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1603static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1604static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1605static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1606static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1607static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1608static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1609static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1610static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
dea31012005-04-17 16:05:31 -05001611
James Smartc3f28af2006-08-18 17:47:18 -04001612
James Smarta12e07b2006-12-02 13:35:30 -05001613static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001614
James Smarte59058c2008-08-24 21:49:00 -04001615/**
James Smart3621a712009-04-06 18:47:14 -04001616 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
James Smarte59058c2008-08-24 21:49:00 -04001617 * @dev: class device that is converted into a Scsi_host.
1618 * @attr: device attribute, not used.
1619 * @buf: containing the string lpfc_soft_wwn_key.
1620 * @count: must be size of lpfc_soft_wwn_key.
1621 *
1622 * Returns:
1623 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1624 * length of buf indicates success
1625 **/
James Smartc3f28af2006-08-18 17:47:18 -04001626static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001627lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1628 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001629{
Tony Jonesee959b02008-02-22 00:13:36 +01001630 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001631 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1632 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001633 unsigned int cnt = count;
1634
1635 /*
1636 * We're doing a simple sanity check for soft_wwpn setting.
1637 * We require that the user write a specific key to enable
1638 * the soft_wwpn attribute to be settable. Once the attribute
1639 * is written, the enable key resets. If further updates are
1640 * desired, the key must be written again to re-enable the
1641 * attribute.
1642 *
1643 * The "key" is not secret - it is a hardcoded string shown
1644 * here. The intent is to protect against the random user or
1645 * application that is just writing attributes.
1646 */
1647
1648 /* count may include a LF at end of string */
1649 if (buf[cnt-1] == '\n')
1650 cnt--;
1651
James Smarta12e07b2006-12-02 13:35:30 -05001652 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1653 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001654 return -EINVAL;
1655
James Smarta12e07b2006-12-02 13:35:30 -05001656 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001657 return count;
1658}
Tony Jonesee959b02008-02-22 00:13:36 +01001659static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1660 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001661
James Smarte59058c2008-08-24 21:49:00 -04001662/**
James Smart3621a712009-04-06 18:47:14 -04001663 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001664 * @dev: class device that is converted into a Scsi_host.
1665 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001666 * @buf: on return contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001667 *
1668 * Returns: size of formatted string.
1669 **/
James Smartc3f28af2006-08-18 17:47:18 -04001670static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001671lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1672 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001673{
Tony Jonesee959b02008-02-22 00:13:36 +01001674 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001675 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1676 struct lpfc_hba *phba = vport->phba;
1677
Randy Dunlapafc071e62006-10-23 21:47:13 -07001678 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1679 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001680}
1681
James Smarte59058c2008-08-24 21:49:00 -04001682/**
James Smart3621a712009-04-06 18:47:14 -04001683 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001684 * @dev class device that is converted into a Scsi_host.
1685 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001686 * @buf: contains the wwpn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001687 * @count: number of wwpn bytes in buf
1688 *
1689 * Returns:
1690 * -EACCES hba reset not enabled, adapter over temp
1691 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1692 * -EIO error taking adapter offline or online
1693 * value of count on success
1694 **/
James Smartc3f28af2006-08-18 17:47:18 -04001695static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001696lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1697 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001698{
Tony Jonesee959b02008-02-22 00:13:36 +01001699 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001700 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1701 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001702 struct completion online_compl;
1703 int stat1=0, stat2=0;
1704 unsigned int i, j, cnt=count;
1705 u8 wwpn[8];
1706
James Smart13815c82008-01-11 01:52:48 -05001707 if (!phba->cfg_enable_hba_reset)
1708 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001709 spin_lock_irq(&phba->hbalock);
1710 if (phba->over_temp_state == HBA_OVER_TEMP) {
1711 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001712 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001713 }
1714 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001715 /* count may include a LF at end of string */
1716 if (buf[cnt-1] == '\n')
1717 cnt--;
1718
James Smarta12e07b2006-12-02 13:35:30 -05001719 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001720 ((cnt == 17) && (*buf++ != 'x')) ||
1721 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1722 return -EINVAL;
1723
James Smarta12e07b2006-12-02 13:35:30 -05001724 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001725
1726 memset(wwpn, 0, sizeof(wwpn));
1727
1728 /* Validate and store the new name */
1729 for (i=0, j=0; i < 16; i++) {
1730 if ((*buf >= 'a') && (*buf <= 'f'))
1731 j = ((j << 4) | ((*buf++ -'a') + 10));
1732 else if ((*buf >= 'A') && (*buf <= 'F'))
1733 j = ((j << 4) | ((*buf++ -'A') + 10));
1734 else if ((*buf >= '0') && (*buf <= '9'))
1735 j = ((j << 4) | (*buf++ -'0'));
1736 else
1737 return -EINVAL;
1738 if (i % 2) {
1739 wwpn[i/2] = j & 0xff;
1740 j = 0;
1741 }
1742 }
1743 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001744 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001745 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001746 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001747
1748 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1749 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1750
James Smart46fa3112007-04-25 09:51:45 -04001751 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001752 if (stat1)
1753 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001754 "0463 lpfc_soft_wwpn attribute set failed to "
1755 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001756 init_completion(&online_compl);
1757 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1758 wait_for_completion(&online_compl);
1759 if (stat2)
1760 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001761 "0464 lpfc_soft_wwpn attribute set failed to "
1762 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001763 return (stat1 || stat2) ? -EIO : count;
1764}
Tony Jonesee959b02008-02-22 00:13:36 +01001765static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1766 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001767
James Smarte59058c2008-08-24 21:49:00 -04001768/**
James Smart3621a712009-04-06 18:47:14 -04001769 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001770 * @dev: class device that is converted into a Scsi_host.
1771 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001772 * @buf: on return contains the wwnn in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001773 *
1774 * Returns: size of formatted string.
1775 **/
James Smarta12e07b2006-12-02 13:35:30 -05001776static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001777lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1778 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001779{
Tony Jonesee959b02008-02-22 00:13:36 +01001780 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001781 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001782 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1783 (unsigned long long)phba->cfg_soft_wwnn);
1784}
1785
James Smarte59058c2008-08-24 21:49:00 -04001786/**
James Smart3621a712009-04-06 18:47:14 -04001787 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
James Smarte59058c2008-08-24 21:49:00 -04001788 * @cdev: class device that is converted into a Scsi_host.
James Smart3621a712009-04-06 18:47:14 -04001789 * @buf: contains the ww node name in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001790 * @count: number of wwnn bytes in buf.
1791 *
1792 * Returns:
1793 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1794 * value of count on success
1795 **/
James Smarta12e07b2006-12-02 13:35:30 -05001796static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001797lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1798 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001799{
Tony Jonesee959b02008-02-22 00:13:36 +01001800 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001801 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001802 unsigned int i, j, cnt=count;
1803 u8 wwnn[8];
1804
1805 /* count may include a LF at end of string */
1806 if (buf[cnt-1] == '\n')
1807 cnt--;
1808
1809 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1810 ((cnt == 17) && (*buf++ != 'x')) ||
1811 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1812 return -EINVAL;
1813
1814 /*
1815 * Allow wwnn to be set many times, as long as the enable is set.
1816 * However, once the wwpn is set, everything locks.
1817 */
1818
1819 memset(wwnn, 0, sizeof(wwnn));
1820
1821 /* Validate and store the new name */
1822 for (i=0, j=0; i < 16; i++) {
1823 if ((*buf >= 'a') && (*buf <= 'f'))
1824 j = ((j << 4) | ((*buf++ -'a') + 10));
1825 else if ((*buf >= 'A') && (*buf <= 'F'))
1826 j = ((j << 4) | ((*buf++ -'A') + 10));
1827 else if ((*buf >= '0') && (*buf <= '9'))
1828 j = ((j << 4) | (*buf++ -'0'));
1829 else
1830 return -EINVAL;
1831 if (i % 2) {
1832 wwnn[i/2] = j & 0xff;
1833 j = 0;
1834 }
1835 }
1836 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1837
1838 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1839 "lpfc%d: soft_wwnn set. Value will take effect upon "
1840 "setting of the soft_wwpn\n", phba->brd_no);
1841
1842 return count;
1843}
Tony Jonesee959b02008-02-22 00:13:36 +01001844static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1845 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001846
James Smartc3f28af2006-08-18 17:47:18 -04001847
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001848static int lpfc_poll = 0;
1849module_param(lpfc_poll, int, 0);
1850MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1851 " 0 - none,"
1852 " 1 - poll with interrupts enabled"
1853 " 3 - poll and disable FCP ring interrupts");
1854
Tony Jonesee959b02008-02-22 00:13:36 +01001855static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1856 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001857
James Smart92d7f7b2007-06-17 19:56:38 -05001858int lpfc_sli_mode = 0;
1859module_param(lpfc_sli_mode, int, 0);
1860MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1861 " 0 - auto (SLI-3 if supported),"
1862 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1863 " 3 - select SLI-3");
1864
James Smart7ee5d432007-10-27 13:37:17 -04001865int lpfc_enable_npiv = 0;
1866module_param(lpfc_enable_npiv, int, 0);
1867MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1868lpfc_param_show(enable_npiv);
1869lpfc_param_init(enable_npiv, 0, 0, 1);
Tony Jonesee959b02008-02-22 00:13:36 +01001870static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
James Smart7ee5d432007-10-27 13:37:17 -04001871 lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001872
dea31012005-04-17 16:05:31 -05001873/*
James Smartc01f3202006-08-18 17:47:08 -04001874# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1875# until the timer expires. Value range is [0,255]. Default value is 30.
1876*/
1877static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1878static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1879module_param(lpfc_nodev_tmo, int, 0);
1880MODULE_PARM_DESC(lpfc_nodev_tmo,
1881 "Seconds driver will hold I/O waiting "
1882 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04001883
1884/**
James Smart3621a712009-04-06 18:47:14 -04001885 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04001886 * @dev: class converted to a Scsi_host structure.
1887 * @attr: device attribute, not used.
1888 * @buf: on return contains the dev loss timeout in decimal.
1889 *
1890 * Returns: size of formatted string.
1891 **/
James Smartc01f3202006-08-18 17:47:08 -04001892static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001893lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1894 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04001895{
Tony Jonesee959b02008-02-22 00:13:36 +01001896 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001897 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smartc01f3202006-08-18 17:47:08 -04001898 int val = 0;
James Smart3de2a652007-08-02 11:09:59 -04001899 val = vport->cfg_devloss_tmo;
1900 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001901}
1902
James Smarte59058c2008-08-24 21:49:00 -04001903/**
James Smart3621a712009-04-06 18:47:14 -04001904 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04001905 * @vport: lpfc vport structure pointer.
1906 * @val: contains the nodev timeout value.
1907 *
1908 * Description:
1909 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1910 * a kernel error message is printed and zero is returned.
1911 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1912 * Otherwise nodev tmo is set to the default value.
1913 *
1914 * Returns:
1915 * zero if already set or if val is in range
1916 * -EINVAL val out of range
1917 **/
James Smartc01f3202006-08-18 17:47:08 -04001918static int
James Smart3de2a652007-08-02 11:09:59 -04001919lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001920{
James Smart3de2a652007-08-02 11:09:59 -04001921 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1922 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1923 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04001924 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001925 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04001926 "parameter because devloss_tmo is "
1927 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001928 return 0;
1929 }
1930
1931 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001932 vport->cfg_nodev_tmo = val;
1933 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04001934 return 0;
1935 }
James Smarte8b62012007-08-02 11:10:09 -04001936 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1937 "0400 lpfc_nodev_tmo attribute cannot be set to"
1938 " %d, allowed range is [%d, %d]\n",
1939 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04001940 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04001941 return -EINVAL;
1942}
1943
James Smarte59058c2008-08-24 21:49:00 -04001944/**
James Smart3621a712009-04-06 18:47:14 -04001945 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04001946 * @vport: lpfc vport structure pointer.
1947 *
1948 * Description:
1949 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
1950 **/
James Smart7054a602007-04-25 09:52:34 -04001951static void
James Smart3de2a652007-08-02 11:09:59 -04001952lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04001953{
James Smart858c9f62007-06-17 19:56:39 -05001954 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04001955 struct lpfc_nodelist *ndlp;
1956
James Smart51ef4c22007-08-02 11:10:31 -04001957 shost = lpfc_shost_from_vport(vport);
1958 spin_lock_irq(shost->host_lock);
1959 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05001960 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04001961 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1962 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04001963}
1964
James Smarte59058c2008-08-24 21:49:00 -04001965/**
James Smart3621a712009-04-06 18:47:14 -04001966 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04001967 * @vport: lpfc vport structure pointer.
1968 * @val: contains the tmo value.
1969 *
1970 * Description:
1971 * If the devloss tmo is already set or the vport dev loss tmo has changed
1972 * then a kernel error message is printed and zero is returned.
1973 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1974 * Otherwise nodev tmo is set to the default value.
1975 *
1976 * Returns:
1977 * zero if already set or if val is in range
1978 * -EINVAL val out of range
1979 **/
James Smartc01f3202006-08-18 17:47:08 -04001980static int
James Smart3de2a652007-08-02 11:09:59 -04001981lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001982{
James Smart3de2a652007-08-02 11:09:59 -04001983 if (vport->dev_loss_tmo_changed ||
1984 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04001985 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1986 "0401 Ignoring change to nodev_tmo "
1987 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001988 return 0;
1989 }
James Smartc01f3202006-08-18 17:47:08 -04001990 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001991 vport->cfg_nodev_tmo = val;
1992 vport->cfg_devloss_tmo = val;
1993 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001994 return 0;
1995 }
James Smarte8b62012007-08-02 11:10:09 -04001996 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1997 "0403 lpfc_nodev_tmo attribute cannot be set to"
1998 "%d, allowed range is [%d, %d]\n",
1999 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002000 return -EINVAL;
2001}
2002
James Smart3de2a652007-08-02 11:09:59 -04002003lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04002004
Tony Jonesee959b02008-02-22 00:13:36 +01002005static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2006 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002007
2008/*
2009# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2010# disappear until the timer expires. Value range is [0,255]. Default
2011# value is 30.
2012*/
2013module_param(lpfc_devloss_tmo, int, 0);
2014MODULE_PARM_DESC(lpfc_devloss_tmo,
2015 "Seconds driver will hold I/O waiting "
2016 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04002017lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2018 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2019lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04002020
2021/**
James Smart3621a712009-04-06 18:47:14 -04002022 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04002023 * @vport: lpfc vport structure pointer.
2024 * @val: contains the tmo value.
2025 *
2026 * Description:
2027 * If val is in a valid range then set the vport nodev tmo,
2028 * devloss tmo, also set the vport dev loss tmo changed flag.
2029 * Else a kernel error message is printed.
2030 *
2031 * Returns:
2032 * zero if val is in range
2033 * -EINVAL val out of range
2034 **/
James Smartc01f3202006-08-18 17:47:08 -04002035static int
James Smart3de2a652007-08-02 11:09:59 -04002036lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04002037{
2038 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04002039 vport->cfg_nodev_tmo = val;
2040 vport->cfg_devloss_tmo = val;
2041 vport->dev_loss_tmo_changed = 1;
2042 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04002043 return 0;
2044 }
2045
James Smarte8b62012007-08-02 11:10:09 -04002046 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2047 "0404 lpfc_devloss_tmo attribute cannot be set to"
2048 " %d, allowed range is [%d, %d]\n",
2049 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04002050 return -EINVAL;
2051}
2052
James Smart3de2a652007-08-02 11:09:59 -04002053lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01002054static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2055 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04002056
2057/*
dea31012005-04-17 16:05:31 -05002058# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2059# deluged with LOTS of information.
2060# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04002061# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05002062*/
James Smartf4b4c682009-05-22 14:53:12 -04002063LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04002064 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05002065
2066/*
James Smart7ee5d432007-10-27 13:37:17 -04002067# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2068# objects that have been registered with the nameserver after login.
2069*/
2070LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2071 "Deregister nameserver objects before LOGO");
2072
2073/*
dea31012005-04-17 16:05:31 -05002074# lun_queue_depth: This parameter is used to limit the number of outstanding
2075# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2076*/
James Smart3de2a652007-08-02 11:09:59 -04002077LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2078 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05002079
2080/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002081# hba_queue_depth: This parameter is used to limit the number of outstanding
2082# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2083# value is greater than the maximum number of exchanges supported by the HBA,
2084# then maximum number of exchanges supported by the HBA is used to determine
2085# the hba_queue_depth.
2086*/
2087LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2088 "Max number of FCP commands we can queue to a lpfc HBA");
2089
2090/*
James Smart92d7f7b2007-06-17 19:56:38 -05002091# peer_port_login: This parameter allows/prevents logins
2092# between peer ports hosted on the same physical port.
2093# When this parameter is set 0 peer ports of same physical port
2094# are not allowed to login to each other.
2095# When this parameter is set 1 peer ports of same physical port
2096# are allowed to login to each other.
2097# Default value of this parameter is 0.
2098*/
James Smart3de2a652007-08-02 11:09:59 -04002099LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2100 "Allow peer ports on the same physical port to login to each "
2101 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002102
2103/*
James Smart3de2a652007-08-02 11:09:59 -04002104# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002105# between Virtual Ports and remote initiators.
2106# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2107# other initiators and will attempt to PLOGI all remote ports.
2108# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2109# remote ports and will not attempt to PLOGI to other initiators.
2110# This parameter does not restrict to the physical port.
2111# This parameter does not restrict logins to Fabric resident remote ports.
2112# Default value of this parameter is 1.
2113*/
James Smart3de2a652007-08-02 11:09:59 -04002114static int lpfc_restrict_login = 1;
2115module_param(lpfc_restrict_login, int, 0);
2116MODULE_PARM_DESC(lpfc_restrict_login,
2117 "Restrict virtual ports login to remote initiators.");
2118lpfc_vport_param_show(restrict_login);
2119
James Smarte59058c2008-08-24 21:49:00 -04002120/**
James Smart3621a712009-04-06 18:47:14 -04002121 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002122 * @vport: lpfc vport structure pointer.
2123 * @val: contains the restrict login value.
2124 *
2125 * Description:
2126 * If val is not in a valid range then log a kernel error message and set
2127 * the vport restrict login to one.
2128 * If the port type is physical clear the restrict login flag and return.
2129 * Else set the restrict login flag to val.
2130 *
2131 * Returns:
2132 * zero if val is in range
2133 * -EINVAL val out of range
2134 **/
James Smart3de2a652007-08-02 11:09:59 -04002135static int
2136lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2137{
2138 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002139 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002140 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002141 "be set to %d, allowed range is [0, 1]\n",
2142 val);
James Smart3de2a652007-08-02 11:09:59 -04002143 vport->cfg_restrict_login = 1;
2144 return -EINVAL;
2145 }
2146 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2147 vport->cfg_restrict_login = 0;
2148 return 0;
2149 }
2150 vport->cfg_restrict_login = val;
2151 return 0;
2152}
2153
James Smarte59058c2008-08-24 21:49:00 -04002154/**
James Smart3621a712009-04-06 18:47:14 -04002155 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04002156 * @vport: lpfc vport structure pointer.
2157 * @val: contains the restrict login value.
2158 *
2159 * Description:
2160 * If val is not in a valid range then log a kernel error message and set
2161 * the vport restrict login to one.
2162 * If the port type is physical and the val is not zero log a kernel
2163 * error message, clear the restrict login flag and return zero.
2164 * Else set the restrict login flag to val.
2165 *
2166 * Returns:
2167 * zero if val is in range
2168 * -EINVAL val out of range
2169 **/
James Smart3de2a652007-08-02 11:09:59 -04002170static int
2171lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2172{
2173 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002174 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002175 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002176 "be set to %d, allowed range is [0, 1]\n",
2177 val);
James Smart3de2a652007-08-02 11:09:59 -04002178 vport->cfg_restrict_login = 1;
2179 return -EINVAL;
2180 }
2181 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002182 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2183 "0468 lpfc_restrict_login must be 0 for "
2184 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002185 vport->cfg_restrict_login = 0;
2186 return 0;
2187 }
2188 vport->cfg_restrict_login = val;
2189 return 0;
2190}
2191lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002192static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2193 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002194
2195/*
dea31012005-04-17 16:05:31 -05002196# Some disk devices have a "select ID" or "select Target" capability.
2197# From a protocol standpoint "select ID" usually means select the
2198# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2199# annex" which contains a table that maps a "select ID" (a number
2200# between 0 and 7F) to an ALPA. By default, for compatibility with
2201# older drivers, the lpfc driver scans this table from low ALPA to high
2202# ALPA.
2203#
2204# Turning on the scan-down variable (on = 1, off = 0) will
2205# cause the lpfc driver to use an inverted table, effectively
2206# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2207#
2208# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2209# and will not work across a fabric. Also this parameter will take
2210# effect only in the case when ALPA map is not available.)
2211*/
James Smart3de2a652007-08-02 11:09:59 -04002212LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2213 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002214
2215/*
dea31012005-04-17 16:05:31 -05002216# lpfc_topology: link topology for init link
2217# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002218# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002219# 0x02 = attempt point-to-point mode only
2220# 0x04 = attempt loop mode only
2221# 0x06 = attempt point-to-point mode then loop
2222# Set point-to-point mode if you want to run as an N_Port.
2223# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2224# Default value is 0.
2225*/
James Smarte59058c2008-08-24 21:49:00 -04002226
2227/**
James Smart3621a712009-04-06 18:47:14 -04002228 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04002229 * @phba: lpfc_hba pointer.
2230 * @val: topology value.
2231 *
2232 * Description:
2233 * If val is in a valid range then set the adapter's topology field and
2234 * issue a lip; if the lip fails reset the topology to the old value.
2235 *
2236 * If the value is not in range log a kernel error message and return an error.
2237 *
2238 * Returns:
2239 * zero if val is in range and lip okay
2240 * non-zero return value from lpfc_issue_lip()
2241 * -EINVAL val out of range
2242 **/
James Smarta257bf92009-04-06 18:48:10 -04002243static ssize_t
2244lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2245 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002246{
James Smarta257bf92009-04-06 18:48:10 -04002247 struct Scsi_Host *shost = class_to_shost(dev);
2248 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2249 struct lpfc_hba *phba = vport->phba;
2250 int val = 0;
2251 int nolip = 0;
2252 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002253 int err;
2254 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002255
2256 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2257 nolip = 1;
2258 val_buf = &buf[strlen("nolip ")];
2259 }
2260
2261 if (!isdigit(val_buf[0]))
2262 return -EINVAL;
2263 if (sscanf(val_buf, "%i", &val) != 1)
2264 return -EINVAL;
2265
James Smart83108bd2008-01-11 01:53:09 -05002266 if (val >= 0 && val <= 6) {
2267 prev_val = phba->cfg_topology;
2268 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04002269 if (nolip)
2270 return strlen(buf);
2271
James Smart83108bd2008-01-11 01:53:09 -05002272 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002273 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002274 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002275 return -EINVAL;
2276 } else
2277 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002278 }
2279 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2280 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2281 "allowed range is [0, 6]\n",
2282 phba->brd_no, val);
2283 return -EINVAL;
2284}
2285static int lpfc_topology = 0;
2286module_param(lpfc_topology, int, 0);
2287MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2288lpfc_param_show(topology)
2289lpfc_param_init(topology, 0, 0, 6)
Tony Jonesee959b02008-02-22 00:13:36 +01002290static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002291 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002292
James Smart21e9a0a2009-05-22 14:53:21 -04002293/**
2294 * lpfc_static_vport_show: Read callback function for
2295 * lpfc_static_vport sysfs file.
2296 * @dev: Pointer to class device object.
2297 * @attr: device attribute structure.
2298 * @buf: Data buffer.
2299 *
2300 * This function is the read call back function for
2301 * lpfc_static_vport sysfs file. The lpfc_static_vport
2302 * sysfs file report the mageability of the vport.
2303 **/
2304static ssize_t
2305lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2306 char *buf)
2307{
2308 struct Scsi_Host *shost = class_to_shost(dev);
2309 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2310 if (vport->vport_flag & STATIC_VPORT)
2311 sprintf(buf, "1\n");
2312 else
2313 sprintf(buf, "0\n");
2314
2315 return strlen(buf);
2316}
2317
2318/*
2319 * Sysfs attribute to control the statistical data collection.
2320 */
2321static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2322 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04002323
2324/**
James Smart3621a712009-04-06 18:47:14 -04002325 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002326 * @dev: Pointer to class device.
2327 * @buf: Data buffer.
2328 * @count: Size of the data buffer.
2329 *
2330 * This function get called when an user write to the lpfc_stat_data_ctrl
2331 * sysfs file. This function parse the command written to the sysfs file
2332 * and take appropriate action. These commands are used for controlling
2333 * driver statistical data collection.
2334 * Following are the command this function handles.
2335 *
2336 * setbucket <bucket_type> <base> <step>
2337 * = Set the latency buckets.
2338 * destroybucket = destroy all the buckets.
2339 * start = start data collection
2340 * stop = stop data collection
2341 * reset = reset the collected data
2342 **/
2343static ssize_t
2344lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2345 const char *buf, size_t count)
2346{
2347 struct Scsi_Host *shost = class_to_shost(dev);
2348 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2349 struct lpfc_hba *phba = vport->phba;
2350#define LPFC_MAX_DATA_CTRL_LEN 1024
2351 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2352 unsigned long i;
2353 char *str_ptr, *token;
2354 struct lpfc_vport **vports;
2355 struct Scsi_Host *v_shost;
2356 char *bucket_type_str, *base_str, *step_str;
2357 unsigned long base, step, bucket_type;
2358
2359 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04002360 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04002361 return -EINVAL;
2362
2363 strcpy(bucket_data, buf);
2364 str_ptr = &bucket_data[0];
2365 /* Ignore this token - this is command token */
2366 token = strsep(&str_ptr, "\t ");
2367 if (!token)
2368 return -EINVAL;
2369
2370 bucket_type_str = strsep(&str_ptr, "\t ");
2371 if (!bucket_type_str)
2372 return -EINVAL;
2373
2374 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2375 bucket_type = LPFC_LINEAR_BUCKET;
2376 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2377 bucket_type = LPFC_POWER2_BUCKET;
2378 else
2379 return -EINVAL;
2380
2381 base_str = strsep(&str_ptr, "\t ");
2382 if (!base_str)
2383 return -EINVAL;
2384 base = simple_strtoul(base_str, NULL, 0);
2385
2386 step_str = strsep(&str_ptr, "\t ");
2387 if (!step_str)
2388 return -EINVAL;
2389 step = simple_strtoul(step_str, NULL, 0);
2390 if (!step)
2391 return -EINVAL;
2392
2393 /* Block the data collection for every vport */
2394 vports = lpfc_create_vport_work_array(phba);
2395 if (vports == NULL)
2396 return -ENOMEM;
2397
James Smartf4b4c682009-05-22 14:53:12 -04002398 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002399 v_shost = lpfc_shost_from_vport(vports[i]);
2400 spin_lock_irq(v_shost->host_lock);
2401 /* Block and reset data collection */
2402 vports[i]->stat_data_blocked = 1;
2403 if (vports[i]->stat_data_enabled)
2404 lpfc_vport_reset_stat_data(vports[i]);
2405 spin_unlock_irq(v_shost->host_lock);
2406 }
2407
2408 /* Set the bucket attributes */
2409 phba->bucket_type = bucket_type;
2410 phba->bucket_base = base;
2411 phba->bucket_step = step;
2412
James Smartf4b4c682009-05-22 14:53:12 -04002413 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002414 v_shost = lpfc_shost_from_vport(vports[i]);
2415
2416 /* Unblock data collection */
2417 spin_lock_irq(v_shost->host_lock);
2418 vports[i]->stat_data_blocked = 0;
2419 spin_unlock_irq(v_shost->host_lock);
2420 }
2421 lpfc_destroy_vport_work_array(phba, vports);
2422 return strlen(buf);
2423 }
2424
2425 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2426 vports = lpfc_create_vport_work_array(phba);
2427 if (vports == NULL)
2428 return -ENOMEM;
2429
James Smartf4b4c682009-05-22 14:53:12 -04002430 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04002431 v_shost = lpfc_shost_from_vport(vports[i]);
2432 spin_lock_irq(shost->host_lock);
2433 vports[i]->stat_data_blocked = 1;
2434 lpfc_free_bucket(vport);
2435 vport->stat_data_enabled = 0;
2436 vports[i]->stat_data_blocked = 0;
2437 spin_unlock_irq(shost->host_lock);
2438 }
2439 lpfc_destroy_vport_work_array(phba, vports);
2440 phba->bucket_type = LPFC_NO_BUCKET;
2441 phba->bucket_base = 0;
2442 phba->bucket_step = 0;
2443 return strlen(buf);
2444 }
2445
2446 if (!strncmp(buf, "start", strlen("start"))) {
2447 /* If no buckets configured return error */
2448 if (phba->bucket_type == LPFC_NO_BUCKET)
2449 return -EINVAL;
2450 spin_lock_irq(shost->host_lock);
2451 if (vport->stat_data_enabled) {
2452 spin_unlock_irq(shost->host_lock);
2453 return strlen(buf);
2454 }
2455 lpfc_alloc_bucket(vport);
2456 vport->stat_data_enabled = 1;
2457 spin_unlock_irq(shost->host_lock);
2458 return strlen(buf);
2459 }
2460
2461 if (!strncmp(buf, "stop", strlen("stop"))) {
2462 spin_lock_irq(shost->host_lock);
2463 if (vport->stat_data_enabled == 0) {
2464 spin_unlock_irq(shost->host_lock);
2465 return strlen(buf);
2466 }
2467 lpfc_free_bucket(vport);
2468 vport->stat_data_enabled = 0;
2469 spin_unlock_irq(shost->host_lock);
2470 return strlen(buf);
2471 }
2472
2473 if (!strncmp(buf, "reset", strlen("reset"))) {
2474 if ((phba->bucket_type == LPFC_NO_BUCKET)
2475 || !vport->stat_data_enabled)
2476 return strlen(buf);
2477 spin_lock_irq(shost->host_lock);
2478 vport->stat_data_blocked = 1;
2479 lpfc_vport_reset_stat_data(vport);
2480 vport->stat_data_blocked = 0;
2481 spin_unlock_irq(shost->host_lock);
2482 return strlen(buf);
2483 }
2484 return -EINVAL;
2485}
2486
2487
2488/**
James Smart3621a712009-04-06 18:47:14 -04002489 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04002490 * @dev: Pointer to class device object.
2491 * @buf: Data buffer.
2492 *
2493 * This function is the read call back function for
2494 * lpfc_stat_data_ctrl sysfs file. This function report the
2495 * current statistical data collection state.
2496 **/
2497static ssize_t
2498lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2499 char *buf)
2500{
2501 struct Scsi_Host *shost = class_to_shost(dev);
2502 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2503 struct lpfc_hba *phba = vport->phba;
2504 int index = 0;
2505 int i;
2506 char *bucket_type;
2507 unsigned long bucket_value;
2508
2509 switch (phba->bucket_type) {
2510 case LPFC_LINEAR_BUCKET:
2511 bucket_type = "linear";
2512 break;
2513 case LPFC_POWER2_BUCKET:
2514 bucket_type = "power2";
2515 break;
2516 default:
2517 bucket_type = "No Bucket";
2518 break;
2519 }
2520
2521 sprintf(&buf[index], "Statistical Data enabled :%d, "
2522 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2523 " Bucket step :%d\nLatency Ranges :",
2524 vport->stat_data_enabled, vport->stat_data_blocked,
2525 bucket_type, phba->bucket_base, phba->bucket_step);
2526 index = strlen(buf);
2527 if (phba->bucket_type != LPFC_NO_BUCKET) {
2528 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2529 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2530 bucket_value = phba->bucket_base +
2531 phba->bucket_step * i;
2532 else
2533 bucket_value = phba->bucket_base +
2534 (1 << i) * phba->bucket_step;
2535
2536 if (index + 10 > PAGE_SIZE)
2537 break;
2538 sprintf(&buf[index], "%08ld ", bucket_value);
2539 index = strlen(buf);
2540 }
2541 }
2542 sprintf(&buf[index], "\n");
2543 return strlen(buf);
2544}
2545
2546/*
2547 * Sysfs attribute to control the statistical data collection.
2548 */
2549static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2550 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2551
2552/*
2553 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2554 */
2555
2556/*
2557 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2558 * for each target.
2559 */
2560#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2561#define MAX_STAT_DATA_SIZE_PER_TARGET \
2562 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2563
2564
2565/**
James Smart3621a712009-04-06 18:47:14 -04002566 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
James Smartea2151b2008-09-07 11:52:10 -04002567 * @kobj: Pointer to the kernel object
2568 * @bin_attr: Attribute object
2569 * @buff: Buffer pointer
2570 * @off: File offset
2571 * @count: Buffer size
2572 *
2573 * This function is the read call back function for lpfc_drvr_stat_data
2574 * sysfs file. This function export the statistical data to user
2575 * applications.
2576 **/
2577static ssize_t
2578sysfs_drvr_stat_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2579 char *buf, loff_t off, size_t count)
2580{
2581 struct device *dev = container_of(kobj, struct device,
2582 kobj);
2583 struct Scsi_Host *shost = class_to_shost(dev);
2584 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2585 struct lpfc_hba *phba = vport->phba;
2586 int i = 0, index = 0;
2587 unsigned long nport_index;
2588 struct lpfc_nodelist *ndlp = NULL;
2589 nport_index = (unsigned long)off /
2590 MAX_STAT_DATA_SIZE_PER_TARGET;
2591
2592 if (!vport->stat_data_enabled || vport->stat_data_blocked
2593 || (phba->bucket_type == LPFC_NO_BUCKET))
2594 return 0;
2595
2596 spin_lock_irq(shost->host_lock);
2597 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2598 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2599 continue;
2600
2601 if (nport_index > 0) {
2602 nport_index--;
2603 continue;
2604 }
2605
2606 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2607 > count)
2608 break;
2609
2610 if (!ndlp->lat_data)
2611 continue;
2612
2613 /* Print the WWN */
2614 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2615 ndlp->nlp_portname.u.wwn[0],
2616 ndlp->nlp_portname.u.wwn[1],
2617 ndlp->nlp_portname.u.wwn[2],
2618 ndlp->nlp_portname.u.wwn[3],
2619 ndlp->nlp_portname.u.wwn[4],
2620 ndlp->nlp_portname.u.wwn[5],
2621 ndlp->nlp_portname.u.wwn[6],
2622 ndlp->nlp_portname.u.wwn[7]);
2623
2624 index = strlen(buf);
2625
2626 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2627 sprintf(&buf[index], "%010u,",
2628 ndlp->lat_data[i].cmd_count);
2629 index = strlen(buf);
2630 }
2631 sprintf(&buf[index], "\n");
2632 index = strlen(buf);
2633 }
2634 spin_unlock_irq(shost->host_lock);
2635 return index;
2636}
2637
2638static struct bin_attribute sysfs_drvr_stat_data_attr = {
2639 .attr = {
2640 .name = "lpfc_drvr_stat_data",
2641 .mode = S_IRUSR,
2642 .owner = THIS_MODULE,
2643 },
2644 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2645 .read = sysfs_drvr_stat_data_read,
2646 .write = NULL,
2647};
2648
dea31012005-04-17 16:05:31 -05002649/*
2650# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2651# connection.
2652# 0 = auto select (default)
2653# 1 = 1 Gigabaud
2654# 2 = 2 Gigabaud
2655# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04002656# 8 = 8 Gigabaud
2657# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05002658*/
James Smarte59058c2008-08-24 21:49:00 -04002659
2660/**
James Smart3621a712009-04-06 18:47:14 -04002661 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002662 * @phba: lpfc_hba pointer.
2663 * @val: link speed value.
2664 *
2665 * Description:
2666 * If val is in a valid range then set the adapter's link speed field and
2667 * issue a lip; if the lip fails reset the link speed to the old value.
2668 *
2669 * Notes:
2670 * If the value is not in range log a kernel error message and return an error.
2671 *
2672 * Returns:
2673 * zero if val is in range and lip okay.
2674 * non-zero return value from lpfc_issue_lip()
2675 * -EINVAL val out of range
2676 **/
James Smarta257bf92009-04-06 18:48:10 -04002677static ssize_t
2678lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2679 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05002680{
James Smarta257bf92009-04-06 18:48:10 -04002681 struct Scsi_Host *shost = class_to_shost(dev);
2682 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2683 struct lpfc_hba *phba = vport->phba;
2684 int val = 0;
2685 int nolip = 0;
2686 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05002687 int err;
2688 uint32_t prev_val;
2689
James Smarta257bf92009-04-06 18:48:10 -04002690 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2691 nolip = 1;
2692 val_buf = &buf[strlen("nolip ")];
2693 }
2694
2695 if (!isdigit(val_buf[0]))
2696 return -EINVAL;
2697 if (sscanf(val_buf, "%i", &val) != 1)
2698 return -EINVAL;
2699
James Smart83108bd2008-01-11 01:53:09 -05002700 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2701 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2702 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2703 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2704 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2705 return -EINVAL;
2706
James Smarta257bf92009-04-06 18:48:10 -04002707 if ((val >= 0 && val <= 8)
James Smart83108bd2008-01-11 01:53:09 -05002708 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2709 prev_val = phba->cfg_link_speed;
2710 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04002711 if (nolip)
2712 return strlen(buf);
2713
James Smart83108bd2008-01-11 01:53:09 -05002714 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04002715 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05002716 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04002717 return -EINVAL;
2718 } else
2719 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05002720 }
2721
2722 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2723 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2724 "allowed range is [0, 8]\n",
2725 phba->brd_no, val);
2726 return -EINVAL;
2727}
2728
2729static int lpfc_link_speed = 0;
2730module_param(lpfc_link_speed, int, 0);
2731MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2732lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002733
2734/**
James Smart3621a712009-04-06 18:47:14 -04002735 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04002736 * @phba: lpfc_hba pointer.
2737 * @val: link speed value.
2738 *
2739 * Description:
2740 * If val is in a valid range then set the adapter's link speed field.
2741 *
2742 * Notes:
2743 * If the value is not in range log a kernel error message, clear the link
2744 * speed and return an error.
2745 *
2746 * Returns:
2747 * zero if val saved.
2748 * -EINVAL val out of range
2749 **/
James Smart83108bd2008-01-11 01:53:09 -05002750static int
2751lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2752{
2753 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2754 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2755 phba->cfg_link_speed = val;
2756 return 0;
2757 }
2758 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002759 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002760 "be set to %d, allowed values are "
2761 "["LPFC_LINK_SPEED_STRING"]\n", val);
2762 phba->cfg_link_speed = 0;
2763 return -EINVAL;
2764}
2765
Tony Jonesee959b02008-02-22 00:13:36 +01002766static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002767 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002768
2769/*
James Smart0d878412009-10-02 15:16:56 -04002770# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2771# 0 = aer disabled or not supported
2772# 1 = aer supported and enabled (default)
2773# Value range is [0,1]. Default value is 1.
2774*/
2775
2776/**
2777 * lpfc_aer_support_store - Set the adapter for aer support
2778 *
2779 * @dev: class device that is converted into a Scsi_host.
2780 * @attr: device attribute, not used.
2781 * @buf: containing the string "selective".
2782 * @count: unused variable.
2783 *
2784 * Description:
2785 * If the val is 1 and currently the device's AER capability was not
2786 * enabled, invoke the kernel's enable AER helper routine, trying to
2787 * enable the device's AER capability. If the helper routine enabling
2788 * AER returns success, update the device's cfg_aer_support flag to
2789 * indicate AER is supported by the device; otherwise, if the device
2790 * AER capability is already enabled to support AER, then do nothing.
2791 *
2792 * If the val is 0 and currently the device's AER support was enabled,
2793 * invoke the kernel's disable AER helper routine. After that, update
2794 * the device's cfg_aer_support flag to indicate AER is not supported
2795 * by the device; otherwise, if the device AER capability is already
2796 * disabled from supporting AER, then do nothing.
2797 *
2798 * Returns:
2799 * length of the buf on success if val is in range the intended mode
2800 * is supported.
2801 * -EINVAL if val out of range or intended mode is not supported.
2802 **/
2803static ssize_t
2804lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
2805 const char *buf, size_t count)
2806{
2807 struct Scsi_Host *shost = class_to_shost(dev);
2808 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
2809 struct lpfc_hba *phba = vport->phba;
2810 int val = 0, rc = -EINVAL;
2811
2812 if (!isdigit(buf[0]))
2813 return -EINVAL;
2814 if (sscanf(buf, "%i", &val) != 1)
2815 return -EINVAL;
2816
2817 switch (val) {
2818 case 0:
2819 if (phba->hba_flag & HBA_AER_ENABLED) {
2820 rc = pci_disable_pcie_error_reporting(phba->pcidev);
2821 if (!rc) {
2822 spin_lock_irq(&phba->hbalock);
2823 phba->hba_flag &= ~HBA_AER_ENABLED;
2824 spin_unlock_irq(&phba->hbalock);
2825 phba->cfg_aer_support = 0;
2826 rc = strlen(buf);
2827 } else
2828 rc = -EINVAL;
2829 } else
2830 phba->cfg_aer_support = 0;
2831 rc = strlen(buf);
2832 break;
2833 case 1:
2834 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
2835 rc = pci_enable_pcie_error_reporting(phba->pcidev);
2836 if (!rc) {
2837 spin_lock_irq(&phba->hbalock);
2838 phba->hba_flag |= HBA_AER_ENABLED;
2839 spin_unlock_irq(&phba->hbalock);
2840 phba->cfg_aer_support = 1;
2841 rc = strlen(buf);
2842 } else
2843 rc = -EINVAL;
2844 } else
2845 phba->cfg_aer_support = 1;
2846 rc = strlen(buf);
2847 break;
2848 default:
2849 rc = -EINVAL;
2850 break;
2851 }
2852 return rc;
2853}
2854
2855static int lpfc_aer_support = 1;
2856module_param(lpfc_aer_support, int, 1);
2857MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
2858lpfc_param_show(aer_support)
2859
2860/**
2861 * lpfc_aer_support_init - Set the initial adapters aer support flag
2862 * @phba: lpfc_hba pointer.
2863 * @val: link speed value.
2864 *
2865 * Description:
2866 * If val is in a valid range [0,1], then set the adapter's initial
2867 * cfg_aer_support field. It will be up to the driver's probe_one
2868 * routine to determine whether the device's AER support can be set
2869 * or not.
2870 *
2871 * Notes:
2872 * If the value is not in range log a kernel error message, and
2873 * choose the default value of setting AER support and return.
2874 *
2875 * Returns:
2876 * zero if val saved.
2877 * -EINVAL val out of range
2878 **/
2879static int
2880lpfc_aer_support_init(struct lpfc_hba *phba, int val)
2881{
2882 if (val == 0 || val == 1) {
2883 phba->cfg_aer_support = val;
2884 return 0;
2885 }
2886 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2887 "2712 lpfc_aer_support attribute value %d out "
2888 "of range, allowed values are 0|1, setting it "
2889 "to default value of 1\n", val);
2890 phba->cfg_aer_support = 1;
2891 return -EINVAL;
2892}
2893
2894static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
2895 lpfc_aer_support_show, lpfc_aer_support_store);
2896
2897/**
2898 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
2899 * @dev: class device that is converted into a Scsi_host.
2900 * @attr: device attribute, not used.
2901 * @buf: containing the string "selective".
2902 * @count: unused variable.
2903 *
2904 * Description:
2905 * If the @buf contains 1 and the device currently has the AER support
2906 * enabled, then invokes the kernel AER helper routine
2907 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
2908 * error status register.
2909 *
2910 * Notes:
2911 *
2912 * Returns:
2913 * -EINVAL if the buf does not contain the 1 or the device is not currently
2914 * enabled with the AER support.
2915 **/
2916static ssize_t
2917lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
2918 const char *buf, size_t count)
2919{
2920 struct Scsi_Host *shost = class_to_shost(dev);
2921 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2922 struct lpfc_hba *phba = vport->phba;
2923 int val, rc = -1;
2924
2925 if (!isdigit(buf[0]))
2926 return -EINVAL;
2927 if (sscanf(buf, "%i", &val) != 1)
2928 return -EINVAL;
2929
2930 if (val == 1 && phba->hba_flag & HBA_AER_ENABLED)
2931 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
2932
2933 if (rc == 0)
2934 return strlen(buf);
2935 else
2936 return -EINVAL;
2937}
2938
2939static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
2940 lpfc_aer_cleanup_state);
2941
2942/*
dea31012005-04-17 16:05:31 -05002943# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
2944# Value range is [2,3]. Default value is 3.
2945*/
James Smart3de2a652007-08-02 11:09:59 -04002946LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
2947 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05002948
2949/*
2950# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
2951# is [0,1]. Default value is 0.
2952*/
James Smart3de2a652007-08-02 11:09:59 -04002953LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
2954 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05002955
2956/*
James Smart977b5a02008-09-07 11:52:04 -04002957# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
2958# depth. Default value is 0. When the value of this parameter is zero the
2959# SCSI command completion time is not used for controlling I/O queue depth. When
2960# the parameter is set to a non-zero value, the I/O queue depth is controlled
2961# to limit the I/O completion time to the parameter value.
2962# The value is set in milliseconds.
2963*/
2964static int lpfc_max_scsicmpl_time;
2965module_param(lpfc_max_scsicmpl_time, int, 0);
2966MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
2967 "Use command completion time to control queue depth");
2968lpfc_vport_param_show(max_scsicmpl_time);
2969lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
2970static int
2971lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
2972{
2973 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2974 struct lpfc_nodelist *ndlp, *next_ndlp;
2975
2976 if (val == vport->cfg_max_scsicmpl_time)
2977 return 0;
2978 if ((val < 0) || (val > 60000))
2979 return -EINVAL;
2980 vport->cfg_max_scsicmpl_time = val;
2981
2982 spin_lock_irq(shost->host_lock);
2983 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2984 if (!NLP_CHK_NODE_ACT(ndlp))
2985 continue;
2986 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2987 continue;
2988 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
2989 }
2990 spin_unlock_irq(shost->host_lock);
2991 return 0;
2992}
2993lpfc_vport_param_store(max_scsicmpl_time);
2994static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
2995 lpfc_max_scsicmpl_time_show,
2996 lpfc_max_scsicmpl_time_store);
2997
2998/*
dea31012005-04-17 16:05:31 -05002999# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3000# range is [0,1]. Default value is 0.
3001*/
3002LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3003
3004/*
3005# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3006# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04003007# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05003008# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3009# cr_delay is set to 0.
3010*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003011LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05003012 "interrupt response is generated");
3013
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05003014LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05003015 "interrupt response is generated");
3016
3017/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003018# lpfc_multi_ring_support: Determines how many rings to spread available
3019# cmd/rsp IOCB entries across.
3020# Value range is [1,2]. Default value is 1.
3021*/
3022LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3023 "SLI rings to spread IOCB entries across");
3024
3025/*
James Smarta4bc3372006-12-02 13:34:16 -05003026# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3027# identifies what rctl value to configure the additional ring for.
3028# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3029*/
James Smart6a9c52c2009-10-02 15:16:51 -04003030LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003031 255, "Identifies RCTL for additional ring configuration");
3032
3033/*
3034# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3035# identifies what type value to configure the additional ring for.
3036# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3037*/
James Smart6a9c52c2009-10-02 15:16:51 -04003038LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05003039 255, "Identifies TYPE for additional ring configuration");
3040
3041/*
dea31012005-04-17 16:05:31 -05003042# lpfc_fdmi_on: controls FDMI support.
3043# 0 = no FDMI support
3044# 1 = support FDMI without attribute of hostname
3045# 2 = support FDMI with attribute of hostname
3046# Value range [0,2]. Default value is 0.
3047*/
James Smart3de2a652007-08-02 11:09:59 -04003048LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05003049
3050/*
3051# Specifies the maximum number of ELS cmds we can have outstanding (for
3052# discovery). Value range is [1,64]. Default value = 32.
3053*/
James Smart3de2a652007-08-02 11:09:59 -04003054LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05003055 "during discovery");
3056
3057/*
James Smart65a29c12006-07-06 15:50:50 -04003058# lpfc_max_luns: maximum allowed LUN.
3059# Value range is [0,65535]. Default value is 255.
3060# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05003061*/
James Smart3de2a652007-08-02 11:09:59 -04003062LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05003063
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003064/*
3065# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3066# Value range is [1,255], default value is 10.
3067*/
3068LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3069 "Milliseconds driver will wait between polling FCP ring");
3070
James Smart4ff43242006-12-02 13:34:56 -05003071/*
3072# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3073# support this feature
James Smartda0436e2009-05-22 14:51:39 -04003074# 0 = MSI disabled (default)
James Smart4ff43242006-12-02 13:34:56 -05003075# 1 = MSI enabled
James Smartda0436e2009-05-22 14:51:39 -04003076# 2 = MSI-X enabled
3077# Value range is [0,2]. Default value is 0.
James Smart4ff43242006-12-02 13:34:56 -05003078*/
James Smartda0436e2009-05-22 14:51:39 -04003079LPFC_ATTR_R(use_msi, 0, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05003080 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05003081
James Smart13815c82008-01-11 01:52:48 -05003082/*
James Smartda0436e2009-05-22 14:51:39 -04003083# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3084#
3085# Value range is [636,651042]. Default value is 10000.
3086*/
3087LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3088 "Set the maximum number of fast-path FCP interrupts per second");
3089
3090/*
3091# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3092#
3093# Value range is [1,31]. Default value is 4.
3094*/
3095LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3096 "Set the number of fast-path FCP work queues, if possible");
3097
3098/*
3099# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3100#
3101# Value range is [1,7]. Default value is 1.
3102*/
3103LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3104 "Set the number of fast-path FCP event queues, if possible");
3105
3106/*
James Smart13815c82008-01-11 01:52:48 -05003107# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3108# 0 = HBA resets disabled
3109# 1 = HBA resets enabled (default)
3110# Value range is [0,1]. Default value is 1.
3111*/
3112LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04003113
James Smart13815c82008-01-11 01:52:48 -05003114/*
3115# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
3116# 0 = HBA Heartbeat disabled
3117# 1 = HBA Heartbeat enabled (default)
3118# Value range is [0,1]. Default value is 1.
3119*/
3120LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05003121
James Smart83108bd2008-01-11 01:53:09 -05003122/*
James Smart81301a92008-12-04 22:39:46 -05003123# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3124# 0 = BlockGuard disabled (default)
3125# 1 = BlockGuard enabled
3126# Value range is [0,1]. Default value is 0.
3127*/
3128LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3129
James Smart6fb120a2009-05-22 14:52:59 -04003130/*
3131# lpfc_enable_fip: When set, FIP is required to start discovery. If not
3132# set, the driver will add an FCF record manually if the port has no
3133# FCF records available and start discovery.
3134# Value range is [0,1]. Default value is 1 (enabled)
3135*/
3136LPFC_ATTR_RW(enable_fip, 0, 0, 1, "Enable FIP Discovery");
3137
James Smart81301a92008-12-04 22:39:46 -05003138
3139/*
3140# lpfc_prot_mask: i
3141# - Bit mask of host protection capabilities used to register with the
3142# SCSI mid-layer
3143# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3144# - Allows you to ultimately specify which profiles to use
3145# - Default will result in registering capabilities for all profiles.
3146#
3147*/
3148unsigned int lpfc_prot_mask = SHOST_DIX_TYPE0_PROTECTION;
3149
3150module_param(lpfc_prot_mask, uint, 0);
3151MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3152
3153/*
3154# lpfc_prot_guard: i
3155# - Bit mask of protection guard types to register with the SCSI mid-layer
3156# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3157# - Allows you to ultimately specify which profiles to use
3158# - Default will result in registering capabilities for all guard types
3159#
3160*/
3161unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3162module_param(lpfc_prot_guard, byte, 0);
3163MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3164
3165
3166/*
James Smart3621a712009-04-06 18:47:14 -04003167 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart83108bd2008-01-11 01:53:09 -05003168 * This value can be set to values between 64 and 256. The default value is
3169 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3170 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3171 */
3172LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3173 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3174
James Smart81301a92008-12-04 22:39:46 -05003175LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3176 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3177 "Max Protection Scatter Gather Segment Count");
3178
Tony Jonesee959b02008-02-22 00:13:36 +01003179struct device_attribute *lpfc_hba_attrs[] = {
James Smart81301a92008-12-04 22:39:46 -05003180 &dev_attr_bg_info,
3181 &dev_attr_bg_guard_err,
3182 &dev_attr_bg_apptag_err,
3183 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01003184 &dev_attr_info,
3185 &dev_attr_serialnum,
3186 &dev_attr_modeldesc,
3187 &dev_attr_modelname,
3188 &dev_attr_programtype,
3189 &dev_attr_portnum,
3190 &dev_attr_fwrev,
3191 &dev_attr_hdw,
3192 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003193 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003194 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04003195 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01003196 &dev_attr_lpfc_drvr_version,
3197 &dev_attr_lpfc_temp_sensor,
3198 &dev_attr_lpfc_log_verbose,
3199 &dev_attr_lpfc_lun_queue_depth,
3200 &dev_attr_lpfc_hba_queue_depth,
3201 &dev_attr_lpfc_peer_port_login,
3202 &dev_attr_lpfc_nodev_tmo,
3203 &dev_attr_lpfc_devloss_tmo,
James Smart6fb120a2009-05-22 14:52:59 -04003204 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003205 &dev_attr_lpfc_fcp_class,
3206 &dev_attr_lpfc_use_adisc,
3207 &dev_attr_lpfc_ack0,
3208 &dev_attr_lpfc_topology,
3209 &dev_attr_lpfc_scan_down,
3210 &dev_attr_lpfc_link_speed,
3211 &dev_attr_lpfc_cr_delay,
3212 &dev_attr_lpfc_cr_count,
3213 &dev_attr_lpfc_multi_ring_support,
3214 &dev_attr_lpfc_multi_ring_rctl,
3215 &dev_attr_lpfc_multi_ring_type,
3216 &dev_attr_lpfc_fdmi_on,
3217 &dev_attr_lpfc_max_luns,
3218 &dev_attr_lpfc_enable_npiv,
3219 &dev_attr_nport_evt_cnt,
3220 &dev_attr_board_mode,
3221 &dev_attr_max_vpi,
3222 &dev_attr_used_vpi,
3223 &dev_attr_max_rpi,
3224 &dev_attr_used_rpi,
3225 &dev_attr_max_xri,
3226 &dev_attr_used_xri,
3227 &dev_attr_npiv_info,
3228 &dev_attr_issue_reset,
3229 &dev_attr_lpfc_poll,
3230 &dev_attr_lpfc_poll_tmo,
3231 &dev_attr_lpfc_use_msi,
James Smartda0436e2009-05-22 14:51:39 -04003232 &dev_attr_lpfc_fcp_imax,
3233 &dev_attr_lpfc_fcp_wq_count,
3234 &dev_attr_lpfc_fcp_eq_count,
James Smart81301a92008-12-04 22:39:46 -05003235 &dev_attr_lpfc_enable_bg,
Tony Jonesee959b02008-02-22 00:13:36 +01003236 &dev_attr_lpfc_soft_wwnn,
3237 &dev_attr_lpfc_soft_wwpn,
3238 &dev_attr_lpfc_soft_wwn_enable,
3239 &dev_attr_lpfc_enable_hba_reset,
3240 &dev_attr_lpfc_enable_hba_heartbeat,
3241 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04003242 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04003243 &dev_attr_lpfc_stat_data_ctrl,
James Smart81301a92008-12-04 22:39:46 -05003244 &dev_attr_lpfc_prot_sg_seg_cnt,
James Smart0d878412009-10-02 15:16:56 -04003245 &dev_attr_lpfc_aer_support,
3246 &dev_attr_lpfc_aer_state_cleanup,
dea31012005-04-17 16:05:31 -05003247 NULL,
3248};
3249
Tony Jonesee959b02008-02-22 00:13:36 +01003250struct device_attribute *lpfc_vport_attrs[] = {
3251 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01003252 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01003253 &dev_attr_num_discovered_ports,
3254 &dev_attr_lpfc_drvr_version,
3255 &dev_attr_lpfc_log_verbose,
3256 &dev_attr_lpfc_lun_queue_depth,
3257 &dev_attr_lpfc_nodev_tmo,
3258 &dev_attr_lpfc_devloss_tmo,
James Smart6fb120a2009-05-22 14:52:59 -04003259 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01003260 &dev_attr_lpfc_hba_queue_depth,
3261 &dev_attr_lpfc_peer_port_login,
3262 &dev_attr_lpfc_restrict_login,
3263 &dev_attr_lpfc_fcp_class,
3264 &dev_attr_lpfc_use_adisc,
3265 &dev_attr_lpfc_fdmi_on,
3266 &dev_attr_lpfc_max_luns,
3267 &dev_attr_nport_evt_cnt,
3268 &dev_attr_npiv_info,
3269 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04003270 &dev_attr_lpfc_max_scsicmpl_time,
3271 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04003272 &dev_attr_lpfc_static_vport,
James Smart3de2a652007-08-02 11:09:59 -04003273 NULL,
3274};
3275
James Smarte59058c2008-08-24 21:49:00 -04003276/**
James Smart3621a712009-04-06 18:47:14 -04003277 * sysfs_ctlreg_write - Write method for writing to ctlreg
James Smarte59058c2008-08-24 21:49:00 -04003278 * @kobj: kernel kobject that contains the kernel class device.
3279 * @bin_attr: kernel attributes passed to us.
3280 * @buf: contains the data to be written to the adapter IOREG space.
3281 * @off: offset into buffer to beginning of data.
3282 * @count: bytes to transfer.
3283 *
3284 * Description:
3285 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3286 * Uses the adapter io control registers to send buf contents to the adapter.
3287 *
3288 * Returns:
3289 * -ERANGE off and count combo out of range
3290 * -EINVAL off, count or buff address invalid
3291 * -EPERM adapter is offline
3292 * value of count, buf contents written
3293 **/
dea31012005-04-17 16:05:31 -05003294static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003295sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3296 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003297{
3298 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01003299 struct device *dev = container_of(kobj, struct device, kobj);
3300 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003301 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3302 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003303
James Smartf1126682009-06-10 17:22:44 -04003304 if (phba->sli_rev >= LPFC_SLI_REV4)
3305 return -EPERM;
3306
dea31012005-04-17 16:05:31 -05003307 if ((off + count) > FF_REG_AREA_SIZE)
3308 return -ERANGE;
3309
3310 if (count == 0) return 0;
3311
3312 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3313 return -EINVAL;
3314
James Smart2e0fef82007-06-17 19:56:36 -05003315 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003316 return -EPERM;
3317 }
3318
James Smart2e0fef82007-06-17 19:56:36 -05003319 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003320 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3321 writel(*((uint32_t *)(buf + buf_off)),
3322 phba->ctrl_regs_memmap_p + off + buf_off);
3323
James Smart2e0fef82007-06-17 19:56:36 -05003324 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003325
3326 return count;
3327}
3328
James Smarte59058c2008-08-24 21:49:00 -04003329/**
James Smart3621a712009-04-06 18:47:14 -04003330 * sysfs_ctlreg_read - Read method for reading from ctlreg
James Smarte59058c2008-08-24 21:49:00 -04003331 * @kobj: kernel kobject that contains the kernel class device.
3332 * @bin_attr: kernel attributes passed to us.
3333 * @buf: if succesful contains the data from the adapter IOREG space.
3334 * @off: offset into buffer to beginning of data.
3335 * @count: bytes to transfer.
3336 *
3337 * Description:
3338 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3339 * Uses the adapter io control registers to read data into buf.
3340 *
3341 * Returns:
3342 * -ERANGE off and count combo out of range
3343 * -EINVAL off, count or buff address invalid
3344 * value of count, buf contents read
3345 **/
dea31012005-04-17 16:05:31 -05003346static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003347sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3348 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003349{
3350 size_t buf_off;
3351 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01003352 struct device *dev = container_of(kobj, struct device, kobj);
3353 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003354 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3355 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003356
James Smartf1126682009-06-10 17:22:44 -04003357 if (phba->sli_rev >= LPFC_SLI_REV4)
3358 return -EPERM;
3359
dea31012005-04-17 16:05:31 -05003360 if (off > FF_REG_AREA_SIZE)
3361 return -ERANGE;
3362
3363 if ((off + count) > FF_REG_AREA_SIZE)
3364 count = FF_REG_AREA_SIZE - off;
3365
3366 if (count == 0) return 0;
3367
3368 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3369 return -EINVAL;
3370
James Smart2e0fef82007-06-17 19:56:36 -05003371 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003372
3373 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3374 tmp_ptr = (uint32_t *)(buf + buf_off);
3375 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3376 }
3377
James Smart2e0fef82007-06-17 19:56:36 -05003378 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003379
3380 return count;
3381}
3382
3383static struct bin_attribute sysfs_ctlreg_attr = {
3384 .attr = {
3385 .name = "ctlreg",
3386 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003387 },
3388 .size = 256,
3389 .read = sysfs_ctlreg_read,
3390 .write = sysfs_ctlreg_write,
3391};
3392
James Smarte59058c2008-08-24 21:49:00 -04003393/**
James Smart3621a712009-04-06 18:47:14 -04003394 * sysfs_mbox_idle - frees the sysfs mailbox
James Smarte59058c2008-08-24 21:49:00 -04003395 * @phba: lpfc_hba pointer
3396 **/
dea31012005-04-17 16:05:31 -05003397static void
James Smart2e0fef82007-06-17 19:56:36 -05003398sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003399{
3400 phba->sysfs_mbox.state = SMBOX_IDLE;
3401 phba->sysfs_mbox.offset = 0;
3402
3403 if (phba->sysfs_mbox.mbox) {
3404 mempool_free(phba->sysfs_mbox.mbox,
3405 phba->mbox_mem_pool);
3406 phba->sysfs_mbox.mbox = NULL;
3407 }
3408}
3409
James Smarte59058c2008-08-24 21:49:00 -04003410/**
James Smart3621a712009-04-06 18:47:14 -04003411 * sysfs_mbox_write - Write method for writing information via mbox
James Smarte59058c2008-08-24 21:49:00 -04003412 * @kobj: kernel kobject that contains the kernel class device.
3413 * @bin_attr: kernel attributes passed to us.
3414 * @buf: contains the data to be written to sysfs mbox.
3415 * @off: offset into buffer to beginning of data.
3416 * @count: bytes to transfer.
3417 *
3418 * Description:
3419 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3420 * Uses the sysfs mbox to send buf contents to the adapter.
3421 *
3422 * Returns:
3423 * -ERANGE off and count combo out of range
3424 * -EINVAL off, count or buff address invalid
3425 * zero if count is zero
3426 * -EPERM adapter is offline
3427 * -ENOMEM failed to allocate memory for the mail box
3428 * -EAGAIN offset, state or mbox is NULL
3429 * count number of bytes transferred
3430 **/
dea31012005-04-17 16:05:31 -05003431static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003432sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3433 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003434{
Tony Jonesee959b02008-02-22 00:13:36 +01003435 struct device *dev = container_of(kobj, struct device, kobj);
3436 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003437 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3438 struct lpfc_hba *phba = vport->phba;
3439 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003440
3441 if ((count + off) > MAILBOX_CMD_SIZE)
3442 return -ERANGE;
3443
3444 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3445 return -EINVAL;
3446
3447 if (count == 0)
3448 return 0;
3449
3450 if (off == 0) {
3451 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3452 if (!mbox)
3453 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003454 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003455 }
3456
James Smart2e0fef82007-06-17 19:56:36 -05003457 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003458
3459 if (off == 0) {
3460 if (phba->sysfs_mbox.mbox)
3461 mempool_free(mbox, phba->mbox_mem_pool);
3462 else
3463 phba->sysfs_mbox.mbox = mbox;
3464 phba->sysfs_mbox.state = SMBOX_WRITING;
3465 } else {
3466 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3467 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003468 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003469 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003470 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003471 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003472 }
3473 }
3474
James Smart04c68492009-05-22 14:52:52 -04003475 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea31012005-04-17 16:05:31 -05003476 buf, count);
3477
3478 phba->sysfs_mbox.offset = off + count;
3479
James Smart2e0fef82007-06-17 19:56:36 -05003480 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003481
3482 return count;
3483}
3484
James Smarte59058c2008-08-24 21:49:00 -04003485/**
James Smart3621a712009-04-06 18:47:14 -04003486 * sysfs_mbox_read - Read method for reading information via mbox
James Smarte59058c2008-08-24 21:49:00 -04003487 * @kobj: kernel kobject that contains the kernel class device.
3488 * @bin_attr: kernel attributes passed to us.
3489 * @buf: contains the data to be read from sysfs mbox.
3490 * @off: offset into buffer to beginning of data.
3491 * @count: bytes to transfer.
3492 *
3493 * Description:
3494 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3495 * Uses the sysfs mbox to receive data from to the adapter.
3496 *
3497 * Returns:
3498 * -ERANGE off greater than mailbox command size
3499 * -EINVAL off, count or buff address invalid
3500 * zero if off and count are zero
3501 * -EACCES adapter over temp
3502 * -EPERM garbage can value to catch a multitude of errors
3503 * -EAGAIN management IO not permitted, state or off error
3504 * -ETIME mailbox timeout
3505 * -ENODEV mailbox error
3506 * count number of bytes transferred
3507 **/
dea31012005-04-17 16:05:31 -05003508static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003509sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3510 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003511{
Tony Jonesee959b02008-02-22 00:13:36 +01003512 struct device *dev = container_of(kobj, struct device, kobj);
3513 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003514 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3515 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003516 int rc;
James Smart04c68492009-05-22 14:52:52 -04003517 MAILBOX_t *pmb;
dea31012005-04-17 16:05:31 -05003518
James Smart1dcb58e2007-04-25 09:51:30 -04003519 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003520 return -ERANGE;
3521
James Smart1dcb58e2007-04-25 09:51:30 -04003522 if ((count + off) > MAILBOX_CMD_SIZE)
3523 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003524
3525 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3526 return -EINVAL;
3527
3528 if (off && count == 0)
3529 return 0;
3530
James Smart2e0fef82007-06-17 19:56:36 -05003531 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003532
James Smart7af67052007-10-27 13:38:11 -04003533 if (phba->over_temp_state == HBA_OVER_TEMP) {
3534 sysfs_mbox_idle(phba);
3535 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003536 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003537 }
3538
dea31012005-04-17 16:05:31 -05003539 if (off == 0 &&
3540 phba->sysfs_mbox.state == SMBOX_WRITING &&
3541 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
James Smart04c68492009-05-22 14:52:52 -04003542 pmb = &phba->sysfs_mbox.mbox->u.mb;
3543 switch (pmb->mbxCommand) {
dea31012005-04-17 16:05:31 -05003544 /* Offline only */
dea31012005-04-17 16:05:31 -05003545 case MBX_INIT_LINK:
3546 case MBX_DOWN_LINK:
3547 case MBX_CONFIG_LINK:
3548 case MBX_CONFIG_RING:
3549 case MBX_RESET_RING:
3550 case MBX_UNREG_LOGIN:
3551 case MBX_CLEAR_LA:
3552 case MBX_DUMP_CONTEXT:
3553 case MBX_RUN_DIAGS:
3554 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003555 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003556 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003557 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003558 printk(KERN_WARNING "mbox_read:Command 0x%x "
3559 "is illegal in on-line state\n",
James Smart04c68492009-05-22 14:52:52 -04003560 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003561 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003562 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003563 return -EPERM;
3564 }
James Smarta8adb832007-10-27 13:37:53 -04003565 case MBX_WRITE_NV:
3566 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003567 case MBX_LOAD_SM:
3568 case MBX_READ_NV:
3569 case MBX_READ_CONFIG:
3570 case MBX_READ_RCONFIG:
3571 case MBX_READ_STATUS:
3572 case MBX_READ_XRI:
3573 case MBX_READ_REV:
3574 case MBX_READ_LNK_STAT:
3575 case MBX_DUMP_MEMORY:
3576 case MBX_DOWN_LOAD:
3577 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003578 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003579 case MBX_LOAD_AREA:
3580 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003581 case MBX_BEACON:
3582 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003583 case MBX_SET_VARIABLE:
3584 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003585 case MBX_PORT_CAPABILITIES:
3586 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003587 break;
3588 case MBX_READ_SPARM64:
3589 case MBX_READ_LA:
3590 case MBX_READ_LA64:
3591 case MBX_REG_LOGIN:
3592 case MBX_REG_LOGIN64:
3593 case MBX_CONFIG_PORT:
3594 case MBX_RUN_BIU_DIAG:
3595 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003596 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003597 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003598 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003599 return -EPERM;
3600 default:
3601 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
James Smart04c68492009-05-22 14:52:52 -04003602 pmb->mbxCommand);
dea31012005-04-17 16:05:31 -05003603 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003604 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003605 return -EPERM;
3606 }
3607
James Smart09372822008-01-11 01:52:54 -05003608 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003609 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003610 */
James Smartd7c255b2008-08-24 21:50:00 -04003611 if (phba->pport->stopped &&
James Smart04c68492009-05-22 14:52:52 -04003612 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3613 pmb->mbxCommand != MBX_RESTART &&
3614 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3615 pmb->mbxCommand != MBX_WRITE_WWN)
James Smartd7c255b2008-08-24 21:50:00 -04003616 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3617 "1259 mbox: Issued mailbox cmd "
3618 "0x%x while in stopped state.\n",
James Smart04c68492009-05-22 14:52:52 -04003619 pmb->mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003620
James Smart92d7f7b2007-06-17 19:56:38 -05003621 phba->sysfs_mbox.mbox->vport = vport;
3622
James Smart58da1ff2008-04-07 10:15:56 -04003623 /* Don't allow mailbox commands to be sent when blocked
3624 * or when in the middle of discovery
3625 */
James Smart495a7142008-06-14 22:52:59 -04003626 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003627 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003628 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003629 return -EAGAIN;
3630 }
3631
James Smart2e0fef82007-06-17 19:56:36 -05003632 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003633 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea31012005-04-17 16:05:31 -05003634
James Smart2e0fef82007-06-17 19:56:36 -05003635 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003636 rc = lpfc_sli_issue_mbox (phba,
3637 phba->sysfs_mbox.mbox,
3638 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003639 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003640
3641 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003642 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003643 rc = lpfc_sli_issue_mbox_wait (phba,
3644 phba->sysfs_mbox.mbox,
James Smart04c68492009-05-22 14:52:52 -04003645 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003646 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003647 }
3648
3649 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003650 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003651 phba->sysfs_mbox.mbox = NULL;
3652 }
dea31012005-04-17 16:05:31 -05003653 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003654 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003655 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003656 }
3657 phba->sysfs_mbox.state = SMBOX_READING;
3658 }
3659 else if (phba->sysfs_mbox.offset != off ||
3660 phba->sysfs_mbox.state != SMBOX_READING) {
3661 printk(KERN_WARNING "mbox_read: Bad State\n");
3662 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003663 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003664 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003665 }
3666
James Smart04c68492009-05-22 14:52:52 -04003667 memcpy(buf, (uint8_t *) &pmb + off, count);
dea31012005-04-17 16:05:31 -05003668
3669 phba->sysfs_mbox.offset = off + count;
3670
James Smart1dcb58e2007-04-25 09:51:30 -04003671 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003672 sysfs_mbox_idle(phba);
3673
James Smart2e0fef82007-06-17 19:56:36 -05003674 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003675
3676 return count;
3677}
3678
3679static struct bin_attribute sysfs_mbox_attr = {
3680 .attr = {
3681 .name = "mbox",
3682 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003683 },
James Smart1dcb58e2007-04-25 09:51:30 -04003684 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05003685 .read = sysfs_mbox_read,
3686 .write = sysfs_mbox_write,
3687};
3688
James Smarte59058c2008-08-24 21:49:00 -04003689/**
James Smart3621a712009-04-06 18:47:14 -04003690 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003691 * @vport: address of lpfc vport structure.
3692 *
3693 * Return codes:
3694 * zero on success
3695 * error return code from sysfs_create_bin_file()
3696 **/
dea31012005-04-17 16:05:31 -05003697int
James Smart2e0fef82007-06-17 19:56:36 -05003698lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003699{
James Smart2e0fef82007-06-17 19:56:36 -05003700 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003701 int error;
3702
Tony Jonesee959b02008-02-22 00:13:36 +01003703 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05003704 &sysfs_drvr_stat_data_attr);
3705
3706 /* Virtual ports do not need ctrl_reg and mbox */
3707 if (error || vport->port_type == LPFC_NPIV_PORT)
3708 goto out;
3709
3710 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003711 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003712 if (error)
James Smarteada2722008-12-04 22:39:13 -05003713 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05003714
Tony Jonesee959b02008-02-22 00:13:36 +01003715 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003716 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05003717 if (error)
3718 goto out_remove_ctlreg_attr;
3719
3720 return 0;
3721out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01003722 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05003723out_remove_stat_attr:
3724 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3725 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05003726out:
3727 return error;
3728}
3729
James Smarte59058c2008-08-24 21:49:00 -04003730/**
James Smart3621a712009-04-06 18:47:14 -04003731 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04003732 * @vport: address of lpfc vport structure.
3733 **/
dea31012005-04-17 16:05:31 -05003734void
James Smart2e0fef82007-06-17 19:56:36 -05003735lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003736{
James Smart2e0fef82007-06-17 19:56:36 -05003737 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04003738 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3739 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05003740 /* Virtual ports do not need ctrl_reg and mbox */
3741 if (vport->port_type == LPFC_NPIV_PORT)
3742 return;
Tony Jonesee959b02008-02-22 00:13:36 +01003743 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3744 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003745}
3746
3747
3748/*
3749 * Dynamic FC Host Attributes Support
3750 */
3751
James Smarte59058c2008-08-24 21:49:00 -04003752/**
James Smart3621a712009-04-06 18:47:14 -04003753 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04003754 * @shost: kernel scsi host pointer.
3755 **/
dea31012005-04-17 16:05:31 -05003756static void
3757lpfc_get_host_port_id(struct Scsi_Host *shost)
3758{
James Smart2e0fef82007-06-17 19:56:36 -05003759 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3760
dea31012005-04-17 16:05:31 -05003761 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05003762 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05003763}
3764
James Smarte59058c2008-08-24 21:49:00 -04003765/**
James Smart3621a712009-04-06 18:47:14 -04003766 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04003767 * @shost: kernel scsi host pointer.
3768 **/
dea31012005-04-17 16:05:31 -05003769static void
3770lpfc_get_host_port_type(struct Scsi_Host *shost)
3771{
James Smart2e0fef82007-06-17 19:56:36 -05003772 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3773 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003774
3775 spin_lock_irq(shost->host_lock);
3776
James Smart92d7f7b2007-06-17 19:56:38 -05003777 if (vport->port_type == LPFC_NPIV_PORT) {
3778 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3779 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003780 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05003781 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05003782 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3783 else
3784 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3785 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003786 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05003787 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3788 else
3789 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3790 }
3791 } else
3792 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3793
3794 spin_unlock_irq(shost->host_lock);
3795}
3796
James Smarte59058c2008-08-24 21:49:00 -04003797/**
James Smart3621a712009-04-06 18:47:14 -04003798 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04003799 * @shost: kernel scsi host pointer.
3800 **/
dea31012005-04-17 16:05:31 -05003801static void
3802lpfc_get_host_port_state(struct Scsi_Host *shost)
3803{
James Smart2e0fef82007-06-17 19:56:36 -05003804 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3805 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003806
3807 spin_lock_irq(shost->host_lock);
3808
James Smart2e0fef82007-06-17 19:56:36 -05003809 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05003810 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3811 else {
James Smart2e0fef82007-06-17 19:56:36 -05003812 switch (phba->link_state) {
3813 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05003814 case LPFC_LINK_DOWN:
3815 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3816 break;
3817 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05003818 case LPFC_CLEAR_LA:
3819 case LPFC_HBA_READY:
3820 /* Links up, beyond this port_type reports state */
3821 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3822 break;
3823 case LPFC_HBA_ERROR:
3824 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3825 break;
3826 default:
3827 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3828 break;
3829 }
3830 }
3831
3832 spin_unlock_irq(shost->host_lock);
3833}
3834
James Smarte59058c2008-08-24 21:49:00 -04003835/**
James Smart3621a712009-04-06 18:47:14 -04003836 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04003837 * @shost: kernel scsi host pointer.
3838 **/
dea31012005-04-17 16:05:31 -05003839static void
3840lpfc_get_host_speed(struct Scsi_Host *shost)
3841{
James Smart2e0fef82007-06-17 19:56:36 -05003842 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3843 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003844
3845 spin_lock_irq(shost->host_lock);
3846
James Smart2e0fef82007-06-17 19:56:36 -05003847 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003848 switch(phba->fc_linkspeed) {
3849 case LA_1GHZ_LINK:
3850 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
3851 break;
3852 case LA_2GHZ_LINK:
3853 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
3854 break;
3855 case LA_4GHZ_LINK:
3856 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
3857 break;
James Smartb87eab32007-04-25 09:53:28 -04003858 case LA_8GHZ_LINK:
3859 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
3860 break;
James Smartf4b4c682009-05-22 14:53:12 -04003861 case LA_10GHZ_LINK:
3862 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
3863 break;
dea31012005-04-17 16:05:31 -05003864 default:
3865 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3866 break;
3867 }
James Smart09372822008-01-11 01:52:54 -05003868 } else
3869 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05003870
3871 spin_unlock_irq(shost->host_lock);
3872}
3873
James Smarte59058c2008-08-24 21:49:00 -04003874/**
James Smart3621a712009-04-06 18:47:14 -04003875 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04003876 * @shost: kernel scsi host pointer.
3877 **/
dea31012005-04-17 16:05:31 -05003878static void
3879lpfc_get_host_fabric_name (struct Scsi_Host *shost)
3880{
James Smart2e0fef82007-06-17 19:56:36 -05003881 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3882 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003883 u64 node_name;
dea31012005-04-17 16:05:31 -05003884
3885 spin_lock_irq(shost->host_lock);
3886
James Smart2e0fef82007-06-17 19:56:36 -05003887 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05003888 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05003889 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07003890 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05003891 else
3892 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05003893 node_name = 0;
dea31012005-04-17 16:05:31 -05003894
3895 spin_unlock_irq(shost->host_lock);
3896
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003897 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05003898}
3899
James Smarte59058c2008-08-24 21:49:00 -04003900/**
James Smart3621a712009-04-06 18:47:14 -04003901 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04003902 * @shost: kernel scsi host pointer.
3903 *
3904 * Notes:
3905 * NULL on error for link down, no mbox pool, sli2 active,
3906 * management not allowed, memory allocation error, or mbox error.
3907 *
3908 * Returns:
3909 * NULL for error
3910 * address of the adapter host statistics
3911 **/
dea31012005-04-17 16:05:31 -05003912static struct fc_host_statistics *
3913lpfc_get_stats(struct Scsi_Host *shost)
3914{
James Smart2e0fef82007-06-17 19:56:36 -05003915 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3916 struct lpfc_hba *phba = vport->phba;
3917 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003918 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04003919 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05003920 LPFC_MBOXQ_t *pmboxq;
3921 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04003922 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003923 int rc = 0;
dea31012005-04-17 16:05:31 -05003924
James Smart92d7f7b2007-06-17 19:56:38 -05003925 /*
3926 * prevent udev from issuing mailbox commands until the port is
3927 * configured.
3928 */
James Smart2e0fef82007-06-17 19:56:36 -05003929 if (phba->link_state < LPFC_LINK_DOWN ||
3930 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04003931 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003932 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003933
3934 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04003935 return NULL;
3936
dea31012005-04-17 16:05:31 -05003937 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3938 if (!pmboxq)
3939 return NULL;
3940 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3941
James Smart04c68492009-05-22 14:52:52 -04003942 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05003943 pmb->mbxCommand = MBX_READ_STATUS;
3944 pmb->mbxOwner = OWN_HOST;
3945 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003946 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05003947
James Smart2e0fef82007-06-17 19:56:36 -05003948 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart04c68492009-05-22 14:52:52 -04003949 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
dea31012005-04-17 16:05:31 -05003950 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003951 else
dea31012005-04-17 16:05:31 -05003952 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3953
3954 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003955 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003956 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003957 return NULL;
3958 }
3959
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003960 memset(hs, 0, sizeof (struct fc_host_statistics));
3961
dea31012005-04-17 16:05:31 -05003962 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
3963 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
3964 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
3965 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
3966
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003967 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003968 pmb->mbxCommand = MBX_READ_LNK_STAT;
3969 pmb->mbxOwner = OWN_HOST;
3970 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003971 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05003972
James Smart2e0fef82007-06-17 19:56:36 -05003973 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04003974 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
dea31012005-04-17 16:05:31 -05003975 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003976 else
dea31012005-04-17 16:05:31 -05003977 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3978
3979 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003980 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05003981 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003982 return NULL;
3983 }
3984
3985 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3986 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3987 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3988 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3989 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3990 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3991 hs->error_frames = pmb->un.varRdLnk.crcCnt;
3992
James Smart64ba8812006-08-02 15:24:34 -04003993 hs->link_failure_count -= lso->link_failure_count;
3994 hs->loss_of_sync_count -= lso->loss_of_sync_count;
3995 hs->loss_of_signal_count -= lso->loss_of_signal_count;
3996 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
3997 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
3998 hs->invalid_crc_count -= lso->invalid_crc_count;
3999 hs->error_frames -= lso->error_frames;
4000
James Smart4d9ab992009-10-02 15:16:39 -04004001 if (phba->hba_flag & HBA_FCOE_SUPPORT) {
4002 hs->lip_count = -1;
4003 hs->nos_count = (phba->link_events >> 1);
4004 hs->nos_count -= lso->link_events;
4005 } else if (phba->fc_topology == TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004006 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004007 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004008 hs->nos_count = -1;
4009 } else {
4010 hs->lip_count = -1;
4011 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004012 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05004013 }
4014
4015 hs->dumped_frames = -1;
4016
James Smart64ba8812006-08-02 15:24:34 -04004017 seconds = get_seconds();
4018 if (seconds < psli->stats_start)
4019 hs->seconds_since_last_reset = seconds +
4020 ((unsigned long)-1 - psli->stats_start);
4021 else
4022 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05004023
James Smart1dcb58e2007-04-25 09:51:30 -04004024 mempool_free(pmboxq, phba->mbox_mem_pool);
4025
dea31012005-04-17 16:05:31 -05004026 return hs;
4027}
4028
James Smarte59058c2008-08-24 21:49:00 -04004029/**
James Smart3621a712009-04-06 18:47:14 -04004030 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04004031 * @shost: kernel scsi host pointer.
4032 **/
James Smart64ba8812006-08-02 15:24:34 -04004033static void
4034lpfc_reset_stats(struct Scsi_Host *shost)
4035{
James Smart2e0fef82007-06-17 19:56:36 -05004036 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4037 struct lpfc_hba *phba = vport->phba;
4038 struct lpfc_sli *psli = &phba->sli;
4039 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04004040 LPFC_MBOXQ_t *pmboxq;
4041 MAILBOX_t *pmb;
4042 int rc = 0;
4043
James Smart2e0fef82007-06-17 19:56:36 -05004044 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04004045 return;
4046
James Smart64ba8812006-08-02 15:24:34 -04004047 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4048 if (!pmboxq)
4049 return;
4050 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4051
James Smart04c68492009-05-22 14:52:52 -04004052 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04004053 pmb->mbxCommand = MBX_READ_STATUS;
4054 pmb->mbxOwner = OWN_HOST;
4055 pmb->un.varWords[0] = 0x1; /* reset request */
4056 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004057 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004058
James Smart2e0fef82007-06-17 19:56:36 -05004059 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004060 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004061 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4062 else
4063 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4064
4065 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004066 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004067 mempool_free(pmboxq, phba->mbox_mem_pool);
4068 return;
4069 }
4070
4071 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4072 pmb->mbxCommand = MBX_READ_LNK_STAT;
4073 pmb->mbxOwner = OWN_HOST;
4074 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004075 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04004076
James Smart2e0fef82007-06-17 19:56:36 -05004077 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04004078 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04004079 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4080 else
4081 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4082
4083 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05004084 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04004085 mempool_free( pmboxq, phba->mbox_mem_pool);
4086 return;
4087 }
4088
4089 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4090 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4091 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4092 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4093 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4094 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4095 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart4d9ab992009-10-02 15:16:39 -04004096 if (phba->hba_flag & HBA_FCOE_SUPPORT)
4097 lso->link_events = (phba->link_events >> 1);
4098 else
4099 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04004100
4101 psli->stats_start = get_seconds();
4102
James Smart1dcb58e2007-04-25 09:51:30 -04004103 mempool_free(pmboxq, phba->mbox_mem_pool);
4104
James Smart64ba8812006-08-02 15:24:34 -04004105 return;
4106}
dea31012005-04-17 16:05:31 -05004107
4108/*
4109 * The LPFC driver treats linkdown handling as target loss events so there
4110 * are no sysfs handlers for link_down_tmo.
4111 */
James Smart685f0bf2007-04-25 09:53:08 -04004112
James Smarte59058c2008-08-24 21:49:00 -04004113/**
James Smart3621a712009-04-06 18:47:14 -04004114 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04004115 * @starget: kernel scsi target pointer.
4116 *
4117 * Returns:
4118 * address of the node list if found
4119 * NULL target not found
4120 **/
James Smart685f0bf2007-04-25 09:53:08 -04004121static struct lpfc_nodelist *
4122lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05004123{
James Smart2e0fef82007-06-17 19:56:36 -05004124 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4125 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04004126 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004127
4128 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004129 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05004130 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004131 if (NLP_CHK_NODE_ACT(ndlp) &&
4132 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04004133 starget->id == ndlp->nlp_sid) {
4134 spin_unlock_irq(shost->host_lock);
4135 return ndlp;
dea31012005-04-17 16:05:31 -05004136 }
4137 }
4138 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004139 return NULL;
4140}
dea31012005-04-17 16:05:31 -05004141
James Smarte59058c2008-08-24 21:49:00 -04004142/**
James Smart3621a712009-04-06 18:47:14 -04004143 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04004144 * @starget: kernel scsi target pointer.
4145 **/
James Smart685f0bf2007-04-25 09:53:08 -04004146static void
4147lpfc_get_starget_port_id(struct scsi_target *starget)
4148{
4149 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4150
4151 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05004152}
4153
James Smarte59058c2008-08-24 21:49:00 -04004154/**
James Smart3621a712009-04-06 18:47:14 -04004155 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04004156 * @starget: kernel scsi target pointer.
4157 *
4158 * Description: Set the target node name to the ndlp node name wwn or zero.
4159 **/
dea31012005-04-17 16:05:31 -05004160static void
4161lpfc_get_starget_node_name(struct scsi_target *starget)
4162{
James Smart685f0bf2007-04-25 09:53:08 -04004163 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004164
James Smart685f0bf2007-04-25 09:53:08 -04004165 fc_starget_node_name(starget) =
4166 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004167}
4168
James Smarte59058c2008-08-24 21:49:00 -04004169/**
James Smart3621a712009-04-06 18:47:14 -04004170 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04004171 * @starget: kernel scsi target pointer.
4172 *
4173 * Description: set the target port name to the ndlp port name wwn or zero.
4174 **/
dea31012005-04-17 16:05:31 -05004175static void
4176lpfc_get_starget_port_name(struct scsi_target *starget)
4177{
James Smart685f0bf2007-04-25 09:53:08 -04004178 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05004179
James Smart685f0bf2007-04-25 09:53:08 -04004180 fc_starget_port_name(starget) =
4181 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05004182}
4183
James Smarte59058c2008-08-24 21:49:00 -04004184/**
James Smart3621a712009-04-06 18:47:14 -04004185 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04004186 * @rport: fc rport address.
4187 * @timeout: new value for dev loss tmo.
4188 *
4189 * Description:
4190 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4191 * dev_loss_tmo to one.
4192 **/
dea31012005-04-17 16:05:31 -05004193static void
dea31012005-04-17 16:05:31 -05004194lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4195{
dea31012005-04-17 16:05:31 -05004196 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04004197 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05004198 else
James Smartc01f3202006-08-18 17:47:08 -04004199 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05004200}
4201
James Smarte59058c2008-08-24 21:49:00 -04004202/**
James Smart3621a712009-04-06 18:47:14 -04004203 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04004204 *
4205 * Description:
4206 * Macro that uses field to generate a function with the name lpfc_show_rport_
4207 *
4208 * lpfc_show_rport_##field: returns the bytes formatted in buf
4209 * @cdev: class converted to an fc_rport.
4210 * @buf: on return contains the target_field or zero.
4211 *
4212 * Returns: size of formatted string.
4213 **/
dea31012005-04-17 16:05:31 -05004214#define lpfc_rport_show_function(field, format_string, sz, cast) \
4215static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01004216lpfc_show_rport_##field (struct device *dev, \
4217 struct device_attribute *attr, \
4218 char *buf) \
dea31012005-04-17 16:05:31 -05004219{ \
Tony Jonesee959b02008-02-22 00:13:36 +01004220 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05004221 struct lpfc_rport_data *rdata = rport->hostdata; \
4222 return snprintf(buf, sz, format_string, \
4223 (rdata->target) ? cast rdata->target->field : 0); \
4224}
4225
4226#define lpfc_rport_rd_attr(field, format_string, sz) \
4227 lpfc_rport_show_function(field, format_string, sz, ) \
4228static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4229
James Smarteada2722008-12-04 22:39:13 -05004230/**
James Smart3621a712009-04-06 18:47:14 -04004231 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05004232 * @fc_vport: The fc_vport who's symbolic name has been changed.
4233 *
4234 * Description:
4235 * This function is called by the transport after the @fc_vport's symbolic name
4236 * has been changed. This function re-registers the symbolic name with the
4237 * switch to propogate the change into the fabric if the vport is active.
4238 **/
4239static void
4240lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4241{
4242 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4243
4244 if (vport->port_state == LPFC_VPORT_READY)
4245 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4246}
dea31012005-04-17 16:05:31 -05004247
James Smartf4b4c682009-05-22 14:53:12 -04004248/**
4249 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4250 * @phba: Pointer to lpfc_hba struct.
4251 *
4252 * This function is called by the lpfc_get_cfgparam() routine to set the
4253 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4254 * log messsage according to the module's lpfc_log_verbose parameter setting
4255 * before hba port or vport created.
4256 **/
4257static void
4258lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4259{
4260 phba->cfg_log_verbose = verbose;
4261}
4262
dea31012005-04-17 16:05:31 -05004263struct fc_function_template lpfc_transport_functions = {
4264 /* fixed attributes the driver supports */
4265 .show_host_node_name = 1,
4266 .show_host_port_name = 1,
4267 .show_host_supported_classes = 1,
4268 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05004269 .show_host_supported_speeds = 1,
4270 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004271 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05004272
4273 /* dynamic attributes the driver supports */
4274 .get_host_port_id = lpfc_get_host_port_id,
4275 .show_host_port_id = 1,
4276
4277 .get_host_port_type = lpfc_get_host_port_type,
4278 .show_host_port_type = 1,
4279
4280 .get_host_port_state = lpfc_get_host_port_state,
4281 .show_host_port_state = 1,
4282
4283 /* active_fc4s is shown but doesn't change (thus no get function) */
4284 .show_host_active_fc4s = 1,
4285
4286 .get_host_speed = lpfc_get_host_speed,
4287 .show_host_speed = 1,
4288
4289 .get_host_fabric_name = lpfc_get_host_fabric_name,
4290 .show_host_fabric_name = 1,
4291
4292 /*
4293 * The LPFC driver treats linkdown handling as target loss events
4294 * so there are no sysfs handlers for link_down_tmo.
4295 */
4296
4297 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04004298 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05004299
4300 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4301 .show_rport_maxframe_size = 1,
4302 .show_rport_supported_classes = 1,
4303
dea31012005-04-17 16:05:31 -05004304 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4305 .show_rport_dev_loss_tmo = 1,
4306
4307 .get_starget_port_id = lpfc_get_starget_port_id,
4308 .show_starget_port_id = 1,
4309
4310 .get_starget_node_name = lpfc_get_starget_node_name,
4311 .show_starget_node_name = 1,
4312
4313 .get_starget_port_name = lpfc_get_starget_port_name,
4314 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07004315
4316 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04004317 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4318 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05004319
James Smart92d7f7b2007-06-17 19:56:38 -05004320 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05004321
4322 .vport_disable = lpfc_vport_disable,
4323
4324 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04004325
4326 .bsg_request = lpfc_bsg_request,
4327 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05004328};
4329
James Smart98c9ea52007-10-27 13:37:33 -04004330struct fc_function_template lpfc_vport_transport_functions = {
4331 /* fixed attributes the driver supports */
4332 .show_host_node_name = 1,
4333 .show_host_port_name = 1,
4334 .show_host_supported_classes = 1,
4335 .show_host_supported_fc4s = 1,
4336 .show_host_supported_speeds = 1,
4337 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05004338 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04004339
4340 /* dynamic attributes the driver supports */
4341 .get_host_port_id = lpfc_get_host_port_id,
4342 .show_host_port_id = 1,
4343
4344 .get_host_port_type = lpfc_get_host_port_type,
4345 .show_host_port_type = 1,
4346
4347 .get_host_port_state = lpfc_get_host_port_state,
4348 .show_host_port_state = 1,
4349
4350 /* active_fc4s is shown but doesn't change (thus no get function) */
4351 .show_host_active_fc4s = 1,
4352
4353 .get_host_speed = lpfc_get_host_speed,
4354 .show_host_speed = 1,
4355
4356 .get_host_fabric_name = lpfc_get_host_fabric_name,
4357 .show_host_fabric_name = 1,
4358
4359 /*
4360 * The LPFC driver treats linkdown handling as target loss events
4361 * so there are no sysfs handlers for link_down_tmo.
4362 */
4363
4364 .get_fc_host_stats = lpfc_get_stats,
4365 .reset_fc_host_stats = lpfc_reset_stats,
4366
4367 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4368 .show_rport_maxframe_size = 1,
4369 .show_rport_supported_classes = 1,
4370
4371 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4372 .show_rport_dev_loss_tmo = 1,
4373
4374 .get_starget_port_id = lpfc_get_starget_port_id,
4375 .show_starget_port_id = 1,
4376
4377 .get_starget_node_name = lpfc_get_starget_node_name,
4378 .show_starget_node_name = 1,
4379
4380 .get_starget_port_name = lpfc_get_starget_port_name,
4381 .show_starget_port_name = 1,
4382
4383 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4384 .terminate_rport_io = lpfc_terminate_rport_io,
4385
4386 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05004387
4388 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04004389};
4390
James Smarte59058c2008-08-24 21:49:00 -04004391/**
James Smart3621a712009-04-06 18:47:14 -04004392 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04004393 * @phba: lpfc_hba pointer.
4394 **/
dea31012005-04-17 16:05:31 -05004395void
4396lpfc_get_cfgparam(struct lpfc_hba *phba)
4397{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004398 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4399 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004400 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05004401 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4402 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004403 lpfc_ack0_init(phba, lpfc_ack0);
4404 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04004405 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004406 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04004407 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05004408 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartda0436e2009-05-22 14:51:39 -04004409 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4410 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4411 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
James Smart13815c82008-01-11 01:52:48 -05004412 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4413 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart81301a92008-12-04 22:39:46 -05004414 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004415 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05004416 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04004417 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05004418 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart81301a92008-12-04 22:39:46 -05004419 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04004420 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04004421 lpfc_enable_fip_init(phba, lpfc_enable_fip);
4422 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04004423 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart6fb120a2009-05-22 14:52:59 -04004424
James Smart3de2a652007-08-02 11:09:59 -04004425 return;
4426}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05004427
James Smarte59058c2008-08-24 21:49:00 -04004428/**
James Smart3621a712009-04-06 18:47:14 -04004429 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04004430 * @vport: lpfc_vport pointer.
4431 **/
James Smart3de2a652007-08-02 11:09:59 -04004432void
4433lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4434{
James Smarte8b62012007-08-02 11:10:09 -04004435 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04004436 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4437 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4438 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4439 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4440 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4441 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4442 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04004443 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04004444 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4445 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4446 lpfc_max_luns_init(vport, lpfc_max_luns);
4447 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004448 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004449 return;
4450}