[SCSI] lpfc 8.3.19: Added support for ELS RRQ command
[deliverable/linux.git] / drivers / scsi / lpfc / lpfc_attr.c
CommitLineData
dea3101e 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
c44ce173 3 * Fibre Channel Host Bus Adapters. *
d8e93df1 4 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
c44ce173 5 * EMULEX and SLI are trademarks of Emulex. *
dea3101e 6 * www.emulex.com *
c44ce173 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea3101e 8 * *
9 * This program is free software; you can redistribute it and/or *
c44ce173
JSEC
10 * 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. *
dea3101e 20 *******************************************************************/
21
dea3101e 22#include <linux/ctype.h>
46fa311e 23#include <linux/delay.h>
dea3101e 24#include <linux/pci.h>
25#include <linux/interrupt.h>
0d878419 26#include <linux/aer.h>
5a0e3ad6 27#include <linux/gfp.h>
ecc30990 28#include <linux/kernel.h>
dea3101e 29
91886523 30#include <scsi/scsi.h>
dea3101e 31#include <scsi/scsi_device.h>
32#include <scsi/scsi_host.h>
33#include <scsi/scsi_tcq.h>
34#include <scsi/scsi_transport_fc.h>
6a9c52cf 35#include <scsi/fc/fc_fs.h>
dea3101e 36
da0436e9 37#include "lpfc_hw4.h"
dea3101e 38#include "lpfc_hw.h"
39#include "lpfc_sli.h"
da0436e9 40#include "lpfc_sli4.h"
ea2151b4 41#include "lpfc_nl.h"
dea3101e 42#include "lpfc_disc.h"
43#include "lpfc_scsi.h"
44#include "lpfc.h"
45#include "lpfc_logmsg.h"
46#include "lpfc_version.h"
47#include "lpfc_compat.h"
48#include "lpfc_crtn.h"
92d7f7b0 49#include "lpfc_vport.h"
dea3101e 50
c01f3208
JS
51#define LPFC_DEF_DEVLOSS_TMO 30
52#define LPFC_MIN_DEVLOSS_TMO 1
53#define LPFC_MAX_DEVLOSS_TMO 255
dea3101e 54
e59058c4 55/**
3621a710 56 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
e59058c4
JS
57 * @incr: integer to convert.
58 * @hdw: ascii string holding converted integer plus a string terminator.
59 *
60 * Description:
61 * JEDEC Joint Electron Device Engineering Council.
62 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
63 * character string. The string is then terminated with a NULL in byte 9.
64 * Hex 0-9 becomes ascii '0' to '9'.
65 * Hex a-f becomes ascii '=' to 'B' capital B.
66 *
67 * Notes:
68 * Coded for 32 bit integers only.
69 **/
dea3101e 70static void
71lpfc_jedec_to_ascii(int incr, char hdw[])
72{
73 int i, j;
74 for (i = 0; i < 8; i++) {
75 j = (incr & 0xf);
76 if (j <= 9)
77 hdw[7 - i] = 0x30 + j;
78 else
79 hdw[7 - i] = 0x61 + j - 10;
80 incr = (incr >> 4);
81 }
82 hdw[8] = 0;
83 return;
84}
85
e59058c4 86/**
3621a710 87 * lpfc_drvr_version_show - Return the Emulex driver string with version number
e59058c4
JS
88 * @dev: class unused variable.
89 * @attr: device attribute, not used.
90 * @buf: on return contains the module description text.
91 *
92 * Returns: size of formatted string.
93 **/
dea3101e 94static ssize_t
ee959b00
TJ
95lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
96 char *buf)
dea3101e 97{
98 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
99}
100
45ed1190
JS
101/**
102 * lpfc_enable_fip_show - Return the fip mode of the HBA
103 * @dev: class unused variable.
104 * @attr: device attribute, not used.
105 * @buf: on return contains the module description text.
106 *
107 * Returns: size of formatted string.
108 **/
109static ssize_t
110lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
111 char *buf)
112{
113 struct Scsi_Host *shost = class_to_shost(dev);
114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
115 struct lpfc_hba *phba = vport->phba;
116
117 if (phba->hba_flag & HBA_FIP_SUPPORT)
118 return snprintf(buf, PAGE_SIZE, "1\n");
119 else
120 return snprintf(buf, PAGE_SIZE, "0\n");
121}
122
81301a9b
JS
123static ssize_t
124lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
125 char *buf)
126{
127 struct Scsi_Host *shost = class_to_shost(dev);
128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
129 struct lpfc_hba *phba = vport->phba;
130
131 if (phba->cfg_enable_bg)
132 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
133 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
134 else
135 return snprintf(buf, PAGE_SIZE,
136 "BlockGuard Not Supported\n");
137 else
138 return snprintf(buf, PAGE_SIZE,
139 "BlockGuard Disabled\n");
140}
141
142static ssize_t
143lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
144 char *buf)
145{
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
148 struct lpfc_hba *phba = vport->phba;
149
87b5c328
JS
150 return snprintf(buf, PAGE_SIZE, "%llu\n",
151 (unsigned long long)phba->bg_guard_err_cnt);
81301a9b
JS
152}
153
154static ssize_t
155lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
156 char *buf)
157{
158 struct Scsi_Host *shost = class_to_shost(dev);
159 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
160 struct lpfc_hba *phba = vport->phba;
161
87b5c328
JS
162 return snprintf(buf, PAGE_SIZE, "%llu\n",
163 (unsigned long long)phba->bg_apptag_err_cnt);
81301a9b
JS
164}
165
166static ssize_t
167lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
168 char *buf)
169{
170 struct Scsi_Host *shost = class_to_shost(dev);
171 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
172 struct lpfc_hba *phba = vport->phba;
173
87b5c328
JS
174 return snprintf(buf, PAGE_SIZE, "%llu\n",
175 (unsigned long long)phba->bg_reftag_err_cnt);
81301a9b
JS
176}
177
e59058c4 178/**
3621a710 179 * lpfc_info_show - Return some pci info about the host in ascii
e59058c4
JS
180 * @dev: class converted to a Scsi_host structure.
181 * @attr: device attribute, not used.
182 * @buf: on return contains the formatted text from lpfc_info().
183 *
184 * Returns: size of formatted string.
185 **/
dea3101e 186static ssize_t
ee959b00
TJ
187lpfc_info_show(struct device *dev, struct device_attribute *attr,
188 char *buf)
dea3101e 189{
ee959b00 190 struct Scsi_Host *host = class_to_shost(dev);
2e0fef85 191
dea3101e 192 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
193}
194
e59058c4 195/**
3621a710 196 * lpfc_serialnum_show - Return the hba serial number in ascii
e59058c4
JS
197 * @dev: class converted to a Scsi_host structure.
198 * @attr: device attribute, not used.
199 * @buf: on return contains the formatted text serial number.
200 *
201 * Returns: size of formatted string.
202 **/
dea3101e 203static ssize_t
ee959b00
TJ
204lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
205 char *buf)
dea3101e 206{
ee959b00 207 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
208 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
209 struct lpfc_hba *phba = vport->phba;
210
dea3101e 211 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
212}
213
e59058c4 214/**
3621a710 215 * lpfc_temp_sensor_show - Return the temperature sensor level
e59058c4
JS
216 * @dev: class converted to a Scsi_host structure.
217 * @attr: device attribute, not used.
218 * @buf: on return contains the formatted support level.
219 *
220 * Description:
221 * Returns a number indicating the temperature sensor level currently
222 * supported, zero or one in ascii.
223 *
224 * Returns: size of formatted string.
225 **/
57127f15 226static ssize_t
ee959b00
TJ
227lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
228 char *buf)
57127f15 229{
ee959b00 230 struct Scsi_Host *shost = class_to_shost(dev);
57127f15
JS
231 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
232 struct lpfc_hba *phba = vport->phba;
233 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
234}
235
e59058c4 236/**
3621a710 237 * lpfc_modeldesc_show - Return the model description of the hba
e59058c4
JS
238 * @dev: class converted to a Scsi_host structure.
239 * @attr: device attribute, not used.
240 * @buf: on return contains the scsi vpd model description.
241 *
242 * Returns: size of formatted string.
243 **/
dea3101e 244static ssize_t
ee959b00
TJ
245lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
246 char *buf)
dea3101e 247{
ee959b00 248 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
249 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
250 struct lpfc_hba *phba = vport->phba;
251
dea3101e 252 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
253}
254
e59058c4 255/**
3621a710 256 * lpfc_modelname_show - Return the model name of the hba
e59058c4
JS
257 * @dev: class converted to a Scsi_host structure.
258 * @attr: device attribute, not used.
259 * @buf: on return contains the scsi vpd model name.
260 *
261 * Returns: size of formatted string.
262 **/
dea3101e 263static ssize_t
ee959b00
TJ
264lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
265 char *buf)
dea3101e 266{
ee959b00 267 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
268 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
269 struct lpfc_hba *phba = vport->phba;
270
dea3101e 271 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
272}
273
e59058c4 274/**
3621a710 275 * lpfc_programtype_show - Return the program type of the hba
e59058c4
JS
276 * @dev: class converted to a Scsi_host structure.
277 * @attr: device attribute, not used.
278 * @buf: on return contains the scsi vpd program type.
279 *
280 * Returns: size of formatted string.
281 **/
dea3101e 282static ssize_t
ee959b00
TJ
283lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
284 char *buf)
dea3101e 285{
ee959b00 286 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
287 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
288 struct lpfc_hba *phba = vport->phba;
289
dea3101e 290 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
291}
292
84774a4d 293/**
3621a710 294 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
84774a4d
JS
295 * @dev: class converted to a Scsi_host structure.
296 * @attr: device attribute, not used.
297 * @buf: on return contains the Menlo Maintenance sli flag.
298 *
299 * Returns: size of formatted string.
300 **/
301static ssize_t
302lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
303{
304 struct Scsi_Host *shost = class_to_shost(dev);
305 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
306 struct lpfc_hba *phba = vport->phba;
307
308 return snprintf(buf, PAGE_SIZE, "%d\n",
309 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
310}
311
e59058c4 312/**
3621a710 313 * lpfc_vportnum_show - Return the port number in ascii of the hba
e59058c4
JS
314 * @dev: class converted to a Scsi_host structure.
315 * @attr: device attribute, not used.
316 * @buf: on return contains scsi vpd program type.
317 *
318 * Returns: size of formatted string.
319 **/
dea3101e 320static ssize_t
ee959b00
TJ
321lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
322 char *buf)
dea3101e 323{
ee959b00 324 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
325 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
326 struct lpfc_hba *phba = vport->phba;
327
dea3101e 328 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
329}
330
e59058c4 331/**
3621a710 332 * lpfc_fwrev_show - Return the firmware rev running in the hba
e59058c4
JS
333 * @dev: class converted to a Scsi_host structure.
334 * @attr: device attribute, not used.
335 * @buf: on return contains the scsi vpd program type.
336 *
337 * Returns: size of formatted string.
338 **/
dea3101e 339static ssize_t
ee959b00
TJ
340lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
341 char *buf)
dea3101e 342{
ee959b00 343 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
345 struct lpfc_hba *phba = vport->phba;
dea3101e 346 char fwrev[32];
2e0fef85 347
dea3101e 348 lpfc_decode_firmware_rev(phba, fwrev, 1);
92d7f7b0 349 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea3101e 350}
351
e59058c4 352/**
3621a710 353 * lpfc_hdw_show - Return the jedec information about the hba
e59058c4
JS
354 * @dev: class converted to a Scsi_host structure.
355 * @attr: device attribute, not used.
356 * @buf: on return contains the scsi vpd program type.
357 *
358 * Returns: size of formatted string.
359 **/
dea3101e 360static ssize_t
ee959b00 361lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea3101e 362{
363 char hdw[9];
ee959b00 364 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
366 struct lpfc_hba *phba = vport->phba;
dea3101e 367 lpfc_vpd_t *vp = &phba->vpd;
2e0fef85 368
dea3101e 369 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
370 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
371}
e59058c4
JS
372
373/**
3621a710 374 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
e59058c4
JS
375 * @dev: class converted to a Scsi_host structure.
376 * @attr: device attribute, not used.
377 * @buf: on return contains the ROM and FCode ascii strings.
378 *
379 * Returns: size of formatted string.
380 **/
dea3101e 381static ssize_t
ee959b00
TJ
382lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
383 char *buf)
dea3101e 384{
ee959b00 385 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
388
dea3101e 389 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
390}
e59058c4
JS
391
392/**
3621a710 393 * lpfc_state_show - Return the link state of the port
e59058c4
JS
394 * @dev: class converted to a Scsi_host structure.
395 * @attr: device attribute, not used.
396 * @buf: on return contains text describing the state of the link.
397 *
398 * Notes:
399 * The switch statement has no default so zero will be returned.
400 *
401 * Returns: size of formatted string.
402 **/
dea3101e 403static ssize_t
bbd1ae41
HR
404lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
405 char *buf)
dea3101e 406{
ee959b00 407 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
408 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
409 struct lpfc_hba *phba = vport->phba;
410 int len = 0;
411
412 switch (phba->link_state) {
413 case LPFC_LINK_UNKNOWN:
41415862 414 case LPFC_WARM_START:
dea3101e 415 case LPFC_INIT_START:
416 case LPFC_INIT_MBX_CMDS:
417 case LPFC_LINK_DOWN:
2e0fef85 418 case LPFC_HBA_ERROR:
a0c87cbd
JS
419 if (phba->hba_flag & LINK_DISABLED)
420 len += snprintf(buf + len, PAGE_SIZE-len,
421 "Link Down - User disabled\n");
422 else
423 len += snprintf(buf + len, PAGE_SIZE-len,
424 "Link Down\n");
dea3101e 425 break;
426 case LPFC_LINK_UP:
dea3101e 427 case LPFC_CLEAR_LA:
dea3101e 428 case LPFC_HBA_READY:
a8adb832 429 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
2e0fef85
JS
430
431 switch (vport->port_state) {
2e0fef85
JS
432 case LPFC_LOCAL_CFG_LINK:
433 len += snprintf(buf + len, PAGE_SIZE-len,
92d7f7b0 434 "Configuring Link\n");
2e0fef85 435 break;
92d7f7b0 436 case LPFC_FDISC:
2e0fef85
JS
437 case LPFC_FLOGI:
438 case LPFC_FABRIC_CFG_LINK:
439 case LPFC_NS_REG:
440 case LPFC_NS_QRY:
441 case LPFC_BUILD_DISC_LIST:
442 case LPFC_DISC_AUTH:
443 len += snprintf(buf + len, PAGE_SIZE - len,
444 "Discovery\n");
445 break;
446 case LPFC_VPORT_READY:
447 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
448 break;
449
92d7f7b0
JS
450 case LPFC_VPORT_FAILED:
451 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
452 break;
453
454 case LPFC_VPORT_UNKNOWN:
2e0fef85
JS
455 len += snprintf(buf + len, PAGE_SIZE - len,
456 "Unknown\n");
457 break;
458 }
84774a4d
JS
459 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
460 len += snprintf(buf + len, PAGE_SIZE-len,
461 " Menlo Maint Mode\n");
76a95d75 462 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2e0fef85 463 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea3101e 464 len += snprintf(buf + len, PAGE_SIZE-len,
465 " Public Loop\n");
466 else
467 len += snprintf(buf + len, PAGE_SIZE-len,
468 " Private Loop\n");
469 } else {
2e0fef85 470 if (vport->fc_flag & FC_FABRIC)
dea3101e 471 len += snprintf(buf + len, PAGE_SIZE-len,
472 " Fabric\n");
473 else
474 len += snprintf(buf + len, PAGE_SIZE-len,
475 " Point-2-Point\n");
476 }
477 }
2e0fef85 478
dea3101e 479 return len;
480}
481
84d1b006
JS
482/**
483 * lpfc_link_state_store - Transition the link_state on an HBA port
484 * @dev: class device that is converted into a Scsi_host.
485 * @attr: device attribute, not used.
486 * @buf: one or more lpfc_polling_flags values.
487 * @count: not used.
488 *
489 * Returns:
490 * -EINVAL if the buffer is not "up" or "down"
491 * return from link state change function if non-zero
492 * length of the buf on success
493 **/
494static ssize_t
495lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
496 const char *buf, size_t count)
497{
498 struct Scsi_Host *shost = class_to_shost(dev);
499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
500 struct lpfc_hba *phba = vport->phba;
501
502 int status = -EINVAL;
503
504 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
505 (phba->link_state == LPFC_LINK_DOWN))
6e7288d9 506 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
84d1b006
JS
507 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
508 (phba->link_state >= LPFC_LINK_UP))
6e7288d9 509 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
84d1b006
JS
510
511 if (status == 0)
512 return strlen(buf);
513 else
514 return status;
515}
516
e59058c4 517/**
3621a710 518 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
e59058c4
JS
519 * @dev: class device that is converted into a Scsi_host.
520 * @attr: device attribute, not used.
521 * @buf: on return contains the sum of fc mapped and unmapped.
522 *
523 * Description:
524 * Returns the ascii text number of the sum of the fc mapped and unmapped
525 * vport counts.
526 *
527 * Returns: size of formatted string.
528 **/
dea3101e 529static ssize_t
ee959b00
TJ
530lpfc_num_discovered_ports_show(struct device *dev,
531 struct device_attribute *attr, char *buf)
dea3101e 532{
ee959b00 533 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
535
536 return snprintf(buf, PAGE_SIZE, "%d\n",
537 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea3101e 538}
539
e59058c4 540/**
3621a710 541 * lpfc_issue_lip - Misnomer, name carried over from long ago
e59058c4
JS
542 * @shost: Scsi_Host pointer.
543 *
544 * Description:
545 * Bring the link down gracefully then re-init the link. The firmware will
546 * re-init the fiber channel interface as required. Does not issue a LIP.
547 *
548 * Returns:
549 * -EPERM port offline or management commands are being blocked
550 * -ENOMEM cannot allocate memory for the mailbox command
551 * -EIO error sending the mailbox command
552 * zero for success
553 **/
91ca7b01 554static int
2e0fef85 555lpfc_issue_lip(struct Scsi_Host *shost)
dea3101e 556{
2e0fef85
JS
557 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
558 struct lpfc_hba *phba = vport->phba;
dea3101e 559 LPFC_MBOXQ_t *pmboxq;
560 int mbxstatus = MBXERR_ERROR;
561
2e0fef85 562 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
83108bd3 563 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea3101e 564 return -EPERM;
565
566 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
567
568 if (!pmboxq)
569 return -ENOMEM;
570
571 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
04c68496
JS
572 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
573 pmboxq->u.mb.mbxOwner = OWN_HOST;
4db621e0 574
33ccf8d1 575 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea3101e 576
04c68496
JS
577 if ((mbxstatus == MBX_SUCCESS) &&
578 (pmboxq->u.mb.mbxStatus == 0 ||
579 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
4db621e0
JS
580 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
581 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
582 phba->cfg_link_speed);
583 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
584 phba->fc_ratov * 2);
dcf2a4e0
JS
585 if ((mbxstatus == MBX_SUCCESS) &&
586 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
587 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
588 "2859 SLI authentication is required "
589 "for INIT_LINK but has not done yet\n");
4db621e0
JS
590 }
591
5b8bd0c9 592 lpfc_set_loopback_flag(phba);
858c9f6c 593 if (mbxstatus != MBX_TIMEOUT)
433c3579 594 mempool_free(pmboxq, phba->mbox_mem_pool);
dea3101e 595
596 if (mbxstatus == MBXERR_ERROR)
597 return -EIO;
598
91ca7b01 599 return 0;
dea3101e 600}
601
e59058c4 602/**
3621a710 603 * lpfc_do_offline - Issues a mailbox command to bring the link down
e59058c4
JS
604 * @phba: lpfc_hba pointer.
605 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
606 *
607 * Notes:
608 * Assumes any error from lpfc_do_offline() will be negative.
609 * Can wait up to 5 seconds for the port ring buffers count
610 * to reach zero, prints a warning if it is not zero and continues.
3621a710 611 * lpfc_workq_post_event() returns a non-zero return code if call fails.
e59058c4
JS
612 *
613 * Returns:
614 * -EIO error posting the event
615 * zero for success
616 **/
40496f07 617static int
46fa311e 618lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
40496f07
JS
619{
620 struct completion online_compl;
46fa311e
JS
621 struct lpfc_sli_ring *pring;
622 struct lpfc_sli *psli;
40496f07 623 int status = 0;
46fa311e
JS
624 int cnt = 0;
625 int i;
40496f07
JS
626
627 init_completion(&online_compl);
628 lpfc_workq_post_event(phba, &status, &online_compl,
46fa311e
JS
629 LPFC_EVT_OFFLINE_PREP);
630 wait_for_completion(&online_compl);
631
632 if (status != 0)
633 return -EIO;
634
635 psli = &phba->sli;
636
09372820
JS
637 /* Wait a little for things to settle down, but not
638 * long enough for dev loss timeout to expire.
639 */
46fa311e
JS
640 for (i = 0; i < psli->num_rings; i++) {
641 pring = &psli->ring[i];
46fa311e
JS
642 while (pring->txcmplq_cnt) {
643 msleep(10);
09372820 644 if (cnt++ > 500) { /* 5 secs */
46fa311e
JS
645 lpfc_printf_log(phba,
646 KERN_WARNING, LOG_INIT,
e8b62011
JS
647 "0466 Outstanding IO when "
648 "bringing Adapter offline\n");
46fa311e
JS
649 break;
650 }
651 }
652 }
653
654 init_completion(&online_compl);
655 lpfc_workq_post_event(phba, &status, &online_compl, type);
40496f07
JS
656 wait_for_completion(&online_compl);
657
658 if (status != 0)
659 return -EIO;
660
46fa311e
JS
661 return 0;
662}
663
e59058c4 664/**
3621a710 665 * lpfc_selective_reset - Offline then onlines the port
e59058c4
JS
666 * @phba: lpfc_hba pointer.
667 *
668 * Description:
669 * If the port is configured to allow a reset then the hba is brought
670 * offline then online.
671 *
672 * Notes:
673 * Assumes any error from lpfc_do_offline() will be negative.
674 *
675 * Returns:
676 * lpfc_do_offline() return code if not zero
677 * -EIO reset not configured or error posting the event
678 * zero for success
679 **/
46fa311e
JS
680static int
681lpfc_selective_reset(struct lpfc_hba *phba)
682{
683 struct completion online_compl;
684 int status = 0;
685
13815c83
JS
686 if (!phba->cfg_enable_hba_reset)
687 return -EIO;
688
46fa311e
JS
689 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
690
691 if (status != 0)
692 return status;
693
40496f07
JS
694 init_completion(&online_compl);
695 lpfc_workq_post_event(phba, &status, &online_compl,
696 LPFC_EVT_ONLINE);
697 wait_for_completion(&online_compl);
698
699 if (status != 0)
700 return -EIO;
701
702 return 0;
703}
704
e59058c4 705/**
3621a710 706 * lpfc_issue_reset - Selectively resets an adapter
e59058c4
JS
707 * @dev: class device that is converted into a Scsi_host.
708 * @attr: device attribute, not used.
709 * @buf: containing the string "selective".
710 * @count: unused variable.
711 *
712 * Description:
713 * If the buf contains the string "selective" then lpfc_selective_reset()
714 * is called to perform the reset.
715 *
716 * Notes:
717 * Assumes any error from lpfc_selective_reset() will be negative.
718 * If lpfc_selective_reset() returns zero then the length of the buffer
af901ca1 719 * is returned which indicates success
e59058c4
JS
720 *
721 * Returns:
722 * -EINVAL if the buffer does not contain the string "selective"
723 * length of buf if lpfc-selective_reset() if the call succeeds
724 * return value of lpfc_selective_reset() if the call fails
725**/
40496f07 726static ssize_t
ee959b00
TJ
727lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
728 const char *buf, size_t count)
40496f07 729{
ee959b00 730 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
731 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
732 struct lpfc_hba *phba = vport->phba;
733
40496f07
JS
734 int status = -EINVAL;
735
736 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
737 status = lpfc_selective_reset(phba);
738
739 if (status == 0)
740 return strlen(buf);
741 else
742 return status;
743}
744
e59058c4 745/**
3621a710 746 * lpfc_nport_evt_cnt_show - Return the number of nport events
e59058c4
JS
747 * @dev: class device that is converted into a Scsi_host.
748 * @attr: device attribute, not used.
749 * @buf: on return contains the ascii number of nport events.
750 *
751 * Returns: size of formatted string.
752 **/
dea3101e 753static ssize_t
ee959b00
TJ
754lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
755 char *buf)
dea3101e 756{
ee959b00 757 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
758 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
759 struct lpfc_hba *phba = vport->phba;
760
dea3101e 761 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
762}
763
e59058c4 764/**
3621a710 765 * lpfc_board_mode_show - Return the state of the board
e59058c4
JS
766 * @dev: class device that is converted into a Scsi_host.
767 * @attr: device attribute, not used.
768 * @buf: on return contains the state of the adapter.
769 *
770 * Returns: size of formatted string.
771 **/
41415862 772static ssize_t
ee959b00
TJ
773lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
774 char *buf)
41415862 775{
ee959b00 776 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
777 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
778 struct lpfc_hba *phba = vport->phba;
41415862
JW
779 char * state;
780
2e0fef85 781 if (phba->link_state == LPFC_HBA_ERROR)
41415862 782 state = "error";
2e0fef85 783 else if (phba->link_state == LPFC_WARM_START)
41415862 784 state = "warm start";
2e0fef85 785 else if (phba->link_state == LPFC_INIT_START)
41415862
JW
786 state = "offline";
787 else
788 state = "online";
789
790 return snprintf(buf, PAGE_SIZE, "%s\n", state);
791}
792
e59058c4 793/**
3621a710 794 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
e59058c4
JS
795 * @dev: class device that is converted into a Scsi_host.
796 * @attr: device attribute, not used.
797 * @buf: containing one of the strings "online", "offline", "warm" or "error".
798 * @count: unused variable.
799 *
800 * Returns:
801 * -EACCES if enable hba reset not enabled
802 * -EINVAL if the buffer does not contain a valid string (see above)
803 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
804 * buf length greater than zero indicates success
805 **/
41415862 806static ssize_t
ee959b00
TJ
807lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
808 const char *buf, size_t count)
41415862 809{
ee959b00 810 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
811 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
812 struct lpfc_hba *phba = vport->phba;
41415862
JW
813 struct completion online_compl;
814 int status=0;
815
13815c83
JS
816 if (!phba->cfg_enable_hba_reset)
817 return -EACCES;
41415862
JW
818 init_completion(&online_compl);
819
46fa311e 820 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
41415862
JW
821 lpfc_workq_post_event(phba, &status, &online_compl,
822 LPFC_EVT_ONLINE);
46fa311e
JS
823 wait_for_completion(&online_compl);
824 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
825 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
41415862 826 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
6a9c52cf
JS
827 if (phba->sli_rev == LPFC_SLI_REV4)
828 return -EINVAL;
829 else
830 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
46fa311e 831 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
6a9c52cf
JS
832 if (phba->sli_rev == LPFC_SLI_REV4)
833 return -EINVAL;
834 else
835 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
41415862
JW
836 else
837 return -EINVAL;
838
41415862
JW
839 if (!status)
840 return strlen(buf);
841 else
842 return -EIO;
843}
844
e59058c4 845/**
3621a710 846 * lpfc_get_hba_info - Return various bits of informaton about the adapter
e59058c4 847 * @phba: pointer to the adapter structure.
3621a710
JS
848 * @mxri: max xri count.
849 * @axri: available xri count.
850 * @mrpi: max rpi count.
851 * @arpi: available rpi count.
852 * @mvpi: max vpi count.
853 * @avpi: available vpi count.
e59058c4
JS
854 *
855 * Description:
856 * If an integer pointer for an count is not null then the value for the
857 * count is returned.
858 *
859 * Returns:
860 * zero on error
861 * one for success
862 **/
311464ec 863static int
858c9f6c
JS
864lpfc_get_hba_info(struct lpfc_hba *phba,
865 uint32_t *mxri, uint32_t *axri,
866 uint32_t *mrpi, uint32_t *arpi,
867 uint32_t *mvpi, uint32_t *avpi)
92d7f7b0 868{
04c68496 869 struct lpfc_mbx_read_config *rd_config;
92d7f7b0
JS
870 LPFC_MBOXQ_t *pmboxq;
871 MAILBOX_t *pmb;
872 int rc = 0;
15672319 873 uint32_t max_vpi;
92d7f7b0
JS
874
875 /*
876 * prevent udev from issuing mailbox commands until the port is
877 * configured.
878 */
879 if (phba->link_state < LPFC_LINK_DOWN ||
880 !phba->mbox_mem_pool ||
f4b4c68f 881 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
92d7f7b0
JS
882 return 0;
883
884 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
885 return 0;
886
887 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
888 if (!pmboxq)
889 return 0;
890 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
891
04c68496 892 pmb = &pmboxq->u.mb;
92d7f7b0
JS
893 pmb->mbxCommand = MBX_READ_CONFIG;
894 pmb->mbxOwner = OWN_HOST;
895 pmboxq->context1 = NULL;
896
75baf696 897 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
92d7f7b0
JS
898 rc = MBX_NOT_FINISHED;
899 else
900 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
901
902 if (rc != MBX_SUCCESS) {
858c9f6c 903 if (rc != MBX_TIMEOUT)
92d7f7b0
JS
904 mempool_free(pmboxq, phba->mbox_mem_pool);
905 return 0;
906 }
907
da0436e9
JS
908 if (phba->sli_rev == LPFC_SLI_REV4) {
909 rd_config = &pmboxq->u.mqe.un.rd_config;
910 if (mrpi)
911 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
912 if (arpi)
913 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
914 phba->sli4_hba.max_cfg_param.rpi_used;
915 if (mxri)
916 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
917 if (axri)
918 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
919 phba->sli4_hba.max_cfg_param.xri_used;
15672319
JS
920
921 /* Account for differences with SLI-3. Get vpi count from
922 * mailbox data and subtract one for max vpi value.
923 */
924 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
925 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
926
da0436e9 927 if (mvpi)
15672319 928 *mvpi = max_vpi;
da0436e9 929 if (avpi)
15672319 930 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
da0436e9
JS
931 } else {
932 if (mrpi)
933 *mrpi = pmb->un.varRdConfig.max_rpi;
934 if (arpi)
935 *arpi = pmb->un.varRdConfig.avail_rpi;
936 if (mxri)
937 *mxri = pmb->un.varRdConfig.max_xri;
938 if (axri)
939 *axri = pmb->un.varRdConfig.avail_xri;
940 if (mvpi)
941 *mvpi = pmb->un.varRdConfig.max_vpi;
942 if (avpi)
943 *avpi = pmb->un.varRdConfig.avail_vpi;
944 }
92d7f7b0
JS
945
946 mempool_free(pmboxq, phba->mbox_mem_pool);
947 return 1;
948}
949
e59058c4 950/**
3621a710 951 * lpfc_max_rpi_show - Return maximum rpi
e59058c4
JS
952 * @dev: class device that is converted into a Scsi_host.
953 * @attr: device attribute, not used.
954 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
955 *
956 * Description:
957 * Calls lpfc_get_hba_info() asking for just the mrpi count.
958 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
959 * to "Unknown" and the buffer length is returned, therefore the caller
960 * must check for "Unknown" in the buffer to detect a failure.
961 *
962 * Returns: size of formatted string.
963 **/
92d7f7b0 964static ssize_t
ee959b00
TJ
965lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
966 char *buf)
92d7f7b0 967{
ee959b00 968 struct Scsi_Host *shost = class_to_shost(dev);
92d7f7b0
JS
969 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
970 struct lpfc_hba *phba = vport->phba;
971 uint32_t cnt;
972
858c9f6c 973 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
92d7f7b0
JS
974 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
975 return snprintf(buf, PAGE_SIZE, "Unknown\n");
976}
977
e59058c4 978/**
3621a710 979 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
e59058c4
JS
980 * @dev: class device that is converted into a Scsi_host.
981 * @attr: device attribute, not used.
982 * @buf: containing the used rpi count in decimal or "Unknown".
983 *
984 * Description:
985 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
986 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
987 * to "Unknown" and the buffer length is returned, therefore the caller
988 * must check for "Unknown" in the buffer to detect a failure.
989 *
990 * Returns: size of formatted string.
991 **/
92d7f7b0 992static ssize_t
ee959b00
TJ
993lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
994 char *buf)
92d7f7b0 995{
ee959b00 996 struct Scsi_Host *shost = class_to_shost(dev);
92d7f7b0
JS
997 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
998 struct lpfc_hba *phba = vport->phba;
999 uint32_t cnt, acnt;
1000
858c9f6c 1001 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
92d7f7b0
JS
1002 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1003 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1004}
1005
e59058c4 1006/**
3621a710 1007 * lpfc_max_xri_show - Return maximum xri
e59058c4
JS
1008 * @dev: class device that is converted into a Scsi_host.
1009 * @attr: device attribute, not used.
1010 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1011 *
1012 * Description:
1013 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1014 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1015 * to "Unknown" and the buffer length is returned, therefore the caller
1016 * must check for "Unknown" in the buffer to detect a failure.
1017 *
1018 * Returns: size of formatted string.
1019 **/
92d7f7b0 1020static ssize_t
ee959b00
TJ
1021lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1022 char *buf)
92d7f7b0 1023{
ee959b00 1024 struct Scsi_Host *shost = class_to_shost(dev);
92d7f7b0
JS
1025 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1026 struct lpfc_hba *phba = vport->phba;
1027 uint32_t cnt;
1028
858c9f6c 1029 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
92d7f7b0
JS
1030 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1031 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1032}
1033
e59058c4 1034/**
3621a710 1035 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
e59058c4
JS
1036 * @dev: class device that is converted into a Scsi_host.
1037 * @attr: device attribute, not used.
1038 * @buf: on return contains the used xri count in decimal or "Unknown".
1039 *
1040 * Description:
1041 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1042 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1043 * to "Unknown" and the buffer length is returned, therefore the caller
1044 * must check for "Unknown" in the buffer to detect a failure.
1045 *
1046 * Returns: size of formatted string.
1047 **/
92d7f7b0 1048static ssize_t
ee959b00
TJ
1049lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1050 char *buf)
92d7f7b0 1051{
ee959b00 1052 struct Scsi_Host *shost = class_to_shost(dev);
92d7f7b0
JS
1053 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1054 struct lpfc_hba *phba = vport->phba;
1055 uint32_t cnt, acnt;
1056
858c9f6c
JS
1057 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1058 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1059 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1060}
1061
e59058c4 1062/**
3621a710 1063 * lpfc_max_vpi_show - Return maximum vpi
e59058c4
JS
1064 * @dev: class device that is converted into a Scsi_host.
1065 * @attr: device attribute, not used.
1066 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1067 *
1068 * Description:
1069 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1070 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1071 * to "Unknown" and the buffer length is returned, therefore the caller
1072 * must check for "Unknown" in the buffer to detect a failure.
1073 *
1074 * Returns: size of formatted string.
1075 **/
858c9f6c 1076static ssize_t
ee959b00
TJ
1077lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1078 char *buf)
858c9f6c 1079{
ee959b00 1080 struct Scsi_Host *shost = class_to_shost(dev);
858c9f6c
JS
1081 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1082 struct lpfc_hba *phba = vport->phba;
1083 uint32_t cnt;
1084
1085 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1086 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1087 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1088}
1089
e59058c4 1090/**
3621a710 1091 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
e59058c4
JS
1092 * @dev: class device that is converted into a Scsi_host.
1093 * @attr: device attribute, not used.
1094 * @buf: on return contains the used vpi count in decimal or "Unknown".
1095 *
1096 * Description:
1097 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1098 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1099 * to "Unknown" and the buffer length is returned, therefore the caller
1100 * must check for "Unknown" in the buffer to detect a failure.
1101 *
1102 * Returns: size of formatted string.
1103 **/
858c9f6c 1104static ssize_t
ee959b00
TJ
1105lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1106 char *buf)
858c9f6c 1107{
ee959b00 1108 struct Scsi_Host *shost = class_to_shost(dev);
858c9f6c
JS
1109 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1110 struct lpfc_hba *phba = vport->phba;
1111 uint32_t cnt, acnt;
1112
1113 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
92d7f7b0
JS
1114 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1115 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1116}
1117
e59058c4 1118/**
3621a710 1119 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
e59058c4
JS
1120 * @dev: class device that is converted into a Scsi_host.
1121 * @attr: device attribute, not used.
1122 * @buf: text that must be interpreted to determine if npiv is supported.
1123 *
1124 * Description:
1125 * Buffer will contain text indicating npiv is not suppoerted on the port,
1126 * the port is an NPIV physical port, or it is an npiv virtual port with
1127 * the id of the vport.
1128 *
1129 * Returns: size of formatted string.
1130 **/
92d7f7b0 1131static ssize_t
ee959b00
TJ
1132lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1133 char *buf)
92d7f7b0 1134{
ee959b00 1135 struct Scsi_Host *shost = class_to_shost(dev);
92d7f7b0
JS
1136 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1137 struct lpfc_hba *phba = vport->phba;
1138
1139 if (!(phba->max_vpi))
1140 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1141 if (vport->port_type == LPFC_PHYSICAL_PORT)
1142 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1143 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1144}
1145
e59058c4 1146/**
3621a710 1147 * lpfc_poll_show - Return text about poll support for the adapter
e59058c4
JS
1148 * @dev: class device that is converted into a Scsi_host.
1149 * @attr: device attribute, not used.
1150 * @buf: on return contains the cfg_poll in hex.
1151 *
1152 * Notes:
1153 * cfg_poll should be a lpfc_polling_flags type.
1154 *
1155 * Returns: size of formatted string.
1156 **/
875fbdfe 1157static ssize_t
ee959b00
TJ
1158lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1159 char *buf)
875fbdfe 1160{
ee959b00 1161 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
1162 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1163 struct lpfc_hba *phba = vport->phba;
875fbdfe
JSEC
1164
1165 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1166}
1167
e59058c4 1168/**
3621a710 1169 * lpfc_poll_store - Set the value of cfg_poll for the adapter
e59058c4
JS
1170 * @dev: class device that is converted into a Scsi_host.
1171 * @attr: device attribute, not used.
1172 * @buf: one or more lpfc_polling_flags values.
1173 * @count: not used.
1174 *
1175 * Notes:
1176 * buf contents converted to integer and checked for a valid value.
1177 *
1178 * Returns:
1179 * -EINVAL if the buffer connot be converted or is out of range
1180 * length of the buf on success
1181 **/
875fbdfe 1182static ssize_t
ee959b00
TJ
1183lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1184 const char *buf, size_t count)
875fbdfe 1185{
ee959b00 1186 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
1187 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1188 struct lpfc_hba *phba = vport->phba;
875fbdfe
JSEC
1189 uint32_t creg_val;
1190 uint32_t old_val;
1191 int val=0;
1192
1193 if (!isdigit(buf[0]))
1194 return -EINVAL;
1195
1196 if (sscanf(buf, "%i", &val) != 1)
1197 return -EINVAL;
1198
1199 if ((val & 0x3) != val)
1200 return -EINVAL;
1201
45ed1190
JS
1202 if (phba->sli_rev == LPFC_SLI_REV4)
1203 val = 0;
1204
2e0fef85 1205 spin_lock_irq(&phba->hbalock);
875fbdfe
JSEC
1206
1207 old_val = phba->cfg_poll;
1208
1209 if (val & ENABLE_FCP_RING_POLLING) {
1210 if ((val & DISABLE_FCP_RING_INT) &&
1211 !(old_val & DISABLE_FCP_RING_INT)) {
1212 creg_val = readl(phba->HCregaddr);
1213 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1214 writel(creg_val, phba->HCregaddr);
1215 readl(phba->HCregaddr); /* flush */
1216
1217 lpfc_poll_start_timer(phba);
1218 }
1219 } else if (val != 0x0) {
2e0fef85 1220 spin_unlock_irq(&phba->hbalock);
875fbdfe
JSEC
1221 return -EINVAL;
1222 }
1223
1224 if (!(val & DISABLE_FCP_RING_INT) &&
1225 (old_val & DISABLE_FCP_RING_INT))
1226 {
2e0fef85 1227 spin_unlock_irq(&phba->hbalock);
875fbdfe 1228 del_timer(&phba->fcp_poll_timer);
2e0fef85 1229 spin_lock_irq(&phba->hbalock);
875fbdfe
JSEC
1230 creg_val = readl(phba->HCregaddr);
1231 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1232 writel(creg_val, phba->HCregaddr);
1233 readl(phba->HCregaddr); /* flush */
1234 }
1235
1236 phba->cfg_poll = val;
1237
2e0fef85 1238 spin_unlock_irq(&phba->hbalock);
875fbdfe
JSEC
1239
1240 return strlen(buf);
1241}
dea3101e 1242
bc73905a
JS
1243/**
1244 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1245 * @dev: class unused variable.
1246 * @attr: device attribute, not used.
1247 * @buf: on return contains the module description text.
1248 *
1249 * Returns: size of formatted string.
1250 **/
1251static ssize_t
1252lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1253 char *buf)
1254{
1255 struct Scsi_Host *shost = class_to_shost(dev);
1256 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1257 struct lpfc_hba *phba = vport->phba;
1258
1259 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1260}
1261
1262/**
1263 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1264 * @dev: class unused variable.
1265 * @attr: device attribute, not used.
1266 * @buf: on return contains the module description text.
1267 *
1268 * Returns: size of formatted string.
1269 **/
1270static ssize_t
1271lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1272 char *buf)
1273{
1274 struct Scsi_Host *shost = class_to_shost(dev);
1275 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1276 struct lpfc_hba *phba = vport->phba;
1277
1278 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1279}
1280
e59058c4 1281/**
3621a710 1282 * lpfc_param_show - Return a cfg attribute value in decimal
e59058c4
JS
1283 *
1284 * Description:
1285 * Macro that given an attr e.g. hba_queue_depth expands
1286 * into a function with the name lpfc_hba_queue_depth_show.
1287 *
1288 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1289 * @dev: class device that is converted into a Scsi_host.
1290 * @attr: device attribute, not used.
1291 * @buf: on return contains the attribute value in decimal.
1292 *
1293 * Returns: size of formatted string.
1294 **/
dea3101e 1295#define lpfc_param_show(attr) \
1296static ssize_t \
ee959b00
TJ
1297lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1298 char *buf) \
dea3101e 1299{ \
ee959b00 1300 struct Scsi_Host *shost = class_to_shost(dev);\
2e0fef85
JS
1301 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1302 struct lpfc_hba *phba = vport->phba;\
84d1b006 1303 uint val = 0;\
7bcbb752
JSEC
1304 val = phba->cfg_##attr;\
1305 return snprintf(buf, PAGE_SIZE, "%d\n",\
1306 phba->cfg_##attr);\
1307}
1308
e59058c4 1309/**
3621a710 1310 * lpfc_param_hex_show - Return a cfg attribute value in hex
e59058c4
JS
1311 *
1312 * Description:
1313 * Macro that given an attr e.g. hba_queue_depth expands
1314 * into a function with the name lpfc_hba_queue_depth_show
1315 *
1316 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1317 * @dev: class device that is converted into a Scsi_host.
1318 * @attr: device attribute, not used.
3621a710 1319 * @buf: on return contains the attribute value in hexadecimal.
e59058c4
JS
1320 *
1321 * Returns: size of formatted string.
1322 **/
93a20f74
JSEC
1323#define lpfc_param_hex_show(attr) \
1324static ssize_t \
ee959b00
TJ
1325lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1326 char *buf) \
93a20f74 1327{ \
ee959b00 1328 struct Scsi_Host *shost = class_to_shost(dev);\
2e0fef85
JS
1329 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1330 struct lpfc_hba *phba = vport->phba;\
84d1b006 1331 uint val = 0;\
93a20f74
JSEC
1332 val = phba->cfg_##attr;\
1333 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1334 phba->cfg_##attr);\
1335}
1336
e59058c4 1337/**
3621a710 1338 * lpfc_param_init - Intializes a cfg attribute
e59058c4
JS
1339 *
1340 * Description:
1341 * Macro that given an attr e.g. hba_queue_depth expands
1342 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1343 * takes a default argument, a minimum and maximum argument.
1344 *
1345 * lpfc_##attr##_init: Initializes an attribute.
1346 * @phba: pointer the the adapter structure.
1347 * @val: integer attribute value.
1348 *
1349 * Validates the min and max values then sets the adapter config field
1350 * accordingly, or uses the default if out of range and prints an error message.
1351 *
1352 * Returns:
1353 * zero on success
1354 * -EINVAL if default used
1355 **/
7bcbb752
JSEC
1356#define lpfc_param_init(attr, default, minval, maxval) \
1357static int \
84d1b006 1358lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
7bcbb752
JSEC
1359{ \
1360 if (val >= minval && val <= maxval) {\
1361 phba->cfg_##attr = val;\
1362 return 0;\
dea3101e 1363 }\
7bcbb752 1364 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
e8b62011
JS
1365 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1366 "allowed range is ["#minval", "#maxval"]\n", val); \
7bcbb752
JSEC
1367 phba->cfg_##attr = default;\
1368 return -EINVAL;\
dea3101e 1369}
1370
e59058c4 1371/**
3621a710 1372 * lpfc_param_set - Set a cfg attribute value
e59058c4
JS
1373 *
1374 * Description:
1375 * Macro that given an attr e.g. hba_queue_depth expands
1376 * into a function with the name lpfc_hba_queue_depth_set
1377 *
1378 * lpfc_##attr##_set: Sets an attribute value.
1379 * @phba: pointer the the adapter structure.
1380 * @val: integer attribute value.
1381 *
1382 * Description:
1383 * Validates the min and max values then sets the
1384 * adapter config field if in the valid range. prints error message
1385 * and does not set the parameter if invalid.
1386 *
1387 * Returns:
1388 * zero on success
1389 * -EINVAL if val is invalid
1390 **/
7bcbb752
JSEC
1391#define lpfc_param_set(attr, default, minval, maxval) \
1392static int \
84d1b006 1393lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
7bcbb752
JSEC
1394{ \
1395 if (val >= minval && val <= maxval) {\
1396 phba->cfg_##attr = val;\
1397 return 0;\
1398 }\
1399 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
e8b62011
JS
1400 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1401 "allowed range is ["#minval", "#maxval"]\n", val); \
7bcbb752
JSEC
1402 return -EINVAL;\
1403}
1404
e59058c4 1405/**
3621a710 1406 * lpfc_param_store - Set a vport attribute value
e59058c4
JS
1407 *
1408 * Description:
1409 * Macro that given an attr e.g. hba_queue_depth expands
1410 * into a function with the name lpfc_hba_queue_depth_store.
1411 *
1412 * lpfc_##attr##_store: Set an sttribute value.
1413 * @dev: class device that is converted into a Scsi_host.
1414 * @attr: device attribute, not used.
1415 * @buf: contains the attribute value in ascii.
1416 * @count: not used.
1417 *
1418 * Description:
1419 * Convert the ascii text number to an integer, then
1420 * use the lpfc_##attr##_set function to set the value.
1421 *
1422 * Returns:
1423 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1424 * length of buffer upon success.
1425 **/
7bcbb752 1426#define lpfc_param_store(attr) \
dea3101e 1427static ssize_t \
ee959b00
TJ
1428lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1429 const char *buf, size_t count) \
dea3101e 1430{ \
ee959b00 1431 struct Scsi_Host *shost = class_to_shost(dev);\
2e0fef85
JS
1432 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1433 struct lpfc_hba *phba = vport->phba;\
84d1b006 1434 uint val = 0;\
93a20f74
JSEC
1435 if (!isdigit(buf[0]))\
1436 return -EINVAL;\
1437 if (sscanf(buf, "%i", &val) != 1)\
1438 return -EINVAL;\
7bcbb752 1439 if (lpfc_##attr##_set(phba, val) == 0) \
755c0d06 1440 return strlen(buf);\
7bcbb752
JSEC
1441 else \
1442 return -EINVAL;\
dea3101e 1443}
1444
e59058c4 1445/**
3621a710 1446 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
e59058c4
JS
1447 *
1448 * Description:
1449 * Macro that given an attr e.g. hba_queue_depth expands
1450 * into a function with the name lpfc_hba_queue_depth_show
1451 *
1452 * lpfc_##attr##_show: prints the attribute value in decimal.
1453 * @dev: class device that is converted into a Scsi_host.
1454 * @attr: device attribute, not used.
1455 * @buf: on return contains the attribute value in decimal.
1456 *
1457 * Returns: length of formatted string.
1458 **/
3de2a653
JS
1459#define lpfc_vport_param_show(attr) \
1460static ssize_t \
ee959b00
TJ
1461lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1462 char *buf) \
3de2a653 1463{ \
ee959b00 1464 struct Scsi_Host *shost = class_to_shost(dev);\
3de2a653 1465 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
84d1b006 1466 uint val = 0;\
3de2a653
JS
1467 val = vport->cfg_##attr;\
1468 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1469}
1470
e59058c4 1471/**
3621a710 1472 * lpfc_vport_param_hex_show - Return hex formatted attribute value
e59058c4
JS
1473 *
1474 * Description:
1475 * Macro that given an attr e.g.
1476 * hba_queue_depth expands into a function with the name
1477 * lpfc_hba_queue_depth_show
1478 *
3621a710 1479 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
e59058c4
JS
1480 * @dev: class device that is converted into a Scsi_host.
1481 * @attr: device attribute, not used.
3621a710 1482 * @buf: on return contains the attribute value in hexadecimal.
e59058c4
JS
1483 *
1484 * Returns: length of formatted string.
1485 **/
3de2a653
JS
1486#define lpfc_vport_param_hex_show(attr) \
1487static ssize_t \
ee959b00
TJ
1488lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1489 char *buf) \
3de2a653 1490{ \
ee959b00 1491 struct Scsi_Host *shost = class_to_shost(dev);\
3de2a653 1492 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
84d1b006 1493 uint val = 0;\
3de2a653
JS
1494 val = vport->cfg_##attr;\
1495 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1496}
1497
e59058c4 1498/**
3621a710 1499 * lpfc_vport_param_init - Initialize a vport cfg attribute
e59058c4
JS
1500 *
1501 * Description:
1502 * Macro that given an attr e.g. hba_queue_depth expands
1503 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1504 * takes a default argument, a minimum and maximum argument.
1505 *
1506 * lpfc_##attr##_init: validates the min and max values then sets the
1507 * adapter config field accordingly, or uses the default if out of range
1508 * and prints an error message.
1509 * @phba: pointer the the adapter structure.
1510 * @val: integer attribute value.
1511 *
1512 * Returns:
1513 * zero on success
1514 * -EINVAL if default used
1515 **/
3de2a653
JS
1516#define lpfc_vport_param_init(attr, default, minval, maxval) \
1517static int \
84d1b006 1518lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
3de2a653
JS
1519{ \
1520 if (val >= minval && val <= maxval) {\
1521 vport->cfg_##attr = val;\
1522 return 0;\
1523 }\
e8b62011 1524 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
d7c255b2 1525 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
e8b62011 1526 "allowed range is ["#minval", "#maxval"]\n", val); \
3de2a653
JS
1527 vport->cfg_##attr = default;\
1528 return -EINVAL;\
1529}
1530
e59058c4 1531/**
3621a710 1532 * lpfc_vport_param_set - Set a vport cfg attribute
e59058c4
JS
1533 *
1534 * Description:
1535 * Macro that given an attr e.g. hba_queue_depth expands
1536 * into a function with the name lpfc_hba_queue_depth_set
1537 *
1538 * lpfc_##attr##_set: validates the min and max values then sets the
1539 * adapter config field if in the valid range. prints error message
1540 * and does not set the parameter if invalid.
1541 * @phba: pointer the the adapter structure.
1542 * @val: integer attribute value.
1543 *
1544 * Returns:
1545 * zero on success
1546 * -EINVAL if val is invalid
1547 **/
3de2a653
JS
1548#define lpfc_vport_param_set(attr, default, minval, maxval) \
1549static int \
84d1b006 1550lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
3de2a653
JS
1551{ \
1552 if (val >= minval && val <= maxval) {\
1553 vport->cfg_##attr = val;\
1554 return 0;\
1555 }\
e8b62011 1556 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
d7c255b2 1557 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
e8b62011 1558 "allowed range is ["#minval", "#maxval"]\n", val); \
3de2a653
JS
1559 return -EINVAL;\
1560}
1561
e59058c4 1562/**
3621a710 1563 * lpfc_vport_param_store - Set a vport attribute
e59058c4
JS
1564 *
1565 * Description:
1566 * Macro that given an attr e.g. hba_queue_depth
1567 * expands into a function with the name lpfc_hba_queue_depth_store
1568 *
1569 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1570 * use the lpfc_##attr##_set function to set the value.
1571 * @cdev: class device that is converted into a Scsi_host.
1572 * @buf: contains the attribute value in decimal.
1573 * @count: not used.
1574 *
1575 * Returns:
1576 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1577 * length of buffer upon success.
1578 **/
3de2a653
JS
1579#define lpfc_vport_param_store(attr) \
1580static ssize_t \
ee959b00
TJ
1581lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1582 const char *buf, size_t count) \
3de2a653 1583{ \
ee959b00 1584 struct Scsi_Host *shost = class_to_shost(dev);\
3de2a653 1585 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
84d1b006 1586 uint val = 0;\
3de2a653
JS
1587 if (!isdigit(buf[0]))\
1588 return -EINVAL;\
1589 if (sscanf(buf, "%i", &val) != 1)\
1590 return -EINVAL;\
1591 if (lpfc_##attr##_set(vport, val) == 0) \
1592 return strlen(buf);\
1593 else \
1594 return -EINVAL;\
1595}
1596
1597
7bcbb752 1598#define LPFC_ATTR(name, defval, minval, maxval, desc) \
84d1b006
JS
1599static uint lpfc_##name = defval;\
1600module_param(lpfc_##name, uint, 0);\
dea3101e 1601MODULE_PARM_DESC(lpfc_##name, desc);\
7bcbb752 1602lpfc_param_init(name, defval, minval, maxval)
dea3101e 1603
1604#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
84d1b006
JS
1605static uint lpfc_##name = defval;\
1606module_param(lpfc_##name, uint, 0);\
dea3101e 1607MODULE_PARM_DESC(lpfc_##name, desc);\
1608lpfc_param_show(name)\
7bcbb752 1609lpfc_param_init(name, defval, minval, maxval)\
ee959b00 1610static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea3101e 1611
1612#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
84d1b006
JS
1613static uint lpfc_##name = defval;\
1614module_param(lpfc_##name, uint, 0);\
dea3101e 1615MODULE_PARM_DESC(lpfc_##name, desc);\
1616lpfc_param_show(name)\
7bcbb752
JSEC
1617lpfc_param_init(name, defval, minval, maxval)\
1618lpfc_param_set(name, defval, minval, maxval)\
1619lpfc_param_store(name)\
ee959b00
TJ
1620static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1621 lpfc_##name##_show, lpfc_##name##_store)
dea3101e 1622
93a20f74 1623#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
84d1b006
JS
1624static uint lpfc_##name = defval;\
1625module_param(lpfc_##name, uint, 0);\
93a20f74
JSEC
1626MODULE_PARM_DESC(lpfc_##name, desc);\
1627lpfc_param_hex_show(name)\
1628lpfc_param_init(name, defval, minval, maxval)\
ee959b00 1629static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
93a20f74
JSEC
1630
1631#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
84d1b006
JS
1632static uint lpfc_##name = defval;\
1633module_param(lpfc_##name, uint, 0);\
93a20f74
JSEC
1634MODULE_PARM_DESC(lpfc_##name, desc);\
1635lpfc_param_hex_show(name)\
1636lpfc_param_init(name, defval, minval, maxval)\
1637lpfc_param_set(name, defval, minval, maxval)\
1638lpfc_param_store(name)\
ee959b00
TJ
1639static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1640 lpfc_##name##_show, lpfc_##name##_store)
93a20f74 1641
3de2a653 1642#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
84d1b006
JS
1643static uint lpfc_##name = defval;\
1644module_param(lpfc_##name, uint, 0);\
3de2a653
JS
1645MODULE_PARM_DESC(lpfc_##name, desc);\
1646lpfc_vport_param_init(name, defval, minval, maxval)
1647
1648#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
84d1b006
JS
1649static uint lpfc_##name = defval;\
1650module_param(lpfc_##name, uint, 0);\
3de2a653
JS
1651MODULE_PARM_DESC(lpfc_##name, desc);\
1652lpfc_vport_param_show(name)\
1653lpfc_vport_param_init(name, defval, minval, maxval)\
ee959b00 1654static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
3de2a653
JS
1655
1656#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
84d1b006
JS
1657static uint lpfc_##name = defval;\
1658module_param(lpfc_##name, uint, 0);\
3de2a653
JS
1659MODULE_PARM_DESC(lpfc_##name, desc);\
1660lpfc_vport_param_show(name)\
1661lpfc_vport_param_init(name, defval, minval, maxval)\
1662lpfc_vport_param_set(name, defval, minval, maxval)\
1663lpfc_vport_param_store(name)\
ee959b00
TJ
1664static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1665 lpfc_##name##_show, lpfc_##name##_store)
3de2a653
JS
1666
1667#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
84d1b006
JS
1668static uint lpfc_##name = defval;\
1669module_param(lpfc_##name, uint, 0);\
3de2a653
JS
1670MODULE_PARM_DESC(lpfc_##name, desc);\
1671lpfc_vport_param_hex_show(name)\
1672lpfc_vport_param_init(name, defval, minval, maxval)\
ee959b00 1673static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
3de2a653
JS
1674
1675#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
84d1b006
JS
1676static uint lpfc_##name = defval;\
1677module_param(lpfc_##name, uint, 0);\
3de2a653
JS
1678MODULE_PARM_DESC(lpfc_##name, desc);\
1679lpfc_vport_param_hex_show(name)\
1680lpfc_vport_param_init(name, defval, minval, maxval)\
1681lpfc_vport_param_set(name, defval, minval, maxval)\
1682lpfc_vport_param_store(name)\
ee959b00
TJ
1683static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1684 lpfc_##name##_show, lpfc_##name##_store)
1685
81301a9b
JS
1686static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1687static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1688static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1689static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
ee959b00
TJ
1690static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1691static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1692static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1693static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1694static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1695static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1696static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1697static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
84d1b006
JS
1698static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1699 lpfc_link_state_store);
ee959b00
TJ
1700static DEVICE_ATTR(option_rom_version, S_IRUGO,
1701 lpfc_option_rom_version_show, NULL);
1702static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1703 lpfc_num_discovered_ports_show, NULL);
84774a4d 1704static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
ee959b00
TJ
1705static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1706static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
45ed1190 1707static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
ee959b00
TJ
1708static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1709 lpfc_board_mode_show, lpfc_board_mode_store);
1710static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1711static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1712static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1713static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1714static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1715static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1716static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1717static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1718static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
bc73905a
JS
1719static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1720static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
dea3101e 1721
c3f28afa 1722
a12e07bc 1723static char *lpfc_soft_wwn_key = "C99G71SL8032A";
c3f28afa 1724
e59058c4 1725/**
3621a710 1726 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
e59058c4
JS
1727 * @dev: class device that is converted into a Scsi_host.
1728 * @attr: device attribute, not used.
1729 * @buf: containing the string lpfc_soft_wwn_key.
1730 * @count: must be size of lpfc_soft_wwn_key.
1731 *
1732 * Returns:
1733 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1734 * length of buf indicates success
1735 **/
c3f28afa 1736static ssize_t
ee959b00
TJ
1737lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1738 const char *buf, size_t count)
c3f28afa 1739{
ee959b00 1740 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
1741 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1742 struct lpfc_hba *phba = vport->phba;
c3f28afa
JS
1743 unsigned int cnt = count;
1744
1745 /*
1746 * We're doing a simple sanity check for soft_wwpn setting.
1747 * We require that the user write a specific key to enable
1748 * the soft_wwpn attribute to be settable. Once the attribute
1749 * is written, the enable key resets. If further updates are
1750 * desired, the key must be written again to re-enable the
1751 * attribute.
1752 *
1753 * The "key" is not secret - it is a hardcoded string shown
1754 * here. The intent is to protect against the random user or
1755 * application that is just writing attributes.
1756 */
1757
1758 /* count may include a LF at end of string */
1759 if (buf[cnt-1] == '\n')
1760 cnt--;
1761
a12e07bc
JS
1762 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1763 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
c3f28afa
JS
1764 return -EINVAL;
1765
a12e07bc 1766 phba->soft_wwn_enable = 1;
c3f28afa
JS
1767 return count;
1768}
ee959b00
TJ
1769static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1770 lpfc_soft_wwn_enable_store);
c3f28afa 1771
e59058c4 1772/**
3621a710 1773 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
e59058c4
JS
1774 * @dev: class device that is converted into a Scsi_host.
1775 * @attr: device attribute, not used.
3621a710 1776 * @buf: on return contains the wwpn in hexadecimal.
e59058c4
JS
1777 *
1778 * Returns: size of formatted string.
1779 **/
c3f28afa 1780static ssize_t
ee959b00
TJ
1781lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1782 char *buf)
c3f28afa 1783{
ee959b00 1784 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
1785 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1786 struct lpfc_hba *phba = vport->phba;
1787
afc071e6
RD
1788 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1789 (unsigned long long)phba->cfg_soft_wwpn);
c3f28afa
JS
1790}
1791
e59058c4 1792/**
3621a710 1793 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
e59058c4
JS
1794 * @dev class device that is converted into a Scsi_host.
1795 * @attr: device attribute, not used.
3621a710 1796 * @buf: contains the wwpn in hexadecimal.
e59058c4
JS
1797 * @count: number of wwpn bytes in buf
1798 *
1799 * Returns:
1800 * -EACCES hba reset not enabled, adapter over temp
1801 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1802 * -EIO error taking adapter offline or online
1803 * value of count on success
1804 **/
c3f28afa 1805static ssize_t
ee959b00
TJ
1806lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1807 const char *buf, size_t count)
c3f28afa 1808{
ee959b00 1809 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
1810 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1811 struct lpfc_hba *phba = vport->phba;
c3f28afa
JS
1812 struct completion online_compl;
1813 int stat1=0, stat2=0;
1814 unsigned int i, j, cnt=count;
1815 u8 wwpn[8];
1816
13815c83
JS
1817 if (!phba->cfg_enable_hba_reset)
1818 return -EACCES;
7af67051
JS
1819 spin_lock_irq(&phba->hbalock);
1820 if (phba->over_temp_state == HBA_OVER_TEMP) {
1821 spin_unlock_irq(&phba->hbalock);
09372820 1822 return -EACCES;
7af67051
JS
1823 }
1824 spin_unlock_irq(&phba->hbalock);
c3f28afa
JS
1825 /* count may include a LF at end of string */
1826 if (buf[cnt-1] == '\n')
1827 cnt--;
1828
a12e07bc 1829 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
c3f28afa
JS
1830 ((cnt == 17) && (*buf++ != 'x')) ||
1831 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1832 return -EINVAL;
1833
a12e07bc 1834 phba->soft_wwn_enable = 0;
c3f28afa
JS
1835
1836 memset(wwpn, 0, sizeof(wwpn));
1837
1838 /* Validate and store the new name */
1839 for (i=0, j=0; i < 16; i++) {
ecc30990
AS
1840 int value;
1841
1842 value = hex_to_bin(*buf++);
1843 if (value >= 0)
1844 j = (j << 4) | value;
c3f28afa
JS
1845 else
1846 return -EINVAL;
1847 if (i % 2) {
1848 wwpn[i/2] = j & 0xff;
1849 j = 0;
1850 }
1851 }
1852 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2e0fef85 1853 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
a12e07bc 1854 if (phba->cfg_soft_wwnn)
2e0fef85 1855 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
c3f28afa
JS
1856
1857 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1858 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1859
46fa311e 1860 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
c3f28afa
JS
1861 if (stat1)
1862 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
e8b62011
JS
1863 "0463 lpfc_soft_wwpn attribute set failed to "
1864 "reinit adapter - %d\n", stat1);
c3f28afa
JS
1865 init_completion(&online_compl);
1866 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1867 wait_for_completion(&online_compl);
1868 if (stat2)
1869 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
e8b62011
JS
1870 "0464 lpfc_soft_wwpn attribute set failed to "
1871 "reinit adapter - %d\n", stat2);
c3f28afa
JS
1872 return (stat1 || stat2) ? -EIO : count;
1873}
ee959b00
TJ
1874static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1875 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
c3f28afa 1876
e59058c4 1877/**
3621a710 1878 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
e59058c4
JS
1879 * @dev: class device that is converted into a Scsi_host.
1880 * @attr: device attribute, not used.
3621a710 1881 * @buf: on return contains the wwnn in hexadecimal.
e59058c4
JS
1882 *
1883 * Returns: size of formatted string.
1884 **/
a12e07bc 1885static ssize_t
ee959b00
TJ
1886lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1887 char *buf)
a12e07bc 1888{
ee959b00 1889 struct Scsi_Host *shost = class_to_shost(dev);
51ef4c26 1890 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
a12e07bc
JS
1891 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1892 (unsigned long long)phba->cfg_soft_wwnn);
1893}
1894
e59058c4 1895/**
3621a710 1896 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
e59058c4 1897 * @cdev: class device that is converted into a Scsi_host.
3621a710 1898 * @buf: contains the ww node name in hexadecimal.
e59058c4
JS
1899 * @count: number of wwnn bytes in buf.
1900 *
1901 * Returns:
1902 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1903 * value of count on success
1904 **/
a12e07bc 1905static ssize_t
ee959b00
TJ
1906lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1907 const char *buf, size_t count)
a12e07bc 1908{
ee959b00 1909 struct Scsi_Host *shost = class_to_shost(dev);
51ef4c26 1910 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
a12e07bc
JS
1911 unsigned int i, j, cnt=count;
1912 u8 wwnn[8];
1913
1914 /* count may include a LF at end of string */
1915 if (buf[cnt-1] == '\n')
1916 cnt--;
1917
1918 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1919 ((cnt == 17) && (*buf++ != 'x')) ||
1920 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1921 return -EINVAL;
1922
1923 /*
1924 * Allow wwnn to be set many times, as long as the enable is set.
1925 * However, once the wwpn is set, everything locks.
1926 */
1927
1928 memset(wwnn, 0, sizeof(wwnn));
1929
1930 /* Validate and store the new name */
1931 for (i=0, j=0; i < 16; i++) {
ecc30990
AS
1932 int value;
1933
1934 value = hex_to_bin(*buf++);
1935 if (value >= 0)
1936 j = (j << 4) | value;
a12e07bc
JS
1937 else
1938 return -EINVAL;
1939 if (i % 2) {
1940 wwnn[i/2] = j & 0xff;
1941 j = 0;
1942 }
1943 }
1944 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1945
1946 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1947 "lpfc%d: soft_wwnn set. Value will take effect upon "
1948 "setting of the soft_wwpn\n", phba->brd_no);
1949
1950 return count;
1951}
ee959b00
TJ
1952static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1953 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
a12e07bc 1954
c3f28afa 1955
875fbdfe
JSEC
1956static int lpfc_poll = 0;
1957module_param(lpfc_poll, int, 0);
1958MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1959 " 0 - none,"
1960 " 1 - poll with interrupts enabled"
1961 " 3 - poll and disable FCP ring interrupts");
1962
ee959b00
TJ
1963static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1964 lpfc_poll_show, lpfc_poll_store);
dea3101e 1965
92d7f7b0
JS
1966int lpfc_sli_mode = 0;
1967module_param(lpfc_sli_mode, int, 0);
1968MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1969 " 0 - auto (SLI-3 if supported),"
1970 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1971 " 3 - select SLI-3");
1972
15672319 1973int lpfc_enable_npiv = 1;
7ee5d43e
JS
1974module_param(lpfc_enable_npiv, int, 0);
1975MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1976lpfc_param_show(enable_npiv);
4b40c59e 1977lpfc_param_init(enable_npiv, 1, 0, 1);
15672319 1978static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
92d7f7b0 1979
19ca7609
JS
1980int lpfc_enable_rrq;
1981module_param(lpfc_enable_rrq, int, 0);
1982MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
1983lpfc_param_show(enable_rrq);
1984lpfc_param_init(enable_rrq, 0, 0, 1);
1985static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
1986
84d1b006
JS
1987/*
1988# lpfc_suppress_link_up: Bring link up at initialization
1989# 0x0 = bring link up (issue MBX_INIT_LINK)
1990# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
1991# 0x2 = never bring up link
1992# Default value is 0.
1993*/
e40a02c1
JS
1994LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
1995 LPFC_DELAY_INIT_LINK_INDEFINITELY,
1996 "Suppress Link Up at initialization");
2a9bf3d0
JS
1997/*
1998# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
1999# 1 - (1024)
2000# 2 - (2048)
2001# 3 - (3072)
2002# 4 - (4096)
2003# 5 - (5120)
2004*/
2005static ssize_t
2006lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2007{
2008 struct Scsi_Host *shost = class_to_shost(dev);
2009 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2010
2011 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2012}
2013
2014static DEVICE_ATTR(iocb_hw, S_IRUGO,
2015 lpfc_iocb_hw_show, NULL);
2016static ssize_t
2017lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2018{
2019 struct Scsi_Host *shost = class_to_shost(dev);
2020 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2021
2022 return snprintf(buf, PAGE_SIZE, "%d\n",
2023 phba->sli.ring[LPFC_ELS_RING].txq_max);
2024}
2025
2026static DEVICE_ATTR(txq_hw, S_IRUGO,
2027 lpfc_txq_hw_show, NULL);
2028static ssize_t
2029lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2030 char *buf)
2031{
2032 struct Scsi_Host *shost = class_to_shost(dev);
2033 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2034
2035 return snprintf(buf, PAGE_SIZE, "%d\n",
2036 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2037}
2038
2039static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2040 lpfc_txcmplq_hw_show, NULL);
2041
2042int lpfc_iocb_cnt = 2;
2043module_param(lpfc_iocb_cnt, int, 1);
2044MODULE_PARM_DESC(lpfc_iocb_cnt,
2045 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2046lpfc_param_show(iocb_cnt);
2047lpfc_param_init(iocb_cnt, 2, 1, 5);
2048static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2049 lpfc_iocb_cnt_show, NULL);
84d1b006 2050
c01f3208
JS
2051/*
2052# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2053# until the timer expires. Value range is [0,255]. Default value is 30.
2054*/
2055static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2056static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2057module_param(lpfc_nodev_tmo, int, 0);
2058MODULE_PARM_DESC(lpfc_nodev_tmo,
2059 "Seconds driver will hold I/O waiting "
2060 "for a device to come back");
e59058c4
JS
2061
2062/**
3621a710 2063 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
e59058c4
JS
2064 * @dev: class converted to a Scsi_host structure.
2065 * @attr: device attribute, not used.
2066 * @buf: on return contains the dev loss timeout in decimal.
2067 *
2068 * Returns: size of formatted string.
2069 **/
c01f3208 2070static ssize_t
ee959b00
TJ
2071lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2072 char *buf)
c01f3208 2073{
ee959b00 2074 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85 2075 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
e40a02c1 2076
3de2a653 2077 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
c01f3208
JS
2078}
2079
e59058c4 2080/**
3621a710 2081 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
e59058c4
JS
2082 * @vport: lpfc vport structure pointer.
2083 * @val: contains the nodev timeout value.
2084 *
2085 * Description:
2086 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2087 * a kernel error message is printed and zero is returned.
2088 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2089 * Otherwise nodev tmo is set to the default value.
2090 *
2091 * Returns:
2092 * zero if already set or if val is in range
2093 * -EINVAL val out of range
2094 **/
c01f3208 2095static int
3de2a653
JS
2096lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
2097{
2098 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2099 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2100 if (val != LPFC_DEF_DEVLOSS_TMO)
e8b62011 2101 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
d7c255b2 2102 "0407 Ignoring nodev_tmo module "
e8b62011
JS
2103 "parameter because devloss_tmo is "
2104 "set.\n");
c01f3208
JS
2105 return 0;
2106 }
2107
2108 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3de2a653
JS
2109 vport->cfg_nodev_tmo = val;
2110 vport->cfg_devloss_tmo = val;
c01f3208
JS
2111 return 0;
2112 }
e8b62011
JS
2113 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2114 "0400 lpfc_nodev_tmo attribute cannot be set to"
2115 " %d, allowed range is [%d, %d]\n",
2116 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3de2a653 2117 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
c01f3208
JS
2118 return -EINVAL;
2119}
2120
e59058c4 2121/**
3621a710 2122 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
e59058c4
JS
2123 * @vport: lpfc vport structure pointer.
2124 *
2125 * Description:
2126 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2127 **/
7054a606 2128static void
3de2a653 2129lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
7054a606 2130{
858c9f6c 2131 struct Scsi_Host *shost;
7054a606
JS
2132 struct lpfc_nodelist *ndlp;
2133
51ef4c26
JS
2134 shost = lpfc_shost_from_vport(vport);
2135 spin_lock_irq(shost->host_lock);
2136 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
e47c9093 2137 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
51ef4c26
JS
2138 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2139 spin_unlock_irq(shost->host_lock);
7054a606
JS
2140}
2141
e59058c4 2142/**
3621a710 2143 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
e59058c4
JS
2144 * @vport: lpfc vport structure pointer.
2145 * @val: contains the tmo value.
2146 *
2147 * Description:
2148 * If the devloss tmo is already set or the vport dev loss tmo has changed
2149 * then a kernel error message is printed and zero is returned.
2150 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2151 * Otherwise nodev tmo is set to the default value.
2152 *
2153 * Returns:
2154 * zero if already set or if val is in range
2155 * -EINVAL val out of range
2156 **/
c01f3208 2157static int
3de2a653 2158lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
c01f3208 2159{
3de2a653
JS
2160 if (vport->dev_loss_tmo_changed ||
2161 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
e8b62011
JS
2162 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2163 "0401 Ignoring change to nodev_tmo "
2164 "because devloss_tmo is set.\n");
c01f3208
JS
2165 return 0;
2166 }
c01f3208 2167 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3de2a653
JS
2168 vport->cfg_nodev_tmo = val;
2169 vport->cfg_devloss_tmo = val;
0af5d708
MC
2170 /*
2171 * For compat: set the fc_host dev loss so new rports
2172 * will get the value.
2173 */
2174 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3de2a653 2175 lpfc_update_rport_devloss_tmo(vport);
c01f3208
JS
2176 return 0;
2177 }
e8b62011
JS
2178 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2179 "0403 lpfc_nodev_tmo attribute cannot be set to"
2180 "%d, allowed range is [%d, %d]\n",
2181 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
c01f3208
JS
2182 return -EINVAL;
2183}
2184
3de2a653 2185lpfc_vport_param_store(nodev_tmo)
c01f3208 2186
ee959b00
TJ
2187static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2188 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
c01f3208
JS
2189
2190/*
2191# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2192# disappear until the timer expires. Value range is [0,255]. Default
2193# value is 30.
2194*/
2195module_param(lpfc_devloss_tmo, int, 0);
2196MODULE_PARM_DESC(lpfc_devloss_tmo,
2197 "Seconds driver will hold I/O waiting "
2198 "for a device to come back");
3de2a653
JS
2199lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2200 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2201lpfc_vport_param_show(devloss_tmo)
e59058c4
JS
2202
2203/**
3621a710 2204 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
e59058c4
JS
2205 * @vport: lpfc vport structure pointer.
2206 * @val: contains the tmo value.
2207 *
2208 * Description:
2209 * If val is in a valid range then set the vport nodev tmo,
2210 * devloss tmo, also set the vport dev loss tmo changed flag.
2211 * Else a kernel error message is printed.
2212 *
2213 * Returns:
2214 * zero if val is in range
2215 * -EINVAL val out of range
2216 **/
c01f3208 2217static int
3de2a653 2218lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
c01f3208
JS
2219{
2220 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3de2a653
JS
2221 vport->cfg_nodev_tmo = val;
2222 vport->cfg_devloss_tmo = val;
2223 vport->dev_loss_tmo_changed = 1;
0af5d708 2224 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3de2a653 2225 lpfc_update_rport_devloss_tmo(vport);
c01f3208
JS
2226 return 0;
2227 }
2228
e8b62011
JS
2229 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2230 "0404 lpfc_devloss_tmo attribute cannot be set to"
2231 " %d, allowed range is [%d, %d]\n",
2232 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
c01f3208
JS
2233 return -EINVAL;
2234}
2235
3de2a653 2236lpfc_vport_param_store(devloss_tmo)
ee959b00
TJ
2237static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2238 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
c01f3208 2239
dea3101e 2240/*
2241# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2242# deluged with LOTS of information.
2243# You can set a bit mask to record specific types of verbose messages:
f4b4c68f 2244# See lpfc_logmsh.h for definitions.
dea3101e 2245*/
f4b4c68f 2246LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
e8b62011 2247 "Verbose logging bit-mask");
dea3101e 2248
7ee5d43e
JS
2249/*
2250# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2251# objects that have been registered with the nameserver after login.
2252*/
2253LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2254 "Deregister nameserver objects before LOGO");
2255
dea3101e 2256/*
2257# lun_queue_depth: This parameter is used to limit the number of outstanding
2258# commands per FCP LUN. Value range is [1,128]. Default value is 30.
2259*/
3de2a653
JS
2260LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2261 "Max number of FCP commands we can queue to a specific LUN");
dea3101e 2262
7dc517df
JS
2263/*
2264# tgt_queue_depth: This parameter is used to limit the number of outstanding
2265# commands per target port. Value range is [10,65535]. Default value is 65535.
2266*/
2267LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2268 "Max number of FCP commands we can queue to a specific target port");
2269
b28485ac
JW
2270/*
2271# hba_queue_depth: This parameter is used to limit the number of outstanding
2272# commands per lpfc HBA. Value range is [32,8192]. If this parameter
2273# value is greater than the maximum number of exchanges supported by the HBA,
2274# then maximum number of exchanges supported by the HBA is used to determine
2275# the hba_queue_depth.
2276*/
2277LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2278 "Max number of FCP commands we can queue to a lpfc HBA");
2279
92d7f7b0
JS
2280/*
2281# peer_port_login: This parameter allows/prevents logins
2282# between peer ports hosted on the same physical port.
2283# When this parameter is set 0 peer ports of same physical port
2284# are not allowed to login to each other.
2285# When this parameter is set 1 peer ports of same physical port
2286# are allowed to login to each other.
2287# Default value of this parameter is 0.
2288*/
3de2a653
JS
2289LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2290 "Allow peer ports on the same physical port to login to each "
2291 "other.");
92d7f7b0
JS
2292
2293/*
3de2a653 2294# restrict_login: This parameter allows/prevents logins
92d7f7b0
JS
2295# between Virtual Ports and remote initiators.
2296# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2297# other initiators and will attempt to PLOGI all remote ports.
2298# When this parameter is set (1) Virtual Ports will reject PLOGIs from
2299# remote ports and will not attempt to PLOGI to other initiators.
2300# This parameter does not restrict to the physical port.
2301# This parameter does not restrict logins to Fabric resident remote ports.
2302# Default value of this parameter is 1.
2303*/
3de2a653
JS
2304static int lpfc_restrict_login = 1;
2305module_param(lpfc_restrict_login, int, 0);
2306MODULE_PARM_DESC(lpfc_restrict_login,
2307 "Restrict virtual ports login to remote initiators.");
2308lpfc_vport_param_show(restrict_login);
2309
e59058c4 2310/**
3621a710 2311 * lpfc_restrict_login_init - Set the vport restrict login flag
e59058c4
JS
2312 * @vport: lpfc vport structure pointer.
2313 * @val: contains the restrict login value.
2314 *
2315 * Description:
2316 * If val is not in a valid range then log a kernel error message and set
2317 * the vport restrict login to one.
2318 * If the port type is physical clear the restrict login flag and return.
2319 * Else set the restrict login flag to val.
2320 *
2321 * Returns:
2322 * zero if val is in range
2323 * -EINVAL val out of range
2324 **/
3de2a653
JS
2325static int
2326lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2327{
2328 if (val < 0 || val > 1) {
e8b62011 2329 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
d7c255b2 2330 "0422 lpfc_restrict_login attribute cannot "
e8b62011
JS
2331 "be set to %d, allowed range is [0, 1]\n",
2332 val);
3de2a653
JS
2333 vport->cfg_restrict_login = 1;
2334 return -EINVAL;
2335 }
2336 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2337 vport->cfg_restrict_login = 0;
2338 return 0;
2339 }
2340 vport->cfg_restrict_login = val;
2341 return 0;
2342}
2343
e59058c4 2344/**
3621a710 2345 * lpfc_restrict_login_set - Set the vport restrict login flag
e59058c4
JS
2346 * @vport: lpfc vport structure pointer.
2347 * @val: contains the restrict login value.
2348 *
2349 * Description:
2350 * If val is not in a valid range then log a kernel error message and set
2351 * the vport restrict login to one.
2352 * If the port type is physical and the val is not zero log a kernel
2353 * error message, clear the restrict login flag and return zero.
2354 * Else set the restrict login flag to val.
2355 *
2356 * Returns:
2357 * zero if val is in range
2358 * -EINVAL val out of range
2359 **/
3de2a653
JS
2360static int
2361lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2362{
2363 if (val < 0 || val > 1) {
e8b62011 2364 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
d7c255b2 2365 "0425 lpfc_restrict_login attribute cannot "
e8b62011
JS
2366 "be set to %d, allowed range is [0, 1]\n",
2367 val);
3de2a653
JS
2368 vport->cfg_restrict_login = 1;
2369 return -EINVAL;
2370 }
2371 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
e8b62011
JS
2372 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2373 "0468 lpfc_restrict_login must be 0 for "
2374 "Physical ports.\n");
3de2a653
JS
2375 vport->cfg_restrict_login = 0;
2376 return 0;
2377 }
2378 vport->cfg_restrict_login = val;
2379 return 0;
2380}
2381lpfc_vport_param_store(restrict_login);
ee959b00
TJ
2382static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2383 lpfc_restrict_login_show, lpfc_restrict_login_store);
92d7f7b0 2384
dea3101e 2385/*
2386# Some disk devices have a "select ID" or "select Target" capability.
2387# From a protocol standpoint "select ID" usually means select the
2388# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2389# annex" which contains a table that maps a "select ID" (a number
2390# between 0 and 7F) to an ALPA. By default, for compatibility with
2391# older drivers, the lpfc driver scans this table from low ALPA to high
2392# ALPA.
2393#
2394# Turning on the scan-down variable (on = 1, off = 0) will
2395# cause the lpfc driver to use an inverted table, effectively
2396# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2397#
2398# (Note: This "select ID" functionality is a LOOP ONLY characteristic
2399# and will not work across a fabric. Also this parameter will take
2400# effect only in the case when ALPA map is not available.)
2401*/
3de2a653
JS
2402LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2403 "Start scanning for devices from highest ALPA to lowest");
dea3101e 2404
dea3101e 2405/*
2406# lpfc_topology: link topology for init link
2407# 0x0 = attempt loop mode then point-to-point
367c2713 2408# 0x01 = internal loopback mode
dea3101e 2409# 0x02 = attempt point-to-point mode only
2410# 0x04 = attempt loop mode only
2411# 0x06 = attempt point-to-point mode then loop
2412# Set point-to-point mode if you want to run as an N_Port.
2413# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2414# Default value is 0.
2415*/
e59058c4
JS
2416
2417/**
3621a710 2418 * lpfc_topology_set - Set the adapters topology field
e59058c4
JS
2419 * @phba: lpfc_hba pointer.
2420 * @val: topology value.
2421 *
2422 * Description:
2423 * If val is in a valid range then set the adapter's topology field and
2424 * issue a lip; if the lip fails reset the topology to the old value.
2425 *
2426 * If the value is not in range log a kernel error message and return an error.
2427 *
2428 * Returns:
2429 * zero if val is in range and lip okay
2430 * non-zero return value from lpfc_issue_lip()
2431 * -EINVAL val out of range
2432 **/
a257bf90
JS
2433static ssize_t
2434lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2435 const char *buf, size_t count)
83108bd3 2436{
a257bf90
JS
2437 struct Scsi_Host *shost = class_to_shost(dev);
2438 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2439 struct lpfc_hba *phba = vport->phba;
2440 int val = 0;
2441 int nolip = 0;
2442 const char *val_buf = buf;
83108bd3
JS
2443 int err;
2444 uint32_t prev_val;
a257bf90
JS
2445
2446 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2447 nolip = 1;
2448 val_buf = &buf[strlen("nolip ")];
2449 }
2450
2451 if (!isdigit(val_buf[0]))
2452 return -EINVAL;
2453 if (sscanf(val_buf, "%i", &val) != 1)
2454 return -EINVAL;
2455
83108bd3
JS
2456 if (val >= 0 && val <= 6) {
2457 prev_val = phba->cfg_topology;
2458 phba->cfg_topology = val;
a257bf90
JS
2459 if (nolip)
2460 return strlen(buf);
2461
83108bd3 2462 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
a257bf90 2463 if (err) {
83108bd3 2464 phba->cfg_topology = prev_val;
a257bf90
JS
2465 return -EINVAL;
2466 } else
2467 return strlen(buf);
83108bd3
JS
2468 }
2469 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2470 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2471 "allowed range is [0, 6]\n",
2472 phba->brd_no, val);
2473 return -EINVAL;
2474}
2475static int lpfc_topology = 0;
2476module_param(lpfc_topology, int, 0);
2477MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2478lpfc_param_show(topology)
2479lpfc_param_init(topology, 0, 0, 6)
ee959b00 2480static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
83108bd3 2481 lpfc_topology_show, lpfc_topology_store);
dea3101e 2482
21e9a0a5
JS
2483/**
2484 * lpfc_static_vport_show: Read callback function for
2485 * lpfc_static_vport sysfs file.
2486 * @dev: Pointer to class device object.
2487 * @attr: device attribute structure.
2488 * @buf: Data buffer.
2489 *
2490 * This function is the read call back function for
2491 * lpfc_static_vport sysfs file. The lpfc_static_vport
2492 * sysfs file report the mageability of the vport.
2493 **/
2494static ssize_t
2495lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2496 char *buf)
2497{
2498 struct Scsi_Host *shost = class_to_shost(dev);
2499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2500 if (vport->vport_flag & STATIC_VPORT)
2501 sprintf(buf, "1\n");
2502 else
2503 sprintf(buf, "0\n");
2504
2505 return strlen(buf);
2506}
2507
2508/*
2509 * Sysfs attribute to control the statistical data collection.
2510 */
2511static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2512 lpfc_static_vport_show, NULL);
ea2151b4
JS
2513
2514/**
3621a710 2515 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
ea2151b4
JS
2516 * @dev: Pointer to class device.
2517 * @buf: Data buffer.
2518 * @count: Size of the data buffer.
2519 *
2520 * This function get called when an user write to the lpfc_stat_data_ctrl
2521 * sysfs file. This function parse the command written to the sysfs file
2522 * and take appropriate action. These commands are used for controlling
2523 * driver statistical data collection.
2524 * Following are the command this function handles.
2525 *
2526 * setbucket <bucket_type> <base> <step>
2527 * = Set the latency buckets.
2528 * destroybucket = destroy all the buckets.
2529 * start = start data collection
2530 * stop = stop data collection
2531 * reset = reset the collected data
2532 **/
2533static ssize_t
2534lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2535 const char *buf, size_t count)
2536{
2537 struct Scsi_Host *shost = class_to_shost(dev);
2538 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2539 struct lpfc_hba *phba = vport->phba;
2540#define LPFC_MAX_DATA_CTRL_LEN 1024
2541 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2542 unsigned long i;
2543 char *str_ptr, *token;
2544 struct lpfc_vport **vports;
2545 struct Scsi_Host *v_shost;
2546 char *bucket_type_str, *base_str, *step_str;
2547 unsigned long base, step, bucket_type;
2548
2549 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
a257bf90 2550 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
ea2151b4
JS
2551 return -EINVAL;
2552
2553 strcpy(bucket_data, buf);
2554 str_ptr = &bucket_data[0];
2555 /* Ignore this token - this is command token */
2556 token = strsep(&str_ptr, "\t ");
2557 if (!token)
2558 return -EINVAL;
2559
2560 bucket_type_str = strsep(&str_ptr, "\t ");
2561 if (!bucket_type_str)
2562 return -EINVAL;
2563
2564 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2565 bucket_type = LPFC_LINEAR_BUCKET;
2566 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2567 bucket_type = LPFC_POWER2_BUCKET;
2568 else
2569 return -EINVAL;
2570
2571 base_str = strsep(&str_ptr, "\t ");
2572 if (!base_str)
2573 return -EINVAL;
2574 base = simple_strtoul(base_str, NULL, 0);
2575
2576 step_str = strsep(&str_ptr, "\t ");
2577 if (!step_str)
2578 return -EINVAL;
2579 step = simple_strtoul(step_str, NULL, 0);
2580 if (!step)
2581 return -EINVAL;
2582
2583 /* Block the data collection for every vport */
2584 vports = lpfc_create_vport_work_array(phba);
2585 if (vports == NULL)
2586 return -ENOMEM;
2587
f4b4c68f 2588 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
ea2151b4
JS
2589 v_shost = lpfc_shost_from_vport(vports[i]);
2590 spin_lock_irq(v_shost->host_lock);
2591 /* Block and reset data collection */
2592 vports[i]->stat_data_blocked = 1;
2593 if (vports[i]->stat_data_enabled)
2594 lpfc_vport_reset_stat_data(vports[i]);
2595 spin_unlock_irq(v_shost->host_lock);
2596 }
2597
2598 /* Set the bucket attributes */
2599 phba->bucket_type = bucket_type;
2600 phba->bucket_base = base;
2601 phba->bucket_step = step;
2602
f4b4c68f 2603 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
ea2151b4
JS
2604 v_shost = lpfc_shost_from_vport(vports[i]);
2605
2606 /* Unblock data collection */
2607 spin_lock_irq(v_shost->host_lock);
2608 vports[i]->stat_data_blocked = 0;
2609 spin_unlock_irq(v_shost->host_lock);
2610 }
2611 lpfc_destroy_vport_work_array(phba, vports);
2612 return strlen(buf);
2613 }
2614
2615 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2616 vports = lpfc_create_vport_work_array(phba);
2617 if (vports == NULL)
2618 return -ENOMEM;
2619
f4b4c68f 2620 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
ea2151b4
JS
2621 v_shost = lpfc_shost_from_vport(vports[i]);
2622 spin_lock_irq(shost->host_lock);
2623 vports[i]->stat_data_blocked = 1;
2624 lpfc_free_bucket(vport);
2625 vport->stat_data_enabled = 0;
2626 vports[i]->stat_data_blocked = 0;
2627 spin_unlock_irq(shost->host_lock);
2628 }
2629 lpfc_destroy_vport_work_array(phba, vports);
2630 phba->bucket_type = LPFC_NO_BUCKET;
2631 phba->bucket_base = 0;
2632 phba->bucket_step = 0;
2633 return strlen(buf);
2634 }
2635
2636 if (!strncmp(buf, "start", strlen("start"))) {
2637 /* If no buckets configured return error */
2638 if (phba->bucket_type == LPFC_NO_BUCKET)
2639 return -EINVAL;
2640 spin_lock_irq(shost->host_lock);
2641 if (vport->stat_data_enabled) {
2642 spin_unlock_irq(shost->host_lock);
2643 return strlen(buf);
2644 }
2645 lpfc_alloc_bucket(vport);
2646 vport->stat_data_enabled = 1;
2647 spin_unlock_irq(shost->host_lock);
2648 return strlen(buf);
2649 }
2650
2651 if (!strncmp(buf, "stop", strlen("stop"))) {
2652 spin_lock_irq(shost->host_lock);
2653 if (vport->stat_data_enabled == 0) {
2654 spin_unlock_irq(shost->host_lock);
2655 return strlen(buf);
2656 }
2657 lpfc_free_bucket(vport);
2658 vport->stat_data_enabled = 0;
2659 spin_unlock_irq(shost->host_lock);
2660 return strlen(buf);
2661 }
2662
2663 if (!strncmp(buf, "reset", strlen("reset"))) {
2664 if ((phba->bucket_type == LPFC_NO_BUCKET)
2665 || !vport->stat_data_enabled)
2666 return strlen(buf);
2667 spin_lock_irq(shost->host_lock);
2668 vport->stat_data_blocked = 1;
2669 lpfc_vport_reset_stat_data(vport);
2670 vport->stat_data_blocked = 0;
2671 spin_unlock_irq(shost->host_lock);
2672 return strlen(buf);
2673 }
2674 return -EINVAL;
2675}
2676
2677
2678/**
3621a710 2679 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
ea2151b4
JS
2680 * @dev: Pointer to class device object.
2681 * @buf: Data buffer.
2682 *
2683 * This function is the read call back function for
2684 * lpfc_stat_data_ctrl sysfs file. This function report the
2685 * current statistical data collection state.
2686 **/
2687static ssize_t
2688lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2689 char *buf)
2690{
2691 struct Scsi_Host *shost = class_to_shost(dev);
2692 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2693 struct lpfc_hba *phba = vport->phba;
2694 int index = 0;
2695 int i;
2696 char *bucket_type;
2697 unsigned long bucket_value;
2698
2699 switch (phba->bucket_type) {
2700 case LPFC_LINEAR_BUCKET:
2701 bucket_type = "linear";
2702 break;
2703 case LPFC_POWER2_BUCKET:
2704 bucket_type = "power2";
2705 break;
2706 default:
2707 bucket_type = "No Bucket";
2708 break;
2709 }
2710
2711 sprintf(&buf[index], "Statistical Data enabled :%d, "
2712 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2713 " Bucket step :%d\nLatency Ranges :",
2714 vport->stat_data_enabled, vport->stat_data_blocked,
2715 bucket_type, phba->bucket_base, phba->bucket_step);
2716 index = strlen(buf);
2717 if (phba->bucket_type != LPFC_NO_BUCKET) {
2718 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2719 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2720 bucket_value = phba->bucket_base +
2721 phba->bucket_step * i;
2722 else
2723 bucket_value = phba->bucket_base +
2724 (1 << i) * phba->bucket_step;
2725
2726 if (index + 10 > PAGE_SIZE)
2727 break;
2728 sprintf(&buf[index], "%08ld ", bucket_value);
2729 index = strlen(buf);
2730 }
2731 }
2732 sprintf(&buf[index], "\n");
2733 return strlen(buf);
2734}
2735
2736/*
2737 * Sysfs attribute to control the statistical data collection.
2738 */
2739static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2740 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2741
2742/*
2743 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2744 */
2745
2746/*
2747 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2748 * for each target.
2749 */
2750#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2751#define MAX_STAT_DATA_SIZE_PER_TARGET \
2752 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2753
2754
2755/**
3621a710 2756 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2c3c8bea 2757 * @filp: sysfs file
ea2151b4
JS
2758 * @kobj: Pointer to the kernel object
2759 * @bin_attr: Attribute object
2760 * @buff: Buffer pointer
2761 * @off: File offset
2762 * @count: Buffer size
2763 *
2764 * This function is the read call back function for lpfc_drvr_stat_data
2765 * sysfs file. This function export the statistical data to user
2766 * applications.
2767 **/
2768static ssize_t
2c3c8bea
CW
2769sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2770 struct bin_attribute *bin_attr,
ea2151b4
JS
2771 char *buf, loff_t off, size_t count)
2772{
2773 struct device *dev = container_of(kobj, struct device,
2774 kobj);
2775 struct Scsi_Host *shost = class_to_shost(dev);
2776 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2777 struct lpfc_hba *phba = vport->phba;
2778 int i = 0, index = 0;
2779 unsigned long nport_index;
2780 struct lpfc_nodelist *ndlp = NULL;
2781 nport_index = (unsigned long)off /
2782 MAX_STAT_DATA_SIZE_PER_TARGET;
2783
2784 if (!vport->stat_data_enabled || vport->stat_data_blocked
2785 || (phba->bucket_type == LPFC_NO_BUCKET))
2786 return 0;
2787
2788 spin_lock_irq(shost->host_lock);
2789 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2790 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2791 continue;
2792
2793 if (nport_index > 0) {
2794 nport_index--;
2795 continue;
2796 }
2797
2798 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2799 > count)
2800 break;
2801
2802 if (!ndlp->lat_data)
2803 continue;
2804
2805 /* Print the WWN */
2806 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2807 ndlp->nlp_portname.u.wwn[0],
2808 ndlp->nlp_portname.u.wwn[1],
2809 ndlp->nlp_portname.u.wwn[2],
2810 ndlp->nlp_portname.u.wwn[3],
2811 ndlp->nlp_portname.u.wwn[4],
2812 ndlp->nlp_portname.u.wwn[5],
2813 ndlp->nlp_portname.u.wwn[6],
2814 ndlp->nlp_portname.u.wwn[7]);
2815
2816 index = strlen(buf);
2817
2818 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2819 sprintf(&buf[index], "%010u,",
2820 ndlp->lat_data[i].cmd_count);
2821 index = strlen(buf);
2822 }
2823 sprintf(&buf[index], "\n");
2824 index = strlen(buf);
2825 }
2826 spin_unlock_irq(shost->host_lock);
2827 return index;
2828}
2829
2830static struct bin_attribute sysfs_drvr_stat_data_attr = {
2831 .attr = {
2832 .name = "lpfc_drvr_stat_data",
2833 .mode = S_IRUSR,
ea2151b4
JS
2834 },
2835 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2836 .read = sysfs_drvr_stat_data_read,
2837 .write = NULL,
2838};
2839
dea3101e 2840/*
2841# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2842# connection.
76a95d75 2843# Value range is [0,16]. Default value is 0.
dea3101e 2844*/
e59058c4 2845/**
3621a710 2846 * lpfc_link_speed_set - Set the adapters link speed
e59058c4
JS
2847 * @phba: lpfc_hba pointer.
2848 * @val: link speed value.
2849 *
2850 * Description:
2851 * If val is in a valid range then set the adapter's link speed field and
2852 * issue a lip; if the lip fails reset the link speed to the old value.
2853 *
2854 * Notes:
2855 * If the value is not in range log a kernel error message and return an error.
2856 *
2857 * Returns:
2858 * zero if val is in range and lip okay.
2859 * non-zero return value from lpfc_issue_lip()
2860 * -EINVAL val out of range
2861 **/
a257bf90
JS
2862static ssize_t
2863lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2864 const char *buf, size_t count)
83108bd3 2865{
a257bf90
JS
2866 struct Scsi_Host *shost = class_to_shost(dev);
2867 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2868 struct lpfc_hba *phba = vport->phba;
76a95d75 2869 int val = LPFC_USER_LINK_SPEED_AUTO;
a257bf90
JS
2870 int nolip = 0;
2871 const char *val_buf = buf;
83108bd3
JS
2872 int err;
2873 uint32_t prev_val;
2874
a257bf90
JS
2875 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2876 nolip = 1;
2877 val_buf = &buf[strlen("nolip ")];
2878 }
2879
2880 if (!isdigit(val_buf[0]))
2881 return -EINVAL;
2882 if (sscanf(val_buf, "%i", &val) != 1)
2883 return -EINVAL;
2884
76a95d75
JS
2885 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2886 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2887 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2888 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2889 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
2890 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
2891 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2892 "2879 lpfc_link_speed attribute cannot be set "
2893 "to %d. Speed is not supported by this port.\n",
2894 val);
83108bd3 2895 return -EINVAL;
76a95d75
JS
2896 }
2897 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2898 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
83108bd3
JS
2899 prev_val = phba->cfg_link_speed;
2900 phba->cfg_link_speed = val;
a257bf90
JS
2901 if (nolip)
2902 return strlen(buf);
2903
83108bd3 2904 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
a257bf90 2905 if (err) {
83108bd3 2906 phba->cfg_link_speed = prev_val;
a257bf90
JS
2907 return -EINVAL;
2908 } else
2909 return strlen(buf);
83108bd3 2910 }
83108bd3 2911 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
76a95d75
JS
2912 "0469 lpfc_link_speed attribute cannot be set to %d, "
2913 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
83108bd3
JS
2914 return -EINVAL;
2915}
2916
2917static int lpfc_link_speed = 0;
2918module_param(lpfc_link_speed, int, 0);
2919MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2920lpfc_param_show(link_speed)
e59058c4
JS
2921
2922/**
3621a710 2923 * lpfc_link_speed_init - Set the adapters link speed
e59058c4
JS
2924 * @phba: lpfc_hba pointer.
2925 * @val: link speed value.
2926 *
2927 * Description:
2928 * If val is in a valid range then set the adapter's link speed field.
2929 *
2930 * Notes:
2931 * If the value is not in range log a kernel error message, clear the link
2932 * speed and return an error.
2933 *
2934 * Returns:
2935 * zero if val saved.
2936 * -EINVAL val out of range
2937 **/
83108bd3
JS
2938static int
2939lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2940{
76a95d75
JS
2941 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2942 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
83108bd3
JS
2943 phba->cfg_link_speed = val;
2944 return 0;
2945 }
2946 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
d7c255b2 2947 "0405 lpfc_link_speed attribute cannot "
83108bd3
JS
2948 "be set to %d, allowed values are "
2949 "["LPFC_LINK_SPEED_STRING"]\n", val);
76a95d75 2950 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
83108bd3
JS
2951 return -EINVAL;
2952}
2953
ee959b00 2954static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
76a95d75 2955 lpfc_link_speed_show, lpfc_link_speed_store);
dea3101e 2956
0d878419
JS
2957/*
2958# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2959# 0 = aer disabled or not supported
2960# 1 = aer supported and enabled (default)
2961# Value range is [0,1]. Default value is 1.
2962*/
2963
2964/**
2965 * lpfc_aer_support_store - Set the adapter for aer support
2966 *
2967 * @dev: class device that is converted into a Scsi_host.
2968 * @attr: device attribute, not used.
2969 * @buf: containing the string "selective".
2970 * @count: unused variable.
2971 *
2972 * Description:
2973 * If the val is 1 and currently the device's AER capability was not
2974 * enabled, invoke the kernel's enable AER helper routine, trying to
2975 * enable the device's AER capability. If the helper routine enabling
2976 * AER returns success, update the device's cfg_aer_support flag to
2977 * indicate AER is supported by the device; otherwise, if the device
2978 * AER capability is already enabled to support AER, then do nothing.
2979 *
2980 * If the val is 0 and currently the device's AER support was enabled,
2981 * invoke the kernel's disable AER helper routine. After that, update
2982 * the device's cfg_aer_support flag to indicate AER is not supported
2983 * by the device; otherwise, if the device AER capability is already
2984 * disabled from supporting AER, then do nothing.
2985 *
2986 * Returns:
2987 * length of the buf on success if val is in range the intended mode
2988 * is supported.
2989 * -EINVAL if val out of range or intended mode is not supported.
2990 **/
2991static ssize_t
2992lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
2993 const char *buf, size_t count)
2994{
2995 struct Scsi_Host *shost = class_to_shost(dev);
2996 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
2997 struct lpfc_hba *phba = vport->phba;
2998 int val = 0, rc = -EINVAL;
2999
3000 if (!isdigit(buf[0]))
3001 return -EINVAL;
3002 if (sscanf(buf, "%i", &val) != 1)
3003 return -EINVAL;
3004
3005 switch (val) {
3006 case 0:
3007 if (phba->hba_flag & HBA_AER_ENABLED) {
3008 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3009 if (!rc) {
3010 spin_lock_irq(&phba->hbalock);
3011 phba->hba_flag &= ~HBA_AER_ENABLED;
3012 spin_unlock_irq(&phba->hbalock);
3013 phba->cfg_aer_support = 0;
3014 rc = strlen(buf);
3015 } else
891478a2
JS
3016 rc = -EPERM;
3017 } else {
0d878419 3018 phba->cfg_aer_support = 0;
891478a2
JS
3019 rc = strlen(buf);
3020 }
0d878419
JS
3021 break;
3022 case 1:
3023 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3024 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3025 if (!rc) {
3026 spin_lock_irq(&phba->hbalock);
3027 phba->hba_flag |= HBA_AER_ENABLED;
3028 spin_unlock_irq(&phba->hbalock);
3029 phba->cfg_aer_support = 1;
3030 rc = strlen(buf);
3031 } else
891478a2
JS
3032 rc = -EPERM;
3033 } else {
0d878419 3034 phba->cfg_aer_support = 1;
891478a2
JS
3035 rc = strlen(buf);
3036 }
0d878419
JS
3037 break;
3038 default:
3039 rc = -EINVAL;
3040 break;
3041 }
3042 return rc;
3043}
3044
3045static int lpfc_aer_support = 1;
3046module_param(lpfc_aer_support, int, 1);
3047MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3048lpfc_param_show(aer_support)
3049
3050/**
3051 * lpfc_aer_support_init - Set the initial adapters aer support flag
3052 * @phba: lpfc_hba pointer.
3053 * @val: link speed value.
3054 *
3055 * Description:
3056 * If val is in a valid range [0,1], then set the adapter's initial
3057 * cfg_aer_support field. It will be up to the driver's probe_one
3058 * routine to determine whether the device's AER support can be set
3059 * or not.
3060 *
3061 * Notes:
3062 * If the value is not in range log a kernel error message, and
3063 * choose the default value of setting AER support and return.
3064 *
3065 * Returns:
3066 * zero if val saved.
3067 * -EINVAL val out of range
3068 **/
3069static int
3070lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3071{
3072 if (val == 0 || val == 1) {
3073 phba->cfg_aer_support = val;
3074 return 0;
3075 }
3076 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3077 "2712 lpfc_aer_support attribute value %d out "
3078 "of range, allowed values are 0|1, setting it "
3079 "to default value of 1\n", val);
891478a2 3080 /* By default, try to enable AER on a device */
0d878419
JS
3081 phba->cfg_aer_support = 1;
3082 return -EINVAL;
3083}
3084
3085static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3086 lpfc_aer_support_show, lpfc_aer_support_store);
3087
3088/**
3089 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3090 * @dev: class device that is converted into a Scsi_host.
3091 * @attr: device attribute, not used.
3092 * @buf: containing the string "selective".
3093 * @count: unused variable.
3094 *
3095 * Description:
3096 * If the @buf contains 1 and the device currently has the AER support
3097 * enabled, then invokes the kernel AER helper routine
3098 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3099 * error status register.
3100 *
3101 * Notes:
3102 *
3103 * Returns:
3104 * -EINVAL if the buf does not contain the 1 or the device is not currently
3105 * enabled with the AER support.
3106 **/
3107static ssize_t
3108lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3109 const char *buf, size_t count)
3110{
3111 struct Scsi_Host *shost = class_to_shost(dev);
3112 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3113 struct lpfc_hba *phba = vport->phba;
3114 int val, rc = -1;
3115
3116 if (!isdigit(buf[0]))
3117 return -EINVAL;
3118 if (sscanf(buf, "%i", &val) != 1)
3119 return -EINVAL;
891478a2
JS
3120 if (val != 1)
3121 return -EINVAL;
0d878419 3122
891478a2 3123 if (phba->hba_flag & HBA_AER_ENABLED)
0d878419
JS
3124 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3125
3126 if (rc == 0)
3127 return strlen(buf);
3128 else
891478a2 3129 return -EPERM;
0d878419
JS
3130}
3131
3132static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3133 lpfc_aer_cleanup_state);
3134
dea3101e 3135/*
3136# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3137# Value range is [2,3]. Default value is 3.
3138*/
3de2a653
JS
3139LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3140 "Select Fibre Channel class of service for FCP sequences");
dea3101e 3141
3142/*
3143# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3144# is [0,1]. Default value is 0.
3145*/
3de2a653
JS
3146LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3147 "Use ADISC on rediscovery to authenticate FCP devices");
dea3101e 3148
977b5a0a
JS
3149/*
3150# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3151# depth. Default value is 0. When the value of this parameter is zero the
3152# SCSI command completion time is not used for controlling I/O queue depth. When
3153# the parameter is set to a non-zero value, the I/O queue depth is controlled
3154# to limit the I/O completion time to the parameter value.
3155# The value is set in milliseconds.
3156*/
3157static int lpfc_max_scsicmpl_time;
3158module_param(lpfc_max_scsicmpl_time, int, 0);
3159MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3160 "Use command completion time to control queue depth");
3161lpfc_vport_param_show(max_scsicmpl_time);
3162lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3163static int
3164lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3165{
3166 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3167 struct lpfc_nodelist *ndlp, *next_ndlp;
3168
3169 if (val == vport->cfg_max_scsicmpl_time)
3170 return 0;
3171 if ((val < 0) || (val > 60000))
3172 return -EINVAL;
3173 vport->cfg_max_scsicmpl_time = val;
3174
3175 spin_lock_irq(shost->host_lock);
3176 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3177 if (!NLP_CHK_NODE_ACT(ndlp))
3178 continue;
3179 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3180 continue;
7dc517df 3181 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
977b5a0a
JS
3182 }
3183 spin_unlock_irq(shost->host_lock);
3184 return 0;
3185}
3186lpfc_vport_param_store(max_scsicmpl_time);
3187static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3188 lpfc_max_scsicmpl_time_show,
3189 lpfc_max_scsicmpl_time_store);
3190
dea3101e 3191/*
3192# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3193# range is [0,1]. Default value is 0.
3194*/
3195LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3196
3197/*
3198# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3199# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
7054a606 3200# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea3101e 3201# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3202# cr_delay is set to 0.
3203*/
8189fd19 3204LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea3101e 3205 "interrupt response is generated");
3206
8189fd19 3207LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea3101e 3208 "interrupt response is generated");
3209
cf5bf97e
JW
3210/*
3211# lpfc_multi_ring_support: Determines how many rings to spread available
3212# cmd/rsp IOCB entries across.
3213# Value range is [1,2]. Default value is 1.
3214*/
3215LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3216 "SLI rings to spread IOCB entries across");
3217
a4bc3379
JS
3218/*
3219# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3220# identifies what rctl value to configure the additional ring for.
3221# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3222*/
6a9c52cf 3223LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
a4bc3379
JS
3224 255, "Identifies RCTL for additional ring configuration");
3225
3226/*
3227# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3228# identifies what type value to configure the additional ring for.
3229# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3230*/
6a9c52cf 3231LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
a4bc3379
JS
3232 255, "Identifies TYPE for additional ring configuration");
3233
dea3101e 3234/*
3235# lpfc_fdmi_on: controls FDMI support.
3236# 0 = no FDMI support
3237# 1 = support FDMI without attribute of hostname
3238# 2 = support FDMI with attribute of hostname
3239# Value range [0,2]. Default value is 0.
3240*/
3de2a653 3241LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea3101e 3242
3243/*
3244# Specifies the maximum number of ELS cmds we can have outstanding (for
3245# discovery). Value range is [1,64]. Default value = 32.
3246*/
3de2a653 3247LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea3101e 3248 "during discovery");
3249
3250/*
65a29c16
JS
3251# lpfc_max_luns: maximum allowed LUN.
3252# Value range is [0,65535]. Default value is 255.
3253# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea3101e 3254*/
3de2a653 3255LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea3101e 3256
875fbdfe
JSEC
3257/*
3258# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3259# Value range is [1,255], default value is 10.
3260*/
3261LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3262 "Milliseconds driver will wait between polling FCP ring");
3263
4ff43246
JS
3264/*
3265# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3266# support this feature
8605c46c 3267# 0 = MSI disabled
4ff43246 3268# 1 = MSI enabled
8605c46c
GK
3269# 2 = MSI-X enabled (default)
3270# Value range is [0,2]. Default value is 2.
4ff43246 3271*/
8605c46c 3272LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
db2378e0 3273 "MSI-X (2), if possible");
4ff43246 3274
da0436e9
JS
3275/*
3276# lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3277#
3278# Value range is [636,651042]. Default value is 10000.
3279*/
3280LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3281 "Set the maximum number of fast-path FCP interrupts per second");
3282
3283/*
3284# lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3285#
3286# Value range is [1,31]. Default value is 4.
3287*/
3288LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3289 "Set the number of fast-path FCP work queues, if possible");
3290
3291/*
3292# lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3293#
3294# Value range is [1,7]. Default value is 1.
3295*/
3296LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3297 "Set the number of fast-path FCP event queues, if possible");
3298
13815c83
JS
3299/*
3300# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3301# 0 = HBA resets disabled
3302# 1 = HBA resets enabled (default)
3303# Value range is [0,1]. Default value is 1.
3304*/
3305LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
c3f28afa 3306
13815c83
JS
3307/*
3308# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
3309# 0 = HBA Heartbeat disabled
3310# 1 = HBA Heartbeat enabled (default)
3311# Value range is [0,1]. Default value is 1.
3312*/
3313LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
92d7f7b0 3314
81301a9b
JS
3315/*
3316# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3317# 0 = BlockGuard disabled (default)
3318# 1 = BlockGuard enabled
3319# Value range is [0,1]. Default value is 0.
3320*/
3321LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3322
81301a9b
JS
3323/*
3324# lpfc_prot_mask: i
3325# - Bit mask of host protection capabilities used to register with the
3326# SCSI mid-layer
3327# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3328# - Allows you to ultimately specify which profiles to use
3329# - Default will result in registering capabilities for all profiles.
3330#
3331*/
bc73905a 3332unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION;
81301a9b
JS
3333
3334module_param(lpfc_prot_mask, uint, 0);
3335MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3336
3337/*
3338# lpfc_prot_guard: i
3339# - Bit mask of protection guard types to register with the SCSI mid-layer
3340# - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3341# - Allows you to ultimately specify which profiles to use
3342# - Default will result in registering capabilities for all guard types
3343#
3344*/
3345unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3346module_param(lpfc_prot_guard, byte, 0);
3347MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3348
3349
83108bd3 3350/*
3621a710 3351 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
83108bd3
JS
3352 * This value can be set to values between 64 and 256. The default value is
3353 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3354 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3355 */
3356LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3357 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3358
81301a9b
JS
3359LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3360 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3361 "Max Protection Scatter Gather Segment Count");
3362
ee959b00 3363struct device_attribute *lpfc_hba_attrs[] = {
81301a9b
JS
3364 &dev_attr_bg_info,
3365 &dev_attr_bg_guard_err,
3366 &dev_attr_bg_apptag_err,
3367 &dev_attr_bg_reftag_err,
ee959b00
TJ
3368 &dev_attr_info,
3369 &dev_attr_serialnum,
3370 &dev_attr_modeldesc,
3371 &dev_attr_modelname,
3372 &dev_attr_programtype,
3373 &dev_attr_portnum,
3374 &dev_attr_fwrev,
3375 &dev_attr_hdw,
3376 &dev_attr_option_rom_version,
bbd1ae41 3377 &dev_attr_link_state,
ee959b00 3378 &dev_attr_num_discovered_ports,
84774a4d 3379 &dev_attr_menlo_mgmt_mode,
ee959b00 3380 &dev_attr_lpfc_drvr_version,
45ed1190 3381 &dev_attr_lpfc_enable_fip,
ee959b00
TJ
3382 &dev_attr_lpfc_temp_sensor,
3383 &dev_attr_lpfc_log_verbose,
3384 &dev_attr_lpfc_lun_queue_depth,
7dc517df 3385 &dev_attr_lpfc_tgt_queue_depth,
ee959b00
TJ
3386 &dev_attr_lpfc_hba_queue_depth,
3387 &dev_attr_lpfc_peer_port_login,
3388 &dev_attr_lpfc_nodev_tmo,
3389 &dev_attr_lpfc_devloss_tmo,
3390 &dev_attr_lpfc_fcp_class,
3391 &dev_attr_lpfc_use_adisc,
3392 &dev_attr_lpfc_ack0,
3393 &dev_attr_lpfc_topology,
3394 &dev_attr_lpfc_scan_down,
3395 &dev_attr_lpfc_link_speed,
3396 &dev_attr_lpfc_cr_delay,
3397 &dev_attr_lpfc_cr_count,
3398 &dev_attr_lpfc_multi_ring_support,
3399 &dev_attr_lpfc_multi_ring_rctl,
3400 &dev_attr_lpfc_multi_ring_type,
3401 &dev_attr_lpfc_fdmi_on,
3402 &dev_attr_lpfc_max_luns,
3403 &dev_attr_lpfc_enable_npiv,
19ca7609 3404 &dev_attr_lpfc_enable_rrq,
ee959b00
TJ
3405 &dev_attr_nport_evt_cnt,
3406 &dev_attr_board_mode,
3407 &dev_attr_max_vpi,
3408 &dev_attr_used_vpi,
3409 &dev_attr_max_rpi,
3410 &dev_attr_used_rpi,
3411 &dev_attr_max_xri,
3412 &dev_attr_used_xri,
3413 &dev_attr_npiv_info,
3414 &dev_attr_issue_reset,
3415 &dev_attr_lpfc_poll,
3416 &dev_attr_lpfc_poll_tmo,
3417 &dev_attr_lpfc_use_msi,
da0436e9
JS
3418 &dev_attr_lpfc_fcp_imax,
3419 &dev_attr_lpfc_fcp_wq_count,
3420 &dev_attr_lpfc_fcp_eq_count,
81301a9b 3421 &dev_attr_lpfc_enable_bg,
ee959b00
TJ
3422 &dev_attr_lpfc_soft_wwnn,
3423 &dev_attr_lpfc_soft_wwpn,
3424 &dev_attr_lpfc_soft_wwn_enable,
3425 &dev_attr_lpfc_enable_hba_reset,
3426 &dev_attr_lpfc_enable_hba_heartbeat,
3427 &dev_attr_lpfc_sg_seg_cnt,
977b5a0a 3428 &dev_attr_lpfc_max_scsicmpl_time,
ea2151b4 3429 &dev_attr_lpfc_stat_data_ctrl,
81301a9b 3430 &dev_attr_lpfc_prot_sg_seg_cnt,
0d878419
JS
3431 &dev_attr_lpfc_aer_support,
3432 &dev_attr_lpfc_aer_state_cleanup,
84d1b006 3433 &dev_attr_lpfc_suppress_link_up,
2a9bf3d0
JS
3434 &dev_attr_lpfc_iocb_cnt,
3435 &dev_attr_iocb_hw,
3436 &dev_attr_txq_hw,
3437 &dev_attr_txcmplq_hw,
bc73905a
JS
3438 &dev_attr_lpfc_fips_level,
3439 &dev_attr_lpfc_fips_rev,
dea3101e 3440 NULL,
3441};
3442
ee959b00
TJ
3443struct device_attribute *lpfc_vport_attrs[] = {
3444 &dev_attr_info,
bbd1ae41 3445 &dev_attr_link_state,
ee959b00
TJ
3446 &dev_attr_num_discovered_ports,
3447 &dev_attr_lpfc_drvr_version,
3448 &dev_attr_lpfc_log_verbose,
3449 &dev_attr_lpfc_lun_queue_depth,
7dc517df 3450 &dev_attr_lpfc_tgt_queue_depth,
ee959b00
TJ
3451 &dev_attr_lpfc_nodev_tmo,
3452 &dev_attr_lpfc_devloss_tmo,
3453 &dev_attr_lpfc_hba_queue_depth,
3454 &dev_attr_lpfc_peer_port_login,
3455 &dev_attr_lpfc_restrict_login,
3456 &dev_attr_lpfc_fcp_class,
3457 &dev_attr_lpfc_use_adisc,
3458 &dev_attr_lpfc_fdmi_on,
3459 &dev_attr_lpfc_max_luns,
3460 &dev_attr_nport_evt_cnt,
3461 &dev_attr_npiv_info,
3462 &dev_attr_lpfc_enable_da_id,
ea2151b4
JS
3463 &dev_attr_lpfc_max_scsicmpl_time,
3464 &dev_attr_lpfc_stat_data_ctrl,
21e9a0a5 3465 &dev_attr_lpfc_static_vport,
bc73905a
JS
3466 &dev_attr_lpfc_fips_level,
3467 &dev_attr_lpfc_fips_rev,
3de2a653
JS
3468 NULL,
3469};
3470
e59058c4 3471/**
3621a710 3472 * sysfs_ctlreg_write - Write method for writing to ctlreg
2c3c8bea 3473 * @filp: open sysfs file
e59058c4
JS
3474 * @kobj: kernel kobject that contains the kernel class device.
3475 * @bin_attr: kernel attributes passed to us.
3476 * @buf: contains the data to be written to the adapter IOREG space.
3477 * @off: offset into buffer to beginning of data.
3478 * @count: bytes to transfer.
3479 *
3480 * Description:
3481 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3482 * Uses the adapter io control registers to send buf contents to the adapter.
3483 *
3484 * Returns:
3485 * -ERANGE off and count combo out of range
3486 * -EINVAL off, count or buff address invalid
3487 * -EPERM adapter is offline
3488 * value of count, buf contents written
3489 **/
dea3101e 3490static ssize_t
2c3c8bea
CW
3491sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3492 struct bin_attribute *bin_attr,
91a69029 3493 char *buf, loff_t off, size_t count)
dea3101e 3494{
3495 size_t buf_off;
ee959b00
TJ
3496 struct device *dev = container_of(kobj, struct device, kobj);
3497 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
3498 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3499 struct lpfc_hba *phba = vport->phba;
dea3101e 3500
f1126688
JS
3501 if (phba->sli_rev >= LPFC_SLI_REV4)
3502 return -EPERM;
3503
dea3101e 3504 if ((off + count) > FF_REG_AREA_SIZE)
3505 return -ERANGE;
3506
3507 if (count == 0) return 0;
3508
3509 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3510 return -EINVAL;
3511
2e0fef85 3512 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea3101e 3513 return -EPERM;
3514 }
3515
2e0fef85 3516 spin_lock_irq(&phba->hbalock);
dea3101e 3517 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3518 writel(*((uint32_t *)(buf + buf_off)),
3519 phba->ctrl_regs_memmap_p + off + buf_off);
3520
2e0fef85 3521 spin_unlock_irq(&phba->hbalock);
dea3101e 3522
3523 return count;
3524}
3525
e59058c4 3526/**
3621a710 3527 * sysfs_ctlreg_read - Read method for reading from ctlreg
2c3c8bea 3528 * @filp: open sysfs file
e59058c4
JS
3529 * @kobj: kernel kobject that contains the kernel class device.
3530 * @bin_attr: kernel attributes passed to us.
af901ca1 3531 * @buf: if successful contains the data from the adapter IOREG space.
e59058c4
JS
3532 * @off: offset into buffer to beginning of data.
3533 * @count: bytes to transfer.
3534 *
3535 * Description:
3536 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3537 * Uses the adapter io control registers to read data into buf.
3538 *
3539 * Returns:
3540 * -ERANGE off and count combo out of range
3541 * -EINVAL off, count or buff address invalid
3542 * value of count, buf contents read
3543 **/
dea3101e 3544static ssize_t
2c3c8bea
CW
3545sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3546 struct bin_attribute *bin_attr,
91a69029 3547 char *buf, loff_t off, size_t count)
dea3101e 3548{
3549 size_t buf_off;
3550 uint32_t * tmp_ptr;
ee959b00
TJ
3551 struct device *dev = container_of(kobj, struct device, kobj);
3552 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
3553 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3554 struct lpfc_hba *phba = vport->phba;
dea3101e 3555
f1126688
JS
3556 if (phba->sli_rev >= LPFC_SLI_REV4)
3557 return -EPERM;
3558
dea3101e 3559 if (off > FF_REG_AREA_SIZE)
3560 return -ERANGE;
3561
3562 if ((off + count) > FF_REG_AREA_SIZE)
3563 count = FF_REG_AREA_SIZE - off;
3564
3565 if (count == 0) return 0;
3566
3567 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3568 return -EINVAL;
3569
2e0fef85 3570 spin_lock_irq(&phba->hbalock);
dea3101e 3571
3572 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3573 tmp_ptr = (uint32_t *)(buf + buf_off);
3574 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3575 }
3576
2e0fef85 3577 spin_unlock_irq(&phba->hbalock);
dea3101e 3578
3579 return count;
3580}
3581
3582static struct bin_attribute sysfs_ctlreg_attr = {
3583 .attr = {
3584 .name = "ctlreg",
3585 .mode = S_IRUSR | S_IWUSR,
dea3101e 3586 },
3587 .size = 256,
3588 .read = sysfs_ctlreg_read,
3589 .write = sysfs_ctlreg_write,
3590};
3591
e59058c4 3592/**
3621a710 3593 * sysfs_mbox_idle - frees the sysfs mailbox
e59058c4
JS
3594 * @phba: lpfc_hba pointer
3595 **/
dea3101e 3596static void
2e0fef85 3597sysfs_mbox_idle(struct lpfc_hba *phba)
dea3101e 3598{
3599 phba->sysfs_mbox.state = SMBOX_IDLE;
3600 phba->sysfs_mbox.offset = 0;
3601
3602 if (phba->sysfs_mbox.mbox) {
3603 mempool_free(phba->sysfs_mbox.mbox,
3604 phba->mbox_mem_pool);
3605 phba->sysfs_mbox.mbox = NULL;
3606 }
3607}
3608
e59058c4 3609/**
3621a710 3610 * sysfs_mbox_write - Write method for writing information via mbox
2c3c8bea 3611 * @filp: open sysfs file
e59058c4
JS
3612 * @kobj: kernel kobject that contains the kernel class device.
3613 * @bin_attr: kernel attributes passed to us.
3614 * @buf: contains the data to be written to sysfs mbox.
3615 * @off: offset into buffer to beginning of data.
3616 * @count: bytes to transfer.
3617 *
3618 * Description:
3619 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3620 * Uses the sysfs mbox to send buf contents to the adapter.
3621 *
3622 * Returns:
3623 * -ERANGE off and count combo out of range
3624 * -EINVAL off, count or buff address invalid
3625 * zero if count is zero
3626 * -EPERM adapter is offline
3627 * -ENOMEM failed to allocate memory for the mail box
3628 * -EAGAIN offset, state or mbox is NULL
3629 * count number of bytes transferred
3630 **/
dea3101e 3631static ssize_t
2c3c8bea
CW
3632sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3633 struct bin_attribute *bin_attr,
91a69029 3634 char *buf, loff_t off, size_t count)
dea3101e 3635{
ee959b00
TJ
3636 struct device *dev = container_of(kobj, struct device, kobj);
3637 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
3638 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3639 struct lpfc_hba *phba = vport->phba;
3640 struct lpfcMboxq *mbox = NULL;
dea3101e 3641
3642 if ((count + off) > MAILBOX_CMD_SIZE)
3643 return -ERANGE;
3644
3645 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3646 return -EINVAL;
3647
3648 if (count == 0)
3649 return 0;
3650
3651 if (off == 0) {
3652 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3653 if (!mbox)
3654 return -ENOMEM;
fc6c12bc 3655 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea3101e 3656 }
3657
2e0fef85 3658 spin_lock_irq(&phba->hbalock);
dea3101e 3659
3660 if (off == 0) {
3661 if (phba->sysfs_mbox.mbox)
3662 mempool_free(mbox, phba->mbox_mem_pool);
3663 else
3664 phba->sysfs_mbox.mbox = mbox;
3665 phba->sysfs_mbox.state = SMBOX_WRITING;
3666 } else {
3667 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3668 phba->sysfs_mbox.offset != off ||
92d7f7b0 3669 phba->sysfs_mbox.mbox == NULL) {
dea3101e 3670 sysfs_mbox_idle(phba);
2e0fef85 3671 spin_unlock_irq(&phba->hbalock);
8f6d98d2 3672 return -EAGAIN;
dea3101e 3673 }
3674 }
3675
04c68496 3676 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
dea3101e 3677 buf, count);
3678
3679 phba->sysfs_mbox.offset = off + count;
3680
2e0fef85 3681 spin_unlock_irq(&phba->hbalock);
dea3101e 3682
3683 return count;
3684}
3685
e59058c4 3686/**
3621a710 3687 * sysfs_mbox_read - Read method for reading information via mbox
2c3c8bea 3688 * @filp: open sysfs file
e59058c4
JS
3689 * @kobj: kernel kobject that contains the kernel class device.
3690 * @bin_attr: kernel attributes passed to us.
3691 * @buf: contains the data to be read from sysfs mbox.
3692 * @off: offset into buffer to beginning of data.
3693 * @count: bytes to transfer.
3694 *
3695 * Description:
3696 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3697 * Uses the sysfs mbox to receive data from to the adapter.
3698 *
3699 * Returns:
3700 * -ERANGE off greater than mailbox command size
3701 * -EINVAL off, count or buff address invalid
3702 * zero if off and count are zero
3703 * -EACCES adapter over temp
3704 * -EPERM garbage can value to catch a multitude of errors
3705 * -EAGAIN management IO not permitted, state or off error
3706 * -ETIME mailbox timeout
3707 * -ENODEV mailbox error
3708 * count number of bytes transferred
3709 **/
dea3101e 3710static ssize_t
2c3c8bea
CW
3711sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3712 struct bin_attribute *bin_attr,
91a69029 3713 char *buf, loff_t off, size_t count)
dea3101e 3714{
ee959b00
TJ
3715 struct device *dev = container_of(kobj, struct device, kobj);
3716 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
3717 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3718 struct lpfc_hba *phba = vport->phba;
dea3101e 3719 int rc;
04c68496 3720 MAILBOX_t *pmb;
dea3101e 3721
1dcb58e5 3722 if (off > MAILBOX_CMD_SIZE)
dea3101e 3723 return -ERANGE;
3724
1dcb58e5
JS
3725 if ((count + off) > MAILBOX_CMD_SIZE)
3726 count = MAILBOX_CMD_SIZE - off;
dea3101e 3727
3728 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3729 return -EINVAL;
3730
3731 if (off && count == 0)
3732 return 0;
3733
2e0fef85 3734 spin_lock_irq(&phba->hbalock);
dea3101e 3735
7af67051
JS
3736 if (phba->over_temp_state == HBA_OVER_TEMP) {
3737 sysfs_mbox_idle(phba);
3738 spin_unlock_irq(&phba->hbalock);
09372820 3739 return -EACCES;
7af67051
JS
3740 }
3741
dea3101e 3742 if (off == 0 &&
3743 phba->sysfs_mbox.state == SMBOX_WRITING &&
3744 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
04c68496
JS
3745 pmb = &phba->sysfs_mbox.mbox->u.mb;
3746 switch (pmb->mbxCommand) {
dea3101e 3747 /* Offline only */
dea3101e 3748 case MBX_INIT_LINK:
3749 case MBX_DOWN_LINK:
3750 case MBX_CONFIG_LINK:
3751 case MBX_CONFIG_RING:
3752 case MBX_RESET_RING:
3753 case MBX_UNREG_LOGIN:
3754 case MBX_CLEAR_LA:
3755 case MBX_DUMP_CONTEXT:
3756 case MBX_RUN_DIAGS:
3757 case MBX_RESTART:
dea3101e 3758 case MBX_SET_MASK:
dea3101e 3759 case MBX_SET_DEBUG:
2e0fef85 3760 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea3101e 3761 printk(KERN_WARNING "mbox_read:Command 0x%x "
3762 "is illegal in on-line state\n",
04c68496 3763 pmb->mbxCommand);
dea3101e 3764 sysfs_mbox_idle(phba);
2e0fef85 3765 spin_unlock_irq(&phba->hbalock);
dea3101e 3766 return -EPERM;
3767 }
a8adb832
JS
3768 case MBX_WRITE_NV:
3769 case MBX_WRITE_VPARMS:
dea3101e 3770 case MBX_LOAD_SM:
3771 case MBX_READ_NV:
3772 case MBX_READ_CONFIG:
3773 case MBX_READ_RCONFIG:
3774 case MBX_READ_STATUS:
3775 case MBX_READ_XRI:
3776 case MBX_READ_REV:
3777 case MBX_READ_LNK_STAT:
3778 case MBX_DUMP_MEMORY:
3779 case MBX_DOWN_LOAD:
3780 case MBX_UPDATE_CFG:
41415862 3781 case MBX_KILL_BOARD:
dea3101e 3782 case MBX_LOAD_AREA:
3783 case MBX_LOAD_EXP_ROM:
41415862
JW
3784 case MBX_BEACON:
3785 case MBX_DEL_LD_ENTRY:
09372820
JS
3786 case MBX_SET_VARIABLE:
3787 case MBX_WRITE_WWN:
84774a4d
JS
3788 case MBX_PORT_CAPABILITIES:
3789 case MBX_PORT_IOV_CONTROL:
dea3101e 3790 break;
dcf2a4e0
JS
3791 case MBX_SECURITY_MGMT:
3792 case MBX_AUTH_PORT:
5989b8d4
JS
3793 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
3794 printk(KERN_WARNING "mbox_read:Command 0x%x "
3795 "is not permitted\n", pmb->mbxCommand);
3796 sysfs_mbox_idle(phba);
3797 spin_unlock_irq(&phba->hbalock);
dcf2a4e0 3798 return -EPERM;
5989b8d4 3799 }
dcf2a4e0 3800 break;
dea3101e 3801 case MBX_READ_SPARM64:
76a95d75 3802 case MBX_READ_TOPOLOGY:
dea3101e 3803 case MBX_REG_LOGIN:
3804 case MBX_REG_LOGIN64:
3805 case MBX_CONFIG_PORT:
3806 case MBX_RUN_BIU_DIAG:
3807 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
04c68496 3808 pmb->mbxCommand);
dea3101e 3809 sysfs_mbox_idle(phba);
2e0fef85 3810 spin_unlock_irq(&phba->hbalock);
dea3101e 3811 return -EPERM;
3812 default:
3813 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
04c68496 3814 pmb->mbxCommand);
dea3101e 3815 sysfs_mbox_idle(phba);
2e0fef85 3816 spin_unlock_irq(&phba->hbalock);
dea3101e 3817 return -EPERM;
3818 }
3819
09372820 3820 /* If HBA encountered an error attention, allow only DUMP
1b32f6aa 3821 * or RESTART mailbox commands until the HBA is restarted.
09372820 3822 */
d7c255b2 3823 if (phba->pport->stopped &&
04c68496
JS
3824 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3825 pmb->mbxCommand != MBX_RESTART &&
3826 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3827 pmb->mbxCommand != MBX_WRITE_WWN)
d7c255b2
JS
3828 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3829 "1259 mbox: Issued mailbox cmd "
3830 "0x%x while in stopped state.\n",
04c68496 3831 pmb->mbxCommand);
09372820 3832
92d7f7b0
JS
3833 phba->sysfs_mbox.mbox->vport = vport;
3834
58da1ffb
JS
3835 /* Don't allow mailbox commands to be sent when blocked
3836 * or when in the middle of discovery
3837 */
495a714c 3838 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
46fa311e 3839 sysfs_mbox_idle(phba);
2e0fef85 3840 spin_unlock_irq(&phba->hbalock);
46fa311e
JS
3841 return -EAGAIN;
3842 }
3843
2e0fef85 3844 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
f4b4c68f 3845 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
dea3101e 3846
2e0fef85 3847 spin_unlock_irq(&phba->hbalock);
dea3101e 3848 rc = lpfc_sli_issue_mbox (phba,
3849 phba->sysfs_mbox.mbox,
3850 MBX_POLL);
2e0fef85 3851 spin_lock_irq(&phba->hbalock);
dea3101e 3852
3853 } else {
2e0fef85 3854 spin_unlock_irq(&phba->hbalock);
dea3101e 3855 rc = lpfc_sli_issue_mbox_wait (phba,
3856 phba->sysfs_mbox.mbox,
04c68496 3857 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
2e0fef85 3858 spin_lock_irq(&phba->hbalock);
dea3101e 3859 }
3860
3861 if (rc != MBX_SUCCESS) {
1dcb58e5 3862 if (rc == MBX_TIMEOUT) {
1dcb58e5
JS
3863 phba->sysfs_mbox.mbox = NULL;
3864 }
dea3101e 3865 sysfs_mbox_idle(phba);
2e0fef85 3866 spin_unlock_irq(&phba->hbalock);
8f6d98d2 3867 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea3101e 3868 }
3869 phba->sysfs_mbox.state = SMBOX_READING;
3870 }
3871 else if (phba->sysfs_mbox.offset != off ||
3872 phba->sysfs_mbox.state != SMBOX_READING) {
3873 printk(KERN_WARNING "mbox_read: Bad State\n");
3874 sysfs_mbox_idle(phba);
2e0fef85 3875 spin_unlock_irq(&phba->hbalock);
8f6d98d2 3876 return -EAGAIN;
dea3101e 3877 }
3878
04c68496 3879 memcpy(buf, (uint8_t *) &pmb + off, count);
dea3101e 3880
3881 phba->sysfs_mbox.offset = off + count;
3882
1dcb58e5 3883 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea3101e 3884 sysfs_mbox_idle(phba);
3885
2e0fef85 3886 spin_unlock_irq(&phba->hbalock);
dea3101e 3887
3888 return count;
3889}
3890
3891static struct bin_attribute sysfs_mbox_attr = {
3892 .attr = {
3893 .name = "mbox",
3894 .mode = S_IRUSR | S_IWUSR,
dea3101e 3895 },
1dcb58e5 3896 .size = MAILBOX_CMD_SIZE,
dea3101e 3897 .read = sysfs_mbox_read,
3898 .write = sysfs_mbox_write,
3899};
3900
e59058c4 3901/**
3621a710 3902 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
e59058c4
JS
3903 * @vport: address of lpfc vport structure.
3904 *
3905 * Return codes:
3906 * zero on success
3907 * error return code from sysfs_create_bin_file()
3908 **/
dea3101e 3909int
2e0fef85 3910lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea3101e 3911{
2e0fef85 3912 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea3101e 3913 int error;
3914
ee959b00 3915 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
eada272d
JS
3916 &sysfs_drvr_stat_data_attr);
3917
3918 /* Virtual ports do not need ctrl_reg and mbox */
3919 if (error || vport->port_type == LPFC_NPIV_PORT)
dea3101e 3920 goto out;
3921
ee959b00 3922 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
eada272d 3923 &sysfs_ctlreg_attr);
dea3101e 3924 if (error)
eada272d 3925 goto out_remove_stat_attr;
dea3101e 3926
ea2151b4 3927 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
eada272d 3928 &sysfs_mbox_attr);
ea2151b4 3929 if (error)
eada272d 3930 goto out_remove_ctlreg_attr;
ea2151b4 3931
dea3101e 3932 return 0;
3933out_remove_ctlreg_attr:
ee959b00 3934 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
eada272d
JS
3935out_remove_stat_attr:
3936 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3937 &sysfs_drvr_stat_data_attr);
dea3101e 3938out:
3939 return error;
3940}
3941
e59058c4 3942/**
3621a710 3943 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
e59058c4
JS
3944 * @vport: address of lpfc vport structure.
3945 **/
dea3101e 3946void
2e0fef85 3947lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea3101e 3948{
2e0fef85 3949 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
ea2151b4
JS
3950 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3951 &sysfs_drvr_stat_data_attr);
eada272d
JS
3952 /* Virtual ports do not need ctrl_reg and mbox */
3953 if (vport->port_type == LPFC_NPIV_PORT)
3954 return;
ee959b00
TJ
3955 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3956 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea3101e 3957}
3958
3959
3960/*
3961 * Dynamic FC Host Attributes Support
3962 */
3963
e59058c4 3964/**
3621a710 3965 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
e59058c4
JS
3966 * @shost: kernel scsi host pointer.
3967 **/
dea3101e 3968static void
3969lpfc_get_host_port_id(struct Scsi_Host *shost)
3970{
2e0fef85
JS
3971 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3972
dea3101e 3973 /* note: fc_myDID already in cpu endianness */
2e0fef85 3974 fc_host_port_id(shost) = vport->fc_myDID;
dea3101e 3975}
3976
e59058c4 3977/**
3621a710 3978 * lpfc_get_host_port_type - Set the value of the scsi host port type
e59058c4
JS
3979 * @shost: kernel scsi host pointer.
3980 **/
dea3101e 3981static void
3982lpfc_get_host_port_type(struct Scsi_Host *shost)
3983{
2e0fef85
JS
3984 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3985 struct lpfc_hba *phba = vport->phba;
dea3101e 3986
3987 spin_lock_irq(shost->host_lock);
3988
92d7f7b0
JS
3989 if (vport->port_type == LPFC_NPIV_PORT) {
3990 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3991 } else if (lpfc_is_link_up(phba)) {
76a95d75 3992 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2e0fef85 3993 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea3101e 3994 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3995 else
3996 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3997 } else {
2e0fef85 3998 if (vport->fc_flag & FC_FABRIC)
dea3101e 3999 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4000 else
4001 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4002 }
4003 } else
4004 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4005
4006 spin_unlock_irq(shost->host_lock);
4007}
4008
e59058c4 4009/**
3621a710 4010 * lpfc_get_host_port_state - Set the value of the scsi host port state
e59058c4
JS
4011 * @shost: kernel scsi host pointer.
4012 **/
dea3101e 4013static void
4014lpfc_get_host_port_state(struct Scsi_Host *shost)
4015{
2e0fef85
JS
4016 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4017 struct lpfc_hba *phba = vport->phba;
dea3101e 4018
4019 spin_lock_irq(shost->host_lock);
4020
2e0fef85 4021 if (vport->fc_flag & FC_OFFLINE_MODE)
dea3101e 4022 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4023 else {
2e0fef85
JS
4024 switch (phba->link_state) {
4025 case LPFC_LINK_UNKNOWN:
dea3101e 4026 case LPFC_LINK_DOWN:
4027 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4028 break;
4029 case LPFC_LINK_UP:
dea3101e 4030 case LPFC_CLEAR_LA:
4031 case LPFC_HBA_READY:
4032 /* Links up, beyond this port_type reports state */
4033 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4034 break;
4035 case LPFC_HBA_ERROR:
4036 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4037 break;
4038 default:
4039 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4040 break;
4041 }
4042 }
4043
4044 spin_unlock_irq(shost->host_lock);
4045}
4046
e59058c4 4047/**
3621a710 4048 * lpfc_get_host_speed - Set the value of the scsi host speed
e59058c4
JS
4049 * @shost: kernel scsi host pointer.
4050 **/
dea3101e 4051static void
4052lpfc_get_host_speed(struct Scsi_Host *shost)
4053{
2e0fef85
JS
4054 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4055 struct lpfc_hba *phba = vport->phba;
dea3101e 4056
4057 spin_lock_irq(shost->host_lock);
4058
2e0fef85 4059 if (lpfc_is_link_up(phba)) {
dea3101e 4060 switch(phba->fc_linkspeed) {
76a95d75
JS
4061 case LPFC_LINK_SPEED_1GHZ:
4062 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea3101e 4063 break;
76a95d75
JS
4064 case LPFC_LINK_SPEED_2GHZ:
4065 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea3101e 4066 break;
76a95d75
JS
4067 case LPFC_LINK_SPEED_4GHZ:
4068 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea3101e 4069 break;
76a95d75
JS
4070 case LPFC_LINK_SPEED_8GHZ:
4071 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
b87eab38 4072 break;
76a95d75
JS
4073 case LPFC_LINK_SPEED_10GHZ:
4074 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
f4b4c68f 4075 break;
76a95d75
JS
4076 case LPFC_LINK_SPEED_16GHZ:
4077 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4078 break;
4079 default:
4080 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea3101e 4081 break;
4082 }
09372820
JS
4083 } else
4084 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea3101e 4085
4086 spin_unlock_irq(shost->host_lock);
4087}
4088
e59058c4 4089/**
3621a710 4090 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
e59058c4
JS
4091 * @shost: kernel scsi host pointer.
4092 **/
dea3101e 4093static void
4094lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4095{
2e0fef85
JS
4096 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4097 struct lpfc_hba *phba = vport->phba;
f631b4be 4098 u64 node_name;
dea3101e 4099
4100 spin_lock_irq(shost->host_lock);
4101
2e0fef85 4102 if ((vport->fc_flag & FC_FABRIC) ||
76a95d75 4103 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
2e0fef85 4104 (vport->fc_flag & FC_PUBLIC_LOOP)))
68ce1eb5 4105 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea3101e 4106 else
4107 /* fabric is local port if there is no F/FL_Port */
09372820 4108 node_name = 0;
dea3101e 4109
4110 spin_unlock_irq(shost->host_lock);
4111
f631b4be 4112 fc_host_fabric_name(shost) = node_name;
dea3101e 4113}
4114
e59058c4 4115/**
3621a710 4116 * lpfc_get_stats - Return statistical information about the adapter
e59058c4
JS
4117 * @shost: kernel scsi host pointer.
4118 *
4119 * Notes:
4120 * NULL on error for link down, no mbox pool, sli2 active,
4121 * management not allowed, memory allocation error, or mbox error.
4122 *
4123 * Returns:
4124 * NULL for error
4125 * address of the adapter host statistics
4126 **/
dea3101e 4127static struct fc_host_statistics *
4128lpfc_get_stats(struct Scsi_Host *shost)
4129{
2e0fef85
JS
4130 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4131 struct lpfc_hba *phba = vport->phba;
4132 struct lpfc_sli *psli = &phba->sli;
f888ba3c 4133 struct fc_host_statistics *hs = &phba->link_stats;
64ba8818 4134 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea3101e 4135 LPFC_MBOXQ_t *pmboxq;
4136 MAILBOX_t *pmb;
64ba8818 4137 unsigned long seconds;
433c3579 4138 int rc = 0;
dea3101e 4139
92d7f7b0
JS
4140 /*
4141 * prevent udev from issuing mailbox commands until the port is
4142 * configured.
4143 */
2e0fef85
JS
4144 if (phba->link_state < LPFC_LINK_DOWN ||
4145 !phba->mbox_mem_pool ||
f4b4c68f 4146 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
92d7f7b0 4147 return NULL;
2e0fef85
JS
4148
4149 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
46fa311e
JS
4150 return NULL;
4151
dea3101e 4152 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4153 if (!pmboxq)
4154 return NULL;
4155 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4156
04c68496 4157 pmb = &pmboxq->u.mb;
dea3101e 4158 pmb->mbxCommand = MBX_READ_STATUS;
4159 pmb->mbxOwner = OWN_HOST;
4160 pmboxq->context1 = NULL;
92d7f7b0 4161 pmboxq->vport = vport;
dea3101e 4162
75baf696 4163 if (vport->fc_flag & FC_OFFLINE_MODE)
dea3101e 4164 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
433c3579 4165 else
dea3101e 4166 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4167
4168 if (rc != MBX_SUCCESS) {
858c9f6c 4169 if (rc != MBX_TIMEOUT)
433c3579 4170 mempool_free(pmboxq, phba->mbox_mem_pool);
dea3101e 4171 return NULL;
4172 }
4173
f888ba3c
JSEC
4174 memset(hs, 0, sizeof (struct fc_host_statistics));
4175
dea3101e 4176 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4177 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4178 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4179 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4180
433c3579 4181 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea3101e 4182 pmb->mbxCommand = MBX_READ_LNK_STAT;
4183 pmb->mbxOwner = OWN_HOST;
4184 pmboxq->context1 = NULL;
92d7f7b0 4185 pmboxq->vport = vport;
dea3101e 4186
75baf696 4187 if (vport->fc_flag & FC_OFFLINE_MODE)
dea3101e 4188 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
433c3579 4189 else
dea3101e 4190 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4191
4192 if (rc != MBX_SUCCESS) {
858c9f6c 4193 if (rc != MBX_TIMEOUT)
92d7f7b0 4194 mempool_free(pmboxq, phba->mbox_mem_pool);
dea3101e 4195 return NULL;
4196 }
4197
4198 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4199 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4200 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4201 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4202 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4203 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4204 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4205
64ba8818
JS
4206 hs->link_failure_count -= lso->link_failure_count;
4207 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4208 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4209 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4210 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4211 hs->invalid_crc_count -= lso->invalid_crc_count;
4212 hs->error_frames -= lso->error_frames;
4213
76a95d75 4214 if (phba->hba_flag & HBA_FCOE_MODE) {
4d9ab994
JS
4215 hs->lip_count = -1;
4216 hs->nos_count = (phba->link_events >> 1);
4217 hs->nos_count -= lso->link_events;
76a95d75 4218 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea3101e 4219 hs->lip_count = (phba->fc_eventTag >> 1);
64ba8818 4220 hs->lip_count -= lso->link_events;
dea3101e 4221 hs->nos_count = -1;
4222 } else {
4223 hs->lip_count = -1;
4224 hs->nos_count = (phba->fc_eventTag >> 1);
64ba8818 4225 hs->nos_count -= lso->link_events;
dea3101e 4226 }
4227
4228 hs->dumped_frames = -1;
4229
64ba8818
JS
4230 seconds = get_seconds();
4231 if (seconds < psli->stats_start)
4232 hs->seconds_since_last_reset = seconds +
4233 ((unsigned long)-1 - psli->stats_start);
4234 else
4235 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea3101e 4236
1dcb58e5
JS
4237 mempool_free(pmboxq, phba->mbox_mem_pool);
4238
dea3101e 4239 return hs;
4240}
4241
e59058c4 4242/**
3621a710 4243 * lpfc_reset_stats - Copy the adapter link stats information
e59058c4
JS
4244 * @shost: kernel scsi host pointer.
4245 **/
64ba8818
JS
4246static void
4247lpfc_reset_stats(struct Scsi_Host *shost)
4248{
2e0fef85
JS
4249 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4250 struct lpfc_hba *phba = vport->phba;
4251 struct lpfc_sli *psli = &phba->sli;
4252 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
64ba8818
JS
4253 LPFC_MBOXQ_t *pmboxq;
4254 MAILBOX_t *pmb;
4255 int rc = 0;
4256
2e0fef85 4257 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
46fa311e
JS
4258 return;
4259
64ba8818
JS
4260 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4261 if (!pmboxq)
4262 return;
4263 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4264
04c68496 4265 pmb = &pmboxq->u.mb;
64ba8818
JS
4266 pmb->mbxCommand = MBX_READ_STATUS;
4267 pmb->mbxOwner = OWN_HOST;
4268 pmb->un.varWords[0] = 0x1; /* reset request */
4269 pmboxq->context1 = NULL;
92d7f7b0 4270 pmboxq->vport = vport;
64ba8818 4271
2e0fef85 4272 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
f4b4c68f 4273 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
64ba8818
JS
4274 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4275 else
4276 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4277
4278 if (rc != MBX_SUCCESS) {
858c9f6c 4279 if (rc != MBX_TIMEOUT)
64ba8818
JS
4280 mempool_free(pmboxq, phba->mbox_mem_pool);
4281 return;
4282 }
4283
4284 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4285 pmb->mbxCommand = MBX_READ_LNK_STAT;
4286 pmb->mbxOwner = OWN_HOST;
4287 pmboxq->context1 = NULL;
92d7f7b0 4288 pmboxq->vport = vport;
64ba8818 4289
2e0fef85 4290 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
f4b4c68f 4291 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
64ba8818
JS
4292 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4293 else
4294 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4295
4296 if (rc != MBX_SUCCESS) {
858c9f6c 4297 if (rc != MBX_TIMEOUT)
64ba8818
JS
4298 mempool_free( pmboxq, phba->mbox_mem_pool);
4299 return;
4300 }
4301
4302 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4303 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4304 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4305 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4306 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4307 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4308 lso->error_frames = pmb->un.varRdLnk.crcCnt;
76a95d75 4309 if (phba->hba_flag & HBA_FCOE_MODE)
4d9ab994
JS
4310 lso->link_events = (phba->link_events >> 1);
4311 else
4312 lso->link_events = (phba->fc_eventTag >> 1);
64ba8818
JS
4313
4314 psli->stats_start = get_seconds();
4315
1dcb58e5
JS
4316 mempool_free(pmboxq, phba->mbox_mem_pool);
4317
64ba8818
JS
4318 return;
4319}
dea3101e 4320
4321/*
4322 * The LPFC driver treats linkdown handling as target loss events so there
4323 * are no sysfs handlers for link_down_tmo.
4324 */
685f0bf7 4325
e59058c4 4326/**
3621a710 4327 * lpfc_get_node_by_target - Return the nodelist for a target
e59058c4
JS
4328 * @starget: kernel scsi target pointer.
4329 *
4330 * Returns:
4331 * address of the node list if found
4332 * NULL target not found
4333 **/
685f0bf7
JS
4334static struct lpfc_nodelist *
4335lpfc_get_node_by_target(struct scsi_target *starget)
dea3101e 4336{
2e0fef85
JS
4337 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4338 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
685f0bf7 4339 struct lpfc_nodelist *ndlp;
dea3101e 4340
4341 spin_lock_irq(shost->host_lock);
685f0bf7 4342 /* Search for this, mapped, target ID */
2e0fef85 4343 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
e47c9093
JS
4344 if (NLP_CHK_NODE_ACT(ndlp) &&
4345 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
685f0bf7
JS
4346 starget->id == ndlp->nlp_sid) {
4347 spin_unlock_irq(shost->host_lock);
4348 return ndlp;
dea3101e 4349 }
4350 }
4351 spin_unlock_irq(shost->host_lock);
685f0bf7
JS
4352 return NULL;
4353}
dea3101e 4354
e59058c4 4355/**
3621a710 4356 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
e59058c4
JS
4357 * @starget: kernel scsi target pointer.
4358 **/
685f0bf7
JS
4359static void
4360lpfc_get_starget_port_id(struct scsi_target *starget)
4361{
4362 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4363
4364 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea3101e 4365}
4366
e59058c4 4367/**
3621a710 4368 * lpfc_get_starget_node_name - Set the target node name
e59058c4
JS
4369 * @starget: kernel scsi target pointer.
4370 *
4371 * Description: Set the target node name to the ndlp node name wwn or zero.
4372 **/
dea3101e 4373static void
4374lpfc_get_starget_node_name(struct scsi_target *starget)
4375{
685f0bf7 4376 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea3101e 4377
685f0bf7
JS
4378 fc_starget_node_name(starget) =
4379 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea3101e 4380}
4381
e59058c4 4382/**
3621a710 4383 * lpfc_get_starget_port_name - Set the target port name
e59058c4
JS
4384 * @starget: kernel scsi target pointer.
4385 *
4386 * Description: set the target port name to the ndlp port name wwn or zero.
4387 **/
dea3101e 4388static void
4389lpfc_get_starget_port_name(struct scsi_target *starget)
4390{
685f0bf7 4391 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea3101e 4392
685f0bf7
JS
4393 fc_starget_port_name(starget) =
4394 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea3101e 4395}
4396
e59058c4 4397/**
3621a710 4398 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
e59058c4
JS
4399 * @rport: fc rport address.
4400 * @timeout: new value for dev loss tmo.
4401 *
4402 * Description:
4403 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4404 * dev_loss_tmo to one.
4405 **/
dea3101e 4406static void
4407lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4408{
dea3101e 4409 if (timeout)
c01f3208 4410 rport->dev_loss_tmo = timeout;
dea3101e 4411 else
c01f3208 4412 rport->dev_loss_tmo = 1;
dea3101e 4413}
4414
e59058c4 4415/**
3621a710 4416 * lpfc_rport_show_function - Return rport target information
e59058c4
JS
4417 *
4418 * Description:
4419 * Macro that uses field to generate a function with the name lpfc_show_rport_
4420 *
4421 * lpfc_show_rport_##field: returns the bytes formatted in buf
4422 * @cdev: class converted to an fc_rport.
4423 * @buf: on return contains the target_field or zero.
4424 *
4425 * Returns: size of formatted string.
4426 **/
dea3101e 4427#define lpfc_rport_show_function(field, format_string, sz, cast) \
4428static ssize_t \
ee959b00
TJ
4429lpfc_show_rport_##field (struct device *dev, \
4430 struct device_attribute *attr, \
4431 char *buf) \
dea3101e 4432{ \
ee959b00 4433 struct fc_rport *rport = transport_class_to_rport(dev); \
dea3101e 4434 struct lpfc_rport_data *rdata = rport->hostdata; \
4435 return snprintf(buf, sz, format_string, \
4436 (rdata->target) ? cast rdata->target->field : 0); \
4437}
4438
4439#define lpfc_rport_rd_attr(field, format_string, sz) \
4440 lpfc_rport_show_function(field, format_string, sz, ) \
4441static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4442
eada272d 4443/**
3621a710 4444 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
eada272d
JS
4445 * @fc_vport: The fc_vport who's symbolic name has been changed.
4446 *
4447 * Description:
4448 * This function is called by the transport after the @fc_vport's symbolic name
4449 * has been changed. This function re-registers the symbolic name with the
4450 * switch to propogate the change into the fabric if the vport is active.
4451 **/
4452static void
4453lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4454{
4455 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4456
4457 if (vport->port_state == LPFC_VPORT_READY)
4458 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4459}
dea3101e 4460
f4b4c68f
JS
4461/**
4462 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4463 * @phba: Pointer to lpfc_hba struct.
4464 *
4465 * This function is called by the lpfc_get_cfgparam() routine to set the
4466 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4467 * log messsage according to the module's lpfc_log_verbose parameter setting
4468 * before hba port or vport created.
4469 **/
4470static void
4471lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4472{
4473 phba->cfg_log_verbose = verbose;
4474}
4475
dea3101e 4476struct fc_function_template lpfc_transport_functions = {
4477 /* fixed attributes the driver supports */
4478 .show_host_node_name = 1,
4479 .show_host_port_name = 1,
4480 .show_host_supported_classes = 1,
4481 .show_host_supported_fc4s = 1,
dea3101e 4482 .show_host_supported_speeds = 1,
4483 .show_host_maxframe_size = 1,
eada272d 4484 .show_host_symbolic_name = 1,
dea3101e 4485
4486 /* dynamic attributes the driver supports */
4487 .get_host_port_id = lpfc_get_host_port_id,
4488 .show_host_port_id = 1,
4489
4490 .get_host_port_type = lpfc_get_host_port_type,
4491 .show_host_port_type = 1,
4492
4493 .get_host_port_state = lpfc_get_host_port_state,
4494 .show_host_port_state = 1,
4495
4496 /* active_fc4s is shown but doesn't change (thus no get function) */
4497 .show_host_active_fc4s = 1,
4498
4499 .get_host_speed = lpfc_get_host_speed,
4500 .show_host_speed = 1,
4501
4502 .get_host_fabric_name = lpfc_get_host_fabric_name,
4503 .show_host_fabric_name = 1,
4504
4505 /*
4506 * The LPFC driver treats linkdown handling as target loss events
4507 * so there are no sysfs handlers for link_down_tmo.
4508 */
4509
4510 .get_fc_host_stats = lpfc_get_stats,
64ba8818 4511 .reset_fc_host_stats = lpfc_reset_stats,
dea3101e 4512
4513 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4514 .show_rport_maxframe_size = 1,
4515 .show_rport_supported_classes = 1,
4516
dea3101e 4517 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4518 .show_rport_dev_loss_tmo = 1,
4519
4520 .get_starget_port_id = lpfc_get_starget_port_id,
4521 .show_starget_port_id = 1,
4522
4523 .get_starget_node_name = lpfc_get_starget_node_name,
4524 .show_starget_node_name = 1,
4525
4526 .get_starget_port_name = lpfc_get_starget_port_name,
4527 .show_starget_port_name = 1,
91ca7b01
AV
4528
4529 .issue_fc_host_lip = lpfc_issue_lip,
c01f3208
JS
4530 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4531 .terminate_rport_io = lpfc_terminate_rport_io,
92d7f7b0 4532
92d7f7b0 4533 .dd_fcvport_size = sizeof(struct lpfc_vport *),
eada272d
JS
4534
4535 .vport_disable = lpfc_vport_disable,
4536
4537 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
f1c3b0fc
JS
4538
4539 .bsg_request = lpfc_bsg_request,
4540 .bsg_timeout = lpfc_bsg_timeout,
92d7f7b0
JS
4541};
4542
98c9ea5c
JS
4543struct fc_function_template lpfc_vport_transport_functions = {
4544 /* fixed attributes the driver supports */
4545 .show_host_node_name = 1,
4546 .show_host_port_name = 1,
4547 .show_host_supported_classes = 1,
4548 .show_host_supported_fc4s = 1,
4549 .show_host_supported_speeds = 1,
4550 .show_host_maxframe_size = 1,
eada272d 4551 .show_host_symbolic_name = 1,
98c9ea5c
JS
4552
4553 /* dynamic attributes the driver supports */
4554 .get_host_port_id = lpfc_get_host_port_id,
4555 .show_host_port_id = 1,
4556
4557 .get_host_port_type = lpfc_get_host_port_type,
4558 .show_host_port_type = 1,
4559
4560 .get_host_port_state = lpfc_get_host_port_state,
4561 .show_host_port_state = 1,
4562
4563 /* active_fc4s is shown but doesn't change (thus no get function) */
4564 .show_host_active_fc4s = 1,
4565
4566 .get_host_speed = lpfc_get_host_speed,
4567 .show_host_speed = 1,
4568
4569 .get_host_fabric_name = lpfc_get_host_fabric_name,
4570 .show_host_fabric_name = 1,
4571
4572 /*
4573 * The LPFC driver treats linkdown handling as target loss events
4574 * so there are no sysfs handlers for link_down_tmo.
4575 */
4576
4577 .get_fc_host_stats = lpfc_get_stats,
4578 .reset_fc_host_stats = lpfc_reset_stats,
4579
4580 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4581 .show_rport_maxframe_size = 1,
4582 .show_rport_supported_classes = 1,
4583
4584 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4585 .show_rport_dev_loss_tmo = 1,
4586
4587 .get_starget_port_id = lpfc_get_starget_port_id,
4588 .show_starget_port_id = 1,
4589
4590 .get_starget_node_name = lpfc_get_starget_node_name,
4591 .show_starget_node_name = 1,
4592
4593 .get_starget_port_name = lpfc_get_starget_port_name,
4594 .show_starget_port_name = 1,
4595
4596 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4597 .terminate_rport_io = lpfc_terminate_rport_io,
4598
4599 .vport_disable = lpfc_vport_disable,
eada272d
JS
4600
4601 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
98c9ea5c
JS
4602};
4603
e59058c4 4604/**
3621a710 4605 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
e59058c4
JS
4606 * @phba: lpfc_hba pointer.
4607 **/
dea3101e 4608void
4609lpfc_get_cfgparam(struct lpfc_hba *phba)
4610{
7bcbb752
JSEC
4611 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4612 lpfc_cr_count_init(phba, lpfc_cr_count);
cf5bf97e 4613 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
a4bc3379
JS
4614 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4615 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
7bcbb752
JSEC
4616 lpfc_ack0_init(phba, lpfc_ack0);
4617 lpfc_topology_init(phba, lpfc_topology);
7bcbb752 4618 lpfc_link_speed_init(phba, lpfc_link_speed);
875fbdfe 4619 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
78b2d852 4620 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
19ca7609 4621 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
4ff43246 4622 lpfc_use_msi_init(phba, lpfc_use_msi);
da0436e9
JS
4623 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4624 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4625 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
13815c83
JS
4626 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4627 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
81301a9b 4628 lpfc_enable_bg_init(phba, lpfc_enable_bg);
45ed1190
JS
4629 if (phba->sli_rev == LPFC_SLI_REV4)
4630 phba->cfg_poll = 0;
4631 else
875fbdfe 4632 phba->cfg_poll = lpfc_poll;
a12e07bc 4633 phba->cfg_soft_wwnn = 0L;
c3f28afa 4634 phba->cfg_soft_wwpn = 0L;
83108bd3 4635 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
81301a9b 4636 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
7054a606 4637 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
6fb120a7 4638 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
0d878419 4639 lpfc_aer_support_init(phba, lpfc_aer_support);
84d1b006 4640 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
2a9bf3d0 4641 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
3de2a653
JS
4642 return;
4643}
b28485ac 4644
e59058c4 4645/**
3621a710 4646 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
e59058c4
JS
4647 * @vport: lpfc_vport pointer.
4648 **/
3de2a653
JS
4649void
4650lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4651{
e8b62011 4652 lpfc_log_verbose_init(vport, lpfc_log_verbose);
3de2a653 4653 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
7dc517df 4654 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
3de2a653
JS
4655 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4656 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4657 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4658 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4659 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4660 lpfc_use_adisc_init(vport, lpfc_use_adisc);
977b5a0a 4661 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
3de2a653
JS
4662 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4663 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4664 lpfc_max_luns_init(vport, lpfc_max_luns);
4665 lpfc_scan_down_init(vport, lpfc_scan_down);
7ee5d43e 4666 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea3101e 4667 return;
4668}
This page took 0.818324 seconds and 5 git commands to generate.