blob: 343b0b36ed2286f575150c2760e8681e26668463 [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"
35#include "lpfc_disc.h"
36#include "lpfc_scsi.h"
37#include "lpfc.h"
38#include "lpfc_logmsg.h"
39#include "lpfc_version.h"
40#include "lpfc_compat.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050043
James Smartc01f3202006-08-18 17:47:08 -040044#define LPFC_DEF_DEVLOSS_TMO 30
45#define LPFC_MIN_DEVLOSS_TMO 1
46#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050047
James Smart83108bd2008-01-11 01:53:09 -050048#define LPFC_MAX_LINK_SPEED 8
49#define LPFC_LINK_SPEED_BITMAP 0x00000117
50#define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
51
James Smarte59058c2008-08-24 21:49:00 -040052/**
53 * lpfc_jedec_to_ascii: Hex to ascii convertor according to JEDEC rules.
54 * @incr: integer to convert.
55 * @hdw: ascii string holding converted integer plus a string terminator.
56 *
57 * Description:
58 * JEDEC Joint Electron Device Engineering Council.
59 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
60 * character string. The string is then terminated with a NULL in byte 9.
61 * Hex 0-9 becomes ascii '0' to '9'.
62 * Hex a-f becomes ascii '=' to 'B' capital B.
63 *
64 * Notes:
65 * Coded for 32 bit integers only.
66 **/
dea31012005-04-17 16:05:31 -050067static void
68lpfc_jedec_to_ascii(int incr, char hdw[])
69{
70 int i, j;
71 for (i = 0; i < 8; i++) {
72 j = (incr & 0xf);
73 if (j <= 9)
74 hdw[7 - i] = 0x30 + j;
75 else
76 hdw[7 - i] = 0x61 + j - 10;
77 incr = (incr >> 4);
78 }
79 hdw[8] = 0;
80 return;
81}
82
James Smarte59058c2008-08-24 21:49:00 -040083/**
84 * lpfc_drvr_version_show: Return the Emulex driver string with version number.
85 * @dev: class unused variable.
86 * @attr: device attribute, not used.
87 * @buf: on return contains the module description text.
88 *
89 * Returns: size of formatted string.
90 **/
dea31012005-04-17 16:05:31 -050091static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +010092lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
93 char *buf)
dea31012005-04-17 16:05:31 -050094{
95 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
96}
97
James Smarte59058c2008-08-24 21:49:00 -040098/**
99 * lpfc_info_show: Return some pci info about the host in ascii.
100 * @dev: class converted to a Scsi_host structure.
101 * @attr: device attribute, not used.
102 * @buf: on return contains the formatted text from lpfc_info().
103 *
104 * Returns: size of formatted string.
105 **/
dea31012005-04-17 16:05:31 -0500106static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100107lpfc_info_show(struct device *dev, struct device_attribute *attr,
108 char *buf)
dea31012005-04-17 16:05:31 -0500109{
Tony Jonesee959b02008-02-22 00:13:36 +0100110 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500111
dea31012005-04-17 16:05:31 -0500112 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
113}
114
James Smarte59058c2008-08-24 21:49:00 -0400115/**
116 * lpfc_serialnum_show: Return the hba serial number in ascii.
117 * @dev: class converted to a Scsi_host structure.
118 * @attr: device attribute, not used.
119 * @buf: on return contains the formatted text serial number.
120 *
121 * Returns: size of formatted string.
122 **/
dea31012005-04-17 16:05:31 -0500123static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100124lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
125 char *buf)
dea31012005-04-17 16:05:31 -0500126{
Tony Jonesee959b02008-02-22 00:13:36 +0100127 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
129 struct lpfc_hba *phba = vport->phba;
130
dea31012005-04-17 16:05:31 -0500131 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
132}
133
James Smarte59058c2008-08-24 21:49:00 -0400134/**
135 * lpfc_temp_sensor_show: Return the temperature sensor level.
136 * @dev: class converted to a Scsi_host structure.
137 * @attr: device attribute, not used.
138 * @buf: on return contains the formatted support level.
139 *
140 * Description:
141 * Returns a number indicating the temperature sensor level currently
142 * supported, zero or one in ascii.
143 *
144 * Returns: size of formatted string.
145 **/
dea31012005-04-17 16:05:31 -0500146static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100147lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
148 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400149{
Tony Jonesee959b02008-02-22 00:13:36 +0100150 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400151 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
152 struct lpfc_hba *phba = vport->phba;
153 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
154}
155
James Smarte59058c2008-08-24 21:49:00 -0400156/**
157 * lpfc_modeldesc_show: Return the model description of the hba.
158 * @dev: class converted to a Scsi_host structure.
159 * @attr: device attribute, not used.
160 * @buf: on return contains the scsi vpd model description.
161 *
162 * Returns: size of formatted string.
163 **/
James Smart57127f12007-10-27 13:37:05 -0400164static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100165lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
166 char *buf)
dea31012005-04-17 16:05:31 -0500167{
Tony Jonesee959b02008-02-22 00:13:36 +0100168 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500169 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
170 struct lpfc_hba *phba = vport->phba;
171
dea31012005-04-17 16:05:31 -0500172 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
173}
174
James Smarte59058c2008-08-24 21:49:00 -0400175/**
176 * lpfc_modelname_show: Return the model name of the hba.
177 * @dev: class converted to a Scsi_host structure.
178 * @attr: device attribute, not used.
179 * @buf: on return contains the scsi vpd model name.
180 *
181 * Returns: size of formatted string.
182 **/
dea31012005-04-17 16:05:31 -0500183static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100184lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
185 char *buf)
dea31012005-04-17 16:05:31 -0500186{
Tony Jonesee959b02008-02-22 00:13:36 +0100187 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500188 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
189 struct lpfc_hba *phba = vport->phba;
190
dea31012005-04-17 16:05:31 -0500191 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
192}
193
James Smarte59058c2008-08-24 21:49:00 -0400194/**
195 * lpfc_programtype_show: Return the program type of the hba.
196 * @dev: class converted to a Scsi_host structure.
197 * @attr: device attribute, not used.
198 * @buf: on return contains the scsi vpd program type.
199 *
200 * Returns: size of formatted string.
201 **/
dea31012005-04-17 16:05:31 -0500202static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100203lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
204 char *buf)
dea31012005-04-17 16:05:31 -0500205{
Tony Jonesee959b02008-02-22 00:13:36 +0100206 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500207 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
208 struct lpfc_hba *phba = vport->phba;
209
dea31012005-04-17 16:05:31 -0500210 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
211}
212
James Smarte59058c2008-08-24 21:49:00 -0400213/**
James Smart84774a42008-08-24 21:50:06 -0400214 * lpfc_mlomgmt_show: Return the Menlo Maintenance sli flag.
215 * @dev: class converted to a Scsi_host structure.
216 * @attr: device attribute, not used.
217 * @buf: on return contains the Menlo Maintenance sli flag.
218 *
219 * Returns: size of formatted string.
220 **/
221static ssize_t
222lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
223{
224 struct Scsi_Host *shost = class_to_shost(dev);
225 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
226 struct lpfc_hba *phba = vport->phba;
227
228 return snprintf(buf, PAGE_SIZE, "%d\n",
229 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
230}
231
232/**
James Smarte59058c2008-08-24 21:49:00 -0400233 * lpfc_vportnum_show: Return the port number in ascii of the hba.
234 * @dev: class converted to a Scsi_host structure.
235 * @attr: device attribute, not used.
236 * @buf: on return contains scsi vpd program type.
237 *
238 * Returns: size of formatted string.
239 **/
dea31012005-04-17 16:05:31 -0500240static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100241lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
242 char *buf)
dea31012005-04-17 16:05:31 -0500243{
Tony Jonesee959b02008-02-22 00:13:36 +0100244 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500245 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
246 struct lpfc_hba *phba = vport->phba;
247
dea31012005-04-17 16:05:31 -0500248 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
249}
250
James Smarte59058c2008-08-24 21:49:00 -0400251/**
252 * lpfc_fwrev_show: Return the firmware rev running in the hba.
253 * @dev: class converted to a Scsi_host structure.
254 * @attr: device attribute, not used.
255 * @buf: on return contains the scsi vpd program type.
256 *
257 * Returns: size of formatted string.
258 **/
dea31012005-04-17 16:05:31 -0500259static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100260lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
261 char *buf)
dea31012005-04-17 16:05:31 -0500262{
Tony Jonesee959b02008-02-22 00:13:36 +0100263 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500264 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
265 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500266 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500267
dea31012005-04-17 16:05:31 -0500268 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500269 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500270}
271
James Smarte59058c2008-08-24 21:49:00 -0400272/**
273 * lpfc_hdw_show: Return the jedec information about the hba.
274 * @dev: class converted to a Scsi_host structure.
275 * @attr: device attribute, not used.
276 * @buf: on return contains the scsi vpd program type.
277 *
278 * Returns: size of formatted string.
279 **/
dea31012005-04-17 16:05:31 -0500280static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100281lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500282{
283 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100284 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500285 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
286 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500287 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500288
dea31012005-04-17 16:05:31 -0500289 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
290 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
291}
James Smarte59058c2008-08-24 21:49:00 -0400292
293/**
294 * lpfc_option_rom_version_show: Return the adapter ROM FCode version.
295 * @dev: class converted to a Scsi_host structure.
296 * @attr: device attribute, not used.
297 * @buf: on return contains the ROM and FCode ascii strings.
298 *
299 * Returns: size of formatted string.
300 **/
dea31012005-04-17 16:05:31 -0500301static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100302lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
303 char *buf)
dea31012005-04-17 16:05:31 -0500304{
Tony Jonesee959b02008-02-22 00:13:36 +0100305 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500306 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
307 struct lpfc_hba *phba = vport->phba;
308
dea31012005-04-17 16:05:31 -0500309 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
310}
James Smarte59058c2008-08-24 21:49:00 -0400311
312/**
313 * lpfc_state_show: Return the link state of the port.
314 * @dev: class converted to a Scsi_host structure.
315 * @attr: device attribute, not used.
316 * @buf: on return contains text describing the state of the link.
317 *
318 * Notes:
319 * The switch statement has no default so zero will be returned.
320 *
321 * Returns: size of formatted string.
322 **/
dea31012005-04-17 16:05:31 -0500323static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100324lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
325 char *buf)
dea31012005-04-17 16:05:31 -0500326{
Tony Jonesee959b02008-02-22 00:13:36 +0100327 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500328 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
329 struct lpfc_hba *phba = vport->phba;
330 int len = 0;
331
332 switch (phba->link_state) {
333 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500334 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500335 case LPFC_INIT_START:
336 case LPFC_INIT_MBX_CMDS:
337 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500338 case LPFC_HBA_ERROR:
dea31012005-04-17 16:05:31 -0500339 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
340 break;
341 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500342 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500343 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400344 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500345
346 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500347 case LPFC_LOCAL_CFG_LINK:
348 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500349 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500350 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500351 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500352 case LPFC_FLOGI:
353 case LPFC_FABRIC_CFG_LINK:
354 case LPFC_NS_REG:
355 case LPFC_NS_QRY:
356 case LPFC_BUILD_DISC_LIST:
357 case LPFC_DISC_AUTH:
358 len += snprintf(buf + len, PAGE_SIZE - len,
359 "Discovery\n");
360 break;
361 case LPFC_VPORT_READY:
362 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
363 break;
364
James Smart92d7f7b2007-06-17 19:56:38 -0500365 case LPFC_VPORT_FAILED:
366 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
367 break;
368
369 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500370 len += snprintf(buf + len, PAGE_SIZE - len,
371 "Unknown\n");
372 break;
373 }
James Smart84774a42008-08-24 21:50:06 -0400374 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
375 len += snprintf(buf + len, PAGE_SIZE-len,
376 " Menlo Maint Mode\n");
377 else if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500378 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500379 len += snprintf(buf + len, PAGE_SIZE-len,
380 " Public Loop\n");
381 else
382 len += snprintf(buf + len, PAGE_SIZE-len,
383 " Private Loop\n");
384 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500385 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500386 len += snprintf(buf + len, PAGE_SIZE-len,
387 " Fabric\n");
388 else
389 len += snprintf(buf + len, PAGE_SIZE-len,
390 " Point-2-Point\n");
391 }
392 }
James Smart2e0fef82007-06-17 19:56:36 -0500393
dea31012005-04-17 16:05:31 -0500394 return len;
395}
396
James Smarte59058c2008-08-24 21:49:00 -0400397/**
398 * lpfc_num_discovered_ports_show: Return sum of mapped and unmapped vports.
399 * @dev: class device that is converted into a Scsi_host.
400 * @attr: device attribute, not used.
401 * @buf: on return contains the sum of fc mapped and unmapped.
402 *
403 * Description:
404 * Returns the ascii text number of the sum of the fc mapped and unmapped
405 * vport counts.
406 *
407 * Returns: size of formatted string.
408 **/
dea31012005-04-17 16:05:31 -0500409static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100410lpfc_num_discovered_ports_show(struct device *dev,
411 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500412{
Tony Jonesee959b02008-02-22 00:13:36 +0100413 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500414 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
415
416 return snprintf(buf, PAGE_SIZE, "%d\n",
417 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500418}
419
James Smarte59058c2008-08-24 21:49:00 -0400420/**
421 * lpfc_issue_lip: Misnomer, name carried over from long ago.
422 * @shost: Scsi_Host pointer.
423 *
424 * Description:
425 * Bring the link down gracefully then re-init the link. The firmware will
426 * re-init the fiber channel interface as required. Does not issue a LIP.
427 *
428 * Returns:
429 * -EPERM port offline or management commands are being blocked
430 * -ENOMEM cannot allocate memory for the mailbox command
431 * -EIO error sending the mailbox command
432 * zero for success
433 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700434static int
James Smart2e0fef82007-06-17 19:56:36 -0500435lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500436{
James Smart2e0fef82007-06-17 19:56:36 -0500437 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
438 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500439 LPFC_MBOXQ_t *pmboxq;
440 int mbxstatus = MBXERR_ERROR;
441
James Smart2e0fef82007-06-17 19:56:36 -0500442 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500443 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500444 return -EPERM;
445
446 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
447
448 if (!pmboxq)
449 return -ENOMEM;
450
451 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart4db621e2006-07-06 15:49:49 -0400452 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
453 pmboxq->mb.mbxOwner = OWN_HOST;
454
James Smart33ccf8d2006-08-17 11:57:58 -0400455 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500456
James Smart4db621e2006-07-06 15:49:49 -0400457 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
458 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
459 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
460 phba->cfg_link_speed);
461 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
462 phba->fc_ratov * 2);
463 }
464
James Smart5b8bd0c2007-04-25 09:52:49 -0400465 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500466 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400467 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500468
469 if (mbxstatus == MBXERR_ERROR)
470 return -EIO;
471
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700472 return 0;
dea31012005-04-17 16:05:31 -0500473}
474
James Smarte59058c2008-08-24 21:49:00 -0400475/**
476 * lpfc_do_offline: Issues a mailbox command to bring the link down.
477 * @phba: lpfc_hba pointer.
478 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
479 *
480 * Notes:
481 * Assumes any error from lpfc_do_offline() will be negative.
482 * Can wait up to 5 seconds for the port ring buffers count
483 * to reach zero, prints a warning if it is not zero and continues.
484 * lpfc_workq_post_event() returns a non-zero return coce if call fails.
485 *
486 * Returns:
487 * -EIO error posting the event
488 * zero for success
489 **/
James Smart40496f02006-07-06 15:50:22 -0400490static int
James Smart46fa3112007-04-25 09:51:45 -0400491lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
492{
493 struct completion online_compl;
494 struct lpfc_sli_ring *pring;
495 struct lpfc_sli *psli;
496 int status = 0;
497 int cnt = 0;
498 int i;
499
500 init_completion(&online_compl);
501 lpfc_workq_post_event(phba, &status, &online_compl,
502 LPFC_EVT_OFFLINE_PREP);
503 wait_for_completion(&online_compl);
504
505 if (status != 0)
506 return -EIO;
507
508 psli = &phba->sli;
509
James Smart09372822008-01-11 01:52:54 -0500510 /* Wait a little for things to settle down, but not
511 * long enough for dev loss timeout to expire.
512 */
James Smart46fa3112007-04-25 09:51:45 -0400513 for (i = 0; i < psli->num_rings; i++) {
514 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400515 while (pring->txcmplq_cnt) {
516 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500517 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400518 lpfc_printf_log(phba,
519 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400520 "0466 Outstanding IO when "
521 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400522 break;
523 }
524 }
525 }
526
527 init_completion(&online_compl);
528 lpfc_workq_post_event(phba, &status, &online_compl, type);
529 wait_for_completion(&online_compl);
530
531 if (status != 0)
532 return -EIO;
533
534 return 0;
535}
536
James Smarte59058c2008-08-24 21:49:00 -0400537/**
538 * lpfc_selective_reset: Offline then onlines the port.
539 * @phba: lpfc_hba pointer.
540 *
541 * Description:
542 * If the port is configured to allow a reset then the hba is brought
543 * offline then online.
544 *
545 * Notes:
546 * Assumes any error from lpfc_do_offline() will be negative.
547 *
548 * Returns:
549 * lpfc_do_offline() return code if not zero
550 * -EIO reset not configured or error posting the event
551 * zero for success
552 **/
James Smart46fa3112007-04-25 09:51:45 -0400553static int
James Smart40496f02006-07-06 15:50:22 -0400554lpfc_selective_reset(struct lpfc_hba *phba)
555{
556 struct completion online_compl;
557 int status = 0;
558
James Smart13815c82008-01-11 01:52:48 -0500559 if (!phba->cfg_enable_hba_reset)
560 return -EIO;
561
James Smart46fa3112007-04-25 09:51:45 -0400562 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400563
564 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400565 return status;
James Smart40496f02006-07-06 15:50:22 -0400566
567 init_completion(&online_compl);
568 lpfc_workq_post_event(phba, &status, &online_compl,
569 LPFC_EVT_ONLINE);
570 wait_for_completion(&online_compl);
571
572 if (status != 0)
573 return -EIO;
574
575 return 0;
576}
577
James Smarte59058c2008-08-24 21:49:00 -0400578/**
579 * lpfc_issue_reset: Selectively resets an adapter.
580 * @dev: class device that is converted into a Scsi_host.
581 * @attr: device attribute, not used.
582 * @buf: containing the string "selective".
583 * @count: unused variable.
584 *
585 * Description:
586 * If the buf contains the string "selective" then lpfc_selective_reset()
587 * is called to perform the reset.
588 *
589 * Notes:
590 * Assumes any error from lpfc_selective_reset() will be negative.
591 * If lpfc_selective_reset() returns zero then the length of the buffer
592 * is returned which indicates succcess
593 *
594 * Returns:
595 * -EINVAL if the buffer does not contain the string "selective"
596 * length of buf if lpfc-selective_reset() if the call succeeds
597 * return value of lpfc_selective_reset() if the call fails
598**/
James Smart40496f02006-07-06 15:50:22 -0400599static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100600lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
601 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400602{
Tony Jonesee959b02008-02-22 00:13:36 +0100603 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500604 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
605 struct lpfc_hba *phba = vport->phba;
606
James Smart40496f02006-07-06 15:50:22 -0400607 int status = -EINVAL;
608
609 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
610 status = lpfc_selective_reset(phba);
611
612 if (status == 0)
613 return strlen(buf);
614 else
615 return status;
616}
617
James Smarte59058c2008-08-24 21:49:00 -0400618/**
619 * lpfc_nport_evt_cnt_show: Return the number of nport events.
620 * @dev: class device that is converted into a Scsi_host.
621 * @attr: device attribute, not used.
622 * @buf: on return contains the ascii number of nport events.
623 *
624 * Returns: size of formatted string.
625 **/
dea31012005-04-17 16:05:31 -0500626static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100627lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
628 char *buf)
dea31012005-04-17 16:05:31 -0500629{
Tony Jonesee959b02008-02-22 00:13:36 +0100630 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500631 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
632 struct lpfc_hba *phba = vport->phba;
633
dea31012005-04-17 16:05:31 -0500634 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
635}
636
James Smarte59058c2008-08-24 21:49:00 -0400637/**
638 * lpfc_board_mode_show: Return the state of the board.
639 * @dev: class device that is converted into a Scsi_host.
640 * @attr: device attribute, not used.
641 * @buf: on return contains the state of the adapter.
642 *
643 * Returns: size of formatted string.
644 **/
dea31012005-04-17 16:05:31 -0500645static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100646lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
647 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500648{
Tony Jonesee959b02008-02-22 00:13:36 +0100649 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500650 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
651 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500652 char * state;
653
James Smart2e0fef82007-06-17 19:56:36 -0500654 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500655 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500656 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500657 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500658 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500659 state = "offline";
660 else
661 state = "online";
662
663 return snprintf(buf, PAGE_SIZE, "%s\n", state);
664}
665
James Smarte59058c2008-08-24 21:49:00 -0400666/**
667 * lpfc_board_mode_store: Puts the hba in online, offline, warm or error state.
668 * @dev: class device that is converted into a Scsi_host.
669 * @attr: device attribute, not used.
670 * @buf: containing one of the strings "online", "offline", "warm" or "error".
671 * @count: unused variable.
672 *
673 * Returns:
674 * -EACCES if enable hba reset not enabled
675 * -EINVAL if the buffer does not contain a valid string (see above)
676 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
677 * buf length greater than zero indicates success
678 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500679static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100680lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
681 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500682{
Tony Jonesee959b02008-02-22 00:13:36 +0100683 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500684 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
685 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500686 struct completion online_compl;
687 int status=0;
688
James Smart13815c82008-01-11 01:52:48 -0500689 if (!phba->cfg_enable_hba_reset)
690 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500691 init_completion(&online_compl);
692
James Smart46fa3112007-04-25 09:51:45 -0400693 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500694 lpfc_workq_post_event(phba, &status, &online_compl,
695 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400696 wait_for_completion(&online_compl);
697 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
698 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500699 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart46fa3112007-04-25 09:51:45 -0400700 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
701 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
702 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500703 else
704 return -EINVAL;
705
Jamie Wellnitz41415862006-02-28 19:25:27 -0500706 if (!status)
707 return strlen(buf);
708 else
709 return -EIO;
710}
711
James Smarte59058c2008-08-24 21:49:00 -0400712/**
713 * lpfc_get_hba_info: Return various bits of informaton about the adapter.
714 * @phba: pointer to the adapter structure.
715 * @mxri max xri count.
716 * @axri available xri count.
717 * @mrpi max rpi count.
718 * @arpi available rpi count.
719 * @mvpi max vpi count.
720 * @avpi available vpi count.
721 *
722 * Description:
723 * If an integer pointer for an count is not null then the value for the
724 * count is returned.
725 *
726 * Returns:
727 * zero on error
728 * one for success
729 **/
James Smart311464e2007-08-02 11:10:37 -0400730static int
James Smart858c9f62007-06-17 19:56:39 -0500731lpfc_get_hba_info(struct lpfc_hba *phba,
732 uint32_t *mxri, uint32_t *axri,
733 uint32_t *mrpi, uint32_t *arpi,
734 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500735{
736 struct lpfc_sli *psli = &phba->sli;
737 LPFC_MBOXQ_t *pmboxq;
738 MAILBOX_t *pmb;
739 int rc = 0;
740
741 /*
742 * prevent udev from issuing mailbox commands until the port is
743 * configured.
744 */
745 if (phba->link_state < LPFC_LINK_DOWN ||
746 !phba->mbox_mem_pool ||
747 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
748 return 0;
749
750 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
751 return 0;
752
753 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
754 if (!pmboxq)
755 return 0;
756 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
757
758 pmb = &pmboxq->mb;
759 pmb->mbxCommand = MBX_READ_CONFIG;
760 pmb->mbxOwner = OWN_HOST;
761 pmboxq->context1 = NULL;
762
763 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
764 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
765 rc = MBX_NOT_FINISHED;
766 else
767 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
768
769 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500770 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500771 mempool_free(pmboxq, phba->mbox_mem_pool);
772 return 0;
773 }
774
775 if (mrpi)
776 *mrpi = pmb->un.varRdConfig.max_rpi;
777 if (arpi)
778 *arpi = pmb->un.varRdConfig.avail_rpi;
779 if (mxri)
780 *mxri = pmb->un.varRdConfig.max_xri;
781 if (axri)
782 *axri = pmb->un.varRdConfig.avail_xri;
James Smart858c9f62007-06-17 19:56:39 -0500783 if (mvpi)
784 *mvpi = pmb->un.varRdConfig.max_vpi;
785 if (avpi)
786 *avpi = pmb->un.varRdConfig.avail_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500787
788 mempool_free(pmboxq, phba->mbox_mem_pool);
789 return 1;
790}
791
James Smarte59058c2008-08-24 21:49:00 -0400792/**
793 * lpfc_max_rpi_show: Return maximum rpi.
794 * @dev: class device that is converted into a Scsi_host.
795 * @attr: device attribute, not used.
796 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
797 *
798 * Description:
799 * Calls lpfc_get_hba_info() asking for just the mrpi count.
800 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
801 * to "Unknown" and the buffer length is returned, therefore the caller
802 * must check for "Unknown" in the buffer to detect a failure.
803 *
804 * Returns: size of formatted string.
805 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500806static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100807lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
808 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500809{
Tony Jonesee959b02008-02-22 00:13:36 +0100810 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500811 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
812 struct lpfc_hba *phba = vport->phba;
813 uint32_t cnt;
814
James Smart858c9f62007-06-17 19:56:39 -0500815 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500816 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
817 return snprintf(buf, PAGE_SIZE, "Unknown\n");
818}
819
James Smarte59058c2008-08-24 21:49:00 -0400820/**
821 * lpfc_used_rpi_show: Return maximum rpi minus available rpi.
822 * @dev: class device that is converted into a Scsi_host.
823 * @attr: device attribute, not used.
824 * @buf: containing the used rpi count in decimal or "Unknown".
825 *
826 * Description:
827 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
828 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
829 * to "Unknown" and the buffer length is returned, therefore the caller
830 * must check for "Unknown" in the buffer to detect a failure.
831 *
832 * Returns: size of formatted string.
833 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500834static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100835lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
836 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500837{
Tony Jonesee959b02008-02-22 00:13:36 +0100838 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500839 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
840 struct lpfc_hba *phba = vport->phba;
841 uint32_t cnt, acnt;
842
James Smart858c9f62007-06-17 19:56:39 -0500843 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500844 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
845 return snprintf(buf, PAGE_SIZE, "Unknown\n");
846}
847
James Smarte59058c2008-08-24 21:49:00 -0400848/**
849 * lpfc_max_xri_show: Return maximum xri.
850 * @dev: class device that is converted into a Scsi_host.
851 * @attr: device attribute, not used.
852 * @buf: on return contains the maximum xri count in decimal or "Unknown".
853 *
854 * Description:
855 * Calls lpfc_get_hba_info() asking for just the mrpi count.
856 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
857 * to "Unknown" and the buffer length is returned, therefore the caller
858 * must check for "Unknown" in the buffer to detect a failure.
859 *
860 * Returns: size of formatted string.
861 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500862static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100863lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
864 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500865{
Tony Jonesee959b02008-02-22 00:13:36 +0100866 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500867 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
868 struct lpfc_hba *phba = vport->phba;
869 uint32_t cnt;
870
James Smart858c9f62007-06-17 19:56:39 -0500871 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500872 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
873 return snprintf(buf, PAGE_SIZE, "Unknown\n");
874}
875
James Smarte59058c2008-08-24 21:49:00 -0400876/**
877 * lpfc_used_xri_show: Return maximum xpi minus the available xpi.
878 * @dev: class device that is converted into a Scsi_host.
879 * @attr: device attribute, not used.
880 * @buf: on return contains the used xri count in decimal or "Unknown".
881 *
882 * Description:
883 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
884 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
885 * to "Unknown" and the buffer length is returned, therefore the caller
886 * must check for "Unknown" in the buffer to detect a failure.
887 *
888 * Returns: size of formatted string.
889 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500890static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100891lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
892 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500893{
Tony Jonesee959b02008-02-22 00:13:36 +0100894 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500895 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
896 struct lpfc_hba *phba = vport->phba;
897 uint32_t cnt, acnt;
898
James Smart858c9f62007-06-17 19:56:39 -0500899 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
900 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
901 return snprintf(buf, PAGE_SIZE, "Unknown\n");
902}
903
James Smarte59058c2008-08-24 21:49:00 -0400904/**
905 * lpfc_max_vpi_show: Return maximum vpi.
906 * @dev: class device that is converted into a Scsi_host.
907 * @attr: device attribute, not used.
908 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
909 *
910 * Description:
911 * Calls lpfc_get_hba_info() asking for just the mvpi count.
912 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
913 * to "Unknown" and the buffer length is returned, therefore the caller
914 * must check for "Unknown" in the buffer to detect a failure.
915 *
916 * Returns: size of formatted string.
917 **/
James Smart858c9f62007-06-17 19:56:39 -0500918static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100919lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
920 char *buf)
James Smart858c9f62007-06-17 19:56:39 -0500921{
Tony Jonesee959b02008-02-22 00:13:36 +0100922 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -0500923 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
924 struct lpfc_hba *phba = vport->phba;
925 uint32_t cnt;
926
927 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
928 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
929 return snprintf(buf, PAGE_SIZE, "Unknown\n");
930}
931
James Smarte59058c2008-08-24 21:49:00 -0400932/**
933 * lpfc_used_vpi_show: Return maximum vpi minus the available vpi.
934 * @dev: class device that is converted into a Scsi_host.
935 * @attr: device attribute, not used.
936 * @buf: on return contains the used vpi count in decimal or "Unknown".
937 *
938 * Description:
939 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
940 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
941 * to "Unknown" and the buffer length is returned, therefore the caller
942 * must check for "Unknown" in the buffer to detect a failure.
943 *
944 * Returns: size of formatted string.
945 **/
James Smart858c9f62007-06-17 19:56:39 -0500946static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100947lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
948 char *buf)
James Smart858c9f62007-06-17 19:56:39 -0500949{
Tony Jonesee959b02008-02-22 00:13:36 +0100950 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -0500951 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
952 struct lpfc_hba *phba = vport->phba;
953 uint32_t cnt, acnt;
954
955 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -0500956 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
957 return snprintf(buf, PAGE_SIZE, "Unknown\n");
958}
959
James Smarte59058c2008-08-24 21:49:00 -0400960/**
961 * lpfc_npiv_info_show: Return text about NPIV support for the adapter.
962 * @dev: class device that is converted into a Scsi_host.
963 * @attr: device attribute, not used.
964 * @buf: text that must be interpreted to determine if npiv is supported.
965 *
966 * Description:
967 * Buffer will contain text indicating npiv is not suppoerted on the port,
968 * the port is an NPIV physical port, or it is an npiv virtual port with
969 * the id of the vport.
970 *
971 * Returns: size of formatted string.
972 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500973static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100974lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
975 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500976{
Tony Jonesee959b02008-02-22 00:13:36 +0100977 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500978 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
979 struct lpfc_hba *phba = vport->phba;
980
981 if (!(phba->max_vpi))
982 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
983 if (vport->port_type == LPFC_PHYSICAL_PORT)
984 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
985 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
986}
987
James Smarte59058c2008-08-24 21:49:00 -0400988/**
989 * lpfc_poll_show: Return text about poll support for the adapter.
990 * @dev: class device that is converted into a Scsi_host.
991 * @attr: device attribute, not used.
992 * @buf: on return contains the cfg_poll in hex.
993 *
994 * Notes:
995 * cfg_poll should be a lpfc_polling_flags type.
996 *
997 * Returns: size of formatted string.
998 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500999static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001000lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1001 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001002{
Tony Jonesee959b02008-02-22 00:13:36 +01001003 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001004 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1005 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001006
1007 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1008}
1009
James Smarte59058c2008-08-24 21:49:00 -04001010/**
1011 * lpfc_poll_store: Set the value of cfg_poll for the adapter.
1012 * @dev: class device that is converted into a Scsi_host.
1013 * @attr: device attribute, not used.
1014 * @buf: one or more lpfc_polling_flags values.
1015 * @count: not used.
1016 *
1017 * Notes:
1018 * buf contents converted to integer and checked for a valid value.
1019 *
1020 * Returns:
1021 * -EINVAL if the buffer connot be converted or is out of range
1022 * length of the buf on success
1023 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001024static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001025lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1026 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001027{
Tony Jonesee959b02008-02-22 00:13:36 +01001028 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001029 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1030 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001031 uint32_t creg_val;
1032 uint32_t old_val;
1033 int val=0;
1034
1035 if (!isdigit(buf[0]))
1036 return -EINVAL;
1037
1038 if (sscanf(buf, "%i", &val) != 1)
1039 return -EINVAL;
1040
1041 if ((val & 0x3) != val)
1042 return -EINVAL;
1043
James Smart2e0fef82007-06-17 19:56:36 -05001044 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001045
1046 old_val = phba->cfg_poll;
1047
1048 if (val & ENABLE_FCP_RING_POLLING) {
1049 if ((val & DISABLE_FCP_RING_INT) &&
1050 !(old_val & DISABLE_FCP_RING_INT)) {
1051 creg_val = readl(phba->HCregaddr);
1052 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1053 writel(creg_val, phba->HCregaddr);
1054 readl(phba->HCregaddr); /* flush */
1055
1056 lpfc_poll_start_timer(phba);
1057 }
1058 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001059 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001060 return -EINVAL;
1061 }
1062
1063 if (!(val & DISABLE_FCP_RING_INT) &&
1064 (old_val & DISABLE_FCP_RING_INT))
1065 {
James Smart2e0fef82007-06-17 19:56:36 -05001066 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001067 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001068 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001069 creg_val = readl(phba->HCregaddr);
1070 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1071 writel(creg_val, phba->HCregaddr);
1072 readl(phba->HCregaddr); /* flush */
1073 }
1074
1075 phba->cfg_poll = val;
1076
James Smart2e0fef82007-06-17 19:56:36 -05001077 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001078
1079 return strlen(buf);
1080}
dea31012005-04-17 16:05:31 -05001081
James Smarte59058c2008-08-24 21:49:00 -04001082/**
1083 * lpfc_param_show: Return a cfg attribute value in decimal.
1084 *
1085 * Description:
1086 * Macro that given an attr e.g. hba_queue_depth expands
1087 * into a function with the name lpfc_hba_queue_depth_show.
1088 *
1089 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1090 * @dev: class device that is converted into a Scsi_host.
1091 * @attr: device attribute, not used.
1092 * @buf: on return contains the attribute value in decimal.
1093 *
1094 * Returns: size of formatted string.
1095 **/
dea31012005-04-17 16:05:31 -05001096#define lpfc_param_show(attr) \
1097static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001098lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1099 char *buf) \
dea31012005-04-17 16:05:31 -05001100{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001101 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001102 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1103 struct lpfc_hba *phba = vport->phba;\
dea31012005-04-17 16:05:31 -05001104 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001105 val = phba->cfg_##attr;\
1106 return snprintf(buf, PAGE_SIZE, "%d\n",\
1107 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001108}
1109
James Smarte59058c2008-08-24 21:49:00 -04001110/**
1111 * lpfc_param_hex_show: Return a cfg attribute value in hex.
1112 *
1113 * Description:
1114 * Macro that given an attr e.g. hba_queue_depth expands
1115 * into a function with the name lpfc_hba_queue_depth_show
1116 *
1117 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1118 * @dev: class device that is converted into a Scsi_host.
1119 * @attr: device attribute, not used.
1120 * @buf: on return contains the attribute value in hexidecimal.
1121 *
1122 * Returns: size of formatted string.
1123 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001124#define lpfc_param_hex_show(attr) \
1125static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001126lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1127 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001128{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001129 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001130 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1131 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001132 int val = 0;\
1133 val = phba->cfg_##attr;\
1134 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1135 phba->cfg_##attr);\
1136}
1137
James Smarte59058c2008-08-24 21:49:00 -04001138/**
1139 * lpfc_param_init: Intializes a cfg attribute.
1140 *
1141 * Description:
1142 * Macro that given an attr e.g. hba_queue_depth expands
1143 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1144 * takes a default argument, a minimum and maximum argument.
1145 *
1146 * lpfc_##attr##_init: Initializes an attribute.
1147 * @phba: pointer the the adapter structure.
1148 * @val: integer attribute value.
1149 *
1150 * Validates the min and max values then sets the adapter config field
1151 * accordingly, or uses the default if out of range and prints an error message.
1152 *
1153 * Returns:
1154 * zero on success
1155 * -EINVAL if default used
1156 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001157#define lpfc_param_init(attr, default, minval, maxval) \
1158static int \
1159lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
1160{ \
1161 if (val >= minval && val <= maxval) {\
1162 phba->cfg_##attr = val;\
1163 return 0;\
1164 }\
1165 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001166 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1167 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001168 phba->cfg_##attr = default;\
1169 return -EINVAL;\
1170}
1171
James Smarte59058c2008-08-24 21:49:00 -04001172/**
1173 * lpfc_param_set: Set a cfg attribute value.
1174 *
1175 * Description:
1176 * Macro that given an attr e.g. hba_queue_depth expands
1177 * into a function with the name lpfc_hba_queue_depth_set
1178 *
1179 * lpfc_##attr##_set: Sets an attribute value.
1180 * @phba: pointer the the adapter structure.
1181 * @val: integer attribute value.
1182 *
1183 * Description:
1184 * Validates the min and max values then sets the
1185 * adapter config field if in the valid range. prints error message
1186 * and does not set the parameter if invalid.
1187 *
1188 * Returns:
1189 * zero on success
1190 * -EINVAL if val is invalid
1191 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001192#define lpfc_param_set(attr, default, minval, maxval) \
1193static int \
1194lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
1195{ \
1196 if (val >= minval && val <= maxval) {\
1197 phba->cfg_##attr = val;\
1198 return 0;\
1199 }\
1200 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001201 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1202 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001203 return -EINVAL;\
1204}
1205
James Smarte59058c2008-08-24 21:49:00 -04001206/**
1207 * lpfc_param_store: Set a vport attribute value.
1208 *
1209 * Description:
1210 * Macro that given an attr e.g. hba_queue_depth expands
1211 * into a function with the name lpfc_hba_queue_depth_store.
1212 *
1213 * lpfc_##attr##_store: Set an sttribute value.
1214 * @dev: class device that is converted into a Scsi_host.
1215 * @attr: device attribute, not used.
1216 * @buf: contains the attribute value in ascii.
1217 * @count: not used.
1218 *
1219 * Description:
1220 * Convert the ascii text number to an integer, then
1221 * use the lpfc_##attr##_set function to set the value.
1222 *
1223 * Returns:
1224 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1225 * length of buffer upon success.
1226 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001227#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001228static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001229lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1230 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001231{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001232 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001233 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1234 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001235 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001236 if (!isdigit(buf[0]))\
1237 return -EINVAL;\
1238 if (sscanf(buf, "%i", &val) != 1)\
1239 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001240 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001241 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001242 else \
1243 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001244}
1245
James Smarte59058c2008-08-24 21:49:00 -04001246/**
1247 * lpfc_vport_param_show: Return decimal formatted cfg attribute value.
1248 *
1249 * Description:
1250 * Macro that given an attr e.g. hba_queue_depth expands
1251 * into a function with the name lpfc_hba_queue_depth_show
1252 *
1253 * lpfc_##attr##_show: prints the attribute value in decimal.
1254 * @dev: class device that is converted into a Scsi_host.
1255 * @attr: device attribute, not used.
1256 * @buf: on return contains the attribute value in decimal.
1257 *
1258 * Returns: length of formatted string.
1259 **/
James Smart3de2a652007-08-02 11:09:59 -04001260#define lpfc_vport_param_show(attr) \
1261static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001262lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1263 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001264{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001265 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001266 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1267 int val = 0;\
1268 val = vport->cfg_##attr;\
1269 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1270}
1271
James Smarte59058c2008-08-24 21:49:00 -04001272/**
1273 * lpfc_vport_param_hex_show: Return hex formatted attribute value.
1274 *
1275 * Description:
1276 * Macro that given an attr e.g.
1277 * hba_queue_depth expands into a function with the name
1278 * lpfc_hba_queue_depth_show
1279 *
1280 * lpfc_##attr##_show: prints the attribute value in hexidecimal.
1281 * @dev: class device that is converted into a Scsi_host.
1282 * @attr: device attribute, not used.
1283 * @buf: on return contains the attribute value in hexidecimal.
1284 *
1285 * Returns: length of formatted string.
1286 **/
James Smart3de2a652007-08-02 11:09:59 -04001287#define lpfc_vport_param_hex_show(attr) \
1288static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001289lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1290 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001291{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001292 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001293 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1294 int val = 0;\
1295 val = vport->cfg_##attr;\
1296 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1297}
1298
James Smarte59058c2008-08-24 21:49:00 -04001299/**
1300 * lpfc_vport_param_init: Initialize a vport cfg attribute.
1301 *
1302 * Description:
1303 * Macro that given an attr e.g. hba_queue_depth expands
1304 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1305 * takes a default argument, a minimum and maximum argument.
1306 *
1307 * lpfc_##attr##_init: validates the min and max values then sets the
1308 * adapter config field accordingly, or uses the default if out of range
1309 * and prints an error message.
1310 * @phba: pointer the the adapter structure.
1311 * @val: integer attribute value.
1312 *
1313 * Returns:
1314 * zero on success
1315 * -EINVAL if default used
1316 **/
James Smart3de2a652007-08-02 11:09:59 -04001317#define lpfc_vport_param_init(attr, default, minval, maxval) \
1318static int \
1319lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
1320{ \
1321 if (val >= minval && val <= maxval) {\
1322 vport->cfg_##attr = val;\
1323 return 0;\
1324 }\
James Smarte8b62012007-08-02 11:10:09 -04001325 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001326 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001327 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001328 vport->cfg_##attr = default;\
1329 return -EINVAL;\
1330}
1331
James Smarte59058c2008-08-24 21:49:00 -04001332/**
1333 * lpfc_vport_param_set: Set a vport cfg attribute.
1334 *
1335 * Description:
1336 * Macro that given an attr e.g. hba_queue_depth expands
1337 * into a function with the name lpfc_hba_queue_depth_set
1338 *
1339 * lpfc_##attr##_set: validates the min and max values then sets the
1340 * adapter config field if in the valid range. prints error message
1341 * and does not set the parameter if invalid.
1342 * @phba: pointer the the adapter structure.
1343 * @val: integer attribute value.
1344 *
1345 * Returns:
1346 * zero on success
1347 * -EINVAL if val is invalid
1348 **/
James Smart3de2a652007-08-02 11:09:59 -04001349#define lpfc_vport_param_set(attr, default, minval, maxval) \
1350static int \
1351lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
1352{ \
1353 if (val >= minval && val <= maxval) {\
1354 vport->cfg_##attr = val;\
1355 return 0;\
1356 }\
James Smarte8b62012007-08-02 11:10:09 -04001357 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04001358 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04001359 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001360 return -EINVAL;\
1361}
1362
James Smarte59058c2008-08-24 21:49:00 -04001363/**
1364 * lpfc_vport_param_store: Set a vport attribute.
1365 *
1366 * Description:
1367 * Macro that given an attr e.g. hba_queue_depth
1368 * expands into a function with the name lpfc_hba_queue_depth_store
1369 *
1370 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1371 * use the lpfc_##attr##_set function to set the value.
1372 * @cdev: class device that is converted into a Scsi_host.
1373 * @buf: contains the attribute value in decimal.
1374 * @count: not used.
1375 *
1376 * Returns:
1377 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1378 * length of buffer upon success.
1379 **/
James Smart3de2a652007-08-02 11:09:59 -04001380#define lpfc_vport_param_store(attr) \
1381static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001382lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1383 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001384{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001385 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1387 int val=0;\
1388 if (!isdigit(buf[0]))\
1389 return -EINVAL;\
1390 if (sscanf(buf, "%i", &val) != 1)\
1391 return -EINVAL;\
1392 if (lpfc_##attr##_set(vport, val) == 0) \
1393 return strlen(buf);\
1394 else \
1395 return -EINVAL;\
1396}
1397
1398
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001399#define LPFC_ATTR(name, defval, minval, maxval, desc) \
1400static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -05001401module_param(lpfc_##name, int, 0);\
1402MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001403lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001404
1405#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1406static int lpfc_##name = defval;\
1407module_param(lpfc_##name, int, 0);\
1408MODULE_PARM_DESC(lpfc_##name, desc);\
1409lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001410lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001411static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001412
1413#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1414static int lpfc_##name = defval;\
1415module_param(lpfc_##name, int, 0);\
1416MODULE_PARM_DESC(lpfc_##name, desc);\
1417lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001418lpfc_param_init(name, defval, minval, maxval)\
1419lpfc_param_set(name, defval, minval, maxval)\
1420lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001421static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1422 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001423
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001424#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1425static int lpfc_##name = defval;\
1426module_param(lpfc_##name, int, 0);\
1427MODULE_PARM_DESC(lpfc_##name, desc);\
1428lpfc_param_hex_show(name)\
1429lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001430static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001431
1432#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1433static int lpfc_##name = defval;\
1434module_param(lpfc_##name, int, 0);\
1435MODULE_PARM_DESC(lpfc_##name, desc);\
1436lpfc_param_hex_show(name)\
1437lpfc_param_init(name, defval, minval, maxval)\
1438lpfc_param_set(name, defval, minval, maxval)\
1439lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001440static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1441 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001442
James Smart3de2a652007-08-02 11:09:59 -04001443#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1444static int lpfc_##name = defval;\
1445module_param(lpfc_##name, int, 0);\
1446MODULE_PARM_DESC(lpfc_##name, desc);\
1447lpfc_vport_param_init(name, defval, minval, maxval)
1448
1449#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1450static int lpfc_##name = defval;\
1451module_param(lpfc_##name, int, 0);\
1452MODULE_PARM_DESC(lpfc_##name, desc);\
1453lpfc_vport_param_show(name)\
1454lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001455static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001456
1457#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1458static int lpfc_##name = defval;\
1459module_param(lpfc_##name, int, 0);\
1460MODULE_PARM_DESC(lpfc_##name, desc);\
1461lpfc_vport_param_show(name)\
1462lpfc_vport_param_init(name, defval, minval, maxval)\
1463lpfc_vport_param_set(name, defval, minval, maxval)\
1464lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001465static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1466 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001467
1468#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1469static int lpfc_##name = defval;\
1470module_param(lpfc_##name, int, 0);\
1471MODULE_PARM_DESC(lpfc_##name, desc);\
1472lpfc_vport_param_hex_show(name)\
1473lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001474static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001475
1476#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1477static int lpfc_##name = defval;\
1478module_param(lpfc_##name, int, 0);\
1479MODULE_PARM_DESC(lpfc_##name, desc);\
1480lpfc_vport_param_hex_show(name)\
1481lpfc_vport_param_init(name, defval, minval, maxval)\
1482lpfc_vport_param_set(name, defval, minval, maxval)\
1483lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001484static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1485 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001486
Tony Jonesee959b02008-02-22 00:13:36 +01001487static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1488static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1489static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1490static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1491static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1492static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1493static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1494static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001495static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001496static DEVICE_ATTR(option_rom_version, S_IRUGO,
1497 lpfc_option_rom_version_show, NULL);
1498static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1499 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04001500static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001501static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1502static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1503static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1504 lpfc_board_mode_show, lpfc_board_mode_store);
1505static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1506static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1507static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1508static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1509static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1510static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1511static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1512static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1513static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
dea31012005-04-17 16:05:31 -05001514
James Smartc3f28af2006-08-18 17:47:18 -04001515
James Smarta12e07b2006-12-02 13:35:30 -05001516static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001517
James Smarte59058c2008-08-24 21:49:00 -04001518/**
1519 * lpfc_soft_wwn_enable_store: Allows setting of the wwn if the key is valid.
1520 * @dev: class device that is converted into a Scsi_host.
1521 * @attr: device attribute, not used.
1522 * @buf: containing the string lpfc_soft_wwn_key.
1523 * @count: must be size of lpfc_soft_wwn_key.
1524 *
1525 * Returns:
1526 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1527 * length of buf indicates success
1528 **/
James Smartc3f28af2006-08-18 17:47:18 -04001529static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001530lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1531 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001532{
Tony Jonesee959b02008-02-22 00:13:36 +01001533 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1535 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001536 unsigned int cnt = count;
1537
1538 /*
1539 * We're doing a simple sanity check for soft_wwpn setting.
1540 * We require that the user write a specific key to enable
1541 * the soft_wwpn attribute to be settable. Once the attribute
1542 * is written, the enable key resets. If further updates are
1543 * desired, the key must be written again to re-enable the
1544 * attribute.
1545 *
1546 * The "key" is not secret - it is a hardcoded string shown
1547 * here. The intent is to protect against the random user or
1548 * application that is just writing attributes.
1549 */
1550
1551 /* count may include a LF at end of string */
1552 if (buf[cnt-1] == '\n')
1553 cnt--;
1554
James Smarta12e07b2006-12-02 13:35:30 -05001555 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1556 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001557 return -EINVAL;
1558
James Smarta12e07b2006-12-02 13:35:30 -05001559 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001560 return count;
1561}
Tony Jonesee959b02008-02-22 00:13:36 +01001562static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1563 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001564
James Smarte59058c2008-08-24 21:49:00 -04001565/**
1566 * lpfc_soft_wwpn_show: Return the cfg soft ww port name of the adapter.
1567 * @dev: class device that is converted into a Scsi_host.
1568 * @attr: device attribute, not used.
1569 * @buf: on return contains the wwpn in hexidecimal.
1570 *
1571 * Returns: size of formatted string.
1572 **/
James Smartc3f28af2006-08-18 17:47:18 -04001573static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001574lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1575 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001576{
Tony Jonesee959b02008-02-22 00:13:36 +01001577 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001578 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1579 struct lpfc_hba *phba = vport->phba;
1580
Randy Dunlapafc071e2006-10-23 21:47:13 -07001581 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1582 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001583}
1584
James Smarte59058c2008-08-24 21:49:00 -04001585/**
1586 * lpfc_soft_wwpn_store: Set the ww port name of the adapter.
1587 * @dev class device that is converted into a Scsi_host.
1588 * @attr: device attribute, not used.
1589 * @buf: contains the wwpn in hexidecimal.
1590 * @count: number of wwpn bytes in buf
1591 *
1592 * Returns:
1593 * -EACCES hba reset not enabled, adapter over temp
1594 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1595 * -EIO error taking adapter offline or online
1596 * value of count on success
1597 **/
James Smartc3f28af2006-08-18 17:47:18 -04001598static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001599lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1600 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001601{
Tony Jonesee959b02008-02-22 00:13:36 +01001602 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001603 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1604 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001605 struct completion online_compl;
1606 int stat1=0, stat2=0;
1607 unsigned int i, j, cnt=count;
1608 u8 wwpn[8];
1609
James Smart13815c82008-01-11 01:52:48 -05001610 if (!phba->cfg_enable_hba_reset)
1611 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001612 spin_lock_irq(&phba->hbalock);
1613 if (phba->over_temp_state == HBA_OVER_TEMP) {
1614 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001615 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001616 }
1617 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001618 /* count may include a LF at end of string */
1619 if (buf[cnt-1] == '\n')
1620 cnt--;
1621
James Smarta12e07b2006-12-02 13:35:30 -05001622 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001623 ((cnt == 17) && (*buf++ != 'x')) ||
1624 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1625 return -EINVAL;
1626
James Smarta12e07b2006-12-02 13:35:30 -05001627 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001628
1629 memset(wwpn, 0, sizeof(wwpn));
1630
1631 /* Validate and store the new name */
1632 for (i=0, j=0; i < 16; i++) {
1633 if ((*buf >= 'a') && (*buf <= 'f'))
1634 j = ((j << 4) | ((*buf++ -'a') + 10));
1635 else if ((*buf >= 'A') && (*buf <= 'F'))
1636 j = ((j << 4) | ((*buf++ -'A') + 10));
1637 else if ((*buf >= '0') && (*buf <= '9'))
1638 j = ((j << 4) | (*buf++ -'0'));
1639 else
1640 return -EINVAL;
1641 if (i % 2) {
1642 wwpn[i/2] = j & 0xff;
1643 j = 0;
1644 }
1645 }
1646 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001647 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001648 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001649 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001650
1651 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1652 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1653
James Smart46fa3112007-04-25 09:51:45 -04001654 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001655 if (stat1)
1656 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001657 "0463 lpfc_soft_wwpn attribute set failed to "
1658 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001659 init_completion(&online_compl);
1660 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1661 wait_for_completion(&online_compl);
1662 if (stat2)
1663 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001664 "0464 lpfc_soft_wwpn attribute set failed to "
1665 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001666 return (stat1 || stat2) ? -EIO : count;
1667}
Tony Jonesee959b02008-02-22 00:13:36 +01001668static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1669 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001670
James Smarte59058c2008-08-24 21:49:00 -04001671/**
1672 * lpfc_soft_wwnn_show: Return the cfg soft ww node name for the adapter.
1673 * @dev: class device that is converted into a Scsi_host.
1674 * @attr: device attribute, not used.
1675 * @buf: on return contains the wwnn in hexidecimal.
1676 *
1677 * Returns: size of formatted string.
1678 **/
James Smarta12e07b2006-12-02 13:35:30 -05001679static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001680lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1681 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001682{
Tony Jonesee959b02008-02-22 00:13:36 +01001683 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001684 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001685 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1686 (unsigned long long)phba->cfg_soft_wwnn);
1687}
1688
James Smarte59058c2008-08-24 21:49:00 -04001689/**
1690 * lpfc_soft_wwnn_store: sets the ww node name of the adapter.
1691 * @cdev: class device that is converted into a Scsi_host.
1692 * @buf: contains the ww node name in hexidecimal.
1693 * @count: number of wwnn bytes in buf.
1694 *
1695 * Returns:
1696 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1697 * value of count on success
1698 **/
James Smarta12e07b2006-12-02 13:35:30 -05001699static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001700lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1701 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001702{
Tony Jonesee959b02008-02-22 00:13:36 +01001703 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001704 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001705 unsigned int i, j, cnt=count;
1706 u8 wwnn[8];
1707
1708 /* count may include a LF at end of string */
1709 if (buf[cnt-1] == '\n')
1710 cnt--;
1711
1712 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1713 ((cnt == 17) && (*buf++ != 'x')) ||
1714 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1715 return -EINVAL;
1716
1717 /*
1718 * Allow wwnn to be set many times, as long as the enable is set.
1719 * However, once the wwpn is set, everything locks.
1720 */
1721
1722 memset(wwnn, 0, sizeof(wwnn));
1723
1724 /* Validate and store the new name */
1725 for (i=0, j=0; i < 16; i++) {
1726 if ((*buf >= 'a') && (*buf <= 'f'))
1727 j = ((j << 4) | ((*buf++ -'a') + 10));
1728 else if ((*buf >= 'A') && (*buf <= 'F'))
1729 j = ((j << 4) | ((*buf++ -'A') + 10));
1730 else if ((*buf >= '0') && (*buf <= '9'))
1731 j = ((j << 4) | (*buf++ -'0'));
1732 else
1733 return -EINVAL;
1734 if (i % 2) {
1735 wwnn[i/2] = j & 0xff;
1736 j = 0;
1737 }
1738 }
1739 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1740
1741 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1742 "lpfc%d: soft_wwnn set. Value will take effect upon "
1743 "setting of the soft_wwpn\n", phba->brd_no);
1744
1745 return count;
1746}
Tony Jonesee959b02008-02-22 00:13:36 +01001747static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1748 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001749
James Smartc3f28af2006-08-18 17:47:18 -04001750
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001751static int lpfc_poll = 0;
1752module_param(lpfc_poll, int, 0);
1753MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1754 " 0 - none,"
1755 " 1 - poll with interrupts enabled"
1756 " 3 - poll and disable FCP ring interrupts");
1757
Tony Jonesee959b02008-02-22 00:13:36 +01001758static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1759 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001760
James Smart92d7f7b2007-06-17 19:56:38 -05001761int lpfc_sli_mode = 0;
1762module_param(lpfc_sli_mode, int, 0);
1763MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1764 " 0 - auto (SLI-3 if supported),"
1765 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1766 " 3 - select SLI-3");
1767
James Smart7ee5d432007-10-27 13:37:17 -04001768int lpfc_enable_npiv = 0;
1769module_param(lpfc_enable_npiv, int, 0);
1770MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1771lpfc_param_show(enable_npiv);
1772lpfc_param_init(enable_npiv, 0, 0, 1);
Tony Jonesee959b02008-02-22 00:13:36 +01001773static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
James Smart7ee5d432007-10-27 13:37:17 -04001774 lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001775
dea31012005-04-17 16:05:31 -05001776/*
James Smartc01f3202006-08-18 17:47:08 -04001777# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1778# until the timer expires. Value range is [0,255]. Default value is 30.
1779*/
1780static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1781static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1782module_param(lpfc_nodev_tmo, int, 0);
1783MODULE_PARM_DESC(lpfc_nodev_tmo,
1784 "Seconds driver will hold I/O waiting "
1785 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04001786
1787/**
1788 * lpfc_nodev_tmo_show: Return the hba dev loss timeout value.
1789 * @dev: class converted to a Scsi_host structure.
1790 * @attr: device attribute, not used.
1791 * @buf: on return contains the dev loss timeout in decimal.
1792 *
1793 * Returns: size of formatted string.
1794 **/
James Smartc01f3202006-08-18 17:47:08 -04001795static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001796lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1797 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04001798{
Tony Jonesee959b02008-02-22 00:13:36 +01001799 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001800 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smartc01f3202006-08-18 17:47:08 -04001801 int val = 0;
James Smart3de2a652007-08-02 11:09:59 -04001802 val = vport->cfg_devloss_tmo;
1803 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001804}
1805
James Smarte59058c2008-08-24 21:49:00 -04001806/**
1807 * lpfc_nodev_tmo_init: Set the hba nodev timeout value.
1808 * @vport: lpfc vport structure pointer.
1809 * @val: contains the nodev timeout value.
1810 *
1811 * Description:
1812 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1813 * a kernel error message is printed and zero is returned.
1814 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1815 * Otherwise nodev tmo is set to the default value.
1816 *
1817 * Returns:
1818 * zero if already set or if val is in range
1819 * -EINVAL val out of range
1820 **/
James Smartc01f3202006-08-18 17:47:08 -04001821static int
James Smart3de2a652007-08-02 11:09:59 -04001822lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001823{
James Smart3de2a652007-08-02 11:09:59 -04001824 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1825 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1826 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04001827 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001828 "0407 Ignoring nodev_tmo module "
James Smarte8b62012007-08-02 11:10:09 -04001829 "parameter because devloss_tmo is "
1830 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001831 return 0;
1832 }
1833
1834 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001835 vport->cfg_nodev_tmo = val;
1836 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04001837 return 0;
1838 }
James Smarte8b62012007-08-02 11:10:09 -04001839 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1840 "0400 lpfc_nodev_tmo attribute cannot be set to"
1841 " %d, allowed range is [%d, %d]\n",
1842 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04001843 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04001844 return -EINVAL;
1845}
1846
James Smarte59058c2008-08-24 21:49:00 -04001847/**
1848 * lpfc_update_rport_devloss_tmo: Update dev loss tmo value.
1849 * @vport: lpfc vport structure pointer.
1850 *
1851 * Description:
1852 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
1853 **/
James Smart7054a602007-04-25 09:52:34 -04001854static void
James Smart3de2a652007-08-02 11:09:59 -04001855lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04001856{
James Smart858c9f62007-06-17 19:56:39 -05001857 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04001858 struct lpfc_nodelist *ndlp;
1859
James Smart51ef4c22007-08-02 11:10:31 -04001860 shost = lpfc_shost_from_vport(vport);
1861 spin_lock_irq(shost->host_lock);
1862 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05001863 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04001864 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1865 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04001866}
1867
James Smarte59058c2008-08-24 21:49:00 -04001868/**
1869 * lpfc_nodev_tmo_set: Set the vport nodev tmo and devloss tmo values.
1870 * @vport: lpfc vport structure pointer.
1871 * @val: contains the tmo value.
1872 *
1873 * Description:
1874 * If the devloss tmo is already set or the vport dev loss tmo has changed
1875 * then a kernel error message is printed and zero is returned.
1876 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1877 * Otherwise nodev tmo is set to the default value.
1878 *
1879 * Returns:
1880 * zero if already set or if val is in range
1881 * -EINVAL val out of range
1882 **/
James Smartc01f3202006-08-18 17:47:08 -04001883static int
James Smart3de2a652007-08-02 11:09:59 -04001884lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001885{
James Smart3de2a652007-08-02 11:09:59 -04001886 if (vport->dev_loss_tmo_changed ||
1887 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04001888 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1889 "0401 Ignoring change to nodev_tmo "
1890 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001891 return 0;
1892 }
James Smartc01f3202006-08-18 17:47:08 -04001893 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001894 vport->cfg_nodev_tmo = val;
1895 vport->cfg_devloss_tmo = val;
1896 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001897 return 0;
1898 }
James Smarte8b62012007-08-02 11:10:09 -04001899 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1900 "0403 lpfc_nodev_tmo attribute cannot be set to"
1901 "%d, allowed range is [%d, %d]\n",
1902 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001903 return -EINVAL;
1904}
1905
James Smart3de2a652007-08-02 11:09:59 -04001906lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001907
Tony Jonesee959b02008-02-22 00:13:36 +01001908static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1909 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04001910
1911/*
1912# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1913# disappear until the timer expires. Value range is [0,255]. Default
1914# value is 30.
1915*/
1916module_param(lpfc_devloss_tmo, int, 0);
1917MODULE_PARM_DESC(lpfc_devloss_tmo,
1918 "Seconds driver will hold I/O waiting "
1919 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04001920lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
1921 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
1922lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04001923
1924/**
1925 * lpfc_devloss_tmo_set: Sets vport nodev tmo, devloss tmo values, changed bit.
1926 * @vport: lpfc vport structure pointer.
1927 * @val: contains the tmo value.
1928 *
1929 * Description:
1930 * If val is in a valid range then set the vport nodev tmo,
1931 * devloss tmo, also set the vport dev loss tmo changed flag.
1932 * Else a kernel error message is printed.
1933 *
1934 * Returns:
1935 * zero if val is in range
1936 * -EINVAL val out of range
1937 **/
James Smartc01f3202006-08-18 17:47:08 -04001938static int
James Smart3de2a652007-08-02 11:09:59 -04001939lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001940{
1941 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001942 vport->cfg_nodev_tmo = val;
1943 vport->cfg_devloss_tmo = val;
1944 vport->dev_loss_tmo_changed = 1;
1945 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001946 return 0;
1947 }
1948
James Smarte8b62012007-08-02 11:10:09 -04001949 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1950 "0404 lpfc_devloss_tmo attribute cannot be set to"
1951 " %d, allowed range is [%d, %d]\n",
1952 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001953 return -EINVAL;
1954}
1955
James Smart3de2a652007-08-02 11:09:59 -04001956lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01001957static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
1958 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04001959
1960/*
dea31012005-04-17 16:05:31 -05001961# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
1962# deluged with LOTS of information.
1963# You can set a bit mask to record specific types of verbose messages:
1964#
1965# LOG_ELS 0x1 ELS events
1966# LOG_DISCOVERY 0x2 Link discovery events
1967# LOG_MBOX 0x4 Mailbox events
1968# LOG_INIT 0x8 Initialization events
1969# LOG_LINK_EVENT 0x10 Link events
dea31012005-04-17 16:05:31 -05001970# LOG_FCP 0x40 FCP traffic history
1971# LOG_NODE 0x80 Node table events
1972# LOG_MISC 0x400 Miscellaneous events
1973# LOG_SLI 0x800 SLI events
James Smartc7743952006-12-02 13:34:42 -05001974# LOG_FCP_ERROR 0x1000 Only log FCP errors
dea31012005-04-17 16:05:31 -05001975# LOG_LIBDFC 0x2000 LIBDFC events
1976# LOG_ALL_MSG 0xffff LOG all messages
1977*/
James Smarte8b62012007-08-02 11:10:09 -04001978LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
1979 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05001980
1981/*
James Smart7ee5d432007-10-27 13:37:17 -04001982# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
1983# objects that have been registered with the nameserver after login.
1984*/
1985LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
1986 "Deregister nameserver objects before LOGO");
1987
1988/*
dea31012005-04-17 16:05:31 -05001989# lun_queue_depth: This parameter is used to limit the number of outstanding
1990# commands per FCP LUN. Value range is [1,128]. Default value is 30.
1991*/
James Smart3de2a652007-08-02 11:09:59 -04001992LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
1993 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05001994
1995/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001996# hba_queue_depth: This parameter is used to limit the number of outstanding
1997# commands per lpfc HBA. Value range is [32,8192]. If this parameter
1998# value is greater than the maximum number of exchanges supported by the HBA,
1999# then maximum number of exchanges supported by the HBA is used to determine
2000# the hba_queue_depth.
2001*/
2002LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2003 "Max number of FCP commands we can queue to a lpfc HBA");
2004
2005/*
James Smart92d7f7b2007-06-17 19:56:38 -05002006# peer_port_login: This parameter allows/prevents logins
2007# between peer ports hosted on the same physical port.
2008# When this parameter is set 0 peer ports of same physical port
2009# are not allowed to login to each other.
2010# When this parameter is set 1 peer ports of same physical port
2011# are allowed to login to each other.
2012# Default value of this parameter is 0.
2013*/
James Smart3de2a652007-08-02 11:09:59 -04002014LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2015 "Allow peer ports on the same physical port to login to each "
2016 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05002017
2018/*
James Smart3de2a652007-08-02 11:09:59 -04002019# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05002020# between Virtual Ports and remote initiators.
2021# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2022# other initiators and will attempt to PLOGI all remote ports.
2023# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2024# remote ports and will not attempt to PLOGI to other initiators.
2025# This parameter does not restrict to the physical port.
2026# This parameter does not restrict logins to Fabric resident remote ports.
2027# Default value of this parameter is 1.
2028*/
James Smart3de2a652007-08-02 11:09:59 -04002029static int lpfc_restrict_login = 1;
2030module_param(lpfc_restrict_login, int, 0);
2031MODULE_PARM_DESC(lpfc_restrict_login,
2032 "Restrict virtual ports login to remote initiators.");
2033lpfc_vport_param_show(restrict_login);
2034
James Smarte59058c2008-08-24 21:49:00 -04002035/**
2036 * lpfc_restrict_login_init: Set the vport restrict login flag.
2037 * @vport: lpfc vport structure pointer.
2038 * @val: contains the restrict login value.
2039 *
2040 * Description:
2041 * If val is not in a valid range then log a kernel error message and set
2042 * the vport restrict login to one.
2043 * If the port type is physical clear the restrict login flag and return.
2044 * Else set the restrict login flag to val.
2045 *
2046 * Returns:
2047 * zero if val is in range
2048 * -EINVAL val out of range
2049 **/
James Smart3de2a652007-08-02 11:09:59 -04002050static int
2051lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2052{
2053 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002054 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002055 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002056 "be set to %d, allowed range is [0, 1]\n",
2057 val);
James Smart3de2a652007-08-02 11:09:59 -04002058 vport->cfg_restrict_login = 1;
2059 return -EINVAL;
2060 }
2061 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2062 vport->cfg_restrict_login = 0;
2063 return 0;
2064 }
2065 vport->cfg_restrict_login = val;
2066 return 0;
2067}
2068
James Smarte59058c2008-08-24 21:49:00 -04002069/**
2070 * lpfc_restrict_login_set: Set the vport restrict login flag.
2071 * @vport: lpfc vport structure pointer.
2072 * @val: contains the restrict login value.
2073 *
2074 * Description:
2075 * If val is not in a valid range then log a kernel error message and set
2076 * the vport restrict login to one.
2077 * If the port type is physical and the val is not zero log a kernel
2078 * error message, clear the restrict login flag and return zero.
2079 * Else set the restrict login flag to val.
2080 *
2081 * Returns:
2082 * zero if val is in range
2083 * -EINVAL val out of range
2084 **/
James Smart3de2a652007-08-02 11:09:59 -04002085static int
2086lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2087{
2088 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002089 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002090 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04002091 "be set to %d, allowed range is [0, 1]\n",
2092 val);
James Smart3de2a652007-08-02 11:09:59 -04002093 vport->cfg_restrict_login = 1;
2094 return -EINVAL;
2095 }
2096 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002097 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2098 "0468 lpfc_restrict_login must be 0 for "
2099 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002100 vport->cfg_restrict_login = 0;
2101 return 0;
2102 }
2103 vport->cfg_restrict_login = val;
2104 return 0;
2105}
2106lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002107static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2108 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002109
2110/*
dea31012005-04-17 16:05:31 -05002111# Some disk devices have a "select ID" or "select Target" capability.
2112# From a protocol standpoint "select ID" usually means select the
2113# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2114# annex" which contains a table that maps a "select ID" (a number
2115# between 0 and 7F) to an ALPA. By default, for compatibility with
2116# older drivers, the lpfc driver scans this table from low ALPA to high
2117# ALPA.
2118#
2119# Turning on the scan-down variable (on = 1, off = 0) will
2120# cause the lpfc driver to use an inverted table, effectively
2121# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2122#
2123# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2124# and will not work across a fabric. Also this parameter will take
2125# effect only in the case when ALPA map is not available.)
2126*/
James Smart3de2a652007-08-02 11:09:59 -04002127LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2128 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002129
2130/*
dea31012005-04-17 16:05:31 -05002131# lpfc_topology: link topology for init link
2132# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002133# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002134# 0x02 = attempt point-to-point mode only
2135# 0x04 = attempt loop mode only
2136# 0x06 = attempt point-to-point mode then loop
2137# Set point-to-point mode if you want to run as an N_Port.
2138# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2139# Default value is 0.
2140*/
James Smarte59058c2008-08-24 21:49:00 -04002141
2142/**
2143 * lpfc_topology_set: Set the adapters topology field.
2144 * @phba: lpfc_hba pointer.
2145 * @val: topology value.
2146 *
2147 * Description:
2148 * If val is in a valid range then set the adapter's topology field and
2149 * issue a lip; if the lip fails reset the topology to the old value.
2150 *
2151 * If the value is not in range log a kernel error message and return an error.
2152 *
2153 * Returns:
2154 * zero if val is in range and lip okay
2155 * non-zero return value from lpfc_issue_lip()
2156 * -EINVAL val out of range
2157 **/
James Smart83108bd2008-01-11 01:53:09 -05002158static int
2159lpfc_topology_set(struct lpfc_hba *phba, int val)
2160{
2161 int err;
2162 uint32_t prev_val;
2163 if (val >= 0 && val <= 6) {
2164 prev_val = phba->cfg_topology;
2165 phba->cfg_topology = val;
2166 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2167 if (err)
2168 phba->cfg_topology = prev_val;
2169 return err;
2170 }
2171 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2172 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2173 "allowed range is [0, 6]\n",
2174 phba->brd_no, val);
2175 return -EINVAL;
2176}
2177static int lpfc_topology = 0;
2178module_param(lpfc_topology, int, 0);
2179MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2180lpfc_param_show(topology)
2181lpfc_param_init(topology, 0, 0, 6)
2182lpfc_param_store(topology)
Tony Jonesee959b02008-02-22 00:13:36 +01002183static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002184 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002185
2186/*
2187# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2188# connection.
2189# 0 = auto select (default)
2190# 1 = 1 Gigabaud
2191# 2 = 2 Gigabaud
2192# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04002193# 8 = 8 Gigabaud
2194# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05002195*/
James Smarte59058c2008-08-24 21:49:00 -04002196
2197/**
2198 * lpfc_link_speed_set: Set the adapters link speed.
2199 * @phba: lpfc_hba pointer.
2200 * @val: link speed value.
2201 *
2202 * Description:
2203 * If val is in a valid range then set the adapter's link speed field and
2204 * issue a lip; if the lip fails reset the link speed to the old value.
2205 *
2206 * Notes:
2207 * If the value is not in range log a kernel error message and return an error.
2208 *
2209 * Returns:
2210 * zero if val is in range and lip okay.
2211 * non-zero return value from lpfc_issue_lip()
2212 * -EINVAL val out of range
2213 **/
James Smart83108bd2008-01-11 01:53:09 -05002214static int
2215lpfc_link_speed_set(struct lpfc_hba *phba, int val)
2216{
2217 int err;
2218 uint32_t prev_val;
2219
2220 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2221 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2222 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2223 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2224 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2225 return -EINVAL;
2226
2227 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2228 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2229 prev_val = phba->cfg_link_speed;
2230 phba->cfg_link_speed = val;
2231 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2232 if (err)
2233 phba->cfg_link_speed = prev_val;
2234 return err;
2235 }
2236
2237 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2238 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2239 "allowed range is [0, 8]\n",
2240 phba->brd_no, val);
2241 return -EINVAL;
2242}
2243
2244static int lpfc_link_speed = 0;
2245module_param(lpfc_link_speed, int, 0);
2246MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2247lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002248
2249/**
2250 * lpfc_link_speed_init: Set the adapters link speed.
2251 * @phba: lpfc_hba pointer.
2252 * @val: link speed value.
2253 *
2254 * Description:
2255 * If val is in a valid range then set the adapter's link speed field.
2256 *
2257 * Notes:
2258 * If the value is not in range log a kernel error message, clear the link
2259 * speed and return an error.
2260 *
2261 * Returns:
2262 * zero if val saved.
2263 * -EINVAL val out of range
2264 **/
James Smart83108bd2008-01-11 01:53:09 -05002265static int
2266lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2267{
2268 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2269 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2270 phba->cfg_link_speed = val;
2271 return 0;
2272 }
2273 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002274 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05002275 "be set to %d, allowed values are "
2276 "["LPFC_LINK_SPEED_STRING"]\n", val);
2277 phba->cfg_link_speed = 0;
2278 return -EINVAL;
2279}
2280
2281lpfc_param_store(link_speed)
Tony Jonesee959b02008-02-22 00:13:36 +01002282static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002283 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002284
2285/*
2286# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
2287# Value range is [2,3]. Default value is 3.
2288*/
James Smart3de2a652007-08-02 11:09:59 -04002289LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
2290 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05002291
2292/*
2293# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
2294# is [0,1]. Default value is 0.
2295*/
James Smart3de2a652007-08-02 11:09:59 -04002296LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
2297 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05002298
2299/*
James Smart977b5a02008-09-07 11:52:04 -04002300# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
2301# depth. Default value is 0. When the value of this parameter is zero the
2302# SCSI command completion time is not used for controlling I/O queue depth. When
2303# the parameter is set to a non-zero value, the I/O queue depth is controlled
2304# to limit the I/O completion time to the parameter value.
2305# The value is set in milliseconds.
2306*/
2307static int lpfc_max_scsicmpl_time;
2308module_param(lpfc_max_scsicmpl_time, int, 0);
2309MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
2310 "Use command completion time to control queue depth");
2311lpfc_vport_param_show(max_scsicmpl_time);
2312lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
2313static int
2314lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
2315{
2316 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2317 struct lpfc_nodelist *ndlp, *next_ndlp;
2318
2319 if (val == vport->cfg_max_scsicmpl_time)
2320 return 0;
2321 if ((val < 0) || (val > 60000))
2322 return -EINVAL;
2323 vport->cfg_max_scsicmpl_time = val;
2324
2325 spin_lock_irq(shost->host_lock);
2326 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2327 if (!NLP_CHK_NODE_ACT(ndlp))
2328 continue;
2329 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2330 continue;
2331 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
2332 }
2333 spin_unlock_irq(shost->host_lock);
2334 return 0;
2335}
2336lpfc_vport_param_store(max_scsicmpl_time);
2337static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
2338 lpfc_max_scsicmpl_time_show,
2339 lpfc_max_scsicmpl_time_store);
2340
2341/*
dea31012005-04-17 16:05:31 -05002342# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
2343# range is [0,1]. Default value is 0.
2344*/
2345LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
2346
2347/*
2348# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
2349# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04002350# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05002351# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
2352# cr_delay is set to 0.
2353*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05002354LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05002355 "interrupt response is generated");
2356
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05002357LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05002358 "interrupt response is generated");
2359
2360/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002361# lpfc_multi_ring_support: Determines how many rings to spread available
2362# cmd/rsp IOCB entries across.
2363# Value range is [1,2]. Default value is 1.
2364*/
2365LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
2366 "SLI rings to spread IOCB entries across");
2367
2368/*
James Smarta4bc3372006-12-02 13:34:16 -05002369# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
2370# identifies what rctl value to configure the additional ring for.
2371# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
2372*/
2373LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
2374 255, "Identifies RCTL for additional ring configuration");
2375
2376/*
2377# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
2378# identifies what type value to configure the additional ring for.
2379# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
2380*/
2381LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
2382 255, "Identifies TYPE for additional ring configuration");
2383
2384/*
dea31012005-04-17 16:05:31 -05002385# lpfc_fdmi_on: controls FDMI support.
2386# 0 = no FDMI support
2387# 1 = support FDMI without attribute of hostname
2388# 2 = support FDMI with attribute of hostname
2389# Value range [0,2]. Default value is 0.
2390*/
James Smart3de2a652007-08-02 11:09:59 -04002391LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05002392
2393/*
2394# Specifies the maximum number of ELS cmds we can have outstanding (for
2395# discovery). Value range is [1,64]. Default value = 32.
2396*/
James Smart3de2a652007-08-02 11:09:59 -04002397LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05002398 "during discovery");
2399
2400/*
James Smart65a29c12006-07-06 15:50:50 -04002401# lpfc_max_luns: maximum allowed LUN.
2402# Value range is [0,65535]. Default value is 255.
2403# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05002404*/
James Smart3de2a652007-08-02 11:09:59 -04002405LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05002406
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002407/*
2408# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
2409# Value range is [1,255], default value is 10.
2410*/
2411LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
2412 "Milliseconds driver will wait between polling FCP ring");
2413
James Smart4ff43242006-12-02 13:34:56 -05002414/*
2415# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
2416# support this feature
James Smart93996272008-08-24 21:50:30 -04002417# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05002418# 1 = MSI enabled
James Smart93996272008-08-24 21:50:30 -04002419# 2 = MSI-X enabled (default)
2420# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05002421*/
James Smart93996272008-08-24 21:50:30 -04002422LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05002423 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05002424
James Smart13815c82008-01-11 01:52:48 -05002425/*
2426# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
2427# 0 = HBA resets disabled
2428# 1 = HBA resets enabled (default)
2429# Value range is [0,1]. Default value is 1.
2430*/
2431LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04002432
James Smart13815c82008-01-11 01:52:48 -05002433/*
2434# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
2435# 0 = HBA Heartbeat disabled
2436# 1 = HBA Heartbeat enabled (default)
2437# Value range is [0,1]. Default value is 1.
2438*/
2439LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05002440
James Smart83108bd2008-01-11 01:53:09 -05002441/*
2442 * lpfc_sg_seg_cnt: Initial Maximum DMA Segment Count
2443 * This value can be set to values between 64 and 256. The default value is
2444 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
2445 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
2446 */
2447LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
2448 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
2449
Tony Jonesee959b02008-02-22 00:13:36 +01002450struct device_attribute *lpfc_hba_attrs[] = {
2451 &dev_attr_info,
2452 &dev_attr_serialnum,
2453 &dev_attr_modeldesc,
2454 &dev_attr_modelname,
2455 &dev_attr_programtype,
2456 &dev_attr_portnum,
2457 &dev_attr_fwrev,
2458 &dev_attr_hdw,
2459 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01002460 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01002461 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04002462 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01002463 &dev_attr_lpfc_drvr_version,
2464 &dev_attr_lpfc_temp_sensor,
2465 &dev_attr_lpfc_log_verbose,
2466 &dev_attr_lpfc_lun_queue_depth,
2467 &dev_attr_lpfc_hba_queue_depth,
2468 &dev_attr_lpfc_peer_port_login,
2469 &dev_attr_lpfc_nodev_tmo,
2470 &dev_attr_lpfc_devloss_tmo,
2471 &dev_attr_lpfc_fcp_class,
2472 &dev_attr_lpfc_use_adisc,
2473 &dev_attr_lpfc_ack0,
2474 &dev_attr_lpfc_topology,
2475 &dev_attr_lpfc_scan_down,
2476 &dev_attr_lpfc_link_speed,
2477 &dev_attr_lpfc_cr_delay,
2478 &dev_attr_lpfc_cr_count,
2479 &dev_attr_lpfc_multi_ring_support,
2480 &dev_attr_lpfc_multi_ring_rctl,
2481 &dev_attr_lpfc_multi_ring_type,
2482 &dev_attr_lpfc_fdmi_on,
2483 &dev_attr_lpfc_max_luns,
2484 &dev_attr_lpfc_enable_npiv,
2485 &dev_attr_nport_evt_cnt,
2486 &dev_attr_board_mode,
2487 &dev_attr_max_vpi,
2488 &dev_attr_used_vpi,
2489 &dev_attr_max_rpi,
2490 &dev_attr_used_rpi,
2491 &dev_attr_max_xri,
2492 &dev_attr_used_xri,
2493 &dev_attr_npiv_info,
2494 &dev_attr_issue_reset,
2495 &dev_attr_lpfc_poll,
2496 &dev_attr_lpfc_poll_tmo,
2497 &dev_attr_lpfc_use_msi,
2498 &dev_attr_lpfc_soft_wwnn,
2499 &dev_attr_lpfc_soft_wwpn,
2500 &dev_attr_lpfc_soft_wwn_enable,
2501 &dev_attr_lpfc_enable_hba_reset,
2502 &dev_attr_lpfc_enable_hba_heartbeat,
2503 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04002504 &dev_attr_lpfc_max_scsicmpl_time,
dea31012005-04-17 16:05:31 -05002505 NULL,
2506};
2507
Tony Jonesee959b02008-02-22 00:13:36 +01002508struct device_attribute *lpfc_vport_attrs[] = {
2509 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01002510 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01002511 &dev_attr_num_discovered_ports,
2512 &dev_attr_lpfc_drvr_version,
2513 &dev_attr_lpfc_log_verbose,
2514 &dev_attr_lpfc_lun_queue_depth,
2515 &dev_attr_lpfc_nodev_tmo,
2516 &dev_attr_lpfc_devloss_tmo,
2517 &dev_attr_lpfc_hba_queue_depth,
2518 &dev_attr_lpfc_peer_port_login,
2519 &dev_attr_lpfc_restrict_login,
2520 &dev_attr_lpfc_fcp_class,
2521 &dev_attr_lpfc_use_adisc,
2522 &dev_attr_lpfc_fdmi_on,
2523 &dev_attr_lpfc_max_luns,
2524 &dev_attr_nport_evt_cnt,
2525 &dev_attr_npiv_info,
2526 &dev_attr_lpfc_enable_da_id,
James Smart3de2a652007-08-02 11:09:59 -04002527 NULL,
2528};
2529
James Smarte59058c2008-08-24 21:49:00 -04002530/**
2531 * sysfs_ctlreg_write: Write method for writing to ctlreg.
2532 * @kobj: kernel kobject that contains the kernel class device.
2533 * @bin_attr: kernel attributes passed to us.
2534 * @buf: contains the data to be written to the adapter IOREG space.
2535 * @off: offset into buffer to beginning of data.
2536 * @count: bytes to transfer.
2537 *
2538 * Description:
2539 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
2540 * Uses the adapter io control registers to send buf contents to the adapter.
2541 *
2542 * Returns:
2543 * -ERANGE off and count combo out of range
2544 * -EINVAL off, count or buff address invalid
2545 * -EPERM adapter is offline
2546 * value of count, buf contents written
2547 **/
dea31012005-04-17 16:05:31 -05002548static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08002549sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
2550 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05002551{
2552 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01002553 struct device *dev = container_of(kobj, struct device, kobj);
2554 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002555 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2556 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002557
2558 if ((off + count) > FF_REG_AREA_SIZE)
2559 return -ERANGE;
2560
2561 if (count == 0) return 0;
2562
2563 if (off % 4 || count % 4 || (unsigned long)buf % 4)
2564 return -EINVAL;
2565
James Smart2e0fef82007-06-17 19:56:36 -05002566 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05002567 return -EPERM;
2568 }
2569
James Smart2e0fef82007-06-17 19:56:36 -05002570 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002571 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
2572 writel(*((uint32_t *)(buf + buf_off)),
2573 phba->ctrl_regs_memmap_p + off + buf_off);
2574
James Smart2e0fef82007-06-17 19:56:36 -05002575 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002576
2577 return count;
2578}
2579
James Smarte59058c2008-08-24 21:49:00 -04002580/**
2581 * sysfs_ctlreg_read: Read method for reading from ctlreg.
2582 * @kobj: kernel kobject that contains the kernel class device.
2583 * @bin_attr: kernel attributes passed to us.
2584 * @buf: if succesful contains the data from the adapter IOREG space.
2585 * @off: offset into buffer to beginning of data.
2586 * @count: bytes to transfer.
2587 *
2588 * Description:
2589 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
2590 * Uses the adapter io control registers to read data into buf.
2591 *
2592 * Returns:
2593 * -ERANGE off and count combo out of range
2594 * -EINVAL off, count or buff address invalid
2595 * value of count, buf contents read
2596 **/
dea31012005-04-17 16:05:31 -05002597static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08002598sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2599 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05002600{
2601 size_t buf_off;
2602 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01002603 struct device *dev = container_of(kobj, struct device, kobj);
2604 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002605 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2606 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002607
2608 if (off > FF_REG_AREA_SIZE)
2609 return -ERANGE;
2610
2611 if ((off + count) > FF_REG_AREA_SIZE)
2612 count = FF_REG_AREA_SIZE - off;
2613
2614 if (count == 0) return 0;
2615
2616 if (off % 4 || count % 4 || (unsigned long)buf % 4)
2617 return -EINVAL;
2618
James Smart2e0fef82007-06-17 19:56:36 -05002619 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002620
2621 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
2622 tmp_ptr = (uint32_t *)(buf + buf_off);
2623 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
2624 }
2625
James Smart2e0fef82007-06-17 19:56:36 -05002626 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002627
2628 return count;
2629}
2630
2631static struct bin_attribute sysfs_ctlreg_attr = {
2632 .attr = {
2633 .name = "ctlreg",
2634 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05002635 },
2636 .size = 256,
2637 .read = sysfs_ctlreg_read,
2638 .write = sysfs_ctlreg_write,
2639};
2640
James Smarte59058c2008-08-24 21:49:00 -04002641/**
2642 * sysfs_mbox_idle: frees the sysfs mailbox.
2643 * @phba: lpfc_hba pointer
2644 **/
dea31012005-04-17 16:05:31 -05002645static void
James Smart2e0fef82007-06-17 19:56:36 -05002646sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002647{
2648 phba->sysfs_mbox.state = SMBOX_IDLE;
2649 phba->sysfs_mbox.offset = 0;
2650
2651 if (phba->sysfs_mbox.mbox) {
2652 mempool_free(phba->sysfs_mbox.mbox,
2653 phba->mbox_mem_pool);
2654 phba->sysfs_mbox.mbox = NULL;
2655 }
2656}
2657
James Smarte59058c2008-08-24 21:49:00 -04002658/**
2659 * sysfs_mbox_write: Write method for writing information via mbox.
2660 * @kobj: kernel kobject that contains the kernel class device.
2661 * @bin_attr: kernel attributes passed to us.
2662 * @buf: contains the data to be written to sysfs mbox.
2663 * @off: offset into buffer to beginning of data.
2664 * @count: bytes to transfer.
2665 *
2666 * Description:
2667 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
2668 * Uses the sysfs mbox to send buf contents to the adapter.
2669 *
2670 * Returns:
2671 * -ERANGE off and count combo out of range
2672 * -EINVAL off, count or buff address invalid
2673 * zero if count is zero
2674 * -EPERM adapter is offline
2675 * -ENOMEM failed to allocate memory for the mail box
2676 * -EAGAIN offset, state or mbox is NULL
2677 * count number of bytes transferred
2678 **/
dea31012005-04-17 16:05:31 -05002679static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08002680sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
2681 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05002682{
Tony Jonesee959b02008-02-22 00:13:36 +01002683 struct device *dev = container_of(kobj, struct device, kobj);
2684 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002685 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2686 struct lpfc_hba *phba = vport->phba;
2687 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05002688
2689 if ((count + off) > MAILBOX_CMD_SIZE)
2690 return -ERANGE;
2691
2692 if (off % 4 || count % 4 || (unsigned long)buf % 4)
2693 return -EINVAL;
2694
2695 if (count == 0)
2696 return 0;
2697
2698 if (off == 0) {
2699 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2700 if (!mbox)
2701 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05002702 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05002703 }
2704
James Smart2e0fef82007-06-17 19:56:36 -05002705 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002706
2707 if (off == 0) {
2708 if (phba->sysfs_mbox.mbox)
2709 mempool_free(mbox, phba->mbox_mem_pool);
2710 else
2711 phba->sysfs_mbox.mbox = mbox;
2712 phba->sysfs_mbox.state = SMBOX_WRITING;
2713 } else {
2714 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
2715 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05002716 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05002717 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002718 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04002719 return -EAGAIN;
dea31012005-04-17 16:05:31 -05002720 }
2721 }
2722
2723 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
2724 buf, count);
2725
2726 phba->sysfs_mbox.offset = off + count;
2727
James Smart2e0fef82007-06-17 19:56:36 -05002728 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002729
2730 return count;
2731}
2732
James Smarte59058c2008-08-24 21:49:00 -04002733/**
2734 * sysfs_mbox_read: Read method for reading information via mbox.
2735 * @kobj: kernel kobject that contains the kernel class device.
2736 * @bin_attr: kernel attributes passed to us.
2737 * @buf: contains the data to be read from sysfs mbox.
2738 * @off: offset into buffer to beginning of data.
2739 * @count: bytes to transfer.
2740 *
2741 * Description:
2742 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
2743 * Uses the sysfs mbox to receive data from to the adapter.
2744 *
2745 * Returns:
2746 * -ERANGE off greater than mailbox command size
2747 * -EINVAL off, count or buff address invalid
2748 * zero if off and count are zero
2749 * -EACCES adapter over temp
2750 * -EPERM garbage can value to catch a multitude of errors
2751 * -EAGAIN management IO not permitted, state or off error
2752 * -ETIME mailbox timeout
2753 * -ENODEV mailbox error
2754 * count number of bytes transferred
2755 **/
dea31012005-04-17 16:05:31 -05002756static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08002757sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2758 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05002759{
Tony Jonesee959b02008-02-22 00:13:36 +01002760 struct device *dev = container_of(kobj, struct device, kobj);
2761 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002762 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2763 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002764 int rc;
2765
James Smart1dcb58e2007-04-25 09:51:30 -04002766 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05002767 return -ERANGE;
2768
James Smart1dcb58e2007-04-25 09:51:30 -04002769 if ((count + off) > MAILBOX_CMD_SIZE)
2770 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05002771
2772 if (off % 4 || count % 4 || (unsigned long)buf % 4)
2773 return -EINVAL;
2774
2775 if (off && count == 0)
2776 return 0;
2777
James Smart2e0fef82007-06-17 19:56:36 -05002778 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002779
James Smart7af67052007-10-27 13:38:11 -04002780 if (phba->over_temp_state == HBA_OVER_TEMP) {
2781 sysfs_mbox_idle(phba);
2782 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05002783 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002784 }
2785
dea31012005-04-17 16:05:31 -05002786 if (off == 0 &&
2787 phba->sysfs_mbox.state == SMBOX_WRITING &&
2788 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
2789
2790 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
2791 /* Offline only */
dea31012005-04-17 16:05:31 -05002792 case MBX_INIT_LINK:
2793 case MBX_DOWN_LINK:
2794 case MBX_CONFIG_LINK:
2795 case MBX_CONFIG_RING:
2796 case MBX_RESET_RING:
2797 case MBX_UNREG_LOGIN:
2798 case MBX_CLEAR_LA:
2799 case MBX_DUMP_CONTEXT:
2800 case MBX_RUN_DIAGS:
2801 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05002802 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05002803 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05002804 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05002805 printk(KERN_WARNING "mbox_read:Command 0x%x "
2806 "is illegal in on-line state\n",
2807 phba->sysfs_mbox.mbox->mb.mbxCommand);
2808 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002809 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002810 return -EPERM;
2811 }
James Smarta8adb832007-10-27 13:37:53 -04002812 case MBX_WRITE_NV:
2813 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05002814 case MBX_LOAD_SM:
2815 case MBX_READ_NV:
2816 case MBX_READ_CONFIG:
2817 case MBX_READ_RCONFIG:
2818 case MBX_READ_STATUS:
2819 case MBX_READ_XRI:
2820 case MBX_READ_REV:
2821 case MBX_READ_LNK_STAT:
2822 case MBX_DUMP_MEMORY:
2823 case MBX_DOWN_LOAD:
2824 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05002825 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05002826 case MBX_LOAD_AREA:
2827 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05002828 case MBX_BEACON:
2829 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05002830 case MBX_SET_VARIABLE:
2831 case MBX_WRITE_WWN:
James Smart84774a42008-08-24 21:50:06 -04002832 case MBX_PORT_CAPABILITIES:
2833 case MBX_PORT_IOV_CONTROL:
dea31012005-04-17 16:05:31 -05002834 break;
2835 case MBX_READ_SPARM64:
2836 case MBX_READ_LA:
2837 case MBX_READ_LA64:
2838 case MBX_REG_LOGIN:
2839 case MBX_REG_LOGIN64:
2840 case MBX_CONFIG_PORT:
2841 case MBX_RUN_BIU_DIAG:
2842 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
2843 phba->sysfs_mbox.mbox->mb.mbxCommand);
2844 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002845 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002846 return -EPERM;
2847 default:
2848 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
2849 phba->sysfs_mbox.mbox->mb.mbxCommand);
2850 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002851 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002852 return -EPERM;
2853 }
2854
James Smart09372822008-01-11 01:52:54 -05002855 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05002856 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05002857 */
James Smartd7c255b2008-08-24 21:50:00 -04002858 if (phba->pport->stopped &&
2859 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_DUMP_MEMORY &&
2860 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_RESTART &&
2861 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_WRITE_VPARMS &&
2862 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_WRITE_WWN)
2863 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
2864 "1259 mbox: Issued mailbox cmd "
2865 "0x%x while in stopped state.\n",
2866 phba->sysfs_mbox.mbox->mb.mbxCommand);
James Smart09372822008-01-11 01:52:54 -05002867
James Smart92d7f7b2007-06-17 19:56:38 -05002868 phba->sysfs_mbox.mbox->vport = vport;
2869
James Smart58da1ff2008-04-07 10:15:56 -04002870 /* Don't allow mailbox commands to be sent when blocked
2871 * or when in the middle of discovery
2872 */
James Smart495a7142008-06-14 22:52:59 -04002873 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04002874 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002875 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04002876 return -EAGAIN;
2877 }
2878
James Smart2e0fef82007-06-17 19:56:36 -05002879 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
dea31012005-04-17 16:05:31 -05002880 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
2881
James Smart2e0fef82007-06-17 19:56:36 -05002882 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002883 rc = lpfc_sli_issue_mbox (phba,
2884 phba->sysfs_mbox.mbox,
2885 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05002886 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002887
2888 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002889 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002890 rc = lpfc_sli_issue_mbox_wait (phba,
2891 phba->sysfs_mbox.mbox,
James Smarta309a6b2006-08-01 07:33:43 -04002892 lpfc_mbox_tmo_val(phba,
2893 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05002894 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002895 }
2896
2897 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04002898 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04002899 phba->sysfs_mbox.mbox = NULL;
2900 }
dea31012005-04-17 16:05:31 -05002901 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002902 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04002903 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05002904 }
2905 phba->sysfs_mbox.state = SMBOX_READING;
2906 }
2907 else if (phba->sysfs_mbox.offset != off ||
2908 phba->sysfs_mbox.state != SMBOX_READING) {
2909 printk(KERN_WARNING "mbox_read: Bad State\n");
2910 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002911 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04002912 return -EAGAIN;
dea31012005-04-17 16:05:31 -05002913 }
2914
2915 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
2916
2917 phba->sysfs_mbox.offset = off + count;
2918
James Smart1dcb58e2007-04-25 09:51:30 -04002919 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05002920 sysfs_mbox_idle(phba);
2921
James Smart2e0fef82007-06-17 19:56:36 -05002922 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002923
2924 return count;
2925}
2926
2927static struct bin_attribute sysfs_mbox_attr = {
2928 .attr = {
2929 .name = "mbox",
2930 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05002931 },
James Smart1dcb58e2007-04-25 09:51:30 -04002932 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05002933 .read = sysfs_mbox_read,
2934 .write = sysfs_mbox_write,
2935};
2936
James Smarte59058c2008-08-24 21:49:00 -04002937/**
James Smart84774a42008-08-24 21:50:06 -04002938 * lpfc_alloc_sysfs_attr: Creates the ctlreg and mbox entries.
James Smarte59058c2008-08-24 21:49:00 -04002939 * @vport: address of lpfc vport structure.
2940 *
2941 * Return codes:
2942 * zero on success
2943 * error return code from sysfs_create_bin_file()
2944 **/
dea31012005-04-17 16:05:31 -05002945int
James Smart2e0fef82007-06-17 19:56:36 -05002946lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002947{
James Smart2e0fef82007-06-17 19:56:36 -05002948 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002949 int error;
2950
Tony Jonesee959b02008-02-22 00:13:36 +01002951 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05002952 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05002953 if (error)
2954 goto out;
2955
Tony Jonesee959b02008-02-22 00:13:36 +01002956 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05002957 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05002958 if (error)
2959 goto out_remove_ctlreg_attr;
2960
2961 return 0;
2962out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01002963 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05002964out:
2965 return error;
2966}
2967
James Smarte59058c2008-08-24 21:49:00 -04002968/**
James Smart84774a42008-08-24 21:50:06 -04002969 * lpfc_free_sysfs_attr: Removes the ctlreg and mbox entries.
James Smarte59058c2008-08-24 21:49:00 -04002970 * @vport: address of lpfc vport structure.
2971 **/
dea31012005-04-17 16:05:31 -05002972void
James Smart2e0fef82007-06-17 19:56:36 -05002973lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002974{
James Smart2e0fef82007-06-17 19:56:36 -05002975 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002976
Tony Jonesee959b02008-02-22 00:13:36 +01002977 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
2978 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05002979}
2980
2981
2982/*
2983 * Dynamic FC Host Attributes Support
2984 */
2985
James Smarte59058c2008-08-24 21:49:00 -04002986/**
2987 * lpfc_get_host_port_id: Copy the vport DID into the scsi host port id.
2988 * @shost: kernel scsi host pointer.
2989 **/
dea31012005-04-17 16:05:31 -05002990static void
2991lpfc_get_host_port_id(struct Scsi_Host *shost)
2992{
James Smart2e0fef82007-06-17 19:56:36 -05002993 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2994
dea31012005-04-17 16:05:31 -05002995 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05002996 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05002997}
2998
James Smarte59058c2008-08-24 21:49:00 -04002999/**
3000 * lpfc_get_host_port_type: Set the value of the scsi host port type.
3001 * @shost: kernel scsi host pointer.
3002 **/
dea31012005-04-17 16:05:31 -05003003static void
3004lpfc_get_host_port_type(struct Scsi_Host *shost)
3005{
James Smart2e0fef82007-06-17 19:56:36 -05003006 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3007 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003008
3009 spin_lock_irq(shost->host_lock);
3010
James Smart92d7f7b2007-06-17 19:56:38 -05003011 if (vport->port_type == LPFC_NPIV_PORT) {
3012 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3013 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003014 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05003015 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05003016 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3017 else
3018 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3019 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003020 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05003021 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3022 else
3023 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3024 }
3025 } else
3026 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3027
3028 spin_unlock_irq(shost->host_lock);
3029}
3030
James Smarte59058c2008-08-24 21:49:00 -04003031/**
3032 * lpfc_get_host_port_state: Set the value of the scsi host port state.
3033 * @shost: kernel scsi host pointer.
3034 **/
dea31012005-04-17 16:05:31 -05003035static void
3036lpfc_get_host_port_state(struct Scsi_Host *shost)
3037{
James Smart2e0fef82007-06-17 19:56:36 -05003038 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3039 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003040
3041 spin_lock_irq(shost->host_lock);
3042
James Smart2e0fef82007-06-17 19:56:36 -05003043 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05003044 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3045 else {
James Smart2e0fef82007-06-17 19:56:36 -05003046 switch (phba->link_state) {
3047 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05003048 case LPFC_LINK_DOWN:
3049 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3050 break;
3051 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05003052 case LPFC_CLEAR_LA:
3053 case LPFC_HBA_READY:
3054 /* Links up, beyond this port_type reports state */
3055 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3056 break;
3057 case LPFC_HBA_ERROR:
3058 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3059 break;
3060 default:
3061 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3062 break;
3063 }
3064 }
3065
3066 spin_unlock_irq(shost->host_lock);
3067}
3068
James Smarte59058c2008-08-24 21:49:00 -04003069/**
3070 * lpfc_get_host_speed: Set the value of the scsi host speed.
3071 * @shost: kernel scsi host pointer.
3072 **/
dea31012005-04-17 16:05:31 -05003073static void
3074lpfc_get_host_speed(struct Scsi_Host *shost)
3075{
James Smart2e0fef82007-06-17 19:56:36 -05003076 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3077 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003078
3079 spin_lock_irq(shost->host_lock);
3080
James Smart2e0fef82007-06-17 19:56:36 -05003081 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003082 switch(phba->fc_linkspeed) {
3083 case LA_1GHZ_LINK:
3084 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
3085 break;
3086 case LA_2GHZ_LINK:
3087 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
3088 break;
3089 case LA_4GHZ_LINK:
3090 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
3091 break;
James Smartb87eab32007-04-25 09:53:28 -04003092 case LA_8GHZ_LINK:
3093 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
3094 break;
dea31012005-04-17 16:05:31 -05003095 default:
3096 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3097 break;
3098 }
James Smart09372822008-01-11 01:52:54 -05003099 } else
3100 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05003101
3102 spin_unlock_irq(shost->host_lock);
3103}
3104
James Smarte59058c2008-08-24 21:49:00 -04003105/**
3106 * lpfc_get_host_fabric_name: Set the value of the scsi host fabric name.
3107 * @shost: kernel scsi host pointer.
3108 **/
dea31012005-04-17 16:05:31 -05003109static void
3110lpfc_get_host_fabric_name (struct Scsi_Host *shost)
3111{
James Smart2e0fef82007-06-17 19:56:36 -05003112 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3113 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003114 u64 node_name;
dea31012005-04-17 16:05:31 -05003115
3116 spin_lock_irq(shost->host_lock);
3117
James Smart2e0fef82007-06-17 19:56:36 -05003118 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05003119 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05003120 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07003121 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05003122 else
3123 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05003124 node_name = 0;
dea31012005-04-17 16:05:31 -05003125
3126 spin_unlock_irq(shost->host_lock);
3127
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003128 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05003129}
3130
James Smarte59058c2008-08-24 21:49:00 -04003131/**
3132 * lpfc_get_stats: Return statistical information about the adapter.
3133 * @shost: kernel scsi host pointer.
3134 *
3135 * Notes:
3136 * NULL on error for link down, no mbox pool, sli2 active,
3137 * management not allowed, memory allocation error, or mbox error.
3138 *
3139 * Returns:
3140 * NULL for error
3141 * address of the adapter host statistics
3142 **/
dea31012005-04-17 16:05:31 -05003143static struct fc_host_statistics *
3144lpfc_get_stats(struct Scsi_Host *shost)
3145{
James Smart2e0fef82007-06-17 19:56:36 -05003146 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3147 struct lpfc_hba *phba = vport->phba;
3148 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003149 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04003150 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05003151 LPFC_MBOXQ_t *pmboxq;
3152 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04003153 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003154 int rc = 0;
dea31012005-04-17 16:05:31 -05003155
James Smart92d7f7b2007-06-17 19:56:38 -05003156 /*
3157 * prevent udev from issuing mailbox commands until the port is
3158 * configured.
3159 */
James Smart2e0fef82007-06-17 19:56:36 -05003160 if (phba->link_state < LPFC_LINK_DOWN ||
3161 !phba->mbox_mem_pool ||
3162 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003163 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003164
3165 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04003166 return NULL;
3167
dea31012005-04-17 16:05:31 -05003168 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3169 if (!pmboxq)
3170 return NULL;
3171 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3172
3173 pmb = &pmboxq->mb;
3174 pmb->mbxCommand = MBX_READ_STATUS;
3175 pmb->mbxOwner = OWN_HOST;
3176 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003177 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05003178
James Smart2e0fef82007-06-17 19:56:36 -05003179 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003180 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05003181 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003182 else
dea31012005-04-17 16:05:31 -05003183 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3184
3185 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003186 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003187 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003188 return NULL;
3189 }
3190
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003191 memset(hs, 0, sizeof (struct fc_host_statistics));
3192
dea31012005-04-17 16:05:31 -05003193 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
3194 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
3195 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
3196 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
3197
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003198 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003199 pmb->mbxCommand = MBX_READ_LNK_STAT;
3200 pmb->mbxOwner = OWN_HOST;
3201 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003202 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05003203
James Smart2e0fef82007-06-17 19:56:36 -05003204 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003205 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05003206 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003207 else
dea31012005-04-17 16:05:31 -05003208 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3209
3210 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003211 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05003212 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003213 return NULL;
3214 }
3215
3216 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3217 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3218 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3219 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3220 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3221 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3222 hs->error_frames = pmb->un.varRdLnk.crcCnt;
3223
James Smart64ba8812006-08-02 15:24:34 -04003224 hs->link_failure_count -= lso->link_failure_count;
3225 hs->loss_of_sync_count -= lso->loss_of_sync_count;
3226 hs->loss_of_signal_count -= lso->loss_of_signal_count;
3227 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
3228 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
3229 hs->invalid_crc_count -= lso->invalid_crc_count;
3230 hs->error_frames -= lso->error_frames;
3231
dea31012005-04-17 16:05:31 -05003232 if (phba->fc_topology == TOPOLOGY_LOOP) {
3233 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04003234 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05003235 hs->nos_count = -1;
3236 } else {
3237 hs->lip_count = -1;
3238 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04003239 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05003240 }
3241
3242 hs->dumped_frames = -1;
3243
James Smart64ba8812006-08-02 15:24:34 -04003244 seconds = get_seconds();
3245 if (seconds < psli->stats_start)
3246 hs->seconds_since_last_reset = seconds +
3247 ((unsigned long)-1 - psli->stats_start);
3248 else
3249 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05003250
James Smart1dcb58e2007-04-25 09:51:30 -04003251 mempool_free(pmboxq, phba->mbox_mem_pool);
3252
dea31012005-04-17 16:05:31 -05003253 return hs;
3254}
3255
James Smarte59058c2008-08-24 21:49:00 -04003256/**
3257 * lpfc_reset_stats: Copy the adapter link stats information.
3258 * @shost: kernel scsi host pointer.
3259 **/
James Smart64ba8812006-08-02 15:24:34 -04003260static void
3261lpfc_reset_stats(struct Scsi_Host *shost)
3262{
James Smart2e0fef82007-06-17 19:56:36 -05003263 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3264 struct lpfc_hba *phba = vport->phba;
3265 struct lpfc_sli *psli = &phba->sli;
3266 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04003267 LPFC_MBOXQ_t *pmboxq;
3268 MAILBOX_t *pmb;
3269 int rc = 0;
3270
James Smart2e0fef82007-06-17 19:56:36 -05003271 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04003272 return;
3273
James Smart64ba8812006-08-02 15:24:34 -04003274 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3275 if (!pmboxq)
3276 return;
3277 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3278
3279 pmb = &pmboxq->mb;
3280 pmb->mbxCommand = MBX_READ_STATUS;
3281 pmb->mbxOwner = OWN_HOST;
3282 pmb->un.varWords[0] = 0x1; /* reset request */
3283 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003284 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04003285
James Smart2e0fef82007-06-17 19:56:36 -05003286 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04003287 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
3288 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3289 else
3290 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3291
3292 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003293 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04003294 mempool_free(pmboxq, phba->mbox_mem_pool);
3295 return;
3296 }
3297
3298 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3299 pmb->mbxCommand = MBX_READ_LNK_STAT;
3300 pmb->mbxOwner = OWN_HOST;
3301 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003302 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04003303
James Smart2e0fef82007-06-17 19:56:36 -05003304 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04003305 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
3306 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3307 else
3308 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3309
3310 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003311 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04003312 mempool_free( pmboxq, phba->mbox_mem_pool);
3313 return;
3314 }
3315
3316 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3317 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3318 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3319 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3320 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3321 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3322 lso->error_frames = pmb->un.varRdLnk.crcCnt;
3323 lso->link_events = (phba->fc_eventTag >> 1);
3324
3325 psli->stats_start = get_seconds();
3326
James Smart1dcb58e2007-04-25 09:51:30 -04003327 mempool_free(pmboxq, phba->mbox_mem_pool);
3328
James Smart64ba8812006-08-02 15:24:34 -04003329 return;
3330}
dea31012005-04-17 16:05:31 -05003331
3332/*
3333 * The LPFC driver treats linkdown handling as target loss events so there
3334 * are no sysfs handlers for link_down_tmo.
3335 */
James Smart685f0bf2007-04-25 09:53:08 -04003336
James Smarte59058c2008-08-24 21:49:00 -04003337/**
3338 * lpfc_get_node_by_target: Return the nodelist for a target.
3339 * @starget: kernel scsi target pointer.
3340 *
3341 * Returns:
3342 * address of the node list if found
3343 * NULL target not found
3344 **/
James Smart685f0bf2007-04-25 09:53:08 -04003345static struct lpfc_nodelist *
3346lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05003347{
James Smart2e0fef82007-06-17 19:56:36 -05003348 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3349 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04003350 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003351
3352 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003353 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05003354 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003355 if (NLP_CHK_NODE_ACT(ndlp) &&
3356 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04003357 starget->id == ndlp->nlp_sid) {
3358 spin_unlock_irq(shost->host_lock);
3359 return ndlp;
dea31012005-04-17 16:05:31 -05003360 }
3361 }
3362 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003363 return NULL;
3364}
dea31012005-04-17 16:05:31 -05003365
James Smarte59058c2008-08-24 21:49:00 -04003366/**
3367 * lpfc_get_starget_port_id: Set the target port id to the ndlp DID or -1.
3368 * @starget: kernel scsi target pointer.
3369 **/
James Smart685f0bf2007-04-25 09:53:08 -04003370static void
3371lpfc_get_starget_port_id(struct scsi_target *starget)
3372{
3373 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
3374
3375 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05003376}
3377
James Smarte59058c2008-08-24 21:49:00 -04003378/**
3379 * lpfc_get_starget_node_name: Set the target node name.
3380 * @starget: kernel scsi target pointer.
3381 *
3382 * Description: Set the target node name to the ndlp node name wwn or zero.
3383 **/
dea31012005-04-17 16:05:31 -05003384static void
3385lpfc_get_starget_node_name(struct scsi_target *starget)
3386{
James Smart685f0bf2007-04-25 09:53:08 -04003387 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05003388
James Smart685f0bf2007-04-25 09:53:08 -04003389 fc_starget_node_name(starget) =
3390 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05003391}
3392
James Smarte59058c2008-08-24 21:49:00 -04003393/**
3394 * lpfc_get_starget_port_name: Set the target port name.
3395 * @starget: kernel scsi target pointer.
3396 *
3397 * Description: set the target port name to the ndlp port name wwn or zero.
3398 **/
dea31012005-04-17 16:05:31 -05003399static void
3400lpfc_get_starget_port_name(struct scsi_target *starget)
3401{
James Smart685f0bf2007-04-25 09:53:08 -04003402 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05003403
James Smart685f0bf2007-04-25 09:53:08 -04003404 fc_starget_port_name(starget) =
3405 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05003406}
3407
James Smarte59058c2008-08-24 21:49:00 -04003408/**
3409 * lpfc_set_rport_loss_tmo: Set the rport dev loss tmo.
3410 * @rport: fc rport address.
3411 * @timeout: new value for dev loss tmo.
3412 *
3413 * Description:
3414 * If timeout is non zero set the dev_loss_tmo to timeout, else set
3415 * dev_loss_tmo to one.
3416 **/
dea31012005-04-17 16:05:31 -05003417static void
dea31012005-04-17 16:05:31 -05003418lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
3419{
dea31012005-04-17 16:05:31 -05003420 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04003421 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05003422 else
James Smartc01f3202006-08-18 17:47:08 -04003423 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05003424}
3425
James Smarte59058c2008-08-24 21:49:00 -04003426/**
3427 * lpfc_rport_show_function: Return rport target information.
3428 *
3429 * Description:
3430 * Macro that uses field to generate a function with the name lpfc_show_rport_
3431 *
3432 * lpfc_show_rport_##field: returns the bytes formatted in buf
3433 * @cdev: class converted to an fc_rport.
3434 * @buf: on return contains the target_field or zero.
3435 *
3436 * Returns: size of formatted string.
3437 **/
dea31012005-04-17 16:05:31 -05003438#define lpfc_rport_show_function(field, format_string, sz, cast) \
3439static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01003440lpfc_show_rport_##field (struct device *dev, \
3441 struct device_attribute *attr, \
3442 char *buf) \
dea31012005-04-17 16:05:31 -05003443{ \
Tony Jonesee959b02008-02-22 00:13:36 +01003444 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05003445 struct lpfc_rport_data *rdata = rport->hostdata; \
3446 return snprintf(buf, sz, format_string, \
3447 (rdata->target) ? cast rdata->target->field : 0); \
3448}
3449
3450#define lpfc_rport_rd_attr(field, format_string, sz) \
3451 lpfc_rport_show_function(field, format_string, sz, ) \
3452static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
3453
3454
3455struct fc_function_template lpfc_transport_functions = {
3456 /* fixed attributes the driver supports */
3457 .show_host_node_name = 1,
3458 .show_host_port_name = 1,
3459 .show_host_supported_classes = 1,
3460 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05003461 .show_host_supported_speeds = 1,
3462 .show_host_maxframe_size = 1,
3463
3464 /* dynamic attributes the driver supports */
3465 .get_host_port_id = lpfc_get_host_port_id,
3466 .show_host_port_id = 1,
3467
3468 .get_host_port_type = lpfc_get_host_port_type,
3469 .show_host_port_type = 1,
3470
3471 .get_host_port_state = lpfc_get_host_port_state,
3472 .show_host_port_state = 1,
3473
3474 /* active_fc4s is shown but doesn't change (thus no get function) */
3475 .show_host_active_fc4s = 1,
3476
3477 .get_host_speed = lpfc_get_host_speed,
3478 .show_host_speed = 1,
3479
3480 .get_host_fabric_name = lpfc_get_host_fabric_name,
3481 .show_host_fabric_name = 1,
3482
3483 /*
3484 * The LPFC driver treats linkdown handling as target loss events
3485 * so there are no sysfs handlers for link_down_tmo.
3486 */
3487
3488 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04003489 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05003490
3491 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
3492 .show_rport_maxframe_size = 1,
3493 .show_rport_supported_classes = 1,
3494
dea31012005-04-17 16:05:31 -05003495 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
3496 .show_rport_dev_loss_tmo = 1,
3497
3498 .get_starget_port_id = lpfc_get_starget_port_id,
3499 .show_starget_port_id = 1,
3500
3501 .get_starget_node_name = lpfc_get_starget_node_name,
3502 .show_starget_node_name = 1,
3503
3504 .get_starget_port_name = lpfc_get_starget_port_name,
3505 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07003506
3507 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04003508 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
3509 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05003510
James Smart92d7f7b2007-06-17 19:56:38 -05003511 .dd_fcvport_size = sizeof(struct lpfc_vport *),
3512};
3513
James Smart98c9ea52007-10-27 13:37:33 -04003514struct fc_function_template lpfc_vport_transport_functions = {
3515 /* fixed attributes the driver supports */
3516 .show_host_node_name = 1,
3517 .show_host_port_name = 1,
3518 .show_host_supported_classes = 1,
3519 .show_host_supported_fc4s = 1,
3520 .show_host_supported_speeds = 1,
3521 .show_host_maxframe_size = 1,
3522
3523 /* dynamic attributes the driver supports */
3524 .get_host_port_id = lpfc_get_host_port_id,
3525 .show_host_port_id = 1,
3526
3527 .get_host_port_type = lpfc_get_host_port_type,
3528 .show_host_port_type = 1,
3529
3530 .get_host_port_state = lpfc_get_host_port_state,
3531 .show_host_port_state = 1,
3532
3533 /* active_fc4s is shown but doesn't change (thus no get function) */
3534 .show_host_active_fc4s = 1,
3535
3536 .get_host_speed = lpfc_get_host_speed,
3537 .show_host_speed = 1,
3538
3539 .get_host_fabric_name = lpfc_get_host_fabric_name,
3540 .show_host_fabric_name = 1,
3541
3542 /*
3543 * The LPFC driver treats linkdown handling as target loss events
3544 * so there are no sysfs handlers for link_down_tmo.
3545 */
3546
3547 .get_fc_host_stats = lpfc_get_stats,
3548 .reset_fc_host_stats = lpfc_reset_stats,
3549
3550 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
3551 .show_rport_maxframe_size = 1,
3552 .show_rport_supported_classes = 1,
3553
3554 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
3555 .show_rport_dev_loss_tmo = 1,
3556
3557 .get_starget_port_id = lpfc_get_starget_port_id,
3558 .show_starget_port_id = 1,
3559
3560 .get_starget_node_name = lpfc_get_starget_node_name,
3561 .show_starget_node_name = 1,
3562
3563 .get_starget_port_name = lpfc_get_starget_port_name,
3564 .show_starget_port_name = 1,
3565
3566 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
3567 .terminate_rport_io = lpfc_terminate_rport_io,
3568
3569 .vport_disable = lpfc_vport_disable,
3570};
3571
James Smarte59058c2008-08-24 21:49:00 -04003572/**
3573 * lpfc_get_cfgparam: Used during probe_one to init the adapter structure.
3574 * @phba: lpfc_hba pointer.
3575 **/
dea31012005-04-17 16:05:31 -05003576void
3577lpfc_get_cfgparam(struct lpfc_hba *phba)
3578{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04003579 lpfc_cr_delay_init(phba, lpfc_cr_delay);
3580 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003581 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05003582 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
3583 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04003584 lpfc_ack0_init(phba, lpfc_ack0);
3585 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04003586 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003587 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04003588 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05003589 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart13815c82008-01-11 01:52:48 -05003590 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
3591 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003592 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05003593 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04003594 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05003595 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
3596 /* Also reinitialize the host templates with new values. */
3597 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
3598 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
dea31012005-04-17 16:05:31 -05003599 /*
3600 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
James Smart83108bd2008-01-11 01:53:09 -05003601 * used to create the sg_dma_buf_pool must be dynamically calculated.
3602 * 2 segments are added since the IOCB needs a command and response bde.
dea31012005-04-17 16:05:31 -05003603 */
3604 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
3605 sizeof(struct fcp_rsp) +
James Smart83108bd2008-01-11 01:53:09 -05003606 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
James Smart7054a602007-04-25 09:52:34 -04003607 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04003608 return;
3609}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003610
James Smarte59058c2008-08-24 21:49:00 -04003611/**
3612 * lpfc_get_vport_cfgparam: Used during port create, init the vport structure.
3613 * @vport: lpfc_vport pointer.
3614 **/
James Smart3de2a652007-08-02 11:09:59 -04003615void
3616lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
3617{
James Smarte8b62012007-08-02 11:10:09 -04003618 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04003619 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
3620 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
3621 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
3622 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
3623 lpfc_restrict_login_init(vport, lpfc_restrict_login);
3624 lpfc_fcp_class_init(vport, lpfc_fcp_class);
3625 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart977b5a02008-09-07 11:52:04 -04003626 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04003627 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
3628 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
3629 lpfc_max_luns_init(vport, lpfc_max_luns);
3630 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04003631 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05003632 return;
3633}