blob: 7c015982b40fcd047b37541f8ead9912dd4ba680 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart09372822008-01-11 01:52:54 -05004 * Copyright (C) 2004-2008 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/ctype.h>
James Smart46fa3112007-04-25 09:51:45 -040023#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050024#include <linux/pci.h>
25#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_tcq.h>
31#include <scsi/scsi_transport_fc.h>
32
33#include "lpfc_hw.h"
34#include "lpfc_sli.h"
James Smartea2151b2008-09-07 11:52:10 -040035#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050036#include "lpfc_disc.h"
37#include "lpfc_scsi.h"
38#include "lpfc.h"
39#include "lpfc_logmsg.h"
40#include "lpfc_version.h"
41#include "lpfc_compat.h"
42#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050043#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050044
James Smartc01f3202006-08-18 17:47:08 -040045#define LPFC_DEF_DEVLOSS_TMO 30
46#define LPFC_MIN_DEVLOSS_TMO 1
47#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050048
James Smart83108bd2008-01-11 01:53:09 -050049#define LPFC_MAX_LINK_SPEED 8
50#define LPFC_LINK_SPEED_BITMAP 0x00000117
51#define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
52
James Smarte59058c2008-08-24 21:49:00 -040053/**
54 * lpfc_jedec_to_ascii: Hex to ascii convertor according to JEDEC rules.
55 * @incr: integer to convert.
56 * @hdw: ascii string holding converted integer plus a string terminator.
57 *
58 * Description:
59 * JEDEC Joint Electron Device Engineering Council.
60 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
61 * character string. The string is then terminated with a NULL in byte 9.
62 * Hex 0-9 becomes ascii '0' to '9'.
63 * Hex a-f becomes ascii '=' to 'B' capital B.
64 *
65 * Notes:
66 * Coded for 32 bit integers only.
67 **/
dea31012005-04-17 16:05:31 -050068static void
69lpfc_jedec_to_ascii(int incr, char hdw[])
70{
71 int i, j;
72 for (i = 0; i < 8; i++) {
73 j = (incr & 0xf);
74 if (j <= 9)
75 hdw[7 - i] = 0x30 + j;
76 else
77 hdw[7 - i] = 0x61 + j - 10;
78 incr = (incr >> 4);
79 }
80 hdw[8] = 0;
81 return;
82}
83
James Smarte59058c2008-08-24 21:49:00 -040084/**
85 * lpfc_drvr_version_show: Return the Emulex driver string with version number.
86 * @dev: class unused variable.
87 * @attr: device attribute, not used.
88 * @buf: on return contains the module description text.
89 *
90 * Returns: size of formatted string.
91 **/
dea31012005-04-17 16:05:31 -050092static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +010093lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
94 char *buf)
dea31012005-04-17 16:05:31 -050095{
96 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
97}
98
James Smarte59058c2008-08-24 21:49:00 -040099/**
100 * lpfc_info_show: Return some pci info about the host in ascii.
101 * @dev: class converted to a Scsi_host structure.
102 * @attr: device attribute, not used.
103 * @buf: on return contains the formatted text from lpfc_info().
104 *
105 * Returns: size of formatted string.
106 **/
dea31012005-04-17 16:05:31 -0500107static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100108lpfc_info_show(struct device *dev, struct device_attribute *attr,
109 char *buf)
dea31012005-04-17 16:05:31 -0500110{
Tony Jonesee959b02008-02-22 00:13:36 +0100111 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500112
dea31012005-04-17 16:05:31 -0500113 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
114}
115
James Smarte59058c2008-08-24 21:49:00 -0400116/**
117 * lpfc_serialnum_show: Return the hba serial number in ascii.
118 * @dev: class converted to a Scsi_host structure.
119 * @attr: device attribute, not used.
120 * @buf: on return contains the formatted text serial number.
121 *
122 * Returns: size of formatted string.
123 **/
dea31012005-04-17 16:05:31 -0500124static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100125lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
126 char *buf)
dea31012005-04-17 16:05:31 -0500127{
Tony Jonesee959b02008-02-22 00:13:36 +0100128 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500129 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
130 struct lpfc_hba *phba = vport->phba;
131
dea31012005-04-17 16:05:31 -0500132 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
133}
134
James Smarte59058c2008-08-24 21:49:00 -0400135/**
136 * lpfc_temp_sensor_show: Return the temperature sensor level.
137 * @dev: class converted to a Scsi_host structure.
138 * @attr: device attribute, not used.
139 * @buf: on return contains the formatted support level.
140 *
141 * Description:
142 * Returns a number indicating the temperature sensor level currently
143 * supported, zero or one in ascii.
144 *
145 * Returns: size of formatted string.
146 **/
dea31012005-04-17 16:05:31 -0500147static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100148lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
149 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400150{
Tony Jonesee959b02008-02-22 00:13:36 +0100151 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400152 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
153 struct lpfc_hba *phba = vport->phba;
154 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
155}
156
James Smarte59058c2008-08-24 21:49:00 -0400157/**
158 * lpfc_modeldesc_show: Return the model description of the hba.
159 * @dev: class converted to a Scsi_host structure.
160 * @attr: device attribute, not used.
161 * @buf: on return contains the scsi vpd model description.
162 *
163 * Returns: size of formatted string.
164 **/
James Smart57127f12007-10-27 13:37:05 -0400165static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100166lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
167 char *buf)
dea31012005-04-17 16:05:31 -0500168{
Tony Jonesee959b02008-02-22 00:13:36 +0100169 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500170 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
171 struct lpfc_hba *phba = vport->phba;
172
dea31012005-04-17 16:05:31 -0500173 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
174}
175
James Smarte59058c2008-08-24 21:49:00 -0400176/**
177 * lpfc_modelname_show: Return the model name of the hba.
178 * @dev: class converted to a Scsi_host structure.
179 * @attr: device attribute, not used.
180 * @buf: on return contains the scsi vpd model name.
181 *
182 * Returns: size of formatted string.
183 **/
dea31012005-04-17 16:05:31 -0500184static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100185lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
186 char *buf)
dea31012005-04-17 16:05:31 -0500187{
Tony Jonesee959b02008-02-22 00:13:36 +0100188 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500189 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
190 struct lpfc_hba *phba = vport->phba;
191
dea31012005-04-17 16:05:31 -0500192 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
193}
194
James Smarte59058c2008-08-24 21:49:00 -0400195/**
196 * lpfc_programtype_show: Return the program type of the hba.
197 * @dev: class converted to a Scsi_host structure.
198 * @attr: device attribute, not used.
199 * @buf: on return contains the scsi vpd program type.
200 *
201 * Returns: size of formatted string.
202 **/
dea31012005-04-17 16:05:31 -0500203static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100204lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
205 char *buf)
dea31012005-04-17 16:05:31 -0500206{
Tony Jonesee959b02008-02-22 00:13:36 +0100207 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500208 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
209 struct lpfc_hba *phba = vport->phba;
210
dea31012005-04-17 16:05:31 -0500211 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
212}
213
James Smarte59058c2008-08-24 21:49:00 -0400214/**
James Smart84774a42008-08-24 21:50:06 -0400215 * lpfc_mlomgmt_show: Return the Menlo Maintenance sli flag.
216 * @dev: class converted to a Scsi_host structure.
217 * @attr: device attribute, not used.
218 * @buf: on return contains the Menlo Maintenance sli flag.
219 *
220 * Returns: size of formatted string.
221 **/
222static ssize_t
223lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
224{
225 struct Scsi_Host *shost = class_to_shost(dev);
226 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
227 struct lpfc_hba *phba = vport->phba;
228
229 return snprintf(buf, PAGE_SIZE, "%d\n",
230 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
231}
232
233/**
James Smarte59058c2008-08-24 21:49:00 -0400234 * lpfc_vportnum_show: Return the port number in ascii of the hba.
235 * @dev: class converted to a Scsi_host structure.
236 * @attr: device attribute, not used.
237 * @buf: on return contains scsi vpd program type.
238 *
239 * Returns: size of formatted string.
240 **/
dea31012005-04-17 16:05:31 -0500241static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100242lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
243 char *buf)
dea31012005-04-17 16:05:31 -0500244{
Tony Jonesee959b02008-02-22 00:13:36 +0100245 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500246 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
247 struct lpfc_hba *phba = vport->phba;
248
dea31012005-04-17 16:05:31 -0500249 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
250}
251
James Smarte59058c2008-08-24 21:49:00 -0400252/**
253 * lpfc_fwrev_show: Return the firmware rev running in the hba.
254 * @dev: class converted to a Scsi_host structure.
255 * @attr: device attribute, not used.
256 * @buf: on return contains the scsi vpd program type.
257 *
258 * Returns: size of formatted string.
259 **/
dea31012005-04-17 16:05:31 -0500260static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100261lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
262 char *buf)
dea31012005-04-17 16:05:31 -0500263{
Tony Jonesee959b02008-02-22 00:13:36 +0100264 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500265 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
266 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500267 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500268
dea31012005-04-17 16:05:31 -0500269 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500270 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500271}
272
James Smarte59058c2008-08-24 21:49:00 -0400273/**
274 * lpfc_hdw_show: Return the jedec information about the hba.
275 * @dev: class converted to a Scsi_host structure.
276 * @attr: device attribute, not used.
277 * @buf: on return contains the scsi vpd program type.
278 *
279 * Returns: size of formatted string.
280 **/
dea31012005-04-17 16:05:31 -0500281static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100282lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500283{
284 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100285 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500286 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
287 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500288 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500289
dea31012005-04-17 16:05:31 -0500290 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
291 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
292}
James Smarte59058c2008-08-24 21:49:00 -0400293
294/**
295 * lpfc_option_rom_version_show: Return the adapter ROM FCode version.
296 * @dev: class converted to a Scsi_host structure.
297 * @attr: device attribute, not used.
298 * @buf: on return contains the ROM and FCode ascii strings.
299 *
300 * Returns: size of formatted string.
301 **/
dea31012005-04-17 16:05:31 -0500302static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100303lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
304 char *buf)
dea31012005-04-17 16:05:31 -0500305{
Tony Jonesee959b02008-02-22 00:13:36 +0100306 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500307 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
308 struct lpfc_hba *phba = vport->phba;
309
dea31012005-04-17 16:05:31 -0500310 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
311}
James Smarte59058c2008-08-24 21:49:00 -0400312
313/**
314 * lpfc_state_show: Return the link state of the port.
315 * @dev: class converted to a Scsi_host structure.
316 * @attr: device attribute, not used.
317 * @buf: on return contains text describing the state of the link.
318 *
319 * Notes:
320 * The switch statement has no default so zero will be returned.
321 *
322 * Returns: size of formatted string.
323 **/
dea31012005-04-17 16:05:31 -0500324static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100325lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
326 char *buf)
dea31012005-04-17 16:05:31 -0500327{
Tony Jonesee959b02008-02-22 00:13:36 +0100328 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500329 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
330 struct lpfc_hba *phba = vport->phba;
331 int len = 0;
332
333 switch (phba->link_state) {
334 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500335 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500336 case LPFC_INIT_START:
337 case LPFC_INIT_MBX_CMDS:
338 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500339 case LPFC_HBA_ERROR:
dea31012005-04-17 16:05:31 -0500340 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
341 break;
342 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500343 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500344 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400345 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500346
347 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500348 case LPFC_LOCAL_CFG_LINK:
349 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500350 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500351 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500352 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500353 case LPFC_FLOGI:
354 case LPFC_FABRIC_CFG_LINK:
355 case LPFC_NS_REG:
356 case LPFC_NS_QRY:
357 case LPFC_BUILD_DISC_LIST:
358 case LPFC_DISC_AUTH:
359 len += snprintf(buf + len, PAGE_SIZE - len,
360 "Discovery\n");
361 break;
362 case LPFC_VPORT_READY:
363 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
364 break;
365
James Smart92d7f7b2007-06-17 19:56:38 -0500366 case LPFC_VPORT_FAILED:
367 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
368 break;
369
370 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500371 len += snprintf(buf + len, PAGE_SIZE - len,
372 "Unknown\n");
373 break;
374 }
James Smart84774a42008-08-24 21:50:06 -0400375 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
376 len += snprintf(buf + len, PAGE_SIZE-len,
377 " Menlo Maint Mode\n");
378 else if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500379 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500380 len += snprintf(buf + len, PAGE_SIZE-len,
381 " Public Loop\n");
382 else
383 len += snprintf(buf + len, PAGE_SIZE-len,
384 " Private Loop\n");
385 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500386 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500387 len += snprintf(buf + len, PAGE_SIZE-len,
388 " Fabric\n");
389 else
390 len += snprintf(buf + len, PAGE_SIZE-len,
391 " Point-2-Point\n");
392 }
393 }
James Smart2e0fef82007-06-17 19:56:36 -0500394
dea31012005-04-17 16:05:31 -0500395 return len;
396}
397
James Smarte59058c2008-08-24 21:49:00 -0400398/**
399 * lpfc_num_discovered_ports_show: Return sum of mapped and unmapped vports.
400 * @dev: class device that is converted into a Scsi_host.
401 * @attr: device attribute, not used.
402 * @buf: on return contains the sum of fc mapped and unmapped.
403 *
404 * Description:
405 * Returns the ascii text number of the sum of the fc mapped and unmapped
406 * vport counts.
407 *
408 * Returns: size of formatted string.
409 **/
dea31012005-04-17 16:05:31 -0500410static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100411lpfc_num_discovered_ports_show(struct device *dev,
412 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500413{
Tony Jonesee959b02008-02-22 00:13:36 +0100414 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500415 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
416
417 return snprintf(buf, PAGE_SIZE, "%d\n",
418 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500419}
420
James Smarte59058c2008-08-24 21:49:00 -0400421/**
422 * lpfc_issue_lip: Misnomer, name carried over from long ago.
423 * @shost: Scsi_Host pointer.
424 *
425 * Description:
426 * Bring the link down gracefully then re-init the link. The firmware will
427 * re-init the fiber channel interface as required. Does not issue a LIP.
428 *
429 * Returns:
430 * -EPERM port offline or management commands are being blocked
431 * -ENOMEM cannot allocate memory for the mailbox command
432 * -EIO error sending the mailbox command
433 * zero for success
434 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700435static int
James Smart2e0fef82007-06-17 19:56:36 -0500436lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500437{
James Smart2e0fef82007-06-17 19:56:36 -0500438 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
439 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500440 LPFC_MBOXQ_t *pmboxq;
441 int mbxstatus = MBXERR_ERROR;
442
James Smart2e0fef82007-06-17 19:56:36 -0500443 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500444 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500445 return -EPERM;
446
447 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
448
449 if (!pmboxq)
450 return -ENOMEM;
451
452 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart4db621e2006-07-06 15:49:49 -0400453 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
454 pmboxq->mb.mbxOwner = OWN_HOST;
455
James Smart33ccf8d2006-08-17 11:57:58 -0400456 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500457
James Smart4db621e2006-07-06 15:49:49 -0400458 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
459 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
460 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
461 phba->cfg_link_speed);
462 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
463 phba->fc_ratov * 2);
464 }
465
James Smart5b8bd0c2007-04-25 09:52:49 -0400466 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500467 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400468 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500469
470 if (mbxstatus == MBXERR_ERROR)
471 return -EIO;
472
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700473 return 0;
dea31012005-04-17 16:05:31 -0500474}
475
James Smarte59058c2008-08-24 21:49:00 -0400476/**
477 * lpfc_do_offline: Issues a mailbox command to bring the link down.
478 * @phba: lpfc_hba pointer.
479 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
480 *
481 * Notes:
482 * Assumes any error from lpfc_do_offline() will be negative.
483 * Can wait up to 5 seconds for the port ring buffers count
484 * to reach zero, prints a warning if it is not zero and continues.
485 * lpfc_workq_post_event() returns a non-zero return coce if call fails.
486 *
487 * Returns:
488 * -EIO error posting the event
489 * zero for success
490 **/
James Smart40496f02006-07-06 15:50:22 -0400491static int
James Smart46fa3112007-04-25 09:51:45 -0400492lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
493{
494 struct completion online_compl;
495 struct lpfc_sli_ring *pring;
496 struct lpfc_sli *psli;
497 int status = 0;
498 int cnt = 0;
499 int i;
500
501 init_completion(&online_compl);
502 lpfc_workq_post_event(phba, &status, &online_compl,
503 LPFC_EVT_OFFLINE_PREP);
504 wait_for_completion(&online_compl);
505
506 if (status != 0)
507 return -EIO;
508
509 psli = &phba->sli;
510
James Smart09372822008-01-11 01:52:54 -0500511 /* Wait a little for things to settle down, but not
512 * long enough for dev loss timeout to expire.
513 */
James Smart46fa3112007-04-25 09:51:45 -0400514 for (i = 0; i < psli->num_rings; i++) {
515 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400516 while (pring->txcmplq_cnt) {
517 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500518 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400519 lpfc_printf_log(phba,
520 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400521 "0466 Outstanding IO when "
522 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400523 break;
524 }
525 }
526 }
527
528 init_completion(&online_compl);
529 lpfc_workq_post_event(phba, &status, &online_compl, type);
530 wait_for_completion(&online_compl);
531
532 if (status != 0)
533 return -EIO;
534
535 return 0;
536}
537
James Smarte59058c2008-08-24 21:49:00 -0400538/**
539 * lpfc_selective_reset: Offline then onlines the port.
540 * @phba: lpfc_hba pointer.
541 *
542 * Description:
543 * If the port is configured to allow a reset then the hba is brought
544 * offline then online.
545 *
546 * Notes:
547 * Assumes any error from lpfc_do_offline() will be negative.
548 *
549 * Returns:
550 * lpfc_do_offline() return code if not zero
551 * -EIO reset not configured or error posting the event
552 * zero for success
553 **/
James Smart46fa3112007-04-25 09:51:45 -0400554static int
James Smart40496f02006-07-06 15:50:22 -0400555lpfc_selective_reset(struct lpfc_hba *phba)
556{
557 struct completion online_compl;
558 int status = 0;
559
James Smart13815c82008-01-11 01:52:48 -0500560 if (!phba->cfg_enable_hba_reset)
561 return -EIO;
562
James Smart46fa3112007-04-25 09:51:45 -0400563 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400564
565 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400566 return status;
James Smart40496f02006-07-06 15:50:22 -0400567
568 init_completion(&online_compl);
569 lpfc_workq_post_event(phba, &status, &online_compl,
570 LPFC_EVT_ONLINE);
571 wait_for_completion(&online_compl);
572
573 if (status != 0)
574 return -EIO;
575
576 return 0;
577}
578
James Smarte59058c2008-08-24 21:49:00 -0400579/**
580 * lpfc_issue_reset: Selectively resets an adapter.
581 * @dev: class device that is converted into a Scsi_host.
582 * @attr: device attribute, not used.
583 * @buf: containing the string "selective".
584 * @count: unused variable.
585 *
586 * Description:
587 * If the buf contains the string "selective" then lpfc_selective_reset()
588 * is called to perform the reset.
589 *
590 * Notes:
591 * Assumes any error from lpfc_selective_reset() will be negative.
592 * If lpfc_selective_reset() returns zero then the length of the buffer
593 * is returned which indicates succcess
594 *
595 * Returns:
596 * -EINVAL if the buffer does not contain the string "selective"
597 * length of buf if lpfc-selective_reset() if the call succeeds
598 * return value of lpfc_selective_reset() if the call fails
599**/
James Smart40496f02006-07-06 15:50:22 -0400600static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100601lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
602 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400603{
Tony Jonesee959b02008-02-22 00:13:36 +0100604 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500605 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
606 struct lpfc_hba *phba = vport->phba;
607
James Smart40496f02006-07-06 15:50:22 -0400608 int status = -EINVAL;
609
610 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
611 status = lpfc_selective_reset(phba);
612
613 if (status == 0)
614 return strlen(buf);
615 else
616 return status;
617}
618
James Smarte59058c2008-08-24 21:49:00 -0400619/**
620 * lpfc_nport_evt_cnt_show: Return the number of nport events.
621 * @dev: class device that is converted into a Scsi_host.
622 * @attr: device attribute, not used.
623 * @buf: on return contains the ascii number of nport events.
624 *
625 * Returns: size of formatted string.
626 **/
dea31012005-04-17 16:05:31 -0500627static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100628lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
629 char *buf)
dea31012005-04-17 16:05:31 -0500630{
Tony Jonesee959b02008-02-22 00:13:36 +0100631 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500632 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
633 struct lpfc_hba *phba = vport->phba;
634
dea31012005-04-17 16:05:31 -0500635 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
636}
637
James Smarte59058c2008-08-24 21:49:00 -0400638/**
639 * lpfc_board_mode_show: Return the state of the board.
640 * @dev: class device that is converted into a Scsi_host.
641 * @attr: device attribute, not used.
642 * @buf: on return contains the state of the adapter.
643 *
644 * Returns: size of formatted string.
645 **/
dea31012005-04-17 16:05:31 -0500646static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100647lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
648 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500649{
Tony Jonesee959b02008-02-22 00:13:36 +0100650 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500651 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
652 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500653 char * state;
654
James Smart2e0fef82007-06-17 19:56:36 -0500655 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500656 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500657 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500658 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500659 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500660 state = "offline";
661 else
662 state = "online";
663
664 return snprintf(buf, PAGE_SIZE, "%s\n", state);
665}
666
James Smarte59058c2008-08-24 21:49:00 -0400667/**
668 * lpfc_board_mode_store: Puts the hba in online, offline, warm or error state.
669 * @dev: class device that is converted into a Scsi_host.
670 * @attr: device attribute, not used.
671 * @buf: containing one of the strings "online", "offline", "warm" or "error".
672 * @count: unused variable.
673 *
674 * Returns:
675 * -EACCES if enable hba reset not enabled
676 * -EINVAL if the buffer does not contain a valid string (see above)
677 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
678 * buf length greater than zero indicates success
679 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500680static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100681lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
682 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500683{
Tony Jonesee959b02008-02-22 00:13:36 +0100684 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500685 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
686 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500687 struct completion online_compl;
688 int status=0;
689
James Smart13815c82008-01-11 01:52:48 -0500690 if (!phba->cfg_enable_hba_reset)
691 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500692 init_completion(&online_compl);
693
James Smart46fa3112007-04-25 09:51:45 -0400694 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500695 lpfc_workq_post_event(phba, &status, &online_compl,
696 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400697 wait_for_completion(&online_compl);
698 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
699 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500700 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart46fa3112007-04-25 09:51:45 -0400701 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
702 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
703 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500704 else
705 return -EINVAL;
706
Jamie Wellnitz41415862006-02-28 19:25:27 -0500707 if (!status)
708 return strlen(buf);
709 else
710 return -EIO;
711}
712
James Smarte59058c2008-08-24 21:49:00 -0400713/**
714 * lpfc_get_hba_info: Return various bits of informaton about the adapter.
715 * @phba: pointer to the adapter structure.
716 * @mxri max xri count.
717 * @axri available xri count.
718 * @mrpi max rpi count.
719 * @arpi available rpi count.
720 * @mvpi max vpi count.
721 * @avpi available vpi count.
722 *
723 * Description:
724 * If an integer pointer for an count is not null then the value for the
725 * count is returned.
726 *
727 * Returns:
728 * zero on error
729 * one for success
730 **/
James Smart311464e2007-08-02 11:10:37 -0400731static int
James Smart858c9f62007-06-17 19:56:39 -0500732lpfc_get_hba_info(struct lpfc_hba *phba,
733 uint32_t *mxri, uint32_t *axri,
734 uint32_t *mrpi, uint32_t *arpi,
735 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500736{
737 struct lpfc_sli *psli = &phba->sli;
738 LPFC_MBOXQ_t *pmboxq;
739 MAILBOX_t *pmb;
740 int rc = 0;
741
742 /*
743 * prevent udev from issuing mailbox commands until the port is
744 * configured.
745 */
746 if (phba->link_state < LPFC_LINK_DOWN ||
747 !phba->mbox_mem_pool ||
748 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
749 return 0;
750
751 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
752 return 0;
753
754 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
755 if (!pmboxq)
756 return 0;
757 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
758
759 pmb = &pmboxq->mb;
760 pmb->mbxCommand = MBX_READ_CONFIG;
761 pmb->mbxOwner = OWN_HOST;
762 pmboxq->context1 = NULL;
763
764 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
765 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
766 rc = MBX_NOT_FINISHED;
767 else
768 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
769
770 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500771 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500772 mempool_free(pmboxq, phba->mbox_mem_pool);
773 return 0;
774 }
775
776 if (mrpi)
777 *mrpi = pmb->un.varRdConfig.max_rpi;
778 if (arpi)
779 *arpi = pmb->un.varRdConfig.avail_rpi;
780 if (mxri)
781 *mxri = pmb->un.varRdConfig.max_xri;
782 if (axri)
783 *axri = pmb->un.varRdConfig.avail_xri;
James Smart858c9f62007-06-17 19:56:39 -0500784 if (mvpi)
785 *mvpi = pmb->un.varRdConfig.max_vpi;
786 if (avpi)
787 *avpi = pmb->un.varRdConfig.avail_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500788
789 mempool_free(pmboxq, phba->mbox_mem_pool);
790 return 1;
791}
792
James Smarte59058c2008-08-24 21:49:00 -0400793/**
794 * lpfc_max_rpi_show: Return maximum rpi.
795 * @dev: class device that is converted into a Scsi_host.
796 * @attr: device attribute, not used.
797 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
798 *
799 * Description:
800 * Calls lpfc_get_hba_info() asking for just the mrpi count.
801 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
802 * to "Unknown" and the buffer length is returned, therefore the caller
803 * must check for "Unknown" in the buffer to detect a failure.
804 *
805 * Returns: size of formatted string.
806 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500807static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100808lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
809 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500810{
Tony Jonesee959b02008-02-22 00:13:36 +0100811 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500812 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
813 struct lpfc_hba *phba = vport->phba;
814 uint32_t cnt;
815
James Smart858c9f62007-06-17 19:56:39 -0500816 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500817 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
818 return snprintf(buf, PAGE_SIZE, "Unknown\n");
819}
820
James Smarte59058c2008-08-24 21:49:00 -0400821/**
822 * lpfc_used_rpi_show: Return maximum rpi minus available rpi.
823 * @dev: class device that is converted into a Scsi_host.
824 * @attr: device attribute, not used.
825 * @buf: containing the used rpi count in decimal or "Unknown".
826 *
827 * Description:
828 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
829 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
830 * to "Unknown" and the buffer length is returned, therefore the caller
831 * must check for "Unknown" in the buffer to detect a failure.
832 *
833 * Returns: size of formatted string.
834 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500835static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100836lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
837 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500838{
Tony Jonesee959b02008-02-22 00:13:36 +0100839 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500840 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
841 struct lpfc_hba *phba = vport->phba;
842 uint32_t cnt, acnt;
843
James Smart858c9f62007-06-17 19:56:39 -0500844 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500845 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
846 return snprintf(buf, PAGE_SIZE, "Unknown\n");
847}
848
James Smarte59058c2008-08-24 21:49:00 -0400849/**
850 * lpfc_max_xri_show: Return maximum xri.
851 * @dev: class device that is converted into a Scsi_host.
852 * @attr: device attribute, not used.
853 * @buf: on return contains the maximum xri count in decimal or "Unknown".
854 *
855 * Description:
856 * Calls lpfc_get_hba_info() asking for just the mrpi count.
857 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
858 * to "Unknown" and the buffer length is returned, therefore the caller
859 * must check for "Unknown" in the buffer to detect a failure.
860 *
861 * Returns: size of formatted string.
862 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500863static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100864lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
865 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500866{
Tony Jonesee959b02008-02-22 00:13:36 +0100867 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500868 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
869 struct lpfc_hba *phba = vport->phba;
870 uint32_t cnt;
871
James Smart858c9f62007-06-17 19:56:39 -0500872 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500873 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
874 return snprintf(buf, PAGE_SIZE, "Unknown\n");
875}
876
James Smarte59058c2008-08-24 21:49:00 -0400877/**
878 * lpfc_used_xri_show: Return maximum xpi minus the available xpi.
879 * @dev: class device that is converted into a Scsi_host.
880 * @attr: device attribute, not used.
881 * @buf: on return contains the used xri count in decimal or "Unknown".
882 *
883 * Description:
884 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
885 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
886 * to "Unknown" and the buffer length is returned, therefore the caller
887 * must check for "Unknown" in the buffer to detect a failure.
888 *
889 * Returns: size of formatted string.
890 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500891static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100892lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
893 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500894{
Tony Jonesee959b02008-02-22 00:13:36 +0100895 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500896 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
897 struct lpfc_hba *phba = vport->phba;
898 uint32_t cnt, acnt;
899
James Smart858c9f62007-06-17 19:56:39 -0500900 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
901 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
902 return snprintf(buf, PAGE_SIZE, "Unknown\n");
903}
904
James Smarte59058c2008-08-24 21:49:00 -0400905/**
906 * lpfc_max_vpi_show: Return maximum vpi.
907 * @dev: class device that is converted into a Scsi_host.
908 * @attr: device attribute, not used.
909 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
910 *
911 * Description:
912 * Calls lpfc_get_hba_info() asking for just the mvpi count.
913 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
914 * to "Unknown" and the buffer length is returned, therefore the caller
915 * must check for "Unknown" in the buffer to detect a failure.
916 *
917 * Returns: size of formatted string.
918 **/
James Smart858c9f62007-06-17 19:56:39 -0500919static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100920lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
921 char *buf)
James Smart858c9f62007-06-17 19:56:39 -0500922{
Tony Jonesee959b02008-02-22 00:13:36 +0100923 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -0500924 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
925 struct lpfc_hba *phba = vport->phba;
926 uint32_t cnt;
927
928 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
929 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
930 return snprintf(buf, PAGE_SIZE, "Unknown\n");
931}
932
James Smarte59058c2008-08-24 21:49:00 -0400933/**
934 * lpfc_used_vpi_show: Return maximum vpi minus the available vpi.
935 * @dev: class device that is converted into a Scsi_host.
936 * @attr: device attribute, not used.
937 * @buf: on return contains the used vpi count in decimal or "Unknown".
938 *
939 * Description:
940 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
941 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
942 * to "Unknown" and the buffer length is returned, therefore the caller
943 * must check for "Unknown" in the buffer to detect a failure.
944 *
945 * Returns: size of formatted string.
946 **/
James Smart858c9f62007-06-17 19:56:39 -0500947static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100948lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
949 char *buf)
James Smart858c9f62007-06-17 19:56:39 -0500950{
Tony Jonesee959b02008-02-22 00:13:36 +0100951 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -0500952 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
953 struct lpfc_hba *phba = vport->phba;
954 uint32_t cnt, acnt;
955
956 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -0500957 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
958 return snprintf(buf, PAGE_SIZE, "Unknown\n");
959}
960
James Smarte59058c2008-08-24 21:49:00 -0400961/**
962 * lpfc_npiv_info_show: Return text about NPIV support for the adapter.
963 * @dev: class device that is converted into a Scsi_host.
964 * @attr: device attribute, not used.
965 * @buf: text that must be interpreted to determine if npiv is supported.
966 *
967 * Description:
968 * Buffer will contain text indicating npiv is not suppoerted on the port,
969 * the port is an NPIV physical port, or it is an npiv virtual port with
970 * the id of the vport.
971 *
972 * Returns: size of formatted string.
973 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500974static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100975lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
976 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500977{
Tony Jonesee959b02008-02-22 00:13:36 +0100978 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500979 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
980 struct lpfc_hba *phba = vport->phba;
981
982 if (!(phba->max_vpi))
983 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
984 if (vport->port_type == LPFC_PHYSICAL_PORT)
985 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
986 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
987}
988
James Smarte59058c2008-08-24 21:49:00 -0400989/**
990 * lpfc_poll_show: Return text about poll support for the adapter.
991 * @dev: class device that is converted into a Scsi_host.
992 * @attr: device attribute, not used.
993 * @buf: on return contains the cfg_poll in hex.
994 *
995 * Notes:
996 * cfg_poll should be a lpfc_polling_flags type.
997 *
998 * Returns: size of formatted string.
999 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001000static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001001lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1002 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001003{
Tony Jonesee959b02008-02-22 00:13:36 +01001004 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001005 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1006 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001007
1008 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1009}
1010
James Smarte59058c2008-08-24 21:49:00 -04001011/**
1012 * lpfc_poll_store: Set the value of cfg_poll for the adapter.
1013 * @dev: class device that is converted into a Scsi_host.
1014 * @attr: device attribute, not used.
1015 * @buf: one or more lpfc_polling_flags values.
1016 * @count: not used.
1017 *
1018 * Notes:
1019 * buf contents converted to integer and checked for a valid value.
1020 *
1021 * Returns:
1022 * -EINVAL if the buffer connot be converted or is out of range
1023 * length of the buf on success
1024 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001025static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001026lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1027 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001028{
Tony Jonesee959b02008-02-22 00:13:36 +01001029 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001030 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1031 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001032 uint32_t creg_val;
1033 uint32_t old_val;
1034 int val=0;
1035
1036 if (!isdigit(buf[0]))
1037 return -EINVAL;
1038
1039 if (sscanf(buf, "%i", &val) != 1)
1040 return -EINVAL;
1041
1042 if ((val & 0x3) != val)
1043 return -EINVAL;
1044
James Smart2e0fef82007-06-17 19:56:36 -05001045 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001046
1047 old_val = phba->cfg_poll;
1048
1049 if (val & ENABLE_FCP_RING_POLLING) {
1050 if ((val & DISABLE_FCP_RING_INT) &&
1051 !(old_val & DISABLE_FCP_RING_INT)) {
1052 creg_val = readl(phba->HCregaddr);
1053 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1054 writel(creg_val, phba->HCregaddr);
1055 readl(phba->HCregaddr); /* flush */
1056
1057 lpfc_poll_start_timer(phba);
1058 }
1059 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001060 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001061 return -EINVAL;
1062 }
1063
1064 if (!(val & DISABLE_FCP_RING_INT) &&
1065 (old_val & DISABLE_FCP_RING_INT))
1066 {
James Smart2e0fef82007-06-17 19:56:36 -05001067 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001068 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001069 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001070 creg_val = readl(phba->HCregaddr);
1071 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1072 writel(creg_val, phba->HCregaddr);
1073 readl(phba->HCregaddr); /* flush */
1074 }
1075
1076 phba->cfg_poll = val;
1077
James Smart2e0fef82007-06-17 19:56:36 -05001078 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001079
1080 return strlen(buf);
1081}
dea31012005-04-17 16:05:31 -05001082
James Smarte59058c2008-08-24 21:49:00 -04001083/**
1084 * lpfc_param_show: Return a cfg attribute value in decimal.
1085 *
1086 * Description:
1087 * Macro that given an attr e.g. hba_queue_depth expands
1088 * into a function with the name lpfc_hba_queue_depth_show.
1089 *
1090 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1091 * @dev: class device that is converted into a Scsi_host.
1092 * @attr: device attribute, not used.
1093 * @buf: on return contains the attribute value in decimal.
1094 *
1095 * Returns: size of formatted string.
1096 **/
dea31012005-04-17 16:05:31 -05001097#define lpfc_param_show(attr) \
1098static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001099lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1100 char *buf) \
dea31012005-04-17 16:05:31 -05001101{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001102 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001103 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1104 struct lpfc_hba *phba = vport->phba;\
dea31012005-04-17 16:05:31 -05001105 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001106 val = phba->cfg_##attr;\
1107 return snprintf(buf, PAGE_SIZE, "%d\n",\
1108 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001109}
1110
James Smarte59058c2008-08-24 21:49:00 -04001111/**
1112 * lpfc_param_hex_show: Return a cfg attribute value in hex.
1113 *
1114 * Description:
1115 * Macro that given an attr e.g. hba_queue_depth expands
1116 * into a function with the name lpfc_hba_queue_depth_show
1117 *
1118 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1119 * @dev: class device that is converted into a Scsi_host.
1120 * @attr: device attribute, not used.
1121 * @buf: on return contains the attribute value in hexidecimal.
1122 *
1123 * Returns: size of formatted string.
1124 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001125#define lpfc_param_hex_show(attr) \
1126static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001127lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1128 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001129{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001130 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001131 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1132 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001133 int val = 0;\
1134 val = phba->cfg_##attr;\
1135 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1136 phba->cfg_##attr);\
1137}
1138
James Smarte59058c2008-08-24 21:49:00 -04001139/**
1140 * lpfc_param_init: Intializes a cfg attribute.
1141 *
1142 * Description:
1143 * Macro that given an attr e.g. hba_queue_depth expands
1144 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1145 * takes a default argument, a minimum and maximum argument.
1146 *
1147 * lpfc_##attr##_init: Initializes an attribute.
1148 * @phba: pointer the the adapter structure.
1149 * @val: integer attribute value.
1150 *
1151 * Validates the min and max values then sets the adapter config field
1152 * accordingly, or uses the default if out of range and prints an error message.
1153 *
1154 * Returns:
1155 * zero on success
1156 * -EINVAL if default used
1157 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001158#define lpfc_param_init(attr, default, minval, maxval) \
1159static int \
1160lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
1161{ \
1162 if (val >= minval && val <= maxval) {\
1163 phba->cfg_##attr = val;\
1164 return 0;\
1165 }\
1166 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001167 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1168 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001169 phba->cfg_##attr = default;\
1170 return -EINVAL;\
1171}
1172
James Smarte59058c2008-08-24 21:49:00 -04001173/**
1174 * lpfc_param_set: Set a cfg attribute value.
1175 *
1176 * Description:
1177 * Macro that given an attr e.g. hba_queue_depth expands
1178 * into a function with the name lpfc_hba_queue_depth_set
1179 *
1180 * lpfc_##attr##_set: Sets an attribute value.
1181 * @phba: pointer the the adapter structure.
1182 * @val: integer attribute value.
1183 *
1184 * Description:
1185 * Validates the min and max values then sets the
1186 * adapter config field if in the valid range. prints error message
1187 * and does not set the parameter if invalid.
1188 *
1189 * Returns:
1190 * zero on success
1191 * -EINVAL if val is invalid
1192 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001193#define lpfc_param_set(attr, default, minval, maxval) \
1194static int \
1195lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
1196{ \
1197 if (val >= minval && val <= maxval) {\
1198 phba->cfg_##attr = val;\
1199 return 0;\
1200 }\
1201 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001202 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1203 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001204 return -EINVAL;\
1205}
1206
James Smarte59058c2008-08-24 21:49:00 -04001207/**
1208 * lpfc_param_store: Set a vport attribute value.
1209 *
1210 * Description:
1211 * Macro that given an attr e.g. hba_queue_depth expands
1212 * into a function with the name lpfc_hba_queue_depth_store.
1213 *
1214 * lpfc_##attr##_store: Set an sttribute value.
1215 * @dev: class device that is converted into a Scsi_host.
1216 * @attr: device attribute, not used.
1217 * @buf: contains the attribute value in ascii.
1218 * @count: not used.
1219 *
1220 * Description:
1221 * Convert the ascii text number to an integer, then
1222 * use the lpfc_##attr##_set function to set the value.
1223 *
1224 * Returns:
1225 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1226 * length of buffer upon success.
1227 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001228#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001229static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001230lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1231 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001232{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001233 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001234 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1235 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001236 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001237 if (!isdigit(buf[0]))\
1238 return -EINVAL;\
1239 if (sscanf(buf, "%i", &val) != 1)\
1240 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001241 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001242 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001243 else \
1244 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001245}
1246
James Smarte59058c2008-08-24 21:49:00 -04001247/**
1248 * lpfc_vport_param_show: Return decimal formatted cfg attribute value.
1249 *
1250 * Description:
1251 * Macro that given an attr e.g. hba_queue_depth expands
1252 * into a function with the name lpfc_hba_queue_depth_show
1253 *
1254 * lpfc_##attr##_show: prints the attribute value in decimal.
1255 * @dev: class device that is converted into a Scsi_host.
1256 * @attr: device attribute, not used.
1257 * @buf: on return contains the attribute value in decimal.
1258 *
1259 * Returns: length of formatted string.
1260 **/
James Smart3de2a652007-08-02 11:09:59 -04001261#define lpfc_vport_param_show(attr) \
1262static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001263lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1264 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001265{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001266 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001267 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1268 int val = 0;\
1269 val = vport->cfg_##attr;\
1270 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1271}
1272
James Smarte59058c2008-08-24 21:49:00 -04001273/**
1274 * lpfc_vport_param_hex_show: Return hex formatted attribute value.
1275 *
1276 * Description:
1277 * Macro that given an attr e.g.
1278 * hba_queue_depth expands into a function with the name
1279 * lpfc_hba_queue_depth_show
1280 *
1281 * lpfc_##attr##_show: prints the attribute value in hexidecimal.
1282 * @dev: class device that is converted into a Scsi_host.
1283 * @attr: device attribute, not used.
1284 * @buf: on return contains the attribute value in hexidecimal.
1285 *
1286 * Returns: length of formatted string.
1287 **/
James Smart3de2a652007-08-02 11:09:59 -04001288#define lpfc_vport_param_hex_show(attr) \
1289static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001290lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1291 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001292{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001293 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001294 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1295 int val = 0;\
1296 val = vport->cfg_##attr;\
1297 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1298}
1299
James Smarte59058c2008-08-24 21:49:00 -04001300/**
1301 * lpfc_vport_param_init: Initialize a vport cfg attribute.
1302 *
1303 * Description:
1304 * Macro that given an attr e.g. hba_queue_depth expands
1305 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1306 * takes a default argument, a minimum and maximum argument.
1307 *
1308 * lpfc_##attr##_init: validates the min and max values then sets the
1309 * adapter config field accordingly, or uses the default if out of range
1310 * and prints an error message.
1311 * @phba: pointer the the adapter structure.
1312 * @val: integer attribute value.
1313 *
1314 * Returns:
1315 * zero on success
1316 * -EINVAL if default used
1317 **/
James Smart3de2a652007-08-02 11:09:59 -04001318#define lpfc_vport_param_init(attr, default, minval, maxval) \
1319static int \
1320lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
1321{ \
1322 if (val >= minval && val <= maxval) {\
1323 vport->cfg_##attr = val;\
1324 return 0;\
1325 }\
James Smarte8b62012007-08-02 11:10:09 -04001326 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001327 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001328 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001329 vport->cfg_##attr = default;\
1330 return -EINVAL;\
1331}
1332
James Smarte59058c2008-08-24 21:49:00 -04001333/**
1334 * lpfc_vport_param_set: Set a vport cfg attribute.
1335 *
1336 * Description:
1337 * Macro that given an attr e.g. hba_queue_depth expands
1338 * into a function with the name lpfc_hba_queue_depth_set
1339 *
1340 * lpfc_##attr##_set: validates the min and max values then sets the
1341 * adapter config field if in the valid range. prints error message
1342 * and does not set the parameter if invalid.
1343 * @phba: pointer the the adapter structure.
1344 * @val: integer attribute value.
1345 *
1346 * Returns:
1347 * zero on success
1348 * -EINVAL if val is invalid
1349 **/
James Smart3de2a652007-08-02 11:09:59 -04001350#define lpfc_vport_param_set(attr, default, minval, maxval) \
1351static int \
1352lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
1353{ \
1354 if (val >= minval && val <= maxval) {\
1355 vport->cfg_##attr = val;\
1356 return 0;\
1357 }\
James Smarte8b62012007-08-02 11:10:09 -04001358 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001359 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001360 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001361 return -EINVAL;\
1362}
1363
James Smarte59058c2008-08-24 21:49:00 -04001364/**
1365 * lpfc_vport_param_store: Set a vport attribute.
1366 *
1367 * Description:
1368 * Macro that given an attr e.g. hba_queue_depth
1369 * expands into a function with the name lpfc_hba_queue_depth_store
1370 *
1371 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1372 * use the lpfc_##attr##_set function to set the value.
1373 * @cdev: class device that is converted into a Scsi_host.
1374 * @buf: contains the attribute value in decimal.
1375 * @count: not used.
1376 *
1377 * Returns:
1378 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1379 * length of buffer upon success.
1380 **/
James Smart3de2a652007-08-02 11:09:59 -04001381#define lpfc_vport_param_store(attr) \
1382static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001383lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1384 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001385{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001386 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001387 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1388 int val=0;\
1389 if (!isdigit(buf[0]))\
1390 return -EINVAL;\
1391 if (sscanf(buf, "%i", &val) != 1)\
1392 return -EINVAL;\
1393 if (lpfc_##attr##_set(vport, val) == 0) \
1394 return strlen(buf);\
1395 else \
1396 return -EINVAL;\
1397}
1398
1399
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001400#define LPFC_ATTR(name, defval, minval, maxval, desc) \
1401static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -05001402module_param(lpfc_##name, int, 0);\
1403MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001404lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001405
1406#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1407static int lpfc_##name = defval;\
1408module_param(lpfc_##name, int, 0);\
1409MODULE_PARM_DESC(lpfc_##name, desc);\
1410lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001411lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001412static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001413
1414#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1415static int lpfc_##name = defval;\
1416module_param(lpfc_##name, int, 0);\
1417MODULE_PARM_DESC(lpfc_##name, desc);\
1418lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001419lpfc_param_init(name, defval, minval, maxval)\
1420lpfc_param_set(name, defval, minval, maxval)\
1421lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001422static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1423 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001424
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001425#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1426static int lpfc_##name = defval;\
1427module_param(lpfc_##name, int, 0);\
1428MODULE_PARM_DESC(lpfc_##name, desc);\
1429lpfc_param_hex_show(name)\
1430lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001431static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001432
1433#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1434static int lpfc_##name = defval;\
1435module_param(lpfc_##name, int, 0);\
1436MODULE_PARM_DESC(lpfc_##name, desc);\
1437lpfc_param_hex_show(name)\
1438lpfc_param_init(name, defval, minval, maxval)\
1439lpfc_param_set(name, defval, minval, maxval)\
1440lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001441static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1442 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001443
James Smart3de2a652007-08-02 11:09:59 -04001444#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1445static int lpfc_##name = defval;\
1446module_param(lpfc_##name, int, 0);\
1447MODULE_PARM_DESC(lpfc_##name, desc);\
1448lpfc_vport_param_init(name, defval, minval, maxval)
1449
1450#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1451static int lpfc_##name = defval;\
1452module_param(lpfc_##name, int, 0);\
1453MODULE_PARM_DESC(lpfc_##name, desc);\
1454lpfc_vport_param_show(name)\
1455lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001456static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001457
1458#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1459static int lpfc_##name = defval;\
1460module_param(lpfc_##name, int, 0);\
1461MODULE_PARM_DESC(lpfc_##name, desc);\
1462lpfc_vport_param_show(name)\
1463lpfc_vport_param_init(name, defval, minval, maxval)\
1464lpfc_vport_param_set(name, defval, minval, maxval)\
1465lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001466static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1467 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001468
1469#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1470static int lpfc_##name = defval;\
1471module_param(lpfc_##name, int, 0);\
1472MODULE_PARM_DESC(lpfc_##name, desc);\
1473lpfc_vport_param_hex_show(name)\
1474lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001475static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001476
1477#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1478static int lpfc_##name = defval;\
1479module_param(lpfc_##name, int, 0);\
1480MODULE_PARM_DESC(lpfc_##name, desc);\
1481lpfc_vport_param_hex_show(name)\
1482lpfc_vport_param_init(name, defval, minval, maxval)\
1483lpfc_vport_param_set(name, defval, minval, maxval)\
1484lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001485static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1486 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001487
Tony Jonesee959b02008-02-22 00:13:36 +01001488static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1489static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1490static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1491static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1492static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1493static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1494static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1495static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001496static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001497static DEVICE_ATTR(option_rom_version, S_IRUGO,
1498 lpfc_option_rom_version_show, NULL);
1499static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1500 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001501static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001502static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1503static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1504static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1505 lpfc_board_mode_show, lpfc_board_mode_store);
1506static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1507static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1508static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1509static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1510static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1511static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1512static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1513static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1514static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
dea31012005-04-17 16:05:31 -05001515
James Smartc3f28af2006-08-18 17:47:18 -04001516
James Smarta12e07b2006-12-02 13:35:30 -05001517static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001518
James Smarte59058c2008-08-24 21:49:00 -04001519/**
1520 * lpfc_soft_wwn_enable_store: Allows setting of the wwn if the key is valid.
1521 * @dev: class device that is converted into a Scsi_host.
1522 * @attr: device attribute, not used.
1523 * @buf: containing the string lpfc_soft_wwn_key.
1524 * @count: must be size of lpfc_soft_wwn_key.
1525 *
1526 * Returns:
1527 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1528 * length of buf indicates success
1529 **/
James Smartc3f28af2006-08-18 17:47:18 -04001530static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001531lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1532 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001533{
Tony Jonesee959b02008-02-22 00:13:36 +01001534 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001535 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1536 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001537 unsigned int cnt = count;
1538
1539 /*
1540 * We're doing a simple sanity check for soft_wwpn setting.
1541 * We require that the user write a specific key to enable
1542 * the soft_wwpn attribute to be settable. Once the attribute
1543 * is written, the enable key resets. If further updates are
1544 * desired, the key must be written again to re-enable the
1545 * attribute.
1546 *
1547 * The "key" is not secret - it is a hardcoded string shown
1548 * here. The intent is to protect against the random user or
1549 * application that is just writing attributes.
1550 */
1551
1552 /* count may include a LF at end of string */
1553 if (buf[cnt-1] == '\n')
1554 cnt--;
1555
James Smarta12e07b2006-12-02 13:35:30 -05001556 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1557 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001558 return -EINVAL;
1559
James Smarta12e07b2006-12-02 13:35:30 -05001560 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001561 return count;
1562}
Tony Jonesee959b02008-02-22 00:13:36 +01001563static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1564 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001565
James Smarte59058c2008-08-24 21:49:00 -04001566/**
1567 * lpfc_soft_wwpn_show: Return the cfg soft ww port name of the adapter.
1568 * @dev: class device that is converted into a Scsi_host.
1569 * @attr: device attribute, not used.
1570 * @buf: on return contains the wwpn in hexidecimal.
1571 *
1572 * Returns: size of formatted string.
1573 **/
James Smartc3f28af2006-08-18 17:47:18 -04001574static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001575lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1576 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001577{
Tony Jonesee959b02008-02-22 00:13:36 +01001578 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001579 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1580 struct lpfc_hba *phba = vport->phba;
1581
Randy Dunlapafc071e2006-10-23 21:47:13 -07001582 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1583 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001584}
1585
James Smarte59058c2008-08-24 21:49:00 -04001586/**
1587 * lpfc_soft_wwpn_store: Set the ww port name of the adapter.
1588 * @dev class device that is converted into a Scsi_host.
1589 * @attr: device attribute, not used.
1590 * @buf: contains the wwpn in hexidecimal.
1591 * @count: number of wwpn bytes in buf
1592 *
1593 * Returns:
1594 * -EACCES hba reset not enabled, adapter over temp
1595 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1596 * -EIO error taking adapter offline or online
1597 * value of count on success
1598 **/
James Smartc3f28af2006-08-18 17:47:18 -04001599static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001600lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1601 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001602{
Tony Jonesee959b02008-02-22 00:13:36 +01001603 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001604 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1605 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001606 struct completion online_compl;
1607 int stat1=0, stat2=0;
1608 unsigned int i, j, cnt=count;
1609 u8 wwpn[8];
1610
James Smart13815c82008-01-11 01:52:48 -05001611 if (!phba->cfg_enable_hba_reset)
1612 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001613 spin_lock_irq(&phba->hbalock);
1614 if (phba->over_temp_state == HBA_OVER_TEMP) {
1615 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001616 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001617 }
1618 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001619 /* count may include a LF at end of string */
1620 if (buf[cnt-1] == '\n')
1621 cnt--;
1622
James Smarta12e07b2006-12-02 13:35:30 -05001623 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001624 ((cnt == 17) && (*buf++ != 'x')) ||
1625 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1626 return -EINVAL;
1627
James Smarta12e07b2006-12-02 13:35:30 -05001628 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001629
1630 memset(wwpn, 0, sizeof(wwpn));
1631
1632 /* Validate and store the new name */
1633 for (i=0, j=0; i < 16; i++) {
1634 if ((*buf >= 'a') && (*buf <= 'f'))
1635 j = ((j << 4) | ((*buf++ -'a') + 10));
1636 else if ((*buf >= 'A') && (*buf <= 'F'))
1637 j = ((j << 4) | ((*buf++ -'A') + 10));
1638 else if ((*buf >= '0') && (*buf <= '9'))
1639 j = ((j << 4) | (*buf++ -'0'));
1640 else
1641 return -EINVAL;
1642 if (i % 2) {
1643 wwpn[i/2] = j & 0xff;
1644 j = 0;
1645 }
1646 }
1647 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001648 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001649 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001650 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001651
1652 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1653 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1654
James Smart46fa3112007-04-25 09:51:45 -04001655 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001656 if (stat1)
1657 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001658 "0463 lpfc_soft_wwpn attribute set failed to "
1659 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001660 init_completion(&online_compl);
1661 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1662 wait_for_completion(&online_compl);
1663 if (stat2)
1664 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001665 "0464 lpfc_soft_wwpn attribute set failed to "
1666 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001667 return (stat1 || stat2) ? -EIO : count;
1668}
Tony Jonesee959b02008-02-22 00:13:36 +01001669static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1670 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001671
James Smarte59058c2008-08-24 21:49:00 -04001672/**
1673 * lpfc_soft_wwnn_show: Return the cfg soft ww node name for the adapter.
1674 * @dev: class device that is converted into a Scsi_host.
1675 * @attr: device attribute, not used.
1676 * @buf: on return contains the wwnn in hexidecimal.
1677 *
1678 * Returns: size of formatted string.
1679 **/
James Smarta12e07b2006-12-02 13:35:30 -05001680static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001681lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1682 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001683{
Tony Jonesee959b02008-02-22 00:13:36 +01001684 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001685 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001686 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1687 (unsigned long long)phba->cfg_soft_wwnn);
1688}
1689
James Smarte59058c2008-08-24 21:49:00 -04001690/**
1691 * lpfc_soft_wwnn_store: sets the ww node name of the adapter.
1692 * @cdev: class device that is converted into a Scsi_host.
1693 * @buf: contains the ww node name in hexidecimal.
1694 * @count: number of wwnn bytes in buf.
1695 *
1696 * Returns:
1697 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1698 * value of count on success
1699 **/
James Smarta12e07b2006-12-02 13:35:30 -05001700static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001701lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1702 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001703{
Tony Jonesee959b02008-02-22 00:13:36 +01001704 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001705 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001706 unsigned int i, j, cnt=count;
1707 u8 wwnn[8];
1708
1709 /* count may include a LF at end of string */
1710 if (buf[cnt-1] == '\n')
1711 cnt--;
1712
1713 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1714 ((cnt == 17) && (*buf++ != 'x')) ||
1715 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1716 return -EINVAL;
1717
1718 /*
1719 * Allow wwnn to be set many times, as long as the enable is set.
1720 * However, once the wwpn is set, everything locks.
1721 */
1722
1723 memset(wwnn, 0, sizeof(wwnn));
1724
1725 /* Validate and store the new name */
1726 for (i=0, j=0; i < 16; i++) {
1727 if ((*buf >= 'a') && (*buf <= 'f'))
1728 j = ((j << 4) | ((*buf++ -'a') + 10));
1729 else if ((*buf >= 'A') && (*buf <= 'F'))
1730 j = ((j << 4) | ((*buf++ -'A') + 10));
1731 else if ((*buf >= '0') && (*buf <= '9'))
1732 j = ((j << 4) | (*buf++ -'0'));
1733 else
1734 return -EINVAL;
1735 if (i % 2) {
1736 wwnn[i/2] = j & 0xff;
1737 j = 0;
1738 }
1739 }
1740 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1741
1742 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1743 "lpfc%d: soft_wwnn set. Value will take effect upon "
1744 "setting of the soft_wwpn\n", phba->brd_no);
1745
1746 return count;
1747}
Tony Jonesee959b02008-02-22 00:13:36 +01001748static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1749 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001750
James Smartc3f28af2006-08-18 17:47:18 -04001751
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001752static int lpfc_poll = 0;
1753module_param(lpfc_poll, int, 0);
1754MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1755 " 0 - none,"
1756 " 1 - poll with interrupts enabled"
1757 " 3 - poll and disable FCP ring interrupts");
1758
Tony Jonesee959b02008-02-22 00:13:36 +01001759static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1760 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001761
James Smart92d7f7b2007-06-17 19:56:38 -05001762int lpfc_sli_mode = 0;
1763module_param(lpfc_sli_mode, int, 0);
1764MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1765 " 0 - auto (SLI-3 if supported),"
1766 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1767 " 3 - select SLI-3");
1768
James Smart7ee5d432007-10-27 13:37:17 -04001769int lpfc_enable_npiv = 0;
1770module_param(lpfc_enable_npiv, int, 0);
1771MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1772lpfc_param_show(enable_npiv);
1773lpfc_param_init(enable_npiv, 0, 0, 1);
Tony Jonesee959b02008-02-22 00:13:36 +01001774static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
James Smart7ee5d432007-10-27 13:37:17 -04001775 lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001776
dea31012005-04-17 16:05:31 -05001777/*
James Smartc01f3202006-08-18 17:47:08 -04001778# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1779# until the timer expires. Value range is [0,255]. Default value is 30.
1780*/
1781static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1782static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1783module_param(lpfc_nodev_tmo, int, 0);
1784MODULE_PARM_DESC(lpfc_nodev_tmo,
1785 "Seconds driver will hold I/O waiting "
1786 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04001787
1788/**
1789 * lpfc_nodev_tmo_show: Return the hba dev loss timeout value.
1790 * @dev: class converted to a Scsi_host structure.
1791 * @attr: device attribute, not used.
1792 * @buf: on return contains the dev loss timeout in decimal.
1793 *
1794 * Returns: size of formatted string.
1795 **/
James Smartc01f3202006-08-18 17:47:08 -04001796static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001797lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1798 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04001799{
Tony Jonesee959b02008-02-22 00:13:36 +01001800 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001801 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smartc01f3202006-08-18 17:47:08 -04001802 int val = 0;
James Smart3de2a652007-08-02 11:09:59 -04001803 val = vport->cfg_devloss_tmo;
1804 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001805}
1806
James Smarte59058c2008-08-24 21:49:00 -04001807/**
1808 * lpfc_nodev_tmo_init: Set the hba nodev timeout value.
1809 * @vport: lpfc vport structure pointer.
1810 * @val: contains the nodev timeout value.
1811 *
1812 * Description:
1813 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1814 * a kernel error message is printed and zero is returned.
1815 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1816 * Otherwise nodev tmo is set to the default value.
1817 *
1818 * Returns:
1819 * zero if already set or if val is in range
1820 * -EINVAL val out of range
1821 **/
James Smartc01f3202006-08-18 17:47:08 -04001822static int
James Smart3de2a652007-08-02 11:09:59 -04001823lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001824{
James Smart3de2a652007-08-02 11:09:59 -04001825 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1826 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1827 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04001828 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001829 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04001830 "parameter because devloss_tmo is "
1831 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001832 return 0;
1833 }
1834
1835 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001836 vport->cfg_nodev_tmo = val;
1837 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04001838 return 0;
1839 }
James Smarte8b62012007-08-02 11:10:09 -04001840 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1841 "0400 lpfc_nodev_tmo attribute cannot be set to"
1842 " %d, allowed range is [%d, %d]\n",
1843 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04001844 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04001845 return -EINVAL;
1846}
1847
James Smarte59058c2008-08-24 21:49:00 -04001848/**
1849 * lpfc_update_rport_devloss_tmo: Update dev loss tmo value.
1850 * @vport: lpfc vport structure pointer.
1851 *
1852 * Description:
1853 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
1854 **/
James Smart7054a602007-04-25 09:52:34 -04001855static void
James Smart3de2a652007-08-02 11:09:59 -04001856lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04001857{
James Smart858c9f62007-06-17 19:56:39 -05001858 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04001859 struct lpfc_nodelist *ndlp;
1860
James Smart51ef4c22007-08-02 11:10:31 -04001861 shost = lpfc_shost_from_vport(vport);
1862 spin_lock_irq(shost->host_lock);
1863 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05001864 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04001865 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1866 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04001867}
1868
James Smarte59058c2008-08-24 21:49:00 -04001869/**
1870 * lpfc_nodev_tmo_set: Set the vport nodev tmo and devloss tmo values.
1871 * @vport: lpfc vport structure pointer.
1872 * @val: contains the tmo value.
1873 *
1874 * Description:
1875 * If the devloss tmo is already set or the vport dev loss tmo has changed
1876 * then a kernel error message is printed and zero is returned.
1877 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1878 * Otherwise nodev tmo is set to the default value.
1879 *
1880 * Returns:
1881 * zero if already set or if val is in range
1882 * -EINVAL val out of range
1883 **/
James Smartc01f3202006-08-18 17:47:08 -04001884static int
James Smart3de2a652007-08-02 11:09:59 -04001885lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001886{
James Smart3de2a652007-08-02 11:09:59 -04001887 if (vport->dev_loss_tmo_changed ||
1888 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04001889 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1890 "0401 Ignoring change to nodev_tmo "
1891 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001892 return 0;
1893 }
James Smartc01f3202006-08-18 17:47:08 -04001894 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001895 vport->cfg_nodev_tmo = val;
1896 vport->cfg_devloss_tmo = val;
1897 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001898 return 0;
1899 }
James Smarte8b62012007-08-02 11:10:09 -04001900 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1901 "0403 lpfc_nodev_tmo attribute cannot be set to"
1902 "%d, allowed range is [%d, %d]\n",
1903 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001904 return -EINVAL;
1905}
1906
James Smart3de2a652007-08-02 11:09:59 -04001907lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001908
Tony Jonesee959b02008-02-22 00:13:36 +01001909static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1910 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04001911
1912/*
1913# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1914# disappear until the timer expires. Value range is [0,255]. Default
1915# value is 30.
1916*/
1917module_param(lpfc_devloss_tmo, int, 0);
1918MODULE_PARM_DESC(lpfc_devloss_tmo,
1919 "Seconds driver will hold I/O waiting "
1920 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04001921lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
1922 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
1923lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04001924
1925/**
1926 * lpfc_devloss_tmo_set: Sets vport nodev tmo, devloss tmo values, changed bit.
1927 * @vport: lpfc vport structure pointer.
1928 * @val: contains the tmo value.
1929 *
1930 * Description:
1931 * If val is in a valid range then set the vport nodev tmo,
1932 * devloss tmo, also set the vport dev loss tmo changed flag.
1933 * Else a kernel error message is printed.
1934 *
1935 * Returns:
1936 * zero if val is in range
1937 * -EINVAL val out of range
1938 **/
James Smartc01f3202006-08-18 17:47:08 -04001939static int
James Smart3de2a652007-08-02 11:09:59 -04001940lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001941{
1942 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001943 vport->cfg_nodev_tmo = val;
1944 vport->cfg_devloss_tmo = val;
1945 vport->dev_loss_tmo_changed = 1;
1946 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001947 return 0;
1948 }
1949
James Smarte8b62012007-08-02 11:10:09 -04001950 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1951 "0404 lpfc_devloss_tmo attribute cannot be set to"
1952 " %d, allowed range is [%d, %d]\n",
1953 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001954 return -EINVAL;
1955}
1956
James Smart3de2a652007-08-02 11:09:59 -04001957lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01001958static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
1959 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04001960
1961/*
dea31012005-04-17 16:05:31 -05001962# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
1963# deluged with LOTS of information.
1964# You can set a bit mask to record specific types of verbose messages:
1965#
1966# LOG_ELS 0x1 ELS events
1967# LOG_DISCOVERY 0x2 Link discovery events
1968# LOG_MBOX 0x4 Mailbox events
1969# LOG_INIT 0x8 Initialization events
1970# LOG_LINK_EVENT 0x10 Link events
dea31012005-04-17 16:05:31 -05001971# LOG_FCP 0x40 FCP traffic history
1972# LOG_NODE 0x80 Node table events
1973# LOG_MISC 0x400 Miscellaneous events
1974# LOG_SLI 0x800 SLI events
James Smartc7743952006-12-02 13:34:42 -05001975# LOG_FCP_ERROR 0x1000 Only log FCP errors
dea31012005-04-17 16:05:31 -05001976# LOG_LIBDFC 0x2000 LIBDFC events
1977# LOG_ALL_MSG 0xffff LOG all messages
1978*/
James Smarte8b62012007-08-02 11:10:09 -04001979LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
1980 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05001981
1982/*
James Smart7ee5d432007-10-27 13:37:17 -04001983# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
1984# objects that have been registered with the nameserver after login.
1985*/
1986LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
1987 "Deregister nameserver objects before LOGO");
1988
1989/*
dea31012005-04-17 16:05:31 -05001990# lun_queue_depth: This parameter is used to limit the number of outstanding
1991# commands per FCP LUN. Value range is [1,128]. Default value is 30.
1992*/
James Smart3de2a652007-08-02 11:09:59 -04001993LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
1994 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05001995
1996/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001997# hba_queue_depth: This parameter is used to limit the number of outstanding
1998# commands per lpfc HBA. Value range is [32,8192]. If this parameter
1999# value is greater than the maximum number of exchanges supported by the HBA,
2000# then maximum number of exchanges supported by the HBA is used to determine
2001# the hba_queue_depth.
2002*/
2003LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2004 "Max number of FCP commands we can queue to a lpfc HBA");
2005
2006/*
James Smart92d7f7b2007-06-17 19:56:38 -05002007# peer_port_login: This parameter allows/prevents logins
2008# between peer ports hosted on the same physical port.
2009# When this parameter is set 0 peer ports of same physical port
2010# are not allowed to login to each other.
2011# When this parameter is set 1 peer ports of same physical port
2012# are allowed to login to each other.
2013# Default value of this parameter is 0.
2014*/
James Smart3de2a652007-08-02 11:09:59 -04002015LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2016 "Allow peer ports on the same physical port to login to each "
2017 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002018
2019/*
James Smart3de2a652007-08-02 11:09:59 -04002020# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002021# between Virtual Ports and remote initiators.
2022# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2023# other initiators and will attempt to PLOGI all remote ports.
2024# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2025# remote ports and will not attempt to PLOGI to other initiators.
2026# This parameter does not restrict to the physical port.
2027# This parameter does not restrict logins to Fabric resident remote ports.
2028# Default value of this parameter is 1.
2029*/
James Smart3de2a652007-08-02 11:09:59 -04002030static int lpfc_restrict_login = 1;
2031module_param(lpfc_restrict_login, int, 0);
2032MODULE_PARM_DESC(lpfc_restrict_login,
2033 "Restrict virtual ports login to remote initiators.");
2034lpfc_vport_param_show(restrict_login);
2035
James Smarte59058c2008-08-24 21:49:00 -04002036/**
2037 * lpfc_restrict_login_init: Set the vport restrict login flag.
2038 * @vport: lpfc vport structure pointer.
2039 * @val: contains the restrict login value.
2040 *
2041 * Description:
2042 * If val is not in a valid range then log a kernel error message and set
2043 * the vport restrict login to one.
2044 * If the port type is physical clear the restrict login flag and return.
2045 * Else set the restrict login flag to val.
2046 *
2047 * Returns:
2048 * zero if val is in range
2049 * -EINVAL val out of range
2050 **/
James Smart3de2a652007-08-02 11:09:59 -04002051static int
2052lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2053{
2054 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002055 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002056 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002057 "be set to %d, allowed range is [0, 1]\n",
2058 val);
James Smart3de2a652007-08-02 11:09:59 -04002059 vport->cfg_restrict_login = 1;
2060 return -EINVAL;
2061 }
2062 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2063 vport->cfg_restrict_login = 0;
2064 return 0;
2065 }
2066 vport->cfg_restrict_login = val;
2067 return 0;
2068}
2069
James Smarte59058c2008-08-24 21:49:00 -04002070/**
2071 * lpfc_restrict_login_set: Set the vport restrict login flag.
2072 * @vport: lpfc vport structure pointer.
2073 * @val: contains the restrict login value.
2074 *
2075 * Description:
2076 * If val is not in a valid range then log a kernel error message and set
2077 * the vport restrict login to one.
2078 * If the port type is physical and the val is not zero log a kernel
2079 * error message, clear the restrict login flag and return zero.
2080 * Else set the restrict login flag to val.
2081 *
2082 * Returns:
2083 * zero if val is in range
2084 * -EINVAL val out of range
2085 **/
James Smart3de2a652007-08-02 11:09:59 -04002086static int
2087lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2088{
2089 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002090 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002091 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002092 "be set to %d, allowed range is [0, 1]\n",
2093 val);
James Smart3de2a652007-08-02 11:09:59 -04002094 vport->cfg_restrict_login = 1;
2095 return -EINVAL;
2096 }
2097 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002098 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2099 "0468 lpfc_restrict_login must be 0 for "
2100 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002101 vport->cfg_restrict_login = 0;
2102 return 0;
2103 }
2104 vport->cfg_restrict_login = val;
2105 return 0;
2106}
2107lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002108static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2109 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002110
2111/*
dea31012005-04-17 16:05:31 -05002112# Some disk devices have a "select ID" or "select Target" capability.
2113# From a protocol standpoint "select ID" usually means select the
2114# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2115# annex" which contains a table that maps a "select ID" (a number
2116# between 0 and 7F) to an ALPA. By default, for compatibility with
2117# older drivers, the lpfc driver scans this table from low ALPA to high
2118# ALPA.
2119#
2120# Turning on the scan-down variable (on = 1, off = 0) will
2121# cause the lpfc driver to use an inverted table, effectively
2122# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2123#
2124# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2125# and will not work across a fabric. Also this parameter will take
2126# effect only in the case when ALPA map is not available.)
2127*/
James Smart3de2a652007-08-02 11:09:59 -04002128LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2129 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002130
2131/*
dea31012005-04-17 16:05:31 -05002132# lpfc_topology: link topology for init link
2133# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002134# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002135# 0x02 = attempt point-to-point mode only
2136# 0x04 = attempt loop mode only
2137# 0x06 = attempt point-to-point mode then loop
2138# Set point-to-point mode if you want to run as an N_Port.
2139# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2140# Default value is 0.
2141*/
James Smarte59058c2008-08-24 21:49:00 -04002142
2143/**
2144 * lpfc_topology_set: Set the adapters topology field.
2145 * @phba: lpfc_hba pointer.
2146 * @val: topology value.
2147 *
2148 * Description:
2149 * If val is in a valid range then set the adapter's topology field and
2150 * issue a lip; if the lip fails reset the topology to the old value.
2151 *
2152 * If the value is not in range log a kernel error message and return an error.
2153 *
2154 * Returns:
2155 * zero if val is in range and lip okay
2156 * non-zero return value from lpfc_issue_lip()
2157 * -EINVAL val out of range
2158 **/
James Smart83108bd2008-01-11 01:53:09 -05002159static int
2160lpfc_topology_set(struct lpfc_hba *phba, int val)
2161{
2162 int err;
2163 uint32_t prev_val;
2164 if (val >= 0 && val <= 6) {
2165 prev_val = phba->cfg_topology;
2166 phba->cfg_topology = val;
2167 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2168 if (err)
2169 phba->cfg_topology = prev_val;
2170 return err;
2171 }
2172 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2173 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2174 "allowed range is [0, 6]\n",
2175 phba->brd_no, val);
2176 return -EINVAL;
2177}
2178static int lpfc_topology = 0;
2179module_param(lpfc_topology, int, 0);
2180MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2181lpfc_param_show(topology)
2182lpfc_param_init(topology, 0, 0, 6)
2183lpfc_param_store(topology)
Tony Jonesee959b02008-02-22 00:13:36 +01002184static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002185 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002186
James Smartea2151b2008-09-07 11:52:10 -04002187
2188/**
2189 * lpfc_stat_data_ctrl_store: write call back for lpfc_stat_data_ctrl
2190 * sysfs file.
2191 * @dev: Pointer to class device.
2192 * @buf: Data buffer.
2193 * @count: Size of the data buffer.
2194 *
2195 * This function get called when an user write to the lpfc_stat_data_ctrl
2196 * sysfs file. This function parse the command written to the sysfs file
2197 * and take appropriate action. These commands are used for controlling
2198 * driver statistical data collection.
2199 * Following are the command this function handles.
2200 *
2201 * setbucket <bucket_type> <base> <step>
2202 * = Set the latency buckets.
2203 * destroybucket = destroy all the buckets.
2204 * start = start data collection
2205 * stop = stop data collection
2206 * reset = reset the collected data
2207 **/
2208static ssize_t
2209lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2210 const char *buf, size_t count)
2211{
2212 struct Scsi_Host *shost = class_to_shost(dev);
2213 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2214 struct lpfc_hba *phba = vport->phba;
2215#define LPFC_MAX_DATA_CTRL_LEN 1024
2216 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2217 unsigned long i;
2218 char *str_ptr, *token;
2219 struct lpfc_vport **vports;
2220 struct Scsi_Host *v_shost;
2221 char *bucket_type_str, *base_str, *step_str;
2222 unsigned long base, step, bucket_type;
2223
2224 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
2225 if (strlen(buf) > LPFC_MAX_DATA_CTRL_LEN)
2226 return -EINVAL;
2227
2228 strcpy(bucket_data, buf);
2229 str_ptr = &bucket_data[0];
2230 /* Ignore this token - this is command token */
2231 token = strsep(&str_ptr, "\t ");
2232 if (!token)
2233 return -EINVAL;
2234
2235 bucket_type_str = strsep(&str_ptr, "\t ");
2236 if (!bucket_type_str)
2237 return -EINVAL;
2238
2239 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2240 bucket_type = LPFC_LINEAR_BUCKET;
2241 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2242 bucket_type = LPFC_POWER2_BUCKET;
2243 else
2244 return -EINVAL;
2245
2246 base_str = strsep(&str_ptr, "\t ");
2247 if (!base_str)
2248 return -EINVAL;
2249 base = simple_strtoul(base_str, NULL, 0);
2250
2251 step_str = strsep(&str_ptr, "\t ");
2252 if (!step_str)
2253 return -EINVAL;
2254 step = simple_strtoul(step_str, NULL, 0);
2255 if (!step)
2256 return -EINVAL;
2257
2258 /* Block the data collection for every vport */
2259 vports = lpfc_create_vport_work_array(phba);
2260 if (vports == NULL)
2261 return -ENOMEM;
2262
2263 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
2264 v_shost = lpfc_shost_from_vport(vports[i]);
2265 spin_lock_irq(v_shost->host_lock);
2266 /* Block and reset data collection */
2267 vports[i]->stat_data_blocked = 1;
2268 if (vports[i]->stat_data_enabled)
2269 lpfc_vport_reset_stat_data(vports[i]);
2270 spin_unlock_irq(v_shost->host_lock);
2271 }
2272
2273 /* Set the bucket attributes */
2274 phba->bucket_type = bucket_type;
2275 phba->bucket_base = base;
2276 phba->bucket_step = step;
2277
2278 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
2279 v_shost = lpfc_shost_from_vport(vports[i]);
2280
2281 /* Unblock data collection */
2282 spin_lock_irq(v_shost->host_lock);
2283 vports[i]->stat_data_blocked = 0;
2284 spin_unlock_irq(v_shost->host_lock);
2285 }
2286 lpfc_destroy_vport_work_array(phba, vports);
2287 return strlen(buf);
2288 }
2289
2290 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2291 vports = lpfc_create_vport_work_array(phba);
2292 if (vports == NULL)
2293 return -ENOMEM;
2294
2295 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
2296 v_shost = lpfc_shost_from_vport(vports[i]);
2297 spin_lock_irq(shost->host_lock);
2298 vports[i]->stat_data_blocked = 1;
2299 lpfc_free_bucket(vport);
2300 vport->stat_data_enabled = 0;
2301 vports[i]->stat_data_blocked = 0;
2302 spin_unlock_irq(shost->host_lock);
2303 }
2304 lpfc_destroy_vport_work_array(phba, vports);
2305 phba->bucket_type = LPFC_NO_BUCKET;
2306 phba->bucket_base = 0;
2307 phba->bucket_step = 0;
2308 return strlen(buf);
2309 }
2310
2311 if (!strncmp(buf, "start", strlen("start"))) {
2312 /* If no buckets configured return error */
2313 if (phba->bucket_type == LPFC_NO_BUCKET)
2314 return -EINVAL;
2315 spin_lock_irq(shost->host_lock);
2316 if (vport->stat_data_enabled) {
2317 spin_unlock_irq(shost->host_lock);
2318 return strlen(buf);
2319 }
2320 lpfc_alloc_bucket(vport);
2321 vport->stat_data_enabled = 1;
2322 spin_unlock_irq(shost->host_lock);
2323 return strlen(buf);
2324 }
2325
2326 if (!strncmp(buf, "stop", strlen("stop"))) {
2327 spin_lock_irq(shost->host_lock);
2328 if (vport->stat_data_enabled == 0) {
2329 spin_unlock_irq(shost->host_lock);
2330 return strlen(buf);
2331 }
2332 lpfc_free_bucket(vport);
2333 vport->stat_data_enabled = 0;
2334 spin_unlock_irq(shost->host_lock);
2335 return strlen(buf);
2336 }
2337
2338 if (!strncmp(buf, "reset", strlen("reset"))) {
2339 if ((phba->bucket_type == LPFC_NO_BUCKET)
2340 || !vport->stat_data_enabled)
2341 return strlen(buf);
2342 spin_lock_irq(shost->host_lock);
2343 vport->stat_data_blocked = 1;
2344 lpfc_vport_reset_stat_data(vport);
2345 vport->stat_data_blocked = 0;
2346 spin_unlock_irq(shost->host_lock);
2347 return strlen(buf);
2348 }
2349 return -EINVAL;
2350}
2351
2352
2353/**
2354 * lpfc_stat_data_ctrl_show: Read callback function for
2355 * lpfc_stat_data_ctrl sysfs file.
2356 * @dev: Pointer to class device object.
2357 * @buf: Data buffer.
2358 *
2359 * This function is the read call back function for
2360 * lpfc_stat_data_ctrl sysfs file. This function report the
2361 * current statistical data collection state.
2362 **/
2363static ssize_t
2364lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2365 char *buf)
2366{
2367 struct Scsi_Host *shost = class_to_shost(dev);
2368 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2369 struct lpfc_hba *phba = vport->phba;
2370 int index = 0;
2371 int i;
2372 char *bucket_type;
2373 unsigned long bucket_value;
2374
2375 switch (phba->bucket_type) {
2376 case LPFC_LINEAR_BUCKET:
2377 bucket_type = "linear";
2378 break;
2379 case LPFC_POWER2_BUCKET:
2380 bucket_type = "power2";
2381 break;
2382 default:
2383 bucket_type = "No Bucket";
2384 break;
2385 }
2386
2387 sprintf(&buf[index], "Statistical Data enabled :%d, "
2388 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2389 " Bucket step :%d\nLatency Ranges :",
2390 vport->stat_data_enabled, vport->stat_data_blocked,
2391 bucket_type, phba->bucket_base, phba->bucket_step);
2392 index = strlen(buf);
2393 if (phba->bucket_type != LPFC_NO_BUCKET) {
2394 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2395 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2396 bucket_value = phba->bucket_base +
2397 phba->bucket_step * i;
2398 else
2399 bucket_value = phba->bucket_base +
2400 (1 << i) * phba->bucket_step;
2401
2402 if (index + 10 > PAGE_SIZE)
2403 break;
2404 sprintf(&buf[index], "%08ld ", bucket_value);
2405 index = strlen(buf);
2406 }
2407 }
2408 sprintf(&buf[index], "\n");
2409 return strlen(buf);
2410}
2411
2412/*
2413 * Sysfs attribute to control the statistical data collection.
2414 */
2415static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2416 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2417
2418/*
2419 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2420 */
2421
2422/*
2423 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2424 * for each target.
2425 */
2426#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2427#define MAX_STAT_DATA_SIZE_PER_TARGET \
2428 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2429
2430
2431/**
2432 * sysfs_drvr_stat_data_read: Read callback function for lpfc_drvr_stat_data
2433 * sysfs attribute.
2434 * @kobj: Pointer to the kernel object
2435 * @bin_attr: Attribute object
2436 * @buff: Buffer pointer
2437 * @off: File offset
2438 * @count: Buffer size
2439 *
2440 * This function is the read call back function for lpfc_drvr_stat_data
2441 * sysfs file. This function export the statistical data to user
2442 * applications.
2443 **/
2444static ssize_t
2445sysfs_drvr_stat_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2446 char *buf, loff_t off, size_t count)
2447{
2448 struct device *dev = container_of(kobj, struct device,
2449 kobj);
2450 struct Scsi_Host *shost = class_to_shost(dev);
2451 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2452 struct lpfc_hba *phba = vport->phba;
2453 int i = 0, index = 0;
2454 unsigned long nport_index;
2455 struct lpfc_nodelist *ndlp = NULL;
2456 nport_index = (unsigned long)off /
2457 MAX_STAT_DATA_SIZE_PER_TARGET;
2458
2459 if (!vport->stat_data_enabled || vport->stat_data_blocked
2460 || (phba->bucket_type == LPFC_NO_BUCKET))
2461 return 0;
2462
2463 spin_lock_irq(shost->host_lock);
2464 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2465 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2466 continue;
2467
2468 if (nport_index > 0) {
2469 nport_index--;
2470 continue;
2471 }
2472
2473 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2474 > count)
2475 break;
2476
2477 if (!ndlp->lat_data)
2478 continue;
2479
2480 /* Print the WWN */
2481 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2482 ndlp->nlp_portname.u.wwn[0],
2483 ndlp->nlp_portname.u.wwn[1],
2484 ndlp->nlp_portname.u.wwn[2],
2485 ndlp->nlp_portname.u.wwn[3],
2486 ndlp->nlp_portname.u.wwn[4],
2487 ndlp->nlp_portname.u.wwn[5],
2488 ndlp->nlp_portname.u.wwn[6],
2489 ndlp->nlp_portname.u.wwn[7]);
2490
2491 index = strlen(buf);
2492
2493 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2494 sprintf(&buf[index], "%010u,",
2495 ndlp->lat_data[i].cmd_count);
2496 index = strlen(buf);
2497 }
2498 sprintf(&buf[index], "\n");
2499 index = strlen(buf);
2500 }
2501 spin_unlock_irq(shost->host_lock);
2502 return index;
2503}
2504
2505static struct bin_attribute sysfs_drvr_stat_data_attr = {
2506 .attr = {
2507 .name = "lpfc_drvr_stat_data",
2508 .mode = S_IRUSR,
2509 .owner = THIS_MODULE,
2510 },
2511 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2512 .read = sysfs_drvr_stat_data_read,
2513 .write = NULL,
2514};
2515
dea31012005-04-17 16:05:31 -05002516/*
2517# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2518# connection.
2519# 0 = auto select (default)
2520# 1 = 1 Gigabaud
2521# 2 = 2 Gigabaud
2522# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04002523# 8 = 8 Gigabaud
2524# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05002525*/
James Smarte59058c2008-08-24 21:49:00 -04002526
2527/**
2528 * lpfc_link_speed_set: Set the adapters link speed.
2529 * @phba: lpfc_hba pointer.
2530 * @val: link speed value.
2531 *
2532 * Description:
2533 * If val is in a valid range then set the adapter's link speed field and
2534 * issue a lip; if the lip fails reset the link speed to the old value.
2535 *
2536 * Notes:
2537 * If the value is not in range log a kernel error message and return an error.
2538 *
2539 * Returns:
2540 * zero if val is in range and lip okay.
2541 * non-zero return value from lpfc_issue_lip()
2542 * -EINVAL val out of range
2543 **/
James Smart83108bd2008-01-11 01:53:09 -05002544static int
2545lpfc_link_speed_set(struct lpfc_hba *phba, int val)
2546{
2547 int err;
2548 uint32_t prev_val;
2549
2550 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2551 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2552 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2553 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2554 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2555 return -EINVAL;
2556
2557 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2558 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2559 prev_val = phba->cfg_link_speed;
2560 phba->cfg_link_speed = val;
2561 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2562 if (err)
2563 phba->cfg_link_speed = prev_val;
2564 return err;
2565 }
2566
2567 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2568 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2569 "allowed range is [0, 8]\n",
2570 phba->brd_no, val);
2571 return -EINVAL;
2572}
2573
2574static int lpfc_link_speed = 0;
2575module_param(lpfc_link_speed, int, 0);
2576MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2577lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002578
2579/**
2580 * lpfc_link_speed_init: Set the adapters link speed.
2581 * @phba: lpfc_hba pointer.
2582 * @val: link speed value.
2583 *
2584 * Description:
2585 * If val is in a valid range then set the adapter's link speed field.
2586 *
2587 * Notes:
2588 * If the value is not in range log a kernel error message, clear the link
2589 * speed and return an error.
2590 *
2591 * Returns:
2592 * zero if val saved.
2593 * -EINVAL val out of range
2594 **/
James Smart83108bd2008-01-11 01:53:09 -05002595static int
2596lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2597{
2598 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2599 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2600 phba->cfg_link_speed = val;
2601 return 0;
2602 }
2603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002604 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002605 "be set to %d, allowed values are "
2606 "["LPFC_LINK_SPEED_STRING"]\n", val);
2607 phba->cfg_link_speed = 0;
2608 return -EINVAL;
2609}
2610
2611lpfc_param_store(link_speed)
Tony Jonesee959b02008-02-22 00:13:36 +01002612static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002613 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002614
2615/*
2616# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
2617# Value range is [2,3]. Default value is 3.
2618*/
James Smart3de2a652007-08-02 11:09:59 -04002619LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
2620 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05002621
2622/*
2623# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
2624# is [0,1]. Default value is 0.
2625*/
James Smart3de2a652007-08-02 11:09:59 -04002626LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
2627 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05002628
2629/*
James Smart977b5a02008-09-07 11:52:04 -04002630# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
2631# depth. Default value is 0. When the value of this parameter is zero the
2632# SCSI command completion time is not used for controlling I/O queue depth. When
2633# the parameter is set to a non-zero value, the I/O queue depth is controlled
2634# to limit the I/O completion time to the parameter value.
2635# The value is set in milliseconds.
2636*/
2637static int lpfc_max_scsicmpl_time;
2638module_param(lpfc_max_scsicmpl_time, int, 0);
2639MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
2640 "Use command completion time to control queue depth");
2641lpfc_vport_param_show(max_scsicmpl_time);
2642lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
2643static int
2644lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
2645{
2646 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2647 struct lpfc_nodelist *ndlp, *next_ndlp;
2648
2649 if (val == vport->cfg_max_scsicmpl_time)
2650 return 0;
2651 if ((val < 0) || (val > 60000))
2652 return -EINVAL;
2653 vport->cfg_max_scsicmpl_time = val;
2654
2655 spin_lock_irq(shost->host_lock);
2656 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2657 if (!NLP_CHK_NODE_ACT(ndlp))
2658 continue;
2659 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2660 continue;
2661 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
2662 }
2663 spin_unlock_irq(shost->host_lock);
2664 return 0;
2665}
2666lpfc_vport_param_store(max_scsicmpl_time);
2667static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
2668 lpfc_max_scsicmpl_time_show,
2669 lpfc_max_scsicmpl_time_store);
2670
2671/*
dea31012005-04-17 16:05:31 -05002672# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
2673# range is [0,1]. Default value is 0.
2674*/
2675LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
2676
2677/*
2678# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
2679# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04002680# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05002681# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
2682# cr_delay is set to 0.
2683*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05002684LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05002685 "interrupt response is generated");
2686
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05002687LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05002688 "interrupt response is generated");
2689
2690/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002691# lpfc_multi_ring_support: Determines how many rings to spread available
2692# cmd/rsp IOCB entries across.
2693# Value range is [1,2]. Default value is 1.
2694*/
2695LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
2696 "SLI rings to spread IOCB entries across");
2697
2698/*
James Smarta4bc3372006-12-02 13:34:16 -05002699# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
2700# identifies what rctl value to configure the additional ring for.
2701# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
2702*/
2703LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
2704 255, "Identifies RCTL for additional ring configuration");
2705
2706/*
2707# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
2708# identifies what type value to configure the additional ring for.
2709# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
2710*/
2711LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
2712 255, "Identifies TYPE for additional ring configuration");
2713
2714/*
dea31012005-04-17 16:05:31 -05002715# lpfc_fdmi_on: controls FDMI support.
2716# 0 = no FDMI support
2717# 1 = support FDMI without attribute of hostname
2718# 2 = support FDMI with attribute of hostname
2719# Value range [0,2]. Default value is 0.
2720*/
James Smart3de2a652007-08-02 11:09:59 -04002721LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05002722
2723/*
2724# Specifies the maximum number of ELS cmds we can have outstanding (for
2725# discovery). Value range is [1,64]. Default value = 32.
2726*/
James Smart3de2a652007-08-02 11:09:59 -04002727LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05002728 "during discovery");
2729
2730/*
James Smart65a29c12006-07-06 15:50:50 -04002731# lpfc_max_luns: maximum allowed LUN.
2732# Value range is [0,65535]. Default value is 255.
2733# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05002734*/
James Smart3de2a652007-08-02 11:09:59 -04002735LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05002736
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002737/*
2738# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
2739# Value range is [1,255], default value is 10.
2740*/
2741LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
2742 "Milliseconds driver will wait between polling FCP ring");
2743
James Smart4ff43242006-12-02 13:34:56 -05002744/*
2745# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
2746# support this feature
James Smart93996272008-08-24 21:50:30 -04002747# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05002748# 1 = MSI enabled
James Smart93996272008-08-24 21:50:30 -04002749# 2 = MSI-X enabled (default)
2750# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05002751*/
James Smart93996272008-08-24 21:50:30 -04002752LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05002753 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05002754
James Smart13815c82008-01-11 01:52:48 -05002755/*
2756# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
2757# 0 = HBA resets disabled
2758# 1 = HBA resets enabled (default)
2759# Value range is [0,1]. Default value is 1.
2760*/
2761LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04002762
James Smart13815c82008-01-11 01:52:48 -05002763/*
2764# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
2765# 0 = HBA Heartbeat disabled
2766# 1 = HBA Heartbeat enabled (default)
2767# Value range is [0,1]. Default value is 1.
2768*/
2769LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05002770
James Smart83108bd2008-01-11 01:53:09 -05002771/*
2772 * lpfc_sg_seg_cnt: Initial Maximum DMA Segment Count
2773 * This value can be set to values between 64 and 256. The default value is
2774 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
2775 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
2776 */
2777LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
2778 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
2779
Tony Jonesee959b02008-02-22 00:13:36 +01002780struct device_attribute *lpfc_hba_attrs[] = {
2781 &dev_attr_info,
2782 &dev_attr_serialnum,
2783 &dev_attr_modeldesc,
2784 &dev_attr_modelname,
2785 &dev_attr_programtype,
2786 &dev_attr_portnum,
2787 &dev_attr_fwrev,
2788 &dev_attr_hdw,
2789 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01002790 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01002791 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04002792 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01002793 &dev_attr_lpfc_drvr_version,
2794 &dev_attr_lpfc_temp_sensor,
2795 &dev_attr_lpfc_log_verbose,
2796 &dev_attr_lpfc_lun_queue_depth,
2797 &dev_attr_lpfc_hba_queue_depth,
2798 &dev_attr_lpfc_peer_port_login,
2799 &dev_attr_lpfc_nodev_tmo,
2800 &dev_attr_lpfc_devloss_tmo,
2801 &dev_attr_lpfc_fcp_class,
2802 &dev_attr_lpfc_use_adisc,
2803 &dev_attr_lpfc_ack0,
2804 &dev_attr_lpfc_topology,
2805 &dev_attr_lpfc_scan_down,
2806 &dev_attr_lpfc_link_speed,
2807 &dev_attr_lpfc_cr_delay,
2808 &dev_attr_lpfc_cr_count,
2809 &dev_attr_lpfc_multi_ring_support,
2810 &dev_attr_lpfc_multi_ring_rctl,
2811 &dev_attr_lpfc_multi_ring_type,
2812 &dev_attr_lpfc_fdmi_on,
2813 &dev_attr_lpfc_max_luns,
2814 &dev_attr_lpfc_enable_npiv,
2815 &dev_attr_nport_evt_cnt,
2816 &dev_attr_board_mode,
2817 &dev_attr_max_vpi,
2818 &dev_attr_used_vpi,
2819 &dev_attr_max_rpi,
2820 &dev_attr_used_rpi,
2821 &dev_attr_max_xri,
2822 &dev_attr_used_xri,
2823 &dev_attr_npiv_info,
2824 &dev_attr_issue_reset,
2825 &dev_attr_lpfc_poll,
2826 &dev_attr_lpfc_poll_tmo,
2827 &dev_attr_lpfc_use_msi,
2828 &dev_attr_lpfc_soft_wwnn,
2829 &dev_attr_lpfc_soft_wwpn,
2830 &dev_attr_lpfc_soft_wwn_enable,
2831 &dev_attr_lpfc_enable_hba_reset,
2832 &dev_attr_lpfc_enable_hba_heartbeat,
2833 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04002834 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04002835 &dev_attr_lpfc_stat_data_ctrl,
dea31012005-04-17 16:05:31 -05002836 NULL,
2837};
2838
Tony Jonesee959b02008-02-22 00:13:36 +01002839struct device_attribute *lpfc_vport_attrs[] = {
2840 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01002841 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01002842 &dev_attr_num_discovered_ports,
2843 &dev_attr_lpfc_drvr_version,
2844 &dev_attr_lpfc_log_verbose,
2845 &dev_attr_lpfc_lun_queue_depth,
2846 &dev_attr_lpfc_nodev_tmo,
2847 &dev_attr_lpfc_devloss_tmo,
2848 &dev_attr_lpfc_hba_queue_depth,
2849 &dev_attr_lpfc_peer_port_login,
2850 &dev_attr_lpfc_restrict_login,
2851 &dev_attr_lpfc_fcp_class,
2852 &dev_attr_lpfc_use_adisc,
2853 &dev_attr_lpfc_fdmi_on,
2854 &dev_attr_lpfc_max_luns,
2855 &dev_attr_nport_evt_cnt,
2856 &dev_attr_npiv_info,
2857 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04002858 &dev_attr_lpfc_max_scsicmpl_time,
2859 &dev_attr_lpfc_stat_data_ctrl,
James Smart3de2a652007-08-02 11:09:59 -04002860 NULL,
2861};
2862
James Smarte59058c2008-08-24 21:49:00 -04002863/**
2864 * sysfs_ctlreg_write: Write method for writing to ctlreg.
2865 * @kobj: kernel kobject that contains the kernel class device.
2866 * @bin_attr: kernel attributes passed to us.
2867 * @buf: contains the data to be written to the adapter IOREG space.
2868 * @off: offset into buffer to beginning of data.
2869 * @count: bytes to transfer.
2870 *
2871 * Description:
2872 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
2873 * Uses the adapter io control registers to send buf contents to the adapter.
2874 *
2875 * Returns:
2876 * -ERANGE off and count combo out of range
2877 * -EINVAL off, count or buff address invalid
2878 * -EPERM adapter is offline
2879 * value of count, buf contents written
2880 **/
dea31012005-04-17 16:05:31 -05002881static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08002882sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
2883 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05002884{
2885 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01002886 struct device *dev = container_of(kobj, struct device, kobj);
2887 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002888 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2889 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002890
2891 if ((off + count) > FF_REG_AREA_SIZE)
2892 return -ERANGE;
2893
2894 if (count == 0) return 0;
2895
2896 if (off % 4 || count % 4 || (unsigned long)buf % 4)
2897 return -EINVAL;
2898
James Smart2e0fef82007-06-17 19:56:36 -05002899 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05002900 return -EPERM;
2901 }
2902
James Smart2e0fef82007-06-17 19:56:36 -05002903 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002904 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
2905 writel(*((uint32_t *)(buf + buf_off)),
2906 phba->ctrl_regs_memmap_p + off + buf_off);
2907
James Smart2e0fef82007-06-17 19:56:36 -05002908 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002909
2910 return count;
2911}
2912
James Smarte59058c2008-08-24 21:49:00 -04002913/**
2914 * sysfs_ctlreg_read: Read method for reading from ctlreg.
2915 * @kobj: kernel kobject that contains the kernel class device.
2916 * @bin_attr: kernel attributes passed to us.
2917 * @buf: if succesful contains the data from the adapter IOREG space.
2918 * @off: offset into buffer to beginning of data.
2919 * @count: bytes to transfer.
2920 *
2921 * Description:
2922 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
2923 * Uses the adapter io control registers to read data into buf.
2924 *
2925 * Returns:
2926 * -ERANGE off and count combo out of range
2927 * -EINVAL off, count or buff address invalid
2928 * value of count, buf contents read
2929 **/
dea31012005-04-17 16:05:31 -05002930static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08002931sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2932 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05002933{
2934 size_t buf_off;
2935 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01002936 struct device *dev = container_of(kobj, struct device, kobj);
2937 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002938 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2939 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002940
2941 if (off > FF_REG_AREA_SIZE)
2942 return -ERANGE;
2943
2944 if ((off + count) > FF_REG_AREA_SIZE)
2945 count = FF_REG_AREA_SIZE - off;
2946
2947 if (count == 0) return 0;
2948
2949 if (off % 4 || count % 4 || (unsigned long)buf % 4)
2950 return -EINVAL;
2951
James Smart2e0fef82007-06-17 19:56:36 -05002952 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002953
2954 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
2955 tmp_ptr = (uint32_t *)(buf + buf_off);
2956 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
2957 }
2958
James Smart2e0fef82007-06-17 19:56:36 -05002959 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002960
2961 return count;
2962}
2963
2964static struct bin_attribute sysfs_ctlreg_attr = {
2965 .attr = {
2966 .name = "ctlreg",
2967 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05002968 },
2969 .size = 256,
2970 .read = sysfs_ctlreg_read,
2971 .write = sysfs_ctlreg_write,
2972};
2973
James Smarte59058c2008-08-24 21:49:00 -04002974/**
2975 * sysfs_mbox_idle: frees the sysfs mailbox.
2976 * @phba: lpfc_hba pointer
2977 **/
dea31012005-04-17 16:05:31 -05002978static void
James Smart2e0fef82007-06-17 19:56:36 -05002979sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002980{
2981 phba->sysfs_mbox.state = SMBOX_IDLE;
2982 phba->sysfs_mbox.offset = 0;
2983
2984 if (phba->sysfs_mbox.mbox) {
2985 mempool_free(phba->sysfs_mbox.mbox,
2986 phba->mbox_mem_pool);
2987 phba->sysfs_mbox.mbox = NULL;
2988 }
2989}
2990
James Smarte59058c2008-08-24 21:49:00 -04002991/**
2992 * sysfs_mbox_write: Write method for writing information via mbox.
2993 * @kobj: kernel kobject that contains the kernel class device.
2994 * @bin_attr: kernel attributes passed to us.
2995 * @buf: contains the data to be written to sysfs mbox.
2996 * @off: offset into buffer to beginning of data.
2997 * @count: bytes to transfer.
2998 *
2999 * Description:
3000 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3001 * Uses the sysfs mbox to send buf contents to the adapter.
3002 *
3003 * Returns:
3004 * -ERANGE off and count combo out of range
3005 * -EINVAL off, count or buff address invalid
3006 * zero if count is zero
3007 * -EPERM adapter is offline
3008 * -ENOMEM failed to allocate memory for the mail box
3009 * -EAGAIN offset, state or mbox is NULL
3010 * count number of bytes transferred
3011 **/
dea31012005-04-17 16:05:31 -05003012static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003013sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3014 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003015{
Tony Jonesee959b02008-02-22 00:13:36 +01003016 struct device *dev = container_of(kobj, struct device, kobj);
3017 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003018 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3019 struct lpfc_hba *phba = vport->phba;
3020 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05003021
3022 if ((count + off) > MAILBOX_CMD_SIZE)
3023 return -ERANGE;
3024
3025 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3026 return -EINVAL;
3027
3028 if (count == 0)
3029 return 0;
3030
3031 if (off == 0) {
3032 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3033 if (!mbox)
3034 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05003035 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003036 }
3037
James Smart2e0fef82007-06-17 19:56:36 -05003038 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003039
3040 if (off == 0) {
3041 if (phba->sysfs_mbox.mbox)
3042 mempool_free(mbox, phba->mbox_mem_pool);
3043 else
3044 phba->sysfs_mbox.mbox = mbox;
3045 phba->sysfs_mbox.state = SMBOX_WRITING;
3046 } else {
3047 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3048 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05003049 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05003050 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003051 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003052 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003053 }
3054 }
3055
3056 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
3057 buf, count);
3058
3059 phba->sysfs_mbox.offset = off + count;
3060
James Smart2e0fef82007-06-17 19:56:36 -05003061 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003062
3063 return count;
3064}
3065
James Smarte59058c2008-08-24 21:49:00 -04003066/**
3067 * sysfs_mbox_read: Read method for reading information via mbox.
3068 * @kobj: kernel kobject that contains the kernel class device.
3069 * @bin_attr: kernel attributes passed to us.
3070 * @buf: contains the data to be read from sysfs mbox.
3071 * @off: offset into buffer to beginning of data.
3072 * @count: bytes to transfer.
3073 *
3074 * Description:
3075 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3076 * Uses the sysfs mbox to receive data from to the adapter.
3077 *
3078 * Returns:
3079 * -ERANGE off greater than mailbox command size
3080 * -EINVAL off, count or buff address invalid
3081 * zero if off and count are zero
3082 * -EACCES adapter over temp
3083 * -EPERM garbage can value to catch a multitude of errors
3084 * -EAGAIN management IO not permitted, state or off error
3085 * -ETIME mailbox timeout
3086 * -ENODEV mailbox error
3087 * count number of bytes transferred
3088 **/
dea31012005-04-17 16:05:31 -05003089static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08003090sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3091 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05003092{
Tony Jonesee959b02008-02-22 00:13:36 +01003093 struct device *dev = container_of(kobj, struct device, kobj);
3094 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003095 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3096 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003097 int rc;
3098
James Smart1dcb58e2007-04-25 09:51:30 -04003099 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003100 return -ERANGE;
3101
James Smart1dcb58e2007-04-25 09:51:30 -04003102 if ((count + off) > MAILBOX_CMD_SIZE)
3103 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05003104
3105 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3106 return -EINVAL;
3107
3108 if (off && count == 0)
3109 return 0;
3110
James Smart2e0fef82007-06-17 19:56:36 -05003111 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003112
James Smart7af67052007-10-27 13:38:11 -04003113 if (phba->over_temp_state == HBA_OVER_TEMP) {
3114 sysfs_mbox_idle(phba);
3115 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05003116 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04003117 }
3118
dea31012005-04-17 16:05:31 -05003119 if (off == 0 &&
3120 phba->sysfs_mbox.state == SMBOX_WRITING &&
3121 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
3122
3123 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
3124 /* Offline only */
dea31012005-04-17 16:05:31 -05003125 case MBX_INIT_LINK:
3126 case MBX_DOWN_LINK:
3127 case MBX_CONFIG_LINK:
3128 case MBX_CONFIG_RING:
3129 case MBX_RESET_RING:
3130 case MBX_UNREG_LOGIN:
3131 case MBX_CLEAR_LA:
3132 case MBX_DUMP_CONTEXT:
3133 case MBX_RUN_DIAGS:
3134 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05003135 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05003136 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05003137 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05003138 printk(KERN_WARNING "mbox_read:Command 0x%x "
3139 "is illegal in on-line state\n",
3140 phba->sysfs_mbox.mbox->mb.mbxCommand);
3141 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003142 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003143 return -EPERM;
3144 }
James Smarta8adb832007-10-27 13:37:53 -04003145 case MBX_WRITE_NV:
3146 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05003147 case MBX_LOAD_SM:
3148 case MBX_READ_NV:
3149 case MBX_READ_CONFIG:
3150 case MBX_READ_RCONFIG:
3151 case MBX_READ_STATUS:
3152 case MBX_READ_XRI:
3153 case MBX_READ_REV:
3154 case MBX_READ_LNK_STAT:
3155 case MBX_DUMP_MEMORY:
3156 case MBX_DOWN_LOAD:
3157 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003158 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05003159 case MBX_LOAD_AREA:
3160 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05003161 case MBX_BEACON:
3162 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05003163 case MBX_SET_VARIABLE:
3164 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04003165 case MBX_PORT_CAPABILITIES:
3166 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05003167 break;
3168 case MBX_READ_SPARM64:
3169 case MBX_READ_LA:
3170 case MBX_READ_LA64:
3171 case MBX_REG_LOGIN:
3172 case MBX_REG_LOGIN64:
3173 case MBX_CONFIG_PORT:
3174 case MBX_RUN_BIU_DIAG:
3175 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
3176 phba->sysfs_mbox.mbox->mb.mbxCommand);
3177 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003178 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003179 return -EPERM;
3180 default:
3181 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
3182 phba->sysfs_mbox.mbox->mb.mbxCommand);
3183 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003184 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003185 return -EPERM;
3186 }
3187
James Smart09372822008-01-11 01:52:54 -05003188 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05003189 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05003190 */
James Smartd7c255b2008-08-24 21:50:00 -04003191 if (phba->pport->stopped &&
3192 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_DUMP_MEMORY &&
3193 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_RESTART &&
3194 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_WRITE_VPARMS &&
3195 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_WRITE_WWN)
3196 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3197 "1259 mbox: Issued mailbox cmd "
3198 "0x%x while in stopped state.\n",
3199 phba->sysfs_mbox.mbox->mb.mbxCommand);
James Smart09372822008-01-11 01:52:54 -05003200
James Smart92d7f7b2007-06-17 19:56:38 -05003201 phba->sysfs_mbox.mbox->vport = vport;
3202
James Smart58da1ff2008-04-07 10:15:56 -04003203 /* Don't allow mailbox commands to be sent when blocked
3204 * or when in the middle of discovery
3205 */
James Smart495a7142008-06-14 22:52:59 -04003206 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04003207 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003208 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04003209 return -EAGAIN;
3210 }
3211
James Smart2e0fef82007-06-17 19:56:36 -05003212 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
dea31012005-04-17 16:05:31 -05003213 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
3214
James Smart2e0fef82007-06-17 19:56:36 -05003215 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003216 rc = lpfc_sli_issue_mbox (phba,
3217 phba->sysfs_mbox.mbox,
3218 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05003219 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003220
3221 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003222 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003223 rc = lpfc_sli_issue_mbox_wait (phba,
3224 phba->sysfs_mbox.mbox,
James Smarta309a6b2006-08-01 07:33:43 -04003225 lpfc_mbox_tmo_val(phba,
3226 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05003227 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003228 }
3229
3230 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04003231 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04003232 phba->sysfs_mbox.mbox = NULL;
3233 }
dea31012005-04-17 16:05:31 -05003234 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003235 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003236 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05003237 }
3238 phba->sysfs_mbox.state = SMBOX_READING;
3239 }
3240 else if (phba->sysfs_mbox.offset != off ||
3241 phba->sysfs_mbox.state != SMBOX_READING) {
3242 printk(KERN_WARNING "mbox_read: Bad State\n");
3243 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003244 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04003245 return -EAGAIN;
dea31012005-04-17 16:05:31 -05003246 }
3247
3248 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
3249
3250 phba->sysfs_mbox.offset = off + count;
3251
James Smart1dcb58e2007-04-25 09:51:30 -04003252 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05003253 sysfs_mbox_idle(phba);
3254
James Smart2e0fef82007-06-17 19:56:36 -05003255 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003256
3257 return count;
3258}
3259
3260static struct bin_attribute sysfs_mbox_attr = {
3261 .attr = {
3262 .name = "mbox",
3263 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05003264 },
James Smart1dcb58e2007-04-25 09:51:30 -04003265 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05003266 .read = sysfs_mbox_read,
3267 .write = sysfs_mbox_write,
3268};
3269
James Smarte59058c2008-08-24 21:49:00 -04003270/**
James Smart84774a42008-08-24 21:50:06 -04003271 * lpfc_alloc_sysfs_attr: Creates the ctlreg and mbox entries.
James Smarte59058c2008-08-24 21:49:00 -04003272 * @vport: address of lpfc vport structure.
3273 *
3274 * Return codes:
3275 * zero on success
3276 * error return code from sysfs_create_bin_file()
3277 **/
dea31012005-04-17 16:05:31 -05003278int
James Smart2e0fef82007-06-17 19:56:36 -05003279lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003280{
James Smart2e0fef82007-06-17 19:56:36 -05003281 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003282 int error;
3283
Tony Jonesee959b02008-02-22 00:13:36 +01003284 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05003285 &sysfs_drvr_stat_data_attr);
3286
3287 /* Virtual ports do not need ctrl_reg and mbox */
3288 if (error || vport->port_type == LPFC_NPIV_PORT)
3289 goto out;
3290
3291 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003292 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003293 if (error)
James Smarteada2722008-12-04 22:39:13 -05003294 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05003295
Tony Jonesee959b02008-02-22 00:13:36 +01003296 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05003297 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05003298 if (error)
3299 goto out_remove_ctlreg_attr;
3300
3301 return 0;
3302out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01003303 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05003304out_remove_stat_attr:
3305 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3306 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05003307out:
3308 return error;
3309}
3310
James Smarte59058c2008-08-24 21:49:00 -04003311/**
James Smart84774a42008-08-24 21:50:06 -04003312 * lpfc_free_sysfs_attr: Removes the ctlreg and mbox entries.
James Smarte59058c2008-08-24 21:49:00 -04003313 * @vport: address of lpfc vport structure.
3314 **/
dea31012005-04-17 16:05:31 -05003315void
James Smart2e0fef82007-06-17 19:56:36 -05003316lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003317{
James Smart2e0fef82007-06-17 19:56:36 -05003318 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04003319 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3320 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05003321 /* Virtual ports do not need ctrl_reg and mbox */
3322 if (vport->port_type == LPFC_NPIV_PORT)
3323 return;
Tony Jonesee959b02008-02-22 00:13:36 +01003324 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3325 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05003326}
3327
3328
3329/*
3330 * Dynamic FC Host Attributes Support
3331 */
3332
James Smarte59058c2008-08-24 21:49:00 -04003333/**
3334 * lpfc_get_host_port_id: Copy the vport DID into the scsi host port id.
3335 * @shost: kernel scsi host pointer.
3336 **/
dea31012005-04-17 16:05:31 -05003337static void
3338lpfc_get_host_port_id(struct Scsi_Host *shost)
3339{
James Smart2e0fef82007-06-17 19:56:36 -05003340 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3341
dea31012005-04-17 16:05:31 -05003342 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05003343 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05003344}
3345
James Smarte59058c2008-08-24 21:49:00 -04003346/**
3347 * lpfc_get_host_port_type: Set the value of the scsi host port type.
3348 * @shost: kernel scsi host pointer.
3349 **/
dea31012005-04-17 16:05:31 -05003350static void
3351lpfc_get_host_port_type(struct Scsi_Host *shost)
3352{
James Smart2e0fef82007-06-17 19:56:36 -05003353 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3354 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003355
3356 spin_lock_irq(shost->host_lock);
3357
James Smart92d7f7b2007-06-17 19:56:38 -05003358 if (vport->port_type == LPFC_NPIV_PORT) {
3359 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3360 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003361 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05003362 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05003363 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3364 else
3365 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3366 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003367 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05003368 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3369 else
3370 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3371 }
3372 } else
3373 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3374
3375 spin_unlock_irq(shost->host_lock);
3376}
3377
James Smarte59058c2008-08-24 21:49:00 -04003378/**
3379 * lpfc_get_host_port_state: Set the value of the scsi host port state.
3380 * @shost: kernel scsi host pointer.
3381 **/
dea31012005-04-17 16:05:31 -05003382static void
3383lpfc_get_host_port_state(struct Scsi_Host *shost)
3384{
James Smart2e0fef82007-06-17 19:56:36 -05003385 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3386 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003387
3388 spin_lock_irq(shost->host_lock);
3389
James Smart2e0fef82007-06-17 19:56:36 -05003390 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05003391 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3392 else {
James Smart2e0fef82007-06-17 19:56:36 -05003393 switch (phba->link_state) {
3394 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05003395 case LPFC_LINK_DOWN:
3396 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3397 break;
3398 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05003399 case LPFC_CLEAR_LA:
3400 case LPFC_HBA_READY:
3401 /* Links up, beyond this port_type reports state */
3402 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3403 break;
3404 case LPFC_HBA_ERROR:
3405 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3406 break;
3407 default:
3408 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3409 break;
3410 }
3411 }
3412
3413 spin_unlock_irq(shost->host_lock);
3414}
3415
James Smarte59058c2008-08-24 21:49:00 -04003416/**
3417 * lpfc_get_host_speed: Set the value of the scsi host speed.
3418 * @shost: kernel scsi host pointer.
3419 **/
dea31012005-04-17 16:05:31 -05003420static void
3421lpfc_get_host_speed(struct Scsi_Host *shost)
3422{
James Smart2e0fef82007-06-17 19:56:36 -05003423 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3424 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003425
3426 spin_lock_irq(shost->host_lock);
3427
James Smart2e0fef82007-06-17 19:56:36 -05003428 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003429 switch(phba->fc_linkspeed) {
3430 case LA_1GHZ_LINK:
3431 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
3432 break;
3433 case LA_2GHZ_LINK:
3434 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
3435 break;
3436 case LA_4GHZ_LINK:
3437 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
3438 break;
James Smartb87eab32007-04-25 09:53:28 -04003439 case LA_8GHZ_LINK:
3440 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
3441 break;
dea31012005-04-17 16:05:31 -05003442 default:
3443 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3444 break;
3445 }
James Smart09372822008-01-11 01:52:54 -05003446 } else
3447 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05003448
3449 spin_unlock_irq(shost->host_lock);
3450}
3451
James Smarte59058c2008-08-24 21:49:00 -04003452/**
3453 * lpfc_get_host_fabric_name: Set the value of the scsi host fabric name.
3454 * @shost: kernel scsi host pointer.
3455 **/
dea31012005-04-17 16:05:31 -05003456static void
3457lpfc_get_host_fabric_name (struct Scsi_Host *shost)
3458{
James Smart2e0fef82007-06-17 19:56:36 -05003459 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3460 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003461 u64 node_name;
dea31012005-04-17 16:05:31 -05003462
3463 spin_lock_irq(shost->host_lock);
3464
James Smart2e0fef82007-06-17 19:56:36 -05003465 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05003466 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05003467 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07003468 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05003469 else
3470 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05003471 node_name = 0;
dea31012005-04-17 16:05:31 -05003472
3473 spin_unlock_irq(shost->host_lock);
3474
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003475 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05003476}
3477
James Smarte59058c2008-08-24 21:49:00 -04003478/**
3479 * lpfc_get_stats: Return statistical information about the adapter.
3480 * @shost: kernel scsi host pointer.
3481 *
3482 * Notes:
3483 * NULL on error for link down, no mbox pool, sli2 active,
3484 * management not allowed, memory allocation error, or mbox error.
3485 *
3486 * Returns:
3487 * NULL for error
3488 * address of the adapter host statistics
3489 **/
dea31012005-04-17 16:05:31 -05003490static struct fc_host_statistics *
3491lpfc_get_stats(struct Scsi_Host *shost)
3492{
James Smart2e0fef82007-06-17 19:56:36 -05003493 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3494 struct lpfc_hba *phba = vport->phba;
3495 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003496 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04003497 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05003498 LPFC_MBOXQ_t *pmboxq;
3499 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04003500 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003501 int rc = 0;
dea31012005-04-17 16:05:31 -05003502
James Smart92d7f7b2007-06-17 19:56:38 -05003503 /*
3504 * prevent udev from issuing mailbox commands until the port is
3505 * configured.
3506 */
James Smart2e0fef82007-06-17 19:56:36 -05003507 if (phba->link_state < LPFC_LINK_DOWN ||
3508 !phba->mbox_mem_pool ||
3509 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003510 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003511
3512 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04003513 return NULL;
3514
dea31012005-04-17 16:05:31 -05003515 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3516 if (!pmboxq)
3517 return NULL;
3518 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3519
3520 pmb = &pmboxq->mb;
3521 pmb->mbxCommand = MBX_READ_STATUS;
3522 pmb->mbxOwner = OWN_HOST;
3523 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003524 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05003525
James Smart2e0fef82007-06-17 19:56:36 -05003526 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003527 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05003528 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003529 else
dea31012005-04-17 16:05:31 -05003530 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3531
3532 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003533 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003534 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003535 return NULL;
3536 }
3537
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003538 memset(hs, 0, sizeof (struct fc_host_statistics));
3539
dea31012005-04-17 16:05:31 -05003540 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
3541 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
3542 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
3543 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
3544
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003545 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003546 pmb->mbxCommand = MBX_READ_LNK_STAT;
3547 pmb->mbxOwner = OWN_HOST;
3548 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003549 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05003550
James Smart2e0fef82007-06-17 19:56:36 -05003551 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003552 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05003553 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003554 else
dea31012005-04-17 16:05:31 -05003555 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3556
3557 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003558 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05003559 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003560 return NULL;
3561 }
3562
3563 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3564 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3565 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3566 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3567 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3568 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3569 hs->error_frames = pmb->un.varRdLnk.crcCnt;
3570
James Smart64ba8812006-08-02 15:24:34 -04003571 hs->link_failure_count -= lso->link_failure_count;
3572 hs->loss_of_sync_count -= lso->loss_of_sync_count;
3573 hs->loss_of_signal_count -= lso->loss_of_signal_count;
3574 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
3575 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
3576 hs->invalid_crc_count -= lso->invalid_crc_count;
3577 hs->error_frames -= lso->error_frames;
3578
dea31012005-04-17 16:05:31 -05003579 if (phba->fc_topology == TOPOLOGY_LOOP) {
3580 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04003581 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05003582 hs->nos_count = -1;
3583 } else {
3584 hs->lip_count = -1;
3585 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04003586 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05003587 }
3588
3589 hs->dumped_frames = -1;
3590
James Smart64ba8812006-08-02 15:24:34 -04003591 seconds = get_seconds();
3592 if (seconds < psli->stats_start)
3593 hs->seconds_since_last_reset = seconds +
3594 ((unsigned long)-1 - psli->stats_start);
3595 else
3596 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05003597
James Smart1dcb58e2007-04-25 09:51:30 -04003598 mempool_free(pmboxq, phba->mbox_mem_pool);
3599
dea31012005-04-17 16:05:31 -05003600 return hs;
3601}
3602
James Smarte59058c2008-08-24 21:49:00 -04003603/**
3604 * lpfc_reset_stats: Copy the adapter link stats information.
3605 * @shost: kernel scsi host pointer.
3606 **/
James Smart64ba8812006-08-02 15:24:34 -04003607static void
3608lpfc_reset_stats(struct Scsi_Host *shost)
3609{
James Smart2e0fef82007-06-17 19:56:36 -05003610 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3611 struct lpfc_hba *phba = vport->phba;
3612 struct lpfc_sli *psli = &phba->sli;
3613 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04003614 LPFC_MBOXQ_t *pmboxq;
3615 MAILBOX_t *pmb;
3616 int rc = 0;
3617
James Smart2e0fef82007-06-17 19:56:36 -05003618 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04003619 return;
3620
James Smart64ba8812006-08-02 15:24:34 -04003621 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3622 if (!pmboxq)
3623 return;
3624 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3625
3626 pmb = &pmboxq->mb;
3627 pmb->mbxCommand = MBX_READ_STATUS;
3628 pmb->mbxOwner = OWN_HOST;
3629 pmb->un.varWords[0] = 0x1; /* reset request */
3630 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003631 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04003632
James Smart2e0fef82007-06-17 19:56:36 -05003633 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04003634 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
3635 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3636 else
3637 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3638
3639 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003640 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04003641 mempool_free(pmboxq, phba->mbox_mem_pool);
3642 return;
3643 }
3644
3645 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3646 pmb->mbxCommand = MBX_READ_LNK_STAT;
3647 pmb->mbxOwner = OWN_HOST;
3648 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003649 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04003650
James Smart2e0fef82007-06-17 19:56:36 -05003651 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04003652 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
3653 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3654 else
3655 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3656
3657 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003658 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04003659 mempool_free( pmboxq, phba->mbox_mem_pool);
3660 return;
3661 }
3662
3663 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3664 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3665 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3666 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3667 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3668 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3669 lso->error_frames = pmb->un.varRdLnk.crcCnt;
3670 lso->link_events = (phba->fc_eventTag >> 1);
3671
3672 psli->stats_start = get_seconds();
3673
James Smart1dcb58e2007-04-25 09:51:30 -04003674 mempool_free(pmboxq, phba->mbox_mem_pool);
3675
James Smart64ba8812006-08-02 15:24:34 -04003676 return;
3677}
dea31012005-04-17 16:05:31 -05003678
3679/*
3680 * The LPFC driver treats linkdown handling as target loss events so there
3681 * are no sysfs handlers for link_down_tmo.
3682 */
James Smart685f0bf2007-04-25 09:53:08 -04003683
James Smarte59058c2008-08-24 21:49:00 -04003684/**
3685 * lpfc_get_node_by_target: Return the nodelist for a target.
3686 * @starget: kernel scsi target pointer.
3687 *
3688 * Returns:
3689 * address of the node list if found
3690 * NULL target not found
3691 **/
James Smart685f0bf2007-04-25 09:53:08 -04003692static struct lpfc_nodelist *
3693lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05003694{
James Smart2e0fef82007-06-17 19:56:36 -05003695 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3696 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04003697 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003698
3699 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003700 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05003701 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003702 if (NLP_CHK_NODE_ACT(ndlp) &&
3703 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04003704 starget->id == ndlp->nlp_sid) {
3705 spin_unlock_irq(shost->host_lock);
3706 return ndlp;
dea31012005-04-17 16:05:31 -05003707 }
3708 }
3709 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003710 return NULL;
3711}
dea31012005-04-17 16:05:31 -05003712
James Smarte59058c2008-08-24 21:49:00 -04003713/**
3714 * lpfc_get_starget_port_id: Set the target port id to the ndlp DID or -1.
3715 * @starget: kernel scsi target pointer.
3716 **/
James Smart685f0bf2007-04-25 09:53:08 -04003717static void
3718lpfc_get_starget_port_id(struct scsi_target *starget)
3719{
3720 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
3721
3722 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05003723}
3724
James Smarte59058c2008-08-24 21:49:00 -04003725/**
3726 * lpfc_get_starget_node_name: Set the target node name.
3727 * @starget: kernel scsi target pointer.
3728 *
3729 * Description: Set the target node name to the ndlp node name wwn or zero.
3730 **/
dea31012005-04-17 16:05:31 -05003731static void
3732lpfc_get_starget_node_name(struct scsi_target *starget)
3733{
James Smart685f0bf2007-04-25 09:53:08 -04003734 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05003735
James Smart685f0bf2007-04-25 09:53:08 -04003736 fc_starget_node_name(starget) =
3737 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05003738}
3739
James Smarte59058c2008-08-24 21:49:00 -04003740/**
3741 * lpfc_get_starget_port_name: Set the target port name.
3742 * @starget: kernel scsi target pointer.
3743 *
3744 * Description: set the target port name to the ndlp port name wwn or zero.
3745 **/
dea31012005-04-17 16:05:31 -05003746static void
3747lpfc_get_starget_port_name(struct scsi_target *starget)
3748{
James Smart685f0bf2007-04-25 09:53:08 -04003749 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05003750
James Smart685f0bf2007-04-25 09:53:08 -04003751 fc_starget_port_name(starget) =
3752 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05003753}
3754
James Smarte59058c2008-08-24 21:49:00 -04003755/**
3756 * lpfc_set_rport_loss_tmo: Set the rport dev loss tmo.
3757 * @rport: fc rport address.
3758 * @timeout: new value for dev loss tmo.
3759 *
3760 * Description:
3761 * If timeout is non zero set the dev_loss_tmo to timeout, else set
3762 * dev_loss_tmo to one.
3763 **/
dea31012005-04-17 16:05:31 -05003764static void
dea31012005-04-17 16:05:31 -05003765lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
3766{
dea31012005-04-17 16:05:31 -05003767 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04003768 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05003769 else
James Smartc01f3202006-08-18 17:47:08 -04003770 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05003771}
3772
James Smarte59058c2008-08-24 21:49:00 -04003773/**
3774 * lpfc_rport_show_function: Return rport target information.
3775 *
3776 * Description:
3777 * Macro that uses field to generate a function with the name lpfc_show_rport_
3778 *
3779 * lpfc_show_rport_##field: returns the bytes formatted in buf
3780 * @cdev: class converted to an fc_rport.
3781 * @buf: on return contains the target_field or zero.
3782 *
3783 * Returns: size of formatted string.
3784 **/
dea31012005-04-17 16:05:31 -05003785#define lpfc_rport_show_function(field, format_string, sz, cast) \
3786static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01003787lpfc_show_rport_##field (struct device *dev, \
3788 struct device_attribute *attr, \
3789 char *buf) \
dea31012005-04-17 16:05:31 -05003790{ \
Tony Jonesee959b02008-02-22 00:13:36 +01003791 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05003792 struct lpfc_rport_data *rdata = rport->hostdata; \
3793 return snprintf(buf, sz, format_string, \
3794 (rdata->target) ? cast rdata->target->field : 0); \
3795}
3796
3797#define lpfc_rport_rd_attr(field, format_string, sz) \
3798 lpfc_rport_show_function(field, format_string, sz, ) \
3799static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
3800
James Smarteada2722008-12-04 22:39:13 -05003801/**
3802 * lpfc_set_vport_symbolic_name: Set the vport's symbolic name.
3803 * @fc_vport: The fc_vport who's symbolic name has been changed.
3804 *
3805 * Description:
3806 * This function is called by the transport after the @fc_vport's symbolic name
3807 * has been changed. This function re-registers the symbolic name with the
3808 * switch to propogate the change into the fabric if the vport is active.
3809 **/
3810static void
3811lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
3812{
3813 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
3814
3815 if (vport->port_state == LPFC_VPORT_READY)
3816 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
3817}
dea31012005-04-17 16:05:31 -05003818
3819struct fc_function_template lpfc_transport_functions = {
3820 /* fixed attributes the driver supports */
3821 .show_host_node_name = 1,
3822 .show_host_port_name = 1,
3823 .show_host_supported_classes = 1,
3824 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05003825 .show_host_supported_speeds = 1,
3826 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05003827 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05003828
3829 /* dynamic attributes the driver supports */
3830 .get_host_port_id = lpfc_get_host_port_id,
3831 .show_host_port_id = 1,
3832
3833 .get_host_port_type = lpfc_get_host_port_type,
3834 .show_host_port_type = 1,
3835
3836 .get_host_port_state = lpfc_get_host_port_state,
3837 .show_host_port_state = 1,
3838
3839 /* active_fc4s is shown but doesn't change (thus no get function) */
3840 .show_host_active_fc4s = 1,
3841
3842 .get_host_speed = lpfc_get_host_speed,
3843 .show_host_speed = 1,
3844
3845 .get_host_fabric_name = lpfc_get_host_fabric_name,
3846 .show_host_fabric_name = 1,
3847
3848 /*
3849 * The LPFC driver treats linkdown handling as target loss events
3850 * so there are no sysfs handlers for link_down_tmo.
3851 */
3852
3853 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04003854 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05003855
3856 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
3857 .show_rport_maxframe_size = 1,
3858 .show_rport_supported_classes = 1,
3859
dea31012005-04-17 16:05:31 -05003860 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
3861 .show_rport_dev_loss_tmo = 1,
3862
3863 .get_starget_port_id = lpfc_get_starget_port_id,
3864 .show_starget_port_id = 1,
3865
3866 .get_starget_node_name = lpfc_get_starget_node_name,
3867 .show_starget_node_name = 1,
3868
3869 .get_starget_port_name = lpfc_get_starget_port_name,
3870 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07003871
3872 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04003873 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
3874 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05003875
James Smart92d7f7b2007-06-17 19:56:38 -05003876 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05003877
3878 .vport_disable = lpfc_vport_disable,
3879
3880 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart92d7f7b2007-06-17 19:56:38 -05003881};
3882
James Smart98c9ea52007-10-27 13:37:33 -04003883struct fc_function_template lpfc_vport_transport_functions = {
3884 /* fixed attributes the driver supports */
3885 .show_host_node_name = 1,
3886 .show_host_port_name = 1,
3887 .show_host_supported_classes = 1,
3888 .show_host_supported_fc4s = 1,
3889 .show_host_supported_speeds = 1,
3890 .show_host_maxframe_size = 1,
James Smarteada2722008-12-04 22:39:13 -05003891 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04003892
3893 /* dynamic attributes the driver supports */
3894 .get_host_port_id = lpfc_get_host_port_id,
3895 .show_host_port_id = 1,
3896
3897 .get_host_port_type = lpfc_get_host_port_type,
3898 .show_host_port_type = 1,
3899
3900 .get_host_port_state = lpfc_get_host_port_state,
3901 .show_host_port_state = 1,
3902
3903 /* active_fc4s is shown but doesn't change (thus no get function) */
3904 .show_host_active_fc4s = 1,
3905
3906 .get_host_speed = lpfc_get_host_speed,
3907 .show_host_speed = 1,
3908
3909 .get_host_fabric_name = lpfc_get_host_fabric_name,
3910 .show_host_fabric_name = 1,
3911
3912 /*
3913 * The LPFC driver treats linkdown handling as target loss events
3914 * so there are no sysfs handlers for link_down_tmo.
3915 */
3916
3917 .get_fc_host_stats = lpfc_get_stats,
3918 .reset_fc_host_stats = lpfc_reset_stats,
3919
3920 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
3921 .show_rport_maxframe_size = 1,
3922 .show_rport_supported_classes = 1,
3923
3924 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
3925 .show_rport_dev_loss_tmo = 1,
3926
3927 .get_starget_port_id = lpfc_get_starget_port_id,
3928 .show_starget_port_id = 1,
3929
3930 .get_starget_node_name = lpfc_get_starget_node_name,
3931 .show_starget_node_name = 1,
3932
3933 .get_starget_port_name = lpfc_get_starget_port_name,
3934 .show_starget_port_name = 1,
3935
3936 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
3937 .terminate_rport_io = lpfc_terminate_rport_io,
3938
3939 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05003940
3941 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04003942};
3943
James Smarte59058c2008-08-24 21:49:00 -04003944/**
3945 * lpfc_get_cfgparam: Used during probe_one to init the adapter structure.
3946 * @phba: lpfc_hba pointer.
3947 **/
dea31012005-04-17 16:05:31 -05003948void
3949lpfc_get_cfgparam(struct lpfc_hba *phba)
3950{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04003951 lpfc_cr_delay_init(phba, lpfc_cr_delay);
3952 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003953 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05003954 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
3955 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04003956 lpfc_ack0_init(phba, lpfc_ack0);
3957 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04003958 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003959 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04003960 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05003961 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart13815c82008-01-11 01:52:48 -05003962 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
3963 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003964 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05003965 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04003966 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05003967 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
3968 /* Also reinitialize the host templates with new values. */
3969 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
3970 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
dea31012005-04-17 16:05:31 -05003971 /*
3972 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
James Smart83108bd2008-01-11 01:53:09 -05003973 * used to create the sg_dma_buf_pool must be dynamically calculated.
3974 * 2 segments are added since the IOCB needs a command and response bde.
dea31012005-04-17 16:05:31 -05003975 */
3976 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
3977 sizeof(struct fcp_rsp) +
James Smart83108bd2008-01-11 01:53:09 -05003978 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
James Smart7054a602007-04-25 09:52:34 -04003979 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04003980 return;
3981}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003982
James Smarte59058c2008-08-24 21:49:00 -04003983/**
3984 * lpfc_get_vport_cfgparam: Used during port create, init the vport structure.
3985 * @vport: lpfc_vport pointer.
3986 **/
James Smart3de2a652007-08-02 11:09:59 -04003987void
3988lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
3989{
James Smarte8b62012007-08-02 11:10:09 -04003990 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04003991 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
3992 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
3993 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
3994 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
3995 lpfc_restrict_login_init(vport, lpfc_restrict_login);
3996 lpfc_fcp_class_init(vport, lpfc_fcp_class);
3997 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04003998 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04003999 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4000 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4001 lpfc_max_luns_init(vport, lpfc_max_luns);
4002 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04004003 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05004004 return;
4005}