blob: 513ac1be861fb2119bece4e9a547fcfec68f2363 [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 Smart128bdda2018-01-30 15:59:03 -08004 * Copyright (C) 2017-2018 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 Smartafff0d22018-06-26 08:24:22 -070067#define LPFC_MAX_NVME_INFO_TMP_LEN 100
68#define LPFC_NVME_INFO_MORE_STR "\nCould be more info...\n"
69
James Smartf7a919b2011-08-21 21:49:16 -040070/*
71 * Write key size should be multiple of 4. If write key is changed
72 * make sure that library write key is also changed.
73 */
74#define LPFC_REG_WRITE_KEY_SIZE 4
75#define LPFC_REG_WRITE_KEY "EMLX"
76
James Smarte59058c2008-08-24 21:49:00 -040077/**
James Smart3621a712009-04-06 18:47:14 -040078 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040079 * @incr: integer to convert.
80 * @hdw: ascii string holding converted integer plus a string terminator.
81 *
82 * Description:
83 * JEDEC Joint Electron Device Engineering Council.
84 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
85 * character string. The string is then terminated with a NULL in byte 9.
86 * Hex 0-9 becomes ascii '0' to '9'.
87 * Hex a-f becomes ascii '=' to 'B' capital B.
88 *
89 * Notes:
90 * Coded for 32 bit integers only.
91 **/
dea31012005-04-17 16:05:31 -050092static void
93lpfc_jedec_to_ascii(int incr, char hdw[])
94{
95 int i, j;
96 for (i = 0; i < 8; i++) {
97 j = (incr & 0xf);
98 if (j <= 9)
99 hdw[7 - i] = 0x30 + j;
100 else
101 hdw[7 - i] = 0x61 + j - 10;
102 incr = (incr >> 4);
103 }
104 hdw[8] = 0;
105 return;
106}
107
James Smarte59058c2008-08-24 21:49:00 -0400108/**
James Smart3621a712009-04-06 18:47:14 -0400109 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -0400110 * @dev: class unused variable.
111 * @attr: device attribute, not used.
112 * @buf: on return contains the module description text.
113 *
114 * Returns: size of formatted string.
115 **/
dea31012005-04-17 16:05:31 -0500116static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100117lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
118 char *buf)
dea31012005-04-17 16:05:31 -0500119{
120 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
121}
122
James Smart45ed1192009-10-02 15:17:02 -0400123/**
124 * lpfc_enable_fip_show - Return the fip mode of the HBA
125 * @dev: class unused variable.
126 * @attr: device attribute, not used.
127 * @buf: on return contains the module description text.
128 *
129 * Returns: size of formatted string.
130 **/
131static ssize_t
132lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
133 char *buf)
134{
135 struct Scsi_Host *shost = class_to_shost(dev);
136 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
137 struct lpfc_hba *phba = vport->phba;
138
139 if (phba->hba_flag & HBA_FIP_SUPPORT)
140 return snprintf(buf, PAGE_SIZE, "1\n");
141 else
142 return snprintf(buf, PAGE_SIZE, "0\n");
143}
144
James Smart81301a92008-12-04 22:39:46 -0500145static ssize_t
James Smart895427b2017-02-12 13:52:30 -0800146lpfc_nvme_info_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 = shost_priv(shost);
151 struct lpfc_hba *phba = vport->phba;
James Smartf358dd02017-02-12 13:52:34 -0800152 struct lpfc_nvmet_tgtport *tgtp;
James Smart895427b2017-02-12 13:52:30 -0800153 struct nvme_fc_local_port *localport;
James Smart4b056682017-12-08 17:18:10 -0800154 struct lpfc_nvme_lport *lport;
James Smart01466022018-04-09 14:24:27 -0700155 struct lpfc_nvme_rport *rport;
James Smart80cc0042017-06-01 21:06:56 -0700156 struct lpfc_nodelist *ndlp;
James Smart895427b2017-02-12 13:52:30 -0800157 struct nvme_fc_remote_port *nrport;
James Smart66a210f2018-04-09 14:24:23 -0700158 struct lpfc_nvme_ctrl_stat *cstat;
159 uint64_t data1, data2, data3;
160 uint64_t totin, totout, tot;
James Smart895427b2017-02-12 13:52:30 -0800161 char *statep;
James Smart66a210f2018-04-09 14:24:23 -0700162 int i;
James Smart895427b2017-02-12 13:52:30 -0800163 int len = 0;
James Smartafff0d22018-06-26 08:24:22 -0700164 char tmp[LPFC_MAX_NVME_INFO_TMP_LEN] = {0};
James Smart895427b2017-02-12 13:52:30 -0800165
166 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
James Smartafff0d22018-06-26 08:24:22 -0700167 len = scnprintf(buf, PAGE_SIZE, "NVME Disabled\n");
James Smart895427b2017-02-12 13:52:30 -0800168 return len;
169 }
James Smartf358dd02017-02-12 13:52:34 -0800170 if (phba->nvmet_support) {
171 if (!phba->targetport) {
James Smartafff0d22018-06-26 08:24:22 -0700172 len = scnprintf(buf, PAGE_SIZE,
James Smartf358dd02017-02-12 13:52:34 -0800173 "NVME Target: x%llx is not allocated\n",
174 wwn_to_u64(vport->fc_portname.u.wwn));
175 return len;
176 }
177 /* Port state is only one of two values for now. */
178 if (phba->targetport->port_id)
179 statep = "REGISTERED";
180 else
181 statep = "INIT";
James Smartafff0d22018-06-26 08:24:22 -0700182 scnprintf(tmp, sizeof(tmp),
183 "NVME Target Enabled State %s\n",
184 statep);
185 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
186 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800187
James Smartafff0d22018-06-26 08:24:22 -0700188 scnprintf(tmp, sizeof(tmp),
189 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
190 "NVME Target: lpfc",
191 phba->brd_no,
192 wwn_to_u64(vport->fc_portname.u.wwn),
193 wwn_to_u64(vport->fc_nodename.u.wwn),
194 phba->targetport->port_id);
195 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
196 goto buffer_done;
197
198 if (strlcat(buf, "\nNVME Target: Statistics\n", PAGE_SIZE)
199 >= PAGE_SIZE)
200 goto buffer_done;
201
James Smartf358dd02017-02-12 13:52:34 -0800202 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
James Smartafff0d22018-06-26 08:24:22 -0700203 scnprintf(tmp, sizeof(tmp),
204 "LS: Rcv %08x Drop %08x Abort %08x\n",
205 atomic_read(&tgtp->rcv_ls_req_in),
206 atomic_read(&tgtp->rcv_ls_req_drop),
207 atomic_read(&tgtp->xmt_ls_abort));
208 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
209 goto buffer_done;
210
James Smartf358dd02017-02-12 13:52:34 -0800211 if (atomic_read(&tgtp->rcv_ls_req_in) !=
212 atomic_read(&tgtp->rcv_ls_req_out)) {
James Smartafff0d22018-06-26 08:24:22 -0700213 scnprintf(tmp, sizeof(tmp),
214 "Rcv LS: in %08x != out %08x\n",
215 atomic_read(&tgtp->rcv_ls_req_in),
216 atomic_read(&tgtp->rcv_ls_req_out));
217 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
218 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800219 }
220
James Smartafff0d22018-06-26 08:24:22 -0700221 scnprintf(tmp, sizeof(tmp),
222 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
223 atomic_read(&tgtp->xmt_ls_rsp),
224 atomic_read(&tgtp->xmt_ls_drop),
225 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
226 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
227 goto buffer_done;
James Smart4b056682017-12-08 17:18:10 -0800228
James Smartafff0d22018-06-26 08:24:22 -0700229 scnprintf(tmp, sizeof(tmp),
230 "LS: RSP Abort %08x xb %08x Err %08x\n",
231 atomic_read(&tgtp->xmt_ls_rsp_aborted),
232 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
233 atomic_read(&tgtp->xmt_ls_rsp_error));
234 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
235 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800236
James Smartafff0d22018-06-26 08:24:22 -0700237 scnprintf(tmp, sizeof(tmp),
238 "FCP: Rcv %08x Defer %08x Release %08x "
239 "Drop %08x\n",
240 atomic_read(&tgtp->rcv_fcp_cmd_in),
241 atomic_read(&tgtp->rcv_fcp_cmd_defer),
242 atomic_read(&tgtp->xmt_fcp_release),
243 atomic_read(&tgtp->rcv_fcp_cmd_drop));
244 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
245 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800246
247 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
248 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
James Smartafff0d22018-06-26 08:24:22 -0700249 scnprintf(tmp, sizeof(tmp),
250 "Rcv FCP: in %08x != out %08x\n",
251 atomic_read(&tgtp->rcv_fcp_cmd_in),
252 atomic_read(&tgtp->rcv_fcp_cmd_out));
253 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
254 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800255 }
256
James Smartafff0d22018-06-26 08:24:22 -0700257 scnprintf(tmp, sizeof(tmp),
258 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
259 "drop %08x\n",
260 atomic_read(&tgtp->xmt_fcp_read),
261 atomic_read(&tgtp->xmt_fcp_read_rsp),
262 atomic_read(&tgtp->xmt_fcp_write),
263 atomic_read(&tgtp->xmt_fcp_rsp),
264 atomic_read(&tgtp->xmt_fcp_drop));
265 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
266 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800267
James Smartafff0d22018-06-26 08:24:22 -0700268 scnprintf(tmp, sizeof(tmp),
269 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
270 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
271 atomic_read(&tgtp->xmt_fcp_rsp_error),
272 atomic_read(&tgtp->xmt_fcp_rsp_drop));
273 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
274 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800275
James Smartafff0d22018-06-26 08:24:22 -0700276 scnprintf(tmp, sizeof(tmp),
277 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
278 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
279 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
280 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
281 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
282 goto buffer_done;
James Smart4b056682017-12-08 17:18:10 -0800283
James Smartafff0d22018-06-26 08:24:22 -0700284 scnprintf(tmp, sizeof(tmp),
285 "ABORT: Xmt %08x Cmpl %08x\n",
286 atomic_read(&tgtp->xmt_fcp_abort),
287 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
288 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
289 goto buffer_done;
James Smart547077a2017-05-15 15:20:40 -0700290
James Smartafff0d22018-06-26 08:24:22 -0700291 scnprintf(tmp, sizeof(tmp),
292 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x\n",
293 atomic_read(&tgtp->xmt_abort_sol),
294 atomic_read(&tgtp->xmt_abort_unsol),
295 atomic_read(&tgtp->xmt_abort_rsp),
296 atomic_read(&tgtp->xmt_abort_rsp_error));
297 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
298 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800299
James Smartafff0d22018-06-26 08:24:22 -0700300 scnprintf(tmp, sizeof(tmp),
301 "DELAY: ctx %08x fod %08x wqfull %08x\n",
302 atomic_read(&tgtp->defer_ctx),
303 atomic_read(&tgtp->defer_fod),
304 atomic_read(&tgtp->defer_wqfull));
305 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
306 goto buffer_done;
James Smart411de512018-01-30 15:58:52 -0800307
Dick Kennedy66d7ce92017-08-23 16:55:42 -0700308 /* Calculate outstanding IOs */
309 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
310 tot += atomic_read(&tgtp->xmt_fcp_release);
311 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
James Smart2cee7802017-06-01 21:07:02 -0700312
James Smartafff0d22018-06-26 08:24:22 -0700313 scnprintf(tmp, sizeof(tmp),
314 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
315 "CTX Outstanding %08llx\n\n",
316 phba->sli4_hba.nvmet_xri_cnt,
317 phba->sli4_hba.nvmet_io_wait_cnt,
318 phba->sli4_hba.nvmet_io_wait_total,
319 tot);
320 strlcat(buf, tmp, PAGE_SIZE);
321 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800322 }
James Smart895427b2017-02-12 13:52:30 -0800323
324 localport = vport->localport;
325 if (!localport) {
James Smartafff0d22018-06-26 08:24:22 -0700326 len = scnprintf(buf, PAGE_SIZE,
James Smart895427b2017-02-12 13:52:30 -0800327 "NVME Initiator x%llx is not allocated\n",
328 wwn_to_u64(vport->fc_portname.u.wwn));
329 return len;
330 }
Colin Ian King5c665ae2017-12-22 00:28:52 +0000331 lport = (struct lpfc_nvme_lport *)localport->private;
James Smartafff0d22018-06-26 08:24:22 -0700332 if (strlcat(buf, "\nNVME Initiator Enabled\n", PAGE_SIZE) >= PAGE_SIZE)
333 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800334
James Smartafff0d22018-06-26 08:24:22 -0700335 rcu_read_lock();
336 scnprintf(tmp, sizeof(tmp),
337 "XRI Dist lpfc%d Total %d NVME %d SCSI %d ELS %d\n",
338 phba->brd_no,
339 phba->sli4_hba.max_cfg_param.max_xri,
340 phba->sli4_hba.nvme_xri_max,
341 phba->sli4_hba.scsi_xri_max,
342 lpfc_sli4_get_els_iocb_cnt(phba));
343 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
344 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800345
346 /* Port state is only one of two values for now. */
347 if (localport->port_id)
348 statep = "ONLINE";
349 else
350 statep = "UNKNOWN ";
351
James Smartafff0d22018-06-26 08:24:22 -0700352 scnprintf(tmp, sizeof(tmp),
353 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
354 "NVME LPORT lpfc",
355 phba->brd_no,
356 wwn_to_u64(vport->fc_portname.u.wwn),
357 wwn_to_u64(vport->fc_nodename.u.wwn),
358 localport->port_id, statep);
359 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
360 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800361
James Smart80cc0042017-06-01 21:06:56 -0700362 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart9e210172018-09-13 15:41:10 -0700363 nrport = NULL;
364 spin_lock(&vport->phba->hbalock);
James Smart01466022018-04-09 14:24:27 -0700365 rport = lpfc_ndlp_get_nrport(ndlp);
James Smart9e210172018-09-13 15:41:10 -0700366 if (rport)
367 nrport = rport->remoteport;
368 spin_unlock(&vport->phba->hbalock);
James Smart01466022018-04-09 14:24:27 -0700369 if (!nrport)
370 continue;
James Smart895427b2017-02-12 13:52:30 -0800371
372 /* Port state is only one of two values for now. */
373 switch (nrport->port_state) {
374 case FC_OBJSTATE_ONLINE:
375 statep = "ONLINE";
376 break;
377 case FC_OBJSTATE_UNKNOWN:
378 statep = "UNKNOWN ";
379 break;
380 default:
381 statep = "UNSUPPORTED";
382 break;
383 }
384
385 /* Tab in to show lport ownership. */
James Smartafff0d22018-06-26 08:24:22 -0700386 if (strlcat(buf, "NVME RPORT ", PAGE_SIZE) >= PAGE_SIZE)
387 goto buffer_done;
388 if (phba->brd_no >= 10) {
389 if (strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
390 goto buffer_done;
391 }
James Smart895427b2017-02-12 13:52:30 -0800392
James Smartafff0d22018-06-26 08:24:22 -0700393 scnprintf(tmp, sizeof(tmp), "WWPN x%llx ",
394 nrport->port_name);
395 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
396 goto buffer_done;
397
398 scnprintf(tmp, sizeof(tmp), "WWNN x%llx ",
399 nrport->node_name);
400 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
401 goto buffer_done;
402
403 scnprintf(tmp, sizeof(tmp), "DID x%06x ",
404 nrport->port_id);
405 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
406 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800407
James Smart7d790f02017-06-01 21:06:57 -0700408 /* An NVME rport can have multiple roles. */
James Smartafff0d22018-06-26 08:24:22 -0700409 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR) {
410 if (strlcat(buf, "INITIATOR ", PAGE_SIZE) >= PAGE_SIZE)
411 goto buffer_done;
412 }
413 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET) {
414 if (strlcat(buf, "TARGET ", PAGE_SIZE) >= PAGE_SIZE)
415 goto buffer_done;
416 }
417 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY) {
418 if (strlcat(buf, "DISCSRVC ", PAGE_SIZE) >= PAGE_SIZE)
419 goto buffer_done;
420 }
James Smart7d790f02017-06-01 21:06:57 -0700421 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
422 FC_PORT_ROLE_NVME_TARGET |
James Smartafff0d22018-06-26 08:24:22 -0700423 FC_PORT_ROLE_NVME_DISCOVERY)) {
424 scnprintf(tmp, sizeof(tmp), "UNKNOWN ROLE x%x",
425 nrport->port_role);
426 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
427 goto buffer_done;
428 }
James Smart7d790f02017-06-01 21:06:57 -0700429
James Smartafff0d22018-06-26 08:24:22 -0700430 scnprintf(tmp, sizeof(tmp), "%s\n", statep);
431 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
432 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800433 }
James Smartafff0d22018-06-26 08:24:22 -0700434 rcu_read_unlock();
James Smart895427b2017-02-12 13:52:30 -0800435
James Smart66a210f2018-04-09 14:24:23 -0700436 if (!lport)
James Smartafff0d22018-06-26 08:24:22 -0700437 goto buffer_done;
James Smart66a210f2018-04-09 14:24:23 -0700438
James Smartafff0d22018-06-26 08:24:22 -0700439 if (strlcat(buf, "\nNVME Statistics\n", PAGE_SIZE) >= PAGE_SIZE)
440 goto buffer_done;
James Smart4b056682017-12-08 17:18:10 -0800441
James Smartafff0d22018-06-26 08:24:22 -0700442 scnprintf(tmp, sizeof(tmp),
443 "LS: Xmt %010x Cmpl %010x Abort %08x\n",
444 atomic_read(&lport->fc4NvmeLsRequests),
445 atomic_read(&lport->fc4NvmeLsCmpls),
446 atomic_read(&lport->xmt_ls_abort));
447 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
448 goto buffer_done;
449
450 scnprintf(tmp, sizeof(tmp),
451 "LS XMIT: Err %08x CMPL: xb %08x Err %08x\n",
452 atomic_read(&lport->xmt_ls_err),
453 atomic_read(&lport->cmpl_ls_xb),
454 atomic_read(&lport->cmpl_ls_err));
455 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
456 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800457
James Smart66a210f2018-04-09 14:24:23 -0700458 totin = 0;
459 totout = 0;
460 for (i = 0; i < phba->cfg_nvme_io_channel; i++) {
461 cstat = &lport->cstat[i];
462 tot = atomic_read(&cstat->fc4NvmeIoCmpls);
463 totin += tot;
464 data1 = atomic_read(&cstat->fc4NvmeInputRequests);
465 data2 = atomic_read(&cstat->fc4NvmeOutputRequests);
466 data3 = atomic_read(&cstat->fc4NvmeControlRequests);
467 totout += (data1 + data2 + data3);
468 }
James Smartafff0d22018-06-26 08:24:22 -0700469 scnprintf(tmp, sizeof(tmp),
470 "Total FCP Cmpl %016llx Issue %016llx "
471 "OutIO %016llx\n",
472 totin, totout, totout - totin);
473 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
474 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800475
James Smartafff0d22018-06-26 08:24:22 -0700476 scnprintf(tmp, sizeof(tmp),
477 "\tabort %08x noxri %08x nondlp %08x qdepth %08x "
478 "wqerr %08x err %08x\n",
479 atomic_read(&lport->xmt_fcp_abort),
480 atomic_read(&lport->xmt_fcp_noxri),
481 atomic_read(&lport->xmt_fcp_bad_ndlp),
482 atomic_read(&lport->xmt_fcp_qdepth),
483 atomic_read(&lport->xmt_fcp_err),
484 atomic_read(&lport->xmt_fcp_wqerr));
485 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
486 goto buffer_done;
James Smart4b056682017-12-08 17:18:10 -0800487
James Smartafff0d22018-06-26 08:24:22 -0700488 scnprintf(tmp, sizeof(tmp),
489 "FCP CMPL: xb %08x Err %08x\n",
490 atomic_read(&lport->cmpl_fcp_xb),
491 atomic_read(&lport->cmpl_fcp_err));
492 strlcat(buf, tmp, PAGE_SIZE);
493
494buffer_done:
495 len = strnlen(buf, PAGE_SIZE);
496
497 if (unlikely(len >= (PAGE_SIZE - 1))) {
498 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
499 "6314 Catching potential buffer "
500 "overflow > PAGE_SIZE = %lu bytes\n",
501 PAGE_SIZE);
502 strlcpy(buf + PAGE_SIZE - 1 -
503 strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1),
504 LPFC_NVME_INFO_MORE_STR,
505 strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1)
506 + 1);
507 }
508
James Smart895427b2017-02-12 13:52:30 -0800509 return len;
510}
511
512static ssize_t
James Smart81301a92008-12-04 22:39:46 -0500513lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
514 char *buf)
515{
516 struct Scsi_Host *shost = class_to_shost(dev);
517 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
518 struct lpfc_hba *phba = vport->phba;
519
520 if (phba->cfg_enable_bg)
521 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
522 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
523 else
524 return snprintf(buf, PAGE_SIZE,
525 "BlockGuard Not Supported\n");
526 else
527 return snprintf(buf, PAGE_SIZE,
528 "BlockGuard Disabled\n");
529}
530
531static ssize_t
532lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
533 char *buf)
534{
535 struct Scsi_Host *shost = class_to_shost(dev);
536 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
537 struct lpfc_hba *phba = vport->phba;
538
James Smart87b5c322008-12-16 10:34:09 -0500539 return snprintf(buf, PAGE_SIZE, "%llu\n",
540 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500541}
542
543static ssize_t
544lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
545 char *buf)
546{
547 struct Scsi_Host *shost = class_to_shost(dev);
548 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
549 struct lpfc_hba *phba = vport->phba;
550
James Smart87b5c322008-12-16 10:34:09 -0500551 return snprintf(buf, PAGE_SIZE, "%llu\n",
552 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500553}
554
555static ssize_t
556lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
557 char *buf)
558{
559 struct Scsi_Host *shost = class_to_shost(dev);
560 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
561 struct lpfc_hba *phba = vport->phba;
562
James Smart87b5c322008-12-16 10:34:09 -0500563 return snprintf(buf, PAGE_SIZE, "%llu\n",
564 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500565}
566
James Smarte59058c2008-08-24 21:49:00 -0400567/**
James Smart3621a712009-04-06 18:47:14 -0400568 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400569 * @dev: class converted to a Scsi_host structure.
570 * @attr: device attribute, not used.
571 * @buf: on return contains the formatted text from lpfc_info().
572 *
573 * Returns: size of formatted string.
574 **/
dea31012005-04-17 16:05:31 -0500575static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100576lpfc_info_show(struct device *dev, struct device_attribute *attr,
577 char *buf)
dea31012005-04-17 16:05:31 -0500578{
Tony Jonesee959b02008-02-22 00:13:36 +0100579 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500580
dea31012005-04-17 16:05:31 -0500581 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
582}
583
James Smarte59058c2008-08-24 21:49:00 -0400584/**
James Smart3621a712009-04-06 18:47:14 -0400585 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400586 * @dev: class converted to a Scsi_host structure.
587 * @attr: device attribute, not used.
588 * @buf: on return contains the formatted text serial number.
589 *
590 * Returns: size of formatted string.
591 **/
dea31012005-04-17 16:05:31 -0500592static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100593lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
594 char *buf)
dea31012005-04-17 16:05:31 -0500595{
Tony Jonesee959b02008-02-22 00:13:36 +0100596 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500597 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
598 struct lpfc_hba *phba = vport->phba;
599
dea31012005-04-17 16:05:31 -0500600 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
601}
602
James Smarte59058c2008-08-24 21:49:00 -0400603/**
James Smart3621a712009-04-06 18:47:14 -0400604 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400605 * @dev: class converted to a Scsi_host structure.
606 * @attr: device attribute, not used.
607 * @buf: on return contains the formatted support level.
608 *
609 * Description:
610 * Returns a number indicating the temperature sensor level currently
611 * supported, zero or one in ascii.
612 *
613 * Returns: size of formatted string.
614 **/
dea31012005-04-17 16:05:31 -0500615static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100616lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
617 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400618{
Tony Jonesee959b02008-02-22 00:13:36 +0100619 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400620 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
621 struct lpfc_hba *phba = vport->phba;
622 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
623}
624
James Smarte59058c2008-08-24 21:49:00 -0400625/**
James Smart3621a712009-04-06 18:47:14 -0400626 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400627 * @dev: class converted to a Scsi_host structure.
628 * @attr: device attribute, not used.
629 * @buf: on return contains the scsi vpd model description.
630 *
631 * Returns: size of formatted string.
632 **/
James Smart57127f12007-10-27 13:37:05 -0400633static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100634lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
635 char *buf)
dea31012005-04-17 16:05:31 -0500636{
Tony Jonesee959b02008-02-22 00:13:36 +0100637 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500638 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
639 struct lpfc_hba *phba = vport->phba;
640
dea31012005-04-17 16:05:31 -0500641 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
642}
643
James Smarte59058c2008-08-24 21:49:00 -0400644/**
James Smart3621a712009-04-06 18:47:14 -0400645 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400646 * @dev: class converted to a Scsi_host structure.
647 * @attr: device attribute, not used.
648 * @buf: on return contains the scsi vpd model name.
649 *
650 * Returns: size of formatted string.
651 **/
dea31012005-04-17 16:05:31 -0500652static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100653lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
654 char *buf)
dea31012005-04-17 16:05:31 -0500655{
Tony Jonesee959b02008-02-22 00:13:36 +0100656 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500657 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
658 struct lpfc_hba *phba = vport->phba;
659
dea31012005-04-17 16:05:31 -0500660 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
661}
662
James Smarte59058c2008-08-24 21:49:00 -0400663/**
James Smart3621a712009-04-06 18:47:14 -0400664 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400665 * @dev: class converted to a Scsi_host structure.
666 * @attr: device attribute, not used.
667 * @buf: on return contains the scsi vpd program type.
668 *
669 * Returns: size of formatted string.
670 **/
dea31012005-04-17 16:05:31 -0500671static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100672lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
673 char *buf)
dea31012005-04-17 16:05:31 -0500674{
Tony Jonesee959b02008-02-22 00:13:36 +0100675 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500676 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
677 struct lpfc_hba *phba = vport->phba;
678
dea31012005-04-17 16:05:31 -0500679 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
680}
681
James Smarte59058c2008-08-24 21:49:00 -0400682/**
James Smart3621a712009-04-06 18:47:14 -0400683 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400684 * @dev: class converted to a Scsi_host structure.
685 * @attr: device attribute, not used.
686 * @buf: on return contains the Menlo Maintenance sli flag.
687 *
688 * Returns: size of formatted string.
689 **/
690static ssize_t
691lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
692{
693 struct Scsi_Host *shost = class_to_shost(dev);
694 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
695 struct lpfc_hba *phba = vport->phba;
696
697 return snprintf(buf, PAGE_SIZE, "%d\n",
698 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
699}
700
701/**
James Smart3621a712009-04-06 18:47:14 -0400702 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400703 * @dev: class converted to a Scsi_host structure.
704 * @attr: device attribute, not used.
705 * @buf: on return contains scsi vpd program type.
706 *
707 * Returns: size of formatted string.
708 **/
dea31012005-04-17 16:05:31 -0500709static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100710lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
711 char *buf)
dea31012005-04-17 16:05:31 -0500712{
Tony Jonesee959b02008-02-22 00:13:36 +0100713 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500714 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
715 struct lpfc_hba *phba = vport->phba;
716
dea31012005-04-17 16:05:31 -0500717 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
718}
719
James Smarte59058c2008-08-24 21:49:00 -0400720/**
James Smart3621a712009-04-06 18:47:14 -0400721 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400722 * @dev: class converted to a Scsi_host structure.
723 * @attr: device attribute, not used.
724 * @buf: on return contains the scsi vpd program type.
725 *
726 * Returns: size of formatted string.
727 **/
dea31012005-04-17 16:05:31 -0500728static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100729lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
730 char *buf)
dea31012005-04-17 16:05:31 -0500731{
Tony Jonesee959b02008-02-22 00:13:36 +0100732 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500733 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
734 struct lpfc_hba *phba = vport->phba;
James Smart026abb82011-12-13 13:20:45 -0500735 uint32_t if_type;
736 uint8_t sli_family;
James Smart6b5151f2012-01-18 16:24:06 -0500737 char fwrev[FW_REV_STR_SIZE];
James Smart026abb82011-12-13 13:20:45 -0500738 int len;
James Smart2e0fef82007-06-17 19:56:36 -0500739
dea31012005-04-17 16:05:31 -0500740 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart026abb82011-12-13 13:20:45 -0500741 if_type = phba->sli4_hba.pc_sli4_params.if_type;
742 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
743
744 if (phba->sli_rev < LPFC_SLI_REV4)
745 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
746 fwrev, phba->sli_rev);
747 else
748 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
749 fwrev, phba->sli_rev, if_type, sli_family);
750
751 return len;
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_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400756 * @dev: class converted to a Scsi_host structure.
757 * @attr: device attribute, not used.
758 * @buf: on return contains the scsi vpd program type.
759 *
760 * Returns: size of formatted string.
761 **/
dea31012005-04-17 16:05:31 -0500762static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100763lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500764{
765 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100766 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500767 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
768 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500769 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500770
dea31012005-04-17 16:05:31 -0500771 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
772 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
773}
James Smarte59058c2008-08-24 21:49:00 -0400774
775/**
James Smart3621a712009-04-06 18:47:14 -0400776 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400777 * @dev: class converted to a Scsi_host structure.
778 * @attr: device attribute, not used.
779 * @buf: on return contains the ROM and FCode ascii strings.
780 *
781 * Returns: size of formatted string.
782 **/
dea31012005-04-17 16:05:31 -0500783static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100784lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
785 char *buf)
dea31012005-04-17 16:05:31 -0500786{
Tony Jonesee959b02008-02-22 00:13:36 +0100787 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500788 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
789 struct lpfc_hba *phba = vport->phba;
James Smarta0683bf2015-04-07 15:07:16 -0400790 char fwrev[FW_REV_STR_SIZE];
James Smart2e0fef82007-06-17 19:56:36 -0500791
James Smarta0683bf2015-04-07 15:07:16 -0400792 if (phba->sli_rev < LPFC_SLI_REV4)
793 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
794
795 lpfc_decode_firmware_rev(phba, fwrev, 1);
796 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
dea31012005-04-17 16:05:31 -0500797}
James Smarte59058c2008-08-24 21:49:00 -0400798
799/**
James Smart3621a712009-04-06 18:47:14 -0400800 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400801 * @dev: class converted to a Scsi_host structure.
802 * @attr: device attribute, not used.
803 * @buf: on return contains text describing the state of the link.
804 *
805 * Notes:
806 * The switch statement has no default so zero will be returned.
807 *
808 * Returns: size of formatted string.
809 **/
dea31012005-04-17 16:05:31 -0500810static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100811lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
812 char *buf)
dea31012005-04-17 16:05:31 -0500813{
Tony Jonesee959b02008-02-22 00:13:36 +0100814 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500815 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
816 struct lpfc_hba *phba = vport->phba;
817 int len = 0;
818
819 switch (phba->link_state) {
820 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500821 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500822 case LPFC_INIT_START:
823 case LPFC_INIT_MBX_CMDS:
824 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500825 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400826 if (phba->hba_flag & LINK_DISABLED)
827 len += snprintf(buf + len, PAGE_SIZE-len,
828 "Link Down - User disabled\n");
829 else
830 len += snprintf(buf + len, PAGE_SIZE-len,
831 "Link Down\n");
dea31012005-04-17 16:05:31 -0500832 break;
833 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500834 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500835 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400836 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500837
838 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500839 case LPFC_LOCAL_CFG_LINK:
840 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500841 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500842 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500843 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500844 case LPFC_FLOGI:
845 case LPFC_FABRIC_CFG_LINK:
846 case LPFC_NS_REG:
847 case LPFC_NS_QRY:
848 case LPFC_BUILD_DISC_LIST:
849 case LPFC_DISC_AUTH:
850 len += snprintf(buf + len, PAGE_SIZE - len,
851 "Discovery\n");
852 break;
853 case LPFC_VPORT_READY:
854 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
855 break;
856
James Smart92d7f7b2007-06-17 19:56:38 -0500857 case LPFC_VPORT_FAILED:
858 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
859 break;
860
861 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500862 len += snprintf(buf + len, PAGE_SIZE - len,
863 "Unknown\n");
864 break;
865 }
James Smart84774a42008-08-24 21:50:06 -0400866 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
867 len += snprintf(buf + len, PAGE_SIZE-len,
868 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500869 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500870 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500871 len += snprintf(buf + len, PAGE_SIZE-len,
872 " Public Loop\n");
873 else
874 len += snprintf(buf + len, PAGE_SIZE-len,
875 " Private Loop\n");
876 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500877 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500878 len += snprintf(buf + len, PAGE_SIZE-len,
879 " Fabric\n");
880 else
881 len += snprintf(buf + len, PAGE_SIZE-len,
882 " Point-2-Point\n");
883 }
884 }
James Smart2e0fef82007-06-17 19:56:36 -0500885
James Smart1dc5ec22018-10-23 13:41:11 -0700886 if ((phba->sli_rev == LPFC_SLI_REV4) &&
887 ((bf_get(lpfc_sli_intf_if_type,
888 &phba->sli4_hba.sli_intf) ==
889 LPFC_SLI_INTF_IF_TYPE_6))) {
890 struct lpfc_trunk_link link = phba->trunk_link;
891
892 if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
893 len += snprintf(buf + len, PAGE_SIZE - len,
894 "Trunk port 0: Link %s %s\n",
895 (link.link0.state == LPFC_LINK_UP) ?
896 "Up" : "Down. ",
897 trunk_errmsg[link.link0.fault]);
898
899 if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
900 len += snprintf(buf + len, PAGE_SIZE - len,
901 "Trunk port 1: Link %s %s\n",
902 (link.link1.state == LPFC_LINK_UP) ?
903 "Up" : "Down. ",
904 trunk_errmsg[link.link1.fault]);
905
906 if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
907 len += snprintf(buf + len, PAGE_SIZE - len,
908 "Trunk port 2: Link %s %s\n",
909 (link.link2.state == LPFC_LINK_UP) ?
910 "Up" : "Down. ",
911 trunk_errmsg[link.link2.fault]);
912
913 if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
914 len += snprintf(buf + len, PAGE_SIZE - len,
915 "Trunk port 3: Link %s %s\n",
916 (link.link3.state == LPFC_LINK_UP) ?
917 "Up" : "Down. ",
918 trunk_errmsg[link.link3.fault]);
919
920 }
921
dea31012005-04-17 16:05:31 -0500922 return len;
923}
924
James Smarte59058c2008-08-24 21:49:00 -0400925/**
James Smart026abb82011-12-13 13:20:45 -0500926 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
927 * @dev: class unused variable.
928 * @attr: device attribute, not used.
929 * @buf: on return contains the module description text.
930 *
931 * Returns: size of formatted string.
932 **/
933static ssize_t
934lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
935 char *buf)
936{
937 struct Scsi_Host *shost = class_to_shost(dev);
938 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
939 struct lpfc_hba *phba = vport->phba;
940
941 if (phba->sli_rev < LPFC_SLI_REV4)
942 return snprintf(buf, PAGE_SIZE, "fc\n");
943
944 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
945 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
946 return snprintf(buf, PAGE_SIZE, "fcoe\n");
947 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
948 return snprintf(buf, PAGE_SIZE, "fc\n");
949 }
950 return snprintf(buf, PAGE_SIZE, "unknown\n");
951}
952
953/**
James Smart1ba981f2014-02-20 09:56:45 -0500954 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
955 * (OAS) is supported.
956 * @dev: class unused variable.
957 * @attr: device attribute, not used.
958 * @buf: on return contains the module description text.
959 *
960 * Returns: size of formatted string.
961 **/
962static ssize_t
963lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
964 char *buf)
965{
966 struct Scsi_Host *shost = class_to_shost(dev);
967 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
968 struct lpfc_hba *phba = vport->phba;
969
970 return snprintf(buf, PAGE_SIZE, "%d\n",
971 phba->sli4_hba.pc_sli4_params.oas_supported);
972}
973
974/**
James Smart84d1b002010-02-12 14:42:33 -0500975 * lpfc_link_state_store - Transition the link_state on an HBA port
976 * @dev: class device that is converted into a Scsi_host.
977 * @attr: device attribute, not used.
978 * @buf: one or more lpfc_polling_flags values.
979 * @count: not used.
980 *
981 * Returns:
982 * -EINVAL if the buffer is not "up" or "down"
983 * return from link state change function if non-zero
984 * length of the buf on success
985 **/
986static ssize_t
987lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
988 const char *buf, size_t count)
989{
990 struct Scsi_Host *shost = class_to_shost(dev);
991 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
992 struct lpfc_hba *phba = vport->phba;
993
994 int status = -EINVAL;
995
996 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
997 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400998 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500999 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
1000 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -04001001 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -05001002
1003 if (status == 0)
1004 return strlen(buf);
1005 else
1006 return status;
1007}
1008
1009/**
James Smart3621a712009-04-06 18:47:14 -04001010 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -04001011 * @dev: class device that is converted into a Scsi_host.
1012 * @attr: device attribute, not used.
1013 * @buf: on return contains the sum of fc mapped and unmapped.
1014 *
1015 * Description:
1016 * Returns the ascii text number of the sum of the fc mapped and unmapped
1017 * vport counts.
1018 *
1019 * Returns: size of formatted string.
1020 **/
dea31012005-04-17 16:05:31 -05001021static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001022lpfc_num_discovered_ports_show(struct device *dev,
1023 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -05001024{
Tony Jonesee959b02008-02-22 00:13:36 +01001025 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001026 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1027
1028 return snprintf(buf, PAGE_SIZE, "%d\n",
1029 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -05001030}
1031
James Smarte59058c2008-08-24 21:49:00 -04001032/**
James Smart3621a712009-04-06 18:47:14 -04001033 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -04001034 * @shost: Scsi_Host pointer.
1035 *
1036 * Description:
1037 * Bring the link down gracefully then re-init the link. The firmware will
1038 * re-init the fiber channel interface as required. Does not issue a LIP.
1039 *
1040 * Returns:
1041 * -EPERM port offline or management commands are being blocked
1042 * -ENOMEM cannot allocate memory for the mailbox command
1043 * -EIO error sending the mailbox command
1044 * zero for success
1045 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001046static int
James Smart2e0fef82007-06-17 19:56:36 -05001047lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -05001048{
James Smart2e0fef82007-06-17 19:56:36 -05001049 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1050 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001051 LPFC_MBOXQ_t *pmboxq;
1052 int mbxstatus = MBXERR_ERROR;
1053
James Smart2289e952018-01-30 15:58:55 -08001054 /*
1055 * If the link is offline, disabled or BLOCK_MGMT_IO
1056 * it doesn't make any sense to allow issue_lip
1057 */
James Smart2e0fef82007-06-17 19:56:36 -05001058 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart2289e952018-01-30 15:58:55 -08001059 (phba->hba_flag & LINK_DISABLED) ||
James Smart83108bd2008-01-11 01:53:09 -05001060 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -05001061 return -EPERM;
1062
1063 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
1064
1065 if (!pmboxq)
1066 return -ENOMEM;
1067
1068 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -04001069 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
1070 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -04001071
James Smart33ccf8d2006-08-17 11:57:58 -04001072 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -05001073
James Smart04c68492009-05-22 14:52:52 -04001074 if ((mbxstatus == MBX_SUCCESS) &&
1075 (pmboxq->u.mb.mbxStatus == 0 ||
1076 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -04001077 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1078 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
1079 phba->cfg_link_speed);
1080 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
1081 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -04001082 if ((mbxstatus == MBX_SUCCESS) &&
1083 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
1084 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1085 "2859 SLI authentication is required "
1086 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -04001087 }
1088
James Smart5b8bd0c2007-04-25 09:52:49 -04001089 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -05001090 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001091 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001092
1093 if (mbxstatus == MBXERR_ERROR)
1094 return -EIO;
1095
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001096 return 0;
dea31012005-04-17 16:05:31 -05001097}
1098
James Smart895427b2017-02-12 13:52:30 -08001099int
1100lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
1101{
1102 int cnt = 0;
1103
1104 spin_lock_irq(lock);
1105 while (!list_empty(q)) {
1106 spin_unlock_irq(lock);
1107 msleep(20);
1108 if (cnt++ > 250) { /* 5 secs */
1109 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1110 "0466 %s %s\n",
1111 "Outstanding IO when ",
1112 "bringing Adapter offline\n");
1113 return 0;
1114 }
1115 spin_lock_irq(lock);
1116 }
1117 spin_unlock_irq(lock);
1118 return 1;
1119}
1120
James Smarte59058c2008-08-24 21:49:00 -04001121/**
James Smart3621a712009-04-06 18:47:14 -04001122 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -04001123 * @phba: lpfc_hba pointer.
1124 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
1125 *
1126 * Notes:
1127 * Assumes any error from lpfc_do_offline() will be negative.
1128 * Can wait up to 5 seconds for the port ring buffers count
1129 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -04001130 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -04001131 *
1132 * Returns:
1133 * -EIO error posting the event
1134 * zero for success
1135 **/
James Smart40496f02006-07-06 15:50:22 -04001136static int
James Smart46fa3112007-04-25 09:51:45 -04001137lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
1138{
1139 struct completion online_compl;
James Smart895427b2017-02-12 13:52:30 -08001140 struct lpfc_queue *qp = NULL;
James Smart46fa3112007-04-25 09:51:45 -04001141 struct lpfc_sli_ring *pring;
1142 struct lpfc_sli *psli;
1143 int status = 0;
James Smart46fa3112007-04-25 09:51:45 -04001144 int i;
James Smartfedd3b72011-02-16 12:39:24 -05001145 int rc;
James Smart46fa3112007-04-25 09:51:45 -04001146
1147 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001148 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -04001149 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -05001150 if (rc == 0)
1151 return -ENOMEM;
1152
James Smart46fa3112007-04-25 09:51:45 -04001153 wait_for_completion(&online_compl);
1154
1155 if (status != 0)
1156 return -EIO;
1157
1158 psli = &phba->sli;
1159
James Smart09372822008-01-11 01:52:54 -05001160 /* Wait a little for things to settle down, but not
1161 * long enough for dev loss timeout to expire.
1162 */
James Smart895427b2017-02-12 13:52:30 -08001163 if (phba->sli_rev != LPFC_SLI_REV4) {
1164 for (i = 0; i < psli->num_rings; i++) {
1165 pring = &psli->sli3_ring[i];
1166 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1167 &phba->hbalock))
1168 goto out;
1169 }
1170 } else {
1171 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1172 pring = qp->pring;
1173 if (!pring)
1174 continue;
1175 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1176 &pring->ring_lock))
1177 goto out;
James Smart46fa3112007-04-25 09:51:45 -04001178 }
1179 }
James Smart895427b2017-02-12 13:52:30 -08001180out:
James Smart46fa3112007-04-25 09:51:45 -04001181 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001182 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1183 if (rc == 0)
1184 return -ENOMEM;
1185
James Smart46fa3112007-04-25 09:51:45 -04001186 wait_for_completion(&online_compl);
1187
1188 if (status != 0)
1189 return -EIO;
1190
1191 return 0;
1192}
1193
James Smarte59058c2008-08-24 21:49:00 -04001194/**
James Smart3621a712009-04-06 18:47:14 -04001195 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -04001196 * @phba: lpfc_hba pointer.
1197 *
1198 * Description:
1199 * If the port is configured to allow a reset then the hba is brought
1200 * offline then online.
1201 *
1202 * Notes:
1203 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -05001204 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -04001205 *
1206 * Returns:
1207 * lpfc_do_offline() return code if not zero
1208 * -EIO reset not configured or error posting the event
1209 * zero for success
1210 **/
James Smart7f860592011-03-11 16:05:52 -05001211int
James Smart40496f02006-07-06 15:50:22 -04001212lpfc_selective_reset(struct lpfc_hba *phba)
1213{
1214 struct completion online_compl;
1215 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001216 int rc;
James Smart40496f02006-07-06 15:50:22 -04001217
James Smart71157c92013-07-15 18:34:36 -04001218 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001219 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -05001220
James Smart71157c92013-07-15 18:34:36 -04001221 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1222 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -04001223
James Smart71157c92013-07-15 18:34:36 -04001224 if (status != 0)
1225 return status;
1226 }
James Smart40496f02006-07-06 15:50:22 -04001227
1228 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001229 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -04001230 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -05001231 if (rc == 0)
1232 return -ENOMEM;
1233
James Smart40496f02006-07-06 15:50:22 -04001234 wait_for_completion(&online_compl);
1235
1236 if (status != 0)
1237 return -EIO;
1238
1239 return 0;
1240}
1241
James Smarte59058c2008-08-24 21:49:00 -04001242/**
James Smart3621a712009-04-06 18:47:14 -04001243 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -04001244 * @dev: class device that is converted into a Scsi_host.
1245 * @attr: device attribute, not used.
1246 * @buf: containing the string "selective".
1247 * @count: unused variable.
1248 *
1249 * Description:
1250 * If the buf contains the string "selective" then lpfc_selective_reset()
1251 * is called to perform the reset.
1252 *
1253 * Notes:
1254 * Assumes any error from lpfc_selective_reset() will be negative.
1255 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001256 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -04001257 *
1258 * Returns:
1259 * -EINVAL if the buffer does not contain the string "selective"
1260 * length of buf if lpfc-selective_reset() if the call succeeds
1261 * return value of lpfc_selective_reset() if the call fails
1262**/
James Smart40496f02006-07-06 15:50:22 -04001263static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001264lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1265 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -04001266{
Tony Jonesee959b02008-02-22 00:13:36 +01001267 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001268 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1269 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -04001270 int status = -EINVAL;
1271
James Smart73d91e52011-10-10 21:32:10 -04001272 if (!phba->cfg_enable_hba_reset)
1273 return -EACCES;
1274
James Smart40496f02006-07-06 15:50:22 -04001275 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -05001276 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -04001277
1278 if (status == 0)
1279 return strlen(buf);
1280 else
1281 return status;
1282}
1283
James Smarte59058c2008-08-24 21:49:00 -04001284/**
James Smart88a2cfb2011-07-22 18:36:33 -04001285 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1286 * @phba: lpfc_hba pointer.
1287 *
1288 * Description:
1289 * SLI4 interface type-2 device to wait on the sliport status register for
1290 * the readyness after performing a firmware reset.
1291 *
1292 * Returns:
Masanari Iida0b1587b2013-07-17 04:37:44 +09001293 * zero for success, -EPERM when port does not have privilege to perform the
James Smart026abb82011-12-13 13:20:45 -05001294 * reset, -EIO when port timeout from recovering from the reset.
1295 *
1296 * Note:
1297 * As the caller will interpret the return code by value, be careful in making
1298 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -04001299 **/
James Smart73d91e52011-10-10 21:32:10 -04001300int
James Smart88a2cfb2011-07-22 18:36:33 -04001301lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1302{
James Smartf7a919b2011-08-21 21:49:16 -04001303 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -04001304 int i;
1305
James Smartf7a919b2011-08-21 21:49:16 -04001306 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -04001307 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1308 &portstat_reg.word0);
1309
Masanari Iida0b1587b2013-07-17 04:37:44 +09001310 /* verify if privileged for the request operation */
James Smartf7a919b2011-08-21 21:49:16 -04001311 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1312 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1313 return -EPERM;
1314
James Smart88a2cfb2011-07-22 18:36:33 -04001315 /* wait for the SLI port firmware ready after firmware reset */
1316 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1317 msleep(10);
1318 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1319 &portstat_reg.word0);
1320 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1321 continue;
1322 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1323 continue;
1324 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1325 continue;
1326 break;
1327 }
1328
1329 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1330 return 0;
1331 else
1332 return -EIO;
1333}
1334
1335/**
James Smart52d52442011-05-24 11:42:45 -04001336 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -04001337 * @phba: lpfc_hba pointer.
1338 *
1339 * Description:
James Smart52d52442011-05-24 11:42:45 -04001340 * Request SLI4 interface type-2 device to perform a physical register set
1341 * access.
James Smartc0c11512011-05-24 11:41:34 -04001342 *
1343 * Returns:
1344 * zero for success
1345 **/
1346static ssize_t
James Smart52d52442011-05-24 11:42:45 -04001347lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -04001348{
1349 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -04001350 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -05001351 uint32_t before_fc_flag;
1352 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -04001353 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -05001354 int status = 0, rc = 0;
1355 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -04001356
1357 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001358 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -04001359
James Smart52d52442011-05-24 11:42:45 -04001360 if ((phba->sli_rev < LPFC_SLI_REV4) ||
James Smart719162b2018-12-10 19:37:01 -08001361 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smart52d52442011-05-24 11:42:45 -04001362 LPFC_SLI_INTF_IF_TYPE_2))
1363 return -EPERM;
1364
James Smart026abb82011-12-13 13:20:45 -05001365 /* Keep state if we need to restore back */
1366 before_fc_flag = phba->pport->fc_flag;
1367 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1368
James Smartb76f2dc2011-07-22 18:37:42 -04001369 /* Disable SR-IOV virtual functions if enabled */
1370 if (phba->cfg_sriov_nr_virtfn) {
1371 pci_disable_sriov(pdev);
1372 phba->cfg_sriov_nr_virtfn = 0;
1373 }
James Smart229adb02013-04-17 20:16:51 -04001374
James Smart02936352014-04-04 13:52:12 -04001375 if (opcode == LPFC_FW_DUMP)
1376 phba->hba_flag |= HBA_FW_DUMP_OP;
1377
James Smartc0c11512011-05-24 11:41:34 -04001378 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1379
James Smart02936352014-04-04 13:52:12 -04001380 if (status != 0) {
1381 phba->hba_flag &= ~HBA_FW_DUMP_OP;
James Smartc0c11512011-05-24 11:41:34 -04001382 return status;
James Smart02936352014-04-04 13:52:12 -04001383 }
James Smartc0c11512011-05-24 11:41:34 -04001384
1385 /* wait for the device to be quiesced before firmware reset */
1386 msleep(100);
1387
1388 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1389 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -04001390
1391 if (opcode == LPFC_FW_DUMP)
1392 reg_val |= LPFC_FW_DUMP_REQUEST;
1393 else if (opcode == LPFC_FW_RESET)
1394 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1395 else if (opcode == LPFC_DV_RESET)
1396 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1397
James Smartc0c11512011-05-24 11:41:34 -04001398 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1399 LPFC_CTL_PDEV_CTL_OFFSET);
1400 /* flush */
1401 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1402
1403 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -04001404 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1405
James Smart026abb82011-12-13 13:20:45 -05001406 if (rc == -EPERM) {
Masanari Iida0b1587b2013-07-17 04:37:44 +09001407 /* no privilege for reset */
James Smart6b5151f2012-01-18 16:24:06 -05001408 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
Masanari Iida0b1587b2013-07-17 04:37:44 +09001409 "3150 No privilege to perform the requested "
James Smart6b5151f2012-01-18 16:24:06 -05001410 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -05001411 } else if (rc == -EIO) {
1412 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -05001413 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1414 "3153 Fail to perform the requested "
1415 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -04001416 return rc;
James Smart026abb82011-12-13 13:20:45 -05001417 }
1418
1419 /* keep the original port state */
1420 if (before_fc_flag & FC_OFFLINE_MODE)
1421 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001422
1423 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -05001424 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1425 LPFC_EVT_ONLINE);
1426 if (!job_posted)
1427 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001428
1429 wait_for_completion(&online_compl);
1430
James Smart026abb82011-12-13 13:20:45 -05001431out:
1432 /* in any case, restore the virtual functions enabled as before */
1433 if (sriov_nr_virtfn) {
1434 sriov_err =
1435 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1436 if (!sriov_err)
1437 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1438 }
James Smartc0c11512011-05-24 11:41:34 -04001439
James Smart026abb82011-12-13 13:20:45 -05001440 /* return proper error code */
1441 if (!rc) {
1442 if (!job_posted)
1443 rc = -ENOMEM;
1444 else if (status)
1445 rc = -EIO;
1446 }
1447 return rc;
James Smartc0c11512011-05-24 11:41:34 -04001448}
1449
1450/**
James Smart3621a712009-04-06 18:47:14 -04001451 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -04001452 * @dev: class device that is converted into a Scsi_host.
1453 * @attr: device attribute, not used.
1454 * @buf: on return contains the ascii number of nport events.
1455 *
1456 * Returns: size of formatted string.
1457 **/
dea31012005-04-17 16:05:31 -05001458static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001459lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1460 char *buf)
dea31012005-04-17 16:05:31 -05001461{
Tony Jonesee959b02008-02-22 00:13:36 +01001462 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001463 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1464 struct lpfc_hba *phba = vport->phba;
1465
dea31012005-04-17 16:05:31 -05001466 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1467}
1468
James Smart1dc5ec22018-10-23 13:41:11 -07001469int
1470lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)
1471{
1472 LPFC_MBOXQ_t *mbox = NULL;
1473 unsigned long val = 0;
1474 char *pval = 0;
1475 int rc = 0;
1476
1477 if (!strncmp("enable", buff_out,
1478 strlen("enable"))) {
1479 pval = buff_out + strlen("enable") + 1;
1480 rc = kstrtoul(pval, 0, &val);
1481 if (rc)
1482 return rc; /* Invalid number */
1483 } else if (!strncmp("disable", buff_out,
1484 strlen("disable"))) {
1485 val = 0;
1486 } else {
1487 return -EINVAL; /* Invalid command */
1488 }
1489
1490 switch (val) {
1491 case 0:
1492 val = 0x0; /* Disable */
1493 break;
1494 case 2:
1495 val = 0x1; /* Enable two port trunk */
1496 break;
1497 case 4:
1498 val = 0x2; /* Enable four port trunk */
1499 break;
1500 default:
1501 return -EINVAL;
1502 }
1503
1504 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1505 "0070 Set trunk mode with val %ld ", val);
1506
1507 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1508 if (!mbox)
1509 return -ENOMEM;
1510
1511 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1512 LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,
1513 12, LPFC_SLI4_MBX_EMBED);
1514
1515 bf_set(lpfc_mbx_set_trunk_mode,
1516 &mbox->u.mqe.un.set_trunk_mode,
1517 val);
1518 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
1519 if (rc)
1520 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1521 "0071 Set trunk mode failed with status: %d",
1522 rc);
1523 if (rc != MBX_TIMEOUT)
1524 mempool_free(mbox, phba->mbox_mem_pool);
1525
1526 return 0;
1527}
1528
James Smarte59058c2008-08-24 21:49:00 -04001529/**
James Smart3621a712009-04-06 18:47:14 -04001530 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -04001531 * @dev: class device that is converted into a Scsi_host.
1532 * @attr: device attribute, not used.
1533 * @buf: on return contains the state of the adapter.
1534 *
1535 * Returns: size of formatted string.
1536 **/
dea31012005-04-17 16:05:31 -05001537static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001538lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1539 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001540{
Tony Jonesee959b02008-02-22 00:13:36 +01001541 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001542 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1543 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001544 char * state;
1545
James Smart2e0fef82007-06-17 19:56:36 -05001546 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001547 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001548 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001549 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001550 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001551 state = "offline";
1552 else
1553 state = "online";
1554
1555 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1556}
1557
James Smarte59058c2008-08-24 21:49:00 -04001558/**
James Smart3621a712009-04-06 18:47:14 -04001559 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001560 * @dev: class device that is converted into a Scsi_host.
1561 * @attr: device attribute, not used.
1562 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1563 * @count: unused variable.
1564 *
1565 * Returns:
1566 * -EACCES if enable hba reset not enabled
1567 * -EINVAL if the buffer does not contain a valid string (see above)
1568 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1569 * buf length greater than zero indicates success
1570 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001571static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001572lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1573 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001574{
Tony Jonesee959b02008-02-22 00:13:36 +01001575 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001576 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1577 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001578 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001579 char *board_mode_str = NULL;
1580 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001581 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001582
James Smart026abb82011-12-13 13:20:45 -05001583 if (!phba->cfg_enable_hba_reset) {
1584 status = -EACCES;
1585 goto board_mode_out;
1586 }
James Smart88a2cfb2011-07-22 18:36:33 -04001587
1588 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001589 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001590
Jamie Wellnitz41415862006-02-28 19:25:27 -05001591 init_completion(&online_compl);
1592
James Smart46fa3112007-04-25 09:51:45 -04001593 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001594 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001595 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001596 if (rc == 0) {
1597 status = -ENOMEM;
1598 goto board_mode_out;
1599 }
James Smart46fa3112007-04-25 09:51:45 -04001600 wait_for_completion(&online_compl);
James Smart522dcee2017-06-01 21:07:03 -07001601 if (status)
1602 status = -EIO;
James Smart46fa3112007-04-25 09:51:45 -04001603 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1604 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001605 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001606 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001607 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001608 else
1609 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001610 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001611 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001612 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001613 else
1614 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001615 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001616 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1617 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1618 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1619 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1620 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
James Smart1dc5ec22018-10-23 13:41:11 -07001621 else if (strncmp(buf, "trunk", sizeof("trunk") - 1) == 0)
1622 status = lpfc_set_trunking(phba, (char *)buf + sizeof("trunk"));
Jamie Wellnitz41415862006-02-28 19:25:27 -05001623 else
James Smart026abb82011-12-13 13:20:45 -05001624 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001625
James Smart026abb82011-12-13 13:20:45 -05001626board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001627 if (!status)
1628 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001629 else {
1630 board_mode_str = strchr(buf, '\n');
1631 if (board_mode_str)
1632 *board_mode_str = '\0';
1633 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1634 "3097 Failed \"%s\", status(%d), "
1635 "fc_flag(x%x)\n",
1636 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001637 return status;
James Smart026abb82011-12-13 13:20:45 -05001638 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001639}
1640
James Smarte59058c2008-08-24 21:49:00 -04001641/**
James Smart3621a712009-04-06 18:47:14 -04001642 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001643 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001644 * @mxri: max xri count.
1645 * @axri: available xri count.
1646 * @mrpi: max rpi count.
1647 * @arpi: available rpi count.
1648 * @mvpi: max vpi count.
1649 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001650 *
1651 * Description:
1652 * If an integer pointer for an count is not null then the value for the
1653 * count is returned.
1654 *
1655 * Returns:
1656 * zero on error
1657 * one for success
1658 **/
James Smart311464e2007-08-02 11:10:37 -04001659static int
James Smart858c9f62007-06-17 19:56:39 -05001660lpfc_get_hba_info(struct lpfc_hba *phba,
1661 uint32_t *mxri, uint32_t *axri,
1662 uint32_t *mrpi, uint32_t *arpi,
1663 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001664{
James Smart04c68492009-05-22 14:52:52 -04001665 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001666 LPFC_MBOXQ_t *pmboxq;
1667 MAILBOX_t *pmb;
1668 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001669 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001670
1671 /*
1672 * prevent udev from issuing mailbox commands until the port is
1673 * configured.
1674 */
1675 if (phba->link_state < LPFC_LINK_DOWN ||
1676 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001677 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001678 return 0;
1679
1680 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1681 return 0;
1682
1683 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1684 if (!pmboxq)
1685 return 0;
1686 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1687
James Smart04c68492009-05-22 14:52:52 -04001688 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001689 pmb->mbxCommand = MBX_READ_CONFIG;
1690 pmb->mbxOwner = OWN_HOST;
James Smart3e1f0712018-11-29 16:09:29 -08001691 pmboxq->ctx_buf = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05001692
James Smart75baf692010-06-08 18:31:21 -04001693 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001694 rc = MBX_NOT_FINISHED;
1695 else
1696 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1697
1698 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001699 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001700 mempool_free(pmboxq, phba->mbox_mem_pool);
1701 return 0;
1702 }
1703
James Smartda0436e2009-05-22 14:51:39 -04001704 if (phba->sli_rev == LPFC_SLI_REV4) {
1705 rd_config = &pmboxq->u.mqe.un.rd_config;
1706 if (mrpi)
1707 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1708 if (arpi)
1709 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1710 phba->sli4_hba.max_cfg_param.rpi_used;
1711 if (mxri)
1712 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1713 if (axri)
1714 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1715 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001716
1717 /* Account for differences with SLI-3. Get vpi count from
1718 * mailbox data and subtract one for max vpi value.
1719 */
1720 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1721 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1722
James Smart8b47ae62018-11-29 16:09:33 -08001723 /* Limit the max we support */
1724 if (max_vpi > LPFC_MAX_VPI)
1725 max_vpi = LPFC_MAX_VPI;
James Smartda0436e2009-05-22 14:51:39 -04001726 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001727 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001728 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001729 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001730 } else {
1731 if (mrpi)
1732 *mrpi = pmb->un.varRdConfig.max_rpi;
1733 if (arpi)
1734 *arpi = pmb->un.varRdConfig.avail_rpi;
1735 if (mxri)
1736 *mxri = pmb->un.varRdConfig.max_xri;
1737 if (axri)
1738 *axri = pmb->un.varRdConfig.avail_xri;
1739 if (mvpi)
1740 *mvpi = pmb->un.varRdConfig.max_vpi;
James Smart8b47ae62018-11-29 16:09:33 -08001741 if (avpi) {
1742 /* avail_vpi is only valid if link is up and ready */
1743 if (phba->link_state == LPFC_HBA_READY)
1744 *avpi = pmb->un.varRdConfig.avail_vpi;
1745 else
1746 *avpi = pmb->un.varRdConfig.max_vpi;
1747 }
James Smartda0436e2009-05-22 14:51:39 -04001748 }
James Smart92d7f7b2007-06-17 19:56:38 -05001749
1750 mempool_free(pmboxq, phba->mbox_mem_pool);
1751 return 1;
1752}
1753
James Smarte59058c2008-08-24 21:49:00 -04001754/**
James Smart3621a712009-04-06 18:47:14 -04001755 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001756 * @dev: class device that is converted into a Scsi_host.
1757 * @attr: device attribute, not used.
1758 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1759 *
1760 * Description:
1761 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1762 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1763 * to "Unknown" and the buffer length is returned, therefore the caller
1764 * must check for "Unknown" in the buffer to detect a failure.
1765 *
1766 * Returns: size of formatted string.
1767 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001768static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001769lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1770 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001771{
Tony Jonesee959b02008-02-22 00:13:36 +01001772 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001773 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1774 struct lpfc_hba *phba = vport->phba;
1775 uint32_t cnt;
1776
James Smart858c9f62007-06-17 19:56:39 -05001777 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001778 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1779 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1780}
1781
James Smarte59058c2008-08-24 21:49:00 -04001782/**
James Smart3621a712009-04-06 18:47:14 -04001783 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001784 * @dev: class device that is converted into a Scsi_host.
1785 * @attr: device attribute, not used.
1786 * @buf: containing the used rpi count in decimal or "Unknown".
1787 *
1788 * Description:
1789 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1790 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1791 * to "Unknown" and the buffer length is returned, therefore the caller
1792 * must check for "Unknown" in the buffer to detect a failure.
1793 *
1794 * Returns: size of formatted string.
1795 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001796static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001797lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1798 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001799{
Tony Jonesee959b02008-02-22 00:13:36 +01001800 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001801 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1802 struct lpfc_hba *phba = vport->phba;
1803 uint32_t cnt, acnt;
1804
James Smart858c9f62007-06-17 19:56:39 -05001805 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001806 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1807 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1808}
1809
James Smarte59058c2008-08-24 21:49:00 -04001810/**
James Smart3621a712009-04-06 18:47:14 -04001811 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001812 * @dev: class device that is converted into a Scsi_host.
1813 * @attr: device attribute, not used.
1814 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1815 *
1816 * Description:
1817 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1818 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1819 * to "Unknown" and the buffer length is returned, therefore the caller
1820 * must check for "Unknown" in the buffer to detect a failure.
1821 *
1822 * Returns: size of formatted string.
1823 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001824static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001825lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1826 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001827{
Tony Jonesee959b02008-02-22 00:13:36 +01001828 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001829 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1830 struct lpfc_hba *phba = vport->phba;
1831 uint32_t cnt;
1832
James Smart858c9f62007-06-17 19:56:39 -05001833 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001834 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1835 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1836}
1837
James Smarte59058c2008-08-24 21:49:00 -04001838/**
James Smart3621a712009-04-06 18:47:14 -04001839 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001840 * @dev: class device that is converted into a Scsi_host.
1841 * @attr: device attribute, not used.
1842 * @buf: on return contains the used xri count in decimal or "Unknown".
1843 *
1844 * Description:
1845 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1846 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1847 * to "Unknown" and the buffer length is returned, therefore the caller
1848 * must check for "Unknown" in the buffer to detect a failure.
1849 *
1850 * Returns: size of formatted string.
1851 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001852static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001853lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1854 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001855{
Tony Jonesee959b02008-02-22 00:13:36 +01001856 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001857 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1858 struct lpfc_hba *phba = vport->phba;
1859 uint32_t cnt, acnt;
1860
James Smart858c9f62007-06-17 19:56:39 -05001861 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1862 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1863 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1864}
1865
James Smarte59058c2008-08-24 21:49:00 -04001866/**
James Smart3621a712009-04-06 18:47:14 -04001867 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001868 * @dev: class device that is converted into a Scsi_host.
1869 * @attr: device attribute, not used.
1870 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1871 *
1872 * Description:
1873 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1874 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1875 * to "Unknown" and the buffer length is returned, therefore the caller
1876 * must check for "Unknown" in the buffer to detect a failure.
1877 *
1878 * Returns: size of formatted string.
1879 **/
James Smart858c9f62007-06-17 19:56:39 -05001880static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001881lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1882 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001883{
Tony Jonesee959b02008-02-22 00:13:36 +01001884 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001885 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1886 struct lpfc_hba *phba = vport->phba;
1887 uint32_t cnt;
1888
1889 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1890 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1891 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1892}
1893
James Smarte59058c2008-08-24 21:49:00 -04001894/**
James Smart3621a712009-04-06 18:47:14 -04001895 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001896 * @dev: class device that is converted into a Scsi_host.
1897 * @attr: device attribute, not used.
1898 * @buf: on return contains the used vpi count in decimal or "Unknown".
1899 *
1900 * Description:
1901 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1902 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1903 * to "Unknown" and the buffer length is returned, therefore the caller
1904 * must check for "Unknown" in the buffer to detect a failure.
1905 *
1906 * Returns: size of formatted string.
1907 **/
James Smart858c9f62007-06-17 19:56:39 -05001908static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001909lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1910 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001911{
Tony Jonesee959b02008-02-22 00:13:36 +01001912 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001913 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1914 struct lpfc_hba *phba = vport->phba;
1915 uint32_t cnt, acnt;
1916
1917 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001918 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1919 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1920}
1921
James Smarte59058c2008-08-24 21:49:00 -04001922/**
James Smart3621a712009-04-06 18:47:14 -04001923 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001924 * @dev: class device that is converted into a Scsi_host.
1925 * @attr: device attribute, not used.
1926 * @buf: text that must be interpreted to determine if npiv is supported.
1927 *
1928 * Description:
1929 * Buffer will contain text indicating npiv is not suppoerted on the port,
1930 * the port is an NPIV physical port, or it is an npiv virtual port with
1931 * the id of the vport.
1932 *
1933 * Returns: size of formatted string.
1934 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001935static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001936lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1937 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001938{
Tony Jonesee959b02008-02-22 00:13:36 +01001939 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001940 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1941 struct lpfc_hba *phba = vport->phba;
1942
1943 if (!(phba->max_vpi))
1944 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1945 if (vport->port_type == LPFC_PHYSICAL_PORT)
1946 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1947 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1948}
1949
James Smarte59058c2008-08-24 21:49:00 -04001950/**
James Smart3621a712009-04-06 18:47:14 -04001951 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001952 * @dev: class device that is converted into a Scsi_host.
1953 * @attr: device attribute, not used.
1954 * @buf: on return contains the cfg_poll in hex.
1955 *
1956 * Notes:
1957 * cfg_poll should be a lpfc_polling_flags type.
1958 *
1959 * Returns: size of formatted string.
1960 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001961static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001962lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1963 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001964{
Tony Jonesee959b02008-02-22 00:13:36 +01001965 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001966 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1967 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001968
1969 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1970}
1971
James Smarte59058c2008-08-24 21:49:00 -04001972/**
James Smart3621a712009-04-06 18:47:14 -04001973 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001974 * @dev: class device that is converted into a Scsi_host.
1975 * @attr: device attribute, not used.
1976 * @buf: one or more lpfc_polling_flags values.
1977 * @count: not used.
1978 *
1979 * Notes:
1980 * buf contents converted to integer and checked for a valid value.
1981 *
1982 * Returns:
1983 * -EINVAL if the buffer connot be converted or is out of range
1984 * length of the buf on success
1985 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001986static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001987lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1988 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001989{
Tony Jonesee959b02008-02-22 00:13:36 +01001990 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001991 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1992 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001993 uint32_t creg_val;
1994 uint32_t old_val;
1995 int val=0;
1996
1997 if (!isdigit(buf[0]))
1998 return -EINVAL;
1999
2000 if (sscanf(buf, "%i", &val) != 1)
2001 return -EINVAL;
2002
2003 if ((val & 0x3) != val)
2004 return -EINVAL;
2005
James Smart45ed1192009-10-02 15:17:02 -04002006 if (phba->sli_rev == LPFC_SLI_REV4)
2007 val = 0;
2008
James Smart88a2cfb2011-07-22 18:36:33 -04002009 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2010 "3051 lpfc_poll changed from %d to %d\n",
2011 phba->cfg_poll, val);
2012
James Smart2e0fef82007-06-17 19:56:36 -05002013 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002014
2015 old_val = phba->cfg_poll;
2016
2017 if (val & ENABLE_FCP_RING_POLLING) {
2018 if ((val & DISABLE_FCP_RING_INT) &&
2019 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05002020 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2021 spin_unlock_irq(&phba->hbalock);
2022 return -EINVAL;
2023 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002024 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
2025 writel(creg_val, phba->HCregaddr);
2026 readl(phba->HCregaddr); /* flush */
2027
2028 lpfc_poll_start_timer(phba);
2029 }
2030 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05002031 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002032 return -EINVAL;
2033 }
2034
2035 if (!(val & DISABLE_FCP_RING_INT) &&
2036 (old_val & DISABLE_FCP_RING_INT))
2037 {
James Smart2e0fef82007-06-17 19:56:36 -05002038 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002039 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05002040 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05002041 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2042 spin_unlock_irq(&phba->hbalock);
2043 return -EINVAL;
2044 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002045 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2046 writel(creg_val, phba->HCregaddr);
2047 readl(phba->HCregaddr); /* flush */
2048 }
2049
2050 phba->cfg_poll = val;
2051
James Smart2e0fef82007-06-17 19:56:36 -05002052 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002053
2054 return strlen(buf);
2055}
dea31012005-04-17 16:05:31 -05002056
James Smarte59058c2008-08-24 21:49:00 -04002057/**
James Smartbc739052010-08-04 16:11:18 -04002058 * lpfc_fips_level_show - Return the current FIPS level for the HBA
2059 * @dev: class unused variable.
2060 * @attr: device attribute, not used.
2061 * @buf: on return contains the module description text.
2062 *
2063 * Returns: size of formatted string.
2064 **/
2065static ssize_t
2066lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
2067 char *buf)
2068{
2069 struct Scsi_Host *shost = class_to_shost(dev);
2070 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2071 struct lpfc_hba *phba = vport->phba;
2072
2073 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
2074}
2075
2076/**
2077 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
2078 * @dev: class unused variable.
2079 * @attr: device attribute, not used.
2080 * @buf: on return contains the module description text.
2081 *
2082 * Returns: size of formatted string.
2083 **/
2084static ssize_t
2085lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
2086 char *buf)
2087{
2088 struct Scsi_Host *shost = class_to_shost(dev);
2089 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2090 struct lpfc_hba *phba = vport->phba;
2091
2092 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
2093}
2094
2095/**
James Smartab56dc22011-02-16 12:39:57 -05002096 * lpfc_dss_show - Return the current state of dss and the configured state
2097 * @dev: class converted to a Scsi_host structure.
2098 * @attr: device attribute, not used.
2099 * @buf: on return contains the formatted text.
2100 *
2101 * Returns: size of formatted string.
2102 **/
2103static ssize_t
2104lpfc_dss_show(struct device *dev, struct device_attribute *attr,
2105 char *buf)
2106{
2107 struct Scsi_Host *shost = class_to_shost(dev);
2108 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2109 struct lpfc_hba *phba = vport->phba;
2110
2111 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
2112 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
2113 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
2114 "" : "Not ");
2115}
2116
2117/**
James Smart912e3ac2011-05-24 11:42:11 -04002118 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
2119 * @dev: class converted to a Scsi_host structure.
2120 * @attr: device attribute, not used.
2121 * @buf: on return contains the formatted support level.
2122 *
2123 * Description:
2124 * Returns the maximum number of virtual functions a physical function can
2125 * support, 0 will be returned if called on virtual function.
2126 *
2127 * Returns: size of formatted string.
2128 **/
2129static ssize_t
2130lpfc_sriov_hw_max_virtfn_show(struct device *dev,
2131 struct device_attribute *attr,
2132 char *buf)
2133{
2134 struct Scsi_Host *shost = class_to_shost(dev);
2135 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2136 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04002137 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04002138
James Smart0a96e972011-07-22 18:37:28 -04002139 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
2140 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04002141}
2142
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002143static inline bool lpfc_rangecheck(uint val, uint min, uint max)
2144{
2145 return val >= min && val <= max;
2146}
2147
James Smart912e3ac2011-05-24 11:42:11 -04002148/**
James Smart44fd7fe2017-08-23 16:55:47 -07002149 * lpfc_enable_bbcr_set: Sets an attribute value.
2150 * @phba: pointer the the adapter structure.
2151 * @val: integer attribute value.
2152 *
2153 * Description:
2154 * Validates the min and max values then sets the
2155 * adapter config field if in the valid range. prints error message
2156 * and does not set the parameter if invalid.
2157 *
2158 * Returns:
2159 * zero on success
2160 * -EINVAL if val is invalid
2161 */
2162static ssize_t
2163lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
2164{
2165 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
2166 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2167 "3068 %s_enable_bbcr changed from %d to %d\n",
2168 LPFC_DRIVER_NAME, phba->cfg_enable_bbcr, val);
2169 phba->cfg_enable_bbcr = val;
2170 return 0;
2171 }
2172 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2173 "0451 %s_enable_bbcr cannot set to %d, range is 0, 1\n",
2174 LPFC_DRIVER_NAME, val);
2175 return -EINVAL;
2176}
2177
2178/**
James Smart3621a712009-04-06 18:47:14 -04002179 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04002180 *
2181 * Description:
2182 * Macro that given an attr e.g. hba_queue_depth expands
2183 * into a function with the name lpfc_hba_queue_depth_show.
2184 *
2185 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
2186 * @dev: class device that is converted into a Scsi_host.
2187 * @attr: device attribute, not used.
2188 * @buf: on return contains the attribute value in decimal.
2189 *
2190 * Returns: size of formatted string.
2191 **/
dea31012005-04-17 16:05:31 -05002192#define lpfc_param_show(attr) \
2193static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002194lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2195 char *buf) \
dea31012005-04-17 16:05:31 -05002196{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002197 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002198 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2199 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002200 return snprintf(buf, PAGE_SIZE, "%d\n",\
2201 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05002202}
2203
James Smarte59058c2008-08-24 21:49:00 -04002204/**
James Smart3621a712009-04-06 18:47:14 -04002205 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04002206 *
2207 * Description:
2208 * Macro that given an attr e.g. hba_queue_depth expands
2209 * into a function with the name lpfc_hba_queue_depth_show
2210 *
2211 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
2212 * @dev: class device that is converted into a Scsi_host.
2213 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002214 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002215 *
2216 * Returns: size of formatted string.
2217 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002218#define lpfc_param_hex_show(attr) \
2219static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002220lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2221 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002222{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002223 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002224 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2225 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05002226 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002227 val = phba->cfg_##attr;\
2228 return snprintf(buf, PAGE_SIZE, "%#x\n",\
2229 phba->cfg_##attr);\
2230}
2231
James Smarte59058c2008-08-24 21:49:00 -04002232/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04002233 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002234 *
2235 * Description:
2236 * Macro that given an attr e.g. hba_queue_depth expands
2237 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2238 * takes a default argument, a minimum and maximum argument.
2239 *
2240 * lpfc_##attr##_init: Initializes an attribute.
2241 * @phba: pointer the the adapter structure.
2242 * @val: integer attribute value.
2243 *
2244 * Validates the min and max values then sets the adapter config field
2245 * accordingly, or uses the default if out of range and prints an error message.
2246 *
2247 * Returns:
2248 * zero on success
2249 * -EINVAL if default used
2250 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002251#define lpfc_param_init(attr, default, minval, maxval) \
2252static int \
James Smart84d1b002010-02-12 14:42:33 -05002253lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002254{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002255 if (lpfc_rangecheck(val, minval, maxval)) {\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002256 phba->cfg_##attr = val;\
2257 return 0;\
2258 }\
2259 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04002260 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2261 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002262 phba->cfg_##attr = default;\
2263 return -EINVAL;\
2264}
2265
James Smarte59058c2008-08-24 21:49:00 -04002266/**
James Smart3621a712009-04-06 18:47:14 -04002267 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04002268 *
2269 * Description:
2270 * Macro that given an attr e.g. hba_queue_depth expands
2271 * into a function with the name lpfc_hba_queue_depth_set
2272 *
2273 * lpfc_##attr##_set: Sets an attribute value.
2274 * @phba: pointer the the adapter structure.
2275 * @val: integer attribute value.
2276 *
2277 * Description:
2278 * Validates the min and max values then sets the
2279 * adapter config field if in the valid range. prints error message
2280 * and does not set the parameter if invalid.
2281 *
2282 * Returns:
2283 * zero on success
2284 * -EINVAL if val is invalid
2285 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002286#define lpfc_param_set(attr, default, minval, maxval) \
2287static int \
James Smart84d1b002010-02-12 14:42:33 -05002288lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002289{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002290 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002291 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2292 "3052 lpfc_" #attr " changed from %d to %d\n", \
2293 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002294 phba->cfg_##attr = val;\
2295 return 0;\
2296 }\
2297 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04002298 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2299 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002300 return -EINVAL;\
2301}
2302
James Smarte59058c2008-08-24 21:49:00 -04002303/**
James Smart3621a712009-04-06 18:47:14 -04002304 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04002305 *
2306 * Description:
2307 * Macro that given an attr e.g. hba_queue_depth expands
2308 * into a function with the name lpfc_hba_queue_depth_store.
2309 *
2310 * lpfc_##attr##_store: Set an sttribute value.
2311 * @dev: class device that is converted into a Scsi_host.
2312 * @attr: device attribute, not used.
2313 * @buf: contains the attribute value in ascii.
2314 * @count: not used.
2315 *
2316 * Description:
2317 * Convert the ascii text number to an integer, then
2318 * use the lpfc_##attr##_set function to set the value.
2319 *
2320 * Returns:
2321 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2322 * length of buffer upon success.
2323 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002324#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05002325static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002326lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2327 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05002328{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002329 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002330 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2331 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05002332 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002333 if (!isdigit(buf[0]))\
2334 return -EINVAL;\
2335 if (sscanf(buf, "%i", &val) != 1)\
2336 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002337 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04002338 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002339 else \
2340 return -EINVAL;\
dea31012005-04-17 16:05:31 -05002341}
2342
James Smarte59058c2008-08-24 21:49:00 -04002343/**
James Smart3621a712009-04-06 18:47:14 -04002344 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04002345 *
2346 * Description:
2347 * Macro that given an attr e.g. hba_queue_depth expands
2348 * into a function with the name lpfc_hba_queue_depth_show
2349 *
2350 * lpfc_##attr##_show: prints the attribute value in decimal.
2351 * @dev: class device that is converted into a Scsi_host.
2352 * @attr: device attribute, not used.
2353 * @buf: on return contains the attribute value in decimal.
2354 *
2355 * Returns: length of formatted string.
2356 **/
James Smart3de2a652007-08-02 11:09:59 -04002357#define lpfc_vport_param_show(attr) \
2358static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002359lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2360 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002361{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002362 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002363 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002364 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2365}
2366
James Smarte59058c2008-08-24 21:49:00 -04002367/**
James Smart3621a712009-04-06 18:47:14 -04002368 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04002369 *
2370 * Description:
2371 * Macro that given an attr e.g.
2372 * hba_queue_depth expands into a function with the name
2373 * lpfc_hba_queue_depth_show
2374 *
James Smart3621a712009-04-06 18:47:14 -04002375 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002376 * @dev: class device that is converted into a Scsi_host.
2377 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002378 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002379 *
2380 * Returns: length of formatted string.
2381 **/
James Smart3de2a652007-08-02 11:09:59 -04002382#define lpfc_vport_param_hex_show(attr) \
2383static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002384lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2385 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002386{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002387 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002388 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002389 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2390}
2391
James Smarte59058c2008-08-24 21:49:00 -04002392/**
James Smart3621a712009-04-06 18:47:14 -04002393 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002394 *
2395 * Description:
2396 * Macro that given an attr e.g. hba_queue_depth expands
2397 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2398 * takes a default argument, a minimum and maximum argument.
2399 *
2400 * lpfc_##attr##_init: validates the min and max values then sets the
2401 * adapter config field accordingly, or uses the default if out of range
2402 * and prints an error message.
2403 * @phba: pointer the the adapter structure.
2404 * @val: integer attribute value.
2405 *
2406 * Returns:
2407 * zero on success
2408 * -EINVAL if default used
2409 **/
James Smart3de2a652007-08-02 11:09:59 -04002410#define lpfc_vport_param_init(attr, default, minval, maxval) \
2411static int \
James Smart84d1b002010-02-12 14:42:33 -05002412lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002413{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002414 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart3de2a652007-08-02 11:09:59 -04002415 vport->cfg_##attr = val;\
2416 return 0;\
2417 }\
James Smarte8b62012007-08-02 11:10:09 -04002418 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002419 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002420 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002421 vport->cfg_##attr = default;\
2422 return -EINVAL;\
2423}
2424
James Smarte59058c2008-08-24 21:49:00 -04002425/**
James Smart3621a712009-04-06 18:47:14 -04002426 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002427 *
2428 * Description:
2429 * Macro that given an attr e.g. hba_queue_depth expands
2430 * into a function with the name lpfc_hba_queue_depth_set
2431 *
2432 * lpfc_##attr##_set: validates the min and max values then sets the
2433 * adapter config field if in the valid range. prints error message
2434 * and does not set the parameter if invalid.
2435 * @phba: pointer the the adapter structure.
2436 * @val: integer attribute value.
2437 *
2438 * Returns:
2439 * zero on success
2440 * -EINVAL if val is invalid
2441 **/
James Smart3de2a652007-08-02 11:09:59 -04002442#define lpfc_vport_param_set(attr, default, minval, maxval) \
2443static int \
James Smart84d1b002010-02-12 14:42:33 -05002444lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002445{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002446 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002447 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04002448 "3053 lpfc_" #attr \
2449 " changed from %d (x%x) to %d (x%x)\n", \
2450 vport->cfg_##attr, vport->cfg_##attr, \
2451 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04002452 vport->cfg_##attr = val;\
2453 return 0;\
2454 }\
James Smarte8b62012007-08-02 11:10:09 -04002455 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002456 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002457 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002458 return -EINVAL;\
2459}
2460
James Smarte59058c2008-08-24 21:49:00 -04002461/**
James Smart3621a712009-04-06 18:47:14 -04002462 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04002463 *
2464 * Description:
2465 * Macro that given an attr e.g. hba_queue_depth
2466 * expands into a function with the name lpfc_hba_queue_depth_store
2467 *
2468 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2469 * use the lpfc_##attr##_set function to set the value.
2470 * @cdev: class device that is converted into a Scsi_host.
2471 * @buf: contains the attribute value in decimal.
2472 * @count: not used.
2473 *
2474 * Returns:
2475 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2476 * length of buffer upon success.
2477 **/
James Smart3de2a652007-08-02 11:09:59 -04002478#define lpfc_vport_param_store(attr) \
2479static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002480lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2481 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04002482{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002483 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002484 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05002485 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04002486 if (!isdigit(buf[0]))\
2487 return -EINVAL;\
2488 if (sscanf(buf, "%i", &val) != 1)\
2489 return -EINVAL;\
2490 if (lpfc_##attr##_set(vport, val) == 0) \
2491 return strlen(buf);\
2492 else \
2493 return -EINVAL;\
2494}
2495
2496
James Smart895427b2017-02-12 13:52:30 -08002497static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
James Smart81301a92008-12-04 22:39:46 -05002498static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2499static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2500static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2501static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002502static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2503static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2504static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2505static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2506static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2507static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2508static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2509static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002510static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2511 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002512static DEVICE_ATTR(option_rom_version, S_IRUGO,
2513 lpfc_option_rom_version_show, NULL);
2514static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2515 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002516static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002517static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
Joe Perchesc828a892017-12-19 10:15:08 -08002518static DEVICE_ATTR_RO(lpfc_drvr_version);
2519static DEVICE_ATTR_RO(lpfc_enable_fip);
Tony Jonesee959b02008-02-22 00:13:36 +01002520static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2521 lpfc_board_mode_show, lpfc_board_mode_store);
2522static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2523static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2524static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2525static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2526static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2527static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2528static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2529static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
Joe Perchesc828a892017-12-19 10:15:08 -08002530static DEVICE_ATTR_RO(lpfc_temp_sensor);
2531static DEVICE_ATTR_RO(lpfc_fips_level);
2532static DEVICE_ATTR_RO(lpfc_fips_rev);
2533static DEVICE_ATTR_RO(lpfc_dss);
2534static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
James Smart026abb82011-12-13 13:20:45 -05002535static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05002536static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2537 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002538
James Smart352e5fd2016-12-30 06:57:47 -08002539static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smart1ba981f2014-02-20 09:56:45 -05002540#define WWN_SZ 8
2541/**
2542 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2543 * @buf: WWN string.
2544 * @cnt: Length of string.
2545 * @wwn: Array to receive converted wwn value.
2546 *
2547 * Returns:
2548 * -EINVAL if the buffer does not contain a valid wwn
2549 * 0 success
2550 **/
2551static size_t
2552lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2553{
2554 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002555
James Smart1ba981f2014-02-20 09:56:45 -05002556 /* Count may include a LF at end of string */
2557 if (buf[cnt-1] == '\n')
2558 cnt--;
2559
2560 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2561 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2562 return -EINVAL;
2563
2564 memset(wwn, 0, WWN_SZ);
2565
2566 /* Validate and store the new name */
2567 for (i = 0, j = 0; i < 16; i++) {
2568 if ((*buf >= 'a') && (*buf <= 'f'))
2569 j = ((j << 4) | ((*buf++ - 'a') + 10));
2570 else if ((*buf >= 'A') && (*buf <= 'F'))
2571 j = ((j << 4) | ((*buf++ - 'A') + 10));
2572 else if ((*buf >= '0') && (*buf <= '9'))
2573 j = ((j << 4) | (*buf++ - '0'));
2574 else
2575 return -EINVAL;
2576 if (i % 2) {
2577 wwn[i/2] = j & 0xff;
2578 j = 0;
2579 }
2580 }
2581 return 0;
2582}
James Smart352e5fd2016-12-30 06:57:47 -08002583/**
2584 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2585 * @dev: class device that is converted into a Scsi_host.
2586 * @attr: device attribute, not used.
2587 * @buf: containing the string lpfc_soft_wwn_key.
2588 * @count: must be size of lpfc_soft_wwn_key.
2589 *
2590 * Returns:
2591 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2592 * length of buf indicates success
2593 **/
2594static ssize_t
2595lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2596 const char *buf, size_t count)
2597{
2598 struct Scsi_Host *shost = class_to_shost(dev);
2599 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2600 struct lpfc_hba *phba = vport->phba;
2601 unsigned int cnt = count;
James Smartaeb3c812017-04-21 16:05:02 -07002602 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2603 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
James Smart352e5fd2016-12-30 06:57:47 -08002604
2605 /*
2606 * We're doing a simple sanity check for soft_wwpn setting.
2607 * We require that the user write a specific key to enable
2608 * the soft_wwpn attribute to be settable. Once the attribute
2609 * is written, the enable key resets. If further updates are
2610 * desired, the key must be written again to re-enable the
2611 * attribute.
2612 *
2613 * The "key" is not secret - it is a hardcoded string shown
2614 * here. The intent is to protect against the random user or
2615 * application that is just writing attributes.
2616 */
James Smartaeb3c812017-04-21 16:05:02 -07002617 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2618 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2619 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2620 " be enabled: fawwpn is enabled\n");
2621 return -EINVAL;
2622 }
James Smart352e5fd2016-12-30 06:57:47 -08002623
2624 /* count may include a LF at end of string */
2625 if (buf[cnt-1] == '\n')
2626 cnt--;
2627
2628 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2629 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2630 return -EINVAL;
2631
2632 phba->soft_wwn_enable = 1;
2633
2634 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2635 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2636 phba->brd_no);
2637 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2638 " The soft_wwpn feature is not supported by Broadcom.");
2639
2640 return count;
2641}
Joe Perches6cbaefb2017-12-19 10:15:09 -08002642static DEVICE_ATTR_WO(lpfc_soft_wwn_enable);
James Smart352e5fd2016-12-30 06:57:47 -08002643
2644/**
2645 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2646 * @dev: class device that is converted into a Scsi_host.
2647 * @attr: device attribute, not used.
2648 * @buf: on return contains the wwpn in hexadecimal.
2649 *
2650 * Returns: size of formatted string.
2651 **/
2652static ssize_t
2653lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2654 char *buf)
2655{
2656 struct Scsi_Host *shost = class_to_shost(dev);
2657 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2658 struct lpfc_hba *phba = vport->phba;
2659
2660 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2661 (unsigned long long)phba->cfg_soft_wwpn);
2662}
2663
2664/**
2665 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2666 * @dev class device that is converted into a Scsi_host.
2667 * @attr: device attribute, not used.
2668 * @buf: contains the wwpn in hexadecimal.
2669 * @count: number of wwpn bytes in buf
2670 *
2671 * Returns:
2672 * -EACCES hba reset not enabled, adapter over temp
2673 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2674 * -EIO error taking adapter offline or online
2675 * value of count on success
2676 **/
2677static ssize_t
2678lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2679 const char *buf, size_t count)
2680{
2681 struct Scsi_Host *shost = class_to_shost(dev);
2682 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2683 struct lpfc_hba *phba = vport->phba;
2684 struct completion online_compl;
2685 int stat1 = 0, stat2 = 0;
2686 unsigned int cnt = count;
2687 u8 wwpn[WWN_SZ];
2688 int rc;
2689
2690 if (!phba->cfg_enable_hba_reset)
2691 return -EACCES;
2692 spin_lock_irq(&phba->hbalock);
2693 if (phba->over_temp_state == HBA_OVER_TEMP) {
2694 spin_unlock_irq(&phba->hbalock);
2695 return -EACCES;
2696 }
2697 spin_unlock_irq(&phba->hbalock);
2698 /* count may include a LF at end of string */
2699 if (buf[cnt-1] == '\n')
2700 cnt--;
2701
2702 if (!phba->soft_wwn_enable)
2703 return -EINVAL;
2704
2705 /* lock setting wwpn, wwnn down */
2706 phba->soft_wwn_enable = 0;
2707
2708 rc = lpfc_wwn_set(buf, cnt, wwpn);
James Smarte2934ed2017-01-17 12:31:56 -08002709 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002710 /* not able to set wwpn, unlock it */
2711 phba->soft_wwn_enable = 1;
2712 return rc;
2713 }
2714
2715 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2716 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2717 if (phba->cfg_soft_wwnn)
2718 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2719
2720 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2721 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2722
2723 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2724 if (stat1)
2725 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2726 "0463 lpfc_soft_wwpn attribute set failed to "
2727 "reinit adapter - %d\n", stat1);
2728 init_completion(&online_compl);
2729 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2730 LPFC_EVT_ONLINE);
2731 if (rc == 0)
2732 return -ENOMEM;
2733
2734 wait_for_completion(&online_compl);
2735 if (stat2)
2736 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2737 "0464 lpfc_soft_wwpn attribute set failed to "
2738 "reinit adapter - %d\n", stat2);
2739 return (stat1 || stat2) ? -EIO : count;
2740}
Joe Perchesb6b996b2017-12-19 10:15:07 -08002741static DEVICE_ATTR_RW(lpfc_soft_wwpn);
James Smart352e5fd2016-12-30 06:57:47 -08002742
2743/**
2744 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2745 * @dev: class device that is converted into a Scsi_host.
2746 * @attr: device attribute, not used.
2747 * @buf: on return contains the wwnn in hexadecimal.
2748 *
2749 * Returns: size of formatted string.
2750 **/
2751static ssize_t
2752lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2753 char *buf)
2754{
2755 struct Scsi_Host *shost = class_to_shost(dev);
2756 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2757 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2758 (unsigned long long)phba->cfg_soft_wwnn);
2759}
2760
2761/**
2762 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2763 * @cdev: class device that is converted into a Scsi_host.
2764 * @buf: contains the ww node name in hexadecimal.
2765 * @count: number of wwnn bytes in buf.
2766 *
2767 * Returns:
2768 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2769 * value of count on success
2770 **/
2771static ssize_t
2772lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2773 const char *buf, size_t count)
2774{
2775 struct Scsi_Host *shost = class_to_shost(dev);
2776 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2777 unsigned int cnt = count;
2778 u8 wwnn[WWN_SZ];
2779 int rc;
2780
2781 /* count may include a LF at end of string */
2782 if (buf[cnt-1] == '\n')
2783 cnt--;
2784
2785 if (!phba->soft_wwn_enable)
2786 return -EINVAL;
2787
2788 rc = lpfc_wwn_set(buf, cnt, wwnn);
James Smarte2934ed2017-01-17 12:31:56 -08002789 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002790 /* Allow wwnn to be set many times, as long as the enable
2791 * is set. However, once the wwpn is set, everything locks.
2792 */
2793 return rc;
2794 }
2795
2796 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2797
2798 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2799 "lpfc%d: soft_wwnn set. Value will take effect upon "
2800 "setting of the soft_wwpn\n", phba->brd_no);
2801
2802 return count;
2803}
Joe Perchesb6b996b2017-12-19 10:15:07 -08002804static DEVICE_ATTR_RW(lpfc_soft_wwnn);
James Smarta12e07b2006-12-02 13:35:30 -05002805
James Smart1ba981f2014-02-20 09:56:45 -05002806/**
2807 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2808 * Optimized Access Storage (OAS) operations.
2809 * @dev: class device that is converted into a Scsi_host.
2810 * @attr: device attribute, not used.
2811 * @buf: buffer for passing information.
2812 *
2813 * Returns:
2814 * value of count
2815 **/
2816static ssize_t
2817lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2818 char *buf)
2819{
2820 struct Scsi_Host *shost = class_to_shost(dev);
2821 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2822
2823 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2824 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2825}
2826
2827/**
2828 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2829 * Optimized Access Storage (OAS) operations.
2830 * @dev: class device that is converted into a Scsi_host.
2831 * @attr: device attribute, not used.
2832 * @buf: buffer for passing information.
2833 * @count: Size of the data buffer.
2834 *
2835 * Returns:
2836 * -EINVAL count is invalid, invalid wwpn byte invalid
2837 * -EPERM oas is not supported by hba
2838 * value of count on success
2839 **/
2840static ssize_t
2841lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2842 const char *buf, size_t count)
2843{
2844 struct Scsi_Host *shost = class_to_shost(dev);
2845 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2846 unsigned int cnt = count;
2847 uint8_t wwpn[WWN_SZ];
2848 int rc;
2849
James Smartf38fa0b2014-04-04 13:52:21 -04002850 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002851 return -EPERM;
2852
2853 /* count may include a LF at end of string */
2854 if (buf[cnt-1] == '\n')
2855 cnt--;
2856
2857 rc = lpfc_wwn_set(buf, cnt, wwpn);
2858 if (rc)
2859 return rc;
2860
2861 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2862 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2863 if (wwn_to_u64(wwpn) == 0)
2864 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2865 else
2866 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2867 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2868 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2869 return count;
2870}
2871static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2872 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2873
2874/**
James Smartc92c8412016-07-06 12:36:05 -07002875 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2876 * Optimized Access Storage (OAS) operations.
2877 * @dev: class device that is converted into a Scsi_host.
2878 * @attr: device attribute, not used.
2879 * @buf: buffer for passing information.
2880 *
2881 * Returns:
2882 * value of count
2883 **/
2884static ssize_t
2885lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2886 char *buf)
2887{
2888 struct Scsi_Host *shost = class_to_shost(dev);
2889 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2890
2891 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2892}
2893
2894/**
2895 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2896 * Optimized Access Storage (OAS) operations.
2897 * @dev: class device that is converted into a Scsi_host.
2898 * @attr: device attribute, not used.
2899 * @buf: buffer for passing information.
2900 * @count: Size of the data buffer.
2901 *
2902 * Returns:
2903 * -EINVAL count is invalid, invalid wwpn byte invalid
2904 * -EPERM oas is not supported by hba
2905 * value of count on success
2906 **/
2907static ssize_t
2908lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2909 const char *buf, size_t count)
2910{
2911 struct Scsi_Host *shost = class_to_shost(dev);
2912 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2913 unsigned int cnt = count;
2914 unsigned long val;
2915 int ret;
2916
2917 if (!phba->cfg_fof)
2918 return -EPERM;
2919
2920 /* count may include a LF at end of string */
2921 if (buf[cnt-1] == '\n')
2922 cnt--;
2923
2924 ret = kstrtoul(buf, 0, &val);
2925 if (ret || (val > 0x7f))
2926 return -EINVAL;
2927
2928 if (val)
2929 phba->cfg_oas_priority = (uint8_t)val;
2930 else
2931 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2932 return count;
2933}
2934static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2935 lpfc_oas_priority_show, lpfc_oas_priority_store);
2936
2937/**
James Smart1ba981f2014-02-20 09:56:45 -05002938 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2939 * for Optimized Access Storage (OAS) operations.
2940 * @dev: class device that is converted into a Scsi_host.
2941 * @attr: device attribute, not used.
2942 * @buf: buffer for passing information.
2943 *
2944 * Returns:
2945 * value of count on success
2946 **/
2947static ssize_t
2948lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2949 char *buf)
2950{
2951 struct Scsi_Host *shost = class_to_shost(dev);
2952 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2953
2954 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2955 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2956}
2957
2958/**
2959 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2960 * for Optimized Access Storage (OAS) operations.
2961 * @dev: class device that is converted into a Scsi_host.
2962 * @attr: device attribute, not used.
2963 * @buf: buffer for passing information.
2964 * @count: Size of the data buffer.
2965 *
2966 * Returns:
2967 * -EINVAL count is invalid, invalid wwpn byte invalid
2968 * -EPERM oas is not supported by hba
2969 * value of count on success
2970 **/
2971static ssize_t
2972lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2973 const char *buf, size_t count)
2974{
2975 struct Scsi_Host *shost = class_to_shost(dev);
2976 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2977 unsigned int cnt = count;
2978 uint8_t wwpn[WWN_SZ];
2979 int rc;
2980
James Smartf38fa0b2014-04-04 13:52:21 -04002981 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002982 return -EPERM;
2983
2984 /* count may include a LF at end of string */
2985 if (buf[cnt-1] == '\n')
2986 cnt--;
2987
2988 rc = lpfc_wwn_set(buf, cnt, wwpn);
2989 if (rc)
2990 return rc;
2991
2992 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2993 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2994 if (wwn_to_u64(wwpn) == 0)
2995 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2996 else
2997 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2998 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
James Smartb5749fe2016-12-19 15:07:26 -08002999 if (phba->cfg_oas_priority == 0)
3000 phba->cfg_oas_priority = phba->cfg_XLanePriority;
James Smart1ba981f2014-02-20 09:56:45 -05003001 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3002 return count;
3003}
3004static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
3005 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
3006
3007/**
3008 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
3009 * of whether luns will be enabled or disabled
3010 * for 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 *
3015 * Returns:
3016 * size of formatted string.
3017 **/
3018static ssize_t
3019lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
3020 char *buf)
3021{
3022 struct Scsi_Host *shost = class_to_shost(dev);
3023 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3024
3025 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
3026}
3027
3028/**
3029 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
3030 * of whether luns will be enabled or disabled
3031 * for Optimized Access Storage (OAS) operations.
3032 * @dev: class device that is converted into a Scsi_host.
3033 * @attr: device attribute, not used.
3034 * @buf: buffer for passing information.
3035 * @count: Size of the data buffer.
3036 *
3037 * Returns:
3038 * -EINVAL count is invalid, invalid wwpn byte invalid
3039 * -EPERM oas is not supported by hba
3040 * value of count on success
3041 **/
3042static ssize_t
3043lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
3044 const char *buf, size_t count)
3045{
3046 struct Scsi_Host *shost = class_to_shost(dev);
3047 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3048 int val = 0;
3049
James Smartf38fa0b2014-04-04 13:52:21 -04003050 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003051 return -EPERM;
3052
3053 if (!isdigit(buf[0]))
3054 return -EINVAL;
3055
3056 if (sscanf(buf, "%i", &val) != 1)
3057 return -EINVAL;
3058
3059 if ((val != 0) && (val != 1))
3060 return -EINVAL;
3061
3062 phba->cfg_oas_lun_state = val;
James Smart1ba981f2014-02-20 09:56:45 -05003063 return strlen(buf);
3064}
3065static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
3066 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
3067
3068/**
3069 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
3070 * Storage (OAS) lun returned by the
3071 * lpfc_oas_lun_show function.
3072 * @dev: class device that is converted into a Scsi_host.
3073 * @attr: device attribute, not used.
3074 * @buf: buffer for passing information.
3075 *
3076 * Returns:
3077 * size of formatted string.
3078 **/
3079static ssize_t
3080lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
3081 char *buf)
3082{
3083 struct Scsi_Host *shost = class_to_shost(dev);
3084 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3085
3086 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
3087 return -EFAULT;
3088
3089 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
3090}
3091static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
3092 lpfc_oas_lun_status_show, NULL);
3093
3094
3095/**
3096 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
3097 * (OAS) operations.
3098 * @phba: lpfc_hba pointer.
3099 * @ndlp: pointer to fcp target node.
3100 * @lun: the fc lun for setting oas state.
3101 * @oas_state: the oas state to be set to the lun.
3102 *
3103 * Returns:
3104 * SUCCESS : 0
3105 * -EPERM OAS is not enabled or not supported by this port.
3106 *
3107 */
3108static size_t
3109lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartc92c8412016-07-06 12:36:05 -07003110 uint8_t tgt_wwpn[], uint64_t lun,
3111 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05003112{
3113
3114 int rc = 0;
3115
James Smartf38fa0b2014-04-04 13:52:21 -04003116 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003117 return -EPERM;
3118
3119 if (oas_state) {
3120 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07003121 (struct lpfc_name *)tgt_wwpn,
3122 lun, pri))
James Smart1ba981f2014-02-20 09:56:45 -05003123 rc = -ENOMEM;
3124 } else {
3125 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08003126 (struct lpfc_name *)tgt_wwpn, lun, pri);
James Smart1ba981f2014-02-20 09:56:45 -05003127 }
3128 return rc;
3129
3130}
3131
3132/**
3133 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
3134 * Access Storage (OAS) operations.
3135 * @phba: lpfc_hba pointer.
3136 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3137 * @tgt_wwpn: wwpn of the target associated with the returned lun
3138 * @lun_status: status of the lun returned lun
3139 *
3140 * Returns the first or next lun enabled for OAS operations for the vport/target
3141 * specified. If a lun is found, its vport wwpn, target wwpn and status is
3142 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
3143 *
3144 * Return:
3145 * lun that is OAS enabled for the vport/target
3146 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
3147 */
3148static uint64_t
3149lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartb5749fe2016-12-19 15:07:26 -08003150 uint8_t tgt_wwpn[], uint32_t *lun_status,
3151 uint32_t *lun_pri)
James Smart1ba981f2014-02-20 09:56:45 -05003152{
3153 uint64_t found_lun;
3154
3155 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
3156 return NOT_OAS_ENABLED_LUN;
3157 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
3158 phba->sli4_hba.oas_next_vpt_wwpn,
3159 (struct lpfc_name *)
3160 phba->sli4_hba.oas_next_tgt_wwpn,
3161 &phba->sli4_hba.oas_next_lun,
3162 (struct lpfc_name *)vpt_wwpn,
3163 (struct lpfc_name *)tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08003164 &found_lun, lun_status, lun_pri))
James Smart1ba981f2014-02-20 09:56:45 -05003165 return found_lun;
3166 else
3167 return NOT_OAS_ENABLED_LUN;
3168}
3169
3170/**
3171 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
3172 * @phba: lpfc_hba pointer.
3173 * @vpt_wwpn: vport wwpn by reference.
3174 * @tgt_wwpn: target wwpn by reference.
3175 * @lun: the fc lun for setting oas state.
3176 * @oas_state: the oas state to be set to the oas_lun.
3177 *
3178 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
3179 * a lun for OAS operations.
3180 *
3181 * Return:
3182 * SUCCESS: 0
3183 * -ENOMEM: failed to enable an lun for OAS operations
3184 * -EPERM: OAS is not enabled
3185 */
3186static ssize_t
3187lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3188 uint8_t tgt_wwpn[], uint64_t lun,
James Smartc92c8412016-07-06 12:36:05 -07003189 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05003190{
3191
3192 int rc;
3193
3194 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
James Smartc92c8412016-07-06 12:36:05 -07003195 oas_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05003196 return rc;
3197}
3198
3199/**
3200 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
3201 * @dev: class device that is converted into a Scsi_host.
3202 * @attr: device attribute, not used.
3203 * @buf: buffer for passing information.
3204 *
3205 * This routine returns a lun enabled for OAS each time the function
3206 * is called.
3207 *
3208 * Returns:
3209 * SUCCESS: size of formatted string.
3210 * -EFAULT: target or vport wwpn was not set properly.
3211 * -EPERM: oas is not enabled.
3212 **/
3213static ssize_t
3214lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3215 char *buf)
3216{
3217 struct Scsi_Host *shost = class_to_shost(dev);
3218 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3219
3220 uint64_t oas_lun;
3221 int len = 0;
3222
James Smartf38fa0b2014-04-04 13:52:21 -04003223 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003224 return -EPERM;
3225
3226 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3227 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3228 return -EFAULT;
3229
3230 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3231 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3232 return -EFAULT;
3233
3234 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3235 phba->cfg_oas_tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08003236 &phba->cfg_oas_lun_status,
3237 &phba->cfg_oas_priority);
James Smart1ba981f2014-02-20 09:56:45 -05003238 if (oas_lun != NOT_OAS_ENABLED_LUN)
3239 phba->cfg_oas_flags |= OAS_LUN_VALID;
3240
3241 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3242
3243 return len;
3244}
3245
3246/**
3247 * lpfc_oas_lun_store - Sets the OAS state for lun
3248 * @dev: class device that is converted into a Scsi_host.
3249 * @attr: device attribute, not used.
3250 * @buf: buffer for passing information.
3251 *
3252 * This function sets the OAS state for lun. Before this function is called,
3253 * the vport wwpn, target wwpn, and oas state need to be set.
3254 *
3255 * Returns:
3256 * SUCCESS: size of formatted string.
3257 * -EFAULT: target or vport wwpn was not set properly.
3258 * -EPERM: oas is not enabled.
3259 * size of formatted string.
3260 **/
3261static ssize_t
3262lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3263 const char *buf, size_t count)
3264{
3265 struct Scsi_Host *shost = class_to_shost(dev);
3266 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3267 uint64_t scsi_lun;
James Smartb5749fe2016-12-19 15:07:26 -08003268 uint32_t pri;
James Smart1ba981f2014-02-20 09:56:45 -05003269 ssize_t rc;
3270
James Smartf38fa0b2014-04-04 13:52:21 -04003271 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003272 return -EPERM;
3273
3274 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3275 return -EFAULT;
3276
3277 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3278 return -EFAULT;
3279
3280 if (!isdigit(buf[0]))
3281 return -EINVAL;
3282
3283 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3284 return -EINVAL;
3285
James Smartb5749fe2016-12-19 15:07:26 -08003286 pri = phba->cfg_oas_priority;
3287 if (pri == 0)
3288 pri = phba->cfg_XLanePriority;
3289
James Smart1ba981f2014-02-20 09:56:45 -05003290 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartc92c8412016-07-06 12:36:05 -07003291 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3292 "priority 0x%x with oas state %d\n",
James Smart1ba981f2014-02-20 09:56:45 -05003293 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3294 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08003295 pri, phba->cfg_oas_lun_state);
James Smart1ba981f2014-02-20 09:56:45 -05003296
3297 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07003298 phba->cfg_oas_tgt_wwpn, scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08003299 phba->cfg_oas_lun_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05003300 if (rc)
3301 return rc;
3302
3303 return count;
3304}
3305static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3306 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04003307
James Smartf358dd02017-02-12 13:52:34 -08003308int lpfc_enable_nvmet_cnt;
3309unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3310 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3311 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3312module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3313MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3314
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003315static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05003316module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003317MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3318 " 0 - none,"
3319 " 1 - poll with interrupts enabled"
3320 " 3 - poll and disable FCP ring interrupts");
3321
Joe Perchesb6b996b2017-12-19 10:15:07 -08003322static DEVICE_ATTR_RW(lpfc_poll);
dea31012005-04-17 16:05:31 -05003323
James Smart96418b52017-03-04 09:30:31 -08003324int lpfc_no_hba_reset_cnt;
3325unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3326 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3327module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3328MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3329
James Smart12247e82016-07-06 12:36:09 -07003330LPFC_ATTR(sli_mode, 0, 0, 3,
3331 "SLI mode selector:"
3332 " 0 - auto (SLI-3 if supported),"
3333 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3334 " 3 - select SLI-3");
James Smart92d7f7b2007-06-17 19:56:38 -05003335
James Smart458c0832016-07-06 12:36:07 -07003336LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3337 "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05003338
James Smart7d791df2011-07-22 18:37:52 -04003339LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3340 "FCF Fast failover=1 Priority failover=2");
3341
James Smarte5771b42013-03-01 16:37:14 -05003342/*
3343# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3344# 0x0 = disabled, XRI/OXID use not tracked.
3345# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3346# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3347*/
James Smart31202b02016-10-13 15:06:08 -07003348LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3349 "Enable RRQ functionality");
James Smart19ca7602010-11-20 23:11:55 -05003350
dea31012005-04-17 16:05:31 -05003351/*
James Smart84d1b002010-02-12 14:42:33 -05003352# lpfc_suppress_link_up: Bring link up at initialization
3353# 0x0 = bring link up (issue MBX_INIT_LINK)
3354# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3355# 0x2 = never bring up link
3356# Default value is 0.
3357*/
James Smarte40a02c2010-02-26 14:13:54 -05003358LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3359 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3360 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04003361/*
3362# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3363# 1 - (1024)
3364# 2 - (2048)
3365# 3 - (3072)
3366# 4 - (4096)
3367# 5 - (5120)
3368*/
3369static ssize_t
3370lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3371{
3372 struct Scsi_Host *shost = class_to_shost(dev);
3373 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3374
3375 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3376}
3377
3378static DEVICE_ATTR(iocb_hw, S_IRUGO,
3379 lpfc_iocb_hw_show, NULL);
3380static ssize_t
3381lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3382{
3383 struct Scsi_Host *shost = class_to_shost(dev);
3384 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003385 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003386
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003387 return snprintf(buf, PAGE_SIZE, "%d\n",
3388 pring ? pring->txq_max : 0);
James Smart2a9bf3d2010-06-07 15:24:45 -04003389}
3390
3391static DEVICE_ATTR(txq_hw, S_IRUGO,
3392 lpfc_txq_hw_show, NULL);
3393static ssize_t
3394lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3395 char *buf)
3396{
3397 struct Scsi_Host *shost = class_to_shost(dev);
3398 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003399 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003400
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003401 return snprintf(buf, PAGE_SIZE, "%d\n",
3402 pring ? pring->txcmplq_max : 0);
James Smart2a9bf3d2010-06-07 15:24:45 -04003403}
3404
3405static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3406 lpfc_txcmplq_hw_show, NULL);
3407
James Smart0d8c8ba2016-10-13 15:06:07 -07003408LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
James Smart2a9bf3d2010-06-07 15:24:45 -04003409 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
James Smart84d1b002010-02-12 14:42:33 -05003410
3411/*
James Smartc01f3202006-08-18 17:47:08 -04003412# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3413# until the timer expires. Value range is [0,255]. Default value is 30.
3414*/
3415static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3416static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3417module_param(lpfc_nodev_tmo, int, 0);
3418MODULE_PARM_DESC(lpfc_nodev_tmo,
3419 "Seconds driver will hold I/O waiting "
3420 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04003421
3422/**
James Smart3621a712009-04-06 18:47:14 -04003423 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04003424 * @dev: class converted to a Scsi_host structure.
3425 * @attr: device attribute, not used.
3426 * @buf: on return contains the dev loss timeout in decimal.
3427 *
3428 * Returns: size of formatted string.
3429 **/
James Smartc01f3202006-08-18 17:47:08 -04003430static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003431lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3432 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04003433{
Tony Jonesee959b02008-02-22 00:13:36 +01003434 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003435 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05003436
James Smart3de2a652007-08-02 11:09:59 -04003437 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003438}
3439
James Smarte59058c2008-08-24 21:49:00 -04003440/**
James Smart3621a712009-04-06 18:47:14 -04003441 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04003442 * @vport: lpfc vport structure pointer.
3443 * @val: contains the nodev timeout value.
3444 *
3445 * Description:
3446 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3447 * a kernel error message is printed and zero is returned.
3448 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3449 * Otherwise nodev tmo is set to the default value.
3450 *
3451 * Returns:
3452 * zero if already set or if val is in range
3453 * -EINVAL val out of range
3454 **/
James Smartc01f3202006-08-18 17:47:08 -04003455static int
James Smart3de2a652007-08-02 11:09:59 -04003456lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003457{
James Smart3de2a652007-08-02 11:09:59 -04003458 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3459 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3460 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04003461 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003462 "0407 Ignoring lpfc_nodev_tmo module "
3463 "parameter because lpfc_devloss_tmo "
3464 "is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003465 return 0;
3466 }
3467
3468 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003469 vport->cfg_nodev_tmo = val;
3470 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04003471 return 0;
3472 }
James Smarte8b62012007-08-02 11:10:09 -04003473 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3474 "0400 lpfc_nodev_tmo attribute cannot be set to"
3475 " %d, allowed range is [%d, %d]\n",
3476 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04003477 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04003478 return -EINVAL;
3479}
3480
James Smarte59058c2008-08-24 21:49:00 -04003481/**
James Smart3621a712009-04-06 18:47:14 -04003482 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04003483 * @vport: lpfc vport structure pointer.
3484 *
3485 * Description:
3486 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3487 **/
James Smart7054a602007-04-25 09:52:34 -04003488static void
James Smart3de2a652007-08-02 11:09:59 -04003489lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04003490{
James Smart858c9f62007-06-17 19:56:39 -05003491 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04003492 struct lpfc_nodelist *ndlp;
James Smart01466022018-04-09 14:24:27 -07003493#if (IS_ENABLED(CONFIG_NVME_FC))
3494 struct lpfc_nvme_rport *rport;
James Smart9e210172018-09-13 15:41:10 -07003495 struct nvme_fc_remote_port *remoteport = NULL;
James Smart01466022018-04-09 14:24:27 -07003496#endif
James Smart7054a602007-04-25 09:52:34 -04003497
James Smart51ef4c22007-08-02 11:10:31 -04003498 shost = lpfc_shost_from_vport(vport);
3499 spin_lock_irq(shost->host_lock);
James Smart7a06dcd2017-06-01 21:06:55 -07003500 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3501 if (!NLP_CHK_NODE_ACT(ndlp))
3502 continue;
3503 if (ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04003504 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
James Smart6ddcf0a2017-11-03 09:33:30 -07003505#if (IS_ENABLED(CONFIG_NVME_FC))
James Smart9e210172018-09-13 15:41:10 -07003506 spin_lock(&vport->phba->hbalock);
James Smart01466022018-04-09 14:24:27 -07003507 rport = lpfc_ndlp_get_nrport(ndlp);
3508 if (rport)
James Smart9e210172018-09-13 15:41:10 -07003509 remoteport = rport->remoteport;
3510 spin_unlock(&vport->phba->hbalock);
3511 if (remoteport)
James Smart01466022018-04-09 14:24:27 -07003512 nvme_fc_set_remoteport_devloss(rport->remoteport,
James Smart6ddcf0a2017-11-03 09:33:30 -07003513 vport->cfg_devloss_tmo);
3514#endif
James Smart7a06dcd2017-06-01 21:06:55 -07003515 }
James Smart51ef4c22007-08-02 11:10:31 -04003516 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04003517}
3518
James Smarte59058c2008-08-24 21:49:00 -04003519/**
James Smart3621a712009-04-06 18:47:14 -04003520 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04003521 * @vport: lpfc vport structure pointer.
3522 * @val: contains the tmo value.
3523 *
3524 * Description:
3525 * If the devloss tmo is already set or the vport dev loss tmo has changed
3526 * then a kernel error message is printed and zero is returned.
3527 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3528 * Otherwise nodev tmo is set to the default value.
3529 *
3530 * Returns:
3531 * zero if already set or if val is in range
3532 * -EINVAL val out of range
3533 **/
James Smartc01f3202006-08-18 17:47:08 -04003534static int
James Smart3de2a652007-08-02 11:09:59 -04003535lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003536{
James Smart3de2a652007-08-02 11:09:59 -04003537 if (vport->dev_loss_tmo_changed ||
3538 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04003539 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003540 "0401 Ignoring change to lpfc_nodev_tmo "
3541 "because lpfc_devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003542 return 0;
3543 }
James Smartc01f3202006-08-18 17:47:08 -04003544 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003545 vport->cfg_nodev_tmo = val;
3546 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05003547 /*
3548 * For compat: set the fc_host dev loss so new rports
3549 * will get the value.
3550 */
3551 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003552 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003553 return 0;
3554 }
James Smarte8b62012007-08-02 11:10:09 -04003555 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003556 "0403 lpfc_nodev_tmo attribute cannot be set to "
James Smarte8b62012007-08-02 11:10:09 -04003557 "%d, allowed range is [%d, %d]\n",
3558 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003559 return -EINVAL;
3560}
3561
James Smart3de2a652007-08-02 11:09:59 -04003562lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04003563
Joe Perchesb6b996b2017-12-19 10:15:07 -08003564static DEVICE_ATTR_RW(lpfc_nodev_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003565
3566/*
3567# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3568# disappear until the timer expires. Value range is [0,255]. Default
3569# value is 30.
3570*/
James Smartab56dc22011-02-16 12:39:57 -05003571module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04003572MODULE_PARM_DESC(lpfc_devloss_tmo,
3573 "Seconds driver will hold I/O waiting "
3574 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04003575lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3576 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3577lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04003578
3579/**
James Smart3621a712009-04-06 18:47:14 -04003580 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04003581 * @vport: lpfc vport structure pointer.
3582 * @val: contains the tmo value.
3583 *
3584 * Description:
3585 * If val is in a valid range then set the vport nodev tmo,
3586 * devloss tmo, also set the vport dev loss tmo changed flag.
3587 * Else a kernel error message is printed.
3588 *
3589 * Returns:
3590 * zero if val is in range
3591 * -EINVAL val out of range
3592 **/
James Smartc01f3202006-08-18 17:47:08 -04003593static int
James Smart3de2a652007-08-02 11:09:59 -04003594lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003595{
3596 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003597 vport->cfg_nodev_tmo = val;
3598 vport->cfg_devloss_tmo = val;
3599 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05003600 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003601 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003602 return 0;
3603 }
3604
James Smarte8b62012007-08-02 11:10:09 -04003605 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003606 "0404 lpfc_devloss_tmo attribute cannot be set to "
3607 "%d, allowed range is [%d, %d]\n",
James Smarte8b62012007-08-02 11:10:09 -04003608 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003609 return -EINVAL;
3610}
3611
James Smart3de2a652007-08-02 11:09:59 -04003612lpfc_vport_param_store(devloss_tmo)
Joe Perchesb6b996b2017-12-19 10:15:07 -08003613static DEVICE_ATTR_RW(lpfc_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003614
3615/*
James Smartf358dd02017-02-12 13:52:34 -08003616 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3617 * lpfc_suppress_rsp = 0 Disable
3618 * lpfc_suppress_rsp = 1 Enable (default)
3619 *
3620 */
3621LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3622 "Enable suppress rsp feature is firmware supports it");
3623
3624/*
James Smart2d7dbc42017-02-12 13:52:35 -08003625 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
James Smartbcb24f62017-11-20 16:00:36 -08003626 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
James Smart2d7dbc42017-02-12 13:52:35 -08003627 * lpfc_nvmet_mrq = 1 use a single RQ pair
3628 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3629 *
3630 */
3631LPFC_ATTR_R(nvmet_mrq,
James Smartbcb24f62017-11-20 16:00:36 -08003632 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
James Smart2d7dbc42017-02-12 13:52:35 -08003633 "Specify number of RQ pairs for processing NVMET cmds");
3634
3635/*
James Smart2448e482018-04-09 14:24:24 -07003636 * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post
3637 * to each NVMET RQ. Range 64 to 2048, default is 512.
3638 */
3639LPFC_ATTR_R(nvmet_mrq_post,
3640 LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,
3641 LPFC_NVMET_RQE_DEF_COUNT,
3642 "Specify number of RQ buffers to initially post");
3643
3644/*
James Smart895427b2017-02-12 13:52:30 -08003645 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3646 * Supported Values: 1 - register just FCP
3647 * 3 - register both FCP and NVME
James Smart7d708032017-03-08 14:36:01 -08003648 * Supported values are [1,3]. Default value is 1
James Smart895427b2017-02-12 13:52:30 -08003649 */
James Smart7d708032017-03-08 14:36:01 -08003650LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP,
James Smart895427b2017-02-12 13:52:30 -08003651 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
Dick Kennedycf4c8c82017-09-29 17:34:38 -07003652 "Enable FC4 Protocol support - FCP / NVME");
James Smart895427b2017-02-12 13:52:30 -08003653
3654/*
3655 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3656 * This parameter is only used if:
James Smartf358dd02017-02-12 13:52:34 -08003657 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3658 * port is not configured for NVMET.
James Smart895427b2017-02-12 13:52:30 -08003659 *
3660 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3661 * The remaining XRIs get split up based on lpfc_xri_split per port:
3662 *
3663 * Supported Values are in percentages
3664 * the xri_split value is the percentage the SCSI port will get. The remaining
3665 * percentage will go to NVME.
3666 */
3667LPFC_ATTR_R(xri_split, 50, 10, 90,
Dick Kennedycf4c8c82017-09-29 17:34:38 -07003668 "Percentage of FCP XRI resources versus NVME");
James Smart895427b2017-02-12 13:52:30 -08003669
3670/*
dea31012005-04-17 16:05:31 -05003671# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3672# deluged with LOTS of information.
3673# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04003674# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05003675*/
James Smartf4b4c682009-05-22 14:53:12 -04003676LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04003677 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05003678
3679/*
James Smart7ee5d432007-10-27 13:37:17 -04003680# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3681# objects that have been registered with the nameserver after login.
3682*/
James Smartcf971242012-03-01 22:37:32 -05003683LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04003684 "Deregister nameserver objects before LOGO");
3685
3686/*
dea31012005-04-17 16:05:31 -05003687# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04003688# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3689# If this parameter value is greater than 1/8th the maximum number of exchanges
3690# supported by the HBA port, then the lun queue depth will be reduced to
3691# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05003692*/
James Smart572709e2013-07-15 18:32:43 -04003693LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04003694 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05003695
3696/*
James Smart7dc517d2010-07-14 15:32:10 -04003697# tgt_queue_depth: This parameter is used to limit the number of outstanding
3698# commands per target port. Value range is [10,65535]. Default value is 65535.
3699*/
James Smartf91bc592018-04-09 14:24:22 -07003700static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
3701module_param(lpfc_tgt_queue_depth, uint, 0444);
3702MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
3703lpfc_vport_param_show(tgt_queue_depth);
3704lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
3705 LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
3706
3707/**
3708 * lpfc_tgt_queue_depth_store: Sets an attribute value.
3709 * @phba: pointer the the adapter structure.
3710 * @val: integer attribute value.
3711 *
3712 * Description: Sets the parameter to the new value.
3713 *
3714 * Returns:
3715 * zero on success
3716 * -EINVAL if val is invalid
3717 */
3718static int
3719lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
3720{
3721 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3722 struct lpfc_nodelist *ndlp;
3723
3724 if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
3725 return -EINVAL;
3726
3727 if (val == vport->cfg_tgt_queue_depth)
3728 return 0;
3729
3730 spin_lock_irq(shost->host_lock);
3731 vport->cfg_tgt_queue_depth = val;
3732
3733 /* Next loop thru nodelist and change cmd_qdepth */
3734 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3735 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3736
3737 spin_unlock_irq(shost->host_lock);
3738 return 0;
3739}
3740
3741lpfc_vport_param_store(tgt_queue_depth);
3742static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04003743
3744/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003745# hba_queue_depth: This parameter is used to limit the number of outstanding
3746# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3747# value is greater than the maximum number of exchanges supported by the HBA,
3748# then maximum number of exchanges supported by the HBA is used to determine
3749# the hba_queue_depth.
3750*/
3751LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3752 "Max number of FCP commands we can queue to a lpfc HBA");
3753
3754/*
James Smart92d7f7b2007-06-17 19:56:38 -05003755# peer_port_login: This parameter allows/prevents logins
3756# between peer ports hosted on the same physical port.
3757# When this parameter is set 0 peer ports of same physical port
3758# are not allowed to login to each other.
3759# When this parameter is set 1 peer ports of same physical port
3760# are allowed to login to each other.
3761# Default value of this parameter is 0.
3762*/
James Smart3de2a652007-08-02 11:09:59 -04003763LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3764 "Allow peer ports on the same physical port to login to each "
3765 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05003766
3767/*
James Smart3de2a652007-08-02 11:09:59 -04003768# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05003769# between Virtual Ports and remote initiators.
3770# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3771# other initiators and will attempt to PLOGI all remote ports.
3772# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3773# remote ports and will not attempt to PLOGI to other initiators.
3774# This parameter does not restrict to the physical port.
3775# This parameter does not restrict logins to Fabric resident remote ports.
3776# Default value of this parameter is 1.
3777*/
James Smart3de2a652007-08-02 11:09:59 -04003778static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05003779module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04003780MODULE_PARM_DESC(lpfc_restrict_login,
3781 "Restrict virtual ports login to remote initiators.");
3782lpfc_vport_param_show(restrict_login);
3783
James Smarte59058c2008-08-24 21:49:00 -04003784/**
James Smart3621a712009-04-06 18:47:14 -04003785 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003786 * @vport: lpfc vport structure pointer.
3787 * @val: contains the restrict login value.
3788 *
3789 * Description:
3790 * If val is not in a valid range then log a kernel error message and set
3791 * the vport restrict login to one.
3792 * If the port type is physical clear the restrict login flag and return.
3793 * Else set the restrict login flag to val.
3794 *
3795 * Returns:
3796 * zero if val is in range
3797 * -EINVAL val out of range
3798 **/
James Smart3de2a652007-08-02 11:09:59 -04003799static int
3800lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3801{
3802 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003803 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003804 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003805 "be set to %d, allowed range is [0, 1]\n",
3806 val);
James Smart3de2a652007-08-02 11:09:59 -04003807 vport->cfg_restrict_login = 1;
3808 return -EINVAL;
3809 }
3810 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3811 vport->cfg_restrict_login = 0;
3812 return 0;
3813 }
3814 vport->cfg_restrict_login = val;
3815 return 0;
3816}
3817
James Smarte59058c2008-08-24 21:49:00 -04003818/**
James Smart3621a712009-04-06 18:47:14 -04003819 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003820 * @vport: lpfc vport structure pointer.
3821 * @val: contains the restrict login value.
3822 *
3823 * Description:
3824 * If val is not in a valid range then log a kernel error message and set
3825 * the vport restrict login to one.
3826 * If the port type is physical and the val is not zero log a kernel
3827 * error message, clear the restrict login flag and return zero.
3828 * Else set the restrict login flag to val.
3829 *
3830 * Returns:
3831 * zero if val is in range
3832 * -EINVAL val out of range
3833 **/
James Smart3de2a652007-08-02 11:09:59 -04003834static int
3835lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3836{
3837 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003838 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003839 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003840 "be set to %d, allowed range is [0, 1]\n",
3841 val);
James Smart3de2a652007-08-02 11:09:59 -04003842 vport->cfg_restrict_login = 1;
3843 return -EINVAL;
3844 }
3845 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04003846 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3847 "0468 lpfc_restrict_login must be 0 for "
3848 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04003849 vport->cfg_restrict_login = 0;
3850 return 0;
3851 }
3852 vport->cfg_restrict_login = val;
3853 return 0;
3854}
3855lpfc_vport_param_store(restrict_login);
Joe Perchesb6b996b2017-12-19 10:15:07 -08003856static DEVICE_ATTR_RW(lpfc_restrict_login);
James Smart92d7f7b2007-06-17 19:56:38 -05003857
3858/*
dea31012005-04-17 16:05:31 -05003859# Some disk devices have a "select ID" or "select Target" capability.
3860# From a protocol standpoint "select ID" usually means select the
3861# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3862# annex" which contains a table that maps a "select ID" (a number
3863# between 0 and 7F) to an ALPA. By default, for compatibility with
3864# older drivers, the lpfc driver scans this table from low ALPA to high
3865# ALPA.
3866#
3867# Turning on the scan-down variable (on = 1, off = 0) will
3868# cause the lpfc driver to use an inverted table, effectively
3869# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3870#
3871# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3872# and will not work across a fabric. Also this parameter will take
3873# effect only in the case when ALPA map is not available.)
3874*/
James Smart3de2a652007-08-02 11:09:59 -04003875LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3876 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05003877
3878/*
dea31012005-04-17 16:05:31 -05003879# lpfc_topology: link topology for init link
3880# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05003881# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05003882# 0x02 = attempt point-to-point mode only
3883# 0x04 = attempt loop mode only
3884# 0x06 = attempt point-to-point mode then loop
3885# Set point-to-point mode if you want to run as an N_Port.
3886# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3887# Default value is 0.
3888*/
James Smart0a035432016-10-13 15:06:10 -07003889LPFC_ATTR(topology, 0, 0, 6,
3890 "Select Fibre Channel topology");
James Smarte59058c2008-08-24 21:49:00 -04003891
3892/**
James Smart3621a712009-04-06 18:47:14 -04003893 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04003894 * @phba: lpfc_hba pointer.
3895 * @val: topology value.
3896 *
3897 * Description:
3898 * If val is in a valid range then set the adapter's topology field and
3899 * issue a lip; if the lip fails reset the topology to the old value.
3900 *
3901 * If the value is not in range log a kernel error message and return an error.
3902 *
3903 * Returns:
3904 * zero if val is in range and lip okay
3905 * non-zero return value from lpfc_issue_lip()
3906 * -EINVAL val out of range
3907 **/
James Smarta257bf92009-04-06 18:48:10 -04003908static ssize_t
3909lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3910 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003911{
James Smarta257bf92009-04-06 18:48:10 -04003912 struct Scsi_Host *shost = class_to_shost(dev);
3913 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3914 struct lpfc_hba *phba = vport->phba;
3915 int val = 0;
3916 int nolip = 0;
3917 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003918 int err;
3919 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003920
3921 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3922 nolip = 1;
3923 val_buf = &buf[strlen("nolip ")];
3924 }
3925
3926 if (!isdigit(val_buf[0]))
3927 return -EINVAL;
3928 if (sscanf(val_buf, "%i", &val) != 1)
3929 return -EINVAL;
3930
James Smart83108bd2008-01-11 01:53:09 -05003931 if (val >= 0 && val <= 6) {
3932 prev_val = phba->cfg_topology;
James Smartff78d8f2011-12-13 13:21:35 -05003933 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3934 val == 4) {
3935 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3936 "3113 Loop mode not supported at speed %d\n",
James Smartd38dd522015-08-31 16:48:17 -04003937 val);
James Smartff78d8f2011-12-13 13:21:35 -05003938 return -EINVAL;
3939 }
James Smart76558b22018-11-29 16:09:38 -08003940 if ((phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC ||
3941 phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC) &&
3942 val == 4) {
James Smartd38dd522015-08-31 16:48:17 -04003943 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3944 "3114 Loop mode not supported\n");
3945 return -EINVAL;
3946 }
3947 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04003948 if (nolip)
3949 return strlen(buf);
3950
James Smart88a2cfb2011-07-22 18:36:33 -04003951 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3952 "3054 lpfc_topology changed from %d to %d\n",
3953 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04003954 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3955 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05003956 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003957 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003958 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003959 return -EINVAL;
3960 } else
3961 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003962 }
3963 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3964 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3965 "allowed range is [0, 6]\n",
3966 phba->brd_no, val);
3967 return -EINVAL;
3968}
James Smart0a035432016-10-13 15:06:10 -07003969
James Smart83108bd2008-01-11 01:53:09 -05003970lpfc_param_show(topology)
Joe Perchesb6b996b2017-12-19 10:15:07 -08003971static DEVICE_ATTR_RW(lpfc_topology);
dea31012005-04-17 16:05:31 -05003972
James Smart21e9a0a2009-05-22 14:53:21 -04003973/**
3974 * lpfc_static_vport_show: Read callback function for
3975 * lpfc_static_vport sysfs file.
3976 * @dev: Pointer to class device object.
3977 * @attr: device attribute structure.
3978 * @buf: Data buffer.
3979 *
3980 * This function is the read call back function for
3981 * lpfc_static_vport sysfs file. The lpfc_static_vport
3982 * sysfs file report the mageability of the vport.
3983 **/
3984static ssize_t
3985lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3986 char *buf)
3987{
3988 struct Scsi_Host *shost = class_to_shost(dev);
3989 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3990 if (vport->vport_flag & STATIC_VPORT)
3991 sprintf(buf, "1\n");
3992 else
3993 sprintf(buf, "0\n");
3994
3995 return strlen(buf);
3996}
3997
3998/*
3999 * Sysfs attribute to control the statistical data collection.
4000 */
Joe Perchesc828a892017-12-19 10:15:08 -08004001static DEVICE_ATTR_RO(lpfc_static_vport);
James Smartea2151b2008-09-07 11:52:10 -04004002
4003/**
James Smart3621a712009-04-06 18:47:14 -04004004 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04004005 * @dev: Pointer to class device.
4006 * @buf: Data buffer.
4007 * @count: Size of the data buffer.
4008 *
Masahiro Yamada9332ef92017-02-27 14:28:47 -08004009 * This function get called when a user write to the lpfc_stat_data_ctrl
James Smartea2151b2008-09-07 11:52:10 -04004010 * sysfs file. This function parse the command written to the sysfs file
4011 * and take appropriate action. These commands are used for controlling
4012 * driver statistical data collection.
4013 * Following are the command this function handles.
4014 *
4015 * setbucket <bucket_type> <base> <step>
4016 * = Set the latency buckets.
4017 * destroybucket = destroy all the buckets.
4018 * start = start data collection
4019 * stop = stop data collection
4020 * reset = reset the collected data
4021 **/
4022static ssize_t
4023lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
4024 const char *buf, size_t count)
4025{
4026 struct Scsi_Host *shost = class_to_shost(dev);
4027 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4028 struct lpfc_hba *phba = vport->phba;
4029#define LPFC_MAX_DATA_CTRL_LEN 1024
4030 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
4031 unsigned long i;
4032 char *str_ptr, *token;
4033 struct lpfc_vport **vports;
4034 struct Scsi_Host *v_shost;
4035 char *bucket_type_str, *base_str, *step_str;
4036 unsigned long base, step, bucket_type;
4037
4038 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04004039 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04004040 return -EINVAL;
4041
James Smarteb016562014-09-03 12:58:06 -04004042 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
James Smartea2151b2008-09-07 11:52:10 -04004043 str_ptr = &bucket_data[0];
4044 /* Ignore this token - this is command token */
4045 token = strsep(&str_ptr, "\t ");
4046 if (!token)
4047 return -EINVAL;
4048
4049 bucket_type_str = strsep(&str_ptr, "\t ");
4050 if (!bucket_type_str)
4051 return -EINVAL;
4052
4053 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
4054 bucket_type = LPFC_LINEAR_BUCKET;
4055 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
4056 bucket_type = LPFC_POWER2_BUCKET;
4057 else
4058 return -EINVAL;
4059
4060 base_str = strsep(&str_ptr, "\t ");
4061 if (!base_str)
4062 return -EINVAL;
4063 base = simple_strtoul(base_str, NULL, 0);
4064
4065 step_str = strsep(&str_ptr, "\t ");
4066 if (!step_str)
4067 return -EINVAL;
4068 step = simple_strtoul(step_str, NULL, 0);
4069 if (!step)
4070 return -EINVAL;
4071
4072 /* Block the data collection for every vport */
4073 vports = lpfc_create_vport_work_array(phba);
4074 if (vports == NULL)
4075 return -ENOMEM;
4076
James Smartf4b4c682009-05-22 14:53:12 -04004077 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04004078 v_shost = lpfc_shost_from_vport(vports[i]);
4079 spin_lock_irq(v_shost->host_lock);
4080 /* Block and reset data collection */
4081 vports[i]->stat_data_blocked = 1;
4082 if (vports[i]->stat_data_enabled)
4083 lpfc_vport_reset_stat_data(vports[i]);
4084 spin_unlock_irq(v_shost->host_lock);
4085 }
4086
4087 /* Set the bucket attributes */
4088 phba->bucket_type = bucket_type;
4089 phba->bucket_base = base;
4090 phba->bucket_step = step;
4091
James Smartf4b4c682009-05-22 14:53:12 -04004092 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04004093 v_shost = lpfc_shost_from_vport(vports[i]);
4094
4095 /* Unblock data collection */
4096 spin_lock_irq(v_shost->host_lock);
4097 vports[i]->stat_data_blocked = 0;
4098 spin_unlock_irq(v_shost->host_lock);
4099 }
4100 lpfc_destroy_vport_work_array(phba, vports);
4101 return strlen(buf);
4102 }
4103
4104 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
4105 vports = lpfc_create_vport_work_array(phba);
4106 if (vports == NULL)
4107 return -ENOMEM;
4108
James Smartf4b4c682009-05-22 14:53:12 -04004109 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04004110 v_shost = lpfc_shost_from_vport(vports[i]);
4111 spin_lock_irq(shost->host_lock);
4112 vports[i]->stat_data_blocked = 1;
4113 lpfc_free_bucket(vport);
4114 vport->stat_data_enabled = 0;
4115 vports[i]->stat_data_blocked = 0;
4116 spin_unlock_irq(shost->host_lock);
4117 }
4118 lpfc_destroy_vport_work_array(phba, vports);
4119 phba->bucket_type = LPFC_NO_BUCKET;
4120 phba->bucket_base = 0;
4121 phba->bucket_step = 0;
4122 return strlen(buf);
4123 }
4124
4125 if (!strncmp(buf, "start", strlen("start"))) {
4126 /* If no buckets configured return error */
4127 if (phba->bucket_type == LPFC_NO_BUCKET)
4128 return -EINVAL;
4129 spin_lock_irq(shost->host_lock);
4130 if (vport->stat_data_enabled) {
4131 spin_unlock_irq(shost->host_lock);
4132 return strlen(buf);
4133 }
4134 lpfc_alloc_bucket(vport);
4135 vport->stat_data_enabled = 1;
4136 spin_unlock_irq(shost->host_lock);
4137 return strlen(buf);
4138 }
4139
4140 if (!strncmp(buf, "stop", strlen("stop"))) {
4141 spin_lock_irq(shost->host_lock);
4142 if (vport->stat_data_enabled == 0) {
4143 spin_unlock_irq(shost->host_lock);
4144 return strlen(buf);
4145 }
4146 lpfc_free_bucket(vport);
4147 vport->stat_data_enabled = 0;
4148 spin_unlock_irq(shost->host_lock);
4149 return strlen(buf);
4150 }
4151
4152 if (!strncmp(buf, "reset", strlen("reset"))) {
4153 if ((phba->bucket_type == LPFC_NO_BUCKET)
4154 || !vport->stat_data_enabled)
4155 return strlen(buf);
4156 spin_lock_irq(shost->host_lock);
4157 vport->stat_data_blocked = 1;
4158 lpfc_vport_reset_stat_data(vport);
4159 vport->stat_data_blocked = 0;
4160 spin_unlock_irq(shost->host_lock);
4161 return strlen(buf);
4162 }
4163 return -EINVAL;
4164}
4165
4166
4167/**
James Smart3621a712009-04-06 18:47:14 -04004168 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04004169 * @dev: Pointer to class device object.
4170 * @buf: Data buffer.
4171 *
4172 * This function is the read call back function for
4173 * lpfc_stat_data_ctrl sysfs file. This function report the
4174 * current statistical data collection state.
4175 **/
4176static ssize_t
4177lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
4178 char *buf)
4179{
4180 struct Scsi_Host *shost = class_to_shost(dev);
4181 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4182 struct lpfc_hba *phba = vport->phba;
4183 int index = 0;
4184 int i;
4185 char *bucket_type;
4186 unsigned long bucket_value;
4187
4188 switch (phba->bucket_type) {
4189 case LPFC_LINEAR_BUCKET:
4190 bucket_type = "linear";
4191 break;
4192 case LPFC_POWER2_BUCKET:
4193 bucket_type = "power2";
4194 break;
4195 default:
4196 bucket_type = "No Bucket";
4197 break;
4198 }
4199
4200 sprintf(&buf[index], "Statistical Data enabled :%d, "
4201 "blocked :%d, Bucket type :%s, Bucket base :%d,"
4202 " Bucket step :%d\nLatency Ranges :",
4203 vport->stat_data_enabled, vport->stat_data_blocked,
4204 bucket_type, phba->bucket_base, phba->bucket_step);
4205 index = strlen(buf);
4206 if (phba->bucket_type != LPFC_NO_BUCKET) {
4207 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4208 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
4209 bucket_value = phba->bucket_base +
4210 phba->bucket_step * i;
4211 else
4212 bucket_value = phba->bucket_base +
4213 (1 << i) * phba->bucket_step;
4214
4215 if (index + 10 > PAGE_SIZE)
4216 break;
4217 sprintf(&buf[index], "%08ld ", bucket_value);
4218 index = strlen(buf);
4219 }
4220 }
4221 sprintf(&buf[index], "\n");
4222 return strlen(buf);
4223}
4224
4225/*
4226 * Sysfs attribute to control the statistical data collection.
4227 */
Joe Perchesb6b996b2017-12-19 10:15:07 -08004228static DEVICE_ATTR_RW(lpfc_stat_data_ctrl);
James Smartea2151b2008-09-07 11:52:10 -04004229
4230/*
4231 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
4232 */
4233
4234/*
4235 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
4236 * for each target.
4237 */
4238#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
4239#define MAX_STAT_DATA_SIZE_PER_TARGET \
4240 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
4241
4242
4243/**
James Smart3621a712009-04-06 18:47:14 -04004244 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07004245 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04004246 * @kobj: Pointer to the kernel object
4247 * @bin_attr: Attribute object
4248 * @buff: Buffer pointer
4249 * @off: File offset
4250 * @count: Buffer size
4251 *
4252 * This function is the read call back function for lpfc_drvr_stat_data
4253 * sysfs file. This function export the statistical data to user
4254 * applications.
4255 **/
4256static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004257sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
4258 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04004259 char *buf, loff_t off, size_t count)
4260{
4261 struct device *dev = container_of(kobj, struct device,
4262 kobj);
4263 struct Scsi_Host *shost = class_to_shost(dev);
4264 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4265 struct lpfc_hba *phba = vport->phba;
4266 int i = 0, index = 0;
4267 unsigned long nport_index;
4268 struct lpfc_nodelist *ndlp = NULL;
4269 nport_index = (unsigned long)off /
4270 MAX_STAT_DATA_SIZE_PER_TARGET;
4271
4272 if (!vport->stat_data_enabled || vport->stat_data_blocked
4273 || (phba->bucket_type == LPFC_NO_BUCKET))
4274 return 0;
4275
4276 spin_lock_irq(shost->host_lock);
4277 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4278 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
4279 continue;
4280
4281 if (nport_index > 0) {
4282 nport_index--;
4283 continue;
4284 }
4285
4286 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
4287 > count)
4288 break;
4289
4290 if (!ndlp->lat_data)
4291 continue;
4292
4293 /* Print the WWN */
4294 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
4295 ndlp->nlp_portname.u.wwn[0],
4296 ndlp->nlp_portname.u.wwn[1],
4297 ndlp->nlp_portname.u.wwn[2],
4298 ndlp->nlp_portname.u.wwn[3],
4299 ndlp->nlp_portname.u.wwn[4],
4300 ndlp->nlp_portname.u.wwn[5],
4301 ndlp->nlp_portname.u.wwn[6],
4302 ndlp->nlp_portname.u.wwn[7]);
4303
4304 index = strlen(buf);
4305
4306 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4307 sprintf(&buf[index], "%010u,",
4308 ndlp->lat_data[i].cmd_count);
4309 index = strlen(buf);
4310 }
4311 sprintf(&buf[index], "\n");
4312 index = strlen(buf);
4313 }
4314 spin_unlock_irq(shost->host_lock);
4315 return index;
4316}
4317
4318static struct bin_attribute sysfs_drvr_stat_data_attr = {
4319 .attr = {
4320 .name = "lpfc_drvr_stat_data",
4321 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04004322 },
4323 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
4324 .read = sysfs_drvr_stat_data_read,
4325 .write = NULL,
4326};
4327
dea31012005-04-17 16:05:31 -05004328/*
4329# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4330# connection.
James Smart76a95d72010-11-20 23:11:48 -05004331# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05004332*/
James Smarte59058c2008-08-24 21:49:00 -04004333/**
James Smart3621a712009-04-06 18:47:14 -04004334 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004335 * @phba: lpfc_hba pointer.
4336 * @val: link speed value.
4337 *
4338 * Description:
4339 * If val is in a valid range then set the adapter's link speed field and
4340 * issue a lip; if the lip fails reset the link speed to the old value.
4341 *
4342 * Notes:
4343 * If the value is not in range log a kernel error message and return an error.
4344 *
4345 * Returns:
4346 * zero if val is in range and lip okay.
4347 * non-zero return value from lpfc_issue_lip()
4348 * -EINVAL val out of range
4349 **/
James Smarta257bf92009-04-06 18:48:10 -04004350static ssize_t
4351lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4352 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05004353{
James Smarta257bf92009-04-06 18:48:10 -04004354 struct Scsi_Host *shost = class_to_shost(dev);
4355 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4356 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05004357 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04004358 int nolip = 0;
4359 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05004360 int err;
James Smartc6918162016-10-13 15:06:16 -07004361 uint32_t prev_val, if_type;
4362
4363 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart719162b2018-12-10 19:37:01 -08004364 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&
James Smartc6918162016-10-13 15:06:16 -07004365 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4366 return -EPERM;
James Smart83108bd2008-01-11 01:53:09 -05004367
James Smarta257bf92009-04-06 18:48:10 -04004368 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4369 nolip = 1;
4370 val_buf = &buf[strlen("nolip ")];
4371 }
4372
4373 if (!isdigit(val_buf[0]))
4374 return -EINVAL;
4375 if (sscanf(val_buf, "%i", &val) != 1)
4376 return -EINVAL;
4377
James Smart88a2cfb2011-07-22 18:36:33 -04004378 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4379 "3055 lpfc_link_speed changed from %d to %d %s\n",
4380 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4381
James Smart76a95d72010-11-20 23:11:48 -05004382 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4383 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4384 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4385 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4386 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
James Smartd38dd522015-08-31 16:48:17 -04004387 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
James Smartfbd8a6b2018-02-22 08:18:45 -08004388 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||
4389 ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {
James Smart76a95d72010-11-20 23:11:48 -05004390 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4391 "2879 lpfc_link_speed attribute cannot be set "
4392 "to %d. Speed is not supported by this port.\n",
4393 val);
James Smart83108bd2008-01-11 01:53:09 -05004394 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05004395 }
James Smartfbd8a6b2018-02-22 08:18:45 -08004396 if (val >= LPFC_USER_LINK_SPEED_16G &&
4397 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smartff78d8f2011-12-13 13:21:35 -05004398 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4399 "3112 lpfc_link_speed attribute cannot be set "
4400 "to %d. Speed is not supported in loop mode.\n",
4401 val);
4402 return -EINVAL;
4403 }
James Smartfbd8a6b2018-02-22 08:18:45 -08004404
4405 switch (val) {
4406 case LPFC_USER_LINK_SPEED_AUTO:
4407 case LPFC_USER_LINK_SPEED_1G:
4408 case LPFC_USER_LINK_SPEED_2G:
4409 case LPFC_USER_LINK_SPEED_4G:
4410 case LPFC_USER_LINK_SPEED_8G:
4411 case LPFC_USER_LINK_SPEED_16G:
4412 case LPFC_USER_LINK_SPEED_32G:
4413 case LPFC_USER_LINK_SPEED_64G:
James Smart83108bd2008-01-11 01:53:09 -05004414 prev_val = phba->cfg_link_speed;
4415 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04004416 if (nolip)
4417 return strlen(buf);
4418
James Smart83108bd2008-01-11 01:53:09 -05004419 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04004420 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05004421 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04004422 return -EINVAL;
James Smartfbd8a6b2018-02-22 08:18:45 -08004423 }
4424 return strlen(buf);
4425 default:
4426 break;
James Smart83108bd2008-01-11 01:53:09 -05004427 }
James Smartfbd8a6b2018-02-22 08:18:45 -08004428
James Smart83108bd2008-01-11 01:53:09 -05004429 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartfbd8a6b2018-02-22 08:18:45 -08004430 "0469 lpfc_link_speed attribute cannot be set to %d, "
4431 "allowed values are [%s]\n",
4432 val, LPFC_LINK_SPEED_STRING);
James Smart83108bd2008-01-11 01:53:09 -05004433 return -EINVAL;
James Smartfbd8a6b2018-02-22 08:18:45 -08004434
James Smart83108bd2008-01-11 01:53:09 -05004435}
4436
4437static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05004438module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05004439MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4440lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04004441
4442/**
James Smart3621a712009-04-06 18:47:14 -04004443 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004444 * @phba: lpfc_hba pointer.
4445 * @val: link speed value.
4446 *
4447 * Description:
4448 * If val is in a valid range then set the adapter's link speed field.
4449 *
4450 * Notes:
4451 * If the value is not in range log a kernel error message, clear the link
4452 * speed and return an error.
4453 *
4454 * Returns:
4455 * zero if val saved.
4456 * -EINVAL val out of range
4457 **/
James Smart83108bd2008-01-11 01:53:09 -05004458static int
4459lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4460{
James Smartfbd8a6b2018-02-22 08:18:45 -08004461 if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
James Smartff78d8f2011-12-13 13:21:35 -05004462 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4463 "3111 lpfc_link_speed of %d cannot "
4464 "support loop mode, setting topology to default.\n",
4465 val);
4466 phba->cfg_topology = 0;
4467 }
James Smartfbd8a6b2018-02-22 08:18:45 -08004468
4469 switch (val) {
4470 case LPFC_USER_LINK_SPEED_AUTO:
4471 case LPFC_USER_LINK_SPEED_1G:
4472 case LPFC_USER_LINK_SPEED_2G:
4473 case LPFC_USER_LINK_SPEED_4G:
4474 case LPFC_USER_LINK_SPEED_8G:
4475 case LPFC_USER_LINK_SPEED_16G:
4476 case LPFC_USER_LINK_SPEED_32G:
4477 case LPFC_USER_LINK_SPEED_64G:
James Smart83108bd2008-01-11 01:53:09 -05004478 phba->cfg_link_speed = val;
4479 return 0;
James Smartfbd8a6b2018-02-22 08:18:45 -08004480 default:
4481 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4482 "0405 lpfc_link_speed attribute cannot "
4483 "be set to %d, allowed values are "
4484 "["LPFC_LINK_SPEED_STRING"]\n", val);
4485 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4486 return -EINVAL;
James Smart83108bd2008-01-11 01:53:09 -05004487 }
James Smart83108bd2008-01-11 01:53:09 -05004488}
4489
Joe Perchesb6b996b2017-12-19 10:15:07 -08004490static DEVICE_ATTR_RW(lpfc_link_speed);
dea31012005-04-17 16:05:31 -05004491
4492/*
James Smart0d878412009-10-02 15:16:56 -04004493# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4494# 0 = aer disabled or not supported
4495# 1 = aer supported and enabled (default)
4496# Value range is [0,1]. Default value is 1.
4497*/
James Smart506139a2016-10-13 15:06:09 -07004498LPFC_ATTR(aer_support, 1, 0, 1,
4499 "Enable PCIe device AER support");
4500lpfc_param_show(aer_support)
James Smart0d878412009-10-02 15:16:56 -04004501
4502/**
4503 * lpfc_aer_support_store - Set the adapter for aer support
4504 *
4505 * @dev: class device that is converted into a Scsi_host.
4506 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004507 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04004508 * @count: unused variable.
4509 *
4510 * Description:
4511 * If the val is 1 and currently the device's AER capability was not
4512 * enabled, invoke the kernel's enable AER helper routine, trying to
4513 * enable the device's AER capability. If the helper routine enabling
4514 * AER returns success, update the device's cfg_aer_support flag to
4515 * indicate AER is supported by the device; otherwise, if the device
4516 * AER capability is already enabled to support AER, then do nothing.
4517 *
4518 * If the val is 0 and currently the device's AER support was enabled,
4519 * invoke the kernel's disable AER helper routine. After that, update
4520 * the device's cfg_aer_support flag to indicate AER is not supported
4521 * by the device; otherwise, if the device AER capability is already
4522 * disabled from supporting AER, then do nothing.
4523 *
4524 * Returns:
4525 * length of the buf on success if val is in range the intended mode
4526 * is supported.
4527 * -EINVAL if val out of range or intended mode is not supported.
4528 **/
4529static ssize_t
4530lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4531 const char *buf, size_t count)
4532{
4533 struct Scsi_Host *shost = class_to_shost(dev);
4534 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4535 struct lpfc_hba *phba = vport->phba;
4536 int val = 0, rc = -EINVAL;
4537
4538 if (!isdigit(buf[0]))
4539 return -EINVAL;
4540 if (sscanf(buf, "%i", &val) != 1)
4541 return -EINVAL;
4542
4543 switch (val) {
4544 case 0:
4545 if (phba->hba_flag & HBA_AER_ENABLED) {
4546 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4547 if (!rc) {
4548 spin_lock_irq(&phba->hbalock);
4549 phba->hba_flag &= ~HBA_AER_ENABLED;
4550 spin_unlock_irq(&phba->hbalock);
4551 phba->cfg_aer_support = 0;
4552 rc = strlen(buf);
4553 } else
James Smart891478a2009-11-18 15:40:23 -05004554 rc = -EPERM;
4555 } else {
James Smart0d878412009-10-02 15:16:56 -04004556 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05004557 rc = strlen(buf);
4558 }
James Smart0d878412009-10-02 15:16:56 -04004559 break;
4560 case 1:
4561 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4562 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4563 if (!rc) {
4564 spin_lock_irq(&phba->hbalock);
4565 phba->hba_flag |= HBA_AER_ENABLED;
4566 spin_unlock_irq(&phba->hbalock);
4567 phba->cfg_aer_support = 1;
4568 rc = strlen(buf);
4569 } else
James Smart891478a2009-11-18 15:40:23 -05004570 rc = -EPERM;
4571 } else {
James Smart0d878412009-10-02 15:16:56 -04004572 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05004573 rc = strlen(buf);
4574 }
James Smart0d878412009-10-02 15:16:56 -04004575 break;
4576 default:
4577 rc = -EINVAL;
4578 break;
4579 }
4580 return rc;
4581}
4582
Joe Perchesb6b996b2017-12-19 10:15:07 -08004583static DEVICE_ATTR_RW(lpfc_aer_support);
James Smart0d878412009-10-02 15:16:56 -04004584
4585/**
4586 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4587 * @dev: class device that is converted into a Scsi_host.
4588 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004589 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04004590 * @count: unused variable.
4591 *
4592 * Description:
4593 * If the @buf contains 1 and the device currently has the AER support
4594 * enabled, then invokes the kernel AER helper routine
4595 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4596 * error status register.
4597 *
4598 * Notes:
4599 *
4600 * Returns:
4601 * -EINVAL if the buf does not contain the 1 or the device is not currently
4602 * enabled with the AER support.
4603 **/
4604static ssize_t
4605lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4606 const char *buf, size_t count)
4607{
4608 struct Scsi_Host *shost = class_to_shost(dev);
4609 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4610 struct lpfc_hba *phba = vport->phba;
4611 int val, rc = -1;
4612
4613 if (!isdigit(buf[0]))
4614 return -EINVAL;
4615 if (sscanf(buf, "%i", &val) != 1)
4616 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05004617 if (val != 1)
4618 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04004619
James Smart891478a2009-11-18 15:40:23 -05004620 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04004621 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4622
4623 if (rc == 0)
4624 return strlen(buf);
4625 else
James Smart891478a2009-11-18 15:40:23 -05004626 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04004627}
4628
4629static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4630 lpfc_aer_cleanup_state);
4631
James Smart912e3ac2011-05-24 11:42:11 -04004632/**
4633 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4634 *
4635 * @dev: class device that is converted into a Scsi_host.
4636 * @attr: device attribute, not used.
4637 * @buf: containing the string the number of vfs to be enabled.
4638 * @count: unused variable.
4639 *
4640 * Description:
4641 * When this api is called either through user sysfs, the driver shall
4642 * try to enable or disable SR-IOV virtual functions according to the
4643 * following:
4644 *
4645 * If zero virtual function has been enabled to the physical function,
4646 * the driver shall invoke the pci enable virtual function api trying
4647 * to enable the virtual functions. If the nr_vfn provided is greater
4648 * than the maximum supported, the maximum virtual function number will
4649 * be used for invoking the api; otherwise, the nr_vfn provided shall
4650 * be used for invoking the api. If the api call returned success, the
4651 * actual number of virtual functions enabled will be set to the driver
4652 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4653 * cfg_sriov_nr_virtfn remains zero.
4654 *
4655 * If none-zero virtual functions have already been enabled to the
4656 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4657 * -EINVAL will be returned and the driver does nothing;
4658 *
4659 * If the nr_vfn provided is zero and none-zero virtual functions have
4660 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4661 * disabling virtual function api shall be invoded to disable all the
4662 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4663 * zero. Otherwise, if zero virtual function has been enabled, do
4664 * nothing.
4665 *
4666 * Returns:
4667 * length of the buf on success if val is in range the intended mode
4668 * is supported.
4669 * -EINVAL if val out of range or intended mode is not supported.
4670 **/
4671static ssize_t
4672lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4673 const char *buf, size_t count)
4674{
4675 struct Scsi_Host *shost = class_to_shost(dev);
4676 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4677 struct lpfc_hba *phba = vport->phba;
4678 struct pci_dev *pdev = phba->pcidev;
4679 int val = 0, rc = -EINVAL;
4680
4681 /* Sanity check on user data */
4682 if (!isdigit(buf[0]))
4683 return -EINVAL;
4684 if (sscanf(buf, "%i", &val) != 1)
4685 return -EINVAL;
4686 if (val < 0)
4687 return -EINVAL;
4688
4689 /* Request disabling virtual functions */
4690 if (val == 0) {
4691 if (phba->cfg_sriov_nr_virtfn > 0) {
4692 pci_disable_sriov(pdev);
4693 phba->cfg_sriov_nr_virtfn = 0;
4694 }
4695 return strlen(buf);
4696 }
4697
4698 /* Request enabling virtual functions */
4699 if (phba->cfg_sriov_nr_virtfn > 0) {
4700 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4701 "3018 There are %d virtual functions "
4702 "enabled on physical function.\n",
4703 phba->cfg_sriov_nr_virtfn);
4704 return -EEXIST;
4705 }
4706
4707 if (val <= LPFC_MAX_VFN_PER_PFN)
4708 phba->cfg_sriov_nr_virtfn = val;
4709 else {
4710 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4711 "3019 Enabling %d virtual functions is not "
4712 "allowed.\n", val);
4713 return -EINVAL;
4714 }
4715
4716 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4717 if (rc) {
4718 phba->cfg_sriov_nr_virtfn = 0;
4719 rc = -EPERM;
4720 } else
4721 rc = strlen(buf);
4722
4723 return rc;
4724}
4725
James Smart0cfbbf22016-10-13 15:06:12 -07004726LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4727 "Enable PCIe device SR-IOV virtual fn");
4728
James Smart912e3ac2011-05-24 11:42:11 -04004729lpfc_param_show(sriov_nr_virtfn)
Joe Perchesb6b996b2017-12-19 10:15:07 -08004730static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04004731
James Smart173edbb2012-06-12 13:54:50 -04004732/**
James Smartc71ab862012-10-31 14:44:33 -04004733 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4734 *
4735 * @dev: class device that is converted into a Scsi_host.
4736 * @attr: device attribute, not used.
4737 * @buf: containing the string the number of vfs to be enabled.
4738 * @count: unused variable.
4739 *
4740 * Description:
4741 *
4742 * Returns:
4743 * length of the buf on success if val is in range the intended mode
4744 * is supported.
4745 * -EINVAL if val out of range or intended mode is not supported.
4746 **/
4747static ssize_t
4748lpfc_request_firmware_upgrade_store(struct device *dev,
4749 struct device_attribute *attr,
4750 const char *buf, size_t count)
4751{
4752 struct Scsi_Host *shost = class_to_shost(dev);
4753 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4754 struct lpfc_hba *phba = vport->phba;
4755 int val = 0, rc = -EINVAL;
4756
4757 /* Sanity check on user data */
4758 if (!isdigit(buf[0]))
4759 return -EINVAL;
4760 if (sscanf(buf, "%i", &val) != 1)
4761 return -EINVAL;
4762 if (val != 1)
4763 return -EINVAL;
4764
4765 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4766 if (rc)
4767 rc = -EPERM;
4768 else
4769 rc = strlen(buf);
4770 return rc;
4771}
4772
4773static int lpfc_req_fw_upgrade;
4774module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4775MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4776lpfc_param_show(request_firmware_upgrade)
4777
4778/**
4779 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4780 * @phba: lpfc_hba pointer.
4781 * @val: 0 or 1.
4782 *
4783 * Description:
4784 * Set the initial Linux generic firmware upgrade enable or disable flag.
4785 *
4786 * Returns:
4787 * zero if val saved.
4788 * -EINVAL val out of range
4789 **/
4790static int
4791lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4792{
4793 if (val >= 0 && val <= 1) {
4794 phba->cfg_request_firmware_upgrade = val;
4795 return 0;
4796 }
4797 return -EINVAL;
4798}
4799static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4800 lpfc_request_firmware_upgrade_show,
4801 lpfc_request_firmware_upgrade_store);
4802
4803/**
James Smart173edbb2012-06-12 13:54:50 -04004804 * lpfc_fcp_imax_store
4805 *
4806 * @dev: class device that is converted into a Scsi_host.
4807 * @attr: device attribute, not used.
4808 * @buf: string with the number of fast-path FCP interrupts per second.
4809 * @count: unused variable.
4810 *
4811 * Description:
4812 * If val is in a valid range [636,651042], then set the adapter's
4813 * maximum number of fast-path FCP interrupts per second.
4814 *
4815 * Returns:
4816 * length of the buf on success if val is in range the intended mode
4817 * is supported.
4818 * -EINVAL if val out of range or intended mode is not supported.
4819 **/
4820static ssize_t
4821lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4822 const char *buf, size_t count)
4823{
4824 struct Scsi_Host *shost = class_to_shost(dev);
4825 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4826 struct lpfc_hba *phba = vport->phba;
4827 int val = 0, i;
4828
James Smartbf8dae82012-08-03 12:36:24 -04004829 /* fcp_imax is only valid for SLI4 */
4830 if (phba->sli_rev != LPFC_SLI_REV4)
4831 return -EINVAL;
4832
James Smart173edbb2012-06-12 13:54:50 -04004833 /* Sanity check on user data */
4834 if (!isdigit(buf[0]))
4835 return -EINVAL;
4836 if (sscanf(buf, "%i", &val) != 1)
4837 return -EINVAL;
4838
James Smartbf8dae82012-08-03 12:36:24 -04004839 /*
4840 * Value range for the HBA is [5000,5000000]
4841 * The value for each EQ depends on how many EQs are configured.
James Smart895427b2017-02-12 13:52:30 -08004842 * Allow value == 0
James Smartbf8dae82012-08-03 12:36:24 -04004843 */
James Smart895427b2017-02-12 13:52:30 -08004844 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
James Smart173edbb2012-06-12 13:54:50 -04004845 return -EINVAL;
4846
4847 phba->cfg_fcp_imax = (uint32_t)val;
James Smart0cf07f842017-06-01 21:07:10 -07004848 phba->initial_imax = phba->cfg_fcp_imax;
James Smart43140ca2017-03-04 09:30:34 -08004849
4850 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart0cf07f842017-06-01 21:07:10 -07004851 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4852 val);
James Smart173edbb2012-06-12 13:54:50 -04004853
4854 return strlen(buf);
4855}
4856
4857/*
4858# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04004859# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04004860#
James Smartbf8dae82012-08-03 12:36:24 -04004861# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04004862*/
James Smartbf8dae82012-08-03 12:36:24 -04004863static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004864module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4865MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04004866 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04004867lpfc_param_show(fcp_imax)
4868
4869/**
4870 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4871 * @phba: lpfc_hba pointer.
4872 * @val: link speed value.
4873 *
4874 * Description:
4875 * If val is in a valid range [636,651042], then initialize the adapter's
4876 * maximum number of fast-path FCP interrupts per second.
4877 *
4878 * Returns:
4879 * zero if val saved.
4880 * -EINVAL val out of range
4881 **/
4882static int
4883lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4884{
James Smartbf8dae82012-08-03 12:36:24 -04004885 if (phba->sli_rev != LPFC_SLI_REV4) {
4886 phba->cfg_fcp_imax = 0;
4887 return 0;
4888 }
4889
James Smart895427b2017-02-12 13:52:30 -08004890 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4891 (val == 0)) {
James Smart173edbb2012-06-12 13:54:50 -04004892 phba->cfg_fcp_imax = val;
4893 return 0;
4894 }
4895
4896 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004897 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4898 val);
James Smartbf8dae82012-08-03 12:36:24 -04004899 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004900
4901 return 0;
4902}
4903
Joe Perchesb6b996b2017-12-19 10:15:07 -08004904static DEVICE_ATTR_RW(lpfc_fcp_imax);
James Smart173edbb2012-06-12 13:54:50 -04004905
James Smart0cf07f842017-06-01 21:07:10 -07004906/*
4907 * lpfc_auto_imax: Controls Auto-interrupt coalescing values support.
4908 * 0 No auto_imax support
4909 * 1 auto imax on
4910 * Auto imax will change the value of fcp_imax on a per EQ basis, using
4911 * the EQ Delay Multiplier, depending on the activity for that EQ.
4912 * Value range [0,1]. Default value is 1.
4913 */
4914LPFC_ATTR_RW(auto_imax, 1, 0, 1, "Enable Auto imax");
4915
James Smart7bb03bb2013-04-17 20:19:16 -04004916/**
4917 * lpfc_state_show - Display current driver CPU affinity
4918 * @dev: class converted to a Scsi_host structure.
4919 * @attr: device attribute, not used.
4920 * @buf: on return contains text describing the state of the link.
4921 *
4922 * Returns: size of formatted string.
4923 **/
4924static ssize_t
4925lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4926 char *buf)
4927{
4928 struct Scsi_Host *shost = class_to_shost(dev);
4929 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4930 struct lpfc_hba *phba = vport->phba;
4931 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05004932 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04004933
4934 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4935 (phba->intr_type != MSIX))
4936 return len;
4937
4938 switch (phba->cfg_fcp_cpu_map) {
4939 case 0:
4940 len += snprintf(buf + len, PAGE_SIZE-len,
4941 "fcp_cpu_map: No mapping (%d)\n",
4942 phba->cfg_fcp_cpu_map);
4943 return len;
4944 case 1:
4945 len += snprintf(buf + len, PAGE_SIZE-len,
4946 "fcp_cpu_map: HBA centric mapping (%d): "
4947 "%d online CPUs\n",
4948 phba->cfg_fcp_cpu_map,
4949 phba->sli4_hba.num_online_cpu);
4950 break;
4951 case 2:
4952 len += snprintf(buf + len, PAGE_SIZE-len,
4953 "fcp_cpu_map: Driver centric mapping (%d): "
4954 "%d online CPUs\n",
4955 phba->cfg_fcp_cpu_map,
4956 phba->sli4_hba.num_online_cpu);
4957 break;
4958 }
4959
James Smart76fd07a2014-02-20 09:57:18 -05004960 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4961 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4962
4963 /* margin should fit in this and the truncated message */
James Smart7bb03bb2013-04-17 20:19:16 -04004964 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4965 len += snprintf(buf + len, PAGE_SIZE-len,
4966 "CPU %02d io_chan %02d "
4967 "physid %d coreid %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004968 phba->sli4_hba.curr_disp_cpu,
4969 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004970 cpup->core_id);
4971 else
4972 len += snprintf(buf + len, PAGE_SIZE-len,
4973 "CPU %02d io_chan %02d "
4974 "physid %d coreid %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004975 phba->sli4_hba.curr_disp_cpu,
4976 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004977 cpup->core_id, cpup->irq);
4978
James Smart76fd07a2014-02-20 09:57:18 -05004979 phba->sli4_hba.curr_disp_cpu++;
4980
4981 /* display max number of CPUs keeping some margin */
4982 if (phba->sli4_hba.curr_disp_cpu <
4983 phba->sli4_hba.num_present_cpu &&
4984 (len >= (PAGE_SIZE - 64))) {
4985 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4986 break;
4987 }
James Smart7bb03bb2013-04-17 20:19:16 -04004988 }
James Smart76fd07a2014-02-20 09:57:18 -05004989
4990 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4991 phba->sli4_hba.curr_disp_cpu = 0;
4992
James Smart7bb03bb2013-04-17 20:19:16 -04004993 return len;
4994}
4995
4996/**
4997 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4998 * @dev: class device that is converted into a Scsi_host.
4999 * @attr: device attribute, not used.
5000 * @buf: one or more lpfc_polling_flags values.
5001 * @count: not used.
5002 *
5003 * Returns:
5004 * -EINVAL - Not implemented yet.
5005 **/
5006static ssize_t
5007lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
5008 const char *buf, size_t count)
5009{
5010 int status = -EINVAL;
5011 return status;
5012}
5013
5014/*
5015# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
5016# for the HBA.
5017#
5018# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
5019# 0 - Do not affinitze IRQ vectors
5020# 1 - Affintize HBA vectors with respect to each HBA
5021# (start with CPU0 for each HBA)
5022# 2 - Affintize HBA vectors with respect to the entire driver
5023# (round robin thru all CPUs across all HBAs)
5024*/
5025static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
5026module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
5027MODULE_PARM_DESC(lpfc_fcp_cpu_map,
5028 "Defines how to map CPUs to IRQ vectors per HBA");
5029
5030/**
5031 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
5032 * @phba: lpfc_hba pointer.
5033 * @val: link speed value.
5034 *
5035 * Description:
5036 * If val is in a valid range [0-2], then affinitze the adapter's
5037 * MSIX vectors.
5038 *
5039 * Returns:
5040 * zero if val saved.
5041 * -EINVAL val out of range
5042 **/
5043static int
5044lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
5045{
5046 if (phba->sli_rev != LPFC_SLI_REV4) {
5047 phba->cfg_fcp_cpu_map = 0;
5048 return 0;
5049 }
5050
5051 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
5052 phba->cfg_fcp_cpu_map = val;
5053 return 0;
5054 }
5055
5056 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07005057 "3326 lpfc_fcp_cpu_map: %d out of range, using "
5058 "default\n", val);
James Smart7bb03bb2013-04-17 20:19:16 -04005059 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
5060
5061 return 0;
5062}
5063
Joe Perchesb6b996b2017-12-19 10:15:07 -08005064static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
James Smart7bb03bb2013-04-17 20:19:16 -04005065
James Smart0d878412009-10-02 15:16:56 -04005066/*
dea31012005-04-17 16:05:31 -05005067# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
5068# Value range is [2,3]. Default value is 3.
5069*/
James Smart3de2a652007-08-02 11:09:59 -04005070LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
5071 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05005072
5073/*
5074# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
5075# is [0,1]. Default value is 0.
5076*/
James Smart3de2a652007-08-02 11:09:59 -04005077LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
5078 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05005079
5080/*
James Smart3cb01c52013-07-15 18:35:04 -04005081# lpfc_first_burst_size: First burst size to use on the NPorts
5082# that support first burst.
5083# Value range is [0,65536]. Default value is 0.
5084*/
5085LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
5086 "First burst size for Targets that support first burst");
5087
5088/*
James Smart2d7dbc42017-02-12 13:52:35 -08005089* lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
5090* When the driver is configured as an NVME target, this value is
5091* communicated to the NVME initiator in the PRLI response. It is
5092* used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
5093* parameters are set and the target is sending the PRLI RSP.
James Smart895427b2017-02-12 13:52:30 -08005094* Parameter supported on physical port only - no NPIV support.
James Smart2d7dbc42017-02-12 13:52:35 -08005095* Value range is [0,65536]. Default value is 0.
James Smart895427b2017-02-12 13:52:30 -08005096*/
James Smart2d7dbc42017-02-12 13:52:35 -08005097LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
5098 "NVME Target mode first burst size in 512B increments.");
5099
5100/*
5101 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
5102 * For the Initiator (I), enabling this parameter means that an NVMET
5103 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
5104 * processed by the initiator for subsequent NVME FCP IO. For the target
5105 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
5106 * driver parameter as the target function's first burst size returned to the
5107 * initiator in the target's NVME PRLI response. Parameter supported on physical
5108 * port only - no NPIV support.
5109 * Value range is [0,1]. Default value is 0 (disabled).
5110 */
James Smart895427b2017-02-12 13:52:30 -08005111LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
5112 "Enable First Burst feature on I and T functions.");
5113
5114/*
James Smart977b5a02008-09-07 11:52:04 -04005115# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
5116# depth. Default value is 0. When the value of this parameter is zero the
5117# SCSI command completion time is not used for controlling I/O queue depth. When
5118# the parameter is set to a non-zero value, the I/O queue depth is controlled
5119# to limit the I/O completion time to the parameter value.
5120# The value is set in milliseconds.
5121*/
James Smarted5b1522016-10-13 15:06:11 -07005122LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
James Smart977b5a02008-09-07 11:52:04 -04005123 "Use command completion time to control queue depth");
James Smarted5b1522016-10-13 15:06:11 -07005124
James Smart977b5a02008-09-07 11:52:04 -04005125lpfc_vport_param_show(max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04005126static int
5127lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
5128{
5129 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5130 struct lpfc_nodelist *ndlp, *next_ndlp;
5131
5132 if (val == vport->cfg_max_scsicmpl_time)
5133 return 0;
5134 if ((val < 0) || (val > 60000))
5135 return -EINVAL;
5136 vport->cfg_max_scsicmpl_time = val;
5137
5138 spin_lock_irq(shost->host_lock);
5139 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5140 if (!NLP_CHK_NODE_ACT(ndlp))
5141 continue;
5142 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
5143 continue;
James Smart7dc517d2010-07-14 15:32:10 -04005144 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04005145 }
5146 spin_unlock_irq(shost->host_lock);
5147 return 0;
5148}
5149lpfc_vport_param_store(max_scsicmpl_time);
Joe Perchesb6b996b2017-12-19 10:15:07 -08005150static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04005151
5152/*
dea31012005-04-17 16:05:31 -05005153# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
5154# range is [0,1]. Default value is 0.
5155*/
5156LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
5157
5158/*
James Smart895427b2017-02-12 13:52:30 -08005159 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
5160 * range is [0,1]. Default value is 0.
5161 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
5162 * For [1], FCP commands are issued to a Work Queue associated with the
5163 * current CPU.
5164 *
5165 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
5166 * LPFC_FCP_SCHED_BY_CPU == 1
5167 *
5168 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
5169 * affinity for FCP/NVME I/Os through Work Queues associated with the current
5170 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
5171 * through WQs will be used.
5172 */
5173LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
5174 LPFC_FCP_SCHED_ROUND_ROBIN,
5175 LPFC_FCP_SCHED_BY_CPU,
5176 "Determine scheduling algorithm for "
5177 "issuing commands [0] - Round Robin, [1] - Current CPU");
James Smart49aa1432012-08-03 12:36:42 -04005178
5179/*
James Smart7ea92eb2018-10-23 13:41:10 -07005180 * lpfc_ns_query: Determine algrithmn for NameServer queries after RSCN
5181 * range is [0,1]. Default value is 0.
5182 * For [0], GID_FT is used for NameServer queries after RSCN (default)
5183 * For [1], GID_PT is used for NameServer queries after RSCN
5184 *
5185 */
5186LPFC_ATTR_RW(ns_query, LPFC_NS_QUERY_GID_FT,
5187 LPFC_NS_QUERY_GID_FT, LPFC_NS_QUERY_GID_PT,
5188 "Determine algorithm NameServer queries after RSCN "
5189 "[0] - GID_FT, [1] - GID_PT");
5190
5191/*
James Smarta6571c62012-10-31 14:44:42 -04005192# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
5193# range is [0,1]. Default value is 0.
5194# For [0], bus reset issues target reset to ALL devices
5195# For [1], bus reset issues target reset to non-FCP2 devices
5196*/
5197LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
5198 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
5199
5200
5201/*
dea31012005-04-17 16:05:31 -05005202# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
5203# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04005204# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05005205# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
5206# cr_delay is set to 0.
5207*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05005208LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05005209 "interrupt response is generated");
5210
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05005211LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05005212 "interrupt response is generated");
5213
5214/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05005215# lpfc_multi_ring_support: Determines how many rings to spread available
5216# cmd/rsp IOCB entries across.
5217# Value range is [1,2]. Default value is 1.
5218*/
5219LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
5220 "SLI rings to spread IOCB entries across");
5221
5222/*
James Smarta4bc3372006-12-02 13:34:16 -05005223# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
5224# identifies what rctl value to configure the additional ring for.
5225# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
5226*/
James Smart6a9c52c2009-10-02 15:16:51 -04005227LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05005228 255, "Identifies RCTL for additional ring configuration");
5229
5230/*
5231# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
5232# identifies what type value to configure the additional ring for.
5233# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
5234*/
James Smart6a9c52c2009-10-02 15:16:51 -04005235LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05005236 255, "Identifies TYPE for additional ring configuration");
5237
5238/*
James Smart4258e982015-12-16 18:11:58 -05005239# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
5240# 0 = SmartSAN functionality disabled (default)
5241# 1 = SmartSAN functionality enabled
5242# This parameter will override the value of lpfc_fdmi_on module parameter.
5243# Value range is [0,1]. Default value is 0.
dea31012005-04-17 16:05:31 -05005244*/
James Smart4258e982015-12-16 18:11:58 -05005245LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
5246
5247/*
5248# lpfc_fdmi_on: Controls FDMI support.
James Smart9abd9992018-08-14 12:55:05 -07005249# 0 No FDMI support
5250# 1 Traditional FDMI support (default)
James Smart8663cbb2016-03-31 14:12:33 -07005251# Traditional FDMI support means the driver will assume FDMI-2 support;
5252# however, if that fails, it will fallback to FDMI-1.
5253# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5254# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5255# lpfc_fdmi_on.
James Smart9abd9992018-08-14 12:55:05 -07005256# Value range [0,1]. Default value is 1.
James Smart4258e982015-12-16 18:11:58 -05005257*/
James Smart9abd9992018-08-14 12:55:05 -07005258LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05005259
5260/*
5261# Specifies the maximum number of ELS cmds we can have outstanding (for
5262# discovery). Value range is [1,64]. Default value = 32.
5263*/
James Smart3de2a652007-08-02 11:09:59 -04005264LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05005265 "during discovery");
5266
5267/*
James Smartc4a7c922013-05-31 17:04:59 -04005268# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
5269# will be scanned by the SCSI midlayer when sequential scanning is
5270# used; and is also the highest LUN ID allowed when the SCSI midlayer
5271# parses REPORT_LUN responses. The lpfc driver has no LUN count or
5272# LUN ID limit, but the SCSI midlayer requires this field for the uses
5273# above. The lpfc driver limits the default value to 255 for two reasons.
5274# As it bounds the sequential scan loop, scanning for thousands of luns
5275# on a target can take minutes of wall clock time. Additionally,
5276# there are FC targets, such as JBODs, that only recognize 8-bits of
5277# LUN ID. When they receive a value greater than 8 bits, they chop off
5278# the high order bits. In other words, they see LUN IDs 0, 256, 512,
5279# and so on all as LUN ID 0. This causes the linux kernel, which sees
5280# valid responses at each of the LUN IDs, to believe there are multiple
5281# devices present, when in fact, there is only 1.
5282# A customer that is aware of their target behaviors, and the results as
5283# indicated above, is welcome to increase the lpfc_max_luns value.
5284# As mentioned, this value is not used by the lpfc driver, only the
5285# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04005286# Value range is [0,65535]. Default value is 255.
5287# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05005288*/
Hannes Reinecke1abf6352014-06-25 15:27:38 +02005289LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05005290
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005291/*
5292# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
5293# Value range is [1,255], default value is 10.
5294*/
5295LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
5296 "Milliseconds driver will wait between polling FCP ring");
5297
James Smart4ff43242006-12-02 13:34:56 -05005298/*
James Smart0c411222013-09-06 12:22:46 -04005299# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
5300# to complete in seconds. Value range is [5,180], default value is 60.
5301*/
5302LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
5303 "Maximum time to wait for task management commands to complete");
5304/*
James Smart4ff43242006-12-02 13:34:56 -05005305# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5306# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02005307# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05005308# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02005309# 2 = MSI-X enabled (default)
5310# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05005311*/
George Kadianakis8605c462010-01-17 21:19:31 +02005312LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05005313 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05005314
James Smart13815c82008-01-11 01:52:48 -05005315/*
James Smartf358dd02017-02-12 13:52:34 -08005316 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
James Smart895427b2017-02-12 13:52:30 -08005317 *
5318 * 0 = NVME OAS disabled
5319 * 1 = NVME OAS enabled
5320 *
5321 * Value range is [0,1]. Default value is 0.
5322 */
5323LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5324 "Use OAS bit on NVME IOs");
5325
5326/*
James Smart4e565cf2018-02-22 08:18:50 -08005327 * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
5328 *
5329 * 0 = Put NVME Command in SGL
5330 * 1 = Embed NVME Command in WQE (unless G7)
5331 * 2 = Embed NVME Command in WQE (force)
5332 *
5333 * Value range is [0,2]. Default value is 1.
5334 */
5335LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,
5336 "Embed NVME Command in WQE");
5337
5338/*
James Smart895427b2017-02-12 13:52:30 -08005339 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
5340 * will advertise it supports to the SCSI layer. This also will map to
5341 * the number of WQs the driver will create.
5342 *
5343 * 0 = Configure the number of io channels to the number of active CPUs.
5344 * 1,32 = Manually specify how many io channels to use.
5345 *
5346 * Value range is [0,32]. Default value is 4.
5347 */
5348LPFC_ATTR_R(fcp_io_channel,
5349 LPFC_FCP_IO_CHAN_DEF,
5350 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
James Smart67d12732012-08-03 12:36:13 -04005351 "Set the number of FCP I/O channels");
5352
5353/*
James Smart895427b2017-02-12 13:52:30 -08005354 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
5355 * will advertise it supports to the NVME layer. This also will map to
5356 * the number of WQs the driver will create.
5357 *
5358 * This module parameter is valid when lpfc_enable_fc4_type is set
5359 * to support NVME.
5360 *
5361 * The NVME Layer will try to create this many, plus 1 administrative
5362 * hardware queue. The administrative queue will always map to WQ 0
5363 * A hardware IO queue maps (qidx) to a specific driver WQ.
5364 *
5365 * 0 = Configure the number of io channels to the number of active CPUs.
5366 * 1,32 = Manually specify how many io channels to use.
5367 *
5368 * Value range is [0,32]. Default value is 0.
5369 */
5370LPFC_ATTR_R(nvme_io_channel,
5371 LPFC_NVME_IO_CHAN_DEF,
5372 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
5373 "Set the number of NVME I/O channels");
5374
5375/*
James Smart13815c82008-01-11 01:52:48 -05005376# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5377# 0 = HBA resets disabled
5378# 1 = HBA resets enabled (default)
5379# Value range is [0,1]. Default value is 1.
5380*/
5381LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04005382
James Smart13815c82008-01-11 01:52:48 -05005383/*
James Smarteb7a3392010-11-20 23:12:02 -05005384# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05005385# 0 = HBA Heartbeat disabled
5386# 1 = HBA Heartbeat enabled (default)
5387# Value range is [0,1]. Default value is 1.
5388*/
James Smarteb7a3392010-11-20 23:12:02 -05005389LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05005390
James Smart83108bd2008-01-11 01:53:09 -05005391/*
James Smart1ba981f2014-02-20 09:56:45 -05005392# lpfc_EnableXLane: Enable Express Lane Feature
5393# 0x0 Express Lane Feature disabled
5394# 0x1 Express Lane Feature enabled
5395# Value range is [0,1]. Default value is 0.
5396*/
5397LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5398
5399/*
5400# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5401# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5402# Value range is [0x0,0x7f]. Default value is 0
5403*/
James Smart28d7f3d2014-05-21 08:05:28 -04005404LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
James Smart1ba981f2014-02-20 09:56:45 -05005405
5406/*
James Smart81301a92008-12-04 22:39:46 -05005407# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5408# 0 = BlockGuard disabled (default)
5409# 1 = BlockGuard enabled
5410# Value range is [0,1]. Default value is 0.
5411*/
5412LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5413
James Smart6fb120a2009-05-22 14:52:59 -04005414/*
James Smartba20c852012-08-03 12:36:52 -04005415# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5416# 0 = disabled (default)
5417# 1 = enabled
5418# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04005419#
5420# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04005421*/
5422unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5423
James Smartba20c852012-08-03 12:36:52 -04005424/*
James Smart81301a92008-12-04 22:39:46 -05005425# lpfc_prot_mask: i
5426# - Bit mask of host protection capabilities used to register with the
5427# SCSI mid-layer
5428# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5429# - Allows you to ultimately specify which profiles to use
5430# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04005431# - SHOST_DIF_TYPE1_PROTECTION 1
5432# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5433# - SHOST_DIX_TYPE0_PROTECTION 8
5434# HBA supports DIX Type 0: Host to HBA protection only
5435# - SHOST_DIX_TYPE1_PROTECTION 16
5436# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05005437#
5438*/
James Smartb3b98b72016-10-13 15:06:06 -07005439LPFC_ATTR(prot_mask,
5440 (SHOST_DIF_TYPE1_PROTECTION |
5441 SHOST_DIX_TYPE0_PROTECTION |
5442 SHOST_DIX_TYPE1_PROTECTION),
5443 0,
5444 (SHOST_DIF_TYPE1_PROTECTION |
5445 SHOST_DIX_TYPE0_PROTECTION |
5446 SHOST_DIX_TYPE1_PROTECTION),
5447 "T10-DIF host protection capabilities mask");
James Smart81301a92008-12-04 22:39:46 -05005448
5449/*
5450# lpfc_prot_guard: i
5451# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04005452# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05005453# - Allows you to ultimately specify which profiles to use
5454# - Default will result in registering capabilities for all guard types
5455#
5456*/
James Smartb3b98b72016-10-13 15:06:06 -07005457LPFC_ATTR(prot_guard,
5458 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5459 "T10-DIF host protection guard type");
James Smart81301a92008-12-04 22:39:46 -05005460
James Smart92494142011-02-16 12:39:44 -05005461/*
5462 * Delay initial NPort discovery when Clean Address bit is cleared in
5463 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5464 * This parameter can have value 0 or 1.
5465 * When this parameter is set to 0, no delay is added to the initial
5466 * discovery.
5467 * When this parameter is set to non-zero value, initial Nport discovery is
5468 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5469 * accept and FCID/Fabric name/Fabric portname is changed.
5470 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5471 * when Clean Address bit is cleared in FLOGI/FDISC
5472 * accept and FCID/Fabric name/Fabric portname is changed.
5473 * Default value is 0.
5474 */
James Smart8eb8b962016-07-06 12:36:08 -07005475LPFC_ATTR(delay_discovery, 0, 0, 1,
5476 "Delay NPort discovery when Clean Address bit is cleared.");
James Smart81301a92008-12-04 22:39:46 -05005477
5478/*
James Smart3621a712009-04-06 18:47:14 -04005479 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart5b9e70b2018-09-10 10:30:42 -07005480 * This value can be set to values between 64 and 4096. The default value
5481 * is 64, but may be increased to allow for larger Max I/O sizes. The scsi
5482 * and nvme layers will allow I/O sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04005483 * Because of the additional overhead involved in setting up T10-DIF,
5484 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5485 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05005486 */
James Smart5b9e70b2018-09-10 10:30:42 -07005487static uint lpfc_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5488module_param(lpfc_sg_seg_cnt, uint, 0444);
5489MODULE_PARM_DESC(lpfc_sg_seg_cnt, "Max Scatter Gather Segment Count");
5490
5491/**
5492 * lpfc_sg_seg_cnt_show - Display the scatter/gather list sizes
5493 * configured for the adapter
5494 * @dev: class converted to a Scsi_host structure.
5495 * @attr: device attribute, not used.
5496 * @buf: on return contains a string with the list sizes
5497 *
5498 * Returns: size of formatted string.
5499 **/
5500static ssize_t
5501lpfc_sg_seg_cnt_show(struct device *dev, struct device_attribute *attr,
5502 char *buf)
5503{
5504 struct Scsi_Host *shost = class_to_shost(dev);
5505 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5506 struct lpfc_hba *phba = vport->phba;
5507 int len;
5508
5509 len = snprintf(buf, PAGE_SIZE, "SGL sz: %d total SGEs: %d\n",
5510 phba->cfg_sg_dma_buf_size, phba->cfg_total_seg_cnt);
5511
5512 len += snprintf(buf + len, PAGE_SIZE, "Cfg: %d SCSI: %d NVME: %d\n",
5513 phba->cfg_sg_seg_cnt, phba->cfg_scsi_seg_cnt,
5514 phba->cfg_nvme_seg_cnt);
5515 return len;
5516}
5517
5518static DEVICE_ATTR_RO(lpfc_sg_seg_cnt);
5519
5520/**
5521 * lpfc_sg_seg_cnt_init - Set the hba sg_seg_cnt initial value
5522 * @phba: lpfc_hba pointer.
5523 * @val: contains the initial value
5524 *
5525 * Description:
5526 * Validates the initial value is within range and assigns it to the
5527 * adapter. If not in range, an error message is posted and the
5528 * default value is assigned.
5529 *
5530 * Returns:
5531 * zero if value is in range and is set
5532 * -EINVAL if value was out of range
5533 **/
5534static int
5535lpfc_sg_seg_cnt_init(struct lpfc_hba *phba, int val)
5536{
5537 if (val >= LPFC_MIN_SG_SEG_CNT && val <= LPFC_MAX_SG_SEG_CNT) {
5538 phba->cfg_sg_seg_cnt = val;
5539 return 0;
5540 }
5541 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5542 "0409 "LPFC_DRIVER_NAME"_sg_seg_cnt attribute cannot "
5543 "be set to %d, allowed range is [%d, %d]\n",
5544 val, LPFC_MIN_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT);
5545 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5546 return -EINVAL;
5547}
James Smart83108bd2008-01-11 01:53:09 -05005548
James Smart96f70772013-04-17 20:16:15 -04005549/*
James Smart7bdedb32016-07-06 12:36:00 -07005550 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5551 * 0 = MDS Diagnostics disabled (default)
5552 * 1 = MDS Diagnostics enabled
5553 * Value range is [0,1]. Default value is 0.
5554 */
5555LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5556
James Smart44fd7fe2017-08-23 16:55:47 -07005557/*
James Smartd2cc9bc2018-09-10 10:30:50 -07005558 * lpfc_ras_fwlog_buffsize: Firmware logging host buffer size
5559 * 0 = Disable firmware logging (default)
5560 * [1-4] = Multiple of 1/4th Mb of host memory for FW logging
5561 * Value range [0..4]. Default value is 0
5562 */
5563LPFC_ATTR_RW(ras_fwlog_buffsize, 0, 0, 4, "Host memory for FW logging");
5564
5565/*
5566 * lpfc_ras_fwlog_level: Firmware logging verbosity level
5567 * Valid only if firmware logging is enabled
5568 * 0(Least Verbosity) 4 (most verbosity)
5569 * Value range is [0..4]. Default value is 0
5570 */
5571LPFC_ATTR_RW(ras_fwlog_level, 0, 0, 4, "Firmware Logging Level");
5572
5573/*
5574 * lpfc_ras_fwlog_func: Firmware logging enabled on function number
5575 * Default function which has RAS support : 0
5576 * Value Range is [0..7].
5577 * FW logging is a global action and enablement is via a specific
5578 * port.
5579 */
5580LPFC_ATTR_RW(ras_fwlog_func, 0, 0, 7, "Firmware Logging Enabled on Function");
5581
5582/*
James Smart44fd7fe2017-08-23 16:55:47 -07005583 * lpfc_enable_bbcr: Enable BB Credit Recovery
5584 * 0 = BB Credit Recovery disabled
5585 * 1 = BB Credit Recovery enabled (default)
5586 * Value range is [0,1]. Default value is 1.
5587 */
5588LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5589
James Smart1351e692018-02-22 08:18:43 -08005590/*
5591 * lpfc_enable_dpp: Enable DPP on G7
5592 * 0 = DPP on G7 disabled
5593 * 1 = DPP on G7 enabled (default)
5594 * Value range is [0,1]. Default value is 1.
5595 */
5596LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");
5597
Tony Jonesee959b02008-02-22 00:13:36 +01005598struct device_attribute *lpfc_hba_attrs[] = {
James Smart895427b2017-02-12 13:52:30 -08005599 &dev_attr_nvme_info,
James Smart81301a92008-12-04 22:39:46 -05005600 &dev_attr_bg_info,
5601 &dev_attr_bg_guard_err,
5602 &dev_attr_bg_apptag_err,
5603 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01005604 &dev_attr_info,
5605 &dev_attr_serialnum,
5606 &dev_attr_modeldesc,
5607 &dev_attr_modelname,
5608 &dev_attr_programtype,
5609 &dev_attr_portnum,
5610 &dev_attr_fwrev,
5611 &dev_attr_hdw,
5612 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005613 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005614 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04005615 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01005616 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04005617 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01005618 &dev_attr_lpfc_temp_sensor,
5619 &dev_attr_lpfc_log_verbose,
5620 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005621 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005622 &dev_attr_lpfc_hba_queue_depth,
5623 &dev_attr_lpfc_peer_port_login,
5624 &dev_attr_lpfc_nodev_tmo,
5625 &dev_attr_lpfc_devloss_tmo,
James Smart895427b2017-02-12 13:52:30 -08005626 &dev_attr_lpfc_enable_fc4_type,
5627 &dev_attr_lpfc_xri_split,
Tony Jonesee959b02008-02-22 00:13:36 +01005628 &dev_attr_lpfc_fcp_class,
5629 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005630 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005631 &dev_attr_lpfc_ack0,
5632 &dev_attr_lpfc_topology,
5633 &dev_attr_lpfc_scan_down,
5634 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04005635 &dev_attr_lpfc_fcp_io_sched,
James Smart7ea92eb2018-10-23 13:41:10 -07005636 &dev_attr_lpfc_ns_query,
James Smarta6571c62012-10-31 14:44:42 -04005637 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01005638 &dev_attr_lpfc_cr_delay,
5639 &dev_attr_lpfc_cr_count,
5640 &dev_attr_lpfc_multi_ring_support,
5641 &dev_attr_lpfc_multi_ring_rctl,
5642 &dev_attr_lpfc_multi_ring_type,
5643 &dev_attr_lpfc_fdmi_on,
James Smart4258e982015-12-16 18:11:58 -05005644 &dev_attr_lpfc_enable_SmartSAN,
Tony Jonesee959b02008-02-22 00:13:36 +01005645 &dev_attr_lpfc_max_luns,
5646 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04005647 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05005648 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01005649 &dev_attr_nport_evt_cnt,
5650 &dev_attr_board_mode,
5651 &dev_attr_max_vpi,
5652 &dev_attr_used_vpi,
5653 &dev_attr_max_rpi,
5654 &dev_attr_used_rpi,
5655 &dev_attr_max_xri,
5656 &dev_attr_used_xri,
5657 &dev_attr_npiv_info,
5658 &dev_attr_issue_reset,
5659 &dev_attr_lpfc_poll,
5660 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04005661 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01005662 &dev_attr_lpfc_use_msi,
James Smart895427b2017-02-12 13:52:30 -08005663 &dev_attr_lpfc_nvme_oas,
James Smart4e565cf2018-02-22 08:18:50 -08005664 &dev_attr_lpfc_nvme_embed_cmd,
James Smart0cf07f842017-06-01 21:07:10 -07005665 &dev_attr_lpfc_auto_imax,
James Smartda0436e2009-05-22 14:51:39 -04005666 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04005667 &dev_attr_lpfc_fcp_cpu_map,
James Smart67d12732012-08-03 12:36:13 -04005668 &dev_attr_lpfc_fcp_io_channel,
James Smartf358dd02017-02-12 13:52:34 -08005669 &dev_attr_lpfc_suppress_rsp,
James Smart895427b2017-02-12 13:52:30 -08005670 &dev_attr_lpfc_nvme_io_channel,
James Smart2d7dbc42017-02-12 13:52:35 -08005671 &dev_attr_lpfc_nvmet_mrq,
James Smart2448e482018-04-09 14:24:24 -07005672 &dev_attr_lpfc_nvmet_mrq_post,
James Smart895427b2017-02-12 13:52:30 -08005673 &dev_attr_lpfc_nvme_enable_fb,
James Smart2d7dbc42017-02-12 13:52:35 -08005674 &dev_attr_lpfc_nvmet_fb_size,
James Smart81301a92008-12-04 22:39:46 -05005675 &dev_attr_lpfc_enable_bg,
James Smart352e5fd2016-12-30 06:57:47 -08005676 &dev_attr_lpfc_soft_wwnn,
5677 &dev_attr_lpfc_soft_wwpn,
5678 &dev_attr_lpfc_soft_wwn_enable,
Tony Jonesee959b02008-02-22 00:13:36 +01005679 &dev_attr_lpfc_enable_hba_reset,
5680 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05005681 &dev_attr_lpfc_EnableXLane,
5682 &dev_attr_lpfc_XLanePriority,
5683 &dev_attr_lpfc_xlane_lun,
5684 &dev_attr_lpfc_xlane_tgt,
5685 &dev_attr_lpfc_xlane_vpt,
5686 &dev_attr_lpfc_xlane_lun_state,
5687 &dev_attr_lpfc_xlane_lun_status,
James Smartc92c8412016-07-06 12:36:05 -07005688 &dev_attr_lpfc_xlane_priority,
Tony Jonesee959b02008-02-22 00:13:36 +01005689 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04005690 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04005691 &dev_attr_lpfc_stat_data_ctrl,
James Smart0d878412009-10-02 15:16:56 -04005692 &dev_attr_lpfc_aer_support,
5693 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04005694 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04005695 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05005696 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04005697 &dev_attr_lpfc_iocb_cnt,
5698 &dev_attr_iocb_hw,
5699 &dev_attr_txq_hw,
5700 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04005701 &dev_attr_lpfc_fips_level,
5702 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05005703 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04005704 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05005705 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05005706 &dev_attr_lpfc_xlane_supported,
James Smart7bdedb32016-07-06 12:36:00 -07005707 &dev_attr_lpfc_enable_mds_diags,
James Smartd2cc9bc2018-09-10 10:30:50 -07005708 &dev_attr_lpfc_ras_fwlog_buffsize,
5709 &dev_attr_lpfc_ras_fwlog_level,
5710 &dev_attr_lpfc_ras_fwlog_func,
James Smart44fd7fe2017-08-23 16:55:47 -07005711 &dev_attr_lpfc_enable_bbcr,
James Smart1351e692018-02-22 08:18:43 -08005712 &dev_attr_lpfc_enable_dpp,
dea31012005-04-17 16:05:31 -05005713 NULL,
5714};
5715
Tony Jonesee959b02008-02-22 00:13:36 +01005716struct device_attribute *lpfc_vport_attrs[] = {
5717 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005718 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005719 &dev_attr_num_discovered_ports,
5720 &dev_attr_lpfc_drvr_version,
5721 &dev_attr_lpfc_log_verbose,
5722 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005723 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005724 &dev_attr_lpfc_nodev_tmo,
5725 &dev_attr_lpfc_devloss_tmo,
5726 &dev_attr_lpfc_hba_queue_depth,
5727 &dev_attr_lpfc_peer_port_login,
5728 &dev_attr_lpfc_restrict_login,
5729 &dev_attr_lpfc_fcp_class,
5730 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005731 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005732 &dev_attr_lpfc_max_luns,
5733 &dev_attr_nport_evt_cnt,
5734 &dev_attr_npiv_info,
5735 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04005736 &dev_attr_lpfc_max_scsicmpl_time,
5737 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04005738 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04005739 &dev_attr_lpfc_fips_level,
5740 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04005741 NULL,
5742};
5743
James Smarte59058c2008-08-24 21:49:00 -04005744/**
James Smart3621a712009-04-06 18:47:14 -04005745 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005746 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005747 * @kobj: kernel kobject that contains the kernel class device.
5748 * @bin_attr: kernel attributes passed to us.
5749 * @buf: contains the data to be written to the adapter IOREG space.
5750 * @off: offset into buffer to beginning of data.
5751 * @count: bytes to transfer.
5752 *
5753 * Description:
5754 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5755 * Uses the adapter io control registers to send buf contents to the adapter.
5756 *
5757 * Returns:
5758 * -ERANGE off and count combo out of range
5759 * -EINVAL off, count or buff address invalid
5760 * -EPERM adapter is offline
5761 * value of count, buf contents written
5762 **/
dea31012005-04-17 16:05:31 -05005763static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005764sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5765 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005766 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005767{
5768 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01005769 struct device *dev = container_of(kobj, struct device, kobj);
5770 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005771 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5772 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005773
James Smartf1126682009-06-10 17:22:44 -04005774 if (phba->sli_rev >= LPFC_SLI_REV4)
5775 return -EPERM;
5776
dea31012005-04-17 16:05:31 -05005777 if ((off + count) > FF_REG_AREA_SIZE)
5778 return -ERANGE;
5779
James Smartf7a919b2011-08-21 21:49:16 -04005780 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5781 return 0;
dea31012005-04-17 16:05:31 -05005782
5783 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5784 return -EINVAL;
5785
James Smartf7a919b2011-08-21 21:49:16 -04005786 /* This is to protect HBA registers from accidental writes. */
5787 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5788 return -EINVAL;
5789
5790 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05005791 return -EPERM;
dea31012005-04-17 16:05:31 -05005792
James Smart2e0fef82007-06-17 19:56:36 -05005793 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04005794 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5795 buf_off += sizeof(uint32_t))
5796 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05005797 phba->ctrl_regs_memmap_p + off + buf_off);
5798
James Smart2e0fef82007-06-17 19:56:36 -05005799 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005800
5801 return count;
5802}
5803
James Smarte59058c2008-08-24 21:49:00 -04005804/**
James Smart3621a712009-04-06 18:47:14 -04005805 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005806 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005807 * @kobj: kernel kobject that contains the kernel class device.
5808 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005809 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04005810 * @off: offset into buffer to beginning of data.
5811 * @count: bytes to transfer.
5812 *
5813 * Description:
5814 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5815 * Uses the adapter io control registers to read data into buf.
5816 *
5817 * Returns:
5818 * -ERANGE off and count combo out of range
5819 * -EINVAL off, count or buff address invalid
5820 * value of count, buf contents read
5821 **/
dea31012005-04-17 16:05:31 -05005822static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005823sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5824 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005825 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005826{
5827 size_t buf_off;
5828 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01005829 struct device *dev = container_of(kobj, struct device, kobj);
5830 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005831 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5832 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005833
James Smartf1126682009-06-10 17:22:44 -04005834 if (phba->sli_rev >= LPFC_SLI_REV4)
5835 return -EPERM;
5836
dea31012005-04-17 16:05:31 -05005837 if (off > FF_REG_AREA_SIZE)
5838 return -ERANGE;
5839
5840 if ((off + count) > FF_REG_AREA_SIZE)
5841 count = FF_REG_AREA_SIZE - off;
5842
5843 if (count == 0) return 0;
5844
5845 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5846 return -EINVAL;
5847
James Smart2e0fef82007-06-17 19:56:36 -05005848 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005849
5850 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5851 tmp_ptr = (uint32_t *)(buf + buf_off);
5852 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5853 }
5854
James Smart2e0fef82007-06-17 19:56:36 -05005855 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005856
5857 return count;
5858}
5859
5860static struct bin_attribute sysfs_ctlreg_attr = {
5861 .attr = {
5862 .name = "ctlreg",
5863 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005864 },
5865 .size = 256,
5866 .read = sysfs_ctlreg_read,
5867 .write = sysfs_ctlreg_write,
5868};
5869
James Smarte59058c2008-08-24 21:49:00 -04005870/**
James Smart3621a712009-04-06 18:47:14 -04005871 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005872 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005873 * @kobj: kernel kobject that contains the kernel class device.
5874 * @bin_attr: kernel attributes passed to us.
5875 * @buf: contains the data to be written to sysfs mbox.
5876 * @off: offset into buffer to beginning of data.
5877 * @count: bytes to transfer.
5878 *
5879 * Description:
James Smart026abb82011-12-13 13:20:45 -05005880 * Deprecated function. All mailbox access from user space is performed via the
5881 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005882 *
5883 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005884 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005885 **/
dea31012005-04-17 16:05:31 -05005886static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005887sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5888 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005889 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005890{
James Smart026abb82011-12-13 13:20:45 -05005891 return -EPERM;
dea31012005-04-17 16:05:31 -05005892}
5893
James Smarte59058c2008-08-24 21:49:00 -04005894/**
James Smart3621a712009-04-06 18:47:14 -04005895 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005896 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005897 * @kobj: kernel kobject that contains the kernel class device.
5898 * @bin_attr: kernel attributes passed to us.
5899 * @buf: contains the data to be read from sysfs mbox.
5900 * @off: offset into buffer to beginning of data.
5901 * @count: bytes to transfer.
5902 *
5903 * Description:
James Smart026abb82011-12-13 13:20:45 -05005904 * Deprecated function. All mailbox access from user space is performed via the
5905 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005906 *
5907 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005908 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005909 **/
dea31012005-04-17 16:05:31 -05005910static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005911sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5912 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005913 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005914{
James Smart026abb82011-12-13 13:20:45 -05005915 return -EPERM;
dea31012005-04-17 16:05:31 -05005916}
5917
5918static struct bin_attribute sysfs_mbox_attr = {
5919 .attr = {
5920 .name = "mbox",
5921 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005922 },
James Smartc0c11512011-05-24 11:41:34 -04005923 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05005924 .read = sysfs_mbox_read,
5925 .write = sysfs_mbox_write,
5926};
5927
James Smarte59058c2008-08-24 21:49:00 -04005928/**
James Smart3621a712009-04-06 18:47:14 -04005929 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005930 * @vport: address of lpfc vport structure.
5931 *
5932 * Return codes:
5933 * zero on success
5934 * error return code from sysfs_create_bin_file()
5935 **/
dea31012005-04-17 16:05:31 -05005936int
James Smart2e0fef82007-06-17 19:56:36 -05005937lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005938{
James Smart2e0fef82007-06-17 19:56:36 -05005939 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005940 int error;
5941
Tony Jonesee959b02008-02-22 00:13:36 +01005942 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05005943 &sysfs_drvr_stat_data_attr);
5944
5945 /* Virtual ports do not need ctrl_reg and mbox */
5946 if (error || vport->port_type == LPFC_NPIV_PORT)
5947 goto out;
5948
5949 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005950 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005951 if (error)
James Smarteada2722008-12-04 22:39:13 -05005952 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05005953
Tony Jonesee959b02008-02-22 00:13:36 +01005954 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005955 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05005956 if (error)
5957 goto out_remove_ctlreg_attr;
5958
5959 return 0;
5960out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01005961 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05005962out_remove_stat_attr:
5963 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5964 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05005965out:
5966 return error;
5967}
5968
James Smarte59058c2008-08-24 21:49:00 -04005969/**
James Smart3621a712009-04-06 18:47:14 -04005970 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005971 * @vport: address of lpfc vport structure.
5972 **/
dea31012005-04-17 16:05:31 -05005973void
James Smart2e0fef82007-06-17 19:56:36 -05005974lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005975{
James Smart2e0fef82007-06-17 19:56:36 -05005976 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04005977 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5978 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05005979 /* Virtual ports do not need ctrl_reg and mbox */
5980 if (vport->port_type == LPFC_NPIV_PORT)
5981 return;
Tony Jonesee959b02008-02-22 00:13:36 +01005982 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5983 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005984}
5985
dea31012005-04-17 16:05:31 -05005986/*
5987 * Dynamic FC Host Attributes Support
5988 */
5989
James Smarte59058c2008-08-24 21:49:00 -04005990/**
James Smart6c9231f2016-12-19 15:07:24 -08005991 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5992 * @shost: kernel scsi host pointer.
5993 **/
5994static void
5995lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5996{
5997 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5998
5999 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
6000 sizeof fc_host_symbolic_name(shost));
6001}
6002
6003/**
James Smart3621a712009-04-06 18:47:14 -04006004 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04006005 * @shost: kernel scsi host pointer.
6006 **/
dea31012005-04-17 16:05:31 -05006007static void
6008lpfc_get_host_port_id(struct Scsi_Host *shost)
6009{
James Smart2e0fef82007-06-17 19:56:36 -05006010 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6011
dea31012005-04-17 16:05:31 -05006012 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05006013 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05006014}
6015
James Smarte59058c2008-08-24 21:49:00 -04006016/**
James Smart3621a712009-04-06 18:47:14 -04006017 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04006018 * @shost: kernel scsi host pointer.
6019 **/
dea31012005-04-17 16:05:31 -05006020static void
6021lpfc_get_host_port_type(struct Scsi_Host *shost)
6022{
James Smart2e0fef82007-06-17 19:56:36 -05006023 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6024 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006025
6026 spin_lock_irq(shost->host_lock);
6027
James Smart92d7f7b2007-06-17 19:56:38 -05006028 if (vport->port_type == LPFC_NPIV_PORT) {
6029 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
6030 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05006031 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05006032 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05006033 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
6034 else
6035 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
6036 } else {
James Smart2e0fef82007-06-17 19:56:36 -05006037 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05006038 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
6039 else
6040 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
6041 }
6042 } else
6043 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
6044
6045 spin_unlock_irq(shost->host_lock);
6046}
6047
James Smarte59058c2008-08-24 21:49:00 -04006048/**
James Smart3621a712009-04-06 18:47:14 -04006049 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04006050 * @shost: kernel scsi host pointer.
6051 **/
dea31012005-04-17 16:05:31 -05006052static void
6053lpfc_get_host_port_state(struct Scsi_Host *shost)
6054{
James Smart2e0fef82007-06-17 19:56:36 -05006055 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6056 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006057
6058 spin_lock_irq(shost->host_lock);
6059
James Smart2e0fef82007-06-17 19:56:36 -05006060 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05006061 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
6062 else {
James Smart2e0fef82007-06-17 19:56:36 -05006063 switch (phba->link_state) {
6064 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05006065 case LPFC_LINK_DOWN:
6066 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
6067 break;
6068 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05006069 case LPFC_CLEAR_LA:
6070 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05006071 /* Links up, reports port state accordingly */
6072 if (vport->port_state < LPFC_VPORT_READY)
6073 fc_host_port_state(shost) =
6074 FC_PORTSTATE_BYPASSED;
6075 else
6076 fc_host_port_state(shost) =
6077 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05006078 break;
6079 case LPFC_HBA_ERROR:
6080 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
6081 break;
6082 default:
6083 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
6084 break;
6085 }
6086 }
6087
6088 spin_unlock_irq(shost->host_lock);
6089}
6090
James Smarte59058c2008-08-24 21:49:00 -04006091/**
James Smart3621a712009-04-06 18:47:14 -04006092 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04006093 * @shost: kernel scsi host pointer.
6094 **/
dea31012005-04-17 16:05:31 -05006095static void
6096lpfc_get_host_speed(struct Scsi_Host *shost)
6097{
James Smart2e0fef82007-06-17 19:56:36 -05006098 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6099 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006100
6101 spin_lock_irq(shost->host_lock);
6102
James Smarta085e872015-12-16 18:12:02 -05006103 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea31012005-04-17 16:05:31 -05006104 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05006105 case LPFC_LINK_SPEED_1GHZ:
6106 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05006107 break;
James Smart76a95d72010-11-20 23:11:48 -05006108 case LPFC_LINK_SPEED_2GHZ:
6109 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05006110 break;
James Smart76a95d72010-11-20 23:11:48 -05006111 case LPFC_LINK_SPEED_4GHZ:
6112 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05006113 break;
James Smart76a95d72010-11-20 23:11:48 -05006114 case LPFC_LINK_SPEED_8GHZ:
6115 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04006116 break;
James Smart76a95d72010-11-20 23:11:48 -05006117 case LPFC_LINK_SPEED_10GHZ:
6118 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04006119 break;
James Smart76a95d72010-11-20 23:11:48 -05006120 case LPFC_LINK_SPEED_16GHZ:
6121 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
6122 break;
James Smartd38dd522015-08-31 16:48:17 -04006123 case LPFC_LINK_SPEED_32GHZ:
6124 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
6125 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08006126 case LPFC_LINK_SPEED_64GHZ:
6127 fc_host_speed(shost) = FC_PORTSPEED_64GBIT;
6128 break;
James Smart1dc5ec22018-10-23 13:41:11 -07006129 case LPFC_LINK_SPEED_128GHZ:
6130 fc_host_speed(shost) = FC_PORTSPEED_128GBIT;
6131 break;
James Smart76a95d72010-11-20 23:11:48 -05006132 default:
6133 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05006134 break;
6135 }
James Smartb615a202018-07-31 17:23:19 -07006136 } else if (lpfc_is_link_up(phba) && (phba->hba_flag & HBA_FCOE_MODE)) {
6137 switch (phba->fc_linkspeed) {
6138 case LPFC_ASYNC_LINK_SPEED_10GBPS:
6139 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6140 break;
6141 case LPFC_ASYNC_LINK_SPEED_25GBPS:
6142 fc_host_speed(shost) = FC_PORTSPEED_25GBIT;
6143 break;
6144 case LPFC_ASYNC_LINK_SPEED_40GBPS:
6145 fc_host_speed(shost) = FC_PORTSPEED_40GBIT;
6146 break;
6147 case LPFC_ASYNC_LINK_SPEED_100GBPS:
6148 fc_host_speed(shost) = FC_PORTSPEED_100GBIT;
6149 break;
6150 default:
6151 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6152 break;
6153 }
James Smart09372822008-01-11 01:52:54 -05006154 } else
6155 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05006156
6157 spin_unlock_irq(shost->host_lock);
6158}
6159
James Smarte59058c2008-08-24 21:49:00 -04006160/**
James Smart3621a712009-04-06 18:47:14 -04006161 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04006162 * @shost: kernel scsi host pointer.
6163 **/
dea31012005-04-17 16:05:31 -05006164static void
6165lpfc_get_host_fabric_name (struct Scsi_Host *shost)
6166{
James Smart2e0fef82007-06-17 19:56:36 -05006167 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6168 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07006169 u64 node_name;
dea31012005-04-17 16:05:31 -05006170
6171 spin_lock_irq(shost->host_lock);
6172
James Smart73d91e52011-10-10 21:32:10 -04006173 if ((vport->port_state > LPFC_FLOGI) &&
6174 ((vport->fc_flag & FC_FABRIC) ||
6175 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
6176 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07006177 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05006178 else
6179 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05006180 node_name = 0;
dea31012005-04-17 16:05:31 -05006181
6182 spin_unlock_irq(shost->host_lock);
6183
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07006184 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05006185}
6186
James Smarte59058c2008-08-24 21:49:00 -04006187/**
James Smart3621a712009-04-06 18:47:14 -04006188 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04006189 * @shost: kernel scsi host pointer.
6190 *
6191 * Notes:
6192 * NULL on error for link down, no mbox pool, sli2 active,
6193 * management not allowed, memory allocation error, or mbox error.
6194 *
6195 * Returns:
6196 * NULL for error
6197 * address of the adapter host statistics
6198 **/
dea31012005-04-17 16:05:31 -05006199static struct fc_host_statistics *
6200lpfc_get_stats(struct Scsi_Host *shost)
6201{
James Smart2e0fef82007-06-17 19:56:36 -05006202 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6203 struct lpfc_hba *phba = vport->phba;
6204 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04006205 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04006206 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05006207 LPFC_MBOXQ_t *pmboxq;
6208 MAILBOX_t *pmb;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04006209 int rc = 0;
dea31012005-04-17 16:05:31 -05006210
James Smart92d7f7b2007-06-17 19:56:38 -05006211 /*
6212 * prevent udev from issuing mailbox commands until the port is
6213 * configured.
6214 */
James Smart2e0fef82007-06-17 19:56:36 -05006215 if (phba->link_state < LPFC_LINK_DOWN ||
6216 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04006217 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05006218 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05006219
6220 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04006221 return NULL;
6222
dea31012005-04-17 16:05:31 -05006223 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6224 if (!pmboxq)
6225 return NULL;
6226 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6227
James Smart04c68492009-05-22 14:52:52 -04006228 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05006229 pmb->mbxCommand = MBX_READ_STATUS;
6230 pmb->mbxOwner = OWN_HOST;
James Smart3e1f0712018-11-29 16:09:29 -08006231 pmboxq->ctx_buf = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006232 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05006233
James Smart75baf692010-06-08 18:31:21 -04006234 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05006235 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04006236 else
dea31012005-04-17 16:05:31 -05006237 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6238
6239 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05006240 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04006241 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05006242 return NULL;
6243 }
6244
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04006245 memset(hs, 0, sizeof (struct fc_host_statistics));
6246
dea31012005-04-17 16:05:31 -05006247 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04006248 /*
6249 * The MBX_READ_STATUS returns tx_k_bytes which has to
6250 * converted to words
6251 */
6252 hs->tx_words = (uint64_t)
6253 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
6254 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05006255 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04006256 hs->rx_words = (uint64_t)
6257 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
6258 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05006259
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04006260 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05006261 pmb->mbxCommand = MBX_READ_LNK_STAT;
6262 pmb->mbxOwner = OWN_HOST;
James Smart3e1f0712018-11-29 16:09:29 -08006263 pmboxq->ctx_buf = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006264 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05006265
James Smart75baf692010-06-08 18:31:21 -04006266 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05006267 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04006268 else
dea31012005-04-17 16:05:31 -05006269 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6270
6271 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05006272 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05006273 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05006274 return NULL;
6275 }
6276
6277 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6278 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6279 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6280 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6281 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6282 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6283 hs->error_frames = pmb->un.varRdLnk.crcCnt;
6284
James Smart64ba8812006-08-02 15:24:34 -04006285 hs->link_failure_count -= lso->link_failure_count;
6286 hs->loss_of_sync_count -= lso->loss_of_sync_count;
6287 hs->loss_of_signal_count -= lso->loss_of_signal_count;
6288 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
6289 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
6290 hs->invalid_crc_count -= lso->invalid_crc_count;
6291 hs->error_frames -= lso->error_frames;
6292
James Smart76a95d72010-11-20 23:11:48 -05006293 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04006294 hs->lip_count = -1;
6295 hs->nos_count = (phba->link_events >> 1);
6296 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05006297 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05006298 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04006299 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05006300 hs->nos_count = -1;
6301 } else {
6302 hs->lip_count = -1;
6303 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04006304 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05006305 }
6306
6307 hs->dumped_frames = -1;
6308
Arnd Bergmannc4d6204d2018-06-18 17:28:23 +02006309 hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;
dea31012005-04-17 16:05:31 -05006310
James Smart1dcb58e2007-04-25 09:51:30 -04006311 mempool_free(pmboxq, phba->mbox_mem_pool);
6312
dea31012005-04-17 16:05:31 -05006313 return hs;
6314}
6315
James Smarte59058c2008-08-24 21:49:00 -04006316/**
James Smart3621a712009-04-06 18:47:14 -04006317 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04006318 * @shost: kernel scsi host pointer.
6319 **/
James Smart64ba8812006-08-02 15:24:34 -04006320static void
6321lpfc_reset_stats(struct Scsi_Host *shost)
6322{
James Smart2e0fef82007-06-17 19:56:36 -05006323 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6324 struct lpfc_hba *phba = vport->phba;
6325 struct lpfc_sli *psli = &phba->sli;
6326 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04006327 LPFC_MBOXQ_t *pmboxq;
6328 MAILBOX_t *pmb;
6329 int rc = 0;
6330
James Smart2e0fef82007-06-17 19:56:36 -05006331 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04006332 return;
6333
James Smart64ba8812006-08-02 15:24:34 -04006334 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6335 if (!pmboxq)
6336 return;
6337 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6338
James Smart04c68492009-05-22 14:52:52 -04006339 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04006340 pmb->mbxCommand = MBX_READ_STATUS;
6341 pmb->mbxOwner = OWN_HOST;
6342 pmb->un.varWords[0] = 0x1; /* reset request */
James Smart3e1f0712018-11-29 16:09:29 -08006343 pmboxq->ctx_buf = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006344 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04006345
James Smart2e0fef82007-06-17 19:56:36 -05006346 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04006347 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04006348 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6349 else
6350 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6351
6352 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05006353 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04006354 mempool_free(pmboxq, phba->mbox_mem_pool);
6355 return;
6356 }
6357
6358 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6359 pmb->mbxCommand = MBX_READ_LNK_STAT;
6360 pmb->mbxOwner = OWN_HOST;
James Smart3e1f0712018-11-29 16:09:29 -08006361 pmboxq->ctx_buf = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006362 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04006363
James Smart2e0fef82007-06-17 19:56:36 -05006364 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04006365 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04006366 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6367 else
6368 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6369
6370 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05006371 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04006372 mempool_free( pmboxq, phba->mbox_mem_pool);
6373 return;
6374 }
6375
6376 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6377 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6378 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6379 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6380 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6381 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6382 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05006383 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04006384 lso->link_events = (phba->link_events >> 1);
6385 else
6386 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04006387
Arnd Bergmannc4d6204d2018-06-18 17:28:23 +02006388 psli->stats_start = ktime_get_seconds();
James Smart64ba8812006-08-02 15:24:34 -04006389
James Smart1dcb58e2007-04-25 09:51:30 -04006390 mempool_free(pmboxq, phba->mbox_mem_pool);
6391
James Smart64ba8812006-08-02 15:24:34 -04006392 return;
6393}
dea31012005-04-17 16:05:31 -05006394
6395/*
6396 * The LPFC driver treats linkdown handling as target loss events so there
6397 * are no sysfs handlers for link_down_tmo.
6398 */
James Smart685f0bf2007-04-25 09:53:08 -04006399
James Smarte59058c2008-08-24 21:49:00 -04006400/**
James Smart3621a712009-04-06 18:47:14 -04006401 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04006402 * @starget: kernel scsi target pointer.
6403 *
6404 * Returns:
6405 * address of the node list if found
6406 * NULL target not found
6407 **/
James Smart685f0bf2007-04-25 09:53:08 -04006408static struct lpfc_nodelist *
6409lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05006410{
James Smart2e0fef82007-06-17 19:56:36 -05006411 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
6412 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04006413 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006414
6415 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04006416 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05006417 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05006418 if (NLP_CHK_NODE_ACT(ndlp) &&
6419 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04006420 starget->id == ndlp->nlp_sid) {
6421 spin_unlock_irq(shost->host_lock);
6422 return ndlp;
dea31012005-04-17 16:05:31 -05006423 }
6424 }
6425 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04006426 return NULL;
6427}
dea31012005-04-17 16:05:31 -05006428
James Smarte59058c2008-08-24 21:49:00 -04006429/**
James Smart3621a712009-04-06 18:47:14 -04006430 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04006431 * @starget: kernel scsi target pointer.
6432 **/
James Smart685f0bf2007-04-25 09:53:08 -04006433static void
6434lpfc_get_starget_port_id(struct scsi_target *starget)
6435{
6436 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6437
6438 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05006439}
6440
James Smarte59058c2008-08-24 21:49:00 -04006441/**
James Smart3621a712009-04-06 18:47:14 -04006442 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04006443 * @starget: kernel scsi target pointer.
6444 *
6445 * Description: Set the target node name to the ndlp node name wwn or zero.
6446 **/
dea31012005-04-17 16:05:31 -05006447static void
6448lpfc_get_starget_node_name(struct scsi_target *starget)
6449{
James Smart685f0bf2007-04-25 09:53:08 -04006450 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05006451
James Smart685f0bf2007-04-25 09:53:08 -04006452 fc_starget_node_name(starget) =
6453 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05006454}
6455
James Smarte59058c2008-08-24 21:49:00 -04006456/**
James Smart3621a712009-04-06 18:47:14 -04006457 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04006458 * @starget: kernel scsi target pointer.
6459 *
6460 * Description: set the target port name to the ndlp port name wwn or zero.
6461 **/
dea31012005-04-17 16:05:31 -05006462static void
6463lpfc_get_starget_port_name(struct scsi_target *starget)
6464{
James Smart685f0bf2007-04-25 09:53:08 -04006465 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05006466
James Smart685f0bf2007-04-25 09:53:08 -04006467 fc_starget_port_name(starget) =
6468 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05006469}
6470
James Smarte59058c2008-08-24 21:49:00 -04006471/**
James Smart3621a712009-04-06 18:47:14 -04006472 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04006473 * @rport: fc rport address.
6474 * @timeout: new value for dev loss tmo.
6475 *
6476 * Description:
6477 * If timeout is non zero set the dev_loss_tmo to timeout, else set
6478 * dev_loss_tmo to one.
6479 **/
dea31012005-04-17 16:05:31 -05006480static void
dea31012005-04-17 16:05:31 -05006481lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6482{
dea31012005-04-17 16:05:31 -05006483 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04006484 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05006485 else
James Smartc01f3202006-08-18 17:47:08 -04006486 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05006487}
6488
James Smarte59058c2008-08-24 21:49:00 -04006489/**
James Smart3621a712009-04-06 18:47:14 -04006490 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04006491 *
6492 * Description:
6493 * Macro that uses field to generate a function with the name lpfc_show_rport_
6494 *
6495 * lpfc_show_rport_##field: returns the bytes formatted in buf
6496 * @cdev: class converted to an fc_rport.
6497 * @buf: on return contains the target_field or zero.
6498 *
6499 * Returns: size of formatted string.
6500 **/
dea31012005-04-17 16:05:31 -05006501#define lpfc_rport_show_function(field, format_string, sz, cast) \
6502static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01006503lpfc_show_rport_##field (struct device *dev, \
6504 struct device_attribute *attr, \
6505 char *buf) \
dea31012005-04-17 16:05:31 -05006506{ \
Tony Jonesee959b02008-02-22 00:13:36 +01006507 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05006508 struct lpfc_rport_data *rdata = rport->hostdata; \
6509 return snprintf(buf, sz, format_string, \
6510 (rdata->target) ? cast rdata->target->field : 0); \
6511}
6512
6513#define lpfc_rport_rd_attr(field, format_string, sz) \
6514 lpfc_rport_show_function(field, format_string, sz, ) \
6515static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6516
James Smarteada2722008-12-04 22:39:13 -05006517/**
James Smart3621a712009-04-06 18:47:14 -04006518 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05006519 * @fc_vport: The fc_vport who's symbolic name has been changed.
6520 *
6521 * Description:
6522 * This function is called by the transport after the @fc_vport's symbolic name
6523 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006524 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05006525 **/
6526static void
6527lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6528{
6529 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6530
6531 if (vport->port_state == LPFC_VPORT_READY)
6532 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6533}
dea31012005-04-17 16:05:31 -05006534
James Smartf4b4c682009-05-22 14:53:12 -04006535/**
6536 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6537 * @phba: Pointer to lpfc_hba struct.
6538 *
6539 * This function is called by the lpfc_get_cfgparam() routine to set the
6540 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02006541 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04006542 * before hba port or vport created.
6543 **/
6544static void
6545lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6546{
6547 phba->cfg_log_verbose = verbose;
6548}
6549
dea31012005-04-17 16:05:31 -05006550struct fc_function_template lpfc_transport_functions = {
6551 /* fixed attributes the driver supports */
6552 .show_host_node_name = 1,
6553 .show_host_port_name = 1,
6554 .show_host_supported_classes = 1,
6555 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05006556 .show_host_supported_speeds = 1,
6557 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006558
6559 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006560 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05006561
6562 /* dynamic attributes the driver supports */
6563 .get_host_port_id = lpfc_get_host_port_id,
6564 .show_host_port_id = 1,
6565
6566 .get_host_port_type = lpfc_get_host_port_type,
6567 .show_host_port_type = 1,
6568
6569 .get_host_port_state = lpfc_get_host_port_state,
6570 .show_host_port_state = 1,
6571
6572 /* active_fc4s is shown but doesn't change (thus no get function) */
6573 .show_host_active_fc4s = 1,
6574
6575 .get_host_speed = lpfc_get_host_speed,
6576 .show_host_speed = 1,
6577
6578 .get_host_fabric_name = lpfc_get_host_fabric_name,
6579 .show_host_fabric_name = 1,
6580
6581 /*
6582 * The LPFC driver treats linkdown handling as target loss events
6583 * so there are no sysfs handlers for link_down_tmo.
6584 */
6585
6586 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04006587 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05006588
6589 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6590 .show_rport_maxframe_size = 1,
6591 .show_rport_supported_classes = 1,
6592
dea31012005-04-17 16:05:31 -05006593 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6594 .show_rport_dev_loss_tmo = 1,
6595
6596 .get_starget_port_id = lpfc_get_starget_port_id,
6597 .show_starget_port_id = 1,
6598
6599 .get_starget_node_name = lpfc_get_starget_node_name,
6600 .show_starget_node_name = 1,
6601
6602 .get_starget_port_name = lpfc_get_starget_port_name,
6603 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07006604
6605 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04006606 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6607 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05006608
James Smart92d7f7b2007-06-17 19:56:38 -05006609 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05006610
6611 .vport_disable = lpfc_vport_disable,
6612
6613 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04006614
6615 .bsg_request = lpfc_bsg_request,
6616 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05006617};
6618
James Smart98c9ea52007-10-27 13:37:33 -04006619struct fc_function_template lpfc_vport_transport_functions = {
6620 /* fixed attributes the driver supports */
6621 .show_host_node_name = 1,
6622 .show_host_port_name = 1,
6623 .show_host_supported_classes = 1,
6624 .show_host_supported_fc4s = 1,
6625 .show_host_supported_speeds = 1,
6626 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006627
6628 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006629 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04006630
6631 /* dynamic attributes the driver supports */
6632 .get_host_port_id = lpfc_get_host_port_id,
6633 .show_host_port_id = 1,
6634
6635 .get_host_port_type = lpfc_get_host_port_type,
6636 .show_host_port_type = 1,
6637
6638 .get_host_port_state = lpfc_get_host_port_state,
6639 .show_host_port_state = 1,
6640
6641 /* active_fc4s is shown but doesn't change (thus no get function) */
6642 .show_host_active_fc4s = 1,
6643
6644 .get_host_speed = lpfc_get_host_speed,
6645 .show_host_speed = 1,
6646
6647 .get_host_fabric_name = lpfc_get_host_fabric_name,
6648 .show_host_fabric_name = 1,
6649
6650 /*
6651 * The LPFC driver treats linkdown handling as target loss events
6652 * so there are no sysfs handlers for link_down_tmo.
6653 */
6654
6655 .get_fc_host_stats = lpfc_get_stats,
6656 .reset_fc_host_stats = lpfc_reset_stats,
6657
6658 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6659 .show_rport_maxframe_size = 1,
6660 .show_rport_supported_classes = 1,
6661
6662 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6663 .show_rport_dev_loss_tmo = 1,
6664
6665 .get_starget_port_id = lpfc_get_starget_port_id,
6666 .show_starget_port_id = 1,
6667
6668 .get_starget_node_name = lpfc_get_starget_node_name,
6669 .show_starget_node_name = 1,
6670
6671 .get_starget_port_name = lpfc_get_starget_port_name,
6672 .show_starget_port_name = 1,
6673
6674 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6675 .terminate_rport_io = lpfc_terminate_rport_io,
6676
6677 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05006678
6679 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04006680};
6681
James Smarte59058c2008-08-24 21:49:00 -04006682/**
James Smart3621a712009-04-06 18:47:14 -04006683 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04006684 * @phba: lpfc_hba pointer.
6685 **/
dea31012005-04-17 16:05:31 -05006686void
6687lpfc_get_cfgparam(struct lpfc_hba *phba)
6688{
James Smart49aa1432012-08-03 12:36:42 -04006689 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smart7ea92eb2018-10-23 13:41:10 -07006690 lpfc_ns_query_init(phba, lpfc_ns_query);
James Smarta6571c62012-10-31 14:44:42 -04006691 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006692 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6693 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05006694 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05006695 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6696 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006697 lpfc_ack0_init(phba, lpfc_ack0);
6698 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006699 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05006700 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04006701 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04006702 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04006703 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05006704 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4258e982015-12-16 18:11:58 -05006705 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6706 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
James Smart4ff43242006-12-02 13:34:56 -05006707 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart895427b2017-02-12 13:52:30 -08006708 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
James Smart4e565cf2018-02-22 08:18:50 -08006709 lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);
James Smart0cf07f842017-06-01 21:07:10 -07006710 lpfc_auto_imax_init(phba, lpfc_auto_imax);
James Smartda0436e2009-05-22 14:51:39 -04006711 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04006712 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart13815c82008-01-11 01:52:48 -05006713 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6714 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart2ea259e2017-02-12 13:52:27 -08006715
James Smart1ba981f2014-02-20 09:56:45 -05006716 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6717 if (phba->sli_rev != LPFC_SLI_REV4)
6718 phba->cfg_EnableXLane = 0;
6719 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
James Smart2ea259e2017-02-12 13:52:27 -08006720
James Smart1ba981f2014-02-20 09:56:45 -05006721 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6722 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6723 phba->cfg_oas_lun_state = 0;
6724 phba->cfg_oas_lun_status = 0;
6725 phba->cfg_oas_flags = 0;
James Smartc92c8412016-07-06 12:36:05 -07006726 phba->cfg_oas_priority = 0;
James Smart81301a92008-12-04 22:39:46 -05006727 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smartb3b98b72016-10-13 15:06:06 -07006728 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6729 lpfc_prot_guard_init(phba, lpfc_prot_guard);
James Smart45ed1192009-10-02 15:17:02 -04006730 if (phba->sli_rev == LPFC_SLI_REV4)
6731 phba->cfg_poll = 0;
6732 else
James Smart1ba981f2014-02-20 09:56:45 -05006733 phba->cfg_poll = lpfc_poll;
James Smartf44ac122018-03-05 12:04:08 -08006734
6735 if (phba->cfg_enable_bg)
6736 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
6737
James Smartf358dd02017-02-12 13:52:34 -08006738 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
James Smart4258e982015-12-16 18:11:58 -05006739
James Smart895427b2017-02-12 13:52:30 -08006740 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
James Smart2d7dbc42017-02-12 13:52:35 -08006741 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
James Smart2448e482018-04-09 14:24:24 -07006742 lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
James Smart895427b2017-02-12 13:52:30 -08006743
6744 /* Initialize first burst. Target vs Initiator are different. */
6745 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
James Smart2d7dbc42017-02-12 13:52:35 -08006746 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
James Smart895427b2017-02-12 13:52:30 -08006747 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6748 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
James Smart44fd7fe2017-08-23 16:55:47 -07006749 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
James Smart1351e692018-02-22 08:18:43 -08006750 lpfc_enable_dpp_init(phba, lpfc_enable_dpp);
James Smart895427b2017-02-12 13:52:30 -08006751
6752 if (phba->sli_rev != LPFC_SLI_REV4) {
6753 /* NVME only supported on SLI4 */
6754 phba->nvmet_support = 0;
6755 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
James Smart44fd7fe2017-08-23 16:55:47 -07006756 phba->cfg_enable_bbcr = 0;
James Smart895427b2017-02-12 13:52:30 -08006757 } else {
6758 /* We MUST have FCP support */
6759 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6760 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6761 }
6762
James Smart0cf07f842017-06-01 21:07:10 -07006763 if (phba->cfg_auto_imax && !phba->cfg_fcp_imax)
6764 phba->cfg_auto_imax = 0;
6765 phba->initial_imax = phba->cfg_fcp_imax;
6766
James Smart06b6fa382018-07-31 17:23:24 -07006767 phba->cfg_enable_pbde = 0;
6768
James Smart895427b2017-02-12 13:52:30 -08006769 /* A value of 0 means use the number of CPUs found in the system */
James Smart895427b2017-02-12 13:52:30 -08006770 if (phba->cfg_fcp_io_channel == 0)
6771 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006772 if (phba->cfg_nvme_io_channel == 0)
6773 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smart895427b2017-02-12 13:52:30 -08006774
6775 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6776 phba->cfg_fcp_io_channel = 0;
6777
James Smartf358dd02017-02-12 13:52:34 -08006778 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6779 phba->cfg_nvme_io_channel = 0;
6780
James Smart895427b2017-02-12 13:52:30 -08006781 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6782 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6783 else
6784 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
James Smart4258e982015-12-16 18:11:58 -05006785
James Smart352e5fd2016-12-30 06:57:47 -08006786 phba->cfg_soft_wwnn = 0L;
6787 phba->cfg_soft_wwpn = 0L;
James Smart895427b2017-02-12 13:52:30 -08006788 lpfc_xri_split_init(phba, lpfc_xri_split);
James Smart83108bd2008-01-11 01:53:09 -05006789 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04006790 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04006791 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04006792 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04006793 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04006794 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05006795 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04006796 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart8eb8b962016-07-06 12:36:08 -07006797 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
James Smart12247e82016-07-06 12:36:09 -07006798 lpfc_sli_mode_init(phba, lpfc_sli_mode);
James Smartab56dc22011-02-16 12:39:57 -05006799 phba->cfg_enable_dss = 1;
James Smart7bdedb32016-07-06 12:36:00 -07006800 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
James Smartd2cc9bc2018-09-10 10:30:50 -07006801 lpfc_ras_fwlog_buffsize_init(phba, lpfc_ras_fwlog_buffsize);
6802 lpfc_ras_fwlog_level_init(phba, lpfc_ras_fwlog_level);
6803 lpfc_ras_fwlog_func_init(phba, lpfc_ras_fwlog_func);
6804
James Smartfaf0a5f2018-09-10 10:30:43 -07006805
6806 /* If the NVME FC4 type is enabled, scale the sg_seg_cnt to
6807 * accommodate 512K and 1M IOs in a single nvme buf and supply
6808 * enough NVME LS iocb buffers for larger connectivity counts.
6809 */
6810 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
6811 phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
6812 phba->cfg_iocb_cnt = 5;
6813 }
6814
James Smart3de2a652007-08-02 11:09:59 -04006815 return;
6816}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05006817
James Smarte59058c2008-08-24 21:49:00 -04006818/**
James Smart895427b2017-02-12 13:52:30 -08006819 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6820 * dependencies between protocols and roles.
6821 * @phba: lpfc_hba pointer.
6822 **/
6823void
6824lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6825{
James Smart895427b2017-02-12 13:52:30 -08006826 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6827 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006828
James Smart895427b2017-02-12 13:52:30 -08006829 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6830 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6831
James Smartf358dd02017-02-12 13:52:34 -08006832 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6833 phba->nvmet_support) {
6834 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6835 phba->cfg_fcp_io_channel = 0;
James Smart2d7dbc42017-02-12 13:52:35 -08006836
6837 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6838 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6839 "NVME Target PRLI ACC enable_fb ",
6840 phba->cfg_nvme_enable_fb,
6841 phba->cfg_nvmet_fb_size,
6842 LPFC_NVMET_FB_SZ_MAX);
6843
6844 if (phba->cfg_nvme_enable_fb == 0)
6845 phba->cfg_nvmet_fb_size = 0;
6846 else {
6847 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6848 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6849 }
6850
James Smartbcb24f62017-11-20 16:00:36 -08006851 if (!phba->cfg_nvmet_mrq)
6852 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6853
James Smart2d7dbc42017-02-12 13:52:35 -08006854 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6855 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6856 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6857 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6858 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6859 phba->cfg_nvmet_mrq);
6860 }
James Smartbcb24f62017-11-20 16:00:36 -08006861 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
6862 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
6863
James Smart2d7dbc42017-02-12 13:52:35 -08006864 } else {
James Smartf358dd02017-02-12 13:52:34 -08006865 /* Not NVME Target mode. Turn off Target parameters. */
6866 phba->nvmet_support = 0;
James Smartbcb24f62017-11-20 16:00:36 -08006867 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF;
James Smart2d7dbc42017-02-12 13:52:35 -08006868 phba->cfg_nvmet_fb_size = 0;
6869 }
James Smartf358dd02017-02-12 13:52:34 -08006870
James Smart895427b2017-02-12 13:52:30 -08006871 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6872 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6873 else
6874 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6875}
6876
6877/**
James Smart3621a712009-04-06 18:47:14 -04006878 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04006879 * @vport: lpfc_vport pointer.
6880 **/
James Smart3de2a652007-08-02 11:09:59 -04006881void
6882lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6883{
James Smarte8b62012007-08-02 11:10:09 -04006884 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04006885 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04006886 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04006887 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6888 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6889 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6890 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6891 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6892 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04006893 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04006894 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04006895 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6896 lpfc_max_luns_init(vport, lpfc_max_luns);
6897 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04006898 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05006899 return;
6900}