]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/scsi/lpfc/lpfc_attr.c
scsi: lpfc: Fix issue_lip if link is disabled
[mirror_ubuntu-bionic-kernel.git] / drivers / scsi / lpfc / lpfc_attr.c
CommitLineData
dea3101e
JB
1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
c44ce173 3 * Fibre Channel Host Bus Adapters. *
d080abe0
JS
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
50611577 6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
c44ce173 7 * EMULEX and SLI are trademarks of Emulex. *
d080abe0 8 * www.broadcom.com *
c44ce173 9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea3101e
JB
10 * *
11 * This program is free software; you can redistribute it and/or *
c44ce173
JSEC
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
dea3101e
JB
22 *******************************************************************/
23
dea3101e 24#include <linux/ctype.h>
46fa311e 25#include <linux/delay.h>
dea3101e
JB
26#include <linux/pci.h>
27#include <linux/interrupt.h>
acf3368f 28#include <linux/module.h>
0d878419 29#include <linux/aer.h>
5a0e3ad6 30#include <linux/gfp.h>
ecc30990 31#include <linux/kernel.h>
dea3101e 32
91886523 33#include <scsi/scsi.h>
dea3101e
JB
34#include <scsi/scsi_device.h>
35#include <scsi/scsi_host.h>
36#include <scsi/scsi_tcq.h>
37#include <scsi/scsi_transport_fc.h>
6a9c52cf 38#include <scsi/fc/fc_fs.h>
dea3101e 39
895427bd
JS
40#include <linux/nvme-fc-driver.h>
41
da0436e9 42#include "lpfc_hw4.h"
dea3101e
JB
43#include "lpfc_hw.h"
44#include "lpfc_sli.h"
da0436e9 45#include "lpfc_sli4.h"
ea2151b4 46#include "lpfc_nl.h"
dea3101e 47#include "lpfc_disc.h"
dea3101e 48#include "lpfc.h"
895427bd
JS
49#include "lpfc_scsi.h"
50#include "lpfc_nvme.h"
f358dd0c 51#include "lpfc_nvmet.h"
dea3101e
JB
52#include "lpfc_logmsg.h"
53#include "lpfc_version.h"
54#include "lpfc_compat.h"
55#include "lpfc_crtn.h"
92d7f7b0 56#include "lpfc_vport.h"
93dd1911 57#include "lpfc_attr.h"
dea3101e 58
2ea259ee
JS
59#define LPFC_DEF_DEVLOSS_TMO 30
60#define LPFC_MIN_DEVLOSS_TMO 1
61#define LPFC_MAX_DEVLOSS_TMO 255
dea3101e 62
61f3d4bf
JS
63#define LPFC_DEF_MRQ_POST 512
64#define LPFC_MIN_MRQ_POST 512
65#define LPFC_MAX_MRQ_POST 2048
dea3101e 66
f7a919b4
JS
67/*
68 * Write key size should be multiple of 4. If write key is changed
69 * make sure that library write key is also changed.
70 */
71#define LPFC_REG_WRITE_KEY_SIZE 4
72#define LPFC_REG_WRITE_KEY "EMLX"
73
e59058c4 74/**
3621a710 75 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
e59058c4
JS
76 * @incr: integer to convert.
77 * @hdw: ascii string holding converted integer plus a string terminator.
78 *
79 * Description:
80 * JEDEC Joint Electron Device Engineering Council.
81 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
82 * character string. The string is then terminated with a NULL in byte 9.
83 * Hex 0-9 becomes ascii '0' to '9'.
84 * Hex a-f becomes ascii '=' to 'B' capital B.
85 *
86 * Notes:
87 * Coded for 32 bit integers only.
88 **/
dea3101e
JB
89static void
90lpfc_jedec_to_ascii(int incr, char hdw[])
91{
92 int i, j;
93 for (i = 0; i < 8; i++) {
94 j = (incr & 0xf);
95 if (j <= 9)
96 hdw[7 - i] = 0x30 + j;
97 else
98 hdw[7 - i] = 0x61 + j - 10;
99 incr = (incr >> 4);
100 }
101 hdw[8] = 0;
102 return;
103}
104
e59058c4 105/**
3621a710 106 * lpfc_drvr_version_show - Return the Emulex driver string with version number
e59058c4
JS
107 * @dev: class unused variable.
108 * @attr: device attribute, not used.
109 * @buf: on return contains the module description text.
110 *
111 * Returns: size of formatted string.
112 **/
dea3101e 113static ssize_t
ee959b00
TJ
114lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
115 char *buf)
dea3101e
JB
116{
117 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
118}
119
45ed1190
JS
120/**
121 * lpfc_enable_fip_show - Return the fip mode of the HBA
122 * @dev: class unused variable.
123 * @attr: device attribute, not used.
124 * @buf: on return contains the module description text.
125 *
126 * Returns: size of formatted string.
127 **/
128static ssize_t
129lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
130 char *buf)
131{
132 struct Scsi_Host *shost = class_to_shost(dev);
133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
134 struct lpfc_hba *phba = vport->phba;
135
136 if (phba->hba_flag & HBA_FIP_SUPPORT)
137 return snprintf(buf, PAGE_SIZE, "1\n");
138 else
139 return snprintf(buf, PAGE_SIZE, "0\n");
140}
141
895427bd
JS
142static ssize_t
143lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
144 char *buf)
145{
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = shost_priv(shost);
148 struct lpfc_hba *phba = vport->phba;
f358dd0c 149 struct lpfc_nvmet_tgtport *tgtp;
895427bd 150 struct nvme_fc_local_port *localport;
24909450 151 struct lpfc_nvme_lport *lport;
80cc0043 152 struct lpfc_nodelist *ndlp;
895427bd 153 struct nvme_fc_remote_port *nrport;
2cee7808 154 uint64_t data1, data2, data3, tot;
895427bd
JS
155 char *statep;
156 int len = 0;
157
158 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
159 len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n");
160 return len;
161 }
f358dd0c
JS
162 if (phba->nvmet_support) {
163 if (!phba->targetport) {
164 len = snprintf(buf, PAGE_SIZE,
165 "NVME Target: x%llx is not allocated\n",
166 wwn_to_u64(vport->fc_portname.u.wwn));
167 return len;
168 }
169 /* Port state is only one of two values for now. */
170 if (phba->targetport->port_id)
171 statep = "REGISTERED";
172 else
173 statep = "INIT";
174 len += snprintf(buf + len, PAGE_SIZE - len,
b4fd681e 175 "NVME Target Enabled State %s\n",
f358dd0c
JS
176 statep);
177 len += snprintf(buf + len, PAGE_SIZE - len,
178 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
179 "NVME Target: lpfc",
180 phba->brd_no,
181 wwn_to_u64(vport->fc_portname.u.wwn),
182 wwn_to_u64(vport->fc_nodename.u.wwn),
183 phba->targetport->port_id);
184
ea98ab34 185 len += snprintf(buf + len, PAGE_SIZE - len,
f358dd0c
JS
186 "\nNVME Target: Statistics\n");
187 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
188 len += snprintf(buf+len, PAGE_SIZE-len,
189 "LS: Rcv %08x Drop %08x Abort %08x\n",
190 atomic_read(&tgtp->rcv_ls_req_in),
191 atomic_read(&tgtp->rcv_ls_req_drop),
192 atomic_read(&tgtp->xmt_ls_abort));
193 if (atomic_read(&tgtp->rcv_ls_req_in) !=
194 atomic_read(&tgtp->rcv_ls_req_out)) {
195 len += snprintf(buf+len, PAGE_SIZE-len,
196 "Rcv LS: in %08x != out %08x\n",
197 atomic_read(&tgtp->rcv_ls_req_in),
198 atomic_read(&tgtp->rcv_ls_req_out));
199 }
200
201 len += snprintf(buf+len, PAGE_SIZE-len,
24909450 202 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
f358dd0c
JS
203 atomic_read(&tgtp->xmt_ls_rsp),
204 atomic_read(&tgtp->xmt_ls_drop),
24909450
JS
205 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
206
207 len += snprintf(buf + len, PAGE_SIZE - len,
208 "LS: RSP Abort %08x xb %08x Err %08x\n",
209 atomic_read(&tgtp->xmt_ls_rsp_aborted),
210 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
f358dd0c
JS
211 atomic_read(&tgtp->xmt_ls_rsp_error));
212
213 len += snprintf(buf+len, PAGE_SIZE-len,
50738420
JS
214 "FCP: Rcv %08x Defer %08x Release %08x "
215 "Drop %08x\n",
f358dd0c 216 atomic_read(&tgtp->rcv_fcp_cmd_in),
50738420 217 atomic_read(&tgtp->rcv_fcp_cmd_defer),
547077a4 218 atomic_read(&tgtp->xmt_fcp_release),
f358dd0c
JS
219 atomic_read(&tgtp->rcv_fcp_cmd_drop));
220
221 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
222 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
223 len += snprintf(buf+len, PAGE_SIZE-len,
224 "Rcv FCP: in %08x != out %08x\n",
225 atomic_read(&tgtp->rcv_fcp_cmd_in),
226 atomic_read(&tgtp->rcv_fcp_cmd_out));
227 }
228
229 len += snprintf(buf+len, PAGE_SIZE-len,
547077a4
JS
230 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
231 "drop %08x\n",
f358dd0c
JS
232 atomic_read(&tgtp->xmt_fcp_read),
233 atomic_read(&tgtp->xmt_fcp_read_rsp),
234 atomic_read(&tgtp->xmt_fcp_write),
547077a4 235 atomic_read(&tgtp->xmt_fcp_rsp),
f358dd0c
JS
236 atomic_read(&tgtp->xmt_fcp_drop));
237
238 len += snprintf(buf+len, PAGE_SIZE-len,
239 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
240 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
241 atomic_read(&tgtp->xmt_fcp_rsp_error),
242 atomic_read(&tgtp->xmt_fcp_rsp_drop));
243
244 len += snprintf(buf+len, PAGE_SIZE-len,
24909450
JS
245 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
246 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
247 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
248 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
249
250 len += snprintf(buf + len, PAGE_SIZE - len,
547077a4
JS
251 "ABORT: Xmt %08x Cmpl %08x\n",
252 atomic_read(&tgtp->xmt_fcp_abort),
253 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
254
255 len += snprintf(buf + len, PAGE_SIZE - len,
256 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
257 atomic_read(&tgtp->xmt_abort_sol),
258 atomic_read(&tgtp->xmt_abort_unsol),
f358dd0c 259 atomic_read(&tgtp->xmt_abort_rsp),
547077a4 260 atomic_read(&tgtp->xmt_abort_rsp_error));
f358dd0c 261
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
JS
4117 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4118 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
76a95d75
JS
4119 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4120 "2879 lpfc_link_speed attribute cannot be set "
4121 "to %d. Speed is not supported by this port.\n",
4122 val);
83108bd3 4123 return -EINVAL;
76a95d75 4124 }
ff78d8f9
JS
4125 if (val == LPFC_USER_LINK_SPEED_16G &&
4126 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4127 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4128 "3112 lpfc_link_speed attribute cannot be set "
4129 "to %d. Speed is not supported in loop mode.\n",
4130 val);
4131 return -EINVAL;
4132 }
76a95d75
JS
4133 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4134 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
83108bd3
JS
4135 prev_val = phba->cfg_link_speed;
4136 phba->cfg_link_speed = val;
a257bf90
JS
4137 if (nolip)
4138 return strlen(buf);
4139
83108bd3 4140 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
a257bf90 4141 if (err) {
83108bd3 4142 phba->cfg_link_speed = prev_val;
a257bf90
JS
4143 return -EINVAL;
4144 } else
4145 return strlen(buf);
83108bd3 4146 }
83108bd3 4147 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
76a95d75
JS
4148 "0469 lpfc_link_speed attribute cannot be set to %d, "
4149 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
83108bd3
JS
4150 return -EINVAL;
4151}
4152
4153static int lpfc_link_speed = 0;
ab56dc2e 4154module_param(lpfc_link_speed, int, S_IRUGO);
83108bd3
JS
4155MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4156lpfc_param_show(link_speed)
e59058c4
JS
4157
4158/**
3621a710 4159 * lpfc_link_speed_init - Set the adapters link speed
e59058c4
JS
4160 * @phba: lpfc_hba pointer.
4161 * @val: link speed value.
4162 *
4163 * Description:
4164 * If val is in a valid range then set the adapter's link speed field.
4165 *
4166 * Notes:
4167 * If the value is not in range log a kernel error message, clear the link
4168 * speed and return an error.
4169 *
4170 * Returns:
4171 * zero if val saved.
4172 * -EINVAL val out of range
4173 **/
83108bd3
JS
4174static int
4175lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4176{
ff78d8f9
JS
4177 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4178 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4179 "3111 lpfc_link_speed of %d cannot "
4180 "support loop mode, setting topology to default.\n",
4181 val);
4182 phba->cfg_topology = 0;
4183 }
76a95d75
JS
4184 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4185 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
83108bd3
JS
4186 phba->cfg_link_speed = val;
4187 return 0;
4188 }
4189 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
d7c255b2 4190 "0405 lpfc_link_speed attribute cannot "
83108bd3
JS
4191 "be set to %d, allowed values are "
4192 "["LPFC_LINK_SPEED_STRING"]\n", val);
76a95d75 4193 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
83108bd3
JS
4194 return -EINVAL;
4195}
4196
69d725f4 4197static DEVICE_ATTR_RW(lpfc_link_speed);
dea3101e 4198
0d878419
JS
4199/*
4200# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4201# 0 = aer disabled or not supported
4202# 1 = aer supported and enabled (default)
4203# Value range is [0,1]. Default value is 1.
4204*/
506139a2
JS
4205LPFC_ATTR(aer_support, 1, 0, 1,
4206 "Enable PCIe device AER support");
4207lpfc_param_show(aer_support)
0d878419
JS
4208
4209/**
4210 * lpfc_aer_support_store - Set the adapter for aer support
4211 *
4212 * @dev: class device that is converted into a Scsi_host.
4213 * @attr: device attribute, not used.
912e3acd 4214 * @buf: containing enable or disable aer flag.
0d878419
JS
4215 * @count: unused variable.
4216 *
4217 * Description:
4218 * If the val is 1 and currently the device's AER capability was not
4219 * enabled, invoke the kernel's enable AER helper routine, trying to
4220 * enable the device's AER capability. If the helper routine enabling
4221 * AER returns success, update the device's cfg_aer_support flag to
4222 * indicate AER is supported by the device; otherwise, if the device
4223 * AER capability is already enabled to support AER, then do nothing.
4224 *
4225 * If the val is 0 and currently the device's AER support was enabled,
4226 * invoke the kernel's disable AER helper routine. After that, update
4227 * the device's cfg_aer_support flag to indicate AER is not supported
4228 * by the device; otherwise, if the device AER capability is already
4229 * disabled from supporting AER, then do nothing.
4230 *
4231 * Returns:
4232 * length of the buf on success if val is in range the intended mode
4233 * is supported.
4234 * -EINVAL if val out of range or intended mode is not supported.
4235 **/
4236static ssize_t
4237lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4238 const char *buf, size_t count)
4239{
4240 struct Scsi_Host *shost = class_to_shost(dev);
4241 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4242 struct lpfc_hba *phba = vport->phba;
4243 int val = 0, rc = -EINVAL;
4244
4245 if (!isdigit(buf[0]))
4246 return -EINVAL;
4247 if (sscanf(buf, "%i", &val) != 1)
4248 return -EINVAL;
4249
4250 switch (val) {
4251 case 0:
4252 if (phba->hba_flag & HBA_AER_ENABLED) {
4253 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4254 if (!rc) {
4255 spin_lock_irq(&phba->hbalock);
4256 phba->hba_flag &= ~HBA_AER_ENABLED;
4257 spin_unlock_irq(&phba->hbalock);
4258 phba->cfg_aer_support = 0;
4259 rc = strlen(buf);
4260 } else
891478a2
JS
4261 rc = -EPERM;
4262 } else {
0d878419 4263 phba->cfg_aer_support = 0;
891478a2
JS
4264 rc = strlen(buf);
4265 }
0d878419
JS
4266 break;
4267 case 1:
4268 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4269 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4270 if (!rc) {
4271 spin_lock_irq(&phba->hbalock);
4272 phba->hba_flag |= HBA_AER_ENABLED;
4273 spin_unlock_irq(&phba->hbalock);
4274 phba->cfg_aer_support = 1;
4275 rc = strlen(buf);
4276 } else
891478a2
JS
4277 rc = -EPERM;
4278 } else {
0d878419 4279 phba->cfg_aer_support = 1;
891478a2
JS
4280 rc = strlen(buf);
4281 }
0d878419
JS
4282 break;
4283 default:
4284 rc = -EINVAL;
4285 break;
4286 }
4287 return rc;
4288}
4289
69d725f4 4290static DEVICE_ATTR_RW(lpfc_aer_support);
0d878419
JS
4291
4292/**
4293 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4294 * @dev: class device that is converted into a Scsi_host.
4295 * @attr: device attribute, not used.
912e3acd 4296 * @buf: containing flag 1 for aer cleanup state.
0d878419
JS
4297 * @count: unused variable.
4298 *
4299 * Description:
4300 * If the @buf contains 1 and the device currently has the AER support
4301 * enabled, then invokes the kernel AER helper routine
4302 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4303 * error status register.
4304 *
4305 * Notes:
4306 *
4307 * Returns:
4308 * -EINVAL if the buf does not contain the 1 or the device is not currently
4309 * enabled with the AER support.
4310 **/
4311static ssize_t
4312lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4313 const char *buf, size_t count)
4314{
4315 struct Scsi_Host *shost = class_to_shost(dev);
4316 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4317 struct lpfc_hba *phba = vport->phba;
4318 int val, rc = -1;
4319
4320 if (!isdigit(buf[0]))
4321 return -EINVAL;
4322 if (sscanf(buf, "%i", &val) != 1)
4323 return -EINVAL;
891478a2
JS
4324 if (val != 1)
4325 return -EINVAL;
0d878419 4326
891478a2 4327 if (phba->hba_flag & HBA_AER_ENABLED)
0d878419
JS
4328 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4329
4330 if (rc == 0)
4331 return strlen(buf);
4332 else
891478a2 4333 return -EPERM;
0d878419
JS
4334}
4335
4336static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4337 lpfc_aer_cleanup_state);
4338
912e3acd
JS
4339/**
4340 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4341 *
4342 * @dev: class device that is converted into a Scsi_host.
4343 * @attr: device attribute, not used.
4344 * @buf: containing the string the number of vfs to be enabled.
4345 * @count: unused variable.
4346 *
4347 * Description:
4348 * When this api is called either through user sysfs, the driver shall
4349 * try to enable or disable SR-IOV virtual functions according to the
4350 * following:
4351 *
4352 * If zero virtual function has been enabled to the physical function,
4353 * the driver shall invoke the pci enable virtual function api trying
4354 * to enable the virtual functions. If the nr_vfn provided is greater
4355 * than the maximum supported, the maximum virtual function number will
4356 * be used for invoking the api; otherwise, the nr_vfn provided shall
4357 * be used for invoking the api. If the api call returned success, the
4358 * actual number of virtual functions enabled will be set to the driver
4359 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4360 * cfg_sriov_nr_virtfn remains zero.
4361 *
4362 * If none-zero virtual functions have already been enabled to the
4363 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4364 * -EINVAL will be returned and the driver does nothing;
4365 *
4366 * If the nr_vfn provided is zero and none-zero virtual functions have
4367 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4368 * disabling virtual function api shall be invoded to disable all the
4369 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4370 * zero. Otherwise, if zero virtual function has been enabled, do
4371 * nothing.
4372 *
4373 * Returns:
4374 * length of the buf on success if val is in range the intended mode
4375 * is supported.
4376 * -EINVAL if val out of range or intended mode is not supported.
4377 **/
4378static ssize_t
4379lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4380 const char *buf, size_t count)
4381{
4382 struct Scsi_Host *shost = class_to_shost(dev);
4383 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4384 struct lpfc_hba *phba = vport->phba;
4385 struct pci_dev *pdev = phba->pcidev;
4386 int val = 0, rc = -EINVAL;
4387
4388 /* Sanity check on user data */
4389 if (!isdigit(buf[0]))
4390 return -EINVAL;
4391 if (sscanf(buf, "%i", &val) != 1)
4392 return -EINVAL;
4393 if (val < 0)
4394 return -EINVAL;
4395
4396 /* Request disabling virtual functions */
4397 if (val == 0) {
4398 if (phba->cfg_sriov_nr_virtfn > 0) {
4399 pci_disable_sriov(pdev);
4400 phba->cfg_sriov_nr_virtfn = 0;
4401 }
4402 return strlen(buf);
4403 }
4404
4405 /* Request enabling virtual functions */
4406 if (phba->cfg_sriov_nr_virtfn > 0) {
4407 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4408 "3018 There are %d virtual functions "
4409 "enabled on physical function.\n",
4410 phba->cfg_sriov_nr_virtfn);
4411 return -EEXIST;
4412 }
4413
4414 if (val <= LPFC_MAX_VFN_PER_PFN)
4415 phba->cfg_sriov_nr_virtfn = val;
4416 else {
4417 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4418 "3019 Enabling %d virtual functions is not "
4419 "allowed.\n", val);
4420 return -EINVAL;
4421 }
4422
4423 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4424 if (rc) {
4425 phba->cfg_sriov_nr_virtfn = 0;
4426 rc = -EPERM;
4427 } else
4428 rc = strlen(buf);
4429
4430 return rc;
4431}
4432
0cfbbf2f
JS
4433LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4434 "Enable PCIe device SR-IOV virtual fn");
912e3acd 4435
0cfbbf2f 4436lpfc_param_show(sriov_nr_virtfn)
69d725f4 4437static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
912e3acd 4438
c71ab861
JS
4439/**
4440 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4441 *
4442 * @dev: class device that is converted into a Scsi_host.
4443 * @attr: device attribute, not used.
4444 * @buf: containing the string the number of vfs to be enabled.
4445 * @count: unused variable.
4446 *
4447 * Description:
4448 *
4449 * Returns:
4450 * length of the buf on success if val is in range the intended mode
4451 * is supported.
4452 * -EINVAL if val out of range or intended mode is not supported.
4453 **/
4454static ssize_t
4455lpfc_request_firmware_upgrade_store(struct device *dev,
4456 struct device_attribute *attr,
4457 const char *buf, size_t count)
4458{
4459 struct Scsi_Host *shost = class_to_shost(dev);
4460 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4461 struct lpfc_hba *phba = vport->phba;
4462 int val = 0, rc = -EINVAL;
4463
4464 /* Sanity check on user data */
4465 if (!isdigit(buf[0]))
4466 return -EINVAL;
4467 if (sscanf(buf, "%i", &val) != 1)
4468 return -EINVAL;
4469 if (val != 1)
4470 return -EINVAL;
4471
4472 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4473 if (rc)
4474 rc = -EPERM;
4475 else
4476 rc = strlen(buf);
4477 return rc;
4478}
4479
4480static int lpfc_req_fw_upgrade;
4481module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4482MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4483lpfc_param_show(request_firmware_upgrade)
4484
4485/**
4486 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4487 * @phba: lpfc_hba pointer.
4488 * @val: 0 or 1.
4489 *
4490 * Description:
4491 * Set the initial Linux generic firmware upgrade enable or disable flag.
4492 *
4493 * Returns:
4494 * zero if val saved.
4495 * -EINVAL val out of range
4496 **/
4497static int
4498lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4499{
4500 if (val >= 0 && val <= 1) {
4501 phba->cfg_request_firmware_upgrade = val;
4502 return 0;
4503 }
4504 return -EINVAL;
4505}
4506static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4507 lpfc_request_firmware_upgrade_show,
4508 lpfc_request_firmware_upgrade_store);
4509
173edbb2
JS
4510/**
4511 * lpfc_fcp_imax_store
4512 *
4513 * @dev: class device that is converted into a Scsi_host.
4514 * @attr: device attribute, not used.
4515 * @buf: string with the number of fast-path FCP interrupts per second.
4516 * @count: unused variable.
4517 *
4518 * Description:
4519 * If val is in a valid range [636,651042], then set the adapter's
4520 * maximum number of fast-path FCP interrupts per second.
4521 *
4522 * Returns:
4523 * length of the buf on success if val is in range the intended mode
4524 * is supported.
4525 * -EINVAL if val out of range or intended mode is not supported.
4526 **/
4527static ssize_t
4528lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4529 const char *buf, size_t count)
4530{
4531 struct Scsi_Host *shost = class_to_shost(dev);
4532 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4533 struct lpfc_hba *phba = vport->phba;
4534 int val = 0, i;
4535
bf8dae83
JS
4536 /* fcp_imax is only valid for SLI4 */
4537 if (phba->sli_rev != LPFC_SLI_REV4)
4538 return -EINVAL;
4539
173edbb2
JS
4540 /* Sanity check on user data */
4541 if (!isdigit(buf[0]))
4542 return -EINVAL;
4543 if (sscanf(buf, "%i", &val) != 1)
4544 return -EINVAL;
4545
bf8dae83
JS
4546 /*
4547 * Value range for the HBA is [5000,5000000]
4548 * The value for each EQ depends on how many EQs are configured.
895427bd 4549 * Allow value == 0
bf8dae83 4550 */
895427bd 4551 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
173edbb2
JS
4552 return -EINVAL;
4553
4554 phba->cfg_fcp_imax = (uint32_t)val;
0cf07f84 4555 phba->initial_imax = phba->cfg_fcp_imax;
43140ca6
JS
4556
4557 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
0cf07f84
JS
4558 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4559 val);
173edbb2
JS
4560
4561 return strlen(buf);
4562}
4563
4564/*
4565# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
bf8dae83 4566# for the HBA.
173edbb2 4567#
bf8dae83 4568# Value range is [5,000 to 5,000,000]. Default value is 50,000.
173edbb2 4569*/
bf8dae83 4570static int lpfc_fcp_imax = LPFC_DEF_IMAX;
173edbb2
JS
4571module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4572MODULE_PARM_DESC(lpfc_fcp_imax,
bf8dae83 4573 "Set the maximum number of FCP interrupts per second per HBA");
173edbb2
JS
4574lpfc_param_show(fcp_imax)
4575
4576/**
4577 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4578 * @phba: lpfc_hba pointer.
4579 * @val: link speed value.
4580 *
4581 * Description:
4582 * If val is in a valid range [636,651042], then initialize the adapter's
4583 * maximum number of fast-path FCP interrupts per second.
4584 *
4585 * Returns:
4586 * zero if val saved.
4587 * -EINVAL val out of range
4588 **/
4589static int
4590lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4591{
bf8dae83
JS
4592 if (phba->sli_rev != LPFC_SLI_REV4) {
4593 phba->cfg_fcp_imax = 0;
4594 return 0;
4595 }
4596
895427bd
JS
4597 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4598 (val == 0)) {
173edbb2
JS
4599 phba->cfg_fcp_imax = val;
4600 return 0;
4601 }
4602
4603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6c86068d
JS
4604 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4605 val);
bf8dae83 4606 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
173edbb2
JS
4607
4608 return 0;
4609}
4610
69d725f4 4611static DEVICE_ATTR_RW(lpfc_fcp_imax);
173edbb2 4612
0cf07f84
JS
4613/*
4614 * lpfc_auto_imax: Controls Auto-interrupt coalescing values support.
4615 * 0 No auto_imax support
4616 * 1 auto imax on
4617 * Auto imax will change the value of fcp_imax on a per EQ basis, using
4618 * the EQ Delay Multiplier, depending on the activity for that EQ.
4619 * Value range [0,1]. Default value is 1.
4620 */
4621LPFC_ATTR_RW(auto_imax, 1, 0, 1, "Enable Auto imax");
4622
7bb03bbf
JS
4623/**
4624 * lpfc_state_show - Display current driver CPU affinity
4625 * @dev: class converted to a Scsi_host structure.
4626 * @attr: device attribute, not used.
4627 * @buf: on return contains text describing the state of the link.
4628 *
4629 * Returns: size of formatted string.
4630 **/
4631static ssize_t
4632lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4633 char *buf)
4634{
4635 struct Scsi_Host *shost = class_to_shost(dev);
4636 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4637 struct lpfc_hba *phba = vport->phba;
4638 struct lpfc_vector_map_info *cpup;
76fd07a6 4639 int len = 0;
7bb03bbf
JS
4640
4641 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4642 (phba->intr_type != MSIX))
4643 return len;
4644
4645 switch (phba->cfg_fcp_cpu_map) {
4646 case 0:
4647 len += snprintf(buf + len, PAGE_SIZE-len,
4648 "fcp_cpu_map: No mapping (%d)\n",
4649 phba->cfg_fcp_cpu_map);
4650 return len;
4651 case 1:
4652 len += snprintf(buf + len, PAGE_SIZE-len,
4653 "fcp_cpu_map: HBA centric mapping (%d): "
4654 "%d online CPUs\n",
4655 phba->cfg_fcp_cpu_map,
4656 phba->sli4_hba.num_online_cpu);
4657 break;
4658 case 2:
4659 len += snprintf(buf + len, PAGE_SIZE-len,
4660 "fcp_cpu_map: Driver centric mapping (%d): "
4661 "%d online CPUs\n",
4662 phba->cfg_fcp_cpu_map,
4663 phba->sli4_hba.num_online_cpu);
4664 break;
4665 }
4666
76fd07a6
JS
4667 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4668 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4669
4670 /* margin should fit in this and the truncated message */
7bb03bbf
JS
4671 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4672 len += snprintf(buf + len, PAGE_SIZE-len,
4673 "CPU %02d io_chan %02d "
4674 "physid %d coreid %d\n",
76fd07a6
JS
4675 phba->sli4_hba.curr_disp_cpu,
4676 cpup->channel_id, cpup->phys_id,
7bb03bbf
JS
4677 cpup->core_id);
4678 else
4679 len += snprintf(buf + len, PAGE_SIZE-len,
4680 "CPU %02d io_chan %02d "
4681 "physid %d coreid %d IRQ %d\n",
76fd07a6
JS
4682 phba->sli4_hba.curr_disp_cpu,
4683 cpup->channel_id, cpup->phys_id,
7bb03bbf
JS
4684 cpup->core_id, cpup->irq);
4685
76fd07a6
JS
4686 phba->sli4_hba.curr_disp_cpu++;
4687
4688 /* display max number of CPUs keeping some margin */
4689 if (phba->sli4_hba.curr_disp_cpu <
4690 phba->sli4_hba.num_present_cpu &&
4691 (len >= (PAGE_SIZE - 64))) {
4692 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4693 break;
4694 }
7bb03bbf 4695 }
76fd07a6
JS
4696
4697 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4698 phba->sli4_hba.curr_disp_cpu = 0;
4699
7bb03bbf
JS
4700 return len;
4701}
4702
4703/**
4704 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4705 * @dev: class device that is converted into a Scsi_host.
4706 * @attr: device attribute, not used.
4707 * @buf: one or more lpfc_polling_flags values.
4708 * @count: not used.
4709 *
4710 * Returns:
4711 * -EINVAL - Not implemented yet.
4712 **/
4713static ssize_t
4714lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4715 const char *buf, size_t count)
4716{
4717 int status = -EINVAL;
4718 return status;
4719}
4720
4721/*
4722# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4723# for the HBA.
4724#
4725# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4726# 0 - Do not affinitze IRQ vectors
4727# 1 - Affintize HBA vectors with respect to each HBA
4728# (start with CPU0 for each HBA)
4729# 2 - Affintize HBA vectors with respect to the entire driver
4730# (round robin thru all CPUs across all HBAs)
4731*/
4732static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4733module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4734MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4735 "Defines how to map CPUs to IRQ vectors per HBA");
4736
4737/**
4738 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4739 * @phba: lpfc_hba pointer.
4740 * @val: link speed value.
4741 *
4742 * Description:
4743 * If val is in a valid range [0-2], then affinitze the adapter's
4744 * MSIX vectors.
4745 *
4746 * Returns:
4747 * zero if val saved.
4748 * -EINVAL val out of range
4749 **/
4750static int
4751lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4752{
4753 if (phba->sli_rev != LPFC_SLI_REV4) {
4754 phba->cfg_fcp_cpu_map = 0;
4755 return 0;
4756 }
4757
4758 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4759 phba->cfg_fcp_cpu_map = val;
4760 return 0;
4761 }
4762
4763 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6c86068d
JS
4764 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4765 "default\n", val);
7bb03bbf
JS
4766 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4767
4768 return 0;
4769}
4770
69d725f4 4771static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
7bb03bbf 4772
dea3101e
JB
4773/*
4774# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4775# Value range is [2,3]. Default value is 3.
4776*/
3de2a653
JS
4777LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4778 "Select Fibre Channel class of service for FCP sequences");
dea3101e
JB
4779
4780/*
4781# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4782# is [0,1]. Default value is 0.
4783*/
3de2a653
JS
4784LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4785 "Use ADISC on rediscovery to authenticate FCP devices");
dea3101e 4786
3cb01c57
JS
4787/*
4788# lpfc_first_burst_size: First burst size to use on the NPorts
4789# that support first burst.
4790# Value range is [0,65536]. Default value is 0.
4791*/
4792LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4793 "First burst size for Targets that support first burst");
4794
895427bd 4795/*
2d7dbc4c
JS
4796* lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4797* When the driver is configured as an NVME target, this value is
4798* communicated to the NVME initiator in the PRLI response. It is
4799* used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4800* parameters are set and the target is sending the PRLI RSP.
895427bd 4801* Parameter supported on physical port only - no NPIV support.
2d7dbc4c 4802* Value range is [0,65536]. Default value is 0.
895427bd 4803*/
2d7dbc4c
JS
4804LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4805 "NVME Target mode first burst size in 512B increments.");
4806
4807/*
4808 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4809 * For the Initiator (I), enabling this parameter means that an NVMET
4810 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4811 * processed by the initiator for subsequent NVME FCP IO. For the target
4812 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4813 * driver parameter as the target function's first burst size returned to the
4814 * initiator in the target's NVME PRLI response. Parameter supported on physical
4815 * port only - no NPIV support.
4816 * Value range is [0,1]. Default value is 0 (disabled).
4817 */
895427bd
JS
4818LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4819 "Enable First Burst feature on I and T functions.");
4820
977b5a0a
JS
4821/*
4822# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4823# depth. Default value is 0. When the value of this parameter is zero the
4824# SCSI command completion time is not used for controlling I/O queue depth. When
4825# the parameter is set to a non-zero value, the I/O queue depth is controlled
4826# to limit the I/O completion time to the parameter value.
4827# The value is set in milliseconds.
4828*/
ed5b1529 4829LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
977b5a0a 4830 "Use command completion time to control queue depth");
ed5b1529 4831
977b5a0a 4832lpfc_vport_param_show(max_scsicmpl_time);
977b5a0a
JS
4833static int
4834lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4835{
4836 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4837 struct lpfc_nodelist *ndlp, *next_ndlp;
4838
4839 if (val == vport->cfg_max_scsicmpl_time)
4840 return 0;
4841 if ((val < 0) || (val > 60000))
4842 return -EINVAL;
4843 vport->cfg_max_scsicmpl_time = val;
4844
4845 spin_lock_irq(shost->host_lock);
4846 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4847 if (!NLP_CHK_NODE_ACT(ndlp))
4848 continue;
4849 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4850 continue;
7dc517df 4851 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
977b5a0a
JS
4852 }
4853 spin_unlock_irq(shost->host_lock);
4854 return 0;
4855}
4856lpfc_vport_param_store(max_scsicmpl_time);
69d725f4 4857static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
977b5a0a 4858
dea3101e
JB
4859/*
4860# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4861# range is [0,1]. Default value is 0.
4862*/
4863LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4864
49aa143d 4865/*
895427bd
JS
4866 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4867 * range is [0,1]. Default value is 0.
4868 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4869 * For [1], FCP commands are issued to a Work Queue associated with the
4870 * current CPU.
4871 *
4872 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4873 * LPFC_FCP_SCHED_BY_CPU == 1
4874 *
4875 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4876 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4877 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4878 * through WQs will be used.
4879 */
4880LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4881 LPFC_FCP_SCHED_ROUND_ROBIN,
4882 LPFC_FCP_SCHED_BY_CPU,
4883 "Determine scheduling algorithm for "
4884 "issuing commands [0] - Round Robin, [1] - Current CPU");
49aa143d 4885
a6571c6e
JS
4886/*
4887# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4888# range is [0,1]. Default value is 0.
4889# For [0], bus reset issues target reset to ALL devices
4890# For [1], bus reset issues target reset to non-FCP2 devices
4891*/
4892LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4893 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4894
4895
dea3101e
JB
4896/*
4897# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4898# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
7054a606 4899# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea3101e
JB
4900# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4901# cr_delay is set to 0.
4902*/
8189fd19 4903LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea3101e
JB
4904 "interrupt response is generated");
4905
8189fd19 4906LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea3101e
JB
4907 "interrupt response is generated");
4908
cf5bf97e
JW
4909/*
4910# lpfc_multi_ring_support: Determines how many rings to spread available
4911# cmd/rsp IOCB entries across.
4912# Value range is [1,2]. Default value is 1.
4913*/
4914LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4915 "SLI rings to spread IOCB entries across");
4916
a4bc3379
JS
4917/*
4918# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4919# identifies what rctl value to configure the additional ring for.
4920# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4921*/
6a9c52cf 4922LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
a4bc3379
JS
4923 255, "Identifies RCTL for additional ring configuration");
4924
4925/*
4926# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4927# identifies what type value to configure the additional ring for.
4928# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4929*/
6a9c52cf 4930LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
a4bc3379
JS
4931 255, "Identifies TYPE for additional ring configuration");
4932
dea3101e 4933/*
4258e98e
JS
4934# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4935# 0 = SmartSAN functionality disabled (default)
4936# 1 = SmartSAN functionality enabled
4937# This parameter will override the value of lpfc_fdmi_on module parameter.
4938# Value range is [0,1]. Default value is 0.
dea3101e 4939*/
4258e98e
JS
4940LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4941
4942/*
4943# lpfc_fdmi_on: Controls FDMI support.
4944# 0 No FDMI support (default)
4945# 1 Traditional FDMI support
8663cbbe
JS
4946# Traditional FDMI support means the driver will assume FDMI-2 support;
4947# however, if that fails, it will fallback to FDMI-1.
4948# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4949# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4950# lpfc_fdmi_on.
4951# Value range [0,1]. Default value is 0.
4258e98e 4952*/
8663cbbe 4953LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
dea3101e
JB
4954
4955/*
4956# Specifies the maximum number of ELS cmds we can have outstanding (for
4957# discovery). Value range is [1,64]. Default value = 32.
4958*/
3de2a653 4959LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea3101e
JB
4960 "during discovery");
4961
4962/*
c4a7c922
JS
4963# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4964# will be scanned by the SCSI midlayer when sequential scanning is
4965# used; and is also the highest LUN ID allowed when the SCSI midlayer
4966# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4967# LUN ID limit, but the SCSI midlayer requires this field for the uses
4968# above. The lpfc driver limits the default value to 255 for two reasons.
4969# As it bounds the sequential scan loop, scanning for thousands of luns
4970# on a target can take minutes of wall clock time. Additionally,
4971# there are FC targets, such as JBODs, that only recognize 8-bits of
4972# LUN ID. When they receive a value greater than 8 bits, they chop off
4973# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4974# and so on all as LUN ID 0. This causes the linux kernel, which sees
4975# valid responses at each of the LUN IDs, to believe there are multiple
4976# devices present, when in fact, there is only 1.
4977# A customer that is aware of their target behaviors, and the results as
4978# indicated above, is welcome to increase the lpfc_max_luns value.
4979# As mentioned, this value is not used by the lpfc driver, only the
4980# SCSI midlayer.
65a29c16
JS
4981# Value range is [0,65535]. Default value is 255.
4982# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea3101e 4983*/
1abf635d 4984LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea3101e 4985
875fbdfe
JSEC
4986/*
4987# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4988# Value range is [1,255], default value is 10.
4989*/
4990LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4991 "Milliseconds driver will wait between polling FCP ring");
4992
4ff43246 4993/*
0c411222
JS
4994# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4995# to complete in seconds. Value range is [5,180], default value is 60.
4996*/
4997LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4998 "Maximum time to wait for task management commands to complete");
4999/*
4ff43246
JS
5000# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5001# support this feature
8605c46c 5002# 0 = MSI disabled
4ff43246 5003# 1 = MSI enabled
8605c46c
GK
5004# 2 = MSI-X enabled (default)
5005# Value range is [0,2]. Default value is 2.
4ff43246 5006*/
8605c46c 5007LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
db2378e0 5008 "MSI-X (2), if possible");
4ff43246 5009
67d12733 5010/*
f358dd0c 5011 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
895427bd
JS
5012 *
5013 * 0 = NVME OAS disabled
5014 * 1 = NVME OAS enabled
5015 *
5016 * Value range is [0,1]. Default value is 0.
5017 */
5018LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5019 "Use OAS bit on NVME IOs");
5020
5021/*
5022 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
5023 * will advertise it supports to the SCSI layer. This also will map to
5024 * the number of WQs the driver will create.
5025 *
5026 * 0 = Configure the number of io channels to the number of active CPUs.
5027 * 1,32 = Manually specify how many io channels to use.
5028 *
5029 * Value range is [0,32]. Default value is 4.
5030 */
5031LPFC_ATTR_R(fcp_io_channel,
5032 LPFC_FCP_IO_CHAN_DEF,
5033 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
67d12733
JS
5034 "Set the number of FCP I/O channels");
5035
895427bd
JS
5036/*
5037 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
5038 * will advertise it supports to the NVME layer. This also will map to
5039 * the number of WQs the driver will create.
5040 *
5041 * This module parameter is valid when lpfc_enable_fc4_type is set
5042 * to support NVME.
5043 *
5044 * The NVME Layer will try to create this many, plus 1 administrative
5045 * hardware queue. The administrative queue will always map to WQ 0
5046 * A hardware IO queue maps (qidx) to a specific driver WQ.
5047 *
5048 * 0 = Configure the number of io channels to the number of active CPUs.
5049 * 1,32 = Manually specify how many io channels to use.
5050 *
5051 * Value range is [0,32]. Default value is 0.
5052 */
5053LPFC_ATTR_R(nvme_io_channel,
5054 LPFC_NVME_IO_CHAN_DEF,
5055 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
5056 "Set the number of NVME I/O channels");
5057
13815c83
JS
5058/*
5059# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5060# 0 = HBA resets disabled
5061# 1 = HBA resets enabled (default)
5062# Value range is [0,1]. Default value is 1.
5063*/
5064LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
c3f28afa 5065
13815c83 5066/*
eb7a339e 5067# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
13815c83
JS
5068# 0 = HBA Heartbeat disabled
5069# 1 = HBA Heartbeat enabled (default)
5070# Value range is [0,1]. Default value is 1.
5071*/
eb7a339e 5072LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
92d7f7b0 5073
1ba981fd
JS
5074/*
5075# lpfc_EnableXLane: Enable Express Lane Feature
5076# 0x0 Express Lane Feature disabled
5077# 0x1 Express Lane Feature enabled
5078# Value range is [0,1]. Default value is 0.
5079*/
5080LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5081
5082/*
5083# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5084# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5085# Value range is [0x0,0x7f]. Default value is 0
5086*/
28d7f3df 5087LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
1ba981fd 5088
81301a9b
JS
5089/*
5090# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5091# 0 = BlockGuard disabled (default)
5092# 1 = BlockGuard enabled
5093# Value range is [0,1]. Default value is 0.
5094*/
5095LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5096
ba20c853
JS
5097/*
5098# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5099# 0 = disabled (default)
5100# 1 = enabled
5101# Value range is [0,1]. Default value is 0.
5688d670
JS
5102#
5103# This feature in under investigation and may be supported in the future.
ba20c853
JS
5104*/
5105unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5106
81301a9b
JS
5107/*
5108# lpfc_prot_mask: i
5109# - Bit mask of host protection capabilities used to register with the
5110# SCSI mid-layer
5111# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5112# - Allows you to ultimately specify which profiles to use
5113# - Default will result in registering capabilities for all profiles.
005ffa70
JS
5114# - SHOST_DIF_TYPE1_PROTECTION 1
5115# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5116# - SHOST_DIX_TYPE0_PROTECTION 8
5117# HBA supports DIX Type 0: Host to HBA protection only
5118# - SHOST_DIX_TYPE1_PROTECTION 16
5119# HBA supports DIX Type 1: Host to HBA Type 1 protection
81301a9b
JS
5120#
5121*/
b3b98b74
JS
5122LPFC_ATTR(prot_mask,
5123 (SHOST_DIF_TYPE1_PROTECTION |
5124 SHOST_DIX_TYPE0_PROTECTION |
5125 SHOST_DIX_TYPE1_PROTECTION),
5126 0,
5127 (SHOST_DIF_TYPE1_PROTECTION |
5128 SHOST_DIX_TYPE0_PROTECTION |
5129 SHOST_DIX_TYPE1_PROTECTION),
5130 "T10-DIF host protection capabilities mask");
81301a9b
JS
5131
5132/*
5133# lpfc_prot_guard: i
5134# - Bit mask of protection guard types to register with the SCSI mid-layer
005ffa70 5135# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
81301a9b
JS
5136# - Allows you to ultimately specify which profiles to use
5137# - Default will result in registering capabilities for all guard types
5138#
5139*/
b3b98b74
JS
5140LPFC_ATTR(prot_guard,
5141 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5142 "T10-DIF host protection guard type");
81301a9b 5143
92494144
JS
5144/*
5145 * Delay initial NPort discovery when Clean Address bit is cleared in
5146 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5147 * This parameter can have value 0 or 1.
5148 * When this parameter is set to 0, no delay is added to the initial
5149 * discovery.
5150 * When this parameter is set to non-zero value, initial Nport discovery is
5151 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5152 * accept and FCID/Fabric name/Fabric portname is changed.
5153 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5154 * when Clean Address bit is cleared in FLOGI/FDISC
5155 * accept and FCID/Fabric name/Fabric portname is changed.
5156 * Default value is 0.
5157 */
8eb8b960
JS
5158LPFC_ATTR(delay_discovery, 0, 0, 1,
5159 "Delay NPort discovery when Clean Address bit is cleared.");
81301a9b 5160
83108bd3 5161/*
3621a710 5162 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
96f7077f 5163 * This value can be set to values between 64 and 4096. The default value is
83108bd3
JS
5164 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5165 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
96f7077f
JS
5166 * Because of the additional overhead involved in setting up T10-DIF,
5167 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5168 * and will be limited to 512 if BlockGuard is enabled under SLI3.
83108bd3 5169 */
f414fb4e 5170LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_MIN_SG_SEG_CNT,
83108bd3
JS
5171 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5172
7bdedb34
JS
5173/*
5174 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5175 * 0 = MDS Diagnostics disabled (default)
5176 * 1 = MDS Diagnostics enabled
5177 * Value range is [0,1]. Default value is 0.
5178 */
5179LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5180
44fd7fe3
JS
5181/*
5182 * lpfc_enable_bbcr: Enable BB Credit Recovery
5183 * 0 = BB Credit Recovery disabled
5184 * 1 = BB Credit Recovery enabled (default)
5185 * Value range is [0,1]. Default value is 1.
5186 */
5187LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5188
ee959b00 5189struct device_attribute *lpfc_hba_attrs[] = {
895427bd 5190 &dev_attr_nvme_info,
81301a9b
JS
5191 &dev_attr_bg_info,
5192 &dev_attr_bg_guard_err,
5193 &dev_attr_bg_apptag_err,
5194 &dev_attr_bg_reftag_err,
ee959b00
TJ
5195 &dev_attr_info,
5196 &dev_attr_serialnum,
5197 &dev_attr_modeldesc,
5198 &dev_attr_modelname,
5199 &dev_attr_programtype,
5200 &dev_attr_portnum,
5201 &dev_attr_fwrev,
5202 &dev_attr_hdw,
5203 &dev_attr_option_rom_version,
bbd1ae41 5204 &dev_attr_link_state,
ee959b00 5205 &dev_attr_num_discovered_ports,
84774a4d 5206 &dev_attr_menlo_mgmt_mode,
ee959b00 5207 &dev_attr_lpfc_drvr_version,
45ed1190 5208 &dev_attr_lpfc_enable_fip,
ee959b00
TJ
5209 &dev_attr_lpfc_temp_sensor,
5210 &dev_attr_lpfc_log_verbose,
5211 &dev_attr_lpfc_lun_queue_depth,
7dc517df 5212 &dev_attr_lpfc_tgt_queue_depth,
ee959b00
TJ
5213 &dev_attr_lpfc_hba_queue_depth,
5214 &dev_attr_lpfc_peer_port_login,
5215 &dev_attr_lpfc_nodev_tmo,
5216 &dev_attr_lpfc_devloss_tmo,
895427bd
JS
5217 &dev_attr_lpfc_enable_fc4_type,
5218 &dev_attr_lpfc_xri_split,
ee959b00
TJ
5219 &dev_attr_lpfc_fcp_class,
5220 &dev_attr_lpfc_use_adisc,
3cb01c57 5221 &dev_attr_lpfc_first_burst_size,
ee959b00
TJ
5222 &dev_attr_lpfc_ack0,
5223 &dev_attr_lpfc_topology,
5224 &dev_attr_lpfc_scan_down,
5225 &dev_attr_lpfc_link_speed,
49aa143d 5226 &dev_attr_lpfc_fcp_io_sched,
a6571c6e 5227 &dev_attr_lpfc_fcp2_no_tgt_reset,
ee959b00
TJ
5228 &dev_attr_lpfc_cr_delay,
5229 &dev_attr_lpfc_cr_count,
5230 &dev_attr_lpfc_multi_ring_support,
5231 &dev_attr_lpfc_multi_ring_rctl,
5232 &dev_attr_lpfc_multi_ring_type,
5233 &dev_attr_lpfc_fdmi_on,
4258e98e 5234 &dev_attr_lpfc_enable_SmartSAN,
ee959b00
TJ
5235 &dev_attr_lpfc_max_luns,
5236 &dev_attr_lpfc_enable_npiv,
7d791df7 5237 &dev_attr_lpfc_fcf_failover_policy,
19ca7609 5238 &dev_attr_lpfc_enable_rrq,
ee959b00
TJ
5239 &dev_attr_nport_evt_cnt,
5240 &dev_attr_board_mode,
5241 &dev_attr_max_vpi,
5242 &dev_attr_used_vpi,
5243 &dev_attr_max_rpi,
5244 &dev_attr_used_rpi,
5245 &dev_attr_max_xri,
5246 &dev_attr_used_xri,
5247 &dev_attr_npiv_info,
5248 &dev_attr_issue_reset,
5249 &dev_attr_lpfc_poll,
5250 &dev_attr_lpfc_poll_tmo,
0c411222 5251 &dev_attr_lpfc_task_mgmt_tmo,
ee959b00 5252 &dev_attr_lpfc_use_msi,
895427bd 5253 &dev_attr_lpfc_nvme_oas,
0cf07f84 5254 &dev_attr_lpfc_auto_imax,
da0436e9 5255 &dev_attr_lpfc_fcp_imax,
7bb03bbf 5256 &dev_attr_lpfc_fcp_cpu_map,
67d12733 5257 &dev_attr_lpfc_fcp_io_channel,
f358dd0c 5258 &dev_attr_lpfc_suppress_rsp,
895427bd 5259 &dev_attr_lpfc_nvme_io_channel,
2d7dbc4c 5260 &dev_attr_lpfc_nvmet_mrq,
895427bd 5261 &dev_attr_lpfc_nvme_enable_fb,
2d7dbc4c 5262 &dev_attr_lpfc_nvmet_fb_size,
81301a9b 5263 &dev_attr_lpfc_enable_bg,
352e5fd1
JS
5264 &dev_attr_lpfc_soft_wwnn,
5265 &dev_attr_lpfc_soft_wwpn,
5266 &dev_attr_lpfc_soft_wwn_enable,
ee959b00
TJ
5267 &dev_attr_lpfc_enable_hba_reset,
5268 &dev_attr_lpfc_enable_hba_heartbeat,
1ba981fd
JS
5269 &dev_attr_lpfc_EnableXLane,
5270 &dev_attr_lpfc_XLanePriority,
5271 &dev_attr_lpfc_xlane_lun,
5272 &dev_attr_lpfc_xlane_tgt,
5273 &dev_attr_lpfc_xlane_vpt,
5274 &dev_attr_lpfc_xlane_lun_state,
5275 &dev_attr_lpfc_xlane_lun_status,
c92c841c 5276 &dev_attr_lpfc_xlane_priority,
ee959b00 5277 &dev_attr_lpfc_sg_seg_cnt,
977b5a0a 5278 &dev_attr_lpfc_max_scsicmpl_time,
ea2151b4 5279 &dev_attr_lpfc_stat_data_ctrl,
0d878419
JS
5280 &dev_attr_lpfc_aer_support,
5281 &dev_attr_lpfc_aer_state_cleanup,
912e3acd 5282 &dev_attr_lpfc_sriov_nr_virtfn,
c71ab861 5283 &dev_attr_lpfc_req_fw_upgrade,
84d1b006 5284 &dev_attr_lpfc_suppress_link_up,
2a9bf3d0
JS
5285 &dev_attr_lpfc_iocb_cnt,
5286 &dev_attr_iocb_hw,
5287 &dev_attr_txq_hw,
5288 &dev_attr_txcmplq_hw,
bc73905a
JS
5289 &dev_attr_lpfc_fips_level,
5290 &dev_attr_lpfc_fips_rev,
ab56dc2e 5291 &dev_attr_lpfc_dss,
912e3acd 5292 &dev_attr_lpfc_sriov_hw_max_virtfn,
026abb87 5293 &dev_attr_protocol,
1ba981fd 5294 &dev_attr_lpfc_xlane_supported,
7bdedb34 5295 &dev_attr_lpfc_enable_mds_diags,
44fd7fe3 5296 &dev_attr_lpfc_enable_bbcr,
dea3101e
JB
5297 NULL,
5298};
5299
ee959b00
TJ
5300struct device_attribute *lpfc_vport_attrs[] = {
5301 &dev_attr_info,
bbd1ae41 5302 &dev_attr_link_state,
ee959b00
TJ
5303 &dev_attr_num_discovered_ports,
5304 &dev_attr_lpfc_drvr_version,
5305 &dev_attr_lpfc_log_verbose,
5306 &dev_attr_lpfc_lun_queue_depth,
7dc517df 5307 &dev_attr_lpfc_tgt_queue_depth,
ee959b00
TJ
5308 &dev_attr_lpfc_nodev_tmo,
5309 &dev_attr_lpfc_devloss_tmo,
5310 &dev_attr_lpfc_hba_queue_depth,
5311 &dev_attr_lpfc_peer_port_login,
5312 &dev_attr_lpfc_restrict_login,
5313 &dev_attr_lpfc_fcp_class,
5314 &dev_attr_lpfc_use_adisc,
3cb01c57 5315 &dev_attr_lpfc_first_burst_size,
ee959b00
TJ
5316 &dev_attr_lpfc_max_luns,
5317 &dev_attr_nport_evt_cnt,
5318 &dev_attr_npiv_info,
5319 &dev_attr_lpfc_enable_da_id,
ea2151b4
JS
5320 &dev_attr_lpfc_max_scsicmpl_time,
5321 &dev_attr_lpfc_stat_data_ctrl,
21e9a0a5 5322 &dev_attr_lpfc_static_vport,
bc73905a
JS
5323 &dev_attr_lpfc_fips_level,
5324 &dev_attr_lpfc_fips_rev,
3de2a653
JS
5325 NULL,
5326};
5327
e59058c4 5328/**
3621a710 5329 * sysfs_ctlreg_write - Write method for writing to ctlreg
2c3c8bea 5330 * @filp: open sysfs file
e59058c4
JS
5331 * @kobj: kernel kobject that contains the kernel class device.
5332 * @bin_attr: kernel attributes passed to us.
5333 * @buf: contains the data to be written to the adapter IOREG space.
5334 * @off: offset into buffer to beginning of data.
5335 * @count: bytes to transfer.
5336 *
5337 * Description:
5338 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5339 * Uses the adapter io control registers to send buf contents to the adapter.
5340 *
5341 * Returns:
5342 * -ERANGE off and count combo out of range
5343 * -EINVAL off, count or buff address invalid
5344 * -EPERM adapter is offline
5345 * value of count, buf contents written
5346 **/
dea3101e 5347static ssize_t
2c3c8bea
CW
5348sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5349 struct bin_attribute *bin_attr,
91a69029 5350 char *buf, loff_t off, size_t count)
dea3101e
JB
5351{
5352 size_t buf_off;
ee959b00
TJ
5353 struct device *dev = container_of(kobj, struct device, kobj);
5354 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
5355 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5356 struct lpfc_hba *phba = vport->phba;
dea3101e 5357
f1126688
JS
5358 if (phba->sli_rev >= LPFC_SLI_REV4)
5359 return -EPERM;
5360
dea3101e
JB
5361 if ((off + count) > FF_REG_AREA_SIZE)
5362 return -ERANGE;
5363
f7a919b4
JS
5364 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5365 return 0;
dea3101e
JB
5366
5367 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5368 return -EINVAL;
5369
f7a919b4
JS
5370 /* This is to protect HBA registers from accidental writes. */
5371 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5372 return -EINVAL;
5373
5374 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea3101e 5375 return -EPERM;
dea3101e 5376
2e0fef85 5377 spin_lock_irq(&phba->hbalock);
f7a919b4
JS
5378 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5379 buf_off += sizeof(uint32_t))
5380 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea3101e
JB
5381 phba->ctrl_regs_memmap_p + off + buf_off);
5382
2e0fef85 5383 spin_unlock_irq(&phba->hbalock);
dea3101e
JB
5384
5385 return count;
5386}
5387
e59058c4 5388/**
3621a710 5389 * sysfs_ctlreg_read - Read method for reading from ctlreg
2c3c8bea 5390 * @filp: open sysfs file
e59058c4
JS
5391 * @kobj: kernel kobject that contains the kernel class device.
5392 * @bin_attr: kernel attributes passed to us.
af901ca1 5393 * @buf: if successful contains the data from the adapter IOREG space.
e59058c4
JS
5394 * @off: offset into buffer to beginning of data.
5395 * @count: bytes to transfer.
5396 *
5397 * Description:
5398 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5399 * Uses the adapter io control registers to read data into buf.
5400 *
5401 * Returns:
5402 * -ERANGE off and count combo out of range
5403 * -EINVAL off, count or buff address invalid
5404 * value of count, buf contents read
5405 **/
dea3101e 5406static ssize_t
2c3c8bea
CW
5407sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5408 struct bin_attribute *bin_attr,
91a69029 5409 char *buf, loff_t off, size_t count)
dea3101e
JB
5410{
5411 size_t buf_off;
5412 uint32_t * tmp_ptr;
ee959b00
TJ
5413 struct device *dev = container_of(kobj, struct device, kobj);
5414 struct Scsi_Host *shost = class_to_shost(dev);
2e0fef85
JS
5415 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5416 struct lpfc_hba *phba = vport->phba;
dea3101e 5417
f1126688
JS
5418 if (phba->sli_rev >= LPFC_SLI_REV4)
5419 return -EPERM;
5420
dea3101e
JB
5421 if (off > FF_REG_AREA_SIZE)
5422 return -ERANGE;
5423
5424 if ((off + count) > FF_REG_AREA_SIZE)
5425 count = FF_REG_AREA_SIZE - off;
5426
5427 if (count == 0) return 0;
5428
5429 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5430 return -EINVAL;
5431
2e0fef85 5432 spin_lock_irq(&phba->hbalock);
dea3101e
JB
5433
5434 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5435 tmp_ptr = (uint32_t *)(buf + buf_off);
5436 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5437 }
5438
2e0fef85 5439 spin_unlock_irq(&phba->hbalock);
dea3101e
JB
5440
5441 return count;
5442}
5443
5444static struct bin_attribute sysfs_ctlreg_attr = {
5445 .attr = {
5446 .name = "ctlreg",
5447 .mode = S_IRUSR | S_IWUSR,
dea3101e
JB
5448 },
5449 .size = 256,
5450 .read = sysfs_ctlreg_read,
5451 .write = sysfs_ctlreg_write,
5452};
5453
e59058c4 5454/**
3621a710 5455 * sysfs_mbox_write - Write method for writing information via mbox
2c3c8bea 5456 * @filp: open sysfs file
e59058c4
JS
5457 * @kobj: kernel kobject that contains the kernel class device.
5458 * @bin_attr: kernel attributes passed to us.
5459 * @buf: contains the data to be written to sysfs mbox.
5460 * @off: offset into buffer to beginning of data.
5461 * @count: bytes to transfer.
5462 *
5463 * Description:
026abb87
JS
5464 * Deprecated function. All mailbox access from user space is performed via the
5465 * bsg interface.
e59058c4
JS
5466 *
5467 * Returns:
026abb87 5468 * -EPERM operation not permitted
e59058c4 5469 **/
dea3101e 5470static ssize_t
2c3c8bea
CW
5471sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5472 struct bin_attribute *bin_attr,
91a69029 5473 char *buf, loff_t off, size_t count)
dea3101e 5474{
026abb87 5475 return -EPERM;
dea3101e
JB
5476}
5477
e59058c4 5478/**
3621a710 5479 * sysfs_mbox_read - Read method for reading information via mbox
2c3c8bea 5480 * @filp: open sysfs file
e59058c4
JS
5481 * @kobj: kernel kobject that contains the kernel class device.
5482 * @bin_attr: kernel attributes passed to us.
5483 * @buf: contains the data to be read from sysfs mbox.
5484 * @off: offset into buffer to beginning of data.
5485 * @count: bytes to transfer.
5486 *
5487 * Description:
026abb87
JS
5488 * Deprecated function. All mailbox access from user space is performed via the
5489 * bsg interface.
e59058c4
JS
5490 *
5491 * Returns:
026abb87 5492 * -EPERM operation not permitted
e59058c4 5493 **/
dea3101e 5494static ssize_t
2c3c8bea
CW
5495sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5496 struct bin_attribute *bin_attr,
91a69029 5497 char *buf, loff_t off, size_t count)
dea3101e 5498{
026abb87 5499 return -EPERM;
dea3101e
JB
5500}
5501
5502static struct bin_attribute sysfs_mbox_attr = {
5503 .attr = {
5504 .name = "mbox",
5505 .mode = S_IRUSR | S_IWUSR,
dea3101e 5506 },
c0c11512 5507 .size = MAILBOX_SYSFS_MAX,
dea3101e
JB
5508 .read = sysfs_mbox_read,
5509 .write = sysfs_mbox_write,
5510};
5511
e59058c4 5512/**
3621a710 5513 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
e59058c4
JS
5514 * @vport: address of lpfc vport structure.
5515 *
5516 * Return codes:
5517 * zero on success
5518 * error return code from sysfs_create_bin_file()
5519 **/
dea3101e 5520int
2e0fef85 5521lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea3101e 5522{
2e0fef85 5523 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea3101e
JB
5524 int error;
5525
ee959b00 5526 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
eada272d
JS
5527 &sysfs_drvr_stat_data_attr);
5528
5529 /* Virtual ports do not need ctrl_reg and mbox */
5530 if (error || vport->port_type == LPFC_NPIV_PORT)
dea3101e
JB
5531 goto out;
5532
ee959b00 5533 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
eada272d 5534 &sysfs_ctlreg_attr);
dea3101e 5535 if (error)
eada272d 5536 goto out_remove_stat_attr;
dea3101e 5537
ea2151b4 5538 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
eada272d 5539 &sysfs_mbox_attr);
ea2151b4 5540 if (error)
eada272d 5541 goto out_remove_ctlreg_attr;
ea2151b4 5542
dea3101e
JB
5543 return 0;
5544out_remove_ctlreg_attr:
ee959b00 5545 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
eada272d
JS
5546out_remove_stat_attr:
5547 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5548 &sysfs_drvr_stat_data_attr);
dea3101e
JB
5549out:
5550 return error;
5551}
5552
e59058c4 5553/**
3621a710 5554 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
e59058c4
JS
5555 * @vport: address of lpfc vport structure.
5556 **/
dea3101e 5557void
2e0fef85 5558lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea3101e 5559{
2e0fef85 5560 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
ea2151b4
JS
5561 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5562 &sysfs_drvr_stat_data_attr);
eada272d
JS
5563 /* Virtual ports do not need ctrl_reg and mbox */
5564 if (vport->port_type == LPFC_NPIV_PORT)
5565 return;
ee959b00
TJ
5566 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5567 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea3101e
JB
5568}
5569
dea3101e
JB
5570/*
5571 * Dynamic FC Host Attributes Support
5572 */
5573
6c9231f6
JS
5574/**
5575 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5576 * @shost: kernel scsi host pointer.
5577 **/
5578static void
5579lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5580{
5581 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5582
5583 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5584 sizeof fc_host_symbolic_name(shost));
5585}
5586
e59058c4 5587/**
3621a710 5588 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
e59058c4
JS
5589 * @shost: kernel scsi host pointer.
5590 **/
dea3101e
JB
5591static void
5592lpfc_get_host_port_id(struct Scsi_Host *shost)
5593{
2e0fef85
JS
5594 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5595
dea3101e 5596 /* note: fc_myDID already in cpu endianness */
2e0fef85 5597 fc_host_port_id(shost) = vport->fc_myDID;
dea3101e
JB
5598}
5599
e59058c4 5600/**
3621a710 5601 * lpfc_get_host_port_type - Set the value of the scsi host port type
e59058c4
JS
5602 * @shost: kernel scsi host pointer.
5603 **/
dea3101e
JB
5604static void
5605lpfc_get_host_port_type(struct Scsi_Host *shost)
5606{
2e0fef85
JS
5607 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5608 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
5609
5610 spin_lock_irq(shost->host_lock);
5611
92d7f7b0
JS
5612 if (vport->port_type == LPFC_NPIV_PORT) {
5613 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5614 } else if (lpfc_is_link_up(phba)) {
76a95d75 5615 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2e0fef85 5616 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea3101e
JB
5617 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5618 else
5619 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5620 } else {
2e0fef85 5621 if (vport->fc_flag & FC_FABRIC)
dea3101e
JB
5622 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5623 else
5624 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5625 }
5626 } else
5627 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5628
5629 spin_unlock_irq(shost->host_lock);
5630}
5631
e59058c4 5632/**
3621a710 5633 * lpfc_get_host_port_state - Set the value of the scsi host port state
e59058c4
JS
5634 * @shost: kernel scsi host pointer.
5635 **/
dea3101e
JB
5636static void
5637lpfc_get_host_port_state(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
2e0fef85 5644 if (vport->fc_flag & FC_OFFLINE_MODE)
dea3101e
JB
5645 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5646 else {
2e0fef85
JS
5647 switch (phba->link_state) {
5648 case LPFC_LINK_UNKNOWN:
dea3101e
JB
5649 case LPFC_LINK_DOWN:
5650 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5651 break;
5652 case LPFC_LINK_UP:
dea3101e
JB
5653 case LPFC_CLEAR_LA:
5654 case LPFC_HBA_READY:
026abb87
JS
5655 /* Links up, reports port state accordingly */
5656 if (vport->port_state < LPFC_VPORT_READY)
5657 fc_host_port_state(shost) =
5658 FC_PORTSTATE_BYPASSED;
5659 else
5660 fc_host_port_state(shost) =
5661 FC_PORTSTATE_ONLINE;
dea3101e
JB
5662 break;
5663 case LPFC_HBA_ERROR:
5664 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5665 break;
5666 default:
5667 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5668 break;
5669 }
5670 }
5671
5672 spin_unlock_irq(shost->host_lock);
5673}
5674
e59058c4 5675/**
3621a710 5676 * lpfc_get_host_speed - Set the value of the scsi host speed
e59058c4
JS
5677 * @shost: kernel scsi host pointer.
5678 **/
dea3101e
JB
5679static void
5680lpfc_get_host_speed(struct Scsi_Host *shost)
5681{
2e0fef85
JS
5682 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5683 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
5684
5685 spin_lock_irq(shost->host_lock);
5686
a085e87c 5687 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea3101e 5688 switch(phba->fc_linkspeed) {
76a95d75
JS
5689 case LPFC_LINK_SPEED_1GHZ:
5690 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea3101e 5691 break;
76a95d75
JS
5692 case LPFC_LINK_SPEED_2GHZ:
5693 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea3101e 5694 break;
76a95d75
JS
5695 case LPFC_LINK_SPEED_4GHZ:
5696 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea3101e 5697 break;
76a95d75
JS
5698 case LPFC_LINK_SPEED_8GHZ:
5699 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
b87eab38 5700 break;
76a95d75
JS
5701 case LPFC_LINK_SPEED_10GHZ:
5702 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
f4b4c68f 5703 break;
76a95d75
JS
5704 case LPFC_LINK_SPEED_16GHZ:
5705 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5706 break;
d38dd52c
JS
5707 case LPFC_LINK_SPEED_32GHZ:
5708 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5709 break;
76a95d75
JS
5710 default:
5711 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea3101e
JB
5712 break;
5713 }
09372820
JS
5714 } else
5715 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea3101e
JB
5716
5717 spin_unlock_irq(shost->host_lock);
5718}
5719
e59058c4 5720/**
3621a710 5721 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
e59058c4
JS
5722 * @shost: kernel scsi host pointer.
5723 **/
dea3101e
JB
5724static void
5725lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5726{
2e0fef85
JS
5727 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5728 struct lpfc_hba *phba = vport->phba;
f631b4be 5729 u64 node_name;
dea3101e
JB
5730
5731 spin_lock_irq(shost->host_lock);
5732
73d91e50
JS
5733 if ((vport->port_state > LPFC_FLOGI) &&
5734 ((vport->fc_flag & FC_FABRIC) ||
5735 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5736 (vport->fc_flag & FC_PUBLIC_LOOP))))
68ce1eb5 5737 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea3101e
JB
5738 else
5739 /* fabric is local port if there is no F/FL_Port */
09372820 5740 node_name = 0;
dea3101e
JB
5741
5742 spin_unlock_irq(shost->host_lock);
5743
f631b4be 5744 fc_host_fabric_name(shost) = node_name;
dea3101e
JB
5745}
5746
e59058c4 5747/**
3621a710 5748 * lpfc_get_stats - Return statistical information about the adapter
e59058c4
JS
5749 * @shost: kernel scsi host pointer.
5750 *
5751 * Notes:
5752 * NULL on error for link down, no mbox pool, sli2 active,
5753 * management not allowed, memory allocation error, or mbox error.
5754 *
5755 * Returns:
5756 * NULL for error
5757 * address of the adapter host statistics
5758 **/
dea3101e
JB
5759static struct fc_host_statistics *
5760lpfc_get_stats(struct Scsi_Host *shost)
5761{
2e0fef85
JS
5762 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5763 struct lpfc_hba *phba = vport->phba;
5764 struct lpfc_sli *psli = &phba->sli;
f888ba3c 5765 struct fc_host_statistics *hs = &phba->link_stats;
64ba8818 5766 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea3101e
JB
5767 LPFC_MBOXQ_t *pmboxq;
5768 MAILBOX_t *pmb;
64ba8818 5769 unsigned long seconds;
433c3579 5770 int rc = 0;
dea3101e 5771
92d7f7b0
JS
5772 /*
5773 * prevent udev from issuing mailbox commands until the port is
5774 * configured.
5775 */
2e0fef85
JS
5776 if (phba->link_state < LPFC_LINK_DOWN ||
5777 !phba->mbox_mem_pool ||
f4b4c68f 5778 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
92d7f7b0 5779 return NULL;
2e0fef85
JS
5780
5781 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
46fa311e
JS
5782 return NULL;
5783
dea3101e
JB
5784 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5785 if (!pmboxq)
5786 return NULL;
5787 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5788
04c68496 5789 pmb = &pmboxq->u.mb;
dea3101e
JB
5790 pmb->mbxCommand = MBX_READ_STATUS;
5791 pmb->mbxOwner = OWN_HOST;
5792 pmboxq->context1 = NULL;
92d7f7b0 5793 pmboxq->vport = vport;
dea3101e 5794
75baf696 5795 if (vport->fc_flag & FC_OFFLINE_MODE)
dea3101e 5796 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
433c3579 5797 else
dea3101e
JB
5798 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5799
5800 if (rc != MBX_SUCCESS) {
858c9f6c 5801 if (rc != MBX_TIMEOUT)
433c3579 5802 mempool_free(pmboxq, phba->mbox_mem_pool);
dea3101e
JB
5803 return NULL;
5804 }
5805
f888ba3c
JSEC
5806 memset(hs, 0, sizeof (struct fc_host_statistics));
5807
dea3101e 5808 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
73d91e50
JS
5809 /*
5810 * The MBX_READ_STATUS returns tx_k_bytes which has to
5811 * converted to words
5812 */
5813 hs->tx_words = (uint64_t)
5814 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5815 * (uint64_t)256);
dea3101e 5816 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
73d91e50
JS
5817 hs->rx_words = (uint64_t)
5818 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5819 * (uint64_t)256);
dea3101e 5820
433c3579 5821 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea3101e
JB
5822 pmb->mbxCommand = MBX_READ_LNK_STAT;
5823 pmb->mbxOwner = OWN_HOST;
5824 pmboxq->context1 = NULL;
92d7f7b0 5825 pmboxq->vport = vport;
dea3101e 5826
75baf696 5827 if (vport->fc_flag & FC_OFFLINE_MODE)
dea3101e 5828 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
433c3579 5829 else
dea3101e
JB
5830 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5831
5832 if (rc != MBX_SUCCESS) {
858c9f6c 5833 if (rc != MBX_TIMEOUT)
92d7f7b0 5834 mempool_free(pmboxq, phba->mbox_mem_pool);
dea3101e
JB
5835 return NULL;
5836 }
5837
5838 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5839 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5840 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5841 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5842 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5843 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5844 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5845
64ba8818
JS
5846 hs->link_failure_count -= lso->link_failure_count;
5847 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5848 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5849 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5850 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5851 hs->invalid_crc_count -= lso->invalid_crc_count;
5852 hs->error_frames -= lso->error_frames;
5853
76a95d75 5854 if (phba->hba_flag & HBA_FCOE_MODE) {
4d9ab994
JS
5855 hs->lip_count = -1;
5856 hs->nos_count = (phba->link_events >> 1);
5857 hs->nos_count -= lso->link_events;
76a95d75 5858 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea3101e 5859 hs->lip_count = (phba->fc_eventTag >> 1);
64ba8818 5860 hs->lip_count -= lso->link_events;
dea3101e
JB
5861 hs->nos_count = -1;
5862 } else {
5863 hs->lip_count = -1;
5864 hs->nos_count = (phba->fc_eventTag >> 1);
64ba8818 5865 hs->nos_count -= lso->link_events;
dea3101e
JB
5866 }
5867
5868 hs->dumped_frames = -1;
5869
64ba8818
JS
5870 seconds = get_seconds();
5871 if (seconds < psli->stats_start)
5872 hs->seconds_since_last_reset = seconds +
5873 ((unsigned long)-1 - psli->stats_start);
5874 else
5875 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea3101e 5876
1dcb58e5
JS
5877 mempool_free(pmboxq, phba->mbox_mem_pool);
5878
dea3101e
JB
5879 return hs;
5880}
5881
e59058c4 5882/**
3621a710 5883 * lpfc_reset_stats - Copy the adapter link stats information
e59058c4
JS
5884 * @shost: kernel scsi host pointer.
5885 **/
64ba8818
JS
5886static void
5887lpfc_reset_stats(struct Scsi_Host *shost)
5888{
2e0fef85
JS
5889 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5890 struct lpfc_hba *phba = vport->phba;
5891 struct lpfc_sli *psli = &phba->sli;
5892 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
64ba8818
JS
5893 LPFC_MBOXQ_t *pmboxq;
5894 MAILBOX_t *pmb;
5895 int rc = 0;
5896
2e0fef85 5897 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
46fa311e
JS
5898 return;
5899
64ba8818
JS
5900 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5901 if (!pmboxq)
5902 return;
5903 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5904
04c68496 5905 pmb = &pmboxq->u.mb;
64ba8818
JS
5906 pmb->mbxCommand = MBX_READ_STATUS;
5907 pmb->mbxOwner = OWN_HOST;
5908 pmb->un.varWords[0] = 0x1; /* reset request */
5909 pmboxq->context1 = NULL;
92d7f7b0 5910 pmboxq->vport = vport;
64ba8818 5911
2e0fef85 5912 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
f4b4c68f 5913 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
64ba8818
JS
5914 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5915 else
5916 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5917
5918 if (rc != MBX_SUCCESS) {
858c9f6c 5919 if (rc != MBX_TIMEOUT)
64ba8818
JS
5920 mempool_free(pmboxq, phba->mbox_mem_pool);
5921 return;
5922 }
5923
5924 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5925 pmb->mbxCommand = MBX_READ_LNK_STAT;
5926 pmb->mbxOwner = OWN_HOST;
5927 pmboxq->context1 = NULL;
92d7f7b0 5928 pmboxq->vport = vport;
64ba8818 5929
2e0fef85 5930 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
f4b4c68f 5931 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
64ba8818
JS
5932 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5933 else
5934 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5935
5936 if (rc != MBX_SUCCESS) {
858c9f6c 5937 if (rc != MBX_TIMEOUT)
64ba8818
JS
5938 mempool_free( pmboxq, phba->mbox_mem_pool);
5939 return;
5940 }
5941
5942 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5943 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5944 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5945 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5946 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5947 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5948 lso->error_frames = pmb->un.varRdLnk.crcCnt;
76a95d75 5949 if (phba->hba_flag & HBA_FCOE_MODE)
4d9ab994
JS
5950 lso->link_events = (phba->link_events >> 1);
5951 else
5952 lso->link_events = (phba->fc_eventTag >> 1);
64ba8818
JS
5953
5954 psli->stats_start = get_seconds();
5955
1dcb58e5
JS
5956 mempool_free(pmboxq, phba->mbox_mem_pool);
5957
64ba8818
JS
5958 return;
5959}
dea3101e
JB
5960
5961/*
5962 * The LPFC driver treats linkdown handling as target loss events so there
5963 * are no sysfs handlers for link_down_tmo.
5964 */
685f0bf7 5965
e59058c4 5966/**
3621a710 5967 * lpfc_get_node_by_target - Return the nodelist for a target
e59058c4
JS
5968 * @starget: kernel scsi target pointer.
5969 *
5970 * Returns:
5971 * address of the node list if found
5972 * NULL target not found
5973 **/
685f0bf7
JS
5974static struct lpfc_nodelist *
5975lpfc_get_node_by_target(struct scsi_target *starget)
dea3101e 5976{
2e0fef85
JS
5977 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5978 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
685f0bf7 5979 struct lpfc_nodelist *ndlp;
dea3101e
JB
5980
5981 spin_lock_irq(shost->host_lock);
685f0bf7 5982 /* Search for this, mapped, target ID */
2e0fef85 5983 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
e47c9093
JS
5984 if (NLP_CHK_NODE_ACT(ndlp) &&
5985 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
685f0bf7
JS
5986 starget->id == ndlp->nlp_sid) {
5987 spin_unlock_irq(shost->host_lock);
5988 return ndlp;
dea3101e
JB
5989 }
5990 }
5991 spin_unlock_irq(shost->host_lock);
685f0bf7
JS
5992 return NULL;
5993}
dea3101e 5994
e59058c4 5995/**
3621a710 5996 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
e59058c4
JS
5997 * @starget: kernel scsi target pointer.
5998 **/
685f0bf7
JS
5999static void
6000lpfc_get_starget_port_id(struct scsi_target *starget)
6001{
6002 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6003
6004 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea3101e
JB
6005}
6006
e59058c4 6007/**
3621a710 6008 * lpfc_get_starget_node_name - Set the target node name
e59058c4
JS
6009 * @starget: kernel scsi target pointer.
6010 *
6011 * Description: Set the target node name to the ndlp node name wwn or zero.
6012 **/
dea3101e
JB
6013static void
6014lpfc_get_starget_node_name(struct scsi_target *starget)
6015{
685f0bf7 6016 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea3101e 6017
685f0bf7
JS
6018 fc_starget_node_name(starget) =
6019 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea3101e
JB
6020}
6021
e59058c4 6022/**
3621a710 6023 * lpfc_get_starget_port_name - Set the target port name
e59058c4
JS
6024 * @starget: kernel scsi target pointer.
6025 *
6026 * Description: set the target port name to the ndlp port name wwn or zero.
6027 **/
dea3101e
JB
6028static void
6029lpfc_get_starget_port_name(struct scsi_target *starget)
6030{
685f0bf7 6031 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea3101e 6032
685f0bf7
JS
6033 fc_starget_port_name(starget) =
6034 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea3101e
JB
6035}
6036
e59058c4 6037/**
3621a710 6038 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
e59058c4
JS
6039 * @rport: fc rport address.
6040 * @timeout: new value for dev loss tmo.
6041 *
6042 * Description:
6043 * If timeout is non zero set the dev_loss_tmo to timeout, else set
6044 * dev_loss_tmo to one.
6045 **/
dea3101e
JB
6046static void
6047lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6048{
dea3101e 6049 if (timeout)
c01f3208 6050 rport->dev_loss_tmo = timeout;
dea3101e 6051 else
c01f3208 6052 rport->dev_loss_tmo = 1;
dea3101e
JB
6053}
6054
e59058c4 6055/**
3621a710 6056 * lpfc_rport_show_function - Return rport target information
e59058c4
JS
6057 *
6058 * Description:
6059 * Macro that uses field to generate a function with the name lpfc_show_rport_
6060 *
6061 * lpfc_show_rport_##field: returns the bytes formatted in buf
6062 * @cdev: class converted to an fc_rport.
6063 * @buf: on return contains the target_field or zero.
6064 *
6065 * Returns: size of formatted string.
6066 **/
dea3101e
JB
6067#define lpfc_rport_show_function(field, format_string, sz, cast) \
6068static ssize_t \
ee959b00
TJ
6069lpfc_show_rport_##field (struct device *dev, \
6070 struct device_attribute *attr, \
6071 char *buf) \
dea3101e 6072{ \
ee959b00 6073 struct fc_rport *rport = transport_class_to_rport(dev); \
dea3101e
JB
6074 struct lpfc_rport_data *rdata = rport->hostdata; \
6075 return snprintf(buf, sz, format_string, \
6076 (rdata->target) ? cast rdata->target->field : 0); \
6077}
6078
6079#define lpfc_rport_rd_attr(field, format_string, sz) \
6080 lpfc_rport_show_function(field, format_string, sz, ) \
6081static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6082
eada272d 6083/**
3621a710 6084 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
eada272d
JS
6085 * @fc_vport: The fc_vport who's symbolic name has been changed.
6086 *
6087 * Description:
6088 * This function is called by the transport after the @fc_vport's symbolic name
6089 * has been changed. This function re-registers the symbolic name with the
25985edc 6090 * switch to propagate the change into the fabric if the vport is active.
eada272d
JS
6091 **/
6092static void
6093lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6094{
6095 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6096
6097 if (vport->port_state == LPFC_VPORT_READY)
6098 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6099}
dea3101e 6100
f4b4c68f
JS
6101/**
6102 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6103 * @phba: Pointer to lpfc_hba struct.
6104 *
6105 * This function is called by the lpfc_get_cfgparam() routine to set the
6106 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
70f23fd6 6107 * log message according to the module's lpfc_log_verbose parameter setting
f4b4c68f
JS
6108 * before hba port or vport created.
6109 **/
6110static void
6111lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6112{
6113 phba->cfg_log_verbose = verbose;
6114}
6115
dea3101e
JB
6116struct fc_function_template lpfc_transport_functions = {
6117 /* fixed attributes the driver supports */
6118 .show_host_node_name = 1,
6119 .show_host_port_name = 1,
6120 .show_host_supported_classes = 1,
6121 .show_host_supported_fc4s = 1,
dea3101e
JB
6122 .show_host_supported_speeds = 1,
6123 .show_host_maxframe_size = 1,
6c9231f6
JS
6124
6125 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
eada272d 6126 .show_host_symbolic_name = 1,
dea3101e
JB
6127
6128 /* dynamic attributes the driver supports */
6129 .get_host_port_id = lpfc_get_host_port_id,
6130 .show_host_port_id = 1,
6131
6132 .get_host_port_type = lpfc_get_host_port_type,
6133 .show_host_port_type = 1,
6134
6135 .get_host_port_state = lpfc_get_host_port_state,
6136 .show_host_port_state = 1,
6137
6138 /* active_fc4s is shown but doesn't change (thus no get function) */
6139 .show_host_active_fc4s = 1,
6140
6141 .get_host_speed = lpfc_get_host_speed,
6142 .show_host_speed = 1,
6143
6144 .get_host_fabric_name = lpfc_get_host_fabric_name,
6145 .show_host_fabric_name = 1,
6146
6147 /*
6148 * The LPFC driver treats linkdown handling as target loss events
6149 * so there are no sysfs handlers for link_down_tmo.
6150 */
6151
6152 .get_fc_host_stats = lpfc_get_stats,
64ba8818 6153 .reset_fc_host_stats = lpfc_reset_stats,
dea3101e
JB
6154
6155 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6156 .show_rport_maxframe_size = 1,
6157 .show_rport_supported_classes = 1,
6158
dea3101e
JB
6159 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6160 .show_rport_dev_loss_tmo = 1,
6161
6162 .get_starget_port_id = lpfc_get_starget_port_id,
6163 .show_starget_port_id = 1,
6164
6165 .get_starget_node_name = lpfc_get_starget_node_name,
6166 .show_starget_node_name = 1,
6167
6168 .get_starget_port_name = lpfc_get_starget_port_name,
6169 .show_starget_port_name = 1,
91ca7b01
AV
6170
6171 .issue_fc_host_lip = lpfc_issue_lip,
c01f3208
JS
6172 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6173 .terminate_rport_io = lpfc_terminate_rport_io,
92d7f7b0 6174
92d7f7b0 6175 .dd_fcvport_size = sizeof(struct lpfc_vport *),
eada272d
JS
6176
6177 .vport_disable = lpfc_vport_disable,
6178
6179 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
f1c3b0fc
JS
6180
6181 .bsg_request = lpfc_bsg_request,
6182 .bsg_timeout = lpfc_bsg_timeout,
92d7f7b0
JS
6183};
6184
98c9ea5c
JS
6185struct fc_function_template lpfc_vport_transport_functions = {
6186 /* fixed attributes the driver supports */
6187 .show_host_node_name = 1,
6188 .show_host_port_name = 1,
6189 .show_host_supported_classes = 1,
6190 .show_host_supported_fc4s = 1,
6191 .show_host_supported_speeds = 1,
6192 .show_host_maxframe_size = 1,
6c9231f6
JS
6193
6194 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
eada272d 6195 .show_host_symbolic_name = 1,
98c9ea5c
JS
6196
6197 /* dynamic attributes the driver supports */
6198 .get_host_port_id = lpfc_get_host_port_id,
6199 .show_host_port_id = 1,
6200
6201 .get_host_port_type = lpfc_get_host_port_type,
6202 .show_host_port_type = 1,
6203
6204 .get_host_port_state = lpfc_get_host_port_state,
6205 .show_host_port_state = 1,
6206
6207 /* active_fc4s is shown but doesn't change (thus no get function) */
6208 .show_host_active_fc4s = 1,
6209
6210 .get_host_speed = lpfc_get_host_speed,
6211 .show_host_speed = 1,
6212
6213 .get_host_fabric_name = lpfc_get_host_fabric_name,
6214 .show_host_fabric_name = 1,
6215
6216 /*
6217 * The LPFC driver treats linkdown handling as target loss events
6218 * so there are no sysfs handlers for link_down_tmo.
6219 */
6220
6221 .get_fc_host_stats = lpfc_get_stats,
6222 .reset_fc_host_stats = lpfc_reset_stats,
6223
6224 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6225 .show_rport_maxframe_size = 1,
6226 .show_rport_supported_classes = 1,
6227
6228 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6229 .show_rport_dev_loss_tmo = 1,
6230
6231 .get_starget_port_id = lpfc_get_starget_port_id,
6232 .show_starget_port_id = 1,
6233
6234 .get_starget_node_name = lpfc_get_starget_node_name,
6235 .show_starget_node_name = 1,
6236
6237 .get_starget_port_name = lpfc_get_starget_port_name,
6238 .show_starget_port_name = 1,
6239
6240 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6241 .terminate_rport_io = lpfc_terminate_rport_io,
6242
6243 .vport_disable = lpfc_vport_disable,
eada272d
JS
6244
6245 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
98c9ea5c
JS
6246};
6247
e59058c4 6248/**
3621a710 6249 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
e59058c4
JS
6250 * @phba: lpfc_hba pointer.
6251 **/
dea3101e
JB
6252void
6253lpfc_get_cfgparam(struct lpfc_hba *phba)
6254{
49aa143d 6255 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
a6571c6e 6256 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
7bcbb752
JSEC
6257 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6258 lpfc_cr_count_init(phba, lpfc_cr_count);
cf5bf97e 6259 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
a4bc3379
JS
6260 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6261 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
7bcbb752
JSEC
6262 lpfc_ack0_init(phba, lpfc_ack0);
6263 lpfc_topology_init(phba, lpfc_topology);
7bcbb752 6264 lpfc_link_speed_init(phba, lpfc_link_speed);
875fbdfe 6265 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
0c411222 6266 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
78b2d852 6267 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
7d791df7 6268 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
19ca7609 6269 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
4258e98e
JS
6270 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6271 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
4ff43246 6272 lpfc_use_msi_init(phba, lpfc_use_msi);
895427bd 6273 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
0cf07f84 6274 lpfc_auto_imax_init(phba, lpfc_auto_imax);
da0436e9 6275 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
7bb03bbf 6276 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
13815c83
JS
6277 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6278 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
2ea259ee 6279
1ba981fd
JS
6280 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6281 if (phba->sli_rev != LPFC_SLI_REV4)
6282 phba->cfg_EnableXLane = 0;
6283 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
2ea259ee 6284
1ba981fd
JS
6285 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6286 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6287 phba->cfg_oas_lun_state = 0;
6288 phba->cfg_oas_lun_status = 0;
6289 phba->cfg_oas_flags = 0;
c92c841c 6290 phba->cfg_oas_priority = 0;
81301a9b 6291 lpfc_enable_bg_init(phba, lpfc_enable_bg);
b3b98b74
JS
6292 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6293 lpfc_prot_guard_init(phba, lpfc_prot_guard);
45ed1190
JS
6294 if (phba->sli_rev == LPFC_SLI_REV4)
6295 phba->cfg_poll = 0;
6296 else
1ba981fd 6297 phba->cfg_poll = lpfc_poll;
f358dd0c 6298 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
4258e98e 6299
895427bd 6300 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
2d7dbc4c 6301 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
895427bd
JS
6302
6303 /* Initialize first burst. Target vs Initiator are different. */
6304 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
2d7dbc4c 6305 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
895427bd
JS
6306 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6307 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
44fd7fe3 6308 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
895427bd
JS
6309
6310 if (phba->sli_rev != LPFC_SLI_REV4) {
6311 /* NVME only supported on SLI4 */
6312 phba->nvmet_support = 0;
6313 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
44fd7fe3 6314 phba->cfg_enable_bbcr = 0;
895427bd
JS
6315 } else {
6316 /* We MUST have FCP support */
6317 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6318 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6319 }
6320
0cf07f84
JS
6321 if (phba->cfg_auto_imax && !phba->cfg_fcp_imax)
6322 phba->cfg_auto_imax = 0;
6323 phba->initial_imax = phba->cfg_fcp_imax;
6324
895427bd 6325 /* A value of 0 means use the number of CPUs found in the system */
895427bd
JS
6326 if (phba->cfg_fcp_io_channel == 0)
6327 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
f358dd0c
JS
6328 if (phba->cfg_nvme_io_channel == 0)
6329 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
895427bd
JS
6330
6331 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6332 phba->cfg_fcp_io_channel = 0;
6333
f358dd0c
JS
6334 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6335 phba->cfg_nvme_io_channel = 0;
6336
895427bd
JS
6337 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6338 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6339 else
6340 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
4258e98e 6341
352e5fd1
JS
6342 phba->cfg_soft_wwnn = 0L;
6343 phba->cfg_soft_wwpn = 0L;
895427bd 6344 lpfc_xri_split_init(phba, lpfc_xri_split);
83108bd3 6345 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
7054a606 6346 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
6fb120a7 6347 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
0d878419 6348 lpfc_aer_support_init(phba, lpfc_aer_support);
912e3acd 6349 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
c71ab861 6350 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
84d1b006 6351 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
2a9bf3d0 6352 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
8eb8b960 6353 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
12247e81 6354 lpfc_sli_mode_init(phba, lpfc_sli_mode);
ab56dc2e 6355 phba->cfg_enable_dss = 1;
7bdedb34 6356 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
3de2a653
JS
6357 return;
6358}
b28485ac 6359
895427bd
JS
6360/**
6361 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6362 * dependencies between protocols and roles.
6363 * @phba: lpfc_hba pointer.
6364 **/
6365void
6366lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6367{
895427bd
JS
6368 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6369 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
f358dd0c 6370
895427bd
JS
6371 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6372 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6373
f358dd0c
JS
6374 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6375 phba->nvmet_support) {
6376 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6377 phba->cfg_fcp_io_channel = 0;
2d7dbc4c
JS
6378
6379 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6380 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6381 "NVME Target PRLI ACC enable_fb ",
6382 phba->cfg_nvme_enable_fb,
6383 phba->cfg_nvmet_fb_size,
6384 LPFC_NVMET_FB_SZ_MAX);
6385
6386 if (phba->cfg_nvme_enable_fb == 0)
6387 phba->cfg_nvmet_fb_size = 0;
6388 else {
6389 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6390 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6391 }
6392
0eeaf17f
JS
6393 if (!phba->cfg_nvmet_mrq)
6394 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6395
2d7dbc4c
JS
6396 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6397 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6398 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6399 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6400 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6401 phba->cfg_nvmet_mrq);
6402 }
0eeaf17f
JS
6403 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
6404 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
6405
2d7dbc4c 6406 } else {
f358dd0c
JS
6407 /* Not NVME Target mode. Turn off Target parameters. */
6408 phba->nvmet_support = 0;
0eeaf17f 6409 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF;
2d7dbc4c
JS
6410 phba->cfg_nvmet_fb_size = 0;
6411 }
f358dd0c 6412
895427bd
JS
6413 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6414 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6415 else
6416 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6417}
6418
e59058c4 6419/**
3621a710 6420 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
e59058c4
JS
6421 * @vport: lpfc_vport pointer.
6422 **/
3de2a653
JS
6423void
6424lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6425{
e8b62011 6426 lpfc_log_verbose_init(vport, lpfc_log_verbose);
3de2a653 6427 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
7dc517df 6428 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
3de2a653
JS
6429 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6430 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6431 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6432 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6433 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6434 lpfc_use_adisc_init(vport, lpfc_use_adisc);
3cb01c57 6435 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
977b5a0a 6436 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
3de2a653
JS
6437 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6438 lpfc_max_luns_init(vport, lpfc_max_luns);
6439 lpfc_scan_down_init(vport, lpfc_scan_down);
7ee5d43e 6440 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea3101e
JB
6441 return;
6442}