blob: 2791efa770afa509998fb0515077019f709b9b16 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart145e5a82020-01-27 16:23:12 -08004 * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term *
James Smart3e21d1c2018-05-04 20:37:59 -07005 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -050010 * *
11 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012 * 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. *
dea31012005-04-17 16:05:31 -050022 *******************************************************************/
23
dea31012005-04-17 16:05:31 -050024#include <linux/ctype.h>
James Smart46fa3112007-04-25 09:51:45 -040025#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050026#include <linux/pci.h>
27#include <linux/interrupt.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040028#include <linux/module.h>
James Smart0d878412009-10-02 15:16:56 -040029#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/gfp.h>
Andy Shevchenkoecc30992010-08-10 18:01:27 -070031#include <linux/kernel.h>
dea31012005-04-17 16:05:31 -050032
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040033#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050034#include <scsi/scsi_device.h>
35#include <scsi/scsi_host.h>
36#include <scsi/scsi_tcq.h>
37#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040038#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050039
James Smart895427b2017-02-12 13:52:30 -080040#include <linux/nvme-fc-driver.h>
41
James Smartda0436e2009-05-22 14:51:39 -040042#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050043#include "lpfc_hw.h"
44#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040045#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040046#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050047#include "lpfc_disc.h"
dea31012005-04-17 16:05:31 -050048#include "lpfc.h"
James Smart895427b2017-02-12 13:52:30 -080049#include "lpfc_scsi.h"
50#include "lpfc_nvme.h"
James Smartf358dd02017-02-12 13:52:34 -080051#include "lpfc_nvmet.h"
dea31012005-04-17 16:05:31 -050052#include "lpfc_logmsg.h"
53#include "lpfc_version.h"
54#include "lpfc_compat.h"
55#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050056#include "lpfc_vport.h"
James Smart93dd1912016-07-06 12:36:10 -070057#include "lpfc_attr.h"
dea31012005-04-17 16:05:31 -050058
James Smart2ea259e2017-02-12 13:52:27 -080059#define LPFC_DEF_DEVLOSS_TMO 30
60#define LPFC_MIN_DEVLOSS_TMO 1
61#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050062
James Smart61f3d4b2017-05-15 15:20:41 -070063#define LPFC_DEF_MRQ_POST 512
64#define LPFC_MIN_MRQ_POST 512
65#define LPFC_MAX_MRQ_POST 2048
dea31012005-04-17 16:05:31 -050066
James Smartf7a919b2011-08-21 21:49:16 -040067/*
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
Bart Van Asschea73cb812019-03-28 11:06:19 -070074const char *const trunk_errmsg[] = { /* map errcode */
75 "", /* There is no such error code at index 0*/
76 "link negotiated speed does not match existing"
77 " trunk - link was \"low\" speed",
78 "link negotiated speed does not match"
79 " existing trunk - link was \"middle\" speed",
80 "link negotiated speed does not match existing"
81 " trunk - link was \"high\" speed",
82 "Attached to non-trunking port - F_Port",
83 "Attached to non-trunking port - N_Port",
84 "FLOGI response timeout",
85 "non-FLOGI frame received",
86 "Invalid FLOGI response",
87 "Trunking initialization protocol",
88 "Trunk peer device mismatch",
89};
90
James Smarte59058c2008-08-24 21:49:00 -040091/**
James Smart3621a712009-04-06 18:47:14 -040092 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040093 * @incr: integer to convert.
94 * @hdw: ascii string holding converted integer plus a string terminator.
95 *
96 * Description:
97 * JEDEC Joint Electron Device Engineering Council.
98 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
99 * character string. The string is then terminated with a NULL in byte 9.
100 * Hex 0-9 becomes ascii '0' to '9'.
101 * Hex a-f becomes ascii '=' to 'B' capital B.
102 *
103 * Notes:
104 * Coded for 32 bit integers only.
105 **/
dea31012005-04-17 16:05:31 -0500106static void
107lpfc_jedec_to_ascii(int incr, char hdw[])
108{
109 int i, j;
110 for (i = 0; i < 8; i++) {
111 j = (incr & 0xf);
112 if (j <= 9)
113 hdw[7 - i] = 0x30 + j;
114 else
115 hdw[7 - i] = 0x61 + j - 10;
116 incr = (incr >> 4);
117 }
118 hdw[8] = 0;
119 return;
120}
121
James Smarte59058c2008-08-24 21:49:00 -0400122/**
James Smart3621a712009-04-06 18:47:14 -0400123 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -0400124 * @dev: class unused variable.
125 * @attr: device attribute, not used.
126 * @buf: on return contains the module description text.
127 *
128 * Returns: size of formatted string.
129 **/
dea31012005-04-17 16:05:31 -0500130static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100131lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
132 char *buf)
dea31012005-04-17 16:05:31 -0500133{
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700134 return scnprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
dea31012005-04-17 16:05:31 -0500135}
136
James Smart45ed1192009-10-02 15:17:02 -0400137/**
138 * lpfc_enable_fip_show - Return the fip mode of the HBA
139 * @dev: class unused variable.
140 * @attr: device attribute, not used.
141 * @buf: on return contains the module description text.
142 *
143 * Returns: size of formatted string.
144 **/
145static ssize_t
146lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
147 char *buf)
148{
149 struct Scsi_Host *shost = class_to_shost(dev);
150 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
151 struct lpfc_hba *phba = vport->phba;
152
153 if (phba->hba_flag & HBA_FIP_SUPPORT)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700154 return scnprintf(buf, PAGE_SIZE, "1\n");
James Smart45ed1192009-10-02 15:17:02 -0400155 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700156 return scnprintf(buf, PAGE_SIZE, "0\n");
James Smart45ed1192009-10-02 15:17:02 -0400157}
158
James Smart81301a92008-12-04 22:39:46 -0500159static ssize_t
James Smart895427b2017-02-12 13:52:30 -0800160lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
161 char *buf)
162{
163 struct Scsi_Host *shost = class_to_shost(dev);
164 struct lpfc_vport *vport = shost_priv(shost);
165 struct lpfc_hba *phba = vport->phba;
James Smartf358dd02017-02-12 13:52:34 -0800166 struct lpfc_nvmet_tgtport *tgtp;
James Smart895427b2017-02-12 13:52:30 -0800167 struct nvme_fc_local_port *localport;
James Smart4b056682017-12-08 17:18:10 -0800168 struct lpfc_nvme_lport *lport;
James Smart01466022018-04-09 14:24:27 -0700169 struct lpfc_nvme_rport *rport;
James Smart80cc0042017-06-01 21:06:56 -0700170 struct lpfc_nodelist *ndlp;
James Smart895427b2017-02-12 13:52:30 -0800171 struct nvme_fc_remote_port *nrport;
James Smart4c47efc2019-01-28 11:14:25 -0800172 struct lpfc_fc4_ctrl_stat *cstat;
James Smart66a210f2018-04-09 14:24:23 -0700173 uint64_t data1, data2, data3;
174 uint64_t totin, totout, tot;
James Smart895427b2017-02-12 13:52:30 -0800175 char *statep;
James Smart66a210f2018-04-09 14:24:23 -0700176 int i;
James Smart895427b2017-02-12 13:52:30 -0800177 int len = 0;
James Smartafff0d22018-06-26 08:24:22 -0700178 char tmp[LPFC_MAX_NVME_INFO_TMP_LEN] = {0};
James Smart895427b2017-02-12 13:52:30 -0800179
James Smartf6e84792019-01-28 11:14:38 -0800180 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
James Smartafff0d22018-06-26 08:24:22 -0700181 len = scnprintf(buf, PAGE_SIZE, "NVME Disabled\n");
James Smart895427b2017-02-12 13:52:30 -0800182 return len;
183 }
James Smartf358dd02017-02-12 13:52:34 -0800184 if (phba->nvmet_support) {
185 if (!phba->targetport) {
James Smartafff0d22018-06-26 08:24:22 -0700186 len = scnprintf(buf, PAGE_SIZE,
James Smartf358dd02017-02-12 13:52:34 -0800187 "NVME Target: x%llx is not allocated\n",
188 wwn_to_u64(vport->fc_portname.u.wwn));
189 return len;
190 }
191 /* Port state is only one of two values for now. */
192 if (phba->targetport->port_id)
193 statep = "REGISTERED";
194 else
195 statep = "INIT";
James Smartafff0d22018-06-26 08:24:22 -0700196 scnprintf(tmp, sizeof(tmp),
197 "NVME Target Enabled State %s\n",
198 statep);
199 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
200 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800201
James Smartafff0d22018-06-26 08:24:22 -0700202 scnprintf(tmp, sizeof(tmp),
203 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
204 "NVME Target: lpfc",
205 phba->brd_no,
206 wwn_to_u64(vport->fc_portname.u.wwn),
207 wwn_to_u64(vport->fc_nodename.u.wwn),
208 phba->targetport->port_id);
209 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
210 goto buffer_done;
211
212 if (strlcat(buf, "\nNVME Target: Statistics\n", PAGE_SIZE)
213 >= PAGE_SIZE)
214 goto buffer_done;
215
James Smartf358dd02017-02-12 13:52:34 -0800216 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
James Smartafff0d22018-06-26 08:24:22 -0700217 scnprintf(tmp, sizeof(tmp),
218 "LS: Rcv %08x Drop %08x Abort %08x\n",
219 atomic_read(&tgtp->rcv_ls_req_in),
220 atomic_read(&tgtp->rcv_ls_req_drop),
221 atomic_read(&tgtp->xmt_ls_abort));
222 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
223 goto buffer_done;
224
James Smartf358dd02017-02-12 13:52:34 -0800225 if (atomic_read(&tgtp->rcv_ls_req_in) !=
226 atomic_read(&tgtp->rcv_ls_req_out)) {
James Smartafff0d22018-06-26 08:24:22 -0700227 scnprintf(tmp, sizeof(tmp),
228 "Rcv LS: in %08x != out %08x\n",
229 atomic_read(&tgtp->rcv_ls_req_in),
230 atomic_read(&tgtp->rcv_ls_req_out));
231 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
232 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800233 }
234
James Smartafff0d22018-06-26 08:24:22 -0700235 scnprintf(tmp, sizeof(tmp),
236 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
237 atomic_read(&tgtp->xmt_ls_rsp),
238 atomic_read(&tgtp->xmt_ls_drop),
239 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
240 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
241 goto buffer_done;
James Smart4b056682017-12-08 17:18:10 -0800242
James Smartafff0d22018-06-26 08:24:22 -0700243 scnprintf(tmp, sizeof(tmp),
244 "LS: RSP Abort %08x xb %08x Err %08x\n",
245 atomic_read(&tgtp->xmt_ls_rsp_aborted),
246 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
247 atomic_read(&tgtp->xmt_ls_rsp_error));
248 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
249 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800250
James Smartafff0d22018-06-26 08:24:22 -0700251 scnprintf(tmp, sizeof(tmp),
252 "FCP: Rcv %08x Defer %08x Release %08x "
253 "Drop %08x\n",
254 atomic_read(&tgtp->rcv_fcp_cmd_in),
255 atomic_read(&tgtp->rcv_fcp_cmd_defer),
256 atomic_read(&tgtp->xmt_fcp_release),
257 atomic_read(&tgtp->rcv_fcp_cmd_drop));
258 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
259 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800260
261 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
262 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
James Smartafff0d22018-06-26 08:24:22 -0700263 scnprintf(tmp, sizeof(tmp),
264 "Rcv FCP: in %08x != out %08x\n",
265 atomic_read(&tgtp->rcv_fcp_cmd_in),
266 atomic_read(&tgtp->rcv_fcp_cmd_out));
267 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
268 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800269 }
270
James Smartafff0d22018-06-26 08:24:22 -0700271 scnprintf(tmp, sizeof(tmp),
272 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
273 "drop %08x\n",
274 atomic_read(&tgtp->xmt_fcp_read),
275 atomic_read(&tgtp->xmt_fcp_read_rsp),
276 atomic_read(&tgtp->xmt_fcp_write),
277 atomic_read(&tgtp->xmt_fcp_rsp),
278 atomic_read(&tgtp->xmt_fcp_drop));
279 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
280 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800281
James Smartafff0d22018-06-26 08:24:22 -0700282 scnprintf(tmp, sizeof(tmp),
283 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
284 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
285 atomic_read(&tgtp->xmt_fcp_rsp_error),
286 atomic_read(&tgtp->xmt_fcp_rsp_drop));
287 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
288 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800289
James Smartafff0d22018-06-26 08:24:22 -0700290 scnprintf(tmp, sizeof(tmp),
291 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
292 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
293 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
294 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
295 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
296 goto buffer_done;
James Smart4b056682017-12-08 17:18:10 -0800297
James Smartafff0d22018-06-26 08:24:22 -0700298 scnprintf(tmp, sizeof(tmp),
299 "ABORT: Xmt %08x Cmpl %08x\n",
300 atomic_read(&tgtp->xmt_fcp_abort),
301 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
302 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
303 goto buffer_done;
James Smart547077a2017-05-15 15:20:40 -0700304
James Smartafff0d22018-06-26 08:24:22 -0700305 scnprintf(tmp, sizeof(tmp),
306 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x\n",
307 atomic_read(&tgtp->xmt_abort_sol),
308 atomic_read(&tgtp->xmt_abort_unsol),
309 atomic_read(&tgtp->xmt_abort_rsp),
310 atomic_read(&tgtp->xmt_abort_rsp_error));
311 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
312 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800313
James Smartafff0d22018-06-26 08:24:22 -0700314 scnprintf(tmp, sizeof(tmp),
315 "DELAY: ctx %08x fod %08x wqfull %08x\n",
316 atomic_read(&tgtp->defer_ctx),
317 atomic_read(&tgtp->defer_fod),
318 atomic_read(&tgtp->defer_wqfull));
319 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
320 goto buffer_done;
James Smart411de512018-01-30 15:58:52 -0800321
Dick Kennedy66d7ce92017-08-23 16:55:42 -0700322 /* Calculate outstanding IOs */
323 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
324 tot += atomic_read(&tgtp->xmt_fcp_release);
325 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
James Smart2cee7802017-06-01 21:07:02 -0700326
James Smartafff0d22018-06-26 08:24:22 -0700327 scnprintf(tmp, sizeof(tmp),
328 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
329 "CTX Outstanding %08llx\n\n",
330 phba->sli4_hba.nvmet_xri_cnt,
331 phba->sli4_hba.nvmet_io_wait_cnt,
332 phba->sli4_hba.nvmet_io_wait_total,
333 tot);
334 strlcat(buf, tmp, PAGE_SIZE);
335 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800336 }
James Smart895427b2017-02-12 13:52:30 -0800337
338 localport = vport->localport;
339 if (!localport) {
James Smartafff0d22018-06-26 08:24:22 -0700340 len = scnprintf(buf, PAGE_SIZE,
James Smart895427b2017-02-12 13:52:30 -0800341 "NVME Initiator x%llx is not allocated\n",
342 wwn_to_u64(vport->fc_portname.u.wwn));
343 return len;
344 }
Colin Ian King5c665ae2017-12-22 00:28:52 +0000345 lport = (struct lpfc_nvme_lport *)localport->private;
James Smartafff0d22018-06-26 08:24:22 -0700346 if (strlcat(buf, "\nNVME Initiator Enabled\n", PAGE_SIZE) >= PAGE_SIZE)
347 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800348
James Smartafff0d22018-06-26 08:24:22 -0700349 scnprintf(tmp, sizeof(tmp),
James Smart0794d602019-01-28 11:14:19 -0800350 "XRI Dist lpfc%d Total %d IO %d ELS %d\n",
James Smartafff0d22018-06-26 08:24:22 -0700351 phba->brd_no,
352 phba->sli4_hba.max_cfg_param.max_xri,
James Smart5e5b5112019-01-28 11:14:22 -0800353 phba->sli4_hba.io_xri_max,
James Smartafff0d22018-06-26 08:24:22 -0700354 lpfc_sli4_get_els_iocb_cnt(phba));
355 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
James Smart6c1e8032019-11-04 16:57:00 -0800356 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800357
358 /* Port state is only one of two values for now. */
359 if (localport->port_id)
360 statep = "ONLINE";
361 else
362 statep = "UNKNOWN ";
363
James Smartafff0d22018-06-26 08:24:22 -0700364 scnprintf(tmp, sizeof(tmp),
365 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
366 "NVME LPORT lpfc",
367 phba->brd_no,
368 wwn_to_u64(vport->fc_portname.u.wwn),
369 wwn_to_u64(vport->fc_nodename.u.wwn),
370 localport->port_id, statep);
371 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
James Smart6c1e8032019-11-04 16:57:00 -0800372 goto buffer_done;
373
374 spin_lock_irq(shost->host_lock);
James Smart895427b2017-02-12 13:52:30 -0800375
James Smart80cc0042017-06-01 21:06:56 -0700376 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart9e210172018-09-13 15:41:10 -0700377 nrport = NULL;
James Smart6c1e8032019-11-04 16:57:00 -0800378 spin_lock(&vport->phba->hbalock);
James Smart01466022018-04-09 14:24:27 -0700379 rport = lpfc_ndlp_get_nrport(ndlp);
James Smart9e210172018-09-13 15:41:10 -0700380 if (rport)
381 nrport = rport->remoteport;
James Smart6c1e8032019-11-04 16:57:00 -0800382 spin_unlock(&vport->phba->hbalock);
James Smart01466022018-04-09 14:24:27 -0700383 if (!nrport)
384 continue;
James Smart895427b2017-02-12 13:52:30 -0800385
386 /* Port state is only one of two values for now. */
387 switch (nrport->port_state) {
388 case FC_OBJSTATE_ONLINE:
389 statep = "ONLINE";
390 break;
391 case FC_OBJSTATE_UNKNOWN:
392 statep = "UNKNOWN ";
393 break;
394 default:
395 statep = "UNSUPPORTED";
396 break;
397 }
398
399 /* Tab in to show lport ownership. */
James Smartafff0d22018-06-26 08:24:22 -0700400 if (strlcat(buf, "NVME RPORT ", PAGE_SIZE) >= PAGE_SIZE)
James Smart6c1e8032019-11-04 16:57:00 -0800401 goto unlock_buf_done;
James Smartafff0d22018-06-26 08:24:22 -0700402 if (phba->brd_no >= 10) {
403 if (strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
James Smart6c1e8032019-11-04 16:57:00 -0800404 goto unlock_buf_done;
James Smartafff0d22018-06-26 08:24:22 -0700405 }
James Smart895427b2017-02-12 13:52:30 -0800406
James Smartafff0d22018-06-26 08:24:22 -0700407 scnprintf(tmp, sizeof(tmp), "WWPN x%llx ",
408 nrport->port_name);
409 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
James Smart6c1e8032019-11-04 16:57:00 -0800410 goto unlock_buf_done;
James Smartafff0d22018-06-26 08:24:22 -0700411
412 scnprintf(tmp, sizeof(tmp), "WWNN x%llx ",
413 nrport->node_name);
414 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
James Smart6c1e8032019-11-04 16:57:00 -0800415 goto unlock_buf_done;
James Smartafff0d22018-06-26 08:24:22 -0700416
417 scnprintf(tmp, sizeof(tmp), "DID x%06x ",
418 nrport->port_id);
419 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
James Smart6c1e8032019-11-04 16:57:00 -0800420 goto unlock_buf_done;
James Smart895427b2017-02-12 13:52:30 -0800421
James Smart7d790f02017-06-01 21:06:57 -0700422 /* An NVME rport can have multiple roles. */
James Smartafff0d22018-06-26 08:24:22 -0700423 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR) {
424 if (strlcat(buf, "INITIATOR ", PAGE_SIZE) >= PAGE_SIZE)
James Smart6c1e8032019-11-04 16:57:00 -0800425 goto unlock_buf_done;
James Smartafff0d22018-06-26 08:24:22 -0700426 }
427 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET) {
428 if (strlcat(buf, "TARGET ", PAGE_SIZE) >= PAGE_SIZE)
James Smart6c1e8032019-11-04 16:57:00 -0800429 goto unlock_buf_done;
James Smartafff0d22018-06-26 08:24:22 -0700430 }
431 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY) {
432 if (strlcat(buf, "DISCSRVC ", PAGE_SIZE) >= PAGE_SIZE)
James Smart6c1e8032019-11-04 16:57:00 -0800433 goto unlock_buf_done;
James Smartafff0d22018-06-26 08:24:22 -0700434 }
James Smart7d790f02017-06-01 21:06:57 -0700435 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
436 FC_PORT_ROLE_NVME_TARGET |
James Smartafff0d22018-06-26 08:24:22 -0700437 FC_PORT_ROLE_NVME_DISCOVERY)) {
438 scnprintf(tmp, sizeof(tmp), "UNKNOWN ROLE x%x",
439 nrport->port_role);
440 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
James Smart6c1e8032019-11-04 16:57:00 -0800441 goto unlock_buf_done;
James Smartafff0d22018-06-26 08:24:22 -0700442 }
James Smart7d790f02017-06-01 21:06:57 -0700443
James Smartafff0d22018-06-26 08:24:22 -0700444 scnprintf(tmp, sizeof(tmp), "%s\n", statep);
445 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
James Smart6c1e8032019-11-04 16:57:00 -0800446 goto unlock_buf_done;
James Smart895427b2017-02-12 13:52:30 -0800447 }
James Smart6c1e8032019-11-04 16:57:00 -0800448 spin_unlock_irq(shost->host_lock);
James Smart895427b2017-02-12 13:52:30 -0800449
James Smart66a210f2018-04-09 14:24:23 -0700450 if (!lport)
James Smartafff0d22018-06-26 08:24:22 -0700451 goto buffer_done;
James Smart66a210f2018-04-09 14:24:23 -0700452
James Smartafff0d22018-06-26 08:24:22 -0700453 if (strlcat(buf, "\nNVME Statistics\n", PAGE_SIZE) >= PAGE_SIZE)
454 goto buffer_done;
James Smart4b056682017-12-08 17:18:10 -0800455
James Smartafff0d22018-06-26 08:24:22 -0700456 scnprintf(tmp, sizeof(tmp),
457 "LS: Xmt %010x Cmpl %010x Abort %08x\n",
458 atomic_read(&lport->fc4NvmeLsRequests),
459 atomic_read(&lport->fc4NvmeLsCmpls),
460 atomic_read(&lport->xmt_ls_abort));
461 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
462 goto buffer_done;
463
464 scnprintf(tmp, sizeof(tmp),
465 "LS XMIT: Err %08x CMPL: xb %08x Err %08x\n",
466 atomic_read(&lport->xmt_ls_err),
467 atomic_read(&lport->cmpl_ls_xb),
468 atomic_read(&lport->cmpl_ls_err));
469 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
470 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800471
James Smart66a210f2018-04-09 14:24:23 -0700472 totin = 0;
473 totout = 0;
James Smartcdb42be2019-01-28 11:14:21 -0800474 for (i = 0; i < phba->cfg_hdw_queue; i++) {
James Smart4c47efc2019-01-28 11:14:25 -0800475 cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;
476 tot = cstat->io_cmpls;
James Smart66a210f2018-04-09 14:24:23 -0700477 totin += tot;
James Smart4c47efc2019-01-28 11:14:25 -0800478 data1 = cstat->input_requests;
479 data2 = cstat->output_requests;
480 data3 = cstat->control_requests;
James Smart66a210f2018-04-09 14:24:23 -0700481 totout += (data1 + data2 + data3);
482 }
James Smartafff0d22018-06-26 08:24:22 -0700483 scnprintf(tmp, sizeof(tmp),
484 "Total FCP Cmpl %016llx Issue %016llx "
485 "OutIO %016llx\n",
486 totin, totout, totout - totin);
487 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
488 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800489
James Smartafff0d22018-06-26 08:24:22 -0700490 scnprintf(tmp, sizeof(tmp),
491 "\tabort %08x noxri %08x nondlp %08x qdepth %08x "
492 "wqerr %08x err %08x\n",
493 atomic_read(&lport->xmt_fcp_abort),
494 atomic_read(&lport->xmt_fcp_noxri),
495 atomic_read(&lport->xmt_fcp_bad_ndlp),
496 atomic_read(&lport->xmt_fcp_qdepth),
497 atomic_read(&lport->xmt_fcp_err),
498 atomic_read(&lport->xmt_fcp_wqerr));
499 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
500 goto buffer_done;
James Smart4b056682017-12-08 17:18:10 -0800501
James Smartafff0d22018-06-26 08:24:22 -0700502 scnprintf(tmp, sizeof(tmp),
503 "FCP CMPL: xb %08x Err %08x\n",
504 atomic_read(&lport->cmpl_fcp_xb),
505 atomic_read(&lport->cmpl_fcp_err));
506 strlcat(buf, tmp, PAGE_SIZE);
507
James Smart6c1e8032019-11-04 16:57:00 -0800508 /* host_lock is already unlocked. */
James Smart79080d32019-05-06 17:26:48 -0700509 goto buffer_done;
510
James Smart6c1e8032019-11-04 16:57:00 -0800511 unlock_buf_done:
512 spin_unlock_irq(shost->host_lock);
James Smart79080d32019-05-06 17:26:48 -0700513
514 buffer_done:
James Smartafff0d22018-06-26 08:24:22 -0700515 len = strnlen(buf, PAGE_SIZE);
516
517 if (unlikely(len >= (PAGE_SIZE - 1))) {
518 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
519 "6314 Catching potential buffer "
520 "overflow > PAGE_SIZE = %lu bytes\n",
521 PAGE_SIZE);
522 strlcpy(buf + PAGE_SIZE - 1 -
523 strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1),
524 LPFC_NVME_INFO_MORE_STR,
525 strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1)
526 + 1);
527 }
528
James Smart895427b2017-02-12 13:52:30 -0800529 return len;
530}
531
532static ssize_t
James Smart4c47efc2019-01-28 11:14:25 -0800533lpfc_scsi_stat_show(struct device *dev, struct device_attribute *attr,
534 char *buf)
535{
536 struct Scsi_Host *shost = class_to_shost(dev);
537 struct lpfc_vport *vport = shost_priv(shost);
538 struct lpfc_hba *phba = vport->phba;
539 int len;
540 struct lpfc_fc4_ctrl_stat *cstat;
541 u64 data1, data2, data3;
542 u64 tot, totin, totout;
543 int i;
544 char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
545
James Smartf6e84792019-01-28 11:14:38 -0800546 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||
James Smart4c47efc2019-01-28 11:14:25 -0800547 (phba->sli_rev != LPFC_SLI_REV4))
548 return 0;
549
550 scnprintf(buf, PAGE_SIZE, "SCSI HDWQ Statistics\n");
551
552 totin = 0;
553 totout = 0;
554 for (i = 0; i < phba->cfg_hdw_queue; i++) {
555 cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;
556 tot = cstat->io_cmpls;
557 totin += tot;
558 data1 = cstat->input_requests;
559 data2 = cstat->output_requests;
560 data3 = cstat->control_requests;
561 totout += (data1 + data2 + data3);
562
563 scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "
564 "IO %016llx ", i, data1, data2, data3);
565 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
566 goto buffer_done;
567
568 scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",
569 tot, ((data1 + data2 + data3) - tot));
570 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
571 goto buffer_done;
572 }
573 scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "
574 "OutIO %016llx\n", totin, totout, totout - totin);
575 strlcat(buf, tmp, PAGE_SIZE);
576
577buffer_done:
578 len = strnlen(buf, PAGE_SIZE);
579
580 return len;
581}
582
583static ssize_t
James Smart81301a92008-12-04 22:39:46 -0500584lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
585 char *buf)
586{
587 struct Scsi_Host *shost = class_to_shost(dev);
588 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
589 struct lpfc_hba *phba = vport->phba;
590
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700591 if (phba->cfg_enable_bg) {
James Smart81301a92008-12-04 22:39:46 -0500592 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700593 return scnprintf(buf, PAGE_SIZE,
594 "BlockGuard Enabled\n");
James Smart81301a92008-12-04 22:39:46 -0500595 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700596 return scnprintf(buf, PAGE_SIZE,
James Smart81301a92008-12-04 22:39:46 -0500597 "BlockGuard Not Supported\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700598 } else
599 return scnprintf(buf, PAGE_SIZE,
James Smart81301a92008-12-04 22:39:46 -0500600 "BlockGuard Disabled\n");
601}
602
603static ssize_t
604lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
605 char *buf)
606{
607 struct Scsi_Host *shost = class_to_shost(dev);
608 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
609 struct lpfc_hba *phba = vport->phba;
610
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700611 return scnprintf(buf, PAGE_SIZE, "%llu\n",
James Smart87b5c322008-12-16 10:34:09 -0500612 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500613}
614
615static ssize_t
616lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
617 char *buf)
618{
619 struct Scsi_Host *shost = class_to_shost(dev);
620 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
621 struct lpfc_hba *phba = vport->phba;
622
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700623 return scnprintf(buf, PAGE_SIZE, "%llu\n",
James Smart87b5c322008-12-16 10:34:09 -0500624 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500625}
626
627static ssize_t
628lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
629 char *buf)
630{
631 struct Scsi_Host *shost = class_to_shost(dev);
632 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
633 struct lpfc_hba *phba = vport->phba;
634
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700635 return scnprintf(buf, PAGE_SIZE, "%llu\n",
James Smart87b5c322008-12-16 10:34:09 -0500636 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500637}
638
James Smarte59058c2008-08-24 21:49:00 -0400639/**
James Smart3621a712009-04-06 18:47:14 -0400640 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400641 * @dev: class converted to a Scsi_host structure.
642 * @attr: device attribute, not used.
643 * @buf: on return contains the formatted text from lpfc_info().
644 *
645 * Returns: size of formatted string.
646 **/
dea31012005-04-17 16:05:31 -0500647static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100648lpfc_info_show(struct device *dev, struct device_attribute *attr,
649 char *buf)
dea31012005-04-17 16:05:31 -0500650{
Tony Jonesee959b02008-02-22 00:13:36 +0100651 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500652
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700653 return scnprintf(buf, PAGE_SIZE, "%s\n", lpfc_info(host));
dea31012005-04-17 16:05:31 -0500654}
655
James Smarte59058c2008-08-24 21:49:00 -0400656/**
James Smart3621a712009-04-06 18:47:14 -0400657 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400658 * @dev: class converted to a Scsi_host structure.
659 * @attr: device attribute, not used.
660 * @buf: on return contains the formatted text serial number.
661 *
662 * Returns: size of formatted string.
663 **/
dea31012005-04-17 16:05:31 -0500664static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100665lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
666 char *buf)
dea31012005-04-17 16:05:31 -0500667{
Tony Jonesee959b02008-02-22 00:13:36 +0100668 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500669 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
670 struct lpfc_hba *phba = vport->phba;
671
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700672 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->SerialNumber);
dea31012005-04-17 16:05:31 -0500673}
674
James Smarte59058c2008-08-24 21:49:00 -0400675/**
James Smart3621a712009-04-06 18:47:14 -0400676 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400677 * @dev: class converted to a Scsi_host structure.
678 * @attr: device attribute, not used.
679 * @buf: on return contains the formatted support level.
680 *
681 * Description:
682 * Returns a number indicating the temperature sensor level currently
683 * supported, zero or one in ascii.
684 *
685 * Returns: size of formatted string.
686 **/
dea31012005-04-17 16:05:31 -0500687static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100688lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
689 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400690{
Tony Jonesee959b02008-02-22 00:13:36 +0100691 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400692 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
693 struct lpfc_hba *phba = vport->phba;
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700694 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->temp_sensor_support);
James Smart57127f12007-10-27 13:37:05 -0400695}
696
James Smarte59058c2008-08-24 21:49:00 -0400697/**
James Smart3621a712009-04-06 18:47:14 -0400698 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400699 * @dev: class converted to a Scsi_host structure.
700 * @attr: device attribute, not used.
701 * @buf: on return contains the scsi vpd model description.
702 *
703 * Returns: size of formatted string.
704 **/
James Smart57127f12007-10-27 13:37:05 -0400705static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100706lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
707 char *buf)
dea31012005-04-17 16:05:31 -0500708{
Tony Jonesee959b02008-02-22 00:13:36 +0100709 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500710 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
711 struct lpfc_hba *phba = vport->phba;
712
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700713 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelDesc);
dea31012005-04-17 16:05:31 -0500714}
715
James Smarte59058c2008-08-24 21:49:00 -0400716/**
James Smart3621a712009-04-06 18:47:14 -0400717 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400718 * @dev: class converted to a Scsi_host structure.
719 * @attr: device attribute, not used.
720 * @buf: on return contains the scsi vpd model name.
721 *
722 * Returns: size of formatted string.
723 **/
dea31012005-04-17 16:05:31 -0500724static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100725lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
726 char *buf)
dea31012005-04-17 16:05:31 -0500727{
Tony Jonesee959b02008-02-22 00:13:36 +0100728 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500729 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
730 struct lpfc_hba *phba = vport->phba;
731
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700732 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelName);
dea31012005-04-17 16:05:31 -0500733}
734
James Smarte59058c2008-08-24 21:49:00 -0400735/**
James Smart3621a712009-04-06 18:47:14 -0400736 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400737 * @dev: class converted to a Scsi_host structure.
738 * @attr: device attribute, not used.
739 * @buf: on return contains the scsi vpd program type.
740 *
741 * Returns: size of formatted string.
742 **/
dea31012005-04-17 16:05:31 -0500743static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100744lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
745 char *buf)
dea31012005-04-17 16:05:31 -0500746{
Tony Jonesee959b02008-02-22 00:13:36 +0100747 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500748 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
749 struct lpfc_hba *phba = vport->phba;
750
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700751 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ProgramType);
dea31012005-04-17 16:05:31 -0500752}
753
James Smarte59058c2008-08-24 21:49:00 -0400754/**
James Smart3621a712009-04-06 18:47:14 -0400755 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400756 * @dev: class converted to a Scsi_host structure.
757 * @attr: device attribute, not used.
758 * @buf: on return contains the Menlo Maintenance sli flag.
759 *
760 * Returns: size of formatted string.
761 **/
762static ssize_t
763lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
764{
765 struct Scsi_Host *shost = class_to_shost(dev);
766 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
767 struct lpfc_hba *phba = vport->phba;
768
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700769 return scnprintf(buf, PAGE_SIZE, "%d\n",
James Smart84774a42008-08-24 21:50:06 -0400770 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
771}
772
773/**
James Smart3621a712009-04-06 18:47:14 -0400774 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400775 * @dev: class converted to a Scsi_host structure.
776 * @attr: device attribute, not used.
777 * @buf: on return contains scsi vpd program type.
778 *
779 * Returns: size of formatted string.
780 **/
dea31012005-04-17 16:05:31 -0500781static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100782lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
783 char *buf)
dea31012005-04-17 16:05:31 -0500784{
Tony Jonesee959b02008-02-22 00:13:36 +0100785 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500786 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
787 struct lpfc_hba *phba = vport->phba;
788
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700789 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->Port);
dea31012005-04-17 16:05:31 -0500790}
791
James Smarte59058c2008-08-24 21:49:00 -0400792/**
James Smart3621a712009-04-06 18:47:14 -0400793 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400794 * @dev: class converted to a Scsi_host structure.
795 * @attr: device attribute, not used.
796 * @buf: on return contains the scsi vpd program type.
797 *
798 * Returns: size of formatted string.
799 **/
dea31012005-04-17 16:05:31 -0500800static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100801lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
802 char *buf)
dea31012005-04-17 16:05:31 -0500803{
Tony Jonesee959b02008-02-22 00:13:36 +0100804 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500805 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
806 struct lpfc_hba *phba = vport->phba;
James Smart026abb82011-12-13 13:20:45 -0500807 uint32_t if_type;
808 uint8_t sli_family;
James Smart6b5151f2012-01-18 16:24:06 -0500809 char fwrev[FW_REV_STR_SIZE];
James Smart026abb82011-12-13 13:20:45 -0500810 int len;
James Smart2e0fef82007-06-17 19:56:36 -0500811
dea31012005-04-17 16:05:31 -0500812 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart026abb82011-12-13 13:20:45 -0500813 if_type = phba->sli4_hba.pc_sli4_params.if_type;
814 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
815
816 if (phba->sli_rev < LPFC_SLI_REV4)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700817 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
James Smart026abb82011-12-13 13:20:45 -0500818 fwrev, phba->sli_rev);
819 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700820 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
James Smart026abb82011-12-13 13:20:45 -0500821 fwrev, phba->sli_rev, if_type, sli_family);
822
823 return len;
dea31012005-04-17 16:05:31 -0500824}
825
James Smarte59058c2008-08-24 21:49:00 -0400826/**
James Smart3621a712009-04-06 18:47:14 -0400827 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400828 * @dev: class converted to a Scsi_host structure.
829 * @attr: device attribute, not used.
830 * @buf: on return contains the scsi vpd program type.
831 *
832 * Returns: size of formatted string.
833 **/
dea31012005-04-17 16:05:31 -0500834static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100835lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500836{
837 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100838 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500839 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
840 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500841 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500842
dea31012005-04-17 16:05:31 -0500843 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
James Smartec762422019-08-14 16:57:07 -0700844 return scnprintf(buf, PAGE_SIZE, "%s %08x %08x\n", hdw,
845 vp->rev.smRev, vp->rev.smFwRev);
dea31012005-04-17 16:05:31 -0500846}
James Smarte59058c2008-08-24 21:49:00 -0400847
848/**
James Smart3621a712009-04-06 18:47:14 -0400849 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400850 * @dev: class converted to a Scsi_host structure.
851 * @attr: device attribute, not used.
852 * @buf: on return contains the ROM and FCode ascii strings.
853 *
854 * Returns: size of formatted string.
855 **/
dea31012005-04-17 16:05:31 -0500856static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100857lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
858 char *buf)
dea31012005-04-17 16:05:31 -0500859{
Tony Jonesee959b02008-02-22 00:13:36 +0100860 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500861 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
862 struct lpfc_hba *phba = vport->phba;
James Smarta0683bf2015-04-07 15:07:16 -0400863 char fwrev[FW_REV_STR_SIZE];
James Smart2e0fef82007-06-17 19:56:36 -0500864
James Smarta0683bf2015-04-07 15:07:16 -0400865 if (phba->sli_rev < LPFC_SLI_REV4)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700866 return scnprintf(buf, PAGE_SIZE, "%s\n",
867 phba->OptionROMVersion);
James Smarta0683bf2015-04-07 15:07:16 -0400868
869 lpfc_decode_firmware_rev(phba, fwrev, 1);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700870 return scnprintf(buf, PAGE_SIZE, "%s\n", fwrev);
dea31012005-04-17 16:05:31 -0500871}
James Smarte59058c2008-08-24 21:49:00 -0400872
873/**
James Smart3621a712009-04-06 18:47:14 -0400874 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400875 * @dev: class converted to a Scsi_host structure.
876 * @attr: device attribute, not used.
877 * @buf: on return contains text describing the state of the link.
878 *
879 * Notes:
880 * The switch statement has no default so zero will be returned.
881 *
882 * Returns: size of formatted string.
883 **/
dea31012005-04-17 16:05:31 -0500884static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100885lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
886 char *buf)
dea31012005-04-17 16:05:31 -0500887{
Tony Jonesee959b02008-02-22 00:13:36 +0100888 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500889 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
890 struct lpfc_hba *phba = vport->phba;
891 int len = 0;
892
893 switch (phba->link_state) {
894 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500895 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500896 case LPFC_INIT_START:
897 case LPFC_INIT_MBX_CMDS:
898 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500899 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400900 if (phba->hba_flag & LINK_DISABLED)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700901 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smarta0c87cb2009-07-19 10:01:10 -0400902 "Link Down - User disabled\n");
903 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700904 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smarta0c87cb2009-07-19 10:01:10 -0400905 "Link Down\n");
dea31012005-04-17 16:05:31 -0500906 break;
907 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500908 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500909 case LPFC_HBA_READY:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700910 len += scnprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500911
912 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500913 case LPFC_LOCAL_CFG_LINK:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700914 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500915 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500916 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500917 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500918 case LPFC_FLOGI:
919 case LPFC_FABRIC_CFG_LINK:
920 case LPFC_NS_REG:
921 case LPFC_NS_QRY:
922 case LPFC_BUILD_DISC_LIST:
923 case LPFC_DISC_AUTH:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700924 len += scnprintf(buf + len, PAGE_SIZE - len,
James Smart2e0fef82007-06-17 19:56:36 -0500925 "Discovery\n");
926 break;
927 case LPFC_VPORT_READY:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700928 len += scnprintf(buf + len, PAGE_SIZE - len,
929 "Ready\n");
James Smart2e0fef82007-06-17 19:56:36 -0500930 break;
931
James Smart92d7f7b2007-06-17 19:56:38 -0500932 case LPFC_VPORT_FAILED:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700933 len += scnprintf(buf + len, PAGE_SIZE - len,
934 "Failed\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500935 break;
936
937 case LPFC_VPORT_UNKNOWN:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700938 len += scnprintf(buf + len, PAGE_SIZE - len,
James Smart2e0fef82007-06-17 19:56:36 -0500939 "Unknown\n");
940 break;
941 }
James Smart84774a42008-08-24 21:50:06 -0400942 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700943 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart84774a42008-08-24 21:50:06 -0400944 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500945 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500946 if (vport->fc_flag & FC_PUBLIC_LOOP)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700947 len += scnprintf(buf + len, PAGE_SIZE-len,
dea31012005-04-17 16:05:31 -0500948 " Public Loop\n");
949 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700950 len += scnprintf(buf + len, PAGE_SIZE-len,
dea31012005-04-17 16:05:31 -0500951 " Private Loop\n");
952 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500953 if (vport->fc_flag & FC_FABRIC)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700954 len += scnprintf(buf + len, PAGE_SIZE-len,
dea31012005-04-17 16:05:31 -0500955 " Fabric\n");
956 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700957 len += scnprintf(buf + len, PAGE_SIZE-len,
dea31012005-04-17 16:05:31 -0500958 " Point-2-Point\n");
959 }
960 }
James Smart2e0fef82007-06-17 19:56:36 -0500961
James Smart1dc5ec22018-10-23 13:41:11 -0700962 if ((phba->sli_rev == LPFC_SLI_REV4) &&
963 ((bf_get(lpfc_sli_intf_if_type,
964 &phba->sli4_hba.sli_intf) ==
965 LPFC_SLI_INTF_IF_TYPE_6))) {
966 struct lpfc_trunk_link link = phba->trunk_link;
967
968 if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700969 len += scnprintf(buf + len, PAGE_SIZE - len,
James Smart1dc5ec22018-10-23 13:41:11 -0700970 "Trunk port 0: Link %s %s\n",
971 (link.link0.state == LPFC_LINK_UP) ?
972 "Up" : "Down. ",
973 trunk_errmsg[link.link0.fault]);
974
975 if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700976 len += scnprintf(buf + len, PAGE_SIZE - len,
James Smart1dc5ec22018-10-23 13:41:11 -0700977 "Trunk port 1: Link %s %s\n",
978 (link.link1.state == LPFC_LINK_UP) ?
979 "Up" : "Down. ",
980 trunk_errmsg[link.link1.fault]);
981
982 if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700983 len += scnprintf(buf + len, PAGE_SIZE - len,
James Smart1dc5ec22018-10-23 13:41:11 -0700984 "Trunk port 2: Link %s %s\n",
985 (link.link2.state == LPFC_LINK_UP) ?
986 "Up" : "Down. ",
987 trunk_errmsg[link.link2.fault]);
988
989 if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700990 len += scnprintf(buf + len, PAGE_SIZE - len,
James Smart1dc5ec22018-10-23 13:41:11 -0700991 "Trunk port 3: Link %s %s\n",
992 (link.link3.state == LPFC_LINK_UP) ?
993 "Up" : "Down. ",
994 trunk_errmsg[link.link3.fault]);
995
996 }
997
dea31012005-04-17 16:05:31 -0500998 return len;
999}
1000
James Smarte59058c2008-08-24 21:49:00 -04001001/**
James Smart026abb82011-12-13 13:20:45 -05001002 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
1003 * @dev: class unused variable.
1004 * @attr: device attribute, not used.
1005 * @buf: on return contains the module description text.
1006 *
1007 * Returns: size of formatted string.
1008 **/
1009static ssize_t
1010lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
1011 char *buf)
1012{
1013 struct Scsi_Host *shost = class_to_shost(dev);
1014 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1015 struct lpfc_hba *phba = vport->phba;
1016
1017 if (phba->sli_rev < LPFC_SLI_REV4)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001018 return scnprintf(buf, PAGE_SIZE, "fc\n");
James Smart026abb82011-12-13 13:20:45 -05001019
1020 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
1021 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001022 return scnprintf(buf, PAGE_SIZE, "fcoe\n");
James Smart026abb82011-12-13 13:20:45 -05001023 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001024 return scnprintf(buf, PAGE_SIZE, "fc\n");
James Smart026abb82011-12-13 13:20:45 -05001025 }
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001026 return scnprintf(buf, PAGE_SIZE, "unknown\n");
James Smart026abb82011-12-13 13:20:45 -05001027}
1028
1029/**
James Smart1ba981f2014-02-20 09:56:45 -05001030 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
1031 * (OAS) is supported.
1032 * @dev: class unused variable.
1033 * @attr: device attribute, not used.
1034 * @buf: on return contains the module description text.
1035 *
1036 * Returns: size of formatted string.
1037 **/
1038static ssize_t
1039lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
1040 char *buf)
1041{
1042 struct Scsi_Host *shost = class_to_shost(dev);
1043 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
1044 struct lpfc_hba *phba = vport->phba;
1045
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001046 return scnprintf(buf, PAGE_SIZE, "%d\n",
James Smart1ba981f2014-02-20 09:56:45 -05001047 phba->sli4_hba.pc_sli4_params.oas_supported);
1048}
1049
1050/**
James Smart84d1b002010-02-12 14:42:33 -05001051 * lpfc_link_state_store - Transition the link_state on an HBA port
1052 * @dev: class device that is converted into a Scsi_host.
1053 * @attr: device attribute, not used.
1054 * @buf: one or more lpfc_polling_flags values.
1055 * @count: not used.
1056 *
1057 * Returns:
1058 * -EINVAL if the buffer is not "up" or "down"
1059 * return from link state change function if non-zero
1060 * length of the buf on success
1061 **/
1062static ssize_t
1063lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
1064 const char *buf, size_t count)
1065{
1066 struct Scsi_Host *shost = class_to_shost(dev);
1067 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1068 struct lpfc_hba *phba = vport->phba;
1069
1070 int status = -EINVAL;
1071
1072 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
1073 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -04001074 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -05001075 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
1076 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -04001077 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -05001078
1079 if (status == 0)
1080 return strlen(buf);
1081 else
1082 return status;
1083}
1084
1085/**
James Smart3621a712009-04-06 18:47:14 -04001086 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -04001087 * @dev: class device that is converted into a Scsi_host.
1088 * @attr: device attribute, not used.
1089 * @buf: on return contains the sum of fc mapped and unmapped.
1090 *
1091 * Description:
1092 * Returns the ascii text number of the sum of the fc mapped and unmapped
1093 * vport counts.
1094 *
1095 * Returns: size of formatted string.
1096 **/
dea31012005-04-17 16:05:31 -05001097static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001098lpfc_num_discovered_ports_show(struct device *dev,
1099 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -05001100{
Tony Jonesee959b02008-02-22 00:13:36 +01001101 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001102 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1103
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001104 return scnprintf(buf, PAGE_SIZE, "%d\n",
James Smart2e0fef82007-06-17 19:56:36 -05001105 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -05001106}
1107
James Smarte59058c2008-08-24 21:49:00 -04001108/**
James Smart3621a712009-04-06 18:47:14 -04001109 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -04001110 * @shost: Scsi_Host pointer.
1111 *
1112 * Description:
1113 * Bring the link down gracefully then re-init the link. The firmware will
1114 * re-init the fiber channel interface as required. Does not issue a LIP.
1115 *
1116 * Returns:
1117 * -EPERM port offline or management commands are being blocked
1118 * -ENOMEM cannot allocate memory for the mailbox command
1119 * -EIO error sending the mailbox command
1120 * zero for success
1121 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001122static int
James Smart2e0fef82007-06-17 19:56:36 -05001123lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -05001124{
James Smart2e0fef82007-06-17 19:56:36 -05001125 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1126 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001127 LPFC_MBOXQ_t *pmboxq;
1128 int mbxstatus = MBXERR_ERROR;
1129
James Smart2289e952018-01-30 15:58:55 -08001130 /*
1131 * If the link is offline, disabled or BLOCK_MGMT_IO
1132 * it doesn't make any sense to allow issue_lip
1133 */
James Smart2e0fef82007-06-17 19:56:36 -05001134 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart2289e952018-01-30 15:58:55 -08001135 (phba->hba_flag & LINK_DISABLED) ||
James Smart83108bd2008-01-11 01:53:09 -05001136 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -05001137 return -EPERM;
1138
1139 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
1140
1141 if (!pmboxq)
1142 return -ENOMEM;
1143
1144 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -04001145 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
1146 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -04001147
James Smart33ccf8d2006-08-17 11:57:58 -04001148 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -05001149
James Smart04c68492009-05-22 14:52:52 -04001150 if ((mbxstatus == MBX_SUCCESS) &&
1151 (pmboxq->u.mb.mbxStatus == 0 ||
1152 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -04001153 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1154 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
1155 phba->cfg_link_speed);
1156 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
1157 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -04001158 if ((mbxstatus == MBX_SUCCESS) &&
1159 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
1160 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1161 "2859 SLI authentication is required "
1162 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -04001163 }
1164
James Smart5b8bd0c2007-04-25 09:52:49 -04001165 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -05001166 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001167 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001168
1169 if (mbxstatus == MBXERR_ERROR)
1170 return -EIO;
1171
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001172 return 0;
dea31012005-04-17 16:05:31 -05001173}
1174
James Smart895427b2017-02-12 13:52:30 -08001175int
1176lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
1177{
1178 int cnt = 0;
1179
1180 spin_lock_irq(lock);
1181 while (!list_empty(q)) {
1182 spin_unlock_irq(lock);
1183 msleep(20);
1184 if (cnt++ > 250) { /* 5 secs */
1185 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1186 "0466 %s %s\n",
1187 "Outstanding IO when ",
1188 "bringing Adapter offline\n");
1189 return 0;
1190 }
1191 spin_lock_irq(lock);
1192 }
1193 spin_unlock_irq(lock);
1194 return 1;
1195}
1196
James Smarte59058c2008-08-24 21:49:00 -04001197/**
James Smart3621a712009-04-06 18:47:14 -04001198 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -04001199 * @phba: lpfc_hba pointer.
1200 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
1201 *
1202 * Notes:
1203 * Assumes any error from lpfc_do_offline() will be negative.
1204 * Can wait up to 5 seconds for the port ring buffers count
1205 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -04001206 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -04001207 *
1208 * Returns:
1209 * -EIO error posting the event
1210 * zero for success
1211 **/
James Smart40496f02006-07-06 15:50:22 -04001212static int
James Smart46fa3112007-04-25 09:51:45 -04001213lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
1214{
1215 struct completion online_compl;
James Smart895427b2017-02-12 13:52:30 -08001216 struct lpfc_queue *qp = NULL;
James Smart46fa3112007-04-25 09:51:45 -04001217 struct lpfc_sli_ring *pring;
1218 struct lpfc_sli *psli;
1219 int status = 0;
James Smart46fa3112007-04-25 09:51:45 -04001220 int i;
James Smartfedd3b72011-02-16 12:39:24 -05001221 int rc;
James Smart46fa3112007-04-25 09:51:45 -04001222
1223 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001224 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -04001225 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -05001226 if (rc == 0)
1227 return -ENOMEM;
1228
James Smart46fa3112007-04-25 09:51:45 -04001229 wait_for_completion(&online_compl);
1230
1231 if (status != 0)
1232 return -EIO;
1233
1234 psli = &phba->sli;
1235
James Smart4645f7b2019-03-12 16:30:14 -07001236 /*
1237 * If freeing the queues have already started, don't access them.
1238 * Otherwise set FREE_WAIT to indicate that queues are being used
1239 * to hold the freeing process until we finish.
1240 */
1241 spin_lock_irq(&phba->hbalock);
1242 if (!(psli->sli_flag & LPFC_QUEUE_FREE_INIT)) {
1243 psli->sli_flag |= LPFC_QUEUE_FREE_WAIT;
1244 } else {
1245 spin_unlock_irq(&phba->hbalock);
1246 goto skip_wait;
1247 }
1248 spin_unlock_irq(&phba->hbalock);
1249
James Smart09372822008-01-11 01:52:54 -05001250 /* Wait a little for things to settle down, but not
1251 * long enough for dev loss timeout to expire.
1252 */
James Smart895427b2017-02-12 13:52:30 -08001253 if (phba->sli_rev != LPFC_SLI_REV4) {
1254 for (i = 0; i < psli->num_rings; i++) {
1255 pring = &psli->sli3_ring[i];
1256 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1257 &phba->hbalock))
1258 goto out;
1259 }
1260 } else {
1261 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1262 pring = qp->pring;
1263 if (!pring)
1264 continue;
1265 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1266 &pring->ring_lock))
1267 goto out;
James Smart46fa3112007-04-25 09:51:45 -04001268 }
1269 }
James Smart895427b2017-02-12 13:52:30 -08001270out:
James Smart4645f7b2019-03-12 16:30:14 -07001271 spin_lock_irq(&phba->hbalock);
1272 psli->sli_flag &= ~LPFC_QUEUE_FREE_WAIT;
1273 spin_unlock_irq(&phba->hbalock);
1274
1275skip_wait:
James Smart46fa3112007-04-25 09:51:45 -04001276 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001277 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1278 if (rc == 0)
1279 return -ENOMEM;
1280
James Smart46fa3112007-04-25 09:51:45 -04001281 wait_for_completion(&online_compl);
1282
1283 if (status != 0)
1284 return -EIO;
1285
1286 return 0;
1287}
1288
James Smarte59058c2008-08-24 21:49:00 -04001289/**
James Smart50212672018-12-13 15:17:57 -08001290 * lpfc_reset_pci_bus - resets PCI bridge controller's secondary bus of an HBA
1291 * @phba: lpfc_hba pointer.
1292 *
1293 * Description:
1294 * Issues a PCI secondary bus reset for the phba->pcidev.
1295 *
1296 * Notes:
1297 * First walks the bus_list to ensure only PCI devices with Emulex
1298 * vendor id, device ids that support hot reset, only one occurrence
1299 * of function 0, and all ports on the bus are in offline mode to ensure the
1300 * hot reset only affects one valid HBA.
1301 *
1302 * Returns:
1303 * -ENOTSUPP, cfg_enable_hba_reset must be of value 2
1304 * -ENODEV, NULL ptr to pcidev
1305 * -EBADSLT, detected invalid device
1306 * -EBUSY, port is not in offline state
1307 * 0, successful
1308 */
Bart Van Assche3999df72019-03-28 11:06:16 -07001309static int
James Smart50212672018-12-13 15:17:57 -08001310lpfc_reset_pci_bus(struct lpfc_hba *phba)
1311{
1312 struct pci_dev *pdev = phba->pcidev;
1313 struct Scsi_Host *shost = NULL;
1314 struct lpfc_hba *phba_other = NULL;
1315 struct pci_dev *ptr = NULL;
1316 int res;
1317
1318 if (phba->cfg_enable_hba_reset != 2)
1319 return -ENOTSUPP;
1320
1321 if (!pdev) {
1322 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "8345 pdev NULL!\n");
1323 return -ENODEV;
1324 }
1325
1326 res = lpfc_check_pci_resettable(phba);
1327 if (res)
1328 return res;
1329
1330 /* Walk the list of devices on the pci_dev's bus */
1331 list_for_each_entry(ptr, &pdev->bus->devices, bus_list) {
1332 /* Check port is offline */
1333 shost = pci_get_drvdata(ptr);
1334 if (shost) {
1335 phba_other =
1336 ((struct lpfc_vport *)shost->hostdata)->phba;
1337 if (!(phba_other->pport->fc_flag & FC_OFFLINE_MODE)) {
1338 lpfc_printf_log(phba_other, KERN_INFO, LOG_INIT,
1339 "8349 WWPN = 0x%02x%02x%02x%02x"
1340 "%02x%02x%02x%02x is not "
1341 "offline!\n",
1342 phba_other->wwpn[0],
1343 phba_other->wwpn[1],
1344 phba_other->wwpn[2],
1345 phba_other->wwpn[3],
1346 phba_other->wwpn[4],
1347 phba_other->wwpn[5],
1348 phba_other->wwpn[6],
1349 phba_other->wwpn[7]);
1350 return -EBUSY;
1351 }
1352 }
1353 }
1354
1355 /* Issue PCI bus reset */
1356 res = pci_reset_bus(pdev);
1357 if (res) {
1358 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1359 "8350 PCI reset bus failed: %d\n", res);
1360 }
1361
1362 return res;
1363}
1364
1365/**
James Smart3621a712009-04-06 18:47:14 -04001366 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -04001367 * @phba: lpfc_hba pointer.
1368 *
1369 * Description:
1370 * If the port is configured to allow a reset then the hba is brought
1371 * offline then online.
1372 *
1373 * Notes:
1374 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -05001375 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -04001376 *
1377 * Returns:
1378 * lpfc_do_offline() return code if not zero
1379 * -EIO reset not configured or error posting the event
1380 * zero for success
1381 **/
James Smart7f860592011-03-11 16:05:52 -05001382int
James Smart40496f02006-07-06 15:50:22 -04001383lpfc_selective_reset(struct lpfc_hba *phba)
1384{
1385 struct completion online_compl;
1386 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001387 int rc;
James Smart40496f02006-07-06 15:50:22 -04001388
James Smart71157c92013-07-15 18:34:36 -04001389 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001390 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -05001391
James Smart71157c92013-07-15 18:34:36 -04001392 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1393 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -04001394
James Smart71157c92013-07-15 18:34:36 -04001395 if (status != 0)
1396 return status;
1397 }
James Smart40496f02006-07-06 15:50:22 -04001398
1399 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001400 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -04001401 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -05001402 if (rc == 0)
1403 return -ENOMEM;
1404
James Smart40496f02006-07-06 15:50:22 -04001405 wait_for_completion(&online_compl);
1406
1407 if (status != 0)
1408 return -EIO;
1409
1410 return 0;
1411}
1412
James Smarte59058c2008-08-24 21:49:00 -04001413/**
James Smart3621a712009-04-06 18:47:14 -04001414 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -04001415 * @dev: class device that is converted into a Scsi_host.
1416 * @attr: device attribute, not used.
1417 * @buf: containing the string "selective".
1418 * @count: unused variable.
1419 *
1420 * Description:
1421 * If the buf contains the string "selective" then lpfc_selective_reset()
1422 * is called to perform the reset.
1423 *
1424 * Notes:
1425 * Assumes any error from lpfc_selective_reset() will be negative.
1426 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001427 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -04001428 *
1429 * Returns:
1430 * -EINVAL if the buffer does not contain the string "selective"
1431 * length of buf if lpfc-selective_reset() if the call succeeds
1432 * return value of lpfc_selective_reset() if the call fails
1433**/
James Smart40496f02006-07-06 15:50:22 -04001434static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001435lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1436 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -04001437{
Tony Jonesee959b02008-02-22 00:13:36 +01001438 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001439 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1440 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -04001441 int status = -EINVAL;
1442
James Smart73d91e52011-10-10 21:32:10 -04001443 if (!phba->cfg_enable_hba_reset)
1444 return -EACCES;
1445
James Smart40496f02006-07-06 15:50:22 -04001446 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -05001447 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -04001448
1449 if (status == 0)
1450 return strlen(buf);
1451 else
1452 return status;
1453}
1454
James Smarte59058c2008-08-24 21:49:00 -04001455/**
James Smart88a2cfb2011-07-22 18:36:33 -04001456 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1457 * @phba: lpfc_hba pointer.
1458 *
1459 * Description:
1460 * SLI4 interface type-2 device to wait on the sliport status register for
1461 * the readyness after performing a firmware reset.
1462 *
1463 * Returns:
Masanari Iida0b1587b2013-07-17 04:37:44 +09001464 * zero for success, -EPERM when port does not have privilege to perform the
James Smart026abb82011-12-13 13:20:45 -05001465 * reset, -EIO when port timeout from recovering from the reset.
1466 *
1467 * Note:
1468 * As the caller will interpret the return code by value, be careful in making
1469 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -04001470 **/
James Smart73d91e52011-10-10 21:32:10 -04001471int
James Smart88a2cfb2011-07-22 18:36:33 -04001472lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1473{
James Smartf7a919b2011-08-21 21:49:16 -04001474 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -04001475 int i;
1476
James Smartf7a919b2011-08-21 21:49:16 -04001477 msleep(100);
James Smartb7b95fb2019-09-21 20:58:49 -07001478 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1479 &portstat_reg.word0))
1480 return -EIO;
James Smart88a2cfb2011-07-22 18:36:33 -04001481
Masanari Iida0b1587b2013-07-17 04:37:44 +09001482 /* verify if privileged for the request operation */
James Smartf7a919b2011-08-21 21:49:16 -04001483 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1484 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1485 return -EPERM;
1486
James Smart88a2cfb2011-07-22 18:36:33 -04001487 /* wait for the SLI port firmware ready after firmware reset */
1488 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1489 msleep(10);
James Smartb7b95fb2019-09-21 20:58:49 -07001490 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1491 &portstat_reg.word0))
1492 continue;
James Smart88a2cfb2011-07-22 18:36:33 -04001493 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1494 continue;
1495 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1496 continue;
1497 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1498 continue;
1499 break;
1500 }
1501
1502 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1503 return 0;
1504 else
1505 return -EIO;
1506}
1507
1508/**
James Smart52d52442011-05-24 11:42:45 -04001509 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -04001510 * @phba: lpfc_hba pointer.
1511 *
1512 * Description:
James Smart52d52442011-05-24 11:42:45 -04001513 * Request SLI4 interface type-2 device to perform a physical register set
1514 * access.
James Smartc0c11512011-05-24 11:41:34 -04001515 *
1516 * Returns:
1517 * zero for success
1518 **/
1519static ssize_t
James Smart52d52442011-05-24 11:42:45 -04001520lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -04001521{
1522 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -04001523 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -05001524 uint32_t before_fc_flag;
1525 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -04001526 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -05001527 int status = 0, rc = 0;
1528 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -04001529
1530 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001531 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -04001532
James Smart52d52442011-05-24 11:42:45 -04001533 if ((phba->sli_rev < LPFC_SLI_REV4) ||
James Smart719162b2018-12-10 19:37:01 -08001534 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smart52d52442011-05-24 11:42:45 -04001535 LPFC_SLI_INTF_IF_TYPE_2))
1536 return -EPERM;
1537
James Smart026abb82011-12-13 13:20:45 -05001538 /* Keep state if we need to restore back */
1539 before_fc_flag = phba->pport->fc_flag;
1540 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1541
James Smartb76f2dc2011-07-22 18:37:42 -04001542 /* Disable SR-IOV virtual functions if enabled */
1543 if (phba->cfg_sriov_nr_virtfn) {
1544 pci_disable_sriov(pdev);
1545 phba->cfg_sriov_nr_virtfn = 0;
1546 }
James Smart229adb02013-04-17 20:16:51 -04001547
James Smart02936352014-04-04 13:52:12 -04001548 if (opcode == LPFC_FW_DUMP)
1549 phba->hba_flag |= HBA_FW_DUMP_OP;
1550
James Smartc0c11512011-05-24 11:41:34 -04001551 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1552
James Smart02936352014-04-04 13:52:12 -04001553 if (status != 0) {
1554 phba->hba_flag &= ~HBA_FW_DUMP_OP;
James Smartc0c11512011-05-24 11:41:34 -04001555 return status;
James Smart02936352014-04-04 13:52:12 -04001556 }
James Smartc0c11512011-05-24 11:41:34 -04001557
1558 /* wait for the device to be quiesced before firmware reset */
1559 msleep(100);
1560
1561 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1562 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -04001563
1564 if (opcode == LPFC_FW_DUMP)
1565 reg_val |= LPFC_FW_DUMP_REQUEST;
1566 else if (opcode == LPFC_FW_RESET)
1567 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1568 else if (opcode == LPFC_DV_RESET)
1569 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1570
James Smartc0c11512011-05-24 11:41:34 -04001571 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1572 LPFC_CTL_PDEV_CTL_OFFSET);
1573 /* flush */
1574 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1575
1576 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -04001577 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1578
James Smart026abb82011-12-13 13:20:45 -05001579 if (rc == -EPERM) {
Masanari Iida0b1587b2013-07-17 04:37:44 +09001580 /* no privilege for reset */
James Smart6b5151f2012-01-18 16:24:06 -05001581 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
Masanari Iida0b1587b2013-07-17 04:37:44 +09001582 "3150 No privilege to perform the requested "
James Smart6b5151f2012-01-18 16:24:06 -05001583 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -05001584 } else if (rc == -EIO) {
1585 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -05001586 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1587 "3153 Fail to perform the requested "
1588 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -04001589 return rc;
James Smart026abb82011-12-13 13:20:45 -05001590 }
1591
1592 /* keep the original port state */
1593 if (before_fc_flag & FC_OFFLINE_MODE)
1594 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001595
1596 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -05001597 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1598 LPFC_EVT_ONLINE);
1599 if (!job_posted)
1600 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001601
1602 wait_for_completion(&online_compl);
1603
James Smart026abb82011-12-13 13:20:45 -05001604out:
1605 /* in any case, restore the virtual functions enabled as before */
1606 if (sriov_nr_virtfn) {
1607 sriov_err =
1608 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1609 if (!sriov_err)
1610 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1611 }
James Smartc0c11512011-05-24 11:41:34 -04001612
James Smart026abb82011-12-13 13:20:45 -05001613 /* return proper error code */
1614 if (!rc) {
1615 if (!job_posted)
1616 rc = -ENOMEM;
1617 else if (status)
1618 rc = -EIO;
1619 }
1620 return rc;
James Smartc0c11512011-05-24 11:41:34 -04001621}
1622
1623/**
James Smart3621a712009-04-06 18:47:14 -04001624 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -04001625 * @dev: class device that is converted into a Scsi_host.
1626 * @attr: device attribute, not used.
1627 * @buf: on return contains the ascii number of nport events.
1628 *
1629 * Returns: size of formatted string.
1630 **/
dea31012005-04-17 16:05:31 -05001631static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001632lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1633 char *buf)
dea31012005-04-17 16:05:31 -05001634{
Tony Jonesee959b02008-02-22 00:13:36 +01001635 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001636 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1637 struct lpfc_hba *phba = vport->phba;
1638
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001639 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
dea31012005-04-17 16:05:31 -05001640}
1641
Bart Van Assche3999df72019-03-28 11:06:16 -07001642static int
James Smart1dc5ec22018-10-23 13:41:11 -07001643lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)
1644{
1645 LPFC_MBOXQ_t *mbox = NULL;
1646 unsigned long val = 0;
Saurav Girepunje2c7fb462019-10-24 08:27:29 +05301647 char *pval = NULL;
James Smart1dc5ec22018-10-23 13:41:11 -07001648 int rc = 0;
1649
1650 if (!strncmp("enable", buff_out,
1651 strlen("enable"))) {
1652 pval = buff_out + strlen("enable") + 1;
1653 rc = kstrtoul(pval, 0, &val);
1654 if (rc)
1655 return rc; /* Invalid number */
1656 } else if (!strncmp("disable", buff_out,
1657 strlen("disable"))) {
1658 val = 0;
1659 } else {
1660 return -EINVAL; /* Invalid command */
1661 }
1662
1663 switch (val) {
1664 case 0:
1665 val = 0x0; /* Disable */
1666 break;
1667 case 2:
1668 val = 0x1; /* Enable two port trunk */
1669 break;
1670 case 4:
1671 val = 0x2; /* Enable four port trunk */
1672 break;
1673 default:
1674 return -EINVAL;
1675 }
1676
1677 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1678 "0070 Set trunk mode with val %ld ", val);
1679
1680 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1681 if (!mbox)
1682 return -ENOMEM;
1683
1684 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1685 LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,
1686 12, LPFC_SLI4_MBX_EMBED);
1687
1688 bf_set(lpfc_mbx_set_trunk_mode,
1689 &mbox->u.mqe.un.set_trunk_mode,
1690 val);
1691 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
1692 if (rc)
1693 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1694 "0071 Set trunk mode failed with status: %d",
1695 rc);
1696 if (rc != MBX_TIMEOUT)
1697 mempool_free(mbox, phba->mbox_mem_pool);
1698
1699 return 0;
1700}
1701
James Smarte59058c2008-08-24 21:49:00 -04001702/**
James Smart3621a712009-04-06 18:47:14 -04001703 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -04001704 * @dev: class device that is converted into a Scsi_host.
1705 * @attr: device attribute, not used.
1706 * @buf: on return contains the state of the adapter.
1707 *
1708 * Returns: size of formatted string.
1709 **/
dea31012005-04-17 16:05:31 -05001710static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001711lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1712 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001713{
Tony Jonesee959b02008-02-22 00:13:36 +01001714 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001715 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1716 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001717 char * state;
1718
James Smart2e0fef82007-06-17 19:56:36 -05001719 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001720 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001721 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001722 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001723 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001724 state = "offline";
1725 else
1726 state = "online";
1727
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001728 return scnprintf(buf, PAGE_SIZE, "%s\n", state);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001729}
1730
James Smarte59058c2008-08-24 21:49:00 -04001731/**
James Smart3621a712009-04-06 18:47:14 -04001732 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001733 * @dev: class device that is converted into a Scsi_host.
1734 * @attr: device attribute, not used.
1735 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1736 * @count: unused variable.
1737 *
1738 * Returns:
1739 * -EACCES if enable hba reset not enabled
1740 * -EINVAL if the buffer does not contain a valid string (see above)
1741 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1742 * buf length greater than zero indicates success
1743 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001744static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001745lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1746 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001747{
Tony Jonesee959b02008-02-22 00:13:36 +01001748 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001749 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1750 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001751 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001752 char *board_mode_str = NULL;
1753 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001754 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001755
James Smart026abb82011-12-13 13:20:45 -05001756 if (!phba->cfg_enable_hba_reset) {
1757 status = -EACCES;
1758 goto board_mode_out;
1759 }
James Smart88a2cfb2011-07-22 18:36:33 -04001760
1761 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001762 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001763
Jamie Wellnitz41415862006-02-28 19:25:27 -05001764 init_completion(&online_compl);
1765
James Smart46fa3112007-04-25 09:51:45 -04001766 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001767 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001768 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001769 if (rc == 0) {
1770 status = -ENOMEM;
1771 goto board_mode_out;
1772 }
James Smart46fa3112007-04-25 09:51:45 -04001773 wait_for_completion(&online_compl);
James Smart522dcee2017-06-01 21:07:03 -07001774 if (status)
1775 status = -EIO;
James Smart46fa3112007-04-25 09:51:45 -04001776 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1777 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001778 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001779 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001780 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001781 else
1782 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001783 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001784 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001785 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001786 else
1787 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001788 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001789 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1790 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1791 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1792 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1793 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
James Smart50212672018-12-13 15:17:57 -08001794 else if (strncmp(buf, "pci_bus_reset", sizeof("pci_bus_reset") - 1)
1795 == 0)
1796 status = lpfc_reset_pci_bus(phba);
James Smart1dc5ec22018-10-23 13:41:11 -07001797 else if (strncmp(buf, "trunk", sizeof("trunk") - 1) == 0)
1798 status = lpfc_set_trunking(phba, (char *)buf + sizeof("trunk"));
Jamie Wellnitz41415862006-02-28 19:25:27 -05001799 else
James Smart026abb82011-12-13 13:20:45 -05001800 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001801
James Smart026abb82011-12-13 13:20:45 -05001802board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001803 if (!status)
1804 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001805 else {
1806 board_mode_str = strchr(buf, '\n');
1807 if (board_mode_str)
1808 *board_mode_str = '\0';
1809 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1810 "3097 Failed \"%s\", status(%d), "
1811 "fc_flag(x%x)\n",
1812 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001813 return status;
James Smart026abb82011-12-13 13:20:45 -05001814 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001815}
1816
James Smarte59058c2008-08-24 21:49:00 -04001817/**
James Smart3621a712009-04-06 18:47:14 -04001818 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001819 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001820 * @mxri: max xri count.
1821 * @axri: available xri count.
1822 * @mrpi: max rpi count.
1823 * @arpi: available rpi count.
1824 * @mvpi: max vpi count.
1825 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001826 *
1827 * Description:
1828 * If an integer pointer for an count is not null then the value for the
1829 * count is returned.
1830 *
1831 * Returns:
1832 * zero on error
1833 * one for success
1834 **/
James Smart311464e2007-08-02 11:10:37 -04001835static int
James Smart858c9f62007-06-17 19:56:39 -05001836lpfc_get_hba_info(struct lpfc_hba *phba,
1837 uint32_t *mxri, uint32_t *axri,
1838 uint32_t *mrpi, uint32_t *arpi,
1839 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001840{
James Smart04c68492009-05-22 14:52:52 -04001841 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001842 LPFC_MBOXQ_t *pmboxq;
1843 MAILBOX_t *pmb;
1844 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001845 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001846
1847 /*
1848 * prevent udev from issuing mailbox commands until the port is
1849 * configured.
1850 */
1851 if (phba->link_state < LPFC_LINK_DOWN ||
1852 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001853 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001854 return 0;
1855
1856 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1857 return 0;
1858
1859 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1860 if (!pmboxq)
1861 return 0;
1862 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1863
James Smart04c68492009-05-22 14:52:52 -04001864 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001865 pmb->mbxCommand = MBX_READ_CONFIG;
1866 pmb->mbxOwner = OWN_HOST;
James Smart3e1f0712018-11-29 16:09:29 -08001867 pmboxq->ctx_buf = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05001868
James Smart75baf692010-06-08 18:31:21 -04001869 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001870 rc = MBX_NOT_FINISHED;
1871 else
1872 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1873
1874 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001875 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001876 mempool_free(pmboxq, phba->mbox_mem_pool);
1877 return 0;
1878 }
1879
James Smartda0436e2009-05-22 14:51:39 -04001880 if (phba->sli_rev == LPFC_SLI_REV4) {
1881 rd_config = &pmboxq->u.mqe.un.rd_config;
1882 if (mrpi)
1883 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1884 if (arpi)
1885 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1886 phba->sli4_hba.max_cfg_param.rpi_used;
1887 if (mxri)
1888 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1889 if (axri)
1890 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1891 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001892
1893 /* Account for differences with SLI-3. Get vpi count from
1894 * mailbox data and subtract one for max vpi value.
1895 */
1896 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1897 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1898
James Smart8b47ae62018-11-29 16:09:33 -08001899 /* Limit the max we support */
1900 if (max_vpi > LPFC_MAX_VPI)
1901 max_vpi = LPFC_MAX_VPI;
James Smartda0436e2009-05-22 14:51:39 -04001902 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001903 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001904 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001905 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001906 } else {
1907 if (mrpi)
1908 *mrpi = pmb->un.varRdConfig.max_rpi;
1909 if (arpi)
1910 *arpi = pmb->un.varRdConfig.avail_rpi;
1911 if (mxri)
1912 *mxri = pmb->un.varRdConfig.max_xri;
1913 if (axri)
1914 *axri = pmb->un.varRdConfig.avail_xri;
1915 if (mvpi)
1916 *mvpi = pmb->un.varRdConfig.max_vpi;
James Smart8b47ae62018-11-29 16:09:33 -08001917 if (avpi) {
1918 /* avail_vpi is only valid if link is up and ready */
1919 if (phba->link_state == LPFC_HBA_READY)
1920 *avpi = pmb->un.varRdConfig.avail_vpi;
1921 else
1922 *avpi = pmb->un.varRdConfig.max_vpi;
1923 }
James Smartda0436e2009-05-22 14:51:39 -04001924 }
James Smart92d7f7b2007-06-17 19:56:38 -05001925
1926 mempool_free(pmboxq, phba->mbox_mem_pool);
1927 return 1;
1928}
1929
James Smarte59058c2008-08-24 21:49:00 -04001930/**
James Smart3621a712009-04-06 18:47:14 -04001931 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001932 * @dev: class device that is converted into a Scsi_host.
1933 * @attr: device attribute, not used.
1934 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1935 *
1936 * Description:
1937 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1938 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1939 * to "Unknown" and the buffer length is returned, therefore the caller
1940 * must check for "Unknown" in the buffer to detect a failure.
1941 *
1942 * Returns: size of formatted string.
1943 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001944static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001945lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1946 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001947{
Tony Jonesee959b02008-02-22 00:13:36 +01001948 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001949 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1950 struct lpfc_hba *phba = vport->phba;
1951 uint32_t cnt;
1952
James Smart858c9f62007-06-17 19:56:39 -05001953 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001954 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
1955 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001956}
1957
James Smarte59058c2008-08-24 21:49:00 -04001958/**
James Smart3621a712009-04-06 18:47:14 -04001959 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001960 * @dev: class device that is converted into a Scsi_host.
1961 * @attr: device attribute, not used.
1962 * @buf: containing the used rpi count in decimal or "Unknown".
1963 *
1964 * Description:
1965 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1966 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1967 * to "Unknown" and the buffer length is returned, therefore the caller
1968 * must check for "Unknown" in the buffer to detect a failure.
1969 *
1970 * Returns: size of formatted string.
1971 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001972static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001973lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1974 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001975{
Tony Jonesee959b02008-02-22 00:13:36 +01001976 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001977 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1978 struct lpfc_hba *phba = vport->phba;
1979 uint32_t cnt, acnt;
1980
James Smart858c9f62007-06-17 19:56:39 -05001981 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001982 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1983 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001984}
1985
James Smarte59058c2008-08-24 21:49:00 -04001986/**
James Smart3621a712009-04-06 18:47:14 -04001987 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001988 * @dev: class device that is converted into a Scsi_host.
1989 * @attr: device attribute, not used.
1990 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1991 *
1992 * Description:
1993 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1994 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1995 * to "Unknown" and the buffer length is returned, therefore the caller
1996 * must check for "Unknown" in the buffer to detect a failure.
1997 *
1998 * Returns: size of formatted string.
1999 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002000static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002001lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
2002 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05002003{
Tony Jonesee959b02008-02-22 00:13:36 +01002004 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05002005 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2006 struct lpfc_hba *phba = vport->phba;
2007 uint32_t cnt;
2008
James Smart858c9f62007-06-17 19:56:39 -05002009 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002010 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2011 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
James Smart92d7f7b2007-06-17 19:56:38 -05002012}
2013
James Smarte59058c2008-08-24 21:49:00 -04002014/**
James Smart3621a712009-04-06 18:47:14 -04002015 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04002016 * @dev: class device that is converted into a Scsi_host.
2017 * @attr: device attribute, not used.
2018 * @buf: on return contains the used xri count in decimal or "Unknown".
2019 *
2020 * Description:
2021 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
2022 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2023 * to "Unknown" and the buffer length is returned, therefore the caller
2024 * must check for "Unknown" in the buffer to detect a failure.
2025 *
2026 * Returns: size of formatted string.
2027 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002028static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002029lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
2030 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05002031{
Tony Jonesee959b02008-02-22 00:13:36 +01002032 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05002033 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2034 struct lpfc_hba *phba = vport->phba;
2035 uint32_t cnt, acnt;
2036
James Smart858c9f62007-06-17 19:56:39 -05002037 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002038 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2039 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
James Smart858c9f62007-06-17 19:56:39 -05002040}
2041
James Smarte59058c2008-08-24 21:49:00 -04002042/**
James Smart3621a712009-04-06 18:47:14 -04002043 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04002044 * @dev: class device that is converted into a Scsi_host.
2045 * @attr: device attribute, not used.
2046 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
2047 *
2048 * Description:
2049 * Calls lpfc_get_hba_info() asking for just the mvpi count.
2050 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2051 * to "Unknown" and the buffer length is returned, therefore the caller
2052 * must check for "Unknown" in the buffer to detect a failure.
2053 *
2054 * Returns: size of formatted string.
2055 **/
James Smart858c9f62007-06-17 19:56:39 -05002056static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002057lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
2058 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05002059{
Tony Jonesee959b02008-02-22 00:13:36 +01002060 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05002061 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2062 struct lpfc_hba *phba = vport->phba;
2063 uint32_t cnt;
2064
2065 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002066 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2067 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
James Smart858c9f62007-06-17 19:56:39 -05002068}
2069
James Smarte59058c2008-08-24 21:49:00 -04002070/**
James Smart3621a712009-04-06 18:47:14 -04002071 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04002072 * @dev: class device that is converted into a Scsi_host.
2073 * @attr: device attribute, not used.
2074 * @buf: on return contains the used vpi count in decimal or "Unknown".
2075 *
2076 * Description:
2077 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
2078 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2079 * to "Unknown" and the buffer length is returned, therefore the caller
2080 * must check for "Unknown" in the buffer to detect a failure.
2081 *
2082 * Returns: size of formatted string.
2083 **/
James Smart858c9f62007-06-17 19:56:39 -05002084static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002085lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
2086 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05002087{
Tony Jonesee959b02008-02-22 00:13:36 +01002088 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05002089 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2090 struct lpfc_hba *phba = vport->phba;
2091 uint32_t cnt, acnt;
2092
2093 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002094 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2095 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
James Smart92d7f7b2007-06-17 19:56:38 -05002096}
2097
James Smarte59058c2008-08-24 21:49:00 -04002098/**
James Smart3621a712009-04-06 18:47:14 -04002099 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002100 * @dev: class device that is converted into a Scsi_host.
2101 * @attr: device attribute, not used.
2102 * @buf: text that must be interpreted to determine if npiv is supported.
2103 *
2104 * Description:
2105 * Buffer will contain text indicating npiv is not suppoerted on the port,
2106 * the port is an NPIV physical port, or it is an npiv virtual port with
2107 * the id of the vport.
2108 *
2109 * Returns: size of formatted string.
2110 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002111static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002112lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
2113 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05002114{
Tony Jonesee959b02008-02-22 00:13:36 +01002115 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05002116 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2117 struct lpfc_hba *phba = vport->phba;
2118
2119 if (!(phba->max_vpi))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002120 return scnprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
James Smart92d7f7b2007-06-17 19:56:38 -05002121 if (vport->port_type == LPFC_PHYSICAL_PORT)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002122 return scnprintf(buf, PAGE_SIZE, "NPIV Physical\n");
2123 return scnprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05002124}
2125
James Smarte59058c2008-08-24 21:49:00 -04002126/**
James Smart3621a712009-04-06 18:47:14 -04002127 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002128 * @dev: class device that is converted into a Scsi_host.
2129 * @attr: device attribute, not used.
2130 * @buf: on return contains the cfg_poll in hex.
2131 *
2132 * Notes:
2133 * cfg_poll should be a lpfc_polling_flags type.
2134 *
2135 * Returns: size of formatted string.
2136 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05002137static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002138lpfc_poll_show(struct device *dev, struct device_attribute *attr,
2139 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002140{
Tony Jonesee959b02008-02-22 00:13:36 +01002141 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002142 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2143 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002144
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002145 return scnprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002146}
2147
James Smarte59058c2008-08-24 21:49:00 -04002148/**
James Smart3621a712009-04-06 18:47:14 -04002149 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002150 * @dev: class device that is converted into a Scsi_host.
2151 * @attr: device attribute, not used.
2152 * @buf: one or more lpfc_polling_flags values.
2153 * @count: not used.
2154 *
2155 * Notes:
2156 * buf contents converted to integer and checked for a valid value.
2157 *
2158 * Returns:
2159 * -EINVAL if the buffer connot be converted or is out of range
2160 * length of the buf on success
2161 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002162static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002163lpfc_poll_store(struct device *dev, struct device_attribute *attr,
2164 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002165{
Tony Jonesee959b02008-02-22 00:13:36 +01002166 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002167 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2168 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002169 uint32_t creg_val;
2170 uint32_t old_val;
2171 int val=0;
2172
2173 if (!isdigit(buf[0]))
2174 return -EINVAL;
2175
2176 if (sscanf(buf, "%i", &val) != 1)
2177 return -EINVAL;
2178
2179 if ((val & 0x3) != val)
2180 return -EINVAL;
2181
James Smart45ed1192009-10-02 15:17:02 -04002182 if (phba->sli_rev == LPFC_SLI_REV4)
2183 val = 0;
2184
James Smart88a2cfb2011-07-22 18:36:33 -04002185 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2186 "3051 lpfc_poll changed from %d to %d\n",
2187 phba->cfg_poll, val);
2188
James Smart2e0fef82007-06-17 19:56:36 -05002189 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002190
2191 old_val = phba->cfg_poll;
2192
2193 if (val & ENABLE_FCP_RING_POLLING) {
2194 if ((val & DISABLE_FCP_RING_INT) &&
2195 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05002196 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2197 spin_unlock_irq(&phba->hbalock);
2198 return -EINVAL;
2199 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002200 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
2201 writel(creg_val, phba->HCregaddr);
2202 readl(phba->HCregaddr); /* flush */
2203
2204 lpfc_poll_start_timer(phba);
2205 }
2206 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05002207 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002208 return -EINVAL;
2209 }
2210
2211 if (!(val & DISABLE_FCP_RING_INT) &&
2212 (old_val & DISABLE_FCP_RING_INT))
2213 {
James Smart2e0fef82007-06-17 19:56:36 -05002214 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002215 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05002216 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05002217 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2218 spin_unlock_irq(&phba->hbalock);
2219 return -EINVAL;
2220 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002221 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2222 writel(creg_val, phba->HCregaddr);
2223 readl(phba->HCregaddr); /* flush */
2224 }
2225
2226 phba->cfg_poll = val;
2227
James Smart2e0fef82007-06-17 19:56:36 -05002228 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002229
2230 return strlen(buf);
2231}
dea31012005-04-17 16:05:31 -05002232
James Smarte59058c2008-08-24 21:49:00 -04002233/**
James Smart912e3ac2011-05-24 11:42:11 -04002234 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
2235 * @dev: class converted to a Scsi_host structure.
2236 * @attr: device attribute, not used.
2237 * @buf: on return contains the formatted support level.
2238 *
2239 * Description:
2240 * Returns the maximum number of virtual functions a physical function can
2241 * support, 0 will be returned if called on virtual function.
2242 *
2243 * Returns: size of formatted string.
2244 **/
2245static ssize_t
2246lpfc_sriov_hw_max_virtfn_show(struct device *dev,
2247 struct device_attribute *attr,
2248 char *buf)
2249{
2250 struct Scsi_Host *shost = class_to_shost(dev);
2251 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2252 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04002253 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04002254
James Smart0a96e972011-07-22 18:37:28 -04002255 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002256 return scnprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04002257}
2258
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002259static inline bool lpfc_rangecheck(uint val, uint min, uint max)
2260{
2261 return val >= min && val <= max;
2262}
2263
James Smart912e3ac2011-05-24 11:42:11 -04002264/**
James Smart44fd7fe2017-08-23 16:55:47 -07002265 * lpfc_enable_bbcr_set: Sets an attribute value.
2266 * @phba: pointer the the adapter structure.
2267 * @val: integer attribute value.
2268 *
2269 * Description:
2270 * Validates the min and max values then sets the
2271 * adapter config field if in the valid range. prints error message
2272 * and does not set the parameter if invalid.
2273 *
2274 * Returns:
2275 * zero on success
2276 * -EINVAL if val is invalid
2277 */
2278static ssize_t
2279lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
2280{
2281 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
2282 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2283 "3068 %s_enable_bbcr changed from %d to %d\n",
2284 LPFC_DRIVER_NAME, phba->cfg_enable_bbcr, val);
2285 phba->cfg_enable_bbcr = val;
2286 return 0;
2287 }
2288 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2289 "0451 %s_enable_bbcr cannot set to %d, range is 0, 1\n",
2290 LPFC_DRIVER_NAME, val);
2291 return -EINVAL;
2292}
2293
2294/**
James Smart3621a712009-04-06 18:47:14 -04002295 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04002296 *
2297 * Description:
2298 * Macro that given an attr e.g. hba_queue_depth expands
2299 * into a function with the name lpfc_hba_queue_depth_show.
2300 *
2301 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
2302 * @dev: class device that is converted into a Scsi_host.
2303 * @attr: device attribute, not used.
2304 * @buf: on return contains the attribute value in decimal.
2305 *
2306 * Returns: size of formatted string.
2307 **/
dea31012005-04-17 16:05:31 -05002308#define lpfc_param_show(attr) \
2309static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002310lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2311 char *buf) \
dea31012005-04-17 16:05:31 -05002312{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002313 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002314 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2315 struct lpfc_hba *phba = vport->phba;\
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002316 return scnprintf(buf, PAGE_SIZE, "%d\n",\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002317 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05002318}
2319
James Smarte59058c2008-08-24 21:49:00 -04002320/**
James Smart3621a712009-04-06 18:47:14 -04002321 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04002322 *
2323 * Description:
2324 * Macro that given an attr e.g. hba_queue_depth expands
2325 * into a function with the name lpfc_hba_queue_depth_show
2326 *
2327 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
2328 * @dev: class device that is converted into a Scsi_host.
2329 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002330 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002331 *
2332 * Returns: size of formatted string.
2333 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002334#define lpfc_param_hex_show(attr) \
2335static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002336lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2337 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002338{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002339 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002340 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2341 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05002342 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002343 val = phba->cfg_##attr;\
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002344 return scnprintf(buf, PAGE_SIZE, "%#x\n",\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002345 phba->cfg_##attr);\
2346}
2347
James Smarte59058c2008-08-24 21:49:00 -04002348/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04002349 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002350 *
2351 * Description:
2352 * Macro that given an attr e.g. hba_queue_depth expands
2353 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2354 * takes a default argument, a minimum and maximum argument.
2355 *
2356 * lpfc_##attr##_init: Initializes an attribute.
2357 * @phba: pointer the the adapter structure.
2358 * @val: integer attribute value.
2359 *
2360 * Validates the min and max values then sets the adapter config field
2361 * accordingly, or uses the default if out of range and prints an error message.
2362 *
2363 * Returns:
2364 * zero on success
2365 * -EINVAL if default used
2366 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002367#define lpfc_param_init(attr, default, minval, maxval) \
2368static int \
James Smart84d1b002010-02-12 14:42:33 -05002369lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002370{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002371 if (lpfc_rangecheck(val, minval, maxval)) {\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002372 phba->cfg_##attr = val;\
2373 return 0;\
2374 }\
2375 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04002376 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2377 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002378 phba->cfg_##attr = default;\
2379 return -EINVAL;\
2380}
2381
James Smarte59058c2008-08-24 21:49:00 -04002382/**
James Smart3621a712009-04-06 18:47:14 -04002383 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04002384 *
2385 * Description:
2386 * Macro that given an attr e.g. hba_queue_depth expands
2387 * into a function with the name lpfc_hba_queue_depth_set
2388 *
2389 * lpfc_##attr##_set: Sets an attribute value.
2390 * @phba: pointer the the adapter structure.
2391 * @val: integer attribute value.
2392 *
2393 * Description:
2394 * Validates the min and max values then sets the
2395 * adapter config field if in the valid range. prints error message
2396 * and does not set the parameter if invalid.
2397 *
2398 * Returns:
2399 * zero on success
2400 * -EINVAL if val is invalid
2401 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002402#define lpfc_param_set(attr, default, minval, maxval) \
2403static int \
James Smart84d1b002010-02-12 14:42:33 -05002404lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002405{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002406 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002407 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2408 "3052 lpfc_" #attr " changed from %d to %d\n", \
2409 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002410 phba->cfg_##attr = val;\
2411 return 0;\
2412 }\
2413 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04002414 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2415 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002416 return -EINVAL;\
2417}
2418
James Smarte59058c2008-08-24 21:49:00 -04002419/**
James Smart3621a712009-04-06 18:47:14 -04002420 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04002421 *
2422 * Description:
2423 * Macro that given an attr e.g. hba_queue_depth expands
2424 * into a function with the name lpfc_hba_queue_depth_store.
2425 *
2426 * lpfc_##attr##_store: Set an sttribute value.
2427 * @dev: class device that is converted into a Scsi_host.
2428 * @attr: device attribute, not used.
2429 * @buf: contains the attribute value in ascii.
2430 * @count: not used.
2431 *
2432 * Description:
2433 * Convert the ascii text number to an integer, then
2434 * use the lpfc_##attr##_set function to set the value.
2435 *
2436 * Returns:
2437 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2438 * length of buffer upon success.
2439 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002440#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05002441static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002442lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2443 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05002444{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002445 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002446 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2447 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05002448 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002449 if (!isdigit(buf[0]))\
2450 return -EINVAL;\
2451 if (sscanf(buf, "%i", &val) != 1)\
2452 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002453 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04002454 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002455 else \
2456 return -EINVAL;\
dea31012005-04-17 16:05:31 -05002457}
2458
James Smarte59058c2008-08-24 21:49:00 -04002459/**
James Smart3621a712009-04-06 18:47:14 -04002460 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04002461 *
2462 * Description:
2463 * Macro that given an attr e.g. hba_queue_depth expands
2464 * into a function with the name lpfc_hba_queue_depth_show
2465 *
2466 * lpfc_##attr##_show: prints the attribute value in decimal.
2467 * @dev: class device that is converted into a Scsi_host.
2468 * @attr: device attribute, not used.
2469 * @buf: on return contains the attribute value in decimal.
2470 *
2471 * Returns: length of formatted string.
2472 **/
James Smart3de2a652007-08-02 11:09:59 -04002473#define lpfc_vport_param_show(attr) \
2474static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002475lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2476 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002477{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002478 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002479 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002480 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
James Smart3de2a652007-08-02 11:09:59 -04002481}
2482
James Smarte59058c2008-08-24 21:49:00 -04002483/**
James Smart3621a712009-04-06 18:47:14 -04002484 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04002485 *
2486 * Description:
2487 * Macro that given an attr e.g.
2488 * hba_queue_depth expands into a function with the name
2489 * lpfc_hba_queue_depth_show
2490 *
James Smart3621a712009-04-06 18:47:14 -04002491 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002492 * @dev: class device that is converted into a Scsi_host.
2493 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002494 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002495 *
2496 * Returns: length of formatted string.
2497 **/
James Smart3de2a652007-08-02 11:09:59 -04002498#define lpfc_vport_param_hex_show(attr) \
2499static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002500lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2501 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002502{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002503 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002504 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002505 return scnprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
James Smart3de2a652007-08-02 11:09:59 -04002506}
2507
James Smarte59058c2008-08-24 21:49:00 -04002508/**
James Smart3621a712009-04-06 18:47:14 -04002509 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002510 *
2511 * Description:
2512 * Macro that given an attr e.g. hba_queue_depth expands
2513 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2514 * takes a default argument, a minimum and maximum argument.
2515 *
2516 * lpfc_##attr##_init: validates the min and max values then sets the
2517 * adapter config field accordingly, or uses the default if out of range
2518 * and prints an error message.
2519 * @phba: pointer the the adapter structure.
2520 * @val: integer attribute value.
2521 *
2522 * Returns:
2523 * zero on success
2524 * -EINVAL if default used
2525 **/
James Smart3de2a652007-08-02 11:09:59 -04002526#define lpfc_vport_param_init(attr, default, minval, maxval) \
2527static int \
James Smart84d1b002010-02-12 14:42:33 -05002528lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002529{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002530 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart3de2a652007-08-02 11:09:59 -04002531 vport->cfg_##attr = val;\
2532 return 0;\
2533 }\
James Smarte8b62012007-08-02 11:10:09 -04002534 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002535 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002536 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002537 vport->cfg_##attr = default;\
2538 return -EINVAL;\
2539}
2540
James Smarte59058c2008-08-24 21:49:00 -04002541/**
James Smart3621a712009-04-06 18:47:14 -04002542 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002543 *
2544 * Description:
2545 * Macro that given an attr e.g. hba_queue_depth expands
2546 * into a function with the name lpfc_hba_queue_depth_set
2547 *
2548 * lpfc_##attr##_set: validates the min and max values then sets the
2549 * adapter config field if in the valid range. prints error message
2550 * and does not set the parameter if invalid.
2551 * @phba: pointer the the adapter structure.
2552 * @val: integer attribute value.
2553 *
2554 * Returns:
2555 * zero on success
2556 * -EINVAL if val is invalid
2557 **/
James Smart3de2a652007-08-02 11:09:59 -04002558#define lpfc_vport_param_set(attr, default, minval, maxval) \
2559static int \
James Smart84d1b002010-02-12 14:42:33 -05002560lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002561{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002562 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002563 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04002564 "3053 lpfc_" #attr \
2565 " changed from %d (x%x) to %d (x%x)\n", \
2566 vport->cfg_##attr, vport->cfg_##attr, \
2567 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04002568 vport->cfg_##attr = val;\
2569 return 0;\
2570 }\
James Smarte8b62012007-08-02 11:10:09 -04002571 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002572 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002573 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002574 return -EINVAL;\
2575}
2576
James Smarte59058c2008-08-24 21:49:00 -04002577/**
James Smart3621a712009-04-06 18:47:14 -04002578 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04002579 *
2580 * Description:
2581 * Macro that given an attr e.g. hba_queue_depth
2582 * expands into a function with the name lpfc_hba_queue_depth_store
2583 *
2584 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2585 * use the lpfc_##attr##_set function to set the value.
2586 * @cdev: class device that is converted into a Scsi_host.
2587 * @buf: contains the attribute value in decimal.
2588 * @count: not used.
2589 *
2590 * Returns:
2591 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2592 * length of buffer upon success.
2593 **/
James Smart3de2a652007-08-02 11:09:59 -04002594#define lpfc_vport_param_store(attr) \
2595static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002596lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2597 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04002598{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002599 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002600 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05002601 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04002602 if (!isdigit(buf[0]))\
2603 return -EINVAL;\
2604 if (sscanf(buf, "%i", &val) != 1)\
2605 return -EINVAL;\
2606 if (lpfc_##attr##_set(vport, val) == 0) \
2607 return strlen(buf);\
2608 else \
2609 return -EINVAL;\
2610}
2611
2612
James Smart895427b2017-02-12 13:52:30 -08002613static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
James Smart4c47efc2019-01-28 11:14:25 -08002614static DEVICE_ATTR(scsi_stat, 0444, lpfc_scsi_stat_show, NULL);
James Smart81301a92008-12-04 22:39:46 -05002615static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2616static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2617static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2618static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002619static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2620static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2621static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2622static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2623static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2624static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2625static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2626static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002627static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2628 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002629static DEVICE_ATTR(option_rom_version, S_IRUGO,
2630 lpfc_option_rom_version_show, NULL);
2631static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2632 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002633static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002634static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
Joe Perchesc828a892017-12-19 10:15:08 -08002635static DEVICE_ATTR_RO(lpfc_drvr_version);
2636static DEVICE_ATTR_RO(lpfc_enable_fip);
Tony Jonesee959b02008-02-22 00:13:36 +01002637static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2638 lpfc_board_mode_show, lpfc_board_mode_store);
2639static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2640static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2641static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2642static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2643static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2644static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2645static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2646static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
Joe Perchesc828a892017-12-19 10:15:08 -08002647static DEVICE_ATTR_RO(lpfc_temp_sensor);
Joe Perchesc828a892017-12-19 10:15:08 -08002648static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
James Smart026abb82011-12-13 13:20:45 -05002649static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05002650static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2651 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002652
James Smart352e5fd2016-12-30 06:57:47 -08002653static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smart1ba981f2014-02-20 09:56:45 -05002654#define WWN_SZ 8
2655/**
2656 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2657 * @buf: WWN string.
2658 * @cnt: Length of string.
2659 * @wwn: Array to receive converted wwn value.
2660 *
2661 * Returns:
2662 * -EINVAL if the buffer does not contain a valid wwn
2663 * 0 success
2664 **/
2665static size_t
2666lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2667{
2668 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002669
James Smart1ba981f2014-02-20 09:56:45 -05002670 /* Count may include a LF at end of string */
2671 if (buf[cnt-1] == '\n')
2672 cnt--;
2673
2674 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2675 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2676 return -EINVAL;
2677
2678 memset(wwn, 0, WWN_SZ);
2679
2680 /* Validate and store the new name */
2681 for (i = 0, j = 0; i < 16; i++) {
2682 if ((*buf >= 'a') && (*buf <= 'f'))
2683 j = ((j << 4) | ((*buf++ - 'a') + 10));
2684 else if ((*buf >= 'A') && (*buf <= 'F'))
2685 j = ((j << 4) | ((*buf++ - 'A') + 10));
2686 else if ((*buf >= '0') && (*buf <= '9'))
2687 j = ((j << 4) | (*buf++ - '0'));
2688 else
2689 return -EINVAL;
2690 if (i % 2) {
2691 wwn[i/2] = j & 0xff;
2692 j = 0;
2693 }
2694 }
2695 return 0;
2696}
James Smart352e5fd2016-12-30 06:57:47 -08002697/**
2698 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2699 * @dev: class device that is converted into a Scsi_host.
2700 * @attr: device attribute, not used.
2701 * @buf: containing the string lpfc_soft_wwn_key.
2702 * @count: must be size of lpfc_soft_wwn_key.
2703 *
2704 * Returns:
2705 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2706 * length of buf indicates success
2707 **/
2708static ssize_t
2709lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2710 const char *buf, size_t count)
2711{
2712 struct Scsi_Host *shost = class_to_shost(dev);
2713 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2714 struct lpfc_hba *phba = vport->phba;
2715 unsigned int cnt = count;
James Smartaeb3c812017-04-21 16:05:02 -07002716 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2717 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
James Smart352e5fd2016-12-30 06:57:47 -08002718
2719 /*
2720 * We're doing a simple sanity check for soft_wwpn setting.
2721 * We require that the user write a specific key to enable
2722 * the soft_wwpn attribute to be settable. Once the attribute
2723 * is written, the enable key resets. If further updates are
2724 * desired, the key must be written again to re-enable the
2725 * attribute.
2726 *
2727 * The "key" is not secret - it is a hardcoded string shown
2728 * here. The intent is to protect against the random user or
2729 * application that is just writing attributes.
2730 */
James Smartaeb3c812017-04-21 16:05:02 -07002731 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2732 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2733 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2734 " be enabled: fawwpn is enabled\n");
2735 return -EINVAL;
2736 }
James Smart352e5fd2016-12-30 06:57:47 -08002737
2738 /* count may include a LF at end of string */
2739 if (buf[cnt-1] == '\n')
2740 cnt--;
2741
2742 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2743 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2744 return -EINVAL;
2745
2746 phba->soft_wwn_enable = 1;
2747
2748 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2749 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2750 phba->brd_no);
2751 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2752 " The soft_wwpn feature is not supported by Broadcom.");
2753
2754 return count;
2755}
Joe Perches6cbaefb2017-12-19 10:15:09 -08002756static DEVICE_ATTR_WO(lpfc_soft_wwn_enable);
James Smart352e5fd2016-12-30 06:57:47 -08002757
2758/**
2759 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2760 * @dev: class device that is converted into a Scsi_host.
2761 * @attr: device attribute, not used.
2762 * @buf: on return contains the wwpn in hexadecimal.
2763 *
2764 * Returns: size of formatted string.
2765 **/
2766static ssize_t
2767lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2768 char *buf)
2769{
2770 struct Scsi_Host *shost = class_to_shost(dev);
2771 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2772 struct lpfc_hba *phba = vport->phba;
2773
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002774 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
James Smart352e5fd2016-12-30 06:57:47 -08002775 (unsigned long long)phba->cfg_soft_wwpn);
2776}
2777
2778/**
2779 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2780 * @dev class device that is converted into a Scsi_host.
2781 * @attr: device attribute, not used.
2782 * @buf: contains the wwpn in hexadecimal.
2783 * @count: number of wwpn bytes in buf
2784 *
2785 * Returns:
2786 * -EACCES hba reset not enabled, adapter over temp
2787 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2788 * -EIO error taking adapter offline or online
2789 * value of count on success
2790 **/
2791static ssize_t
2792lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2793 const char *buf, size_t count)
2794{
2795 struct Scsi_Host *shost = class_to_shost(dev);
2796 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2797 struct lpfc_hba *phba = vport->phba;
2798 struct completion online_compl;
2799 int stat1 = 0, stat2 = 0;
2800 unsigned int cnt = count;
2801 u8 wwpn[WWN_SZ];
2802 int rc;
2803
2804 if (!phba->cfg_enable_hba_reset)
2805 return -EACCES;
2806 spin_lock_irq(&phba->hbalock);
2807 if (phba->over_temp_state == HBA_OVER_TEMP) {
2808 spin_unlock_irq(&phba->hbalock);
2809 return -EACCES;
2810 }
2811 spin_unlock_irq(&phba->hbalock);
2812 /* count may include a LF at end of string */
2813 if (buf[cnt-1] == '\n')
2814 cnt--;
2815
2816 if (!phba->soft_wwn_enable)
2817 return -EINVAL;
2818
2819 /* lock setting wwpn, wwnn down */
2820 phba->soft_wwn_enable = 0;
2821
2822 rc = lpfc_wwn_set(buf, cnt, wwpn);
James Smarte2934ed2017-01-17 12:31:56 -08002823 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002824 /* not able to set wwpn, unlock it */
2825 phba->soft_wwn_enable = 1;
2826 return rc;
2827 }
2828
2829 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2830 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2831 if (phba->cfg_soft_wwnn)
2832 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2833
2834 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2835 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2836
2837 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2838 if (stat1)
2839 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2840 "0463 lpfc_soft_wwpn attribute set failed to "
2841 "reinit adapter - %d\n", stat1);
2842 init_completion(&online_compl);
2843 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2844 LPFC_EVT_ONLINE);
2845 if (rc == 0)
2846 return -ENOMEM;
2847
2848 wait_for_completion(&online_compl);
2849 if (stat2)
2850 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2851 "0464 lpfc_soft_wwpn attribute set failed to "
2852 "reinit adapter - %d\n", stat2);
2853 return (stat1 || stat2) ? -EIO : count;
2854}
Joe Perchesb6b996b2017-12-19 10:15:07 -08002855static DEVICE_ATTR_RW(lpfc_soft_wwpn);
James Smart352e5fd2016-12-30 06:57:47 -08002856
2857/**
2858 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2859 * @dev: class device that is converted into a Scsi_host.
2860 * @attr: device attribute, not used.
2861 * @buf: on return contains the wwnn in hexadecimal.
2862 *
2863 * Returns: size of formatted string.
2864 **/
2865static ssize_t
2866lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2867 char *buf)
2868{
2869 struct Scsi_Host *shost = class_to_shost(dev);
2870 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002871 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
James Smart352e5fd2016-12-30 06:57:47 -08002872 (unsigned long long)phba->cfg_soft_wwnn);
2873}
2874
2875/**
2876 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2877 * @cdev: class device that is converted into a Scsi_host.
2878 * @buf: contains the ww node name in hexadecimal.
2879 * @count: number of wwnn bytes in buf.
2880 *
2881 * Returns:
2882 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2883 * value of count on success
2884 **/
2885static ssize_t
2886lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2887 const char *buf, size_t count)
2888{
2889 struct Scsi_Host *shost = class_to_shost(dev);
2890 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2891 unsigned int cnt = count;
2892 u8 wwnn[WWN_SZ];
2893 int rc;
2894
2895 /* count may include a LF at end of string */
2896 if (buf[cnt-1] == '\n')
2897 cnt--;
2898
2899 if (!phba->soft_wwn_enable)
2900 return -EINVAL;
2901
2902 rc = lpfc_wwn_set(buf, cnt, wwnn);
James Smarte2934ed2017-01-17 12:31:56 -08002903 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002904 /* Allow wwnn to be set many times, as long as the enable
2905 * is set. However, once the wwpn is set, everything locks.
2906 */
2907 return rc;
2908 }
2909
2910 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2911
2912 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2913 "lpfc%d: soft_wwnn set. Value will take effect upon "
2914 "setting of the soft_wwpn\n", phba->brd_no);
2915
2916 return count;
2917}
Joe Perchesb6b996b2017-12-19 10:15:07 -08002918static DEVICE_ATTR_RW(lpfc_soft_wwnn);
James Smarta12e07b2006-12-02 13:35:30 -05002919
James Smart1ba981f2014-02-20 09:56:45 -05002920/**
2921 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2922 * Optimized Access Storage (OAS) operations.
2923 * @dev: class device that is converted into a Scsi_host.
2924 * @attr: device attribute, not used.
2925 * @buf: buffer for passing information.
2926 *
2927 * Returns:
2928 * value of count
2929 **/
2930static ssize_t
2931lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2932 char *buf)
2933{
2934 struct Scsi_Host *shost = class_to_shost(dev);
2935 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2936
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002937 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
James Smart1ba981f2014-02-20 09:56:45 -05002938 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2939}
2940
2941/**
2942 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2943 * Optimized Access Storage (OAS) operations.
2944 * @dev: class device that is converted into a Scsi_host.
2945 * @attr: device attribute, not used.
2946 * @buf: buffer for passing information.
2947 * @count: Size of the data buffer.
2948 *
2949 * Returns:
2950 * -EINVAL count is invalid, invalid wwpn byte invalid
2951 * -EPERM oas is not supported by hba
2952 * value of count on success
2953 **/
2954static ssize_t
2955lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2956 const char *buf, size_t count)
2957{
2958 struct Scsi_Host *shost = class_to_shost(dev);
2959 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2960 unsigned int cnt = count;
2961 uint8_t wwpn[WWN_SZ];
2962 int rc;
2963
James Smartf38fa0b2014-04-04 13:52:21 -04002964 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002965 return -EPERM;
2966
2967 /* count may include a LF at end of string */
2968 if (buf[cnt-1] == '\n')
2969 cnt--;
2970
2971 rc = lpfc_wwn_set(buf, cnt, wwpn);
2972 if (rc)
2973 return rc;
2974
2975 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2976 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2977 if (wwn_to_u64(wwpn) == 0)
2978 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2979 else
2980 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2981 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2982 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2983 return count;
2984}
2985static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2986 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2987
2988/**
James Smartc92c8412016-07-06 12:36:05 -07002989 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2990 * Optimized Access Storage (OAS) operations.
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 * Returns:
2996 * value of count
2997 **/
2998static ssize_t
2999lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
3000 char *buf)
3001{
3002 struct Scsi_Host *shost = class_to_shost(dev);
3003 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3004
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003005 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
James Smartc92c8412016-07-06 12:36:05 -07003006}
3007
3008/**
3009 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
3010 * Optimized Access Storage (OAS) operations.
3011 * @dev: class device that is converted into a Scsi_host.
3012 * @attr: device attribute, not used.
3013 * @buf: buffer for passing information.
3014 * @count: Size of the data buffer.
3015 *
3016 * Returns:
3017 * -EINVAL count is invalid, invalid wwpn byte invalid
3018 * -EPERM oas is not supported by hba
3019 * value of count on success
3020 **/
3021static ssize_t
3022lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
3023 const char *buf, size_t count)
3024{
3025 struct Scsi_Host *shost = class_to_shost(dev);
3026 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3027 unsigned int cnt = count;
3028 unsigned long val;
3029 int ret;
3030
3031 if (!phba->cfg_fof)
3032 return -EPERM;
3033
3034 /* count may include a LF at end of string */
3035 if (buf[cnt-1] == '\n')
3036 cnt--;
3037
3038 ret = kstrtoul(buf, 0, &val);
3039 if (ret || (val > 0x7f))
3040 return -EINVAL;
3041
3042 if (val)
3043 phba->cfg_oas_priority = (uint8_t)val;
3044 else
3045 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3046 return count;
3047}
3048static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
3049 lpfc_oas_priority_show, lpfc_oas_priority_store);
3050
3051/**
James Smart1ba981f2014-02-20 09:56:45 -05003052 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
3053 * for Optimized Access Storage (OAS) operations.
3054 * @dev: class device that is converted into a Scsi_host.
3055 * @attr: device attribute, not used.
3056 * @buf: buffer for passing information.
3057 *
3058 * Returns:
3059 * value of count on success
3060 **/
3061static ssize_t
3062lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
3063 char *buf)
3064{
3065 struct Scsi_Host *shost = class_to_shost(dev);
3066 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3067
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003068 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
James Smart1ba981f2014-02-20 09:56:45 -05003069 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
3070}
3071
3072/**
3073 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
3074 * for Optimized Access Storage (OAS) operations.
3075 * @dev: class device that is converted into a Scsi_host.
3076 * @attr: device attribute, not used.
3077 * @buf: buffer for passing information.
3078 * @count: Size of the data buffer.
3079 *
3080 * Returns:
3081 * -EINVAL count is invalid, invalid wwpn byte invalid
3082 * -EPERM oas is not supported by hba
3083 * value of count on success
3084 **/
3085static ssize_t
3086lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
3087 const char *buf, size_t count)
3088{
3089 struct Scsi_Host *shost = class_to_shost(dev);
3090 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3091 unsigned int cnt = count;
3092 uint8_t wwpn[WWN_SZ];
3093 int rc;
3094
James Smartf38fa0b2014-04-04 13:52:21 -04003095 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003096 return -EPERM;
3097
3098 /* count may include a LF at end of string */
3099 if (buf[cnt-1] == '\n')
3100 cnt--;
3101
3102 rc = lpfc_wwn_set(buf, cnt, wwpn);
3103 if (rc)
3104 return rc;
3105
3106 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3107 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3108 if (wwn_to_u64(wwpn) == 0)
3109 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
3110 else
3111 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
3112 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
James Smartb5749fe2016-12-19 15:07:26 -08003113 if (phba->cfg_oas_priority == 0)
3114 phba->cfg_oas_priority = phba->cfg_XLanePriority;
James Smart1ba981f2014-02-20 09:56:45 -05003115 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3116 return count;
3117}
3118static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
3119 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
3120
3121/**
3122 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
3123 * of whether luns will be enabled or disabled
3124 * for Optimized Access Storage (OAS) operations.
3125 * @dev: class device that is converted into a Scsi_host.
3126 * @attr: device attribute, not used.
3127 * @buf: buffer for passing information.
3128 *
3129 * Returns:
3130 * size of formatted string.
3131 **/
3132static ssize_t
3133lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
3134 char *buf)
3135{
3136 struct Scsi_Host *shost = class_to_shost(dev);
3137 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3138
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003139 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
James Smart1ba981f2014-02-20 09:56:45 -05003140}
3141
3142/**
3143 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
3144 * of whether luns will be enabled or disabled
3145 * for Optimized Access Storage (OAS) operations.
3146 * @dev: class device that is converted into a Scsi_host.
3147 * @attr: device attribute, not used.
3148 * @buf: buffer for passing information.
3149 * @count: Size of the data buffer.
3150 *
3151 * Returns:
3152 * -EINVAL count is invalid, invalid wwpn byte invalid
3153 * -EPERM oas is not supported by hba
3154 * value of count on success
3155 **/
3156static ssize_t
3157lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
3158 const char *buf, size_t count)
3159{
3160 struct Scsi_Host *shost = class_to_shost(dev);
3161 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3162 int val = 0;
3163
James Smartf38fa0b2014-04-04 13:52:21 -04003164 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003165 return -EPERM;
3166
3167 if (!isdigit(buf[0]))
3168 return -EINVAL;
3169
3170 if (sscanf(buf, "%i", &val) != 1)
3171 return -EINVAL;
3172
3173 if ((val != 0) && (val != 1))
3174 return -EINVAL;
3175
3176 phba->cfg_oas_lun_state = val;
James Smart1ba981f2014-02-20 09:56:45 -05003177 return strlen(buf);
3178}
3179static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
3180 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
3181
3182/**
3183 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
3184 * Storage (OAS) lun returned by the
3185 * lpfc_oas_lun_show function.
3186 * @dev: class device that is converted into a Scsi_host.
3187 * @attr: device attribute, not used.
3188 * @buf: buffer for passing information.
3189 *
3190 * Returns:
3191 * size of formatted string.
3192 **/
3193static ssize_t
3194lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
3195 char *buf)
3196{
3197 struct Scsi_Host *shost = class_to_shost(dev);
3198 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3199
3200 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
3201 return -EFAULT;
3202
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003203 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
James Smart1ba981f2014-02-20 09:56:45 -05003204}
3205static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
3206 lpfc_oas_lun_status_show, NULL);
3207
3208
3209/**
3210 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
3211 * (OAS) operations.
3212 * @phba: lpfc_hba pointer.
3213 * @ndlp: pointer to fcp target node.
3214 * @lun: the fc lun for setting oas state.
3215 * @oas_state: the oas state to be set to the lun.
3216 *
3217 * Returns:
3218 * SUCCESS : 0
3219 * -EPERM OAS is not enabled or not supported by this port.
3220 *
3221 */
3222static size_t
3223lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartc92c8412016-07-06 12:36:05 -07003224 uint8_t tgt_wwpn[], uint64_t lun,
3225 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05003226{
3227
3228 int rc = 0;
3229
James Smartf38fa0b2014-04-04 13:52:21 -04003230 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003231 return -EPERM;
3232
3233 if (oas_state) {
3234 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07003235 (struct lpfc_name *)tgt_wwpn,
3236 lun, pri))
James Smart1ba981f2014-02-20 09:56:45 -05003237 rc = -ENOMEM;
3238 } else {
3239 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08003240 (struct lpfc_name *)tgt_wwpn, lun, pri);
James Smart1ba981f2014-02-20 09:56:45 -05003241 }
3242 return rc;
3243
3244}
3245
3246/**
3247 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
3248 * Access Storage (OAS) operations.
3249 * @phba: lpfc_hba pointer.
3250 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3251 * @tgt_wwpn: wwpn of the target associated with the returned lun
3252 * @lun_status: status of the lun returned lun
3253 *
3254 * Returns the first or next lun enabled for OAS operations for the vport/target
3255 * specified. If a lun is found, its vport wwpn, target wwpn and status is
3256 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
3257 *
3258 * Return:
3259 * lun that is OAS enabled for the vport/target
3260 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
3261 */
3262static uint64_t
3263lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartb5749fe2016-12-19 15:07:26 -08003264 uint8_t tgt_wwpn[], uint32_t *lun_status,
3265 uint32_t *lun_pri)
James Smart1ba981f2014-02-20 09:56:45 -05003266{
3267 uint64_t found_lun;
3268
3269 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
3270 return NOT_OAS_ENABLED_LUN;
3271 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
3272 phba->sli4_hba.oas_next_vpt_wwpn,
3273 (struct lpfc_name *)
3274 phba->sli4_hba.oas_next_tgt_wwpn,
3275 &phba->sli4_hba.oas_next_lun,
3276 (struct lpfc_name *)vpt_wwpn,
3277 (struct lpfc_name *)tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08003278 &found_lun, lun_status, lun_pri))
James Smart1ba981f2014-02-20 09:56:45 -05003279 return found_lun;
3280 else
3281 return NOT_OAS_ENABLED_LUN;
3282}
3283
3284/**
3285 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
3286 * @phba: lpfc_hba pointer.
3287 * @vpt_wwpn: vport wwpn by reference.
3288 * @tgt_wwpn: target wwpn by reference.
3289 * @lun: the fc lun for setting oas state.
3290 * @oas_state: the oas state to be set to the oas_lun.
3291 *
3292 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
3293 * a lun for OAS operations.
3294 *
3295 * Return:
3296 * SUCCESS: 0
3297 * -ENOMEM: failed to enable an lun for OAS operations
3298 * -EPERM: OAS is not enabled
3299 */
3300static ssize_t
3301lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3302 uint8_t tgt_wwpn[], uint64_t lun,
James Smartc92c8412016-07-06 12:36:05 -07003303 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05003304{
3305
3306 int rc;
3307
3308 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
James Smartc92c8412016-07-06 12:36:05 -07003309 oas_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05003310 return rc;
3311}
3312
3313/**
3314 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
3315 * @dev: class device that is converted into a Scsi_host.
3316 * @attr: device attribute, not used.
3317 * @buf: buffer for passing information.
3318 *
3319 * This routine returns a lun enabled for OAS each time the function
3320 * is called.
3321 *
3322 * Returns:
3323 * SUCCESS: size of formatted string.
3324 * -EFAULT: target or vport wwpn was not set properly.
3325 * -EPERM: oas is not enabled.
3326 **/
3327static ssize_t
3328lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3329 char *buf)
3330{
3331 struct Scsi_Host *shost = class_to_shost(dev);
3332 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3333
3334 uint64_t oas_lun;
3335 int len = 0;
3336
James Smartf38fa0b2014-04-04 13:52:21 -04003337 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003338 return -EPERM;
3339
3340 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3341 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3342 return -EFAULT;
3343
3344 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3345 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3346 return -EFAULT;
3347
3348 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3349 phba->cfg_oas_tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08003350 &phba->cfg_oas_lun_status,
3351 &phba->cfg_oas_priority);
James Smart1ba981f2014-02-20 09:56:45 -05003352 if (oas_lun != NOT_OAS_ENABLED_LUN)
3353 phba->cfg_oas_flags |= OAS_LUN_VALID;
3354
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003355 len += scnprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
James Smart1ba981f2014-02-20 09:56:45 -05003356
3357 return len;
3358}
3359
3360/**
3361 * lpfc_oas_lun_store - Sets the OAS state for lun
3362 * @dev: class device that is converted into a Scsi_host.
3363 * @attr: device attribute, not used.
3364 * @buf: buffer for passing information.
3365 *
3366 * This function sets the OAS state for lun. Before this function is called,
3367 * the vport wwpn, target wwpn, and oas state need to be set.
3368 *
3369 * Returns:
3370 * SUCCESS: size of formatted string.
3371 * -EFAULT: target or vport wwpn was not set properly.
3372 * -EPERM: oas is not enabled.
3373 * size of formatted string.
3374 **/
3375static ssize_t
3376lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3377 const char *buf, size_t count)
3378{
3379 struct Scsi_Host *shost = class_to_shost(dev);
3380 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3381 uint64_t scsi_lun;
James Smartb5749fe2016-12-19 15:07:26 -08003382 uint32_t pri;
James Smart1ba981f2014-02-20 09:56:45 -05003383 ssize_t rc;
3384
James Smartf38fa0b2014-04-04 13:52:21 -04003385 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003386 return -EPERM;
3387
3388 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3389 return -EFAULT;
3390
3391 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3392 return -EFAULT;
3393
3394 if (!isdigit(buf[0]))
3395 return -EINVAL;
3396
3397 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3398 return -EINVAL;
3399
James Smartb5749fe2016-12-19 15:07:26 -08003400 pri = phba->cfg_oas_priority;
3401 if (pri == 0)
3402 pri = phba->cfg_XLanePriority;
3403
James Smart1ba981f2014-02-20 09:56:45 -05003404 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartc92c8412016-07-06 12:36:05 -07003405 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3406 "priority 0x%x with oas state %d\n",
James Smart1ba981f2014-02-20 09:56:45 -05003407 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3408 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08003409 pri, phba->cfg_oas_lun_state);
James Smart1ba981f2014-02-20 09:56:45 -05003410
3411 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07003412 phba->cfg_oas_tgt_wwpn, scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08003413 phba->cfg_oas_lun_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05003414 if (rc)
3415 return rc;
3416
3417 return count;
3418}
3419static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3420 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04003421
James Smartf358dd02017-02-12 13:52:34 -08003422int lpfc_enable_nvmet_cnt;
3423unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3424 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3425 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3426module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3427MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3428
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003429static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05003430module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003431MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3432 " 0 - none,"
3433 " 1 - poll with interrupts enabled"
3434 " 3 - poll and disable FCP ring interrupts");
3435
Joe Perchesb6b996b2017-12-19 10:15:07 -08003436static DEVICE_ATTR_RW(lpfc_poll);
dea31012005-04-17 16:05:31 -05003437
James Smart96418b52017-03-04 09:30:31 -08003438int lpfc_no_hba_reset_cnt;
3439unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3440 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3441module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3442MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3443
James Smart12247e82016-07-06 12:36:09 -07003444LPFC_ATTR(sli_mode, 0, 0, 3,
3445 "SLI mode selector:"
3446 " 0 - auto (SLI-3 if supported),"
3447 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3448 " 3 - select SLI-3");
James Smart92d7f7b2007-06-17 19:56:38 -05003449
James Smart458c0832016-07-06 12:36:07 -07003450LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3451 "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05003452
James Smart7d791df2011-07-22 18:37:52 -04003453LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3454 "FCF Fast failover=1 Priority failover=2");
3455
James Smarte5771b42013-03-01 16:37:14 -05003456/*
3457# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3458# 0x0 = disabled, XRI/OXID use not tracked.
3459# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3460# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3461*/
James Smart31202b02016-10-13 15:06:08 -07003462LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3463 "Enable RRQ functionality");
James Smart19ca7602010-11-20 23:11:55 -05003464
dea31012005-04-17 16:05:31 -05003465/*
James Smart84d1b002010-02-12 14:42:33 -05003466# lpfc_suppress_link_up: Bring link up at initialization
3467# 0x0 = bring link up (issue MBX_INIT_LINK)
3468# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3469# 0x2 = never bring up link
3470# Default value is 0.
3471*/
James Smarte40a02c2010-02-26 14:13:54 -05003472LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3473 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3474 "Suppress Link Up at initialization");
James Smart83c6cb12019-10-18 14:18:30 -07003475
3476static ssize_t
3477lpfc_pls_show(struct device *dev, struct device_attribute *attr, char *buf)
3478{
3479 struct Scsi_Host *shost = class_to_shost(dev);
3480 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3481
3482 return scnprintf(buf, PAGE_SIZE, "%d\n",
3483 phba->sli4_hba.pc_sli4_params.pls);
3484}
3485static DEVICE_ATTR(pls, 0444,
3486 lpfc_pls_show, NULL);
3487
3488static ssize_t
3489lpfc_pt_show(struct device *dev, struct device_attribute *attr, char *buf)
3490{
3491 struct Scsi_Host *shost = class_to_shost(dev);
3492 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3493
3494 return scnprintf(buf, PAGE_SIZE, "%d\n",
3495 (phba->hba_flag & HBA_PERSISTENT_TOPO) ? 1 : 0);
3496}
3497static DEVICE_ATTR(pt, 0444,
3498 lpfc_pt_show, NULL);
3499
James Smart2a9bf3d2010-06-07 15:24:45 -04003500/*
3501# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3502# 1 - (1024)
3503# 2 - (2048)
3504# 3 - (3072)
3505# 4 - (4096)
3506# 5 - (5120)
3507*/
3508static ssize_t
3509lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3510{
3511 struct Scsi_Host *shost = class_to_shost(dev);
3512 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3513
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003514 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
James Smart2a9bf3d2010-06-07 15:24:45 -04003515}
3516
3517static DEVICE_ATTR(iocb_hw, S_IRUGO,
3518 lpfc_iocb_hw_show, NULL);
3519static ssize_t
3520lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3521{
3522 struct Scsi_Host *shost = class_to_shost(dev);
3523 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003524 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003525
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003526 return scnprintf(buf, PAGE_SIZE, "%d\n",
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003527 pring ? pring->txq_max : 0);
James Smart2a9bf3d2010-06-07 15:24:45 -04003528}
3529
3530static DEVICE_ATTR(txq_hw, S_IRUGO,
3531 lpfc_txq_hw_show, NULL);
3532static ssize_t
3533lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3534 char *buf)
3535{
3536 struct Scsi_Host *shost = class_to_shost(dev);
3537 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003538 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003539
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003540 return scnprintf(buf, PAGE_SIZE, "%d\n",
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003541 pring ? pring->txcmplq_max : 0);
James Smart2a9bf3d2010-06-07 15:24:45 -04003542}
3543
3544static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3545 lpfc_txcmplq_hw_show, NULL);
3546
James Smart84d1b002010-02-12 14:42:33 -05003547/*
James Smartc01f3202006-08-18 17:47:08 -04003548# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3549# until the timer expires. Value range is [0,255]. Default value is 30.
3550*/
3551static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3552static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3553module_param(lpfc_nodev_tmo, int, 0);
3554MODULE_PARM_DESC(lpfc_nodev_tmo,
3555 "Seconds driver will hold I/O waiting "
3556 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04003557
3558/**
James Smart3621a712009-04-06 18:47:14 -04003559 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04003560 * @dev: class converted to a Scsi_host structure.
3561 * @attr: device attribute, not used.
3562 * @buf: on return contains the dev loss timeout in decimal.
3563 *
3564 * Returns: size of formatted string.
3565 **/
James Smartc01f3202006-08-18 17:47:08 -04003566static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003567lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3568 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04003569{
Tony Jonesee959b02008-02-22 00:13:36 +01003570 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003571 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05003572
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003573 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003574}
3575
James Smarte59058c2008-08-24 21:49:00 -04003576/**
James Smart3621a712009-04-06 18:47:14 -04003577 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04003578 * @vport: lpfc vport structure pointer.
3579 * @val: contains the nodev timeout value.
3580 *
3581 * Description:
3582 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3583 * a kernel error message is printed and zero is returned.
3584 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3585 * Otherwise nodev tmo is set to the default value.
3586 *
3587 * Returns:
3588 * zero if already set or if val is in range
3589 * -EINVAL val out of range
3590 **/
James Smartc01f3202006-08-18 17:47:08 -04003591static int
James Smart3de2a652007-08-02 11:09:59 -04003592lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003593{
James Smart3de2a652007-08-02 11:09:59 -04003594 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3595 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3596 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04003597 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003598 "0407 Ignoring lpfc_nodev_tmo module "
3599 "parameter because lpfc_devloss_tmo "
3600 "is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003601 return 0;
3602 }
3603
3604 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003605 vport->cfg_nodev_tmo = val;
3606 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04003607 return 0;
3608 }
James Smarte8b62012007-08-02 11:10:09 -04003609 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3610 "0400 lpfc_nodev_tmo attribute cannot be set to"
3611 " %d, allowed range is [%d, %d]\n",
3612 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04003613 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04003614 return -EINVAL;
3615}
3616
James Smarte59058c2008-08-24 21:49:00 -04003617/**
James Smart3621a712009-04-06 18:47:14 -04003618 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04003619 * @vport: lpfc vport structure pointer.
3620 *
3621 * Description:
3622 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3623 **/
James Smart7054a602007-04-25 09:52:34 -04003624static void
James Smart3de2a652007-08-02 11:09:59 -04003625lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04003626{
James Smart858c9f62007-06-17 19:56:39 -05003627 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04003628 struct lpfc_nodelist *ndlp;
James Smart01466022018-04-09 14:24:27 -07003629#if (IS_ENABLED(CONFIG_NVME_FC))
3630 struct lpfc_nvme_rport *rport;
James Smart9e210172018-09-13 15:41:10 -07003631 struct nvme_fc_remote_port *remoteport = NULL;
James Smart01466022018-04-09 14:24:27 -07003632#endif
James Smart7054a602007-04-25 09:52:34 -04003633
James Smart51ef4c22007-08-02 11:10:31 -04003634 shost = lpfc_shost_from_vport(vport);
3635 spin_lock_irq(shost->host_lock);
James Smart7a06dcd2017-06-01 21:06:55 -07003636 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3637 if (!NLP_CHK_NODE_ACT(ndlp))
3638 continue;
3639 if (ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04003640 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
James Smart6ddcf0a2017-11-03 09:33:30 -07003641#if (IS_ENABLED(CONFIG_NVME_FC))
James Smart9e210172018-09-13 15:41:10 -07003642 spin_lock(&vport->phba->hbalock);
James Smart01466022018-04-09 14:24:27 -07003643 rport = lpfc_ndlp_get_nrport(ndlp);
3644 if (rport)
James Smart9e210172018-09-13 15:41:10 -07003645 remoteport = rport->remoteport;
3646 spin_unlock(&vport->phba->hbalock);
James Smart07f50992019-08-14 16:56:45 -07003647 if (rport && remoteport)
3648 nvme_fc_set_remoteport_devloss(remoteport,
James Smart6ddcf0a2017-11-03 09:33:30 -07003649 vport->cfg_devloss_tmo);
3650#endif
James Smart7a06dcd2017-06-01 21:06:55 -07003651 }
James Smart51ef4c22007-08-02 11:10:31 -04003652 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04003653}
3654
James Smarte59058c2008-08-24 21:49:00 -04003655/**
James Smart3621a712009-04-06 18:47:14 -04003656 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04003657 * @vport: lpfc vport structure pointer.
3658 * @val: contains the tmo value.
3659 *
3660 * Description:
3661 * If the devloss tmo is already set or the vport dev loss tmo has changed
3662 * then a kernel error message is printed and zero is returned.
3663 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3664 * Otherwise nodev tmo is set to the default value.
3665 *
3666 * Returns:
3667 * zero if already set or if val is in range
3668 * -EINVAL val out of range
3669 **/
James Smartc01f3202006-08-18 17:47:08 -04003670static int
James Smart3de2a652007-08-02 11:09:59 -04003671lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003672{
James Smart3de2a652007-08-02 11:09:59 -04003673 if (vport->dev_loss_tmo_changed ||
3674 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04003675 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003676 "0401 Ignoring change to lpfc_nodev_tmo "
3677 "because lpfc_devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003678 return 0;
3679 }
James Smartc01f3202006-08-18 17:47:08 -04003680 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003681 vport->cfg_nodev_tmo = val;
3682 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05003683 /*
3684 * For compat: set the fc_host dev loss so new rports
3685 * will get the value.
3686 */
3687 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003688 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003689 return 0;
3690 }
James Smarte8b62012007-08-02 11:10:09 -04003691 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003692 "0403 lpfc_nodev_tmo attribute cannot be set to "
James Smarte8b62012007-08-02 11:10:09 -04003693 "%d, allowed range is [%d, %d]\n",
3694 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003695 return -EINVAL;
3696}
3697
James Smart3de2a652007-08-02 11:09:59 -04003698lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04003699
Joe Perchesb6b996b2017-12-19 10:15:07 -08003700static DEVICE_ATTR_RW(lpfc_nodev_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003701
3702/*
3703# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3704# disappear until the timer expires. Value range is [0,255]. Default
3705# value is 30.
3706*/
James Smartab56dc22011-02-16 12:39:57 -05003707module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04003708MODULE_PARM_DESC(lpfc_devloss_tmo,
3709 "Seconds driver will hold I/O waiting "
3710 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04003711lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3712 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3713lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04003714
3715/**
James Smart3621a712009-04-06 18:47:14 -04003716 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04003717 * @vport: lpfc vport structure pointer.
3718 * @val: contains the tmo value.
3719 *
3720 * Description:
3721 * If val is in a valid range then set the vport nodev tmo,
3722 * devloss tmo, also set the vport dev loss tmo changed flag.
3723 * Else a kernel error message is printed.
3724 *
3725 * Returns:
3726 * zero if val is in range
3727 * -EINVAL val out of range
3728 **/
James Smartc01f3202006-08-18 17:47:08 -04003729static int
James Smart3de2a652007-08-02 11:09:59 -04003730lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003731{
3732 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003733 vport->cfg_nodev_tmo = val;
3734 vport->cfg_devloss_tmo = val;
3735 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05003736 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003737 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003738 return 0;
3739 }
3740
James Smarte8b62012007-08-02 11:10:09 -04003741 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003742 "0404 lpfc_devloss_tmo attribute cannot be set to "
3743 "%d, allowed range is [%d, %d]\n",
James Smarte8b62012007-08-02 11:10:09 -04003744 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003745 return -EINVAL;
3746}
3747
James Smart3de2a652007-08-02 11:09:59 -04003748lpfc_vport_param_store(devloss_tmo)
Joe Perchesb6b996b2017-12-19 10:15:07 -08003749static DEVICE_ATTR_RW(lpfc_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003750
3751/*
James Smartf358dd02017-02-12 13:52:34 -08003752 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3753 * lpfc_suppress_rsp = 0 Disable
3754 * lpfc_suppress_rsp = 1 Enable (default)
3755 *
3756 */
3757LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3758 "Enable suppress rsp feature is firmware supports it");
3759
3760/*
James Smart2d7dbc42017-02-12 13:52:35 -08003761 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
James Smartbcb24f62017-11-20 16:00:36 -08003762 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
James Smart2d7dbc42017-02-12 13:52:35 -08003763 * lpfc_nvmet_mrq = 1 use a single RQ pair
3764 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3765 *
3766 */
3767LPFC_ATTR_R(nvmet_mrq,
James Smartbcb24f62017-11-20 16:00:36 -08003768 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
James Smart2d7dbc42017-02-12 13:52:35 -08003769 "Specify number of RQ pairs for processing NVMET cmds");
3770
3771/*
James Smart2448e482018-04-09 14:24:24 -07003772 * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post
3773 * to each NVMET RQ. Range 64 to 2048, default is 512.
3774 */
3775LPFC_ATTR_R(nvmet_mrq_post,
3776 LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,
3777 LPFC_NVMET_RQE_DEF_COUNT,
3778 "Specify number of RQ buffers to initially post");
3779
3780/*
James Smart895427b2017-02-12 13:52:30 -08003781 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3782 * Supported Values: 1 - register just FCP
3783 * 3 - register both FCP and NVME
James Smartb1684a02019-01-28 11:14:36 -08003784 * Supported values are [1,3]. Default value is 3
James Smart895427b2017-02-12 13:52:30 -08003785 */
James Smartb1684a02019-01-28 11:14:36 -08003786LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_BOTH,
James Smart895427b2017-02-12 13:52:30 -08003787 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
Dick Kennedycf4c8c82017-09-29 17:34:38 -07003788 "Enable FC4 Protocol support - FCP / NVME");
James Smart895427b2017-02-12 13:52:30 -08003789
3790/*
dea31012005-04-17 16:05:31 -05003791# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3792# deluged with LOTS of information.
3793# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04003794# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05003795*/
James Smartf4b4c682009-05-22 14:53:12 -04003796LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04003797 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05003798
3799/*
James Smart7ee5d432007-10-27 13:37:17 -04003800# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3801# objects that have been registered with the nameserver after login.
3802*/
James Smartcf971242012-03-01 22:37:32 -05003803LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04003804 "Deregister nameserver objects before LOGO");
3805
3806/*
dea31012005-04-17 16:05:31 -05003807# lun_queue_depth: This parameter is used to limit the number of outstanding
Dick Kennedy763a18c2020-03-23 09:19:35 -07003808# commands per FCP LUN.
dea31012005-04-17 16:05:31 -05003809*/
Dick Kennedy763a18c2020-03-23 09:19:35 -07003810LPFC_VPORT_ATTR_R(lun_queue_depth, 64, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04003811 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05003812
3813/*
James Smart7dc517d2010-07-14 15:32:10 -04003814# tgt_queue_depth: This parameter is used to limit the number of outstanding
3815# commands per target port. Value range is [10,65535]. Default value is 65535.
3816*/
James Smartf91bc592018-04-09 14:24:22 -07003817static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
3818module_param(lpfc_tgt_queue_depth, uint, 0444);
3819MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
3820lpfc_vport_param_show(tgt_queue_depth);
3821lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
3822 LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
3823
3824/**
3825 * lpfc_tgt_queue_depth_store: Sets an attribute value.
3826 * @phba: pointer the the adapter structure.
3827 * @val: integer attribute value.
3828 *
3829 * Description: Sets the parameter to the new value.
3830 *
3831 * Returns:
3832 * zero on success
3833 * -EINVAL if val is invalid
3834 */
3835static int
3836lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
3837{
3838 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3839 struct lpfc_nodelist *ndlp;
3840
3841 if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
3842 return -EINVAL;
3843
3844 if (val == vport->cfg_tgt_queue_depth)
3845 return 0;
3846
3847 spin_lock_irq(shost->host_lock);
3848 vport->cfg_tgt_queue_depth = val;
3849
3850 /* Next loop thru nodelist and change cmd_qdepth */
3851 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3852 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3853
3854 spin_unlock_irq(shost->host_lock);
3855 return 0;
3856}
3857
3858lpfc_vport_param_store(tgt_queue_depth);
3859static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04003860
3861/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003862# hba_queue_depth: This parameter is used to limit the number of outstanding
3863# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3864# value is greater than the maximum number of exchanges supported by the HBA,
3865# then maximum number of exchanges supported by the HBA is used to determine
3866# the hba_queue_depth.
3867*/
3868LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3869 "Max number of FCP commands we can queue to a lpfc HBA");
3870
3871/*
James Smart92d7f7b2007-06-17 19:56:38 -05003872# peer_port_login: This parameter allows/prevents logins
3873# between peer ports hosted on the same physical port.
3874# When this parameter is set 0 peer ports of same physical port
3875# are not allowed to login to each other.
3876# When this parameter is set 1 peer ports of same physical port
3877# are allowed to login to each other.
3878# Default value of this parameter is 0.
3879*/
James Smart3de2a652007-08-02 11:09:59 -04003880LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3881 "Allow peer ports on the same physical port to login to each "
3882 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05003883
3884/*
James Smart3de2a652007-08-02 11:09:59 -04003885# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05003886# between Virtual Ports and remote initiators.
3887# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3888# other initiators and will attempt to PLOGI all remote ports.
3889# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3890# remote ports and will not attempt to PLOGI to other initiators.
3891# This parameter does not restrict to the physical port.
3892# This parameter does not restrict logins to Fabric resident remote ports.
3893# Default value of this parameter is 1.
3894*/
James Smart3de2a652007-08-02 11:09:59 -04003895static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05003896module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04003897MODULE_PARM_DESC(lpfc_restrict_login,
3898 "Restrict virtual ports login to remote initiators.");
3899lpfc_vport_param_show(restrict_login);
3900
James Smarte59058c2008-08-24 21:49:00 -04003901/**
James Smart3621a712009-04-06 18:47:14 -04003902 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003903 * @vport: lpfc vport structure pointer.
3904 * @val: contains the restrict login value.
3905 *
3906 * Description:
3907 * If val is not in a valid range then log a kernel error message and set
3908 * the vport restrict login to one.
3909 * If the port type is physical clear the restrict login flag and return.
3910 * Else set the restrict login flag to val.
3911 *
3912 * Returns:
3913 * zero if val is in range
3914 * -EINVAL val out of range
3915 **/
James Smart3de2a652007-08-02 11:09:59 -04003916static int
3917lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3918{
3919 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003920 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003921 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003922 "be set to %d, allowed range is [0, 1]\n",
3923 val);
James Smart3de2a652007-08-02 11:09:59 -04003924 vport->cfg_restrict_login = 1;
3925 return -EINVAL;
3926 }
3927 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3928 vport->cfg_restrict_login = 0;
3929 return 0;
3930 }
3931 vport->cfg_restrict_login = val;
3932 return 0;
3933}
3934
James Smarte59058c2008-08-24 21:49:00 -04003935/**
James Smart3621a712009-04-06 18:47:14 -04003936 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003937 * @vport: lpfc vport structure pointer.
3938 * @val: contains the restrict login value.
3939 *
3940 * Description:
3941 * If val is not in a valid range then log a kernel error message and set
3942 * the vport restrict login to one.
3943 * If the port type is physical and the val is not zero log a kernel
3944 * error message, clear the restrict login flag and return zero.
3945 * Else set the restrict login flag to val.
3946 *
3947 * Returns:
3948 * zero if val is in range
3949 * -EINVAL val out of range
3950 **/
James Smart3de2a652007-08-02 11:09:59 -04003951static int
3952lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3953{
3954 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003955 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003956 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003957 "be set to %d, allowed range is [0, 1]\n",
3958 val);
James Smart3de2a652007-08-02 11:09:59 -04003959 vport->cfg_restrict_login = 1;
3960 return -EINVAL;
3961 }
3962 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04003963 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3964 "0468 lpfc_restrict_login must be 0 for "
3965 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04003966 vport->cfg_restrict_login = 0;
3967 return 0;
3968 }
3969 vport->cfg_restrict_login = val;
3970 return 0;
3971}
3972lpfc_vport_param_store(restrict_login);
Joe Perchesb6b996b2017-12-19 10:15:07 -08003973static DEVICE_ATTR_RW(lpfc_restrict_login);
James Smart92d7f7b2007-06-17 19:56:38 -05003974
3975/*
dea31012005-04-17 16:05:31 -05003976# Some disk devices have a "select ID" or "select Target" capability.
3977# From a protocol standpoint "select ID" usually means select the
3978# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3979# annex" which contains a table that maps a "select ID" (a number
3980# between 0 and 7F) to an ALPA. By default, for compatibility with
3981# older drivers, the lpfc driver scans this table from low ALPA to high
3982# ALPA.
3983#
3984# Turning on the scan-down variable (on = 1, off = 0) will
3985# cause the lpfc driver to use an inverted table, effectively
3986# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3987#
3988# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3989# and will not work across a fabric. Also this parameter will take
3990# effect only in the case when ALPA map is not available.)
3991*/
James Smart3de2a652007-08-02 11:09:59 -04003992LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3993 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05003994
3995/*
dea31012005-04-17 16:05:31 -05003996# lpfc_topology: link topology for init link
3997# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05003998# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05003999# 0x02 = attempt point-to-point mode only
4000# 0x04 = attempt loop mode only
4001# 0x06 = attempt point-to-point mode then loop
4002# Set point-to-point mode if you want to run as an N_Port.
4003# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
4004# Default value is 0.
4005*/
James Smart0a035432016-10-13 15:06:10 -07004006LPFC_ATTR(topology, 0, 0, 6,
4007 "Select Fibre Channel topology");
James Smarte59058c2008-08-24 21:49:00 -04004008
4009/**
James Smart3621a712009-04-06 18:47:14 -04004010 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04004011 * @phba: lpfc_hba pointer.
4012 * @val: topology value.
4013 *
4014 * Description:
4015 * If val is in a valid range then set the adapter's topology field and
4016 * issue a lip; if the lip fails reset the topology to the old value.
4017 *
4018 * If the value is not in range log a kernel error message and return an error.
4019 *
4020 * Returns:
4021 * zero if val is in range and lip okay
4022 * non-zero return value from lpfc_issue_lip()
4023 * -EINVAL val out of range
4024 **/
James Smarta257bf92009-04-06 18:48:10 -04004025static ssize_t
4026lpfc_topology_store(struct device *dev, struct device_attribute *attr,
4027 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05004028{
James Smarta257bf92009-04-06 18:48:10 -04004029 struct Scsi_Host *shost = class_to_shost(dev);
4030 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4031 struct lpfc_hba *phba = vport->phba;
4032 int val = 0;
4033 int nolip = 0;
4034 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05004035 int err;
4036 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04004037
4038 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4039 nolip = 1;
4040 val_buf = &buf[strlen("nolip ")];
4041 }
4042
4043 if (!isdigit(val_buf[0]))
4044 return -EINVAL;
4045 if (sscanf(val_buf, "%i", &val) != 1)
4046 return -EINVAL;
4047
James Smart83108bd2008-01-11 01:53:09 -05004048 if (val >= 0 && val <= 6) {
4049 prev_val = phba->cfg_topology;
James Smartff78d8f2011-12-13 13:21:35 -05004050 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
4051 val == 4) {
4052 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4053 "3113 Loop mode not supported at speed %d\n",
James Smartd38dd522015-08-31 16:48:17 -04004054 val);
James Smartff78d8f2011-12-13 13:21:35 -05004055 return -EINVAL;
4056 }
James Smart83c6cb12019-10-18 14:18:30 -07004057 /*
4058 * The 'topology' is not a configurable parameter if :
4059 * - persistent topology enabled
James Smarta052ce82019-12-18 15:58:04 -08004060 * - G7/G6 with no private loop support
James Smart83c6cb12019-10-18 14:18:30 -07004061 */
4062
James Smarta052ce82019-12-18 15:58:04 -08004063 if ((phba->hba_flag & HBA_PERSISTENT_TOPO ||
James Smart83c6cb12019-10-18 14:18:30 -07004064 (!phba->sli4_hba.pc_sli4_params.pls &&
James Smarta052ce82019-12-18 15:58:04 -08004065 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC ||
4066 phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC))) &&
James Smartf6978f42019-05-21 17:48:57 -07004067 val == 4) {
James Smartd38dd522015-08-31 16:48:17 -04004068 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartf6978f42019-05-21 17:48:57 -07004069 "3114 Loop mode not supported\n");
James Smartd38dd522015-08-31 16:48:17 -04004070 return -EINVAL;
4071 }
4072 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04004073 if (nolip)
4074 return strlen(buf);
4075
James Smart88a2cfb2011-07-22 18:36:33 -04004076 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4077 "3054 lpfc_topology changed from %d to %d\n",
4078 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04004079 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
4080 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05004081 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04004082 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05004083 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04004084 return -EINVAL;
4085 } else
4086 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05004087 }
4088 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4089 "%d:0467 lpfc_topology attribute cannot be set to %d, "
4090 "allowed range is [0, 6]\n",
4091 phba->brd_no, val);
4092 return -EINVAL;
4093}
James Smart0a035432016-10-13 15:06:10 -07004094
James Smart83108bd2008-01-11 01:53:09 -05004095lpfc_param_show(topology)
Joe Perchesb6b996b2017-12-19 10:15:07 -08004096static DEVICE_ATTR_RW(lpfc_topology);
dea31012005-04-17 16:05:31 -05004097
James Smart21e9a0a2009-05-22 14:53:21 -04004098/**
4099 * lpfc_static_vport_show: Read callback function for
4100 * lpfc_static_vport sysfs file.
4101 * @dev: Pointer to class device object.
4102 * @attr: device attribute structure.
4103 * @buf: Data buffer.
4104 *
4105 * This function is the read call back function for
4106 * lpfc_static_vport sysfs file. The lpfc_static_vport
4107 * sysfs file report the mageability of the vport.
4108 **/
4109static ssize_t
4110lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
4111 char *buf)
4112{
4113 struct Scsi_Host *shost = class_to_shost(dev);
4114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4115 if (vport->vport_flag & STATIC_VPORT)
4116 sprintf(buf, "1\n");
4117 else
4118 sprintf(buf, "0\n");
4119
4120 return strlen(buf);
4121}
4122
4123/*
4124 * Sysfs attribute to control the statistical data collection.
4125 */
Joe Perchesc828a892017-12-19 10:15:08 -08004126static DEVICE_ATTR_RO(lpfc_static_vport);
James Smartea2151b2008-09-07 11:52:10 -04004127
4128/**
James Smart3621a712009-04-06 18:47:14 -04004129 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04004130 * @dev: Pointer to class device.
4131 * @buf: Data buffer.
4132 * @count: Size of the data buffer.
4133 *
Masahiro Yamada9332ef92017-02-27 14:28:47 -08004134 * This function get called when a user write to the lpfc_stat_data_ctrl
James Smartea2151b2008-09-07 11:52:10 -04004135 * sysfs file. This function parse the command written to the sysfs file
4136 * and take appropriate action. These commands are used for controlling
4137 * driver statistical data collection.
4138 * Following are the command this function handles.
4139 *
4140 * setbucket <bucket_type> <base> <step>
4141 * = Set the latency buckets.
4142 * destroybucket = destroy all the buckets.
4143 * start = start data collection
4144 * stop = stop data collection
4145 * reset = reset the collected data
4146 **/
4147static ssize_t
4148lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
4149 const char *buf, size_t count)
4150{
4151 struct Scsi_Host *shost = class_to_shost(dev);
4152 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4153 struct lpfc_hba *phba = vport->phba;
4154#define LPFC_MAX_DATA_CTRL_LEN 1024
4155 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
4156 unsigned long i;
4157 char *str_ptr, *token;
4158 struct lpfc_vport **vports;
4159 struct Scsi_Host *v_shost;
4160 char *bucket_type_str, *base_str, *step_str;
4161 unsigned long base, step, bucket_type;
4162
4163 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04004164 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04004165 return -EINVAL;
4166
James Smarteb016562014-09-03 12:58:06 -04004167 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
James Smartea2151b2008-09-07 11:52:10 -04004168 str_ptr = &bucket_data[0];
4169 /* Ignore this token - this is command token */
4170 token = strsep(&str_ptr, "\t ");
4171 if (!token)
4172 return -EINVAL;
4173
4174 bucket_type_str = strsep(&str_ptr, "\t ");
4175 if (!bucket_type_str)
4176 return -EINVAL;
4177
4178 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
4179 bucket_type = LPFC_LINEAR_BUCKET;
4180 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
4181 bucket_type = LPFC_POWER2_BUCKET;
4182 else
4183 return -EINVAL;
4184
4185 base_str = strsep(&str_ptr, "\t ");
4186 if (!base_str)
4187 return -EINVAL;
4188 base = simple_strtoul(base_str, NULL, 0);
4189
4190 step_str = strsep(&str_ptr, "\t ");
4191 if (!step_str)
4192 return -EINVAL;
4193 step = simple_strtoul(step_str, NULL, 0);
4194 if (!step)
4195 return -EINVAL;
4196
4197 /* Block the data collection for every vport */
4198 vports = lpfc_create_vport_work_array(phba);
4199 if (vports == NULL)
4200 return -ENOMEM;
4201
James Smartf4b4c682009-05-22 14:53:12 -04004202 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04004203 v_shost = lpfc_shost_from_vport(vports[i]);
4204 spin_lock_irq(v_shost->host_lock);
4205 /* Block and reset data collection */
4206 vports[i]->stat_data_blocked = 1;
4207 if (vports[i]->stat_data_enabled)
4208 lpfc_vport_reset_stat_data(vports[i]);
4209 spin_unlock_irq(v_shost->host_lock);
4210 }
4211
4212 /* Set the bucket attributes */
4213 phba->bucket_type = bucket_type;
4214 phba->bucket_base = base;
4215 phba->bucket_step = step;
4216
James Smartf4b4c682009-05-22 14:53:12 -04004217 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04004218 v_shost = lpfc_shost_from_vport(vports[i]);
4219
4220 /* Unblock data collection */
4221 spin_lock_irq(v_shost->host_lock);
4222 vports[i]->stat_data_blocked = 0;
4223 spin_unlock_irq(v_shost->host_lock);
4224 }
4225 lpfc_destroy_vport_work_array(phba, vports);
4226 return strlen(buf);
4227 }
4228
4229 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
4230 vports = lpfc_create_vport_work_array(phba);
4231 if (vports == NULL)
4232 return -ENOMEM;
4233
James Smartf4b4c682009-05-22 14:53:12 -04004234 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04004235 v_shost = lpfc_shost_from_vport(vports[i]);
4236 spin_lock_irq(shost->host_lock);
4237 vports[i]->stat_data_blocked = 1;
4238 lpfc_free_bucket(vport);
4239 vport->stat_data_enabled = 0;
4240 vports[i]->stat_data_blocked = 0;
4241 spin_unlock_irq(shost->host_lock);
4242 }
4243 lpfc_destroy_vport_work_array(phba, vports);
4244 phba->bucket_type = LPFC_NO_BUCKET;
4245 phba->bucket_base = 0;
4246 phba->bucket_step = 0;
4247 return strlen(buf);
4248 }
4249
4250 if (!strncmp(buf, "start", strlen("start"))) {
4251 /* If no buckets configured return error */
4252 if (phba->bucket_type == LPFC_NO_BUCKET)
4253 return -EINVAL;
4254 spin_lock_irq(shost->host_lock);
4255 if (vport->stat_data_enabled) {
4256 spin_unlock_irq(shost->host_lock);
4257 return strlen(buf);
4258 }
4259 lpfc_alloc_bucket(vport);
4260 vport->stat_data_enabled = 1;
4261 spin_unlock_irq(shost->host_lock);
4262 return strlen(buf);
4263 }
4264
4265 if (!strncmp(buf, "stop", strlen("stop"))) {
4266 spin_lock_irq(shost->host_lock);
4267 if (vport->stat_data_enabled == 0) {
4268 spin_unlock_irq(shost->host_lock);
4269 return strlen(buf);
4270 }
4271 lpfc_free_bucket(vport);
4272 vport->stat_data_enabled = 0;
4273 spin_unlock_irq(shost->host_lock);
4274 return strlen(buf);
4275 }
4276
4277 if (!strncmp(buf, "reset", strlen("reset"))) {
4278 if ((phba->bucket_type == LPFC_NO_BUCKET)
4279 || !vport->stat_data_enabled)
4280 return strlen(buf);
4281 spin_lock_irq(shost->host_lock);
4282 vport->stat_data_blocked = 1;
4283 lpfc_vport_reset_stat_data(vport);
4284 vport->stat_data_blocked = 0;
4285 spin_unlock_irq(shost->host_lock);
4286 return strlen(buf);
4287 }
4288 return -EINVAL;
4289}
4290
4291
4292/**
James Smart3621a712009-04-06 18:47:14 -04004293 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04004294 * @dev: Pointer to class device object.
4295 * @buf: Data buffer.
4296 *
4297 * This function is the read call back function for
4298 * lpfc_stat_data_ctrl sysfs file. This function report the
4299 * current statistical data collection state.
4300 **/
4301static ssize_t
4302lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
4303 char *buf)
4304{
4305 struct Scsi_Host *shost = class_to_shost(dev);
4306 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4307 struct lpfc_hba *phba = vport->phba;
4308 int index = 0;
4309 int i;
4310 char *bucket_type;
4311 unsigned long bucket_value;
4312
4313 switch (phba->bucket_type) {
4314 case LPFC_LINEAR_BUCKET:
4315 bucket_type = "linear";
4316 break;
4317 case LPFC_POWER2_BUCKET:
4318 bucket_type = "power2";
4319 break;
4320 default:
4321 bucket_type = "No Bucket";
4322 break;
4323 }
4324
4325 sprintf(&buf[index], "Statistical Data enabled :%d, "
4326 "blocked :%d, Bucket type :%s, Bucket base :%d,"
4327 " Bucket step :%d\nLatency Ranges :",
4328 vport->stat_data_enabled, vport->stat_data_blocked,
4329 bucket_type, phba->bucket_base, phba->bucket_step);
4330 index = strlen(buf);
4331 if (phba->bucket_type != LPFC_NO_BUCKET) {
4332 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4333 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
4334 bucket_value = phba->bucket_base +
4335 phba->bucket_step * i;
4336 else
4337 bucket_value = phba->bucket_base +
4338 (1 << i) * phba->bucket_step;
4339
4340 if (index + 10 > PAGE_SIZE)
4341 break;
4342 sprintf(&buf[index], "%08ld ", bucket_value);
4343 index = strlen(buf);
4344 }
4345 }
4346 sprintf(&buf[index], "\n");
4347 return strlen(buf);
4348}
4349
4350/*
4351 * Sysfs attribute to control the statistical data collection.
4352 */
Joe Perchesb6b996b2017-12-19 10:15:07 -08004353static DEVICE_ATTR_RW(lpfc_stat_data_ctrl);
James Smartea2151b2008-09-07 11:52:10 -04004354
4355/*
4356 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
4357 */
4358
4359/*
4360 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
4361 * for each target.
4362 */
4363#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
4364#define MAX_STAT_DATA_SIZE_PER_TARGET \
4365 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
4366
4367
4368/**
James Smart3621a712009-04-06 18:47:14 -04004369 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07004370 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04004371 * @kobj: Pointer to the kernel object
4372 * @bin_attr: Attribute object
4373 * @buff: Buffer pointer
4374 * @off: File offset
4375 * @count: Buffer size
4376 *
4377 * This function is the read call back function for lpfc_drvr_stat_data
4378 * sysfs file. This function export the statistical data to user
4379 * applications.
4380 **/
4381static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004382sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
4383 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04004384 char *buf, loff_t off, size_t count)
4385{
4386 struct device *dev = container_of(kobj, struct device,
4387 kobj);
4388 struct Scsi_Host *shost = class_to_shost(dev);
4389 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4390 struct lpfc_hba *phba = vport->phba;
4391 int i = 0, index = 0;
4392 unsigned long nport_index;
4393 struct lpfc_nodelist *ndlp = NULL;
4394 nport_index = (unsigned long)off /
4395 MAX_STAT_DATA_SIZE_PER_TARGET;
4396
4397 if (!vport->stat_data_enabled || vport->stat_data_blocked
4398 || (phba->bucket_type == LPFC_NO_BUCKET))
4399 return 0;
4400
4401 spin_lock_irq(shost->host_lock);
4402 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4403 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
4404 continue;
4405
4406 if (nport_index > 0) {
4407 nport_index--;
4408 continue;
4409 }
4410
4411 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
4412 > count)
4413 break;
4414
4415 if (!ndlp->lat_data)
4416 continue;
4417
4418 /* Print the WWN */
4419 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
4420 ndlp->nlp_portname.u.wwn[0],
4421 ndlp->nlp_portname.u.wwn[1],
4422 ndlp->nlp_portname.u.wwn[2],
4423 ndlp->nlp_portname.u.wwn[3],
4424 ndlp->nlp_portname.u.wwn[4],
4425 ndlp->nlp_portname.u.wwn[5],
4426 ndlp->nlp_portname.u.wwn[6],
4427 ndlp->nlp_portname.u.wwn[7]);
4428
4429 index = strlen(buf);
4430
4431 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4432 sprintf(&buf[index], "%010u,",
4433 ndlp->lat_data[i].cmd_count);
4434 index = strlen(buf);
4435 }
4436 sprintf(&buf[index], "\n");
4437 index = strlen(buf);
4438 }
4439 spin_unlock_irq(shost->host_lock);
4440 return index;
4441}
4442
4443static struct bin_attribute sysfs_drvr_stat_data_attr = {
4444 .attr = {
4445 .name = "lpfc_drvr_stat_data",
4446 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04004447 },
4448 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
4449 .read = sysfs_drvr_stat_data_read,
4450 .write = NULL,
4451};
4452
dea31012005-04-17 16:05:31 -05004453/*
4454# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4455# connection.
James Smart76a95d72010-11-20 23:11:48 -05004456# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05004457*/
James Smarte59058c2008-08-24 21:49:00 -04004458/**
James Smart3621a712009-04-06 18:47:14 -04004459 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004460 * @phba: lpfc_hba pointer.
4461 * @val: link speed value.
4462 *
4463 * Description:
4464 * If val is in a valid range then set the adapter's link speed field and
4465 * issue a lip; if the lip fails reset the link speed to the old value.
4466 *
4467 * Notes:
4468 * If the value is not in range log a kernel error message and return an error.
4469 *
4470 * Returns:
4471 * zero if val is in range and lip okay.
4472 * non-zero return value from lpfc_issue_lip()
4473 * -EINVAL val out of range
4474 **/
James Smarta257bf92009-04-06 18:48:10 -04004475static ssize_t
4476lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4477 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05004478{
James Smarta257bf92009-04-06 18:48:10 -04004479 struct Scsi_Host *shost = class_to_shost(dev);
4480 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4481 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05004482 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04004483 int nolip = 0;
4484 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05004485 int err;
James Smartc6918162016-10-13 15:06:16 -07004486 uint32_t prev_val, if_type;
4487
4488 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart719162b2018-12-10 19:37:01 -08004489 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&
James Smartc6918162016-10-13 15:06:16 -07004490 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4491 return -EPERM;
James Smart83108bd2008-01-11 01:53:09 -05004492
James Smarta257bf92009-04-06 18:48:10 -04004493 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4494 nolip = 1;
4495 val_buf = &buf[strlen("nolip ")];
4496 }
4497
4498 if (!isdigit(val_buf[0]))
4499 return -EINVAL;
4500 if (sscanf(val_buf, "%i", &val) != 1)
4501 return -EINVAL;
4502
James Smart88a2cfb2011-07-22 18:36:33 -04004503 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4504 "3055 lpfc_link_speed changed from %d to %d %s\n",
4505 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4506
James Smart76a95d72010-11-20 23:11:48 -05004507 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4508 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4509 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4510 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4511 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
James Smartd38dd522015-08-31 16:48:17 -04004512 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
James Smartfbd8a6b2018-02-22 08:18:45 -08004513 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||
4514 ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {
James Smart76a95d72010-11-20 23:11:48 -05004515 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4516 "2879 lpfc_link_speed attribute cannot be set "
4517 "to %d. Speed is not supported by this port.\n",
4518 val);
James Smart83108bd2008-01-11 01:53:09 -05004519 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05004520 }
James Smartfbd8a6b2018-02-22 08:18:45 -08004521 if (val >= LPFC_USER_LINK_SPEED_16G &&
4522 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smartff78d8f2011-12-13 13:21:35 -05004523 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4524 "3112 lpfc_link_speed attribute cannot be set "
4525 "to %d. Speed is not supported in loop mode.\n",
4526 val);
4527 return -EINVAL;
4528 }
James Smartfbd8a6b2018-02-22 08:18:45 -08004529
4530 switch (val) {
4531 case LPFC_USER_LINK_SPEED_AUTO:
4532 case LPFC_USER_LINK_SPEED_1G:
4533 case LPFC_USER_LINK_SPEED_2G:
4534 case LPFC_USER_LINK_SPEED_4G:
4535 case LPFC_USER_LINK_SPEED_8G:
4536 case LPFC_USER_LINK_SPEED_16G:
4537 case LPFC_USER_LINK_SPEED_32G:
4538 case LPFC_USER_LINK_SPEED_64G:
James Smart83108bd2008-01-11 01:53:09 -05004539 prev_val = phba->cfg_link_speed;
4540 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04004541 if (nolip)
4542 return strlen(buf);
4543
James Smart83108bd2008-01-11 01:53:09 -05004544 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04004545 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05004546 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04004547 return -EINVAL;
James Smartfbd8a6b2018-02-22 08:18:45 -08004548 }
4549 return strlen(buf);
4550 default:
4551 break;
James Smart83108bd2008-01-11 01:53:09 -05004552 }
James Smartfbd8a6b2018-02-22 08:18:45 -08004553
James Smart83108bd2008-01-11 01:53:09 -05004554 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartfbd8a6b2018-02-22 08:18:45 -08004555 "0469 lpfc_link_speed attribute cannot be set to %d, "
4556 "allowed values are [%s]\n",
4557 val, LPFC_LINK_SPEED_STRING);
James Smart83108bd2008-01-11 01:53:09 -05004558 return -EINVAL;
James Smartfbd8a6b2018-02-22 08:18:45 -08004559
James Smart83108bd2008-01-11 01:53:09 -05004560}
4561
4562static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05004563module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05004564MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4565lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04004566
4567/**
James Smart3621a712009-04-06 18:47:14 -04004568 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004569 * @phba: lpfc_hba pointer.
4570 * @val: link speed value.
4571 *
4572 * Description:
4573 * If val is in a valid range then set the adapter's link speed field.
4574 *
4575 * Notes:
4576 * If the value is not in range log a kernel error message, clear the link
4577 * speed and return an error.
4578 *
4579 * Returns:
4580 * zero if val saved.
4581 * -EINVAL val out of range
4582 **/
James Smart83108bd2008-01-11 01:53:09 -05004583static int
4584lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4585{
James Smartfbd8a6b2018-02-22 08:18:45 -08004586 if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
James Smartff78d8f2011-12-13 13:21:35 -05004587 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4588 "3111 lpfc_link_speed of %d cannot "
4589 "support loop mode, setting topology to default.\n",
4590 val);
4591 phba->cfg_topology = 0;
4592 }
James Smartfbd8a6b2018-02-22 08:18:45 -08004593
4594 switch (val) {
4595 case LPFC_USER_LINK_SPEED_AUTO:
4596 case LPFC_USER_LINK_SPEED_1G:
4597 case LPFC_USER_LINK_SPEED_2G:
4598 case LPFC_USER_LINK_SPEED_4G:
4599 case LPFC_USER_LINK_SPEED_8G:
4600 case LPFC_USER_LINK_SPEED_16G:
4601 case LPFC_USER_LINK_SPEED_32G:
4602 case LPFC_USER_LINK_SPEED_64G:
James Smart83108bd2008-01-11 01:53:09 -05004603 phba->cfg_link_speed = val;
4604 return 0;
James Smartfbd8a6b2018-02-22 08:18:45 -08004605 default:
4606 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4607 "0405 lpfc_link_speed attribute cannot "
4608 "be set to %d, allowed values are "
4609 "["LPFC_LINK_SPEED_STRING"]\n", val);
4610 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4611 return -EINVAL;
James Smart83108bd2008-01-11 01:53:09 -05004612 }
James Smart83108bd2008-01-11 01:53:09 -05004613}
4614
Joe Perchesb6b996b2017-12-19 10:15:07 -08004615static DEVICE_ATTR_RW(lpfc_link_speed);
dea31012005-04-17 16:05:31 -05004616
4617/*
James Smart0d878412009-10-02 15:16:56 -04004618# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4619# 0 = aer disabled or not supported
4620# 1 = aer supported and enabled (default)
4621# Value range is [0,1]. Default value is 1.
4622*/
James Smart506139a2016-10-13 15:06:09 -07004623LPFC_ATTR(aer_support, 1, 0, 1,
4624 "Enable PCIe device AER support");
4625lpfc_param_show(aer_support)
James Smart0d878412009-10-02 15:16:56 -04004626
4627/**
4628 * lpfc_aer_support_store - Set the adapter for aer support
4629 *
4630 * @dev: class device that is converted into a Scsi_host.
4631 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004632 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04004633 * @count: unused variable.
4634 *
4635 * Description:
4636 * If the val is 1 and currently the device's AER capability was not
4637 * enabled, invoke the kernel's enable AER helper routine, trying to
4638 * enable the device's AER capability. If the helper routine enabling
4639 * AER returns success, update the device's cfg_aer_support flag to
4640 * indicate AER is supported by the device; otherwise, if the device
4641 * AER capability is already enabled to support AER, then do nothing.
4642 *
4643 * If the val is 0 and currently the device's AER support was enabled,
4644 * invoke the kernel's disable AER helper routine. After that, update
4645 * the device's cfg_aer_support flag to indicate AER is not supported
4646 * by the device; otherwise, if the device AER capability is already
4647 * disabled from supporting AER, then do nothing.
4648 *
4649 * Returns:
4650 * length of the buf on success if val is in range the intended mode
4651 * is supported.
4652 * -EINVAL if val out of range or intended mode is not supported.
4653 **/
4654static ssize_t
4655lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4656 const char *buf, size_t count)
4657{
4658 struct Scsi_Host *shost = class_to_shost(dev);
4659 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4660 struct lpfc_hba *phba = vport->phba;
4661 int val = 0, rc = -EINVAL;
4662
4663 if (!isdigit(buf[0]))
4664 return -EINVAL;
4665 if (sscanf(buf, "%i", &val) != 1)
4666 return -EINVAL;
4667
4668 switch (val) {
4669 case 0:
4670 if (phba->hba_flag & HBA_AER_ENABLED) {
4671 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4672 if (!rc) {
4673 spin_lock_irq(&phba->hbalock);
4674 phba->hba_flag &= ~HBA_AER_ENABLED;
4675 spin_unlock_irq(&phba->hbalock);
4676 phba->cfg_aer_support = 0;
4677 rc = strlen(buf);
4678 } else
James Smart891478a2009-11-18 15:40:23 -05004679 rc = -EPERM;
4680 } else {
James Smart0d878412009-10-02 15:16:56 -04004681 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05004682 rc = strlen(buf);
4683 }
James Smart0d878412009-10-02 15:16:56 -04004684 break;
4685 case 1:
4686 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4687 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4688 if (!rc) {
4689 spin_lock_irq(&phba->hbalock);
4690 phba->hba_flag |= HBA_AER_ENABLED;
4691 spin_unlock_irq(&phba->hbalock);
4692 phba->cfg_aer_support = 1;
4693 rc = strlen(buf);
4694 } else
James Smart891478a2009-11-18 15:40:23 -05004695 rc = -EPERM;
4696 } else {
James Smart0d878412009-10-02 15:16:56 -04004697 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05004698 rc = strlen(buf);
4699 }
James Smart0d878412009-10-02 15:16:56 -04004700 break;
4701 default:
4702 rc = -EINVAL;
4703 break;
4704 }
4705 return rc;
4706}
4707
Joe Perchesb6b996b2017-12-19 10:15:07 -08004708static DEVICE_ATTR_RW(lpfc_aer_support);
James Smart0d878412009-10-02 15:16:56 -04004709
4710/**
4711 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4712 * @dev: class device that is converted into a Scsi_host.
4713 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004714 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04004715 * @count: unused variable.
4716 *
4717 * Description:
4718 * If the @buf contains 1 and the device currently has the AER support
4719 * enabled, then invokes the kernel AER helper routine
Kuppuswamy Sathyanarayanan894020f2020-03-23 17:26:08 -07004720 * pci_aer_clear_nonfatal_status() to clean up the uncorrectable
James Smart0d878412009-10-02 15:16:56 -04004721 * error status register.
4722 *
4723 * Notes:
4724 *
4725 * Returns:
4726 * -EINVAL if the buf does not contain the 1 or the device is not currently
4727 * enabled with the AER support.
4728 **/
4729static ssize_t
4730lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4731 const char *buf, size_t count)
4732{
4733 struct Scsi_Host *shost = class_to_shost(dev);
4734 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4735 struct lpfc_hba *phba = vport->phba;
4736 int val, rc = -1;
4737
4738 if (!isdigit(buf[0]))
4739 return -EINVAL;
4740 if (sscanf(buf, "%i", &val) != 1)
4741 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05004742 if (val != 1)
4743 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04004744
James Smart891478a2009-11-18 15:40:23 -05004745 if (phba->hba_flag & HBA_AER_ENABLED)
Kuppuswamy Sathyanarayanan894020f2020-03-23 17:26:08 -07004746 rc = pci_aer_clear_nonfatal_status(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -04004747
4748 if (rc == 0)
4749 return strlen(buf);
4750 else
James Smart891478a2009-11-18 15:40:23 -05004751 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04004752}
4753
4754static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4755 lpfc_aer_cleanup_state);
4756
James Smart912e3ac2011-05-24 11:42:11 -04004757/**
4758 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4759 *
4760 * @dev: class device that is converted into a Scsi_host.
4761 * @attr: device attribute, not used.
4762 * @buf: containing the string the number of vfs to be enabled.
4763 * @count: unused variable.
4764 *
4765 * Description:
4766 * When this api is called either through user sysfs, the driver shall
4767 * try to enable or disable SR-IOV virtual functions according to the
4768 * following:
4769 *
4770 * If zero virtual function has been enabled to the physical function,
4771 * the driver shall invoke the pci enable virtual function api trying
4772 * to enable the virtual functions. If the nr_vfn provided is greater
4773 * than the maximum supported, the maximum virtual function number will
4774 * be used for invoking the api; otherwise, the nr_vfn provided shall
4775 * be used for invoking the api. If the api call returned success, the
4776 * actual number of virtual functions enabled will be set to the driver
4777 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4778 * cfg_sriov_nr_virtfn remains zero.
4779 *
4780 * If none-zero virtual functions have already been enabled to the
4781 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4782 * -EINVAL will be returned and the driver does nothing;
4783 *
4784 * If the nr_vfn provided is zero and none-zero virtual functions have
4785 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4786 * disabling virtual function api shall be invoded to disable all the
4787 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4788 * zero. Otherwise, if zero virtual function has been enabled, do
4789 * nothing.
4790 *
4791 * Returns:
4792 * length of the buf on success if val is in range the intended mode
4793 * is supported.
4794 * -EINVAL if val out of range or intended mode is not supported.
4795 **/
4796static ssize_t
4797lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4798 const char *buf, size_t count)
4799{
4800 struct Scsi_Host *shost = class_to_shost(dev);
4801 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4802 struct lpfc_hba *phba = vport->phba;
4803 struct pci_dev *pdev = phba->pcidev;
4804 int val = 0, rc = -EINVAL;
4805
4806 /* Sanity check on user data */
4807 if (!isdigit(buf[0]))
4808 return -EINVAL;
4809 if (sscanf(buf, "%i", &val) != 1)
4810 return -EINVAL;
4811 if (val < 0)
4812 return -EINVAL;
4813
4814 /* Request disabling virtual functions */
4815 if (val == 0) {
4816 if (phba->cfg_sriov_nr_virtfn > 0) {
4817 pci_disable_sriov(pdev);
4818 phba->cfg_sriov_nr_virtfn = 0;
4819 }
4820 return strlen(buf);
4821 }
4822
4823 /* Request enabling virtual functions */
4824 if (phba->cfg_sriov_nr_virtfn > 0) {
4825 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4826 "3018 There are %d virtual functions "
4827 "enabled on physical function.\n",
4828 phba->cfg_sriov_nr_virtfn);
4829 return -EEXIST;
4830 }
4831
4832 if (val <= LPFC_MAX_VFN_PER_PFN)
4833 phba->cfg_sriov_nr_virtfn = val;
4834 else {
4835 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4836 "3019 Enabling %d virtual functions is not "
4837 "allowed.\n", val);
4838 return -EINVAL;
4839 }
4840
4841 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4842 if (rc) {
4843 phba->cfg_sriov_nr_virtfn = 0;
4844 rc = -EPERM;
4845 } else
4846 rc = strlen(buf);
4847
4848 return rc;
4849}
4850
James Smart0cfbbf22016-10-13 15:06:12 -07004851LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4852 "Enable PCIe device SR-IOV virtual fn");
4853
James Smart912e3ac2011-05-24 11:42:11 -04004854lpfc_param_show(sriov_nr_virtfn)
Joe Perchesb6b996b2017-12-19 10:15:07 -08004855static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04004856
James Smart173edbb2012-06-12 13:54:50 -04004857/**
James Smartc71ab862012-10-31 14:44:33 -04004858 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4859 *
4860 * @dev: class device that is converted into a Scsi_host.
4861 * @attr: device attribute, not used.
4862 * @buf: containing the string the number of vfs to be enabled.
4863 * @count: unused variable.
4864 *
4865 * Description:
4866 *
4867 * Returns:
4868 * length of the buf on success if val is in range the intended mode
4869 * is supported.
4870 * -EINVAL if val out of range or intended mode is not supported.
4871 **/
4872static ssize_t
4873lpfc_request_firmware_upgrade_store(struct device *dev,
4874 struct device_attribute *attr,
4875 const char *buf, size_t count)
4876{
4877 struct Scsi_Host *shost = class_to_shost(dev);
4878 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4879 struct lpfc_hba *phba = vport->phba;
4880 int val = 0, rc = -EINVAL;
4881
4882 /* Sanity check on user data */
4883 if (!isdigit(buf[0]))
4884 return -EINVAL;
4885 if (sscanf(buf, "%i", &val) != 1)
4886 return -EINVAL;
4887 if (val != 1)
4888 return -EINVAL;
4889
4890 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4891 if (rc)
4892 rc = -EPERM;
4893 else
4894 rc = strlen(buf);
4895 return rc;
4896}
4897
4898static int lpfc_req_fw_upgrade;
4899module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4900MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4901lpfc_param_show(request_firmware_upgrade)
4902
4903/**
4904 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4905 * @phba: lpfc_hba pointer.
4906 * @val: 0 or 1.
4907 *
4908 * Description:
4909 * Set the initial Linux generic firmware upgrade enable or disable flag.
4910 *
4911 * Returns:
4912 * zero if val saved.
4913 * -EINVAL val out of range
4914 **/
4915static int
4916lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4917{
4918 if (val >= 0 && val <= 1) {
4919 phba->cfg_request_firmware_upgrade = val;
4920 return 0;
4921 }
4922 return -EINVAL;
4923}
4924static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4925 lpfc_request_firmware_upgrade_show,
4926 lpfc_request_firmware_upgrade_store);
4927
4928/**
James Smart41b194b2019-05-14 14:58:08 -07004929 * lpfc_force_rscn_store
4930 *
4931 * @dev: class device that is converted into a Scsi_host.
4932 * @attr: device attribute, not used.
4933 * @buf: unused string
4934 * @count: unused variable.
4935 *
4936 * Description:
4937 * Force the switch to send a RSCN to all other NPorts in our zone
4938 * If we are direct connect pt2pt, build the RSCN command ourself
4939 * and send to the other NPort. Not supported for private loop.
4940 *
4941 * Returns:
4942 * 0 - on success
4943 * -EIO - if command is not sent
4944 **/
4945static ssize_t
4946lpfc_force_rscn_store(struct device *dev, struct device_attribute *attr,
4947 const char *buf, size_t count)
4948{
4949 struct Scsi_Host *shost = class_to_shost(dev);
4950 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4951 int i;
4952
4953 i = lpfc_issue_els_rscn(vport, 0);
4954 if (i)
4955 return -EIO;
4956 return strlen(buf);
4957}
4958
4959/*
4960 * lpfc_force_rscn: Force an RSCN to be sent to all remote NPorts
4961 * connected to the HBA.
4962 *
4963 * Value range is any ascii value
4964 */
4965static int lpfc_force_rscn;
4966module_param(lpfc_force_rscn, int, 0644);
4967MODULE_PARM_DESC(lpfc_force_rscn,
4968 "Force an RSCN to be sent to all remote NPorts");
4969lpfc_param_show(force_rscn)
4970
4971/**
4972 * lpfc_force_rscn_init - Force an RSCN to be sent to all remote NPorts
4973 * @phba: lpfc_hba pointer.
4974 * @val: unused value.
4975 *
4976 * Returns:
4977 * zero if val saved.
4978 **/
4979static int
4980lpfc_force_rscn_init(struct lpfc_hba *phba, int val)
4981{
4982 return 0;
4983}
4984static DEVICE_ATTR_RW(lpfc_force_rscn);
4985
4986/**
James Smart173edbb2012-06-12 13:54:50 -04004987 * lpfc_fcp_imax_store
4988 *
4989 * @dev: class device that is converted into a Scsi_host.
4990 * @attr: device attribute, not used.
4991 * @buf: string with the number of fast-path FCP interrupts per second.
4992 * @count: unused variable.
4993 *
4994 * Description:
4995 * If val is in a valid range [636,651042], then set the adapter's
4996 * maximum number of fast-path FCP interrupts per second.
4997 *
4998 * Returns:
4999 * length of the buf on success if val is in range the intended mode
5000 * is supported.
5001 * -EINVAL if val out of range or intended mode is not supported.
5002 **/
5003static ssize_t
5004lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
5005 const char *buf, size_t count)
5006{
5007 struct Scsi_Host *shost = class_to_shost(dev);
5008 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5009 struct lpfc_hba *phba = vport->phba;
James Smart32517fc2019-01-28 11:14:33 -08005010 struct lpfc_eq_intr_info *eqi;
James Smartcb733e32019-01-28 11:14:32 -08005011 uint32_t usdelay;
James Smart173edbb2012-06-12 13:54:50 -04005012 int val = 0, i;
5013
James Smartbf8dae82012-08-03 12:36:24 -04005014 /* fcp_imax is only valid for SLI4 */
5015 if (phba->sli_rev != LPFC_SLI_REV4)
5016 return -EINVAL;
5017
James Smart173edbb2012-06-12 13:54:50 -04005018 /* Sanity check on user data */
5019 if (!isdigit(buf[0]))
5020 return -EINVAL;
5021 if (sscanf(buf, "%i", &val) != 1)
5022 return -EINVAL;
5023
James Smartbf8dae82012-08-03 12:36:24 -04005024 /*
5025 * Value range for the HBA is [5000,5000000]
5026 * The value for each EQ depends on how many EQs are configured.
James Smart895427b2017-02-12 13:52:30 -08005027 * Allow value == 0
James Smartbf8dae82012-08-03 12:36:24 -04005028 */
James Smart895427b2017-02-12 13:52:30 -08005029 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
James Smart173edbb2012-06-12 13:54:50 -04005030 return -EINVAL;
5031
James Smart32517fc2019-01-28 11:14:33 -08005032 phba->cfg_auto_imax = (val) ? 0 : 1;
5033 if (phba->cfg_fcp_imax && !val) {
5034 queue_delayed_work(phba->wq, &phba->eq_delay_work,
5035 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
5036
5037 for_each_present_cpu(i) {
5038 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
5039 eqi->icnt = 0;
5040 }
5041 }
5042
James Smart173edbb2012-06-12 13:54:50 -04005043 phba->cfg_fcp_imax = (uint32_t)val;
James Smart43140ca2017-03-04 09:30:34 -08005044
James Smartcb733e32019-01-28 11:14:32 -08005045 if (phba->cfg_fcp_imax)
5046 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
5047 else
5048 usdelay = 0;
5049
James Smart6a828b02019-01-28 11:14:31 -08005050 for (i = 0; i < phba->cfg_irq_chann; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart0cf07f842017-06-01 21:07:10 -07005051 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
James Smartcb733e32019-01-28 11:14:32 -08005052 usdelay);
James Smart173edbb2012-06-12 13:54:50 -04005053
5054 return strlen(buf);
5055}
5056
5057/*
5058# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04005059# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04005060#
James Smartbf8dae82012-08-03 12:36:24 -04005061# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04005062*/
James Smartbf8dae82012-08-03 12:36:24 -04005063static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04005064module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
5065MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04005066 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04005067lpfc_param_show(fcp_imax)
5068
5069/**
5070 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
5071 * @phba: lpfc_hba pointer.
5072 * @val: link speed value.
5073 *
5074 * Description:
5075 * If val is in a valid range [636,651042], then initialize the adapter's
5076 * maximum number of fast-path FCP interrupts per second.
5077 *
5078 * Returns:
5079 * zero if val saved.
5080 * -EINVAL val out of range
5081 **/
5082static int
5083lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
5084{
James Smartbf8dae82012-08-03 12:36:24 -04005085 if (phba->sli_rev != LPFC_SLI_REV4) {
5086 phba->cfg_fcp_imax = 0;
5087 return 0;
5088 }
5089
James Smart895427b2017-02-12 13:52:30 -08005090 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
5091 (val == 0)) {
James Smart173edbb2012-06-12 13:54:50 -04005092 phba->cfg_fcp_imax = val;
5093 return 0;
5094 }
5095
5096 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07005097 "3016 lpfc_fcp_imax: %d out of range, using default\n",
5098 val);
James Smartbf8dae82012-08-03 12:36:24 -04005099 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04005100
5101 return 0;
5102}
5103
Joe Perchesb6b996b2017-12-19 10:15:07 -08005104static DEVICE_ATTR_RW(lpfc_fcp_imax);
James Smart173edbb2012-06-12 13:54:50 -04005105
James Smart32517fc2019-01-28 11:14:33 -08005106/**
5107 * lpfc_cq_max_proc_limit_store
5108 *
5109 * @dev: class device that is converted into a Scsi_host.
5110 * @attr: device attribute, not used.
5111 * @buf: string with the cq max processing limit of cqes
5112 * @count: unused variable.
5113 *
5114 * Description:
5115 * If val is in a valid range, then set value on each cq
5116 *
5117 * Returns:
5118 * The length of the buf: if successful
5119 * -ERANGE: if val is not in the valid range
5120 * -EINVAL: if bad value format or intended mode is not supported.
5121 **/
5122static ssize_t
5123lpfc_cq_max_proc_limit_store(struct device *dev, struct device_attribute *attr,
5124 const char *buf, size_t count)
5125{
5126 struct Scsi_Host *shost = class_to_shost(dev);
5127 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5128 struct lpfc_hba *phba = vport->phba;
5129 struct lpfc_queue *eq, *cq;
5130 unsigned long val;
5131 int i;
5132
5133 /* cq_max_proc_limit is only valid for SLI4 */
5134 if (phba->sli_rev != LPFC_SLI_REV4)
5135 return -EINVAL;
5136
5137 /* Sanity check on user data */
5138 if (!isdigit(buf[0]))
5139 return -EINVAL;
5140 if (kstrtoul(buf, 0, &val))
5141 return -EINVAL;
5142
5143 if (val < LPFC_CQ_MIN_PROC_LIMIT || val > LPFC_CQ_MAX_PROC_LIMIT)
5144 return -ERANGE;
5145
5146 phba->cfg_cq_max_proc_limit = (uint32_t)val;
5147
5148 /* set the values on the cq's */
5149 for (i = 0; i < phba->cfg_irq_chann; i++) {
James Smart657add42019-05-21 17:49:06 -07005150 /* Get the EQ corresponding to the IRQ vector */
5151 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
James Smart32517fc2019-01-28 11:14:33 -08005152 if (!eq)
5153 continue;
5154
5155 list_for_each_entry(cq, &eq->child_list, list)
5156 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
5157 cq->entry_count);
5158 }
5159
5160 return strlen(buf);
5161}
5162
James Smart0cf07f842017-06-01 21:07:10 -07005163/*
James Smart32517fc2019-01-28 11:14:33 -08005164 * lpfc_cq_max_proc_limit: The maximum number CQE entries processed in an
5165 * itteration of CQ processing.
James Smart0cf07f842017-06-01 21:07:10 -07005166 */
James Smart32517fc2019-01-28 11:14:33 -08005167static int lpfc_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
5168module_param(lpfc_cq_max_proc_limit, int, 0644);
5169MODULE_PARM_DESC(lpfc_cq_max_proc_limit,
5170 "Set the maximum number CQEs processed in an iteration of "
5171 "CQ processing");
5172lpfc_param_show(cq_max_proc_limit)
5173
5174/*
5175 * lpfc_cq_poll_threshold: Set the threshold of CQE completions in a
5176 * single handler call which should request a polled completion rather
5177 * than re-enabling interrupts.
5178 */
5179LPFC_ATTR_RW(cq_poll_threshold, LPFC_CQ_DEF_THRESHOLD_TO_POLL,
5180 LPFC_CQ_MIN_THRESHOLD_TO_POLL,
5181 LPFC_CQ_MAX_THRESHOLD_TO_POLL,
5182 "CQE Processing Threshold to enable Polling");
5183
5184/**
5185 * lpfc_cq_max_proc_limit_init - Set the initial cq max_proc_limit
5186 * @phba: lpfc_hba pointer.
5187 * @val: entry limit
5188 *
5189 * Description:
5190 * If val is in a valid range, then initialize the adapter's maximum
5191 * value.
5192 *
5193 * Returns:
5194 * Always returns 0 for success, even if value not always set to
5195 * requested value. If value out of range or not supported, will fall
5196 * back to default.
5197 **/
5198static int
5199lpfc_cq_max_proc_limit_init(struct lpfc_hba *phba, int val)
5200{
5201 phba->cfg_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
5202
5203 if (phba->sli_rev != LPFC_SLI_REV4)
5204 return 0;
5205
5206 if (val >= LPFC_CQ_MIN_PROC_LIMIT && val <= LPFC_CQ_MAX_PROC_LIMIT) {
5207 phba->cfg_cq_max_proc_limit = val;
5208 return 0;
5209 }
5210
5211 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5212 "0371 "LPFC_DRIVER_NAME"_cq_max_proc_limit: "
5213 "%d out of range, using default\n",
5214 phba->cfg_cq_max_proc_limit);
5215
5216 return 0;
5217}
5218
5219static DEVICE_ATTR_RW(lpfc_cq_max_proc_limit);
James Smart0cf07f842017-06-01 21:07:10 -07005220
James Smart7bb03bb2013-04-17 20:19:16 -04005221/**
5222 * lpfc_state_show - Display current driver CPU affinity
5223 * @dev: class converted to a Scsi_host structure.
5224 * @attr: device attribute, not used.
5225 * @buf: on return contains text describing the state of the link.
5226 *
5227 * Returns: size of formatted string.
5228 **/
5229static ssize_t
5230lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
5231 char *buf)
5232{
5233 struct Scsi_Host *shost = class_to_shost(dev);
5234 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5235 struct lpfc_hba *phba = vport->phba;
5236 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05005237 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04005238
5239 if ((phba->sli_rev != LPFC_SLI_REV4) ||
5240 (phba->intr_type != MSIX))
5241 return len;
5242
5243 switch (phba->cfg_fcp_cpu_map) {
5244 case 0:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005245 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart7bb03bb2013-04-17 20:19:16 -04005246 "fcp_cpu_map: No mapping (%d)\n",
5247 phba->cfg_fcp_cpu_map);
5248 return len;
5249 case 1:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005250 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart7bb03bb2013-04-17 20:19:16 -04005251 "fcp_cpu_map: HBA centric mapping (%d): "
James Smart222e9232019-01-28 11:14:35 -08005252 "%d of %d CPUs online from %d possible CPUs\n",
5253 phba->cfg_fcp_cpu_map, num_online_cpus(),
5254 num_present_cpus(),
5255 phba->sli4_hba.num_possible_cpu);
James Smart7bb03bb2013-04-17 20:19:16 -04005256 break;
James Smart7bb03bb2013-04-17 20:19:16 -04005257 }
5258
James Smart222e9232019-01-28 11:14:35 -08005259 while (phba->sli4_hba.curr_disp_cpu <
5260 phba->sli4_hba.num_possible_cpu) {
James Smart76fd07a2014-02-20 09:57:18 -05005261 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
5262
James Smart222e9232019-01-28 11:14:35 -08005263 if (!cpu_present(phba->sli4_hba.curr_disp_cpu))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005264 len += scnprintf(buf + len, PAGE_SIZE - len,
James Smart222e9232019-01-28 11:14:35 -08005265 "CPU %02d not present\n",
5266 phba->sli4_hba.curr_disp_cpu);
James Smartdcaa2132019-11-04 16:57:06 -08005267 else if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
James Smartb3295c22019-01-28 11:14:30 -08005268 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005269 len += scnprintf(
James Smartb3295c22019-01-28 11:14:30 -08005270 buf + len, PAGE_SIZE - len,
5271 "CPU %02d hdwq None "
James Smartd9954a22019-05-21 17:49:05 -07005272 "physid %d coreid %d ht %d ua %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05005273 phba->sli4_hba.curr_disp_cpu,
James Smartd9954a22019-05-21 17:49:05 -07005274 cpup->phys_id, cpup->core_id,
5275 (cpup->flag & LPFC_CPU_MAP_HYPER),
5276 (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
James Smartb3295c22019-01-28 11:14:30 -08005277 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005278 len += scnprintf(
James Smartb3295c22019-01-28 11:14:30 -08005279 buf + len, PAGE_SIZE - len,
James Smartdcaa2132019-11-04 16:57:06 -08005280 "CPU %02d EQ None hdwq %04d "
James Smartd9954a22019-05-21 17:49:05 -07005281 "physid %d coreid %d ht %d ua %d\n",
James Smartb3295c22019-01-28 11:14:30 -08005282 phba->sli4_hba.curr_disp_cpu,
James Smartdcaa2132019-11-04 16:57:06 -08005283 cpup->hdwq, cpup->phys_id,
James Smartd9954a22019-05-21 17:49:05 -07005284 cpup->core_id,
5285 (cpup->flag & LPFC_CPU_MAP_HYPER),
5286 (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
James Smartb3295c22019-01-28 11:14:30 -08005287 } else {
5288 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005289 len += scnprintf(
James Smartb3295c22019-01-28 11:14:30 -08005290 buf + len, PAGE_SIZE - len,
5291 "CPU %02d hdwq None "
James Smartd9954a22019-05-21 17:49:05 -07005292 "physid %d coreid %d ht %d ua %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05005293 phba->sli4_hba.curr_disp_cpu,
James Smartb3295c22019-01-28 11:14:30 -08005294 cpup->phys_id,
James Smartd9954a22019-05-21 17:49:05 -07005295 cpup->core_id,
5296 (cpup->flag & LPFC_CPU_MAP_HYPER),
5297 (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
James Smartdcaa2132019-11-04 16:57:06 -08005298 lpfc_get_irq(cpup->eq));
James Smartb3295c22019-01-28 11:14:30 -08005299 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005300 len += scnprintf(
James Smartb3295c22019-01-28 11:14:30 -08005301 buf + len, PAGE_SIZE - len,
James Smart6a828b02019-01-28 11:14:31 -08005302 "CPU %02d EQ %04d hdwq %04d "
James Smartd9954a22019-05-21 17:49:05 -07005303 "physid %d coreid %d ht %d ua %d IRQ %d\n",
James Smartb3295c22019-01-28 11:14:30 -08005304 phba->sli4_hba.curr_disp_cpu,
James Smart6a828b02019-01-28 11:14:31 -08005305 cpup->eq, cpup->hdwq, cpup->phys_id,
James Smartd9954a22019-05-21 17:49:05 -07005306 cpup->core_id,
5307 (cpup->flag & LPFC_CPU_MAP_HYPER),
5308 (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
James Smartdcaa2132019-11-04 16:57:06 -08005309 lpfc_get_irq(cpup->eq));
James Smartb3295c22019-01-28 11:14:30 -08005310 }
James Smart7bb03bb2013-04-17 20:19:16 -04005311
James Smart76fd07a2014-02-20 09:57:18 -05005312 phba->sli4_hba.curr_disp_cpu++;
5313
5314 /* display max number of CPUs keeping some margin */
5315 if (phba->sli4_hba.curr_disp_cpu <
James Smart222e9232019-01-28 11:14:35 -08005316 phba->sli4_hba.num_possible_cpu &&
James Smart76fd07a2014-02-20 09:57:18 -05005317 (len >= (PAGE_SIZE - 64))) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005318 len += scnprintf(buf + len,
James Smart222e9232019-01-28 11:14:35 -08005319 PAGE_SIZE - len, "more...\n");
James Smart76fd07a2014-02-20 09:57:18 -05005320 break;
5321 }
James Smart7bb03bb2013-04-17 20:19:16 -04005322 }
James Smart76fd07a2014-02-20 09:57:18 -05005323
James Smart222e9232019-01-28 11:14:35 -08005324 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_possible_cpu)
James Smart76fd07a2014-02-20 09:57:18 -05005325 phba->sli4_hba.curr_disp_cpu = 0;
5326
James Smart7bb03bb2013-04-17 20:19:16 -04005327 return len;
5328}
5329
5330/**
5331 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
5332 * @dev: class device that is converted into a Scsi_host.
5333 * @attr: device attribute, not used.
5334 * @buf: one or more lpfc_polling_flags values.
5335 * @count: not used.
5336 *
5337 * Returns:
5338 * -EINVAL - Not implemented yet.
5339 **/
5340static ssize_t
5341lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
5342 const char *buf, size_t count)
5343{
5344 int status = -EINVAL;
5345 return status;
5346}
5347
5348/*
5349# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
5350# for the HBA.
5351#
James Smart6a828b02019-01-28 11:14:31 -08005352# Value range is [0 to 1]. Default value is LPFC_HBA_CPU_MAP (1).
James Smart7bb03bb2013-04-17 20:19:16 -04005353# 0 - Do not affinitze IRQ vectors
5354# 1 - Affintize HBA vectors with respect to each HBA
5355# (start with CPU0 for each HBA)
James Smart6a828b02019-01-28 11:14:31 -08005356# This also defines how Hardware Queues are mapped to specific CPUs.
James Smart7bb03bb2013-04-17 20:19:16 -04005357*/
James Smart6a828b02019-01-28 11:14:31 -08005358static int lpfc_fcp_cpu_map = LPFC_HBA_CPU_MAP;
James Smart7bb03bb2013-04-17 20:19:16 -04005359module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
5360MODULE_PARM_DESC(lpfc_fcp_cpu_map,
5361 "Defines how to map CPUs to IRQ vectors per HBA");
5362
5363/**
5364 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
5365 * @phba: lpfc_hba pointer.
5366 * @val: link speed value.
5367 *
5368 * Description:
5369 * If val is in a valid range [0-2], then affinitze the adapter's
5370 * MSIX vectors.
5371 *
5372 * Returns:
5373 * zero if val saved.
5374 * -EINVAL val out of range
5375 **/
5376static int
5377lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
5378{
5379 if (phba->sli_rev != LPFC_SLI_REV4) {
5380 phba->cfg_fcp_cpu_map = 0;
5381 return 0;
5382 }
5383
5384 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
5385 phba->cfg_fcp_cpu_map = val;
5386 return 0;
5387 }
5388
5389 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07005390 "3326 lpfc_fcp_cpu_map: %d out of range, using "
5391 "default\n", val);
James Smart6a828b02019-01-28 11:14:31 -08005392 phba->cfg_fcp_cpu_map = LPFC_HBA_CPU_MAP;
James Smart7bb03bb2013-04-17 20:19:16 -04005393
5394 return 0;
5395}
5396
Joe Perchesb6b996b2017-12-19 10:15:07 -08005397static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
James Smart7bb03bb2013-04-17 20:19:16 -04005398
James Smart0d878412009-10-02 15:16:56 -04005399/*
dea31012005-04-17 16:05:31 -05005400# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
5401# Value range is [2,3]. Default value is 3.
5402*/
James Smart3de2a652007-08-02 11:09:59 -04005403LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
5404 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05005405
5406/*
5407# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
5408# is [0,1]. Default value is 0.
5409*/
James Smart3de2a652007-08-02 11:09:59 -04005410LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
5411 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05005412
5413/*
James Smart3cb01c52013-07-15 18:35:04 -04005414# lpfc_first_burst_size: First burst size to use on the NPorts
5415# that support first burst.
5416# Value range is [0,65536]. Default value is 0.
5417*/
5418LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
5419 "First burst size for Targets that support first burst");
5420
5421/*
James Smart2d7dbc42017-02-12 13:52:35 -08005422* lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
5423* When the driver is configured as an NVME target, this value is
5424* communicated to the NVME initiator in the PRLI response. It is
5425* used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
5426* parameters are set and the target is sending the PRLI RSP.
James Smart895427b2017-02-12 13:52:30 -08005427* Parameter supported on physical port only - no NPIV support.
James Smart2d7dbc42017-02-12 13:52:35 -08005428* Value range is [0,65536]. Default value is 0.
James Smart895427b2017-02-12 13:52:30 -08005429*/
James Smart2d7dbc42017-02-12 13:52:35 -08005430LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
5431 "NVME Target mode first burst size in 512B increments.");
5432
5433/*
5434 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
5435 * For the Initiator (I), enabling this parameter means that an NVMET
5436 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
James Smartdb197bc2019-08-14 16:57:03 -07005437 * processed by the initiator for subsequent NVME FCP IO.
5438 * Currently, this feature is not supported on the NVME target
James Smart2d7dbc42017-02-12 13:52:35 -08005439 * Value range is [0,1]. Default value is 0 (disabled).
5440 */
James Smart895427b2017-02-12 13:52:30 -08005441LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
James Smartdb197bc2019-08-14 16:57:03 -07005442 "Enable First Burst feature for NVME Initiator.");
James Smart895427b2017-02-12 13:52:30 -08005443
5444/*
James Smart977b5a02008-09-07 11:52:04 -04005445# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
5446# depth. Default value is 0. When the value of this parameter is zero the
5447# SCSI command completion time is not used for controlling I/O queue depth. When
5448# the parameter is set to a non-zero value, the I/O queue depth is controlled
5449# to limit the I/O completion time to the parameter value.
5450# The value is set in milliseconds.
5451*/
James Smarted5b1522016-10-13 15:06:11 -07005452LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
James Smart977b5a02008-09-07 11:52:04 -04005453 "Use command completion time to control queue depth");
James Smarted5b1522016-10-13 15:06:11 -07005454
James Smart977b5a02008-09-07 11:52:04 -04005455lpfc_vport_param_show(max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04005456static int
5457lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
5458{
5459 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5460 struct lpfc_nodelist *ndlp, *next_ndlp;
5461
5462 if (val == vport->cfg_max_scsicmpl_time)
5463 return 0;
5464 if ((val < 0) || (val > 60000))
5465 return -EINVAL;
5466 vport->cfg_max_scsicmpl_time = val;
5467
5468 spin_lock_irq(shost->host_lock);
5469 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5470 if (!NLP_CHK_NODE_ACT(ndlp))
5471 continue;
5472 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
5473 continue;
James Smart7dc517d2010-07-14 15:32:10 -04005474 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04005475 }
5476 spin_unlock_irq(shost->host_lock);
5477 return 0;
5478}
5479lpfc_vport_param_store(max_scsicmpl_time);
Joe Perchesb6b996b2017-12-19 10:15:07 -08005480static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04005481
5482/*
dea31012005-04-17 16:05:31 -05005483# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
5484# range is [0,1]. Default value is 0.
5485*/
5486LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
5487
5488/*
James Smartc4908502019-01-28 11:14:28 -08005489# lpfc_xri_rebalancing: enable or disable XRI rebalancing feature
5490# range is [0,1]. Default value is 1.
5491*/
5492LPFC_ATTR_R(xri_rebalancing, 1, 0, 1, "Enable/Disable XRI rebalancing");
5493
5494/*
James Smart895427b2017-02-12 13:52:30 -08005495 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
5496 * range is [0,1]. Default value is 0.
James Smart45aa3122019-01-28 11:14:29 -08005497 * For [0], FCP commands are issued to Work Queues based on upper layer
5498 * hardware queue index.
James Smart895427b2017-02-12 13:52:30 -08005499 * For [1], FCP commands are issued to a Work Queue associated with the
5500 * current CPU.
5501 *
James Smart45aa3122019-01-28 11:14:29 -08005502 * LPFC_FCP_SCHED_BY_HDWQ == 0
James Smart895427b2017-02-12 13:52:30 -08005503 * LPFC_FCP_SCHED_BY_CPU == 1
5504 *
5505 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
5506 * affinity for FCP/NVME I/Os through Work Queues associated with the current
5507 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
5508 * through WQs will be used.
5509 */
James Smart6a828b02019-01-28 11:14:31 -08005510LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_BY_CPU,
James Smart45aa3122019-01-28 11:14:29 -08005511 LPFC_FCP_SCHED_BY_HDWQ,
James Smart895427b2017-02-12 13:52:30 -08005512 LPFC_FCP_SCHED_BY_CPU,
5513 "Determine scheduling algorithm for "
James Smart45aa3122019-01-28 11:14:29 -08005514 "issuing commands [0] - Hardware Queue, [1] - Current CPU");
James Smart49aa1432012-08-03 12:36:42 -04005515
5516/*
James Smart7ea92eb2018-10-23 13:41:10 -07005517 * lpfc_ns_query: Determine algrithmn for NameServer queries after RSCN
5518 * range is [0,1]. Default value is 0.
5519 * For [0], GID_FT is used for NameServer queries after RSCN (default)
5520 * For [1], GID_PT is used for NameServer queries after RSCN
5521 *
5522 */
5523LPFC_ATTR_RW(ns_query, LPFC_NS_QUERY_GID_FT,
5524 LPFC_NS_QUERY_GID_FT, LPFC_NS_QUERY_GID_PT,
5525 "Determine algorithm NameServer queries after RSCN "
5526 "[0] - GID_FT, [1] - GID_PT");
5527
5528/*
James Smarta6571c62012-10-31 14:44:42 -04005529# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
5530# range is [0,1]. Default value is 0.
5531# For [0], bus reset issues target reset to ALL devices
5532# For [1], bus reset issues target reset to non-FCP2 devices
5533*/
5534LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
5535 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
5536
5537
5538/*
dea31012005-04-17 16:05:31 -05005539# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
5540# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04005541# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05005542# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
5543# cr_delay is set to 0.
5544*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05005545LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05005546 "interrupt response is generated");
5547
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05005548LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05005549 "interrupt response is generated");
5550
5551/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05005552# lpfc_multi_ring_support: Determines how many rings to spread available
5553# cmd/rsp IOCB entries across.
5554# Value range is [1,2]. Default value is 1.
5555*/
5556LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
5557 "SLI rings to spread IOCB entries across");
5558
5559/*
James Smarta4bc3372006-12-02 13:34:16 -05005560# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
5561# identifies what rctl value to configure the additional ring for.
5562# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
5563*/
James Smart6a9c52c2009-10-02 15:16:51 -04005564LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05005565 255, "Identifies RCTL for additional ring configuration");
5566
5567/*
5568# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
5569# identifies what type value to configure the additional ring for.
5570# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
5571*/
James Smart6a9c52c2009-10-02 15:16:51 -04005572LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05005573 255, "Identifies TYPE for additional ring configuration");
5574
5575/*
James Smart4258e982015-12-16 18:11:58 -05005576# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
5577# 0 = SmartSAN functionality disabled (default)
5578# 1 = SmartSAN functionality enabled
5579# This parameter will override the value of lpfc_fdmi_on module parameter.
5580# Value range is [0,1]. Default value is 0.
dea31012005-04-17 16:05:31 -05005581*/
James Smart4258e982015-12-16 18:11:58 -05005582LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
5583
5584/*
5585# lpfc_fdmi_on: Controls FDMI support.
James Smart9abd9992018-08-14 12:55:05 -07005586# 0 No FDMI support
5587# 1 Traditional FDMI support (default)
James Smart8663cbb2016-03-31 14:12:33 -07005588# Traditional FDMI support means the driver will assume FDMI-2 support;
5589# however, if that fails, it will fallback to FDMI-1.
5590# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5591# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5592# lpfc_fdmi_on.
James Smart9abd9992018-08-14 12:55:05 -07005593# Value range [0,1]. Default value is 1.
James Smart4258e982015-12-16 18:11:58 -05005594*/
James Smart9abd9992018-08-14 12:55:05 -07005595LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05005596
5597/*
5598# Specifies the maximum number of ELS cmds we can have outstanding (for
5599# discovery). Value range is [1,64]. Default value = 32.
5600*/
James Smart3de2a652007-08-02 11:09:59 -04005601LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05005602 "during discovery");
5603
5604/*
James Smartc4a7c922013-05-31 17:04:59 -04005605# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
5606# will be scanned by the SCSI midlayer when sequential scanning is
5607# used; and is also the highest LUN ID allowed when the SCSI midlayer
5608# parses REPORT_LUN responses. The lpfc driver has no LUN count or
5609# LUN ID limit, but the SCSI midlayer requires this field for the uses
5610# above. The lpfc driver limits the default value to 255 for two reasons.
5611# As it bounds the sequential scan loop, scanning for thousands of luns
5612# on a target can take minutes of wall clock time. Additionally,
5613# there are FC targets, such as JBODs, that only recognize 8-bits of
5614# LUN ID. When they receive a value greater than 8 bits, they chop off
5615# the high order bits. In other words, they see LUN IDs 0, 256, 512,
5616# and so on all as LUN ID 0. This causes the linux kernel, which sees
5617# valid responses at each of the LUN IDs, to believe there are multiple
5618# devices present, when in fact, there is only 1.
5619# A customer that is aware of their target behaviors, and the results as
5620# indicated above, is welcome to increase the lpfc_max_luns value.
5621# As mentioned, this value is not used by the lpfc driver, only the
5622# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04005623# Value range is [0,65535]. Default value is 255.
5624# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05005625*/
Hannes Reinecke1abf6352014-06-25 15:27:38 +02005626LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05005627
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005628/*
5629# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
5630# Value range is [1,255], default value is 10.
5631*/
5632LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
5633 "Milliseconds driver will wait between polling FCP ring");
5634
James Smart4ff43242006-12-02 13:34:56 -05005635/*
James Smart0c411222013-09-06 12:22:46 -04005636# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
5637# to complete in seconds. Value range is [5,180], default value is 60.
5638*/
5639LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
5640 "Maximum time to wait for task management commands to complete");
5641/*
James Smart4ff43242006-12-02 13:34:56 -05005642# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5643# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02005644# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05005645# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02005646# 2 = MSI-X enabled (default)
5647# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05005648*/
George Kadianakis8605c462010-01-17 21:19:31 +02005649LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05005650 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05005651
James Smart13815c82008-01-11 01:52:48 -05005652/*
James Smartf358dd02017-02-12 13:52:34 -08005653 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
James Smart895427b2017-02-12 13:52:30 -08005654 *
5655 * 0 = NVME OAS disabled
5656 * 1 = NVME OAS enabled
5657 *
5658 * Value range is [0,1]. Default value is 0.
5659 */
5660LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5661 "Use OAS bit on NVME IOs");
5662
5663/*
James Smart4e565cf2018-02-22 08:18:50 -08005664 * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
5665 *
5666 * 0 = Put NVME Command in SGL
5667 * 1 = Embed NVME Command in WQE (unless G7)
5668 * 2 = Embed NVME Command in WQE (force)
5669 *
5670 * Value range is [0,2]. Default value is 1.
5671 */
5672LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,
5673 "Embed NVME Command in WQE");
5674
5675/*
James Smart77ffd342019-08-15 19:36:49 -07005676 * lpfc_fcp_mq_threshold: Set the maximum number of Hardware Queues
5677 * the driver will advertise it supports to the SCSI layer.
5678 *
5679 * 0 = Set nr_hw_queues by the number of CPUs or HW queues.
James Smartdcaa2132019-11-04 16:57:06 -08005680 * 1,256 = Manually specify nr_hw_queue value to be advertised,
James Smart77ffd342019-08-15 19:36:49 -07005681 *
James Smart06228002019-08-27 14:28:23 -07005682 * Value range is [0,256]. Default value is 8.
James Smart77ffd342019-08-15 19:36:49 -07005683 */
5684LPFC_ATTR_R(fcp_mq_threshold, LPFC_FCP_MQ_THRESHOLD_DEF,
5685 LPFC_FCP_MQ_THRESHOLD_MIN, LPFC_FCP_MQ_THRESHOLD_MAX,
5686 "Set the number of SCSI Queues advertised");
5687
5688/*
James Smart6a828b02019-01-28 11:14:31 -08005689 * lpfc_hdw_queue: Set the number of Hardware Queues the driver
James Smartcdb42be2019-01-28 11:14:21 -08005690 * will advertise it supports to the NVME and SCSI layers. This also
James Smart6a828b02019-01-28 11:14:31 -08005691 * will map to the number of CQ/WQ pairs the driver will create.
James Smart895427b2017-02-12 13:52:30 -08005692 *
5693 * The NVME Layer will try to create this many, plus 1 administrative
5694 * hardware queue. The administrative queue will always map to WQ 0
James Smart6a828b02019-01-28 11:14:31 -08005695 * A hardware IO queue maps (qidx) to a specific driver CQ/WQ.
James Smart895427b2017-02-12 13:52:30 -08005696 *
James Smartcdb42be2019-01-28 11:14:21 -08005697 * 0 = Configure the number of hdw queues to the number of active CPUs.
James Smartdcaa2132019-11-04 16:57:06 -08005698 * 1,256 = Manually specify how many hdw queues to use.
James Smart895427b2017-02-12 13:52:30 -08005699 *
James Smartdcaa2132019-11-04 16:57:06 -08005700 * Value range is [0,256]. Default value is 0.
James Smart895427b2017-02-12 13:52:30 -08005701 */
James Smartcdb42be2019-01-28 11:14:21 -08005702LPFC_ATTR_R(hdw_queue,
5703 LPFC_HBA_HDWQ_DEF,
5704 LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,
5705 "Set the number of I/O Hardware Queues");
James Smart895427b2017-02-12 13:52:30 -08005706
Dick Kennedy3048e3e2020-05-01 14:43:06 -07005707#if IS_ENABLED(CONFIG_X86)
5708/**
5709 * lpfc_cpumask_irq_mode_init - initalizes cpumask of phba based on
5710 * irq_chann_mode
5711 * @phba: Pointer to HBA context object.
5712 **/
5713static void
5714lpfc_cpumask_irq_mode_init(struct lpfc_hba *phba)
5715{
5716 unsigned int cpu, first_cpu, numa_node = NUMA_NO_NODE;
5717 const struct cpumask *sibling_mask;
5718 struct cpumask *aff_mask = &phba->sli4_hba.irq_aff_mask;
5719
5720 cpumask_clear(aff_mask);
5721
5722 if (phba->irq_chann_mode == NUMA_MODE) {
5723 /* Check if we're a NUMA architecture */
5724 numa_node = dev_to_node(&phba->pcidev->dev);
5725 if (numa_node == NUMA_NO_NODE) {
5726 phba->irq_chann_mode = NORMAL_MODE;
5727 return;
5728 }
5729 }
5730
5731 for_each_possible_cpu(cpu) {
5732 switch (phba->irq_chann_mode) {
5733 case NUMA_MODE:
5734 if (cpu_to_node(cpu) == numa_node)
5735 cpumask_set_cpu(cpu, aff_mask);
5736 break;
5737 case NHT_MODE:
5738 sibling_mask = topology_sibling_cpumask(cpu);
5739 first_cpu = cpumask_first(sibling_mask);
5740 if (first_cpu < nr_cpu_ids)
5741 cpumask_set_cpu(first_cpu, aff_mask);
5742 break;
5743 default:
5744 break;
5745 }
5746 }
5747}
5748#endif
5749
5750static void
5751lpfc_assign_default_irq_chann(struct lpfc_hba *phba)
James Smartdcaa2132019-11-04 16:57:06 -08005752{
5753#if IS_ENABLED(CONFIG_X86)
Dick Kennedy3048e3e2020-05-01 14:43:06 -07005754 switch (boot_cpu_data.x86_vendor) {
5755 case X86_VENDOR_AMD:
5756 /* If AMD architecture, then default is NUMA_MODE */
5757 phba->irq_chann_mode = NUMA_MODE;
5758 break;
5759 case X86_VENDOR_INTEL:
5760 /* If Intel architecture, then default is no hyperthread mode */
5761 phba->irq_chann_mode = NHT_MODE;
5762 break;
5763 default:
5764 phba->irq_chann_mode = NORMAL_MODE;
5765 break;
5766 }
5767 lpfc_cpumask_irq_mode_init(phba);
James Smartdcaa2132019-11-04 16:57:06 -08005768#else
Dick Kennedy3048e3e2020-05-01 14:43:06 -07005769 phba->irq_chann_mode = NORMAL_MODE;
James Smartdcaa2132019-11-04 16:57:06 -08005770#endif
5771}
5772
James Smart895427b2017-02-12 13:52:30 -08005773/*
James Smart6a828b02019-01-28 11:14:31 -08005774 * lpfc_irq_chann: Set the number of IRQ vectors that are available
5775 * for Hardware Queues to utilize. This also will map to the number
5776 * of EQ / MSI-X vectors the driver will create. This should never be
5777 * more than the number of Hardware Queues
5778 *
James Smartdcaa2132019-11-04 16:57:06 -08005779 * 0 = Configure number of IRQ Channels to:
5780 * if AMD architecture, number of CPUs on HBA's NUMA node
Dick Kennedy3048e3e2020-05-01 14:43:06 -07005781 * if Intel architecture, number of physical CPUs.
James Smartdcaa2132019-11-04 16:57:06 -08005782 * otherwise, number of active CPUs.
5783 * [1,256] = Manually specify how many IRQ Channels to use.
James Smart6a828b02019-01-28 11:14:31 -08005784 *
James Smartdcaa2132019-11-04 16:57:06 -08005785 * Value range is [0,256]. Default value is [0].
James Smart6a828b02019-01-28 11:14:31 -08005786 */
James Smartdcaa2132019-11-04 16:57:06 -08005787static uint lpfc_irq_chann = LPFC_IRQ_CHANN_DEF;
5788module_param(lpfc_irq_chann, uint, 0444);
5789MODULE_PARM_DESC(lpfc_irq_chann, "Set number of interrupt vectors to allocate");
5790
5791/* lpfc_irq_chann_init - Set the hba irq_chann initial value
5792 * @phba: lpfc_hba pointer.
5793 * @val: contains the initial value
5794 *
5795 * Description:
5796 * Validates the initial value is within range and assigns it to the
5797 * adapter. If not in range, an error message is posted and the
5798 * default value is assigned.
5799 *
5800 * Returns:
5801 * zero if value is in range and is set
5802 * -EINVAL if value was out of range
5803 **/
5804static int
5805lpfc_irq_chann_init(struct lpfc_hba *phba, uint32_t val)
5806{
Dick Kennedy3048e3e2020-05-01 14:43:06 -07005807 const struct cpumask *aff_mask;
James Smartdcaa2132019-11-04 16:57:06 -08005808
5809 if (phba->cfg_use_msi != 2) {
5810 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5811 "8532 use_msi = %u ignoring cfg_irq_numa\n",
5812 phba->cfg_use_msi);
Dick Kennedy3048e3e2020-05-01 14:43:06 -07005813 phba->irq_chann_mode = NORMAL_MODE;
5814 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
James Smartdcaa2132019-11-04 16:57:06 -08005815 return 0;
5816 }
5817
5818 /* Check if default setting was passed */
5819 if (val == LPFC_IRQ_CHANN_DEF)
Dick Kennedy3048e3e2020-05-01 14:43:06 -07005820 lpfc_assign_default_irq_chann(phba);
James Smartdcaa2132019-11-04 16:57:06 -08005821
Dick Kennedy3048e3e2020-05-01 14:43:06 -07005822 if (phba->irq_chann_mode != NORMAL_MODE) {
5823 aff_mask = &phba->sli4_hba.irq_aff_mask;
James Smartdcaa2132019-11-04 16:57:06 -08005824
Dick Kennedy3048e3e2020-05-01 14:43:06 -07005825 if (cpumask_empty(aff_mask)) {
James Smartdcaa2132019-11-04 16:57:06 -08005826 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
Dick Kennedy3048e3e2020-05-01 14:43:06 -07005827 "8533 Could not identify CPUS for "
5828 "mode %d, ignoring\n",
5829 phba->irq_chann_mode);
5830 phba->irq_chann_mode = NORMAL_MODE;
5831 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
James Smartdcaa2132019-11-04 16:57:06 -08005832 } else {
Dick Kennedy3048e3e2020-05-01 14:43:06 -07005833 phba->cfg_irq_chann = cpumask_weight(aff_mask);
5834
5835 /* If no hyperthread mode, then set hdwq count to
5836 * aff_mask weight as well
5837 */
5838 if (phba->irq_chann_mode == NHT_MODE)
5839 phba->cfg_hdw_queue = phba->cfg_irq_chann;
5840
James Smartdcaa2132019-11-04 16:57:06 -08005841 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5842 "8543 lpfc_irq_chann set to %u "
Dick Kennedy3048e3e2020-05-01 14:43:06 -07005843 "(mode: %d)\n", phba->cfg_irq_chann,
5844 phba->irq_chann_mode);
James Smartdcaa2132019-11-04 16:57:06 -08005845 }
5846 } else {
5847 if (val > LPFC_IRQ_CHANN_MAX) {
5848 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5849 "8545 lpfc_irq_chann attribute cannot "
5850 "be set to %u, allowed range is "
5851 "[%u,%u]\n",
5852 val,
5853 LPFC_IRQ_CHANN_MIN,
5854 LPFC_IRQ_CHANN_MAX);
Dick Kennedy3048e3e2020-05-01 14:43:06 -07005855 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
James Smartdcaa2132019-11-04 16:57:06 -08005856 return -EINVAL;
5857 }
5858 phba->cfg_irq_chann = val;
5859 }
5860
5861 return 0;
5862}
5863
5864/**
5865 * lpfc_irq_chann_show - Display value of irq_chann
5866 * @dev: class converted to a Scsi_host structure.
5867 * @attr: device attribute, not used.
5868 * @buf: on return contains a string with the list sizes
5869 *
5870 * Returns: size of formatted string.
5871 **/
5872static ssize_t
5873lpfc_irq_chann_show(struct device *dev, struct device_attribute *attr,
5874 char *buf)
5875{
5876 struct Scsi_Host *shost = class_to_shost(dev);
5877 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5878 struct lpfc_hba *phba = vport->phba;
5879
5880 return scnprintf(buf, PAGE_SIZE, "%u\n", phba->cfg_irq_chann);
5881}
5882
5883static DEVICE_ATTR_RO(lpfc_irq_chann);
James Smart6a828b02019-01-28 11:14:31 -08005884
5885/*
James Smart13815c82008-01-11 01:52:48 -05005886# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5887# 0 = HBA resets disabled
5888# 1 = HBA resets enabled (default)
James Smart50212672018-12-13 15:17:57 -08005889# 2 = HBA reset via PCI bus reset enabled
5890# Value range is [0,2]. Default value is 1.
James Smart13815c82008-01-11 01:52:48 -05005891*/
James Smart50212672018-12-13 15:17:57 -08005892LPFC_ATTR_RW(enable_hba_reset, 1, 0, 2, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04005893
James Smart13815c82008-01-11 01:52:48 -05005894/*
James Smarteb7a3392010-11-20 23:12:02 -05005895# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05005896# 0 = HBA Heartbeat disabled
5897# 1 = HBA Heartbeat enabled (default)
5898# Value range is [0,1]. Default value is 1.
5899*/
James Smarteb7a3392010-11-20 23:12:02 -05005900LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05005901
James Smart83108bd2008-01-11 01:53:09 -05005902/*
James Smart1ba981f2014-02-20 09:56:45 -05005903# lpfc_EnableXLane: Enable Express Lane Feature
5904# 0x0 Express Lane Feature disabled
5905# 0x1 Express Lane Feature enabled
5906# Value range is [0,1]. Default value is 0.
5907*/
5908LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5909
5910/*
5911# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5912# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5913# Value range is [0x0,0x7f]. Default value is 0
5914*/
James Smart28d7f3d2014-05-21 08:05:28 -04005915LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
James Smart1ba981f2014-02-20 09:56:45 -05005916
5917/*
James Smart81301a92008-12-04 22:39:46 -05005918# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5919# 0 = BlockGuard disabled (default)
5920# 1 = BlockGuard enabled
5921# Value range is [0,1]. Default value is 0.
5922*/
5923LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5924
James Smart6fb120a2009-05-22 14:52:59 -04005925/*
James Smart81301a92008-12-04 22:39:46 -05005926# lpfc_prot_mask: i
5927# - Bit mask of host protection capabilities used to register with the
5928# SCSI mid-layer
5929# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5930# - Allows you to ultimately specify which profiles to use
5931# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04005932# - SHOST_DIF_TYPE1_PROTECTION 1
5933# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5934# - SHOST_DIX_TYPE0_PROTECTION 8
5935# HBA supports DIX Type 0: Host to HBA protection only
5936# - SHOST_DIX_TYPE1_PROTECTION 16
5937# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05005938#
5939*/
James Smartb3b98b72016-10-13 15:06:06 -07005940LPFC_ATTR(prot_mask,
5941 (SHOST_DIF_TYPE1_PROTECTION |
5942 SHOST_DIX_TYPE0_PROTECTION |
5943 SHOST_DIX_TYPE1_PROTECTION),
5944 0,
5945 (SHOST_DIF_TYPE1_PROTECTION |
5946 SHOST_DIX_TYPE0_PROTECTION |
5947 SHOST_DIX_TYPE1_PROTECTION),
5948 "T10-DIF host protection capabilities mask");
James Smart81301a92008-12-04 22:39:46 -05005949
5950/*
5951# lpfc_prot_guard: i
5952# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04005953# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05005954# - Allows you to ultimately specify which profiles to use
5955# - Default will result in registering capabilities for all guard types
5956#
5957*/
James Smartb3b98b72016-10-13 15:06:06 -07005958LPFC_ATTR(prot_guard,
5959 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5960 "T10-DIF host protection guard type");
James Smart81301a92008-12-04 22:39:46 -05005961
James Smart92494142011-02-16 12:39:44 -05005962/*
5963 * Delay initial NPort discovery when Clean Address bit is cleared in
5964 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5965 * This parameter can have value 0 or 1.
5966 * When this parameter is set to 0, no delay is added to the initial
5967 * discovery.
5968 * When this parameter is set to non-zero value, initial Nport discovery is
5969 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5970 * accept and FCID/Fabric name/Fabric portname is changed.
5971 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5972 * when Clean Address bit is cleared in FLOGI/FDISC
5973 * accept and FCID/Fabric name/Fabric portname is changed.
5974 * Default value is 0.
5975 */
James Smart8eb8b962016-07-06 12:36:08 -07005976LPFC_ATTR(delay_discovery, 0, 0, 1,
5977 "Delay NPort discovery when Clean Address bit is cleared.");
James Smart81301a92008-12-04 22:39:46 -05005978
5979/*
James Smart3621a712009-04-06 18:47:14 -04005980 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart5b9e70b2018-09-10 10:30:42 -07005981 * This value can be set to values between 64 and 4096. The default value
5982 * is 64, but may be increased to allow for larger Max I/O sizes. The scsi
5983 * and nvme layers will allow I/O sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04005984 * Because of the additional overhead involved in setting up T10-DIF,
5985 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5986 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05005987 */
James Smart5b9e70b2018-09-10 10:30:42 -07005988static uint lpfc_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5989module_param(lpfc_sg_seg_cnt, uint, 0444);
5990MODULE_PARM_DESC(lpfc_sg_seg_cnt, "Max Scatter Gather Segment Count");
5991
5992/**
5993 * lpfc_sg_seg_cnt_show - Display the scatter/gather list sizes
5994 * configured for the adapter
5995 * @dev: class converted to a Scsi_host structure.
5996 * @attr: device attribute, not used.
5997 * @buf: on return contains a string with the list sizes
5998 *
5999 * Returns: size of formatted string.
6000 **/
6001static ssize_t
6002lpfc_sg_seg_cnt_show(struct device *dev, struct device_attribute *attr,
6003 char *buf)
6004{
6005 struct Scsi_Host *shost = class_to_shost(dev);
6006 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
6007 struct lpfc_hba *phba = vport->phba;
6008 int len;
6009
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07006010 len = scnprintf(buf, PAGE_SIZE, "SGL sz: %d total SGEs: %d\n",
James Smart5b9e70b2018-09-10 10:30:42 -07006011 phba->cfg_sg_dma_buf_size, phba->cfg_total_seg_cnt);
6012
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07006013 len += scnprintf(buf + len, PAGE_SIZE, "Cfg: %d SCSI: %d NVME: %d\n",
James Smart5b9e70b2018-09-10 10:30:42 -07006014 phba->cfg_sg_seg_cnt, phba->cfg_scsi_seg_cnt,
6015 phba->cfg_nvme_seg_cnt);
6016 return len;
6017}
6018
6019static DEVICE_ATTR_RO(lpfc_sg_seg_cnt);
6020
6021/**
6022 * lpfc_sg_seg_cnt_init - Set the hba sg_seg_cnt initial value
6023 * @phba: lpfc_hba pointer.
6024 * @val: contains the initial value
6025 *
6026 * Description:
6027 * Validates the initial value is within range and assigns it to the
6028 * adapter. If not in range, an error message is posted and the
6029 * default value is assigned.
6030 *
6031 * Returns:
6032 * zero if value is in range and is set
6033 * -EINVAL if value was out of range
6034 **/
6035static int
6036lpfc_sg_seg_cnt_init(struct lpfc_hba *phba, int val)
6037{
6038 if (val >= LPFC_MIN_SG_SEG_CNT && val <= LPFC_MAX_SG_SEG_CNT) {
6039 phba->cfg_sg_seg_cnt = val;
6040 return 0;
6041 }
6042 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6043 "0409 "LPFC_DRIVER_NAME"_sg_seg_cnt attribute cannot "
6044 "be set to %d, allowed range is [%d, %d]\n",
6045 val, LPFC_MIN_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT);
6046 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
6047 return -EINVAL;
6048}
James Smart83108bd2008-01-11 01:53:09 -05006049
James Smart96f70772013-04-17 20:16:15 -04006050/*
James Smart7bdedb32016-07-06 12:36:00 -07006051 * lpfc_enable_mds_diags: Enable MDS Diagnostics
6052 * 0 = MDS Diagnostics disabled (default)
6053 * 1 = MDS Diagnostics enabled
6054 * Value range is [0,1]. Default value is 0.
6055 */
James Smarte62245d2019-08-14 16:57:08 -07006056LPFC_ATTR_RW(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
James Smart7bdedb32016-07-06 12:36:00 -07006057
James Smart44fd7fe2017-08-23 16:55:47 -07006058/*
James Smartd2cc9bc2018-09-10 10:30:50 -07006059 * lpfc_ras_fwlog_buffsize: Firmware logging host buffer size
6060 * 0 = Disable firmware logging (default)
6061 * [1-4] = Multiple of 1/4th Mb of host memory for FW logging
6062 * Value range [0..4]. Default value is 0
6063 */
James Smart95bfc6d2019-10-18 14:18:27 -07006064LPFC_ATTR(ras_fwlog_buffsize, 0, 0, 4, "Host memory for FW logging");
6065lpfc_param_show(ras_fwlog_buffsize);
6066
6067static ssize_t
6068lpfc_ras_fwlog_buffsize_set(struct lpfc_hba *phba, uint val)
6069{
6070 int ret = 0;
6071 enum ras_state state;
6072
6073 if (!lpfc_rangecheck(val, 0, 4))
6074 return -EINVAL;
6075
6076 if (phba->cfg_ras_fwlog_buffsize == val)
6077 return 0;
6078
James Smartdda5bdf2019-11-04 16:57:02 -08006079 if (phba->cfg_ras_fwlog_func != PCI_FUNC(phba->pcidev->devfn))
James Smart95bfc6d2019-10-18 14:18:27 -07006080 return -EINVAL;
6081
6082 spin_lock_irq(&phba->hbalock);
6083 state = phba->ras_fwlog.state;
6084 spin_unlock_irq(&phba->hbalock);
6085
6086 if (state == REG_INPROGRESS) {
6087 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, "6147 RAS Logging "
6088 "registration is in progress\n");
6089 return -EBUSY;
6090 }
6091
6092 /* For disable logging: stop the logs and free the DMA.
6093 * For ras_fwlog_buffsize size change we still need to free and
6094 * reallocate the DMA in lpfc_sli4_ras_fwlog_init.
6095 */
6096 phba->cfg_ras_fwlog_buffsize = val;
6097 if (state == ACTIVE) {
6098 lpfc_ras_stop_fwlog(phba);
6099 lpfc_sli4_ras_dma_free(phba);
6100 }
6101
6102 lpfc_sli4_ras_init(phba);
6103 if (phba->ras_fwlog.ras_enabled)
6104 ret = lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,
6105 LPFC_RAS_ENABLE_LOGGING);
6106 return ret;
6107}
6108
6109lpfc_param_store(ras_fwlog_buffsize);
6110static DEVICE_ATTR_RW(lpfc_ras_fwlog_buffsize);
James Smartd2cc9bc2018-09-10 10:30:50 -07006111
6112/*
6113 * lpfc_ras_fwlog_level: Firmware logging verbosity level
6114 * Valid only if firmware logging is enabled
6115 * 0(Least Verbosity) 4 (most verbosity)
6116 * Value range is [0..4]. Default value is 0
6117 */
6118LPFC_ATTR_RW(ras_fwlog_level, 0, 0, 4, "Firmware Logging Level");
6119
6120/*
6121 * lpfc_ras_fwlog_func: Firmware logging enabled on function number
6122 * Default function which has RAS support : 0
6123 * Value Range is [0..7].
6124 * FW logging is a global action and enablement is via a specific
6125 * port.
6126 */
6127LPFC_ATTR_RW(ras_fwlog_func, 0, 0, 7, "Firmware Logging Enabled on Function");
6128
6129/*
James Smart44fd7fe2017-08-23 16:55:47 -07006130 * lpfc_enable_bbcr: Enable BB Credit Recovery
6131 * 0 = BB Credit Recovery disabled
6132 * 1 = BB Credit Recovery enabled (default)
6133 * Value range is [0,1]. Default value is 1.
6134 */
6135LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
6136
James Smart1351e692018-02-22 08:18:43 -08006137/*
6138 * lpfc_enable_dpp: Enable DPP on G7
6139 * 0 = DPP on G7 disabled
6140 * 1 = DPP on G7 enabled (default)
6141 * Value range is [0,1]. Default value is 1.
6142 */
6143LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");
6144
Tony Jonesee959b02008-02-22 00:13:36 +01006145struct device_attribute *lpfc_hba_attrs[] = {
James Smart895427b2017-02-12 13:52:30 -08006146 &dev_attr_nvme_info,
James Smart4c47efc2019-01-28 11:14:25 -08006147 &dev_attr_scsi_stat,
James Smart81301a92008-12-04 22:39:46 -05006148 &dev_attr_bg_info,
6149 &dev_attr_bg_guard_err,
6150 &dev_attr_bg_apptag_err,
6151 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01006152 &dev_attr_info,
6153 &dev_attr_serialnum,
6154 &dev_attr_modeldesc,
6155 &dev_attr_modelname,
6156 &dev_attr_programtype,
6157 &dev_attr_portnum,
6158 &dev_attr_fwrev,
6159 &dev_attr_hdw,
6160 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01006161 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01006162 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04006163 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01006164 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04006165 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01006166 &dev_attr_lpfc_temp_sensor,
6167 &dev_attr_lpfc_log_verbose,
6168 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04006169 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01006170 &dev_attr_lpfc_hba_queue_depth,
6171 &dev_attr_lpfc_peer_port_login,
6172 &dev_attr_lpfc_nodev_tmo,
6173 &dev_attr_lpfc_devloss_tmo,
James Smart895427b2017-02-12 13:52:30 -08006174 &dev_attr_lpfc_enable_fc4_type,
Tony Jonesee959b02008-02-22 00:13:36 +01006175 &dev_attr_lpfc_fcp_class,
6176 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04006177 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01006178 &dev_attr_lpfc_ack0,
James Smartc4908502019-01-28 11:14:28 -08006179 &dev_attr_lpfc_xri_rebalancing,
Tony Jonesee959b02008-02-22 00:13:36 +01006180 &dev_attr_lpfc_topology,
6181 &dev_attr_lpfc_scan_down,
6182 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04006183 &dev_attr_lpfc_fcp_io_sched,
James Smart7ea92eb2018-10-23 13:41:10 -07006184 &dev_attr_lpfc_ns_query,
James Smarta6571c62012-10-31 14:44:42 -04006185 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01006186 &dev_attr_lpfc_cr_delay,
6187 &dev_attr_lpfc_cr_count,
6188 &dev_attr_lpfc_multi_ring_support,
6189 &dev_attr_lpfc_multi_ring_rctl,
6190 &dev_attr_lpfc_multi_ring_type,
6191 &dev_attr_lpfc_fdmi_on,
James Smart4258e982015-12-16 18:11:58 -05006192 &dev_attr_lpfc_enable_SmartSAN,
Tony Jonesee959b02008-02-22 00:13:36 +01006193 &dev_attr_lpfc_max_luns,
6194 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04006195 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05006196 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01006197 &dev_attr_nport_evt_cnt,
6198 &dev_attr_board_mode,
6199 &dev_attr_max_vpi,
6200 &dev_attr_used_vpi,
6201 &dev_attr_max_rpi,
6202 &dev_attr_used_rpi,
6203 &dev_attr_max_xri,
6204 &dev_attr_used_xri,
6205 &dev_attr_npiv_info,
6206 &dev_attr_issue_reset,
6207 &dev_attr_lpfc_poll,
6208 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04006209 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01006210 &dev_attr_lpfc_use_msi,
James Smart895427b2017-02-12 13:52:30 -08006211 &dev_attr_lpfc_nvme_oas,
James Smart4e565cf2018-02-22 08:18:50 -08006212 &dev_attr_lpfc_nvme_embed_cmd,
James Smartda0436e2009-05-22 14:51:39 -04006213 &dev_attr_lpfc_fcp_imax,
James Smart41b194b2019-05-14 14:58:08 -07006214 &dev_attr_lpfc_force_rscn,
James Smart32517fc2019-01-28 11:14:33 -08006215 &dev_attr_lpfc_cq_poll_threshold,
6216 &dev_attr_lpfc_cq_max_proc_limit,
James Smart7bb03bb2013-04-17 20:19:16 -04006217 &dev_attr_lpfc_fcp_cpu_map,
James Smart77ffd342019-08-15 19:36:49 -07006218 &dev_attr_lpfc_fcp_mq_threshold,
James Smartcdb42be2019-01-28 11:14:21 -08006219 &dev_attr_lpfc_hdw_queue,
James Smart6a828b02019-01-28 11:14:31 -08006220 &dev_attr_lpfc_irq_chann,
James Smartf358dd02017-02-12 13:52:34 -08006221 &dev_attr_lpfc_suppress_rsp,
James Smart2d7dbc42017-02-12 13:52:35 -08006222 &dev_attr_lpfc_nvmet_mrq,
James Smart2448e482018-04-09 14:24:24 -07006223 &dev_attr_lpfc_nvmet_mrq_post,
James Smart895427b2017-02-12 13:52:30 -08006224 &dev_attr_lpfc_nvme_enable_fb,
James Smart2d7dbc42017-02-12 13:52:35 -08006225 &dev_attr_lpfc_nvmet_fb_size,
James Smart81301a92008-12-04 22:39:46 -05006226 &dev_attr_lpfc_enable_bg,
James Smart352e5fd2016-12-30 06:57:47 -08006227 &dev_attr_lpfc_soft_wwnn,
6228 &dev_attr_lpfc_soft_wwpn,
6229 &dev_attr_lpfc_soft_wwn_enable,
Tony Jonesee959b02008-02-22 00:13:36 +01006230 &dev_attr_lpfc_enable_hba_reset,
6231 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05006232 &dev_attr_lpfc_EnableXLane,
6233 &dev_attr_lpfc_XLanePriority,
6234 &dev_attr_lpfc_xlane_lun,
6235 &dev_attr_lpfc_xlane_tgt,
6236 &dev_attr_lpfc_xlane_vpt,
6237 &dev_attr_lpfc_xlane_lun_state,
6238 &dev_attr_lpfc_xlane_lun_status,
James Smartc92c8412016-07-06 12:36:05 -07006239 &dev_attr_lpfc_xlane_priority,
Tony Jonesee959b02008-02-22 00:13:36 +01006240 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04006241 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04006242 &dev_attr_lpfc_stat_data_ctrl,
James Smart0d878412009-10-02 15:16:56 -04006243 &dev_attr_lpfc_aer_support,
6244 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04006245 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04006246 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05006247 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04006248 &dev_attr_iocb_hw,
James Smart83c6cb12019-10-18 14:18:30 -07006249 &dev_attr_pls,
6250 &dev_attr_pt,
James Smart2a9bf3d2010-06-07 15:24:45 -04006251 &dev_attr_txq_hw,
6252 &dev_attr_txcmplq_hw,
James Smart912e3ac2011-05-24 11:42:11 -04006253 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05006254 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05006255 &dev_attr_lpfc_xlane_supported,
James Smart7bdedb32016-07-06 12:36:00 -07006256 &dev_attr_lpfc_enable_mds_diags,
James Smartd2cc9bc2018-09-10 10:30:50 -07006257 &dev_attr_lpfc_ras_fwlog_buffsize,
6258 &dev_attr_lpfc_ras_fwlog_level,
6259 &dev_attr_lpfc_ras_fwlog_func,
James Smart44fd7fe2017-08-23 16:55:47 -07006260 &dev_attr_lpfc_enable_bbcr,
James Smart1351e692018-02-22 08:18:43 -08006261 &dev_attr_lpfc_enable_dpp,
dea31012005-04-17 16:05:31 -05006262 NULL,
6263};
6264
Tony Jonesee959b02008-02-22 00:13:36 +01006265struct device_attribute *lpfc_vport_attrs[] = {
6266 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01006267 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01006268 &dev_attr_num_discovered_ports,
6269 &dev_attr_lpfc_drvr_version,
6270 &dev_attr_lpfc_log_verbose,
6271 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04006272 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01006273 &dev_attr_lpfc_nodev_tmo,
6274 &dev_attr_lpfc_devloss_tmo,
6275 &dev_attr_lpfc_hba_queue_depth,
6276 &dev_attr_lpfc_peer_port_login,
6277 &dev_attr_lpfc_restrict_login,
6278 &dev_attr_lpfc_fcp_class,
6279 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04006280 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01006281 &dev_attr_lpfc_max_luns,
6282 &dev_attr_nport_evt_cnt,
6283 &dev_attr_npiv_info,
6284 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04006285 &dev_attr_lpfc_max_scsicmpl_time,
6286 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04006287 &dev_attr_lpfc_static_vport,
James Smart3de2a652007-08-02 11:09:59 -04006288 NULL,
6289};
6290
James Smarte59058c2008-08-24 21:49:00 -04006291/**
James Smart3621a712009-04-06 18:47:14 -04006292 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07006293 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04006294 * @kobj: kernel kobject that contains the kernel class device.
6295 * @bin_attr: kernel attributes passed to us.
6296 * @buf: contains the data to be written to the adapter IOREG space.
6297 * @off: offset into buffer to beginning of data.
6298 * @count: bytes to transfer.
6299 *
6300 * Description:
6301 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6302 * Uses the adapter io control registers to send buf contents to the adapter.
6303 *
6304 * Returns:
6305 * -ERANGE off and count combo out of range
6306 * -EINVAL off, count or buff address invalid
6307 * -EPERM adapter is offline
6308 * value of count, buf contents written
6309 **/
dea31012005-04-17 16:05:31 -05006310static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07006311sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
6312 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08006313 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05006314{
6315 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01006316 struct device *dev = container_of(kobj, struct device, kobj);
6317 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05006318 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6319 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006320
James Smartf1126682009-06-10 17:22:44 -04006321 if (phba->sli_rev >= LPFC_SLI_REV4)
6322 return -EPERM;
6323
dea31012005-04-17 16:05:31 -05006324 if ((off + count) > FF_REG_AREA_SIZE)
6325 return -ERANGE;
6326
James Smartf7a919b2011-08-21 21:49:16 -04006327 if (count <= LPFC_REG_WRITE_KEY_SIZE)
6328 return 0;
dea31012005-04-17 16:05:31 -05006329
6330 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6331 return -EINVAL;
6332
James Smartf7a919b2011-08-21 21:49:16 -04006333 /* This is to protect HBA registers from accidental writes. */
6334 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
6335 return -EINVAL;
6336
6337 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05006338 return -EPERM;
dea31012005-04-17 16:05:31 -05006339
James Smart2e0fef82007-06-17 19:56:36 -05006340 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04006341 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
6342 buf_off += sizeof(uint32_t))
6343 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05006344 phba->ctrl_regs_memmap_p + off + buf_off);
6345
James Smart2e0fef82007-06-17 19:56:36 -05006346 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006347
6348 return count;
6349}
6350
James Smarte59058c2008-08-24 21:49:00 -04006351/**
James Smart3621a712009-04-06 18:47:14 -04006352 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07006353 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04006354 * @kobj: kernel kobject that contains the kernel class device.
6355 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006356 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04006357 * @off: offset into buffer to beginning of data.
6358 * @count: bytes to transfer.
6359 *
6360 * Description:
6361 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6362 * Uses the adapter io control registers to read data into buf.
6363 *
6364 * Returns:
6365 * -ERANGE off and count combo out of range
6366 * -EINVAL off, count or buff address invalid
6367 * value of count, buf contents read
6368 **/
dea31012005-04-17 16:05:31 -05006369static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07006370sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
6371 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08006372 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05006373{
6374 size_t buf_off;
6375 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01006376 struct device *dev = container_of(kobj, struct device, kobj);
6377 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05006378 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6379 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006380
James Smartf1126682009-06-10 17:22:44 -04006381 if (phba->sli_rev >= LPFC_SLI_REV4)
6382 return -EPERM;
6383
dea31012005-04-17 16:05:31 -05006384 if (off > FF_REG_AREA_SIZE)
6385 return -ERANGE;
6386
6387 if ((off + count) > FF_REG_AREA_SIZE)
6388 count = FF_REG_AREA_SIZE - off;
6389
6390 if (count == 0) return 0;
6391
6392 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6393 return -EINVAL;
6394
James Smart2e0fef82007-06-17 19:56:36 -05006395 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006396
6397 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
6398 tmp_ptr = (uint32_t *)(buf + buf_off);
6399 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
6400 }
6401
James Smart2e0fef82007-06-17 19:56:36 -05006402 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006403
6404 return count;
6405}
6406
6407static struct bin_attribute sysfs_ctlreg_attr = {
6408 .attr = {
6409 .name = "ctlreg",
6410 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05006411 },
6412 .size = 256,
6413 .read = sysfs_ctlreg_read,
6414 .write = sysfs_ctlreg_write,
6415};
6416
James Smarte59058c2008-08-24 21:49:00 -04006417/**
James Smart3621a712009-04-06 18:47:14 -04006418 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07006419 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04006420 * @kobj: kernel kobject that contains the kernel class device.
6421 * @bin_attr: kernel attributes passed to us.
6422 * @buf: contains the data to be written to sysfs mbox.
6423 * @off: offset into buffer to beginning of data.
6424 * @count: bytes to transfer.
6425 *
6426 * Description:
James Smart026abb82011-12-13 13:20:45 -05006427 * Deprecated function. All mailbox access from user space is performed via the
6428 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04006429 *
6430 * Returns:
James Smart026abb82011-12-13 13:20:45 -05006431 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04006432 **/
dea31012005-04-17 16:05:31 -05006433static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07006434sysfs_mbox_write(struct file *filp, struct kobject *kobj,
6435 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08006436 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05006437{
James Smart026abb82011-12-13 13:20:45 -05006438 return -EPERM;
dea31012005-04-17 16:05:31 -05006439}
6440
James Smarte59058c2008-08-24 21:49:00 -04006441/**
James Smart3621a712009-04-06 18:47:14 -04006442 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07006443 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04006444 * @kobj: kernel kobject that contains the kernel class device.
6445 * @bin_attr: kernel attributes passed to us.
6446 * @buf: contains the data to be read from sysfs mbox.
6447 * @off: offset into buffer to beginning of data.
6448 * @count: bytes to transfer.
6449 *
6450 * Description:
James Smart026abb82011-12-13 13:20:45 -05006451 * Deprecated function. All mailbox access from user space is performed via the
6452 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04006453 *
6454 * Returns:
James Smart026abb82011-12-13 13:20:45 -05006455 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04006456 **/
dea31012005-04-17 16:05:31 -05006457static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07006458sysfs_mbox_read(struct file *filp, struct kobject *kobj,
6459 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08006460 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05006461{
James Smart026abb82011-12-13 13:20:45 -05006462 return -EPERM;
dea31012005-04-17 16:05:31 -05006463}
6464
6465static struct bin_attribute sysfs_mbox_attr = {
6466 .attr = {
6467 .name = "mbox",
6468 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05006469 },
James Smartc0c11512011-05-24 11:41:34 -04006470 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05006471 .read = sysfs_mbox_read,
6472 .write = sysfs_mbox_write,
6473};
6474
James Smarte59058c2008-08-24 21:49:00 -04006475/**
James Smart3621a712009-04-06 18:47:14 -04006476 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04006477 * @vport: address of lpfc vport structure.
6478 *
6479 * Return codes:
6480 * zero on success
6481 * error return code from sysfs_create_bin_file()
6482 **/
dea31012005-04-17 16:05:31 -05006483int
James Smart2e0fef82007-06-17 19:56:36 -05006484lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006485{
James Smart2e0fef82007-06-17 19:56:36 -05006486 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05006487 int error;
6488
Tony Jonesee959b02008-02-22 00:13:36 +01006489 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05006490 &sysfs_drvr_stat_data_attr);
6491
6492 /* Virtual ports do not need ctrl_reg and mbox */
6493 if (error || vport->port_type == LPFC_NPIV_PORT)
6494 goto out;
6495
6496 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05006497 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05006498 if (error)
James Smarteada2722008-12-04 22:39:13 -05006499 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05006500
Tony Jonesee959b02008-02-22 00:13:36 +01006501 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05006502 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05006503 if (error)
6504 goto out_remove_ctlreg_attr;
6505
6506 return 0;
6507out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01006508 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05006509out_remove_stat_attr:
6510 sysfs_remove_bin_file(&shost->shost_dev.kobj,
6511 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05006512out:
6513 return error;
6514}
6515
James Smarte59058c2008-08-24 21:49:00 -04006516/**
James Smart3621a712009-04-06 18:47:14 -04006517 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04006518 * @vport: address of lpfc vport structure.
6519 **/
dea31012005-04-17 16:05:31 -05006520void
James Smart2e0fef82007-06-17 19:56:36 -05006521lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006522{
James Smart2e0fef82007-06-17 19:56:36 -05006523 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04006524 sysfs_remove_bin_file(&shost->shost_dev.kobj,
6525 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05006526 /* Virtual ports do not need ctrl_reg and mbox */
6527 if (vport->port_type == LPFC_NPIV_PORT)
6528 return;
Tony Jonesee959b02008-02-22 00:13:36 +01006529 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
6530 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05006531}
6532
dea31012005-04-17 16:05:31 -05006533/*
6534 * Dynamic FC Host Attributes Support
6535 */
6536
James Smarte59058c2008-08-24 21:49:00 -04006537/**
James Smart6c9231f2016-12-19 15:07:24 -08006538 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
6539 * @shost: kernel scsi host pointer.
6540 **/
6541static void
6542lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
6543{
6544 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
6545
6546 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
6547 sizeof fc_host_symbolic_name(shost));
6548}
6549
6550/**
James Smart3621a712009-04-06 18:47:14 -04006551 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04006552 * @shost: kernel scsi host pointer.
6553 **/
dea31012005-04-17 16:05:31 -05006554static void
6555lpfc_get_host_port_id(struct Scsi_Host *shost)
6556{
James Smart2e0fef82007-06-17 19:56:36 -05006557 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6558
dea31012005-04-17 16:05:31 -05006559 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05006560 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05006561}
6562
James Smarte59058c2008-08-24 21:49:00 -04006563/**
James Smart3621a712009-04-06 18:47:14 -04006564 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04006565 * @shost: kernel scsi host pointer.
6566 **/
dea31012005-04-17 16:05:31 -05006567static void
6568lpfc_get_host_port_type(struct Scsi_Host *shost)
6569{
James Smart2e0fef82007-06-17 19:56:36 -05006570 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6571 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006572
6573 spin_lock_irq(shost->host_lock);
6574
James Smart92d7f7b2007-06-17 19:56:38 -05006575 if (vport->port_type == LPFC_NPIV_PORT) {
6576 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
6577 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05006578 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05006579 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05006580 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
6581 else
6582 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
6583 } else {
James Smart2e0fef82007-06-17 19:56:36 -05006584 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05006585 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
6586 else
6587 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
6588 }
6589 } else
6590 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
6591
6592 spin_unlock_irq(shost->host_lock);
6593}
6594
James Smarte59058c2008-08-24 21:49:00 -04006595/**
James Smart3621a712009-04-06 18:47:14 -04006596 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04006597 * @shost: kernel scsi host pointer.
6598 **/
dea31012005-04-17 16:05:31 -05006599static void
6600lpfc_get_host_port_state(struct Scsi_Host *shost)
6601{
James Smart2e0fef82007-06-17 19:56:36 -05006602 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6603 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006604
6605 spin_lock_irq(shost->host_lock);
6606
James Smart2e0fef82007-06-17 19:56:36 -05006607 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05006608 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
6609 else {
James Smart2e0fef82007-06-17 19:56:36 -05006610 switch (phba->link_state) {
6611 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05006612 case LPFC_LINK_DOWN:
6613 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
6614 break;
6615 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05006616 case LPFC_CLEAR_LA:
6617 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05006618 /* Links up, reports port state accordingly */
6619 if (vport->port_state < LPFC_VPORT_READY)
6620 fc_host_port_state(shost) =
6621 FC_PORTSTATE_BYPASSED;
6622 else
6623 fc_host_port_state(shost) =
6624 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05006625 break;
6626 case LPFC_HBA_ERROR:
6627 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
6628 break;
6629 default:
6630 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
6631 break;
6632 }
6633 }
6634
6635 spin_unlock_irq(shost->host_lock);
6636}
6637
James Smarte59058c2008-08-24 21:49:00 -04006638/**
James Smart3621a712009-04-06 18:47:14 -04006639 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04006640 * @shost: kernel scsi host pointer.
6641 **/
dea31012005-04-17 16:05:31 -05006642static void
6643lpfc_get_host_speed(struct Scsi_Host *shost)
6644{
James Smart2e0fef82007-06-17 19:56:36 -05006645 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6646 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006647
6648 spin_lock_irq(shost->host_lock);
6649
James Smarta085e872015-12-16 18:12:02 -05006650 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea31012005-04-17 16:05:31 -05006651 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05006652 case LPFC_LINK_SPEED_1GHZ:
6653 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05006654 break;
James Smart76a95d72010-11-20 23:11:48 -05006655 case LPFC_LINK_SPEED_2GHZ:
6656 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05006657 break;
James Smart76a95d72010-11-20 23:11:48 -05006658 case LPFC_LINK_SPEED_4GHZ:
6659 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05006660 break;
James Smart76a95d72010-11-20 23:11:48 -05006661 case LPFC_LINK_SPEED_8GHZ:
6662 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04006663 break;
James Smart76a95d72010-11-20 23:11:48 -05006664 case LPFC_LINK_SPEED_10GHZ:
6665 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04006666 break;
James Smart76a95d72010-11-20 23:11:48 -05006667 case LPFC_LINK_SPEED_16GHZ:
6668 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
6669 break;
James Smartd38dd522015-08-31 16:48:17 -04006670 case LPFC_LINK_SPEED_32GHZ:
6671 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
6672 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08006673 case LPFC_LINK_SPEED_64GHZ:
6674 fc_host_speed(shost) = FC_PORTSPEED_64GBIT;
6675 break;
James Smart1dc5ec22018-10-23 13:41:11 -07006676 case LPFC_LINK_SPEED_128GHZ:
6677 fc_host_speed(shost) = FC_PORTSPEED_128GBIT;
6678 break;
James Smart76a95d72010-11-20 23:11:48 -05006679 default:
6680 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05006681 break;
6682 }
James Smartb615a202018-07-31 17:23:19 -07006683 } else if (lpfc_is_link_up(phba) && (phba->hba_flag & HBA_FCOE_MODE)) {
6684 switch (phba->fc_linkspeed) {
6685 case LPFC_ASYNC_LINK_SPEED_10GBPS:
6686 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6687 break;
6688 case LPFC_ASYNC_LINK_SPEED_25GBPS:
6689 fc_host_speed(shost) = FC_PORTSPEED_25GBIT;
6690 break;
6691 case LPFC_ASYNC_LINK_SPEED_40GBPS:
6692 fc_host_speed(shost) = FC_PORTSPEED_40GBIT;
6693 break;
6694 case LPFC_ASYNC_LINK_SPEED_100GBPS:
6695 fc_host_speed(shost) = FC_PORTSPEED_100GBIT;
6696 break;
6697 default:
6698 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6699 break;
6700 }
James Smart09372822008-01-11 01:52:54 -05006701 } else
6702 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05006703
6704 spin_unlock_irq(shost->host_lock);
6705}
6706
James Smarte59058c2008-08-24 21:49:00 -04006707/**
James Smart3621a712009-04-06 18:47:14 -04006708 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04006709 * @shost: kernel scsi host pointer.
6710 **/
dea31012005-04-17 16:05:31 -05006711static void
6712lpfc_get_host_fabric_name (struct Scsi_Host *shost)
6713{
James Smart2e0fef82007-06-17 19:56:36 -05006714 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6715 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07006716 u64 node_name;
dea31012005-04-17 16:05:31 -05006717
6718 spin_lock_irq(shost->host_lock);
6719
James Smart73d91e52011-10-10 21:32:10 -04006720 if ((vport->port_state > LPFC_FLOGI) &&
6721 ((vport->fc_flag & FC_FABRIC) ||
6722 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
6723 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07006724 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05006725 else
6726 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05006727 node_name = 0;
dea31012005-04-17 16:05:31 -05006728
6729 spin_unlock_irq(shost->host_lock);
6730
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07006731 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05006732}
6733
James Smarte59058c2008-08-24 21:49:00 -04006734/**
James Smart3621a712009-04-06 18:47:14 -04006735 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04006736 * @shost: kernel scsi host pointer.
6737 *
6738 * Notes:
6739 * NULL on error for link down, no mbox pool, sli2 active,
6740 * management not allowed, memory allocation error, or mbox error.
6741 *
6742 * Returns:
6743 * NULL for error
6744 * address of the adapter host statistics
6745 **/
dea31012005-04-17 16:05:31 -05006746static struct fc_host_statistics *
6747lpfc_get_stats(struct Scsi_Host *shost)
6748{
James Smart2e0fef82007-06-17 19:56:36 -05006749 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6750 struct lpfc_hba *phba = vport->phba;
6751 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04006752 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04006753 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05006754 LPFC_MBOXQ_t *pmboxq;
6755 MAILBOX_t *pmb;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04006756 int rc = 0;
dea31012005-04-17 16:05:31 -05006757
James Smart92d7f7b2007-06-17 19:56:38 -05006758 /*
6759 * prevent udev from issuing mailbox commands until the port is
6760 * configured.
6761 */
James Smart2e0fef82007-06-17 19:56:36 -05006762 if (phba->link_state < LPFC_LINK_DOWN ||
6763 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04006764 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05006765 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05006766
6767 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04006768 return NULL;
6769
dea31012005-04-17 16:05:31 -05006770 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6771 if (!pmboxq)
6772 return NULL;
6773 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6774
James Smart04c68492009-05-22 14:52:52 -04006775 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05006776 pmb->mbxCommand = MBX_READ_STATUS;
6777 pmb->mbxOwner = OWN_HOST;
James Smart3e1f0712018-11-29 16:09:29 -08006778 pmboxq->ctx_buf = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006779 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05006780
James Smart75baf692010-06-08 18:31:21 -04006781 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05006782 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04006783 else
dea31012005-04-17 16:05:31 -05006784 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6785
6786 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05006787 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04006788 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05006789 return NULL;
6790 }
6791
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04006792 memset(hs, 0, sizeof (struct fc_host_statistics));
6793
dea31012005-04-17 16:05:31 -05006794 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04006795 /*
6796 * The MBX_READ_STATUS returns tx_k_bytes which has to
6797 * converted to words
6798 */
6799 hs->tx_words = (uint64_t)
6800 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
6801 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05006802 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04006803 hs->rx_words = (uint64_t)
6804 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
6805 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05006806
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04006807 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05006808 pmb->mbxCommand = MBX_READ_LNK_STAT;
6809 pmb->mbxOwner = OWN_HOST;
James Smart3e1f0712018-11-29 16:09:29 -08006810 pmboxq->ctx_buf = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006811 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05006812
James Smart75baf692010-06-08 18:31:21 -04006813 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05006814 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04006815 else
dea31012005-04-17 16:05:31 -05006816 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6817
6818 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05006819 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05006820 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05006821 return NULL;
6822 }
6823
6824 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6825 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6826 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6827 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6828 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6829 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6830 hs->error_frames = pmb->un.varRdLnk.crcCnt;
6831
James Smart64ba8812006-08-02 15:24:34 -04006832 hs->link_failure_count -= lso->link_failure_count;
6833 hs->loss_of_sync_count -= lso->loss_of_sync_count;
6834 hs->loss_of_signal_count -= lso->loss_of_signal_count;
6835 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
6836 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
6837 hs->invalid_crc_count -= lso->invalid_crc_count;
6838 hs->error_frames -= lso->error_frames;
6839
James Smart76a95d72010-11-20 23:11:48 -05006840 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04006841 hs->lip_count = -1;
6842 hs->nos_count = (phba->link_events >> 1);
6843 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05006844 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05006845 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04006846 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05006847 hs->nos_count = -1;
6848 } else {
6849 hs->lip_count = -1;
6850 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04006851 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05006852 }
6853
6854 hs->dumped_frames = -1;
6855
Arnd Bergmannc4d6204d2018-06-18 17:28:23 +02006856 hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;
dea31012005-04-17 16:05:31 -05006857
James Smart1dcb58e2007-04-25 09:51:30 -04006858 mempool_free(pmboxq, phba->mbox_mem_pool);
6859
dea31012005-04-17 16:05:31 -05006860 return hs;
6861}
6862
James Smarte59058c2008-08-24 21:49:00 -04006863/**
James Smart3621a712009-04-06 18:47:14 -04006864 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04006865 * @shost: kernel scsi host pointer.
6866 **/
James Smart64ba8812006-08-02 15:24:34 -04006867static void
6868lpfc_reset_stats(struct Scsi_Host *shost)
6869{
James Smart2e0fef82007-06-17 19:56:36 -05006870 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6871 struct lpfc_hba *phba = vport->phba;
6872 struct lpfc_sli *psli = &phba->sli;
6873 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04006874 LPFC_MBOXQ_t *pmboxq;
6875 MAILBOX_t *pmb;
6876 int rc = 0;
6877
James Smart2e0fef82007-06-17 19:56:36 -05006878 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04006879 return;
6880
James Smart64ba8812006-08-02 15:24:34 -04006881 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6882 if (!pmboxq)
6883 return;
6884 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6885
James Smart04c68492009-05-22 14:52:52 -04006886 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04006887 pmb->mbxCommand = MBX_READ_STATUS;
6888 pmb->mbxOwner = OWN_HOST;
6889 pmb->un.varWords[0] = 0x1; /* reset request */
James Smart3e1f0712018-11-29 16:09:29 -08006890 pmboxq->ctx_buf = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006891 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04006892
James Smart2e0fef82007-06-17 19:56:36 -05006893 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04006894 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04006895 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6896 else
6897 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6898
6899 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05006900 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04006901 mempool_free(pmboxq, phba->mbox_mem_pool);
6902 return;
6903 }
6904
6905 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6906 pmb->mbxCommand = MBX_READ_LNK_STAT;
6907 pmb->mbxOwner = OWN_HOST;
James Smart3e1f0712018-11-29 16:09:29 -08006908 pmboxq->ctx_buf = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006909 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04006910
James Smart2e0fef82007-06-17 19:56:36 -05006911 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04006912 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04006913 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6914 else
6915 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6916
6917 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05006918 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04006919 mempool_free( pmboxq, phba->mbox_mem_pool);
6920 return;
6921 }
6922
6923 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6924 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6925 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6926 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6927 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6928 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6929 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05006930 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04006931 lso->link_events = (phba->link_events >> 1);
6932 else
6933 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04006934
Arnd Bergmannc4d6204d2018-06-18 17:28:23 +02006935 psli->stats_start = ktime_get_seconds();
James Smart64ba8812006-08-02 15:24:34 -04006936
James Smart1dcb58e2007-04-25 09:51:30 -04006937 mempool_free(pmboxq, phba->mbox_mem_pool);
6938
James Smart64ba8812006-08-02 15:24:34 -04006939 return;
6940}
dea31012005-04-17 16:05:31 -05006941
6942/*
6943 * The LPFC driver treats linkdown handling as target loss events so there
6944 * are no sysfs handlers for link_down_tmo.
6945 */
James Smart685f0bf2007-04-25 09:53:08 -04006946
James Smarte59058c2008-08-24 21:49:00 -04006947/**
James Smart3621a712009-04-06 18:47:14 -04006948 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04006949 * @starget: kernel scsi target pointer.
6950 *
6951 * Returns:
6952 * address of the node list if found
6953 * NULL target not found
6954 **/
James Smart685f0bf2007-04-25 09:53:08 -04006955static struct lpfc_nodelist *
6956lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05006957{
James Smart2e0fef82007-06-17 19:56:36 -05006958 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
6959 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04006960 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006961
6962 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04006963 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05006964 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05006965 if (NLP_CHK_NODE_ACT(ndlp) &&
6966 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04006967 starget->id == ndlp->nlp_sid) {
6968 spin_unlock_irq(shost->host_lock);
6969 return ndlp;
dea31012005-04-17 16:05:31 -05006970 }
6971 }
6972 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04006973 return NULL;
6974}
dea31012005-04-17 16:05:31 -05006975
James Smarte59058c2008-08-24 21:49:00 -04006976/**
James Smart3621a712009-04-06 18:47:14 -04006977 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04006978 * @starget: kernel scsi target pointer.
6979 **/
James Smart685f0bf2007-04-25 09:53:08 -04006980static void
6981lpfc_get_starget_port_id(struct scsi_target *starget)
6982{
6983 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6984
6985 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05006986}
6987
James Smarte59058c2008-08-24 21:49:00 -04006988/**
James Smart3621a712009-04-06 18:47:14 -04006989 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04006990 * @starget: kernel scsi target pointer.
6991 *
6992 * Description: Set the target node name to the ndlp node name wwn or zero.
6993 **/
dea31012005-04-17 16:05:31 -05006994static void
6995lpfc_get_starget_node_name(struct scsi_target *starget)
6996{
James Smart685f0bf2007-04-25 09:53:08 -04006997 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05006998
James Smart685f0bf2007-04-25 09:53:08 -04006999 fc_starget_node_name(starget) =
7000 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05007001}
7002
James Smarte59058c2008-08-24 21:49:00 -04007003/**
James Smart3621a712009-04-06 18:47:14 -04007004 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04007005 * @starget: kernel scsi target pointer.
7006 *
7007 * Description: set the target port name to the ndlp port name wwn or zero.
7008 **/
dea31012005-04-17 16:05:31 -05007009static void
7010lpfc_get_starget_port_name(struct scsi_target *starget)
7011{
James Smart685f0bf2007-04-25 09:53:08 -04007012 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05007013
James Smart685f0bf2007-04-25 09:53:08 -04007014 fc_starget_port_name(starget) =
7015 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05007016}
7017
James Smarte59058c2008-08-24 21:49:00 -04007018/**
James Smart3621a712009-04-06 18:47:14 -04007019 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04007020 * @rport: fc rport address.
7021 * @timeout: new value for dev loss tmo.
7022 *
7023 * Description:
7024 * If timeout is non zero set the dev_loss_tmo to timeout, else set
7025 * dev_loss_tmo to one.
7026 **/
dea31012005-04-17 16:05:31 -05007027static void
dea31012005-04-17 16:05:31 -05007028lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
7029{
James Smarta643c6d2019-08-14 16:56:48 -07007030 struct lpfc_rport_data *rdata = rport->dd_data;
7031 struct lpfc_nodelist *ndlp = rdata->pnode;
7032#if (IS_ENABLED(CONFIG_NVME_FC))
7033 struct lpfc_nvme_rport *nrport = NULL;
7034#endif
7035
dea31012005-04-17 16:05:31 -05007036 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04007037 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05007038 else
James Smartc01f3202006-08-18 17:47:08 -04007039 rport->dev_loss_tmo = 1;
James Smarta643c6d2019-08-14 16:56:48 -07007040
7041 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
7042 dev_info(&rport->dev, "Cannot find remote node to "
7043 "set rport dev loss tmo, port_id x%x\n",
7044 rport->port_id);
7045 return;
7046 }
7047
7048#if (IS_ENABLED(CONFIG_NVME_FC))
7049 nrport = lpfc_ndlp_get_nrport(ndlp);
7050
7051 if (nrport && nrport->remoteport)
7052 nvme_fc_set_remoteport_devloss(nrport->remoteport,
7053 rport->dev_loss_tmo);
7054#endif
dea31012005-04-17 16:05:31 -05007055}
7056
James Smarte59058c2008-08-24 21:49:00 -04007057/**
James Smart3621a712009-04-06 18:47:14 -04007058 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04007059 *
7060 * Description:
7061 * Macro that uses field to generate a function with the name lpfc_show_rport_
7062 *
7063 * lpfc_show_rport_##field: returns the bytes formatted in buf
7064 * @cdev: class converted to an fc_rport.
7065 * @buf: on return contains the target_field or zero.
7066 *
7067 * Returns: size of formatted string.
7068 **/
dea31012005-04-17 16:05:31 -05007069#define lpfc_rport_show_function(field, format_string, sz, cast) \
7070static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01007071lpfc_show_rport_##field (struct device *dev, \
7072 struct device_attribute *attr, \
7073 char *buf) \
dea31012005-04-17 16:05:31 -05007074{ \
Tony Jonesee959b02008-02-22 00:13:36 +01007075 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05007076 struct lpfc_rport_data *rdata = rport->hostdata; \
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07007077 return scnprintf(buf, sz, format_string, \
dea31012005-04-17 16:05:31 -05007078 (rdata->target) ? cast rdata->target->field : 0); \
7079}
7080
7081#define lpfc_rport_rd_attr(field, format_string, sz) \
7082 lpfc_rport_show_function(field, format_string, sz, ) \
7083static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
7084
James Smarteada2722008-12-04 22:39:13 -05007085/**
James Smart3621a712009-04-06 18:47:14 -04007086 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05007087 * @fc_vport: The fc_vport who's symbolic name has been changed.
7088 *
7089 * Description:
7090 * This function is called by the transport after the @fc_vport's symbolic name
7091 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007092 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05007093 **/
7094static void
7095lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
7096{
7097 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
7098
7099 if (vport->port_state == LPFC_VPORT_READY)
7100 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
7101}
dea31012005-04-17 16:05:31 -05007102
James Smartf4b4c682009-05-22 14:53:12 -04007103/**
7104 * lpfc_hba_log_verbose_init - Set hba's log verbose level
7105 * @phba: Pointer to lpfc_hba struct.
7106 *
7107 * This function is called by the lpfc_get_cfgparam() routine to set the
7108 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02007109 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04007110 * before hba port or vport created.
7111 **/
7112static void
7113lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
7114{
7115 phba->cfg_log_verbose = verbose;
7116}
7117
dea31012005-04-17 16:05:31 -05007118struct fc_function_template lpfc_transport_functions = {
7119 /* fixed attributes the driver supports */
7120 .show_host_node_name = 1,
7121 .show_host_port_name = 1,
7122 .show_host_supported_classes = 1,
7123 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05007124 .show_host_supported_speeds = 1,
7125 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08007126
7127 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05007128 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05007129
7130 /* dynamic attributes the driver supports */
7131 .get_host_port_id = lpfc_get_host_port_id,
7132 .show_host_port_id = 1,
7133
7134 .get_host_port_type = lpfc_get_host_port_type,
7135 .show_host_port_type = 1,
7136
7137 .get_host_port_state = lpfc_get_host_port_state,
7138 .show_host_port_state = 1,
7139
7140 /* active_fc4s is shown but doesn't change (thus no get function) */
7141 .show_host_active_fc4s = 1,
7142
7143 .get_host_speed = lpfc_get_host_speed,
7144 .show_host_speed = 1,
7145
7146 .get_host_fabric_name = lpfc_get_host_fabric_name,
7147 .show_host_fabric_name = 1,
7148
7149 /*
7150 * The LPFC driver treats linkdown handling as target loss events
7151 * so there are no sysfs handlers for link_down_tmo.
7152 */
7153
7154 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04007155 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05007156
7157 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
7158 .show_rport_maxframe_size = 1,
7159 .show_rport_supported_classes = 1,
7160
dea31012005-04-17 16:05:31 -05007161 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7162 .show_rport_dev_loss_tmo = 1,
7163
7164 .get_starget_port_id = lpfc_get_starget_port_id,
7165 .show_starget_port_id = 1,
7166
7167 .get_starget_node_name = lpfc_get_starget_node_name,
7168 .show_starget_node_name = 1,
7169
7170 .get_starget_port_name = lpfc_get_starget_port_name,
7171 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07007172
7173 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04007174 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7175 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05007176
James Smart92d7f7b2007-06-17 19:56:38 -05007177 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05007178
7179 .vport_disable = lpfc_vport_disable,
7180
7181 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04007182
7183 .bsg_request = lpfc_bsg_request,
7184 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05007185};
7186
James Smart98c9ea52007-10-27 13:37:33 -04007187struct fc_function_template lpfc_vport_transport_functions = {
7188 /* fixed attributes the driver supports */
7189 .show_host_node_name = 1,
7190 .show_host_port_name = 1,
7191 .show_host_supported_classes = 1,
7192 .show_host_supported_fc4s = 1,
7193 .show_host_supported_speeds = 1,
7194 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08007195
7196 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05007197 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04007198
7199 /* dynamic attributes the driver supports */
7200 .get_host_port_id = lpfc_get_host_port_id,
7201 .show_host_port_id = 1,
7202
7203 .get_host_port_type = lpfc_get_host_port_type,
7204 .show_host_port_type = 1,
7205
7206 .get_host_port_state = lpfc_get_host_port_state,
7207 .show_host_port_state = 1,
7208
7209 /* active_fc4s is shown but doesn't change (thus no get function) */
7210 .show_host_active_fc4s = 1,
7211
7212 .get_host_speed = lpfc_get_host_speed,
7213 .show_host_speed = 1,
7214
7215 .get_host_fabric_name = lpfc_get_host_fabric_name,
7216 .show_host_fabric_name = 1,
7217
7218 /*
7219 * The LPFC driver treats linkdown handling as target loss events
7220 * so there are no sysfs handlers for link_down_tmo.
7221 */
7222
7223 .get_fc_host_stats = lpfc_get_stats,
7224 .reset_fc_host_stats = lpfc_reset_stats,
7225
7226 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
7227 .show_rport_maxframe_size = 1,
7228 .show_rport_supported_classes = 1,
7229
7230 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7231 .show_rport_dev_loss_tmo = 1,
7232
7233 .get_starget_port_id = lpfc_get_starget_port_id,
7234 .show_starget_port_id = 1,
7235
7236 .get_starget_node_name = lpfc_get_starget_node_name,
7237 .show_starget_node_name = 1,
7238
7239 .get_starget_port_name = lpfc_get_starget_port_name,
7240 .show_starget_port_name = 1,
7241
7242 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7243 .terminate_rport_io = lpfc_terminate_rport_io,
7244
7245 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05007246
7247 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04007248};
7249
James Smarte59058c2008-08-24 21:49:00 -04007250/**
James Smart4945c0f2019-08-14 16:57:02 -07007251 * lpfc_get_hba_function_mode - Used to determine the HBA function in FCoE
7252 * Mode
7253 * @phba: lpfc_hba pointer.
7254 **/
7255static void
7256lpfc_get_hba_function_mode(struct lpfc_hba *phba)
7257{
James Smart412e7372019-09-21 20:59:04 -07007258 /* If the adapter supports FCoE mode */
7259 switch (phba->pcidev->device) {
7260 case PCI_DEVICE_ID_SKYHAWK:
7261 case PCI_DEVICE_ID_SKYHAWK_VF:
7262 case PCI_DEVICE_ID_LANCER_FCOE:
7263 case PCI_DEVICE_ID_LANCER_FCOE_VF:
7264 case PCI_DEVICE_ID_ZEPHYR_DCSP:
7265 case PCI_DEVICE_ID_HORNET:
7266 case PCI_DEVICE_ID_TIGERSHARK:
7267 case PCI_DEVICE_ID_TOMCAT:
James Smart4945c0f2019-08-14 16:57:02 -07007268 phba->hba_flag |= HBA_FCOE_MODE;
James Smart412e7372019-09-21 20:59:04 -07007269 break;
7270 default:
7271 /* for others, clear the flag */
James Smart4945c0f2019-08-14 16:57:02 -07007272 phba->hba_flag &= ~HBA_FCOE_MODE;
James Smart412e7372019-09-21 20:59:04 -07007273 }
James Smart4945c0f2019-08-14 16:57:02 -07007274}
7275
7276/**
James Smart3621a712009-04-06 18:47:14 -04007277 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04007278 * @phba: lpfc_hba pointer.
7279 **/
dea31012005-04-17 16:05:31 -05007280void
7281lpfc_get_cfgparam(struct lpfc_hba *phba)
7282{
James Smartdcaa2132019-11-04 16:57:06 -08007283 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart49aa1432012-08-03 12:36:42 -04007284 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smart7ea92eb2018-10-23 13:41:10 -07007285 lpfc_ns_query_init(phba, lpfc_ns_query);
James Smarta6571c62012-10-31 14:44:42 -04007286 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04007287 lpfc_cr_delay_init(phba, lpfc_cr_delay);
7288 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05007289 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05007290 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
7291 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04007292 lpfc_ack0_init(phba, lpfc_ack0);
James Smartc4908502019-01-28 11:14:28 -08007293 lpfc_xri_rebalancing_init(phba, lpfc_xri_rebalancing);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04007294 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04007295 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05007296 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04007297 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04007298 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04007299 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05007300 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4258e982015-12-16 18:11:58 -05007301 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
7302 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
James Smart4ff43242006-12-02 13:34:56 -05007303 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart895427b2017-02-12 13:52:30 -08007304 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
James Smart4e565cf2018-02-22 08:18:50 -08007305 lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);
James Smartda0436e2009-05-22 14:51:39 -04007306 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart41b194b2019-05-14 14:58:08 -07007307 lpfc_force_rscn_init(phba, lpfc_force_rscn);
James Smart32517fc2019-01-28 11:14:33 -08007308 lpfc_cq_poll_threshold_init(phba, lpfc_cq_poll_threshold);
7309 lpfc_cq_max_proc_limit_init(phba, lpfc_cq_max_proc_limit);
James Smart7bb03bb2013-04-17 20:19:16 -04007310 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart13815c82008-01-11 01:52:48 -05007311 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
7312 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart2ea259e2017-02-12 13:52:27 -08007313
James Smart1ba981f2014-02-20 09:56:45 -05007314 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
7315 if (phba->sli_rev != LPFC_SLI_REV4)
7316 phba->cfg_EnableXLane = 0;
7317 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
James Smart2ea259e2017-02-12 13:52:27 -08007318
James Smart1ba981f2014-02-20 09:56:45 -05007319 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
7320 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
7321 phba->cfg_oas_lun_state = 0;
7322 phba->cfg_oas_lun_status = 0;
7323 phba->cfg_oas_flags = 0;
James Smartc92c8412016-07-06 12:36:05 -07007324 phba->cfg_oas_priority = 0;
James Smart81301a92008-12-04 22:39:46 -05007325 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smartb3b98b72016-10-13 15:06:06 -07007326 lpfc_prot_mask_init(phba, lpfc_prot_mask);
7327 lpfc_prot_guard_init(phba, lpfc_prot_guard);
James Smart45ed1192009-10-02 15:17:02 -04007328 if (phba->sli_rev == LPFC_SLI_REV4)
7329 phba->cfg_poll = 0;
7330 else
James Smart1ba981f2014-02-20 09:56:45 -05007331 phba->cfg_poll = lpfc_poll;
James Smartf44ac122018-03-05 12:04:08 -08007332
James Smart4945c0f2019-08-14 16:57:02 -07007333 /* Get the function mode */
7334 lpfc_get_hba_function_mode(phba);
7335
7336 /* BlockGuard allowed for FC only. */
7337 if (phba->cfg_enable_bg && phba->hba_flag & HBA_FCOE_MODE) {
7338 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7339 "0581 BlockGuard feature not supported\n");
7340 /* If set, clear the BlockGuard support param */
7341 phba->cfg_enable_bg = 0;
7342 } else if (phba->cfg_enable_bg) {
James Smartf44ac122018-03-05 12:04:08 -08007343 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
James Smart4945c0f2019-08-14 16:57:02 -07007344 }
James Smartf44ac122018-03-05 12:04:08 -08007345
James Smartf358dd02017-02-12 13:52:34 -08007346 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
James Smart4258e982015-12-16 18:11:58 -05007347
James Smart895427b2017-02-12 13:52:30 -08007348 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
James Smart2d7dbc42017-02-12 13:52:35 -08007349 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
James Smart2448e482018-04-09 14:24:24 -07007350 lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
James Smart895427b2017-02-12 13:52:30 -08007351
7352 /* Initialize first burst. Target vs Initiator are different. */
7353 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
James Smart2d7dbc42017-02-12 13:52:35 -08007354 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
James Smart77ffd342019-08-15 19:36:49 -07007355 lpfc_fcp_mq_threshold_init(phba, lpfc_fcp_mq_threshold);
James Smartcdb42be2019-01-28 11:14:21 -08007356 lpfc_hdw_queue_init(phba, lpfc_hdw_queue);
James Smart6a828b02019-01-28 11:14:31 -08007357 lpfc_irq_chann_init(phba, lpfc_irq_chann);
James Smart44fd7fe2017-08-23 16:55:47 -07007358 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
James Smart1351e692018-02-22 08:18:43 -08007359 lpfc_enable_dpp_init(phba, lpfc_enable_dpp);
James Smart895427b2017-02-12 13:52:30 -08007360
7361 if (phba->sli_rev != LPFC_SLI_REV4) {
7362 /* NVME only supported on SLI4 */
7363 phba->nvmet_support = 0;
James Smart982ab122019-03-12 16:30:10 -07007364 phba->cfg_nvmet_mrq = 0;
James Smart895427b2017-02-12 13:52:30 -08007365 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
James Smart44fd7fe2017-08-23 16:55:47 -07007366 phba->cfg_enable_bbcr = 0;
James Smartc4908502019-01-28 11:14:28 -08007367 phba->cfg_xri_rebalancing = 0;
James Smart895427b2017-02-12 13:52:30 -08007368 } else {
7369 /* We MUST have FCP support */
7370 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
7371 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
7372 }
7373
James Smart32517fc2019-01-28 11:14:33 -08007374 phba->cfg_auto_imax = (phba->cfg_fcp_imax) ? 0 : 1;
James Smart0cf07f842017-06-01 21:07:10 -07007375
James Smart06b6fa382018-07-31 17:23:24 -07007376 phba->cfg_enable_pbde = 0;
7377
James Smart895427b2017-02-12 13:52:30 -08007378 /* A value of 0 means use the number of CPUs found in the system */
James Smartcdb42be2019-01-28 11:14:21 -08007379 if (phba->cfg_hdw_queue == 0)
7380 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
James Smart6a828b02019-01-28 11:14:31 -08007381 if (phba->cfg_irq_chann == 0)
7382 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7383 if (phba->cfg_irq_chann > phba->cfg_hdw_queue)
7384 phba->cfg_irq_chann = phba->cfg_hdw_queue;
James Smart4258e982015-12-16 18:11:58 -05007385
James Smart352e5fd2016-12-30 06:57:47 -08007386 phba->cfg_soft_wwnn = 0L;
7387 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05007388 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04007389 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart0d878412009-10-02 15:16:56 -04007390 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04007391 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04007392 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05007393 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart8eb8b962016-07-06 12:36:08 -07007394 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
James Smart12247e82016-07-06 12:36:09 -07007395 lpfc_sli_mode_init(phba, lpfc_sli_mode);
James Smart7bdedb32016-07-06 12:36:00 -07007396 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
James Smartd2cc9bc2018-09-10 10:30:50 -07007397 lpfc_ras_fwlog_buffsize_init(phba, lpfc_ras_fwlog_buffsize);
7398 lpfc_ras_fwlog_level_init(phba, lpfc_ras_fwlog_level);
7399 lpfc_ras_fwlog_func_init(phba, lpfc_ras_fwlog_func);
7400
James Smart3de2a652007-08-02 11:09:59 -04007401 return;
7402}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05007403
James Smarte59058c2008-08-24 21:49:00 -04007404/**
James Smart895427b2017-02-12 13:52:30 -08007405 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
7406 * dependencies between protocols and roles.
7407 * @phba: lpfc_hba pointer.
7408 **/
7409void
7410lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
7411{
James Smartcdb42be2019-01-28 11:14:21 -08007412 if (phba->cfg_hdw_queue > phba->sli4_hba.num_present_cpu)
7413 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
James Smart6a828b02019-01-28 11:14:31 -08007414 if (phba->cfg_irq_chann > phba->sli4_hba.num_present_cpu)
7415 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7416 if (phba->cfg_irq_chann > phba->cfg_hdw_queue)
7417 phba->cfg_irq_chann = phba->cfg_hdw_queue;
James Smart895427b2017-02-12 13:52:30 -08007418
James Smartf358dd02017-02-12 13:52:34 -08007419 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
7420 phba->nvmet_support) {
7421 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
James Smart2d7dbc42017-02-12 13:52:35 -08007422
7423 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
7424 "6013 %s x%x fb_size x%x, fb_max x%x\n",
7425 "NVME Target PRLI ACC enable_fb ",
7426 phba->cfg_nvme_enable_fb,
7427 phba->cfg_nvmet_fb_size,
7428 LPFC_NVMET_FB_SZ_MAX);
7429
7430 if (phba->cfg_nvme_enable_fb == 0)
7431 phba->cfg_nvmet_fb_size = 0;
7432 else {
7433 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
7434 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
7435 }
7436
James Smartbcb24f62017-11-20 16:00:36 -08007437 if (!phba->cfg_nvmet_mrq)
James Smart97a9ed32019-10-18 14:18:17 -07007438 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
James Smartbcb24f62017-11-20 16:00:36 -08007439
James Smart2d7dbc42017-02-12 13:52:35 -08007440 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
James Smart97a9ed32019-10-18 14:18:17 -07007441 if (phba->cfg_nvmet_mrq > phba->cfg_hdw_queue) {
7442 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
James Smart2d7dbc42017-02-12 13:52:35 -08007443 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
7444 "6018 Adjust lpfc_nvmet_mrq to %d\n",
7445 phba->cfg_nvmet_mrq);
7446 }
James Smartbcb24f62017-11-20 16:00:36 -08007447 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
7448 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
7449
James Smart2d7dbc42017-02-12 13:52:35 -08007450 } else {
James Smartf358dd02017-02-12 13:52:34 -08007451 /* Not NVME Target mode. Turn off Target parameters. */
7452 phba->nvmet_support = 0;
James Smart982ab122019-03-12 16:30:10 -07007453 phba->cfg_nvmet_mrq = 0;
James Smart2d7dbc42017-02-12 13:52:35 -08007454 phba->cfg_nvmet_fb_size = 0;
7455 }
James Smart895427b2017-02-12 13:52:30 -08007456}
7457
7458/**
James Smart3621a712009-04-06 18:47:14 -04007459 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04007460 * @vport: lpfc_vport pointer.
7461 **/
James Smart3de2a652007-08-02 11:09:59 -04007462void
7463lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
7464{
James Smarte8b62012007-08-02 11:10:09 -04007465 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04007466 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04007467 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04007468 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
7469 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
7470 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
7471 lpfc_restrict_login_init(vport, lpfc_restrict_login);
7472 lpfc_fcp_class_init(vport, lpfc_fcp_class);
7473 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04007474 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04007475 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04007476 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
7477 lpfc_max_luns_init(vport, lpfc_max_luns);
7478 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04007479 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05007480 return;
7481}