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