]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/scsi/lpfc/lpfc_attr.c
treewide: Use DEVICE_ATTR_RW
[mirror_ubuntu-bionic-kernel.git] / drivers / scsi / lpfc / lpfc_attr.c
CommitLineData
dea3101e
JB
1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
c44ce173 3 * Fibre Channel Host Bus Adapters. *
d080abe0
JS
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
50611577 6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
c44ce173 7 * EMULEX and SLI are trademarks of Emulex. *
d080abe0 8 * www.broadcom.com *
c44ce173 9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea3101e
JB
10 * *
11 * This program is free software; you can redistribute it and/or *
c44ce173
JSEC
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
dea3101e
JB
22 *******************************************************************/
23
dea3101e 24#include <linux/ctype.h>
46fa311e 25#include <linux/delay.h>
dea3101e
JB
26#include <linux/pci.h>
27#include <linux/interrupt.h>
acf3368f 28#include <linux/module.h>
0d878419 29#include <linux/aer.h>
5a0e3ad6 30#include <linux/gfp.h>
ecc30990 31#include <linux/kernel.h>
dea3101e 32
91886523 33#include <scsi/scsi.h>
dea3101e
JB
34#include <scsi/scsi_device.h>
35#include <scsi/scsi_host.h>
36#include <scsi/scsi_tcq.h>
37#include <scsi/scsi_transport_fc.h>
6a9c52cf 38#include <scsi/fc/fc_fs.h>
dea3101e 39
895427bd
JS
40#include <linux/nvme-fc-driver.h>
41
da0436e9 42#include "lpfc_hw4.h"
dea3101e
JB
43#include "lpfc_hw.h"
44#include "lpfc_sli.h"
da0436e9 45#include "lpfc_sli4.h"
ea2151b4 46#include "lpfc_nl.h"
dea3101e 47#include "lpfc_disc.h"
dea3101e 48#include "lpfc.h"
895427bd
JS
49#include "lpfc_scsi.h"
50#include "lpfc_nvme.h"
f358dd0c 51#include "lpfc_nvmet.h"
dea3101e
JB
52#include "lpfc_logmsg.h"
53#include "lpfc_version.h"
54#include "lpfc_compat.h"
55#include "lpfc_crtn.h"
92d7f7b0 56#include "lpfc_vport.h"
93dd1911 57#include "lpfc_attr.h"
dea3101e 58
2ea259ee
JS
59#define LPFC_DEF_DEVLOSS_TMO 30
60#define LPFC_MIN_DEVLOSS_TMO 1
61#define LPFC_MAX_DEVLOSS_TMO 255
dea3101e 62
61f3d4bf
JS
63#define LPFC_DEF_MRQ_POST 512
64#define LPFC_MIN_MRQ_POST 512
65#define LPFC_MAX_MRQ_POST 2048
dea3101e 66
f7a919b4
JS
67/*
68 * Write key size should be multiple of 4. If write key is changed
69 * make sure that library write key is also changed.
70 */
71#define LPFC_REG_WRITE_KEY_SIZE 4
72#define LPFC_REG_WRITE_KEY "EMLX"
73
e59058c4 74/**
3621a710 75 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
e59058c4
JS
76 * @incr: integer to convert.
77 * @hdw: ascii string holding converted integer plus a string terminator.
78 *
79 * Description:
80 * JEDEC Joint Electron Device Engineering Council.
81 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
82 * character string. The string is then terminated with a NULL in byte 9.
83 * Hex 0-9 becomes ascii '0' to '9'.
84 * Hex a-f becomes ascii '=' to 'B' capital B.
85 *
86 * Notes:
87 * Coded for 32 bit integers only.
88 **/
dea3101e
JB
89static void
90lpfc_jedec_to_ascii(int incr, char hdw[])
91{
92 int i, j;
93 for (i = 0; i < 8; i++) {
94 j = (incr & 0xf);
95 if (j <= 9)
96 hdw[7 - i] = 0x30 + j;
97 else
98 hdw[7 - i] = 0x61 + j - 10;
99 incr = (incr >> 4);
100 }
101 hdw[8] = 0;
102 return;
103}
104
e59058c4 105/**
3621a710 106 * lpfc_drvr_version_show - Return the Emulex driver string with version number
e59058c4
JS
107 * @dev: class unused variable.
108 * @attr: device attribute, not used.
109 * @buf: on return contains the module description text.
110 *
111 * Returns: size of formatted string.
112 **/
dea3101e 113static ssize_t
ee959b00
TJ
114lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
115 char *buf)
dea3101e
JB
116{
117 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
118}
119
45ed1190
JS
120/**
121 * lpfc_enable_fip_show - Return the fip mode of the HBA
122 * @dev: class unused variable.
123 * @attr: device attribute, not used.
124 * @buf: on return contains the module description text.
125 *
126 * Returns: size of formatted string.
127 **/
128static ssize_t
129lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
130 char *buf)
131{
132 struct Scsi_Host *shost = class_to_shost(dev);
133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
134 struct lpfc_hba *phba = vport->phba;
135
136 if (phba->hba_flag & HBA_FIP_SUPPORT)
137 return snprintf(buf, PAGE_SIZE, "1\n");
138 else
139 return snprintf(buf, PAGE_SIZE, "0\n");
140}
141
895427bd
JS
142static ssize_t
143lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
144 char *buf)
145{
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = shost_priv(shost);
148 struct lpfc_hba *phba = vport->phba;
f358dd0c 149 struct lpfc_nvmet_tgtport *tgtp;
895427bd 150 struct nvme_fc_local_port *localport;
24909450 151 struct lpfc_nvme_lport *lport;
80cc0043 152 struct lpfc_nodelist *ndlp;
895427bd 153 struct nvme_fc_remote_port *nrport;
2cee7808 154 uint64_t data1, data2, data3, tot;
895427bd
JS
155 char *statep;
156 int len = 0;
157
158 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
159 len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n");
160 return len;
161 }
f358dd0c
JS
162 if (phba->nvmet_support) {
163 if (!phba->targetport) {
164 len = snprintf(buf, PAGE_SIZE,
165 "NVME Target: x%llx is not allocated\n",
166 wwn_to_u64(vport->fc_portname.u.wwn));
167 return len;
168 }
169 /* Port state is only one of two values for now. */
170 if (phba->targetport->port_id)
171 statep = "REGISTERED";
172 else
173 statep = "INIT";
174 len += snprintf(buf + len, PAGE_SIZE - len,
b4fd681e 175 "NVME Target Enabled State %s\n",
f358dd0c
JS
176 statep);
177 len += snprintf(buf + len, PAGE_SIZE - len,
178 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
179 "NVME Target: lpfc",
180 phba->brd_no,
181 wwn_to_u64(vport->fc_portname.u.wwn),
182 wwn_to_u64(vport->fc_nodename.u.wwn),
183 phba->targetport->port_id);
184
ea98ab34 185 len += snprintf(buf + len, PAGE_SIZE - len,
f358dd0c
JS
186 "\nNVME Target: Statistics\n");
187 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
188 len += snprintf(buf+len, PAGE_SIZE-len,
189 "LS: Rcv %08x Drop %08x Abort %08x\n",
190 atomic_read(&tgtp->rcv_ls_req_in),
191 atomic_read(&tgtp->rcv_ls_req_drop),
192 atomic_read(&tgtp->xmt_ls_abort));
193 if (atomic_read(&tgtp->rcv_ls_req_in) !=
194 atomic_read(&tgtp->rcv_ls_req_out)) {
195 len += snprintf(buf+len, PAGE_SIZE-len,
196 "Rcv LS: in %08x != out %08x\n",
197 atomic_read(&tgtp->rcv_ls_req_in),
198 atomic_read(&tgtp->rcv_ls_req_out));
199 }
200
201 len += snprintf(buf+len, PAGE_SIZE-len,
24909450 202 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
f358dd0c
JS
203 atomic_read(&tgtp->xmt_ls_rsp),
204 atomic_read(&tgtp->xmt_ls_drop),
24909450
JS
205 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
206
207 len += snprintf(buf + len, PAGE_SIZE - len,
208 "LS: RSP Abort %08x xb %08x Err %08x\n",
209 atomic_read(&tgtp->xmt_ls_rsp_aborted),
210 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
f358dd0c
JS
211 atomic_read(&tgtp->xmt_ls_rsp_error));
212
213 len += snprintf(buf+len, PAGE_SIZE-len,
50738420
JS
214 "FCP: Rcv %08x Defer %08x Release %08x "
215 "Drop %08x\n",
f358dd0c 216 atomic_read(&tgtp->rcv_fcp_cmd_in),
50738420 217 atomic_read(&tgtp->rcv_fcp_cmd_defer),
547077a4 218 atomic_read(&tgtp->xmt_fcp_release),
f358dd0c
JS
219 atomic_read(&tgtp->rcv_fcp_cmd_drop));
220
221 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
222 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
223 len += snprintf(buf+len, PAGE_SIZE-len,
224 "Rcv FCP: in %08x != out %08x\n",
225 atomic_read(&tgtp->rcv_fcp_cmd_in),
226 atomic_read(&tgtp->rcv_fcp_cmd_out));
227 }
228
229 len += snprintf(buf+len, PAGE_SIZE-len,
547077a4
JS
230 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
231 "drop %08x\n",
f358dd0c
JS
232 atomic_read(&tgtp->xmt_fcp_read),
233 atomic_read(&tgtp->xmt_fcp_read_rsp),
234 atomic_read(&tgtp->xmt_fcp_write),
547077a4 235 atomic_read(&tgtp->xmt_fcp_rsp),
f358dd0c
JS
236 atomic_read(&tgtp->xmt_fcp_drop));
237
238 len += snprintf(buf+len, PAGE_SIZE-len,
239 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
240 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
241 atomic_read(&tgtp->xmt_fcp_rsp_error),
242 atomic_read(&tgtp->xmt_fcp_rsp_drop));
243
244 len += snprintf(buf+len, PAGE_SIZE-len,
24909450
JS
245 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
246 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
247 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
248 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
249
250 len += snprintf(buf + len, PAGE_SIZE - len,
547077a4
JS
251 "ABORT: Xmt %08x Cmpl %08x\n",
252 atomic_read(&tgtp->xmt_fcp_abort),
253 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
254
255 len += snprintf(buf + len, PAGE_SIZE - len,
256 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
257 atomic_read(&tgtp->xmt_abort_sol),
258 atomic_read(&tgtp->xmt_abort_unsol),
f358dd0c 259 atomic_read(&tgtp->xmt_abort_rsp),
547077a4 260 atomic_read(&tgtp->xmt_abort_rsp_error));
f358dd0c 261
66d7ce93
DK
262 /* Calculate outstanding IOs */
263 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
264 tot += atomic_read(&tgtp->xmt_fcp_release);
265 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
2cee7808 266
a8cf5dfe 267 len += snprintf(buf + len, PAGE_SIZE - len,
2cee7808
JS
268 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
269 "CTX Outstanding %08llx\n",
966bb5b7 270 phba->sli4_hba.nvmet_xri_cnt,
a8cf5dfe 271 phba->sli4_hba.nvmet_io_wait_cnt,
2cee7808
JS
272 phba->sli4_hba.nvmet_io_wait_total,
273 tot);
a8cf5dfe 274
f358dd0c
JS
275 len += snprintf(buf+len, PAGE_SIZE-len, "\n");
276 return len;
277 }
895427bd
JS
278
279 localport = vport->localport;
280 if (!localport) {
281 len = snprintf(buf, PAGE_SIZE,
282 "NVME Initiator x%llx is not allocated\n",
283 wwn_to_u64(vport->fc_portname.u.wwn));
284 return len;
285 }
89842a20 286 lport = (struct lpfc_nvme_lport *)localport->private;
895427bd
JS
287 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
288
289 spin_lock_irq(shost->host_lock);
895427bd
JS
290
291 /* Port state is only one of two values for now. */
292 if (localport->port_id)
293 statep = "ONLINE";
294 else
295 statep = "UNKNOWN ";
296
297 len += snprintf(buf + len, PAGE_SIZE - len,
298 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
299 "NVME LPORT lpfc",
300 phba->brd_no,
301 wwn_to_u64(vport->fc_portname.u.wwn),
302 wwn_to_u64(vport->fc_nodename.u.wwn),
303 localport->port_id, statep);
304
80cc0043
JS
305 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
306 if (!ndlp->nrport)
307 continue;
308
895427bd 309 /* local short-hand pointer. */
80cc0043 310 nrport = ndlp->nrport->remoteport;
895427bd
JS
311
312 /* Port state is only one of two values for now. */
313 switch (nrport->port_state) {
314 case FC_OBJSTATE_ONLINE:
315 statep = "ONLINE";
316 break;
317 case FC_OBJSTATE_UNKNOWN:
318 statep = "UNKNOWN ";
319 break;
320 default:
321 statep = "UNSUPPORTED";
322 break;
323 }
324
325 /* Tab in to show lport ownership. */
326 len += snprintf(buf + len, PAGE_SIZE - len,
327 "NVME RPORT ");
328 if (phba->brd_no >= 10)
329 len += snprintf(buf + len, PAGE_SIZE - len, " ");
330
331 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ",
332 nrport->port_name);
333 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ",
334 nrport->node_name);
335 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ",
336 nrport->port_id);
337
7d790f04
JS
338 /* An NVME rport can have multiple roles. */
339 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
895427bd
JS
340 len += snprintf(buf + len, PAGE_SIZE - len,
341 "INITIATOR ");
7d790f04 342 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
895427bd
JS
343 len += snprintf(buf + len, PAGE_SIZE - len,
344 "TARGET ");
7d790f04 345 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
895427bd 346 len += snprintf(buf + len, PAGE_SIZE - len,
7d790f04
JS
347 "DISCSRVC ");
348 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
349 FC_PORT_ROLE_NVME_TARGET |
350 FC_PORT_ROLE_NVME_DISCOVERY))
895427bd 351 len += snprintf(buf + len, PAGE_SIZE - len,
7d790f04 352 "UNKNOWN ROLE x%x",
895427bd 353 nrport->port_role);
7d790f04 354
895427bd
JS
355 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep);
356 /* Terminate the string. */
357 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
358 }
359 spin_unlock_irq(shost->host_lock);
360
ea98ab34 361 len += snprintf(buf + len, PAGE_SIZE - len, "\nNVME Statistics\n");
895427bd 362 len += snprintf(buf+len, PAGE_SIZE-len,
24909450 363 "LS: Xmt %010x Cmpl %010x Abort %08x\n",
2cee7808 364 atomic_read(&phba->fc4NvmeLsRequests),
24909450
JS
365 atomic_read(&phba->fc4NvmeLsCmpls),
366 atomic_read(&lport->xmt_ls_abort));
367
368 len += snprintf(buf + len, PAGE_SIZE - len,
369 "LS XMIT: Err %08x CMPL: xb %08x Err %08x\n",
370 atomic_read(&lport->xmt_ls_err),
371 atomic_read(&lport->cmpl_ls_xb),
372 atomic_read(&lport->cmpl_ls_err));
2cee7808
JS
373
374 tot = atomic_read(&phba->fc4NvmeIoCmpls);
375 data1 = atomic_read(&phba->fc4NvmeInputRequests);
376 data2 = atomic_read(&phba->fc4NvmeOutputRequests);
377 data3 = atomic_read(&phba->fc4NvmeControlRequests);
895427bd
JS
378 len += snprintf(buf+len, PAGE_SIZE-len,
379 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
2cee7808 380 data1, data2, data3);
895427bd
JS
381
382 len += snprintf(buf+len, PAGE_SIZE-len,
24909450
JS
383 " noxri %08x nondlp %08x qdepth %08x "
384 "wqerr %08x\n",
385 atomic_read(&lport->xmt_fcp_noxri),
386 atomic_read(&lport->xmt_fcp_bad_ndlp),
387 atomic_read(&lport->xmt_fcp_qdepth),
388 atomic_read(&lport->xmt_fcp_wqerr));
389
390 len += snprintf(buf + len, PAGE_SIZE - len,
391 " Cmpl %016llx Outstanding %016llx Abort %08x\n",
392 tot, ((data1 + data2 + data3) - tot),
393 atomic_read(&lport->xmt_fcp_abort));
394
395 len += snprintf(buf + len, PAGE_SIZE - len,
396 "FCP CMPL: xb %08x Err %08x\n",
397 atomic_read(&lport->cmpl_fcp_xb),
398 atomic_read(&lport->cmpl_fcp_err));
895427bd
JS
399 return len;
400}
401
81301a9b
JS
402static ssize_t
403lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
404 char *buf)
405{
406 struct Scsi_Host *shost = class_to_shost(dev);
407 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
408 struct lpfc_hba *phba = vport->phba;
409
410 if (phba->cfg_enable_bg)
411 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
412 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
413 else
414 return snprintf(buf, PAGE_SIZE,
415 "BlockGuard Not Supported\n");
416 else
417 return snprintf(buf, PAGE_SIZE,
418 "BlockGuard Disabled\n");
419}
420
421static ssize_t
422lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
423 char *buf)
424{
425 struct Scsi_Host *shost = class_to_shost(dev);
426 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
427 struct lpfc_hba *phba = vport->phba;
428
87b5c328
JS
429 return snprintf(buf, PAGE_SIZE, "%llu\n",
430 (unsigned long long)phba->bg_guard_err_cnt);
81301a9b
JS
431}
432
433static ssize_t
434lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
435 char *buf)
436{
437 struct Scsi_Host *shost = class_to_shost(dev);
438 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
439 struct lpfc_hba *phba = vport->phba;
440
87b5c328
JS
441 return snprintf(buf, PAGE_SIZE, "%llu\n",
442 (unsigned long long)phba->bg_apptag_err_cnt);
81301a9b
JS
443}
444
445static ssize_t
446lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
447 char *buf)
448{
449 struct Scsi_Host *shost = class_to_shost(dev);
450 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
451 struct lpfc_hba *phba = vport->phba;
452
87b5c328
JS
453 return snprintf(buf, PAGE_SIZE, "%llu\n",
454 (unsigned long long)phba->bg_reftag_err_cnt);
81301a9b
JS
455}
456
e59058c4 457/**
3621a710 458 * lpfc_info_show - Return some pci info about the host in ascii
e59058c4
JS
459 * @dev: class converted to a Scsi_host structure.
460 * @attr: device attribute, not used.
461 * @buf: on return contains the formatted text from lpfc_info().
462 *
463 * Returns: size of formatted string.
464 **/
dea3101e 465static ssize_t
ee959b00
TJ
466lpfc_info_show(struct device *dev, struct device_attribute *attr,
467 char *buf)
dea3101e 468{
ee959b00 469 struct Scsi_Host *host = class_to_shost(dev);
2e0fef85 470
dea3101e
JB
471 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
472}
473
e59058c4 474/**
3621a710 475 * lpfc_serialnum_show - Return the hba serial number in ascii
e59058c4
JS
476 * @dev: class converted to a Scsi_host structure.
477 * @attr: device attribute, not used.
478 * @buf: on return contains the formatted text serial number.
479 *
480 * Returns: size of formatted string.
481 **/
dea3101e 482static ssize_t
ee959b00
TJ
483lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
484 char *buf)
dea3101e 485{
ee959b00 486 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
487 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
488 struct lpfc_hba *phba = vport->phba;
489
dea3101e
JB
490 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
491}
492
e59058c4 493/**
3621a710 494 * lpfc_temp_sensor_show - Return the temperature sensor level
e59058c4
JS
495 * @dev: class converted to a Scsi_host structure.
496 * @attr: device attribute, not used.
497 * @buf: on return contains the formatted support level.
498 *
499 * Description:
500 * Returns a number indicating the temperature sensor level currently
501 * supported, zero or one in ascii.
502 *
503 * Returns: size of formatted string.
504 **/
57127f15 505static ssize_t
ee959b00
TJ
506lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
507 char *buf)
57127f15 508{
ee959b00 509 struct Scsi_Host *shost = class_to_shost(dev);
57127f15
JS
510 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
511 struct lpfc_hba *phba = vport->phba;
512 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
513}
514
e59058c4 515/**
3621a710 516 * lpfc_modeldesc_show - Return the model description of the hba
e59058c4
JS
517 * @dev: class converted to a Scsi_host structure.
518 * @attr: device attribute, not used.
519 * @buf: on return contains the scsi vpd model description.
520 *
521 * Returns: size of formatted string.
522 **/
dea3101e 523static ssize_t
ee959b00
TJ
524lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
525 char *buf)
dea3101e 526{
ee959b00 527 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
528 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
529 struct lpfc_hba *phba = vport->phba;
530
dea3101e
JB
531 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
532}
533
e59058c4 534/**
3621a710 535 * lpfc_modelname_show - Return the model name of the hba
e59058c4
JS
536 * @dev: class converted to a Scsi_host structure.
537 * @attr: device attribute, not used.
538 * @buf: on return contains the scsi vpd model name.
539 *
540 * Returns: size of formatted string.
541 **/
dea3101e 542static ssize_t
ee959b00
TJ
543lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
544 char *buf)
dea3101e 545{
ee959b00 546 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
547 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
548 struct lpfc_hba *phba = vport->phba;
549
dea3101e
JB
550 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
551}
552
e59058c4 553/**
3621a710 554 * lpfc_programtype_show - Return the program type of the hba
e59058c4
JS
555 * @dev: class converted to a Scsi_host structure.
556 * @attr: device attribute, not used.
557 * @buf: on return contains the scsi vpd program type.
558 *
559 * Returns: size of formatted string.
560 **/
dea3101e 561static ssize_t
ee959b00
TJ
562lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
563 char *buf)
dea3101e 564{
ee959b00 565 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
566 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
567 struct lpfc_hba *phba = vport->phba;
568
dea3101e
JB
569 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
570}
571
84774a4d 572/**
3621a710 573 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
84774a4d
JS
574 * @dev: class converted to a Scsi_host structure.
575 * @attr: device attribute, not used.
576 * @buf: on return contains the Menlo Maintenance sli flag.
577 *
578 * Returns: size of formatted string.
579 **/
580static ssize_t
581lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
582{
583 struct Scsi_Host *shost = class_to_shost(dev);
584 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
585 struct lpfc_hba *phba = vport->phba;
586
587 return snprintf(buf, PAGE_SIZE, "%d\n",
588 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
589}
590
e59058c4 591/**
3621a710 592 * lpfc_vportnum_show - Return the port number in ascii of the hba
e59058c4
JS
593 * @dev: class converted to a Scsi_host structure.
594 * @attr: device attribute, not used.
595 * @buf: on return contains scsi vpd program type.
596 *
597 * Returns: size of formatted string.
598 **/
dea3101e 599static ssize_t
ee959b00
TJ
600lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
601 char *buf)
dea3101e 602{
ee959b00 603 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
604 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
605 struct lpfc_hba *phba = vport->phba;
606
dea3101e
JB
607 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
608}
609
e59058c4 610/**
3621a710 611 * lpfc_fwrev_show - Return the firmware rev running in the hba
e59058c4
JS
612 * @dev: class converted to a Scsi_host structure.
613 * @attr: device attribute, not used.
614 * @buf: on return contains the scsi vpd program type.
615 *
616 * Returns: size of formatted string.
617 **/
dea3101e 618static ssize_t
ee959b00
TJ
619lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
620 char *buf)
dea3101e 621{
ee959b00 622 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
623 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
624 struct lpfc_hba *phba = vport->phba;
026abb87
JS
625 uint32_t if_type;
626 uint8_t sli_family;
6b5151fd 627 char fwrev[FW_REV_STR_SIZE];
026abb87 628 int len;
2e0fef85 629
dea3101e 630 lpfc_decode_firmware_rev(phba, fwrev, 1);
026abb87
JS
631 if_type = phba->sli4_hba.pc_sli4_params.if_type;
632 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
633
634 if (phba->sli_rev < LPFC_SLI_REV4)
635 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
636 fwrev, phba->sli_rev);
637 else
638 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
639 fwrev, phba->sli_rev, if_type, sli_family);
640
641 return len;
dea3101e
JB
642}
643
e59058c4 644/**
3621a710 645 * lpfc_hdw_show - Return the jedec information about the hba
e59058c4
JS
646 * @dev: class converted to a Scsi_host structure.
647 * @attr: device attribute, not used.
648 * @buf: on return contains the scsi vpd program type.
649 *
650 * Returns: size of formatted string.
651 **/
dea3101e 652static ssize_t
ee959b00 653lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea3101e
JB
654{
655 char hdw[9];
ee959b00 656 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
657 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
658 struct lpfc_hba *phba = vport->phba;
dea3101e 659 lpfc_vpd_t *vp = &phba->vpd;
2e0fef85 660
dea3101e
JB
661 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
662 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
663}
e59058c4
JS
664
665/**
3621a710 666 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
e59058c4
JS
667 * @dev: class converted to a Scsi_host structure.
668 * @attr: device attribute, not used.
669 * @buf: on return contains the ROM and FCode ascii strings.
670 *
671 * Returns: size of formatted string.
672 **/
dea3101e 673static ssize_t
ee959b00
TJ
674lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
675 char *buf)
dea3101e 676{
ee959b00 677 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
678 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
679 struct lpfc_hba *phba = vport->phba;
a0683bf6
JS
680 char fwrev[FW_REV_STR_SIZE];
681
682 if (phba->sli_rev < LPFC_SLI_REV4)
683 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
2e0fef85 684
a0683bf6
JS
685 lpfc_decode_firmware_rev(phba, fwrev, 1);
686 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
dea3101e 687}
e59058c4
JS
688
689/**
3621a710 690 * lpfc_state_show - Return the link state of the port
e59058c4
JS
691 * @dev: class converted to a Scsi_host structure.
692 * @attr: device attribute, not used.
693 * @buf: on return contains text describing the state of the link.
694 *
695 * Notes:
696 * The switch statement has no default so zero will be returned.
697 *
698 * Returns: size of formatted string.
699 **/
dea3101e 700static ssize_t
bbd1ae41
HR
701lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
702 char *buf)
dea3101e 703{
ee959b00 704 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
705 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
706 struct lpfc_hba *phba = vport->phba;
707 int len = 0;
708
709 switch (phba->link_state) {
710 case LPFC_LINK_UNKNOWN:
41415862 711 case LPFC_WARM_START:
dea3101e
JB
712 case LPFC_INIT_START:
713 case LPFC_INIT_MBX_CMDS:
714 case LPFC_LINK_DOWN:
2e0fef85 715 case LPFC_HBA_ERROR:
a0c87cbd
JS
716 if (phba->hba_flag & LINK_DISABLED)
717 len += snprintf(buf + len, PAGE_SIZE-len,
718 "Link Down - User disabled\n");
719 else
720 len += snprintf(buf + len, PAGE_SIZE-len,
721 "Link Down\n");
dea3101e
JB
722 break;
723 case LPFC_LINK_UP:
dea3101e 724 case LPFC_CLEAR_LA:
dea3101e 725 case LPFC_HBA_READY:
a8adb832 726 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
2e0fef85
JS
727
728 switch (vport->port_state) {
2e0fef85
JS
729 case LPFC_LOCAL_CFG_LINK:
730 len += snprintf(buf + len, PAGE_SIZE-len,
92d7f7b0 731 "Configuring Link\n");
2e0fef85 732 break;
92d7f7b0 733 case LPFC_FDISC:
2e0fef85
JS
734 case LPFC_FLOGI:
735 case LPFC_FABRIC_CFG_LINK:
736 case LPFC_NS_REG:
737 case LPFC_NS_QRY:
738 case LPFC_BUILD_DISC_LIST:
739 case LPFC_DISC_AUTH:
740 len += snprintf(buf + len, PAGE_SIZE - len,
741 "Discovery\n");
742 break;
743 case LPFC_VPORT_READY:
744 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
745 break;
746
92d7f7b0
JS
747 case LPFC_VPORT_FAILED:
748 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
749 break;
750
751 case LPFC_VPORT_UNKNOWN:
2e0fef85
JS
752 len += snprintf(buf + len, PAGE_SIZE - len,
753 "Unknown\n");
754 break;
755 }
84774a4d
JS
756 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
757 len += snprintf(buf + len, PAGE_SIZE-len,
758 " Menlo Maint Mode\n");
76a95d75 759 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2e0fef85 760 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea3101e
JB
761 len += snprintf(buf + len, PAGE_SIZE-len,
762 " Public Loop\n");
763 else
764 len += snprintf(buf + len, PAGE_SIZE-len,
765 " Private Loop\n");
766 } else {
2e0fef85 767 if (vport->fc_flag & FC_FABRIC)
dea3101e
JB
768 len += snprintf(buf + len, PAGE_SIZE-len,
769 " Fabric\n");
770 else
771 len += snprintf(buf + len, PAGE_SIZE-len,
772 " Point-2-Point\n");
773 }
774 }
2e0fef85 775
dea3101e
JB
776 return len;
777}
778
026abb87
JS
779/**
780 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
781 * @dev: class unused variable.
782 * @attr: device attribute, not used.
783 * @buf: on return contains the module description text.
784 *
785 * Returns: size of formatted string.
786 **/
787static ssize_t
788lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
789 char *buf)
790{
791 struct Scsi_Host *shost = class_to_shost(dev);
792 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
793 struct lpfc_hba *phba = vport->phba;
794
795 if (phba->sli_rev < LPFC_SLI_REV4)
796 return snprintf(buf, PAGE_SIZE, "fc\n");
797
798 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
799 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
800 return snprintf(buf, PAGE_SIZE, "fcoe\n");
801 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
802 return snprintf(buf, PAGE_SIZE, "fc\n");
803 }
804 return snprintf(buf, PAGE_SIZE, "unknown\n");
805}
806
1ba981fd
JS
807/**
808 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
809 * (OAS) is supported.
810 * @dev: class unused variable.
811 * @attr: device attribute, not used.
812 * @buf: on return contains the module description text.
813 *
814 * Returns: size of formatted string.
815 **/
816static ssize_t
817lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
818 char *buf)
819{
820 struct Scsi_Host *shost = class_to_shost(dev);
821 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
822 struct lpfc_hba *phba = vport->phba;
823
824 return snprintf(buf, PAGE_SIZE, "%d\n",
825 phba->sli4_hba.pc_sli4_params.oas_supported);
826}
827
84d1b006
JS
828/**
829 * lpfc_link_state_store - Transition the link_state on an HBA port
830 * @dev: class device that is converted into a Scsi_host.
831 * @attr: device attribute, not used.
832 * @buf: one or more lpfc_polling_flags values.
833 * @count: not used.
834 *
835 * Returns:
836 * -EINVAL if the buffer is not "up" or "down"
837 * return from link state change function if non-zero
838 * length of the buf on success
839 **/
840static ssize_t
841lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
842 const char *buf, size_t count)
843{
844 struct Scsi_Host *shost = class_to_shost(dev);
845 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
846 struct lpfc_hba *phba = vport->phba;
847
848 int status = -EINVAL;
849
850 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
851 (phba->link_state == LPFC_LINK_DOWN))
6e7288d9 852 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
84d1b006
JS
853 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
854 (phba->link_state >= LPFC_LINK_UP))
6e7288d9 855 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
84d1b006
JS
856
857 if (status == 0)
858 return strlen(buf);
859 else
860 return status;
861}
862
e59058c4 863/**
3621a710 864 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
e59058c4
JS
865 * @dev: class device that is converted into a Scsi_host.
866 * @attr: device attribute, not used.
867 * @buf: on return contains the sum of fc mapped and unmapped.
868 *
869 * Description:
870 * Returns the ascii text number of the sum of the fc mapped and unmapped
871 * vport counts.
872 *
873 * Returns: size of formatted string.
874 **/
dea3101e 875static ssize_t
ee959b00
TJ
876lpfc_num_discovered_ports_show(struct device *dev,
877 struct device_attribute *attr, char *buf)
dea3101e 878{
ee959b00 879 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
880 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
881
882 return snprintf(buf, PAGE_SIZE, "%d\n",
883 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea3101e
JB
884}
885
e59058c4 886/**
3621a710 887 * lpfc_issue_lip - Misnomer, name carried over from long ago
e59058c4
JS
888 * @shost: Scsi_Host pointer.
889 *
890 * Description:
891 * Bring the link down gracefully then re-init the link. The firmware will
892 * re-init the fiber channel interface as required. Does not issue a LIP.
893 *
894 * Returns:
895 * -EPERM port offline or management commands are being blocked
896 * -ENOMEM cannot allocate memory for the mailbox command
897 * -EIO error sending the mailbox command
898 * zero for success
899 **/
91ca7b01 900static int
2e0fef85 901lpfc_issue_lip(struct Scsi_Host *shost)
dea3101e 902{
2e0fef85
JS
903 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
904 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
905 LPFC_MBOXQ_t *pmboxq;
906 int mbxstatus = MBXERR_ERROR;
907
2e0fef85 908 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
83108bd3 909 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea3101e
JB
910 return -EPERM;
911
912 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
913
914 if (!pmboxq)
915 return -ENOMEM;
916
917 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
04c68496
JS
918 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
919 pmboxq->u.mb.mbxOwner = OWN_HOST;
4db621e0 920
33ccf8d1 921 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea3101e 922
04c68496
JS
923 if ((mbxstatus == MBX_SUCCESS) &&
924 (pmboxq->u.mb.mbxStatus == 0 ||
925 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
4db621e0
JS
926 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
927 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
928 phba->cfg_link_speed);
929 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
930 phba->fc_ratov * 2);
dcf2a4e0
JS
931 if ((mbxstatus == MBX_SUCCESS) &&
932 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
933 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
934 "2859 SLI authentication is required "
935 "for INIT_LINK but has not done yet\n");
4db621e0
JS
936 }
937
5b8bd0c9 938 lpfc_set_loopback_flag(phba);
858c9f6c 939 if (mbxstatus != MBX_TIMEOUT)
433c3579 940 mempool_free(pmboxq, phba->mbox_mem_pool);
dea3101e
JB
941
942 if (mbxstatus == MBXERR_ERROR)
943 return -EIO;
944
91ca7b01 945 return 0;
dea3101e
JB
946}
947
895427bd
JS
948int
949lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
950{
951 int cnt = 0;
952
953 spin_lock_irq(lock);
954 while (!list_empty(q)) {
955 spin_unlock_irq(lock);
956 msleep(20);
957 if (cnt++ > 250) { /* 5 secs */
958 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
959 "0466 %s %s\n",
960 "Outstanding IO when ",
961 "bringing Adapter offline\n");
962 return 0;
963 }
964 spin_lock_irq(lock);
965 }
966 spin_unlock_irq(lock);
967 return 1;
968}
969
e59058c4 970/**
3621a710 971 * lpfc_do_offline - Issues a mailbox command to bring the link down
e59058c4
JS
972 * @phba: lpfc_hba pointer.
973 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
974 *
975 * Notes:
976 * Assumes any error from lpfc_do_offline() will be negative.
977 * Can wait up to 5 seconds for the port ring buffers count
978 * to reach zero, prints a warning if it is not zero and continues.
3621a710 979 * lpfc_workq_post_event() returns a non-zero return code if call fails.
e59058c4
JS
980 *
981 * Returns:
982 * -EIO error posting the event
983 * zero for success
984 **/
40496f07 985static int
46fa311e 986lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
40496f07
JS
987{
988 struct completion online_compl;
895427bd 989 struct lpfc_queue *qp = NULL;
46fa311e
JS
990 struct lpfc_sli_ring *pring;
991 struct lpfc_sli *psli;
40496f07 992 int status = 0;
46fa311e 993 int i;
fedd3b7b 994 int rc;
40496f07
JS
995
996 init_completion(&online_compl);
fedd3b7b 997 rc = lpfc_workq_post_event(phba, &status, &online_compl,
46fa311e 998 LPFC_EVT_OFFLINE_PREP);
fedd3b7b
JS
999 if (rc == 0)
1000 return -ENOMEM;
1001
46fa311e
JS
1002 wait_for_completion(&online_compl);
1003
1004 if (status != 0)
1005 return -EIO;
1006
1007 psli = &phba->sli;
1008
09372820
JS
1009 /* Wait a little for things to settle down, but not
1010 * long enough for dev loss timeout to expire.
1011 */
895427bd
JS
1012 if (phba->sli_rev != LPFC_SLI_REV4) {
1013 for (i = 0; i < psli->num_rings; i++) {
1014 pring = &psli->sli3_ring[i];
1015 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1016 &phba->hbalock))
1017 goto out;
1018 }
1019 } else {
1020 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1021 pring = qp->pring;
1022 if (!pring)
1023 continue;
1024 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1025 &pring->ring_lock))
1026 goto out;
46fa311e
JS
1027 }
1028 }
895427bd 1029out:
46fa311e 1030 init_completion(&online_compl);
fedd3b7b
JS
1031 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1032 if (rc == 0)
1033 return -ENOMEM;
1034
40496f07
JS
1035 wait_for_completion(&online_compl);
1036
1037 if (status != 0)
1038 return -EIO;
1039
46fa311e
JS
1040 return 0;
1041}
1042
e59058c4 1043/**
3621a710 1044 * lpfc_selective_reset - Offline then onlines the port
e59058c4
JS
1045 * @phba: lpfc_hba pointer.
1046 *
1047 * Description:
1048 * If the port is configured to allow a reset then the hba is brought
1049 * offline then online.
1050 *
1051 * Notes:
1052 * Assumes any error from lpfc_do_offline() will be negative.
ab56dc2e 1053 * Do not make this function static.
e59058c4
JS
1054 *
1055 * Returns:
1056 * lpfc_do_offline() return code if not zero
1057 * -EIO reset not configured or error posting the event
1058 * zero for success
1059 **/
7f86059a 1060int
46fa311e
JS
1061lpfc_selective_reset(struct lpfc_hba *phba)
1062{
1063 struct completion online_compl;
1064 int status = 0;
fedd3b7b 1065 int rc;
46fa311e 1066
71157c9e 1067 if (!phba->cfg_enable_hba_reset)
f7a919b4 1068 return -EACCES;
13815c83 1069
71157c9e
JS
1070 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1071 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
46fa311e 1072
71157c9e
JS
1073 if (status != 0)
1074 return status;
1075 }
46fa311e 1076
40496f07 1077 init_completion(&online_compl);
fedd3b7b 1078 rc = lpfc_workq_post_event(phba, &status, &online_compl,
40496f07 1079 LPFC_EVT_ONLINE);
fedd3b7b
JS
1080 if (rc == 0)
1081 return -ENOMEM;
1082
40496f07
JS
1083 wait_for_completion(&online_compl);
1084
1085 if (status != 0)
1086 return -EIO;
1087
1088 return 0;
1089}
1090
e59058c4 1091/**
3621a710 1092 * lpfc_issue_reset - Selectively resets an adapter
e59058c4
JS
1093 * @dev: class device that is converted into a Scsi_host.
1094 * @attr: device attribute, not used.
1095 * @buf: containing the string "selective".
1096 * @count: unused variable.
1097 *
1098 * Description:
1099 * If the buf contains the string "selective" then lpfc_selective_reset()
1100 * is called to perform the reset.
1101 *
1102 * Notes:
1103 * Assumes any error from lpfc_selective_reset() will be negative.
1104 * If lpfc_selective_reset() returns zero then the length of the buffer
af901ca1 1105 * is returned which indicates success
e59058c4
JS
1106 *
1107 * Returns:
1108 * -EINVAL if the buffer does not contain the string "selective"
1109 * length of buf if lpfc-selective_reset() if the call succeeds
1110 * return value of lpfc_selective_reset() if the call fails
1111**/
40496f07 1112static ssize_t
ee959b00
TJ
1113lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1114 const char *buf, size_t count)
40496f07 1115{
ee959b00 1116 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
1117 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1118 struct lpfc_hba *phba = vport->phba;
40496f07
JS
1119 int status = -EINVAL;
1120
73d91e50
JS
1121 if (!phba->cfg_enable_hba_reset)
1122 return -EACCES;
1123
40496f07 1124 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
7f86059a 1125 status = phba->lpfc_selective_reset(phba);
40496f07
JS
1126
1127 if (status == 0)
1128 return strlen(buf);
1129 else
1130 return status;
1131}
1132
88a2cfbb
JS
1133/**
1134 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1135 * @phba: lpfc_hba pointer.
1136 *
1137 * Description:
1138 * SLI4 interface type-2 device to wait on the sliport status register for
1139 * the readyness after performing a firmware reset.
1140 *
1141 * Returns:
0b1587b1 1142 * zero for success, -EPERM when port does not have privilege to perform the
026abb87
JS
1143 * reset, -EIO when port timeout from recovering from the reset.
1144 *
1145 * Note:
1146 * As the caller will interpret the return code by value, be careful in making
1147 * change or addition to return codes.
88a2cfbb 1148 **/
73d91e50 1149int
88a2cfbb
JS
1150lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1151{
f7a919b4 1152 struct lpfc_register portstat_reg = {0};
88a2cfbb
JS
1153 int i;
1154
f7a919b4 1155 msleep(100);
88a2cfbb
JS
1156 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1157 &portstat_reg.word0);
1158
0b1587b1 1159 /* verify if privileged for the request operation */
f7a919b4
JS
1160 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1161 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1162 return -EPERM;
1163
88a2cfbb
JS
1164 /* wait for the SLI port firmware ready after firmware reset */
1165 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1166 msleep(10);
1167 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1168 &portstat_reg.word0);
1169 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1170 continue;
1171 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1172 continue;
1173 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1174 continue;
1175 break;
1176 }
1177
1178 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1179 return 0;
1180 else
1181 return -EIO;
1182}
1183
c0c11512 1184/**
52d52440 1185 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
c0c11512
JS
1186 * @phba: lpfc_hba pointer.
1187 *
1188 * Description:
52d52440
JS
1189 * Request SLI4 interface type-2 device to perform a physical register set
1190 * access.
c0c11512
JS
1191 *
1192 * Returns:
1193 * zero for success
1194 **/
1195static ssize_t
52d52440 1196lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
c0c11512
JS
1197{
1198 struct completion online_compl;
b76f2dc9 1199 struct pci_dev *pdev = phba->pcidev;
026abb87
JS
1200 uint32_t before_fc_flag;
1201 uint32_t sriov_nr_virtfn;
c0c11512 1202 uint32_t reg_val;
026abb87
JS
1203 int status = 0, rc = 0;
1204 int job_posted = 1, sriov_err;
c0c11512
JS
1205
1206 if (!phba->cfg_enable_hba_reset)
f7a919b4 1207 return -EACCES;
c0c11512 1208
52d52440
JS
1209 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1210 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1211 LPFC_SLI_INTF_IF_TYPE_2))
1212 return -EPERM;
1213
026abb87
JS
1214 /* Keep state if we need to restore back */
1215 before_fc_flag = phba->pport->fc_flag;
1216 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1217
b76f2dc9
JS
1218 /* Disable SR-IOV virtual functions if enabled */
1219 if (phba->cfg_sriov_nr_virtfn) {
1220 pci_disable_sriov(pdev);
1221 phba->cfg_sriov_nr_virtfn = 0;
1222 }
229adb0e 1223
0293635e
JS
1224 if (opcode == LPFC_FW_DUMP)
1225 phba->hba_flag |= HBA_FW_DUMP_OP;
1226
c0c11512
JS
1227 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1228
0293635e
JS
1229 if (status != 0) {
1230 phba->hba_flag &= ~HBA_FW_DUMP_OP;
c0c11512 1231 return status;
0293635e 1232 }
c0c11512
JS
1233
1234 /* wait for the device to be quiesced before firmware reset */
1235 msleep(100);
1236
1237 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1238 LPFC_CTL_PDEV_CTL_OFFSET);
52d52440
JS
1239
1240 if (opcode == LPFC_FW_DUMP)
1241 reg_val |= LPFC_FW_DUMP_REQUEST;
1242 else if (opcode == LPFC_FW_RESET)
1243 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1244 else if (opcode == LPFC_DV_RESET)
1245 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1246
c0c11512
JS
1247 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1248 LPFC_CTL_PDEV_CTL_OFFSET);
1249 /* flush */
1250 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1251
1252 /* delay driver action following IF_TYPE_2 reset */
88a2cfbb
JS
1253 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1254
026abb87 1255 if (rc == -EPERM) {
0b1587b1 1256 /* no privilege for reset */
6b5151fd 1257 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
0b1587b1 1258 "3150 No privilege to perform the requested "
6b5151fd 1259 "access: x%x\n", reg_val);
026abb87
JS
1260 } else if (rc == -EIO) {
1261 /* reset failed, there is nothing more we can do */
6b5151fd
JS
1262 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1263 "3153 Fail to perform the requested "
1264 "access: x%x\n", reg_val);
f7a919b4 1265 return rc;
026abb87
JS
1266 }
1267
1268 /* keep the original port state */
1269 if (before_fc_flag & FC_OFFLINE_MODE)
1270 goto out;
c0c11512
JS
1271
1272 init_completion(&online_compl);
026abb87
JS
1273 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1274 LPFC_EVT_ONLINE);
1275 if (!job_posted)
1276 goto out;
c0c11512
JS
1277
1278 wait_for_completion(&online_compl);
1279
026abb87
JS
1280out:
1281 /* in any case, restore the virtual functions enabled as before */
1282 if (sriov_nr_virtfn) {
1283 sriov_err =
1284 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1285 if (!sriov_err)
1286 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1287 }
c0c11512 1288
026abb87
JS
1289 /* return proper error code */
1290 if (!rc) {
1291 if (!job_posted)
1292 rc = -ENOMEM;
1293 else if (status)
1294 rc = -EIO;
1295 }
1296 return rc;
c0c11512
JS
1297}
1298
e59058c4 1299/**
3621a710 1300 * lpfc_nport_evt_cnt_show - Return the number of nport events
e59058c4
JS
1301 * @dev: class device that is converted into a Scsi_host.
1302 * @attr: device attribute, not used.
1303 * @buf: on return contains the ascii number of nport events.
1304 *
1305 * Returns: size of formatted string.
1306 **/
dea3101e 1307static ssize_t
ee959b00
TJ
1308lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1309 char *buf)
dea3101e 1310{
ee959b00 1311 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
1312 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1313 struct lpfc_hba *phba = vport->phba;
1314
dea3101e
JB
1315 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1316}
1317
e59058c4 1318/**
3621a710 1319 * lpfc_board_mode_show - Return the state of the board
e59058c4
JS
1320 * @dev: class device that is converted into a Scsi_host.
1321 * @attr: device attribute, not used.
1322 * @buf: on return contains the state of the adapter.
1323 *
1324 * Returns: size of formatted string.
1325 **/
41415862 1326static ssize_t
ee959b00
TJ
1327lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1328 char *buf)
41415862 1329{
ee959b00 1330 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
1331 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1332 struct lpfc_hba *phba = vport->phba;
41415862
JW
1333 char * state;
1334
2e0fef85 1335 if (phba->link_state == LPFC_HBA_ERROR)
41415862 1336 state = "error";
2e0fef85 1337 else if (phba->link_state == LPFC_WARM_START)
41415862 1338 state = "warm start";
2e0fef85 1339 else if (phba->link_state == LPFC_INIT_START)
41415862
JW
1340 state = "offline";
1341 else
1342 state = "online";
1343
1344 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1345}
1346
e59058c4 1347/**
3621a710 1348 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
e59058c4
JS
1349 * @dev: class device that is converted into a Scsi_host.
1350 * @attr: device attribute, not used.
1351 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1352 * @count: unused variable.
1353 *
1354 * Returns:
1355 * -EACCES if enable hba reset not enabled
1356 * -EINVAL if the buffer does not contain a valid string (see above)
1357 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1358 * buf length greater than zero indicates success
1359 **/
41415862 1360static ssize_t
ee959b00
TJ
1361lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1362 const char *buf, size_t count)
41415862 1363{
ee959b00 1364 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
1365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1366 struct lpfc_hba *phba = vport->phba;
41415862 1367 struct completion online_compl;
026abb87
JS
1368 char *board_mode_str = NULL;
1369 int status = 0;
fedd3b7b 1370 int rc;
41415862 1371
026abb87
JS
1372 if (!phba->cfg_enable_hba_reset) {
1373 status = -EACCES;
1374 goto board_mode_out;
1375 }
88a2cfbb
JS
1376
1377 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
026abb87 1378 "3050 lpfc_board_mode set to %s\n", buf);
88a2cfbb 1379
41415862
JW
1380 init_completion(&online_compl);
1381
46fa311e 1382 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
fedd3b7b 1383 rc = lpfc_workq_post_event(phba, &status, &online_compl,
41415862 1384 LPFC_EVT_ONLINE);
026abb87
JS
1385 if (rc == 0) {
1386 status = -ENOMEM;
1387 goto board_mode_out;
1388 }
46fa311e 1389 wait_for_completion(&online_compl);
522dceeb
JS
1390 if (status)
1391 status = -EIO;
46fa311e
JS
1392 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1393 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
41415862 1394 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
6a9c52cf 1395 if (phba->sli_rev == LPFC_SLI_REV4)
026abb87 1396 status = -EINVAL;
6a9c52cf
JS
1397 else
1398 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
46fa311e 1399 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
6a9c52cf 1400 if (phba->sli_rev == LPFC_SLI_REV4)
026abb87 1401 status = -EINVAL;
6a9c52cf
JS
1402 else
1403 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
c0c11512 1404 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
52d52440
JS
1405 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1406 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1407 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1408 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1409 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
41415862 1410 else
026abb87 1411 status = -EINVAL;
41415862 1412
026abb87 1413board_mode_out:
41415862
JW
1414 if (!status)
1415 return strlen(buf);
026abb87
JS
1416 else {
1417 board_mode_str = strchr(buf, '\n');
1418 if (board_mode_str)
1419 *board_mode_str = '\0';
1420 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1421 "3097 Failed \"%s\", status(%d), "
1422 "fc_flag(x%x)\n",
1423 buf, status, phba->pport->fc_flag);
f7a919b4 1424 return status;
026abb87 1425 }
41415862
JW
1426}
1427
e59058c4 1428/**
3621a710 1429 * lpfc_get_hba_info - Return various bits of informaton about the adapter
e59058c4 1430 * @phba: pointer to the adapter structure.
3621a710
JS
1431 * @mxri: max xri count.
1432 * @axri: available xri count.
1433 * @mrpi: max rpi count.
1434 * @arpi: available rpi count.
1435 * @mvpi: max vpi count.
1436 * @avpi: available vpi count.
e59058c4
JS
1437 *
1438 * Description:
1439 * If an integer pointer for an count is not null then the value for the
1440 * count is returned.
1441 *
1442 * Returns:
1443 * zero on error
1444 * one for success
1445 **/
311464ec 1446static int
858c9f6c
JS
1447lpfc_get_hba_info(struct lpfc_hba *phba,
1448 uint32_t *mxri, uint32_t *axri,
1449 uint32_t *mrpi, uint32_t *arpi,
1450 uint32_t *mvpi, uint32_t *avpi)
92d7f7b0 1451{
04c68496 1452 struct lpfc_mbx_read_config *rd_config;
92d7f7b0
JS
1453 LPFC_MBOXQ_t *pmboxq;
1454 MAILBOX_t *pmb;
1455 int rc = 0;
15672319 1456 uint32_t max_vpi;
92d7f7b0
JS
1457
1458 /*
1459 * prevent udev from issuing mailbox commands until the port is
1460 * configured.
1461 */
1462 if (phba->link_state < LPFC_LINK_DOWN ||
1463 !phba->mbox_mem_pool ||
f4b4c68f 1464 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
92d7f7b0
JS
1465 return 0;
1466
1467 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1468 return 0;
1469
1470 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1471 if (!pmboxq)
1472 return 0;
1473 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1474
04c68496 1475 pmb = &pmboxq->u.mb;
92d7f7b0
JS
1476 pmb->mbxCommand = MBX_READ_CONFIG;
1477 pmb->mbxOwner = OWN_HOST;
1478 pmboxq->context1 = NULL;
1479
75baf696 1480 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
92d7f7b0
JS
1481 rc = MBX_NOT_FINISHED;
1482 else
1483 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1484
1485 if (rc != MBX_SUCCESS) {
858c9f6c 1486 if (rc != MBX_TIMEOUT)
92d7f7b0
JS
1487 mempool_free(pmboxq, phba->mbox_mem_pool);
1488 return 0;
1489 }
1490
da0436e9
JS
1491 if (phba->sli_rev == LPFC_SLI_REV4) {
1492 rd_config = &pmboxq->u.mqe.un.rd_config;
1493 if (mrpi)
1494 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1495 if (arpi)
1496 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1497 phba->sli4_hba.max_cfg_param.rpi_used;
1498 if (mxri)
1499 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1500 if (axri)
1501 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1502 phba->sli4_hba.max_cfg_param.xri_used;
15672319
JS
1503
1504 /* Account for differences with SLI-3. Get vpi count from
1505 * mailbox data and subtract one for max vpi value.
1506 */
1507 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1508 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1509
da0436e9 1510 if (mvpi)
15672319 1511 *mvpi = max_vpi;
da0436e9 1512 if (avpi)
15672319 1513 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
da0436e9
JS
1514 } else {
1515 if (mrpi)
1516 *mrpi = pmb->un.varRdConfig.max_rpi;
1517 if (arpi)
1518 *arpi = pmb->un.varRdConfig.avail_rpi;
1519 if (mxri)
1520 *mxri = pmb->un.varRdConfig.max_xri;
1521 if (axri)
1522 *axri = pmb->un.varRdConfig.avail_xri;
1523 if (mvpi)
1524 *mvpi = pmb->un.varRdConfig.max_vpi;
1525 if (avpi)
1526 *avpi = pmb->un.varRdConfig.avail_vpi;
1527 }
92d7f7b0
JS
1528
1529 mempool_free(pmboxq, phba->mbox_mem_pool);
1530 return 1;
1531}
1532
e59058c4 1533/**
3621a710 1534 * lpfc_max_rpi_show - Return maximum rpi
e59058c4
JS
1535 * @dev: class device that is converted into a Scsi_host.
1536 * @attr: device attribute, not used.
1537 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1538 *
1539 * Description:
1540 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1541 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1542 * to "Unknown" and the buffer length is returned, therefore the caller
1543 * must check for "Unknown" in the buffer to detect a failure.
1544 *
1545 * Returns: size of formatted string.
1546 **/
92d7f7b0 1547static ssize_t
ee959b00
TJ
1548lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1549 char *buf)
92d7f7b0 1550{
ee959b00 1551 struct Scsi_Host *shost = class_to_shost(dev);
92d7f7b0
JS
1552 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1553 struct lpfc_hba *phba = vport->phba;
1554 uint32_t cnt;
1555
858c9f6c 1556 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
92d7f7b0
JS
1557 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1558 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1559}
1560
e59058c4 1561/**
3621a710 1562 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
e59058c4
JS
1563 * @dev: class device that is converted into a Scsi_host.
1564 * @attr: device attribute, not used.
1565 * @buf: containing the used rpi count in decimal or "Unknown".
1566 *
1567 * Description:
1568 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1569 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1570 * to "Unknown" and the buffer length is returned, therefore the caller
1571 * must check for "Unknown" in the buffer to detect a failure.
1572 *
1573 * Returns: size of formatted string.
1574 **/
92d7f7b0 1575static ssize_t
ee959b00
TJ
1576lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1577 char *buf)
92d7f7b0 1578{
ee959b00 1579 struct Scsi_Host *shost = class_to_shost(dev);
92d7f7b0
JS
1580 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1581 struct lpfc_hba *phba = vport->phba;
1582 uint32_t cnt, acnt;
1583
858c9f6c 1584 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
92d7f7b0
JS
1585 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1586 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1587}
1588
e59058c4 1589/**
3621a710 1590 * lpfc_max_xri_show - Return maximum xri
e59058c4
JS
1591 * @dev: class device that is converted into a Scsi_host.
1592 * @attr: device attribute, not used.
1593 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1594 *
1595 * Description:
1596 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1597 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1598 * to "Unknown" and the buffer length is returned, therefore the caller
1599 * must check for "Unknown" in the buffer to detect a failure.
1600 *
1601 * Returns: size of formatted string.
1602 **/
92d7f7b0 1603static ssize_t
ee959b00
TJ
1604lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1605 char *buf)
92d7f7b0 1606{
ee959b00 1607 struct Scsi_Host *shost = class_to_shost(dev);
92d7f7b0
JS
1608 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1609 struct lpfc_hba *phba = vport->phba;
1610 uint32_t cnt;
1611
858c9f6c 1612 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
92d7f7b0
JS
1613 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1614 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1615}
1616
e59058c4 1617/**
3621a710 1618 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
e59058c4
JS
1619 * @dev: class device that is converted into a Scsi_host.
1620 * @attr: device attribute, not used.
1621 * @buf: on return contains the used xri count in decimal or "Unknown".
1622 *
1623 * Description:
1624 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1625 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1626 * to "Unknown" and the buffer length is returned, therefore the caller
1627 * must check for "Unknown" in the buffer to detect a failure.
1628 *
1629 * Returns: size of formatted string.
1630 **/
92d7f7b0 1631static ssize_t
ee959b00
TJ
1632lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1633 char *buf)
92d7f7b0 1634{
ee959b00 1635 struct Scsi_Host *shost = class_to_shost(dev);
92d7f7b0
JS
1636 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1637 struct lpfc_hba *phba = vport->phba;
1638 uint32_t cnt, acnt;
1639
858c9f6c
JS
1640 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1641 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1642 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1643}
1644
e59058c4 1645/**
3621a710 1646 * lpfc_max_vpi_show - Return maximum vpi
e59058c4
JS
1647 * @dev: class device that is converted into a Scsi_host.
1648 * @attr: device attribute, not used.
1649 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1650 *
1651 * Description:
1652 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1653 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1654 * to "Unknown" and the buffer length is returned, therefore the caller
1655 * must check for "Unknown" in the buffer to detect a failure.
1656 *
1657 * Returns: size of formatted string.
1658 **/
858c9f6c 1659static ssize_t
ee959b00
TJ
1660lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1661 char *buf)
858c9f6c 1662{
ee959b00 1663 struct Scsi_Host *shost = class_to_shost(dev);
858c9f6c
JS
1664 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1665 struct lpfc_hba *phba = vport->phba;
1666 uint32_t cnt;
1667
1668 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1669 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1670 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1671}
1672
e59058c4 1673/**
3621a710 1674 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
e59058c4
JS
1675 * @dev: class device that is converted into a Scsi_host.
1676 * @attr: device attribute, not used.
1677 * @buf: on return contains the used vpi count in decimal or "Unknown".
1678 *
1679 * Description:
1680 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1681 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1682 * to "Unknown" and the buffer length is returned, therefore the caller
1683 * must check for "Unknown" in the buffer to detect a failure.
1684 *
1685 * Returns: size of formatted string.
1686 **/
858c9f6c 1687static ssize_t
ee959b00
TJ
1688lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1689 char *buf)
858c9f6c 1690{
ee959b00 1691 struct Scsi_Host *shost = class_to_shost(dev);
858c9f6c
JS
1692 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1693 struct lpfc_hba *phba = vport->phba;
1694 uint32_t cnt, acnt;
1695
1696 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
92d7f7b0
JS
1697 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1698 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1699}
1700
e59058c4 1701/**
3621a710 1702 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
e59058c4
JS
1703 * @dev: class device that is converted into a Scsi_host.
1704 * @attr: device attribute, not used.
1705 * @buf: text that must be interpreted to determine if npiv is supported.
1706 *
1707 * Description:
1708 * Buffer will contain text indicating npiv is not suppoerted on the port,
1709 * the port is an NPIV physical port, or it is an npiv virtual port with
1710 * the id of the vport.
1711 *
1712 * Returns: size of formatted string.
1713 **/
92d7f7b0 1714static ssize_t
ee959b00
TJ
1715lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1716 char *buf)
92d7f7b0 1717{
ee959b00 1718 struct Scsi_Host *shost = class_to_shost(dev);
92d7f7b0
JS
1719 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1720 struct lpfc_hba *phba = vport->phba;
1721
1722 if (!(phba->max_vpi))
1723 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1724 if (vport->port_type == LPFC_PHYSICAL_PORT)
1725 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1726 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1727}
1728
e59058c4 1729/**
3621a710 1730 * lpfc_poll_show - Return text about poll support for the adapter
e59058c4
JS
1731 * @dev: class device that is converted into a Scsi_host.
1732 * @attr: device attribute, not used.
1733 * @buf: on return contains the cfg_poll in hex.
1734 *
1735 * Notes:
1736 * cfg_poll should be a lpfc_polling_flags type.
1737 *
1738 * Returns: size of formatted string.
1739 **/
875fbdfe 1740static ssize_t
ee959b00
TJ
1741lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1742 char *buf)
875fbdfe 1743{
ee959b00 1744 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
1745 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1746 struct lpfc_hba *phba = vport->phba;
875fbdfe
JSEC
1747
1748 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1749}
1750
e59058c4 1751/**
3621a710 1752 * lpfc_poll_store - Set the value of cfg_poll for the adapter
e59058c4
JS
1753 * @dev: class device that is converted into a Scsi_host.
1754 * @attr: device attribute, not used.
1755 * @buf: one or more lpfc_polling_flags values.
1756 * @count: not used.
1757 *
1758 * Notes:
1759 * buf contents converted to integer and checked for a valid value.
1760 *
1761 * Returns:
1762 * -EINVAL if the buffer connot be converted or is out of range
1763 * length of the buf on success
1764 **/
875fbdfe 1765static ssize_t
ee959b00
TJ
1766lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1767 const char *buf, size_t count)
875fbdfe 1768{
ee959b00 1769 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
1770 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1771 struct lpfc_hba *phba = vport->phba;
875fbdfe
JSEC
1772 uint32_t creg_val;
1773 uint32_t old_val;
1774 int val=0;
1775
1776 if (!isdigit(buf[0]))
1777 return -EINVAL;
1778
1779 if (sscanf(buf, "%i", &val) != 1)
1780 return -EINVAL;
1781
1782 if ((val & 0x3) != val)
1783 return -EINVAL;
1784
45ed1190
JS
1785 if (phba->sli_rev == LPFC_SLI_REV4)
1786 val = 0;
1787
88a2cfbb
JS
1788 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1789 "3051 lpfc_poll changed from %d to %d\n",
1790 phba->cfg_poll, val);
1791
2e0fef85 1792 spin_lock_irq(&phba->hbalock);
875fbdfe
JSEC
1793
1794 old_val = phba->cfg_poll;
1795
1796 if (val & ENABLE_FCP_RING_POLLING) {
1797 if ((val & DISABLE_FCP_RING_INT) &&
1798 !(old_val & DISABLE_FCP_RING_INT)) {
9940b97b
JS
1799 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1800 spin_unlock_irq(&phba->hbalock);
1801 return -EINVAL;
1802 }
875fbdfe
JSEC
1803 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1804 writel(creg_val, phba->HCregaddr);
1805 readl(phba->HCregaddr); /* flush */
1806
1807 lpfc_poll_start_timer(phba);
1808 }
1809 } else if (val != 0x0) {
2e0fef85 1810 spin_unlock_irq(&phba->hbalock);
875fbdfe
JSEC
1811 return -EINVAL;
1812 }
1813
1814 if (!(val & DISABLE_FCP_RING_INT) &&
1815 (old_val & DISABLE_FCP_RING_INT))
1816 {
2e0fef85 1817 spin_unlock_irq(&phba->hbalock);
875fbdfe 1818 del_timer(&phba->fcp_poll_timer);
2e0fef85 1819 spin_lock_irq(&phba->hbalock);
9940b97b
JS
1820 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1821 spin_unlock_irq(&phba->hbalock);
1822 return -EINVAL;
1823 }
875fbdfe
JSEC
1824 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1825 writel(creg_val, phba->HCregaddr);
1826 readl(phba->HCregaddr); /* flush */
1827 }
1828
1829 phba->cfg_poll = val;
1830
2e0fef85 1831 spin_unlock_irq(&phba->hbalock);
875fbdfe
JSEC
1832
1833 return strlen(buf);
1834}
dea3101e 1835
bc73905a
JS
1836/**
1837 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1838 * @dev: class unused variable.
1839 * @attr: device attribute, not used.
1840 * @buf: on return contains the module description text.
1841 *
1842 * Returns: size of formatted string.
1843 **/
1844static ssize_t
1845lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1846 char *buf)
1847{
1848 struct Scsi_Host *shost = class_to_shost(dev);
1849 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1850 struct lpfc_hba *phba = vport->phba;
1851
1852 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1853}
1854
1855/**
1856 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1857 * @dev: class unused variable.
1858 * @attr: device attribute, not used.
1859 * @buf: on return contains the module description text.
1860 *
1861 * Returns: size of formatted string.
1862 **/
1863static ssize_t
1864lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1865 char *buf)
1866{
1867 struct Scsi_Host *shost = class_to_shost(dev);
1868 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1869 struct lpfc_hba *phba = vport->phba;
1870
1871 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1872}
1873
ab56dc2e
JS
1874/**
1875 * lpfc_dss_show - Return the current state of dss and the configured state
1876 * @dev: class converted to a Scsi_host structure.
1877 * @attr: device attribute, not used.
1878 * @buf: on return contains the formatted text.
1879 *
1880 * Returns: size of formatted string.
1881 **/
1882static ssize_t
1883lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1884 char *buf)
1885{
1886 struct Scsi_Host *shost = class_to_shost(dev);
1887 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1888 struct lpfc_hba *phba = vport->phba;
1889
1890 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1891 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1892 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1893 "" : "Not ");
1894}
1895
912e3acd
JS
1896/**
1897 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1898 * @dev: class converted to a Scsi_host structure.
1899 * @attr: device attribute, not used.
1900 * @buf: on return contains the formatted support level.
1901 *
1902 * Description:
1903 * Returns the maximum number of virtual functions a physical function can
1904 * support, 0 will be returned if called on virtual function.
1905 *
1906 * Returns: size of formatted string.
1907 **/
1908static ssize_t
1909lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1910 struct device_attribute *attr,
1911 char *buf)
1912{
1913 struct Scsi_Host *shost = class_to_shost(dev);
1914 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1915 struct lpfc_hba *phba = vport->phba;
0a96e975 1916 uint16_t max_nr_virtfn;
912e3acd 1917
0a96e975
JS
1918 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1919 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
912e3acd
JS
1920}
1921
de8c36bb
AB
1922static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1923{
1924 return val >= min && val <= max;
1925}
1926
44fd7fe3
JS
1927/**
1928 * lpfc_enable_bbcr_set: Sets an attribute value.
1929 * @phba: pointer the the adapter structure.
1930 * @val: integer attribute value.
1931 *
1932 * Description:
1933 * Validates the min and max values then sets the
1934 * adapter config field if in the valid range. prints error message
1935 * and does not set the parameter if invalid.
1936 *
1937 * Returns:
1938 * zero on success
1939 * -EINVAL if val is invalid
1940 */
1941static ssize_t
1942lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
1943{
1944 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
1945 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1946 "3068 %s_enable_bbcr changed from %d to %d\n",
1947 LPFC_DRIVER_NAME, phba->cfg_enable_bbcr, val);
1948 phba->cfg_enable_bbcr = val;
1949 return 0;
1950 }
1951 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1952 "0451 %s_enable_bbcr cannot set to %d, range is 0, 1\n",
1953 LPFC_DRIVER_NAME, val);
1954 return -EINVAL;
1955}
1956
e59058c4 1957/**
3621a710 1958 * lpfc_param_show - Return a cfg attribute value in decimal
e59058c4
JS
1959 *
1960 * Description:
1961 * Macro that given an attr e.g. hba_queue_depth expands
1962 * into a function with the name lpfc_hba_queue_depth_show.
1963 *
1964 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1965 * @dev: class device that is converted into a Scsi_host.
1966 * @attr: device attribute, not used.
1967 * @buf: on return contains the attribute value in decimal.
1968 *
1969 * Returns: size of formatted string.
1970 **/
dea3101e
JB
1971#define lpfc_param_show(attr) \
1972static ssize_t \
ee959b00
TJ
1973lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1974 char *buf) \
dea3101e 1975{ \
ee959b00 1976 struct Scsi_Host *shost = class_to_shost(dev);\
2e0fef85
JS
1977 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1978 struct lpfc_hba *phba = vport->phba;\
7bcbb752
JSEC
1979 return snprintf(buf, PAGE_SIZE, "%d\n",\
1980 phba->cfg_##attr);\
1981}
1982
e59058c4 1983/**
3621a710 1984 * lpfc_param_hex_show - Return a cfg attribute value in hex
e59058c4
JS
1985 *
1986 * Description:
1987 * Macro that given an attr e.g. hba_queue_depth expands
1988 * into a function with the name lpfc_hba_queue_depth_show
1989 *
1990 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1991 * @dev: class device that is converted into a Scsi_host.
1992 * @attr: device attribute, not used.
3621a710 1993 * @buf: on return contains the attribute value in hexadecimal.
e59058c4
JS
1994 *
1995 * Returns: size of formatted string.
1996 **/
93a20f74
JSEC
1997#define lpfc_param_hex_show(attr) \
1998static ssize_t \
ee959b00
TJ
1999lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2000 char *buf) \
93a20f74 2001{ \
ee959b00 2002 struct Scsi_Host *shost = class_to_shost(dev);\
2e0fef85
JS
2003 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2004 struct lpfc_hba *phba = vport->phba;\
84d1b006 2005 uint val = 0;\
93a20f74
JSEC
2006 val = phba->cfg_##attr;\
2007 return snprintf(buf, PAGE_SIZE, "%#x\n",\
2008 phba->cfg_##attr);\
2009}
2010
e59058c4 2011/**
b595076a 2012 * lpfc_param_init - Initializes a cfg attribute
e59058c4
JS
2013 *
2014 * Description:
2015 * Macro that given an attr e.g. hba_queue_depth expands
2016 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2017 * takes a default argument, a minimum and maximum argument.
2018 *
2019 * lpfc_##attr##_init: Initializes an attribute.
2020 * @phba: pointer the the adapter structure.
2021 * @val: integer attribute value.
2022 *
2023 * Validates the min and max values then sets the adapter config field
2024 * accordingly, or uses the default if out of range and prints an error message.
2025 *
2026 * Returns:
2027 * zero on success
2028 * -EINVAL if default used
2029 **/
7bcbb752
JSEC
2030#define lpfc_param_init(attr, default, minval, maxval) \
2031static int \
84d1b006 2032lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
7bcbb752 2033{ \
de8c36bb 2034 if (lpfc_rangecheck(val, minval, maxval)) {\
7bcbb752
JSEC
2035 phba->cfg_##attr = val;\
2036 return 0;\
dea3101e 2037 }\
7bcbb752 2038 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
e8b62011
JS
2039 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2040 "allowed range is ["#minval", "#maxval"]\n", val); \
7bcbb752
JSEC
2041 phba->cfg_##attr = default;\
2042 return -EINVAL;\
dea3101e
JB
2043}
2044
e59058c4 2045/**
3621a710 2046 * lpfc_param_set - Set a cfg attribute value
e59058c4
JS
2047 *
2048 * Description:
2049 * Macro that given an attr e.g. hba_queue_depth expands
2050 * into a function with the name lpfc_hba_queue_depth_set
2051 *
2052 * lpfc_##attr##_set: Sets an attribute value.
2053 * @phba: pointer the the adapter structure.
2054 * @val: integer attribute value.
2055 *
2056 * Description:
2057 * Validates the min and max values then sets the
2058 * adapter config field if in the valid range. prints error message
2059 * and does not set the parameter if invalid.
2060 *
2061 * Returns:
2062 * zero on success
2063 * -EINVAL if val is invalid
2064 **/
7bcbb752
JSEC
2065#define lpfc_param_set(attr, default, minval, maxval) \
2066static int \
84d1b006 2067lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
7bcbb752 2068{ \
de8c36bb 2069 if (lpfc_rangecheck(val, minval, maxval)) {\
88a2cfbb
JS
2070 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2071 "3052 lpfc_" #attr " changed from %d to %d\n", \
2072 phba->cfg_##attr, val); \
7bcbb752
JSEC
2073 phba->cfg_##attr = val;\
2074 return 0;\
2075 }\
2076 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
e8b62011
JS
2077 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2078 "allowed range is ["#minval", "#maxval"]\n", val); \
7bcbb752
JSEC
2079 return -EINVAL;\
2080}
2081
e59058c4 2082/**
3621a710 2083 * lpfc_param_store - Set a vport attribute value
e59058c4
JS
2084 *
2085 * Description:
2086 * Macro that given an attr e.g. hba_queue_depth expands
2087 * into a function with the name lpfc_hba_queue_depth_store.
2088 *
2089 * lpfc_##attr##_store: Set an sttribute value.
2090 * @dev: class device that is converted into a Scsi_host.
2091 * @attr: device attribute, not used.
2092 * @buf: contains the attribute value in ascii.
2093 * @count: not used.
2094 *
2095 * Description:
2096 * Convert the ascii text number to an integer, then
2097 * use the lpfc_##attr##_set function to set the value.
2098 *
2099 * Returns:
2100 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2101 * length of buffer upon success.
2102 **/
7bcbb752 2103#define lpfc_param_store(attr) \
dea3101e 2104static ssize_t \
ee959b00
TJ
2105lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2106 const char *buf, size_t count) \
dea3101e 2107{ \
ee959b00 2108 struct Scsi_Host *shost = class_to_shost(dev);\
2e0fef85
JS
2109 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2110 struct lpfc_hba *phba = vport->phba;\
84d1b006 2111 uint val = 0;\
93a20f74
JSEC
2112 if (!isdigit(buf[0]))\
2113 return -EINVAL;\
2114 if (sscanf(buf, "%i", &val) != 1)\
2115 return -EINVAL;\
7bcbb752 2116 if (lpfc_##attr##_set(phba, val) == 0) \
755c0d06 2117 return strlen(buf);\
7bcbb752
JSEC
2118 else \
2119 return -EINVAL;\
dea3101e
JB
2120}
2121
e59058c4 2122/**
3621a710 2123 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
e59058c4
JS
2124 *
2125 * Description:
2126 * Macro that given an attr e.g. hba_queue_depth expands
2127 * into a function with the name lpfc_hba_queue_depth_show
2128 *
2129 * lpfc_##attr##_show: prints the attribute value in decimal.
2130 * @dev: class device that is converted into a Scsi_host.
2131 * @attr: device attribute, not used.
2132 * @buf: on return contains the attribute value in decimal.
2133 *
2134 * Returns: length of formatted string.
2135 **/
3de2a653
JS
2136#define lpfc_vport_param_show(attr) \
2137static ssize_t \
ee959b00
TJ
2138lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2139 char *buf) \
3de2a653 2140{ \
ee959b00 2141 struct Scsi_Host *shost = class_to_shost(dev);\
3de2a653 2142 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
3de2a653
JS
2143 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2144}
2145
e59058c4 2146/**
3621a710 2147 * lpfc_vport_param_hex_show - Return hex formatted attribute value
e59058c4
JS
2148 *
2149 * Description:
2150 * Macro that given an attr e.g.
2151 * hba_queue_depth expands into a function with the name
2152 * lpfc_hba_queue_depth_show
2153 *
3621a710 2154 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
e59058c4
JS
2155 * @dev: class device that is converted into a Scsi_host.
2156 * @attr: device attribute, not used.
3621a710 2157 * @buf: on return contains the attribute value in hexadecimal.
e59058c4
JS
2158 *
2159 * Returns: length of formatted string.
2160 **/
3de2a653
JS
2161#define lpfc_vport_param_hex_show(attr) \
2162static ssize_t \
ee959b00
TJ
2163lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2164 char *buf) \
3de2a653 2165{ \
ee959b00 2166 struct Scsi_Host *shost = class_to_shost(dev);\
3de2a653 2167 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
3de2a653
JS
2168 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2169}
2170
e59058c4 2171/**
3621a710 2172 * lpfc_vport_param_init - Initialize a vport cfg attribute
e59058c4
JS
2173 *
2174 * Description:
2175 * Macro that given an attr e.g. hba_queue_depth expands
2176 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2177 * takes a default argument, a minimum and maximum argument.
2178 *
2179 * lpfc_##attr##_init: validates the min and max values then sets the
2180 * adapter config field accordingly, or uses the default if out of range
2181 * and prints an error message.
2182 * @phba: pointer the the adapter structure.
2183 * @val: integer attribute value.
2184 *
2185 * Returns:
2186 * zero on success
2187 * -EINVAL if default used
2188 **/
3de2a653
JS
2189#define lpfc_vport_param_init(attr, default, minval, maxval) \
2190static int \
84d1b006 2191lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
3de2a653 2192{ \
de8c36bb 2193 if (lpfc_rangecheck(val, minval, maxval)) {\
3de2a653
JS
2194 vport->cfg_##attr = val;\
2195 return 0;\
2196 }\
e8b62011 2197 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
d7c255b2 2198 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
e8b62011 2199 "allowed range is ["#minval", "#maxval"]\n", val); \
3de2a653
JS
2200 vport->cfg_##attr = default;\
2201 return -EINVAL;\
2202}
2203
e59058c4 2204/**
3621a710 2205 * lpfc_vport_param_set - Set a vport cfg attribute
e59058c4
JS
2206 *
2207 * Description:
2208 * Macro that given an attr e.g. hba_queue_depth expands
2209 * into a function with the name lpfc_hba_queue_depth_set
2210 *
2211 * lpfc_##attr##_set: validates the min and max values then sets the
2212 * adapter config field if in the valid range. prints error message
2213 * and does not set the parameter if invalid.
2214 * @phba: pointer the the adapter structure.
2215 * @val: integer attribute value.
2216 *
2217 * Returns:
2218 * zero on success
2219 * -EINVAL if val is invalid
2220 **/
3de2a653
JS
2221#define lpfc_vport_param_set(attr, default, minval, maxval) \
2222static int \
84d1b006 2223lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
3de2a653 2224{ \
de8c36bb 2225 if (lpfc_rangecheck(val, minval, maxval)) {\
88a2cfbb 2226 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
14660f4f
JS
2227 "3053 lpfc_" #attr \
2228 " changed from %d (x%x) to %d (x%x)\n", \
2229 vport->cfg_##attr, vport->cfg_##attr, \
2230 val, val); \
3de2a653
JS
2231 vport->cfg_##attr = val;\
2232 return 0;\
2233 }\
e8b62011 2234 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
d7c255b2 2235 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
e8b62011 2236 "allowed range is ["#minval", "#maxval"]\n", val); \
3de2a653
JS
2237 return -EINVAL;\
2238}
2239
e59058c4 2240/**
3621a710 2241 * lpfc_vport_param_store - Set a vport attribute
e59058c4
JS
2242 *
2243 * Description:
2244 * Macro that given an attr e.g. hba_queue_depth
2245 * expands into a function with the name lpfc_hba_queue_depth_store
2246 *
2247 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2248 * use the lpfc_##attr##_set function to set the value.
2249 * @cdev: class device that is converted into a Scsi_host.
2250 * @buf: contains the attribute value in decimal.
2251 * @count: not used.
2252 *
2253 * Returns:
2254 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2255 * length of buffer upon success.
2256 **/
3de2a653
JS
2257#define lpfc_vport_param_store(attr) \
2258static ssize_t \
ee959b00
TJ
2259lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2260 const char *buf, size_t count) \
3de2a653 2261{ \
ee959b00 2262 struct Scsi_Host *shost = class_to_shost(dev);\
3de2a653 2263 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
84d1b006 2264 uint val = 0;\
3de2a653
JS
2265 if (!isdigit(buf[0]))\
2266 return -EINVAL;\
2267 if (sscanf(buf, "%i", &val) != 1)\
2268 return -EINVAL;\
2269 if (lpfc_##attr##_set(vport, val) == 0) \
2270 return strlen(buf);\
2271 else \
2272 return -EINVAL;\
2273}
2274
2275
895427bd 2276static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
81301a9b
JS
2277static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2278static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2279static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2280static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
ee959b00
TJ
2281static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2282static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2283static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2284static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2285static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2286static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2287static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2288static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
84d1b006
JS
2289static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2290 lpfc_link_state_store);
ee959b00
TJ
2291static DEVICE_ATTR(option_rom_version, S_IRUGO,
2292 lpfc_option_rom_version_show, NULL);
2293static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2294 lpfc_num_discovered_ports_show, NULL);
84774a4d 2295static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
ee959b00
TJ
2296static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2297static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
45ed1190 2298static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
ee959b00
TJ
2299static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2300 lpfc_board_mode_show, lpfc_board_mode_store);
2301static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2302static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2303static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2304static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2305static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2306static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2307static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2308static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2309static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
bc73905a
JS
2310static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2311static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
ab56dc2e 2312static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
912e3acd
JS
2313static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2314 lpfc_sriov_hw_max_virtfn_show, NULL);
026abb87 2315static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
1ba981fd
JS
2316static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2317 NULL);
c3f28afa 2318
352e5fd1 2319static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1ba981fd
JS
2320#define WWN_SZ 8
2321/**
2322 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2323 * @buf: WWN string.
2324 * @cnt: Length of string.
2325 * @wwn: Array to receive converted wwn value.
2326 *
2327 * Returns:
2328 * -EINVAL if the buffer does not contain a valid wwn
2329 * 0 success
2330 **/
2331static size_t
2332lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2333{
2334 unsigned int i, j;
2335
2336 /* Count may include a LF at end of string */
2337 if (buf[cnt-1] == '\n')
2338 cnt--;
c3f28afa 2339
1ba981fd
JS
2340 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2341 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2342 return -EINVAL;
2343
2344 memset(wwn, 0, WWN_SZ);
2345
2346 /* Validate and store the new name */
2347 for (i = 0, j = 0; i < 16; i++) {
2348 if ((*buf >= 'a') && (*buf <= 'f'))
2349 j = ((j << 4) | ((*buf++ - 'a') + 10));
2350 else if ((*buf >= 'A') && (*buf <= 'F'))
2351 j = ((j << 4) | ((*buf++ - 'A') + 10));
2352 else if ((*buf >= '0') && (*buf <= '9'))
2353 j = ((j << 4) | (*buf++ - '0'));
2354 else
2355 return -EINVAL;
2356 if (i % 2) {
2357 wwn[i/2] = j & 0xff;
2358 j = 0;
2359 }
2360 }
2361 return 0;
2362}
352e5fd1
JS
2363/**
2364 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2365 * @dev: class device that is converted into a Scsi_host.
2366 * @attr: device attribute, not used.
2367 * @buf: containing the string lpfc_soft_wwn_key.
2368 * @count: must be size of lpfc_soft_wwn_key.
2369 *
2370 * Returns:
2371 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2372 * length of buf indicates success
2373 **/
2374static ssize_t
2375lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2376 const char *buf, size_t count)
2377{
2378 struct Scsi_Host *shost = class_to_shost(dev);
2379 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2380 struct lpfc_hba *phba = vport->phba;
2381 unsigned int cnt = count;
aeb3c817
JS
2382 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2383 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
352e5fd1
JS
2384
2385 /*
2386 * We're doing a simple sanity check for soft_wwpn setting.
2387 * We require that the user write a specific key to enable
2388 * the soft_wwpn attribute to be settable. Once the attribute
2389 * is written, the enable key resets. If further updates are
2390 * desired, the key must be written again to re-enable the
2391 * attribute.
2392 *
2393 * The "key" is not secret - it is a hardcoded string shown
2394 * here. The intent is to protect against the random user or
2395 * application that is just writing attributes.
2396 */
aeb3c817
JS
2397 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2398 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2399 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2400 " be enabled: fawwpn is enabled\n");
2401 return -EINVAL;
2402 }
352e5fd1
JS
2403
2404 /* count may include a LF at end of string */
2405 if (buf[cnt-1] == '\n')
2406 cnt--;
2407
2408 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2409 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2410 return -EINVAL;
2411
2412 phba->soft_wwn_enable = 1;
2413
2414 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2415 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2416 phba->brd_no);
2417 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2418 " The soft_wwpn feature is not supported by Broadcom.");
2419
2420 return count;
2421}
2422static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2423 lpfc_soft_wwn_enable_store);
2424
2425/**
2426 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2427 * @dev: class device that is converted into a Scsi_host.
2428 * @attr: device attribute, not used.
2429 * @buf: on return contains the wwpn in hexadecimal.
2430 *
2431 * Returns: size of formatted string.
2432 **/
2433static ssize_t
2434lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2435 char *buf)
2436{
2437 struct Scsi_Host *shost = class_to_shost(dev);
2438 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2439 struct lpfc_hba *phba = vport->phba;
2440
2441 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2442 (unsigned long long)phba->cfg_soft_wwpn);
2443}
2444
2445/**
2446 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2447 * @dev class device that is converted into a Scsi_host.
2448 * @attr: device attribute, not used.
2449 * @buf: contains the wwpn in hexadecimal.
2450 * @count: number of wwpn bytes in buf
2451 *
2452 * Returns:
2453 * -EACCES hba reset not enabled, adapter over temp
2454 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2455 * -EIO error taking adapter offline or online
2456 * value of count on success
2457 **/
2458static ssize_t
2459lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2460 const char *buf, size_t count)
2461{
2462 struct Scsi_Host *shost = class_to_shost(dev);
2463 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2464 struct lpfc_hba *phba = vport->phba;
2465 struct completion online_compl;
2466 int stat1 = 0, stat2 = 0;
2467 unsigned int cnt = count;
2468 u8 wwpn[WWN_SZ];
2469 int rc;
2470
2471 if (!phba->cfg_enable_hba_reset)
2472 return -EACCES;
2473 spin_lock_irq(&phba->hbalock);
2474 if (phba->over_temp_state == HBA_OVER_TEMP) {
2475 spin_unlock_irq(&phba->hbalock);
2476 return -EACCES;
2477 }
2478 spin_unlock_irq(&phba->hbalock);
2479 /* count may include a LF at end of string */
2480 if (buf[cnt-1] == '\n')
2481 cnt--;
2482
2483 if (!phba->soft_wwn_enable)
2484 return -EINVAL;
2485
2486 /* lock setting wwpn, wwnn down */
2487 phba->soft_wwn_enable = 0;
2488
2489 rc = lpfc_wwn_set(buf, cnt, wwpn);
e2934ed1 2490 if (rc) {
352e5fd1
JS
2491 /* not able to set wwpn, unlock it */
2492 phba->soft_wwn_enable = 1;
2493 return rc;
2494 }
2495
2496 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2497 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2498 if (phba->cfg_soft_wwnn)
2499 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2500
2501 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2502 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2503
2504 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2505 if (stat1)
2506 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2507 "0463 lpfc_soft_wwpn attribute set failed to "
2508 "reinit adapter - %d\n", stat1);
2509 init_completion(&online_compl);
2510 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2511 LPFC_EVT_ONLINE);
2512 if (rc == 0)
2513 return -ENOMEM;
2514
2515 wait_for_completion(&online_compl);
2516 if (stat2)
2517 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2518 "0464 lpfc_soft_wwpn attribute set failed to "
2519 "reinit adapter - %d\n", stat2);
2520 return (stat1 || stat2) ? -EIO : count;
2521}
69d725f4 2522static DEVICE_ATTR_RW(lpfc_soft_wwpn);
352e5fd1
JS
2523
2524/**
2525 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2526 * @dev: class device that is converted into a Scsi_host.
2527 * @attr: device attribute, not used.
2528 * @buf: on return contains the wwnn in hexadecimal.
2529 *
2530 * Returns: size of formatted string.
2531 **/
2532static ssize_t
2533lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2534 char *buf)
2535{
2536 struct Scsi_Host *shost = class_to_shost(dev);
2537 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2538 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2539 (unsigned long long)phba->cfg_soft_wwnn);
2540}
2541
2542/**
2543 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2544 * @cdev: class device that is converted into a Scsi_host.
2545 * @buf: contains the ww node name in hexadecimal.
2546 * @count: number of wwnn bytes in buf.
2547 *
2548 * Returns:
2549 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2550 * value of count on success
2551 **/
2552static ssize_t
2553lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2554 const char *buf, size_t count)
2555{
2556 struct Scsi_Host *shost = class_to_shost(dev);
2557 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2558 unsigned int cnt = count;
2559 u8 wwnn[WWN_SZ];
2560 int rc;
2561
2562 /* count may include a LF at end of string */
2563 if (buf[cnt-1] == '\n')
2564 cnt--;
2565
2566 if (!phba->soft_wwn_enable)
2567 return -EINVAL;
2568
2569 rc = lpfc_wwn_set(buf, cnt, wwnn);
e2934ed1 2570 if (rc) {
352e5fd1
JS
2571 /* Allow wwnn to be set many times, as long as the enable
2572 * is set. However, once the wwpn is set, everything locks.
2573 */
2574 return rc;
2575 }
2576
2577 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2578
2579 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2580 "lpfc%d: soft_wwnn set. Value will take effect upon "
2581 "setting of the soft_wwpn\n", phba->brd_no);
2582
2583 return count;
2584}
69d725f4 2585static DEVICE_ATTR_RW(lpfc_soft_wwnn);
a12e07bc 2586
1ba981fd
JS
2587/**
2588 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2589 * Optimized Access Storage (OAS) operations.
2590 * @dev: class device that is converted into a Scsi_host.
2591 * @attr: device attribute, not used.
2592 * @buf: buffer for passing information.
2593 *
2594 * Returns:
2595 * value of count
2596 **/
2597static ssize_t
2598lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2599 char *buf)
2600{
2601 struct Scsi_Host *shost = class_to_shost(dev);
2602 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2603
2604 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2605 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2606}
2607
2608/**
2609 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2610 * Optimized Access Storage (OAS) operations.
2611 * @dev: class device that is converted into a Scsi_host.
2612 * @attr: device attribute, not used.
2613 * @buf: buffer for passing information.
2614 * @count: Size of the data buffer.
2615 *
2616 * Returns:
2617 * -EINVAL count is invalid, invalid wwpn byte invalid
2618 * -EPERM oas is not supported by hba
2619 * value of count on success
2620 **/
2621static ssize_t
2622lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2623 const char *buf, size_t count)
2624{
2625 struct Scsi_Host *shost = class_to_shost(dev);
2626 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2627 unsigned int cnt = count;
2628 uint8_t wwpn[WWN_SZ];
2629 int rc;
2630
f38fa0bb 2631 if (!phba->cfg_fof)
1ba981fd
JS
2632 return -EPERM;
2633
2634 /* count may include a LF at end of string */
2635 if (buf[cnt-1] == '\n')
2636 cnt--;
2637
2638 rc = lpfc_wwn_set(buf, cnt, wwpn);
2639 if (rc)
2640 return rc;
2641
2642 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2643 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2644 if (wwn_to_u64(wwpn) == 0)
2645 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2646 else
2647 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2648 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2649 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2650 return count;
2651}
2652static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2653 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2654
c92c841c
JS
2655/**
2656 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2657 * Optimized Access Storage (OAS) operations.
2658 * @dev: class device that is converted into a Scsi_host.
2659 * @attr: device attribute, not used.
2660 * @buf: buffer for passing information.
2661 *
2662 * Returns:
2663 * value of count
2664 **/
2665static ssize_t
2666lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2667 char *buf)
2668{
2669 struct Scsi_Host *shost = class_to_shost(dev);
2670 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2671
2672 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2673}
2674
2675/**
2676 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2677 * Optimized Access Storage (OAS) operations.
2678 * @dev: class device that is converted into a Scsi_host.
2679 * @attr: device attribute, not used.
2680 * @buf: buffer for passing information.
2681 * @count: Size of the data buffer.
2682 *
2683 * Returns:
2684 * -EINVAL count is invalid, invalid wwpn byte invalid
2685 * -EPERM oas is not supported by hba
2686 * value of count on success
2687 **/
2688static ssize_t
2689lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2690 const char *buf, size_t count)
2691{
2692 struct Scsi_Host *shost = class_to_shost(dev);
2693 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2694 unsigned int cnt = count;
2695 unsigned long val;
2696 int ret;
2697
2698 if (!phba->cfg_fof)
2699 return -EPERM;
2700
2701 /* count may include a LF at end of string */
2702 if (buf[cnt-1] == '\n')
2703 cnt--;
2704
2705 ret = kstrtoul(buf, 0, &val);
2706 if (ret || (val > 0x7f))
2707 return -EINVAL;
2708
2709 if (val)
2710 phba->cfg_oas_priority = (uint8_t)val;
2711 else
2712 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2713 return count;
2714}
2715static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2716 lpfc_oas_priority_show, lpfc_oas_priority_store);
2717
1ba981fd
JS
2718/**
2719 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2720 * for Optimized Access Storage (OAS) operations.
2721 * @dev: class device that is converted into a Scsi_host.
2722 * @attr: device attribute, not used.
2723 * @buf: buffer for passing information.
2724 *
2725 * Returns:
2726 * value of count on success
2727 **/
2728static ssize_t
2729lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2730 char *buf)
2731{
2732 struct Scsi_Host *shost = class_to_shost(dev);
2733 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2734
2735 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2736 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2737}
2738
2739/**
2740 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2741 * for Optimized Access Storage (OAS) operations.
2742 * @dev: class device that is converted into a Scsi_host.
2743 * @attr: device attribute, not used.
2744 * @buf: buffer for passing information.
2745 * @count: Size of the data buffer.
2746 *
2747 * Returns:
2748 * -EINVAL count is invalid, invalid wwpn byte invalid
2749 * -EPERM oas is not supported by hba
2750 * value of count on success
2751 **/
2752static ssize_t
2753lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2754 const char *buf, size_t count)
2755{
2756 struct Scsi_Host *shost = class_to_shost(dev);
2757 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2758 unsigned int cnt = count;
2759 uint8_t wwpn[WWN_SZ];
2760 int rc;
2761
f38fa0bb 2762 if (!phba->cfg_fof)
1ba981fd
JS
2763 return -EPERM;
2764
2765 /* count may include a LF at end of string */
2766 if (buf[cnt-1] == '\n')
2767 cnt--;
2768
2769 rc = lpfc_wwn_set(buf, cnt, wwpn);
2770 if (rc)
2771 return rc;
2772
2773 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2774 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2775 if (wwn_to_u64(wwpn) == 0)
2776 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2777 else
2778 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2779 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
b5749fe1
JS
2780 if (phba->cfg_oas_priority == 0)
2781 phba->cfg_oas_priority = phba->cfg_XLanePriority;
1ba981fd
JS
2782 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2783 return count;
2784}
2785static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2786 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2787
2788/**
2789 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2790 * of whether luns will be enabled or disabled
2791 * for Optimized Access Storage (OAS) operations.
2792 * @dev: class device that is converted into a Scsi_host.
2793 * @attr: device attribute, not used.
2794 * @buf: buffer for passing information.
2795 *
2796 * Returns:
2797 * size of formatted string.
2798 **/
2799static ssize_t
2800lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2801 char *buf)
2802{
2803 struct Scsi_Host *shost = class_to_shost(dev);
2804 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2805
2806 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2807}
2808
2809/**
2810 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2811 * of whether luns will be enabled or disabled
2812 * for Optimized Access Storage (OAS) operations.
2813 * @dev: class device that is converted into a Scsi_host.
2814 * @attr: device attribute, not used.
2815 * @buf: buffer for passing information.
2816 * @count: Size of the data buffer.
2817 *
2818 * Returns:
2819 * -EINVAL count is invalid, invalid wwpn byte invalid
2820 * -EPERM oas is not supported by hba
2821 * value of count on success
2822 **/
2823static ssize_t
2824lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2825 const char *buf, size_t count)
2826{
2827 struct Scsi_Host *shost = class_to_shost(dev);
2828 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2829 int val = 0;
2830
f38fa0bb 2831 if (!phba->cfg_fof)
1ba981fd
JS
2832 return -EPERM;
2833
2834 if (!isdigit(buf[0]))
2835 return -EINVAL;
2836
2837 if (sscanf(buf, "%i", &val) != 1)
2838 return -EINVAL;
2839
2840 if ((val != 0) && (val != 1))
2841 return -EINVAL;
2842
2843 phba->cfg_oas_lun_state = val;
1ba981fd
JS
2844 return strlen(buf);
2845}
2846static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2847 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2848
2849/**
2850 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2851 * Storage (OAS) lun returned by the
2852 * lpfc_oas_lun_show function.
2853 * @dev: class device that is converted into a Scsi_host.
2854 * @attr: device attribute, not used.
2855 * @buf: buffer for passing information.
2856 *
2857 * Returns:
2858 * size of formatted string.
2859 **/
2860static ssize_t
2861lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2862 char *buf)
2863{
2864 struct Scsi_Host *shost = class_to_shost(dev);
2865 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2866
2867 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2868 return -EFAULT;
2869
2870 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2871}
2872static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2873 lpfc_oas_lun_status_show, NULL);
2874
2875
2876/**
2877 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2878 * (OAS) operations.
2879 * @phba: lpfc_hba pointer.
2880 * @ndlp: pointer to fcp target node.
2881 * @lun: the fc lun for setting oas state.
2882 * @oas_state: the oas state to be set to the lun.
2883 *
2884 * Returns:
2885 * SUCCESS : 0
2886 * -EPERM OAS is not enabled or not supported by this port.
2887 *
2888 */
2889static size_t
2890lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
c92c841c
JS
2891 uint8_t tgt_wwpn[], uint64_t lun,
2892 uint32_t oas_state, uint8_t pri)
1ba981fd
JS
2893{
2894
2895 int rc = 0;
2896
f38fa0bb 2897 if (!phba->cfg_fof)
1ba981fd
JS
2898 return -EPERM;
2899
2900 if (oas_state) {
2901 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
c92c841c
JS
2902 (struct lpfc_name *)tgt_wwpn,
2903 lun, pri))
1ba981fd
JS
2904 rc = -ENOMEM;
2905 } else {
2906 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
b5749fe1 2907 (struct lpfc_name *)tgt_wwpn, lun, pri);
1ba981fd
JS
2908 }
2909 return rc;
2910
2911}
2912
2913/**
2914 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2915 * Access Storage (OAS) operations.
2916 * @phba: lpfc_hba pointer.
2917 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2918 * @tgt_wwpn: wwpn of the target associated with the returned lun
2919 * @lun_status: status of the lun returned lun
2920 *
2921 * Returns the first or next lun enabled for OAS operations for the vport/target
2922 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2923 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2924 *
2925 * Return:
2926 * lun that is OAS enabled for the vport/target
2927 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2928 */
2929static uint64_t
2930lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
b5749fe1
JS
2931 uint8_t tgt_wwpn[], uint32_t *lun_status,
2932 uint32_t *lun_pri)
1ba981fd
JS
2933{
2934 uint64_t found_lun;
2935
2936 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2937 return NOT_OAS_ENABLED_LUN;
2938 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2939 phba->sli4_hba.oas_next_vpt_wwpn,
2940 (struct lpfc_name *)
2941 phba->sli4_hba.oas_next_tgt_wwpn,
2942 &phba->sli4_hba.oas_next_lun,
2943 (struct lpfc_name *)vpt_wwpn,
2944 (struct lpfc_name *)tgt_wwpn,
b5749fe1 2945 &found_lun, lun_status, lun_pri))
1ba981fd
JS
2946 return found_lun;
2947 else
2948 return NOT_OAS_ENABLED_LUN;
2949}
2950
2951/**
2952 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2953 * @phba: lpfc_hba pointer.
2954 * @vpt_wwpn: vport wwpn by reference.
2955 * @tgt_wwpn: target wwpn by reference.
2956 * @lun: the fc lun for setting oas state.
2957 * @oas_state: the oas state to be set to the oas_lun.
2958 *
2959 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2960 * a lun for OAS operations.
2961 *
2962 * Return:
2963 * SUCCESS: 0
2964 * -ENOMEM: failed to enable an lun for OAS operations
2965 * -EPERM: OAS is not enabled
2966 */
2967static ssize_t
2968lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2969 uint8_t tgt_wwpn[], uint64_t lun,
c92c841c 2970 uint32_t oas_state, uint8_t pri)
1ba981fd
JS
2971{
2972
2973 int rc;
2974
2975 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
c92c841c 2976 oas_state, pri);
1ba981fd
JS
2977 return rc;
2978}
2979
2980/**
2981 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2982 * @dev: class device that is converted into a Scsi_host.
2983 * @attr: device attribute, not used.
2984 * @buf: buffer for passing information.
2985 *
2986 * This routine returns a lun enabled for OAS each time the function
2987 * is called.
2988 *
2989 * Returns:
2990 * SUCCESS: size of formatted string.
2991 * -EFAULT: target or vport wwpn was not set properly.
2992 * -EPERM: oas is not enabled.
2993 **/
2994static ssize_t
2995lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2996 char *buf)
2997{
2998 struct Scsi_Host *shost = class_to_shost(dev);
2999 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3000
3001 uint64_t oas_lun;
3002 int len = 0;
3003
f38fa0bb 3004 if (!phba->cfg_fof)
1ba981fd
JS
3005 return -EPERM;
3006
3007 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3008 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3009 return -EFAULT;
3010
3011 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3012 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3013 return -EFAULT;
3014
3015 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3016 phba->cfg_oas_tgt_wwpn,
b5749fe1
JS
3017 &phba->cfg_oas_lun_status,
3018 &phba->cfg_oas_priority);
1ba981fd
JS
3019 if (oas_lun != NOT_OAS_ENABLED_LUN)
3020 phba->cfg_oas_flags |= OAS_LUN_VALID;
3021
3022 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3023
3024 return len;
3025}
3026
3027/**
3028 * lpfc_oas_lun_store - Sets the OAS state for lun
3029 * @dev: class device that is converted into a Scsi_host.
3030 * @attr: device attribute, not used.
3031 * @buf: buffer for passing information.
3032 *
3033 * This function sets the OAS state for lun. Before this function is called,
3034 * the vport wwpn, target wwpn, and oas state need to be set.
3035 *
3036 * Returns:
3037 * SUCCESS: size of formatted string.
3038 * -EFAULT: target or vport wwpn was not set properly.
3039 * -EPERM: oas is not enabled.
3040 * size of formatted string.
3041 **/
3042static ssize_t
3043lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3044 const char *buf, size_t count)
3045{
3046 struct Scsi_Host *shost = class_to_shost(dev);
3047 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3048 uint64_t scsi_lun;
b5749fe1 3049 uint32_t pri;
1ba981fd
JS
3050 ssize_t rc;
3051
f38fa0bb 3052 if (!phba->cfg_fof)
1ba981fd
JS
3053 return -EPERM;
3054
3055 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3056 return -EFAULT;
3057
3058 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3059 return -EFAULT;
3060
3061 if (!isdigit(buf[0]))
3062 return -EINVAL;
3063
3064 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3065 return -EINVAL;
3066
b5749fe1
JS
3067 pri = phba->cfg_oas_priority;
3068 if (pri == 0)
3069 pri = phba->cfg_XLanePriority;
3070
1ba981fd 3071 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
c92c841c
JS
3072 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3073 "priority 0x%x with oas state %d\n",
1ba981fd
JS
3074 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3075 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
b5749fe1 3076 pri, phba->cfg_oas_lun_state);
1ba981fd
JS
3077
3078 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
c92c841c 3079 phba->cfg_oas_tgt_wwpn, scsi_lun,
b5749fe1 3080 phba->cfg_oas_lun_state, pri);
1ba981fd
JS
3081 if (rc)
3082 return rc;
3083
3084 return count;
3085}
3086static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3087 lpfc_oas_lun_show, lpfc_oas_lun_store);
c3f28afa 3088
f358dd0c
JS
3089int lpfc_enable_nvmet_cnt;
3090unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3091 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3092 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3093module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3094MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3095
875fbdfe 3096static int lpfc_poll = 0;
ab56dc2e 3097module_param(lpfc_poll, int, S_IRUGO);
875fbdfe
JSEC
3098MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3099 " 0 - none,"
3100 " 1 - poll with interrupts enabled"
3101 " 3 - poll and disable FCP ring interrupts");
3102
69d725f4 3103static DEVICE_ATTR_RW(lpfc_poll);
dea3101e 3104
96418b5e
JS
3105int lpfc_no_hba_reset_cnt;
3106unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3107 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3108module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3109MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3110
12247e81
JS
3111LPFC_ATTR(sli_mode, 0, 0, 3,
3112 "SLI mode selector:"
3113 " 0 - auto (SLI-3 if supported),"
3114 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3115 " 3 - select SLI-3");
92d7f7b0 3116
458c083e
JS
3117LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3118 "Enable NPIV functionality");
92d7f7b0 3119
7d791df7
JS
3120LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3121 "FCF Fast failover=1 Priority failover=2");
3122
e5771b4d
JS
3123/*
3124# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3125# 0x0 = disabled, XRI/OXID use not tracked.
3126# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3127# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3128*/
31202b0e
JS
3129LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3130 "Enable RRQ functionality");
19ca7609 3131
84d1b006
JS
3132/*
3133# lpfc_suppress_link_up: Bring link up at initialization
3134# 0x0 = bring link up (issue MBX_INIT_LINK)
3135# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3136# 0x2 = never bring up link
3137# Default value is 0.
3138*/
e40a02c1
JS
3139LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3140 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3141 "Suppress Link Up at initialization");
2a9bf3d0
JS
3142/*
3143# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3144# 1 - (1024)
3145# 2 - (2048)
3146# 3 - (3072)
3147# 4 - (4096)
3148# 5 - (5120)
3149*/
3150static ssize_t
3151lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3152{
3153 struct Scsi_Host *shost = class_to_shost(dev);
3154 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3155
3156 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3157}
3158
3159static DEVICE_ATTR(iocb_hw, S_IRUGO,
3160 lpfc_iocb_hw_show, NULL);
3161static ssize_t
3162lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3163{
3164 struct Scsi_Host *shost = class_to_shost(dev);
3165 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
895427bd 3166 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
2a9bf3d0 3167
1234a6d5
DK
3168 return snprintf(buf, PAGE_SIZE, "%d\n",
3169 pring ? pring->txq_max : 0);
2a9bf3d0
JS
3170}
3171
3172static DEVICE_ATTR(txq_hw, S_IRUGO,
3173 lpfc_txq_hw_show, NULL);
3174static ssize_t
3175lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3176 char *buf)
3177{
3178 struct Scsi_Host *shost = class_to_shost(dev);
3179 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
895427bd 3180 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
2a9bf3d0 3181
1234a6d5
DK
3182 return snprintf(buf, PAGE_SIZE, "%d\n",
3183 pring ? pring->txcmplq_max : 0);
2a9bf3d0
JS
3184}
3185
3186static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3187 lpfc_txcmplq_hw_show, NULL);
3188
0d8c8ba3 3189LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
2a9bf3d0 3190 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
84d1b006 3191
c01f3208
JS
3192/*
3193# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3194# until the timer expires. Value range is [0,255]. Default value is 30.
3195*/
3196static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3197static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3198module_param(lpfc_nodev_tmo, int, 0);
3199MODULE_PARM_DESC(lpfc_nodev_tmo,
3200 "Seconds driver will hold I/O waiting "
3201 "for a device to come back");
e59058c4
JS
3202
3203/**
3621a710 3204 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
e59058c4
JS
3205 * @dev: class converted to a Scsi_host structure.
3206 * @attr: device attribute, not used.
3207 * @buf: on return contains the dev loss timeout in decimal.
3208 *
3209 * Returns: size of formatted string.
3210 **/
c01f3208 3211static ssize_t
ee959b00
TJ
3212lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3213 char *buf)
c01f3208 3214{
ee959b00 3215 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85 3216 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
e40a02c1 3217
3de2a653 3218 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
c01f3208
JS
3219}
3220
e59058c4 3221/**
3621a710 3222 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
e59058c4
JS
3223 * @vport: lpfc vport structure pointer.
3224 * @val: contains the nodev timeout value.
3225 *
3226 * Description:
3227 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3228 * a kernel error message is printed and zero is returned.
3229 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3230 * Otherwise nodev tmo is set to the default value.
3231 *
3232 * Returns:
3233 * zero if already set or if val is in range
3234 * -EINVAL val out of range
3235 **/
c01f3208 3236static int
3de2a653
JS
3237lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3238{
3239 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3240 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3241 if (val != LPFC_DEF_DEVLOSS_TMO)
e8b62011 3242 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6c86068d
JS
3243 "0407 Ignoring lpfc_nodev_tmo module "
3244 "parameter because lpfc_devloss_tmo "
3245 "is set.\n");
c01f3208
JS
3246 return 0;
3247 }
3248
3249 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3de2a653
JS
3250 vport->cfg_nodev_tmo = val;
3251 vport->cfg_devloss_tmo = val;
c01f3208
JS
3252 return 0;
3253 }
e8b62011
JS
3254 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3255 "0400 lpfc_nodev_tmo attribute cannot be set to"
3256 " %d, allowed range is [%d, %d]\n",
3257 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3de2a653 3258 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
c01f3208
JS
3259 return -EINVAL;
3260}
3261
e59058c4 3262/**
3621a710 3263 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
e59058c4
JS
3264 * @vport: lpfc vport structure pointer.
3265 *
3266 * Description:
3267 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3268 **/
7054a606 3269static void
3de2a653 3270lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
7054a606 3271{
858c9f6c 3272 struct Scsi_Host *shost;
7054a606
JS
3273 struct lpfc_nodelist *ndlp;
3274
51ef4c26
JS
3275 shost = lpfc_shost_from_vport(vport);
3276 spin_lock_irq(shost->host_lock);
7a06dcd3
JS
3277 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3278 if (!NLP_CHK_NODE_ACT(ndlp))
3279 continue;
3280 if (ndlp->rport)
51ef4c26 3281 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
6ddcf0a3
JS
3282#if (IS_ENABLED(CONFIG_NVME_FC))
3283 if (ndlp->nrport)
3284 nvme_fc_set_remoteport_devloss(ndlp->nrport->remoteport,
3285 vport->cfg_devloss_tmo);
3286#endif
7a06dcd3 3287 }
51ef4c26 3288 spin_unlock_irq(shost->host_lock);
7054a606
JS
3289}
3290
e59058c4 3291/**
3621a710 3292 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
e59058c4
JS
3293 * @vport: lpfc vport structure pointer.
3294 * @val: contains the tmo value.
3295 *
3296 * Description:
3297 * If the devloss tmo is already set or the vport dev loss tmo has changed
3298 * then a kernel error message is printed and zero is returned.
3299 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3300 * Otherwise nodev tmo is set to the default value.
3301 *
3302 * Returns:
3303 * zero if already set or if val is in range
3304 * -EINVAL val out of range
3305 **/
c01f3208 3306static int
3de2a653 3307lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
c01f3208 3308{
3de2a653
JS
3309 if (vport->dev_loss_tmo_changed ||
3310 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
e8b62011 3311 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6c86068d
JS
3312 "0401 Ignoring change to lpfc_nodev_tmo "
3313 "because lpfc_devloss_tmo is set.\n");
c01f3208
JS
3314 return 0;
3315 }
c01f3208 3316 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3de2a653
JS
3317 vport->cfg_nodev_tmo = val;
3318 vport->cfg_devloss_tmo = val;
0af5d708
MC
3319 /*
3320 * For compat: set the fc_host dev loss so new rports
3321 * will get the value.
3322 */
3323 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3de2a653 3324 lpfc_update_rport_devloss_tmo(vport);
c01f3208
JS
3325 return 0;
3326 }
e8b62011 3327 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6c86068d 3328 "0403 lpfc_nodev_tmo attribute cannot be set to "
e8b62011
JS
3329 "%d, allowed range is [%d, %d]\n",
3330 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
c01f3208
JS
3331 return -EINVAL;
3332}
3333
3de2a653 3334lpfc_vport_param_store(nodev_tmo)
c01f3208 3335
69d725f4 3336static DEVICE_ATTR_RW(lpfc_nodev_tmo);
c01f3208
JS
3337
3338/*
3339# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3340# disappear until the timer expires. Value range is [0,255]. Default
3341# value is 30.
3342*/
ab56dc2e 3343module_param(lpfc_devloss_tmo, int, S_IRUGO);
c01f3208
JS
3344MODULE_PARM_DESC(lpfc_devloss_tmo,
3345 "Seconds driver will hold I/O waiting "
3346 "for a device to come back");
3de2a653
JS
3347lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3348 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3349lpfc_vport_param_show(devloss_tmo)
e59058c4
JS
3350
3351/**
3621a710 3352 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
e59058c4
JS
3353 * @vport: lpfc vport structure pointer.
3354 * @val: contains the tmo value.
3355 *
3356 * Description:
3357 * If val is in a valid range then set the vport nodev tmo,
3358 * devloss tmo, also set the vport dev loss tmo changed flag.
3359 * Else a kernel error message is printed.
3360 *
3361 * Returns:
3362 * zero if val is in range
3363 * -EINVAL val out of range
3364 **/
c01f3208 3365static int
3de2a653 3366lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
c01f3208
JS
3367{
3368 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3de2a653
JS
3369 vport->cfg_nodev_tmo = val;
3370 vport->cfg_devloss_tmo = val;
3371 vport->dev_loss_tmo_changed = 1;
0af5d708 3372 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3de2a653 3373 lpfc_update_rport_devloss_tmo(vport);
c01f3208
JS
3374 return 0;
3375 }
3376
e8b62011 3377 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6c86068d
JS
3378 "0404 lpfc_devloss_tmo attribute cannot be set to "
3379 "%d, allowed range is [%d, %d]\n",
e8b62011 3380 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
c01f3208
JS
3381 return -EINVAL;
3382}
3383
3de2a653 3384lpfc_vport_param_store(devloss_tmo)
69d725f4 3385static DEVICE_ATTR_RW(lpfc_devloss_tmo);
c01f3208 3386
f358dd0c
JS
3387/*
3388 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3389 * lpfc_suppress_rsp = 0 Disable
3390 * lpfc_suppress_rsp = 1 Enable (default)
3391 *
3392 */
3393LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3394 "Enable suppress rsp feature is firmware supports it");
3395
2d7dbc4c
JS
3396/*
3397 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
0eeaf17f 3398 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
2d7dbc4c
JS
3399 * lpfc_nvmet_mrq = 1 use a single RQ pair
3400 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3401 *
3402 */
3403LPFC_ATTR_R(nvmet_mrq,
0eeaf17f 3404 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
2d7dbc4c
JS
3405 "Specify number of RQ pairs for processing NVMET cmds");
3406
895427bd
JS
3407/*
3408 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3409 * Supported Values: 1 - register just FCP
3410 * 3 - register both FCP and NVME
7d708033 3411 * Supported values are [1,3]. Default value is 1
895427bd 3412 */
7d708033 3413LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP,
895427bd 3414 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
cf4c8c86 3415 "Enable FC4 Protocol support - FCP / NVME");
895427bd
JS
3416
3417/*
3418 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3419 * This parameter is only used if:
f358dd0c
JS
3420 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3421 * port is not configured for NVMET.
895427bd
JS
3422 *
3423 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3424 * The remaining XRIs get split up based on lpfc_xri_split per port:
3425 *
3426 * Supported Values are in percentages
3427 * the xri_split value is the percentage the SCSI port will get. The remaining
3428 * percentage will go to NVME.
3429 */
3430LPFC_ATTR_R(xri_split, 50, 10, 90,
cf4c8c86 3431 "Percentage of FCP XRI resources versus NVME");
895427bd 3432
dea3101e
JB
3433/*
3434# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3435# deluged with LOTS of information.
3436# You can set a bit mask to record specific types of verbose messages:
f4b4c68f 3437# See lpfc_logmsh.h for definitions.
dea3101e 3438*/
f4b4c68f 3439LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
e8b62011 3440 "Verbose logging bit-mask");
dea3101e 3441
7ee5d43e
JS
3442/*
3443# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3444# objects that have been registered with the nameserver after login.
3445*/
cf971240 3446LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
7ee5d43e
JS
3447 "Deregister nameserver objects before LOGO");
3448
dea3101e
JB
3449/*
3450# lun_queue_depth: This parameter is used to limit the number of outstanding
572709e2
JS
3451# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3452# If this parameter value is greater than 1/8th the maximum number of exchanges
3453# supported by the HBA port, then the lun queue depth will be reduced to
3454# 1/8th the maximum number of exchanges.
dea3101e 3455*/
572709e2 3456LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
3de2a653 3457 "Max number of FCP commands we can queue to a specific LUN");
dea3101e 3458
7dc517df
JS
3459/*
3460# tgt_queue_depth: This parameter is used to limit the number of outstanding
3461# commands per target port. Value range is [10,65535]. Default value is 65535.
3462*/
3463LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
572709e2 3464 "Max number of FCP commands we can queue to a specific target port");
7dc517df 3465
b28485ac
JW
3466/*
3467# hba_queue_depth: This parameter is used to limit the number of outstanding
3468# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3469# value is greater than the maximum number of exchanges supported by the HBA,
3470# then maximum number of exchanges supported by the HBA is used to determine
3471# the hba_queue_depth.
3472*/
3473LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3474 "Max number of FCP commands we can queue to a lpfc HBA");
3475
92d7f7b0
JS
3476/*
3477# peer_port_login: This parameter allows/prevents logins
3478# between peer ports hosted on the same physical port.
3479# When this parameter is set 0 peer ports of same physical port
3480# are not allowed to login to each other.
3481# When this parameter is set 1 peer ports of same physical port
3482# are allowed to login to each other.
3483# Default value of this parameter is 0.
3484*/
3de2a653
JS
3485LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3486 "Allow peer ports on the same physical port to login to each "
3487 "other.");
92d7f7b0
JS
3488
3489/*
3de2a653 3490# restrict_login: This parameter allows/prevents logins
92d7f7b0
JS
3491# between Virtual Ports and remote initiators.
3492# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3493# other initiators and will attempt to PLOGI all remote ports.
3494# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3495# remote ports and will not attempt to PLOGI to other initiators.
3496# This parameter does not restrict to the physical port.
3497# This parameter does not restrict logins to Fabric resident remote ports.
3498# Default value of this parameter is 1.
3499*/
3de2a653 3500static int lpfc_restrict_login = 1;
ab56dc2e 3501module_param(lpfc_restrict_login, int, S_IRUGO);
3de2a653
JS
3502MODULE_PARM_DESC(lpfc_restrict_login,
3503 "Restrict virtual ports login to remote initiators.");
3504lpfc_vport_param_show(restrict_login);
3505
e59058c4 3506/**
3621a710 3507 * lpfc_restrict_login_init - Set the vport restrict login flag
e59058c4
JS
3508 * @vport: lpfc vport structure pointer.
3509 * @val: contains the restrict login value.
3510 *
3511 * Description:
3512 * If val is not in a valid range then log a kernel error message and set
3513 * the vport restrict login to one.
3514 * If the port type is physical clear the restrict login flag and return.
3515 * Else set the restrict login flag to val.
3516 *
3517 * Returns:
3518 * zero if val is in range
3519 * -EINVAL val out of range
3520 **/
3de2a653
JS
3521static int
3522lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3523{
3524 if (val < 0 || val > 1) {
e8b62011 3525 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
d7c255b2 3526 "0422 lpfc_restrict_login attribute cannot "
e8b62011
JS
3527 "be set to %d, allowed range is [0, 1]\n",
3528 val);
3de2a653
JS
3529 vport->cfg_restrict_login = 1;
3530 return -EINVAL;
3531 }
3532 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3533 vport->cfg_restrict_login = 0;
3534 return 0;
3535 }
3536 vport->cfg_restrict_login = val;
3537 return 0;
3538}
3539
e59058c4 3540/**
3621a710 3541 * lpfc_restrict_login_set - Set the vport restrict login flag
e59058c4
JS
3542 * @vport: lpfc vport structure pointer.
3543 * @val: contains the restrict login value.
3544 *
3545 * Description:
3546 * If val is not in a valid range then log a kernel error message and set
3547 * the vport restrict login to one.
3548 * If the port type is physical and the val is not zero log a kernel
3549 * error message, clear the restrict login flag and return zero.
3550 * Else set the restrict login flag to val.
3551 *
3552 * Returns:
3553 * zero if val is in range
3554 * -EINVAL val out of range
3555 **/
3de2a653
JS
3556static int
3557lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3558{
3559 if (val < 0 || val > 1) {
e8b62011 3560 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
d7c255b2 3561 "0425 lpfc_restrict_login attribute cannot "
e8b62011
JS
3562 "be set to %d, allowed range is [0, 1]\n",
3563 val);
3de2a653
JS
3564 vport->cfg_restrict_login = 1;
3565 return -EINVAL;
3566 }
3567 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
e8b62011
JS
3568 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3569 "0468 lpfc_restrict_login must be 0 for "
3570 "Physical ports.\n");
3de2a653
JS
3571 vport->cfg_restrict_login = 0;
3572 return 0;
3573 }
3574 vport->cfg_restrict_login = val;
3575 return 0;
3576}
3577lpfc_vport_param_store(restrict_login);
69d725f4 3578static DEVICE_ATTR_RW(lpfc_restrict_login);
92d7f7b0 3579
dea3101e
JB
3580/*
3581# Some disk devices have a "select ID" or "select Target" capability.
3582# From a protocol standpoint "select ID" usually means select the
3583# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3584# annex" which contains a table that maps a "select ID" (a number
3585# between 0 and 7F) to an ALPA. By default, for compatibility with
3586# older drivers, the lpfc driver scans this table from low ALPA to high
3587# ALPA.
3588#
3589# Turning on the scan-down variable (on = 1, off = 0) will
3590# cause the lpfc driver to use an inverted table, effectively
3591# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3592#
3593# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3594# and will not work across a fabric. Also this parameter will take
3595# effect only in the case when ALPA map is not available.)
3596*/
3de2a653
JS
3597LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3598 "Start scanning for devices from highest ALPA to lowest");
dea3101e 3599
dea3101e
JB
3600/*
3601# lpfc_topology: link topology for init link
3602# 0x0 = attempt loop mode then point-to-point
367c2713 3603# 0x01 = internal loopback mode
dea3101e
JB
3604# 0x02 = attempt point-to-point mode only
3605# 0x04 = attempt loop mode only
3606# 0x06 = attempt point-to-point mode then loop
3607# Set point-to-point mode if you want to run as an N_Port.
3608# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3609# Default value is 0.
3610*/
0a035439
JS
3611LPFC_ATTR(topology, 0, 0, 6,
3612 "Select Fibre Channel topology");
e59058c4
JS
3613
3614/**
3621a710 3615 * lpfc_topology_set - Set the adapters topology field
e59058c4
JS
3616 * @phba: lpfc_hba pointer.
3617 * @val: topology value.
3618 *
3619 * Description:
3620 * If val is in a valid range then set the adapter's topology field and
3621 * issue a lip; if the lip fails reset the topology to the old value.
3622 *
3623 * If the value is not in range log a kernel error message and return an error.
3624 *
3625 * Returns:
3626 * zero if val is in range and lip okay
3627 * non-zero return value from lpfc_issue_lip()
3628 * -EINVAL val out of range
3629 **/
a257bf90
JS
3630static ssize_t
3631lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3632 const char *buf, size_t count)
83108bd3 3633{
a257bf90
JS
3634 struct Scsi_Host *shost = class_to_shost(dev);
3635 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3636 struct lpfc_hba *phba = vport->phba;
3637 int val = 0;
3638 int nolip = 0;
3639 const char *val_buf = buf;
83108bd3
JS
3640 int err;
3641 uint32_t prev_val;
a257bf90
JS
3642
3643 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3644 nolip = 1;
3645 val_buf = &buf[strlen("nolip ")];
3646 }
3647
3648 if (!isdigit(val_buf[0]))
3649 return -EINVAL;
3650 if (sscanf(val_buf, "%i", &val) != 1)
3651 return -EINVAL;
3652
83108bd3
JS
3653 if (val >= 0 && val <= 6) {
3654 prev_val = phba->cfg_topology;
ff78d8f9
JS
3655 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3656 val == 4) {
3657 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3658 "3113 Loop mode not supported at speed %d\n",
d38dd52c 3659 val);
ff78d8f9
JS
3660 return -EINVAL;
3661 }
d38dd52c
JS
3662 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3663 val == 4) {
3664 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3665 "3114 Loop mode not supported\n");
3666 return -EINVAL;
3667 }
3668 phba->cfg_topology = val;
a257bf90
JS
3669 if (nolip)
3670 return strlen(buf);
3671
88a2cfbb
JS
3672 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3673 "3054 lpfc_topology changed from %d to %d\n",
3674 prev_val, val);
e74c03c8
JS
3675 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3676 phba->fc_topology_changed = 1;
83108bd3 3677 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
a257bf90 3678 if (err) {
83108bd3 3679 phba->cfg_topology = prev_val;
a257bf90
JS
3680 return -EINVAL;
3681 } else
3682 return strlen(buf);
83108bd3
JS
3683 }
3684 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3685 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3686 "allowed range is [0, 6]\n",
3687 phba->brd_no, val);
3688 return -EINVAL;
3689}
0a035439 3690
83108bd3 3691lpfc_param_show(topology)
69d725f4 3692static DEVICE_ATTR_RW(lpfc_topology);
dea3101e 3693
21e9a0a5
JS
3694/**
3695 * lpfc_static_vport_show: Read callback function for
3696 * lpfc_static_vport sysfs file.
3697 * @dev: Pointer to class device object.
3698 * @attr: device attribute structure.
3699 * @buf: Data buffer.
3700 *
3701 * This function is the read call back function for
3702 * lpfc_static_vport sysfs file. The lpfc_static_vport
3703 * sysfs file report the mageability of the vport.
3704 **/
3705static ssize_t
3706lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3707 char *buf)
3708{
3709 struct Scsi_Host *shost = class_to_shost(dev);
3710 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3711 if (vport->vport_flag & STATIC_VPORT)
3712 sprintf(buf, "1\n");
3713 else
3714 sprintf(buf, "0\n");
3715
3716 return strlen(buf);
3717}
3718
3719/*
3720 * Sysfs attribute to control the statistical data collection.
3721 */
3722static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3723 lpfc_static_vport_show, NULL);
ea2151b4
JS
3724
3725/**
3621a710 3726 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
ea2151b4
JS
3727 * @dev: Pointer to class device.
3728 * @buf: Data buffer.
3729 * @count: Size of the data buffer.
3730 *
9332ef9d 3731 * This function get called when a user write to the lpfc_stat_data_ctrl
ea2151b4
JS
3732 * sysfs file. This function parse the command written to the sysfs file
3733 * and take appropriate action. These commands are used for controlling
3734 * driver statistical data collection.
3735 * Following are the command this function handles.
3736 *
3737 * setbucket <bucket_type> <base> <step>
3738 * = Set the latency buckets.
3739 * destroybucket = destroy all the buckets.
3740 * start = start data collection
3741 * stop = stop data collection
3742 * reset = reset the collected data
3743 **/
3744static ssize_t
3745lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3746 const char *buf, size_t count)
3747{
3748 struct Scsi_Host *shost = class_to_shost(dev);
3749 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3750 struct lpfc_hba *phba = vport->phba;
3751#define LPFC_MAX_DATA_CTRL_LEN 1024
3752 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3753 unsigned long i;
3754 char *str_ptr, *token;
3755 struct lpfc_vport **vports;
3756 struct Scsi_Host *v_shost;
3757 char *bucket_type_str, *base_str, *step_str;
3758 unsigned long base, step, bucket_type;
3759
3760 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
a257bf90 3761 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
ea2151b4
JS
3762 return -EINVAL;
3763
eb016566 3764 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
ea2151b4
JS
3765 str_ptr = &bucket_data[0];
3766 /* Ignore this token - this is command token */
3767 token = strsep(&str_ptr, "\t ");
3768 if (!token)
3769 return -EINVAL;
3770
3771 bucket_type_str = strsep(&str_ptr, "\t ");
3772 if (!bucket_type_str)
3773 return -EINVAL;
3774
3775 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3776 bucket_type = LPFC_LINEAR_BUCKET;
3777 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3778 bucket_type = LPFC_POWER2_BUCKET;
3779 else
3780 return -EINVAL;
3781
3782 base_str = strsep(&str_ptr, "\t ");
3783 if (!base_str)
3784 return -EINVAL;
3785 base = simple_strtoul(base_str, NULL, 0);
3786
3787 step_str = strsep(&str_ptr, "\t ");
3788 if (!step_str)
3789 return -EINVAL;
3790 step = simple_strtoul(step_str, NULL, 0);
3791 if (!step)
3792 return -EINVAL;
3793
3794 /* Block the data collection for every vport */
3795 vports = lpfc_create_vport_work_array(phba);
3796 if (vports == NULL)
3797 return -ENOMEM;
3798
f4b4c68f 3799 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
ea2151b4
JS
3800 v_shost = lpfc_shost_from_vport(vports[i]);
3801 spin_lock_irq(v_shost->host_lock);
3802 /* Block and reset data collection */
3803 vports[i]->stat_data_blocked = 1;
3804 if (vports[i]->stat_data_enabled)
3805 lpfc_vport_reset_stat_data(vports[i]);
3806 spin_unlock_irq(v_shost->host_lock);
3807 }
3808
3809 /* Set the bucket attributes */
3810 phba->bucket_type = bucket_type;
3811 phba->bucket_base = base;
3812 phba->bucket_step = step;
3813
f4b4c68f 3814 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
ea2151b4
JS
3815 v_shost = lpfc_shost_from_vport(vports[i]);
3816
3817 /* Unblock data collection */
3818 spin_lock_irq(v_shost->host_lock);
3819 vports[i]->stat_data_blocked = 0;
3820 spin_unlock_irq(v_shost->host_lock);
3821 }
3822 lpfc_destroy_vport_work_array(phba, vports);
3823 return strlen(buf);
3824 }
3825
3826 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3827 vports = lpfc_create_vport_work_array(phba);
3828 if (vports == NULL)
3829 return -ENOMEM;
3830
f4b4c68f 3831 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
ea2151b4
JS
3832 v_shost = lpfc_shost_from_vport(vports[i]);
3833 spin_lock_irq(shost->host_lock);
3834 vports[i]->stat_data_blocked = 1;
3835 lpfc_free_bucket(vport);
3836 vport->stat_data_enabled = 0;
3837 vports[i]->stat_data_blocked = 0;
3838 spin_unlock_irq(shost->host_lock);
3839 }
3840 lpfc_destroy_vport_work_array(phba, vports);
3841 phba->bucket_type = LPFC_NO_BUCKET;
3842 phba->bucket_base = 0;
3843 phba->bucket_step = 0;
3844 return strlen(buf);
3845 }
3846
3847 if (!strncmp(buf, "start", strlen("start"))) {
3848 /* If no buckets configured return error */
3849 if (phba->bucket_type == LPFC_NO_BUCKET)
3850 return -EINVAL;
3851 spin_lock_irq(shost->host_lock);
3852 if (vport->stat_data_enabled) {
3853 spin_unlock_irq(shost->host_lock);
3854 return strlen(buf);
3855 }
3856 lpfc_alloc_bucket(vport);
3857 vport->stat_data_enabled = 1;
3858 spin_unlock_irq(shost->host_lock);
3859 return strlen(buf);
3860 }
3861
3862 if (!strncmp(buf, "stop", strlen("stop"))) {
3863 spin_lock_irq(shost->host_lock);
3864 if (vport->stat_data_enabled == 0) {
3865 spin_unlock_irq(shost->host_lock);
3866 return strlen(buf);
3867 }
3868 lpfc_free_bucket(vport);
3869 vport->stat_data_enabled = 0;
3870 spin_unlock_irq(shost->host_lock);
3871 return strlen(buf);
3872 }
3873
3874 if (!strncmp(buf, "reset", strlen("reset"))) {
3875 if ((phba->bucket_type == LPFC_NO_BUCKET)
3876 || !vport->stat_data_enabled)
3877 return strlen(buf);
3878 spin_lock_irq(shost->host_lock);
3879 vport->stat_data_blocked = 1;
3880 lpfc_vport_reset_stat_data(vport);
3881 vport->stat_data_blocked = 0;
3882 spin_unlock_irq(shost->host_lock);
3883 return strlen(buf);
3884 }
3885 return -EINVAL;
3886}
3887
3888
3889/**
3621a710 3890 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
ea2151b4
JS
3891 * @dev: Pointer to class device object.
3892 * @buf: Data buffer.
3893 *
3894 * This function is the read call back function for
3895 * lpfc_stat_data_ctrl sysfs file. This function report the
3896 * current statistical data collection state.
3897 **/
3898static ssize_t
3899lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3900 char *buf)
3901{
3902 struct Scsi_Host *shost = class_to_shost(dev);
3903 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3904 struct lpfc_hba *phba = vport->phba;
3905 int index = 0;
3906 int i;
3907 char *bucket_type;
3908 unsigned long bucket_value;
3909
3910 switch (phba->bucket_type) {
3911 case LPFC_LINEAR_BUCKET:
3912 bucket_type = "linear";
3913 break;
3914 case LPFC_POWER2_BUCKET:
3915 bucket_type = "power2";
3916 break;
3917 default:
3918 bucket_type = "No Bucket";
3919 break;
3920 }
3921
3922 sprintf(&buf[index], "Statistical Data enabled :%d, "
3923 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3924 " Bucket step :%d\nLatency Ranges :",
3925 vport->stat_data_enabled, vport->stat_data_blocked,
3926 bucket_type, phba->bucket_base, phba->bucket_step);
3927 index = strlen(buf);
3928 if (phba->bucket_type != LPFC_NO_BUCKET) {
3929 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3930 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3931 bucket_value = phba->bucket_base +
3932 phba->bucket_step * i;
3933 else
3934 bucket_value = phba->bucket_base +
3935 (1 << i) * phba->bucket_step;
3936
3937 if (index + 10 > PAGE_SIZE)
3938 break;
3939 sprintf(&buf[index], "%08ld ", bucket_value);
3940 index = strlen(buf);
3941 }
3942 }
3943 sprintf(&buf[index], "\n");
3944 return strlen(buf);
3945}
3946
3947/*
3948 * Sysfs attribute to control the statistical data collection.
3949 */
69d725f4 3950static DEVICE_ATTR_RW(lpfc_stat_data_ctrl);
ea2151b4
JS
3951
3952/*
3953 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3954 */
3955
3956/*
3957 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3958 * for each target.
3959 */
3960#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3961#define MAX_STAT_DATA_SIZE_PER_TARGET \
3962 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3963
3964
3965/**
3621a710 3966 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2c3c8bea 3967 * @filp: sysfs file
ea2151b4
JS
3968 * @kobj: Pointer to the kernel object
3969 * @bin_attr: Attribute object
3970 * @buff: Buffer pointer
3971 * @off: File offset
3972 * @count: Buffer size
3973 *
3974 * This function is the read call back function for lpfc_drvr_stat_data
3975 * sysfs file. This function export the statistical data to user
3976 * applications.
3977 **/
3978static ssize_t
2c3c8bea
CW
3979sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3980 struct bin_attribute *bin_attr,
ea2151b4
JS
3981 char *buf, loff_t off, size_t count)
3982{
3983 struct device *dev = container_of(kobj, struct device,
3984 kobj);
3985 struct Scsi_Host *shost = class_to_shost(dev);
3986 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3987 struct lpfc_hba *phba = vport->phba;
3988 int i = 0, index = 0;
3989 unsigned long nport_index;
3990 struct lpfc_nodelist *ndlp = NULL;
3991 nport_index = (unsigned long)off /
3992 MAX_STAT_DATA_SIZE_PER_TARGET;
3993
3994 if (!vport->stat_data_enabled || vport->stat_data_blocked
3995 || (phba->bucket_type == LPFC_NO_BUCKET))
3996 return 0;
3997
3998 spin_lock_irq(shost->host_lock);
3999 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4000 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
4001 continue;
4002
4003 if (nport_index > 0) {
4004 nport_index--;
4005 continue;
4006 }
4007
4008 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
4009 > count)
4010 break;
4011
4012 if (!ndlp->lat_data)
4013 continue;
4014
4015 /* Print the WWN */
4016 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
4017 ndlp->nlp_portname.u.wwn[0],
4018 ndlp->nlp_portname.u.wwn[1],
4019 ndlp->nlp_portname.u.wwn[2],
4020 ndlp->nlp_portname.u.wwn[3],
4021 ndlp->nlp_portname.u.wwn[4],
4022 ndlp->nlp_portname.u.wwn[5],
4023 ndlp->nlp_portname.u.wwn[6],
4024 ndlp->nlp_portname.u.wwn[7]);
4025
4026 index = strlen(buf);
4027
4028 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4029 sprintf(&buf[index], "%010u,",
4030 ndlp->lat_data[i].cmd_count);
4031 index = strlen(buf);
4032 }
4033 sprintf(&buf[index], "\n");
4034 index = strlen(buf);
4035 }
4036 spin_unlock_irq(shost->host_lock);
4037 return index;
4038}
4039
4040static struct bin_attribute sysfs_drvr_stat_data_attr = {
4041 .attr = {
4042 .name = "lpfc_drvr_stat_data",
4043 .mode = S_IRUSR,
ea2151b4
JS
4044 },
4045 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
4046 .read = sysfs_drvr_stat_data_read,
4047 .write = NULL,
4048};
4049
dea3101e
JB
4050/*
4051# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4052# connection.
76a95d75 4053# Value range is [0,16]. Default value is 0.
dea3101e 4054*/
e59058c4 4055/**
3621a710 4056 * lpfc_link_speed_set - Set the adapters link speed
e59058c4
JS
4057 * @phba: lpfc_hba pointer.
4058 * @val: link speed value.
4059 *
4060 * Description:
4061 * If val is in a valid range then set the adapter's link speed field and
4062 * issue a lip; if the lip fails reset the link speed to the old value.
4063 *
4064 * Notes:
4065 * If the value is not in range log a kernel error message and return an error.
4066 *
4067 * Returns:
4068 * zero if val is in range and lip okay.
4069 * non-zero return value from lpfc_issue_lip()
4070 * -EINVAL val out of range
4071 **/
a257bf90
JS
4072static ssize_t
4073lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4074 const char *buf, size_t count)
83108bd3 4075{
a257bf90
JS
4076 struct Scsi_Host *shost = class_to_shost(dev);
4077 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4078 struct lpfc_hba *phba = vport->phba;
76a95d75 4079 int val = LPFC_USER_LINK_SPEED_AUTO;
a257bf90
JS
4080 int nolip = 0;
4081 const char *val_buf = buf;
83108bd3 4082 int err;
c691816e
JS
4083 uint32_t prev_val, if_type;
4084
4085 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4086 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
4087 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4088 return -EPERM;
83108bd3 4089
a257bf90
JS
4090 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4091 nolip = 1;
4092 val_buf = &buf[strlen("nolip ")];
4093 }
4094
4095 if (!isdigit(val_buf[0]))
4096 return -EINVAL;
4097 if (sscanf(val_buf, "%i", &val) != 1)
4098 return -EINVAL;
4099
88a2cfbb
JS
4100 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4101 "3055 lpfc_link_speed changed from %d to %d %s\n",
4102 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4103
76a95d75
JS
4104 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4105 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4106 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4107 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4108 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
d38dd52c
JS
4109 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4110 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
76a95d75
JS
4111 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4112 "2879 lpfc_link_speed attribute cannot be set "
4113 "to %d. Speed is not supported by this port.\n",
4114 val);
83108bd3 4115 return -EINVAL;
76a95d75 4116 }
ff78d8f9
JS
4117 if (val == LPFC_USER_LINK_SPEED_16G &&
4118 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4119 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4120 "3112 lpfc_link_speed attribute cannot be set "
4121 "to %d. Speed is not supported in loop mode.\n",
4122 val);
4123 return -EINVAL;
4124 }
76a95d75
JS
4125 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4126 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
83108bd3
JS
4127 prev_val = phba->cfg_link_speed;
4128 phba->cfg_link_speed = val;
a257bf90
JS
4129 if (nolip)
4130 return strlen(buf);
4131
83108bd3 4132 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
a257bf90 4133 if (err) {
83108bd3 4134 phba->cfg_link_speed = prev_val;
a257bf90
JS
4135 return -EINVAL;
4136 } else
4137 return strlen(buf);
83108bd3 4138 }
83108bd3 4139 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
76a95d75
JS
4140 "0469 lpfc_link_speed attribute cannot be set to %d, "
4141 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
83108bd3
JS
4142 return -EINVAL;
4143}
4144
4145static int lpfc_link_speed = 0;
ab56dc2e 4146module_param(lpfc_link_speed, int, S_IRUGO);
83108bd3
JS
4147MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4148lpfc_param_show(link_speed)
e59058c4
JS
4149
4150/**
3621a710 4151 * lpfc_link_speed_init - Set the adapters link speed
e59058c4
JS
4152 * @phba: lpfc_hba pointer.
4153 * @val: link speed value.
4154 *
4155 * Description:
4156 * If val is in a valid range then set the adapter's link speed field.
4157 *
4158 * Notes:
4159 * If the value is not in range log a kernel error message, clear the link
4160 * speed and return an error.
4161 *
4162 * Returns:
4163 * zero if val saved.
4164 * -EINVAL val out of range
4165 **/
83108bd3
JS
4166static int
4167lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4168{
ff78d8f9
JS
4169 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4170 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4171 "3111 lpfc_link_speed of %d cannot "
4172 "support loop mode, setting topology to default.\n",
4173 val);
4174 phba->cfg_topology = 0;
4175 }
76a95d75
JS
4176 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4177 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
83108bd3
JS
4178 phba->cfg_link_speed = val;
4179 return 0;
4180 }
4181 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
d7c255b2 4182 "0405 lpfc_link_speed attribute cannot "
83108bd3
JS
4183 "be set to %d, allowed values are "
4184 "["LPFC_LINK_SPEED_STRING"]\n", val);
76a95d75 4185 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
83108bd3
JS
4186 return -EINVAL;
4187}
4188
69d725f4 4189static DEVICE_ATTR_RW(lpfc_link_speed);
dea3101e 4190
0d878419
JS
4191/*
4192# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4193# 0 = aer disabled or not supported
4194# 1 = aer supported and enabled (default)
4195# Value range is [0,1]. Default value is 1.
4196*/
506139a2
JS
4197LPFC_ATTR(aer_support, 1, 0, 1,
4198 "Enable PCIe device AER support");
4199lpfc_param_show(aer_support)
0d878419
JS
4200
4201/**
4202 * lpfc_aer_support_store - Set the adapter for aer support
4203 *
4204 * @dev: class device that is converted into a Scsi_host.
4205 * @attr: device attribute, not used.
912e3acd 4206 * @buf: containing enable or disable aer flag.
0d878419
JS
4207 * @count: unused variable.
4208 *
4209 * Description:
4210 * If the val is 1 and currently the device's AER capability was not
4211 * enabled, invoke the kernel's enable AER helper routine, trying to
4212 * enable the device's AER capability. If the helper routine enabling
4213 * AER returns success, update the device's cfg_aer_support flag to
4214 * indicate AER is supported by the device; otherwise, if the device
4215 * AER capability is already enabled to support AER, then do nothing.
4216 *
4217 * If the val is 0 and currently the device's AER support was enabled,
4218 * invoke the kernel's disable AER helper routine. After that, update
4219 * the device's cfg_aer_support flag to indicate AER is not supported
4220 * by the device; otherwise, if the device AER capability is already
4221 * disabled from supporting AER, then do nothing.
4222 *
4223 * Returns:
4224 * length of the buf on success if val is in range the intended mode
4225 * is supported.
4226 * -EINVAL if val out of range or intended mode is not supported.
4227 **/
4228static ssize_t
4229lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4230 const char *buf, size_t count)
4231{
4232 struct Scsi_Host *shost = class_to_shost(dev);
4233 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4234 struct lpfc_hba *phba = vport->phba;
4235 int val = 0, rc = -EINVAL;
4236
4237 if (!isdigit(buf[0]))
4238 return -EINVAL;
4239 if (sscanf(buf, "%i", &val) != 1)
4240 return -EINVAL;
4241
4242 switch (val) {
4243 case 0:
4244 if (phba->hba_flag & HBA_AER_ENABLED) {
4245 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4246 if (!rc) {
4247 spin_lock_irq(&phba->hbalock);
4248 phba->hba_flag &= ~HBA_AER_ENABLED;
4249 spin_unlock_irq(&phba->hbalock);
4250 phba->cfg_aer_support = 0;
4251 rc = strlen(buf);
4252 } else
891478a2
JS
4253 rc = -EPERM;
4254 } else {
0d878419 4255 phba->cfg_aer_support = 0;
891478a2
JS
4256 rc = strlen(buf);
4257 }
0d878419
JS
4258 break;
4259 case 1:
4260 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4261 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4262 if (!rc) {
4263 spin_lock_irq(&phba->hbalock);
4264 phba->hba_flag |= HBA_AER_ENABLED;
4265 spin_unlock_irq(&phba->hbalock);
4266 phba->cfg_aer_support = 1;
4267 rc = strlen(buf);
4268 } else
891478a2
JS
4269 rc = -EPERM;
4270 } else {
0d878419 4271 phba->cfg_aer_support = 1;
891478a2
JS
4272 rc = strlen(buf);
4273 }
0d878419
JS
4274 break;
4275 default:
4276 rc = -EINVAL;
4277 break;
4278 }
4279 return rc;
4280}
4281
69d725f4 4282static DEVICE_ATTR_RW(lpfc_aer_support);
0d878419
JS
4283
4284/**
4285 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4286 * @dev: class device that is converted into a Scsi_host.
4287 * @attr: device attribute, not used.
912e3acd 4288 * @buf: containing flag 1 for aer cleanup state.
0d878419
JS
4289 * @count: unused variable.
4290 *
4291 * Description:
4292 * If the @buf contains 1 and the device currently has the AER support
4293 * enabled, then invokes the kernel AER helper routine
4294 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4295 * error status register.
4296 *
4297 * Notes:
4298 *
4299 * Returns:
4300 * -EINVAL if the buf does not contain the 1 or the device is not currently
4301 * enabled with the AER support.
4302 **/
4303static ssize_t
4304lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4305 const char *buf, size_t count)
4306{
4307 struct Scsi_Host *shost = class_to_shost(dev);
4308 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4309 struct lpfc_hba *phba = vport->phba;
4310 int val, rc = -1;
4311
4312 if (!isdigit(buf[0]))
4313 return -EINVAL;
4314 if (sscanf(buf, "%i", &val) != 1)
4315 return -EINVAL;
891478a2
JS
4316 if (val != 1)
4317 return -EINVAL;
0d878419 4318
891478a2 4319 if (phba->hba_flag & HBA_AER_ENABLED)
0d878419
JS
4320 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4321
4322 if (rc == 0)
4323 return strlen(buf);
4324 else
891478a2 4325 return -EPERM;
0d878419
JS
4326}
4327
4328static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4329 lpfc_aer_cleanup_state);
4330
912e3acd
JS
4331/**
4332 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4333 *
4334 * @dev: class device that is converted into a Scsi_host.
4335 * @attr: device attribute, not used.
4336 * @buf: containing the string the number of vfs to be enabled.
4337 * @count: unused variable.
4338 *
4339 * Description:
4340 * When this api is called either through user sysfs, the driver shall
4341 * try to enable or disable SR-IOV virtual functions according to the
4342 * following:
4343 *
4344 * If zero virtual function has been enabled to the physical function,
4345 * the driver shall invoke the pci enable virtual function api trying
4346 * to enable the virtual functions. If the nr_vfn provided is greater
4347 * than the maximum supported, the maximum virtual function number will
4348 * be used for invoking the api; otherwise, the nr_vfn provided shall
4349 * be used for invoking the api. If the api call returned success, the
4350 * actual number of virtual functions enabled will be set to the driver
4351 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4352 * cfg_sriov_nr_virtfn remains zero.
4353 *
4354 * If none-zero virtual functions have already been enabled to the
4355 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4356 * -EINVAL will be returned and the driver does nothing;
4357 *
4358 * If the nr_vfn provided is zero and none-zero virtual functions have
4359 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4360 * disabling virtual function api shall be invoded to disable all the
4361 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4362 * zero. Otherwise, if zero virtual function has been enabled, do
4363 * nothing.
4364 *
4365 * Returns:
4366 * length of the buf on success if val is in range the intended mode
4367 * is supported.
4368 * -EINVAL if val out of range or intended mode is not supported.
4369 **/
4370static ssize_t
4371lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4372 const char *buf, size_t count)
4373{
4374 struct Scsi_Host *shost = class_to_shost(dev);
4375 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4376 struct lpfc_hba *phba = vport->phba;
4377 struct pci_dev *pdev = phba->pcidev;
4378 int val = 0, rc = -EINVAL;
4379
4380 /* Sanity check on user data */
4381 if (!isdigit(buf[0]))
4382 return -EINVAL;
4383 if (sscanf(buf, "%i", &val) != 1)
4384 return -EINVAL;
4385 if (val < 0)
4386 return -EINVAL;
4387
4388 /* Request disabling virtual functions */
4389 if (val == 0) {
4390 if (phba->cfg_sriov_nr_virtfn > 0) {
4391 pci_disable_sriov(pdev);
4392 phba->cfg_sriov_nr_virtfn = 0;
4393 }
4394 return strlen(buf);
4395 }
4396
4397 /* Request enabling virtual functions */
4398 if (phba->cfg_sriov_nr_virtfn > 0) {
4399 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4400 "3018 There are %d virtual functions "
4401 "enabled on physical function.\n",
4402 phba->cfg_sriov_nr_virtfn);
4403 return -EEXIST;
4404 }
4405
4406 if (val <= LPFC_MAX_VFN_PER_PFN)
4407 phba->cfg_sriov_nr_virtfn = val;
4408 else {
4409 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4410 "3019 Enabling %d virtual functions is not "
4411 "allowed.\n", val);
4412 return -EINVAL;
4413 }
4414
4415 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4416 if (rc) {
4417 phba->cfg_sriov_nr_virtfn = 0;
4418 rc = -EPERM;
4419 } else
4420 rc = strlen(buf);
4421
4422 return rc;
4423}
4424
0cfbbf2f
JS
4425LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4426 "Enable PCIe device SR-IOV virtual fn");
912e3acd 4427
0cfbbf2f 4428lpfc_param_show(sriov_nr_virtfn)
69d725f4 4429static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
912e3acd 4430
c71ab861
JS
4431/**
4432 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4433 *
4434 * @dev: class device that is converted into a Scsi_host.
4435 * @attr: device attribute, not used.
4436 * @buf: containing the string the number of vfs to be enabled.
4437 * @count: unused variable.
4438 *
4439 * Description:
4440 *
4441 * Returns:
4442 * length of the buf on success if val is in range the intended mode
4443 * is supported.
4444 * -EINVAL if val out of range or intended mode is not supported.
4445 **/
4446static ssize_t
4447lpfc_request_firmware_upgrade_store(struct device *dev,
4448 struct device_attribute *attr,
4449 const char *buf, size_t count)
4450{
4451 struct Scsi_Host *shost = class_to_shost(dev);
4452 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4453 struct lpfc_hba *phba = vport->phba;
4454 int val = 0, rc = -EINVAL;
4455
4456 /* Sanity check on user data */
4457 if (!isdigit(buf[0]))
4458 return -EINVAL;
4459 if (sscanf(buf, "%i", &val) != 1)
4460 return -EINVAL;
4461 if (val != 1)
4462 return -EINVAL;
4463
4464 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4465 if (rc)
4466 rc = -EPERM;
4467 else
4468 rc = strlen(buf);
4469 return rc;
4470}
4471
4472static int lpfc_req_fw_upgrade;
4473module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4474MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4475lpfc_param_show(request_firmware_upgrade)
4476
4477/**
4478 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4479 * @phba: lpfc_hba pointer.
4480 * @val: 0 or 1.
4481 *
4482 * Description:
4483 * Set the initial Linux generic firmware upgrade enable or disable flag.
4484 *
4485 * Returns:
4486 * zero if val saved.
4487 * -EINVAL val out of range
4488 **/
4489static int
4490lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4491{
4492 if (val >= 0 && val <= 1) {
4493 phba->cfg_request_firmware_upgrade = val;
4494 return 0;
4495 }
4496 return -EINVAL;
4497}
4498static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4499 lpfc_request_firmware_upgrade_show,
4500 lpfc_request_firmware_upgrade_store);
4501
173edbb2
JS
4502/**
4503 * lpfc_fcp_imax_store
4504 *
4505 * @dev: class device that is converted into a Scsi_host.
4506 * @attr: device attribute, not used.
4507 * @buf: string with the number of fast-path FCP interrupts per second.
4508 * @count: unused variable.
4509 *
4510 * Description:
4511 * If val is in a valid range [636,651042], then set the adapter's
4512 * maximum number of fast-path FCP interrupts per second.
4513 *
4514 * Returns:
4515 * length of the buf on success if val is in range the intended mode
4516 * is supported.
4517 * -EINVAL if val out of range or intended mode is not supported.
4518 **/
4519static ssize_t
4520lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4521 const char *buf, size_t count)
4522{
4523 struct Scsi_Host *shost = class_to_shost(dev);
4524 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4525 struct lpfc_hba *phba = vport->phba;
4526 int val = 0, i;
4527
bf8dae83
JS
4528 /* fcp_imax is only valid for SLI4 */
4529 if (phba->sli_rev != LPFC_SLI_REV4)
4530 return -EINVAL;
4531
173edbb2
JS
4532 /* Sanity check on user data */
4533 if (!isdigit(buf[0]))
4534 return -EINVAL;
4535 if (sscanf(buf, "%i", &val) != 1)
4536 return -EINVAL;
4537
bf8dae83
JS
4538 /*
4539 * Value range for the HBA is [5000,5000000]
4540 * The value for each EQ depends on how many EQs are configured.
895427bd 4541 * Allow value == 0
bf8dae83 4542 */
895427bd 4543 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
173edbb2
JS
4544 return -EINVAL;
4545
4546 phba->cfg_fcp_imax = (uint32_t)val;
0cf07f84 4547 phba->initial_imax = phba->cfg_fcp_imax;
43140ca6
JS
4548
4549 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
0cf07f84
JS
4550 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4551 val);
173edbb2
JS
4552
4553 return strlen(buf);
4554}
4555
4556/*
4557# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
bf8dae83 4558# for the HBA.
173edbb2 4559#
bf8dae83 4560# Value range is [5,000 to 5,000,000]. Default value is 50,000.
173edbb2 4561*/
bf8dae83 4562static int lpfc_fcp_imax = LPFC_DEF_IMAX;
173edbb2
JS
4563module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4564MODULE_PARM_DESC(lpfc_fcp_imax,
bf8dae83 4565 "Set the maximum number of FCP interrupts per second per HBA");
173edbb2
JS
4566lpfc_param_show(fcp_imax)
4567
4568/**
4569 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4570 * @phba: lpfc_hba pointer.
4571 * @val: link speed value.
4572 *
4573 * Description:
4574 * If val is in a valid range [636,651042], then initialize the adapter's
4575 * maximum number of fast-path FCP interrupts per second.
4576 *
4577 * Returns:
4578 * zero if val saved.
4579 * -EINVAL val out of range
4580 **/
4581static int
4582lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4583{
bf8dae83
JS
4584 if (phba->sli_rev != LPFC_SLI_REV4) {
4585 phba->cfg_fcp_imax = 0;
4586 return 0;
4587 }
4588
895427bd
JS
4589 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4590 (val == 0)) {
173edbb2
JS
4591 phba->cfg_fcp_imax = val;
4592 return 0;
4593 }
4594
4595 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6c86068d
JS
4596 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4597 val);
bf8dae83 4598 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
173edbb2
JS
4599
4600 return 0;
4601}
4602
69d725f4 4603static DEVICE_ATTR_RW(lpfc_fcp_imax);
173edbb2 4604
0cf07f84
JS
4605/*
4606 * lpfc_auto_imax: Controls Auto-interrupt coalescing values support.
4607 * 0 No auto_imax support
4608 * 1 auto imax on
4609 * Auto imax will change the value of fcp_imax on a per EQ basis, using
4610 * the EQ Delay Multiplier, depending on the activity for that EQ.
4611 * Value range [0,1]. Default value is 1.
4612 */
4613LPFC_ATTR_RW(auto_imax, 1, 0, 1, "Enable Auto imax");
4614
7bb03bbf
JS
4615/**
4616 * lpfc_state_show - Display current driver CPU affinity
4617 * @dev: class converted to a Scsi_host structure.
4618 * @attr: device attribute, not used.
4619 * @buf: on return contains text describing the state of the link.
4620 *
4621 * Returns: size of formatted string.
4622 **/
4623static ssize_t
4624lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4625 char *buf)
4626{
4627 struct Scsi_Host *shost = class_to_shost(dev);
4628 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4629 struct lpfc_hba *phba = vport->phba;
4630 struct lpfc_vector_map_info *cpup;
76fd07a6 4631 int len = 0;
7bb03bbf
JS
4632
4633 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4634 (phba->intr_type != MSIX))
4635 return len;
4636
4637 switch (phba->cfg_fcp_cpu_map) {
4638 case 0:
4639 len += snprintf(buf + len, PAGE_SIZE-len,
4640 "fcp_cpu_map: No mapping (%d)\n",
4641 phba->cfg_fcp_cpu_map);
4642 return len;
4643 case 1:
4644 len += snprintf(buf + len, PAGE_SIZE-len,
4645 "fcp_cpu_map: HBA centric mapping (%d): "
4646 "%d online CPUs\n",
4647 phba->cfg_fcp_cpu_map,
4648 phba->sli4_hba.num_online_cpu);
4649 break;
4650 case 2:
4651 len += snprintf(buf + len, PAGE_SIZE-len,
4652 "fcp_cpu_map: Driver centric mapping (%d): "
4653 "%d online CPUs\n",
4654 phba->cfg_fcp_cpu_map,
4655 phba->sli4_hba.num_online_cpu);
4656 break;
4657 }
4658
76fd07a6
JS
4659 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4660 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4661
4662 /* margin should fit in this and the truncated message */
7bb03bbf
JS
4663 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4664 len += snprintf(buf + len, PAGE_SIZE-len,
4665 "CPU %02d io_chan %02d "
4666 "physid %d coreid %d\n",
76fd07a6
JS
4667 phba->sli4_hba.curr_disp_cpu,
4668 cpup->channel_id, cpup->phys_id,
7bb03bbf
JS
4669 cpup->core_id);
4670 else
4671 len += snprintf(buf + len, PAGE_SIZE-len,
4672 "CPU %02d io_chan %02d "
4673 "physid %d coreid %d IRQ %d\n",
76fd07a6
JS
4674 phba->sli4_hba.curr_disp_cpu,
4675 cpup->channel_id, cpup->phys_id,
7bb03bbf
JS
4676 cpup->core_id, cpup->irq);
4677
76fd07a6
JS
4678 phba->sli4_hba.curr_disp_cpu++;
4679
4680 /* display max number of CPUs keeping some margin */
4681 if (phba->sli4_hba.curr_disp_cpu <
4682 phba->sli4_hba.num_present_cpu &&
4683 (len >= (PAGE_SIZE - 64))) {
4684 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4685 break;
4686 }
7bb03bbf 4687 }
76fd07a6
JS
4688
4689 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4690 phba->sli4_hba.curr_disp_cpu = 0;
4691
7bb03bbf
JS
4692 return len;
4693}
4694
4695/**
4696 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4697 * @dev: class device that is converted into a Scsi_host.
4698 * @attr: device attribute, not used.
4699 * @buf: one or more lpfc_polling_flags values.
4700 * @count: not used.
4701 *
4702 * Returns:
4703 * -EINVAL - Not implemented yet.
4704 **/
4705static ssize_t
4706lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4707 const char *buf, size_t count)
4708{
4709 int status = -EINVAL;
4710 return status;
4711}
4712
4713/*
4714# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4715# for the HBA.
4716#
4717# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4718# 0 - Do not affinitze IRQ vectors
4719# 1 - Affintize HBA vectors with respect to each HBA
4720# (start with CPU0 for each HBA)
4721# 2 - Affintize HBA vectors with respect to the entire driver
4722# (round robin thru all CPUs across all HBAs)
4723*/
4724static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4725module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4726MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4727 "Defines how to map CPUs to IRQ vectors per HBA");
4728
4729/**
4730 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4731 * @phba: lpfc_hba pointer.
4732 * @val: link speed value.
4733 *
4734 * Description:
4735 * If val is in a valid range [0-2], then affinitze the adapter's
4736 * MSIX vectors.
4737 *
4738 * Returns:
4739 * zero if val saved.
4740 * -EINVAL val out of range
4741 **/
4742static int
4743lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4744{
4745 if (phba->sli_rev != LPFC_SLI_REV4) {
4746 phba->cfg_fcp_cpu_map = 0;
4747 return 0;
4748 }
4749
4750 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4751 phba->cfg_fcp_cpu_map = val;
4752 return 0;
4753 }
4754
4755 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6c86068d
JS
4756 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4757 "default\n", val);
7bb03bbf
JS
4758 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4759
4760 return 0;
4761}
4762
69d725f4 4763static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
7bb03bbf 4764
dea3101e
JB
4765/*
4766# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4767# Value range is [2,3]. Default value is 3.
4768*/
3de2a653
JS
4769LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4770 "Select Fibre Channel class of service for FCP sequences");
dea3101e
JB
4771
4772/*
4773# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4774# is [0,1]. Default value is 0.
4775*/
3de2a653
JS
4776LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4777 "Use ADISC on rediscovery to authenticate FCP devices");
dea3101e 4778
3cb01c57
JS
4779/*
4780# lpfc_first_burst_size: First burst size to use on the NPorts
4781# that support first burst.
4782# Value range is [0,65536]. Default value is 0.
4783*/
4784LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4785 "First burst size for Targets that support first burst");
4786
895427bd 4787/*
2d7dbc4c
JS
4788* lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4789* When the driver is configured as an NVME target, this value is
4790* communicated to the NVME initiator in the PRLI response. It is
4791* used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4792* parameters are set and the target is sending the PRLI RSP.
895427bd 4793* Parameter supported on physical port only - no NPIV support.
2d7dbc4c 4794* Value range is [0,65536]. Default value is 0.
895427bd 4795*/
2d7dbc4c
JS
4796LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4797 "NVME Target mode first burst size in 512B increments.");
4798
4799/*
4800 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4801 * For the Initiator (I), enabling this parameter means that an NVMET
4802 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4803 * processed by the initiator for subsequent NVME FCP IO. For the target
4804 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4805 * driver parameter as the target function's first burst size returned to the
4806 * initiator in the target's NVME PRLI response. Parameter supported on physical
4807 * port only - no NPIV support.
4808 * Value range is [0,1]. Default value is 0 (disabled).
4809 */
895427bd
JS
4810LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4811 "Enable First Burst feature on I and T functions.");
4812
977b5a0a
JS
4813/*
4814# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4815# depth. Default value is 0. When the value of this parameter is zero the
4816# SCSI command completion time is not used for controlling I/O queue depth. When
4817# the parameter is set to a non-zero value, the I/O queue depth is controlled
4818# to limit the I/O completion time to the parameter value.
4819# The value is set in milliseconds.
4820*/
ed5b1529 4821LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
977b5a0a 4822 "Use command completion time to control queue depth");
ed5b1529 4823
977b5a0a 4824lpfc_vport_param_show(max_scsicmpl_time);
977b5a0a
JS
4825static int
4826lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4827{
4828 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4829 struct lpfc_nodelist *ndlp, *next_ndlp;
4830
4831 if (val == vport->cfg_max_scsicmpl_time)
4832 return 0;
4833 if ((val < 0) || (val > 60000))
4834 return -EINVAL;
4835 vport->cfg_max_scsicmpl_time = val;
4836
4837 spin_lock_irq(shost->host_lock);
4838 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4839 if (!NLP_CHK_NODE_ACT(ndlp))
4840 continue;
4841 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4842 continue;
7dc517df 4843 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
977b5a0a
JS
4844 }
4845 spin_unlock_irq(shost->host_lock);
4846 return 0;
4847}
4848lpfc_vport_param_store(max_scsicmpl_time);
69d725f4 4849static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
977b5a0a 4850
dea3101e
JB
4851/*
4852# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4853# range is [0,1]. Default value is 0.
4854*/
4855LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4856
49aa143d 4857/*
895427bd
JS
4858 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4859 * range is [0,1]. Default value is 0.
4860 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4861 * For [1], FCP commands are issued to a Work Queue associated with the
4862 * current CPU.
4863 *
4864 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4865 * LPFC_FCP_SCHED_BY_CPU == 1
4866 *
4867 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4868 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4869 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4870 * through WQs will be used.
4871 */
4872LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4873 LPFC_FCP_SCHED_ROUND_ROBIN,
4874 LPFC_FCP_SCHED_BY_CPU,
4875 "Determine scheduling algorithm for "
4876 "issuing commands [0] - Round Robin, [1] - Current CPU");
49aa143d 4877
a6571c6e
JS
4878/*
4879# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4880# range is [0,1]. Default value is 0.
4881# For [0], bus reset issues target reset to ALL devices
4882# For [1], bus reset issues target reset to non-FCP2 devices
4883*/
4884LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4885 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4886
4887
dea3101e
JB
4888/*
4889# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4890# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
7054a606 4891# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea3101e
JB
4892# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4893# cr_delay is set to 0.
4894*/
8189fd19 4895LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea3101e
JB
4896 "interrupt response is generated");
4897
8189fd19 4898LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea3101e
JB
4899 "interrupt response is generated");
4900
cf5bf97e
JW
4901/*
4902# lpfc_multi_ring_support: Determines how many rings to spread available
4903# cmd/rsp IOCB entries across.
4904# Value range is [1,2]. Default value is 1.
4905*/
4906LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4907 "SLI rings to spread IOCB entries across");
4908
a4bc3379
JS
4909/*
4910# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4911# identifies what rctl value to configure the additional ring for.
4912# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4913*/
6a9c52cf 4914LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
a4bc3379
JS
4915 255, "Identifies RCTL for additional ring configuration");
4916
4917/*
4918# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4919# identifies what type value to configure the additional ring for.
4920# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4921*/
6a9c52cf 4922LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
a4bc3379
JS
4923 255, "Identifies TYPE for additional ring configuration");
4924
dea3101e 4925/*
4258e98e
JS
4926# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4927# 0 = SmartSAN functionality disabled (default)
4928# 1 = SmartSAN functionality enabled
4929# This parameter will override the value of lpfc_fdmi_on module parameter.
4930# Value range is [0,1]. Default value is 0.
dea3101e 4931*/
4258e98e
JS
4932LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4933
4934/*
4935# lpfc_fdmi_on: Controls FDMI support.
4936# 0 No FDMI support (default)
4937# 1 Traditional FDMI support
8663cbbe
JS
4938# Traditional FDMI support means the driver will assume FDMI-2 support;
4939# however, if that fails, it will fallback to FDMI-1.
4940# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4941# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4942# lpfc_fdmi_on.
4943# Value range [0,1]. Default value is 0.
4258e98e 4944*/
8663cbbe 4945LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
dea3101e
JB
4946
4947/*
4948# Specifies the maximum number of ELS cmds we can have outstanding (for
4949# discovery). Value range is [1,64]. Default value = 32.
4950*/
3de2a653 4951LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea3101e
JB
4952 "during discovery");
4953
4954/*
c4a7c922
JS
4955# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4956# will be scanned by the SCSI midlayer when sequential scanning is
4957# used; and is also the highest LUN ID allowed when the SCSI midlayer
4958# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4959# LUN ID limit, but the SCSI midlayer requires this field for the uses
4960# above. The lpfc driver limits the default value to 255 for two reasons.
4961# As it bounds the sequential scan loop, scanning for thousands of luns
4962# on a target can take minutes of wall clock time. Additionally,
4963# there are FC targets, such as JBODs, that only recognize 8-bits of
4964# LUN ID. When they receive a value greater than 8 bits, they chop off
4965# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4966# and so on all as LUN ID 0. This causes the linux kernel, which sees
4967# valid responses at each of the LUN IDs, to believe there are multiple
4968# devices present, when in fact, there is only 1.
4969# A customer that is aware of their target behaviors, and the results as
4970# indicated above, is welcome to increase the lpfc_max_luns value.
4971# As mentioned, this value is not used by the lpfc driver, only the
4972# SCSI midlayer.
65a29c16
JS
4973# Value range is [0,65535]. Default value is 255.
4974# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea3101e 4975*/
1abf635d 4976LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea3101e 4977
875fbdfe
JSEC
4978/*
4979# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4980# Value range is [1,255], default value is 10.
4981*/
4982LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4983 "Milliseconds driver will wait between polling FCP ring");
4984
4ff43246 4985/*
0c411222
JS
4986# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4987# to complete in seconds. Value range is [5,180], default value is 60.
4988*/
4989LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4990 "Maximum time to wait for task management commands to complete");
4991/*
4ff43246
JS
4992# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4993# support this feature
8605c46c 4994# 0 = MSI disabled
4ff43246 4995# 1 = MSI enabled
8605c46c
GK
4996# 2 = MSI-X enabled (default)
4997# Value range is [0,2]. Default value is 2.
4ff43246 4998*/
8605c46c 4999LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
db2378e0 5000 "MSI-X (2), if possible");
4ff43246 5001
67d12733 5002/*
f358dd0c 5003 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
895427bd
JS
5004 *
5005 * 0 = NVME OAS disabled
5006 * 1 = NVME OAS enabled
5007 *
5008 * Value range is [0,1]. Default value is 0.
5009 */
5010LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5011 "Use OAS bit on NVME IOs");
5012
5013/*
5014 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
5015 * will advertise it supports to the SCSI layer. This also will map to
5016 * the number of WQs the driver will create.
5017 *
5018 * 0 = Configure the number of io channels to the number of active CPUs.
5019 * 1,32 = Manually specify how many io channels to use.
5020 *
5021 * Value range is [0,32]. Default value is 4.
5022 */
5023LPFC_ATTR_R(fcp_io_channel,
5024 LPFC_FCP_IO_CHAN_DEF,
5025 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
67d12733
JS
5026 "Set the number of FCP I/O channels");
5027
895427bd
JS
5028/*
5029 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
5030 * will advertise it supports to the NVME layer. This also will map to
5031 * the number of WQs the driver will create.
5032 *
5033 * This module parameter is valid when lpfc_enable_fc4_type is set
5034 * to support NVME.
5035 *
5036 * The NVME Layer will try to create this many, plus 1 administrative
5037 * hardware queue. The administrative queue will always map to WQ 0
5038 * A hardware IO queue maps (qidx) to a specific driver WQ.
5039 *
5040 * 0 = Configure the number of io channels to the number of active CPUs.
5041 * 1,32 = Manually specify how many io channels to use.
5042 *
5043 * Value range is [0,32]. Default value is 0.
5044 */
5045LPFC_ATTR_R(nvme_io_channel,
5046 LPFC_NVME_IO_CHAN_DEF,
5047 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
5048 "Set the number of NVME I/O channels");
5049
13815c83
JS
5050/*
5051# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5052# 0 = HBA resets disabled
5053# 1 = HBA resets enabled (default)
5054# Value range is [0,1]. Default value is 1.
5055*/
5056LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
c3f28afa 5057
13815c83 5058/*
eb7a339e 5059# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
13815c83
JS
5060# 0 = HBA Heartbeat disabled
5061# 1 = HBA Heartbeat enabled (default)
5062# Value range is [0,1]. Default value is 1.
5063*/
eb7a339e 5064LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
92d7f7b0 5065
1ba981fd
JS
5066/*
5067# lpfc_EnableXLane: Enable Express Lane Feature
5068# 0x0 Express Lane Feature disabled
5069# 0x1 Express Lane Feature enabled
5070# Value range is [0,1]. Default value is 0.
5071*/
5072LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5073
5074/*
5075# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5076# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5077# Value range is [0x0,0x7f]. Default value is 0
5078*/
28d7f3df 5079LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
1ba981fd 5080
81301a9b
JS
5081/*
5082# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5083# 0 = BlockGuard disabled (default)
5084# 1 = BlockGuard enabled
5085# Value range is [0,1]. Default value is 0.
5086*/
5087LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5088
ba20c853
JS
5089/*
5090# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5091# 0 = disabled (default)
5092# 1 = enabled
5093# Value range is [0,1]. Default value is 0.
5688d670
JS
5094#
5095# This feature in under investigation and may be supported in the future.
ba20c853
JS
5096*/
5097unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5098
81301a9b
JS
5099/*
5100# lpfc_prot_mask: i
5101# - Bit mask of host protection capabilities used to register with the
5102# SCSI mid-layer
5103# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5104# - Allows you to ultimately specify which profiles to use
5105# - Default will result in registering capabilities for all profiles.
005ffa70
JS
5106# - SHOST_DIF_TYPE1_PROTECTION 1
5107# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5108# - SHOST_DIX_TYPE0_PROTECTION 8
5109# HBA supports DIX Type 0: Host to HBA protection only
5110# - SHOST_DIX_TYPE1_PROTECTION 16
5111# HBA supports DIX Type 1: Host to HBA Type 1 protection
81301a9b
JS
5112#
5113*/
b3b98b74
JS
5114LPFC_ATTR(prot_mask,
5115 (SHOST_DIF_TYPE1_PROTECTION |
5116 SHOST_DIX_TYPE0_PROTECTION |
5117 SHOST_DIX_TYPE1_PROTECTION),
5118 0,
5119 (SHOST_DIF_TYPE1_PROTECTION |
5120 SHOST_DIX_TYPE0_PROTECTION |
5121 SHOST_DIX_TYPE1_PROTECTION),
5122 "T10-DIF host protection capabilities mask");
81301a9b
JS
5123
5124/*
5125# lpfc_prot_guard: i
5126# - Bit mask of protection guard types to register with the SCSI mid-layer
005ffa70 5127# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
81301a9b
JS
5128# - Allows you to ultimately specify which profiles to use
5129# - Default will result in registering capabilities for all guard types
5130#
5131*/
b3b98b74
JS
5132LPFC_ATTR(prot_guard,
5133 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5134 "T10-DIF host protection guard type");
81301a9b 5135
92494144
JS
5136/*
5137 * Delay initial NPort discovery when Clean Address bit is cleared in
5138 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5139 * This parameter can have value 0 or 1.
5140 * When this parameter is set to 0, no delay is added to the initial
5141 * discovery.
5142 * When this parameter is set to non-zero value, initial Nport discovery is
5143 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5144 * accept and FCID/Fabric name/Fabric portname is changed.
5145 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5146 * when Clean Address bit is cleared in FLOGI/FDISC
5147 * accept and FCID/Fabric name/Fabric portname is changed.
5148 * Default value is 0.
5149 */
8eb8b960
JS
5150LPFC_ATTR(delay_discovery, 0, 0, 1,
5151 "Delay NPort discovery when Clean Address bit is cleared.");
81301a9b 5152
83108bd3 5153/*
3621a710 5154 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
96f7077f 5155 * This value can be set to values between 64 and 4096. The default value is
83108bd3
JS
5156 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5157 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
96f7077f
JS
5158 * Because of the additional overhead involved in setting up T10-DIF,
5159 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5160 * and will be limited to 512 if BlockGuard is enabled under SLI3.
83108bd3 5161 */
f414fb4e 5162LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_MIN_SG_SEG_CNT,
83108bd3
JS
5163 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5164
7bdedb34
JS
5165/*
5166 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5167 * 0 = MDS Diagnostics disabled (default)
5168 * 1 = MDS Diagnostics enabled
5169 * Value range is [0,1]. Default value is 0.
5170 */
5171LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5172
44fd7fe3
JS
5173/*
5174 * lpfc_enable_bbcr: Enable BB Credit Recovery
5175 * 0 = BB Credit Recovery disabled
5176 * 1 = BB Credit Recovery enabled (default)
5177 * Value range is [0,1]. Default value is 1.
5178 */
5179LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5180
ee959b00 5181struct device_attribute *lpfc_hba_attrs[] = {
895427bd 5182 &dev_attr_nvme_info,
81301a9b
JS
5183 &dev_attr_bg_info,
5184 &dev_attr_bg_guard_err,
5185 &dev_attr_bg_apptag_err,
5186 &dev_attr_bg_reftag_err,
ee959b00
TJ
5187 &dev_attr_info,
5188 &dev_attr_serialnum,
5189 &dev_attr_modeldesc,
5190 &dev_attr_modelname,
5191 &dev_attr_programtype,
5192 &dev_attr_portnum,
5193 &dev_attr_fwrev,
5194 &dev_attr_hdw,
5195 &dev_attr_option_rom_version,
bbd1ae41 5196 &dev_attr_link_state,
ee959b00 5197 &dev_attr_num_discovered_ports,
84774a4d 5198 &dev_attr_menlo_mgmt_mode,
ee959b00 5199 &dev_attr_lpfc_drvr_version,
45ed1190 5200 &dev_attr_lpfc_enable_fip,
ee959b00
TJ
5201 &dev_attr_lpfc_temp_sensor,
5202 &dev_attr_lpfc_log_verbose,
5203 &dev_attr_lpfc_lun_queue_depth,
7dc517df 5204 &dev_attr_lpfc_tgt_queue_depth,
ee959b00
TJ
5205 &dev_attr_lpfc_hba_queue_depth,
5206 &dev_attr_lpfc_peer_port_login,
5207 &dev_attr_lpfc_nodev_tmo,
5208 &dev_attr_lpfc_devloss_tmo,
895427bd
JS
5209 &dev_attr_lpfc_enable_fc4_type,
5210 &dev_attr_lpfc_xri_split,
ee959b00
TJ
5211 &dev_attr_lpfc_fcp_class,
5212 &dev_attr_lpfc_use_adisc,
3cb01c57 5213 &dev_attr_lpfc_first_burst_size,
ee959b00
TJ
5214 &dev_attr_lpfc_ack0,
5215 &dev_attr_lpfc_topology,
5216 &dev_attr_lpfc_scan_down,
5217 &dev_attr_lpfc_link_speed,
49aa143d 5218 &dev_attr_lpfc_fcp_io_sched,
a6571c6e 5219 &dev_attr_lpfc_fcp2_no_tgt_reset,
ee959b00
TJ
5220 &dev_attr_lpfc_cr_delay,
5221 &dev_attr_lpfc_cr_count,
5222 &dev_attr_lpfc_multi_ring_support,
5223 &dev_attr_lpfc_multi_ring_rctl,
5224 &dev_attr_lpfc_multi_ring_type,
5225 &dev_attr_lpfc_fdmi_on,
4258e98e 5226 &dev_attr_lpfc_enable_SmartSAN,
ee959b00
TJ
5227 &dev_attr_lpfc_max_luns,
5228 &dev_attr_lpfc_enable_npiv,
7d791df7 5229 &dev_attr_lpfc_fcf_failover_policy,
19ca7609 5230 &dev_attr_lpfc_enable_rrq,
ee959b00
TJ
5231 &dev_attr_nport_evt_cnt,
5232 &dev_attr_board_mode,
5233 &dev_attr_max_vpi,
5234 &dev_attr_used_vpi,
5235 &dev_attr_max_rpi,
5236 &dev_attr_used_rpi,
5237 &dev_attr_max_xri,
5238 &dev_attr_used_xri,
5239 &dev_attr_npiv_info,
5240 &dev_attr_issue_reset,
5241 &dev_attr_lpfc_poll,
5242 &dev_attr_lpfc_poll_tmo,
0c411222 5243 &dev_attr_lpfc_task_mgmt_tmo,
ee959b00 5244 &dev_attr_lpfc_use_msi,
895427bd 5245 &dev_attr_lpfc_nvme_oas,
0cf07f84 5246 &dev_attr_lpfc_auto_imax,
da0436e9 5247 &dev_attr_lpfc_fcp_imax,
7bb03bbf 5248 &dev_attr_lpfc_fcp_cpu_map,
67d12733 5249 &dev_attr_lpfc_fcp_io_channel,
f358dd0c 5250 &dev_attr_lpfc_suppress_rsp,
895427bd 5251 &dev_attr_lpfc_nvme_io_channel,
2d7dbc4c 5252 &dev_attr_lpfc_nvmet_mrq,
895427bd 5253 &dev_attr_lpfc_nvme_enable_fb,
2d7dbc4c 5254 &dev_attr_lpfc_nvmet_fb_size,
81301a9b 5255 &dev_attr_lpfc_enable_bg,
352e5fd1
JS
5256 &dev_attr_lpfc_soft_wwnn,
5257 &dev_attr_lpfc_soft_wwpn,
5258 &dev_attr_lpfc_soft_wwn_enable,
ee959b00
TJ
5259 &dev_attr_lpfc_enable_hba_reset,
5260 &dev_attr_lpfc_enable_hba_heartbeat,
1ba981fd
JS
5261 &dev_attr_lpfc_EnableXLane,
5262 &dev_attr_lpfc_XLanePriority,
5263 &dev_attr_lpfc_xlane_lun,
5264 &dev_attr_lpfc_xlane_tgt,
5265 &dev_attr_lpfc_xlane_vpt,
5266 &dev_attr_lpfc_xlane_lun_state,
5267 &dev_attr_lpfc_xlane_lun_status,
c92c841c 5268 &dev_attr_lpfc_xlane_priority,
ee959b00 5269 &dev_attr_lpfc_sg_seg_cnt,
977b5a0a 5270 &dev_attr_lpfc_max_scsicmpl_time,
ea2151b4 5271 &dev_attr_lpfc_stat_data_ctrl,
0d878419
JS
5272 &dev_attr_lpfc_aer_support,
5273 &dev_attr_lpfc_aer_state_cleanup,
912e3acd 5274 &dev_attr_lpfc_sriov_nr_virtfn,
c71ab861 5275 &dev_attr_lpfc_req_fw_upgrade,
84d1b006 5276 &dev_attr_lpfc_suppress_link_up,
2a9bf3d0
JS
5277 &dev_attr_lpfc_iocb_cnt,
5278 &dev_attr_iocb_hw,
5279 &dev_attr_txq_hw,
5280 &dev_attr_txcmplq_hw,
bc73905a
JS
5281 &dev_attr_lpfc_fips_level,
5282 &dev_attr_lpfc_fips_rev,
ab56dc2e 5283 &dev_attr_lpfc_dss,
912e3acd 5284 &dev_attr_lpfc_sriov_hw_max_virtfn,
026abb87 5285 &dev_attr_protocol,
1ba981fd 5286 &dev_attr_lpfc_xlane_supported,
7bdedb34 5287 &dev_attr_lpfc_enable_mds_diags,
44fd7fe3 5288 &dev_attr_lpfc_enable_bbcr,
dea3101e
JB
5289 NULL,
5290};
5291
ee959b00
TJ
5292struct device_attribute *lpfc_vport_attrs[] = {
5293 &dev_attr_info,
bbd1ae41 5294 &dev_attr_link_state,
ee959b00
TJ
5295 &dev_attr_num_discovered_ports,
5296 &dev_attr_lpfc_drvr_version,
5297 &dev_attr_lpfc_log_verbose,
5298 &dev_attr_lpfc_lun_queue_depth,
7dc517df 5299 &dev_attr_lpfc_tgt_queue_depth,
ee959b00
TJ
5300 &dev_attr_lpfc_nodev_tmo,
5301 &dev_attr_lpfc_devloss_tmo,
5302 &dev_attr_lpfc_hba_queue_depth,
5303 &dev_attr_lpfc_peer_port_login,
5304 &dev_attr_lpfc_restrict_login,
5305 &dev_attr_lpfc_fcp_class,
5306 &dev_attr_lpfc_use_adisc,
3cb01c57 5307 &dev_attr_lpfc_first_burst_size,
ee959b00
TJ
5308 &dev_attr_lpfc_max_luns,
5309 &dev_attr_nport_evt_cnt,
5310 &dev_attr_npiv_info,
5311 &dev_attr_lpfc_enable_da_id,
ea2151b4
JS
5312 &dev_attr_lpfc_max_scsicmpl_time,
5313 &dev_attr_lpfc_stat_data_ctrl,
21e9a0a5 5314 &dev_attr_lpfc_static_vport,
bc73905a
JS
5315 &dev_attr_lpfc_fips_level,
5316 &dev_attr_lpfc_fips_rev,
3de2a653
JS
5317 NULL,
5318};
5319
e59058c4 5320/**
3621a710 5321 * sysfs_ctlreg_write - Write method for writing to ctlreg
2c3c8bea 5322 * @filp: open sysfs file
e59058c4
JS
5323 * @kobj: kernel kobject that contains the kernel class device.
5324 * @bin_attr: kernel attributes passed to us.
5325 * @buf: contains the data to be written to the adapter IOREG space.
5326 * @off: offset into buffer to beginning of data.
5327 * @count: bytes to transfer.
5328 *
5329 * Description:
5330 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5331 * Uses the adapter io control registers to send buf contents to the adapter.
5332 *
5333 * Returns:
5334 * -ERANGE off and count combo out of range
5335 * -EINVAL off, count or buff address invalid
5336 * -EPERM adapter is offline
5337 * value of count, buf contents written
5338 **/
dea3101e 5339static ssize_t
2c3c8bea
CW
5340sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5341 struct bin_attribute *bin_attr,
91a69029 5342 char *buf, loff_t off, size_t count)
dea3101e
JB
5343{
5344 size_t buf_off;
ee959b00
TJ
5345 struct device *dev = container_of(kobj, struct device, kobj);
5346 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
5347 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5348 struct lpfc_hba *phba = vport->phba;
dea3101e 5349
f1126688
JS
5350 if (phba->sli_rev >= LPFC_SLI_REV4)
5351 return -EPERM;
5352
dea3101e
JB
5353 if ((off + count) > FF_REG_AREA_SIZE)
5354 return -ERANGE;
5355
f7a919b4
JS
5356 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5357 return 0;
dea3101e
JB
5358
5359 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5360 return -EINVAL;
5361
f7a919b4
JS
5362 /* This is to protect HBA registers from accidental writes. */
5363 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5364 return -EINVAL;
5365
5366 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea3101e 5367 return -EPERM;
dea3101e 5368
2e0fef85 5369 spin_lock_irq(&phba->hbalock);
f7a919b4
JS
5370 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5371 buf_off += sizeof(uint32_t))
5372 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea3101e
JB
5373 phba->ctrl_regs_memmap_p + off + buf_off);
5374
2e0fef85 5375 spin_unlock_irq(&phba->hbalock);
dea3101e
JB
5376
5377 return count;
5378}
5379
e59058c4 5380/**
3621a710 5381 * sysfs_ctlreg_read - Read method for reading from ctlreg
2c3c8bea 5382 * @filp: open sysfs file
e59058c4
JS
5383 * @kobj: kernel kobject that contains the kernel class device.
5384 * @bin_attr: kernel attributes passed to us.
af901ca1 5385 * @buf: if successful contains the data from the adapter IOREG space.
e59058c4
JS
5386 * @off: offset into buffer to beginning of data.
5387 * @count: bytes to transfer.
5388 *
5389 * Description:
5390 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5391 * Uses the adapter io control registers to read data into buf.
5392 *
5393 * Returns:
5394 * -ERANGE off and count combo out of range
5395 * -EINVAL off, count or buff address invalid
5396 * value of count, buf contents read
5397 **/
dea3101e 5398static ssize_t
2c3c8bea
CW
5399sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5400 struct bin_attribute *bin_attr,
91a69029 5401 char *buf, loff_t off, size_t count)
dea3101e
JB
5402{
5403 size_t buf_off;
5404 uint32_t * tmp_ptr;
ee959b00
TJ
5405 struct device *dev = container_of(kobj, struct device, kobj);
5406 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
5407 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5408 struct lpfc_hba *phba = vport->phba;
dea3101e 5409
f1126688
JS
5410 if (phba->sli_rev >= LPFC_SLI_REV4)
5411 return -EPERM;
5412
dea3101e
JB
5413 if (off > FF_REG_AREA_SIZE)
5414 return -ERANGE;
5415
5416 if ((off + count) > FF_REG_AREA_SIZE)
5417 count = FF_REG_AREA_SIZE - off;
5418
5419 if (count == 0) return 0;
5420
5421 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5422 return -EINVAL;
5423
2e0fef85 5424 spin_lock_irq(&phba->hbalock);
dea3101e
JB
5425
5426 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5427 tmp_ptr = (uint32_t *)(buf + buf_off);
5428 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5429 }
5430
2e0fef85 5431 spin_unlock_irq(&phba->hbalock);
dea3101e
JB
5432
5433 return count;
5434}
5435
5436static struct bin_attribute sysfs_ctlreg_attr = {
5437 .attr = {
5438 .name = "ctlreg",
5439 .mode = S_IRUSR | S_IWUSR,
dea3101e
JB
5440 },
5441 .size = 256,
5442 .read = sysfs_ctlreg_read,
5443 .write = sysfs_ctlreg_write,
5444};
5445
e59058c4 5446/**
3621a710 5447 * sysfs_mbox_write - Write method for writing information via mbox
2c3c8bea 5448 * @filp: open sysfs file
e59058c4
JS
5449 * @kobj: kernel kobject that contains the kernel class device.
5450 * @bin_attr: kernel attributes passed to us.
5451 * @buf: contains the data to be written to sysfs mbox.
5452 * @off: offset into buffer to beginning of data.
5453 * @count: bytes to transfer.
5454 *
5455 * Description:
026abb87
JS
5456 * Deprecated function. All mailbox access from user space is performed via the
5457 * bsg interface.
e59058c4
JS
5458 *
5459 * Returns:
026abb87 5460 * -EPERM operation not permitted
e59058c4 5461 **/
dea3101e 5462static ssize_t
2c3c8bea
CW
5463sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5464 struct bin_attribute *bin_attr,
91a69029 5465 char *buf, loff_t off, size_t count)
dea3101e 5466{
026abb87 5467 return -EPERM;
dea3101e
JB
5468}
5469
e59058c4 5470/**
3621a710 5471 * sysfs_mbox_read - Read method for reading information via mbox
2c3c8bea 5472 * @filp: open sysfs file
e59058c4
JS
5473 * @kobj: kernel kobject that contains the kernel class device.
5474 * @bin_attr: kernel attributes passed to us.
5475 * @buf: contains the data to be read from sysfs mbox.
5476 * @off: offset into buffer to beginning of data.
5477 * @count: bytes to transfer.
5478 *
5479 * Description:
026abb87
JS
5480 * Deprecated function. All mailbox access from user space is performed via the
5481 * bsg interface.
e59058c4
JS
5482 *
5483 * Returns:
026abb87 5484 * -EPERM operation not permitted
e59058c4 5485 **/
dea3101e 5486static ssize_t
2c3c8bea
CW
5487sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5488 struct bin_attribute *bin_attr,
91a69029 5489 char *buf, loff_t off, size_t count)
dea3101e 5490{
026abb87 5491 return -EPERM;
dea3101e
JB
5492}
5493
5494static struct bin_attribute sysfs_mbox_attr = {
5495 .attr = {
5496 .name = "mbox",
5497 .mode = S_IRUSR | S_IWUSR,
dea3101e 5498 },
c0c11512 5499 .size = MAILBOX_SYSFS_MAX,
dea3101e
JB
5500 .read = sysfs_mbox_read,
5501 .write = sysfs_mbox_write,
5502};
5503
e59058c4 5504/**
3621a710 5505 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
e59058c4
JS
5506 * @vport: address of lpfc vport structure.
5507 *
5508 * Return codes:
5509 * zero on success
5510 * error return code from sysfs_create_bin_file()
5511 **/
dea3101e 5512int
2e0fef85 5513lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea3101e 5514{
2e0fef85 5515 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea3101e
JB
5516 int error;
5517
ee959b00 5518 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
eada272d
JS
5519 &sysfs_drvr_stat_data_attr);
5520
5521 /* Virtual ports do not need ctrl_reg and mbox */
5522 if (error || vport->port_type == LPFC_NPIV_PORT)
dea3101e
JB
5523 goto out;
5524
ee959b00 5525 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
eada272d 5526 &sysfs_ctlreg_attr);
dea3101e 5527 if (error)
eada272d 5528 goto out_remove_stat_attr;
dea3101e 5529
ea2151b4 5530 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
eada272d 5531 &sysfs_mbox_attr);
ea2151b4 5532 if (error)
eada272d 5533 goto out_remove_ctlreg_attr;
ea2151b4 5534
dea3101e
JB
5535 return 0;
5536out_remove_ctlreg_attr:
ee959b00 5537 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
eada272d
JS
5538out_remove_stat_attr:
5539 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5540 &sysfs_drvr_stat_data_attr);
dea3101e
JB
5541out:
5542 return error;
5543}
5544
e59058c4 5545/**
3621a710 5546 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
e59058c4
JS
5547 * @vport: address of lpfc vport structure.
5548 **/
dea3101e 5549void
2e0fef85 5550lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea3101e 5551{
2e0fef85 5552 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
ea2151b4
JS
5553 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5554 &sysfs_drvr_stat_data_attr);
eada272d
JS
5555 /* Virtual ports do not need ctrl_reg and mbox */
5556 if (vport->port_type == LPFC_NPIV_PORT)
5557 return;
ee959b00
TJ
5558 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5559 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea3101e
JB
5560}
5561
dea3101e
JB
5562/*
5563 * Dynamic FC Host Attributes Support
5564 */
5565
6c9231f6
JS
5566/**
5567 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5568 * @shost: kernel scsi host pointer.
5569 **/
5570static void
5571lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5572{
5573 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5574
5575 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5576 sizeof fc_host_symbolic_name(shost));
5577}
5578
e59058c4 5579/**
3621a710 5580 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
e59058c4
JS
5581 * @shost: kernel scsi host pointer.
5582 **/
dea3101e
JB
5583static void
5584lpfc_get_host_port_id(struct Scsi_Host *shost)
5585{
2e0fef85
JS
5586 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5587
dea3101e 5588 /* note: fc_myDID already in cpu endianness */
2e0fef85 5589 fc_host_port_id(shost) = vport->fc_myDID;
dea3101e
JB
5590}
5591
e59058c4 5592/**
3621a710 5593 * lpfc_get_host_port_type - Set the value of the scsi host port type
e59058c4
JS
5594 * @shost: kernel scsi host pointer.
5595 **/
dea3101e
JB
5596static void
5597lpfc_get_host_port_type(struct Scsi_Host *shost)
5598{
2e0fef85
JS
5599 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5600 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
5601
5602 spin_lock_irq(shost->host_lock);
5603
92d7f7b0
JS
5604 if (vport->port_type == LPFC_NPIV_PORT) {
5605 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5606 } else if (lpfc_is_link_up(phba)) {
76a95d75 5607 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2e0fef85 5608 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea3101e
JB
5609 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5610 else
5611 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5612 } else {
2e0fef85 5613 if (vport->fc_flag & FC_FABRIC)
dea3101e
JB
5614 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5615 else
5616 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5617 }
5618 } else
5619 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5620
5621 spin_unlock_irq(shost->host_lock);
5622}
5623
e59058c4 5624/**
3621a710 5625 * lpfc_get_host_port_state - Set the value of the scsi host port state
e59058c4
JS
5626 * @shost: kernel scsi host pointer.
5627 **/
dea3101e
JB
5628static void
5629lpfc_get_host_port_state(struct Scsi_Host *shost)
5630{
2e0fef85
JS
5631 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5632 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
5633
5634 spin_lock_irq(shost->host_lock);
5635
2e0fef85 5636 if (vport->fc_flag & FC_OFFLINE_MODE)
dea3101e
JB
5637 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5638 else {
2e0fef85
JS
5639 switch (phba->link_state) {
5640 case LPFC_LINK_UNKNOWN:
dea3101e
JB
5641 case LPFC_LINK_DOWN:
5642 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5643 break;
5644 case LPFC_LINK_UP:
dea3101e
JB
5645 case LPFC_CLEAR_LA:
5646 case LPFC_HBA_READY:
026abb87
JS
5647 /* Links up, reports port state accordingly */
5648 if (vport->port_state < LPFC_VPORT_READY)
5649 fc_host_port_state(shost) =
5650 FC_PORTSTATE_BYPASSED;
5651 else
5652 fc_host_port_state(shost) =
5653 FC_PORTSTATE_ONLINE;
dea3101e
JB
5654 break;
5655 case LPFC_HBA_ERROR:
5656 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5657 break;
5658 default:
5659 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5660 break;
5661 }
5662 }
5663
5664 spin_unlock_irq(shost->host_lock);
5665}
5666
e59058c4 5667/**
3621a710 5668 * lpfc_get_host_speed - Set the value of the scsi host speed
e59058c4
JS
5669 * @shost: kernel scsi host pointer.
5670 **/
dea3101e
JB
5671static void
5672lpfc_get_host_speed(struct Scsi_Host *shost)
5673{
2e0fef85
JS
5674 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5675 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
5676
5677 spin_lock_irq(shost->host_lock);
5678
a085e87c 5679 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea3101e 5680 switch(phba->fc_linkspeed) {
76a95d75
JS
5681 case LPFC_LINK_SPEED_1GHZ:
5682 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea3101e 5683 break;
76a95d75
JS
5684 case LPFC_LINK_SPEED_2GHZ:
5685 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea3101e 5686 break;
76a95d75
JS
5687 case LPFC_LINK_SPEED_4GHZ:
5688 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea3101e 5689 break;
76a95d75
JS
5690 case LPFC_LINK_SPEED_8GHZ:
5691 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
b87eab38 5692 break;
76a95d75
JS
5693 case LPFC_LINK_SPEED_10GHZ:
5694 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
f4b4c68f 5695 break;
76a95d75
JS
5696 case LPFC_LINK_SPEED_16GHZ:
5697 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5698 break;
d38dd52c
JS
5699 case LPFC_LINK_SPEED_32GHZ:
5700 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5701 break;
76a95d75
JS
5702 default:
5703 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea3101e
JB
5704 break;
5705 }
09372820
JS
5706 } else
5707 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea3101e
JB
5708
5709 spin_unlock_irq(shost->host_lock);
5710}
5711
e59058c4 5712/**
3621a710 5713 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
e59058c4
JS
5714 * @shost: kernel scsi host pointer.
5715 **/
dea3101e
JB
5716static void
5717lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5718{
2e0fef85
JS
5719 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5720 struct lpfc_hba *phba = vport->phba;
f631b4be 5721 u64 node_name;
dea3101e
JB
5722
5723 spin_lock_irq(shost->host_lock);
5724
73d91e50
JS
5725 if ((vport->port_state > LPFC_FLOGI) &&
5726 ((vport->fc_flag & FC_FABRIC) ||
5727 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5728 (vport->fc_flag & FC_PUBLIC_LOOP))))
68ce1eb5 5729 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea3101e
JB
5730 else
5731 /* fabric is local port if there is no F/FL_Port */
09372820 5732 node_name = 0;
dea3101e
JB
5733
5734 spin_unlock_irq(shost->host_lock);
5735
f631b4be 5736 fc_host_fabric_name(shost) = node_name;
dea3101e
JB
5737}
5738
e59058c4 5739/**
3621a710 5740 * lpfc_get_stats - Return statistical information about the adapter
e59058c4
JS
5741 * @shost: kernel scsi host pointer.
5742 *
5743 * Notes:
5744 * NULL on error for link down, no mbox pool, sli2 active,
5745 * management not allowed, memory allocation error, or mbox error.
5746 *
5747 * Returns:
5748 * NULL for error
5749 * address of the adapter host statistics
5750 **/
dea3101e
JB
5751static struct fc_host_statistics *
5752lpfc_get_stats(struct Scsi_Host *shost)
5753{
2e0fef85
JS
5754 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5755 struct lpfc_hba *phba = vport->phba;
5756 struct lpfc_sli *psli = &phba->sli;
f888ba3c 5757 struct fc_host_statistics *hs = &phba->link_stats;
64ba8818 5758 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea3101e
JB
5759 LPFC_MBOXQ_t *pmboxq;
5760 MAILBOX_t *pmb;
64ba8818 5761 unsigned long seconds;
433c3579 5762 int rc = 0;
dea3101e 5763
92d7f7b0
JS
5764 /*
5765 * prevent udev from issuing mailbox commands until the port is
5766 * configured.
5767 */
2e0fef85
JS
5768 if (phba->link_state < LPFC_LINK_DOWN ||
5769 !phba->mbox_mem_pool ||
f4b4c68f 5770 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
92d7f7b0 5771 return NULL;
2e0fef85
JS
5772
5773 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
46fa311e
JS
5774 return NULL;
5775
dea3101e
JB
5776 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5777 if (!pmboxq)
5778 return NULL;
5779 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5780
04c68496 5781 pmb = &pmboxq->u.mb;
dea3101e
JB
5782 pmb->mbxCommand = MBX_READ_STATUS;
5783 pmb->mbxOwner = OWN_HOST;
5784 pmboxq->context1 = NULL;
92d7f7b0 5785 pmboxq->vport = vport;
dea3101e 5786
75baf696 5787 if (vport->fc_flag & FC_OFFLINE_MODE)
dea3101e 5788 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
433c3579 5789 else
dea3101e
JB
5790 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5791
5792 if (rc != MBX_SUCCESS) {
858c9f6c 5793 if (rc != MBX_TIMEOUT)
433c3579 5794 mempool_free(pmboxq, phba->mbox_mem_pool);
dea3101e
JB
5795 return NULL;
5796 }
5797
f888ba3c
JSEC
5798 memset(hs, 0, sizeof (struct fc_host_statistics));
5799
dea3101e 5800 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
73d91e50
JS
5801 /*
5802 * The MBX_READ_STATUS returns tx_k_bytes which has to
5803 * converted to words
5804 */
5805 hs->tx_words = (uint64_t)
5806 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5807 * (uint64_t)256);
dea3101e 5808 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
73d91e50
JS
5809 hs->rx_words = (uint64_t)
5810 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5811 * (uint64_t)256);
dea3101e 5812
433c3579 5813 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea3101e
JB
5814 pmb->mbxCommand = MBX_READ_LNK_STAT;
5815 pmb->mbxOwner = OWN_HOST;
5816 pmboxq->context1 = NULL;
92d7f7b0 5817 pmboxq->vport = vport;
dea3101e 5818
75baf696 5819 if (vport->fc_flag & FC_OFFLINE_MODE)
dea3101e 5820 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
433c3579 5821 else
dea3101e
JB
5822 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5823
5824 if (rc != MBX_SUCCESS) {
858c9f6c 5825 if (rc != MBX_TIMEOUT)
92d7f7b0 5826 mempool_free(pmboxq, phba->mbox_mem_pool);
dea3101e
JB
5827 return NULL;
5828 }
5829
5830 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5831 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5832 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5833 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5834 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5835 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5836 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5837
64ba8818
JS
5838 hs->link_failure_count -= lso->link_failure_count;
5839 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5840 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5841 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5842 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5843 hs->invalid_crc_count -= lso->invalid_crc_count;
5844 hs->error_frames -= lso->error_frames;
5845
76a95d75 5846 if (phba->hba_flag & HBA_FCOE_MODE) {
4d9ab994
JS
5847 hs->lip_count = -1;
5848 hs->nos_count = (phba->link_events >> 1);
5849 hs->nos_count -= lso->link_events;
76a95d75 5850 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea3101e 5851 hs->lip_count = (phba->fc_eventTag >> 1);
64ba8818 5852 hs->lip_count -= lso->link_events;
dea3101e
JB
5853 hs->nos_count = -1;
5854 } else {
5855 hs->lip_count = -1;
5856 hs->nos_count = (phba->fc_eventTag >> 1);
64ba8818 5857 hs->nos_count -= lso->link_events;
dea3101e
JB
5858 }
5859
5860 hs->dumped_frames = -1;
5861
64ba8818
JS
5862 seconds = get_seconds();
5863 if (seconds < psli->stats_start)
5864 hs->seconds_since_last_reset = seconds +
5865 ((unsigned long)-1 - psli->stats_start);
5866 else
5867 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea3101e 5868
1dcb58e5
JS
5869 mempool_free(pmboxq, phba->mbox_mem_pool);
5870
dea3101e
JB
5871 return hs;
5872}
5873
e59058c4 5874/**
3621a710 5875 * lpfc_reset_stats - Copy the adapter link stats information
e59058c4
JS
5876 * @shost: kernel scsi host pointer.
5877 **/
64ba8818
JS
5878static void
5879lpfc_reset_stats(struct Scsi_Host *shost)
5880{
2e0fef85
JS
5881 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5882 struct lpfc_hba *phba = vport->phba;
5883 struct lpfc_sli *psli = &phba->sli;
5884 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
64ba8818
JS
5885 LPFC_MBOXQ_t *pmboxq;
5886 MAILBOX_t *pmb;
5887 int rc = 0;
5888
2e0fef85 5889 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
46fa311e
JS
5890 return;
5891
64ba8818
JS
5892 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5893 if (!pmboxq)
5894 return;
5895 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5896
04c68496 5897 pmb = &pmboxq->u.mb;
64ba8818
JS
5898 pmb->mbxCommand = MBX_READ_STATUS;
5899 pmb->mbxOwner = OWN_HOST;
5900 pmb->un.varWords[0] = 0x1; /* reset request */
5901 pmboxq->context1 = NULL;
92d7f7b0 5902 pmboxq->vport = vport;
64ba8818 5903
2e0fef85 5904 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
f4b4c68f 5905 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
64ba8818
JS
5906 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5907 else
5908 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5909
5910 if (rc != MBX_SUCCESS) {
858c9f6c 5911 if (rc != MBX_TIMEOUT)
64ba8818
JS
5912 mempool_free(pmboxq, phba->mbox_mem_pool);
5913 return;
5914 }
5915
5916 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5917 pmb->mbxCommand = MBX_READ_LNK_STAT;
5918 pmb->mbxOwner = OWN_HOST;
5919 pmboxq->context1 = NULL;
92d7f7b0 5920 pmboxq->vport = vport;
64ba8818 5921
2e0fef85 5922 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
f4b4c68f 5923 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
64ba8818
JS
5924 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5925 else
5926 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5927
5928 if (rc != MBX_SUCCESS) {
858c9f6c 5929 if (rc != MBX_TIMEOUT)
64ba8818
JS
5930 mempool_free( pmboxq, phba->mbox_mem_pool);
5931 return;
5932 }
5933
5934 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5935 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5936 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5937 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5938 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5939 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5940 lso->error_frames = pmb->un.varRdLnk.crcCnt;
76a95d75 5941 if (phba->hba_flag & HBA_FCOE_MODE)
4d9ab994
JS
5942 lso->link_events = (phba->link_events >> 1);
5943 else
5944 lso->link_events = (phba->fc_eventTag >> 1);
64ba8818
JS
5945
5946 psli->stats_start = get_seconds();
5947
1dcb58e5
JS
5948 mempool_free(pmboxq, phba->mbox_mem_pool);
5949
64ba8818
JS
5950 return;
5951}
dea3101e
JB
5952
5953/*
5954 * The LPFC driver treats linkdown handling as target loss events so there
5955 * are no sysfs handlers for link_down_tmo.
5956 */
685f0bf7 5957
e59058c4 5958/**
3621a710 5959 * lpfc_get_node_by_target - Return the nodelist for a target
e59058c4
JS
5960 * @starget: kernel scsi target pointer.
5961 *
5962 * Returns:
5963 * address of the node list if found
5964 * NULL target not found
5965 **/
685f0bf7
JS
5966static struct lpfc_nodelist *
5967lpfc_get_node_by_target(struct scsi_target *starget)
dea3101e 5968{
2e0fef85
JS
5969 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5970 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
685f0bf7 5971 struct lpfc_nodelist *ndlp;
dea3101e
JB
5972
5973 spin_lock_irq(shost->host_lock);
685f0bf7 5974 /* Search for this, mapped, target ID */
2e0fef85 5975 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
e47c9093
JS
5976 if (NLP_CHK_NODE_ACT(ndlp) &&
5977 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
685f0bf7
JS
5978 starget->id == ndlp->nlp_sid) {
5979 spin_unlock_irq(shost->host_lock);
5980 return ndlp;
dea3101e
JB
5981 }
5982 }
5983 spin_unlock_irq(shost->host_lock);
685f0bf7
JS
5984 return NULL;
5985}
dea3101e 5986
e59058c4 5987/**
3621a710 5988 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
e59058c4
JS
5989 * @starget: kernel scsi target pointer.
5990 **/
685f0bf7
JS
5991static void
5992lpfc_get_starget_port_id(struct scsi_target *starget)
5993{
5994 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5995
5996 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea3101e
JB
5997}
5998
e59058c4 5999/**
3621a710 6000 * lpfc_get_starget_node_name - Set the target node name
e59058c4
JS
6001 * @starget: kernel scsi target pointer.
6002 *
6003 * Description: Set the target node name to the ndlp node name wwn or zero.
6004 **/
dea3101e
JB
6005static void
6006lpfc_get_starget_node_name(struct scsi_target *starget)
6007{
685f0bf7 6008 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea3101e 6009
685f0bf7
JS
6010 fc_starget_node_name(starget) =
6011 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea3101e
JB
6012}
6013
e59058c4 6014/**
3621a710 6015 * lpfc_get_starget_port_name - Set the target port name
e59058c4
JS
6016 * @starget: kernel scsi target pointer.
6017 *
6018 * Description: set the target port name to the ndlp port name wwn or zero.
6019 **/
dea3101e
JB
6020static void
6021lpfc_get_starget_port_name(struct scsi_target *starget)
6022{
685f0bf7 6023 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea3101e 6024
685f0bf7
JS
6025 fc_starget_port_name(starget) =
6026 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea3101e
JB
6027}
6028
e59058c4 6029/**
3621a710 6030 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
e59058c4
JS
6031 * @rport: fc rport address.
6032 * @timeout: new value for dev loss tmo.
6033 *
6034 * Description:
6035 * If timeout is non zero set the dev_loss_tmo to timeout, else set
6036 * dev_loss_tmo to one.
6037 **/
dea3101e
JB
6038static void
6039lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6040{
dea3101e 6041 if (timeout)
c01f3208 6042 rport->dev_loss_tmo = timeout;
dea3101e 6043 else
c01f3208 6044 rport->dev_loss_tmo = 1;
dea3101e
JB
6045}
6046
e59058c4 6047/**
3621a710 6048 * lpfc_rport_show_function - Return rport target information
e59058c4
JS
6049 *
6050 * Description:
6051 * Macro that uses field to generate a function with the name lpfc_show_rport_
6052 *
6053 * lpfc_show_rport_##field: returns the bytes formatted in buf
6054 * @cdev: class converted to an fc_rport.
6055 * @buf: on return contains the target_field or zero.
6056 *
6057 * Returns: size of formatted string.
6058 **/
dea3101e
JB
6059#define lpfc_rport_show_function(field, format_string, sz, cast) \
6060static ssize_t \
ee959b00
TJ
6061lpfc_show_rport_##field (struct device *dev, \
6062 struct device_attribute *attr, \
6063 char *buf) \
dea3101e 6064{ \
ee959b00 6065 struct fc_rport *rport = transport_class_to_rport(dev); \
dea3101e
JB
6066 struct lpfc_rport_data *rdata = rport->hostdata; \
6067 return snprintf(buf, sz, format_string, \
6068 (rdata->target) ? cast rdata->target->field : 0); \
6069}
6070
6071#define lpfc_rport_rd_attr(field, format_string, sz) \
6072 lpfc_rport_show_function(field, format_string, sz, ) \
6073static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6074
eada272d 6075/**
3621a710 6076 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
eada272d
JS
6077 * @fc_vport: The fc_vport who's symbolic name has been changed.
6078 *
6079 * Description:
6080 * This function is called by the transport after the @fc_vport's symbolic name
6081 * has been changed. This function re-registers the symbolic name with the
25985edc 6082 * switch to propagate the change into the fabric if the vport is active.
eada272d
JS
6083 **/
6084static void
6085lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6086{
6087 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6088
6089 if (vport->port_state == LPFC_VPORT_READY)
6090 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6091}
dea3101e 6092
f4b4c68f
JS
6093/**
6094 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6095 * @phba: Pointer to lpfc_hba struct.
6096 *
6097 * This function is called by the lpfc_get_cfgparam() routine to set the
6098 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
70f23fd6 6099 * log message according to the module's lpfc_log_verbose parameter setting
f4b4c68f
JS
6100 * before hba port or vport created.
6101 **/
6102static void
6103lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6104{
6105 phba->cfg_log_verbose = verbose;
6106}
6107
dea3101e
JB
6108struct fc_function_template lpfc_transport_functions = {
6109 /* fixed attributes the driver supports */
6110 .show_host_node_name = 1,
6111 .show_host_port_name = 1,
6112 .show_host_supported_classes = 1,
6113 .show_host_supported_fc4s = 1,
dea3101e
JB
6114 .show_host_supported_speeds = 1,
6115 .show_host_maxframe_size = 1,
6c9231f6
JS
6116
6117 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
eada272d 6118 .show_host_symbolic_name = 1,
dea3101e
JB
6119
6120 /* dynamic attributes the driver supports */
6121 .get_host_port_id = lpfc_get_host_port_id,
6122 .show_host_port_id = 1,
6123
6124 .get_host_port_type = lpfc_get_host_port_type,
6125 .show_host_port_type = 1,
6126
6127 .get_host_port_state = lpfc_get_host_port_state,
6128 .show_host_port_state = 1,
6129
6130 /* active_fc4s is shown but doesn't change (thus no get function) */
6131 .show_host_active_fc4s = 1,
6132
6133 .get_host_speed = lpfc_get_host_speed,
6134 .show_host_speed = 1,
6135
6136 .get_host_fabric_name = lpfc_get_host_fabric_name,
6137 .show_host_fabric_name = 1,
6138
6139 /*
6140 * The LPFC driver treats linkdown handling as target loss events
6141 * so there are no sysfs handlers for link_down_tmo.
6142 */
6143
6144 .get_fc_host_stats = lpfc_get_stats,
64ba8818 6145 .reset_fc_host_stats = lpfc_reset_stats,
dea3101e
JB
6146
6147 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6148 .show_rport_maxframe_size = 1,
6149 .show_rport_supported_classes = 1,
6150
dea3101e
JB
6151 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6152 .show_rport_dev_loss_tmo = 1,
6153
6154 .get_starget_port_id = lpfc_get_starget_port_id,
6155 .show_starget_port_id = 1,
6156
6157 .get_starget_node_name = lpfc_get_starget_node_name,
6158 .show_starget_node_name = 1,
6159
6160 .get_starget_port_name = lpfc_get_starget_port_name,
6161 .show_starget_port_name = 1,
91ca7b01
AV
6162
6163 .issue_fc_host_lip = lpfc_issue_lip,
c01f3208
JS
6164 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6165 .terminate_rport_io = lpfc_terminate_rport_io,
92d7f7b0 6166
92d7f7b0 6167 .dd_fcvport_size = sizeof(struct lpfc_vport *),
eada272d
JS
6168
6169 .vport_disable = lpfc_vport_disable,
6170
6171 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
f1c3b0fc
JS
6172
6173 .bsg_request = lpfc_bsg_request,
6174 .bsg_timeout = lpfc_bsg_timeout,
92d7f7b0
JS
6175};
6176
98c9ea5c
JS
6177struct fc_function_template lpfc_vport_transport_functions = {
6178 /* fixed attributes the driver supports */
6179 .show_host_node_name = 1,
6180 .show_host_port_name = 1,
6181 .show_host_supported_classes = 1,
6182 .show_host_supported_fc4s = 1,
6183 .show_host_supported_speeds = 1,
6184 .show_host_maxframe_size = 1,
6c9231f6
JS
6185
6186 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
eada272d 6187 .show_host_symbolic_name = 1,
98c9ea5c
JS
6188
6189 /* dynamic attributes the driver supports */
6190 .get_host_port_id = lpfc_get_host_port_id,
6191 .show_host_port_id = 1,
6192
6193 .get_host_port_type = lpfc_get_host_port_type,
6194 .show_host_port_type = 1,
6195
6196 .get_host_port_state = lpfc_get_host_port_state,
6197 .show_host_port_state = 1,
6198
6199 /* active_fc4s is shown but doesn't change (thus no get function) */
6200 .show_host_active_fc4s = 1,
6201
6202 .get_host_speed = lpfc_get_host_speed,
6203 .show_host_speed = 1,
6204
6205 .get_host_fabric_name = lpfc_get_host_fabric_name,
6206 .show_host_fabric_name = 1,
6207
6208 /*
6209 * The LPFC driver treats linkdown handling as target loss events
6210 * so there are no sysfs handlers for link_down_tmo.
6211 */
6212
6213 .get_fc_host_stats = lpfc_get_stats,
6214 .reset_fc_host_stats = lpfc_reset_stats,
6215
6216 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6217 .show_rport_maxframe_size = 1,
6218 .show_rport_supported_classes = 1,
6219
6220 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6221 .show_rport_dev_loss_tmo = 1,
6222
6223 .get_starget_port_id = lpfc_get_starget_port_id,
6224 .show_starget_port_id = 1,
6225
6226 .get_starget_node_name = lpfc_get_starget_node_name,
6227 .show_starget_node_name = 1,
6228
6229 .get_starget_port_name = lpfc_get_starget_port_name,
6230 .show_starget_port_name = 1,
6231
6232 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6233 .terminate_rport_io = lpfc_terminate_rport_io,
6234
6235 .vport_disable = lpfc_vport_disable,
eada272d
JS
6236
6237 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
98c9ea5c
JS
6238};
6239
e59058c4 6240/**
3621a710 6241 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
e59058c4
JS
6242 * @phba: lpfc_hba pointer.
6243 **/
dea3101e
JB
6244void
6245lpfc_get_cfgparam(struct lpfc_hba *phba)
6246{
49aa143d 6247 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
a6571c6e 6248 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
7bcbb752
JSEC
6249 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6250 lpfc_cr_count_init(phba, lpfc_cr_count);
cf5bf97e 6251 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
a4bc3379
JS
6252 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6253 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
7bcbb752
JSEC
6254 lpfc_ack0_init(phba, lpfc_ack0);
6255 lpfc_topology_init(phba, lpfc_topology);
7bcbb752 6256 lpfc_link_speed_init(phba, lpfc_link_speed);
875fbdfe 6257 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
0c411222 6258 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
78b2d852 6259 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
7d791df7 6260 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
19ca7609 6261 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
4258e98e
JS
6262 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6263 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
4ff43246 6264 lpfc_use_msi_init(phba, lpfc_use_msi);
895427bd 6265 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
0cf07f84 6266 lpfc_auto_imax_init(phba, lpfc_auto_imax);
da0436e9 6267 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
7bb03bbf 6268 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
13815c83
JS
6269 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6270 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
2ea259ee 6271
1ba981fd
JS
6272 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6273 if (phba->sli_rev != LPFC_SLI_REV4)
6274 phba->cfg_EnableXLane = 0;
6275 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
2ea259ee 6276
1ba981fd
JS
6277 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6278 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6279 phba->cfg_oas_lun_state = 0;
6280 phba->cfg_oas_lun_status = 0;
6281 phba->cfg_oas_flags = 0;
c92c841c 6282 phba->cfg_oas_priority = 0;
81301a9b 6283 lpfc_enable_bg_init(phba, lpfc_enable_bg);
b3b98b74
JS
6284 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6285 lpfc_prot_guard_init(phba, lpfc_prot_guard);
45ed1190
JS
6286 if (phba->sli_rev == LPFC_SLI_REV4)
6287 phba->cfg_poll = 0;
6288 else
1ba981fd 6289 phba->cfg_poll = lpfc_poll;
f358dd0c 6290 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
4258e98e 6291
895427bd 6292 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
2d7dbc4c 6293 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
895427bd
JS
6294
6295 /* Initialize first burst. Target vs Initiator are different. */
6296 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
2d7dbc4c 6297 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
895427bd
JS
6298 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6299 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
44fd7fe3 6300 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
895427bd
JS
6301
6302 if (phba->sli_rev != LPFC_SLI_REV4) {
6303 /* NVME only supported on SLI4 */
6304 phba->nvmet_support = 0;
6305 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
44fd7fe3 6306 phba->cfg_enable_bbcr = 0;
895427bd
JS
6307 } else {
6308 /* We MUST have FCP support */
6309 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6310 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6311 }
6312
0cf07f84
JS
6313 if (phba->cfg_auto_imax && !phba->cfg_fcp_imax)
6314 phba->cfg_auto_imax = 0;
6315 phba->initial_imax = phba->cfg_fcp_imax;
6316
895427bd 6317 /* A value of 0 means use the number of CPUs found in the system */
895427bd
JS
6318 if (phba->cfg_fcp_io_channel == 0)
6319 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
f358dd0c
JS
6320 if (phba->cfg_nvme_io_channel == 0)
6321 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
895427bd
JS
6322
6323 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6324 phba->cfg_fcp_io_channel = 0;
6325
f358dd0c
JS
6326 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6327 phba->cfg_nvme_io_channel = 0;
6328
895427bd
JS
6329 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6330 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6331 else
6332 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
4258e98e 6333
352e5fd1
JS
6334 phba->cfg_soft_wwnn = 0L;
6335 phba->cfg_soft_wwpn = 0L;
895427bd 6336 lpfc_xri_split_init(phba, lpfc_xri_split);
83108bd3 6337 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
7054a606 6338 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
6fb120a7 6339 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
0d878419 6340 lpfc_aer_support_init(phba, lpfc_aer_support);
912e3acd 6341 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
c71ab861 6342 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
84d1b006 6343 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
2a9bf3d0 6344 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
8eb8b960 6345 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
12247e81 6346 lpfc_sli_mode_init(phba, lpfc_sli_mode);
ab56dc2e 6347 phba->cfg_enable_dss = 1;
7bdedb34 6348 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
3de2a653
JS
6349 return;
6350}
b28485ac 6351
895427bd
JS
6352/**
6353 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6354 * dependencies between protocols and roles.
6355 * @phba: lpfc_hba pointer.
6356 **/
6357void
6358lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6359{
895427bd
JS
6360 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6361 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
f358dd0c 6362
895427bd
JS
6363 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6364 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6365
f358dd0c
JS
6366 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6367 phba->nvmet_support) {
6368 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6369 phba->cfg_fcp_io_channel = 0;
2d7dbc4c
JS
6370
6371 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6372 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6373 "NVME Target PRLI ACC enable_fb ",
6374 phba->cfg_nvme_enable_fb,
6375 phba->cfg_nvmet_fb_size,
6376 LPFC_NVMET_FB_SZ_MAX);
6377
6378 if (phba->cfg_nvme_enable_fb == 0)
6379 phba->cfg_nvmet_fb_size = 0;
6380 else {
6381 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6382 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6383 }
6384
0eeaf17f
JS
6385 if (!phba->cfg_nvmet_mrq)
6386 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6387
2d7dbc4c
JS
6388 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6389 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6390 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6391 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6392 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6393 phba->cfg_nvmet_mrq);
6394 }
0eeaf17f
JS
6395 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
6396 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
6397
2d7dbc4c 6398 } else {
f358dd0c
JS
6399 /* Not NVME Target mode. Turn off Target parameters. */
6400 phba->nvmet_support = 0;
0eeaf17f 6401 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF;
2d7dbc4c
JS
6402 phba->cfg_nvmet_fb_size = 0;
6403 }
f358dd0c 6404
895427bd
JS
6405 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6406 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6407 else
6408 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6409}
6410
e59058c4 6411/**
3621a710 6412 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
e59058c4
JS
6413 * @vport: lpfc_vport pointer.
6414 **/
3de2a653
JS
6415void
6416lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6417{
e8b62011 6418 lpfc_log_verbose_init(vport, lpfc_log_verbose);
3de2a653 6419 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
7dc517df 6420 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
3de2a653
JS
6421 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6422 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6423 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6424 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6425 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6426 lpfc_use_adisc_init(vport, lpfc_use_adisc);
3cb01c57 6427 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
977b5a0a 6428 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
3de2a653
JS
6429 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6430 lpfc_max_luns_init(vport, lpfc_max_luns);
6431 lpfc_scan_down_init(vport, lpfc_scan_down);
7ee5d43e 6432 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea3101e
JB
6433 return;
6434}