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