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