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