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