blob: 2926a2a7ee70c8a565e8980347679e745eb68805 [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/**
214 * lpfc_vportnum_show: Return the port number in ascii of the hba.
215 * @dev: class converted to a Scsi_host structure.
216 * @attr: device attribute, not used.
217 * @buf: on return contains scsi vpd program type.
218 *
219 * Returns: size of formatted string.
220 **/
dea31012005-04-17 16:05:31 -0500221static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100222lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
223 char *buf)
dea31012005-04-17 16:05:31 -0500224{
Tony Jonesee959b02008-02-22 00:13:36 +0100225 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500226 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
227 struct lpfc_hba *phba = vport->phba;
228
dea31012005-04-17 16:05:31 -0500229 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
230}
231
James Smarte59058c2008-08-24 21:49:00 -0400232/**
233 * lpfc_fwrev_show: Return the firmware rev running in the hba.
234 * @dev: class converted to a Scsi_host structure.
235 * @attr: device attribute, not used.
236 * @buf: on return contains the 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_fwrev_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;
dea31012005-04-17 16:05:31 -0500247 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500248
dea31012005-04-17 16:05:31 -0500249 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500250 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500251}
252
James Smarte59058c2008-08-24 21:49:00 -0400253/**
254 * lpfc_hdw_show: Return the jedec information about the hba.
255 * @dev: class converted to a Scsi_host structure.
256 * @attr: device attribute, not used.
257 * @buf: on return contains the scsi vpd program type.
258 *
259 * Returns: size of formatted string.
260 **/
dea31012005-04-17 16:05:31 -0500261static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100262lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500263{
264 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100265 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500266 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
267 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500268 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500269
dea31012005-04-17 16:05:31 -0500270 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
271 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
272}
James Smarte59058c2008-08-24 21:49:00 -0400273
274/**
275 * lpfc_option_rom_version_show: Return the adapter ROM FCode version.
276 * @dev: class converted to a Scsi_host structure.
277 * @attr: device attribute, not used.
278 * @buf: on return contains the ROM and FCode ascii strings.
279 *
280 * Returns: size of formatted string.
281 **/
dea31012005-04-17 16:05:31 -0500282static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100283lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
284 char *buf)
dea31012005-04-17 16:05:31 -0500285{
Tony Jonesee959b02008-02-22 00:13:36 +0100286 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500287 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
288 struct lpfc_hba *phba = vport->phba;
289
dea31012005-04-17 16:05:31 -0500290 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
291}
James Smarte59058c2008-08-24 21:49:00 -0400292
293/**
294 * lpfc_state_show: Return the link state of the port.
295 * @dev: class converted to a Scsi_host structure.
296 * @attr: device attribute, not used.
297 * @buf: on return contains text describing the state of the link.
298 *
299 * Notes:
300 * The switch statement has no default so zero will be returned.
301 *
302 * Returns: size of formatted string.
303 **/
dea31012005-04-17 16:05:31 -0500304static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100305lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
306 char *buf)
dea31012005-04-17 16:05:31 -0500307{
Tony Jonesee959b02008-02-22 00:13:36 +0100308 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500309 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
310 struct lpfc_hba *phba = vport->phba;
311 int len = 0;
312
313 switch (phba->link_state) {
314 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500315 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500316 case LPFC_INIT_START:
317 case LPFC_INIT_MBX_CMDS:
318 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500319 case LPFC_HBA_ERROR:
dea31012005-04-17 16:05:31 -0500320 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
321 break;
322 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500323 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500324 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400325 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500326
327 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500328 case LPFC_LOCAL_CFG_LINK:
329 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500330 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500331 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500332 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500333 case LPFC_FLOGI:
334 case LPFC_FABRIC_CFG_LINK:
335 case LPFC_NS_REG:
336 case LPFC_NS_QRY:
337 case LPFC_BUILD_DISC_LIST:
338 case LPFC_DISC_AUTH:
339 len += snprintf(buf + len, PAGE_SIZE - len,
340 "Discovery\n");
341 break;
342 case LPFC_VPORT_READY:
343 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
344 break;
345
James Smart92d7f7b2007-06-17 19:56:38 -0500346 case LPFC_VPORT_FAILED:
347 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
348 break;
349
350 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500351 len += snprintf(buf + len, PAGE_SIZE - len,
352 "Unknown\n");
353 break;
354 }
355
dea31012005-04-17 16:05:31 -0500356 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500357 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500358 len += snprintf(buf + len, PAGE_SIZE-len,
359 " Public Loop\n");
360 else
361 len += snprintf(buf + len, PAGE_SIZE-len,
362 " Private Loop\n");
363 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500364 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500365 len += snprintf(buf + len, PAGE_SIZE-len,
366 " Fabric\n");
367 else
368 len += snprintf(buf + len, PAGE_SIZE-len,
369 " Point-2-Point\n");
370 }
371 }
James Smart2e0fef82007-06-17 19:56:36 -0500372
dea31012005-04-17 16:05:31 -0500373 return len;
374}
375
James Smarte59058c2008-08-24 21:49:00 -0400376/**
377 * lpfc_num_discovered_ports_show: Return sum of mapped and unmapped vports.
378 * @dev: class device that is converted into a Scsi_host.
379 * @attr: device attribute, not used.
380 * @buf: on return contains the sum of fc mapped and unmapped.
381 *
382 * Description:
383 * Returns the ascii text number of the sum of the fc mapped and unmapped
384 * vport counts.
385 *
386 * Returns: size of formatted string.
387 **/
dea31012005-04-17 16:05:31 -0500388static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100389lpfc_num_discovered_ports_show(struct device *dev,
390 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500391{
Tony Jonesee959b02008-02-22 00:13:36 +0100392 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500393 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
394
395 return snprintf(buf, PAGE_SIZE, "%d\n",
396 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500397}
398
James Smarte59058c2008-08-24 21:49:00 -0400399/**
400 * lpfc_issue_lip: Misnomer, name carried over from long ago.
401 * @shost: Scsi_Host pointer.
402 *
403 * Description:
404 * Bring the link down gracefully then re-init the link. The firmware will
405 * re-init the fiber channel interface as required. Does not issue a LIP.
406 *
407 * Returns:
408 * -EPERM port offline or management commands are being blocked
409 * -ENOMEM cannot allocate memory for the mailbox command
410 * -EIO error sending the mailbox command
411 * zero for success
412 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700413static int
James Smart2e0fef82007-06-17 19:56:36 -0500414lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500415{
James Smart2e0fef82007-06-17 19:56:36 -0500416 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
417 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500418 LPFC_MBOXQ_t *pmboxq;
419 int mbxstatus = MBXERR_ERROR;
420
James Smart2e0fef82007-06-17 19:56:36 -0500421 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500422 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500423 return -EPERM;
424
425 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
426
427 if (!pmboxq)
428 return -ENOMEM;
429
430 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart4db621e2006-07-06 15:49:49 -0400431 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
432 pmboxq->mb.mbxOwner = OWN_HOST;
433
James Smart33ccf8d2006-08-17 11:57:58 -0400434 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500435
James Smart4db621e2006-07-06 15:49:49 -0400436 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
437 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
438 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
439 phba->cfg_link_speed);
440 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
441 phba->fc_ratov * 2);
442 }
443
James Smart5b8bd0c2007-04-25 09:52:49 -0400444 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500445 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400446 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500447
448 if (mbxstatus == MBXERR_ERROR)
449 return -EIO;
450
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700451 return 0;
dea31012005-04-17 16:05:31 -0500452}
453
James Smarte59058c2008-08-24 21:49:00 -0400454/**
455 * lpfc_do_offline: Issues a mailbox command to bring the link down.
456 * @phba: lpfc_hba pointer.
457 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
458 *
459 * Notes:
460 * Assumes any error from lpfc_do_offline() will be negative.
461 * Can wait up to 5 seconds for the port ring buffers count
462 * to reach zero, prints a warning if it is not zero and continues.
463 * lpfc_workq_post_event() returns a non-zero return coce if call fails.
464 *
465 * Returns:
466 * -EIO error posting the event
467 * zero for success
468 **/
James Smart40496f02006-07-06 15:50:22 -0400469static int
James Smart46fa3112007-04-25 09:51:45 -0400470lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
471{
472 struct completion online_compl;
473 struct lpfc_sli_ring *pring;
474 struct lpfc_sli *psli;
475 int status = 0;
476 int cnt = 0;
477 int i;
478
479 init_completion(&online_compl);
480 lpfc_workq_post_event(phba, &status, &online_compl,
481 LPFC_EVT_OFFLINE_PREP);
482 wait_for_completion(&online_compl);
483
484 if (status != 0)
485 return -EIO;
486
487 psli = &phba->sli;
488
James Smart09372822008-01-11 01:52:54 -0500489 /* Wait a little for things to settle down, but not
490 * long enough for dev loss timeout to expire.
491 */
James Smart46fa3112007-04-25 09:51:45 -0400492 for (i = 0; i < psli->num_rings; i++) {
493 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400494 while (pring->txcmplq_cnt) {
495 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500496 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400497 lpfc_printf_log(phba,
498 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400499 "0466 Outstanding IO when "
500 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400501 break;
502 }
503 }
504 }
505
506 init_completion(&online_compl);
507 lpfc_workq_post_event(phba, &status, &online_compl, type);
508 wait_for_completion(&online_compl);
509
510 if (status != 0)
511 return -EIO;
512
513 return 0;
514}
515
James Smarte59058c2008-08-24 21:49:00 -0400516/**
517 * lpfc_selective_reset: Offline then onlines the port.
518 * @phba: lpfc_hba pointer.
519 *
520 * Description:
521 * If the port is configured to allow a reset then the hba is brought
522 * offline then online.
523 *
524 * Notes:
525 * Assumes any error from lpfc_do_offline() will be negative.
526 *
527 * Returns:
528 * lpfc_do_offline() return code if not zero
529 * -EIO reset not configured or error posting the event
530 * zero for success
531 **/
James Smart46fa3112007-04-25 09:51:45 -0400532static int
James Smart40496f02006-07-06 15:50:22 -0400533lpfc_selective_reset(struct lpfc_hba *phba)
534{
535 struct completion online_compl;
536 int status = 0;
537
James Smart13815c82008-01-11 01:52:48 -0500538 if (!phba->cfg_enable_hba_reset)
539 return -EIO;
540
James Smart46fa3112007-04-25 09:51:45 -0400541 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400542
543 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400544 return status;
James Smart40496f02006-07-06 15:50:22 -0400545
546 init_completion(&online_compl);
547 lpfc_workq_post_event(phba, &status, &online_compl,
548 LPFC_EVT_ONLINE);
549 wait_for_completion(&online_compl);
550
551 if (status != 0)
552 return -EIO;
553
554 return 0;
555}
556
James Smarte59058c2008-08-24 21:49:00 -0400557/**
558 * lpfc_issue_reset: Selectively resets an adapter.
559 * @dev: class device that is converted into a Scsi_host.
560 * @attr: device attribute, not used.
561 * @buf: containing the string "selective".
562 * @count: unused variable.
563 *
564 * Description:
565 * If the buf contains the string "selective" then lpfc_selective_reset()
566 * is called to perform the reset.
567 *
568 * Notes:
569 * Assumes any error from lpfc_selective_reset() will be negative.
570 * If lpfc_selective_reset() returns zero then the length of the buffer
571 * is returned which indicates succcess
572 *
573 * Returns:
574 * -EINVAL if the buffer does not contain the string "selective"
575 * length of buf if lpfc-selective_reset() if the call succeeds
576 * return value of lpfc_selective_reset() if the call fails
577**/
James Smart40496f02006-07-06 15:50:22 -0400578static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100579lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
580 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400581{
Tony Jonesee959b02008-02-22 00:13:36 +0100582 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
584 struct lpfc_hba *phba = vport->phba;
585
James Smart40496f02006-07-06 15:50:22 -0400586 int status = -EINVAL;
587
588 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
589 status = lpfc_selective_reset(phba);
590
591 if (status == 0)
592 return strlen(buf);
593 else
594 return status;
595}
596
James Smarte59058c2008-08-24 21:49:00 -0400597/**
598 * lpfc_nport_evt_cnt_show: Return the number of nport events.
599 * @dev: class device that is converted into a Scsi_host.
600 * @attr: device attribute, not used.
601 * @buf: on return contains the ascii number of nport events.
602 *
603 * Returns: size of formatted string.
604 **/
dea31012005-04-17 16:05:31 -0500605static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100606lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
607 char *buf)
dea31012005-04-17 16:05:31 -0500608{
Tony Jonesee959b02008-02-22 00:13:36 +0100609 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500610 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
611 struct lpfc_hba *phba = vport->phba;
612
dea31012005-04-17 16:05:31 -0500613 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
614}
615
James Smarte59058c2008-08-24 21:49:00 -0400616/**
617 * lpfc_board_mode_show: Return the state of the board.
618 * @dev: class device that is converted into a Scsi_host.
619 * @attr: device attribute, not used.
620 * @buf: on return contains the state of the adapter.
621 *
622 * Returns: size of formatted string.
623 **/
dea31012005-04-17 16:05:31 -0500624static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100625lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
626 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500627{
Tony Jonesee959b02008-02-22 00:13:36 +0100628 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500629 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
630 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500631 char * state;
632
James Smart2e0fef82007-06-17 19:56:36 -0500633 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500634 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500635 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500636 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500637 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500638 state = "offline";
639 else
640 state = "online";
641
642 return snprintf(buf, PAGE_SIZE, "%s\n", state);
643}
644
James Smarte59058c2008-08-24 21:49:00 -0400645/**
646 * lpfc_board_mode_store: Puts the hba in online, offline, warm or error state.
647 * @dev: class device that is converted into a Scsi_host.
648 * @attr: device attribute, not used.
649 * @buf: containing one of the strings "online", "offline", "warm" or "error".
650 * @count: unused variable.
651 *
652 * Returns:
653 * -EACCES if enable hba reset not enabled
654 * -EINVAL if the buffer does not contain a valid string (see above)
655 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
656 * buf length greater than zero indicates success
657 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500658static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100659lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
660 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500661{
Tony Jonesee959b02008-02-22 00:13:36 +0100662 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500663 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
664 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500665 struct completion online_compl;
666 int status=0;
667
James Smart13815c82008-01-11 01:52:48 -0500668 if (!phba->cfg_enable_hba_reset)
669 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500670 init_completion(&online_compl);
671
James Smart46fa3112007-04-25 09:51:45 -0400672 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500673 lpfc_workq_post_event(phba, &status, &online_compl,
674 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400675 wait_for_completion(&online_compl);
676 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
677 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500678 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart46fa3112007-04-25 09:51:45 -0400679 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
680 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
681 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500682 else
683 return -EINVAL;
684
Jamie Wellnitz41415862006-02-28 19:25:27 -0500685 if (!status)
686 return strlen(buf);
687 else
688 return -EIO;
689}
690
James Smarte59058c2008-08-24 21:49:00 -0400691/**
692 * lpfc_get_hba_info: Return various bits of informaton about the adapter.
693 * @phba: pointer to the adapter structure.
694 * @mxri max xri count.
695 * @axri available xri count.
696 * @mrpi max rpi count.
697 * @arpi available rpi count.
698 * @mvpi max vpi count.
699 * @avpi available vpi count.
700 *
701 * Description:
702 * If an integer pointer for an count is not null then the value for the
703 * count is returned.
704 *
705 * Returns:
706 * zero on error
707 * one for success
708 **/
James Smart311464e2007-08-02 11:10:37 -0400709static int
James Smart858c9f62007-06-17 19:56:39 -0500710lpfc_get_hba_info(struct lpfc_hba *phba,
711 uint32_t *mxri, uint32_t *axri,
712 uint32_t *mrpi, uint32_t *arpi,
713 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500714{
715 struct lpfc_sli *psli = &phba->sli;
716 LPFC_MBOXQ_t *pmboxq;
717 MAILBOX_t *pmb;
718 int rc = 0;
719
720 /*
721 * prevent udev from issuing mailbox commands until the port is
722 * configured.
723 */
724 if (phba->link_state < LPFC_LINK_DOWN ||
725 !phba->mbox_mem_pool ||
726 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
727 return 0;
728
729 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
730 return 0;
731
732 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
733 if (!pmboxq)
734 return 0;
735 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
736
737 pmb = &pmboxq->mb;
738 pmb->mbxCommand = MBX_READ_CONFIG;
739 pmb->mbxOwner = OWN_HOST;
740 pmboxq->context1 = NULL;
741
742 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
743 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
744 rc = MBX_NOT_FINISHED;
745 else
746 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
747
748 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500749 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500750 mempool_free(pmboxq, phba->mbox_mem_pool);
751 return 0;
752 }
753
754 if (mrpi)
755 *mrpi = pmb->un.varRdConfig.max_rpi;
756 if (arpi)
757 *arpi = pmb->un.varRdConfig.avail_rpi;
758 if (mxri)
759 *mxri = pmb->un.varRdConfig.max_xri;
760 if (axri)
761 *axri = pmb->un.varRdConfig.avail_xri;
James Smart858c9f62007-06-17 19:56:39 -0500762 if (mvpi)
763 *mvpi = pmb->un.varRdConfig.max_vpi;
764 if (avpi)
765 *avpi = pmb->un.varRdConfig.avail_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500766
767 mempool_free(pmboxq, phba->mbox_mem_pool);
768 return 1;
769}
770
James Smarte59058c2008-08-24 21:49:00 -0400771/**
772 * lpfc_max_rpi_show: Return maximum rpi.
773 * @dev: class device that is converted into a Scsi_host.
774 * @attr: device attribute, not used.
775 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
776 *
777 * Description:
778 * Calls lpfc_get_hba_info() asking for just the mrpi count.
779 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
780 * to "Unknown" and the buffer length is returned, therefore the caller
781 * must check for "Unknown" in the buffer to detect a failure.
782 *
783 * Returns: size of formatted string.
784 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500785static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100786lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
787 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500788{
Tony Jonesee959b02008-02-22 00:13:36 +0100789 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500790 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
791 struct lpfc_hba *phba = vport->phba;
792 uint32_t cnt;
793
James Smart858c9f62007-06-17 19:56:39 -0500794 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500795 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
796 return snprintf(buf, PAGE_SIZE, "Unknown\n");
797}
798
James Smarte59058c2008-08-24 21:49:00 -0400799/**
800 * lpfc_used_rpi_show: Return maximum rpi minus available rpi.
801 * @dev: class device that is converted into a Scsi_host.
802 * @attr: device attribute, not used.
803 * @buf: containing the used rpi count in decimal or "Unknown".
804 *
805 * Description:
806 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
807 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
808 * to "Unknown" and the buffer length is returned, therefore the caller
809 * must check for "Unknown" in the buffer to detect a failure.
810 *
811 * Returns: size of formatted string.
812 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500813static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100814lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
815 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500816{
Tony Jonesee959b02008-02-22 00:13:36 +0100817 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500818 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
819 struct lpfc_hba *phba = vport->phba;
820 uint32_t cnt, acnt;
821
James Smart858c9f62007-06-17 19:56:39 -0500822 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500823 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
824 return snprintf(buf, PAGE_SIZE, "Unknown\n");
825}
826
James Smarte59058c2008-08-24 21:49:00 -0400827/**
828 * lpfc_max_xri_show: Return maximum xri.
829 * @dev: class device that is converted into a Scsi_host.
830 * @attr: device attribute, not used.
831 * @buf: on return contains the maximum xri count in decimal or "Unknown".
832 *
833 * Description:
834 * Calls lpfc_get_hba_info() asking for just the mrpi count.
835 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
836 * to "Unknown" and the buffer length is returned, therefore the caller
837 * must check for "Unknown" in the buffer to detect a failure.
838 *
839 * Returns: size of formatted string.
840 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500841static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100842lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
843 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500844{
Tony Jonesee959b02008-02-22 00:13:36 +0100845 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500846 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
847 struct lpfc_hba *phba = vport->phba;
848 uint32_t cnt;
849
James Smart858c9f62007-06-17 19:56:39 -0500850 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500851 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
852 return snprintf(buf, PAGE_SIZE, "Unknown\n");
853}
854
James Smarte59058c2008-08-24 21:49:00 -0400855/**
856 * lpfc_used_xri_show: Return maximum xpi minus the available xpi.
857 * @dev: class device that is converted into a Scsi_host.
858 * @attr: device attribute, not used.
859 * @buf: on return contains the used xri count in decimal or "Unknown".
860 *
861 * Description:
862 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
863 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
864 * to "Unknown" and the buffer length is returned, therefore the caller
865 * must check for "Unknown" in the buffer to detect a failure.
866 *
867 * Returns: size of formatted string.
868 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500869static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100870lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
871 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500872{
Tony Jonesee959b02008-02-22 00:13:36 +0100873 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500874 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
875 struct lpfc_hba *phba = vport->phba;
876 uint32_t cnt, acnt;
877
James Smart858c9f62007-06-17 19:56:39 -0500878 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
879 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
880 return snprintf(buf, PAGE_SIZE, "Unknown\n");
881}
882
James Smarte59058c2008-08-24 21:49:00 -0400883/**
884 * lpfc_max_vpi_show: Return maximum vpi.
885 * @dev: class device that is converted into a Scsi_host.
886 * @attr: device attribute, not used.
887 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
888 *
889 * Description:
890 * Calls lpfc_get_hba_info() asking for just the mvpi count.
891 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
892 * to "Unknown" and the buffer length is returned, therefore the caller
893 * must check for "Unknown" in the buffer to detect a failure.
894 *
895 * Returns: size of formatted string.
896 **/
James Smart858c9f62007-06-17 19:56:39 -0500897static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100898lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
899 char *buf)
James Smart858c9f62007-06-17 19:56:39 -0500900{
Tony Jonesee959b02008-02-22 00:13:36 +0100901 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -0500902 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
903 struct lpfc_hba *phba = vport->phba;
904 uint32_t cnt;
905
906 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
907 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
908 return snprintf(buf, PAGE_SIZE, "Unknown\n");
909}
910
James Smarte59058c2008-08-24 21:49:00 -0400911/**
912 * lpfc_used_vpi_show: Return maximum vpi minus the available vpi.
913 * @dev: class device that is converted into a Scsi_host.
914 * @attr: device attribute, not used.
915 * @buf: on return contains the used vpi count in decimal or "Unknown".
916 *
917 * Description:
918 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
919 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
920 * to "Unknown" and the buffer length is returned, therefore the caller
921 * must check for "Unknown" in the buffer to detect a failure.
922 *
923 * Returns: size of formatted string.
924 **/
James Smart858c9f62007-06-17 19:56:39 -0500925static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100926lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
927 char *buf)
James Smart858c9f62007-06-17 19:56:39 -0500928{
Tony Jonesee959b02008-02-22 00:13:36 +0100929 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -0500930 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
931 struct lpfc_hba *phba = vport->phba;
932 uint32_t cnt, acnt;
933
934 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -0500935 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
936 return snprintf(buf, PAGE_SIZE, "Unknown\n");
937}
938
James Smarte59058c2008-08-24 21:49:00 -0400939/**
940 * lpfc_npiv_info_show: Return text about NPIV support for the adapter.
941 * @dev: class device that is converted into a Scsi_host.
942 * @attr: device attribute, not used.
943 * @buf: text that must be interpreted to determine if npiv is supported.
944 *
945 * Description:
946 * Buffer will contain text indicating npiv is not suppoerted on the port,
947 * the port is an NPIV physical port, or it is an npiv virtual port with
948 * the id of the vport.
949 *
950 * Returns: size of formatted string.
951 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500952static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100953lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
954 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500955{
Tony Jonesee959b02008-02-22 00:13:36 +0100956 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500957 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
958 struct lpfc_hba *phba = vport->phba;
959
960 if (!(phba->max_vpi))
961 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
962 if (vport->port_type == LPFC_PHYSICAL_PORT)
963 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
964 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
965}
966
James Smarte59058c2008-08-24 21:49:00 -0400967/**
968 * lpfc_poll_show: Return text about poll support for the adapter.
969 * @dev: class device that is converted into a Scsi_host.
970 * @attr: device attribute, not used.
971 * @buf: on return contains the cfg_poll in hex.
972 *
973 * Notes:
974 * cfg_poll should be a lpfc_polling_flags type.
975 *
976 * Returns: size of formatted string.
977 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500978static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100979lpfc_poll_show(struct device *dev, struct device_attribute *attr,
980 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500981{
Tony Jonesee959b02008-02-22 00:13:36 +0100982 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500983 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
984 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500985
986 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
987}
988
James Smarte59058c2008-08-24 21:49:00 -0400989/**
990 * lpfc_poll_store: Set the value of cfg_poll for the adapter.
991 * @dev: class device that is converted into a Scsi_host.
992 * @attr: device attribute, not used.
993 * @buf: one or more lpfc_polling_flags values.
994 * @count: not used.
995 *
996 * Notes:
997 * buf contents converted to integer and checked for a valid value.
998 *
999 * Returns:
1000 * -EINVAL if the buffer connot be converted or is out of range
1001 * length of the buf on success
1002 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001003static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001004lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1005 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001006{
Tony Jonesee959b02008-02-22 00:13:36 +01001007 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001008 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1009 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001010 uint32_t creg_val;
1011 uint32_t old_val;
1012 int val=0;
1013
1014 if (!isdigit(buf[0]))
1015 return -EINVAL;
1016
1017 if (sscanf(buf, "%i", &val) != 1)
1018 return -EINVAL;
1019
1020 if ((val & 0x3) != val)
1021 return -EINVAL;
1022
James Smart2e0fef82007-06-17 19:56:36 -05001023 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001024
1025 old_val = phba->cfg_poll;
1026
1027 if (val & ENABLE_FCP_RING_POLLING) {
1028 if ((val & DISABLE_FCP_RING_INT) &&
1029 !(old_val & DISABLE_FCP_RING_INT)) {
1030 creg_val = readl(phba->HCregaddr);
1031 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1032 writel(creg_val, phba->HCregaddr);
1033 readl(phba->HCregaddr); /* flush */
1034
1035 lpfc_poll_start_timer(phba);
1036 }
1037 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001038 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001039 return -EINVAL;
1040 }
1041
1042 if (!(val & DISABLE_FCP_RING_INT) &&
1043 (old_val & DISABLE_FCP_RING_INT))
1044 {
James Smart2e0fef82007-06-17 19:56:36 -05001045 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001046 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001047 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001048 creg_val = readl(phba->HCregaddr);
1049 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1050 writel(creg_val, phba->HCregaddr);
1051 readl(phba->HCregaddr); /* flush */
1052 }
1053
1054 phba->cfg_poll = val;
1055
James Smart2e0fef82007-06-17 19:56:36 -05001056 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001057
1058 return strlen(buf);
1059}
dea31012005-04-17 16:05:31 -05001060
James Smarte59058c2008-08-24 21:49:00 -04001061/**
1062 * lpfc_param_show: Return a cfg attribute value in decimal.
1063 *
1064 * Description:
1065 * Macro that given an attr e.g. hba_queue_depth expands
1066 * into a function with the name lpfc_hba_queue_depth_show.
1067 *
1068 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1069 * @dev: class device that is converted into a Scsi_host.
1070 * @attr: device attribute, not used.
1071 * @buf: on return contains the attribute value in decimal.
1072 *
1073 * Returns: size of formatted string.
1074 **/
dea31012005-04-17 16:05:31 -05001075#define lpfc_param_show(attr) \
1076static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001077lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1078 char *buf) \
dea31012005-04-17 16:05:31 -05001079{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001080 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001081 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1082 struct lpfc_hba *phba = vport->phba;\
dea31012005-04-17 16:05:31 -05001083 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001084 val = phba->cfg_##attr;\
1085 return snprintf(buf, PAGE_SIZE, "%d\n",\
1086 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001087}
1088
James Smarte59058c2008-08-24 21:49:00 -04001089/**
1090 * lpfc_param_hex_show: Return a cfg attribute value in hex.
1091 *
1092 * Description:
1093 * Macro that given an attr e.g. hba_queue_depth expands
1094 * into a function with the name lpfc_hba_queue_depth_show
1095 *
1096 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1097 * @dev: class device that is converted into a Scsi_host.
1098 * @attr: device attribute, not used.
1099 * @buf: on return contains the attribute value in hexidecimal.
1100 *
1101 * Returns: size of formatted string.
1102 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001103#define lpfc_param_hex_show(attr) \
1104static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001105lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1106 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001107{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001108 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001109 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1110 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001111 int val = 0;\
1112 val = phba->cfg_##attr;\
1113 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1114 phba->cfg_##attr);\
1115}
1116
James Smarte59058c2008-08-24 21:49:00 -04001117/**
1118 * lpfc_param_init: Intializes a cfg attribute.
1119 *
1120 * Description:
1121 * Macro that given an attr e.g. hba_queue_depth expands
1122 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1123 * takes a default argument, a minimum and maximum argument.
1124 *
1125 * lpfc_##attr##_init: Initializes an attribute.
1126 * @phba: pointer the the adapter structure.
1127 * @val: integer attribute value.
1128 *
1129 * Validates the min and max values then sets the adapter config field
1130 * accordingly, or uses the default if out of range and prints an error message.
1131 *
1132 * Returns:
1133 * zero on success
1134 * -EINVAL if default used
1135 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001136#define lpfc_param_init(attr, default, minval, maxval) \
1137static int \
1138lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
1139{ \
1140 if (val >= minval && val <= maxval) {\
1141 phba->cfg_##attr = val;\
1142 return 0;\
1143 }\
1144 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001145 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1146 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001147 phba->cfg_##attr = default;\
1148 return -EINVAL;\
1149}
1150
James Smarte59058c2008-08-24 21:49:00 -04001151/**
1152 * lpfc_param_set: Set a cfg attribute value.
1153 *
1154 * Description:
1155 * Macro that given an attr e.g. hba_queue_depth expands
1156 * into a function with the name lpfc_hba_queue_depth_set
1157 *
1158 * lpfc_##attr##_set: Sets an attribute value.
1159 * @phba: pointer the the adapter structure.
1160 * @val: integer attribute value.
1161 *
1162 * Description:
1163 * Validates the min and max values then sets the
1164 * adapter config field if in the valid range. prints error message
1165 * and does not set the parameter if invalid.
1166 *
1167 * Returns:
1168 * zero on success
1169 * -EINVAL if val is invalid
1170 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001171#define lpfc_param_set(attr, default, minval, maxval) \
1172static int \
1173lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
1174{ \
1175 if (val >= minval && val <= maxval) {\
1176 phba->cfg_##attr = val;\
1177 return 0;\
1178 }\
1179 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001180 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1181 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001182 return -EINVAL;\
1183}
1184
James Smarte59058c2008-08-24 21:49:00 -04001185/**
1186 * lpfc_param_store: Set a vport attribute value.
1187 *
1188 * Description:
1189 * Macro that given an attr e.g. hba_queue_depth expands
1190 * into a function with the name lpfc_hba_queue_depth_store.
1191 *
1192 * lpfc_##attr##_store: Set an sttribute value.
1193 * @dev: class device that is converted into a Scsi_host.
1194 * @attr: device attribute, not used.
1195 * @buf: contains the attribute value in ascii.
1196 * @count: not used.
1197 *
1198 * Description:
1199 * Convert the ascii text number to an integer, then
1200 * use the lpfc_##attr##_set function to set the value.
1201 *
1202 * Returns:
1203 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1204 * length of buffer upon success.
1205 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001206#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001207static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001208lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1209 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001210{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001211 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001212 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1213 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001214 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001215 if (!isdigit(buf[0]))\
1216 return -EINVAL;\
1217 if (sscanf(buf, "%i", &val) != 1)\
1218 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001219 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001220 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001221 else \
1222 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001223}
1224
James Smarte59058c2008-08-24 21:49:00 -04001225/**
1226 * lpfc_vport_param_show: Return decimal formatted cfg attribute value.
1227 *
1228 * Description:
1229 * Macro that given an attr e.g. hba_queue_depth expands
1230 * into a function with the name lpfc_hba_queue_depth_show
1231 *
1232 * lpfc_##attr##_show: prints the attribute value in decimal.
1233 * @dev: class device that is converted into a Scsi_host.
1234 * @attr: device attribute, not used.
1235 * @buf: on return contains the attribute value in decimal.
1236 *
1237 * Returns: length of formatted string.
1238 **/
James Smart3de2a652007-08-02 11:09:59 -04001239#define lpfc_vport_param_show(attr) \
1240static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001241lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1242 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001243{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001244 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001245 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1246 int val = 0;\
1247 val = vport->cfg_##attr;\
1248 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1249}
1250
James Smarte59058c2008-08-24 21:49:00 -04001251/**
1252 * lpfc_vport_param_hex_show: Return hex formatted attribute value.
1253 *
1254 * Description:
1255 * Macro that given an attr e.g.
1256 * hba_queue_depth expands into a function with the name
1257 * lpfc_hba_queue_depth_show
1258 *
1259 * lpfc_##attr##_show: prints the attribute value in hexidecimal.
1260 * @dev: class device that is converted into a Scsi_host.
1261 * @attr: device attribute, not used.
1262 * @buf: on return contains the attribute value in hexidecimal.
1263 *
1264 * Returns: length of formatted string.
1265 **/
James Smart3de2a652007-08-02 11:09:59 -04001266#define lpfc_vport_param_hex_show(attr) \
1267static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001268lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1269 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001270{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001271 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001272 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1273 int val = 0;\
1274 val = vport->cfg_##attr;\
1275 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1276}
1277
James Smarte59058c2008-08-24 21:49:00 -04001278/**
1279 * lpfc_vport_param_init: Initialize a vport cfg attribute.
1280 *
1281 * Description:
1282 * Macro that given an attr e.g. hba_queue_depth expands
1283 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1284 * takes a default argument, a minimum and maximum argument.
1285 *
1286 * lpfc_##attr##_init: validates the min and max values then sets the
1287 * adapter config field accordingly, or uses the default if out of range
1288 * and prints an error message.
1289 * @phba: pointer the the adapter structure.
1290 * @val: integer attribute value.
1291 *
1292 * Returns:
1293 * zero on success
1294 * -EINVAL if default used
1295 **/
James Smart3de2a652007-08-02 11:09:59 -04001296#define lpfc_vport_param_init(attr, default, minval, maxval) \
1297static int \
1298lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
1299{ \
1300 if (val >= minval && val <= maxval) {\
1301 vport->cfg_##attr = val;\
1302 return 0;\
1303 }\
James Smarte8b62012007-08-02 11:10:09 -04001304 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1305 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1306 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001307 vport->cfg_##attr = default;\
1308 return -EINVAL;\
1309}
1310
James Smarte59058c2008-08-24 21:49:00 -04001311/**
1312 * lpfc_vport_param_set: Set a vport cfg attribute.
1313 *
1314 * Description:
1315 * Macro that given an attr e.g. hba_queue_depth expands
1316 * into a function with the name lpfc_hba_queue_depth_set
1317 *
1318 * lpfc_##attr##_set: validates the min and max values then sets the
1319 * adapter config field if in the valid range. prints error message
1320 * and does not set the parameter if invalid.
1321 * @phba: pointer the the adapter structure.
1322 * @val: integer attribute value.
1323 *
1324 * Returns:
1325 * zero on success
1326 * -EINVAL if val is invalid
1327 **/
James Smart3de2a652007-08-02 11:09:59 -04001328#define lpfc_vport_param_set(attr, default, minval, maxval) \
1329static int \
1330lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
1331{ \
1332 if (val >= minval && val <= maxval) {\
1333 vport->cfg_##attr = val;\
1334 return 0;\
1335 }\
James Smarte8b62012007-08-02 11:10:09 -04001336 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1337 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1338 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04001339 return -EINVAL;\
1340}
1341
James Smarte59058c2008-08-24 21:49:00 -04001342/**
1343 * lpfc_vport_param_store: Set a vport attribute.
1344 *
1345 * Description:
1346 * Macro that given an attr e.g. hba_queue_depth
1347 * expands into a function with the name lpfc_hba_queue_depth_store
1348 *
1349 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1350 * use the lpfc_##attr##_set function to set the value.
1351 * @cdev: class device that is converted into a Scsi_host.
1352 * @buf: contains the attribute value in decimal.
1353 * @count: not used.
1354 *
1355 * Returns:
1356 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1357 * length of buffer upon success.
1358 **/
James Smart3de2a652007-08-02 11:09:59 -04001359#define lpfc_vport_param_store(attr) \
1360static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001361lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1362 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04001363{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001364 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1366 int val=0;\
1367 if (!isdigit(buf[0]))\
1368 return -EINVAL;\
1369 if (sscanf(buf, "%i", &val) != 1)\
1370 return -EINVAL;\
1371 if (lpfc_##attr##_set(vport, val) == 0) \
1372 return strlen(buf);\
1373 else \
1374 return -EINVAL;\
1375}
1376
1377
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001378#define LPFC_ATTR(name, defval, minval, maxval, desc) \
1379static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -05001380module_param(lpfc_##name, int, 0);\
1381MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001382lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -05001383
1384#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1385static int lpfc_##name = defval;\
1386module_param(lpfc_##name, int, 0);\
1387MODULE_PARM_DESC(lpfc_##name, desc);\
1388lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001389lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001390static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -05001391
1392#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1393static int lpfc_##name = defval;\
1394module_param(lpfc_##name, int, 0);\
1395MODULE_PARM_DESC(lpfc_##name, desc);\
1396lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001397lpfc_param_init(name, defval, minval, maxval)\
1398lpfc_param_set(name, defval, minval, maxval)\
1399lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001400static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1401 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -05001402
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001403#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1404static int lpfc_##name = defval;\
1405module_param(lpfc_##name, int, 0);\
1406MODULE_PARM_DESC(lpfc_##name, desc);\
1407lpfc_param_hex_show(name)\
1408lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001409static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001410
1411#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1412static int lpfc_##name = defval;\
1413module_param(lpfc_##name, int, 0);\
1414MODULE_PARM_DESC(lpfc_##name, desc);\
1415lpfc_param_hex_show(name)\
1416lpfc_param_init(name, defval, minval, maxval)\
1417lpfc_param_set(name, defval, minval, maxval)\
1418lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001419static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1420 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001421
James Smart3de2a652007-08-02 11:09:59 -04001422#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1423static int lpfc_##name = defval;\
1424module_param(lpfc_##name, int, 0);\
1425MODULE_PARM_DESC(lpfc_##name, desc);\
1426lpfc_vport_param_init(name, defval, minval, maxval)
1427
1428#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1429static int lpfc_##name = defval;\
1430module_param(lpfc_##name, int, 0);\
1431MODULE_PARM_DESC(lpfc_##name, desc);\
1432lpfc_vport_param_show(name)\
1433lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001434static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001435
1436#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1437static int lpfc_##name = defval;\
1438module_param(lpfc_##name, int, 0);\
1439MODULE_PARM_DESC(lpfc_##name, desc);\
1440lpfc_vport_param_show(name)\
1441lpfc_vport_param_init(name, defval, minval, maxval)\
1442lpfc_vport_param_set(name, defval, minval, maxval)\
1443lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001444static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1445 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001446
1447#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1448static int lpfc_##name = defval;\
1449module_param(lpfc_##name, int, 0);\
1450MODULE_PARM_DESC(lpfc_##name, desc);\
1451lpfc_vport_param_hex_show(name)\
1452lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +01001453static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -04001454
1455#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1456static int lpfc_##name = defval;\
1457module_param(lpfc_##name, int, 0);\
1458MODULE_PARM_DESC(lpfc_##name, desc);\
1459lpfc_vport_param_hex_show(name)\
1460lpfc_vport_param_init(name, defval, minval, maxval)\
1461lpfc_vport_param_set(name, defval, minval, maxval)\
1462lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +01001463static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1464 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -04001465
Tony Jonesee959b02008-02-22 00:13:36 +01001466static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1467static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1468static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1469static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1470static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1471static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1472static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1473static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01001474static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01001475static DEVICE_ATTR(option_rom_version, S_IRUGO,
1476 lpfc_option_rom_version_show, NULL);
1477static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1478 lpfc_num_discovered_ports_show, NULL);
1479static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1480static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1481static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1482 lpfc_board_mode_show, lpfc_board_mode_store);
1483static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1484static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1485static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1486static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1487static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1488static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1489static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1490static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1491static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
dea31012005-04-17 16:05:31 -05001492
James Smartc3f28af2006-08-18 17:47:18 -04001493
James Smarta12e07b2006-12-02 13:35:30 -05001494static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -04001495
James Smarte59058c2008-08-24 21:49:00 -04001496/**
1497 * lpfc_soft_wwn_enable_store: Allows setting of the wwn if the key is valid.
1498 * @dev: class device that is converted into a Scsi_host.
1499 * @attr: device attribute, not used.
1500 * @buf: containing the string lpfc_soft_wwn_key.
1501 * @count: must be size of lpfc_soft_wwn_key.
1502 *
1503 * Returns:
1504 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1505 * length of buf indicates success
1506 **/
James Smartc3f28af2006-08-18 17:47:18 -04001507static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001508lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1509 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001510{
Tony Jonesee959b02008-02-22 00:13:36 +01001511 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001512 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1513 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001514 unsigned int cnt = count;
1515
1516 /*
1517 * We're doing a simple sanity check for soft_wwpn setting.
1518 * We require that the user write a specific key to enable
1519 * the soft_wwpn attribute to be settable. Once the attribute
1520 * is written, the enable key resets. If further updates are
1521 * desired, the key must be written again to re-enable the
1522 * attribute.
1523 *
1524 * The "key" is not secret - it is a hardcoded string shown
1525 * here. The intent is to protect against the random user or
1526 * application that is just writing attributes.
1527 */
1528
1529 /* count may include a LF at end of string */
1530 if (buf[cnt-1] == '\n')
1531 cnt--;
1532
James Smarta12e07b2006-12-02 13:35:30 -05001533 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1534 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -04001535 return -EINVAL;
1536
James Smarta12e07b2006-12-02 13:35:30 -05001537 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -04001538 return count;
1539}
Tony Jonesee959b02008-02-22 00:13:36 +01001540static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1541 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -04001542
James Smarte59058c2008-08-24 21:49:00 -04001543/**
1544 * lpfc_soft_wwpn_show: Return the cfg soft ww port name of the adapter.
1545 * @dev: class device that is converted into a Scsi_host.
1546 * @attr: device attribute, not used.
1547 * @buf: on return contains the wwpn in hexidecimal.
1548 *
1549 * Returns: size of formatted string.
1550 **/
James Smartc3f28af2006-08-18 17:47:18 -04001551static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001552lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1553 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001554{
Tony Jonesee959b02008-02-22 00:13:36 +01001555 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001556 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1557 struct lpfc_hba *phba = vport->phba;
1558
Randy Dunlapafc071e2006-10-23 21:47:13 -07001559 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1560 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001561}
1562
James Smarte59058c2008-08-24 21:49:00 -04001563/**
1564 * lpfc_soft_wwpn_store: Set the ww port name of the adapter.
1565 * @dev class device that is converted into a Scsi_host.
1566 * @attr: device attribute, not used.
1567 * @buf: contains the wwpn in hexidecimal.
1568 * @count: number of wwpn bytes in buf
1569 *
1570 * Returns:
1571 * -EACCES hba reset not enabled, adapter over temp
1572 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1573 * -EIO error taking adapter offline or online
1574 * value of count on success
1575 **/
James Smartc3f28af2006-08-18 17:47:18 -04001576static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001577lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1578 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001579{
Tony Jonesee959b02008-02-22 00:13:36 +01001580 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001581 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1582 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001583 struct completion online_compl;
1584 int stat1=0, stat2=0;
1585 unsigned int i, j, cnt=count;
1586 u8 wwpn[8];
1587
James Smart13815c82008-01-11 01:52:48 -05001588 if (!phba->cfg_enable_hba_reset)
1589 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001590 spin_lock_irq(&phba->hbalock);
1591 if (phba->over_temp_state == HBA_OVER_TEMP) {
1592 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001593 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001594 }
1595 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001596 /* count may include a LF at end of string */
1597 if (buf[cnt-1] == '\n')
1598 cnt--;
1599
James Smarta12e07b2006-12-02 13:35:30 -05001600 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001601 ((cnt == 17) && (*buf++ != 'x')) ||
1602 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1603 return -EINVAL;
1604
James Smarta12e07b2006-12-02 13:35:30 -05001605 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001606
1607 memset(wwpn, 0, sizeof(wwpn));
1608
1609 /* Validate and store the new name */
1610 for (i=0, j=0; i < 16; i++) {
1611 if ((*buf >= 'a') && (*buf <= 'f'))
1612 j = ((j << 4) | ((*buf++ -'a') + 10));
1613 else if ((*buf >= 'A') && (*buf <= 'F'))
1614 j = ((j << 4) | ((*buf++ -'A') + 10));
1615 else if ((*buf >= '0') && (*buf <= '9'))
1616 j = ((j << 4) | (*buf++ -'0'));
1617 else
1618 return -EINVAL;
1619 if (i % 2) {
1620 wwpn[i/2] = j & 0xff;
1621 j = 0;
1622 }
1623 }
1624 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001625 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001626 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001627 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001628
1629 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1630 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1631
James Smart46fa3112007-04-25 09:51:45 -04001632 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001633 if (stat1)
1634 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001635 "0463 lpfc_soft_wwpn attribute set failed to "
1636 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001637 init_completion(&online_compl);
1638 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1639 wait_for_completion(&online_compl);
1640 if (stat2)
1641 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001642 "0464 lpfc_soft_wwpn attribute set failed to "
1643 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001644 return (stat1 || stat2) ? -EIO : count;
1645}
Tony Jonesee959b02008-02-22 00:13:36 +01001646static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1647 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001648
James Smarte59058c2008-08-24 21:49:00 -04001649/**
1650 * lpfc_soft_wwnn_show: Return the cfg soft ww node name for the adapter.
1651 * @dev: class device that is converted into a Scsi_host.
1652 * @attr: device attribute, not used.
1653 * @buf: on return contains the wwnn in hexidecimal.
1654 *
1655 * Returns: size of formatted string.
1656 **/
James Smarta12e07b2006-12-02 13:35:30 -05001657static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001658lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1659 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001660{
Tony Jonesee959b02008-02-22 00:13:36 +01001661 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001662 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001663 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1664 (unsigned long long)phba->cfg_soft_wwnn);
1665}
1666
James Smarte59058c2008-08-24 21:49:00 -04001667/**
1668 * lpfc_soft_wwnn_store: sets the ww node name of the adapter.
1669 * @cdev: class device that is converted into a Scsi_host.
1670 * @buf: contains the ww node name in hexidecimal.
1671 * @count: number of wwnn bytes in buf.
1672 *
1673 * Returns:
1674 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1675 * value of count on success
1676 **/
James Smarta12e07b2006-12-02 13:35:30 -05001677static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001678lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1679 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001680{
Tony Jonesee959b02008-02-22 00:13:36 +01001681 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001682 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001683 unsigned int i, j, cnt=count;
1684 u8 wwnn[8];
1685
1686 /* count may include a LF at end of string */
1687 if (buf[cnt-1] == '\n')
1688 cnt--;
1689
1690 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1691 ((cnt == 17) && (*buf++ != 'x')) ||
1692 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1693 return -EINVAL;
1694
1695 /*
1696 * Allow wwnn to be set many times, as long as the enable is set.
1697 * However, once the wwpn is set, everything locks.
1698 */
1699
1700 memset(wwnn, 0, sizeof(wwnn));
1701
1702 /* Validate and store the new name */
1703 for (i=0, j=0; i < 16; i++) {
1704 if ((*buf >= 'a') && (*buf <= 'f'))
1705 j = ((j << 4) | ((*buf++ -'a') + 10));
1706 else if ((*buf >= 'A') && (*buf <= 'F'))
1707 j = ((j << 4) | ((*buf++ -'A') + 10));
1708 else if ((*buf >= '0') && (*buf <= '9'))
1709 j = ((j << 4) | (*buf++ -'0'));
1710 else
1711 return -EINVAL;
1712 if (i % 2) {
1713 wwnn[i/2] = j & 0xff;
1714 j = 0;
1715 }
1716 }
1717 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1718
1719 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1720 "lpfc%d: soft_wwnn set. Value will take effect upon "
1721 "setting of the soft_wwpn\n", phba->brd_no);
1722
1723 return count;
1724}
Tony Jonesee959b02008-02-22 00:13:36 +01001725static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1726 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001727
James Smartc3f28af2006-08-18 17:47:18 -04001728
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001729static int lpfc_poll = 0;
1730module_param(lpfc_poll, int, 0);
1731MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1732 " 0 - none,"
1733 " 1 - poll with interrupts enabled"
1734 " 3 - poll and disable FCP ring interrupts");
1735
Tony Jonesee959b02008-02-22 00:13:36 +01001736static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1737 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001738
James Smart92d7f7b2007-06-17 19:56:38 -05001739int lpfc_sli_mode = 0;
1740module_param(lpfc_sli_mode, int, 0);
1741MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1742 " 0 - auto (SLI-3 if supported),"
1743 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1744 " 3 - select SLI-3");
1745
James Smart7ee5d432007-10-27 13:37:17 -04001746int lpfc_enable_npiv = 0;
1747module_param(lpfc_enable_npiv, int, 0);
1748MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1749lpfc_param_show(enable_npiv);
1750lpfc_param_init(enable_npiv, 0, 0, 1);
Tony Jonesee959b02008-02-22 00:13:36 +01001751static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
James Smart7ee5d432007-10-27 13:37:17 -04001752 lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001753
dea31012005-04-17 16:05:31 -05001754/*
James Smartc01f3202006-08-18 17:47:08 -04001755# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1756# until the timer expires. Value range is [0,255]. Default value is 30.
1757*/
1758static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1759static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1760module_param(lpfc_nodev_tmo, int, 0);
1761MODULE_PARM_DESC(lpfc_nodev_tmo,
1762 "Seconds driver will hold I/O waiting "
1763 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04001764
1765/**
1766 * lpfc_nodev_tmo_show: Return the hba dev loss timeout value.
1767 * @dev: class converted to a Scsi_host structure.
1768 * @attr: device attribute, not used.
1769 * @buf: on return contains the dev loss timeout in decimal.
1770 *
1771 * Returns: size of formatted string.
1772 **/
James Smartc01f3202006-08-18 17:47:08 -04001773static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001774lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1775 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04001776{
Tony Jonesee959b02008-02-22 00:13:36 +01001777 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001778 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smartc01f3202006-08-18 17:47:08 -04001779 int val = 0;
James Smart3de2a652007-08-02 11:09:59 -04001780 val = vport->cfg_devloss_tmo;
1781 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001782}
1783
James Smarte59058c2008-08-24 21:49:00 -04001784/**
1785 * lpfc_nodev_tmo_init: Set the hba nodev timeout value.
1786 * @vport: lpfc vport structure pointer.
1787 * @val: contains the nodev timeout value.
1788 *
1789 * Description:
1790 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1791 * a kernel error message is printed and zero is returned.
1792 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1793 * Otherwise nodev tmo is set to the default value.
1794 *
1795 * Returns:
1796 * zero if already set or if val is in range
1797 * -EINVAL val out of range
1798 **/
James Smartc01f3202006-08-18 17:47:08 -04001799static int
James Smart3de2a652007-08-02 11:09:59 -04001800lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001801{
James Smart3de2a652007-08-02 11:09:59 -04001802 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1803 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1804 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04001805 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1806 "0402 Ignoring nodev_tmo module "
1807 "parameter because devloss_tmo is "
1808 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001809 return 0;
1810 }
1811
1812 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001813 vport->cfg_nodev_tmo = val;
1814 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04001815 return 0;
1816 }
James Smarte8b62012007-08-02 11:10:09 -04001817 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1818 "0400 lpfc_nodev_tmo attribute cannot be set to"
1819 " %d, allowed range is [%d, %d]\n",
1820 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04001821 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04001822 return -EINVAL;
1823}
1824
James Smarte59058c2008-08-24 21:49:00 -04001825/**
1826 * lpfc_update_rport_devloss_tmo: Update dev loss tmo value.
1827 * @vport: lpfc vport structure pointer.
1828 *
1829 * Description:
1830 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
1831 **/
James Smart7054a602007-04-25 09:52:34 -04001832static void
James Smart3de2a652007-08-02 11:09:59 -04001833lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04001834{
James Smart858c9f62007-06-17 19:56:39 -05001835 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04001836 struct lpfc_nodelist *ndlp;
1837
James Smart51ef4c22007-08-02 11:10:31 -04001838 shost = lpfc_shost_from_vport(vport);
1839 spin_lock_irq(shost->host_lock);
1840 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05001841 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04001842 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1843 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04001844}
1845
James Smarte59058c2008-08-24 21:49:00 -04001846/**
1847 * lpfc_nodev_tmo_set: Set the vport nodev tmo and devloss tmo values.
1848 * @vport: lpfc vport structure pointer.
1849 * @val: contains the tmo value.
1850 *
1851 * Description:
1852 * If the devloss tmo is already set or the vport dev loss tmo has changed
1853 * then a kernel error message is printed and zero is returned.
1854 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1855 * Otherwise nodev tmo is set to the default value.
1856 *
1857 * Returns:
1858 * zero if already set or if val is in range
1859 * -EINVAL val out of range
1860 **/
James Smartc01f3202006-08-18 17:47:08 -04001861static int
James Smart3de2a652007-08-02 11:09:59 -04001862lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001863{
James Smart3de2a652007-08-02 11:09:59 -04001864 if (vport->dev_loss_tmo_changed ||
1865 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04001866 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1867 "0401 Ignoring change to nodev_tmo "
1868 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001869 return 0;
1870 }
James Smartc01f3202006-08-18 17:47:08 -04001871 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001872 vport->cfg_nodev_tmo = val;
1873 vport->cfg_devloss_tmo = val;
1874 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001875 return 0;
1876 }
James Smarte8b62012007-08-02 11:10:09 -04001877 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1878 "0403 lpfc_nodev_tmo attribute cannot be set to"
1879 "%d, allowed range is [%d, %d]\n",
1880 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001881 return -EINVAL;
1882}
1883
James Smart3de2a652007-08-02 11:09:59 -04001884lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001885
Tony Jonesee959b02008-02-22 00:13:36 +01001886static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1887 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04001888
1889/*
1890# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1891# disappear until the timer expires. Value range is [0,255]. Default
1892# value is 30.
1893*/
1894module_param(lpfc_devloss_tmo, int, 0);
1895MODULE_PARM_DESC(lpfc_devloss_tmo,
1896 "Seconds driver will hold I/O waiting "
1897 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04001898lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
1899 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
1900lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04001901
1902/**
1903 * lpfc_devloss_tmo_set: Sets vport nodev tmo, devloss tmo values, changed bit.
1904 * @vport: lpfc vport structure pointer.
1905 * @val: contains the tmo value.
1906 *
1907 * Description:
1908 * If val is in a valid range then set the vport nodev tmo,
1909 * devloss tmo, also set the vport dev loss tmo changed flag.
1910 * Else a kernel error message is printed.
1911 *
1912 * Returns:
1913 * zero if val is in range
1914 * -EINVAL val out of range
1915 **/
James Smartc01f3202006-08-18 17:47:08 -04001916static int
James Smart3de2a652007-08-02 11:09:59 -04001917lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001918{
1919 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001920 vport->cfg_nodev_tmo = val;
1921 vport->cfg_devloss_tmo = val;
1922 vport->dev_loss_tmo_changed = 1;
1923 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001924 return 0;
1925 }
1926
James Smarte8b62012007-08-02 11:10:09 -04001927 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1928 "0404 lpfc_devloss_tmo attribute cannot be set to"
1929 " %d, allowed range is [%d, %d]\n",
1930 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001931 return -EINVAL;
1932}
1933
James Smart3de2a652007-08-02 11:09:59 -04001934lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01001935static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
1936 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04001937
1938/*
dea31012005-04-17 16:05:31 -05001939# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
1940# deluged with LOTS of information.
1941# You can set a bit mask to record specific types of verbose messages:
1942#
1943# LOG_ELS 0x1 ELS events
1944# LOG_DISCOVERY 0x2 Link discovery events
1945# LOG_MBOX 0x4 Mailbox events
1946# LOG_INIT 0x8 Initialization events
1947# LOG_LINK_EVENT 0x10 Link events
dea31012005-04-17 16:05:31 -05001948# LOG_FCP 0x40 FCP traffic history
1949# LOG_NODE 0x80 Node table events
1950# LOG_MISC 0x400 Miscellaneous events
1951# LOG_SLI 0x800 SLI events
James Smartc7743952006-12-02 13:34:42 -05001952# LOG_FCP_ERROR 0x1000 Only log FCP errors
dea31012005-04-17 16:05:31 -05001953# LOG_LIBDFC 0x2000 LIBDFC events
1954# LOG_ALL_MSG 0xffff LOG all messages
1955*/
James Smarte8b62012007-08-02 11:10:09 -04001956LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
1957 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05001958
1959/*
James Smart7ee5d432007-10-27 13:37:17 -04001960# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
1961# objects that have been registered with the nameserver after login.
1962*/
1963LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
1964 "Deregister nameserver objects before LOGO");
1965
1966/*
dea31012005-04-17 16:05:31 -05001967# lun_queue_depth: This parameter is used to limit the number of outstanding
1968# commands per FCP LUN. Value range is [1,128]. Default value is 30.
1969*/
James Smart3de2a652007-08-02 11:09:59 -04001970LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
1971 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05001972
1973/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001974# hba_queue_depth: This parameter is used to limit the number of outstanding
1975# commands per lpfc HBA. Value range is [32,8192]. If this parameter
1976# value is greater than the maximum number of exchanges supported by the HBA,
1977# then maximum number of exchanges supported by the HBA is used to determine
1978# the hba_queue_depth.
1979*/
1980LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
1981 "Max number of FCP commands we can queue to a lpfc HBA");
1982
1983/*
James Smart92d7f7b2007-06-17 19:56:38 -05001984# peer_port_login: This parameter allows/prevents logins
1985# between peer ports hosted on the same physical port.
1986# When this parameter is set 0 peer ports of same physical port
1987# are not allowed to login to each other.
1988# When this parameter is set 1 peer ports of same physical port
1989# are allowed to login to each other.
1990# Default value of this parameter is 0.
1991*/
James Smart3de2a652007-08-02 11:09:59 -04001992LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
1993 "Allow peer ports on the same physical port to login to each "
1994 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05001995
1996/*
James Smart3de2a652007-08-02 11:09:59 -04001997# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05001998# between Virtual Ports and remote initiators.
1999# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2000# other initiators and will attempt to PLOGI all remote ports.
2001# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2002# remote ports and will not attempt to PLOGI to other initiators.
2003# This parameter does not restrict to the physical port.
2004# This parameter does not restrict logins to Fabric resident remote ports.
2005# Default value of this parameter is 1.
2006*/
James Smart3de2a652007-08-02 11:09:59 -04002007static int lpfc_restrict_login = 1;
2008module_param(lpfc_restrict_login, int, 0);
2009MODULE_PARM_DESC(lpfc_restrict_login,
2010 "Restrict virtual ports login to remote initiators.");
2011lpfc_vport_param_show(restrict_login);
2012
James Smarte59058c2008-08-24 21:49:00 -04002013/**
2014 * lpfc_restrict_login_init: Set the vport restrict login flag.
2015 * @vport: lpfc vport structure pointer.
2016 * @val: contains the restrict login value.
2017 *
2018 * Description:
2019 * If val is not in a valid range then log a kernel error message and set
2020 * the vport restrict login to one.
2021 * If the port type is physical clear the restrict login flag and return.
2022 * Else set the restrict login flag to val.
2023 *
2024 * Returns:
2025 * zero if val is in range
2026 * -EINVAL val out of range
2027 **/
James Smart3de2a652007-08-02 11:09:59 -04002028static int
2029lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2030{
2031 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002032 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2033 "0449 lpfc_restrict_login attribute cannot "
2034 "be set to %d, allowed range is [0, 1]\n",
2035 val);
James Smart3de2a652007-08-02 11:09:59 -04002036 vport->cfg_restrict_login = 1;
2037 return -EINVAL;
2038 }
2039 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2040 vport->cfg_restrict_login = 0;
2041 return 0;
2042 }
2043 vport->cfg_restrict_login = val;
2044 return 0;
2045}
2046
James Smarte59058c2008-08-24 21:49:00 -04002047/**
2048 * lpfc_restrict_login_set: Set the vport restrict login flag.
2049 * @vport: lpfc vport structure pointer.
2050 * @val: contains the restrict login value.
2051 *
2052 * Description:
2053 * If val is not in a valid range then log a kernel error message and set
2054 * the vport restrict login to one.
2055 * If the port type is physical and the val is not zero log a kernel
2056 * error message, clear the restrict login flag and return zero.
2057 * Else set the restrict login flag to val.
2058 *
2059 * Returns:
2060 * zero if val is in range
2061 * -EINVAL val out of range
2062 **/
James Smart3de2a652007-08-02 11:09:59 -04002063static int
2064lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2065{
2066 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04002067 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2068 "0450 lpfc_restrict_login attribute cannot "
2069 "be set to %d, allowed range is [0, 1]\n",
2070 val);
James Smart3de2a652007-08-02 11:09:59 -04002071 vport->cfg_restrict_login = 1;
2072 return -EINVAL;
2073 }
2074 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04002075 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2076 "0468 lpfc_restrict_login must be 0 for "
2077 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04002078 vport->cfg_restrict_login = 0;
2079 return 0;
2080 }
2081 vport->cfg_restrict_login = val;
2082 return 0;
2083}
2084lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01002085static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2086 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05002087
2088/*
dea31012005-04-17 16:05:31 -05002089# Some disk devices have a "select ID" or "select Target" capability.
2090# From a protocol standpoint "select ID" usually means select the
2091# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2092# annex" which contains a table that maps a "select ID" (a number
2093# between 0 and 7F) to an ALPA. By default, for compatibility with
2094# older drivers, the lpfc driver scans this table from low ALPA to high
2095# ALPA.
2096#
2097# Turning on the scan-down variable (on = 1, off = 0) will
2098# cause the lpfc driver to use an inverted table, effectively
2099# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2100#
2101# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2102# and will not work across a fabric. Also this parameter will take
2103# effect only in the case when ALPA map is not available.)
2104*/
James Smart3de2a652007-08-02 11:09:59 -04002105LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2106 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05002107
2108/*
dea31012005-04-17 16:05:31 -05002109# lpfc_topology: link topology for init link
2110# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05002111# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05002112# 0x02 = attempt point-to-point mode only
2113# 0x04 = attempt loop mode only
2114# 0x06 = attempt point-to-point mode then loop
2115# Set point-to-point mode if you want to run as an N_Port.
2116# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2117# Default value is 0.
2118*/
James Smarte59058c2008-08-24 21:49:00 -04002119
2120/**
2121 * lpfc_topology_set: Set the adapters topology field.
2122 * @phba: lpfc_hba pointer.
2123 * @val: topology value.
2124 *
2125 * Description:
2126 * If val is in a valid range then set the adapter's topology field and
2127 * issue a lip; if the lip fails reset the topology to the old value.
2128 *
2129 * If the value is not in range log a kernel error message and return an error.
2130 *
2131 * Returns:
2132 * zero if val is in range and lip okay
2133 * non-zero return value from lpfc_issue_lip()
2134 * -EINVAL val out of range
2135 **/
James Smart83108bd2008-01-11 01:53:09 -05002136static int
2137lpfc_topology_set(struct lpfc_hba *phba, int val)
2138{
2139 int err;
2140 uint32_t prev_val;
2141 if (val >= 0 && val <= 6) {
2142 prev_val = phba->cfg_topology;
2143 phba->cfg_topology = val;
2144 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2145 if (err)
2146 phba->cfg_topology = prev_val;
2147 return err;
2148 }
2149 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2150 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2151 "allowed range is [0, 6]\n",
2152 phba->brd_no, val);
2153 return -EINVAL;
2154}
2155static int lpfc_topology = 0;
2156module_param(lpfc_topology, int, 0);
2157MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2158lpfc_param_show(topology)
2159lpfc_param_init(topology, 0, 0, 6)
2160lpfc_param_store(topology)
Tony Jonesee959b02008-02-22 00:13:36 +01002161static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002162 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05002163
2164/*
2165# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2166# connection.
2167# 0 = auto select (default)
2168# 1 = 1 Gigabaud
2169# 2 = 2 Gigabaud
2170# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04002171# 8 = 8 Gigabaud
2172# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05002173*/
James Smarte59058c2008-08-24 21:49:00 -04002174
2175/**
2176 * lpfc_link_speed_set: Set the adapters link speed.
2177 * @phba: lpfc_hba pointer.
2178 * @val: link speed value.
2179 *
2180 * Description:
2181 * If val is in a valid range then set the adapter's link speed field and
2182 * issue a lip; if the lip fails reset the link speed to the old value.
2183 *
2184 * Notes:
2185 * If the value is not in range log a kernel error message and return an error.
2186 *
2187 * Returns:
2188 * zero if val is in range and lip okay.
2189 * non-zero return value from lpfc_issue_lip()
2190 * -EINVAL val out of range
2191 **/
James Smart83108bd2008-01-11 01:53:09 -05002192static int
2193lpfc_link_speed_set(struct lpfc_hba *phba, int val)
2194{
2195 int err;
2196 uint32_t prev_val;
2197
2198 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2199 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2200 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2201 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2202 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2203 return -EINVAL;
2204
2205 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2206 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2207 prev_val = phba->cfg_link_speed;
2208 phba->cfg_link_speed = val;
2209 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2210 if (err)
2211 phba->cfg_link_speed = prev_val;
2212 return err;
2213 }
2214
2215 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2216 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2217 "allowed range is [0, 8]\n",
2218 phba->brd_no, val);
2219 return -EINVAL;
2220}
2221
2222static int lpfc_link_speed = 0;
2223module_param(lpfc_link_speed, int, 0);
2224MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2225lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04002226
2227/**
2228 * lpfc_link_speed_init: Set the adapters link speed.
2229 * @phba: lpfc_hba pointer.
2230 * @val: link speed value.
2231 *
2232 * Description:
2233 * If val is in a valid range then set the adapter's link speed field.
2234 *
2235 * Notes:
2236 * If the value is not in range log a kernel error message, clear the link
2237 * speed and return an error.
2238 *
2239 * Returns:
2240 * zero if val saved.
2241 * -EINVAL val out of range
2242 **/
James Smart83108bd2008-01-11 01:53:09 -05002243static int
2244lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2245{
2246 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2247 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2248 phba->cfg_link_speed = val;
2249 return 0;
2250 }
2251 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2252 "0454 lpfc_link_speed attribute cannot "
2253 "be set to %d, allowed values are "
2254 "["LPFC_LINK_SPEED_STRING"]\n", val);
2255 phba->cfg_link_speed = 0;
2256 return -EINVAL;
2257}
2258
2259lpfc_param_store(link_speed)
Tony Jonesee959b02008-02-22 00:13:36 +01002260static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05002261 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05002262
2263/*
2264# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
2265# Value range is [2,3]. Default value is 3.
2266*/
James Smart3de2a652007-08-02 11:09:59 -04002267LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
2268 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05002269
2270/*
2271# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
2272# is [0,1]. Default value is 0.
2273*/
James Smart3de2a652007-08-02 11:09:59 -04002274LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
2275 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05002276
2277/*
2278# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
2279# range is [0,1]. Default value is 0.
2280*/
2281LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
2282
2283/*
2284# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
2285# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04002286# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05002287# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
2288# cr_delay is set to 0.
2289*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05002290LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05002291 "interrupt response is generated");
2292
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05002293LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05002294 "interrupt response is generated");
2295
2296/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002297# lpfc_multi_ring_support: Determines how many rings to spread available
2298# cmd/rsp IOCB entries across.
2299# Value range is [1,2]. Default value is 1.
2300*/
2301LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
2302 "SLI rings to spread IOCB entries across");
2303
2304/*
James Smarta4bc3372006-12-02 13:34:16 -05002305# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
2306# identifies what rctl value to configure the additional ring for.
2307# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
2308*/
2309LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
2310 255, "Identifies RCTL for additional ring configuration");
2311
2312/*
2313# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
2314# identifies what type value to configure the additional ring for.
2315# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
2316*/
2317LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
2318 255, "Identifies TYPE for additional ring configuration");
2319
2320/*
dea31012005-04-17 16:05:31 -05002321# lpfc_fdmi_on: controls FDMI support.
2322# 0 = no FDMI support
2323# 1 = support FDMI without attribute of hostname
2324# 2 = support FDMI with attribute of hostname
2325# Value range [0,2]. Default value is 0.
2326*/
James Smart3de2a652007-08-02 11:09:59 -04002327LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05002328
2329/*
2330# Specifies the maximum number of ELS cmds we can have outstanding (for
2331# discovery). Value range is [1,64]. Default value = 32.
2332*/
James Smart3de2a652007-08-02 11:09:59 -04002333LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05002334 "during discovery");
2335
2336/*
James Smart65a29c12006-07-06 15:50:50 -04002337# lpfc_max_luns: maximum allowed LUN.
2338# Value range is [0,65535]. Default value is 255.
2339# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05002340*/
James Smart3de2a652007-08-02 11:09:59 -04002341LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05002342
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002343/*
2344# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
2345# Value range is [1,255], default value is 10.
2346*/
2347LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
2348 "Milliseconds driver will wait between polling FCP ring");
2349
James Smart4ff43242006-12-02 13:34:56 -05002350/*
2351# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
2352# support this feature
2353# 0 = MSI disabled (default)
2354# 1 = MSI enabled
James Smartdb2378e2008-02-08 18:49:51 -05002355# 2 = MSI-X enabled
2356# Value range is [0,2]. Default value is 0.
James Smart4ff43242006-12-02 13:34:56 -05002357*/
James Smartdb2378e2008-02-08 18:49:51 -05002358LPFC_ATTR_R(use_msi, 0, 0, 2, "Use Message Signaled Interrupts (1) or "
2359 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05002360
James Smart13815c82008-01-11 01:52:48 -05002361/*
2362# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
2363# 0 = HBA resets disabled
2364# 1 = HBA resets enabled (default)
2365# Value range is [0,1]. Default value is 1.
2366*/
2367LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04002368
James Smart13815c82008-01-11 01:52:48 -05002369/*
2370# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
2371# 0 = HBA Heartbeat disabled
2372# 1 = HBA Heartbeat enabled (default)
2373# Value range is [0,1]. Default value is 1.
2374*/
2375LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05002376
James Smart83108bd2008-01-11 01:53:09 -05002377/*
2378 * lpfc_sg_seg_cnt: Initial Maximum DMA Segment Count
2379 * This value can be set to values between 64 and 256. The default value is
2380 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
2381 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
2382 */
2383LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
2384 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
2385
Tony Jonesee959b02008-02-22 00:13:36 +01002386struct device_attribute *lpfc_hba_attrs[] = {
2387 &dev_attr_info,
2388 &dev_attr_serialnum,
2389 &dev_attr_modeldesc,
2390 &dev_attr_modelname,
2391 &dev_attr_programtype,
2392 &dev_attr_portnum,
2393 &dev_attr_fwrev,
2394 &dev_attr_hdw,
2395 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01002396 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01002397 &dev_attr_num_discovered_ports,
2398 &dev_attr_lpfc_drvr_version,
2399 &dev_attr_lpfc_temp_sensor,
2400 &dev_attr_lpfc_log_verbose,
2401 &dev_attr_lpfc_lun_queue_depth,
2402 &dev_attr_lpfc_hba_queue_depth,
2403 &dev_attr_lpfc_peer_port_login,
2404 &dev_attr_lpfc_nodev_tmo,
2405 &dev_attr_lpfc_devloss_tmo,
2406 &dev_attr_lpfc_fcp_class,
2407 &dev_attr_lpfc_use_adisc,
2408 &dev_attr_lpfc_ack0,
2409 &dev_attr_lpfc_topology,
2410 &dev_attr_lpfc_scan_down,
2411 &dev_attr_lpfc_link_speed,
2412 &dev_attr_lpfc_cr_delay,
2413 &dev_attr_lpfc_cr_count,
2414 &dev_attr_lpfc_multi_ring_support,
2415 &dev_attr_lpfc_multi_ring_rctl,
2416 &dev_attr_lpfc_multi_ring_type,
2417 &dev_attr_lpfc_fdmi_on,
2418 &dev_attr_lpfc_max_luns,
2419 &dev_attr_lpfc_enable_npiv,
2420 &dev_attr_nport_evt_cnt,
2421 &dev_attr_board_mode,
2422 &dev_attr_max_vpi,
2423 &dev_attr_used_vpi,
2424 &dev_attr_max_rpi,
2425 &dev_attr_used_rpi,
2426 &dev_attr_max_xri,
2427 &dev_attr_used_xri,
2428 &dev_attr_npiv_info,
2429 &dev_attr_issue_reset,
2430 &dev_attr_lpfc_poll,
2431 &dev_attr_lpfc_poll_tmo,
2432 &dev_attr_lpfc_use_msi,
2433 &dev_attr_lpfc_soft_wwnn,
2434 &dev_attr_lpfc_soft_wwpn,
2435 &dev_attr_lpfc_soft_wwn_enable,
2436 &dev_attr_lpfc_enable_hba_reset,
2437 &dev_attr_lpfc_enable_hba_heartbeat,
2438 &dev_attr_lpfc_sg_seg_cnt,
dea31012005-04-17 16:05:31 -05002439 NULL,
2440};
2441
Tony Jonesee959b02008-02-22 00:13:36 +01002442struct device_attribute *lpfc_vport_attrs[] = {
2443 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01002444 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01002445 &dev_attr_num_discovered_ports,
2446 &dev_attr_lpfc_drvr_version,
2447 &dev_attr_lpfc_log_verbose,
2448 &dev_attr_lpfc_lun_queue_depth,
2449 &dev_attr_lpfc_nodev_tmo,
2450 &dev_attr_lpfc_devloss_tmo,
2451 &dev_attr_lpfc_hba_queue_depth,
2452 &dev_attr_lpfc_peer_port_login,
2453 &dev_attr_lpfc_restrict_login,
2454 &dev_attr_lpfc_fcp_class,
2455 &dev_attr_lpfc_use_adisc,
2456 &dev_attr_lpfc_fdmi_on,
2457 &dev_attr_lpfc_max_luns,
2458 &dev_attr_nport_evt_cnt,
2459 &dev_attr_npiv_info,
2460 &dev_attr_lpfc_enable_da_id,
James Smart3de2a652007-08-02 11:09:59 -04002461 NULL,
2462};
2463
James Smarte59058c2008-08-24 21:49:00 -04002464/**
2465 * sysfs_ctlreg_write: Write method for writing to ctlreg.
2466 * @kobj: kernel kobject that contains the kernel class device.
2467 * @bin_attr: kernel attributes passed to us.
2468 * @buf: contains the data to be written to the adapter IOREG space.
2469 * @off: offset into buffer to beginning of data.
2470 * @count: bytes to transfer.
2471 *
2472 * Description:
2473 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
2474 * Uses the adapter io control registers to send buf contents to the adapter.
2475 *
2476 * Returns:
2477 * -ERANGE off and count combo out of range
2478 * -EINVAL off, count or buff address invalid
2479 * -EPERM adapter is offline
2480 * value of count, buf contents written
2481 **/
dea31012005-04-17 16:05:31 -05002482static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08002483sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
2484 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05002485{
2486 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01002487 struct device *dev = container_of(kobj, struct device, kobj);
2488 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002489 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2490 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002491
2492 if ((off + count) > FF_REG_AREA_SIZE)
2493 return -ERANGE;
2494
2495 if (count == 0) return 0;
2496
2497 if (off % 4 || count % 4 || (unsigned long)buf % 4)
2498 return -EINVAL;
2499
James Smart2e0fef82007-06-17 19:56:36 -05002500 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05002501 return -EPERM;
2502 }
2503
James Smart2e0fef82007-06-17 19:56:36 -05002504 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002505 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
2506 writel(*((uint32_t *)(buf + buf_off)),
2507 phba->ctrl_regs_memmap_p + off + buf_off);
2508
James Smart2e0fef82007-06-17 19:56:36 -05002509 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002510
2511 return count;
2512}
2513
James Smarte59058c2008-08-24 21:49:00 -04002514/**
2515 * sysfs_ctlreg_read: Read method for reading from ctlreg.
2516 * @kobj: kernel kobject that contains the kernel class device.
2517 * @bin_attr: kernel attributes passed to us.
2518 * @buf: if succesful contains the data from the adapter IOREG space.
2519 * @off: offset into buffer to beginning of data.
2520 * @count: bytes to transfer.
2521 *
2522 * Description:
2523 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
2524 * Uses the adapter io control registers to read data into buf.
2525 *
2526 * Returns:
2527 * -ERANGE off and count combo out of range
2528 * -EINVAL off, count or buff address invalid
2529 * value of count, buf contents read
2530 **/
dea31012005-04-17 16:05:31 -05002531static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08002532sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2533 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05002534{
2535 size_t buf_off;
2536 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01002537 struct device *dev = container_of(kobj, struct device, kobj);
2538 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002539 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2540 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002541
2542 if (off > FF_REG_AREA_SIZE)
2543 return -ERANGE;
2544
2545 if ((off + count) > FF_REG_AREA_SIZE)
2546 count = FF_REG_AREA_SIZE - off;
2547
2548 if (count == 0) return 0;
2549
2550 if (off % 4 || count % 4 || (unsigned long)buf % 4)
2551 return -EINVAL;
2552
James Smart2e0fef82007-06-17 19:56:36 -05002553 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002554
2555 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
2556 tmp_ptr = (uint32_t *)(buf + buf_off);
2557 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
2558 }
2559
James Smart2e0fef82007-06-17 19:56:36 -05002560 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002561
2562 return count;
2563}
2564
2565static struct bin_attribute sysfs_ctlreg_attr = {
2566 .attr = {
2567 .name = "ctlreg",
2568 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05002569 },
2570 .size = 256,
2571 .read = sysfs_ctlreg_read,
2572 .write = sysfs_ctlreg_write,
2573};
2574
James Smarte59058c2008-08-24 21:49:00 -04002575/**
2576 * sysfs_mbox_idle: frees the sysfs mailbox.
2577 * @phba: lpfc_hba pointer
2578 **/
dea31012005-04-17 16:05:31 -05002579static void
James Smart2e0fef82007-06-17 19:56:36 -05002580sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002581{
2582 phba->sysfs_mbox.state = SMBOX_IDLE;
2583 phba->sysfs_mbox.offset = 0;
2584
2585 if (phba->sysfs_mbox.mbox) {
2586 mempool_free(phba->sysfs_mbox.mbox,
2587 phba->mbox_mem_pool);
2588 phba->sysfs_mbox.mbox = NULL;
2589 }
2590}
2591
James Smarte59058c2008-08-24 21:49:00 -04002592/**
2593 * sysfs_mbox_write: Write method for writing information via mbox.
2594 * @kobj: kernel kobject that contains the kernel class device.
2595 * @bin_attr: kernel attributes passed to us.
2596 * @buf: contains the data to be written to sysfs mbox.
2597 * @off: offset into buffer to beginning of data.
2598 * @count: bytes to transfer.
2599 *
2600 * Description:
2601 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
2602 * Uses the sysfs mbox to send buf contents to the adapter.
2603 *
2604 * Returns:
2605 * -ERANGE off and count combo out of range
2606 * -EINVAL off, count or buff address invalid
2607 * zero if count is zero
2608 * -EPERM adapter is offline
2609 * -ENOMEM failed to allocate memory for the mail box
2610 * -EAGAIN offset, state or mbox is NULL
2611 * count number of bytes transferred
2612 **/
dea31012005-04-17 16:05:31 -05002613static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08002614sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
2615 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05002616{
Tony Jonesee959b02008-02-22 00:13:36 +01002617 struct device *dev = container_of(kobj, struct device, kobj);
2618 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002619 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2620 struct lpfc_hba *phba = vport->phba;
2621 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05002622
2623 if ((count + off) > MAILBOX_CMD_SIZE)
2624 return -ERANGE;
2625
2626 if (off % 4 || count % 4 || (unsigned long)buf % 4)
2627 return -EINVAL;
2628
2629 if (count == 0)
2630 return 0;
2631
2632 if (off == 0) {
2633 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2634 if (!mbox)
2635 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05002636 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05002637 }
2638
James Smart2e0fef82007-06-17 19:56:36 -05002639 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002640
2641 if (off == 0) {
2642 if (phba->sysfs_mbox.mbox)
2643 mempool_free(mbox, phba->mbox_mem_pool);
2644 else
2645 phba->sysfs_mbox.mbox = mbox;
2646 phba->sysfs_mbox.state = SMBOX_WRITING;
2647 } else {
2648 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
2649 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05002650 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05002651 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002652 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04002653 return -EAGAIN;
dea31012005-04-17 16:05:31 -05002654 }
2655 }
2656
2657 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
2658 buf, count);
2659
2660 phba->sysfs_mbox.offset = off + count;
2661
James Smart2e0fef82007-06-17 19:56:36 -05002662 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002663
2664 return count;
2665}
2666
James Smarte59058c2008-08-24 21:49:00 -04002667/**
2668 * sysfs_mbox_read: Read method for reading information via mbox.
2669 * @kobj: kernel kobject that contains the kernel class device.
2670 * @bin_attr: kernel attributes passed to us.
2671 * @buf: contains the data to be read from sysfs mbox.
2672 * @off: offset into buffer to beginning of data.
2673 * @count: bytes to transfer.
2674 *
2675 * Description:
2676 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
2677 * Uses the sysfs mbox to receive data from to the adapter.
2678 *
2679 * Returns:
2680 * -ERANGE off greater than mailbox command size
2681 * -EINVAL off, count or buff address invalid
2682 * zero if off and count are zero
2683 * -EACCES adapter over temp
2684 * -EPERM garbage can value to catch a multitude of errors
2685 * -EAGAIN management IO not permitted, state or off error
2686 * -ETIME mailbox timeout
2687 * -ENODEV mailbox error
2688 * count number of bytes transferred
2689 **/
dea31012005-04-17 16:05:31 -05002690static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08002691sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2692 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05002693{
Tony Jonesee959b02008-02-22 00:13:36 +01002694 struct device *dev = container_of(kobj, struct device, kobj);
2695 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002696 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2697 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002698 int rc;
2699
James Smart1dcb58e2007-04-25 09:51:30 -04002700 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05002701 return -ERANGE;
2702
James Smart1dcb58e2007-04-25 09:51:30 -04002703 if ((count + off) > MAILBOX_CMD_SIZE)
2704 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05002705
2706 if (off % 4 || count % 4 || (unsigned long)buf % 4)
2707 return -EINVAL;
2708
2709 if (off && count == 0)
2710 return 0;
2711
James Smart2e0fef82007-06-17 19:56:36 -05002712 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002713
James Smart7af67052007-10-27 13:38:11 -04002714 if (phba->over_temp_state == HBA_OVER_TEMP) {
2715 sysfs_mbox_idle(phba);
2716 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05002717 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04002718 }
2719
dea31012005-04-17 16:05:31 -05002720 if (off == 0 &&
2721 phba->sysfs_mbox.state == SMBOX_WRITING &&
2722 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
2723
2724 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
2725 /* Offline only */
dea31012005-04-17 16:05:31 -05002726 case MBX_INIT_LINK:
2727 case MBX_DOWN_LINK:
2728 case MBX_CONFIG_LINK:
2729 case MBX_CONFIG_RING:
2730 case MBX_RESET_RING:
2731 case MBX_UNREG_LOGIN:
2732 case MBX_CLEAR_LA:
2733 case MBX_DUMP_CONTEXT:
2734 case MBX_RUN_DIAGS:
2735 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05002736 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05002737 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05002738 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05002739 printk(KERN_WARNING "mbox_read:Command 0x%x "
2740 "is illegal in on-line state\n",
2741 phba->sysfs_mbox.mbox->mb.mbxCommand);
2742 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002743 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002744 return -EPERM;
2745 }
James Smarta8adb832007-10-27 13:37:53 -04002746 case MBX_WRITE_NV:
2747 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05002748 case MBX_LOAD_SM:
2749 case MBX_READ_NV:
2750 case MBX_READ_CONFIG:
2751 case MBX_READ_RCONFIG:
2752 case MBX_READ_STATUS:
2753 case MBX_READ_XRI:
2754 case MBX_READ_REV:
2755 case MBX_READ_LNK_STAT:
2756 case MBX_DUMP_MEMORY:
2757 case MBX_DOWN_LOAD:
2758 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05002759 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05002760 case MBX_LOAD_AREA:
2761 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05002762 case MBX_BEACON:
2763 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05002764 case MBX_SET_VARIABLE:
2765 case MBX_WRITE_WWN:
dea31012005-04-17 16:05:31 -05002766 break;
2767 case MBX_READ_SPARM64:
2768 case MBX_READ_LA:
2769 case MBX_READ_LA64:
2770 case MBX_REG_LOGIN:
2771 case MBX_REG_LOGIN64:
2772 case MBX_CONFIG_PORT:
2773 case MBX_RUN_BIU_DIAG:
2774 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
2775 phba->sysfs_mbox.mbox->mb.mbxCommand);
2776 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002777 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002778 return -EPERM;
2779 default:
2780 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
2781 phba->sysfs_mbox.mbox->mb.mbxCommand);
2782 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002783 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002784 return -EPERM;
2785 }
2786
James Smart09372822008-01-11 01:52:54 -05002787 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05002788 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05002789 */
2790 if ((phba->pport->stopped) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002791 (phba->sysfs_mbox.mbox->mb.mbxCommand !=
2792 MBX_DUMP_MEMORY &&
2793 phba->sysfs_mbox.mbox->mb.mbxCommand !=
James Smart97eab632008-04-07 10:16:05 -04002794 MBX_RESTART &&
2795 phba->sysfs_mbox.mbox->mb.mbxCommand !=
2796 MBX_WRITE_VPARMS)) {
James Smart09372822008-01-11 01:52:54 -05002797 sysfs_mbox_idle(phba);
2798 spin_unlock_irq(&phba->hbalock);
2799 return -EPERM;
2800 }
2801
James Smart92d7f7b2007-06-17 19:56:38 -05002802 phba->sysfs_mbox.mbox->vport = vport;
2803
James Smart58da1ff2008-04-07 10:15:56 -04002804 /* Don't allow mailbox commands to be sent when blocked
2805 * or when in the middle of discovery
2806 */
James Smart495a7142008-06-14 22:52:59 -04002807 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04002808 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002809 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04002810 return -EAGAIN;
2811 }
2812
James Smart2e0fef82007-06-17 19:56:36 -05002813 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
dea31012005-04-17 16:05:31 -05002814 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
2815
James Smart2e0fef82007-06-17 19:56:36 -05002816 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002817 rc = lpfc_sli_issue_mbox (phba,
2818 phba->sysfs_mbox.mbox,
2819 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05002820 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002821
2822 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002823 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002824 rc = lpfc_sli_issue_mbox_wait (phba,
2825 phba->sysfs_mbox.mbox,
James Smarta309a6b2006-08-01 07:33:43 -04002826 lpfc_mbox_tmo_val(phba,
2827 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05002828 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002829 }
2830
2831 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04002832 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04002833 phba->sysfs_mbox.mbox = NULL;
2834 }
dea31012005-04-17 16:05:31 -05002835 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002836 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04002837 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05002838 }
2839 phba->sysfs_mbox.state = SMBOX_READING;
2840 }
2841 else if (phba->sysfs_mbox.offset != off ||
2842 phba->sysfs_mbox.state != SMBOX_READING) {
2843 printk(KERN_WARNING "mbox_read: Bad State\n");
2844 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002845 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04002846 return -EAGAIN;
dea31012005-04-17 16:05:31 -05002847 }
2848
2849 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
2850
2851 phba->sysfs_mbox.offset = off + count;
2852
James Smart1dcb58e2007-04-25 09:51:30 -04002853 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05002854 sysfs_mbox_idle(phba);
2855
James Smart2e0fef82007-06-17 19:56:36 -05002856 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002857
2858 return count;
2859}
2860
2861static struct bin_attribute sysfs_mbox_attr = {
2862 .attr = {
2863 .name = "mbox",
2864 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05002865 },
James Smart1dcb58e2007-04-25 09:51:30 -04002866 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05002867 .read = sysfs_mbox_read,
2868 .write = sysfs_mbox_write,
2869};
2870
James Smarte59058c2008-08-24 21:49:00 -04002871/**
2872 * lpfc_alloc_sysfs_attr: Creates the sysfs, ctlreg, menlo and mbox entries.
2873 * @vport: address of lpfc vport structure.
2874 *
2875 * Return codes:
2876 * zero on success
2877 * error return code from sysfs_create_bin_file()
2878 **/
dea31012005-04-17 16:05:31 -05002879int
James Smart2e0fef82007-06-17 19:56:36 -05002880lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002881{
James Smart2e0fef82007-06-17 19:56:36 -05002882 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002883 int error;
2884
Tony Jonesee959b02008-02-22 00:13:36 +01002885 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05002886 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05002887 if (error)
2888 goto out;
2889
Tony Jonesee959b02008-02-22 00:13:36 +01002890 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05002891 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05002892 if (error)
2893 goto out_remove_ctlreg_attr;
2894
2895 return 0;
2896out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01002897 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05002898out:
2899 return error;
2900}
2901
James Smarte59058c2008-08-24 21:49:00 -04002902/**
2903 * lpfc_free_sysfs_attr: Removes the sysfs, ctlreg, menlo and mbox entries.
2904 * @vport: address of lpfc vport structure.
2905 **/
dea31012005-04-17 16:05:31 -05002906void
James Smart2e0fef82007-06-17 19:56:36 -05002907lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002908{
James Smart2e0fef82007-06-17 19:56:36 -05002909 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002910
Tony Jonesee959b02008-02-22 00:13:36 +01002911 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
2912 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05002913}
2914
2915
2916/*
2917 * Dynamic FC Host Attributes Support
2918 */
2919
James Smarte59058c2008-08-24 21:49:00 -04002920/**
2921 * lpfc_get_host_port_id: Copy the vport DID into the scsi host port id.
2922 * @shost: kernel scsi host pointer.
2923 **/
dea31012005-04-17 16:05:31 -05002924static void
2925lpfc_get_host_port_id(struct Scsi_Host *shost)
2926{
James Smart2e0fef82007-06-17 19:56:36 -05002927 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2928
dea31012005-04-17 16:05:31 -05002929 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05002930 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05002931}
2932
James Smarte59058c2008-08-24 21:49:00 -04002933/**
2934 * lpfc_get_host_port_type: Set the value of the scsi host port type.
2935 * @shost: kernel scsi host pointer.
2936 **/
dea31012005-04-17 16:05:31 -05002937static void
2938lpfc_get_host_port_type(struct Scsi_Host *shost)
2939{
James Smart2e0fef82007-06-17 19:56:36 -05002940 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2941 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002942
2943 spin_lock_irq(shost->host_lock);
2944
James Smart92d7f7b2007-06-17 19:56:38 -05002945 if (vport->port_type == LPFC_NPIV_PORT) {
2946 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
2947 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05002948 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05002949 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05002950 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2951 else
2952 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
2953 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002954 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05002955 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2956 else
2957 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2958 }
2959 } else
2960 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2961
2962 spin_unlock_irq(shost->host_lock);
2963}
2964
James Smarte59058c2008-08-24 21:49:00 -04002965/**
2966 * lpfc_get_host_port_state: Set the value of the scsi host port state.
2967 * @shost: kernel scsi host pointer.
2968 **/
dea31012005-04-17 16:05:31 -05002969static void
2970lpfc_get_host_port_state(struct Scsi_Host *shost)
2971{
James Smart2e0fef82007-06-17 19:56:36 -05002972 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2973 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002974
2975 spin_lock_irq(shost->host_lock);
2976
James Smart2e0fef82007-06-17 19:56:36 -05002977 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05002978 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
2979 else {
James Smart2e0fef82007-06-17 19:56:36 -05002980 switch (phba->link_state) {
2981 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05002982 case LPFC_LINK_DOWN:
2983 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2984 break;
2985 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05002986 case LPFC_CLEAR_LA:
2987 case LPFC_HBA_READY:
2988 /* Links up, beyond this port_type reports state */
2989 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
2990 break;
2991 case LPFC_HBA_ERROR:
2992 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
2993 break;
2994 default:
2995 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
2996 break;
2997 }
2998 }
2999
3000 spin_unlock_irq(shost->host_lock);
3001}
3002
James Smarte59058c2008-08-24 21:49:00 -04003003/**
3004 * lpfc_get_host_speed: Set the value of the scsi host speed.
3005 * @shost: kernel scsi host pointer.
3006 **/
dea31012005-04-17 16:05:31 -05003007static void
3008lpfc_get_host_speed(struct Scsi_Host *shost)
3009{
James Smart2e0fef82007-06-17 19:56:36 -05003010 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3011 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003012
3013 spin_lock_irq(shost->host_lock);
3014
James Smart2e0fef82007-06-17 19:56:36 -05003015 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05003016 switch(phba->fc_linkspeed) {
3017 case LA_1GHZ_LINK:
3018 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
3019 break;
3020 case LA_2GHZ_LINK:
3021 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
3022 break;
3023 case LA_4GHZ_LINK:
3024 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
3025 break;
James Smartb87eab32007-04-25 09:53:28 -04003026 case LA_8GHZ_LINK:
3027 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
3028 break;
dea31012005-04-17 16:05:31 -05003029 default:
3030 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3031 break;
3032 }
James Smart09372822008-01-11 01:52:54 -05003033 } else
3034 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05003035
3036 spin_unlock_irq(shost->host_lock);
3037}
3038
James Smarte59058c2008-08-24 21:49:00 -04003039/**
3040 * lpfc_get_host_fabric_name: Set the value of the scsi host fabric name.
3041 * @shost: kernel scsi host pointer.
3042 **/
dea31012005-04-17 16:05:31 -05003043static void
3044lpfc_get_host_fabric_name (struct Scsi_Host *shost)
3045{
James Smart2e0fef82007-06-17 19:56:36 -05003046 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3047 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003048 u64 node_name;
dea31012005-04-17 16:05:31 -05003049
3050 spin_lock_irq(shost->host_lock);
3051
James Smart2e0fef82007-06-17 19:56:36 -05003052 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05003053 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05003054 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07003055 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05003056 else
3057 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05003058 node_name = 0;
dea31012005-04-17 16:05:31 -05003059
3060 spin_unlock_irq(shost->host_lock);
3061
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07003062 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05003063}
3064
James Smarte59058c2008-08-24 21:49:00 -04003065/**
3066 * lpfc_get_stats: Return statistical information about the adapter.
3067 * @shost: kernel scsi host pointer.
3068 *
3069 * Notes:
3070 * NULL on error for link down, no mbox pool, sli2 active,
3071 * management not allowed, memory allocation error, or mbox error.
3072 *
3073 * Returns:
3074 * NULL for error
3075 * address of the adapter host statistics
3076 **/
dea31012005-04-17 16:05:31 -05003077static struct fc_host_statistics *
3078lpfc_get_stats(struct Scsi_Host *shost)
3079{
James Smart2e0fef82007-06-17 19:56:36 -05003080 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3081 struct lpfc_hba *phba = vport->phba;
3082 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003083 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04003084 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05003085 LPFC_MBOXQ_t *pmboxq;
3086 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04003087 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003088 int rc = 0;
dea31012005-04-17 16:05:31 -05003089
James Smart92d7f7b2007-06-17 19:56:38 -05003090 /*
3091 * prevent udev from issuing mailbox commands until the port is
3092 * configured.
3093 */
James Smart2e0fef82007-06-17 19:56:36 -05003094 if (phba->link_state < LPFC_LINK_DOWN ||
3095 !phba->mbox_mem_pool ||
3096 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003097 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003098
3099 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04003100 return NULL;
3101
dea31012005-04-17 16:05:31 -05003102 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3103 if (!pmboxq)
3104 return NULL;
3105 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3106
3107 pmb = &pmboxq->mb;
3108 pmb->mbxCommand = MBX_READ_STATUS;
3109 pmb->mbxOwner = OWN_HOST;
3110 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003111 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05003112
James Smart2e0fef82007-06-17 19:56:36 -05003113 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003114 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05003115 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003116 else
dea31012005-04-17 16:05:31 -05003117 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3118
3119 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003120 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003121 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003122 return NULL;
3123 }
3124
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04003125 memset(hs, 0, sizeof (struct fc_host_statistics));
3126
dea31012005-04-17 16:05:31 -05003127 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
3128 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
3129 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
3130 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
3131
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003132 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05003133 pmb->mbxCommand = MBX_READ_LNK_STAT;
3134 pmb->mbxOwner = OWN_HOST;
3135 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003136 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05003137
James Smart2e0fef82007-06-17 19:56:36 -05003138 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003139 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05003140 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04003141 else
dea31012005-04-17 16:05:31 -05003142 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3143
3144 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003145 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05003146 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003147 return NULL;
3148 }
3149
3150 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3151 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3152 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3153 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3154 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3155 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3156 hs->error_frames = pmb->un.varRdLnk.crcCnt;
3157
James Smart64ba8812006-08-02 15:24:34 -04003158 hs->link_failure_count -= lso->link_failure_count;
3159 hs->loss_of_sync_count -= lso->loss_of_sync_count;
3160 hs->loss_of_signal_count -= lso->loss_of_signal_count;
3161 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
3162 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
3163 hs->invalid_crc_count -= lso->invalid_crc_count;
3164 hs->error_frames -= lso->error_frames;
3165
dea31012005-04-17 16:05:31 -05003166 if (phba->fc_topology == TOPOLOGY_LOOP) {
3167 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04003168 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05003169 hs->nos_count = -1;
3170 } else {
3171 hs->lip_count = -1;
3172 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04003173 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05003174 }
3175
3176 hs->dumped_frames = -1;
3177
James Smart64ba8812006-08-02 15:24:34 -04003178 seconds = get_seconds();
3179 if (seconds < psli->stats_start)
3180 hs->seconds_since_last_reset = seconds +
3181 ((unsigned long)-1 - psli->stats_start);
3182 else
3183 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05003184
James Smart1dcb58e2007-04-25 09:51:30 -04003185 mempool_free(pmboxq, phba->mbox_mem_pool);
3186
dea31012005-04-17 16:05:31 -05003187 return hs;
3188}
3189
James Smarte59058c2008-08-24 21:49:00 -04003190/**
3191 * lpfc_reset_stats: Copy the adapter link stats information.
3192 * @shost: kernel scsi host pointer.
3193 **/
James Smart64ba8812006-08-02 15:24:34 -04003194static void
3195lpfc_reset_stats(struct Scsi_Host *shost)
3196{
James Smart2e0fef82007-06-17 19:56:36 -05003197 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3198 struct lpfc_hba *phba = vport->phba;
3199 struct lpfc_sli *psli = &phba->sli;
3200 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04003201 LPFC_MBOXQ_t *pmboxq;
3202 MAILBOX_t *pmb;
3203 int rc = 0;
3204
James Smart2e0fef82007-06-17 19:56:36 -05003205 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04003206 return;
3207
James Smart64ba8812006-08-02 15:24:34 -04003208 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3209 if (!pmboxq)
3210 return;
3211 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3212
3213 pmb = &pmboxq->mb;
3214 pmb->mbxCommand = MBX_READ_STATUS;
3215 pmb->mbxOwner = OWN_HOST;
3216 pmb->un.varWords[0] = 0x1; /* reset request */
3217 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003218 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04003219
James Smart2e0fef82007-06-17 19:56:36 -05003220 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04003221 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
3222 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3223 else
3224 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3225
3226 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003227 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04003228 mempool_free(pmboxq, phba->mbox_mem_pool);
3229 return;
3230 }
3231
3232 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3233 pmb->mbxCommand = MBX_READ_LNK_STAT;
3234 pmb->mbxOwner = OWN_HOST;
3235 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003236 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04003237
James Smart2e0fef82007-06-17 19:56:36 -05003238 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04003239 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
3240 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3241 else
3242 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3243
3244 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05003245 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04003246 mempool_free( pmboxq, phba->mbox_mem_pool);
3247 return;
3248 }
3249
3250 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3251 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3252 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3253 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3254 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3255 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3256 lso->error_frames = pmb->un.varRdLnk.crcCnt;
3257 lso->link_events = (phba->fc_eventTag >> 1);
3258
3259 psli->stats_start = get_seconds();
3260
James Smart1dcb58e2007-04-25 09:51:30 -04003261 mempool_free(pmboxq, phba->mbox_mem_pool);
3262
James Smart64ba8812006-08-02 15:24:34 -04003263 return;
3264}
dea31012005-04-17 16:05:31 -05003265
3266/*
3267 * The LPFC driver treats linkdown handling as target loss events so there
3268 * are no sysfs handlers for link_down_tmo.
3269 */
James Smart685f0bf2007-04-25 09:53:08 -04003270
James Smarte59058c2008-08-24 21:49:00 -04003271/**
3272 * lpfc_get_node_by_target: Return the nodelist for a target.
3273 * @starget: kernel scsi target pointer.
3274 *
3275 * Returns:
3276 * address of the node list if found
3277 * NULL target not found
3278 **/
James Smart685f0bf2007-04-25 09:53:08 -04003279static struct lpfc_nodelist *
3280lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05003281{
James Smart2e0fef82007-06-17 19:56:36 -05003282 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3283 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04003284 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003285
3286 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003287 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05003288 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003289 if (NLP_CHK_NODE_ACT(ndlp) &&
3290 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04003291 starget->id == ndlp->nlp_sid) {
3292 spin_unlock_irq(shost->host_lock);
3293 return ndlp;
dea31012005-04-17 16:05:31 -05003294 }
3295 }
3296 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003297 return NULL;
3298}
dea31012005-04-17 16:05:31 -05003299
James Smarte59058c2008-08-24 21:49:00 -04003300/**
3301 * lpfc_get_starget_port_id: Set the target port id to the ndlp DID or -1.
3302 * @starget: kernel scsi target pointer.
3303 **/
James Smart685f0bf2007-04-25 09:53:08 -04003304static void
3305lpfc_get_starget_port_id(struct scsi_target *starget)
3306{
3307 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
3308
3309 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05003310}
3311
James Smarte59058c2008-08-24 21:49:00 -04003312/**
3313 * lpfc_get_starget_node_name: Set the target node name.
3314 * @starget: kernel scsi target pointer.
3315 *
3316 * Description: Set the target node name to the ndlp node name wwn or zero.
3317 **/
dea31012005-04-17 16:05:31 -05003318static void
3319lpfc_get_starget_node_name(struct scsi_target *starget)
3320{
James Smart685f0bf2007-04-25 09:53:08 -04003321 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05003322
James Smart685f0bf2007-04-25 09:53:08 -04003323 fc_starget_node_name(starget) =
3324 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05003325}
3326
James Smarte59058c2008-08-24 21:49:00 -04003327/**
3328 * lpfc_get_starget_port_name: Set the target port name.
3329 * @starget: kernel scsi target pointer.
3330 *
3331 * Description: set the target port name to the ndlp port name wwn or zero.
3332 **/
dea31012005-04-17 16:05:31 -05003333static void
3334lpfc_get_starget_port_name(struct scsi_target *starget)
3335{
James Smart685f0bf2007-04-25 09:53:08 -04003336 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05003337
James Smart685f0bf2007-04-25 09:53:08 -04003338 fc_starget_port_name(starget) =
3339 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05003340}
3341
James Smarte59058c2008-08-24 21:49:00 -04003342/**
3343 * lpfc_set_rport_loss_tmo: Set the rport dev loss tmo.
3344 * @rport: fc rport address.
3345 * @timeout: new value for dev loss tmo.
3346 *
3347 * Description:
3348 * If timeout is non zero set the dev_loss_tmo to timeout, else set
3349 * dev_loss_tmo to one.
3350 **/
dea31012005-04-17 16:05:31 -05003351static void
dea31012005-04-17 16:05:31 -05003352lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
3353{
dea31012005-04-17 16:05:31 -05003354 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04003355 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05003356 else
James Smartc01f3202006-08-18 17:47:08 -04003357 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05003358}
3359
James Smarte59058c2008-08-24 21:49:00 -04003360/**
3361 * lpfc_rport_show_function: Return rport target information.
3362 *
3363 * Description:
3364 * Macro that uses field to generate a function with the name lpfc_show_rport_
3365 *
3366 * lpfc_show_rport_##field: returns the bytes formatted in buf
3367 * @cdev: class converted to an fc_rport.
3368 * @buf: on return contains the target_field or zero.
3369 *
3370 * Returns: size of formatted string.
3371 **/
dea31012005-04-17 16:05:31 -05003372#define lpfc_rport_show_function(field, format_string, sz, cast) \
3373static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01003374lpfc_show_rport_##field (struct device *dev, \
3375 struct device_attribute *attr, \
3376 char *buf) \
dea31012005-04-17 16:05:31 -05003377{ \
Tony Jonesee959b02008-02-22 00:13:36 +01003378 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05003379 struct lpfc_rport_data *rdata = rport->hostdata; \
3380 return snprintf(buf, sz, format_string, \
3381 (rdata->target) ? cast rdata->target->field : 0); \
3382}
3383
3384#define lpfc_rport_rd_attr(field, format_string, sz) \
3385 lpfc_rport_show_function(field, format_string, sz, ) \
3386static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
3387
3388
3389struct fc_function_template lpfc_transport_functions = {
3390 /* fixed attributes the driver supports */
3391 .show_host_node_name = 1,
3392 .show_host_port_name = 1,
3393 .show_host_supported_classes = 1,
3394 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05003395 .show_host_supported_speeds = 1,
3396 .show_host_maxframe_size = 1,
3397
3398 /* dynamic attributes the driver supports */
3399 .get_host_port_id = lpfc_get_host_port_id,
3400 .show_host_port_id = 1,
3401
3402 .get_host_port_type = lpfc_get_host_port_type,
3403 .show_host_port_type = 1,
3404
3405 .get_host_port_state = lpfc_get_host_port_state,
3406 .show_host_port_state = 1,
3407
3408 /* active_fc4s is shown but doesn't change (thus no get function) */
3409 .show_host_active_fc4s = 1,
3410
3411 .get_host_speed = lpfc_get_host_speed,
3412 .show_host_speed = 1,
3413
3414 .get_host_fabric_name = lpfc_get_host_fabric_name,
3415 .show_host_fabric_name = 1,
3416
3417 /*
3418 * The LPFC driver treats linkdown handling as target loss events
3419 * so there are no sysfs handlers for link_down_tmo.
3420 */
3421
3422 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04003423 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05003424
3425 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
3426 .show_rport_maxframe_size = 1,
3427 .show_rport_supported_classes = 1,
3428
dea31012005-04-17 16:05:31 -05003429 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
3430 .show_rport_dev_loss_tmo = 1,
3431
3432 .get_starget_port_id = lpfc_get_starget_port_id,
3433 .show_starget_port_id = 1,
3434
3435 .get_starget_node_name = lpfc_get_starget_node_name,
3436 .show_starget_node_name = 1,
3437
3438 .get_starget_port_name = lpfc_get_starget_port_name,
3439 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07003440
3441 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04003442 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
3443 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05003444
James Smart92d7f7b2007-06-17 19:56:38 -05003445 .dd_fcvport_size = sizeof(struct lpfc_vport *),
3446};
3447
James Smart98c9ea52007-10-27 13:37:33 -04003448struct fc_function_template lpfc_vport_transport_functions = {
3449 /* fixed attributes the driver supports */
3450 .show_host_node_name = 1,
3451 .show_host_port_name = 1,
3452 .show_host_supported_classes = 1,
3453 .show_host_supported_fc4s = 1,
3454 .show_host_supported_speeds = 1,
3455 .show_host_maxframe_size = 1,
3456
3457 /* dynamic attributes the driver supports */
3458 .get_host_port_id = lpfc_get_host_port_id,
3459 .show_host_port_id = 1,
3460
3461 .get_host_port_type = lpfc_get_host_port_type,
3462 .show_host_port_type = 1,
3463
3464 .get_host_port_state = lpfc_get_host_port_state,
3465 .show_host_port_state = 1,
3466
3467 /* active_fc4s is shown but doesn't change (thus no get function) */
3468 .show_host_active_fc4s = 1,
3469
3470 .get_host_speed = lpfc_get_host_speed,
3471 .show_host_speed = 1,
3472
3473 .get_host_fabric_name = lpfc_get_host_fabric_name,
3474 .show_host_fabric_name = 1,
3475
3476 /*
3477 * The LPFC driver treats linkdown handling as target loss events
3478 * so there are no sysfs handlers for link_down_tmo.
3479 */
3480
3481 .get_fc_host_stats = lpfc_get_stats,
3482 .reset_fc_host_stats = lpfc_reset_stats,
3483
3484 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
3485 .show_rport_maxframe_size = 1,
3486 .show_rport_supported_classes = 1,
3487
3488 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
3489 .show_rport_dev_loss_tmo = 1,
3490
3491 .get_starget_port_id = lpfc_get_starget_port_id,
3492 .show_starget_port_id = 1,
3493
3494 .get_starget_node_name = lpfc_get_starget_node_name,
3495 .show_starget_node_name = 1,
3496
3497 .get_starget_port_name = lpfc_get_starget_port_name,
3498 .show_starget_port_name = 1,
3499
3500 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
3501 .terminate_rport_io = lpfc_terminate_rport_io,
3502
3503 .vport_disable = lpfc_vport_disable,
3504};
3505
James Smarte59058c2008-08-24 21:49:00 -04003506/**
3507 * lpfc_get_cfgparam: Used during probe_one to init the adapter structure.
3508 * @phba: lpfc_hba pointer.
3509 **/
dea31012005-04-17 16:05:31 -05003510void
3511lpfc_get_cfgparam(struct lpfc_hba *phba)
3512{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04003513 lpfc_cr_delay_init(phba, lpfc_cr_delay);
3514 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05003515 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05003516 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
3517 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04003518 lpfc_ack0_init(phba, lpfc_ack0);
3519 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04003520 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003521 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04003522 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05003523 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart13815c82008-01-11 01:52:48 -05003524 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
3525 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003526 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05003527 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04003528 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05003529 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
3530 /* Also reinitialize the host templates with new values. */
3531 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
3532 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
dea31012005-04-17 16:05:31 -05003533 /*
3534 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
James Smart83108bd2008-01-11 01:53:09 -05003535 * used to create the sg_dma_buf_pool must be dynamically calculated.
3536 * 2 segments are added since the IOCB needs a command and response bde.
dea31012005-04-17 16:05:31 -05003537 */
3538 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
3539 sizeof(struct fcp_rsp) +
James Smart83108bd2008-01-11 01:53:09 -05003540 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
James Smart7054a602007-04-25 09:52:34 -04003541 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04003542 return;
3543}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003544
James Smarte59058c2008-08-24 21:49:00 -04003545/**
3546 * lpfc_get_vport_cfgparam: Used during port create, init the vport structure.
3547 * @vport: lpfc_vport pointer.
3548 **/
James Smart3de2a652007-08-02 11:09:59 -04003549void
3550lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
3551{
James Smarte8b62012007-08-02 11:10:09 -04003552 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04003553 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
3554 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
3555 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
3556 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
3557 lpfc_restrict_login_init(vport, lpfc_restrict_login);
3558 lpfc_fcp_class_init(vport, lpfc_fcp_class);
3559 lpfc_use_adisc_init(vport, lpfc_use_adisc);
3560 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
3561 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
3562 lpfc_max_luns_init(vport, lpfc_max_luns);
3563 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04003564 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05003565 return;
3566}