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