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