lpfc: Update modified file copyrights
[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. *
50611577 4 * Copyright (C) 2004-2016 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;
a0683bf6
JS
409 char fwrev[FW_REV_STR_SIZE];
410
411 if (phba->sli_rev < LPFC_SLI_REV4)
412 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
2e0fef85 413
a0683bf6
JS
414 lpfc_decode_firmware_rev(phba, fwrev, 1);
415 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
dea3101e 416}
e59058c4
JS
417
418/**
3621a710 419 * lpfc_state_show - Return the link state of the port
e59058c4
JS
420 * @dev: class converted to a Scsi_host structure.
421 * @attr: device attribute, not used.
422 * @buf: on return contains text describing the state of the link.
423 *
424 * Notes:
425 * The switch statement has no default so zero will be returned.
426 *
427 * Returns: size of formatted string.
428 **/
dea3101e 429static ssize_t
bbd1ae41
HR
430lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
431 char *buf)
dea3101e 432{
ee959b00 433 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
434 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
435 struct lpfc_hba *phba = vport->phba;
436 int len = 0;
437
438 switch (phba->link_state) {
439 case LPFC_LINK_UNKNOWN:
41415862 440 case LPFC_WARM_START:
dea3101e 441 case LPFC_INIT_START:
442 case LPFC_INIT_MBX_CMDS:
443 case LPFC_LINK_DOWN:
2e0fef85 444 case LPFC_HBA_ERROR:
a0c87cbd
JS
445 if (phba->hba_flag & LINK_DISABLED)
446 len += snprintf(buf + len, PAGE_SIZE-len,
447 "Link Down - User disabled\n");
448 else
449 len += snprintf(buf + len, PAGE_SIZE-len,
450 "Link Down\n");
dea3101e 451 break;
452 case LPFC_LINK_UP:
dea3101e 453 case LPFC_CLEAR_LA:
dea3101e 454 case LPFC_HBA_READY:
a8adb832 455 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
2e0fef85
JS
456
457 switch (vport->port_state) {
2e0fef85
JS
458 case LPFC_LOCAL_CFG_LINK:
459 len += snprintf(buf + len, PAGE_SIZE-len,
92d7f7b0 460 "Configuring Link\n");
2e0fef85 461 break;
92d7f7b0 462 case LPFC_FDISC:
2e0fef85
JS
463 case LPFC_FLOGI:
464 case LPFC_FABRIC_CFG_LINK:
465 case LPFC_NS_REG:
466 case LPFC_NS_QRY:
467 case LPFC_BUILD_DISC_LIST:
468 case LPFC_DISC_AUTH:
469 len += snprintf(buf + len, PAGE_SIZE - len,
470 "Discovery\n");
471 break;
472 case LPFC_VPORT_READY:
473 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
474 break;
475
92d7f7b0
JS
476 case LPFC_VPORT_FAILED:
477 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
478 break;
479
480 case LPFC_VPORT_UNKNOWN:
2e0fef85
JS
481 len += snprintf(buf + len, PAGE_SIZE - len,
482 "Unknown\n");
483 break;
484 }
84774a4d
JS
485 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
486 len += snprintf(buf + len, PAGE_SIZE-len,
487 " Menlo Maint Mode\n");
76a95d75 488 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2e0fef85 489 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea3101e 490 len += snprintf(buf + len, PAGE_SIZE-len,
491 " Public Loop\n");
492 else
493 len += snprintf(buf + len, PAGE_SIZE-len,
494 " Private Loop\n");
495 } else {
2e0fef85 496 if (vport->fc_flag & FC_FABRIC)
dea3101e 497 len += snprintf(buf + len, PAGE_SIZE-len,
498 " Fabric\n");
499 else
500 len += snprintf(buf + len, PAGE_SIZE-len,
501 " Point-2-Point\n");
502 }
503 }
2e0fef85 504
dea3101e 505 return len;
506}
507
026abb87
JS
508/**
509 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
510 * @dev: class unused variable.
511 * @attr: device attribute, not used.
512 * @buf: on return contains the module description text.
513 *
514 * Returns: size of formatted string.
515 **/
516static ssize_t
517lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
518 char *buf)
519{
520 struct Scsi_Host *shost = class_to_shost(dev);
521 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
522 struct lpfc_hba *phba = vport->phba;
523
524 if (phba->sli_rev < LPFC_SLI_REV4)
525 return snprintf(buf, PAGE_SIZE, "fc\n");
526
527 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
528 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
529 return snprintf(buf, PAGE_SIZE, "fcoe\n");
530 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
531 return snprintf(buf, PAGE_SIZE, "fc\n");
532 }
533 return snprintf(buf, PAGE_SIZE, "unknown\n");
534}
535
1ba981fd
JS
536/**
537 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
538 * (OAS) is supported.
539 * @dev: class unused variable.
540 * @attr: device attribute, not used.
541 * @buf: on return contains the module description text.
542 *
543 * Returns: size of formatted string.
544 **/
545static ssize_t
546lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
547 char *buf)
548{
549 struct Scsi_Host *shost = class_to_shost(dev);
550 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
551 struct lpfc_hba *phba = vport->phba;
552
553 return snprintf(buf, PAGE_SIZE, "%d\n",
554 phba->sli4_hba.pc_sli4_params.oas_supported);
555}
556
84d1b006
JS
557/**
558 * lpfc_link_state_store - Transition the link_state on an HBA port
559 * @dev: class device that is converted into a Scsi_host.
560 * @attr: device attribute, not used.
561 * @buf: one or more lpfc_polling_flags values.
562 * @count: not used.
563 *
564 * Returns:
565 * -EINVAL if the buffer is not "up" or "down"
566 * return from link state change function if non-zero
567 * length of the buf on success
568 **/
569static ssize_t
570lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
571 const char *buf, size_t count)
572{
573 struct Scsi_Host *shost = class_to_shost(dev);
574 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
575 struct lpfc_hba *phba = vport->phba;
576
577 int status = -EINVAL;
578
579 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
580 (phba->link_state == LPFC_LINK_DOWN))
6e7288d9 581 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
84d1b006
JS
582 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
583 (phba->link_state >= LPFC_LINK_UP))
6e7288d9 584 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
84d1b006
JS
585
586 if (status == 0)
587 return strlen(buf);
588 else
589 return status;
590}
591
e59058c4 592/**
3621a710 593 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
e59058c4
JS
594 * @dev: class device that is converted into a Scsi_host.
595 * @attr: device attribute, not used.
596 * @buf: on return contains the sum of fc mapped and unmapped.
597 *
598 * Description:
599 * Returns the ascii text number of the sum of the fc mapped and unmapped
600 * vport counts.
601 *
602 * Returns: size of formatted string.
603 **/
dea3101e 604static ssize_t
ee959b00
TJ
605lpfc_num_discovered_ports_show(struct device *dev,
606 struct device_attribute *attr, char *buf)
dea3101e 607{
ee959b00 608 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
609 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
610
611 return snprintf(buf, PAGE_SIZE, "%d\n",
612 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea3101e 613}
614
e59058c4 615/**
3621a710 616 * lpfc_issue_lip - Misnomer, name carried over from long ago
e59058c4
JS
617 * @shost: Scsi_Host pointer.
618 *
619 * Description:
620 * Bring the link down gracefully then re-init the link. The firmware will
621 * re-init the fiber channel interface as required. Does not issue a LIP.
622 *
623 * Returns:
624 * -EPERM port offline or management commands are being blocked
625 * -ENOMEM cannot allocate memory for the mailbox command
626 * -EIO error sending the mailbox command
627 * zero for success
628 **/
91ca7b01 629static int
2e0fef85 630lpfc_issue_lip(struct Scsi_Host *shost)
dea3101e 631{
2e0fef85
JS
632 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
633 struct lpfc_hba *phba = vport->phba;
dea3101e 634 LPFC_MBOXQ_t *pmboxq;
635 int mbxstatus = MBXERR_ERROR;
636
2e0fef85 637 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
83108bd3 638 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea3101e 639 return -EPERM;
640
641 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
642
643 if (!pmboxq)
644 return -ENOMEM;
645
646 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
04c68496
JS
647 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
648 pmboxq->u.mb.mbxOwner = OWN_HOST;
4db621e0 649
33ccf8d1 650 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea3101e 651
04c68496
JS
652 if ((mbxstatus == MBX_SUCCESS) &&
653 (pmboxq->u.mb.mbxStatus == 0 ||
654 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
4db621e0
JS
655 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
656 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
657 phba->cfg_link_speed);
658 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
659 phba->fc_ratov * 2);
dcf2a4e0
JS
660 if ((mbxstatus == MBX_SUCCESS) &&
661 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
662 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
663 "2859 SLI authentication is required "
664 "for INIT_LINK but has not done yet\n");
4db621e0
JS
665 }
666
5b8bd0c9 667 lpfc_set_loopback_flag(phba);
858c9f6c 668 if (mbxstatus != MBX_TIMEOUT)
433c3579 669 mempool_free(pmboxq, phba->mbox_mem_pool);
dea3101e 670
671 if (mbxstatus == MBXERR_ERROR)
672 return -EIO;
673
91ca7b01 674 return 0;
dea3101e 675}
676
e59058c4 677/**
3621a710 678 * lpfc_do_offline - Issues a mailbox command to bring the link down
e59058c4
JS
679 * @phba: lpfc_hba pointer.
680 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
681 *
682 * Notes:
683 * Assumes any error from lpfc_do_offline() will be negative.
684 * Can wait up to 5 seconds for the port ring buffers count
685 * to reach zero, prints a warning if it is not zero and continues.
3621a710 686 * lpfc_workq_post_event() returns a non-zero return code if call fails.
e59058c4
JS
687 *
688 * Returns:
689 * -EIO error posting the event
690 * zero for success
691 **/
40496f07 692static int
46fa311e 693lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
40496f07
JS
694{
695 struct completion online_compl;
46fa311e
JS
696 struct lpfc_sli_ring *pring;
697 struct lpfc_sli *psli;
40496f07 698 int status = 0;
46fa311e
JS
699 int cnt = 0;
700 int i;
fedd3b7b 701 int rc;
40496f07
JS
702
703 init_completion(&online_compl);
fedd3b7b 704 rc = lpfc_workq_post_event(phba, &status, &online_compl,
46fa311e 705 LPFC_EVT_OFFLINE_PREP);
fedd3b7b
JS
706 if (rc == 0)
707 return -ENOMEM;
708
46fa311e
JS
709 wait_for_completion(&online_compl);
710
711 if (status != 0)
712 return -EIO;
713
714 psli = &phba->sli;
715
09372820
JS
716 /* Wait a little for things to settle down, but not
717 * long enough for dev loss timeout to expire.
718 */
46fa311e
JS
719 for (i = 0; i < psli->num_rings; i++) {
720 pring = &psli->ring[i];
0e9bb8d7 721 while (!list_empty(&pring->txcmplq)) {
46fa311e 722 msleep(10);
09372820 723 if (cnt++ > 500) { /* 5 secs */
46fa311e
JS
724 lpfc_printf_log(phba,
725 KERN_WARNING, LOG_INIT,
e8b62011
JS
726 "0466 Outstanding IO when "
727 "bringing Adapter offline\n");
46fa311e
JS
728 break;
729 }
730 }
731 }
732
733 init_completion(&online_compl);
fedd3b7b
JS
734 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
735 if (rc == 0)
736 return -ENOMEM;
737
40496f07
JS
738 wait_for_completion(&online_compl);
739
740 if (status != 0)
741 return -EIO;
742
46fa311e
JS
743 return 0;
744}
745
e59058c4 746/**
3621a710 747 * lpfc_selective_reset - Offline then onlines the port
e59058c4
JS
748 * @phba: lpfc_hba pointer.
749 *
750 * Description:
751 * If the port is configured to allow a reset then the hba is brought
752 * offline then online.
753 *
754 * Notes:
755 * Assumes any error from lpfc_do_offline() will be negative.
ab56dc2e 756 * Do not make this function static.
e59058c4
JS
757 *
758 * Returns:
759 * lpfc_do_offline() return code if not zero
760 * -EIO reset not configured or error posting the event
761 * zero for success
762 **/
7f86059a 763int
46fa311e
JS
764lpfc_selective_reset(struct lpfc_hba *phba)
765{
766 struct completion online_compl;
767 int status = 0;
fedd3b7b 768 int rc;
46fa311e 769
71157c9e 770 if (!phba->cfg_enable_hba_reset)
f7a919b4 771 return -EACCES;
13815c83 772
71157c9e
JS
773 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
774 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
46fa311e 775
71157c9e
JS
776 if (status != 0)
777 return status;
778 }
46fa311e 779
40496f07 780 init_completion(&online_compl);
fedd3b7b 781 rc = lpfc_workq_post_event(phba, &status, &online_compl,
40496f07 782 LPFC_EVT_ONLINE);
fedd3b7b
JS
783 if (rc == 0)
784 return -ENOMEM;
785
40496f07
JS
786 wait_for_completion(&online_compl);
787
788 if (status != 0)
789 return -EIO;
790
791 return 0;
792}
793
e59058c4 794/**
3621a710 795 * lpfc_issue_reset - Selectively resets an adapter
e59058c4
JS
796 * @dev: class device that is converted into a Scsi_host.
797 * @attr: device attribute, not used.
798 * @buf: containing the string "selective".
799 * @count: unused variable.
800 *
801 * Description:
802 * If the buf contains the string "selective" then lpfc_selective_reset()
803 * is called to perform the reset.
804 *
805 * Notes:
806 * Assumes any error from lpfc_selective_reset() will be negative.
807 * If lpfc_selective_reset() returns zero then the length of the buffer
af901ca1 808 * is returned which indicates success
e59058c4
JS
809 *
810 * Returns:
811 * -EINVAL if the buffer does not contain the string "selective"
812 * length of buf if lpfc-selective_reset() if the call succeeds
813 * return value of lpfc_selective_reset() if the call fails
814**/
40496f07 815static ssize_t
ee959b00
TJ
816lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
817 const char *buf, size_t count)
40496f07 818{
ee959b00 819 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
820 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
821 struct lpfc_hba *phba = vport->phba;
40496f07
JS
822 int status = -EINVAL;
823
73d91e50
JS
824 if (!phba->cfg_enable_hba_reset)
825 return -EACCES;
826
40496f07 827 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
7f86059a 828 status = phba->lpfc_selective_reset(phba);
40496f07
JS
829
830 if (status == 0)
831 return strlen(buf);
832 else
833 return status;
834}
835
88a2cfbb
JS
836/**
837 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
838 * @phba: lpfc_hba pointer.
839 *
840 * Description:
841 * SLI4 interface type-2 device to wait on the sliport status register for
842 * the readyness after performing a firmware reset.
843 *
844 * Returns:
0b1587b1 845 * zero for success, -EPERM when port does not have privilege to perform the
026abb87
JS
846 * reset, -EIO when port timeout from recovering from the reset.
847 *
848 * Note:
849 * As the caller will interpret the return code by value, be careful in making
850 * change or addition to return codes.
88a2cfbb 851 **/
73d91e50 852int
88a2cfbb
JS
853lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
854{
f7a919b4 855 struct lpfc_register portstat_reg = {0};
88a2cfbb
JS
856 int i;
857
f7a919b4 858 msleep(100);
88a2cfbb
JS
859 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
860 &portstat_reg.word0);
861
0b1587b1 862 /* verify if privileged for the request operation */
f7a919b4
JS
863 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
864 !bf_get(lpfc_sliport_status_err, &portstat_reg))
865 return -EPERM;
866
88a2cfbb
JS
867 /* wait for the SLI port firmware ready after firmware reset */
868 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
869 msleep(10);
870 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
871 &portstat_reg.word0);
872 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
873 continue;
874 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
875 continue;
876 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
877 continue;
878 break;
879 }
880
881 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
882 return 0;
883 else
884 return -EIO;
885}
886
c0c11512 887/**
52d52440 888 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
c0c11512
JS
889 * @phba: lpfc_hba pointer.
890 *
891 * Description:
52d52440
JS
892 * Request SLI4 interface type-2 device to perform a physical register set
893 * access.
c0c11512
JS
894 *
895 * Returns:
896 * zero for success
897 **/
898static ssize_t
52d52440 899lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
c0c11512
JS
900{
901 struct completion online_compl;
b76f2dc9 902 struct pci_dev *pdev = phba->pcidev;
026abb87
JS
903 uint32_t before_fc_flag;
904 uint32_t sriov_nr_virtfn;
c0c11512 905 uint32_t reg_val;
026abb87
JS
906 int status = 0, rc = 0;
907 int job_posted = 1, sriov_err;
c0c11512
JS
908
909 if (!phba->cfg_enable_hba_reset)
f7a919b4 910 return -EACCES;
c0c11512 911
52d52440
JS
912 if ((phba->sli_rev < LPFC_SLI_REV4) ||
913 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
914 LPFC_SLI_INTF_IF_TYPE_2))
915 return -EPERM;
916
026abb87
JS
917 /* Keep state if we need to restore back */
918 before_fc_flag = phba->pport->fc_flag;
919 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
920
b76f2dc9
JS
921 /* Disable SR-IOV virtual functions if enabled */
922 if (phba->cfg_sriov_nr_virtfn) {
923 pci_disable_sriov(pdev);
924 phba->cfg_sriov_nr_virtfn = 0;
925 }
229adb0e 926
0293635e
JS
927 if (opcode == LPFC_FW_DUMP)
928 phba->hba_flag |= HBA_FW_DUMP_OP;
929
c0c11512
JS
930 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
931
0293635e
JS
932 if (status != 0) {
933 phba->hba_flag &= ~HBA_FW_DUMP_OP;
c0c11512 934 return status;
0293635e 935 }
c0c11512
JS
936
937 /* wait for the device to be quiesced before firmware reset */
938 msleep(100);
939
940 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
941 LPFC_CTL_PDEV_CTL_OFFSET);
52d52440
JS
942
943 if (opcode == LPFC_FW_DUMP)
944 reg_val |= LPFC_FW_DUMP_REQUEST;
945 else if (opcode == LPFC_FW_RESET)
946 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
947 else if (opcode == LPFC_DV_RESET)
948 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
949
c0c11512
JS
950 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
951 LPFC_CTL_PDEV_CTL_OFFSET);
952 /* flush */
953 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
954
955 /* delay driver action following IF_TYPE_2 reset */
88a2cfbb
JS
956 rc = lpfc_sli4_pdev_status_reg_wait(phba);
957
026abb87 958 if (rc == -EPERM) {
0b1587b1 959 /* no privilege for reset */
6b5151fd 960 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
0b1587b1 961 "3150 No privilege to perform the requested "
6b5151fd 962 "access: x%x\n", reg_val);
026abb87
JS
963 } else if (rc == -EIO) {
964 /* reset failed, there is nothing more we can do */
6b5151fd
JS
965 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
966 "3153 Fail to perform the requested "
967 "access: x%x\n", reg_val);
f7a919b4 968 return rc;
026abb87
JS
969 }
970
971 /* keep the original port state */
972 if (before_fc_flag & FC_OFFLINE_MODE)
973 goto out;
c0c11512
JS
974
975 init_completion(&online_compl);
026abb87
JS
976 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
977 LPFC_EVT_ONLINE);
978 if (!job_posted)
979 goto out;
c0c11512
JS
980
981 wait_for_completion(&online_compl);
982
026abb87
JS
983out:
984 /* in any case, restore the virtual functions enabled as before */
985 if (sriov_nr_virtfn) {
986 sriov_err =
987 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
988 if (!sriov_err)
989 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
990 }
c0c11512 991
026abb87
JS
992 /* return proper error code */
993 if (!rc) {
994 if (!job_posted)
995 rc = -ENOMEM;
996 else if (status)
997 rc = -EIO;
998 }
999 return rc;
c0c11512
JS
1000}
1001
e59058c4 1002/**
3621a710 1003 * lpfc_nport_evt_cnt_show - Return the number of nport events
e59058c4
JS
1004 * @dev: class device that is converted into a Scsi_host.
1005 * @attr: device attribute, not used.
1006 * @buf: on return contains the ascii number of nport events.
1007 *
1008 * Returns: size of formatted string.
1009 **/
dea3101e 1010static ssize_t
ee959b00
TJ
1011lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1012 char *buf)
dea3101e 1013{
ee959b00 1014 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
1015 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1016 struct lpfc_hba *phba = vport->phba;
1017
dea3101e 1018 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1019}
1020
e59058c4 1021/**
3621a710 1022 * lpfc_board_mode_show - Return the state of the board
e59058c4
JS
1023 * @dev: class device that is converted into a Scsi_host.
1024 * @attr: device attribute, not used.
1025 * @buf: on return contains the state of the adapter.
1026 *
1027 * Returns: size of formatted string.
1028 **/
41415862 1029static ssize_t
ee959b00
TJ
1030lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1031 char *buf)
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
JW
1036 char * state;
1037
2e0fef85 1038 if (phba->link_state == LPFC_HBA_ERROR)
41415862 1039 state = "error";
2e0fef85 1040 else if (phba->link_state == LPFC_WARM_START)
41415862 1041 state = "warm start";
2e0fef85 1042 else if (phba->link_state == LPFC_INIT_START)
41415862
JW
1043 state = "offline";
1044 else
1045 state = "online";
1046
1047 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1048}
1049
e59058c4 1050/**
3621a710 1051 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
e59058c4
JS
1052 * @dev: class device that is converted into a Scsi_host.
1053 * @attr: device attribute, not used.
1054 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1055 * @count: unused variable.
1056 *
1057 * Returns:
1058 * -EACCES if enable hba reset not enabled
1059 * -EINVAL if the buffer does not contain a valid string (see above)
1060 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1061 * buf length greater than zero indicates success
1062 **/
41415862 1063static ssize_t
ee959b00
TJ
1064lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1065 const char *buf, size_t count)
41415862 1066{
ee959b00 1067 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
1068 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1069 struct lpfc_hba *phba = vport->phba;
41415862 1070 struct completion online_compl;
026abb87
JS
1071 char *board_mode_str = NULL;
1072 int status = 0;
fedd3b7b 1073 int rc;
41415862 1074
026abb87
JS
1075 if (!phba->cfg_enable_hba_reset) {
1076 status = -EACCES;
1077 goto board_mode_out;
1078 }
88a2cfbb
JS
1079
1080 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
026abb87 1081 "3050 lpfc_board_mode set to %s\n", buf);
88a2cfbb 1082
41415862
JW
1083 init_completion(&online_compl);
1084
46fa311e 1085 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
fedd3b7b 1086 rc = lpfc_workq_post_event(phba, &status, &online_compl,
41415862 1087 LPFC_EVT_ONLINE);
026abb87
JS
1088 if (rc == 0) {
1089 status = -ENOMEM;
1090 goto board_mode_out;
1091 }
46fa311e
JS
1092 wait_for_completion(&online_compl);
1093 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1094 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
41415862 1095 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
6a9c52cf 1096 if (phba->sli_rev == LPFC_SLI_REV4)
026abb87 1097 status = -EINVAL;
6a9c52cf
JS
1098 else
1099 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
46fa311e 1100 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
6a9c52cf 1101 if (phba->sli_rev == LPFC_SLI_REV4)
026abb87 1102 status = -EINVAL;
6a9c52cf
JS
1103 else
1104 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
c0c11512 1105 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
52d52440
JS
1106 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1107 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1108 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1109 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1110 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
41415862 1111 else
026abb87 1112 status = -EINVAL;
41415862 1113
026abb87 1114board_mode_out:
41415862
JW
1115 if (!status)
1116 return strlen(buf);
026abb87
JS
1117 else {
1118 board_mode_str = strchr(buf, '\n');
1119 if (board_mode_str)
1120 *board_mode_str = '\0';
1121 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1122 "3097 Failed \"%s\", status(%d), "
1123 "fc_flag(x%x)\n",
1124 buf, status, phba->pport->fc_flag);
f7a919b4 1125 return status;
026abb87 1126 }
41415862
JW
1127}
1128
e59058c4 1129/**
3621a710 1130 * lpfc_get_hba_info - Return various bits of informaton about the adapter
e59058c4 1131 * @phba: pointer to the adapter structure.
3621a710
JS
1132 * @mxri: max xri count.
1133 * @axri: available xri count.
1134 * @mrpi: max rpi count.
1135 * @arpi: available rpi count.
1136 * @mvpi: max vpi count.
1137 * @avpi: available vpi count.
e59058c4
JS
1138 *
1139 * Description:
1140 * If an integer pointer for an count is not null then the value for the
1141 * count is returned.
1142 *
1143 * Returns:
1144 * zero on error
1145 * one for success
1146 **/
311464ec 1147static int
858c9f6c
JS
1148lpfc_get_hba_info(struct lpfc_hba *phba,
1149 uint32_t *mxri, uint32_t *axri,
1150 uint32_t *mrpi, uint32_t *arpi,
1151 uint32_t *mvpi, uint32_t *avpi)
92d7f7b0 1152{
04c68496 1153 struct lpfc_mbx_read_config *rd_config;
92d7f7b0
JS
1154 LPFC_MBOXQ_t *pmboxq;
1155 MAILBOX_t *pmb;
1156 int rc = 0;
15672319 1157 uint32_t max_vpi;
92d7f7b0
JS
1158
1159 /*
1160 * prevent udev from issuing mailbox commands until the port is
1161 * configured.
1162 */
1163 if (phba->link_state < LPFC_LINK_DOWN ||
1164 !phba->mbox_mem_pool ||
f4b4c68f 1165 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
92d7f7b0
JS
1166 return 0;
1167
1168 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1169 return 0;
1170
1171 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1172 if (!pmboxq)
1173 return 0;
1174 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1175
04c68496 1176 pmb = &pmboxq->u.mb;
92d7f7b0
JS
1177 pmb->mbxCommand = MBX_READ_CONFIG;
1178 pmb->mbxOwner = OWN_HOST;
1179 pmboxq->context1 = NULL;
1180
75baf696 1181 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
92d7f7b0
JS
1182 rc = MBX_NOT_FINISHED;
1183 else
1184 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1185
1186 if (rc != MBX_SUCCESS) {
858c9f6c 1187 if (rc != MBX_TIMEOUT)
92d7f7b0
JS
1188 mempool_free(pmboxq, phba->mbox_mem_pool);
1189 return 0;
1190 }
1191
da0436e9
JS
1192 if (phba->sli_rev == LPFC_SLI_REV4) {
1193 rd_config = &pmboxq->u.mqe.un.rd_config;
1194 if (mrpi)
1195 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1196 if (arpi)
1197 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1198 phba->sli4_hba.max_cfg_param.rpi_used;
1199 if (mxri)
1200 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1201 if (axri)
1202 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1203 phba->sli4_hba.max_cfg_param.xri_used;
15672319
JS
1204
1205 /* Account for differences with SLI-3. Get vpi count from
1206 * mailbox data and subtract one for max vpi value.
1207 */
1208 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1209 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1210
da0436e9 1211 if (mvpi)
15672319 1212 *mvpi = max_vpi;
da0436e9 1213 if (avpi)
15672319 1214 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
da0436e9
JS
1215 } else {
1216 if (mrpi)
1217 *mrpi = pmb->un.varRdConfig.max_rpi;
1218 if (arpi)
1219 *arpi = pmb->un.varRdConfig.avail_rpi;
1220 if (mxri)
1221 *mxri = pmb->un.varRdConfig.max_xri;
1222 if (axri)
1223 *axri = pmb->un.varRdConfig.avail_xri;
1224 if (mvpi)
1225 *mvpi = pmb->un.varRdConfig.max_vpi;
1226 if (avpi)
1227 *avpi = pmb->un.varRdConfig.avail_vpi;
1228 }
92d7f7b0
JS
1229
1230 mempool_free(pmboxq, phba->mbox_mem_pool);
1231 return 1;
1232}
1233
e59058c4 1234/**
3621a710 1235 * lpfc_max_rpi_show - Return maximum rpi
e59058c4
JS
1236 * @dev: class device that is converted into a Scsi_host.
1237 * @attr: device attribute, not used.
1238 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1239 *
1240 * Description:
1241 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1242 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1243 * to "Unknown" and the buffer length is returned, therefore the caller
1244 * must check for "Unknown" in the buffer to detect a failure.
1245 *
1246 * Returns: size of formatted string.
1247 **/
92d7f7b0 1248static ssize_t
ee959b00
TJ
1249lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1250 char *buf)
92d7f7b0 1251{
ee959b00 1252 struct Scsi_Host *shost = class_to_shost(dev);
92d7f7b0
JS
1253 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1254 struct lpfc_hba *phba = vport->phba;
1255 uint32_t cnt;
1256
858c9f6c 1257 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
92d7f7b0
JS
1258 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1259 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1260}
1261
e59058c4 1262/**
3621a710 1263 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
e59058c4
JS
1264 * @dev: class device that is converted into a Scsi_host.
1265 * @attr: device attribute, not used.
1266 * @buf: containing the used rpi count in decimal or "Unknown".
1267 *
1268 * Description:
1269 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1270 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1271 * to "Unknown" and the buffer length is returned, therefore the caller
1272 * must check for "Unknown" in the buffer to detect a failure.
1273 *
1274 * Returns: size of formatted string.
1275 **/
92d7f7b0 1276static ssize_t
ee959b00
TJ
1277lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1278 char *buf)
92d7f7b0 1279{
ee959b00 1280 struct Scsi_Host *shost = class_to_shost(dev);
92d7f7b0
JS
1281 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1282 struct lpfc_hba *phba = vport->phba;
1283 uint32_t cnt, acnt;
1284
858c9f6c 1285 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
92d7f7b0
JS
1286 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1287 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1288}
1289
e59058c4 1290/**
3621a710 1291 * lpfc_max_xri_show - Return maximum xri
e59058c4
JS
1292 * @dev: class device that is converted into a Scsi_host.
1293 * @attr: device attribute, not used.
1294 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1295 *
1296 * Description:
1297 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1298 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1299 * to "Unknown" and the buffer length is returned, therefore the caller
1300 * must check for "Unknown" in the buffer to detect a failure.
1301 *
1302 * Returns: size of formatted string.
1303 **/
92d7f7b0 1304static ssize_t
ee959b00
TJ
1305lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1306 char *buf)
92d7f7b0 1307{
ee959b00 1308 struct Scsi_Host *shost = class_to_shost(dev);
92d7f7b0
JS
1309 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1310 struct lpfc_hba *phba = vport->phba;
1311 uint32_t cnt;
1312
858c9f6c 1313 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
92d7f7b0
JS
1314 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1315 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1316}
1317
e59058c4 1318/**
3621a710 1319 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
e59058c4
JS
1320 * @dev: class device that is converted into a Scsi_host.
1321 * @attr: device attribute, not used.
1322 * @buf: on return contains the used xri count in decimal or "Unknown".
1323 *
1324 * Description:
1325 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1326 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1327 * to "Unknown" and the buffer length is returned, therefore the caller
1328 * must check for "Unknown" in the buffer to detect a failure.
1329 *
1330 * Returns: size of formatted string.
1331 **/
92d7f7b0 1332static ssize_t
ee959b00
TJ
1333lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1334 char *buf)
92d7f7b0 1335{
ee959b00 1336 struct Scsi_Host *shost = class_to_shost(dev);
92d7f7b0
JS
1337 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1338 struct lpfc_hba *phba = vport->phba;
1339 uint32_t cnt, acnt;
1340
858c9f6c
JS
1341 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1342 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1343 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1344}
1345
e59058c4 1346/**
3621a710 1347 * lpfc_max_vpi_show - Return maximum vpi
e59058c4
JS
1348 * @dev: class device that is converted into a Scsi_host.
1349 * @attr: device attribute, not used.
1350 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1351 *
1352 * Description:
1353 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1354 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1355 * to "Unknown" and the buffer length is returned, therefore the caller
1356 * must check for "Unknown" in the buffer to detect a failure.
1357 *
1358 * Returns: size of formatted string.
1359 **/
858c9f6c 1360static ssize_t
ee959b00
TJ
1361lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1362 char *buf)
858c9f6c 1363{
ee959b00 1364 struct Scsi_Host *shost = class_to_shost(dev);
858c9f6c
JS
1365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1366 struct lpfc_hba *phba = vport->phba;
1367 uint32_t cnt;
1368
1369 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1370 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1371 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1372}
1373
e59058c4 1374/**
3621a710 1375 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
e59058c4
JS
1376 * @dev: class device that is converted into a Scsi_host.
1377 * @attr: device attribute, not used.
1378 * @buf: on return contains the used vpi count in decimal or "Unknown".
1379 *
1380 * Description:
1381 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1382 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1383 * to "Unknown" and the buffer length is returned, therefore the caller
1384 * must check for "Unknown" in the buffer to detect a failure.
1385 *
1386 * Returns: size of formatted string.
1387 **/
858c9f6c 1388static ssize_t
ee959b00
TJ
1389lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1390 char *buf)
858c9f6c 1391{
ee959b00 1392 struct Scsi_Host *shost = class_to_shost(dev);
858c9f6c
JS
1393 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1394 struct lpfc_hba *phba = vport->phba;
1395 uint32_t cnt, acnt;
1396
1397 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
92d7f7b0
JS
1398 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1399 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1400}
1401
e59058c4 1402/**
3621a710 1403 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
e59058c4
JS
1404 * @dev: class device that is converted into a Scsi_host.
1405 * @attr: device attribute, not used.
1406 * @buf: text that must be interpreted to determine if npiv is supported.
1407 *
1408 * Description:
1409 * Buffer will contain text indicating npiv is not suppoerted on the port,
1410 * the port is an NPIV physical port, or it is an npiv virtual port with
1411 * the id of the vport.
1412 *
1413 * Returns: size of formatted string.
1414 **/
92d7f7b0 1415static ssize_t
ee959b00
TJ
1416lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1417 char *buf)
92d7f7b0 1418{
ee959b00 1419 struct Scsi_Host *shost = class_to_shost(dev);
92d7f7b0
JS
1420 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1421 struct lpfc_hba *phba = vport->phba;
1422
1423 if (!(phba->max_vpi))
1424 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1425 if (vport->port_type == LPFC_PHYSICAL_PORT)
1426 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1427 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1428}
1429
e59058c4 1430/**
3621a710 1431 * lpfc_poll_show - Return text about poll support for the adapter
e59058c4
JS
1432 * @dev: class device that is converted into a Scsi_host.
1433 * @attr: device attribute, not used.
1434 * @buf: on return contains the cfg_poll in hex.
1435 *
1436 * Notes:
1437 * cfg_poll should be a lpfc_polling_flags type.
1438 *
1439 * Returns: size of formatted string.
1440 **/
875fbdfe 1441static ssize_t
ee959b00
TJ
1442lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1443 char *buf)
875fbdfe 1444{
ee959b00 1445 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
1446 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1447 struct lpfc_hba *phba = vport->phba;
875fbdfe
JSEC
1448
1449 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1450}
1451
e59058c4 1452/**
3621a710 1453 * lpfc_poll_store - Set the value of cfg_poll for the adapter
e59058c4
JS
1454 * @dev: class device that is converted into a Scsi_host.
1455 * @attr: device attribute, not used.
1456 * @buf: one or more lpfc_polling_flags values.
1457 * @count: not used.
1458 *
1459 * Notes:
1460 * buf contents converted to integer and checked for a valid value.
1461 *
1462 * Returns:
1463 * -EINVAL if the buffer connot be converted or is out of range
1464 * length of the buf on success
1465 **/
875fbdfe 1466static ssize_t
ee959b00
TJ
1467lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1468 const char *buf, size_t count)
875fbdfe 1469{
ee959b00 1470 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
1471 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1472 struct lpfc_hba *phba = vport->phba;
875fbdfe
JSEC
1473 uint32_t creg_val;
1474 uint32_t old_val;
1475 int val=0;
1476
1477 if (!isdigit(buf[0]))
1478 return -EINVAL;
1479
1480 if (sscanf(buf, "%i", &val) != 1)
1481 return -EINVAL;
1482
1483 if ((val & 0x3) != val)
1484 return -EINVAL;
1485
45ed1190
JS
1486 if (phba->sli_rev == LPFC_SLI_REV4)
1487 val = 0;
1488
88a2cfbb
JS
1489 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1490 "3051 lpfc_poll changed from %d to %d\n",
1491 phba->cfg_poll, val);
1492
2e0fef85 1493 spin_lock_irq(&phba->hbalock);
875fbdfe
JSEC
1494
1495 old_val = phba->cfg_poll;
1496
1497 if (val & ENABLE_FCP_RING_POLLING) {
1498 if ((val & DISABLE_FCP_RING_INT) &&
1499 !(old_val & DISABLE_FCP_RING_INT)) {
9940b97b
JS
1500 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1501 spin_unlock_irq(&phba->hbalock);
1502 return -EINVAL;
1503 }
875fbdfe
JSEC
1504 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1505 writel(creg_val, phba->HCregaddr);
1506 readl(phba->HCregaddr); /* flush */
1507
1508 lpfc_poll_start_timer(phba);
1509 }
1510 } else if (val != 0x0) {
2e0fef85 1511 spin_unlock_irq(&phba->hbalock);
875fbdfe
JSEC
1512 return -EINVAL;
1513 }
1514
1515 if (!(val & DISABLE_FCP_RING_INT) &&
1516 (old_val & DISABLE_FCP_RING_INT))
1517 {
2e0fef85 1518 spin_unlock_irq(&phba->hbalock);
875fbdfe 1519 del_timer(&phba->fcp_poll_timer);
2e0fef85 1520 spin_lock_irq(&phba->hbalock);
9940b97b
JS
1521 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1522 spin_unlock_irq(&phba->hbalock);
1523 return -EINVAL;
1524 }
875fbdfe
JSEC
1525 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1526 writel(creg_val, phba->HCregaddr);
1527 readl(phba->HCregaddr); /* flush */
1528 }
1529
1530 phba->cfg_poll = val;
1531
2e0fef85 1532 spin_unlock_irq(&phba->hbalock);
875fbdfe
JSEC
1533
1534 return strlen(buf);
1535}
dea3101e 1536
bc73905a
JS
1537/**
1538 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1539 * @dev: class unused variable.
1540 * @attr: device attribute, not used.
1541 * @buf: on return contains the module description text.
1542 *
1543 * Returns: size of formatted string.
1544 **/
1545static ssize_t
1546lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1547 char *buf)
1548{
1549 struct Scsi_Host *shost = class_to_shost(dev);
1550 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1551 struct lpfc_hba *phba = vport->phba;
1552
1553 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1554}
1555
1556/**
1557 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1558 * @dev: class unused variable.
1559 * @attr: device attribute, not used.
1560 * @buf: on return contains the module description text.
1561 *
1562 * Returns: size of formatted string.
1563 **/
1564static ssize_t
1565lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1566 char *buf)
1567{
1568 struct Scsi_Host *shost = class_to_shost(dev);
1569 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1570 struct lpfc_hba *phba = vport->phba;
1571
1572 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1573}
1574
ab56dc2e
JS
1575/**
1576 * lpfc_dss_show - Return the current state of dss and the configured state
1577 * @dev: class converted to a Scsi_host structure.
1578 * @attr: device attribute, not used.
1579 * @buf: on return contains the formatted text.
1580 *
1581 * Returns: size of formatted string.
1582 **/
1583static ssize_t
1584lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1585 char *buf)
1586{
1587 struct Scsi_Host *shost = class_to_shost(dev);
1588 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1589 struct lpfc_hba *phba = vport->phba;
1590
1591 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1592 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1593 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1594 "" : "Not ");
1595}
1596
912e3acd
JS
1597/**
1598 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1599 * @dev: class converted to a Scsi_host structure.
1600 * @attr: device attribute, not used.
1601 * @buf: on return contains the formatted support level.
1602 *
1603 * Description:
1604 * Returns the maximum number of virtual functions a physical function can
1605 * support, 0 will be returned if called on virtual function.
1606 *
1607 * Returns: size of formatted string.
1608 **/
1609static ssize_t
1610lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1611 struct device_attribute *attr,
1612 char *buf)
1613{
1614 struct Scsi_Host *shost = class_to_shost(dev);
1615 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1616 struct lpfc_hba *phba = vport->phba;
0a96e975 1617 uint16_t max_nr_virtfn;
912e3acd 1618
0a96e975
JS
1619 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1620 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
912e3acd
JS
1621}
1622
e59058c4 1623/**
3621a710 1624 * lpfc_param_show - Return a cfg attribute value in decimal
e59058c4
JS
1625 *
1626 * Description:
1627 * Macro that given an attr e.g. hba_queue_depth expands
1628 * into a function with the name lpfc_hba_queue_depth_show.
1629 *
1630 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1631 * @dev: class device that is converted into a Scsi_host.
1632 * @attr: device attribute, not used.
1633 * @buf: on return contains the attribute value in decimal.
1634 *
1635 * Returns: size of formatted string.
1636 **/
dea3101e 1637#define lpfc_param_show(attr) \
1638static ssize_t \
ee959b00
TJ
1639lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1640 char *buf) \
dea3101e 1641{ \
ee959b00 1642 struct Scsi_Host *shost = class_to_shost(dev);\
2e0fef85
JS
1643 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1644 struct lpfc_hba *phba = vport->phba;\
7bcbb752
JSEC
1645 return snprintf(buf, PAGE_SIZE, "%d\n",\
1646 phba->cfg_##attr);\
1647}
1648
e59058c4 1649/**
3621a710 1650 * lpfc_param_hex_show - Return a cfg attribute value in hex
e59058c4
JS
1651 *
1652 * Description:
1653 * Macro that given an attr e.g. hba_queue_depth expands
1654 * into a function with the name lpfc_hba_queue_depth_show
1655 *
1656 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1657 * @dev: class device that is converted into a Scsi_host.
1658 * @attr: device attribute, not used.
3621a710 1659 * @buf: on return contains the attribute value in hexadecimal.
e59058c4
JS
1660 *
1661 * Returns: size of formatted string.
1662 **/
93a20f74
JSEC
1663#define lpfc_param_hex_show(attr) \
1664static ssize_t \
ee959b00
TJ
1665lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1666 char *buf) \
93a20f74 1667{ \
ee959b00 1668 struct Scsi_Host *shost = class_to_shost(dev);\
2e0fef85
JS
1669 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1670 struct lpfc_hba *phba = vport->phba;\
84d1b006 1671 uint val = 0;\
93a20f74
JSEC
1672 val = phba->cfg_##attr;\
1673 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1674 phba->cfg_##attr);\
1675}
1676
e59058c4 1677/**
b595076a 1678 * lpfc_param_init - Initializes a cfg attribute
e59058c4
JS
1679 *
1680 * Description:
1681 * Macro that given an attr e.g. hba_queue_depth expands
1682 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1683 * takes a default argument, a minimum and maximum argument.
1684 *
1685 * lpfc_##attr##_init: Initializes an attribute.
1686 * @phba: pointer the the adapter structure.
1687 * @val: integer attribute value.
1688 *
1689 * Validates the min and max values then sets the adapter config field
1690 * accordingly, or uses the default if out of range and prints an error message.
1691 *
1692 * Returns:
1693 * zero on success
1694 * -EINVAL if default used
1695 **/
7bcbb752
JSEC
1696#define lpfc_param_init(attr, default, minval, maxval) \
1697static int \
84d1b006 1698lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
7bcbb752
JSEC
1699{ \
1700 if (val >= minval && val <= maxval) {\
1701 phba->cfg_##attr = val;\
1702 return 0;\
dea3101e 1703 }\
7bcbb752 1704 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
e8b62011
JS
1705 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1706 "allowed range is ["#minval", "#maxval"]\n", val); \
7bcbb752
JSEC
1707 phba->cfg_##attr = default;\
1708 return -EINVAL;\
dea3101e 1709}
1710
e59058c4 1711/**
3621a710 1712 * lpfc_param_set - Set a cfg attribute value
e59058c4
JS
1713 *
1714 * Description:
1715 * Macro that given an attr e.g. hba_queue_depth expands
1716 * into a function with the name lpfc_hba_queue_depth_set
1717 *
1718 * lpfc_##attr##_set: Sets an attribute value.
1719 * @phba: pointer the the adapter structure.
1720 * @val: integer attribute value.
1721 *
1722 * Description:
1723 * Validates the min and max values then sets the
1724 * adapter config field if in the valid range. prints error message
1725 * and does not set the parameter if invalid.
1726 *
1727 * Returns:
1728 * zero on success
1729 * -EINVAL if val is invalid
1730 **/
7bcbb752
JSEC
1731#define lpfc_param_set(attr, default, minval, maxval) \
1732static int \
84d1b006 1733lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
7bcbb752
JSEC
1734{ \
1735 if (val >= minval && val <= maxval) {\
88a2cfbb
JS
1736 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1737 "3052 lpfc_" #attr " changed from %d to %d\n", \
1738 phba->cfg_##attr, val); \
7bcbb752
JSEC
1739 phba->cfg_##attr = val;\
1740 return 0;\
1741 }\
1742 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
e8b62011
JS
1743 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1744 "allowed range is ["#minval", "#maxval"]\n", val); \
7bcbb752
JSEC
1745 return -EINVAL;\
1746}
1747
e59058c4 1748/**
3621a710 1749 * lpfc_param_store - Set a vport attribute value
e59058c4
JS
1750 *
1751 * Description:
1752 * Macro that given an attr e.g. hba_queue_depth expands
1753 * into a function with the name lpfc_hba_queue_depth_store.
1754 *
1755 * lpfc_##attr##_store: Set an sttribute value.
1756 * @dev: class device that is converted into a Scsi_host.
1757 * @attr: device attribute, not used.
1758 * @buf: contains the attribute value in ascii.
1759 * @count: not used.
1760 *
1761 * Description:
1762 * Convert the ascii text number to an integer, then
1763 * use the lpfc_##attr##_set function to set the value.
1764 *
1765 * Returns:
1766 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1767 * length of buffer upon success.
1768 **/
7bcbb752 1769#define lpfc_param_store(attr) \
dea3101e 1770static ssize_t \
ee959b00
TJ
1771lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1772 const char *buf, size_t count) \
dea3101e 1773{ \
ee959b00 1774 struct Scsi_Host *shost = class_to_shost(dev);\
2e0fef85
JS
1775 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1776 struct lpfc_hba *phba = vport->phba;\
84d1b006 1777 uint val = 0;\
93a20f74
JSEC
1778 if (!isdigit(buf[0]))\
1779 return -EINVAL;\
1780 if (sscanf(buf, "%i", &val) != 1)\
1781 return -EINVAL;\
7bcbb752 1782 if (lpfc_##attr##_set(phba, val) == 0) \
755c0d06 1783 return strlen(buf);\
7bcbb752
JSEC
1784 else \
1785 return -EINVAL;\
dea3101e 1786}
1787
e59058c4 1788/**
3621a710 1789 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
e59058c4
JS
1790 *
1791 * Description:
1792 * Macro that given an attr e.g. hba_queue_depth expands
1793 * into a function with the name lpfc_hba_queue_depth_show
1794 *
1795 * lpfc_##attr##_show: prints the attribute value in decimal.
1796 * @dev: class device that is converted into a Scsi_host.
1797 * @attr: device attribute, not used.
1798 * @buf: on return contains the attribute value in decimal.
1799 *
1800 * Returns: length of formatted string.
1801 **/
3de2a653
JS
1802#define lpfc_vport_param_show(attr) \
1803static ssize_t \
ee959b00
TJ
1804lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1805 char *buf) \
3de2a653 1806{ \
ee959b00 1807 struct Scsi_Host *shost = class_to_shost(dev);\
3de2a653 1808 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
3de2a653
JS
1809 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1810}
1811
e59058c4 1812/**
3621a710 1813 * lpfc_vport_param_hex_show - Return hex formatted attribute value
e59058c4
JS
1814 *
1815 * Description:
1816 * Macro that given an attr e.g.
1817 * hba_queue_depth expands into a function with the name
1818 * lpfc_hba_queue_depth_show
1819 *
3621a710 1820 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
e59058c4
JS
1821 * @dev: class device that is converted into a Scsi_host.
1822 * @attr: device attribute, not used.
3621a710 1823 * @buf: on return contains the attribute value in hexadecimal.
e59058c4
JS
1824 *
1825 * Returns: length of formatted string.
1826 **/
3de2a653
JS
1827#define lpfc_vport_param_hex_show(attr) \
1828static ssize_t \
ee959b00
TJ
1829lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1830 char *buf) \
3de2a653 1831{ \
ee959b00 1832 struct Scsi_Host *shost = class_to_shost(dev);\
3de2a653 1833 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
3de2a653
JS
1834 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1835}
1836
e59058c4 1837/**
3621a710 1838 * lpfc_vport_param_init - Initialize a vport cfg attribute
e59058c4
JS
1839 *
1840 * Description:
1841 * Macro that given an attr e.g. hba_queue_depth expands
1842 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1843 * takes a default argument, a minimum and maximum argument.
1844 *
1845 * lpfc_##attr##_init: validates the min and max values then sets the
1846 * adapter config field accordingly, or uses the default if out of range
1847 * and prints an error message.
1848 * @phba: pointer the the adapter structure.
1849 * @val: integer attribute value.
1850 *
1851 * Returns:
1852 * zero on success
1853 * -EINVAL if default used
1854 **/
3de2a653
JS
1855#define lpfc_vport_param_init(attr, default, minval, maxval) \
1856static int \
84d1b006 1857lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
3de2a653
JS
1858{ \
1859 if (val >= minval && val <= maxval) {\
1860 vport->cfg_##attr = val;\
1861 return 0;\
1862 }\
e8b62011 1863 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
d7c255b2 1864 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
e8b62011 1865 "allowed range is ["#minval", "#maxval"]\n", val); \
3de2a653
JS
1866 vport->cfg_##attr = default;\
1867 return -EINVAL;\
1868}
1869
e59058c4 1870/**
3621a710 1871 * lpfc_vport_param_set - Set a vport cfg attribute
e59058c4
JS
1872 *
1873 * Description:
1874 * Macro that given an attr e.g. hba_queue_depth expands
1875 * into a function with the name lpfc_hba_queue_depth_set
1876 *
1877 * lpfc_##attr##_set: validates the min and max values then sets the
1878 * adapter config field if in the valid range. prints error message
1879 * and does not set the parameter if invalid.
1880 * @phba: pointer the the adapter structure.
1881 * @val: integer attribute value.
1882 *
1883 * Returns:
1884 * zero on success
1885 * -EINVAL if val is invalid
1886 **/
3de2a653
JS
1887#define lpfc_vport_param_set(attr, default, minval, maxval) \
1888static int \
84d1b006 1889lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
3de2a653
JS
1890{ \
1891 if (val >= minval && val <= maxval) {\
88a2cfbb 1892 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
14660f4f
JS
1893 "3053 lpfc_" #attr \
1894 " changed from %d (x%x) to %d (x%x)\n", \
1895 vport->cfg_##attr, vport->cfg_##attr, \
1896 val, val); \
3de2a653
JS
1897 vport->cfg_##attr = val;\
1898 return 0;\
1899 }\
e8b62011 1900 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
d7c255b2 1901 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
e8b62011 1902 "allowed range is ["#minval", "#maxval"]\n", val); \
3de2a653
JS
1903 return -EINVAL;\
1904}
1905
e59058c4 1906/**
3621a710 1907 * lpfc_vport_param_store - Set a vport attribute
e59058c4
JS
1908 *
1909 * Description:
1910 * Macro that given an attr e.g. hba_queue_depth
1911 * expands into a function with the name lpfc_hba_queue_depth_store
1912 *
1913 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1914 * use the lpfc_##attr##_set function to set the value.
1915 * @cdev: class device that is converted into a Scsi_host.
1916 * @buf: contains the attribute value in decimal.
1917 * @count: not used.
1918 *
1919 * Returns:
1920 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1921 * length of buffer upon success.
1922 **/
3de2a653
JS
1923#define lpfc_vport_param_store(attr) \
1924static ssize_t \
ee959b00
TJ
1925lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1926 const char *buf, size_t count) \
3de2a653 1927{ \
ee959b00 1928 struct Scsi_Host *shost = class_to_shost(dev);\
3de2a653 1929 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
84d1b006 1930 uint val = 0;\
3de2a653
JS
1931 if (!isdigit(buf[0]))\
1932 return -EINVAL;\
1933 if (sscanf(buf, "%i", &val) != 1)\
1934 return -EINVAL;\
1935 if (lpfc_##attr##_set(vport, val) == 0) \
1936 return strlen(buf);\
1937 else \
1938 return -EINVAL;\
1939}
1940
1941
7bcbb752 1942#define LPFC_ATTR(name, defval, minval, maxval, desc) \
84d1b006 1943static uint lpfc_##name = defval;\
ab56dc2e 1944module_param(lpfc_##name, uint, S_IRUGO);\
dea3101e 1945MODULE_PARM_DESC(lpfc_##name, desc);\
7bcbb752 1946lpfc_param_init(name, defval, minval, maxval)
dea3101e 1947
1948#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
84d1b006 1949static uint lpfc_##name = defval;\
ab56dc2e 1950module_param(lpfc_##name, uint, S_IRUGO);\
dea3101e 1951MODULE_PARM_DESC(lpfc_##name, desc);\
1952lpfc_param_show(name)\
7bcbb752 1953lpfc_param_init(name, defval, minval, maxval)\
ee959b00 1954static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea3101e 1955
1956#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
84d1b006 1957static uint lpfc_##name = defval;\
ab56dc2e 1958module_param(lpfc_##name, uint, S_IRUGO);\
dea3101e 1959MODULE_PARM_DESC(lpfc_##name, desc);\
1960lpfc_param_show(name)\
7bcbb752
JSEC
1961lpfc_param_init(name, defval, minval, maxval)\
1962lpfc_param_set(name, defval, minval, maxval)\
1963lpfc_param_store(name)\
ee959b00
TJ
1964static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1965 lpfc_##name##_show, lpfc_##name##_store)
dea3101e 1966
93a20f74 1967#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
84d1b006 1968static uint lpfc_##name = defval;\
ab56dc2e 1969module_param(lpfc_##name, uint, S_IRUGO);\
93a20f74
JSEC
1970MODULE_PARM_DESC(lpfc_##name, desc);\
1971lpfc_param_hex_show(name)\
1972lpfc_param_init(name, defval, minval, maxval)\
ee959b00 1973static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
93a20f74
JSEC
1974
1975#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
84d1b006 1976static uint lpfc_##name = defval;\
ab56dc2e 1977module_param(lpfc_##name, uint, S_IRUGO);\
93a20f74
JSEC
1978MODULE_PARM_DESC(lpfc_##name, desc);\
1979lpfc_param_hex_show(name)\
1980lpfc_param_init(name, defval, minval, maxval)\
1981lpfc_param_set(name, defval, minval, maxval)\
1982lpfc_param_store(name)\
ee959b00
TJ
1983static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1984 lpfc_##name##_show, lpfc_##name##_store)
93a20f74 1985
3de2a653 1986#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
84d1b006 1987static uint lpfc_##name = defval;\
ab56dc2e 1988module_param(lpfc_##name, uint, S_IRUGO);\
3de2a653
JS
1989MODULE_PARM_DESC(lpfc_##name, desc);\
1990lpfc_vport_param_init(name, defval, minval, maxval)
1991
1992#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
84d1b006 1993static uint lpfc_##name = defval;\
ab56dc2e 1994module_param(lpfc_##name, uint, S_IRUGO);\
3de2a653
JS
1995MODULE_PARM_DESC(lpfc_##name, desc);\
1996lpfc_vport_param_show(name)\
1997lpfc_vport_param_init(name, defval, minval, maxval)\
ee959b00 1998static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
3de2a653 1999
1abf635d
HR
2000#define LPFC_VPORT_ULL_ATTR_R(name, defval, minval, maxval, desc) \
2001static uint64_t lpfc_##name = defval;\
2002module_param(lpfc_##name, ullong, S_IRUGO);\
2003MODULE_PARM_DESC(lpfc_##name, desc);\
2004lpfc_vport_param_show(name)\
2005lpfc_vport_param_init(name, defval, minval, maxval)\
2006static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
2007
3de2a653 2008#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
84d1b006 2009static uint lpfc_##name = defval;\
ab56dc2e 2010module_param(lpfc_##name, uint, S_IRUGO);\
3de2a653
JS
2011MODULE_PARM_DESC(lpfc_##name, desc);\
2012lpfc_vport_param_show(name)\
2013lpfc_vport_param_init(name, defval, minval, maxval)\
2014lpfc_vport_param_set(name, defval, minval, maxval)\
2015lpfc_vport_param_store(name)\
ee959b00
TJ
2016static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
2017 lpfc_##name##_show, lpfc_##name##_store)
3de2a653
JS
2018
2019#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
84d1b006 2020static uint lpfc_##name = defval;\
ab56dc2e 2021module_param(lpfc_##name, uint, S_IRUGO);\
3de2a653
JS
2022MODULE_PARM_DESC(lpfc_##name, desc);\
2023lpfc_vport_param_hex_show(name)\
2024lpfc_vport_param_init(name, defval, minval, maxval)\
ee959b00 2025static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
3de2a653
JS
2026
2027#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
84d1b006 2028static uint lpfc_##name = defval;\
ab56dc2e 2029module_param(lpfc_##name, uint, S_IRUGO);\
3de2a653
JS
2030MODULE_PARM_DESC(lpfc_##name, desc);\
2031lpfc_vport_param_hex_show(name)\
2032lpfc_vport_param_init(name, defval, minval, maxval)\
2033lpfc_vport_param_set(name, defval, minval, maxval)\
2034lpfc_vport_param_store(name)\
ee959b00
TJ
2035static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
2036 lpfc_##name##_show, lpfc_##name##_store)
2037
81301a9b
JS
2038static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2039static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2040static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2041static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
ee959b00
TJ
2042static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2043static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2044static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2045static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2046static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2047static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2048static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2049static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
84d1b006
JS
2050static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2051 lpfc_link_state_store);
ee959b00
TJ
2052static DEVICE_ATTR(option_rom_version, S_IRUGO,
2053 lpfc_option_rom_version_show, NULL);
2054static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2055 lpfc_num_discovered_ports_show, NULL);
84774a4d 2056static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
ee959b00
TJ
2057static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2058static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
45ed1190 2059static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
ee959b00
TJ
2060static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2061 lpfc_board_mode_show, lpfc_board_mode_store);
2062static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2063static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2064static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2065static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2066static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2067static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2068static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2069static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2070static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
bc73905a
JS
2071static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2072static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
ab56dc2e 2073static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
912e3acd
JS
2074static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2075 lpfc_sriov_hw_max_virtfn_show, NULL);
026abb87 2076static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
1ba981fd
JS
2077static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2078 NULL);
c3f28afa 2079
a12e07bc 2080static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1ba981fd
JS
2081#define WWN_SZ 8
2082/**
2083 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2084 * @buf: WWN string.
2085 * @cnt: Length of string.
2086 * @wwn: Array to receive converted wwn value.
2087 *
2088 * Returns:
2089 * -EINVAL if the buffer does not contain a valid wwn
2090 * 0 success
2091 **/
2092static size_t
2093lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2094{
2095 unsigned int i, j;
2096
2097 /* Count may include a LF at end of string */
2098 if (buf[cnt-1] == '\n')
2099 cnt--;
c3f28afa 2100
1ba981fd
JS
2101 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2102 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2103 return -EINVAL;
2104
2105 memset(wwn, 0, WWN_SZ);
2106
2107 /* Validate and store the new name */
2108 for (i = 0, j = 0; i < 16; i++) {
2109 if ((*buf >= 'a') && (*buf <= 'f'))
2110 j = ((j << 4) | ((*buf++ - 'a') + 10));
2111 else if ((*buf >= 'A') && (*buf <= 'F'))
2112 j = ((j << 4) | ((*buf++ - 'A') + 10));
2113 else if ((*buf >= '0') && (*buf <= '9'))
2114 j = ((j << 4) | (*buf++ - '0'));
2115 else
2116 return -EINVAL;
2117 if (i % 2) {
2118 wwn[i/2] = j & 0xff;
2119 j = 0;
2120 }
2121 }
2122 return 0;
2123}
e59058c4 2124/**
3621a710 2125 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
e59058c4
JS
2126 * @dev: class device that is converted into a Scsi_host.
2127 * @attr: device attribute, not used.
2128 * @buf: containing the string lpfc_soft_wwn_key.
2129 * @count: must be size of lpfc_soft_wwn_key.
2130 *
2131 * Returns:
2132 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2133 * length of buf indicates success
2134 **/
c3f28afa 2135static ssize_t
ee959b00
TJ
2136lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2137 const char *buf, size_t count)
c3f28afa 2138{
ee959b00 2139 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
2140 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2141 struct lpfc_hba *phba = vport->phba;
c3f28afa
JS
2142 unsigned int cnt = count;
2143
2144 /*
2145 * We're doing a simple sanity check for soft_wwpn setting.
2146 * We require that the user write a specific key to enable
2147 * the soft_wwpn attribute to be settable. Once the attribute
2148 * is written, the enable key resets. If further updates are
2149 * desired, the key must be written again to re-enable the
2150 * attribute.
2151 *
2152 * The "key" is not secret - it is a hardcoded string shown
2153 * here. The intent is to protect against the random user or
2154 * application that is just writing attributes.
2155 */
2156
2157 /* count may include a LF at end of string */
2158 if (buf[cnt-1] == '\n')
2159 cnt--;
2160
a12e07bc
JS
2161 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2162 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
c3f28afa
JS
2163 return -EINVAL;
2164
a12e07bc 2165 phba->soft_wwn_enable = 1;
c3f28afa
JS
2166 return count;
2167}
ee959b00
TJ
2168static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2169 lpfc_soft_wwn_enable_store);
c3f28afa 2170
e59058c4 2171/**
3621a710 2172 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
e59058c4
JS
2173 * @dev: class device that is converted into a Scsi_host.
2174 * @attr: device attribute, not used.
3621a710 2175 * @buf: on return contains the wwpn in hexadecimal.
e59058c4
JS
2176 *
2177 * Returns: size of formatted string.
2178 **/
c3f28afa 2179static ssize_t
ee959b00
TJ
2180lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2181 char *buf)
c3f28afa 2182{
ee959b00 2183 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
2184 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2185 struct lpfc_hba *phba = vport->phba;
2186
afc071e6
RD
2187 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2188 (unsigned long long)phba->cfg_soft_wwpn);
c3f28afa
JS
2189}
2190
e59058c4 2191/**
3621a710 2192 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
e59058c4
JS
2193 * @dev class device that is converted into a Scsi_host.
2194 * @attr: device attribute, not used.
3621a710 2195 * @buf: contains the wwpn in hexadecimal.
e59058c4
JS
2196 * @count: number of wwpn bytes in buf
2197 *
2198 * Returns:
2199 * -EACCES hba reset not enabled, adapter over temp
2200 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2201 * -EIO error taking adapter offline or online
2202 * value of count on success
2203 **/
c3f28afa 2204static ssize_t
ee959b00
TJ
2205lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2206 const char *buf, size_t count)
c3f28afa 2207{
ee959b00 2208 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
2209 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2210 struct lpfc_hba *phba = vport->phba;
c3f28afa 2211 struct completion online_compl;
1ba981fd
JS
2212 int stat1 = 0, stat2 = 0;
2213 unsigned int cnt = count;
2214 u8 wwpn[WWN_SZ];
fedd3b7b 2215 int rc;
c3f28afa 2216
13815c83
JS
2217 if (!phba->cfg_enable_hba_reset)
2218 return -EACCES;
7af67051
JS
2219 spin_lock_irq(&phba->hbalock);
2220 if (phba->over_temp_state == HBA_OVER_TEMP) {
2221 spin_unlock_irq(&phba->hbalock);
09372820 2222 return -EACCES;
7af67051
JS
2223 }
2224 spin_unlock_irq(&phba->hbalock);
c3f28afa
JS
2225 /* count may include a LF at end of string */
2226 if (buf[cnt-1] == '\n')
2227 cnt--;
2228
1ba981fd 2229 if (!phba->soft_wwn_enable)
c3f28afa
JS
2230 return -EINVAL;
2231
1ba981fd 2232 /* lock setting wwpn, wwnn down */
a12e07bc 2233 phba->soft_wwn_enable = 0;
c3f28afa 2234
1ba981fd
JS
2235 rc = lpfc_wwn_set(buf, cnt, wwpn);
2236 if (!rc) {
2237 /* not able to set wwpn, unlock it */
2238 phba->soft_wwn_enable = 1;
2239 return rc;
c3f28afa 2240 }
1ba981fd 2241
c3f28afa 2242 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2e0fef85 2243 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
a12e07bc 2244 if (phba->cfg_soft_wwnn)
2e0fef85 2245 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
c3f28afa
JS
2246
2247 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2248 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2249
46fa311e 2250 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
c3f28afa
JS
2251 if (stat1)
2252 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
e8b62011
JS
2253 "0463 lpfc_soft_wwpn attribute set failed to "
2254 "reinit adapter - %d\n", stat1);
c3f28afa 2255 init_completion(&online_compl);
fedd3b7b
JS
2256 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2257 LPFC_EVT_ONLINE);
2258 if (rc == 0)
2259 return -ENOMEM;
2260
c3f28afa
JS
2261 wait_for_completion(&online_compl);
2262 if (stat2)
2263 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
e8b62011
JS
2264 "0464 lpfc_soft_wwpn attribute set failed to "
2265 "reinit adapter - %d\n", stat2);
c3f28afa
JS
2266 return (stat1 || stat2) ? -EIO : count;
2267}
1ba981fd 2268static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
ee959b00 2269 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
c3f28afa 2270
e59058c4 2271/**
3621a710 2272 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
e59058c4
JS
2273 * @dev: class device that is converted into a Scsi_host.
2274 * @attr: device attribute, not used.
3621a710 2275 * @buf: on return contains the wwnn in hexadecimal.
e59058c4
JS
2276 *
2277 * Returns: size of formatted string.
2278 **/
a12e07bc 2279static ssize_t
ee959b00
TJ
2280lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2281 char *buf)
a12e07bc 2282{
ee959b00 2283 struct Scsi_Host *shost = class_to_shost(dev);
51ef4c26 2284 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
a12e07bc
JS
2285 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2286 (unsigned long long)phba->cfg_soft_wwnn);
2287}
2288
e59058c4 2289/**
3621a710 2290 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
e59058c4 2291 * @cdev: class device that is converted into a Scsi_host.
3621a710 2292 * @buf: contains the ww node name in hexadecimal.
e59058c4
JS
2293 * @count: number of wwnn bytes in buf.
2294 *
2295 * Returns:
2296 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2297 * value of count on success
2298 **/
a12e07bc 2299static ssize_t
ee959b00
TJ
2300lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2301 const char *buf, size_t count)
a12e07bc 2302{
ee959b00 2303 struct Scsi_Host *shost = class_to_shost(dev);
51ef4c26 2304 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1ba981fd
JS
2305 unsigned int cnt = count;
2306 u8 wwnn[WWN_SZ];
2307 int rc;
a12e07bc
JS
2308
2309 /* count may include a LF at end of string */
2310 if (buf[cnt-1] == '\n')
2311 cnt--;
2312
1ba981fd 2313 if (!phba->soft_wwn_enable)
a12e07bc
JS
2314 return -EINVAL;
2315
1ba981fd
JS
2316 rc = lpfc_wwn_set(buf, cnt, wwnn);
2317 if (!rc) {
2318 /* Allow wwnn to be set many times, as long as the enable
2319 * is set. However, once the wwpn is set, everything locks.
2320 */
2321 return rc;
a12e07bc 2322 }
1ba981fd 2323
a12e07bc
JS
2324 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2325
2326 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2327 "lpfc%d: soft_wwnn set. Value will take effect upon "
2328 "setting of the soft_wwpn\n", phba->brd_no);
2329
2330 return count;
2331}
1ba981fd 2332static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
ee959b00 2333 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
a12e07bc 2334
1ba981fd
JS
2335/**
2336 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2337 * Optimized Access Storage (OAS) operations.
2338 * @dev: class device that is converted into a Scsi_host.
2339 * @attr: device attribute, not used.
2340 * @buf: buffer for passing information.
2341 *
2342 * Returns:
2343 * value of count
2344 **/
2345static ssize_t
2346lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2347 char *buf)
2348{
2349 struct Scsi_Host *shost = class_to_shost(dev);
2350 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2351
2352 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2353 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2354}
2355
2356/**
2357 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2358 * Optimized Access Storage (OAS) operations.
2359 * @dev: class device that is converted into a Scsi_host.
2360 * @attr: device attribute, not used.
2361 * @buf: buffer for passing information.
2362 * @count: Size of the data buffer.
2363 *
2364 * Returns:
2365 * -EINVAL count is invalid, invalid wwpn byte invalid
2366 * -EPERM oas is not supported by hba
2367 * value of count on success
2368 **/
2369static ssize_t
2370lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2371 const char *buf, size_t count)
2372{
2373 struct Scsi_Host *shost = class_to_shost(dev);
2374 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2375 unsigned int cnt = count;
2376 uint8_t wwpn[WWN_SZ];
2377 int rc;
2378
f38fa0bb 2379 if (!phba->cfg_fof)
1ba981fd
JS
2380 return -EPERM;
2381
2382 /* count may include a LF at end of string */
2383 if (buf[cnt-1] == '\n')
2384 cnt--;
2385
2386 rc = lpfc_wwn_set(buf, cnt, wwpn);
2387 if (rc)
2388 return rc;
2389
2390 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2391 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2392 if (wwn_to_u64(wwpn) == 0)
2393 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2394 else
2395 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2396 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2397 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2398 return count;
2399}
2400static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2401 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2402
2403/**
2404 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2405 * for Optimized Access Storage (OAS) operations.
2406 * @dev: class device that is converted into a Scsi_host.
2407 * @attr: device attribute, not used.
2408 * @buf: buffer for passing information.
2409 *
2410 * Returns:
2411 * value of count on success
2412 **/
2413static ssize_t
2414lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2415 char *buf)
2416{
2417 struct Scsi_Host *shost = class_to_shost(dev);
2418 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2419
2420 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2421 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2422}
2423
2424/**
2425 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2426 * for Optimized Access Storage (OAS) operations.
2427 * @dev: class device that is converted into a Scsi_host.
2428 * @attr: device attribute, not used.
2429 * @buf: buffer for passing information.
2430 * @count: Size of the data buffer.
2431 *
2432 * Returns:
2433 * -EINVAL count is invalid, invalid wwpn byte invalid
2434 * -EPERM oas is not supported by hba
2435 * value of count on success
2436 **/
2437static ssize_t
2438lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2439 const char *buf, size_t count)
2440{
2441 struct Scsi_Host *shost = class_to_shost(dev);
2442 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2443 unsigned int cnt = count;
2444 uint8_t wwpn[WWN_SZ];
2445 int rc;
2446
f38fa0bb 2447 if (!phba->cfg_fof)
1ba981fd
JS
2448 return -EPERM;
2449
2450 /* count may include a LF at end of string */
2451 if (buf[cnt-1] == '\n')
2452 cnt--;
2453
2454 rc = lpfc_wwn_set(buf, cnt, wwpn);
2455 if (rc)
2456 return rc;
2457
2458 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2459 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2460 if (wwn_to_u64(wwpn) == 0)
2461 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2462 else
2463 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2464 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2465 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2466 return count;
2467}
2468static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2469 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2470
2471/**
2472 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2473 * of whether luns will be enabled or disabled
2474 * for Optimized Access Storage (OAS) operations.
2475 * @dev: class device that is converted into a Scsi_host.
2476 * @attr: device attribute, not used.
2477 * @buf: buffer for passing information.
2478 *
2479 * Returns:
2480 * size of formatted string.
2481 **/
2482static ssize_t
2483lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2484 char *buf)
2485{
2486 struct Scsi_Host *shost = class_to_shost(dev);
2487 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2488
2489 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2490}
2491
2492/**
2493 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2494 * of whether luns will be enabled or disabled
2495 * for Optimized Access Storage (OAS) operations.
2496 * @dev: class device that is converted into a Scsi_host.
2497 * @attr: device attribute, not used.
2498 * @buf: buffer for passing information.
2499 * @count: Size of the data buffer.
2500 *
2501 * Returns:
2502 * -EINVAL count is invalid, invalid wwpn byte invalid
2503 * -EPERM oas is not supported by hba
2504 * value of count on success
2505 **/
2506static ssize_t
2507lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2508 const char *buf, size_t count)
2509{
2510 struct Scsi_Host *shost = class_to_shost(dev);
2511 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2512 int val = 0;
2513
f38fa0bb 2514 if (!phba->cfg_fof)
1ba981fd
JS
2515 return -EPERM;
2516
2517 if (!isdigit(buf[0]))
2518 return -EINVAL;
2519
2520 if (sscanf(buf, "%i", &val) != 1)
2521 return -EINVAL;
2522
2523 if ((val != 0) && (val != 1))
2524 return -EINVAL;
2525
2526 phba->cfg_oas_lun_state = val;
2527
2528 return strlen(buf);
2529}
2530static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2531 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2532
2533/**
2534 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2535 * Storage (OAS) lun returned by the
2536 * lpfc_oas_lun_show function.
2537 * @dev: class device that is converted into a Scsi_host.
2538 * @attr: device attribute, not used.
2539 * @buf: buffer for passing information.
2540 *
2541 * Returns:
2542 * size of formatted string.
2543 **/
2544static ssize_t
2545lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2546 char *buf)
2547{
2548 struct Scsi_Host *shost = class_to_shost(dev);
2549 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2550
2551 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2552 return -EFAULT;
2553
2554 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2555}
2556static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2557 lpfc_oas_lun_status_show, NULL);
2558
2559
2560/**
2561 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2562 * (OAS) operations.
2563 * @phba: lpfc_hba pointer.
2564 * @ndlp: pointer to fcp target node.
2565 * @lun: the fc lun for setting oas state.
2566 * @oas_state: the oas state to be set to the lun.
2567 *
2568 * Returns:
2569 * SUCCESS : 0
2570 * -EPERM OAS is not enabled or not supported by this port.
2571 *
2572 */
2573static size_t
2574lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2575 uint8_t tgt_wwpn[], uint64_t lun, uint32_t oas_state)
2576{
2577
2578 int rc = 0;
2579
f38fa0bb 2580 if (!phba->cfg_fof)
1ba981fd
JS
2581 return -EPERM;
2582
2583 if (oas_state) {
2584 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2585 (struct lpfc_name *)tgt_wwpn, lun))
2586 rc = -ENOMEM;
2587 } else {
2588 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2589 (struct lpfc_name *)tgt_wwpn, lun);
2590 }
2591 return rc;
2592
2593}
2594
2595/**
2596 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2597 * Access Storage (OAS) operations.
2598 * @phba: lpfc_hba pointer.
2599 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2600 * @tgt_wwpn: wwpn of the target associated with the returned lun
2601 * @lun_status: status of the lun returned lun
2602 *
2603 * Returns the first or next lun enabled for OAS operations for the vport/target
2604 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2605 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2606 *
2607 * Return:
2608 * lun that is OAS enabled for the vport/target
2609 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2610 */
2611static uint64_t
2612lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2613 uint8_t tgt_wwpn[], uint32_t *lun_status)
2614{
2615 uint64_t found_lun;
2616
2617 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2618 return NOT_OAS_ENABLED_LUN;
2619 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2620 phba->sli4_hba.oas_next_vpt_wwpn,
2621 (struct lpfc_name *)
2622 phba->sli4_hba.oas_next_tgt_wwpn,
2623 &phba->sli4_hba.oas_next_lun,
2624 (struct lpfc_name *)vpt_wwpn,
2625 (struct lpfc_name *)tgt_wwpn,
2626 &found_lun, lun_status))
2627 return found_lun;
2628 else
2629 return NOT_OAS_ENABLED_LUN;
2630}
2631
2632/**
2633 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2634 * @phba: lpfc_hba pointer.
2635 * @vpt_wwpn: vport wwpn by reference.
2636 * @tgt_wwpn: target wwpn by reference.
2637 * @lun: the fc lun for setting oas state.
2638 * @oas_state: the oas state to be set to the oas_lun.
2639 *
2640 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2641 * a lun for OAS operations.
2642 *
2643 * Return:
2644 * SUCCESS: 0
2645 * -ENOMEM: failed to enable an lun for OAS operations
2646 * -EPERM: OAS is not enabled
2647 */
2648static ssize_t
2649lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2650 uint8_t tgt_wwpn[], uint64_t lun,
2651 uint32_t oas_state)
2652{
2653
2654 int rc;
2655
2656 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
2657 oas_state);
2658 return rc;
2659}
2660
2661/**
2662 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2663 * @dev: class device that is converted into a Scsi_host.
2664 * @attr: device attribute, not used.
2665 * @buf: buffer for passing information.
2666 *
2667 * This routine returns a lun enabled for OAS each time the function
2668 * is called.
2669 *
2670 * Returns:
2671 * SUCCESS: size of formatted string.
2672 * -EFAULT: target or vport wwpn was not set properly.
2673 * -EPERM: oas is not enabled.
2674 **/
2675static ssize_t
2676lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2677 char *buf)
2678{
2679 struct Scsi_Host *shost = class_to_shost(dev);
2680 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2681
2682 uint64_t oas_lun;
2683 int len = 0;
2684
f38fa0bb 2685 if (!phba->cfg_fof)
1ba981fd
JS
2686 return -EPERM;
2687
2688 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2689 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2690 return -EFAULT;
2691
2692 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2693 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2694 return -EFAULT;
2695
2696 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2697 phba->cfg_oas_tgt_wwpn,
2698 &phba->cfg_oas_lun_status);
2699 if (oas_lun != NOT_OAS_ENABLED_LUN)
2700 phba->cfg_oas_flags |= OAS_LUN_VALID;
2701
2702 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2703
2704 return len;
2705}
2706
2707/**
2708 * lpfc_oas_lun_store - Sets the OAS state for lun
2709 * @dev: class device that is converted into a Scsi_host.
2710 * @attr: device attribute, not used.
2711 * @buf: buffer for passing information.
2712 *
2713 * This function sets the OAS state for lun. Before this function is called,
2714 * the vport wwpn, target wwpn, and oas state need to be set.
2715 *
2716 * Returns:
2717 * SUCCESS: size of formatted string.
2718 * -EFAULT: target or vport wwpn was not set properly.
2719 * -EPERM: oas is not enabled.
2720 * size of formatted string.
2721 **/
2722static ssize_t
2723lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2724 const char *buf, size_t count)
2725{
2726 struct Scsi_Host *shost = class_to_shost(dev);
2727 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2728 uint64_t scsi_lun;
2729 ssize_t rc;
2730
f38fa0bb 2731 if (!phba->cfg_fof)
1ba981fd
JS
2732 return -EPERM;
2733
2734 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2735 return -EFAULT;
2736
2737 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2738 return -EFAULT;
2739
2740 if (!isdigit(buf[0]))
2741 return -EINVAL;
2742
2743 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
2744 return -EINVAL;
2745
2746 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2747 "3372 Try to set vport 0x%llx target 0x%llx lun:%lld "
2748 "with oas set to %d\n",
2749 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
2750 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
2751 phba->cfg_oas_lun_state);
2752
2753 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
2754 phba->cfg_oas_tgt_wwpn, scsi_lun,
2755 phba->cfg_oas_lun_state);
2756
2757 if (rc)
2758 return rc;
2759
2760 return count;
2761}
2762static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
2763 lpfc_oas_lun_show, lpfc_oas_lun_store);
c3f28afa 2764
875fbdfe 2765static int lpfc_poll = 0;
ab56dc2e 2766module_param(lpfc_poll, int, S_IRUGO);
875fbdfe
JSEC
2767MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2768 " 0 - none,"
2769 " 1 - poll with interrupts enabled"
2770 " 3 - poll and disable FCP ring interrupts");
2771
ee959b00
TJ
2772static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2773 lpfc_poll_show, lpfc_poll_store);
dea3101e 2774
92d7f7b0 2775int lpfc_sli_mode = 0;
ab56dc2e 2776module_param(lpfc_sli_mode, int, S_IRUGO);
92d7f7b0
JS
2777MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2778 " 0 - auto (SLI-3 if supported),"
2779 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2780 " 3 - select SLI-3");
2781
15672319 2782int lpfc_enable_npiv = 1;
ab56dc2e 2783module_param(lpfc_enable_npiv, int, S_IRUGO);
7ee5d43e
JS
2784MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2785lpfc_param_show(enable_npiv);
4b40c59e 2786lpfc_param_init(enable_npiv, 1, 0, 1);
15672319 2787static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
92d7f7b0 2788
7d791df7
JS
2789LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2790 "FCF Fast failover=1 Priority failover=2");
2791
c14e9957 2792int lpfc_enable_rrq = 2;
ab56dc2e 2793module_param(lpfc_enable_rrq, int, S_IRUGO);
19ca7609
JS
2794MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2795lpfc_param_show(enable_rrq);
e5771b4d
JS
2796/*
2797# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
2798# 0x0 = disabled, XRI/OXID use not tracked.
2799# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
2800# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
2801*/
2802lpfc_param_init(enable_rrq, 2, 0, 2);
19ca7609
JS
2803static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2804
84d1b006
JS
2805/*
2806# lpfc_suppress_link_up: Bring link up at initialization
2807# 0x0 = bring link up (issue MBX_INIT_LINK)
2808# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2809# 0x2 = never bring up link
2810# Default value is 0.
2811*/
e40a02c1
JS
2812LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2813 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2814 "Suppress Link Up at initialization");
2a9bf3d0
JS
2815/*
2816# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2817# 1 - (1024)
2818# 2 - (2048)
2819# 3 - (3072)
2820# 4 - (4096)
2821# 5 - (5120)
2822*/
2823static ssize_t
2824lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2825{
2826 struct Scsi_Host *shost = class_to_shost(dev);
2827 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2828
2829 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2830}
2831
2832static DEVICE_ATTR(iocb_hw, S_IRUGO,
2833 lpfc_iocb_hw_show, NULL);
2834static ssize_t
2835lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2836{
2837 struct Scsi_Host *shost = class_to_shost(dev);
2838 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2839
2840 return snprintf(buf, PAGE_SIZE, "%d\n",
2841 phba->sli.ring[LPFC_ELS_RING].txq_max);
2842}
2843
2844static DEVICE_ATTR(txq_hw, S_IRUGO,
2845 lpfc_txq_hw_show, NULL);
2846static ssize_t
2847lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2848 char *buf)
2849{
2850 struct Scsi_Host *shost = class_to_shost(dev);
2851 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2852
2853 return snprintf(buf, PAGE_SIZE, "%d\n",
2854 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2855}
2856
2857static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2858 lpfc_txcmplq_hw_show, NULL);
2859
2860int lpfc_iocb_cnt = 2;
ab56dc2e 2861module_param(lpfc_iocb_cnt, int, S_IRUGO);
2a9bf3d0
JS
2862MODULE_PARM_DESC(lpfc_iocb_cnt,
2863 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2864lpfc_param_show(iocb_cnt);
2865lpfc_param_init(iocb_cnt, 2, 1, 5);
2866static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2867 lpfc_iocb_cnt_show, NULL);
84d1b006 2868
c01f3208
JS
2869/*
2870# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2871# until the timer expires. Value range is [0,255]. Default value is 30.
2872*/
2873static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2874static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2875module_param(lpfc_nodev_tmo, int, 0);
2876MODULE_PARM_DESC(lpfc_nodev_tmo,
2877 "Seconds driver will hold I/O waiting "
2878 "for a device to come back");
e59058c4
JS
2879
2880/**
3621a710 2881 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
e59058c4
JS
2882 * @dev: class converted to a Scsi_host structure.
2883 * @attr: device attribute, not used.
2884 * @buf: on return contains the dev loss timeout in decimal.
2885 *
2886 * Returns: size of formatted string.
2887 **/
c01f3208 2888static ssize_t
ee959b00
TJ
2889lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2890 char *buf)
c01f3208 2891{
ee959b00 2892 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85 2893 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
e40a02c1 2894
3de2a653 2895 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
c01f3208
JS
2896}
2897
e59058c4 2898/**
3621a710 2899 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
e59058c4
JS
2900 * @vport: lpfc vport structure pointer.
2901 * @val: contains the nodev timeout value.
2902 *
2903 * Description:
2904 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2905 * a kernel error message is printed and zero is returned.
2906 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2907 * Otherwise nodev tmo is set to the default value.
2908 *
2909 * Returns:
2910 * zero if already set or if val is in range
2911 * -EINVAL val out of range
2912 **/
c01f3208 2913static int
3de2a653
JS
2914lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
2915{
2916 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2917 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2918 if (val != LPFC_DEF_DEVLOSS_TMO)
e8b62011 2919 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
d7c255b2 2920 "0407 Ignoring nodev_tmo module "
e8b62011
JS
2921 "parameter because devloss_tmo is "
2922 "set.\n");
c01f3208
JS
2923 return 0;
2924 }
2925
2926 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3de2a653
JS
2927 vport->cfg_nodev_tmo = val;
2928 vport->cfg_devloss_tmo = val;
c01f3208
JS
2929 return 0;
2930 }
e8b62011
JS
2931 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2932 "0400 lpfc_nodev_tmo attribute cannot be set to"
2933 " %d, allowed range is [%d, %d]\n",
2934 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3de2a653 2935 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
c01f3208
JS
2936 return -EINVAL;
2937}
2938
e59058c4 2939/**
3621a710 2940 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
e59058c4
JS
2941 * @vport: lpfc vport structure pointer.
2942 *
2943 * Description:
2944 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2945 **/
7054a606 2946static void
3de2a653 2947lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
7054a606 2948{
858c9f6c 2949 struct Scsi_Host *shost;
7054a606
JS
2950 struct lpfc_nodelist *ndlp;
2951
51ef4c26
JS
2952 shost = lpfc_shost_from_vport(vport);
2953 spin_lock_irq(shost->host_lock);
2954 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
e47c9093 2955 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
51ef4c26
JS
2956 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2957 spin_unlock_irq(shost->host_lock);
7054a606
JS
2958}
2959
e59058c4 2960/**
3621a710 2961 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
e59058c4
JS
2962 * @vport: lpfc vport structure pointer.
2963 * @val: contains the tmo value.
2964 *
2965 * Description:
2966 * If the devloss tmo is already set or the vport dev loss tmo has changed
2967 * then a kernel error message is printed and zero is returned.
2968 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2969 * Otherwise nodev tmo is set to the default value.
2970 *
2971 * Returns:
2972 * zero if already set or if val is in range
2973 * -EINVAL val out of range
2974 **/
c01f3208 2975static int
3de2a653 2976lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
c01f3208 2977{
3de2a653
JS
2978 if (vport->dev_loss_tmo_changed ||
2979 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
e8b62011
JS
2980 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2981 "0401 Ignoring change to nodev_tmo "
2982 "because devloss_tmo is set.\n");
c01f3208
JS
2983 return 0;
2984 }
c01f3208 2985 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3de2a653
JS
2986 vport->cfg_nodev_tmo = val;
2987 vport->cfg_devloss_tmo = val;
0af5d708
MC
2988 /*
2989 * For compat: set the fc_host dev loss so new rports
2990 * will get the value.
2991 */
2992 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3de2a653 2993 lpfc_update_rport_devloss_tmo(vport);
c01f3208
JS
2994 return 0;
2995 }
e8b62011
JS
2996 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2997 "0403 lpfc_nodev_tmo attribute cannot be set to"
2998 "%d, allowed range is [%d, %d]\n",
2999 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
c01f3208
JS
3000 return -EINVAL;
3001}
3002
3de2a653 3003lpfc_vport_param_store(nodev_tmo)
c01f3208 3004
ee959b00
TJ
3005static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3006 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
c01f3208
JS
3007
3008/*
3009# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3010# disappear until the timer expires. Value range is [0,255]. Default
3011# value is 30.
3012*/
ab56dc2e 3013module_param(lpfc_devloss_tmo, int, S_IRUGO);
c01f3208
JS
3014MODULE_PARM_DESC(lpfc_devloss_tmo,
3015 "Seconds driver will hold I/O waiting "
3016 "for a device to come back");
3de2a653
JS
3017lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3018 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3019lpfc_vport_param_show(devloss_tmo)
e59058c4
JS
3020
3021/**
3621a710 3022 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
e59058c4
JS
3023 * @vport: lpfc vport structure pointer.
3024 * @val: contains the tmo value.
3025 *
3026 * Description:
3027 * If val is in a valid range then set the vport nodev tmo,
3028 * devloss tmo, also set the vport dev loss tmo changed flag.
3029 * Else a kernel error message is printed.
3030 *
3031 * Returns:
3032 * zero if val is in range
3033 * -EINVAL val out of range
3034 **/
c01f3208 3035static int
3de2a653 3036lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
c01f3208
JS
3037{
3038 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3de2a653
JS
3039 vport->cfg_nodev_tmo = val;
3040 vport->cfg_devloss_tmo = val;
3041 vport->dev_loss_tmo_changed = 1;
0af5d708 3042 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3de2a653 3043 lpfc_update_rport_devloss_tmo(vport);
c01f3208
JS
3044 return 0;
3045 }
3046
e8b62011
JS
3047 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3048 "0404 lpfc_devloss_tmo attribute cannot be set to"
3049 " %d, allowed range is [%d, %d]\n",
3050 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
c01f3208
JS
3051 return -EINVAL;
3052}
3053
3de2a653 3054lpfc_vport_param_store(devloss_tmo)
ee959b00
TJ
3055static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3056 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
c01f3208 3057
dea3101e 3058/*
3059# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3060# deluged with LOTS of information.
3061# You can set a bit mask to record specific types of verbose messages:
f4b4c68f 3062# See lpfc_logmsh.h for definitions.
dea3101e 3063*/
f4b4c68f 3064LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
e8b62011 3065 "Verbose logging bit-mask");
dea3101e 3066
7ee5d43e
JS
3067/*
3068# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3069# objects that have been registered with the nameserver after login.
3070*/
cf971240 3071LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
7ee5d43e
JS
3072 "Deregister nameserver objects before LOGO");
3073
dea3101e 3074/*
3075# lun_queue_depth: This parameter is used to limit the number of outstanding
572709e2
JS
3076# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3077# If this parameter value is greater than 1/8th the maximum number of exchanges
3078# supported by the HBA port, then the lun queue depth will be reduced to
3079# 1/8th the maximum number of exchanges.
dea3101e 3080*/
572709e2 3081LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
3de2a653 3082 "Max number of FCP commands we can queue to a specific LUN");
dea3101e 3083
7dc517df
JS
3084/*
3085# tgt_queue_depth: This parameter is used to limit the number of outstanding
3086# commands per target port. Value range is [10,65535]. Default value is 65535.
3087*/
3088LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
572709e2 3089 "Max number of FCP commands we can queue to a specific target port");
7dc517df 3090
b28485ac
JW
3091/*
3092# hba_queue_depth: This parameter is used to limit the number of outstanding
3093# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3094# value is greater than the maximum number of exchanges supported by the HBA,
3095# then maximum number of exchanges supported by the HBA is used to determine
3096# the hba_queue_depth.
3097*/
3098LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3099 "Max number of FCP commands we can queue to a lpfc HBA");
3100
92d7f7b0
JS
3101/*
3102# peer_port_login: This parameter allows/prevents logins
3103# between peer ports hosted on the same physical port.
3104# When this parameter is set 0 peer ports of same physical port
3105# are not allowed to login to each other.
3106# When this parameter is set 1 peer ports of same physical port
3107# are allowed to login to each other.
3108# Default value of this parameter is 0.
3109*/
3de2a653
JS
3110LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3111 "Allow peer ports on the same physical port to login to each "
3112 "other.");
92d7f7b0
JS
3113
3114/*
3de2a653 3115# restrict_login: This parameter allows/prevents logins
92d7f7b0
JS
3116# between Virtual Ports and remote initiators.
3117# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3118# other initiators and will attempt to PLOGI all remote ports.
3119# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3120# remote ports and will not attempt to PLOGI to other initiators.
3121# This parameter does not restrict to the physical port.
3122# This parameter does not restrict logins to Fabric resident remote ports.
3123# Default value of this parameter is 1.
3124*/
3de2a653 3125static int lpfc_restrict_login = 1;
ab56dc2e 3126module_param(lpfc_restrict_login, int, S_IRUGO);
3de2a653
JS
3127MODULE_PARM_DESC(lpfc_restrict_login,
3128 "Restrict virtual ports login to remote initiators.");
3129lpfc_vport_param_show(restrict_login);
3130
e59058c4 3131/**
3621a710 3132 * lpfc_restrict_login_init - Set the vport restrict login flag
e59058c4
JS
3133 * @vport: lpfc vport structure pointer.
3134 * @val: contains the restrict login value.
3135 *
3136 * Description:
3137 * If val is not in a valid range then log a kernel error message and set
3138 * the vport restrict login to one.
3139 * If the port type is physical clear the restrict login flag and return.
3140 * Else set the restrict login flag to val.
3141 *
3142 * Returns:
3143 * zero if val is in range
3144 * -EINVAL val out of range
3145 **/
3de2a653
JS
3146static int
3147lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3148{
3149 if (val < 0 || val > 1) {
e8b62011 3150 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
d7c255b2 3151 "0422 lpfc_restrict_login attribute cannot "
e8b62011
JS
3152 "be set to %d, allowed range is [0, 1]\n",
3153 val);
3de2a653
JS
3154 vport->cfg_restrict_login = 1;
3155 return -EINVAL;
3156 }
3157 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3158 vport->cfg_restrict_login = 0;
3159 return 0;
3160 }
3161 vport->cfg_restrict_login = val;
3162 return 0;
3163}
3164
e59058c4 3165/**
3621a710 3166 * lpfc_restrict_login_set - Set the vport restrict login flag
e59058c4
JS
3167 * @vport: lpfc vport structure pointer.
3168 * @val: contains the restrict login value.
3169 *
3170 * Description:
3171 * If val is not in a valid range then log a kernel error message and set
3172 * the vport restrict login to one.
3173 * If the port type is physical and the val is not zero log a kernel
3174 * error message, clear the restrict login flag and return zero.
3175 * Else set the restrict login flag to val.
3176 *
3177 * Returns:
3178 * zero if val is in range
3179 * -EINVAL val out of range
3180 **/
3de2a653
JS
3181static int
3182lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3183{
3184 if (val < 0 || val > 1) {
e8b62011 3185 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
d7c255b2 3186 "0425 lpfc_restrict_login attribute cannot "
e8b62011
JS
3187 "be set to %d, allowed range is [0, 1]\n",
3188 val);
3de2a653
JS
3189 vport->cfg_restrict_login = 1;
3190 return -EINVAL;
3191 }
3192 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
e8b62011
JS
3193 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3194 "0468 lpfc_restrict_login must be 0 for "
3195 "Physical ports.\n");
3de2a653
JS
3196 vport->cfg_restrict_login = 0;
3197 return 0;
3198 }
3199 vport->cfg_restrict_login = val;
3200 return 0;
3201}
3202lpfc_vport_param_store(restrict_login);
ee959b00
TJ
3203static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3204 lpfc_restrict_login_show, lpfc_restrict_login_store);
92d7f7b0 3205
dea3101e 3206/*
3207# Some disk devices have a "select ID" or "select Target" capability.
3208# From a protocol standpoint "select ID" usually means select the
3209# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3210# annex" which contains a table that maps a "select ID" (a number
3211# between 0 and 7F) to an ALPA. By default, for compatibility with
3212# older drivers, the lpfc driver scans this table from low ALPA to high
3213# ALPA.
3214#
3215# Turning on the scan-down variable (on = 1, off = 0) will
3216# cause the lpfc driver to use an inverted table, effectively
3217# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3218#
3219# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3220# and will not work across a fabric. Also this parameter will take
3221# effect only in the case when ALPA map is not available.)
3222*/
3de2a653
JS
3223LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3224 "Start scanning for devices from highest ALPA to lowest");
dea3101e 3225
dea3101e 3226/*
3227# lpfc_topology: link topology for init link
3228# 0x0 = attempt loop mode then point-to-point
367c2713 3229# 0x01 = internal loopback mode
dea3101e 3230# 0x02 = attempt point-to-point mode only
3231# 0x04 = attempt loop mode only
3232# 0x06 = attempt point-to-point mode then loop
3233# Set point-to-point mode if you want to run as an N_Port.
3234# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3235# Default value is 0.
3236*/
e59058c4
JS
3237
3238/**
3621a710 3239 * lpfc_topology_set - Set the adapters topology field
e59058c4
JS
3240 * @phba: lpfc_hba pointer.
3241 * @val: topology value.
3242 *
3243 * Description:
3244 * If val is in a valid range then set the adapter's topology field and
3245 * issue a lip; if the lip fails reset the topology to the old value.
3246 *
3247 * If the value is not in range log a kernel error message and return an error.
3248 *
3249 * Returns:
3250 * zero if val is in range and lip okay
3251 * non-zero return value from lpfc_issue_lip()
3252 * -EINVAL val out of range
3253 **/
a257bf90
JS
3254static ssize_t
3255lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3256 const char *buf, size_t count)
83108bd3 3257{
a257bf90
JS
3258 struct Scsi_Host *shost = class_to_shost(dev);
3259 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3260 struct lpfc_hba *phba = vport->phba;
3261 int val = 0;
3262 int nolip = 0;
3263 const char *val_buf = buf;
83108bd3
JS
3264 int err;
3265 uint32_t prev_val;
a257bf90
JS
3266
3267 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3268 nolip = 1;
3269 val_buf = &buf[strlen("nolip ")];
3270 }
3271
3272 if (!isdigit(val_buf[0]))
3273 return -EINVAL;
3274 if (sscanf(val_buf, "%i", &val) != 1)
3275 return -EINVAL;
3276
83108bd3
JS
3277 if (val >= 0 && val <= 6) {
3278 prev_val = phba->cfg_topology;
ff78d8f9
JS
3279 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3280 val == 4) {
3281 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3282 "3113 Loop mode not supported at speed %d\n",
d38dd52c 3283 val);
ff78d8f9
JS
3284 return -EINVAL;
3285 }
d38dd52c
JS
3286 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3287 val == 4) {
3288 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3289 "3114 Loop mode not supported\n");
3290 return -EINVAL;
3291 }
3292 phba->cfg_topology = val;
a257bf90
JS
3293 if (nolip)
3294 return strlen(buf);
3295
88a2cfbb
JS
3296 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3297 "3054 lpfc_topology changed from %d to %d\n",
3298 prev_val, val);
e74c03c8
JS
3299 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3300 phba->fc_topology_changed = 1;
83108bd3 3301 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
a257bf90 3302 if (err) {
83108bd3 3303 phba->cfg_topology = prev_val;
a257bf90
JS
3304 return -EINVAL;
3305 } else
3306 return strlen(buf);
83108bd3
JS
3307 }
3308 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3309 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3310 "allowed range is [0, 6]\n",
3311 phba->brd_no, val);
3312 return -EINVAL;
3313}
3314static int lpfc_topology = 0;
ab56dc2e 3315module_param(lpfc_topology, int, S_IRUGO);
83108bd3
JS
3316MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
3317lpfc_param_show(topology)
3318lpfc_param_init(topology, 0, 0, 6)
ee959b00 3319static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
83108bd3 3320 lpfc_topology_show, lpfc_topology_store);
dea3101e 3321
21e9a0a5
JS
3322/**
3323 * lpfc_static_vport_show: Read callback function for
3324 * lpfc_static_vport sysfs file.
3325 * @dev: Pointer to class device object.
3326 * @attr: device attribute structure.
3327 * @buf: Data buffer.
3328 *
3329 * This function is the read call back function for
3330 * lpfc_static_vport sysfs file. The lpfc_static_vport
3331 * sysfs file report the mageability of the vport.
3332 **/
3333static ssize_t
3334lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3335 char *buf)
3336{
3337 struct Scsi_Host *shost = class_to_shost(dev);
3338 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3339 if (vport->vport_flag & STATIC_VPORT)
3340 sprintf(buf, "1\n");
3341 else
3342 sprintf(buf, "0\n");
3343
3344 return strlen(buf);
3345}
3346
3347/*
3348 * Sysfs attribute to control the statistical data collection.
3349 */
3350static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3351 lpfc_static_vport_show, NULL);
ea2151b4
JS
3352
3353/**
3621a710 3354 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
ea2151b4
JS
3355 * @dev: Pointer to class device.
3356 * @buf: Data buffer.
3357 * @count: Size of the data buffer.
3358 *
3359 * This function get called when an user write to the lpfc_stat_data_ctrl
3360 * sysfs file. This function parse the command written to the sysfs file
3361 * and take appropriate action. These commands are used for controlling
3362 * driver statistical data collection.
3363 * Following are the command this function handles.
3364 *
3365 * setbucket <bucket_type> <base> <step>
3366 * = Set the latency buckets.
3367 * destroybucket = destroy all the buckets.
3368 * start = start data collection
3369 * stop = stop data collection
3370 * reset = reset the collected data
3371 **/
3372static ssize_t
3373lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3374 const char *buf, size_t count)
3375{
3376 struct Scsi_Host *shost = class_to_shost(dev);
3377 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3378 struct lpfc_hba *phba = vport->phba;
3379#define LPFC_MAX_DATA_CTRL_LEN 1024
3380 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3381 unsigned long i;
3382 char *str_ptr, *token;
3383 struct lpfc_vport **vports;
3384 struct Scsi_Host *v_shost;
3385 char *bucket_type_str, *base_str, *step_str;
3386 unsigned long base, step, bucket_type;
3387
3388 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
a257bf90 3389 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
ea2151b4
JS
3390 return -EINVAL;
3391
eb016566 3392 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
ea2151b4
JS
3393 str_ptr = &bucket_data[0];
3394 /* Ignore this token - this is command token */
3395 token = strsep(&str_ptr, "\t ");
3396 if (!token)
3397 return -EINVAL;
3398
3399 bucket_type_str = strsep(&str_ptr, "\t ");
3400 if (!bucket_type_str)
3401 return -EINVAL;
3402
3403 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3404 bucket_type = LPFC_LINEAR_BUCKET;
3405 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3406 bucket_type = LPFC_POWER2_BUCKET;
3407 else
3408 return -EINVAL;
3409
3410 base_str = strsep(&str_ptr, "\t ");
3411 if (!base_str)
3412 return -EINVAL;
3413 base = simple_strtoul(base_str, NULL, 0);
3414
3415 step_str = strsep(&str_ptr, "\t ");
3416 if (!step_str)
3417 return -EINVAL;
3418 step = simple_strtoul(step_str, NULL, 0);
3419 if (!step)
3420 return -EINVAL;
3421
3422 /* Block the data collection for every vport */
3423 vports = lpfc_create_vport_work_array(phba);
3424 if (vports == NULL)
3425 return -ENOMEM;
3426
f4b4c68f 3427 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
ea2151b4
JS
3428 v_shost = lpfc_shost_from_vport(vports[i]);
3429 spin_lock_irq(v_shost->host_lock);
3430 /* Block and reset data collection */
3431 vports[i]->stat_data_blocked = 1;
3432 if (vports[i]->stat_data_enabled)
3433 lpfc_vport_reset_stat_data(vports[i]);
3434 spin_unlock_irq(v_shost->host_lock);
3435 }
3436
3437 /* Set the bucket attributes */
3438 phba->bucket_type = bucket_type;
3439 phba->bucket_base = base;
3440 phba->bucket_step = step;
3441
f4b4c68f 3442 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
ea2151b4
JS
3443 v_shost = lpfc_shost_from_vport(vports[i]);
3444
3445 /* Unblock data collection */
3446 spin_lock_irq(v_shost->host_lock);
3447 vports[i]->stat_data_blocked = 0;
3448 spin_unlock_irq(v_shost->host_lock);
3449 }
3450 lpfc_destroy_vport_work_array(phba, vports);
3451 return strlen(buf);
3452 }
3453
3454 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3455 vports = lpfc_create_vport_work_array(phba);
3456 if (vports == NULL)
3457 return -ENOMEM;
3458
f4b4c68f 3459 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
ea2151b4
JS
3460 v_shost = lpfc_shost_from_vport(vports[i]);
3461 spin_lock_irq(shost->host_lock);
3462 vports[i]->stat_data_blocked = 1;
3463 lpfc_free_bucket(vport);
3464 vport->stat_data_enabled = 0;
3465 vports[i]->stat_data_blocked = 0;
3466 spin_unlock_irq(shost->host_lock);
3467 }
3468 lpfc_destroy_vport_work_array(phba, vports);
3469 phba->bucket_type = LPFC_NO_BUCKET;
3470 phba->bucket_base = 0;
3471 phba->bucket_step = 0;
3472 return strlen(buf);
3473 }
3474
3475 if (!strncmp(buf, "start", strlen("start"))) {
3476 /* If no buckets configured return error */
3477 if (phba->bucket_type == LPFC_NO_BUCKET)
3478 return -EINVAL;
3479 spin_lock_irq(shost->host_lock);
3480 if (vport->stat_data_enabled) {
3481 spin_unlock_irq(shost->host_lock);
3482 return strlen(buf);
3483 }
3484 lpfc_alloc_bucket(vport);
3485 vport->stat_data_enabled = 1;
3486 spin_unlock_irq(shost->host_lock);
3487 return strlen(buf);
3488 }
3489
3490 if (!strncmp(buf, "stop", strlen("stop"))) {
3491 spin_lock_irq(shost->host_lock);
3492 if (vport->stat_data_enabled == 0) {
3493 spin_unlock_irq(shost->host_lock);
3494 return strlen(buf);
3495 }
3496 lpfc_free_bucket(vport);
3497 vport->stat_data_enabled = 0;
3498 spin_unlock_irq(shost->host_lock);
3499 return strlen(buf);
3500 }
3501
3502 if (!strncmp(buf, "reset", strlen("reset"))) {
3503 if ((phba->bucket_type == LPFC_NO_BUCKET)
3504 || !vport->stat_data_enabled)
3505 return strlen(buf);
3506 spin_lock_irq(shost->host_lock);
3507 vport->stat_data_blocked = 1;
3508 lpfc_vport_reset_stat_data(vport);
3509 vport->stat_data_blocked = 0;
3510 spin_unlock_irq(shost->host_lock);
3511 return strlen(buf);
3512 }
3513 return -EINVAL;
3514}
3515
3516
3517/**
3621a710 3518 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
ea2151b4
JS
3519 * @dev: Pointer to class device object.
3520 * @buf: Data buffer.
3521 *
3522 * This function is the read call back function for
3523 * lpfc_stat_data_ctrl sysfs file. This function report the
3524 * current statistical data collection state.
3525 **/
3526static ssize_t
3527lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3528 char *buf)
3529{
3530 struct Scsi_Host *shost = class_to_shost(dev);
3531 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3532 struct lpfc_hba *phba = vport->phba;
3533 int index = 0;
3534 int i;
3535 char *bucket_type;
3536 unsigned long bucket_value;
3537
3538 switch (phba->bucket_type) {
3539 case LPFC_LINEAR_BUCKET:
3540 bucket_type = "linear";
3541 break;
3542 case LPFC_POWER2_BUCKET:
3543 bucket_type = "power2";
3544 break;
3545 default:
3546 bucket_type = "No Bucket";
3547 break;
3548 }
3549
3550 sprintf(&buf[index], "Statistical Data enabled :%d, "
3551 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3552 " Bucket step :%d\nLatency Ranges :",
3553 vport->stat_data_enabled, vport->stat_data_blocked,
3554 bucket_type, phba->bucket_base, phba->bucket_step);
3555 index = strlen(buf);
3556 if (phba->bucket_type != LPFC_NO_BUCKET) {
3557 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3558 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3559 bucket_value = phba->bucket_base +
3560 phba->bucket_step * i;
3561 else
3562 bucket_value = phba->bucket_base +
3563 (1 << i) * phba->bucket_step;
3564
3565 if (index + 10 > PAGE_SIZE)
3566 break;
3567 sprintf(&buf[index], "%08ld ", bucket_value);
3568 index = strlen(buf);
3569 }
3570 }
3571 sprintf(&buf[index], "\n");
3572 return strlen(buf);
3573}
3574
3575/*
3576 * Sysfs attribute to control the statistical data collection.
3577 */
3578static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3579 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3580
3581/*
3582 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3583 */
3584
3585/*
3586 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3587 * for each target.
3588 */
3589#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3590#define MAX_STAT_DATA_SIZE_PER_TARGET \
3591 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3592
3593
3594/**
3621a710 3595 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2c3c8bea 3596 * @filp: sysfs file
ea2151b4
JS
3597 * @kobj: Pointer to the kernel object
3598 * @bin_attr: Attribute object
3599 * @buff: Buffer pointer
3600 * @off: File offset
3601 * @count: Buffer size
3602 *
3603 * This function is the read call back function for lpfc_drvr_stat_data
3604 * sysfs file. This function export the statistical data to user
3605 * applications.
3606 **/
3607static ssize_t
2c3c8bea
CW
3608sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3609 struct bin_attribute *bin_attr,
ea2151b4
JS
3610 char *buf, loff_t off, size_t count)
3611{
3612 struct device *dev = container_of(kobj, struct device,
3613 kobj);
3614 struct Scsi_Host *shost = class_to_shost(dev);
3615 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3616 struct lpfc_hba *phba = vport->phba;
3617 int i = 0, index = 0;
3618 unsigned long nport_index;
3619 struct lpfc_nodelist *ndlp = NULL;
3620 nport_index = (unsigned long)off /
3621 MAX_STAT_DATA_SIZE_PER_TARGET;
3622
3623 if (!vport->stat_data_enabled || vport->stat_data_blocked
3624 || (phba->bucket_type == LPFC_NO_BUCKET))
3625 return 0;
3626
3627 spin_lock_irq(shost->host_lock);
3628 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3629 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3630 continue;
3631
3632 if (nport_index > 0) {
3633 nport_index--;
3634 continue;
3635 }
3636
3637 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3638 > count)
3639 break;
3640
3641 if (!ndlp->lat_data)
3642 continue;
3643
3644 /* Print the WWN */
3645 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3646 ndlp->nlp_portname.u.wwn[0],
3647 ndlp->nlp_portname.u.wwn[1],
3648 ndlp->nlp_portname.u.wwn[2],
3649 ndlp->nlp_portname.u.wwn[3],
3650 ndlp->nlp_portname.u.wwn[4],
3651 ndlp->nlp_portname.u.wwn[5],
3652 ndlp->nlp_portname.u.wwn[6],
3653 ndlp->nlp_portname.u.wwn[7]);
3654
3655 index = strlen(buf);
3656
3657 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3658 sprintf(&buf[index], "%010u,",
3659 ndlp->lat_data[i].cmd_count);
3660 index = strlen(buf);
3661 }
3662 sprintf(&buf[index], "\n");
3663 index = strlen(buf);
3664 }
3665 spin_unlock_irq(shost->host_lock);
3666 return index;
3667}
3668
3669static struct bin_attribute sysfs_drvr_stat_data_attr = {
3670 .attr = {
3671 .name = "lpfc_drvr_stat_data",
3672 .mode = S_IRUSR,
ea2151b4
JS
3673 },
3674 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3675 .read = sysfs_drvr_stat_data_read,
3676 .write = NULL,
3677};
3678
dea3101e 3679/*
3680# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3681# connection.
76a95d75 3682# Value range is [0,16]. Default value is 0.
dea3101e 3683*/
e59058c4 3684/**
3621a710 3685 * lpfc_link_speed_set - Set the adapters link speed
e59058c4
JS
3686 * @phba: lpfc_hba pointer.
3687 * @val: link speed value.
3688 *
3689 * Description:
3690 * If val is in a valid range then set the adapter's link speed field and
3691 * issue a lip; if the lip fails reset the link speed to the old value.
3692 *
3693 * Notes:
3694 * If the value is not in range log a kernel error message and return an error.
3695 *
3696 * Returns:
3697 * zero if val is in range and lip okay.
3698 * non-zero return value from lpfc_issue_lip()
3699 * -EINVAL val out of range
3700 **/
a257bf90
JS
3701static ssize_t
3702lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3703 const char *buf, size_t count)
83108bd3 3704{
a257bf90
JS
3705 struct Scsi_Host *shost = class_to_shost(dev);
3706 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3707 struct lpfc_hba *phba = vport->phba;
76a95d75 3708 int val = LPFC_USER_LINK_SPEED_AUTO;
a257bf90
JS
3709 int nolip = 0;
3710 const char *val_buf = buf;
83108bd3
JS
3711 int err;
3712 uint32_t prev_val;
3713
a257bf90
JS
3714 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3715 nolip = 1;
3716 val_buf = &buf[strlen("nolip ")];
3717 }
3718
3719 if (!isdigit(val_buf[0]))
3720 return -EINVAL;
3721 if (sscanf(val_buf, "%i", &val) != 1)
3722 return -EINVAL;
3723
88a2cfbb
JS
3724 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3725 "3055 lpfc_link_speed changed from %d to %d %s\n",
3726 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3727
76a95d75
JS
3728 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3729 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3730 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3731 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3732 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
d38dd52c
JS
3733 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
3734 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
76a95d75
JS
3735 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3736 "2879 lpfc_link_speed attribute cannot be set "
3737 "to %d. Speed is not supported by this port.\n",
3738 val);
83108bd3 3739 return -EINVAL;
76a95d75 3740 }
ff78d8f9
JS
3741 if (val == LPFC_USER_LINK_SPEED_16G &&
3742 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3743 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3744 "3112 lpfc_link_speed attribute cannot be set "
3745 "to %d. Speed is not supported in loop mode.\n",
3746 val);
3747 return -EINVAL;
3748 }
76a95d75
JS
3749 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3750 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
83108bd3
JS
3751 prev_val = phba->cfg_link_speed;
3752 phba->cfg_link_speed = val;
a257bf90
JS
3753 if (nolip)
3754 return strlen(buf);
3755
83108bd3 3756 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
a257bf90 3757 if (err) {
83108bd3 3758 phba->cfg_link_speed = prev_val;
a257bf90
JS
3759 return -EINVAL;
3760 } else
3761 return strlen(buf);
83108bd3 3762 }
83108bd3 3763 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
76a95d75
JS
3764 "0469 lpfc_link_speed attribute cannot be set to %d, "
3765 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
83108bd3
JS
3766 return -EINVAL;
3767}
3768
3769static int lpfc_link_speed = 0;
ab56dc2e 3770module_param(lpfc_link_speed, int, S_IRUGO);
83108bd3
JS
3771MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3772lpfc_param_show(link_speed)
e59058c4
JS
3773
3774/**
3621a710 3775 * lpfc_link_speed_init - Set the adapters link speed
e59058c4
JS
3776 * @phba: lpfc_hba pointer.
3777 * @val: link speed value.
3778 *
3779 * Description:
3780 * If val is in a valid range then set the adapter's link speed field.
3781 *
3782 * Notes:
3783 * If the value is not in range log a kernel error message, clear the link
3784 * speed and return an error.
3785 *
3786 * Returns:
3787 * zero if val saved.
3788 * -EINVAL val out of range
3789 **/
83108bd3
JS
3790static int
3791lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3792{
ff78d8f9
JS
3793 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
3794 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3795 "3111 lpfc_link_speed of %d cannot "
3796 "support loop mode, setting topology to default.\n",
3797 val);
3798 phba->cfg_topology = 0;
3799 }
76a95d75
JS
3800 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3801 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
83108bd3
JS
3802 phba->cfg_link_speed = val;
3803 return 0;
3804 }
3805 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
d7c255b2 3806 "0405 lpfc_link_speed attribute cannot "
83108bd3
JS
3807 "be set to %d, allowed values are "
3808 "["LPFC_LINK_SPEED_STRING"]\n", val);
76a95d75 3809 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
83108bd3
JS
3810 return -EINVAL;
3811}
3812
ee959b00 3813static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
76a95d75 3814 lpfc_link_speed_show, lpfc_link_speed_store);
dea3101e 3815
0d878419
JS
3816/*
3817# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3818# 0 = aer disabled or not supported
3819# 1 = aer supported and enabled (default)
3820# Value range is [0,1]. Default value is 1.
3821*/
3822
3823/**
3824 * lpfc_aer_support_store - Set the adapter for aer support
3825 *
3826 * @dev: class device that is converted into a Scsi_host.
3827 * @attr: device attribute, not used.
912e3acd 3828 * @buf: containing enable or disable aer flag.
0d878419
JS
3829 * @count: unused variable.
3830 *
3831 * Description:
3832 * If the val is 1 and currently the device's AER capability was not
3833 * enabled, invoke the kernel's enable AER helper routine, trying to
3834 * enable the device's AER capability. If the helper routine enabling
3835 * AER returns success, update the device's cfg_aer_support flag to
3836 * indicate AER is supported by the device; otherwise, if the device
3837 * AER capability is already enabled to support AER, then do nothing.
3838 *
3839 * If the val is 0 and currently the device's AER support was enabled,
3840 * invoke the kernel's disable AER helper routine. After that, update
3841 * the device's cfg_aer_support flag to indicate AER is not supported
3842 * by the device; otherwise, if the device AER capability is already
3843 * disabled from supporting AER, then do nothing.
3844 *
3845 * Returns:
3846 * length of the buf on success if val is in range the intended mode
3847 * is supported.
3848 * -EINVAL if val out of range or intended mode is not supported.
3849 **/
3850static ssize_t
3851lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3852 const char *buf, size_t count)
3853{
3854 struct Scsi_Host *shost = class_to_shost(dev);
3855 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3856 struct lpfc_hba *phba = vport->phba;
3857 int val = 0, rc = -EINVAL;
3858
3859 if (!isdigit(buf[0]))
3860 return -EINVAL;
3861 if (sscanf(buf, "%i", &val) != 1)
3862 return -EINVAL;
3863
3864 switch (val) {
3865 case 0:
3866 if (phba->hba_flag & HBA_AER_ENABLED) {
3867 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3868 if (!rc) {
3869 spin_lock_irq(&phba->hbalock);
3870 phba->hba_flag &= ~HBA_AER_ENABLED;
3871 spin_unlock_irq(&phba->hbalock);
3872 phba->cfg_aer_support = 0;
3873 rc = strlen(buf);
3874 } else
891478a2
JS
3875 rc = -EPERM;
3876 } else {
0d878419 3877 phba->cfg_aer_support = 0;
891478a2
JS
3878 rc = strlen(buf);
3879 }
0d878419
JS
3880 break;
3881 case 1:
3882 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3883 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3884 if (!rc) {
3885 spin_lock_irq(&phba->hbalock);
3886 phba->hba_flag |= HBA_AER_ENABLED;
3887 spin_unlock_irq(&phba->hbalock);
3888 phba->cfg_aer_support = 1;
3889 rc = strlen(buf);
3890 } else
891478a2
JS
3891 rc = -EPERM;
3892 } else {
0d878419 3893 phba->cfg_aer_support = 1;
891478a2
JS
3894 rc = strlen(buf);
3895 }
0d878419
JS
3896 break;
3897 default:
3898 rc = -EINVAL;
3899 break;
3900 }
3901 return rc;
3902}
3903
3904static int lpfc_aer_support = 1;
ab56dc2e 3905module_param(lpfc_aer_support, int, S_IRUGO);
0d878419
JS
3906MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3907lpfc_param_show(aer_support)
3908
3909/**
3910 * lpfc_aer_support_init - Set the initial adapters aer support flag
3911 * @phba: lpfc_hba pointer.
912e3acd 3912 * @val: enable aer or disable aer flag.
0d878419
JS
3913 *
3914 * Description:
3915 * If val is in a valid range [0,1], then set the adapter's initial
3916 * cfg_aer_support field. It will be up to the driver's probe_one
3917 * routine to determine whether the device's AER support can be set
3918 * or not.
3919 *
3920 * Notes:
3921 * If the value is not in range log a kernel error message, and
3922 * choose the default value of setting AER support and return.
3923 *
3924 * Returns:
3925 * zero if val saved.
3926 * -EINVAL val out of range
3927 **/
3928static int
3929lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3930{
3931 if (val == 0 || val == 1) {
3932 phba->cfg_aer_support = val;
3933 return 0;
3934 }
3935 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3936 "2712 lpfc_aer_support attribute value %d out "
3937 "of range, allowed values are 0|1, setting it "
3938 "to default value of 1\n", val);
891478a2 3939 /* By default, try to enable AER on a device */
0d878419
JS
3940 phba->cfg_aer_support = 1;
3941 return -EINVAL;
3942}
3943
3944static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3945 lpfc_aer_support_show, lpfc_aer_support_store);
3946
3947/**
3948 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3949 * @dev: class device that is converted into a Scsi_host.
3950 * @attr: device attribute, not used.
912e3acd 3951 * @buf: containing flag 1 for aer cleanup state.
0d878419
JS
3952 * @count: unused variable.
3953 *
3954 * Description:
3955 * If the @buf contains 1 and the device currently has the AER support
3956 * enabled, then invokes the kernel AER helper routine
3957 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3958 * error status register.
3959 *
3960 * Notes:
3961 *
3962 * Returns:
3963 * -EINVAL if the buf does not contain the 1 or the device is not currently
3964 * enabled with the AER support.
3965 **/
3966static ssize_t
3967lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3968 const char *buf, size_t count)
3969{
3970 struct Scsi_Host *shost = class_to_shost(dev);
3971 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3972 struct lpfc_hba *phba = vport->phba;
3973 int val, rc = -1;
3974
3975 if (!isdigit(buf[0]))
3976 return -EINVAL;
3977 if (sscanf(buf, "%i", &val) != 1)
3978 return -EINVAL;
891478a2
JS
3979 if (val != 1)
3980 return -EINVAL;
0d878419 3981
891478a2 3982 if (phba->hba_flag & HBA_AER_ENABLED)
0d878419
JS
3983 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3984
3985 if (rc == 0)
3986 return strlen(buf);
3987 else
891478a2 3988 return -EPERM;
0d878419
JS
3989}
3990
3991static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3992 lpfc_aer_cleanup_state);
3993
912e3acd
JS
3994/**
3995 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3996 *
3997 * @dev: class device that is converted into a Scsi_host.
3998 * @attr: device attribute, not used.
3999 * @buf: containing the string the number of vfs to be enabled.
4000 * @count: unused variable.
4001 *
4002 * Description:
4003 * When this api is called either through user sysfs, the driver shall
4004 * try to enable or disable SR-IOV virtual functions according to the
4005 * following:
4006 *
4007 * If zero virtual function has been enabled to the physical function,
4008 * the driver shall invoke the pci enable virtual function api trying
4009 * to enable the virtual functions. If the nr_vfn provided is greater
4010 * than the maximum supported, the maximum virtual function number will
4011 * be used for invoking the api; otherwise, the nr_vfn provided shall
4012 * be used for invoking the api. If the api call returned success, the
4013 * actual number of virtual functions enabled will be set to the driver
4014 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4015 * cfg_sriov_nr_virtfn remains zero.
4016 *
4017 * If none-zero virtual functions have already been enabled to the
4018 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4019 * -EINVAL will be returned and the driver does nothing;
4020 *
4021 * If the nr_vfn provided is zero and none-zero virtual functions have
4022 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4023 * disabling virtual function api shall be invoded to disable all the
4024 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4025 * zero. Otherwise, if zero virtual function has been enabled, do
4026 * nothing.
4027 *
4028 * Returns:
4029 * length of the buf on success if val is in range the intended mode
4030 * is supported.
4031 * -EINVAL if val out of range or intended mode is not supported.
4032 **/
4033static ssize_t
4034lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4035 const char *buf, size_t count)
4036{
4037 struct Scsi_Host *shost = class_to_shost(dev);
4038 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4039 struct lpfc_hba *phba = vport->phba;
4040 struct pci_dev *pdev = phba->pcidev;
4041 int val = 0, rc = -EINVAL;
4042
4043 /* Sanity check on user data */
4044 if (!isdigit(buf[0]))
4045 return -EINVAL;
4046 if (sscanf(buf, "%i", &val) != 1)
4047 return -EINVAL;
4048 if (val < 0)
4049 return -EINVAL;
4050
4051 /* Request disabling virtual functions */
4052 if (val == 0) {
4053 if (phba->cfg_sriov_nr_virtfn > 0) {
4054 pci_disable_sriov(pdev);
4055 phba->cfg_sriov_nr_virtfn = 0;
4056 }
4057 return strlen(buf);
4058 }
4059
4060 /* Request enabling virtual functions */
4061 if (phba->cfg_sriov_nr_virtfn > 0) {
4062 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4063 "3018 There are %d virtual functions "
4064 "enabled on physical function.\n",
4065 phba->cfg_sriov_nr_virtfn);
4066 return -EEXIST;
4067 }
4068
4069 if (val <= LPFC_MAX_VFN_PER_PFN)
4070 phba->cfg_sriov_nr_virtfn = val;
4071 else {
4072 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4073 "3019 Enabling %d virtual functions is not "
4074 "allowed.\n", val);
4075 return -EINVAL;
4076 }
4077
4078 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4079 if (rc) {
4080 phba->cfg_sriov_nr_virtfn = 0;
4081 rc = -EPERM;
4082 } else
4083 rc = strlen(buf);
4084
4085 return rc;
4086}
4087
4088static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
4089module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
4090MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
4091lpfc_param_show(sriov_nr_virtfn)
4092
4093/**
4094 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
4095 * @phba: lpfc_hba pointer.
4096 * @val: link speed value.
4097 *
4098 * Description:
4099 * If val is in a valid range [0,255], then set the adapter's initial
4100 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
4101 * number shall be used instead. It will be up to the driver's probe_one
4102 * routine to determine whether the device's SR-IOV is supported or not.
4103 *
4104 * Returns:
4105 * zero if val saved.
4106 * -EINVAL val out of range
4107 **/
4108static int
4109lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
4110{
4111 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
4112 phba->cfg_sriov_nr_virtfn = val;
4113 return 0;
4114 }
4115
4116 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4117 "3017 Enabling %d virtual functions is not "
4118 "allowed.\n", val);
4119 return -EINVAL;
4120}
4121static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4122 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4123
c71ab861
JS
4124/**
4125 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4126 *
4127 * @dev: class device that is converted into a Scsi_host.
4128 * @attr: device attribute, not used.
4129 * @buf: containing the string the number of vfs to be enabled.
4130 * @count: unused variable.
4131 *
4132 * Description:
4133 *
4134 * Returns:
4135 * length of the buf on success if val is in range the intended mode
4136 * is supported.
4137 * -EINVAL if val out of range or intended mode is not supported.
4138 **/
4139static ssize_t
4140lpfc_request_firmware_upgrade_store(struct device *dev,
4141 struct device_attribute *attr,
4142 const char *buf, size_t count)
4143{
4144 struct Scsi_Host *shost = class_to_shost(dev);
4145 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4146 struct lpfc_hba *phba = vport->phba;
4147 int val = 0, rc = -EINVAL;
4148
4149 /* Sanity check on user data */
4150 if (!isdigit(buf[0]))
4151 return -EINVAL;
4152 if (sscanf(buf, "%i", &val) != 1)
4153 return -EINVAL;
4154 if (val != 1)
4155 return -EINVAL;
4156
4157 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4158 if (rc)
4159 rc = -EPERM;
4160 else
4161 rc = strlen(buf);
4162 return rc;
4163}
4164
4165static int lpfc_req_fw_upgrade;
4166module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4167MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4168lpfc_param_show(request_firmware_upgrade)
4169
4170/**
4171 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4172 * @phba: lpfc_hba pointer.
4173 * @val: 0 or 1.
4174 *
4175 * Description:
4176 * Set the initial Linux generic firmware upgrade enable or disable flag.
4177 *
4178 * Returns:
4179 * zero if val saved.
4180 * -EINVAL val out of range
4181 **/
4182static int
4183lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4184{
4185 if (val >= 0 && val <= 1) {
4186 phba->cfg_request_firmware_upgrade = val;
4187 return 0;
4188 }
4189 return -EINVAL;
4190}
4191static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4192 lpfc_request_firmware_upgrade_show,
4193 lpfc_request_firmware_upgrade_store);
4194
173edbb2
JS
4195/**
4196 * lpfc_fcp_imax_store
4197 *
4198 * @dev: class device that is converted into a Scsi_host.
4199 * @attr: device attribute, not used.
4200 * @buf: string with the number of fast-path FCP interrupts per second.
4201 * @count: unused variable.
4202 *
4203 * Description:
4204 * If val is in a valid range [636,651042], then set the adapter's
4205 * maximum number of fast-path FCP interrupts per second.
4206 *
4207 * Returns:
4208 * length of the buf on success if val is in range the intended mode
4209 * is supported.
4210 * -EINVAL if val out of range or intended mode is not supported.
4211 **/
4212static ssize_t
4213lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4214 const char *buf, size_t count)
4215{
4216 struct Scsi_Host *shost = class_to_shost(dev);
4217 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4218 struct lpfc_hba *phba = vport->phba;
4219 int val = 0, i;
4220
bf8dae83
JS
4221 /* fcp_imax is only valid for SLI4 */
4222 if (phba->sli_rev != LPFC_SLI_REV4)
4223 return -EINVAL;
4224
173edbb2
JS
4225 /* Sanity check on user data */
4226 if (!isdigit(buf[0]))
4227 return -EINVAL;
4228 if (sscanf(buf, "%i", &val) != 1)
4229 return -EINVAL;
4230
bf8dae83
JS
4231 /*
4232 * Value range for the HBA is [5000,5000000]
4233 * The value for each EQ depends on how many EQs are configured.
4234 */
4235 if (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX)
173edbb2
JS
4236 return -EINVAL;
4237
4238 phba->cfg_fcp_imax = (uint32_t)val;
67d12733 4239 for (i = 0; i < phba->cfg_fcp_io_channel; i += LPFC_MAX_EQ_DELAY)
173edbb2
JS
4240 lpfc_modify_fcp_eq_delay(phba, i);
4241
4242 return strlen(buf);
4243}
4244
4245/*
4246# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
bf8dae83 4247# for the HBA.
173edbb2 4248#
bf8dae83 4249# Value range is [5,000 to 5,000,000]. Default value is 50,000.
173edbb2 4250*/
bf8dae83 4251static int lpfc_fcp_imax = LPFC_DEF_IMAX;
173edbb2
JS
4252module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4253MODULE_PARM_DESC(lpfc_fcp_imax,
bf8dae83 4254 "Set the maximum number of FCP interrupts per second per HBA");
173edbb2
JS
4255lpfc_param_show(fcp_imax)
4256
4257/**
4258 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4259 * @phba: lpfc_hba pointer.
4260 * @val: link speed value.
4261 *
4262 * Description:
4263 * If val is in a valid range [636,651042], then initialize the adapter's
4264 * maximum number of fast-path FCP interrupts per second.
4265 *
4266 * Returns:
4267 * zero if val saved.
4268 * -EINVAL val out of range
4269 **/
4270static int
4271lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4272{
bf8dae83
JS
4273 if (phba->sli_rev != LPFC_SLI_REV4) {
4274 phba->cfg_fcp_imax = 0;
4275 return 0;
4276 }
4277
4278 if (val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) {
173edbb2
JS
4279 phba->cfg_fcp_imax = val;
4280 return 0;
4281 }
4282
4283 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4284 "3016 fcp_imax: %d out of range, using default\n", val);
bf8dae83 4285 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
173edbb2
JS
4286
4287 return 0;
4288}
4289
4290static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4291 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4292
7bb03bbf
JS
4293/**
4294 * lpfc_state_show - Display current driver CPU affinity
4295 * @dev: class converted to a Scsi_host structure.
4296 * @attr: device attribute, not used.
4297 * @buf: on return contains text describing the state of the link.
4298 *
4299 * Returns: size of formatted string.
4300 **/
4301static ssize_t
4302lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4303 char *buf)
4304{
4305 struct Scsi_Host *shost = class_to_shost(dev);
4306 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4307 struct lpfc_hba *phba = vport->phba;
4308 struct lpfc_vector_map_info *cpup;
76fd07a6 4309 int len = 0;
7bb03bbf
JS
4310
4311 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4312 (phba->intr_type != MSIX))
4313 return len;
4314
4315 switch (phba->cfg_fcp_cpu_map) {
4316 case 0:
4317 len += snprintf(buf + len, PAGE_SIZE-len,
4318 "fcp_cpu_map: No mapping (%d)\n",
4319 phba->cfg_fcp_cpu_map);
4320 return len;
4321 case 1:
4322 len += snprintf(buf + len, PAGE_SIZE-len,
4323 "fcp_cpu_map: HBA centric mapping (%d): "
4324 "%d online CPUs\n",
4325 phba->cfg_fcp_cpu_map,
4326 phba->sli4_hba.num_online_cpu);
4327 break;
4328 case 2:
4329 len += snprintf(buf + len, PAGE_SIZE-len,
4330 "fcp_cpu_map: Driver centric mapping (%d): "
4331 "%d online CPUs\n",
4332 phba->cfg_fcp_cpu_map,
4333 phba->sli4_hba.num_online_cpu);
4334 break;
4335 }
4336
76fd07a6
JS
4337 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4338 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4339
4340 /* margin should fit in this and the truncated message */
7bb03bbf
JS
4341 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4342 len += snprintf(buf + len, PAGE_SIZE-len,
4343 "CPU %02d io_chan %02d "
4344 "physid %d coreid %d\n",
76fd07a6
JS
4345 phba->sli4_hba.curr_disp_cpu,
4346 cpup->channel_id, cpup->phys_id,
7bb03bbf
JS
4347 cpup->core_id);
4348 else
4349 len += snprintf(buf + len, PAGE_SIZE-len,
4350 "CPU %02d io_chan %02d "
4351 "physid %d coreid %d IRQ %d\n",
76fd07a6
JS
4352 phba->sli4_hba.curr_disp_cpu,
4353 cpup->channel_id, cpup->phys_id,
7bb03bbf
JS
4354 cpup->core_id, cpup->irq);
4355
76fd07a6
JS
4356 phba->sli4_hba.curr_disp_cpu++;
4357
4358 /* display max number of CPUs keeping some margin */
4359 if (phba->sli4_hba.curr_disp_cpu <
4360 phba->sli4_hba.num_present_cpu &&
4361 (len >= (PAGE_SIZE - 64))) {
4362 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4363 break;
4364 }
7bb03bbf 4365 }
76fd07a6
JS
4366
4367 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4368 phba->sli4_hba.curr_disp_cpu = 0;
4369
7bb03bbf
JS
4370 return len;
4371}
4372
4373/**
4374 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4375 * @dev: class device that is converted into a Scsi_host.
4376 * @attr: device attribute, not used.
4377 * @buf: one or more lpfc_polling_flags values.
4378 * @count: not used.
4379 *
4380 * Returns:
4381 * -EINVAL - Not implemented yet.
4382 **/
4383static ssize_t
4384lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4385 const char *buf, size_t count)
4386{
4387 int status = -EINVAL;
4388 return status;
4389}
4390
4391/*
4392# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4393# for the HBA.
4394#
4395# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4396# 0 - Do not affinitze IRQ vectors
4397# 1 - Affintize HBA vectors with respect to each HBA
4398# (start with CPU0 for each HBA)
4399# 2 - Affintize HBA vectors with respect to the entire driver
4400# (round robin thru all CPUs across all HBAs)
4401*/
4402static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4403module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4404MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4405 "Defines how to map CPUs to IRQ vectors per HBA");
4406
4407/**
4408 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4409 * @phba: lpfc_hba pointer.
4410 * @val: link speed value.
4411 *
4412 * Description:
4413 * If val is in a valid range [0-2], then affinitze the adapter's
4414 * MSIX vectors.
4415 *
4416 * Returns:
4417 * zero if val saved.
4418 * -EINVAL val out of range
4419 **/
4420static int
4421lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4422{
4423 if (phba->sli_rev != LPFC_SLI_REV4) {
4424 phba->cfg_fcp_cpu_map = 0;
4425 return 0;
4426 }
4427
4428 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4429 phba->cfg_fcp_cpu_map = val;
4430 return 0;
4431 }
4432
4433 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4434 "3326 fcp_cpu_map: %d out of range, using default\n",
4435 val);
4436 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4437
4438 return 0;
4439}
4440
4441static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4442 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4443
dea3101e 4444/*
4445# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4446# Value range is [2,3]. Default value is 3.
4447*/
3de2a653
JS
4448LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4449 "Select Fibre Channel class of service for FCP sequences");
dea3101e 4450
4451/*
4452# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4453# is [0,1]. Default value is 0.
4454*/
3de2a653
JS
4455LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4456 "Use ADISC on rediscovery to authenticate FCP devices");
dea3101e 4457
3cb01c57
JS
4458/*
4459# lpfc_first_burst_size: First burst size to use on the NPorts
4460# that support first burst.
4461# Value range is [0,65536]. Default value is 0.
4462*/
4463LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4464 "First burst size for Targets that support first burst");
4465
977b5a0a
JS
4466/*
4467# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4468# depth. Default value is 0. When the value of this parameter is zero the
4469# SCSI command completion time is not used for controlling I/O queue depth. When
4470# the parameter is set to a non-zero value, the I/O queue depth is controlled
4471# to limit the I/O completion time to the parameter value.
4472# The value is set in milliseconds.
4473*/
4474static int lpfc_max_scsicmpl_time;
ab56dc2e 4475module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
977b5a0a
JS
4476MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
4477 "Use command completion time to control queue depth");
4478lpfc_vport_param_show(max_scsicmpl_time);
4479lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
4480static int
4481lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4482{
4483 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4484 struct lpfc_nodelist *ndlp, *next_ndlp;
4485
4486 if (val == vport->cfg_max_scsicmpl_time)
4487 return 0;
4488 if ((val < 0) || (val > 60000))
4489 return -EINVAL;
4490 vport->cfg_max_scsicmpl_time = val;
4491
4492 spin_lock_irq(shost->host_lock);
4493 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4494 if (!NLP_CHK_NODE_ACT(ndlp))
4495 continue;
4496 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4497 continue;
7dc517df 4498 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
977b5a0a
JS
4499 }
4500 spin_unlock_irq(shost->host_lock);
4501 return 0;
4502}
4503lpfc_vport_param_store(max_scsicmpl_time);
4504static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4505 lpfc_max_scsicmpl_time_show,
4506 lpfc_max_scsicmpl_time_store);
4507
dea3101e 4508/*
4509# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4510# range is [0,1]. Default value is 0.
4511*/
4512LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4513
49aa143d
JS
4514/*
4515# lpfc_fcp_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4516# range is [0,1]. Default value is 0.
4517# For [0], FCP commands are issued to Work Queues ina round robin fashion.
4518# For [1], FCP commands are issued to a Work Queue associated with the
4519# current CPU.
ec2087a7
JS
4520# It would be set to 1 by the driver if it's able to set up cpu affinity
4521# for FCP I/Os through Work Queue associated with the current CPU. Otherwise,
4522# roundrobin scheduling of FCP I/Os through WQs will be used.
49aa143d 4523*/
ec2087a7 4524LPFC_ATTR_RW(fcp_io_sched, 0, 0, 1, "Determine scheduling algorithm for "
49aa143d
JS
4525 "issuing commands [0] - Round Robin, [1] - Current CPU");
4526
a6571c6e
JS
4527/*
4528# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4529# range is [0,1]. Default value is 0.
4530# For [0], bus reset issues target reset to ALL devices
4531# For [1], bus reset issues target reset to non-FCP2 devices
4532*/
4533LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4534 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4535
4536
dea3101e 4537/*
4538# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4539# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
7054a606 4540# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea3101e 4541# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4542# cr_delay is set to 0.
4543*/
8189fd19 4544LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea3101e 4545 "interrupt response is generated");
4546
8189fd19 4547LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea3101e 4548 "interrupt response is generated");
4549
cf5bf97e
JW
4550/*
4551# lpfc_multi_ring_support: Determines how many rings to spread available
4552# cmd/rsp IOCB entries across.
4553# Value range is [1,2]. Default value is 1.
4554*/
4555LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4556 "SLI rings to spread IOCB entries across");
4557
a4bc3379
JS
4558/*
4559# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4560# identifies what rctl value to configure the additional ring for.
4561# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4562*/
6a9c52cf 4563LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
a4bc3379
JS
4564 255, "Identifies RCTL for additional ring configuration");
4565
4566/*
4567# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4568# identifies what type value to configure the additional ring for.
4569# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4570*/
6a9c52cf 4571LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
a4bc3379
JS
4572 255, "Identifies TYPE for additional ring configuration");
4573
dea3101e 4574/*
4258e98e
JS
4575# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4576# 0 = SmartSAN functionality disabled (default)
4577# 1 = SmartSAN functionality enabled
4578# This parameter will override the value of lpfc_fdmi_on module parameter.
4579# Value range is [0,1]. Default value is 0.
dea3101e 4580*/
4258e98e
JS
4581LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4582
4583/*
4584# lpfc_fdmi_on: Controls FDMI support.
4585# 0 No FDMI support (default)
4586# 1 Traditional FDMI support
8663cbbe
JS
4587# Traditional FDMI support means the driver will assume FDMI-2 support;
4588# however, if that fails, it will fallback to FDMI-1.
4589# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4590# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4591# lpfc_fdmi_on.
4592# Value range [0,1]. Default value is 0.
4258e98e 4593*/
8663cbbe 4594LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
dea3101e 4595
4596/*
4597# Specifies the maximum number of ELS cmds we can have outstanding (for
4598# discovery). Value range is [1,64]. Default value = 32.
4599*/
3de2a653 4600LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea3101e 4601 "during discovery");
4602
4603/*
c4a7c922
JS
4604# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4605# will be scanned by the SCSI midlayer when sequential scanning is
4606# used; and is also the highest LUN ID allowed when the SCSI midlayer
4607# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4608# LUN ID limit, but the SCSI midlayer requires this field for the uses
4609# above. The lpfc driver limits the default value to 255 for two reasons.
4610# As it bounds the sequential scan loop, scanning for thousands of luns
4611# on a target can take minutes of wall clock time. Additionally,
4612# there are FC targets, such as JBODs, that only recognize 8-bits of
4613# LUN ID. When they receive a value greater than 8 bits, they chop off
4614# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4615# and so on all as LUN ID 0. This causes the linux kernel, which sees
4616# valid responses at each of the LUN IDs, to believe there are multiple
4617# devices present, when in fact, there is only 1.
4618# A customer that is aware of their target behaviors, and the results as
4619# indicated above, is welcome to increase the lpfc_max_luns value.
4620# As mentioned, this value is not used by the lpfc driver, only the
4621# SCSI midlayer.
65a29c16
JS
4622# Value range is [0,65535]. Default value is 255.
4623# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea3101e 4624*/
1abf635d 4625LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea3101e 4626
875fbdfe
JSEC
4627/*
4628# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4629# Value range is [1,255], default value is 10.
4630*/
4631LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4632 "Milliseconds driver will wait between polling FCP ring");
4633
4ff43246 4634/*
0c411222
JS
4635# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4636# to complete in seconds. Value range is [5,180], default value is 60.
4637*/
4638LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4639 "Maximum time to wait for task management commands to complete");
4640/*
4ff43246
JS
4641# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4642# support this feature
8605c46c 4643# 0 = MSI disabled
4ff43246 4644# 1 = MSI enabled
8605c46c
GK
4645# 2 = MSI-X enabled (default)
4646# Value range is [0,2]. Default value is 2.
4ff43246 4647*/
8605c46c 4648LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
db2378e0 4649 "MSI-X (2), if possible");
4ff43246 4650
67d12733
JS
4651/*
4652# lpfc_fcp_io_channel: Set the number of FCP EQ/CQ/WQ IO channels
4653#
4654# Value range is [1,7]. Default value is 4.
4655*/
4656LPFC_ATTR_R(fcp_io_channel, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
4657 LPFC_FCP_IO_CHAN_MAX,
4658 "Set the number of FCP I/O channels");
4659
13815c83
JS
4660/*
4661# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4662# 0 = HBA resets disabled
4663# 1 = HBA resets enabled (default)
4664# Value range is [0,1]. Default value is 1.
4665*/
4666LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
c3f28afa 4667
13815c83 4668/*
eb7a339e 4669# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
13815c83
JS
4670# 0 = HBA Heartbeat disabled
4671# 1 = HBA Heartbeat enabled (default)
4672# Value range is [0,1]. Default value is 1.
4673*/
eb7a339e 4674LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
92d7f7b0 4675
1ba981fd
JS
4676/*
4677# lpfc_EnableXLane: Enable Express Lane Feature
4678# 0x0 Express Lane Feature disabled
4679# 0x1 Express Lane Feature enabled
4680# Value range is [0,1]. Default value is 0.
4681*/
4682LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
4683
4684/*
4685# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
4686# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
4687# Value range is [0x0,0x7f]. Default value is 0
4688*/
28d7f3df 4689LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
1ba981fd 4690
81301a9b
JS
4691/*
4692# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4693# 0 = BlockGuard disabled (default)
4694# 1 = BlockGuard enabled
4695# Value range is [0,1]. Default value is 0.
4696*/
4697LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
4698
ba20c853
JS
4699/*
4700# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
4701# 0 = disabled (default)
4702# 1 = enabled
4703# Value range is [0,1]. Default value is 0.
5688d670
JS
4704#
4705# This feature in under investigation and may be supported in the future.
ba20c853
JS
4706*/
4707unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
4708
81301a9b
JS
4709/*
4710# lpfc_prot_mask: i
4711# - Bit mask of host protection capabilities used to register with the
4712# SCSI mid-layer
4713# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
4714# - Allows you to ultimately specify which profiles to use
4715# - Default will result in registering capabilities for all profiles.
005ffa70
JS
4716# - SHOST_DIF_TYPE1_PROTECTION 1
4717# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
4718# - SHOST_DIX_TYPE0_PROTECTION 8
4719# HBA supports DIX Type 0: Host to HBA protection only
4720# - SHOST_DIX_TYPE1_PROTECTION 16
4721# HBA supports DIX Type 1: Host to HBA Type 1 protection
81301a9b
JS
4722#
4723*/
7c56b9fd
JS
4724unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
4725 SHOST_DIX_TYPE0_PROTECTION |
4726 SHOST_DIX_TYPE1_PROTECTION;
81301a9b 4727
ab56dc2e 4728module_param(lpfc_prot_mask, uint, S_IRUGO);
81301a9b
JS
4729MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
4730
4731/*
4732# lpfc_prot_guard: i
4733# - Bit mask of protection guard types to register with the SCSI mid-layer
005ffa70 4734# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
81301a9b
JS
4735# - Allows you to ultimately specify which profiles to use
4736# - Default will result in registering capabilities for all guard types
4737#
4738*/
4739unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
ab56dc2e 4740module_param(lpfc_prot_guard, byte, S_IRUGO);
81301a9b
JS
4741MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
4742
92494144
JS
4743/*
4744 * Delay initial NPort discovery when Clean Address bit is cleared in
4745 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
4746 * This parameter can have value 0 or 1.
4747 * When this parameter is set to 0, no delay is added to the initial
4748 * discovery.
4749 * When this parameter is set to non-zero value, initial Nport discovery is
4750 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
4751 * accept and FCID/Fabric name/Fabric portname is changed.
4752 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
4753 * when Clean Address bit is cleared in FLOGI/FDISC
4754 * accept and FCID/Fabric name/Fabric portname is changed.
4755 * Default value is 0.
4756 */
4757int lpfc_delay_discovery;
ab56dc2e 4758module_param(lpfc_delay_discovery, int, S_IRUGO);
92494144
JS
4759MODULE_PARM_DESC(lpfc_delay_discovery,
4760 "Delay NPort discovery when Clean Address bit is cleared. "
4761 "Allowed values: 0,1.");
81301a9b 4762
83108bd3 4763/*
3621a710 4764 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
96f7077f 4765 * This value can be set to values between 64 and 4096. The default value is
83108bd3
JS
4766 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
4767 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
96f7077f
JS
4768 * Because of the additional overhead involved in setting up T10-DIF,
4769 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
4770 * and will be limited to 512 if BlockGuard is enabled under SLI3.
83108bd3
JS
4771 */
4772LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
4773 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
4774
96f7077f
JS
4775/*
4776 * This parameter will be depricated, the driver cannot limit the
4777 * protection data s/g list.
4778 */
4779LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT,
4780 LPFC_DEFAULT_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT,
4781 "Max Protection Scatter Gather Segment Count");
81301a9b 4782
ee959b00 4783struct device_attribute *lpfc_hba_attrs[] = {
81301a9b
JS
4784 &dev_attr_bg_info,
4785 &dev_attr_bg_guard_err,
4786 &dev_attr_bg_apptag_err,
4787 &dev_attr_bg_reftag_err,
ee959b00
TJ
4788 &dev_attr_info,
4789 &dev_attr_serialnum,
4790 &dev_attr_modeldesc,
4791 &dev_attr_modelname,
4792 &dev_attr_programtype,
4793 &dev_attr_portnum,
4794 &dev_attr_fwrev,
4795 &dev_attr_hdw,
4796 &dev_attr_option_rom_version,
bbd1ae41 4797 &dev_attr_link_state,
ee959b00 4798 &dev_attr_num_discovered_ports,
84774a4d 4799 &dev_attr_menlo_mgmt_mode,
ee959b00 4800 &dev_attr_lpfc_drvr_version,
45ed1190 4801 &dev_attr_lpfc_enable_fip,
ee959b00
TJ
4802 &dev_attr_lpfc_temp_sensor,
4803 &dev_attr_lpfc_log_verbose,
4804 &dev_attr_lpfc_lun_queue_depth,
7dc517df 4805 &dev_attr_lpfc_tgt_queue_depth,
ee959b00
TJ
4806 &dev_attr_lpfc_hba_queue_depth,
4807 &dev_attr_lpfc_peer_port_login,
4808 &dev_attr_lpfc_nodev_tmo,
4809 &dev_attr_lpfc_devloss_tmo,
4810 &dev_attr_lpfc_fcp_class,
4811 &dev_attr_lpfc_use_adisc,
3cb01c57 4812 &dev_attr_lpfc_first_burst_size,
ee959b00
TJ
4813 &dev_attr_lpfc_ack0,
4814 &dev_attr_lpfc_topology,
4815 &dev_attr_lpfc_scan_down,
4816 &dev_attr_lpfc_link_speed,
49aa143d 4817 &dev_attr_lpfc_fcp_io_sched,
a6571c6e 4818 &dev_attr_lpfc_fcp2_no_tgt_reset,
ee959b00
TJ
4819 &dev_attr_lpfc_cr_delay,
4820 &dev_attr_lpfc_cr_count,
4821 &dev_attr_lpfc_multi_ring_support,
4822 &dev_attr_lpfc_multi_ring_rctl,
4823 &dev_attr_lpfc_multi_ring_type,
4824 &dev_attr_lpfc_fdmi_on,
4258e98e 4825 &dev_attr_lpfc_enable_SmartSAN,
ee959b00
TJ
4826 &dev_attr_lpfc_max_luns,
4827 &dev_attr_lpfc_enable_npiv,
7d791df7 4828 &dev_attr_lpfc_fcf_failover_policy,
19ca7609 4829 &dev_attr_lpfc_enable_rrq,
ee959b00
TJ
4830 &dev_attr_nport_evt_cnt,
4831 &dev_attr_board_mode,
4832 &dev_attr_max_vpi,
4833 &dev_attr_used_vpi,
4834 &dev_attr_max_rpi,
4835 &dev_attr_used_rpi,
4836 &dev_attr_max_xri,
4837 &dev_attr_used_xri,
4838 &dev_attr_npiv_info,
4839 &dev_attr_issue_reset,
4840 &dev_attr_lpfc_poll,
4841 &dev_attr_lpfc_poll_tmo,
0c411222 4842 &dev_attr_lpfc_task_mgmt_tmo,
ee959b00 4843 &dev_attr_lpfc_use_msi,
da0436e9 4844 &dev_attr_lpfc_fcp_imax,
7bb03bbf 4845 &dev_attr_lpfc_fcp_cpu_map,
67d12733 4846 &dev_attr_lpfc_fcp_io_channel,
81301a9b 4847 &dev_attr_lpfc_enable_bg,
ee959b00
TJ
4848 &dev_attr_lpfc_soft_wwnn,
4849 &dev_attr_lpfc_soft_wwpn,
4850 &dev_attr_lpfc_soft_wwn_enable,
4851 &dev_attr_lpfc_enable_hba_reset,
4852 &dev_attr_lpfc_enable_hba_heartbeat,
1ba981fd
JS
4853 &dev_attr_lpfc_EnableXLane,
4854 &dev_attr_lpfc_XLanePriority,
4855 &dev_attr_lpfc_xlane_lun,
4856 &dev_attr_lpfc_xlane_tgt,
4857 &dev_attr_lpfc_xlane_vpt,
4858 &dev_attr_lpfc_xlane_lun_state,
4859 &dev_attr_lpfc_xlane_lun_status,
ee959b00 4860 &dev_attr_lpfc_sg_seg_cnt,
977b5a0a 4861 &dev_attr_lpfc_max_scsicmpl_time,
ea2151b4 4862 &dev_attr_lpfc_stat_data_ctrl,
81301a9b 4863 &dev_attr_lpfc_prot_sg_seg_cnt,
0d878419
JS
4864 &dev_attr_lpfc_aer_support,
4865 &dev_attr_lpfc_aer_state_cleanup,
912e3acd 4866 &dev_attr_lpfc_sriov_nr_virtfn,
c71ab861 4867 &dev_attr_lpfc_req_fw_upgrade,
84d1b006 4868 &dev_attr_lpfc_suppress_link_up,
2a9bf3d0
JS
4869 &dev_attr_lpfc_iocb_cnt,
4870 &dev_attr_iocb_hw,
4871 &dev_attr_txq_hw,
4872 &dev_attr_txcmplq_hw,
bc73905a
JS
4873 &dev_attr_lpfc_fips_level,
4874 &dev_attr_lpfc_fips_rev,
ab56dc2e 4875 &dev_attr_lpfc_dss,
912e3acd 4876 &dev_attr_lpfc_sriov_hw_max_virtfn,
026abb87 4877 &dev_attr_protocol,
1ba981fd 4878 &dev_attr_lpfc_xlane_supported,
dea3101e 4879 NULL,
4880};
4881
ee959b00
TJ
4882struct device_attribute *lpfc_vport_attrs[] = {
4883 &dev_attr_info,
bbd1ae41 4884 &dev_attr_link_state,
ee959b00
TJ
4885 &dev_attr_num_discovered_ports,
4886 &dev_attr_lpfc_drvr_version,
4887 &dev_attr_lpfc_log_verbose,
4888 &dev_attr_lpfc_lun_queue_depth,
7dc517df 4889 &dev_attr_lpfc_tgt_queue_depth,
ee959b00
TJ
4890 &dev_attr_lpfc_nodev_tmo,
4891 &dev_attr_lpfc_devloss_tmo,
4892 &dev_attr_lpfc_hba_queue_depth,
4893 &dev_attr_lpfc_peer_port_login,
4894 &dev_attr_lpfc_restrict_login,
4895 &dev_attr_lpfc_fcp_class,
4896 &dev_attr_lpfc_use_adisc,
3cb01c57 4897 &dev_attr_lpfc_first_burst_size,
ee959b00
TJ
4898 &dev_attr_lpfc_max_luns,
4899 &dev_attr_nport_evt_cnt,
4900 &dev_attr_npiv_info,
4901 &dev_attr_lpfc_enable_da_id,
ea2151b4
JS
4902 &dev_attr_lpfc_max_scsicmpl_time,
4903 &dev_attr_lpfc_stat_data_ctrl,
21e9a0a5 4904 &dev_attr_lpfc_static_vport,
bc73905a
JS
4905 &dev_attr_lpfc_fips_level,
4906 &dev_attr_lpfc_fips_rev,
3de2a653
JS
4907 NULL,
4908};
4909
e59058c4 4910/**
3621a710 4911 * sysfs_ctlreg_write - Write method for writing to ctlreg
2c3c8bea 4912 * @filp: open sysfs file
e59058c4
JS
4913 * @kobj: kernel kobject that contains the kernel class device.
4914 * @bin_attr: kernel attributes passed to us.
4915 * @buf: contains the data to be written to the adapter IOREG space.
4916 * @off: offset into buffer to beginning of data.
4917 * @count: bytes to transfer.
4918 *
4919 * Description:
4920 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4921 * Uses the adapter io control registers to send buf contents to the adapter.
4922 *
4923 * Returns:
4924 * -ERANGE off and count combo out of range
4925 * -EINVAL off, count or buff address invalid
4926 * -EPERM adapter is offline
4927 * value of count, buf contents written
4928 **/
dea3101e 4929static ssize_t
2c3c8bea
CW
4930sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
4931 struct bin_attribute *bin_attr,
91a69029 4932 char *buf, loff_t off, size_t count)
dea3101e 4933{
4934 size_t buf_off;
ee959b00
TJ
4935 struct device *dev = container_of(kobj, struct device, kobj);
4936 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
4937 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4938 struct lpfc_hba *phba = vport->phba;
dea3101e 4939
f1126688
JS
4940 if (phba->sli_rev >= LPFC_SLI_REV4)
4941 return -EPERM;
4942
dea3101e 4943 if ((off + count) > FF_REG_AREA_SIZE)
4944 return -ERANGE;
4945
f7a919b4
JS
4946 if (count <= LPFC_REG_WRITE_KEY_SIZE)
4947 return 0;
dea3101e 4948
4949 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4950 return -EINVAL;
4951
f7a919b4
JS
4952 /* This is to protect HBA registers from accidental writes. */
4953 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
4954 return -EINVAL;
4955
4956 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea3101e 4957 return -EPERM;
dea3101e 4958
2e0fef85 4959 spin_lock_irq(&phba->hbalock);
f7a919b4
JS
4960 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
4961 buf_off += sizeof(uint32_t))
4962 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea3101e 4963 phba->ctrl_regs_memmap_p + off + buf_off);
4964
2e0fef85 4965 spin_unlock_irq(&phba->hbalock);
dea3101e 4966
4967 return count;
4968}
4969
e59058c4 4970/**
3621a710 4971 * sysfs_ctlreg_read - Read method for reading from ctlreg
2c3c8bea 4972 * @filp: open sysfs file
e59058c4
JS
4973 * @kobj: kernel kobject that contains the kernel class device.
4974 * @bin_attr: kernel attributes passed to us.
af901ca1 4975 * @buf: if successful contains the data from the adapter IOREG space.
e59058c4
JS
4976 * @off: offset into buffer to beginning of data.
4977 * @count: bytes to transfer.
4978 *
4979 * Description:
4980 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4981 * Uses the adapter io control registers to read data into buf.
4982 *
4983 * Returns:
4984 * -ERANGE off and count combo out of range
4985 * -EINVAL off, count or buff address invalid
4986 * value of count, buf contents read
4987 **/
dea3101e 4988static ssize_t
2c3c8bea
CW
4989sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
4990 struct bin_attribute *bin_attr,
91a69029 4991 char *buf, loff_t off, size_t count)
dea3101e 4992{
4993 size_t buf_off;
4994 uint32_t * tmp_ptr;
ee959b00
TJ
4995 struct device *dev = container_of(kobj, struct device, kobj);
4996 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
4997 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4998 struct lpfc_hba *phba = vport->phba;
dea3101e 4999
f1126688
JS
5000 if (phba->sli_rev >= LPFC_SLI_REV4)
5001 return -EPERM;
5002
dea3101e 5003 if (off > FF_REG_AREA_SIZE)
5004 return -ERANGE;
5005
5006 if ((off + count) > FF_REG_AREA_SIZE)
5007 count = FF_REG_AREA_SIZE - off;
5008
5009 if (count == 0) return 0;
5010
5011 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5012 return -EINVAL;
5013
2e0fef85 5014 spin_lock_irq(&phba->hbalock);
dea3101e 5015
5016 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5017 tmp_ptr = (uint32_t *)(buf + buf_off);
5018 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5019 }
5020
2e0fef85 5021 spin_unlock_irq(&phba->hbalock);
dea3101e 5022
5023 return count;
5024}
5025
5026static struct bin_attribute sysfs_ctlreg_attr = {
5027 .attr = {
5028 .name = "ctlreg",
5029 .mode = S_IRUSR | S_IWUSR,
dea3101e 5030 },
5031 .size = 256,
5032 .read = sysfs_ctlreg_read,
5033 .write = sysfs_ctlreg_write,
5034};
5035
e59058c4 5036/**
3621a710 5037 * sysfs_mbox_write - Write method for writing information via mbox
2c3c8bea 5038 * @filp: open sysfs file
e59058c4
JS
5039 * @kobj: kernel kobject that contains the kernel class device.
5040 * @bin_attr: kernel attributes passed to us.
5041 * @buf: contains the data to be written to sysfs mbox.
5042 * @off: offset into buffer to beginning of data.
5043 * @count: bytes to transfer.
5044 *
5045 * Description:
026abb87
JS
5046 * Deprecated function. All mailbox access from user space is performed via the
5047 * bsg interface.
e59058c4
JS
5048 *
5049 * Returns:
026abb87 5050 * -EPERM operation not permitted
e59058c4 5051 **/
dea3101e 5052static ssize_t
2c3c8bea
CW
5053sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5054 struct bin_attribute *bin_attr,
91a69029 5055 char *buf, loff_t off, size_t count)
dea3101e 5056{
026abb87 5057 return -EPERM;
dea3101e 5058}
5059
e59058c4 5060/**
3621a710 5061 * sysfs_mbox_read - Read method for reading information via mbox
2c3c8bea 5062 * @filp: open sysfs file
e59058c4
JS
5063 * @kobj: kernel kobject that contains the kernel class device.
5064 * @bin_attr: kernel attributes passed to us.
5065 * @buf: contains the data to be read from sysfs mbox.
5066 * @off: offset into buffer to beginning of data.
5067 * @count: bytes to transfer.
5068 *
5069 * Description:
026abb87
JS
5070 * Deprecated function. All mailbox access from user space is performed via the
5071 * bsg interface.
e59058c4
JS
5072 *
5073 * Returns:
026abb87 5074 * -EPERM operation not permitted
e59058c4 5075 **/
dea3101e 5076static ssize_t
2c3c8bea
CW
5077sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5078 struct bin_attribute *bin_attr,
91a69029 5079 char *buf, loff_t off, size_t count)
dea3101e 5080{
026abb87 5081 return -EPERM;
dea3101e 5082}
5083
5084static struct bin_attribute sysfs_mbox_attr = {
5085 .attr = {
5086 .name = "mbox",
5087 .mode = S_IRUSR | S_IWUSR,
dea3101e 5088 },
c0c11512 5089 .size = MAILBOX_SYSFS_MAX,
dea3101e 5090 .read = sysfs_mbox_read,
5091 .write = sysfs_mbox_write,
5092};
5093
e59058c4 5094/**
3621a710 5095 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
e59058c4
JS
5096 * @vport: address of lpfc vport structure.
5097 *
5098 * Return codes:
5099 * zero on success
5100 * error return code from sysfs_create_bin_file()
5101 **/
dea3101e 5102int
2e0fef85 5103lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea3101e 5104{
2e0fef85 5105 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea3101e 5106 int error;
5107
ee959b00 5108 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
eada272d
JS
5109 &sysfs_drvr_stat_data_attr);
5110
5111 /* Virtual ports do not need ctrl_reg and mbox */
5112 if (error || vport->port_type == LPFC_NPIV_PORT)
dea3101e 5113 goto out;
5114
ee959b00 5115 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
eada272d 5116 &sysfs_ctlreg_attr);
dea3101e 5117 if (error)
eada272d 5118 goto out_remove_stat_attr;
dea3101e 5119
ea2151b4 5120 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
eada272d 5121 &sysfs_mbox_attr);
ea2151b4 5122 if (error)
eada272d 5123 goto out_remove_ctlreg_attr;
ea2151b4 5124
dea3101e 5125 return 0;
5126out_remove_ctlreg_attr:
ee959b00 5127 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
eada272d
JS
5128out_remove_stat_attr:
5129 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5130 &sysfs_drvr_stat_data_attr);
dea3101e 5131out:
5132 return error;
5133}
5134
e59058c4 5135/**
3621a710 5136 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
e59058c4
JS
5137 * @vport: address of lpfc vport structure.
5138 **/
dea3101e 5139void
2e0fef85 5140lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea3101e 5141{
2e0fef85 5142 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
ea2151b4
JS
5143 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5144 &sysfs_drvr_stat_data_attr);
eada272d
JS
5145 /* Virtual ports do not need ctrl_reg and mbox */
5146 if (vport->port_type == LPFC_NPIV_PORT)
5147 return;
ee959b00
TJ
5148 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5149 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea3101e 5150}
5151
dea3101e 5152/*
5153 * Dynamic FC Host Attributes Support
5154 */
5155
e59058c4 5156/**
3621a710 5157 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
e59058c4
JS
5158 * @shost: kernel scsi host pointer.
5159 **/
dea3101e 5160static void
5161lpfc_get_host_port_id(struct Scsi_Host *shost)
5162{
2e0fef85
JS
5163 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5164
dea3101e 5165 /* note: fc_myDID already in cpu endianness */
2e0fef85 5166 fc_host_port_id(shost) = vport->fc_myDID;
dea3101e 5167}
5168
e59058c4 5169/**
3621a710 5170 * lpfc_get_host_port_type - Set the value of the scsi host port type
e59058c4
JS
5171 * @shost: kernel scsi host pointer.
5172 **/
dea3101e 5173static void
5174lpfc_get_host_port_type(struct Scsi_Host *shost)
5175{
2e0fef85
JS
5176 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5177 struct lpfc_hba *phba = vport->phba;
dea3101e 5178
5179 spin_lock_irq(shost->host_lock);
5180
92d7f7b0
JS
5181 if (vport->port_type == LPFC_NPIV_PORT) {
5182 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5183 } else if (lpfc_is_link_up(phba)) {
76a95d75 5184 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2e0fef85 5185 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea3101e 5186 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5187 else
5188 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5189 } else {
2e0fef85 5190 if (vport->fc_flag & FC_FABRIC)
dea3101e 5191 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5192 else
5193 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5194 }
5195 } else
5196 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5197
5198 spin_unlock_irq(shost->host_lock);
5199}
5200
e59058c4 5201/**
3621a710 5202 * lpfc_get_host_port_state - Set the value of the scsi host port state
e59058c4
JS
5203 * @shost: kernel scsi host pointer.
5204 **/
dea3101e 5205static void
5206lpfc_get_host_port_state(struct Scsi_Host *shost)
5207{
2e0fef85
JS
5208 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5209 struct lpfc_hba *phba = vport->phba;
dea3101e 5210
5211 spin_lock_irq(shost->host_lock);
5212
2e0fef85 5213 if (vport->fc_flag & FC_OFFLINE_MODE)
dea3101e 5214 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5215 else {
2e0fef85
JS
5216 switch (phba->link_state) {
5217 case LPFC_LINK_UNKNOWN:
dea3101e 5218 case LPFC_LINK_DOWN:
5219 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5220 break;
5221 case LPFC_LINK_UP:
dea3101e 5222 case LPFC_CLEAR_LA:
5223 case LPFC_HBA_READY:
026abb87
JS
5224 /* Links up, reports port state accordingly */
5225 if (vport->port_state < LPFC_VPORT_READY)
5226 fc_host_port_state(shost) =
5227 FC_PORTSTATE_BYPASSED;
5228 else
5229 fc_host_port_state(shost) =
5230 FC_PORTSTATE_ONLINE;
dea3101e 5231 break;
5232 case LPFC_HBA_ERROR:
5233 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5234 break;
5235 default:
5236 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5237 break;
5238 }
5239 }
5240
5241 spin_unlock_irq(shost->host_lock);
5242}
5243
e59058c4 5244/**
3621a710 5245 * lpfc_get_host_speed - Set the value of the scsi host speed
e59058c4
JS
5246 * @shost: kernel scsi host pointer.
5247 **/
dea3101e 5248static void
5249lpfc_get_host_speed(struct Scsi_Host *shost)
5250{
2e0fef85
JS
5251 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5252 struct lpfc_hba *phba = vport->phba;
dea3101e 5253
5254 spin_lock_irq(shost->host_lock);
5255
a085e87c 5256 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea3101e 5257 switch(phba->fc_linkspeed) {
76a95d75
JS
5258 case LPFC_LINK_SPEED_1GHZ:
5259 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea3101e 5260 break;
76a95d75
JS
5261 case LPFC_LINK_SPEED_2GHZ:
5262 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea3101e 5263 break;
76a95d75
JS
5264 case LPFC_LINK_SPEED_4GHZ:
5265 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea3101e 5266 break;
76a95d75
JS
5267 case LPFC_LINK_SPEED_8GHZ:
5268 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
b87eab38 5269 break;
76a95d75
JS
5270 case LPFC_LINK_SPEED_10GHZ:
5271 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
f4b4c68f 5272 break;
76a95d75
JS
5273 case LPFC_LINK_SPEED_16GHZ:
5274 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5275 break;
d38dd52c
JS
5276 case LPFC_LINK_SPEED_32GHZ:
5277 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5278 break;
76a95d75
JS
5279 default:
5280 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea3101e 5281 break;
5282 }
09372820
JS
5283 } else
5284 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea3101e 5285
5286 spin_unlock_irq(shost->host_lock);
5287}
5288
e59058c4 5289/**
3621a710 5290 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
e59058c4
JS
5291 * @shost: kernel scsi host pointer.
5292 **/
dea3101e 5293static void
5294lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5295{
2e0fef85
JS
5296 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5297 struct lpfc_hba *phba = vport->phba;
f631b4be 5298 u64 node_name;
dea3101e 5299
5300 spin_lock_irq(shost->host_lock);
5301
73d91e50
JS
5302 if ((vport->port_state > LPFC_FLOGI) &&
5303 ((vport->fc_flag & FC_FABRIC) ||
5304 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5305 (vport->fc_flag & FC_PUBLIC_LOOP))))
68ce1eb5 5306 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea3101e 5307 else
5308 /* fabric is local port if there is no F/FL_Port */
09372820 5309 node_name = 0;
dea3101e 5310
5311 spin_unlock_irq(shost->host_lock);
5312
f631b4be 5313 fc_host_fabric_name(shost) = node_name;
dea3101e 5314}
5315
e59058c4 5316/**
3621a710 5317 * lpfc_get_stats - Return statistical information about the adapter
e59058c4
JS
5318 * @shost: kernel scsi host pointer.
5319 *
5320 * Notes:
5321 * NULL on error for link down, no mbox pool, sli2 active,
5322 * management not allowed, memory allocation error, or mbox error.
5323 *
5324 * Returns:
5325 * NULL for error
5326 * address of the adapter host statistics
5327 **/
dea3101e 5328static struct fc_host_statistics *
5329lpfc_get_stats(struct Scsi_Host *shost)
5330{
2e0fef85
JS
5331 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5332 struct lpfc_hba *phba = vport->phba;
5333 struct lpfc_sli *psli = &phba->sli;
f888ba3c 5334 struct fc_host_statistics *hs = &phba->link_stats;
64ba8818 5335 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea3101e 5336 LPFC_MBOXQ_t *pmboxq;
5337 MAILBOX_t *pmb;
64ba8818 5338 unsigned long seconds;
433c3579 5339 int rc = 0;
dea3101e 5340
92d7f7b0
JS
5341 /*
5342 * prevent udev from issuing mailbox commands until the port is
5343 * configured.
5344 */
2e0fef85
JS
5345 if (phba->link_state < LPFC_LINK_DOWN ||
5346 !phba->mbox_mem_pool ||
f4b4c68f 5347 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
92d7f7b0 5348 return NULL;
2e0fef85
JS
5349
5350 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
46fa311e
JS
5351 return NULL;
5352
dea3101e 5353 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5354 if (!pmboxq)
5355 return NULL;
5356 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5357
04c68496 5358 pmb = &pmboxq->u.mb;
dea3101e 5359 pmb->mbxCommand = MBX_READ_STATUS;
5360 pmb->mbxOwner = OWN_HOST;
5361 pmboxq->context1 = NULL;
92d7f7b0 5362 pmboxq->vport = vport;
dea3101e 5363
75baf696 5364 if (vport->fc_flag & FC_OFFLINE_MODE)
dea3101e 5365 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
433c3579 5366 else
dea3101e 5367 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5368
5369 if (rc != MBX_SUCCESS) {
858c9f6c 5370 if (rc != MBX_TIMEOUT)
433c3579 5371 mempool_free(pmboxq, phba->mbox_mem_pool);
dea3101e 5372 return NULL;
5373 }
5374
f888ba3c
JSEC
5375 memset(hs, 0, sizeof (struct fc_host_statistics));
5376
dea3101e 5377 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
73d91e50
JS
5378 /*
5379 * The MBX_READ_STATUS returns tx_k_bytes which has to
5380 * converted to words
5381 */
5382 hs->tx_words = (uint64_t)
5383 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5384 * (uint64_t)256);
dea3101e 5385 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
73d91e50
JS
5386 hs->rx_words = (uint64_t)
5387 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5388 * (uint64_t)256);
dea3101e 5389
433c3579 5390 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea3101e 5391 pmb->mbxCommand = MBX_READ_LNK_STAT;
5392 pmb->mbxOwner = OWN_HOST;
5393 pmboxq->context1 = NULL;
92d7f7b0 5394 pmboxq->vport = vport;
dea3101e 5395
75baf696 5396 if (vport->fc_flag & FC_OFFLINE_MODE)
dea3101e 5397 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
433c3579 5398 else
dea3101e 5399 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5400
5401 if (rc != MBX_SUCCESS) {
858c9f6c 5402 if (rc != MBX_TIMEOUT)
92d7f7b0 5403 mempool_free(pmboxq, phba->mbox_mem_pool);
dea3101e 5404 return NULL;
5405 }
5406
5407 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5408 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5409 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5410 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5411 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5412 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5413 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5414
64ba8818
JS
5415 hs->link_failure_count -= lso->link_failure_count;
5416 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5417 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5418 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5419 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5420 hs->invalid_crc_count -= lso->invalid_crc_count;
5421 hs->error_frames -= lso->error_frames;
5422
76a95d75 5423 if (phba->hba_flag & HBA_FCOE_MODE) {
4d9ab994
JS
5424 hs->lip_count = -1;
5425 hs->nos_count = (phba->link_events >> 1);
5426 hs->nos_count -= lso->link_events;
76a95d75 5427 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea3101e 5428 hs->lip_count = (phba->fc_eventTag >> 1);
64ba8818 5429 hs->lip_count -= lso->link_events;
dea3101e 5430 hs->nos_count = -1;
5431 } else {
5432 hs->lip_count = -1;
5433 hs->nos_count = (phba->fc_eventTag >> 1);
64ba8818 5434 hs->nos_count -= lso->link_events;
dea3101e 5435 }
5436
5437 hs->dumped_frames = -1;
5438
64ba8818
JS
5439 seconds = get_seconds();
5440 if (seconds < psli->stats_start)
5441 hs->seconds_since_last_reset = seconds +
5442 ((unsigned long)-1 - psli->stats_start);
5443 else
5444 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea3101e 5445
1dcb58e5
JS
5446 mempool_free(pmboxq, phba->mbox_mem_pool);
5447
dea3101e 5448 return hs;
5449}
5450
e59058c4 5451/**
3621a710 5452 * lpfc_reset_stats - Copy the adapter link stats information
e59058c4
JS
5453 * @shost: kernel scsi host pointer.
5454 **/
64ba8818
JS
5455static void
5456lpfc_reset_stats(struct Scsi_Host *shost)
5457{
2e0fef85
JS
5458 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5459 struct lpfc_hba *phba = vport->phba;
5460 struct lpfc_sli *psli = &phba->sli;
5461 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
64ba8818
JS
5462 LPFC_MBOXQ_t *pmboxq;
5463 MAILBOX_t *pmb;
5464 int rc = 0;
5465
2e0fef85 5466 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
46fa311e
JS
5467 return;
5468
64ba8818
JS
5469 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5470 if (!pmboxq)
5471 return;
5472 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5473
04c68496 5474 pmb = &pmboxq->u.mb;
64ba8818
JS
5475 pmb->mbxCommand = MBX_READ_STATUS;
5476 pmb->mbxOwner = OWN_HOST;
5477 pmb->un.varWords[0] = 0x1; /* reset request */
5478 pmboxq->context1 = NULL;
92d7f7b0 5479 pmboxq->vport = vport;
64ba8818 5480
2e0fef85 5481 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
f4b4c68f 5482 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
64ba8818
JS
5483 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5484 else
5485 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5486
5487 if (rc != MBX_SUCCESS) {
858c9f6c 5488 if (rc != MBX_TIMEOUT)
64ba8818
JS
5489 mempool_free(pmboxq, phba->mbox_mem_pool);
5490 return;
5491 }
5492
5493 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5494 pmb->mbxCommand = MBX_READ_LNK_STAT;
5495 pmb->mbxOwner = OWN_HOST;
5496 pmboxq->context1 = NULL;
92d7f7b0 5497 pmboxq->vport = vport;
64ba8818 5498
2e0fef85 5499 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
f4b4c68f 5500 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
64ba8818
JS
5501 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5502 else
5503 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5504
5505 if (rc != MBX_SUCCESS) {
858c9f6c 5506 if (rc != MBX_TIMEOUT)
64ba8818
JS
5507 mempool_free( pmboxq, phba->mbox_mem_pool);
5508 return;
5509 }
5510
5511 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5512 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5513 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5514 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5515 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5516 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5517 lso->error_frames = pmb->un.varRdLnk.crcCnt;
76a95d75 5518 if (phba->hba_flag & HBA_FCOE_MODE)
4d9ab994
JS
5519 lso->link_events = (phba->link_events >> 1);
5520 else
5521 lso->link_events = (phba->fc_eventTag >> 1);
64ba8818
JS
5522
5523 psli->stats_start = get_seconds();
5524
1dcb58e5
JS
5525 mempool_free(pmboxq, phba->mbox_mem_pool);
5526
64ba8818
JS
5527 return;
5528}
dea3101e 5529
5530/*
5531 * The LPFC driver treats linkdown handling as target loss events so there
5532 * are no sysfs handlers for link_down_tmo.
5533 */
685f0bf7 5534
e59058c4 5535/**
3621a710 5536 * lpfc_get_node_by_target - Return the nodelist for a target
e59058c4
JS
5537 * @starget: kernel scsi target pointer.
5538 *
5539 * Returns:
5540 * address of the node list if found
5541 * NULL target not found
5542 **/
685f0bf7
JS
5543static struct lpfc_nodelist *
5544lpfc_get_node_by_target(struct scsi_target *starget)
dea3101e 5545{
2e0fef85
JS
5546 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5547 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
685f0bf7 5548 struct lpfc_nodelist *ndlp;
dea3101e 5549
5550 spin_lock_irq(shost->host_lock);
685f0bf7 5551 /* Search for this, mapped, target ID */
2e0fef85 5552 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
e47c9093
JS
5553 if (NLP_CHK_NODE_ACT(ndlp) &&
5554 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
685f0bf7
JS
5555 starget->id == ndlp->nlp_sid) {
5556 spin_unlock_irq(shost->host_lock);
5557 return ndlp;
dea3101e 5558 }
5559 }
5560 spin_unlock_irq(shost->host_lock);
685f0bf7
JS
5561 return NULL;
5562}
dea3101e 5563
e59058c4 5564/**
3621a710 5565 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
e59058c4
JS
5566 * @starget: kernel scsi target pointer.
5567 **/
685f0bf7
JS
5568static void
5569lpfc_get_starget_port_id(struct scsi_target *starget)
5570{
5571 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5572
5573 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea3101e 5574}
5575
e59058c4 5576/**
3621a710 5577 * lpfc_get_starget_node_name - Set the target node name
e59058c4
JS
5578 * @starget: kernel scsi target pointer.
5579 *
5580 * Description: Set the target node name to the ndlp node name wwn or zero.
5581 **/
dea3101e 5582static void
5583lpfc_get_starget_node_name(struct scsi_target *starget)
5584{
685f0bf7 5585 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea3101e 5586
685f0bf7
JS
5587 fc_starget_node_name(starget) =
5588 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea3101e 5589}
5590
e59058c4 5591/**
3621a710 5592 * lpfc_get_starget_port_name - Set the target port name
e59058c4
JS
5593 * @starget: kernel scsi target pointer.
5594 *
5595 * Description: set the target port name to the ndlp port name wwn or zero.
5596 **/
dea3101e 5597static void
5598lpfc_get_starget_port_name(struct scsi_target *starget)
5599{
685f0bf7 5600 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea3101e 5601
685f0bf7
JS
5602 fc_starget_port_name(starget) =
5603 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea3101e 5604}
5605
e59058c4 5606/**
3621a710 5607 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
e59058c4
JS
5608 * @rport: fc rport address.
5609 * @timeout: new value for dev loss tmo.
5610 *
5611 * Description:
5612 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5613 * dev_loss_tmo to one.
5614 **/
dea3101e 5615static void
5616lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5617{
dea3101e 5618 if (timeout)
c01f3208 5619 rport->dev_loss_tmo = timeout;
dea3101e 5620 else
c01f3208 5621 rport->dev_loss_tmo = 1;
dea3101e 5622}
5623
e59058c4 5624/**
3621a710 5625 * lpfc_rport_show_function - Return rport target information
e59058c4
JS
5626 *
5627 * Description:
5628 * Macro that uses field to generate a function with the name lpfc_show_rport_
5629 *
5630 * lpfc_show_rport_##field: returns the bytes formatted in buf
5631 * @cdev: class converted to an fc_rport.
5632 * @buf: on return contains the target_field or zero.
5633 *
5634 * Returns: size of formatted string.
5635 **/
dea3101e 5636#define lpfc_rport_show_function(field, format_string, sz, cast) \
5637static ssize_t \
ee959b00
TJ
5638lpfc_show_rport_##field (struct device *dev, \
5639 struct device_attribute *attr, \
5640 char *buf) \
dea3101e 5641{ \
ee959b00 5642 struct fc_rport *rport = transport_class_to_rport(dev); \
dea3101e 5643 struct lpfc_rport_data *rdata = rport->hostdata; \
5644 return snprintf(buf, sz, format_string, \
5645 (rdata->target) ? cast rdata->target->field : 0); \
5646}
5647
5648#define lpfc_rport_rd_attr(field, format_string, sz) \
5649 lpfc_rport_show_function(field, format_string, sz, ) \
5650static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5651
eada272d 5652/**
3621a710 5653 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
eada272d
JS
5654 * @fc_vport: The fc_vport who's symbolic name has been changed.
5655 *
5656 * Description:
5657 * This function is called by the transport after the @fc_vport's symbolic name
5658 * has been changed. This function re-registers the symbolic name with the
25985edc 5659 * switch to propagate the change into the fabric if the vport is active.
eada272d
JS
5660 **/
5661static void
5662lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5663{
5664 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5665
5666 if (vport->port_state == LPFC_VPORT_READY)
5667 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5668}
dea3101e 5669
f4b4c68f
JS
5670/**
5671 * lpfc_hba_log_verbose_init - Set hba's log verbose level
5672 * @phba: Pointer to lpfc_hba struct.
5673 *
5674 * This function is called by the lpfc_get_cfgparam() routine to set the
5675 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
70f23fd6 5676 * log message according to the module's lpfc_log_verbose parameter setting
f4b4c68f
JS
5677 * before hba port or vport created.
5678 **/
5679static void
5680lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
5681{
5682 phba->cfg_log_verbose = verbose;
5683}
5684
dea3101e 5685struct fc_function_template lpfc_transport_functions = {
5686 /* fixed attributes the driver supports */
5687 .show_host_node_name = 1,
5688 .show_host_port_name = 1,
5689 .show_host_supported_classes = 1,
5690 .show_host_supported_fc4s = 1,
dea3101e 5691 .show_host_supported_speeds = 1,
5692 .show_host_maxframe_size = 1,
eada272d 5693 .show_host_symbolic_name = 1,
dea3101e 5694
5695 /* dynamic attributes the driver supports */
5696 .get_host_port_id = lpfc_get_host_port_id,
5697 .show_host_port_id = 1,
5698
5699 .get_host_port_type = lpfc_get_host_port_type,
5700 .show_host_port_type = 1,
5701
5702 .get_host_port_state = lpfc_get_host_port_state,
5703 .show_host_port_state = 1,
5704
5705 /* active_fc4s is shown but doesn't change (thus no get function) */
5706 .show_host_active_fc4s = 1,
5707
5708 .get_host_speed = lpfc_get_host_speed,
5709 .show_host_speed = 1,
5710
5711 .get_host_fabric_name = lpfc_get_host_fabric_name,
5712 .show_host_fabric_name = 1,
5713
5714 /*
5715 * The LPFC driver treats linkdown handling as target loss events
5716 * so there are no sysfs handlers for link_down_tmo.
5717 */
5718
5719 .get_fc_host_stats = lpfc_get_stats,
64ba8818 5720 .reset_fc_host_stats = lpfc_reset_stats,
dea3101e 5721
5722 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5723 .show_rport_maxframe_size = 1,
5724 .show_rport_supported_classes = 1,
5725
dea3101e 5726 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5727 .show_rport_dev_loss_tmo = 1,
5728
5729 .get_starget_port_id = lpfc_get_starget_port_id,
5730 .show_starget_port_id = 1,
5731
5732 .get_starget_node_name = lpfc_get_starget_node_name,
5733 .show_starget_node_name = 1,
5734
5735 .get_starget_port_name = lpfc_get_starget_port_name,
5736 .show_starget_port_name = 1,
91ca7b01
AV
5737
5738 .issue_fc_host_lip = lpfc_issue_lip,
c01f3208
JS
5739 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5740 .terminate_rport_io = lpfc_terminate_rport_io,
92d7f7b0 5741
92d7f7b0 5742 .dd_fcvport_size = sizeof(struct lpfc_vport *),
eada272d
JS
5743
5744 .vport_disable = lpfc_vport_disable,
5745
5746 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
f1c3b0fc
JS
5747
5748 .bsg_request = lpfc_bsg_request,
5749 .bsg_timeout = lpfc_bsg_timeout,
92d7f7b0
JS
5750};
5751
98c9ea5c
JS
5752struct fc_function_template lpfc_vport_transport_functions = {
5753 /* fixed attributes the driver supports */
5754 .show_host_node_name = 1,
5755 .show_host_port_name = 1,
5756 .show_host_supported_classes = 1,
5757 .show_host_supported_fc4s = 1,
5758 .show_host_supported_speeds = 1,
5759 .show_host_maxframe_size = 1,
eada272d 5760 .show_host_symbolic_name = 1,
98c9ea5c
JS
5761
5762 /* dynamic attributes the driver supports */
5763 .get_host_port_id = lpfc_get_host_port_id,
5764 .show_host_port_id = 1,
5765
5766 .get_host_port_type = lpfc_get_host_port_type,
5767 .show_host_port_type = 1,
5768
5769 .get_host_port_state = lpfc_get_host_port_state,
5770 .show_host_port_state = 1,
5771
5772 /* active_fc4s is shown but doesn't change (thus no get function) */
5773 .show_host_active_fc4s = 1,
5774
5775 .get_host_speed = lpfc_get_host_speed,
5776 .show_host_speed = 1,
5777
5778 .get_host_fabric_name = lpfc_get_host_fabric_name,
5779 .show_host_fabric_name = 1,
5780
5781 /*
5782 * The LPFC driver treats linkdown handling as target loss events
5783 * so there are no sysfs handlers for link_down_tmo.
5784 */
5785
5786 .get_fc_host_stats = lpfc_get_stats,
5787 .reset_fc_host_stats = lpfc_reset_stats,
5788
5789 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5790 .show_rport_maxframe_size = 1,
5791 .show_rport_supported_classes = 1,
5792
5793 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5794 .show_rport_dev_loss_tmo = 1,
5795
5796 .get_starget_port_id = lpfc_get_starget_port_id,
5797 .show_starget_port_id = 1,
5798
5799 .get_starget_node_name = lpfc_get_starget_node_name,
5800 .show_starget_node_name = 1,
5801
5802 .get_starget_port_name = lpfc_get_starget_port_name,
5803 .show_starget_port_name = 1,
5804
5805 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5806 .terminate_rport_io = lpfc_terminate_rport_io,
5807
5808 .vport_disable = lpfc_vport_disable,
eada272d
JS
5809
5810 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
98c9ea5c
JS
5811};
5812
e59058c4 5813/**
3621a710 5814 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
e59058c4
JS
5815 * @phba: lpfc_hba pointer.
5816 **/
dea3101e 5817void
5818lpfc_get_cfgparam(struct lpfc_hba *phba)
5819{
49aa143d 5820 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
a6571c6e 5821 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
7bcbb752
JSEC
5822 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5823 lpfc_cr_count_init(phba, lpfc_cr_count);
cf5bf97e 5824 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
a4bc3379
JS
5825 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5826 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
7bcbb752
JSEC
5827 lpfc_ack0_init(phba, lpfc_ack0);
5828 lpfc_topology_init(phba, lpfc_topology);
7bcbb752 5829 lpfc_link_speed_init(phba, lpfc_link_speed);
875fbdfe 5830 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
0c411222 5831 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
78b2d852 5832 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
7d791df7 5833 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
19ca7609 5834 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
4258e98e
JS
5835 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
5836 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
4ff43246 5837 lpfc_use_msi_init(phba, lpfc_use_msi);
da0436e9 5838 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
7bb03bbf 5839 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
67d12733 5840 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
13815c83
JS
5841 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5842 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
1ba981fd
JS
5843 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
5844 if (phba->sli_rev != LPFC_SLI_REV4)
5845 phba->cfg_EnableXLane = 0;
5846 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
5847 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
5848 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
5849 phba->cfg_oas_lun_state = 0;
5850 phba->cfg_oas_lun_status = 0;
5851 phba->cfg_oas_flags = 0;
81301a9b 5852 lpfc_enable_bg_init(phba, lpfc_enable_bg);
45ed1190
JS
5853 if (phba->sli_rev == LPFC_SLI_REV4)
5854 phba->cfg_poll = 0;
5855 else
1ba981fd 5856 phba->cfg_poll = lpfc_poll;
4258e98e 5857
a12e07bc 5858 phba->cfg_soft_wwnn = 0L;
c3f28afa 5859 phba->cfg_soft_wwpn = 0L;
83108bd3 5860 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
81301a9b 5861 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
7054a606 5862 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
6fb120a7 5863 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
0d878419 5864 lpfc_aer_support_init(phba, lpfc_aer_support);
912e3acd 5865 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
c71ab861 5866 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
84d1b006 5867 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
2a9bf3d0 5868 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
ab56dc2e 5869 phba->cfg_enable_dss = 1;
3de2a653
JS
5870 return;
5871}
b28485ac 5872
e59058c4 5873/**
3621a710 5874 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
e59058c4
JS
5875 * @vport: lpfc_vport pointer.
5876 **/
3de2a653
JS
5877void
5878lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5879{
e8b62011 5880 lpfc_log_verbose_init(vport, lpfc_log_verbose);
3de2a653 5881 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
7dc517df 5882 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
3de2a653
JS
5883 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5884 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5885 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5886 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5887 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5888 lpfc_use_adisc_init(vport, lpfc_use_adisc);
3cb01c57 5889 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
977b5a0a 5890 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
3de2a653
JS
5891 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5892 lpfc_max_luns_init(vport, lpfc_max_luns);
5893 lpfc_scan_down_init(vport, lpfc_scan_down);
7ee5d43e 5894 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea3101e 5895 return;
5896}
This page took 1.24401 seconds and 5 git commands to generate.