blob: 212bfae1966a817180616c468bd41adfdca95a24 [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 Smartf7a919b2011-08-21 21:49:16 -040067/*
68 * Write key size should be multiple of 4. If write key is changed
69 * make sure that library write key is also changed.
70 */
71#define LPFC_REG_WRITE_KEY_SIZE 4
72#define LPFC_REG_WRITE_KEY "EMLX"
73
James Smarte59058c2008-08-24 21:49:00 -040074/**
James Smart3621a712009-04-06 18:47:14 -040075 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040076 * @incr: integer to convert.
77 * @hdw: ascii string holding converted integer plus a string terminator.
78 *
79 * Description:
80 * JEDEC Joint Electron Device Engineering Council.
81 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
82 * character string. The string is then terminated with a NULL in byte 9.
83 * Hex 0-9 becomes ascii '0' to '9'.
84 * Hex a-f becomes ascii '=' to 'B' capital B.
85 *
86 * Notes:
87 * Coded for 32 bit integers only.
88 **/
dea31012005-04-17 16:05:31 -050089static void
90lpfc_jedec_to_ascii(int incr, char hdw[])
91{
92 int i, j;
93 for (i = 0; i < 8; i++) {
94 j = (incr & 0xf);
95 if (j <= 9)
96 hdw[7 - i] = 0x30 + j;
97 else
98 hdw[7 - i] = 0x61 + j - 10;
99 incr = (incr >> 4);
100 }
101 hdw[8] = 0;
102 return;
103}
104
James Smarte59058c2008-08-24 21:49:00 -0400105/**
James Smart3621a712009-04-06 18:47:14 -0400106 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -0400107 * @dev: class unused variable.
108 * @attr: device attribute, not used.
109 * @buf: on return contains the module description text.
110 *
111 * Returns: size of formatted string.
112 **/
dea31012005-04-17 16:05:31 -0500113static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100114lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
115 char *buf)
dea31012005-04-17 16:05:31 -0500116{
117 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
118}
119
James Smart45ed1192009-10-02 15:17:02 -0400120/**
121 * lpfc_enable_fip_show - Return the fip mode of the HBA
122 * @dev: class unused variable.
123 * @attr: device attribute, not used.
124 * @buf: on return contains the module description text.
125 *
126 * Returns: size of formatted string.
127 **/
128static ssize_t
129lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
130 char *buf)
131{
132 struct Scsi_Host *shost = class_to_shost(dev);
133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
134 struct lpfc_hba *phba = vport->phba;
135
136 if (phba->hba_flag & HBA_FIP_SUPPORT)
137 return snprintf(buf, PAGE_SIZE, "1\n");
138 else
139 return snprintf(buf, PAGE_SIZE, "0\n");
140}
141
James Smart81301a92008-12-04 22:39:46 -0500142static ssize_t
James Smart895427b2017-02-12 13:52:30 -0800143lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
144 char *buf)
145{
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = shost_priv(shost);
148 struct lpfc_hba *phba = vport->phba;
James Smartf358dd02017-02-12 13:52:34 -0800149 struct lpfc_nvmet_tgtport *tgtp;
James Smart895427b2017-02-12 13:52:30 -0800150 struct nvme_fc_local_port *localport;
James Smart4b056682017-12-08 17:18:10 -0800151 struct lpfc_nvme_lport *lport;
James Smart01466022018-04-09 14:24:27 -0700152 struct lpfc_nvme_rport *rport;
James Smart80cc0042017-06-01 21:06:56 -0700153 struct lpfc_nodelist *ndlp;
James Smart895427b2017-02-12 13:52:30 -0800154 struct nvme_fc_remote_port *nrport;
James Smart4c47efc2019-01-28 11:14:25 -0800155 struct lpfc_fc4_ctrl_stat *cstat;
James Smart66a210f2018-04-09 14:24:23 -0700156 uint64_t data1, data2, data3;
157 uint64_t totin, totout, tot;
James Smart895427b2017-02-12 13:52:30 -0800158 char *statep;
James Smart66a210f2018-04-09 14:24:23 -0700159 int i;
James Smart895427b2017-02-12 13:52:30 -0800160 int len = 0;
James Smartafff0d22018-06-26 08:24:22 -0700161 char tmp[LPFC_MAX_NVME_INFO_TMP_LEN] = {0};
James Smart895427b2017-02-12 13:52:30 -0800162
James Smartf6e84792019-01-28 11:14:38 -0800163 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
James Smartafff0d22018-06-26 08:24:22 -0700164 len = scnprintf(buf, PAGE_SIZE, "NVME Disabled\n");
James Smart895427b2017-02-12 13:52:30 -0800165 return len;
166 }
James Smartf358dd02017-02-12 13:52:34 -0800167 if (phba->nvmet_support) {
168 if (!phba->targetport) {
James Smartafff0d22018-06-26 08:24:22 -0700169 len = scnprintf(buf, PAGE_SIZE,
James Smartf358dd02017-02-12 13:52:34 -0800170 "NVME Target: x%llx is not allocated\n",
171 wwn_to_u64(vport->fc_portname.u.wwn));
172 return len;
173 }
174 /* Port state is only one of two values for now. */
175 if (phba->targetport->port_id)
176 statep = "REGISTERED";
177 else
178 statep = "INIT";
James Smartafff0d22018-06-26 08:24:22 -0700179 scnprintf(tmp, sizeof(tmp),
180 "NVME Target Enabled State %s\n",
181 statep);
182 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
183 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800184
James Smartafff0d22018-06-26 08:24:22 -0700185 scnprintf(tmp, sizeof(tmp),
186 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
187 "NVME Target: lpfc",
188 phba->brd_no,
189 wwn_to_u64(vport->fc_portname.u.wwn),
190 wwn_to_u64(vport->fc_nodename.u.wwn),
191 phba->targetport->port_id);
192 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
193 goto buffer_done;
194
195 if (strlcat(buf, "\nNVME Target: Statistics\n", PAGE_SIZE)
196 >= PAGE_SIZE)
197 goto buffer_done;
198
James Smartf358dd02017-02-12 13:52:34 -0800199 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
James Smartafff0d22018-06-26 08:24:22 -0700200 scnprintf(tmp, sizeof(tmp),
201 "LS: Rcv %08x Drop %08x Abort %08x\n",
202 atomic_read(&tgtp->rcv_ls_req_in),
203 atomic_read(&tgtp->rcv_ls_req_drop),
204 atomic_read(&tgtp->xmt_ls_abort));
205 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
206 goto buffer_done;
207
James Smartf358dd02017-02-12 13:52:34 -0800208 if (atomic_read(&tgtp->rcv_ls_req_in) !=
209 atomic_read(&tgtp->rcv_ls_req_out)) {
James Smartafff0d22018-06-26 08:24:22 -0700210 scnprintf(tmp, sizeof(tmp),
211 "Rcv LS: in %08x != out %08x\n",
212 atomic_read(&tgtp->rcv_ls_req_in),
213 atomic_read(&tgtp->rcv_ls_req_out));
214 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
215 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800216 }
217
James Smartafff0d22018-06-26 08:24:22 -0700218 scnprintf(tmp, sizeof(tmp),
219 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
220 atomic_read(&tgtp->xmt_ls_rsp),
221 atomic_read(&tgtp->xmt_ls_drop),
222 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
223 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
224 goto buffer_done;
James Smart4b056682017-12-08 17:18:10 -0800225
James Smartafff0d22018-06-26 08:24:22 -0700226 scnprintf(tmp, sizeof(tmp),
227 "LS: RSP Abort %08x xb %08x Err %08x\n",
228 atomic_read(&tgtp->xmt_ls_rsp_aborted),
229 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
230 atomic_read(&tgtp->xmt_ls_rsp_error));
231 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
232 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800233
James Smartafff0d22018-06-26 08:24:22 -0700234 scnprintf(tmp, sizeof(tmp),
235 "FCP: Rcv %08x Defer %08x Release %08x "
236 "Drop %08x\n",
237 atomic_read(&tgtp->rcv_fcp_cmd_in),
238 atomic_read(&tgtp->rcv_fcp_cmd_defer),
239 atomic_read(&tgtp->xmt_fcp_release),
240 atomic_read(&tgtp->rcv_fcp_cmd_drop));
241 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
242 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800243
244 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
245 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
James Smartafff0d22018-06-26 08:24:22 -0700246 scnprintf(tmp, sizeof(tmp),
247 "Rcv FCP: in %08x != out %08x\n",
248 atomic_read(&tgtp->rcv_fcp_cmd_in),
249 atomic_read(&tgtp->rcv_fcp_cmd_out));
250 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
251 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800252 }
253
James Smartafff0d22018-06-26 08:24:22 -0700254 scnprintf(tmp, sizeof(tmp),
255 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
256 "drop %08x\n",
257 atomic_read(&tgtp->xmt_fcp_read),
258 atomic_read(&tgtp->xmt_fcp_read_rsp),
259 atomic_read(&tgtp->xmt_fcp_write),
260 atomic_read(&tgtp->xmt_fcp_rsp),
261 atomic_read(&tgtp->xmt_fcp_drop));
262 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
263 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800264
James Smartafff0d22018-06-26 08:24:22 -0700265 scnprintf(tmp, sizeof(tmp),
266 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
267 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
268 atomic_read(&tgtp->xmt_fcp_rsp_error),
269 atomic_read(&tgtp->xmt_fcp_rsp_drop));
270 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
271 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800272
James Smartafff0d22018-06-26 08:24:22 -0700273 scnprintf(tmp, sizeof(tmp),
274 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
275 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
276 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
277 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
278 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
279 goto buffer_done;
James Smart4b056682017-12-08 17:18:10 -0800280
James Smartafff0d22018-06-26 08:24:22 -0700281 scnprintf(tmp, sizeof(tmp),
282 "ABORT: Xmt %08x Cmpl %08x\n",
283 atomic_read(&tgtp->xmt_fcp_abort),
284 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
285 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
286 goto buffer_done;
James Smart547077a2017-05-15 15:20:40 -0700287
James Smartafff0d22018-06-26 08:24:22 -0700288 scnprintf(tmp, sizeof(tmp),
289 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x\n",
290 atomic_read(&tgtp->xmt_abort_sol),
291 atomic_read(&tgtp->xmt_abort_unsol),
292 atomic_read(&tgtp->xmt_abort_rsp),
293 atomic_read(&tgtp->xmt_abort_rsp_error));
294 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
295 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800296
James Smartafff0d22018-06-26 08:24:22 -0700297 scnprintf(tmp, sizeof(tmp),
298 "DELAY: ctx %08x fod %08x wqfull %08x\n",
299 atomic_read(&tgtp->defer_ctx),
300 atomic_read(&tgtp->defer_fod),
301 atomic_read(&tgtp->defer_wqfull));
302 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
303 goto buffer_done;
James Smart411de512018-01-30 15:58:52 -0800304
Dick Kennedy66d7ce92017-08-23 16:55:42 -0700305 /* Calculate outstanding IOs */
306 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
307 tot += atomic_read(&tgtp->xmt_fcp_release);
308 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
James Smart2cee7802017-06-01 21:07:02 -0700309
James Smartafff0d22018-06-26 08:24:22 -0700310 scnprintf(tmp, sizeof(tmp),
311 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
312 "CTX Outstanding %08llx\n\n",
313 phba->sli4_hba.nvmet_xri_cnt,
314 phba->sli4_hba.nvmet_io_wait_cnt,
315 phba->sli4_hba.nvmet_io_wait_total,
316 tot);
317 strlcat(buf, tmp, PAGE_SIZE);
318 goto buffer_done;
James Smartf358dd02017-02-12 13:52:34 -0800319 }
James Smart895427b2017-02-12 13:52:30 -0800320
321 localport = vport->localport;
322 if (!localport) {
James Smartafff0d22018-06-26 08:24:22 -0700323 len = scnprintf(buf, PAGE_SIZE,
James Smart895427b2017-02-12 13:52:30 -0800324 "NVME Initiator x%llx is not allocated\n",
325 wwn_to_u64(vport->fc_portname.u.wwn));
326 return len;
327 }
Colin Ian King5c665ae2017-12-22 00:28:52 +0000328 lport = (struct lpfc_nvme_lport *)localport->private;
James Smartafff0d22018-06-26 08:24:22 -0700329 if (strlcat(buf, "\nNVME Initiator Enabled\n", PAGE_SIZE) >= PAGE_SIZE)
330 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800331
James Smartafff0d22018-06-26 08:24:22 -0700332 rcu_read_lock();
333 scnprintf(tmp, sizeof(tmp),
James Smart0794d602019-01-28 11:14:19 -0800334 "XRI Dist lpfc%d Total %d IO %d ELS %d\n",
James Smartafff0d22018-06-26 08:24:22 -0700335 phba->brd_no,
336 phba->sli4_hba.max_cfg_param.max_xri,
James Smart5e5b5112019-01-28 11:14:22 -0800337 phba->sli4_hba.io_xri_max,
James Smartafff0d22018-06-26 08:24:22 -0700338 lpfc_sli4_get_els_iocb_cnt(phba));
339 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
340 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800341
342 /* Port state is only one of two values for now. */
343 if (localport->port_id)
344 statep = "ONLINE";
345 else
346 statep = "UNKNOWN ";
347
James Smartafff0d22018-06-26 08:24:22 -0700348 scnprintf(tmp, sizeof(tmp),
349 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
350 "NVME LPORT lpfc",
351 phba->brd_no,
352 wwn_to_u64(vport->fc_portname.u.wwn),
353 wwn_to_u64(vport->fc_nodename.u.wwn),
354 localport->port_id, statep);
355 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
356 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800357
James Smart80cc0042017-06-01 21:06:56 -0700358 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart9e210172018-09-13 15:41:10 -0700359 nrport = NULL;
360 spin_lock(&vport->phba->hbalock);
James Smart01466022018-04-09 14:24:27 -0700361 rport = lpfc_ndlp_get_nrport(ndlp);
James Smart9e210172018-09-13 15:41:10 -0700362 if (rport)
363 nrport = rport->remoteport;
364 spin_unlock(&vport->phba->hbalock);
James Smart01466022018-04-09 14:24:27 -0700365 if (!nrport)
366 continue;
James Smart895427b2017-02-12 13:52:30 -0800367
368 /* Port state is only one of two values for now. */
369 switch (nrport->port_state) {
370 case FC_OBJSTATE_ONLINE:
371 statep = "ONLINE";
372 break;
373 case FC_OBJSTATE_UNKNOWN:
374 statep = "UNKNOWN ";
375 break;
376 default:
377 statep = "UNSUPPORTED";
378 break;
379 }
380
381 /* Tab in to show lport ownership. */
James Smartafff0d22018-06-26 08:24:22 -0700382 if (strlcat(buf, "NVME RPORT ", PAGE_SIZE) >= PAGE_SIZE)
383 goto buffer_done;
384 if (phba->brd_no >= 10) {
385 if (strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
386 goto buffer_done;
387 }
James Smart895427b2017-02-12 13:52:30 -0800388
James Smartafff0d22018-06-26 08:24:22 -0700389 scnprintf(tmp, sizeof(tmp), "WWPN x%llx ",
390 nrport->port_name);
391 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
392 goto buffer_done;
393
394 scnprintf(tmp, sizeof(tmp), "WWNN x%llx ",
395 nrport->node_name);
396 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
397 goto buffer_done;
398
399 scnprintf(tmp, sizeof(tmp), "DID x%06x ",
400 nrport->port_id);
401 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
402 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800403
James Smart7d790f02017-06-01 21:06:57 -0700404 /* An NVME rport can have multiple roles. */
James Smartafff0d22018-06-26 08:24:22 -0700405 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR) {
406 if (strlcat(buf, "INITIATOR ", PAGE_SIZE) >= PAGE_SIZE)
407 goto buffer_done;
408 }
409 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET) {
410 if (strlcat(buf, "TARGET ", PAGE_SIZE) >= PAGE_SIZE)
411 goto buffer_done;
412 }
413 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY) {
414 if (strlcat(buf, "DISCSRVC ", PAGE_SIZE) >= PAGE_SIZE)
415 goto buffer_done;
416 }
James Smart7d790f02017-06-01 21:06:57 -0700417 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
418 FC_PORT_ROLE_NVME_TARGET |
James Smartafff0d22018-06-26 08:24:22 -0700419 FC_PORT_ROLE_NVME_DISCOVERY)) {
420 scnprintf(tmp, sizeof(tmp), "UNKNOWN ROLE x%x",
421 nrport->port_role);
422 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
423 goto buffer_done;
424 }
James Smart7d790f02017-06-01 21:06:57 -0700425
James Smartafff0d22018-06-26 08:24:22 -0700426 scnprintf(tmp, sizeof(tmp), "%s\n", statep);
427 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
428 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800429 }
James Smartafff0d22018-06-26 08:24:22 -0700430 rcu_read_unlock();
James Smart895427b2017-02-12 13:52:30 -0800431
James Smart66a210f2018-04-09 14:24:23 -0700432 if (!lport)
James Smartafff0d22018-06-26 08:24:22 -0700433 goto buffer_done;
James Smart66a210f2018-04-09 14:24:23 -0700434
James Smartafff0d22018-06-26 08:24:22 -0700435 if (strlcat(buf, "\nNVME Statistics\n", PAGE_SIZE) >= PAGE_SIZE)
436 goto buffer_done;
James Smart4b056682017-12-08 17:18:10 -0800437
James Smartafff0d22018-06-26 08:24:22 -0700438 scnprintf(tmp, sizeof(tmp),
439 "LS: Xmt %010x Cmpl %010x Abort %08x\n",
440 atomic_read(&lport->fc4NvmeLsRequests),
441 atomic_read(&lport->fc4NvmeLsCmpls),
442 atomic_read(&lport->xmt_ls_abort));
443 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
444 goto buffer_done;
445
446 scnprintf(tmp, sizeof(tmp),
447 "LS XMIT: Err %08x CMPL: xb %08x Err %08x\n",
448 atomic_read(&lport->xmt_ls_err),
449 atomic_read(&lport->cmpl_ls_xb),
450 atomic_read(&lport->cmpl_ls_err));
451 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
452 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800453
James Smart66a210f2018-04-09 14:24:23 -0700454 totin = 0;
455 totout = 0;
James Smartcdb42be2019-01-28 11:14:21 -0800456 for (i = 0; i < phba->cfg_hdw_queue; i++) {
James Smart4c47efc2019-01-28 11:14:25 -0800457 cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;
458 tot = cstat->io_cmpls;
James Smart66a210f2018-04-09 14:24:23 -0700459 totin += tot;
James Smart4c47efc2019-01-28 11:14:25 -0800460 data1 = cstat->input_requests;
461 data2 = cstat->output_requests;
462 data3 = cstat->control_requests;
James Smart66a210f2018-04-09 14:24:23 -0700463 totout += (data1 + data2 + data3);
464 }
James Smartafff0d22018-06-26 08:24:22 -0700465 scnprintf(tmp, sizeof(tmp),
466 "Total FCP Cmpl %016llx Issue %016llx "
467 "OutIO %016llx\n",
468 totin, totout, totout - totin);
469 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
470 goto buffer_done;
James Smart895427b2017-02-12 13:52:30 -0800471
James Smartafff0d22018-06-26 08:24:22 -0700472 scnprintf(tmp, sizeof(tmp),
473 "\tabort %08x noxri %08x nondlp %08x qdepth %08x "
474 "wqerr %08x err %08x\n",
475 atomic_read(&lport->xmt_fcp_abort),
476 atomic_read(&lport->xmt_fcp_noxri),
477 atomic_read(&lport->xmt_fcp_bad_ndlp),
478 atomic_read(&lport->xmt_fcp_qdepth),
479 atomic_read(&lport->xmt_fcp_err),
480 atomic_read(&lport->xmt_fcp_wqerr));
481 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
482 goto buffer_done;
James Smart4b056682017-12-08 17:18:10 -0800483
James Smartafff0d22018-06-26 08:24:22 -0700484 scnprintf(tmp, sizeof(tmp),
485 "FCP CMPL: xb %08x Err %08x\n",
486 atomic_read(&lport->cmpl_fcp_xb),
487 atomic_read(&lport->cmpl_fcp_err));
488 strlcat(buf, tmp, PAGE_SIZE);
489
490buffer_done:
491 len = strnlen(buf, PAGE_SIZE);
492
493 if (unlikely(len >= (PAGE_SIZE - 1))) {
494 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
495 "6314 Catching potential buffer "
496 "overflow > PAGE_SIZE = %lu bytes\n",
497 PAGE_SIZE);
498 strlcpy(buf + PAGE_SIZE - 1 -
499 strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1),
500 LPFC_NVME_INFO_MORE_STR,
501 strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1)
502 + 1);
503 }
504
James Smart895427b2017-02-12 13:52:30 -0800505 return len;
506}
507
508static ssize_t
James Smart4c47efc2019-01-28 11:14:25 -0800509lpfc_scsi_stat_show(struct device *dev, struct device_attribute *attr,
510 char *buf)
511{
512 struct Scsi_Host *shost = class_to_shost(dev);
513 struct lpfc_vport *vport = shost_priv(shost);
514 struct lpfc_hba *phba = vport->phba;
515 int len;
516 struct lpfc_fc4_ctrl_stat *cstat;
517 u64 data1, data2, data3;
518 u64 tot, totin, totout;
519 int i;
520 char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
521
James Smartf6e84792019-01-28 11:14:38 -0800522 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||
James Smart4c47efc2019-01-28 11:14:25 -0800523 (phba->sli_rev != LPFC_SLI_REV4))
524 return 0;
525
526 scnprintf(buf, PAGE_SIZE, "SCSI HDWQ Statistics\n");
527
528 totin = 0;
529 totout = 0;
530 for (i = 0; i < phba->cfg_hdw_queue; i++) {
531 cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;
532 tot = cstat->io_cmpls;
533 totin += tot;
534 data1 = cstat->input_requests;
535 data2 = cstat->output_requests;
536 data3 = cstat->control_requests;
537 totout += (data1 + data2 + data3);
538
539 scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "
540 "IO %016llx ", i, data1, data2, data3);
541 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
542 goto buffer_done;
543
544 scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",
545 tot, ((data1 + data2 + data3) - tot));
546 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
547 goto buffer_done;
548 }
549 scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "
550 "OutIO %016llx\n", totin, totout, totout - totin);
551 strlcat(buf, tmp, PAGE_SIZE);
552
553buffer_done:
554 len = strnlen(buf, PAGE_SIZE);
555
556 return len;
557}
558
559static ssize_t
James Smart81301a92008-12-04 22:39:46 -0500560lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
561 char *buf)
562{
563 struct Scsi_Host *shost = class_to_shost(dev);
564 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
565 struct lpfc_hba *phba = vport->phba;
566
567 if (phba->cfg_enable_bg)
568 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
569 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
570 else
571 return snprintf(buf, PAGE_SIZE,
572 "BlockGuard Not Supported\n");
573 else
574 return snprintf(buf, PAGE_SIZE,
575 "BlockGuard Disabled\n");
576}
577
578static ssize_t
579lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
580 char *buf)
581{
582 struct Scsi_Host *shost = class_to_shost(dev);
583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
584 struct lpfc_hba *phba = vport->phba;
585
James Smart87b5c322008-12-16 10:34:09 -0500586 return snprintf(buf, PAGE_SIZE, "%llu\n",
587 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500588}
589
590static ssize_t
591lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
592 char *buf)
593{
594 struct Scsi_Host *shost = class_to_shost(dev);
595 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
596 struct lpfc_hba *phba = vport->phba;
597
James Smart87b5c322008-12-16 10:34:09 -0500598 return snprintf(buf, PAGE_SIZE, "%llu\n",
599 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500600}
601
602static ssize_t
603lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
604 char *buf)
605{
606 struct Scsi_Host *shost = class_to_shost(dev);
607 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
608 struct lpfc_hba *phba = vport->phba;
609
James Smart87b5c322008-12-16 10:34:09 -0500610 return snprintf(buf, PAGE_SIZE, "%llu\n",
611 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500612}
613
James Smarte59058c2008-08-24 21:49:00 -0400614/**
James Smart3621a712009-04-06 18:47:14 -0400615 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400616 * @dev: class converted to a Scsi_host structure.
617 * @attr: device attribute, not used.
618 * @buf: on return contains the formatted text from lpfc_info().
619 *
620 * Returns: size of formatted string.
621 **/
dea31012005-04-17 16:05:31 -0500622static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100623lpfc_info_show(struct device *dev, struct device_attribute *attr,
624 char *buf)
dea31012005-04-17 16:05:31 -0500625{
Tony Jonesee959b02008-02-22 00:13:36 +0100626 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500627
dea31012005-04-17 16:05:31 -0500628 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
629}
630
James Smarte59058c2008-08-24 21:49:00 -0400631/**
James Smart3621a712009-04-06 18:47:14 -0400632 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400633 * @dev: class converted to a Scsi_host structure.
634 * @attr: device attribute, not used.
635 * @buf: on return contains the formatted text serial number.
636 *
637 * Returns: size of formatted string.
638 **/
dea31012005-04-17 16:05:31 -0500639static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100640lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
641 char *buf)
dea31012005-04-17 16:05:31 -0500642{
Tony Jonesee959b02008-02-22 00:13:36 +0100643 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500644 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
645 struct lpfc_hba *phba = vport->phba;
646
dea31012005-04-17 16:05:31 -0500647 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
648}
649
James Smarte59058c2008-08-24 21:49:00 -0400650/**
James Smart3621a712009-04-06 18:47:14 -0400651 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400652 * @dev: class converted to a Scsi_host structure.
653 * @attr: device attribute, not used.
654 * @buf: on return contains the formatted support level.
655 *
656 * Description:
657 * Returns a number indicating the temperature sensor level currently
658 * supported, zero or one in ascii.
659 *
660 * Returns: size of formatted string.
661 **/
dea31012005-04-17 16:05:31 -0500662static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100663lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
664 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400665{
Tony Jonesee959b02008-02-22 00:13:36 +0100666 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400667 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
668 struct lpfc_hba *phba = vport->phba;
669 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
670}
671
James Smarte59058c2008-08-24 21:49:00 -0400672/**
James Smart3621a712009-04-06 18:47:14 -0400673 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400674 * @dev: class converted to a Scsi_host structure.
675 * @attr: device attribute, not used.
676 * @buf: on return contains the scsi vpd model description.
677 *
678 * Returns: size of formatted string.
679 **/
James Smart57127f12007-10-27 13:37:05 -0400680static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100681lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
682 char *buf)
dea31012005-04-17 16:05:31 -0500683{
Tony Jonesee959b02008-02-22 00:13:36 +0100684 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500685 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
686 struct lpfc_hba *phba = vport->phba;
687
dea31012005-04-17 16:05:31 -0500688 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
689}
690
James Smarte59058c2008-08-24 21:49:00 -0400691/**
James Smart3621a712009-04-06 18:47:14 -0400692 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400693 * @dev: class converted to a Scsi_host structure.
694 * @attr: device attribute, not used.
695 * @buf: on return contains the scsi vpd model name.
696 *
697 * Returns: size of formatted string.
698 **/
dea31012005-04-17 16:05:31 -0500699static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100700lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
701 char *buf)
dea31012005-04-17 16:05:31 -0500702{
Tony Jonesee959b02008-02-22 00:13:36 +0100703 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500704 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
705 struct lpfc_hba *phba = vport->phba;
706
dea31012005-04-17 16:05:31 -0500707 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
708}
709
James Smarte59058c2008-08-24 21:49:00 -0400710/**
James Smart3621a712009-04-06 18:47:14 -0400711 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400712 * @dev: class converted to a Scsi_host structure.
713 * @attr: device attribute, not used.
714 * @buf: on return contains the scsi vpd program type.
715 *
716 * Returns: size of formatted string.
717 **/
dea31012005-04-17 16:05:31 -0500718static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100719lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
720 char *buf)
dea31012005-04-17 16:05:31 -0500721{
Tony Jonesee959b02008-02-22 00:13:36 +0100722 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500723 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
724 struct lpfc_hba *phba = vport->phba;
725
dea31012005-04-17 16:05:31 -0500726 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
727}
728
James Smarte59058c2008-08-24 21:49:00 -0400729/**
James Smart3621a712009-04-06 18:47:14 -0400730 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400731 * @dev: class converted to a Scsi_host structure.
732 * @attr: device attribute, not used.
733 * @buf: on return contains the Menlo Maintenance sli flag.
734 *
735 * Returns: size of formatted string.
736 **/
737static ssize_t
738lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
739{
740 struct Scsi_Host *shost = class_to_shost(dev);
741 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
742 struct lpfc_hba *phba = vport->phba;
743
744 return snprintf(buf, PAGE_SIZE, "%d\n",
745 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
746}
747
748/**
James Smart3621a712009-04-06 18:47:14 -0400749 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400750 * @dev: class converted to a Scsi_host structure.
751 * @attr: device attribute, not used.
752 * @buf: on return contains scsi vpd program type.
753 *
754 * Returns: size of formatted string.
755 **/
dea31012005-04-17 16:05:31 -0500756static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100757lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
758 char *buf)
dea31012005-04-17 16:05:31 -0500759{
Tony Jonesee959b02008-02-22 00:13:36 +0100760 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500761 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
762 struct lpfc_hba *phba = vport->phba;
763
dea31012005-04-17 16:05:31 -0500764 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
765}
766
James Smarte59058c2008-08-24 21:49:00 -0400767/**
James Smart3621a712009-04-06 18:47:14 -0400768 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400769 * @dev: class converted to a Scsi_host structure.
770 * @attr: device attribute, not used.
771 * @buf: on return contains the scsi vpd program type.
772 *
773 * Returns: size of formatted string.
774 **/
dea31012005-04-17 16:05:31 -0500775static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100776lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
777 char *buf)
dea31012005-04-17 16:05:31 -0500778{
Tony Jonesee959b02008-02-22 00:13:36 +0100779 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500780 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
781 struct lpfc_hba *phba = vport->phba;
James Smart026abb82011-12-13 13:20:45 -0500782 uint32_t if_type;
783 uint8_t sli_family;
James Smart6b5151f2012-01-18 16:24:06 -0500784 char fwrev[FW_REV_STR_SIZE];
James Smart026abb82011-12-13 13:20:45 -0500785 int len;
James Smart2e0fef82007-06-17 19:56:36 -0500786
dea31012005-04-17 16:05:31 -0500787 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart026abb82011-12-13 13:20:45 -0500788 if_type = phba->sli4_hba.pc_sli4_params.if_type;
789 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
790
791 if (phba->sli_rev < LPFC_SLI_REV4)
792 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
793 fwrev, phba->sli_rev);
794 else
795 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
796 fwrev, phba->sli_rev, if_type, sli_family);
797
798 return len;
dea31012005-04-17 16:05:31 -0500799}
800
James Smarte59058c2008-08-24 21:49:00 -0400801/**
James Smart3621a712009-04-06 18:47:14 -0400802 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400803 * @dev: class converted to a Scsi_host structure.
804 * @attr: device attribute, not used.
805 * @buf: on return contains the scsi vpd program type.
806 *
807 * Returns: size of formatted string.
808 **/
dea31012005-04-17 16:05:31 -0500809static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100810lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500811{
812 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100813 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500814 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
815 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500816 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500817
dea31012005-04-17 16:05:31 -0500818 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
819 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
820}
James Smarte59058c2008-08-24 21:49:00 -0400821
822/**
James Smart3621a712009-04-06 18:47:14 -0400823 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400824 * @dev: class converted to a Scsi_host structure.
825 * @attr: device attribute, not used.
826 * @buf: on return contains the ROM and FCode ascii strings.
827 *
828 * Returns: size of formatted string.
829 **/
dea31012005-04-17 16:05:31 -0500830static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100831lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
832 char *buf)
dea31012005-04-17 16:05:31 -0500833{
Tony Jonesee959b02008-02-22 00:13:36 +0100834 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500835 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
836 struct lpfc_hba *phba = vport->phba;
James Smarta0683bf2015-04-07 15:07:16 -0400837 char fwrev[FW_REV_STR_SIZE];
James Smart2e0fef82007-06-17 19:56:36 -0500838
James Smarta0683bf2015-04-07 15:07:16 -0400839 if (phba->sli_rev < LPFC_SLI_REV4)
840 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
841
842 lpfc_decode_firmware_rev(phba, fwrev, 1);
843 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
dea31012005-04-17 16:05:31 -0500844}
James Smarte59058c2008-08-24 21:49:00 -0400845
846/**
James Smart3621a712009-04-06 18:47:14 -0400847 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400848 * @dev: class converted to a Scsi_host structure.
849 * @attr: device attribute, not used.
850 * @buf: on return contains text describing the state of the link.
851 *
852 * Notes:
853 * The switch statement has no default so zero will be returned.
854 *
855 * Returns: size of formatted string.
856 **/
dea31012005-04-17 16:05:31 -0500857static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100858lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
859 char *buf)
dea31012005-04-17 16:05:31 -0500860{
Tony Jonesee959b02008-02-22 00:13:36 +0100861 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500862 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
863 struct lpfc_hba *phba = vport->phba;
864 int len = 0;
865
866 switch (phba->link_state) {
867 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500868 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500869 case LPFC_INIT_START:
870 case LPFC_INIT_MBX_CMDS:
871 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500872 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400873 if (phba->hba_flag & LINK_DISABLED)
874 len += snprintf(buf + len, PAGE_SIZE-len,
875 "Link Down - User disabled\n");
876 else
877 len += snprintf(buf + len, PAGE_SIZE-len,
878 "Link Down\n");
dea31012005-04-17 16:05:31 -0500879 break;
880 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500881 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500882 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400883 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500884
885 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500886 case LPFC_LOCAL_CFG_LINK:
887 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500888 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500889 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500890 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500891 case LPFC_FLOGI:
892 case LPFC_FABRIC_CFG_LINK:
893 case LPFC_NS_REG:
894 case LPFC_NS_QRY:
895 case LPFC_BUILD_DISC_LIST:
896 case LPFC_DISC_AUTH:
897 len += snprintf(buf + len, PAGE_SIZE - len,
898 "Discovery\n");
899 break;
900 case LPFC_VPORT_READY:
901 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
902 break;
903
James Smart92d7f7b2007-06-17 19:56:38 -0500904 case LPFC_VPORT_FAILED:
905 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
906 break;
907
908 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500909 len += snprintf(buf + len, PAGE_SIZE - len,
910 "Unknown\n");
911 break;
912 }
James Smart84774a42008-08-24 21:50:06 -0400913 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
914 len += snprintf(buf + len, PAGE_SIZE-len,
915 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500916 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500917 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500918 len += snprintf(buf + len, PAGE_SIZE-len,
919 " Public Loop\n");
920 else
921 len += snprintf(buf + len, PAGE_SIZE-len,
922 " Private Loop\n");
923 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500924 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500925 len += snprintf(buf + len, PAGE_SIZE-len,
926 " Fabric\n");
927 else
928 len += snprintf(buf + len, PAGE_SIZE-len,
929 " Point-2-Point\n");
930 }
931 }
James Smart2e0fef82007-06-17 19:56:36 -0500932
James Smart1dc5ec22018-10-23 13:41:11 -0700933 if ((phba->sli_rev == LPFC_SLI_REV4) &&
934 ((bf_get(lpfc_sli_intf_if_type,
935 &phba->sli4_hba.sli_intf) ==
936 LPFC_SLI_INTF_IF_TYPE_6))) {
937 struct lpfc_trunk_link link = phba->trunk_link;
938
939 if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
940 len += snprintf(buf + len, PAGE_SIZE - len,
941 "Trunk port 0: Link %s %s\n",
942 (link.link0.state == LPFC_LINK_UP) ?
943 "Up" : "Down. ",
944 trunk_errmsg[link.link0.fault]);
945
946 if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
947 len += snprintf(buf + len, PAGE_SIZE - len,
948 "Trunk port 1: Link %s %s\n",
949 (link.link1.state == LPFC_LINK_UP) ?
950 "Up" : "Down. ",
951 trunk_errmsg[link.link1.fault]);
952
953 if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
954 len += snprintf(buf + len, PAGE_SIZE - len,
955 "Trunk port 2: Link %s %s\n",
956 (link.link2.state == LPFC_LINK_UP) ?
957 "Up" : "Down. ",
958 trunk_errmsg[link.link2.fault]);
959
960 if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
961 len += snprintf(buf + len, PAGE_SIZE - len,
962 "Trunk port 3: Link %s %s\n",
963 (link.link3.state == LPFC_LINK_UP) ?
964 "Up" : "Down. ",
965 trunk_errmsg[link.link3.fault]);
966
967 }
968
dea31012005-04-17 16:05:31 -0500969 return len;
970}
971
James Smarte59058c2008-08-24 21:49:00 -0400972/**
James Smart026abb82011-12-13 13:20:45 -0500973 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
974 * @dev: class unused variable.
975 * @attr: device attribute, not used.
976 * @buf: on return contains the module description text.
977 *
978 * Returns: size of formatted string.
979 **/
980static ssize_t
981lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
982 char *buf)
983{
984 struct Scsi_Host *shost = class_to_shost(dev);
985 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
986 struct lpfc_hba *phba = vport->phba;
987
988 if (phba->sli_rev < LPFC_SLI_REV4)
989 return snprintf(buf, PAGE_SIZE, "fc\n");
990
991 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
992 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
993 return snprintf(buf, PAGE_SIZE, "fcoe\n");
994 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
995 return snprintf(buf, PAGE_SIZE, "fc\n");
996 }
997 return snprintf(buf, PAGE_SIZE, "unknown\n");
998}
999
1000/**
James Smart1ba981f2014-02-20 09:56:45 -05001001 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
1002 * (OAS) is supported.
1003 * @dev: class unused variable.
1004 * @attr: device attribute, not used.
1005 * @buf: on return contains the module description text.
1006 *
1007 * Returns: size of formatted string.
1008 **/
1009static ssize_t
1010lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
1011 char *buf)
1012{
1013 struct Scsi_Host *shost = class_to_shost(dev);
1014 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
1015 struct lpfc_hba *phba = vport->phba;
1016
1017 return snprintf(buf, PAGE_SIZE, "%d\n",
1018 phba->sli4_hba.pc_sli4_params.oas_supported);
1019}
1020
1021/**
James Smart84d1b002010-02-12 14:42:33 -05001022 * lpfc_link_state_store - Transition the link_state on an HBA port
1023 * @dev: class device that is converted into a Scsi_host.
1024 * @attr: device attribute, not used.
1025 * @buf: one or more lpfc_polling_flags values.
1026 * @count: not used.
1027 *
1028 * Returns:
1029 * -EINVAL if the buffer is not "up" or "down"
1030 * return from link state change function if non-zero
1031 * length of the buf on success
1032 **/
1033static ssize_t
1034lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
1035 const char *buf, size_t count)
1036{
1037 struct Scsi_Host *shost = class_to_shost(dev);
1038 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1039 struct lpfc_hba *phba = vport->phba;
1040
1041 int status = -EINVAL;
1042
1043 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
1044 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -04001045 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -05001046 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
1047 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -04001048 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -05001049
1050 if (status == 0)
1051 return strlen(buf);
1052 else
1053 return status;
1054}
1055
1056/**
James Smart3621a712009-04-06 18:47:14 -04001057 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -04001058 * @dev: class device that is converted into a Scsi_host.
1059 * @attr: device attribute, not used.
1060 * @buf: on return contains the sum of fc mapped and unmapped.
1061 *
1062 * Description:
1063 * Returns the ascii text number of the sum of the fc mapped and unmapped
1064 * vport counts.
1065 *
1066 * Returns: size of formatted string.
1067 **/
dea31012005-04-17 16:05:31 -05001068static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001069lpfc_num_discovered_ports_show(struct device *dev,
1070 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -05001071{
Tony Jonesee959b02008-02-22 00:13:36 +01001072 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001073 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1074
1075 return snprintf(buf, PAGE_SIZE, "%d\n",
1076 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -05001077}
1078
James Smarte59058c2008-08-24 21:49:00 -04001079/**
James Smart3621a712009-04-06 18:47:14 -04001080 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -04001081 * @shost: Scsi_Host pointer.
1082 *
1083 * Description:
1084 * Bring the link down gracefully then re-init the link. The firmware will
1085 * re-init the fiber channel interface as required. Does not issue a LIP.
1086 *
1087 * Returns:
1088 * -EPERM port offline or management commands are being blocked
1089 * -ENOMEM cannot allocate memory for the mailbox command
1090 * -EIO error sending the mailbox command
1091 * zero for success
1092 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001093static int
James Smart2e0fef82007-06-17 19:56:36 -05001094lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -05001095{
James Smart2e0fef82007-06-17 19:56:36 -05001096 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1097 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001098 LPFC_MBOXQ_t *pmboxq;
1099 int mbxstatus = MBXERR_ERROR;
1100
James Smart2289e952018-01-30 15:58:55 -08001101 /*
1102 * If the link is offline, disabled or BLOCK_MGMT_IO
1103 * it doesn't make any sense to allow issue_lip
1104 */
James Smart2e0fef82007-06-17 19:56:36 -05001105 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart2289e952018-01-30 15:58:55 -08001106 (phba->hba_flag & LINK_DISABLED) ||
James Smart83108bd2008-01-11 01:53:09 -05001107 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -05001108 return -EPERM;
1109
1110 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
1111
1112 if (!pmboxq)
1113 return -ENOMEM;
1114
1115 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -04001116 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
1117 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -04001118
James Smart33ccf8d2006-08-17 11:57:58 -04001119 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -05001120
James Smart04c68492009-05-22 14:52:52 -04001121 if ((mbxstatus == MBX_SUCCESS) &&
1122 (pmboxq->u.mb.mbxStatus == 0 ||
1123 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -04001124 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1125 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
1126 phba->cfg_link_speed);
1127 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
1128 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -04001129 if ((mbxstatus == MBX_SUCCESS) &&
1130 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
1131 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1132 "2859 SLI authentication is required "
1133 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -04001134 }
1135
James Smart5b8bd0c2007-04-25 09:52:49 -04001136 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -05001137 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001138 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001139
1140 if (mbxstatus == MBXERR_ERROR)
1141 return -EIO;
1142
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001143 return 0;
dea31012005-04-17 16:05:31 -05001144}
1145
James Smart895427b2017-02-12 13:52:30 -08001146int
1147lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
1148{
1149 int cnt = 0;
1150
1151 spin_lock_irq(lock);
1152 while (!list_empty(q)) {
1153 spin_unlock_irq(lock);
1154 msleep(20);
1155 if (cnt++ > 250) { /* 5 secs */
1156 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1157 "0466 %s %s\n",
1158 "Outstanding IO when ",
1159 "bringing Adapter offline\n");
1160 return 0;
1161 }
1162 spin_lock_irq(lock);
1163 }
1164 spin_unlock_irq(lock);
1165 return 1;
1166}
1167
James Smarte59058c2008-08-24 21:49:00 -04001168/**
James Smart3621a712009-04-06 18:47:14 -04001169 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -04001170 * @phba: lpfc_hba pointer.
1171 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
1172 *
1173 * Notes:
1174 * Assumes any error from lpfc_do_offline() will be negative.
1175 * Can wait up to 5 seconds for the port ring buffers count
1176 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -04001177 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -04001178 *
1179 * Returns:
1180 * -EIO error posting the event
1181 * zero for success
1182 **/
James Smart40496f02006-07-06 15:50:22 -04001183static int
James Smart46fa3112007-04-25 09:51:45 -04001184lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
1185{
1186 struct completion online_compl;
James Smart895427b2017-02-12 13:52:30 -08001187 struct lpfc_queue *qp = NULL;
James Smart46fa3112007-04-25 09:51:45 -04001188 struct lpfc_sli_ring *pring;
1189 struct lpfc_sli *psli;
1190 int status = 0;
James Smart46fa3112007-04-25 09:51:45 -04001191 int i;
James Smartfedd3b72011-02-16 12:39:24 -05001192 int rc;
James Smart46fa3112007-04-25 09:51:45 -04001193
1194 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001195 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -04001196 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -05001197 if (rc == 0)
1198 return -ENOMEM;
1199
James Smart46fa3112007-04-25 09:51:45 -04001200 wait_for_completion(&online_compl);
1201
1202 if (status != 0)
1203 return -EIO;
1204
1205 psli = &phba->sli;
1206
James Smart09372822008-01-11 01:52:54 -05001207 /* Wait a little for things to settle down, but not
1208 * long enough for dev loss timeout to expire.
1209 */
James Smart895427b2017-02-12 13:52:30 -08001210 if (phba->sli_rev != LPFC_SLI_REV4) {
1211 for (i = 0; i < psli->num_rings; i++) {
1212 pring = &psli->sli3_ring[i];
1213 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1214 &phba->hbalock))
1215 goto out;
1216 }
1217 } else {
1218 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1219 pring = qp->pring;
1220 if (!pring)
1221 continue;
1222 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1223 &pring->ring_lock))
1224 goto out;
James Smart46fa3112007-04-25 09:51:45 -04001225 }
1226 }
James Smart895427b2017-02-12 13:52:30 -08001227out:
James Smart46fa3112007-04-25 09:51:45 -04001228 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001229 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1230 if (rc == 0)
1231 return -ENOMEM;
1232
James Smart46fa3112007-04-25 09:51:45 -04001233 wait_for_completion(&online_compl);
1234
1235 if (status != 0)
1236 return -EIO;
1237
1238 return 0;
1239}
1240
James Smarte59058c2008-08-24 21:49:00 -04001241/**
James Smart50212672018-12-13 15:17:57 -08001242 * lpfc_reset_pci_bus - resets PCI bridge controller's secondary bus of an HBA
1243 * @phba: lpfc_hba pointer.
1244 *
1245 * Description:
1246 * Issues a PCI secondary bus reset for the phba->pcidev.
1247 *
1248 * Notes:
1249 * First walks the bus_list to ensure only PCI devices with Emulex
1250 * vendor id, device ids that support hot reset, only one occurrence
1251 * of function 0, and all ports on the bus are in offline mode to ensure the
1252 * hot reset only affects one valid HBA.
1253 *
1254 * Returns:
1255 * -ENOTSUPP, cfg_enable_hba_reset must be of value 2
1256 * -ENODEV, NULL ptr to pcidev
1257 * -EBADSLT, detected invalid device
1258 * -EBUSY, port is not in offline state
1259 * 0, successful
1260 */
1261int
1262lpfc_reset_pci_bus(struct lpfc_hba *phba)
1263{
1264 struct pci_dev *pdev = phba->pcidev;
1265 struct Scsi_Host *shost = NULL;
1266 struct lpfc_hba *phba_other = NULL;
1267 struct pci_dev *ptr = NULL;
1268 int res;
1269
1270 if (phba->cfg_enable_hba_reset != 2)
1271 return -ENOTSUPP;
1272
1273 if (!pdev) {
1274 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "8345 pdev NULL!\n");
1275 return -ENODEV;
1276 }
1277
1278 res = lpfc_check_pci_resettable(phba);
1279 if (res)
1280 return res;
1281
1282 /* Walk the list of devices on the pci_dev's bus */
1283 list_for_each_entry(ptr, &pdev->bus->devices, bus_list) {
1284 /* Check port is offline */
1285 shost = pci_get_drvdata(ptr);
1286 if (shost) {
1287 phba_other =
1288 ((struct lpfc_vport *)shost->hostdata)->phba;
1289 if (!(phba_other->pport->fc_flag & FC_OFFLINE_MODE)) {
1290 lpfc_printf_log(phba_other, KERN_INFO, LOG_INIT,
1291 "8349 WWPN = 0x%02x%02x%02x%02x"
1292 "%02x%02x%02x%02x is not "
1293 "offline!\n",
1294 phba_other->wwpn[0],
1295 phba_other->wwpn[1],
1296 phba_other->wwpn[2],
1297 phba_other->wwpn[3],
1298 phba_other->wwpn[4],
1299 phba_other->wwpn[5],
1300 phba_other->wwpn[6],
1301 phba_other->wwpn[7]);
1302 return -EBUSY;
1303 }
1304 }
1305 }
1306
1307 /* Issue PCI bus reset */
1308 res = pci_reset_bus(pdev);
1309 if (res) {
1310 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1311 "8350 PCI reset bus failed: %d\n", res);
1312 }
1313
1314 return res;
1315}
1316
1317/**
James Smart3621a712009-04-06 18:47:14 -04001318 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -04001319 * @phba: lpfc_hba pointer.
1320 *
1321 * Description:
1322 * If the port is configured to allow a reset then the hba is brought
1323 * offline then online.
1324 *
1325 * Notes:
1326 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -05001327 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -04001328 *
1329 * Returns:
1330 * lpfc_do_offline() return code if not zero
1331 * -EIO reset not configured or error posting the event
1332 * zero for success
1333 **/
James Smart7f860592011-03-11 16:05:52 -05001334int
James Smart40496f02006-07-06 15:50:22 -04001335lpfc_selective_reset(struct lpfc_hba *phba)
1336{
1337 struct completion online_compl;
1338 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001339 int rc;
James Smart40496f02006-07-06 15:50:22 -04001340
James Smart71157c92013-07-15 18:34:36 -04001341 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001342 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -05001343
James Smart71157c92013-07-15 18:34:36 -04001344 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1345 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -04001346
James Smart71157c92013-07-15 18:34:36 -04001347 if (status != 0)
1348 return status;
1349 }
James Smart40496f02006-07-06 15:50:22 -04001350
1351 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001352 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -04001353 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -05001354 if (rc == 0)
1355 return -ENOMEM;
1356
James Smart40496f02006-07-06 15:50:22 -04001357 wait_for_completion(&online_compl);
1358
1359 if (status != 0)
1360 return -EIO;
1361
1362 return 0;
1363}
1364
James Smarte59058c2008-08-24 21:49:00 -04001365/**
James Smart3621a712009-04-06 18:47:14 -04001366 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -04001367 * @dev: class device that is converted into a Scsi_host.
1368 * @attr: device attribute, not used.
1369 * @buf: containing the string "selective".
1370 * @count: unused variable.
1371 *
1372 * Description:
1373 * If the buf contains the string "selective" then lpfc_selective_reset()
1374 * is called to perform the reset.
1375 *
1376 * Notes:
1377 * Assumes any error from lpfc_selective_reset() will be negative.
1378 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001379 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -04001380 *
1381 * Returns:
1382 * -EINVAL if the buffer does not contain the string "selective"
1383 * length of buf if lpfc-selective_reset() if the call succeeds
1384 * return value of lpfc_selective_reset() if the call fails
1385**/
James Smart40496f02006-07-06 15:50:22 -04001386static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001387lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1388 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -04001389{
Tony Jonesee959b02008-02-22 00:13:36 +01001390 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001391 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1392 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -04001393 int status = -EINVAL;
1394
James Smart73d91e52011-10-10 21:32:10 -04001395 if (!phba->cfg_enable_hba_reset)
1396 return -EACCES;
1397
James Smart40496f02006-07-06 15:50:22 -04001398 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -05001399 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -04001400
1401 if (status == 0)
1402 return strlen(buf);
1403 else
1404 return status;
1405}
1406
James Smarte59058c2008-08-24 21:49:00 -04001407/**
James Smart88a2cfb2011-07-22 18:36:33 -04001408 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1409 * @phba: lpfc_hba pointer.
1410 *
1411 * Description:
1412 * SLI4 interface type-2 device to wait on the sliport status register for
1413 * the readyness after performing a firmware reset.
1414 *
1415 * Returns:
Masanari Iida0b1587b2013-07-17 04:37:44 +09001416 * zero for success, -EPERM when port does not have privilege to perform the
James Smart026abb82011-12-13 13:20:45 -05001417 * reset, -EIO when port timeout from recovering from the reset.
1418 *
1419 * Note:
1420 * As the caller will interpret the return code by value, be careful in making
1421 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -04001422 **/
James Smart73d91e52011-10-10 21:32:10 -04001423int
James Smart88a2cfb2011-07-22 18:36:33 -04001424lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1425{
James Smartf7a919b2011-08-21 21:49:16 -04001426 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -04001427 int i;
1428
James Smartf7a919b2011-08-21 21:49:16 -04001429 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -04001430 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1431 &portstat_reg.word0);
1432
Masanari Iida0b1587b2013-07-17 04:37:44 +09001433 /* verify if privileged for the request operation */
James Smartf7a919b2011-08-21 21:49:16 -04001434 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1435 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1436 return -EPERM;
1437
James Smart88a2cfb2011-07-22 18:36:33 -04001438 /* wait for the SLI port firmware ready after firmware reset */
1439 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1440 msleep(10);
1441 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1442 &portstat_reg.word0);
1443 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1444 continue;
1445 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1446 continue;
1447 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1448 continue;
1449 break;
1450 }
1451
1452 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1453 return 0;
1454 else
1455 return -EIO;
1456}
1457
1458/**
James Smart52d52442011-05-24 11:42:45 -04001459 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -04001460 * @phba: lpfc_hba pointer.
1461 *
1462 * Description:
James Smart52d52442011-05-24 11:42:45 -04001463 * Request SLI4 interface type-2 device to perform a physical register set
1464 * access.
James Smartc0c11512011-05-24 11:41:34 -04001465 *
1466 * Returns:
1467 * zero for success
1468 **/
1469static ssize_t
James Smart52d52442011-05-24 11:42:45 -04001470lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -04001471{
1472 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -04001473 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -05001474 uint32_t before_fc_flag;
1475 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -04001476 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -05001477 int status = 0, rc = 0;
1478 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -04001479
1480 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001481 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -04001482
James Smart52d52442011-05-24 11:42:45 -04001483 if ((phba->sli_rev < LPFC_SLI_REV4) ||
James Smart719162b2018-12-10 19:37:01 -08001484 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smart52d52442011-05-24 11:42:45 -04001485 LPFC_SLI_INTF_IF_TYPE_2))
1486 return -EPERM;
1487
James Smart026abb82011-12-13 13:20:45 -05001488 /* Keep state if we need to restore back */
1489 before_fc_flag = phba->pport->fc_flag;
1490 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1491
James Smartb76f2dc2011-07-22 18:37:42 -04001492 /* Disable SR-IOV virtual functions if enabled */
1493 if (phba->cfg_sriov_nr_virtfn) {
1494 pci_disable_sriov(pdev);
1495 phba->cfg_sriov_nr_virtfn = 0;
1496 }
James Smart229adb02013-04-17 20:16:51 -04001497
James Smart02936352014-04-04 13:52:12 -04001498 if (opcode == LPFC_FW_DUMP)
1499 phba->hba_flag |= HBA_FW_DUMP_OP;
1500
James Smartc0c11512011-05-24 11:41:34 -04001501 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1502
James Smart02936352014-04-04 13:52:12 -04001503 if (status != 0) {
1504 phba->hba_flag &= ~HBA_FW_DUMP_OP;
James Smartc0c11512011-05-24 11:41:34 -04001505 return status;
James Smart02936352014-04-04 13:52:12 -04001506 }
James Smartc0c11512011-05-24 11:41:34 -04001507
1508 /* wait for the device to be quiesced before firmware reset */
1509 msleep(100);
1510
1511 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1512 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -04001513
1514 if (opcode == LPFC_FW_DUMP)
1515 reg_val |= LPFC_FW_DUMP_REQUEST;
1516 else if (opcode == LPFC_FW_RESET)
1517 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1518 else if (opcode == LPFC_DV_RESET)
1519 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1520
James Smartc0c11512011-05-24 11:41:34 -04001521 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1522 LPFC_CTL_PDEV_CTL_OFFSET);
1523 /* flush */
1524 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1525
1526 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -04001527 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1528
James Smart026abb82011-12-13 13:20:45 -05001529 if (rc == -EPERM) {
Masanari Iida0b1587b2013-07-17 04:37:44 +09001530 /* no privilege for reset */
James Smart6b5151f2012-01-18 16:24:06 -05001531 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
Masanari Iida0b1587b2013-07-17 04:37:44 +09001532 "3150 No privilege to perform the requested "
James Smart6b5151f2012-01-18 16:24:06 -05001533 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -05001534 } else if (rc == -EIO) {
1535 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -05001536 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1537 "3153 Fail to perform the requested "
1538 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -04001539 return rc;
James Smart026abb82011-12-13 13:20:45 -05001540 }
1541
1542 /* keep the original port state */
1543 if (before_fc_flag & FC_OFFLINE_MODE)
1544 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001545
1546 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -05001547 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1548 LPFC_EVT_ONLINE);
1549 if (!job_posted)
1550 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001551
1552 wait_for_completion(&online_compl);
1553
James Smart026abb82011-12-13 13:20:45 -05001554out:
1555 /* in any case, restore the virtual functions enabled as before */
1556 if (sriov_nr_virtfn) {
1557 sriov_err =
1558 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1559 if (!sriov_err)
1560 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1561 }
James Smartc0c11512011-05-24 11:41:34 -04001562
James Smart026abb82011-12-13 13:20:45 -05001563 /* return proper error code */
1564 if (!rc) {
1565 if (!job_posted)
1566 rc = -ENOMEM;
1567 else if (status)
1568 rc = -EIO;
1569 }
1570 return rc;
James Smartc0c11512011-05-24 11:41:34 -04001571}
1572
1573/**
James Smart3621a712009-04-06 18:47:14 -04001574 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -04001575 * @dev: class device that is converted into a Scsi_host.
1576 * @attr: device attribute, not used.
1577 * @buf: on return contains the ascii number of nport events.
1578 *
1579 * Returns: size of formatted string.
1580 **/
dea31012005-04-17 16:05:31 -05001581static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001582lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1583 char *buf)
dea31012005-04-17 16:05:31 -05001584{
Tony Jonesee959b02008-02-22 00:13:36 +01001585 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001586 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1587 struct lpfc_hba *phba = vport->phba;
1588
dea31012005-04-17 16:05:31 -05001589 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1590}
1591
James Smart1dc5ec22018-10-23 13:41:11 -07001592int
1593lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)
1594{
1595 LPFC_MBOXQ_t *mbox = NULL;
1596 unsigned long val = 0;
1597 char *pval = 0;
1598 int rc = 0;
1599
1600 if (!strncmp("enable", buff_out,
1601 strlen("enable"))) {
1602 pval = buff_out + strlen("enable") + 1;
1603 rc = kstrtoul(pval, 0, &val);
1604 if (rc)
1605 return rc; /* Invalid number */
1606 } else if (!strncmp("disable", buff_out,
1607 strlen("disable"))) {
1608 val = 0;
1609 } else {
1610 return -EINVAL; /* Invalid command */
1611 }
1612
1613 switch (val) {
1614 case 0:
1615 val = 0x0; /* Disable */
1616 break;
1617 case 2:
1618 val = 0x1; /* Enable two port trunk */
1619 break;
1620 case 4:
1621 val = 0x2; /* Enable four port trunk */
1622 break;
1623 default:
1624 return -EINVAL;
1625 }
1626
1627 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1628 "0070 Set trunk mode with val %ld ", val);
1629
1630 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1631 if (!mbox)
1632 return -ENOMEM;
1633
1634 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1635 LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,
1636 12, LPFC_SLI4_MBX_EMBED);
1637
1638 bf_set(lpfc_mbx_set_trunk_mode,
1639 &mbox->u.mqe.un.set_trunk_mode,
1640 val);
1641 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
1642 if (rc)
1643 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1644 "0071 Set trunk mode failed with status: %d",
1645 rc);
1646 if (rc != MBX_TIMEOUT)
1647 mempool_free(mbox, phba->mbox_mem_pool);
1648
1649 return 0;
1650}
1651
James Smarte59058c2008-08-24 21:49:00 -04001652/**
James Smart3621a712009-04-06 18:47:14 -04001653 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -04001654 * @dev: class device that is converted into a Scsi_host.
1655 * @attr: device attribute, not used.
1656 * @buf: on return contains the state of the adapter.
1657 *
1658 * Returns: size of formatted string.
1659 **/
dea31012005-04-17 16:05:31 -05001660static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001661lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1662 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001663{
Tony Jonesee959b02008-02-22 00:13:36 +01001664 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001665 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1666 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001667 char * state;
1668
James Smart2e0fef82007-06-17 19:56:36 -05001669 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001670 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001671 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001672 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001673 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001674 state = "offline";
1675 else
1676 state = "online";
1677
1678 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1679}
1680
James Smarte59058c2008-08-24 21:49:00 -04001681/**
James Smart3621a712009-04-06 18:47:14 -04001682 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001683 * @dev: class device that is converted into a Scsi_host.
1684 * @attr: device attribute, not used.
1685 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1686 * @count: unused variable.
1687 *
1688 * Returns:
1689 * -EACCES if enable hba reset not enabled
1690 * -EINVAL if the buffer does not contain a valid string (see above)
1691 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1692 * buf length greater than zero indicates success
1693 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001694static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001695lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1696 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001697{
Tony Jonesee959b02008-02-22 00:13:36 +01001698 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001699 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1700 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001701 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001702 char *board_mode_str = NULL;
1703 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001704 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001705
James Smart026abb82011-12-13 13:20:45 -05001706 if (!phba->cfg_enable_hba_reset) {
1707 status = -EACCES;
1708 goto board_mode_out;
1709 }
James Smart88a2cfb2011-07-22 18:36:33 -04001710
1711 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001712 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001713
Jamie Wellnitz41415862006-02-28 19:25:27 -05001714 init_completion(&online_compl);
1715
James Smart46fa3112007-04-25 09:51:45 -04001716 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001717 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001718 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001719 if (rc == 0) {
1720 status = -ENOMEM;
1721 goto board_mode_out;
1722 }
James Smart46fa3112007-04-25 09:51:45 -04001723 wait_for_completion(&online_compl);
James Smart522dcee2017-06-01 21:07:03 -07001724 if (status)
1725 status = -EIO;
James Smart46fa3112007-04-25 09:51:45 -04001726 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1727 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001728 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001729 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001730 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001731 else
1732 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001733 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001734 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001735 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001736 else
1737 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001738 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001739 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1740 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1741 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1742 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1743 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
James Smart50212672018-12-13 15:17:57 -08001744 else if (strncmp(buf, "pci_bus_reset", sizeof("pci_bus_reset") - 1)
1745 == 0)
1746 status = lpfc_reset_pci_bus(phba);
James Smart1dc5ec22018-10-23 13:41:11 -07001747 else if (strncmp(buf, "trunk", sizeof("trunk") - 1) == 0)
1748 status = lpfc_set_trunking(phba, (char *)buf + sizeof("trunk"));
Jamie Wellnitz41415862006-02-28 19:25:27 -05001749 else
James Smart026abb82011-12-13 13:20:45 -05001750 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001751
James Smart026abb82011-12-13 13:20:45 -05001752board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001753 if (!status)
1754 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001755 else {
1756 board_mode_str = strchr(buf, '\n');
1757 if (board_mode_str)
1758 *board_mode_str = '\0';
1759 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1760 "3097 Failed \"%s\", status(%d), "
1761 "fc_flag(x%x)\n",
1762 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001763 return status;
James Smart026abb82011-12-13 13:20:45 -05001764 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001765}
1766
James Smarte59058c2008-08-24 21:49:00 -04001767/**
James Smart3621a712009-04-06 18:47:14 -04001768 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001769 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001770 * @mxri: max xri count.
1771 * @axri: available xri count.
1772 * @mrpi: max rpi count.
1773 * @arpi: available rpi count.
1774 * @mvpi: max vpi count.
1775 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001776 *
1777 * Description:
1778 * If an integer pointer for an count is not null then the value for the
1779 * count is returned.
1780 *
1781 * Returns:
1782 * zero on error
1783 * one for success
1784 **/
James Smart311464e2007-08-02 11:10:37 -04001785static int
James Smart858c9f62007-06-17 19:56:39 -05001786lpfc_get_hba_info(struct lpfc_hba *phba,
1787 uint32_t *mxri, uint32_t *axri,
1788 uint32_t *mrpi, uint32_t *arpi,
1789 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001790{
James Smart04c68492009-05-22 14:52:52 -04001791 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001792 LPFC_MBOXQ_t *pmboxq;
1793 MAILBOX_t *pmb;
1794 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001795 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001796
1797 /*
1798 * prevent udev from issuing mailbox commands until the port is
1799 * configured.
1800 */
1801 if (phba->link_state < LPFC_LINK_DOWN ||
1802 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001803 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001804 return 0;
1805
1806 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1807 return 0;
1808
1809 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1810 if (!pmboxq)
1811 return 0;
1812 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1813
James Smart04c68492009-05-22 14:52:52 -04001814 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001815 pmb->mbxCommand = MBX_READ_CONFIG;
1816 pmb->mbxOwner = OWN_HOST;
James Smart3e1f0712018-11-29 16:09:29 -08001817 pmboxq->ctx_buf = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05001818
James Smart75baf692010-06-08 18:31:21 -04001819 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001820 rc = MBX_NOT_FINISHED;
1821 else
1822 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1823
1824 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001825 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001826 mempool_free(pmboxq, phba->mbox_mem_pool);
1827 return 0;
1828 }
1829
James Smartda0436e2009-05-22 14:51:39 -04001830 if (phba->sli_rev == LPFC_SLI_REV4) {
1831 rd_config = &pmboxq->u.mqe.un.rd_config;
1832 if (mrpi)
1833 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1834 if (arpi)
1835 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1836 phba->sli4_hba.max_cfg_param.rpi_used;
1837 if (mxri)
1838 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1839 if (axri)
1840 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1841 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001842
1843 /* Account for differences with SLI-3. Get vpi count from
1844 * mailbox data and subtract one for max vpi value.
1845 */
1846 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1847 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1848
James Smart8b47ae62018-11-29 16:09:33 -08001849 /* Limit the max we support */
1850 if (max_vpi > LPFC_MAX_VPI)
1851 max_vpi = LPFC_MAX_VPI;
James Smartda0436e2009-05-22 14:51:39 -04001852 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001853 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001854 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001855 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001856 } else {
1857 if (mrpi)
1858 *mrpi = pmb->un.varRdConfig.max_rpi;
1859 if (arpi)
1860 *arpi = pmb->un.varRdConfig.avail_rpi;
1861 if (mxri)
1862 *mxri = pmb->un.varRdConfig.max_xri;
1863 if (axri)
1864 *axri = pmb->un.varRdConfig.avail_xri;
1865 if (mvpi)
1866 *mvpi = pmb->un.varRdConfig.max_vpi;
James Smart8b47ae62018-11-29 16:09:33 -08001867 if (avpi) {
1868 /* avail_vpi is only valid if link is up and ready */
1869 if (phba->link_state == LPFC_HBA_READY)
1870 *avpi = pmb->un.varRdConfig.avail_vpi;
1871 else
1872 *avpi = pmb->un.varRdConfig.max_vpi;
1873 }
James Smartda0436e2009-05-22 14:51:39 -04001874 }
James Smart92d7f7b2007-06-17 19:56:38 -05001875
1876 mempool_free(pmboxq, phba->mbox_mem_pool);
1877 return 1;
1878}
1879
James Smarte59058c2008-08-24 21:49:00 -04001880/**
James Smart3621a712009-04-06 18:47:14 -04001881 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001882 * @dev: class device that is converted into a Scsi_host.
1883 * @attr: device attribute, not used.
1884 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1885 *
1886 * Description:
1887 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1888 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1889 * to "Unknown" and the buffer length is returned, therefore the caller
1890 * must check for "Unknown" in the buffer to detect a failure.
1891 *
1892 * Returns: size of formatted string.
1893 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001894static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001895lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1896 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001897{
Tony Jonesee959b02008-02-22 00:13:36 +01001898 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001899 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1900 struct lpfc_hba *phba = vport->phba;
1901 uint32_t cnt;
1902
James Smart858c9f62007-06-17 19:56:39 -05001903 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001904 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1905 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1906}
1907
James Smarte59058c2008-08-24 21:49:00 -04001908/**
James Smart3621a712009-04-06 18:47:14 -04001909 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001910 * @dev: class device that is converted into a Scsi_host.
1911 * @attr: device attribute, not used.
1912 * @buf: containing the used rpi count in decimal or "Unknown".
1913 *
1914 * Description:
1915 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1916 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1917 * to "Unknown" and the buffer length is returned, therefore the caller
1918 * must check for "Unknown" in the buffer to detect a failure.
1919 *
1920 * Returns: size of formatted string.
1921 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001922static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001923lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1924 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001925{
Tony Jonesee959b02008-02-22 00:13:36 +01001926 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001927 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1928 struct lpfc_hba *phba = vport->phba;
1929 uint32_t cnt, acnt;
1930
James Smart858c9f62007-06-17 19:56:39 -05001931 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001932 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1933 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1934}
1935
James Smarte59058c2008-08-24 21:49:00 -04001936/**
James Smart3621a712009-04-06 18:47:14 -04001937 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001938 * @dev: class device that is converted into a Scsi_host.
1939 * @attr: device attribute, not used.
1940 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1941 *
1942 * Description:
1943 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1944 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1945 * to "Unknown" and the buffer length is returned, therefore the caller
1946 * must check for "Unknown" in the buffer to detect a failure.
1947 *
1948 * Returns: size of formatted string.
1949 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001950static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001951lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1952 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001953{
Tony Jonesee959b02008-02-22 00:13:36 +01001954 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001955 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1956 struct lpfc_hba *phba = vport->phba;
1957 uint32_t cnt;
1958
James Smart858c9f62007-06-17 19:56:39 -05001959 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001960 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1961 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1962}
1963
James Smarte59058c2008-08-24 21:49:00 -04001964/**
James Smart3621a712009-04-06 18:47:14 -04001965 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001966 * @dev: class device that is converted into a Scsi_host.
1967 * @attr: device attribute, not used.
1968 * @buf: on return contains the used xri count in decimal or "Unknown".
1969 *
1970 * Description:
1971 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1972 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1973 * to "Unknown" and the buffer length is returned, therefore the caller
1974 * must check for "Unknown" in the buffer to detect a failure.
1975 *
1976 * Returns: size of formatted string.
1977 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001978static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001979lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1980 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001981{
Tony Jonesee959b02008-02-22 00:13:36 +01001982 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001983 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1984 struct lpfc_hba *phba = vport->phba;
1985 uint32_t cnt, acnt;
1986
James Smart858c9f62007-06-17 19:56:39 -05001987 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1988 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1989 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1990}
1991
James Smarte59058c2008-08-24 21:49:00 -04001992/**
James Smart3621a712009-04-06 18:47:14 -04001993 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001994 * @dev: class device that is converted into a Scsi_host.
1995 * @attr: device attribute, not used.
1996 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1997 *
1998 * Description:
1999 * Calls lpfc_get_hba_info() asking for just the mvpi count.
2000 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2001 * to "Unknown" and the buffer length is returned, therefore the caller
2002 * must check for "Unknown" in the buffer to detect a failure.
2003 *
2004 * Returns: size of formatted string.
2005 **/
James Smart858c9f62007-06-17 19:56:39 -05002006static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002007lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
2008 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05002009{
Tony Jonesee959b02008-02-22 00:13:36 +01002010 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05002011 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2012 struct lpfc_hba *phba = vport->phba;
2013 uint32_t cnt;
2014
2015 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
2016 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
2017 return snprintf(buf, PAGE_SIZE, "Unknown\n");
2018}
2019
James Smarte59058c2008-08-24 21:49:00 -04002020/**
James Smart3621a712009-04-06 18:47:14 -04002021 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04002022 * @dev: class device that is converted into a Scsi_host.
2023 * @attr: device attribute, not used.
2024 * @buf: on return contains the used vpi count in decimal or "Unknown".
2025 *
2026 * Description:
2027 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
2028 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2029 * to "Unknown" and the buffer length is returned, therefore the caller
2030 * must check for "Unknown" in the buffer to detect a failure.
2031 *
2032 * Returns: size of formatted string.
2033 **/
James Smart858c9f62007-06-17 19:56:39 -05002034static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002035lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
2036 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05002037{
Tony Jonesee959b02008-02-22 00:13:36 +01002038 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05002039 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2040 struct lpfc_hba *phba = vport->phba;
2041 uint32_t cnt, acnt;
2042
2043 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05002044 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2045 return snprintf(buf, PAGE_SIZE, "Unknown\n");
2046}
2047
James Smarte59058c2008-08-24 21:49:00 -04002048/**
James Smart3621a712009-04-06 18:47:14 -04002049 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002050 * @dev: class device that is converted into a Scsi_host.
2051 * @attr: device attribute, not used.
2052 * @buf: text that must be interpreted to determine if npiv is supported.
2053 *
2054 * Description:
2055 * Buffer will contain text indicating npiv is not suppoerted on the port,
2056 * the port is an NPIV physical port, or it is an npiv virtual port with
2057 * the id of the vport.
2058 *
2059 * Returns: size of formatted string.
2060 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002061static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002062lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
2063 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05002064{
Tony Jonesee959b02008-02-22 00:13:36 +01002065 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05002066 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2067 struct lpfc_hba *phba = vport->phba;
2068
2069 if (!(phba->max_vpi))
2070 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
2071 if (vport->port_type == LPFC_PHYSICAL_PORT)
2072 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
2073 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
2074}
2075
James Smarte59058c2008-08-24 21:49:00 -04002076/**
James Smart3621a712009-04-06 18:47:14 -04002077 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002078 * @dev: class device that is converted into a Scsi_host.
2079 * @attr: device attribute, not used.
2080 * @buf: on return contains the cfg_poll in hex.
2081 *
2082 * Notes:
2083 * cfg_poll should be a lpfc_polling_flags type.
2084 *
2085 * Returns: size of formatted string.
2086 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05002087static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002088lpfc_poll_show(struct device *dev, struct device_attribute *attr,
2089 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002090{
Tony Jonesee959b02008-02-22 00:13:36 +01002091 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002092 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2093 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002094
2095 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
2096}
2097
James Smarte59058c2008-08-24 21:49:00 -04002098/**
James Smart3621a712009-04-06 18:47:14 -04002099 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04002100 * @dev: class device that is converted into a Scsi_host.
2101 * @attr: device attribute, not used.
2102 * @buf: one or more lpfc_polling_flags values.
2103 * @count: not used.
2104 *
2105 * Notes:
2106 * buf contents converted to integer and checked for a valid value.
2107 *
2108 * Returns:
2109 * -EINVAL if the buffer connot be converted or is out of range
2110 * length of the buf on success
2111 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002112static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01002113lpfc_poll_store(struct device *dev, struct device_attribute *attr,
2114 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002115{
Tony Jonesee959b02008-02-22 00:13:36 +01002116 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05002117 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2118 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002119 uint32_t creg_val;
2120 uint32_t old_val;
2121 int val=0;
2122
2123 if (!isdigit(buf[0]))
2124 return -EINVAL;
2125
2126 if (sscanf(buf, "%i", &val) != 1)
2127 return -EINVAL;
2128
2129 if ((val & 0x3) != val)
2130 return -EINVAL;
2131
James Smart45ed1192009-10-02 15:17:02 -04002132 if (phba->sli_rev == LPFC_SLI_REV4)
2133 val = 0;
2134
James Smart88a2cfb2011-07-22 18:36:33 -04002135 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2136 "3051 lpfc_poll changed from %d to %d\n",
2137 phba->cfg_poll, val);
2138
James Smart2e0fef82007-06-17 19:56:36 -05002139 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002140
2141 old_val = phba->cfg_poll;
2142
2143 if (val & ENABLE_FCP_RING_POLLING) {
2144 if ((val & DISABLE_FCP_RING_INT) &&
2145 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05002146 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2147 spin_unlock_irq(&phba->hbalock);
2148 return -EINVAL;
2149 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002150 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
2151 writel(creg_val, phba->HCregaddr);
2152 readl(phba->HCregaddr); /* flush */
2153
2154 lpfc_poll_start_timer(phba);
2155 }
2156 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05002157 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002158 return -EINVAL;
2159 }
2160
2161 if (!(val & DISABLE_FCP_RING_INT) &&
2162 (old_val & DISABLE_FCP_RING_INT))
2163 {
James Smart2e0fef82007-06-17 19:56:36 -05002164 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002165 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05002166 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05002167 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2168 spin_unlock_irq(&phba->hbalock);
2169 return -EINVAL;
2170 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002171 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2172 writel(creg_val, phba->HCregaddr);
2173 readl(phba->HCregaddr); /* flush */
2174 }
2175
2176 phba->cfg_poll = val;
2177
James Smart2e0fef82007-06-17 19:56:36 -05002178 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002179
2180 return strlen(buf);
2181}
dea31012005-04-17 16:05:31 -05002182
James Smarte59058c2008-08-24 21:49:00 -04002183/**
James Smartbc739052010-08-04 16:11:18 -04002184 * lpfc_fips_level_show - Return the current FIPS level for the HBA
2185 * @dev: class unused variable.
2186 * @attr: device attribute, not used.
2187 * @buf: on return contains the module description text.
2188 *
2189 * Returns: size of formatted string.
2190 **/
2191static ssize_t
2192lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
2193 char *buf)
2194{
2195 struct Scsi_Host *shost = class_to_shost(dev);
2196 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2197 struct lpfc_hba *phba = vport->phba;
2198
2199 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
2200}
2201
2202/**
2203 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
2204 * @dev: class unused variable.
2205 * @attr: device attribute, not used.
2206 * @buf: on return contains the module description text.
2207 *
2208 * Returns: size of formatted string.
2209 **/
2210static ssize_t
2211lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
2212 char *buf)
2213{
2214 struct Scsi_Host *shost = class_to_shost(dev);
2215 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2216 struct lpfc_hba *phba = vport->phba;
2217
2218 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
2219}
2220
2221/**
James Smartab56dc22011-02-16 12:39:57 -05002222 * lpfc_dss_show - Return the current state of dss and the configured state
2223 * @dev: class converted to a Scsi_host structure.
2224 * @attr: device attribute, not used.
2225 * @buf: on return contains the formatted text.
2226 *
2227 * Returns: size of formatted string.
2228 **/
2229static ssize_t
2230lpfc_dss_show(struct device *dev, struct device_attribute *attr,
2231 char *buf)
2232{
2233 struct Scsi_Host *shost = class_to_shost(dev);
2234 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2235 struct lpfc_hba *phba = vport->phba;
2236
2237 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
2238 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
2239 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
2240 "" : "Not ");
2241}
2242
2243/**
James Smart912e3ac2011-05-24 11:42:11 -04002244 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
2245 * @dev: class converted to a Scsi_host structure.
2246 * @attr: device attribute, not used.
2247 * @buf: on return contains the formatted support level.
2248 *
2249 * Description:
2250 * Returns the maximum number of virtual functions a physical function can
2251 * support, 0 will be returned if called on virtual function.
2252 *
2253 * Returns: size of formatted string.
2254 **/
2255static ssize_t
2256lpfc_sriov_hw_max_virtfn_show(struct device *dev,
2257 struct device_attribute *attr,
2258 char *buf)
2259{
2260 struct Scsi_Host *shost = class_to_shost(dev);
2261 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2262 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04002263 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04002264
James Smart0a96e972011-07-22 18:37:28 -04002265 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
2266 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04002267}
2268
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002269static inline bool lpfc_rangecheck(uint val, uint min, uint max)
2270{
2271 return val >= min && val <= max;
2272}
2273
James Smart912e3ac2011-05-24 11:42:11 -04002274/**
James Smart44fd7fe2017-08-23 16:55:47 -07002275 * lpfc_enable_bbcr_set: Sets an attribute value.
2276 * @phba: pointer the the adapter structure.
2277 * @val: integer attribute value.
2278 *
2279 * Description:
2280 * Validates the min and max values then sets the
2281 * adapter config field if in the valid range. prints error message
2282 * and does not set the parameter if invalid.
2283 *
2284 * Returns:
2285 * zero on success
2286 * -EINVAL if val is invalid
2287 */
2288static ssize_t
2289lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
2290{
2291 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
2292 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2293 "3068 %s_enable_bbcr changed from %d to %d\n",
2294 LPFC_DRIVER_NAME, phba->cfg_enable_bbcr, val);
2295 phba->cfg_enable_bbcr = val;
2296 return 0;
2297 }
2298 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2299 "0451 %s_enable_bbcr cannot set to %d, range is 0, 1\n",
2300 LPFC_DRIVER_NAME, val);
2301 return -EINVAL;
2302}
2303
2304/**
James Smart3621a712009-04-06 18:47:14 -04002305 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04002306 *
2307 * Description:
2308 * Macro that given an attr e.g. hba_queue_depth expands
2309 * into a function with the name lpfc_hba_queue_depth_show.
2310 *
2311 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
2312 * @dev: class device that is converted into a Scsi_host.
2313 * @attr: device attribute, not used.
2314 * @buf: on return contains the attribute value in decimal.
2315 *
2316 * Returns: size of formatted string.
2317 **/
dea31012005-04-17 16:05:31 -05002318#define lpfc_param_show(attr) \
2319static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002320lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2321 char *buf) \
dea31012005-04-17 16:05:31 -05002322{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002323 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002324 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2325 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002326 return snprintf(buf, PAGE_SIZE, "%d\n",\
2327 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05002328}
2329
James Smarte59058c2008-08-24 21:49:00 -04002330/**
James Smart3621a712009-04-06 18:47:14 -04002331 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04002332 *
2333 * Description:
2334 * Macro that given an attr e.g. hba_queue_depth expands
2335 * into a function with the name lpfc_hba_queue_depth_show
2336 *
2337 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
2338 * @dev: class device that is converted into a Scsi_host.
2339 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002340 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002341 *
2342 * Returns: size of formatted string.
2343 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002344#define lpfc_param_hex_show(attr) \
2345static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002346lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2347 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002348{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002349 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002350 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2351 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05002352 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002353 val = phba->cfg_##attr;\
2354 return snprintf(buf, PAGE_SIZE, "%#x\n",\
2355 phba->cfg_##attr);\
2356}
2357
James Smarte59058c2008-08-24 21:49:00 -04002358/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04002359 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002360 *
2361 * Description:
2362 * Macro that given an attr e.g. hba_queue_depth expands
2363 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2364 * takes a default argument, a minimum and maximum argument.
2365 *
2366 * lpfc_##attr##_init: Initializes an attribute.
2367 * @phba: pointer the the adapter structure.
2368 * @val: integer attribute value.
2369 *
2370 * Validates the min and max values then sets the adapter config field
2371 * accordingly, or uses the default if out of range and prints an error message.
2372 *
2373 * Returns:
2374 * zero on success
2375 * -EINVAL if default used
2376 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002377#define lpfc_param_init(attr, default, minval, maxval) \
2378static int \
James Smart84d1b002010-02-12 14:42:33 -05002379lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002380{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002381 if (lpfc_rangecheck(val, minval, maxval)) {\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002382 phba->cfg_##attr = val;\
2383 return 0;\
2384 }\
2385 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04002386 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2387 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002388 phba->cfg_##attr = default;\
2389 return -EINVAL;\
2390}
2391
James Smarte59058c2008-08-24 21:49:00 -04002392/**
James Smart3621a712009-04-06 18:47:14 -04002393 * lpfc_param_set - Set a cfg attribute value
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_set
2398 *
2399 * lpfc_##attr##_set: Sets an attribute value.
2400 * @phba: pointer the the adapter structure.
2401 * @val: integer attribute value.
2402 *
2403 * Description:
2404 * Validates the min and max values then sets the
2405 * adapter config field if in the valid range. prints error message
2406 * and does not set the parameter if invalid.
2407 *
2408 * Returns:
2409 * zero on success
2410 * -EINVAL if val is invalid
2411 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002412#define lpfc_param_set(attr, default, minval, maxval) \
2413static int \
James Smart84d1b002010-02-12 14:42:33 -05002414lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002415{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002416 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002417 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2418 "3052 lpfc_" #attr " changed from %d to %d\n", \
2419 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002420 phba->cfg_##attr = val;\
2421 return 0;\
2422 }\
2423 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04002424 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2425 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002426 return -EINVAL;\
2427}
2428
James Smarte59058c2008-08-24 21:49:00 -04002429/**
James Smart3621a712009-04-06 18:47:14 -04002430 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04002431 *
2432 * Description:
2433 * Macro that given an attr e.g. hba_queue_depth expands
2434 * into a function with the name lpfc_hba_queue_depth_store.
2435 *
2436 * lpfc_##attr##_store: Set an sttribute value.
2437 * @dev: class device that is converted into a Scsi_host.
2438 * @attr: device attribute, not used.
2439 * @buf: contains the attribute value in ascii.
2440 * @count: not used.
2441 *
2442 * Description:
2443 * Convert the ascii text number to an integer, then
2444 * use the lpfc_##attr##_set function to set the value.
2445 *
2446 * Returns:
2447 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2448 * length of buffer upon success.
2449 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002450#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05002451static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002452lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2453 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05002454{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002455 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002456 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2457 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05002458 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002459 if (!isdigit(buf[0]))\
2460 return -EINVAL;\
2461 if (sscanf(buf, "%i", &val) != 1)\
2462 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002463 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04002464 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002465 else \
2466 return -EINVAL;\
dea31012005-04-17 16:05:31 -05002467}
2468
James Smarte59058c2008-08-24 21:49:00 -04002469/**
James Smart3621a712009-04-06 18:47:14 -04002470 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04002471 *
2472 * Description:
2473 * Macro that given an attr e.g. hba_queue_depth expands
2474 * into a function with the name lpfc_hba_queue_depth_show
2475 *
2476 * lpfc_##attr##_show: prints the attribute value in decimal.
2477 * @dev: class device that is converted into a Scsi_host.
2478 * @attr: device attribute, not used.
2479 * @buf: on return contains the attribute value in decimal.
2480 *
2481 * Returns: length of formatted string.
2482 **/
James Smart3de2a652007-08-02 11:09:59 -04002483#define lpfc_vport_param_show(attr) \
2484static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002485lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2486 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002487{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002488 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002489 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002490 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2491}
2492
James Smarte59058c2008-08-24 21:49:00 -04002493/**
James Smart3621a712009-04-06 18:47:14 -04002494 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04002495 *
2496 * Description:
2497 * Macro that given an attr e.g.
2498 * hba_queue_depth expands into a function with the name
2499 * lpfc_hba_queue_depth_show
2500 *
James Smart3621a712009-04-06 18:47:14 -04002501 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002502 * @dev: class device that is converted into a Scsi_host.
2503 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002504 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002505 *
2506 * Returns: length of formatted string.
2507 **/
James Smart3de2a652007-08-02 11:09:59 -04002508#define lpfc_vport_param_hex_show(attr) \
2509static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002510lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2511 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002512{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002513 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002514 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002515 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2516}
2517
James Smarte59058c2008-08-24 21:49:00 -04002518/**
James Smart3621a712009-04-06 18:47:14 -04002519 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002520 *
2521 * Description:
2522 * Macro that given an attr e.g. hba_queue_depth expands
2523 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2524 * takes a default argument, a minimum and maximum argument.
2525 *
2526 * lpfc_##attr##_init: validates the min and max values then sets the
2527 * adapter config field accordingly, or uses the default if out of range
2528 * and prints an error message.
2529 * @phba: pointer the the adapter structure.
2530 * @val: integer attribute value.
2531 *
2532 * Returns:
2533 * zero on success
2534 * -EINVAL if default used
2535 **/
James Smart3de2a652007-08-02 11:09:59 -04002536#define lpfc_vport_param_init(attr, default, minval, maxval) \
2537static int \
James Smart84d1b002010-02-12 14:42:33 -05002538lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002539{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002540 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart3de2a652007-08-02 11:09:59 -04002541 vport->cfg_##attr = val;\
2542 return 0;\
2543 }\
James Smarte8b62012007-08-02 11:10:09 -04002544 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002545 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002546 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002547 vport->cfg_##attr = default;\
2548 return -EINVAL;\
2549}
2550
James Smarte59058c2008-08-24 21:49:00 -04002551/**
James Smart3621a712009-04-06 18:47:14 -04002552 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002553 *
2554 * Description:
2555 * Macro that given an attr e.g. hba_queue_depth expands
2556 * into a function with the name lpfc_hba_queue_depth_set
2557 *
2558 * lpfc_##attr##_set: validates the min and max values then sets the
2559 * adapter config field if in the valid range. prints error message
2560 * and does not set the parameter if invalid.
2561 * @phba: pointer the the adapter structure.
2562 * @val: integer attribute value.
2563 *
2564 * Returns:
2565 * zero on success
2566 * -EINVAL if val is invalid
2567 **/
James Smart3de2a652007-08-02 11:09:59 -04002568#define lpfc_vport_param_set(attr, default, minval, maxval) \
2569static int \
James Smart84d1b002010-02-12 14:42:33 -05002570lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002571{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002572 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002573 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04002574 "3053 lpfc_" #attr \
2575 " changed from %d (x%x) to %d (x%x)\n", \
2576 vport->cfg_##attr, vport->cfg_##attr, \
2577 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04002578 vport->cfg_##attr = val;\
2579 return 0;\
2580 }\
James Smarte8b62012007-08-02 11:10:09 -04002581 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002582 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002583 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002584 return -EINVAL;\
2585}
2586
James Smarte59058c2008-08-24 21:49:00 -04002587/**
James Smart3621a712009-04-06 18:47:14 -04002588 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04002589 *
2590 * Description:
2591 * Macro that given an attr e.g. hba_queue_depth
2592 * expands into a function with the name lpfc_hba_queue_depth_store
2593 *
2594 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2595 * use the lpfc_##attr##_set function to set the value.
2596 * @cdev: class device that is converted into a Scsi_host.
2597 * @buf: contains the attribute value in decimal.
2598 * @count: not used.
2599 *
2600 * Returns:
2601 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2602 * length of buffer upon success.
2603 **/
James Smart3de2a652007-08-02 11:09:59 -04002604#define lpfc_vport_param_store(attr) \
2605static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002606lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2607 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04002608{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002609 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002610 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05002611 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04002612 if (!isdigit(buf[0]))\
2613 return -EINVAL;\
2614 if (sscanf(buf, "%i", &val) != 1)\
2615 return -EINVAL;\
2616 if (lpfc_##attr##_set(vport, val) == 0) \
2617 return strlen(buf);\
2618 else \
2619 return -EINVAL;\
2620}
2621
2622
James Smart895427b2017-02-12 13:52:30 -08002623static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
James Smart4c47efc2019-01-28 11:14:25 -08002624static DEVICE_ATTR(scsi_stat, 0444, lpfc_scsi_stat_show, NULL);
James Smart81301a92008-12-04 22:39:46 -05002625static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2626static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2627static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2628static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002629static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2630static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2631static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2632static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2633static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2634static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2635static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2636static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002637static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2638 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002639static DEVICE_ATTR(option_rom_version, S_IRUGO,
2640 lpfc_option_rom_version_show, NULL);
2641static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2642 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002643static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002644static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
Joe Perchesc828a892017-12-19 10:15:08 -08002645static DEVICE_ATTR_RO(lpfc_drvr_version);
2646static DEVICE_ATTR_RO(lpfc_enable_fip);
Tony Jonesee959b02008-02-22 00:13:36 +01002647static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2648 lpfc_board_mode_show, lpfc_board_mode_store);
2649static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2650static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2651static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2652static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2653static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2654static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2655static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2656static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
Joe Perchesc828a892017-12-19 10:15:08 -08002657static DEVICE_ATTR_RO(lpfc_temp_sensor);
2658static DEVICE_ATTR_RO(lpfc_fips_level);
2659static DEVICE_ATTR_RO(lpfc_fips_rev);
2660static DEVICE_ATTR_RO(lpfc_dss);
2661static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
James Smart026abb82011-12-13 13:20:45 -05002662static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05002663static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2664 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002665
James Smart352e5fd2016-12-30 06:57:47 -08002666static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smart1ba981f2014-02-20 09:56:45 -05002667#define WWN_SZ 8
2668/**
2669 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2670 * @buf: WWN string.
2671 * @cnt: Length of string.
2672 * @wwn: Array to receive converted wwn value.
2673 *
2674 * Returns:
2675 * -EINVAL if the buffer does not contain a valid wwn
2676 * 0 success
2677 **/
2678static size_t
2679lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2680{
2681 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002682
James Smart1ba981f2014-02-20 09:56:45 -05002683 /* Count may include a LF at end of string */
2684 if (buf[cnt-1] == '\n')
2685 cnt--;
2686
2687 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2688 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2689 return -EINVAL;
2690
2691 memset(wwn, 0, WWN_SZ);
2692
2693 /* Validate and store the new name */
2694 for (i = 0, j = 0; i < 16; i++) {
2695 if ((*buf >= 'a') && (*buf <= 'f'))
2696 j = ((j << 4) | ((*buf++ - 'a') + 10));
2697 else if ((*buf >= 'A') && (*buf <= 'F'))
2698 j = ((j << 4) | ((*buf++ - 'A') + 10));
2699 else if ((*buf >= '0') && (*buf <= '9'))
2700 j = ((j << 4) | (*buf++ - '0'));
2701 else
2702 return -EINVAL;
2703 if (i % 2) {
2704 wwn[i/2] = j & 0xff;
2705 j = 0;
2706 }
2707 }
2708 return 0;
2709}
James Smart352e5fd2016-12-30 06:57:47 -08002710/**
2711 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2712 * @dev: class device that is converted into a Scsi_host.
2713 * @attr: device attribute, not used.
2714 * @buf: containing the string lpfc_soft_wwn_key.
2715 * @count: must be size of lpfc_soft_wwn_key.
2716 *
2717 * Returns:
2718 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2719 * length of buf indicates success
2720 **/
2721static ssize_t
2722lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2723 const char *buf, size_t count)
2724{
2725 struct Scsi_Host *shost = class_to_shost(dev);
2726 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2727 struct lpfc_hba *phba = vport->phba;
2728 unsigned int cnt = count;
James Smartaeb3c812017-04-21 16:05:02 -07002729 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2730 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
James Smart352e5fd2016-12-30 06:57:47 -08002731
2732 /*
2733 * We're doing a simple sanity check for soft_wwpn setting.
2734 * We require that the user write a specific key to enable
2735 * the soft_wwpn attribute to be settable. Once the attribute
2736 * is written, the enable key resets. If further updates are
2737 * desired, the key must be written again to re-enable the
2738 * attribute.
2739 *
2740 * The "key" is not secret - it is a hardcoded string shown
2741 * here. The intent is to protect against the random user or
2742 * application that is just writing attributes.
2743 */
James Smartaeb3c812017-04-21 16:05:02 -07002744 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2745 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2746 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2747 " be enabled: fawwpn is enabled\n");
2748 return -EINVAL;
2749 }
James Smart352e5fd2016-12-30 06:57:47 -08002750
2751 /* count may include a LF at end of string */
2752 if (buf[cnt-1] == '\n')
2753 cnt--;
2754
2755 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2756 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2757 return -EINVAL;
2758
2759 phba->soft_wwn_enable = 1;
2760
2761 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2762 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2763 phba->brd_no);
2764 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2765 " The soft_wwpn feature is not supported by Broadcom.");
2766
2767 return count;
2768}
Joe Perches6cbaefb2017-12-19 10:15:09 -08002769static DEVICE_ATTR_WO(lpfc_soft_wwn_enable);
James Smart352e5fd2016-12-30 06:57:47 -08002770
2771/**
2772 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2773 * @dev: class device that is converted into a Scsi_host.
2774 * @attr: device attribute, not used.
2775 * @buf: on return contains the wwpn in hexadecimal.
2776 *
2777 * Returns: size of formatted string.
2778 **/
2779static ssize_t
2780lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2781 char *buf)
2782{
2783 struct Scsi_Host *shost = class_to_shost(dev);
2784 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2785 struct lpfc_hba *phba = vport->phba;
2786
2787 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2788 (unsigned long long)phba->cfg_soft_wwpn);
2789}
2790
2791/**
2792 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2793 * @dev class device that is converted into a Scsi_host.
2794 * @attr: device attribute, not used.
2795 * @buf: contains the wwpn in hexadecimal.
2796 * @count: number of wwpn bytes in buf
2797 *
2798 * Returns:
2799 * -EACCES hba reset not enabled, adapter over temp
2800 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2801 * -EIO error taking adapter offline or online
2802 * value of count on success
2803 **/
2804static ssize_t
2805lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2806 const char *buf, size_t count)
2807{
2808 struct Scsi_Host *shost = class_to_shost(dev);
2809 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2810 struct lpfc_hba *phba = vport->phba;
2811 struct completion online_compl;
2812 int stat1 = 0, stat2 = 0;
2813 unsigned int cnt = count;
2814 u8 wwpn[WWN_SZ];
2815 int rc;
2816
2817 if (!phba->cfg_enable_hba_reset)
2818 return -EACCES;
2819 spin_lock_irq(&phba->hbalock);
2820 if (phba->over_temp_state == HBA_OVER_TEMP) {
2821 spin_unlock_irq(&phba->hbalock);
2822 return -EACCES;
2823 }
2824 spin_unlock_irq(&phba->hbalock);
2825 /* count may include a LF at end of string */
2826 if (buf[cnt-1] == '\n')
2827 cnt--;
2828
2829 if (!phba->soft_wwn_enable)
2830 return -EINVAL;
2831
2832 /* lock setting wwpn, wwnn down */
2833 phba->soft_wwn_enable = 0;
2834
2835 rc = lpfc_wwn_set(buf, cnt, wwpn);
James Smarte2934ed2017-01-17 12:31:56 -08002836 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002837 /* not able to set wwpn, unlock it */
2838 phba->soft_wwn_enable = 1;
2839 return rc;
2840 }
2841
2842 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2843 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2844 if (phba->cfg_soft_wwnn)
2845 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2846
2847 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2848 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2849
2850 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2851 if (stat1)
2852 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2853 "0463 lpfc_soft_wwpn attribute set failed to "
2854 "reinit adapter - %d\n", stat1);
2855 init_completion(&online_compl);
2856 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2857 LPFC_EVT_ONLINE);
2858 if (rc == 0)
2859 return -ENOMEM;
2860
2861 wait_for_completion(&online_compl);
2862 if (stat2)
2863 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2864 "0464 lpfc_soft_wwpn attribute set failed to "
2865 "reinit adapter - %d\n", stat2);
2866 return (stat1 || stat2) ? -EIO : count;
2867}
Joe Perchesb6b996b2017-12-19 10:15:07 -08002868static DEVICE_ATTR_RW(lpfc_soft_wwpn);
James Smart352e5fd2016-12-30 06:57:47 -08002869
2870/**
2871 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2872 * @dev: class device that is converted into a Scsi_host.
2873 * @attr: device attribute, not used.
2874 * @buf: on return contains the wwnn in hexadecimal.
2875 *
2876 * Returns: size of formatted string.
2877 **/
2878static ssize_t
2879lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2880 char *buf)
2881{
2882 struct Scsi_Host *shost = class_to_shost(dev);
2883 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2884 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2885 (unsigned long long)phba->cfg_soft_wwnn);
2886}
2887
2888/**
2889 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2890 * @cdev: class device that is converted into a Scsi_host.
2891 * @buf: contains the ww node name in hexadecimal.
2892 * @count: number of wwnn bytes in buf.
2893 *
2894 * Returns:
2895 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2896 * value of count on success
2897 **/
2898static ssize_t
2899lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2900 const char *buf, size_t count)
2901{
2902 struct Scsi_Host *shost = class_to_shost(dev);
2903 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2904 unsigned int cnt = count;
2905 u8 wwnn[WWN_SZ];
2906 int rc;
2907
2908 /* count may include a LF at end of string */
2909 if (buf[cnt-1] == '\n')
2910 cnt--;
2911
2912 if (!phba->soft_wwn_enable)
2913 return -EINVAL;
2914
2915 rc = lpfc_wwn_set(buf, cnt, wwnn);
James Smarte2934ed2017-01-17 12:31:56 -08002916 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002917 /* Allow wwnn to be set many times, as long as the enable
2918 * is set. However, once the wwpn is set, everything locks.
2919 */
2920 return rc;
2921 }
2922
2923 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2924
2925 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2926 "lpfc%d: soft_wwnn set. Value will take effect upon "
2927 "setting of the soft_wwpn\n", phba->brd_no);
2928
2929 return count;
2930}
Joe Perchesb6b996b2017-12-19 10:15:07 -08002931static DEVICE_ATTR_RW(lpfc_soft_wwnn);
James Smarta12e07b2006-12-02 13:35:30 -05002932
James Smart1ba981f2014-02-20 09:56:45 -05002933/**
2934 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2935 * Optimized Access Storage (OAS) operations.
2936 * @dev: class device that is converted into a Scsi_host.
2937 * @attr: device attribute, not used.
2938 * @buf: buffer for passing information.
2939 *
2940 * Returns:
2941 * value of count
2942 **/
2943static ssize_t
2944lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2945 char *buf)
2946{
2947 struct Scsi_Host *shost = class_to_shost(dev);
2948 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2949
2950 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2951 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2952}
2953
2954/**
2955 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2956 * Optimized Access Storage (OAS) operations.
2957 * @dev: class device that is converted into a Scsi_host.
2958 * @attr: device attribute, not used.
2959 * @buf: buffer for passing information.
2960 * @count: Size of the data buffer.
2961 *
2962 * Returns:
2963 * -EINVAL count is invalid, invalid wwpn byte invalid
2964 * -EPERM oas is not supported by hba
2965 * value of count on success
2966 **/
2967static ssize_t
2968lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2969 const char *buf, size_t count)
2970{
2971 struct Scsi_Host *shost = class_to_shost(dev);
2972 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2973 unsigned int cnt = count;
2974 uint8_t wwpn[WWN_SZ];
2975 int rc;
2976
James Smartf38fa0b2014-04-04 13:52:21 -04002977 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002978 return -EPERM;
2979
2980 /* count may include a LF at end of string */
2981 if (buf[cnt-1] == '\n')
2982 cnt--;
2983
2984 rc = lpfc_wwn_set(buf, cnt, wwpn);
2985 if (rc)
2986 return rc;
2987
2988 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2989 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2990 if (wwn_to_u64(wwpn) == 0)
2991 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2992 else
2993 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2994 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2995 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2996 return count;
2997}
2998static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2999 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
3000
3001/**
James Smartc92c8412016-07-06 12:36:05 -07003002 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
3003 * Optimized Access Storage (OAS) operations.
3004 * @dev: class device that is converted into a Scsi_host.
3005 * @attr: device attribute, not used.
3006 * @buf: buffer for passing information.
3007 *
3008 * Returns:
3009 * value of count
3010 **/
3011static ssize_t
3012lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
3013 char *buf)
3014{
3015 struct Scsi_Host *shost = class_to_shost(dev);
3016 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3017
3018 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
3019}
3020
3021/**
3022 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
3023 * Optimized Access Storage (OAS) operations.
3024 * @dev: class device that is converted into a Scsi_host.
3025 * @attr: device attribute, not used.
3026 * @buf: buffer for passing information.
3027 * @count: Size of the data buffer.
3028 *
3029 * Returns:
3030 * -EINVAL count is invalid, invalid wwpn byte invalid
3031 * -EPERM oas is not supported by hba
3032 * value of count on success
3033 **/
3034static ssize_t
3035lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
3036 const char *buf, size_t count)
3037{
3038 struct Scsi_Host *shost = class_to_shost(dev);
3039 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3040 unsigned int cnt = count;
3041 unsigned long val;
3042 int ret;
3043
3044 if (!phba->cfg_fof)
3045 return -EPERM;
3046
3047 /* count may include a LF at end of string */
3048 if (buf[cnt-1] == '\n')
3049 cnt--;
3050
3051 ret = kstrtoul(buf, 0, &val);
3052 if (ret || (val > 0x7f))
3053 return -EINVAL;
3054
3055 if (val)
3056 phba->cfg_oas_priority = (uint8_t)val;
3057 else
3058 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3059 return count;
3060}
3061static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
3062 lpfc_oas_priority_show, lpfc_oas_priority_store);
3063
3064/**
James Smart1ba981f2014-02-20 09:56:45 -05003065 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
3066 * for Optimized Access Storage (OAS) operations.
3067 * @dev: class device that is converted into a Scsi_host.
3068 * @attr: device attribute, not used.
3069 * @buf: buffer for passing information.
3070 *
3071 * Returns:
3072 * value of count on success
3073 **/
3074static ssize_t
3075lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
3076 char *buf)
3077{
3078 struct Scsi_Host *shost = class_to_shost(dev);
3079 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3080
3081 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
3082 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
3083}
3084
3085/**
3086 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
3087 * for Optimized Access Storage (OAS) operations.
3088 * @dev: class device that is converted into a Scsi_host.
3089 * @attr: device attribute, not used.
3090 * @buf: buffer for passing information.
3091 * @count: Size of the data buffer.
3092 *
3093 * Returns:
3094 * -EINVAL count is invalid, invalid wwpn byte invalid
3095 * -EPERM oas is not supported by hba
3096 * value of count on success
3097 **/
3098static ssize_t
3099lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
3100 const char *buf, size_t count)
3101{
3102 struct Scsi_Host *shost = class_to_shost(dev);
3103 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3104 unsigned int cnt = count;
3105 uint8_t wwpn[WWN_SZ];
3106 int rc;
3107
James Smartf38fa0b2014-04-04 13:52:21 -04003108 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003109 return -EPERM;
3110
3111 /* count may include a LF at end of string */
3112 if (buf[cnt-1] == '\n')
3113 cnt--;
3114
3115 rc = lpfc_wwn_set(buf, cnt, wwpn);
3116 if (rc)
3117 return rc;
3118
3119 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3120 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3121 if (wwn_to_u64(wwpn) == 0)
3122 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
3123 else
3124 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
3125 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
James Smartb5749fe2016-12-19 15:07:26 -08003126 if (phba->cfg_oas_priority == 0)
3127 phba->cfg_oas_priority = phba->cfg_XLanePriority;
James Smart1ba981f2014-02-20 09:56:45 -05003128 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3129 return count;
3130}
3131static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
3132 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
3133
3134/**
3135 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
3136 * of whether luns will be enabled or disabled
3137 * for Optimized Access Storage (OAS) operations.
3138 * @dev: class device that is converted into a Scsi_host.
3139 * @attr: device attribute, not used.
3140 * @buf: buffer for passing information.
3141 *
3142 * Returns:
3143 * size of formatted string.
3144 **/
3145static ssize_t
3146lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
3147 char *buf)
3148{
3149 struct Scsi_Host *shost = class_to_shost(dev);
3150 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3151
3152 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
3153}
3154
3155/**
3156 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
3157 * of whether luns will be enabled or disabled
3158 * for Optimized Access Storage (OAS) operations.
3159 * @dev: class device that is converted into a Scsi_host.
3160 * @attr: device attribute, not used.
3161 * @buf: buffer for passing information.
3162 * @count: Size of the data buffer.
3163 *
3164 * Returns:
3165 * -EINVAL count is invalid, invalid wwpn byte invalid
3166 * -EPERM oas is not supported by hba
3167 * value of count on success
3168 **/
3169static ssize_t
3170lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
3171 const char *buf, size_t count)
3172{
3173 struct Scsi_Host *shost = class_to_shost(dev);
3174 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3175 int val = 0;
3176
James Smartf38fa0b2014-04-04 13:52:21 -04003177 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003178 return -EPERM;
3179
3180 if (!isdigit(buf[0]))
3181 return -EINVAL;
3182
3183 if (sscanf(buf, "%i", &val) != 1)
3184 return -EINVAL;
3185
3186 if ((val != 0) && (val != 1))
3187 return -EINVAL;
3188
3189 phba->cfg_oas_lun_state = val;
James Smart1ba981f2014-02-20 09:56:45 -05003190 return strlen(buf);
3191}
3192static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
3193 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
3194
3195/**
3196 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
3197 * Storage (OAS) lun returned by the
3198 * lpfc_oas_lun_show function.
3199 * @dev: class device that is converted into a Scsi_host.
3200 * @attr: device attribute, not used.
3201 * @buf: buffer for passing information.
3202 *
3203 * Returns:
3204 * size of formatted string.
3205 **/
3206static ssize_t
3207lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
3208 char *buf)
3209{
3210 struct Scsi_Host *shost = class_to_shost(dev);
3211 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3212
3213 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
3214 return -EFAULT;
3215
3216 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
3217}
3218static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
3219 lpfc_oas_lun_status_show, NULL);
3220
3221
3222/**
3223 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
3224 * (OAS) operations.
3225 * @phba: lpfc_hba pointer.
3226 * @ndlp: pointer to fcp target node.
3227 * @lun: the fc lun for setting oas state.
3228 * @oas_state: the oas state to be set to the lun.
3229 *
3230 * Returns:
3231 * SUCCESS : 0
3232 * -EPERM OAS is not enabled or not supported by this port.
3233 *
3234 */
3235static size_t
3236lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartc92c8412016-07-06 12:36:05 -07003237 uint8_t tgt_wwpn[], uint64_t lun,
3238 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05003239{
3240
3241 int rc = 0;
3242
James Smartf38fa0b2014-04-04 13:52:21 -04003243 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003244 return -EPERM;
3245
3246 if (oas_state) {
3247 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07003248 (struct lpfc_name *)tgt_wwpn,
3249 lun, pri))
James Smart1ba981f2014-02-20 09:56:45 -05003250 rc = -ENOMEM;
3251 } else {
3252 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08003253 (struct lpfc_name *)tgt_wwpn, lun, pri);
James Smart1ba981f2014-02-20 09:56:45 -05003254 }
3255 return rc;
3256
3257}
3258
3259/**
3260 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
3261 * Access Storage (OAS) operations.
3262 * @phba: lpfc_hba pointer.
3263 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3264 * @tgt_wwpn: wwpn of the target associated with the returned lun
3265 * @lun_status: status of the lun returned lun
3266 *
3267 * Returns the first or next lun enabled for OAS operations for the vport/target
3268 * specified. If a lun is found, its vport wwpn, target wwpn and status is
3269 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
3270 *
3271 * Return:
3272 * lun that is OAS enabled for the vport/target
3273 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
3274 */
3275static uint64_t
3276lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartb5749fe2016-12-19 15:07:26 -08003277 uint8_t tgt_wwpn[], uint32_t *lun_status,
3278 uint32_t *lun_pri)
James Smart1ba981f2014-02-20 09:56:45 -05003279{
3280 uint64_t found_lun;
3281
3282 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
3283 return NOT_OAS_ENABLED_LUN;
3284 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
3285 phba->sli4_hba.oas_next_vpt_wwpn,
3286 (struct lpfc_name *)
3287 phba->sli4_hba.oas_next_tgt_wwpn,
3288 &phba->sli4_hba.oas_next_lun,
3289 (struct lpfc_name *)vpt_wwpn,
3290 (struct lpfc_name *)tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08003291 &found_lun, lun_status, lun_pri))
James Smart1ba981f2014-02-20 09:56:45 -05003292 return found_lun;
3293 else
3294 return NOT_OAS_ENABLED_LUN;
3295}
3296
3297/**
3298 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
3299 * @phba: lpfc_hba pointer.
3300 * @vpt_wwpn: vport wwpn by reference.
3301 * @tgt_wwpn: target wwpn by reference.
3302 * @lun: the fc lun for setting oas state.
3303 * @oas_state: the oas state to be set to the oas_lun.
3304 *
3305 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
3306 * a lun for OAS operations.
3307 *
3308 * Return:
3309 * SUCCESS: 0
3310 * -ENOMEM: failed to enable an lun for OAS operations
3311 * -EPERM: OAS is not enabled
3312 */
3313static ssize_t
3314lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3315 uint8_t tgt_wwpn[], uint64_t lun,
James Smartc92c8412016-07-06 12:36:05 -07003316 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05003317{
3318
3319 int rc;
3320
3321 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
James Smartc92c8412016-07-06 12:36:05 -07003322 oas_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05003323 return rc;
3324}
3325
3326/**
3327 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
3328 * @dev: class device that is converted into a Scsi_host.
3329 * @attr: device attribute, not used.
3330 * @buf: buffer for passing information.
3331 *
3332 * This routine returns a lun enabled for OAS each time the function
3333 * is called.
3334 *
3335 * Returns:
3336 * SUCCESS: size of formatted string.
3337 * -EFAULT: target or vport wwpn was not set properly.
3338 * -EPERM: oas is not enabled.
3339 **/
3340static ssize_t
3341lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3342 char *buf)
3343{
3344 struct Scsi_Host *shost = class_to_shost(dev);
3345 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3346
3347 uint64_t oas_lun;
3348 int len = 0;
3349
James Smartf38fa0b2014-04-04 13:52:21 -04003350 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003351 return -EPERM;
3352
3353 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3354 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3355 return -EFAULT;
3356
3357 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3358 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3359 return -EFAULT;
3360
3361 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3362 phba->cfg_oas_tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08003363 &phba->cfg_oas_lun_status,
3364 &phba->cfg_oas_priority);
James Smart1ba981f2014-02-20 09:56:45 -05003365 if (oas_lun != NOT_OAS_ENABLED_LUN)
3366 phba->cfg_oas_flags |= OAS_LUN_VALID;
3367
3368 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3369
3370 return len;
3371}
3372
3373/**
3374 * lpfc_oas_lun_store - Sets the OAS state for lun
3375 * @dev: class device that is converted into a Scsi_host.
3376 * @attr: device attribute, not used.
3377 * @buf: buffer for passing information.
3378 *
3379 * This function sets the OAS state for lun. Before this function is called,
3380 * the vport wwpn, target wwpn, and oas state need to be set.
3381 *
3382 * Returns:
3383 * SUCCESS: size of formatted string.
3384 * -EFAULT: target or vport wwpn was not set properly.
3385 * -EPERM: oas is not enabled.
3386 * size of formatted string.
3387 **/
3388static ssize_t
3389lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3390 const char *buf, size_t count)
3391{
3392 struct Scsi_Host *shost = class_to_shost(dev);
3393 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3394 uint64_t scsi_lun;
James Smartb5749fe2016-12-19 15:07:26 -08003395 uint32_t pri;
James Smart1ba981f2014-02-20 09:56:45 -05003396 ssize_t rc;
3397
James Smartf38fa0b2014-04-04 13:52:21 -04003398 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003399 return -EPERM;
3400
3401 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3402 return -EFAULT;
3403
3404 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3405 return -EFAULT;
3406
3407 if (!isdigit(buf[0]))
3408 return -EINVAL;
3409
3410 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3411 return -EINVAL;
3412
James Smartb5749fe2016-12-19 15:07:26 -08003413 pri = phba->cfg_oas_priority;
3414 if (pri == 0)
3415 pri = phba->cfg_XLanePriority;
3416
James Smart1ba981f2014-02-20 09:56:45 -05003417 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartc92c8412016-07-06 12:36:05 -07003418 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3419 "priority 0x%x with oas state %d\n",
James Smart1ba981f2014-02-20 09:56:45 -05003420 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3421 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08003422 pri, phba->cfg_oas_lun_state);
James Smart1ba981f2014-02-20 09:56:45 -05003423
3424 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07003425 phba->cfg_oas_tgt_wwpn, scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08003426 phba->cfg_oas_lun_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05003427 if (rc)
3428 return rc;
3429
3430 return count;
3431}
3432static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3433 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04003434
James Smartf358dd02017-02-12 13:52:34 -08003435int lpfc_enable_nvmet_cnt;
3436unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3437 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3438 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3439module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3440MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3441
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003442static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05003443module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003444MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3445 " 0 - none,"
3446 " 1 - poll with interrupts enabled"
3447 " 3 - poll and disable FCP ring interrupts");
3448
Joe Perchesb6b996b2017-12-19 10:15:07 -08003449static DEVICE_ATTR_RW(lpfc_poll);
dea31012005-04-17 16:05:31 -05003450
James Smart96418b52017-03-04 09:30:31 -08003451int lpfc_no_hba_reset_cnt;
3452unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3453 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3454module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3455MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3456
James Smart12247e82016-07-06 12:36:09 -07003457LPFC_ATTR(sli_mode, 0, 0, 3,
3458 "SLI mode selector:"
3459 " 0 - auto (SLI-3 if supported),"
3460 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3461 " 3 - select SLI-3");
James Smart92d7f7b2007-06-17 19:56:38 -05003462
James Smart458c0832016-07-06 12:36:07 -07003463LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3464 "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05003465
James Smart7d791df2011-07-22 18:37:52 -04003466LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3467 "FCF Fast failover=1 Priority failover=2");
3468
James Smarte5771b42013-03-01 16:37:14 -05003469/*
3470# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3471# 0x0 = disabled, XRI/OXID use not tracked.
3472# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3473# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3474*/
James Smart31202b02016-10-13 15:06:08 -07003475LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3476 "Enable RRQ functionality");
James Smart19ca7602010-11-20 23:11:55 -05003477
dea31012005-04-17 16:05:31 -05003478/*
James Smart84d1b002010-02-12 14:42:33 -05003479# lpfc_suppress_link_up: Bring link up at initialization
3480# 0x0 = bring link up (issue MBX_INIT_LINK)
3481# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3482# 0x2 = never bring up link
3483# Default value is 0.
3484*/
James Smarte40a02c2010-02-26 14:13:54 -05003485LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3486 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3487 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04003488/*
3489# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3490# 1 - (1024)
3491# 2 - (2048)
3492# 3 - (3072)
3493# 4 - (4096)
3494# 5 - (5120)
3495*/
3496static ssize_t
3497lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3498{
3499 struct Scsi_Host *shost = class_to_shost(dev);
3500 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3501
3502 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3503}
3504
3505static DEVICE_ATTR(iocb_hw, S_IRUGO,
3506 lpfc_iocb_hw_show, NULL);
3507static ssize_t
3508lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3509{
3510 struct Scsi_Host *shost = class_to_shost(dev);
3511 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003512 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003513
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003514 return snprintf(buf, PAGE_SIZE, "%d\n",
3515 pring ? pring->txq_max : 0);
James Smart2a9bf3d2010-06-07 15:24:45 -04003516}
3517
3518static DEVICE_ATTR(txq_hw, S_IRUGO,
3519 lpfc_txq_hw_show, NULL);
3520static ssize_t
3521lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3522 char *buf)
3523{
3524 struct Scsi_Host *shost = class_to_shost(dev);
3525 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003526 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003527
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003528 return snprintf(buf, PAGE_SIZE, "%d\n",
3529 pring ? pring->txcmplq_max : 0);
James Smart2a9bf3d2010-06-07 15:24:45 -04003530}
3531
3532static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3533 lpfc_txcmplq_hw_show, NULL);
3534
James Smart0d8c8ba2016-10-13 15:06:07 -07003535LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
James Smart2a9bf3d2010-06-07 15:24:45 -04003536 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
James Smart84d1b002010-02-12 14:42:33 -05003537
3538/*
James Smartc01f3202006-08-18 17:47:08 -04003539# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3540# until the timer expires. Value range is [0,255]. Default value is 30.
3541*/
3542static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3543static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3544module_param(lpfc_nodev_tmo, int, 0);
3545MODULE_PARM_DESC(lpfc_nodev_tmo,
3546 "Seconds driver will hold I/O waiting "
3547 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04003548
3549/**
James Smart3621a712009-04-06 18:47:14 -04003550 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04003551 * @dev: class converted to a Scsi_host structure.
3552 * @attr: device attribute, not used.
3553 * @buf: on return contains the dev loss timeout in decimal.
3554 *
3555 * Returns: size of formatted string.
3556 **/
James Smartc01f3202006-08-18 17:47:08 -04003557static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003558lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3559 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04003560{
Tony Jonesee959b02008-02-22 00:13:36 +01003561 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003562 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05003563
James Smart3de2a652007-08-02 11:09:59 -04003564 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003565}
3566
James Smarte59058c2008-08-24 21:49:00 -04003567/**
James Smart3621a712009-04-06 18:47:14 -04003568 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04003569 * @vport: lpfc vport structure pointer.
3570 * @val: contains the nodev timeout value.
3571 *
3572 * Description:
3573 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3574 * a kernel error message is printed and zero is returned.
3575 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3576 * Otherwise nodev tmo is set to the default value.
3577 *
3578 * Returns:
3579 * zero if already set or if val is in range
3580 * -EINVAL val out of range
3581 **/
James Smartc01f3202006-08-18 17:47:08 -04003582static int
James Smart3de2a652007-08-02 11:09:59 -04003583lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003584{
James Smart3de2a652007-08-02 11:09:59 -04003585 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3586 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3587 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04003588 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003589 "0407 Ignoring lpfc_nodev_tmo module "
3590 "parameter because lpfc_devloss_tmo "
3591 "is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003592 return 0;
3593 }
3594
3595 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003596 vport->cfg_nodev_tmo = val;
3597 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04003598 return 0;
3599 }
James Smarte8b62012007-08-02 11:10:09 -04003600 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3601 "0400 lpfc_nodev_tmo attribute cannot be set to"
3602 " %d, allowed range is [%d, %d]\n",
3603 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04003604 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04003605 return -EINVAL;
3606}
3607
James Smarte59058c2008-08-24 21:49:00 -04003608/**
James Smart3621a712009-04-06 18:47:14 -04003609 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04003610 * @vport: lpfc vport structure pointer.
3611 *
3612 * Description:
3613 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3614 **/
James Smart7054a602007-04-25 09:52:34 -04003615static void
James Smart3de2a652007-08-02 11:09:59 -04003616lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04003617{
James Smart858c9f62007-06-17 19:56:39 -05003618 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04003619 struct lpfc_nodelist *ndlp;
James Smart01466022018-04-09 14:24:27 -07003620#if (IS_ENABLED(CONFIG_NVME_FC))
3621 struct lpfc_nvme_rport *rport;
James Smart9e210172018-09-13 15:41:10 -07003622 struct nvme_fc_remote_port *remoteport = NULL;
James Smart01466022018-04-09 14:24:27 -07003623#endif
James Smart7054a602007-04-25 09:52:34 -04003624
James Smart51ef4c22007-08-02 11:10:31 -04003625 shost = lpfc_shost_from_vport(vport);
3626 spin_lock_irq(shost->host_lock);
James Smart7a06dcd2017-06-01 21:06:55 -07003627 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3628 if (!NLP_CHK_NODE_ACT(ndlp))
3629 continue;
3630 if (ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04003631 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
James Smart6ddcf0a2017-11-03 09:33:30 -07003632#if (IS_ENABLED(CONFIG_NVME_FC))
James Smart9e210172018-09-13 15:41:10 -07003633 spin_lock(&vport->phba->hbalock);
James Smart01466022018-04-09 14:24:27 -07003634 rport = lpfc_ndlp_get_nrport(ndlp);
3635 if (rport)
James Smart9e210172018-09-13 15:41:10 -07003636 remoteport = rport->remoteport;
3637 spin_unlock(&vport->phba->hbalock);
3638 if (remoteport)
James Smart01466022018-04-09 14:24:27 -07003639 nvme_fc_set_remoteport_devloss(rport->remoteport,
James Smart6ddcf0a2017-11-03 09:33:30 -07003640 vport->cfg_devloss_tmo);
3641#endif
James Smart7a06dcd2017-06-01 21:06:55 -07003642 }
James Smart51ef4c22007-08-02 11:10:31 -04003643 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04003644}
3645
James Smarte59058c2008-08-24 21:49:00 -04003646/**
James Smart3621a712009-04-06 18:47:14 -04003647 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04003648 * @vport: lpfc vport structure pointer.
3649 * @val: contains the tmo value.
3650 *
3651 * Description:
3652 * If the devloss tmo is already set or the vport dev loss tmo has changed
3653 * then a kernel error message is printed and zero is returned.
3654 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3655 * Otherwise nodev tmo is set to the default value.
3656 *
3657 * Returns:
3658 * zero if already set or if val is in range
3659 * -EINVAL val out of range
3660 **/
James Smartc01f3202006-08-18 17:47:08 -04003661static int
James Smart3de2a652007-08-02 11:09:59 -04003662lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003663{
James Smart3de2a652007-08-02 11:09:59 -04003664 if (vport->dev_loss_tmo_changed ||
3665 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04003666 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003667 "0401 Ignoring change to lpfc_nodev_tmo "
3668 "because lpfc_devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003669 return 0;
3670 }
James Smartc01f3202006-08-18 17:47:08 -04003671 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003672 vport->cfg_nodev_tmo = val;
3673 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05003674 /*
3675 * For compat: set the fc_host dev loss so new rports
3676 * will get the value.
3677 */
3678 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003679 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003680 return 0;
3681 }
James Smarte8b62012007-08-02 11:10:09 -04003682 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003683 "0403 lpfc_nodev_tmo attribute cannot be set to "
James Smarte8b62012007-08-02 11:10:09 -04003684 "%d, allowed range is [%d, %d]\n",
3685 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003686 return -EINVAL;
3687}
3688
James Smart3de2a652007-08-02 11:09:59 -04003689lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04003690
Joe Perchesb6b996b2017-12-19 10:15:07 -08003691static DEVICE_ATTR_RW(lpfc_nodev_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003692
3693/*
3694# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3695# disappear until the timer expires. Value range is [0,255]. Default
3696# value is 30.
3697*/
James Smartab56dc22011-02-16 12:39:57 -05003698module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04003699MODULE_PARM_DESC(lpfc_devloss_tmo,
3700 "Seconds driver will hold I/O waiting "
3701 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04003702lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3703 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3704lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04003705
3706/**
James Smart3621a712009-04-06 18:47:14 -04003707 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04003708 * @vport: lpfc vport structure pointer.
3709 * @val: contains the tmo value.
3710 *
3711 * Description:
3712 * If val is in a valid range then set the vport nodev tmo,
3713 * devloss tmo, also set the vport dev loss tmo changed flag.
3714 * Else a kernel error message is printed.
3715 *
3716 * Returns:
3717 * zero if val is in range
3718 * -EINVAL val out of range
3719 **/
James Smartc01f3202006-08-18 17:47:08 -04003720static int
James Smart3de2a652007-08-02 11:09:59 -04003721lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003722{
3723 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003724 vport->cfg_nodev_tmo = val;
3725 vport->cfg_devloss_tmo = val;
3726 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05003727 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003728 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003729 return 0;
3730 }
3731
James Smarte8b62012007-08-02 11:10:09 -04003732 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003733 "0404 lpfc_devloss_tmo attribute cannot be set to "
3734 "%d, allowed range is [%d, %d]\n",
James Smarte8b62012007-08-02 11:10:09 -04003735 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003736 return -EINVAL;
3737}
3738
James Smart3de2a652007-08-02 11:09:59 -04003739lpfc_vport_param_store(devloss_tmo)
Joe Perchesb6b996b2017-12-19 10:15:07 -08003740static DEVICE_ATTR_RW(lpfc_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003741
3742/*
James Smartf358dd02017-02-12 13:52:34 -08003743 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3744 * lpfc_suppress_rsp = 0 Disable
3745 * lpfc_suppress_rsp = 1 Enable (default)
3746 *
3747 */
3748LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3749 "Enable suppress rsp feature is firmware supports it");
3750
3751/*
James Smart2d7dbc42017-02-12 13:52:35 -08003752 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
James Smartbcb24f62017-11-20 16:00:36 -08003753 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
James Smart2d7dbc42017-02-12 13:52:35 -08003754 * lpfc_nvmet_mrq = 1 use a single RQ pair
3755 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3756 *
3757 */
3758LPFC_ATTR_R(nvmet_mrq,
James Smartbcb24f62017-11-20 16:00:36 -08003759 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
James Smart2d7dbc42017-02-12 13:52:35 -08003760 "Specify number of RQ pairs for processing NVMET cmds");
3761
3762/*
James Smart2448e482018-04-09 14:24:24 -07003763 * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post
3764 * to each NVMET RQ. Range 64 to 2048, default is 512.
3765 */
3766LPFC_ATTR_R(nvmet_mrq_post,
3767 LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,
3768 LPFC_NVMET_RQE_DEF_COUNT,
3769 "Specify number of RQ buffers to initially post");
3770
3771/*
James Smart895427b2017-02-12 13:52:30 -08003772 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3773 * Supported Values: 1 - register just FCP
3774 * 3 - register both FCP and NVME
James Smartb1684a02019-01-28 11:14:36 -08003775 * Supported values are [1,3]. Default value is 3
James Smart895427b2017-02-12 13:52:30 -08003776 */
James Smartb1684a02019-01-28 11:14:36 -08003777LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_BOTH,
James Smart895427b2017-02-12 13:52:30 -08003778 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
Dick Kennedycf4c8c82017-09-29 17:34:38 -07003779 "Enable FC4 Protocol support - FCP / NVME");
James Smart895427b2017-02-12 13:52:30 -08003780
3781/*
dea31012005-04-17 16:05:31 -05003782# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3783# deluged with LOTS of information.
3784# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04003785# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05003786*/
James Smartf4b4c682009-05-22 14:53:12 -04003787LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04003788 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05003789
3790/*
James Smart7ee5d432007-10-27 13:37:17 -04003791# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3792# objects that have been registered with the nameserver after login.
3793*/
James Smartcf971242012-03-01 22:37:32 -05003794LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04003795 "Deregister nameserver objects before LOGO");
3796
3797/*
dea31012005-04-17 16:05:31 -05003798# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04003799# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3800# If this parameter value is greater than 1/8th the maximum number of exchanges
3801# supported by the HBA port, then the lun queue depth will be reduced to
3802# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05003803*/
James Smart572709e2013-07-15 18:32:43 -04003804LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04003805 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05003806
3807/*
James Smart7dc517d2010-07-14 15:32:10 -04003808# tgt_queue_depth: This parameter is used to limit the number of outstanding
3809# commands per target port. Value range is [10,65535]. Default value is 65535.
3810*/
James Smartf91bc592018-04-09 14:24:22 -07003811static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
3812module_param(lpfc_tgt_queue_depth, uint, 0444);
3813MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
3814lpfc_vport_param_show(tgt_queue_depth);
3815lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
3816 LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
3817
3818/**
3819 * lpfc_tgt_queue_depth_store: Sets an attribute value.
3820 * @phba: pointer the the adapter structure.
3821 * @val: integer attribute value.
3822 *
3823 * Description: Sets the parameter to the new value.
3824 *
3825 * Returns:
3826 * zero on success
3827 * -EINVAL if val is invalid
3828 */
3829static int
3830lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
3831{
3832 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3833 struct lpfc_nodelist *ndlp;
3834
3835 if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
3836 return -EINVAL;
3837
3838 if (val == vport->cfg_tgt_queue_depth)
3839 return 0;
3840
3841 spin_lock_irq(shost->host_lock);
3842 vport->cfg_tgt_queue_depth = val;
3843
3844 /* Next loop thru nodelist and change cmd_qdepth */
3845 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3846 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3847
3848 spin_unlock_irq(shost->host_lock);
3849 return 0;
3850}
3851
3852lpfc_vport_param_store(tgt_queue_depth);
3853static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04003854
3855/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003856# hba_queue_depth: This parameter is used to limit the number of outstanding
3857# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3858# value is greater than the maximum number of exchanges supported by the HBA,
3859# then maximum number of exchanges supported by the HBA is used to determine
3860# the hba_queue_depth.
3861*/
3862LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3863 "Max number of FCP commands we can queue to a lpfc HBA");
3864
3865/*
James Smart92d7f7b2007-06-17 19:56:38 -05003866# peer_port_login: This parameter allows/prevents logins
3867# between peer ports hosted on the same physical port.
3868# When this parameter is set 0 peer ports of same physical port
3869# are not allowed to login to each other.
3870# When this parameter is set 1 peer ports of same physical port
3871# are allowed to login to each other.
3872# Default value of this parameter is 0.
3873*/
James Smart3de2a652007-08-02 11:09:59 -04003874LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3875 "Allow peer ports on the same physical port to login to each "
3876 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05003877
3878/*
James Smart3de2a652007-08-02 11:09:59 -04003879# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05003880# between Virtual Ports and remote initiators.
3881# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3882# other initiators and will attempt to PLOGI all remote ports.
3883# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3884# remote ports and will not attempt to PLOGI to other initiators.
3885# This parameter does not restrict to the physical port.
3886# This parameter does not restrict logins to Fabric resident remote ports.
3887# Default value of this parameter is 1.
3888*/
James Smart3de2a652007-08-02 11:09:59 -04003889static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05003890module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04003891MODULE_PARM_DESC(lpfc_restrict_login,
3892 "Restrict virtual ports login to remote initiators.");
3893lpfc_vport_param_show(restrict_login);
3894
James Smarte59058c2008-08-24 21:49:00 -04003895/**
James Smart3621a712009-04-06 18:47:14 -04003896 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003897 * @vport: lpfc vport structure pointer.
3898 * @val: contains the restrict login value.
3899 *
3900 * Description:
3901 * If val is not in a valid range then log a kernel error message and set
3902 * the vport restrict login to one.
3903 * If the port type is physical clear the restrict login flag and return.
3904 * Else set the restrict login flag to val.
3905 *
3906 * Returns:
3907 * zero if val is in range
3908 * -EINVAL val out of range
3909 **/
James Smart3de2a652007-08-02 11:09:59 -04003910static int
3911lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3912{
3913 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003914 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003915 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003916 "be set to %d, allowed range is [0, 1]\n",
3917 val);
James Smart3de2a652007-08-02 11:09:59 -04003918 vport->cfg_restrict_login = 1;
3919 return -EINVAL;
3920 }
3921 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3922 vport->cfg_restrict_login = 0;
3923 return 0;
3924 }
3925 vport->cfg_restrict_login = val;
3926 return 0;
3927}
3928
James Smarte59058c2008-08-24 21:49:00 -04003929/**
James Smart3621a712009-04-06 18:47:14 -04003930 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003931 * @vport: lpfc vport structure pointer.
3932 * @val: contains the restrict login value.
3933 *
3934 * Description:
3935 * If val is not in a valid range then log a kernel error message and set
3936 * the vport restrict login to one.
3937 * If the port type is physical and the val is not zero log a kernel
3938 * error message, clear the restrict login flag and return zero.
3939 * Else set the restrict login flag to val.
3940 *
3941 * Returns:
3942 * zero if val is in range
3943 * -EINVAL val out of range
3944 **/
James Smart3de2a652007-08-02 11:09:59 -04003945static int
3946lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3947{
3948 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003949 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003950 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003951 "be set to %d, allowed range is [0, 1]\n",
3952 val);
James Smart3de2a652007-08-02 11:09:59 -04003953 vport->cfg_restrict_login = 1;
3954 return -EINVAL;
3955 }
3956 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04003957 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3958 "0468 lpfc_restrict_login must be 0 for "
3959 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04003960 vport->cfg_restrict_login = 0;
3961 return 0;
3962 }
3963 vport->cfg_restrict_login = val;
3964 return 0;
3965}
3966lpfc_vport_param_store(restrict_login);
Joe Perchesb6b996b2017-12-19 10:15:07 -08003967static DEVICE_ATTR_RW(lpfc_restrict_login);
James Smart92d7f7b2007-06-17 19:56:38 -05003968
3969/*
dea31012005-04-17 16:05:31 -05003970# Some disk devices have a "select ID" or "select Target" capability.
3971# From a protocol standpoint "select ID" usually means select the
3972# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3973# annex" which contains a table that maps a "select ID" (a number
3974# between 0 and 7F) to an ALPA. By default, for compatibility with
3975# older drivers, the lpfc driver scans this table from low ALPA to high
3976# ALPA.
3977#
3978# Turning on the scan-down variable (on = 1, off = 0) will
3979# cause the lpfc driver to use an inverted table, effectively
3980# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3981#
3982# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3983# and will not work across a fabric. Also this parameter will take
3984# effect only in the case when ALPA map is not available.)
3985*/
James Smart3de2a652007-08-02 11:09:59 -04003986LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3987 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05003988
3989/*
dea31012005-04-17 16:05:31 -05003990# lpfc_topology: link topology for init link
3991# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05003992# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05003993# 0x02 = attempt point-to-point mode only
3994# 0x04 = attempt loop mode only
3995# 0x06 = attempt point-to-point mode then loop
3996# Set point-to-point mode if you want to run as an N_Port.
3997# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3998# Default value is 0.
3999*/
James Smart0a035432016-10-13 15:06:10 -07004000LPFC_ATTR(topology, 0, 0, 6,
4001 "Select Fibre Channel topology");
James Smarte59058c2008-08-24 21:49:00 -04004002
4003/**
James Smart3621a712009-04-06 18:47:14 -04004004 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04004005 * @phba: lpfc_hba pointer.
4006 * @val: topology value.
4007 *
4008 * Description:
4009 * If val is in a valid range then set the adapter's topology field and
4010 * issue a lip; if the lip fails reset the topology to the old value.
4011 *
4012 * If the value is not in range log a kernel error message and return an error.
4013 *
4014 * Returns:
4015 * zero if val is in range and lip okay
4016 * non-zero return value from lpfc_issue_lip()
4017 * -EINVAL val out of range
4018 **/
James Smarta257bf92009-04-06 18:48:10 -04004019static ssize_t
4020lpfc_topology_store(struct device *dev, struct device_attribute *attr,
4021 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05004022{
James Smarta257bf92009-04-06 18:48:10 -04004023 struct Scsi_Host *shost = class_to_shost(dev);
4024 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4025 struct lpfc_hba *phba = vport->phba;
4026 int val = 0;
4027 int nolip = 0;
4028 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05004029 int err;
4030 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04004031
4032 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4033 nolip = 1;
4034 val_buf = &buf[strlen("nolip ")];
4035 }
4036
4037 if (!isdigit(val_buf[0]))
4038 return -EINVAL;
4039 if (sscanf(val_buf, "%i", &val) != 1)
4040 return -EINVAL;
4041
James Smart83108bd2008-01-11 01:53:09 -05004042 if (val >= 0 && val <= 6) {
4043 prev_val = phba->cfg_topology;
James Smartff78d8f2011-12-13 13:21:35 -05004044 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
4045 val == 4) {
4046 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4047 "3113 Loop mode not supported at speed %d\n",
James Smartd38dd522015-08-31 16:48:17 -04004048 val);
James Smartff78d8f2011-12-13 13:21:35 -05004049 return -EINVAL;
4050 }
James Smart76558b22018-11-29 16:09:38 -08004051 if ((phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC ||
4052 phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC) &&
4053 val == 4) {
James Smartd38dd522015-08-31 16:48:17 -04004054 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4055 "3114 Loop mode not supported\n");
4056 return -EINVAL;
4057 }
4058 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04004059 if (nolip)
4060 return strlen(buf);
4061
James Smart88a2cfb2011-07-22 18:36:33 -04004062 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4063 "3054 lpfc_topology changed from %d to %d\n",
4064 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04004065 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
4066 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05004067 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04004068 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05004069 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04004070 return -EINVAL;
4071 } else
4072 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05004073 }
4074 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4075 "%d:0467 lpfc_topology attribute cannot be set to %d, "
4076 "allowed range is [0, 6]\n",
4077 phba->brd_no, val);
4078 return -EINVAL;
4079}
James Smart0a035432016-10-13 15:06:10 -07004080
James Smart83108bd2008-01-11 01:53:09 -05004081lpfc_param_show(topology)
Joe Perchesb6b996b2017-12-19 10:15:07 -08004082static DEVICE_ATTR_RW(lpfc_topology);
dea31012005-04-17 16:05:31 -05004083
James Smart21e9a0a2009-05-22 14:53:21 -04004084/**
4085 * lpfc_static_vport_show: Read callback function for
4086 * lpfc_static_vport sysfs file.
4087 * @dev: Pointer to class device object.
4088 * @attr: device attribute structure.
4089 * @buf: Data buffer.
4090 *
4091 * This function is the read call back function for
4092 * lpfc_static_vport sysfs file. The lpfc_static_vport
4093 * sysfs file report the mageability of the vport.
4094 **/
4095static ssize_t
4096lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
4097 char *buf)
4098{
4099 struct Scsi_Host *shost = class_to_shost(dev);
4100 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4101 if (vport->vport_flag & STATIC_VPORT)
4102 sprintf(buf, "1\n");
4103 else
4104 sprintf(buf, "0\n");
4105
4106 return strlen(buf);
4107}
4108
4109/*
4110 * Sysfs attribute to control the statistical data collection.
4111 */
Joe Perchesc828a892017-12-19 10:15:08 -08004112static DEVICE_ATTR_RO(lpfc_static_vport);
James Smartea2151b2008-09-07 11:52:10 -04004113
4114/**
James Smart3621a712009-04-06 18:47:14 -04004115 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04004116 * @dev: Pointer to class device.
4117 * @buf: Data buffer.
4118 * @count: Size of the data buffer.
4119 *
Masahiro Yamada9332ef92017-02-27 14:28:47 -08004120 * This function get called when a user write to the lpfc_stat_data_ctrl
James Smartea2151b2008-09-07 11:52:10 -04004121 * sysfs file. This function parse the command written to the sysfs file
4122 * and take appropriate action. These commands are used for controlling
4123 * driver statistical data collection.
4124 * Following are the command this function handles.
4125 *
4126 * setbucket <bucket_type> <base> <step>
4127 * = Set the latency buckets.
4128 * destroybucket = destroy all the buckets.
4129 * start = start data collection
4130 * stop = stop data collection
4131 * reset = reset the collected data
4132 **/
4133static ssize_t
4134lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
4135 const char *buf, size_t count)
4136{
4137 struct Scsi_Host *shost = class_to_shost(dev);
4138 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4139 struct lpfc_hba *phba = vport->phba;
4140#define LPFC_MAX_DATA_CTRL_LEN 1024
4141 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
4142 unsigned long i;
4143 char *str_ptr, *token;
4144 struct lpfc_vport **vports;
4145 struct Scsi_Host *v_shost;
4146 char *bucket_type_str, *base_str, *step_str;
4147 unsigned long base, step, bucket_type;
4148
4149 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04004150 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04004151 return -EINVAL;
4152
James Smarteb016562014-09-03 12:58:06 -04004153 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
James Smartea2151b2008-09-07 11:52:10 -04004154 str_ptr = &bucket_data[0];
4155 /* Ignore this token - this is command token */
4156 token = strsep(&str_ptr, "\t ");
4157 if (!token)
4158 return -EINVAL;
4159
4160 bucket_type_str = strsep(&str_ptr, "\t ");
4161 if (!bucket_type_str)
4162 return -EINVAL;
4163
4164 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
4165 bucket_type = LPFC_LINEAR_BUCKET;
4166 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
4167 bucket_type = LPFC_POWER2_BUCKET;
4168 else
4169 return -EINVAL;
4170
4171 base_str = strsep(&str_ptr, "\t ");
4172 if (!base_str)
4173 return -EINVAL;
4174 base = simple_strtoul(base_str, NULL, 0);
4175
4176 step_str = strsep(&str_ptr, "\t ");
4177 if (!step_str)
4178 return -EINVAL;
4179 step = simple_strtoul(step_str, NULL, 0);
4180 if (!step)
4181 return -EINVAL;
4182
4183 /* Block the data collection for every vport */
4184 vports = lpfc_create_vport_work_array(phba);
4185 if (vports == NULL)
4186 return -ENOMEM;
4187
James Smartf4b4c682009-05-22 14:53:12 -04004188 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04004189 v_shost = lpfc_shost_from_vport(vports[i]);
4190 spin_lock_irq(v_shost->host_lock);
4191 /* Block and reset data collection */
4192 vports[i]->stat_data_blocked = 1;
4193 if (vports[i]->stat_data_enabled)
4194 lpfc_vport_reset_stat_data(vports[i]);
4195 spin_unlock_irq(v_shost->host_lock);
4196 }
4197
4198 /* Set the bucket attributes */
4199 phba->bucket_type = bucket_type;
4200 phba->bucket_base = base;
4201 phba->bucket_step = step;
4202
James Smartf4b4c682009-05-22 14:53:12 -04004203 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04004204 v_shost = lpfc_shost_from_vport(vports[i]);
4205
4206 /* Unblock data collection */
4207 spin_lock_irq(v_shost->host_lock);
4208 vports[i]->stat_data_blocked = 0;
4209 spin_unlock_irq(v_shost->host_lock);
4210 }
4211 lpfc_destroy_vport_work_array(phba, vports);
4212 return strlen(buf);
4213 }
4214
4215 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
4216 vports = lpfc_create_vport_work_array(phba);
4217 if (vports == NULL)
4218 return -ENOMEM;
4219
James Smartf4b4c682009-05-22 14:53:12 -04004220 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04004221 v_shost = lpfc_shost_from_vport(vports[i]);
4222 spin_lock_irq(shost->host_lock);
4223 vports[i]->stat_data_blocked = 1;
4224 lpfc_free_bucket(vport);
4225 vport->stat_data_enabled = 0;
4226 vports[i]->stat_data_blocked = 0;
4227 spin_unlock_irq(shost->host_lock);
4228 }
4229 lpfc_destroy_vport_work_array(phba, vports);
4230 phba->bucket_type = LPFC_NO_BUCKET;
4231 phba->bucket_base = 0;
4232 phba->bucket_step = 0;
4233 return strlen(buf);
4234 }
4235
4236 if (!strncmp(buf, "start", strlen("start"))) {
4237 /* If no buckets configured return error */
4238 if (phba->bucket_type == LPFC_NO_BUCKET)
4239 return -EINVAL;
4240 spin_lock_irq(shost->host_lock);
4241 if (vport->stat_data_enabled) {
4242 spin_unlock_irq(shost->host_lock);
4243 return strlen(buf);
4244 }
4245 lpfc_alloc_bucket(vport);
4246 vport->stat_data_enabled = 1;
4247 spin_unlock_irq(shost->host_lock);
4248 return strlen(buf);
4249 }
4250
4251 if (!strncmp(buf, "stop", strlen("stop"))) {
4252 spin_lock_irq(shost->host_lock);
4253 if (vport->stat_data_enabled == 0) {
4254 spin_unlock_irq(shost->host_lock);
4255 return strlen(buf);
4256 }
4257 lpfc_free_bucket(vport);
4258 vport->stat_data_enabled = 0;
4259 spin_unlock_irq(shost->host_lock);
4260 return strlen(buf);
4261 }
4262
4263 if (!strncmp(buf, "reset", strlen("reset"))) {
4264 if ((phba->bucket_type == LPFC_NO_BUCKET)
4265 || !vport->stat_data_enabled)
4266 return strlen(buf);
4267 spin_lock_irq(shost->host_lock);
4268 vport->stat_data_blocked = 1;
4269 lpfc_vport_reset_stat_data(vport);
4270 vport->stat_data_blocked = 0;
4271 spin_unlock_irq(shost->host_lock);
4272 return strlen(buf);
4273 }
4274 return -EINVAL;
4275}
4276
4277
4278/**
James Smart3621a712009-04-06 18:47:14 -04004279 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04004280 * @dev: Pointer to class device object.
4281 * @buf: Data buffer.
4282 *
4283 * This function is the read call back function for
4284 * lpfc_stat_data_ctrl sysfs file. This function report the
4285 * current statistical data collection state.
4286 **/
4287static ssize_t
4288lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
4289 char *buf)
4290{
4291 struct Scsi_Host *shost = class_to_shost(dev);
4292 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4293 struct lpfc_hba *phba = vport->phba;
4294 int index = 0;
4295 int i;
4296 char *bucket_type;
4297 unsigned long bucket_value;
4298
4299 switch (phba->bucket_type) {
4300 case LPFC_LINEAR_BUCKET:
4301 bucket_type = "linear";
4302 break;
4303 case LPFC_POWER2_BUCKET:
4304 bucket_type = "power2";
4305 break;
4306 default:
4307 bucket_type = "No Bucket";
4308 break;
4309 }
4310
4311 sprintf(&buf[index], "Statistical Data enabled :%d, "
4312 "blocked :%d, Bucket type :%s, Bucket base :%d,"
4313 " Bucket step :%d\nLatency Ranges :",
4314 vport->stat_data_enabled, vport->stat_data_blocked,
4315 bucket_type, phba->bucket_base, phba->bucket_step);
4316 index = strlen(buf);
4317 if (phba->bucket_type != LPFC_NO_BUCKET) {
4318 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4319 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
4320 bucket_value = phba->bucket_base +
4321 phba->bucket_step * i;
4322 else
4323 bucket_value = phba->bucket_base +
4324 (1 << i) * phba->bucket_step;
4325
4326 if (index + 10 > PAGE_SIZE)
4327 break;
4328 sprintf(&buf[index], "%08ld ", bucket_value);
4329 index = strlen(buf);
4330 }
4331 }
4332 sprintf(&buf[index], "\n");
4333 return strlen(buf);
4334}
4335
4336/*
4337 * Sysfs attribute to control the statistical data collection.
4338 */
Joe Perchesb6b996b2017-12-19 10:15:07 -08004339static DEVICE_ATTR_RW(lpfc_stat_data_ctrl);
James Smartea2151b2008-09-07 11:52:10 -04004340
4341/*
4342 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
4343 */
4344
4345/*
4346 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
4347 * for each target.
4348 */
4349#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
4350#define MAX_STAT_DATA_SIZE_PER_TARGET \
4351 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
4352
4353
4354/**
James Smart3621a712009-04-06 18:47:14 -04004355 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07004356 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04004357 * @kobj: Pointer to the kernel object
4358 * @bin_attr: Attribute object
4359 * @buff: Buffer pointer
4360 * @off: File offset
4361 * @count: Buffer size
4362 *
4363 * This function is the read call back function for lpfc_drvr_stat_data
4364 * sysfs file. This function export the statistical data to user
4365 * applications.
4366 **/
4367static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004368sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
4369 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04004370 char *buf, loff_t off, size_t count)
4371{
4372 struct device *dev = container_of(kobj, struct device,
4373 kobj);
4374 struct Scsi_Host *shost = class_to_shost(dev);
4375 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4376 struct lpfc_hba *phba = vport->phba;
4377 int i = 0, index = 0;
4378 unsigned long nport_index;
4379 struct lpfc_nodelist *ndlp = NULL;
4380 nport_index = (unsigned long)off /
4381 MAX_STAT_DATA_SIZE_PER_TARGET;
4382
4383 if (!vport->stat_data_enabled || vport->stat_data_blocked
4384 || (phba->bucket_type == LPFC_NO_BUCKET))
4385 return 0;
4386
4387 spin_lock_irq(shost->host_lock);
4388 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4389 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
4390 continue;
4391
4392 if (nport_index > 0) {
4393 nport_index--;
4394 continue;
4395 }
4396
4397 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
4398 > count)
4399 break;
4400
4401 if (!ndlp->lat_data)
4402 continue;
4403
4404 /* Print the WWN */
4405 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
4406 ndlp->nlp_portname.u.wwn[0],
4407 ndlp->nlp_portname.u.wwn[1],
4408 ndlp->nlp_portname.u.wwn[2],
4409 ndlp->nlp_portname.u.wwn[3],
4410 ndlp->nlp_portname.u.wwn[4],
4411 ndlp->nlp_portname.u.wwn[5],
4412 ndlp->nlp_portname.u.wwn[6],
4413 ndlp->nlp_portname.u.wwn[7]);
4414
4415 index = strlen(buf);
4416
4417 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4418 sprintf(&buf[index], "%010u,",
4419 ndlp->lat_data[i].cmd_count);
4420 index = strlen(buf);
4421 }
4422 sprintf(&buf[index], "\n");
4423 index = strlen(buf);
4424 }
4425 spin_unlock_irq(shost->host_lock);
4426 return index;
4427}
4428
4429static struct bin_attribute sysfs_drvr_stat_data_attr = {
4430 .attr = {
4431 .name = "lpfc_drvr_stat_data",
4432 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04004433 },
4434 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
4435 .read = sysfs_drvr_stat_data_read,
4436 .write = NULL,
4437};
4438
dea31012005-04-17 16:05:31 -05004439/*
4440# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4441# connection.
James Smart76a95d72010-11-20 23:11:48 -05004442# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05004443*/
James Smarte59058c2008-08-24 21:49:00 -04004444/**
James Smart3621a712009-04-06 18:47:14 -04004445 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004446 * @phba: lpfc_hba pointer.
4447 * @val: link speed value.
4448 *
4449 * Description:
4450 * If val is in a valid range then set the adapter's link speed field and
4451 * issue a lip; if the lip fails reset the link speed to the old value.
4452 *
4453 * Notes:
4454 * If the value is not in range log a kernel error message and return an error.
4455 *
4456 * Returns:
4457 * zero if val is in range and lip okay.
4458 * non-zero return value from lpfc_issue_lip()
4459 * -EINVAL val out of range
4460 **/
James Smarta257bf92009-04-06 18:48:10 -04004461static ssize_t
4462lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4463 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05004464{
James Smarta257bf92009-04-06 18:48:10 -04004465 struct Scsi_Host *shost = class_to_shost(dev);
4466 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4467 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05004468 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04004469 int nolip = 0;
4470 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05004471 int err;
James Smartc6918162016-10-13 15:06:16 -07004472 uint32_t prev_val, if_type;
4473
4474 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart719162b2018-12-10 19:37:01 -08004475 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&
James Smartc6918162016-10-13 15:06:16 -07004476 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4477 return -EPERM;
James Smart83108bd2008-01-11 01:53:09 -05004478
James Smarta257bf92009-04-06 18:48:10 -04004479 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4480 nolip = 1;
4481 val_buf = &buf[strlen("nolip ")];
4482 }
4483
4484 if (!isdigit(val_buf[0]))
4485 return -EINVAL;
4486 if (sscanf(val_buf, "%i", &val) != 1)
4487 return -EINVAL;
4488
James Smart88a2cfb2011-07-22 18:36:33 -04004489 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4490 "3055 lpfc_link_speed changed from %d to %d %s\n",
4491 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4492
James Smart76a95d72010-11-20 23:11:48 -05004493 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4494 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4495 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4496 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4497 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
James Smartd38dd522015-08-31 16:48:17 -04004498 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
James Smartfbd8a6b2018-02-22 08:18:45 -08004499 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||
4500 ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {
James Smart76a95d72010-11-20 23:11:48 -05004501 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4502 "2879 lpfc_link_speed attribute cannot be set "
4503 "to %d. Speed is not supported by this port.\n",
4504 val);
James Smart83108bd2008-01-11 01:53:09 -05004505 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05004506 }
James Smartfbd8a6b2018-02-22 08:18:45 -08004507 if (val >= LPFC_USER_LINK_SPEED_16G &&
4508 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smartff78d8f2011-12-13 13:21:35 -05004509 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4510 "3112 lpfc_link_speed attribute cannot be set "
4511 "to %d. Speed is not supported in loop mode.\n",
4512 val);
4513 return -EINVAL;
4514 }
James Smartfbd8a6b2018-02-22 08:18:45 -08004515
4516 switch (val) {
4517 case LPFC_USER_LINK_SPEED_AUTO:
4518 case LPFC_USER_LINK_SPEED_1G:
4519 case LPFC_USER_LINK_SPEED_2G:
4520 case LPFC_USER_LINK_SPEED_4G:
4521 case LPFC_USER_LINK_SPEED_8G:
4522 case LPFC_USER_LINK_SPEED_16G:
4523 case LPFC_USER_LINK_SPEED_32G:
4524 case LPFC_USER_LINK_SPEED_64G:
James Smart83108bd2008-01-11 01:53:09 -05004525 prev_val = phba->cfg_link_speed;
4526 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04004527 if (nolip)
4528 return strlen(buf);
4529
James Smart83108bd2008-01-11 01:53:09 -05004530 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04004531 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05004532 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04004533 return -EINVAL;
James Smartfbd8a6b2018-02-22 08:18:45 -08004534 }
4535 return strlen(buf);
4536 default:
4537 break;
James Smart83108bd2008-01-11 01:53:09 -05004538 }
James Smartfbd8a6b2018-02-22 08:18:45 -08004539
James Smart83108bd2008-01-11 01:53:09 -05004540 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartfbd8a6b2018-02-22 08:18:45 -08004541 "0469 lpfc_link_speed attribute cannot be set to %d, "
4542 "allowed values are [%s]\n",
4543 val, LPFC_LINK_SPEED_STRING);
James Smart83108bd2008-01-11 01:53:09 -05004544 return -EINVAL;
James Smartfbd8a6b2018-02-22 08:18:45 -08004545
James Smart83108bd2008-01-11 01:53:09 -05004546}
4547
4548static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05004549module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05004550MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4551lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04004552
4553/**
James Smart3621a712009-04-06 18:47:14 -04004554 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004555 * @phba: lpfc_hba pointer.
4556 * @val: link speed value.
4557 *
4558 * Description:
4559 * If val is in a valid range then set the adapter's link speed field.
4560 *
4561 * Notes:
4562 * If the value is not in range log a kernel error message, clear the link
4563 * speed and return an error.
4564 *
4565 * Returns:
4566 * zero if val saved.
4567 * -EINVAL val out of range
4568 **/
James Smart83108bd2008-01-11 01:53:09 -05004569static int
4570lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4571{
James Smartfbd8a6b2018-02-22 08:18:45 -08004572 if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
James Smartff78d8f2011-12-13 13:21:35 -05004573 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4574 "3111 lpfc_link_speed of %d cannot "
4575 "support loop mode, setting topology to default.\n",
4576 val);
4577 phba->cfg_topology = 0;
4578 }
James Smartfbd8a6b2018-02-22 08:18:45 -08004579
4580 switch (val) {
4581 case LPFC_USER_LINK_SPEED_AUTO:
4582 case LPFC_USER_LINK_SPEED_1G:
4583 case LPFC_USER_LINK_SPEED_2G:
4584 case LPFC_USER_LINK_SPEED_4G:
4585 case LPFC_USER_LINK_SPEED_8G:
4586 case LPFC_USER_LINK_SPEED_16G:
4587 case LPFC_USER_LINK_SPEED_32G:
4588 case LPFC_USER_LINK_SPEED_64G:
James Smart83108bd2008-01-11 01:53:09 -05004589 phba->cfg_link_speed = val;
4590 return 0;
James Smartfbd8a6b2018-02-22 08:18:45 -08004591 default:
4592 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4593 "0405 lpfc_link_speed attribute cannot "
4594 "be set to %d, allowed values are "
4595 "["LPFC_LINK_SPEED_STRING"]\n", val);
4596 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4597 return -EINVAL;
James Smart83108bd2008-01-11 01:53:09 -05004598 }
James Smart83108bd2008-01-11 01:53:09 -05004599}
4600
Joe Perchesb6b996b2017-12-19 10:15:07 -08004601static DEVICE_ATTR_RW(lpfc_link_speed);
dea31012005-04-17 16:05:31 -05004602
4603/*
James Smart0d878412009-10-02 15:16:56 -04004604# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4605# 0 = aer disabled or not supported
4606# 1 = aer supported and enabled (default)
4607# Value range is [0,1]. Default value is 1.
4608*/
James Smart506139a2016-10-13 15:06:09 -07004609LPFC_ATTR(aer_support, 1, 0, 1,
4610 "Enable PCIe device AER support");
4611lpfc_param_show(aer_support)
James Smart0d878412009-10-02 15:16:56 -04004612
4613/**
4614 * lpfc_aer_support_store - Set the adapter for aer support
4615 *
4616 * @dev: class device that is converted into a Scsi_host.
4617 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004618 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04004619 * @count: unused variable.
4620 *
4621 * Description:
4622 * If the val is 1 and currently the device's AER capability was not
4623 * enabled, invoke the kernel's enable AER helper routine, trying to
4624 * enable the device's AER capability. If the helper routine enabling
4625 * AER returns success, update the device's cfg_aer_support flag to
4626 * indicate AER is supported by the device; otherwise, if the device
4627 * AER capability is already enabled to support AER, then do nothing.
4628 *
4629 * If the val is 0 and currently the device's AER support was enabled,
4630 * invoke the kernel's disable AER helper routine. After that, update
4631 * the device's cfg_aer_support flag to indicate AER is not supported
4632 * by the device; otherwise, if the device AER capability is already
4633 * disabled from supporting AER, then do nothing.
4634 *
4635 * Returns:
4636 * length of the buf on success if val is in range the intended mode
4637 * is supported.
4638 * -EINVAL if val out of range or intended mode is not supported.
4639 **/
4640static ssize_t
4641lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4642 const char *buf, size_t count)
4643{
4644 struct Scsi_Host *shost = class_to_shost(dev);
4645 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4646 struct lpfc_hba *phba = vport->phba;
4647 int val = 0, rc = -EINVAL;
4648
4649 if (!isdigit(buf[0]))
4650 return -EINVAL;
4651 if (sscanf(buf, "%i", &val) != 1)
4652 return -EINVAL;
4653
4654 switch (val) {
4655 case 0:
4656 if (phba->hba_flag & HBA_AER_ENABLED) {
4657 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4658 if (!rc) {
4659 spin_lock_irq(&phba->hbalock);
4660 phba->hba_flag &= ~HBA_AER_ENABLED;
4661 spin_unlock_irq(&phba->hbalock);
4662 phba->cfg_aer_support = 0;
4663 rc = strlen(buf);
4664 } else
James Smart891478a2009-11-18 15:40:23 -05004665 rc = -EPERM;
4666 } else {
James Smart0d878412009-10-02 15:16:56 -04004667 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05004668 rc = strlen(buf);
4669 }
James Smart0d878412009-10-02 15:16:56 -04004670 break;
4671 case 1:
4672 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4673 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4674 if (!rc) {
4675 spin_lock_irq(&phba->hbalock);
4676 phba->hba_flag |= HBA_AER_ENABLED;
4677 spin_unlock_irq(&phba->hbalock);
4678 phba->cfg_aer_support = 1;
4679 rc = strlen(buf);
4680 } else
James Smart891478a2009-11-18 15:40:23 -05004681 rc = -EPERM;
4682 } else {
James Smart0d878412009-10-02 15:16:56 -04004683 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05004684 rc = strlen(buf);
4685 }
James Smart0d878412009-10-02 15:16:56 -04004686 break;
4687 default:
4688 rc = -EINVAL;
4689 break;
4690 }
4691 return rc;
4692}
4693
Joe Perchesb6b996b2017-12-19 10:15:07 -08004694static DEVICE_ATTR_RW(lpfc_aer_support);
James Smart0d878412009-10-02 15:16:56 -04004695
4696/**
4697 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4698 * @dev: class device that is converted into a Scsi_host.
4699 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004700 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04004701 * @count: unused variable.
4702 *
4703 * Description:
4704 * If the @buf contains 1 and the device currently has the AER support
4705 * enabled, then invokes the kernel AER helper routine
4706 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4707 * error status register.
4708 *
4709 * Notes:
4710 *
4711 * Returns:
4712 * -EINVAL if the buf does not contain the 1 or the device is not currently
4713 * enabled with the AER support.
4714 **/
4715static ssize_t
4716lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4717 const char *buf, size_t count)
4718{
4719 struct Scsi_Host *shost = class_to_shost(dev);
4720 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4721 struct lpfc_hba *phba = vport->phba;
4722 int val, rc = -1;
4723
4724 if (!isdigit(buf[0]))
4725 return -EINVAL;
4726 if (sscanf(buf, "%i", &val) != 1)
4727 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05004728 if (val != 1)
4729 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04004730
James Smart891478a2009-11-18 15:40:23 -05004731 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04004732 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4733
4734 if (rc == 0)
4735 return strlen(buf);
4736 else
James Smart891478a2009-11-18 15:40:23 -05004737 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04004738}
4739
4740static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4741 lpfc_aer_cleanup_state);
4742
James Smart912e3ac2011-05-24 11:42:11 -04004743/**
4744 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4745 *
4746 * @dev: class device that is converted into a Scsi_host.
4747 * @attr: device attribute, not used.
4748 * @buf: containing the string the number of vfs to be enabled.
4749 * @count: unused variable.
4750 *
4751 * Description:
4752 * When this api is called either through user sysfs, the driver shall
4753 * try to enable or disable SR-IOV virtual functions according to the
4754 * following:
4755 *
4756 * If zero virtual function has been enabled to the physical function,
4757 * the driver shall invoke the pci enable virtual function api trying
4758 * to enable the virtual functions. If the nr_vfn provided is greater
4759 * than the maximum supported, the maximum virtual function number will
4760 * be used for invoking the api; otherwise, the nr_vfn provided shall
4761 * be used for invoking the api. If the api call returned success, the
4762 * actual number of virtual functions enabled will be set to the driver
4763 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4764 * cfg_sriov_nr_virtfn remains zero.
4765 *
4766 * If none-zero virtual functions have already been enabled to the
4767 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4768 * -EINVAL will be returned and the driver does nothing;
4769 *
4770 * If the nr_vfn provided is zero and none-zero virtual functions have
4771 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4772 * disabling virtual function api shall be invoded to disable all the
4773 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4774 * zero. Otherwise, if zero virtual function has been enabled, do
4775 * nothing.
4776 *
4777 * Returns:
4778 * length of the buf on success if val is in range the intended mode
4779 * is supported.
4780 * -EINVAL if val out of range or intended mode is not supported.
4781 **/
4782static ssize_t
4783lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4784 const char *buf, size_t count)
4785{
4786 struct Scsi_Host *shost = class_to_shost(dev);
4787 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4788 struct lpfc_hba *phba = vport->phba;
4789 struct pci_dev *pdev = phba->pcidev;
4790 int val = 0, rc = -EINVAL;
4791
4792 /* Sanity check on user data */
4793 if (!isdigit(buf[0]))
4794 return -EINVAL;
4795 if (sscanf(buf, "%i", &val) != 1)
4796 return -EINVAL;
4797 if (val < 0)
4798 return -EINVAL;
4799
4800 /* Request disabling virtual functions */
4801 if (val == 0) {
4802 if (phba->cfg_sriov_nr_virtfn > 0) {
4803 pci_disable_sriov(pdev);
4804 phba->cfg_sriov_nr_virtfn = 0;
4805 }
4806 return strlen(buf);
4807 }
4808
4809 /* Request enabling virtual functions */
4810 if (phba->cfg_sriov_nr_virtfn > 0) {
4811 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4812 "3018 There are %d virtual functions "
4813 "enabled on physical function.\n",
4814 phba->cfg_sriov_nr_virtfn);
4815 return -EEXIST;
4816 }
4817
4818 if (val <= LPFC_MAX_VFN_PER_PFN)
4819 phba->cfg_sriov_nr_virtfn = val;
4820 else {
4821 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4822 "3019 Enabling %d virtual functions is not "
4823 "allowed.\n", val);
4824 return -EINVAL;
4825 }
4826
4827 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4828 if (rc) {
4829 phba->cfg_sriov_nr_virtfn = 0;
4830 rc = -EPERM;
4831 } else
4832 rc = strlen(buf);
4833
4834 return rc;
4835}
4836
James Smart0cfbbf22016-10-13 15:06:12 -07004837LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4838 "Enable PCIe device SR-IOV virtual fn");
4839
James Smart912e3ac2011-05-24 11:42:11 -04004840lpfc_param_show(sriov_nr_virtfn)
Joe Perchesb6b996b2017-12-19 10:15:07 -08004841static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04004842
James Smart173edbb2012-06-12 13:54:50 -04004843/**
James Smartc71ab862012-10-31 14:44:33 -04004844 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4845 *
4846 * @dev: class device that is converted into a Scsi_host.
4847 * @attr: device attribute, not used.
4848 * @buf: containing the string the number of vfs to be enabled.
4849 * @count: unused variable.
4850 *
4851 * Description:
4852 *
4853 * Returns:
4854 * length of the buf on success if val is in range the intended mode
4855 * is supported.
4856 * -EINVAL if val out of range or intended mode is not supported.
4857 **/
4858static ssize_t
4859lpfc_request_firmware_upgrade_store(struct device *dev,
4860 struct device_attribute *attr,
4861 const char *buf, size_t count)
4862{
4863 struct Scsi_Host *shost = class_to_shost(dev);
4864 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4865 struct lpfc_hba *phba = vport->phba;
4866 int val = 0, rc = -EINVAL;
4867
4868 /* Sanity check on user data */
4869 if (!isdigit(buf[0]))
4870 return -EINVAL;
4871 if (sscanf(buf, "%i", &val) != 1)
4872 return -EINVAL;
4873 if (val != 1)
4874 return -EINVAL;
4875
4876 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4877 if (rc)
4878 rc = -EPERM;
4879 else
4880 rc = strlen(buf);
4881 return rc;
4882}
4883
4884static int lpfc_req_fw_upgrade;
4885module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4886MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4887lpfc_param_show(request_firmware_upgrade)
4888
4889/**
4890 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4891 * @phba: lpfc_hba pointer.
4892 * @val: 0 or 1.
4893 *
4894 * Description:
4895 * Set the initial Linux generic firmware upgrade enable or disable flag.
4896 *
4897 * Returns:
4898 * zero if val saved.
4899 * -EINVAL val out of range
4900 **/
4901static int
4902lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4903{
4904 if (val >= 0 && val <= 1) {
4905 phba->cfg_request_firmware_upgrade = val;
4906 return 0;
4907 }
4908 return -EINVAL;
4909}
4910static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4911 lpfc_request_firmware_upgrade_show,
4912 lpfc_request_firmware_upgrade_store);
4913
4914/**
James Smart173edbb2012-06-12 13:54:50 -04004915 * lpfc_fcp_imax_store
4916 *
4917 * @dev: class device that is converted into a Scsi_host.
4918 * @attr: device attribute, not used.
4919 * @buf: string with the number of fast-path FCP interrupts per second.
4920 * @count: unused variable.
4921 *
4922 * Description:
4923 * If val is in a valid range [636,651042], then set the adapter's
4924 * maximum number of fast-path FCP interrupts per second.
4925 *
4926 * Returns:
4927 * length of the buf on success if val is in range the intended mode
4928 * is supported.
4929 * -EINVAL if val out of range or intended mode is not supported.
4930 **/
4931static ssize_t
4932lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4933 const char *buf, size_t count)
4934{
4935 struct Scsi_Host *shost = class_to_shost(dev);
4936 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4937 struct lpfc_hba *phba = vport->phba;
James Smart32517fc2019-01-28 11:14:33 -08004938 struct lpfc_eq_intr_info *eqi;
James Smartcb733e32019-01-28 11:14:32 -08004939 uint32_t usdelay;
James Smart173edbb2012-06-12 13:54:50 -04004940 int val = 0, i;
4941
James Smartbf8dae82012-08-03 12:36:24 -04004942 /* fcp_imax is only valid for SLI4 */
4943 if (phba->sli_rev != LPFC_SLI_REV4)
4944 return -EINVAL;
4945
James Smart173edbb2012-06-12 13:54:50 -04004946 /* Sanity check on user data */
4947 if (!isdigit(buf[0]))
4948 return -EINVAL;
4949 if (sscanf(buf, "%i", &val) != 1)
4950 return -EINVAL;
4951
James Smartbf8dae82012-08-03 12:36:24 -04004952 /*
4953 * Value range for the HBA is [5000,5000000]
4954 * The value for each EQ depends on how many EQs are configured.
James Smart895427b2017-02-12 13:52:30 -08004955 * Allow value == 0
James Smartbf8dae82012-08-03 12:36:24 -04004956 */
James Smart895427b2017-02-12 13:52:30 -08004957 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
James Smart173edbb2012-06-12 13:54:50 -04004958 return -EINVAL;
4959
James Smart32517fc2019-01-28 11:14:33 -08004960 phba->cfg_auto_imax = (val) ? 0 : 1;
4961 if (phba->cfg_fcp_imax && !val) {
4962 queue_delayed_work(phba->wq, &phba->eq_delay_work,
4963 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
4964
4965 for_each_present_cpu(i) {
4966 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
4967 eqi->icnt = 0;
4968 }
4969 }
4970
James Smart173edbb2012-06-12 13:54:50 -04004971 phba->cfg_fcp_imax = (uint32_t)val;
James Smart43140ca2017-03-04 09:30:34 -08004972
James Smartcb733e32019-01-28 11:14:32 -08004973 if (phba->cfg_fcp_imax)
4974 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
4975 else
4976 usdelay = 0;
4977
James Smart6a828b02019-01-28 11:14:31 -08004978 for (i = 0; i < phba->cfg_irq_chann; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart0cf07f842017-06-01 21:07:10 -07004979 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
James Smartcb733e32019-01-28 11:14:32 -08004980 usdelay);
James Smart173edbb2012-06-12 13:54:50 -04004981
4982 return strlen(buf);
4983}
4984
4985/*
4986# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04004987# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04004988#
James Smartbf8dae82012-08-03 12:36:24 -04004989# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04004990*/
James Smartbf8dae82012-08-03 12:36:24 -04004991static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004992module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4993MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04004994 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04004995lpfc_param_show(fcp_imax)
4996
4997/**
4998 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4999 * @phba: lpfc_hba pointer.
5000 * @val: link speed value.
5001 *
5002 * Description:
5003 * If val is in a valid range [636,651042], then initialize the adapter's
5004 * maximum number of fast-path FCP interrupts per second.
5005 *
5006 * Returns:
5007 * zero if val saved.
5008 * -EINVAL val out of range
5009 **/
5010static int
5011lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
5012{
James Smartbf8dae82012-08-03 12:36:24 -04005013 if (phba->sli_rev != LPFC_SLI_REV4) {
5014 phba->cfg_fcp_imax = 0;
5015 return 0;
5016 }
5017
James Smart895427b2017-02-12 13:52:30 -08005018 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
5019 (val == 0)) {
James Smart173edbb2012-06-12 13:54:50 -04005020 phba->cfg_fcp_imax = val;
5021 return 0;
5022 }
5023
5024 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07005025 "3016 lpfc_fcp_imax: %d out of range, using default\n",
5026 val);
James Smartbf8dae82012-08-03 12:36:24 -04005027 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04005028
5029 return 0;
5030}
5031
Joe Perchesb6b996b2017-12-19 10:15:07 -08005032static DEVICE_ATTR_RW(lpfc_fcp_imax);
James Smart173edbb2012-06-12 13:54:50 -04005033
James Smart32517fc2019-01-28 11:14:33 -08005034/**
5035 * lpfc_cq_max_proc_limit_store
5036 *
5037 * @dev: class device that is converted into a Scsi_host.
5038 * @attr: device attribute, not used.
5039 * @buf: string with the cq max processing limit of cqes
5040 * @count: unused variable.
5041 *
5042 * Description:
5043 * If val is in a valid range, then set value on each cq
5044 *
5045 * Returns:
5046 * The length of the buf: if successful
5047 * -ERANGE: if val is not in the valid range
5048 * -EINVAL: if bad value format or intended mode is not supported.
5049 **/
5050static ssize_t
5051lpfc_cq_max_proc_limit_store(struct device *dev, struct device_attribute *attr,
5052 const char *buf, size_t count)
5053{
5054 struct Scsi_Host *shost = class_to_shost(dev);
5055 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5056 struct lpfc_hba *phba = vport->phba;
5057 struct lpfc_queue *eq, *cq;
5058 unsigned long val;
5059 int i;
5060
5061 /* cq_max_proc_limit is only valid for SLI4 */
5062 if (phba->sli_rev != LPFC_SLI_REV4)
5063 return -EINVAL;
5064
5065 /* Sanity check on user data */
5066 if (!isdigit(buf[0]))
5067 return -EINVAL;
5068 if (kstrtoul(buf, 0, &val))
5069 return -EINVAL;
5070
5071 if (val < LPFC_CQ_MIN_PROC_LIMIT || val > LPFC_CQ_MAX_PROC_LIMIT)
5072 return -ERANGE;
5073
5074 phba->cfg_cq_max_proc_limit = (uint32_t)val;
5075
5076 /* set the values on the cq's */
5077 for (i = 0; i < phba->cfg_irq_chann; i++) {
5078 eq = phba->sli4_hba.hdwq[i].hba_eq;
5079 if (!eq)
5080 continue;
5081
5082 list_for_each_entry(cq, &eq->child_list, list)
5083 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
5084 cq->entry_count);
5085 }
5086
5087 return strlen(buf);
5088}
5089
James Smart0cf07f842017-06-01 21:07:10 -07005090/*
James Smart32517fc2019-01-28 11:14:33 -08005091 * lpfc_cq_max_proc_limit: The maximum number CQE entries processed in an
5092 * itteration of CQ processing.
James Smart0cf07f842017-06-01 21:07:10 -07005093 */
James Smart32517fc2019-01-28 11:14:33 -08005094static int lpfc_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
5095module_param(lpfc_cq_max_proc_limit, int, 0644);
5096MODULE_PARM_DESC(lpfc_cq_max_proc_limit,
5097 "Set the maximum number CQEs processed in an iteration of "
5098 "CQ processing");
5099lpfc_param_show(cq_max_proc_limit)
5100
5101/*
5102 * lpfc_cq_poll_threshold: Set the threshold of CQE completions in a
5103 * single handler call which should request a polled completion rather
5104 * than re-enabling interrupts.
5105 */
5106LPFC_ATTR_RW(cq_poll_threshold, LPFC_CQ_DEF_THRESHOLD_TO_POLL,
5107 LPFC_CQ_MIN_THRESHOLD_TO_POLL,
5108 LPFC_CQ_MAX_THRESHOLD_TO_POLL,
5109 "CQE Processing Threshold to enable Polling");
5110
5111/**
5112 * lpfc_cq_max_proc_limit_init - Set the initial cq max_proc_limit
5113 * @phba: lpfc_hba pointer.
5114 * @val: entry limit
5115 *
5116 * Description:
5117 * If val is in a valid range, then initialize the adapter's maximum
5118 * value.
5119 *
5120 * Returns:
5121 * Always returns 0 for success, even if value not always set to
5122 * requested value. If value out of range or not supported, will fall
5123 * back to default.
5124 **/
5125static int
5126lpfc_cq_max_proc_limit_init(struct lpfc_hba *phba, int val)
5127{
5128 phba->cfg_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
5129
5130 if (phba->sli_rev != LPFC_SLI_REV4)
5131 return 0;
5132
5133 if (val >= LPFC_CQ_MIN_PROC_LIMIT && val <= LPFC_CQ_MAX_PROC_LIMIT) {
5134 phba->cfg_cq_max_proc_limit = val;
5135 return 0;
5136 }
5137
5138 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5139 "0371 "LPFC_DRIVER_NAME"_cq_max_proc_limit: "
5140 "%d out of range, using default\n",
5141 phba->cfg_cq_max_proc_limit);
5142
5143 return 0;
5144}
5145
5146static DEVICE_ATTR_RW(lpfc_cq_max_proc_limit);
James Smart0cf07f842017-06-01 21:07:10 -07005147
James Smart7bb03bb2013-04-17 20:19:16 -04005148/**
5149 * lpfc_state_show - Display current driver CPU affinity
5150 * @dev: class converted to a Scsi_host structure.
5151 * @attr: device attribute, not used.
5152 * @buf: on return contains text describing the state of the link.
5153 *
5154 * Returns: size of formatted string.
5155 **/
5156static ssize_t
5157lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
5158 char *buf)
5159{
5160 struct Scsi_Host *shost = class_to_shost(dev);
5161 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5162 struct lpfc_hba *phba = vport->phba;
5163 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05005164 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04005165
5166 if ((phba->sli_rev != LPFC_SLI_REV4) ||
5167 (phba->intr_type != MSIX))
5168 return len;
5169
5170 switch (phba->cfg_fcp_cpu_map) {
5171 case 0:
5172 len += snprintf(buf + len, PAGE_SIZE-len,
5173 "fcp_cpu_map: No mapping (%d)\n",
5174 phba->cfg_fcp_cpu_map);
5175 return len;
5176 case 1:
5177 len += snprintf(buf + len, PAGE_SIZE-len,
5178 "fcp_cpu_map: HBA centric mapping (%d): "
James Smart222e9232019-01-28 11:14:35 -08005179 "%d of %d CPUs online from %d possible CPUs\n",
5180 phba->cfg_fcp_cpu_map, num_online_cpus(),
5181 num_present_cpus(),
5182 phba->sli4_hba.num_possible_cpu);
James Smart7bb03bb2013-04-17 20:19:16 -04005183 break;
James Smart7bb03bb2013-04-17 20:19:16 -04005184 }
5185
James Smart222e9232019-01-28 11:14:35 -08005186 while (phba->sli4_hba.curr_disp_cpu <
5187 phba->sli4_hba.num_possible_cpu) {
James Smart76fd07a2014-02-20 09:57:18 -05005188 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
5189
James Smart222e9232019-01-28 11:14:35 -08005190 if (!cpu_present(phba->sli4_hba.curr_disp_cpu))
5191 len += snprintf(buf + len, PAGE_SIZE - len,
5192 "CPU %02d not present\n",
5193 phba->sli4_hba.curr_disp_cpu);
5194 else if (cpup->irq == LPFC_VECTOR_MAP_EMPTY) {
James Smartb3295c22019-01-28 11:14:30 -08005195 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5196 len += snprintf(
5197 buf + len, PAGE_SIZE - len,
5198 "CPU %02d hdwq None "
James Smart6a828b02019-01-28 11:14:31 -08005199 "physid %d coreid %d ht %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05005200 phba->sli4_hba.curr_disp_cpu,
James Smartb3295c22019-01-28 11:14:30 -08005201 cpup->phys_id,
James Smart6a828b02019-01-28 11:14:31 -08005202 cpup->core_id, cpup->hyper);
James Smartb3295c22019-01-28 11:14:30 -08005203 else
5204 len += snprintf(
5205 buf + len, PAGE_SIZE - len,
James Smart6a828b02019-01-28 11:14:31 -08005206 "CPU %02d EQ %04d hdwq %04d "
5207 "physid %d coreid %d ht %d\n",
James Smartb3295c22019-01-28 11:14:30 -08005208 phba->sli4_hba.curr_disp_cpu,
James Smart6a828b02019-01-28 11:14:31 -08005209 cpup->eq, cpup->hdwq, cpup->phys_id,
5210 cpup->core_id, cpup->hyper);
James Smartb3295c22019-01-28 11:14:30 -08005211 } else {
5212 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5213 len += snprintf(
5214 buf + len, PAGE_SIZE - len,
5215 "CPU %02d hdwq None "
James Smart6a828b02019-01-28 11:14:31 -08005216 "physid %d coreid %d ht %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05005217 phba->sli4_hba.curr_disp_cpu,
James Smartb3295c22019-01-28 11:14:30 -08005218 cpup->phys_id,
James Smart6a828b02019-01-28 11:14:31 -08005219 cpup->core_id, cpup->hyper, cpup->irq);
James Smartb3295c22019-01-28 11:14:30 -08005220 else
5221 len += snprintf(
5222 buf + len, PAGE_SIZE - len,
James Smart6a828b02019-01-28 11:14:31 -08005223 "CPU %02d EQ %04d hdwq %04d "
5224 "physid %d coreid %d ht %d IRQ %d\n",
James Smartb3295c22019-01-28 11:14:30 -08005225 phba->sli4_hba.curr_disp_cpu,
James Smart6a828b02019-01-28 11:14:31 -08005226 cpup->eq, cpup->hdwq, cpup->phys_id,
5227 cpup->core_id, cpup->hyper, cpup->irq);
James Smartb3295c22019-01-28 11:14:30 -08005228 }
James Smart7bb03bb2013-04-17 20:19:16 -04005229
James Smart76fd07a2014-02-20 09:57:18 -05005230 phba->sli4_hba.curr_disp_cpu++;
5231
5232 /* display max number of CPUs keeping some margin */
5233 if (phba->sli4_hba.curr_disp_cpu <
James Smart222e9232019-01-28 11:14:35 -08005234 phba->sli4_hba.num_possible_cpu &&
James Smart76fd07a2014-02-20 09:57:18 -05005235 (len >= (PAGE_SIZE - 64))) {
James Smart222e9232019-01-28 11:14:35 -08005236 len += snprintf(buf + len,
5237 PAGE_SIZE - len, "more...\n");
James Smart76fd07a2014-02-20 09:57:18 -05005238 break;
5239 }
James Smart7bb03bb2013-04-17 20:19:16 -04005240 }
James Smart76fd07a2014-02-20 09:57:18 -05005241
James Smart222e9232019-01-28 11:14:35 -08005242 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_possible_cpu)
James Smart76fd07a2014-02-20 09:57:18 -05005243 phba->sli4_hba.curr_disp_cpu = 0;
5244
James Smart7bb03bb2013-04-17 20:19:16 -04005245 return len;
5246}
5247
5248/**
5249 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
5250 * @dev: class device that is converted into a Scsi_host.
5251 * @attr: device attribute, not used.
5252 * @buf: one or more lpfc_polling_flags values.
5253 * @count: not used.
5254 *
5255 * Returns:
5256 * -EINVAL - Not implemented yet.
5257 **/
5258static ssize_t
5259lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
5260 const char *buf, size_t count)
5261{
5262 int status = -EINVAL;
5263 return status;
5264}
5265
5266/*
5267# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
5268# for the HBA.
5269#
James Smart6a828b02019-01-28 11:14:31 -08005270# Value range is [0 to 1]. Default value is LPFC_HBA_CPU_MAP (1).
James Smart7bb03bb2013-04-17 20:19:16 -04005271# 0 - Do not affinitze IRQ vectors
5272# 1 - Affintize HBA vectors with respect to each HBA
5273# (start with CPU0 for each HBA)
James Smart6a828b02019-01-28 11:14:31 -08005274# This also defines how Hardware Queues are mapped to specific CPUs.
James Smart7bb03bb2013-04-17 20:19:16 -04005275*/
James Smart6a828b02019-01-28 11:14:31 -08005276static int lpfc_fcp_cpu_map = LPFC_HBA_CPU_MAP;
James Smart7bb03bb2013-04-17 20:19:16 -04005277module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
5278MODULE_PARM_DESC(lpfc_fcp_cpu_map,
5279 "Defines how to map CPUs to IRQ vectors per HBA");
5280
5281/**
5282 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
5283 * @phba: lpfc_hba pointer.
5284 * @val: link speed value.
5285 *
5286 * Description:
5287 * If val is in a valid range [0-2], then affinitze the adapter's
5288 * MSIX vectors.
5289 *
5290 * Returns:
5291 * zero if val saved.
5292 * -EINVAL val out of range
5293 **/
5294static int
5295lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
5296{
5297 if (phba->sli_rev != LPFC_SLI_REV4) {
5298 phba->cfg_fcp_cpu_map = 0;
5299 return 0;
5300 }
5301
5302 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
5303 phba->cfg_fcp_cpu_map = val;
5304 return 0;
5305 }
5306
5307 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07005308 "3326 lpfc_fcp_cpu_map: %d out of range, using "
5309 "default\n", val);
James Smart6a828b02019-01-28 11:14:31 -08005310 phba->cfg_fcp_cpu_map = LPFC_HBA_CPU_MAP;
James Smart7bb03bb2013-04-17 20:19:16 -04005311
5312 return 0;
5313}
5314
Joe Perchesb6b996b2017-12-19 10:15:07 -08005315static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
James Smart7bb03bb2013-04-17 20:19:16 -04005316
James Smart0d878412009-10-02 15:16:56 -04005317/*
dea31012005-04-17 16:05:31 -05005318# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
5319# Value range is [2,3]. Default value is 3.
5320*/
James Smart3de2a652007-08-02 11:09:59 -04005321LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
5322 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05005323
5324/*
5325# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
5326# is [0,1]. Default value is 0.
5327*/
James Smart3de2a652007-08-02 11:09:59 -04005328LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
5329 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05005330
5331/*
James Smart3cb01c52013-07-15 18:35:04 -04005332# lpfc_first_burst_size: First burst size to use on the NPorts
5333# that support first burst.
5334# Value range is [0,65536]. Default value is 0.
5335*/
5336LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
5337 "First burst size for Targets that support first burst");
5338
5339/*
James Smart2d7dbc42017-02-12 13:52:35 -08005340* lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
5341* When the driver is configured as an NVME target, this value is
5342* communicated to the NVME initiator in the PRLI response. It is
5343* used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
5344* parameters are set and the target is sending the PRLI RSP.
James Smart895427b2017-02-12 13:52:30 -08005345* Parameter supported on physical port only - no NPIV support.
James Smart2d7dbc42017-02-12 13:52:35 -08005346* Value range is [0,65536]. Default value is 0.
James Smart895427b2017-02-12 13:52:30 -08005347*/
James Smart2d7dbc42017-02-12 13:52:35 -08005348LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
5349 "NVME Target mode first burst size in 512B increments.");
5350
5351/*
5352 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
5353 * For the Initiator (I), enabling this parameter means that an NVMET
5354 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
5355 * processed by the initiator for subsequent NVME FCP IO. For the target
5356 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
5357 * driver parameter as the target function's first burst size returned to the
5358 * initiator in the target's NVME PRLI response. Parameter supported on physical
5359 * port only - no NPIV support.
5360 * Value range is [0,1]. Default value is 0 (disabled).
5361 */
James Smart895427b2017-02-12 13:52:30 -08005362LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
5363 "Enable First Burst feature on I and T functions.");
5364
5365/*
James Smart977b5a02008-09-07 11:52:04 -04005366# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
5367# depth. Default value is 0. When the value of this parameter is zero the
5368# SCSI command completion time is not used for controlling I/O queue depth. When
5369# the parameter is set to a non-zero value, the I/O queue depth is controlled
5370# to limit the I/O completion time to the parameter value.
5371# The value is set in milliseconds.
5372*/
James Smarted5b1522016-10-13 15:06:11 -07005373LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
James Smart977b5a02008-09-07 11:52:04 -04005374 "Use command completion time to control queue depth");
James Smarted5b1522016-10-13 15:06:11 -07005375
James Smart977b5a02008-09-07 11:52:04 -04005376lpfc_vport_param_show(max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04005377static int
5378lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
5379{
5380 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5381 struct lpfc_nodelist *ndlp, *next_ndlp;
5382
5383 if (val == vport->cfg_max_scsicmpl_time)
5384 return 0;
5385 if ((val < 0) || (val > 60000))
5386 return -EINVAL;
5387 vport->cfg_max_scsicmpl_time = val;
5388
5389 spin_lock_irq(shost->host_lock);
5390 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5391 if (!NLP_CHK_NODE_ACT(ndlp))
5392 continue;
5393 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
5394 continue;
James Smart7dc517d2010-07-14 15:32:10 -04005395 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04005396 }
5397 spin_unlock_irq(shost->host_lock);
5398 return 0;
5399}
5400lpfc_vport_param_store(max_scsicmpl_time);
Joe Perchesb6b996b2017-12-19 10:15:07 -08005401static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04005402
5403/*
dea31012005-04-17 16:05:31 -05005404# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
5405# range is [0,1]. Default value is 0.
5406*/
5407LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
5408
5409/*
James Smartc4908502019-01-28 11:14:28 -08005410# lpfc_xri_rebalancing: enable or disable XRI rebalancing feature
5411# range is [0,1]. Default value is 1.
5412*/
5413LPFC_ATTR_R(xri_rebalancing, 1, 0, 1, "Enable/Disable XRI rebalancing");
5414
5415/*
James Smart895427b2017-02-12 13:52:30 -08005416 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
5417 * range is [0,1]. Default value is 0.
James Smart45aa3122019-01-28 11:14:29 -08005418 * For [0], FCP commands are issued to Work Queues based on upper layer
5419 * hardware queue index.
James Smart895427b2017-02-12 13:52:30 -08005420 * For [1], FCP commands are issued to a Work Queue associated with the
5421 * current CPU.
5422 *
James Smart45aa3122019-01-28 11:14:29 -08005423 * LPFC_FCP_SCHED_BY_HDWQ == 0
James Smart895427b2017-02-12 13:52:30 -08005424 * LPFC_FCP_SCHED_BY_CPU == 1
5425 *
5426 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
5427 * affinity for FCP/NVME I/Os through Work Queues associated with the current
5428 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
5429 * through WQs will be used.
5430 */
James Smart6a828b02019-01-28 11:14:31 -08005431LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_BY_CPU,
James Smart45aa3122019-01-28 11:14:29 -08005432 LPFC_FCP_SCHED_BY_HDWQ,
James Smart895427b2017-02-12 13:52:30 -08005433 LPFC_FCP_SCHED_BY_CPU,
5434 "Determine scheduling algorithm for "
James Smart45aa3122019-01-28 11:14:29 -08005435 "issuing commands [0] - Hardware Queue, [1] - Current CPU");
James Smart49aa1432012-08-03 12:36:42 -04005436
5437/*
James Smart7ea92eb2018-10-23 13:41:10 -07005438 * lpfc_ns_query: Determine algrithmn for NameServer queries after RSCN
5439 * range is [0,1]. Default value is 0.
5440 * For [0], GID_FT is used for NameServer queries after RSCN (default)
5441 * For [1], GID_PT is used for NameServer queries after RSCN
5442 *
5443 */
5444LPFC_ATTR_RW(ns_query, LPFC_NS_QUERY_GID_FT,
5445 LPFC_NS_QUERY_GID_FT, LPFC_NS_QUERY_GID_PT,
5446 "Determine algorithm NameServer queries after RSCN "
5447 "[0] - GID_FT, [1] - GID_PT");
5448
5449/*
James Smarta6571c62012-10-31 14:44:42 -04005450# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
5451# range is [0,1]. Default value is 0.
5452# For [0], bus reset issues target reset to ALL devices
5453# For [1], bus reset issues target reset to non-FCP2 devices
5454*/
5455LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
5456 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
5457
5458
5459/*
dea31012005-04-17 16:05:31 -05005460# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
5461# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04005462# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05005463# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
5464# cr_delay is set to 0.
5465*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05005466LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05005467 "interrupt response is generated");
5468
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05005469LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05005470 "interrupt response is generated");
5471
5472/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05005473# lpfc_multi_ring_support: Determines how many rings to spread available
5474# cmd/rsp IOCB entries across.
5475# Value range is [1,2]. Default value is 1.
5476*/
5477LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
5478 "SLI rings to spread IOCB entries across");
5479
5480/*
James Smarta4bc3372006-12-02 13:34:16 -05005481# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
5482# identifies what rctl value to configure the additional ring for.
5483# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
5484*/
James Smart6a9c52c2009-10-02 15:16:51 -04005485LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05005486 255, "Identifies RCTL for additional ring configuration");
5487
5488/*
5489# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
5490# identifies what type value to configure the additional ring for.
5491# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
5492*/
James Smart6a9c52c2009-10-02 15:16:51 -04005493LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05005494 255, "Identifies TYPE for additional ring configuration");
5495
5496/*
James Smart4258e982015-12-16 18:11:58 -05005497# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
5498# 0 = SmartSAN functionality disabled (default)
5499# 1 = SmartSAN functionality enabled
5500# This parameter will override the value of lpfc_fdmi_on module parameter.
5501# Value range is [0,1]. Default value is 0.
dea31012005-04-17 16:05:31 -05005502*/
James Smart4258e982015-12-16 18:11:58 -05005503LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
5504
5505/*
5506# lpfc_fdmi_on: Controls FDMI support.
James Smart9abd9992018-08-14 12:55:05 -07005507# 0 No FDMI support
5508# 1 Traditional FDMI support (default)
James Smart8663cbb2016-03-31 14:12:33 -07005509# Traditional FDMI support means the driver will assume FDMI-2 support;
5510# however, if that fails, it will fallback to FDMI-1.
5511# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5512# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5513# lpfc_fdmi_on.
James Smart9abd9992018-08-14 12:55:05 -07005514# Value range [0,1]. Default value is 1.
James Smart4258e982015-12-16 18:11:58 -05005515*/
James Smart9abd9992018-08-14 12:55:05 -07005516LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05005517
5518/*
5519# Specifies the maximum number of ELS cmds we can have outstanding (for
5520# discovery). Value range is [1,64]. Default value = 32.
5521*/
James Smart3de2a652007-08-02 11:09:59 -04005522LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05005523 "during discovery");
5524
5525/*
James Smartc4a7c922013-05-31 17:04:59 -04005526# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
5527# will be scanned by the SCSI midlayer when sequential scanning is
5528# used; and is also the highest LUN ID allowed when the SCSI midlayer
5529# parses REPORT_LUN responses. The lpfc driver has no LUN count or
5530# LUN ID limit, but the SCSI midlayer requires this field for the uses
5531# above. The lpfc driver limits the default value to 255 for two reasons.
5532# As it bounds the sequential scan loop, scanning for thousands of luns
5533# on a target can take minutes of wall clock time. Additionally,
5534# there are FC targets, such as JBODs, that only recognize 8-bits of
5535# LUN ID. When they receive a value greater than 8 bits, they chop off
5536# the high order bits. In other words, they see LUN IDs 0, 256, 512,
5537# and so on all as LUN ID 0. This causes the linux kernel, which sees
5538# valid responses at each of the LUN IDs, to believe there are multiple
5539# devices present, when in fact, there is only 1.
5540# A customer that is aware of their target behaviors, and the results as
5541# indicated above, is welcome to increase the lpfc_max_luns value.
5542# As mentioned, this value is not used by the lpfc driver, only the
5543# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04005544# Value range is [0,65535]. Default value is 255.
5545# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05005546*/
Hannes Reinecke1abf6352014-06-25 15:27:38 +02005547LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05005548
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005549/*
5550# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
5551# Value range is [1,255], default value is 10.
5552*/
5553LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
5554 "Milliseconds driver will wait between polling FCP ring");
5555
James Smart4ff43242006-12-02 13:34:56 -05005556/*
James Smart0c411222013-09-06 12:22:46 -04005557# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
5558# to complete in seconds. Value range is [5,180], default value is 60.
5559*/
5560LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
5561 "Maximum time to wait for task management commands to complete");
5562/*
James Smart4ff43242006-12-02 13:34:56 -05005563# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5564# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02005565# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05005566# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02005567# 2 = MSI-X enabled (default)
5568# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05005569*/
George Kadianakis8605c462010-01-17 21:19:31 +02005570LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05005571 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05005572
James Smart13815c82008-01-11 01:52:48 -05005573/*
James Smartf358dd02017-02-12 13:52:34 -08005574 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
James Smart895427b2017-02-12 13:52:30 -08005575 *
5576 * 0 = NVME OAS disabled
5577 * 1 = NVME OAS enabled
5578 *
5579 * Value range is [0,1]. Default value is 0.
5580 */
5581LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5582 "Use OAS bit on NVME IOs");
5583
5584/*
James Smart4e565cf2018-02-22 08:18:50 -08005585 * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
5586 *
5587 * 0 = Put NVME Command in SGL
5588 * 1 = Embed NVME Command in WQE (unless G7)
5589 * 2 = Embed NVME Command in WQE (force)
5590 *
5591 * Value range is [0,2]. Default value is 1.
5592 */
5593LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,
5594 "Embed NVME Command in WQE");
5595
5596/*
James Smart6a828b02019-01-28 11:14:31 -08005597 * lpfc_hdw_queue: Set the number of Hardware Queues the driver
James Smartcdb42be2019-01-28 11:14:21 -08005598 * will advertise it supports to the NVME and SCSI layers. This also
James Smart6a828b02019-01-28 11:14:31 -08005599 * will map to the number of CQ/WQ pairs the driver will create.
James Smart895427b2017-02-12 13:52:30 -08005600 *
5601 * The NVME Layer will try to create this many, plus 1 administrative
5602 * hardware queue. The administrative queue will always map to WQ 0
James Smart6a828b02019-01-28 11:14:31 -08005603 * A hardware IO queue maps (qidx) to a specific driver CQ/WQ.
James Smart895427b2017-02-12 13:52:30 -08005604 *
James Smartcdb42be2019-01-28 11:14:21 -08005605 * 0 = Configure the number of hdw queues to the number of active CPUs.
James Smart6a828b02019-01-28 11:14:31 -08005606 * 1,128 = Manually specify how many hdw queues to use.
James Smart895427b2017-02-12 13:52:30 -08005607 *
James Smart6a828b02019-01-28 11:14:31 -08005608 * Value range is [0,128]. Default value is 0.
James Smart895427b2017-02-12 13:52:30 -08005609 */
James Smartcdb42be2019-01-28 11:14:21 -08005610LPFC_ATTR_R(hdw_queue,
5611 LPFC_HBA_HDWQ_DEF,
5612 LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,
5613 "Set the number of I/O Hardware Queues");
James Smart895427b2017-02-12 13:52:30 -08005614
5615/*
James Smart6a828b02019-01-28 11:14:31 -08005616 * lpfc_irq_chann: Set the number of IRQ vectors that are available
5617 * for Hardware Queues to utilize. This also will map to the number
5618 * of EQ / MSI-X vectors the driver will create. This should never be
5619 * more than the number of Hardware Queues
5620 *
5621 * 0 = Configure number of IRQ Channels to the number of active CPUs.
5622 * 1,128 = Manually specify how many IRQ Channels to use.
5623 *
5624 * Value range is [0,128]. Default value is 0.
5625 */
5626LPFC_ATTR_R(irq_chann,
5627 LPFC_HBA_HDWQ_DEF,
5628 LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,
5629 "Set the number of I/O IRQ Channels");
5630
5631/*
James Smart13815c82008-01-11 01:52:48 -05005632# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5633# 0 = HBA resets disabled
5634# 1 = HBA resets enabled (default)
James Smart50212672018-12-13 15:17:57 -08005635# 2 = HBA reset via PCI bus reset enabled
5636# Value range is [0,2]. Default value is 1.
James Smart13815c82008-01-11 01:52:48 -05005637*/
James Smart50212672018-12-13 15:17:57 -08005638LPFC_ATTR_RW(enable_hba_reset, 1, 0, 2, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04005639
James Smart13815c82008-01-11 01:52:48 -05005640/*
James Smarteb7a3392010-11-20 23:12:02 -05005641# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05005642# 0 = HBA Heartbeat disabled
5643# 1 = HBA Heartbeat enabled (default)
5644# Value range is [0,1]. Default value is 1.
5645*/
James Smarteb7a3392010-11-20 23:12:02 -05005646LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05005647
James Smart83108bd2008-01-11 01:53:09 -05005648/*
James Smart1ba981f2014-02-20 09:56:45 -05005649# lpfc_EnableXLane: Enable Express Lane Feature
5650# 0x0 Express Lane Feature disabled
5651# 0x1 Express Lane Feature enabled
5652# Value range is [0,1]. Default value is 0.
5653*/
5654LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5655
5656/*
5657# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5658# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5659# Value range is [0x0,0x7f]. Default value is 0
5660*/
James Smart28d7f3d2014-05-21 08:05:28 -04005661LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
James Smart1ba981f2014-02-20 09:56:45 -05005662
5663/*
James Smart81301a92008-12-04 22:39:46 -05005664# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5665# 0 = BlockGuard disabled (default)
5666# 1 = BlockGuard enabled
5667# Value range is [0,1]. Default value is 0.
5668*/
5669LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5670
James Smart6fb120a2009-05-22 14:52:59 -04005671/*
James Smart81301a92008-12-04 22:39:46 -05005672# lpfc_prot_mask: i
5673# - Bit mask of host protection capabilities used to register with the
5674# SCSI mid-layer
5675# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5676# - Allows you to ultimately specify which profiles to use
5677# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04005678# - SHOST_DIF_TYPE1_PROTECTION 1
5679# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5680# - SHOST_DIX_TYPE0_PROTECTION 8
5681# HBA supports DIX Type 0: Host to HBA protection only
5682# - SHOST_DIX_TYPE1_PROTECTION 16
5683# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05005684#
5685*/
James Smartb3b98b72016-10-13 15:06:06 -07005686LPFC_ATTR(prot_mask,
5687 (SHOST_DIF_TYPE1_PROTECTION |
5688 SHOST_DIX_TYPE0_PROTECTION |
5689 SHOST_DIX_TYPE1_PROTECTION),
5690 0,
5691 (SHOST_DIF_TYPE1_PROTECTION |
5692 SHOST_DIX_TYPE0_PROTECTION |
5693 SHOST_DIX_TYPE1_PROTECTION),
5694 "T10-DIF host protection capabilities mask");
James Smart81301a92008-12-04 22:39:46 -05005695
5696/*
5697# lpfc_prot_guard: i
5698# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04005699# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05005700# - Allows you to ultimately specify which profiles to use
5701# - Default will result in registering capabilities for all guard types
5702#
5703*/
James Smartb3b98b72016-10-13 15:06:06 -07005704LPFC_ATTR(prot_guard,
5705 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5706 "T10-DIF host protection guard type");
James Smart81301a92008-12-04 22:39:46 -05005707
James Smart92494142011-02-16 12:39:44 -05005708/*
5709 * Delay initial NPort discovery when Clean Address bit is cleared in
5710 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5711 * This parameter can have value 0 or 1.
5712 * When this parameter is set to 0, no delay is added to the initial
5713 * discovery.
5714 * When this parameter is set to non-zero value, initial Nport discovery is
5715 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5716 * accept and FCID/Fabric name/Fabric portname is changed.
5717 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5718 * when Clean Address bit is cleared in FLOGI/FDISC
5719 * accept and FCID/Fabric name/Fabric portname is changed.
5720 * Default value is 0.
5721 */
James Smart8eb8b962016-07-06 12:36:08 -07005722LPFC_ATTR(delay_discovery, 0, 0, 1,
5723 "Delay NPort discovery when Clean Address bit is cleared.");
James Smart81301a92008-12-04 22:39:46 -05005724
5725/*
James Smart3621a712009-04-06 18:47:14 -04005726 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart5b9e70b2018-09-10 10:30:42 -07005727 * This value can be set to values between 64 and 4096. The default value
5728 * is 64, but may be increased to allow for larger Max I/O sizes. The scsi
5729 * and nvme layers will allow I/O sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04005730 * Because of the additional overhead involved in setting up T10-DIF,
5731 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5732 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05005733 */
James Smart5b9e70b2018-09-10 10:30:42 -07005734static uint lpfc_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5735module_param(lpfc_sg_seg_cnt, uint, 0444);
5736MODULE_PARM_DESC(lpfc_sg_seg_cnt, "Max Scatter Gather Segment Count");
5737
5738/**
5739 * lpfc_sg_seg_cnt_show - Display the scatter/gather list sizes
5740 * configured for the adapter
5741 * @dev: class converted to a Scsi_host structure.
5742 * @attr: device attribute, not used.
5743 * @buf: on return contains a string with the list sizes
5744 *
5745 * Returns: size of formatted string.
5746 **/
5747static ssize_t
5748lpfc_sg_seg_cnt_show(struct device *dev, struct device_attribute *attr,
5749 char *buf)
5750{
5751 struct Scsi_Host *shost = class_to_shost(dev);
5752 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5753 struct lpfc_hba *phba = vport->phba;
5754 int len;
5755
5756 len = snprintf(buf, PAGE_SIZE, "SGL sz: %d total SGEs: %d\n",
5757 phba->cfg_sg_dma_buf_size, phba->cfg_total_seg_cnt);
5758
5759 len += snprintf(buf + len, PAGE_SIZE, "Cfg: %d SCSI: %d NVME: %d\n",
5760 phba->cfg_sg_seg_cnt, phba->cfg_scsi_seg_cnt,
5761 phba->cfg_nvme_seg_cnt);
5762 return len;
5763}
5764
5765static DEVICE_ATTR_RO(lpfc_sg_seg_cnt);
5766
5767/**
5768 * lpfc_sg_seg_cnt_init - Set the hba sg_seg_cnt initial value
5769 * @phba: lpfc_hba pointer.
5770 * @val: contains the initial value
5771 *
5772 * Description:
5773 * Validates the initial value is within range and assigns it to the
5774 * adapter. If not in range, an error message is posted and the
5775 * default value is assigned.
5776 *
5777 * Returns:
5778 * zero if value is in range and is set
5779 * -EINVAL if value was out of range
5780 **/
5781static int
5782lpfc_sg_seg_cnt_init(struct lpfc_hba *phba, int val)
5783{
5784 if (val >= LPFC_MIN_SG_SEG_CNT && val <= LPFC_MAX_SG_SEG_CNT) {
5785 phba->cfg_sg_seg_cnt = val;
5786 return 0;
5787 }
5788 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5789 "0409 "LPFC_DRIVER_NAME"_sg_seg_cnt attribute cannot "
5790 "be set to %d, allowed range is [%d, %d]\n",
5791 val, LPFC_MIN_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT);
5792 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5793 return -EINVAL;
5794}
James Smart83108bd2008-01-11 01:53:09 -05005795
James Smart96f70772013-04-17 20:16:15 -04005796/*
James Smart7bdedb32016-07-06 12:36:00 -07005797 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5798 * 0 = MDS Diagnostics disabled (default)
5799 * 1 = MDS Diagnostics enabled
5800 * Value range is [0,1]. Default value is 0.
5801 */
5802LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5803
James Smart44fd7fe2017-08-23 16:55:47 -07005804/*
James Smartd2cc9bc2018-09-10 10:30:50 -07005805 * lpfc_ras_fwlog_buffsize: Firmware logging host buffer size
5806 * 0 = Disable firmware logging (default)
5807 * [1-4] = Multiple of 1/4th Mb of host memory for FW logging
5808 * Value range [0..4]. Default value is 0
5809 */
5810LPFC_ATTR_RW(ras_fwlog_buffsize, 0, 0, 4, "Host memory for FW logging");
5811
5812/*
5813 * lpfc_ras_fwlog_level: Firmware logging verbosity level
5814 * Valid only if firmware logging is enabled
5815 * 0(Least Verbosity) 4 (most verbosity)
5816 * Value range is [0..4]. Default value is 0
5817 */
5818LPFC_ATTR_RW(ras_fwlog_level, 0, 0, 4, "Firmware Logging Level");
5819
5820/*
5821 * lpfc_ras_fwlog_func: Firmware logging enabled on function number
5822 * Default function which has RAS support : 0
5823 * Value Range is [0..7].
5824 * FW logging is a global action and enablement is via a specific
5825 * port.
5826 */
5827LPFC_ATTR_RW(ras_fwlog_func, 0, 0, 7, "Firmware Logging Enabled on Function");
5828
5829/*
James Smart44fd7fe2017-08-23 16:55:47 -07005830 * lpfc_enable_bbcr: Enable BB Credit Recovery
5831 * 0 = BB Credit Recovery disabled
5832 * 1 = BB Credit Recovery enabled (default)
5833 * Value range is [0,1]. Default value is 1.
5834 */
5835LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5836
James Smart1351e692018-02-22 08:18:43 -08005837/*
5838 * lpfc_enable_dpp: Enable DPP on G7
5839 * 0 = DPP on G7 disabled
5840 * 1 = DPP on G7 enabled (default)
5841 * Value range is [0,1]. Default value is 1.
5842 */
5843LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");
5844
Tony Jonesee959b02008-02-22 00:13:36 +01005845struct device_attribute *lpfc_hba_attrs[] = {
James Smart895427b2017-02-12 13:52:30 -08005846 &dev_attr_nvme_info,
James Smart4c47efc2019-01-28 11:14:25 -08005847 &dev_attr_scsi_stat,
James Smart81301a92008-12-04 22:39:46 -05005848 &dev_attr_bg_info,
5849 &dev_attr_bg_guard_err,
5850 &dev_attr_bg_apptag_err,
5851 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01005852 &dev_attr_info,
5853 &dev_attr_serialnum,
5854 &dev_attr_modeldesc,
5855 &dev_attr_modelname,
5856 &dev_attr_programtype,
5857 &dev_attr_portnum,
5858 &dev_attr_fwrev,
5859 &dev_attr_hdw,
5860 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005861 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005862 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04005863 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01005864 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04005865 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01005866 &dev_attr_lpfc_temp_sensor,
5867 &dev_attr_lpfc_log_verbose,
5868 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005869 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005870 &dev_attr_lpfc_hba_queue_depth,
5871 &dev_attr_lpfc_peer_port_login,
5872 &dev_attr_lpfc_nodev_tmo,
5873 &dev_attr_lpfc_devloss_tmo,
James Smart895427b2017-02-12 13:52:30 -08005874 &dev_attr_lpfc_enable_fc4_type,
Tony Jonesee959b02008-02-22 00:13:36 +01005875 &dev_attr_lpfc_fcp_class,
5876 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005877 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005878 &dev_attr_lpfc_ack0,
James Smartc4908502019-01-28 11:14:28 -08005879 &dev_attr_lpfc_xri_rebalancing,
Tony Jonesee959b02008-02-22 00:13:36 +01005880 &dev_attr_lpfc_topology,
5881 &dev_attr_lpfc_scan_down,
5882 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04005883 &dev_attr_lpfc_fcp_io_sched,
James Smart7ea92eb2018-10-23 13:41:10 -07005884 &dev_attr_lpfc_ns_query,
James Smarta6571c62012-10-31 14:44:42 -04005885 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01005886 &dev_attr_lpfc_cr_delay,
5887 &dev_attr_lpfc_cr_count,
5888 &dev_attr_lpfc_multi_ring_support,
5889 &dev_attr_lpfc_multi_ring_rctl,
5890 &dev_attr_lpfc_multi_ring_type,
5891 &dev_attr_lpfc_fdmi_on,
James Smart4258e982015-12-16 18:11:58 -05005892 &dev_attr_lpfc_enable_SmartSAN,
Tony Jonesee959b02008-02-22 00:13:36 +01005893 &dev_attr_lpfc_max_luns,
5894 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04005895 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05005896 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01005897 &dev_attr_nport_evt_cnt,
5898 &dev_attr_board_mode,
5899 &dev_attr_max_vpi,
5900 &dev_attr_used_vpi,
5901 &dev_attr_max_rpi,
5902 &dev_attr_used_rpi,
5903 &dev_attr_max_xri,
5904 &dev_attr_used_xri,
5905 &dev_attr_npiv_info,
5906 &dev_attr_issue_reset,
5907 &dev_attr_lpfc_poll,
5908 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04005909 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01005910 &dev_attr_lpfc_use_msi,
James Smart895427b2017-02-12 13:52:30 -08005911 &dev_attr_lpfc_nvme_oas,
James Smart4e565cf2018-02-22 08:18:50 -08005912 &dev_attr_lpfc_nvme_embed_cmd,
James Smartda0436e2009-05-22 14:51:39 -04005913 &dev_attr_lpfc_fcp_imax,
James Smart32517fc2019-01-28 11:14:33 -08005914 &dev_attr_lpfc_cq_poll_threshold,
5915 &dev_attr_lpfc_cq_max_proc_limit,
James Smart7bb03bb2013-04-17 20:19:16 -04005916 &dev_attr_lpfc_fcp_cpu_map,
James Smartcdb42be2019-01-28 11:14:21 -08005917 &dev_attr_lpfc_hdw_queue,
James Smart6a828b02019-01-28 11:14:31 -08005918 &dev_attr_lpfc_irq_chann,
James Smartf358dd02017-02-12 13:52:34 -08005919 &dev_attr_lpfc_suppress_rsp,
James Smart2d7dbc42017-02-12 13:52:35 -08005920 &dev_attr_lpfc_nvmet_mrq,
James Smart2448e482018-04-09 14:24:24 -07005921 &dev_attr_lpfc_nvmet_mrq_post,
James Smart895427b2017-02-12 13:52:30 -08005922 &dev_attr_lpfc_nvme_enable_fb,
James Smart2d7dbc42017-02-12 13:52:35 -08005923 &dev_attr_lpfc_nvmet_fb_size,
James Smart81301a92008-12-04 22:39:46 -05005924 &dev_attr_lpfc_enable_bg,
James Smart352e5fd2016-12-30 06:57:47 -08005925 &dev_attr_lpfc_soft_wwnn,
5926 &dev_attr_lpfc_soft_wwpn,
5927 &dev_attr_lpfc_soft_wwn_enable,
Tony Jonesee959b02008-02-22 00:13:36 +01005928 &dev_attr_lpfc_enable_hba_reset,
5929 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05005930 &dev_attr_lpfc_EnableXLane,
5931 &dev_attr_lpfc_XLanePriority,
5932 &dev_attr_lpfc_xlane_lun,
5933 &dev_attr_lpfc_xlane_tgt,
5934 &dev_attr_lpfc_xlane_vpt,
5935 &dev_attr_lpfc_xlane_lun_state,
5936 &dev_attr_lpfc_xlane_lun_status,
James Smartc92c8412016-07-06 12:36:05 -07005937 &dev_attr_lpfc_xlane_priority,
Tony Jonesee959b02008-02-22 00:13:36 +01005938 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04005939 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04005940 &dev_attr_lpfc_stat_data_ctrl,
James Smart0d878412009-10-02 15:16:56 -04005941 &dev_attr_lpfc_aer_support,
5942 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04005943 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04005944 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05005945 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04005946 &dev_attr_lpfc_iocb_cnt,
5947 &dev_attr_iocb_hw,
5948 &dev_attr_txq_hw,
5949 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04005950 &dev_attr_lpfc_fips_level,
5951 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05005952 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04005953 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05005954 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05005955 &dev_attr_lpfc_xlane_supported,
James Smart7bdedb32016-07-06 12:36:00 -07005956 &dev_attr_lpfc_enable_mds_diags,
James Smartd2cc9bc2018-09-10 10:30:50 -07005957 &dev_attr_lpfc_ras_fwlog_buffsize,
5958 &dev_attr_lpfc_ras_fwlog_level,
5959 &dev_attr_lpfc_ras_fwlog_func,
James Smart44fd7fe2017-08-23 16:55:47 -07005960 &dev_attr_lpfc_enable_bbcr,
James Smart1351e692018-02-22 08:18:43 -08005961 &dev_attr_lpfc_enable_dpp,
dea31012005-04-17 16:05:31 -05005962 NULL,
5963};
5964
Tony Jonesee959b02008-02-22 00:13:36 +01005965struct device_attribute *lpfc_vport_attrs[] = {
5966 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005967 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005968 &dev_attr_num_discovered_ports,
5969 &dev_attr_lpfc_drvr_version,
5970 &dev_attr_lpfc_log_verbose,
5971 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005972 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005973 &dev_attr_lpfc_nodev_tmo,
5974 &dev_attr_lpfc_devloss_tmo,
5975 &dev_attr_lpfc_hba_queue_depth,
5976 &dev_attr_lpfc_peer_port_login,
5977 &dev_attr_lpfc_restrict_login,
5978 &dev_attr_lpfc_fcp_class,
5979 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005980 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005981 &dev_attr_lpfc_max_luns,
5982 &dev_attr_nport_evt_cnt,
5983 &dev_attr_npiv_info,
5984 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04005985 &dev_attr_lpfc_max_scsicmpl_time,
5986 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04005987 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04005988 &dev_attr_lpfc_fips_level,
5989 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04005990 NULL,
5991};
5992
James Smarte59058c2008-08-24 21:49:00 -04005993/**
James Smart3621a712009-04-06 18:47:14 -04005994 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005995 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005996 * @kobj: kernel kobject that contains the kernel class device.
5997 * @bin_attr: kernel attributes passed to us.
5998 * @buf: contains the data to be written to the adapter IOREG space.
5999 * @off: offset into buffer to beginning of data.
6000 * @count: bytes to transfer.
6001 *
6002 * Description:
6003 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6004 * Uses the adapter io control registers to send buf contents to the adapter.
6005 *
6006 * Returns:
6007 * -ERANGE off and count combo out of range
6008 * -EINVAL off, count or buff address invalid
6009 * -EPERM adapter is offline
6010 * value of count, buf contents written
6011 **/
dea31012005-04-17 16:05:31 -05006012static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07006013sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
6014 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08006015 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05006016{
6017 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01006018 struct device *dev = container_of(kobj, struct device, kobj);
6019 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05006020 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6021 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006022
James Smartf1126682009-06-10 17:22:44 -04006023 if (phba->sli_rev >= LPFC_SLI_REV4)
6024 return -EPERM;
6025
dea31012005-04-17 16:05:31 -05006026 if ((off + count) > FF_REG_AREA_SIZE)
6027 return -ERANGE;
6028
James Smartf7a919b2011-08-21 21:49:16 -04006029 if (count <= LPFC_REG_WRITE_KEY_SIZE)
6030 return 0;
dea31012005-04-17 16:05:31 -05006031
6032 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6033 return -EINVAL;
6034
James Smartf7a919b2011-08-21 21:49:16 -04006035 /* This is to protect HBA registers from accidental writes. */
6036 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
6037 return -EINVAL;
6038
6039 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05006040 return -EPERM;
dea31012005-04-17 16:05:31 -05006041
James Smart2e0fef82007-06-17 19:56:36 -05006042 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04006043 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
6044 buf_off += sizeof(uint32_t))
6045 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05006046 phba->ctrl_regs_memmap_p + off + buf_off);
6047
James Smart2e0fef82007-06-17 19:56:36 -05006048 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006049
6050 return count;
6051}
6052
James Smarte59058c2008-08-24 21:49:00 -04006053/**
James Smart3621a712009-04-06 18:47:14 -04006054 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07006055 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04006056 * @kobj: kernel kobject that contains the kernel class device.
6057 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006058 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04006059 * @off: offset into buffer to beginning of data.
6060 * @count: bytes to transfer.
6061 *
6062 * Description:
6063 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6064 * Uses the adapter io control registers to read data into buf.
6065 *
6066 * Returns:
6067 * -ERANGE off and count combo out of range
6068 * -EINVAL off, count or buff address invalid
6069 * value of count, buf contents read
6070 **/
dea31012005-04-17 16:05:31 -05006071static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07006072sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
6073 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08006074 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05006075{
6076 size_t buf_off;
6077 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01006078 struct device *dev = container_of(kobj, struct device, kobj);
6079 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05006080 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6081 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006082
James Smartf1126682009-06-10 17:22:44 -04006083 if (phba->sli_rev >= LPFC_SLI_REV4)
6084 return -EPERM;
6085
dea31012005-04-17 16:05:31 -05006086 if (off > FF_REG_AREA_SIZE)
6087 return -ERANGE;
6088
6089 if ((off + count) > FF_REG_AREA_SIZE)
6090 count = FF_REG_AREA_SIZE - off;
6091
6092 if (count == 0) return 0;
6093
6094 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6095 return -EINVAL;
6096
James Smart2e0fef82007-06-17 19:56:36 -05006097 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006098
6099 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
6100 tmp_ptr = (uint32_t *)(buf + buf_off);
6101 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
6102 }
6103
James Smart2e0fef82007-06-17 19:56:36 -05006104 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006105
6106 return count;
6107}
6108
6109static struct bin_attribute sysfs_ctlreg_attr = {
6110 .attr = {
6111 .name = "ctlreg",
6112 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05006113 },
6114 .size = 256,
6115 .read = sysfs_ctlreg_read,
6116 .write = sysfs_ctlreg_write,
6117};
6118
James Smarte59058c2008-08-24 21:49:00 -04006119/**
James Smart3621a712009-04-06 18:47:14 -04006120 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07006121 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04006122 * @kobj: kernel kobject that contains the kernel class device.
6123 * @bin_attr: kernel attributes passed to us.
6124 * @buf: contains the data to be written to sysfs mbox.
6125 * @off: offset into buffer to beginning of data.
6126 * @count: bytes to transfer.
6127 *
6128 * Description:
James Smart026abb82011-12-13 13:20:45 -05006129 * Deprecated function. All mailbox access from user space is performed via the
6130 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04006131 *
6132 * Returns:
James Smart026abb82011-12-13 13:20:45 -05006133 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04006134 **/
dea31012005-04-17 16:05:31 -05006135static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07006136sysfs_mbox_write(struct file *filp, struct kobject *kobj,
6137 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08006138 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05006139{
James Smart026abb82011-12-13 13:20:45 -05006140 return -EPERM;
dea31012005-04-17 16:05:31 -05006141}
6142
James Smarte59058c2008-08-24 21:49:00 -04006143/**
James Smart3621a712009-04-06 18:47:14 -04006144 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07006145 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04006146 * @kobj: kernel kobject that contains the kernel class device.
6147 * @bin_attr: kernel attributes passed to us.
6148 * @buf: contains the data to be read from sysfs mbox.
6149 * @off: offset into buffer to beginning of data.
6150 * @count: bytes to transfer.
6151 *
6152 * Description:
James Smart026abb82011-12-13 13:20:45 -05006153 * Deprecated function. All mailbox access from user space is performed via the
6154 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04006155 *
6156 * Returns:
James Smart026abb82011-12-13 13:20:45 -05006157 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04006158 **/
dea31012005-04-17 16:05:31 -05006159static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07006160sysfs_mbox_read(struct file *filp, struct kobject *kobj,
6161 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08006162 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05006163{
James Smart026abb82011-12-13 13:20:45 -05006164 return -EPERM;
dea31012005-04-17 16:05:31 -05006165}
6166
6167static struct bin_attribute sysfs_mbox_attr = {
6168 .attr = {
6169 .name = "mbox",
6170 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05006171 },
James Smartc0c11512011-05-24 11:41:34 -04006172 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05006173 .read = sysfs_mbox_read,
6174 .write = sysfs_mbox_write,
6175};
6176
James Smarte59058c2008-08-24 21:49:00 -04006177/**
James Smart3621a712009-04-06 18:47:14 -04006178 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04006179 * @vport: address of lpfc vport structure.
6180 *
6181 * Return codes:
6182 * zero on success
6183 * error return code from sysfs_create_bin_file()
6184 **/
dea31012005-04-17 16:05:31 -05006185int
James Smart2e0fef82007-06-17 19:56:36 -05006186lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006187{
James Smart2e0fef82007-06-17 19:56:36 -05006188 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05006189 int error;
6190
Tony Jonesee959b02008-02-22 00:13:36 +01006191 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05006192 &sysfs_drvr_stat_data_attr);
6193
6194 /* Virtual ports do not need ctrl_reg and mbox */
6195 if (error || vport->port_type == LPFC_NPIV_PORT)
6196 goto out;
6197
6198 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05006199 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05006200 if (error)
James Smarteada2722008-12-04 22:39:13 -05006201 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05006202
Tony Jonesee959b02008-02-22 00:13:36 +01006203 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05006204 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05006205 if (error)
6206 goto out_remove_ctlreg_attr;
6207
6208 return 0;
6209out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01006210 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05006211out_remove_stat_attr:
6212 sysfs_remove_bin_file(&shost->shost_dev.kobj,
6213 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05006214out:
6215 return error;
6216}
6217
James Smarte59058c2008-08-24 21:49:00 -04006218/**
James Smart3621a712009-04-06 18:47:14 -04006219 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04006220 * @vport: address of lpfc vport structure.
6221 **/
dea31012005-04-17 16:05:31 -05006222void
James Smart2e0fef82007-06-17 19:56:36 -05006223lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006224{
James Smart2e0fef82007-06-17 19:56:36 -05006225 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04006226 sysfs_remove_bin_file(&shost->shost_dev.kobj,
6227 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05006228 /* Virtual ports do not need ctrl_reg and mbox */
6229 if (vport->port_type == LPFC_NPIV_PORT)
6230 return;
Tony Jonesee959b02008-02-22 00:13:36 +01006231 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
6232 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05006233}
6234
dea31012005-04-17 16:05:31 -05006235/*
6236 * Dynamic FC Host Attributes Support
6237 */
6238
James Smarte59058c2008-08-24 21:49:00 -04006239/**
James Smart6c9231f2016-12-19 15:07:24 -08006240 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
6241 * @shost: kernel scsi host pointer.
6242 **/
6243static void
6244lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
6245{
6246 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
6247
6248 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
6249 sizeof fc_host_symbolic_name(shost));
6250}
6251
6252/**
James Smart3621a712009-04-06 18:47:14 -04006253 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04006254 * @shost: kernel scsi host pointer.
6255 **/
dea31012005-04-17 16:05:31 -05006256static void
6257lpfc_get_host_port_id(struct Scsi_Host *shost)
6258{
James Smart2e0fef82007-06-17 19:56:36 -05006259 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6260
dea31012005-04-17 16:05:31 -05006261 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05006262 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05006263}
6264
James Smarte59058c2008-08-24 21:49:00 -04006265/**
James Smart3621a712009-04-06 18:47:14 -04006266 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04006267 * @shost: kernel scsi host pointer.
6268 **/
dea31012005-04-17 16:05:31 -05006269static void
6270lpfc_get_host_port_type(struct Scsi_Host *shost)
6271{
James Smart2e0fef82007-06-17 19:56:36 -05006272 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6273 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006274
6275 spin_lock_irq(shost->host_lock);
6276
James Smart92d7f7b2007-06-17 19:56:38 -05006277 if (vport->port_type == LPFC_NPIV_PORT) {
6278 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
6279 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05006280 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05006281 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05006282 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
6283 else
6284 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
6285 } else {
James Smart2e0fef82007-06-17 19:56:36 -05006286 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05006287 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
6288 else
6289 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
6290 }
6291 } else
6292 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
6293
6294 spin_unlock_irq(shost->host_lock);
6295}
6296
James Smarte59058c2008-08-24 21:49:00 -04006297/**
James Smart3621a712009-04-06 18:47:14 -04006298 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04006299 * @shost: kernel scsi host pointer.
6300 **/
dea31012005-04-17 16:05:31 -05006301static void
6302lpfc_get_host_port_state(struct Scsi_Host *shost)
6303{
James Smart2e0fef82007-06-17 19:56:36 -05006304 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6305 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006306
6307 spin_lock_irq(shost->host_lock);
6308
James Smart2e0fef82007-06-17 19:56:36 -05006309 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05006310 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
6311 else {
James Smart2e0fef82007-06-17 19:56:36 -05006312 switch (phba->link_state) {
6313 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05006314 case LPFC_LINK_DOWN:
6315 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
6316 break;
6317 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05006318 case LPFC_CLEAR_LA:
6319 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05006320 /* Links up, reports port state accordingly */
6321 if (vport->port_state < LPFC_VPORT_READY)
6322 fc_host_port_state(shost) =
6323 FC_PORTSTATE_BYPASSED;
6324 else
6325 fc_host_port_state(shost) =
6326 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05006327 break;
6328 case LPFC_HBA_ERROR:
6329 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
6330 break;
6331 default:
6332 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
6333 break;
6334 }
6335 }
6336
6337 spin_unlock_irq(shost->host_lock);
6338}
6339
James Smarte59058c2008-08-24 21:49:00 -04006340/**
James Smart3621a712009-04-06 18:47:14 -04006341 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04006342 * @shost: kernel scsi host pointer.
6343 **/
dea31012005-04-17 16:05:31 -05006344static void
6345lpfc_get_host_speed(struct Scsi_Host *shost)
6346{
James Smart2e0fef82007-06-17 19:56:36 -05006347 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6348 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006349
6350 spin_lock_irq(shost->host_lock);
6351
James Smarta085e872015-12-16 18:12:02 -05006352 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea31012005-04-17 16:05:31 -05006353 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05006354 case LPFC_LINK_SPEED_1GHZ:
6355 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05006356 break;
James Smart76a95d72010-11-20 23:11:48 -05006357 case LPFC_LINK_SPEED_2GHZ:
6358 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05006359 break;
James Smart76a95d72010-11-20 23:11:48 -05006360 case LPFC_LINK_SPEED_4GHZ:
6361 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05006362 break;
James Smart76a95d72010-11-20 23:11:48 -05006363 case LPFC_LINK_SPEED_8GHZ:
6364 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04006365 break;
James Smart76a95d72010-11-20 23:11:48 -05006366 case LPFC_LINK_SPEED_10GHZ:
6367 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04006368 break;
James Smart76a95d72010-11-20 23:11:48 -05006369 case LPFC_LINK_SPEED_16GHZ:
6370 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
6371 break;
James Smartd38dd522015-08-31 16:48:17 -04006372 case LPFC_LINK_SPEED_32GHZ:
6373 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
6374 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08006375 case LPFC_LINK_SPEED_64GHZ:
6376 fc_host_speed(shost) = FC_PORTSPEED_64GBIT;
6377 break;
James Smart1dc5ec22018-10-23 13:41:11 -07006378 case LPFC_LINK_SPEED_128GHZ:
6379 fc_host_speed(shost) = FC_PORTSPEED_128GBIT;
6380 break;
James Smart76a95d72010-11-20 23:11:48 -05006381 default:
6382 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05006383 break;
6384 }
James Smartb615a202018-07-31 17:23:19 -07006385 } else if (lpfc_is_link_up(phba) && (phba->hba_flag & HBA_FCOE_MODE)) {
6386 switch (phba->fc_linkspeed) {
6387 case LPFC_ASYNC_LINK_SPEED_10GBPS:
6388 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6389 break;
6390 case LPFC_ASYNC_LINK_SPEED_25GBPS:
6391 fc_host_speed(shost) = FC_PORTSPEED_25GBIT;
6392 break;
6393 case LPFC_ASYNC_LINK_SPEED_40GBPS:
6394 fc_host_speed(shost) = FC_PORTSPEED_40GBIT;
6395 break;
6396 case LPFC_ASYNC_LINK_SPEED_100GBPS:
6397 fc_host_speed(shost) = FC_PORTSPEED_100GBIT;
6398 break;
6399 default:
6400 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6401 break;
6402 }
James Smart09372822008-01-11 01:52:54 -05006403 } else
6404 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05006405
6406 spin_unlock_irq(shost->host_lock);
6407}
6408
James Smarte59058c2008-08-24 21:49:00 -04006409/**
James Smart3621a712009-04-06 18:47:14 -04006410 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04006411 * @shost: kernel scsi host pointer.
6412 **/
dea31012005-04-17 16:05:31 -05006413static void
6414lpfc_get_host_fabric_name (struct Scsi_Host *shost)
6415{
James Smart2e0fef82007-06-17 19:56:36 -05006416 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6417 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07006418 u64 node_name;
dea31012005-04-17 16:05:31 -05006419
6420 spin_lock_irq(shost->host_lock);
6421
James Smart73d91e52011-10-10 21:32:10 -04006422 if ((vport->port_state > LPFC_FLOGI) &&
6423 ((vport->fc_flag & FC_FABRIC) ||
6424 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
6425 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07006426 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05006427 else
6428 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05006429 node_name = 0;
dea31012005-04-17 16:05:31 -05006430
6431 spin_unlock_irq(shost->host_lock);
6432
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07006433 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05006434}
6435
James Smarte59058c2008-08-24 21:49:00 -04006436/**
James Smart3621a712009-04-06 18:47:14 -04006437 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04006438 * @shost: kernel scsi host pointer.
6439 *
6440 * Notes:
6441 * NULL on error for link down, no mbox pool, sli2 active,
6442 * management not allowed, memory allocation error, or mbox error.
6443 *
6444 * Returns:
6445 * NULL for error
6446 * address of the adapter host statistics
6447 **/
dea31012005-04-17 16:05:31 -05006448static struct fc_host_statistics *
6449lpfc_get_stats(struct Scsi_Host *shost)
6450{
James Smart2e0fef82007-06-17 19:56:36 -05006451 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6452 struct lpfc_hba *phba = vport->phba;
6453 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04006454 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04006455 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05006456 LPFC_MBOXQ_t *pmboxq;
6457 MAILBOX_t *pmb;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04006458 int rc = 0;
dea31012005-04-17 16:05:31 -05006459
James Smart92d7f7b2007-06-17 19:56:38 -05006460 /*
6461 * prevent udev from issuing mailbox commands until the port is
6462 * configured.
6463 */
James Smart2e0fef82007-06-17 19:56:36 -05006464 if (phba->link_state < LPFC_LINK_DOWN ||
6465 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04006466 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05006467 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05006468
6469 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04006470 return NULL;
6471
dea31012005-04-17 16:05:31 -05006472 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6473 if (!pmboxq)
6474 return NULL;
6475 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6476
James Smart04c68492009-05-22 14:52:52 -04006477 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05006478 pmb->mbxCommand = MBX_READ_STATUS;
6479 pmb->mbxOwner = OWN_HOST;
James Smart3e1f0712018-11-29 16:09:29 -08006480 pmboxq->ctx_buf = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006481 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05006482
James Smart75baf692010-06-08 18:31:21 -04006483 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05006484 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04006485 else
dea31012005-04-17 16:05:31 -05006486 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6487
6488 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05006489 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04006490 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05006491 return NULL;
6492 }
6493
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04006494 memset(hs, 0, sizeof (struct fc_host_statistics));
6495
dea31012005-04-17 16:05:31 -05006496 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04006497 /*
6498 * The MBX_READ_STATUS returns tx_k_bytes which has to
6499 * converted to words
6500 */
6501 hs->tx_words = (uint64_t)
6502 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
6503 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05006504 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04006505 hs->rx_words = (uint64_t)
6506 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
6507 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05006508
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04006509 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05006510 pmb->mbxCommand = MBX_READ_LNK_STAT;
6511 pmb->mbxOwner = OWN_HOST;
James Smart3e1f0712018-11-29 16:09:29 -08006512 pmboxq->ctx_buf = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006513 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05006514
James Smart75baf692010-06-08 18:31:21 -04006515 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05006516 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04006517 else
dea31012005-04-17 16:05:31 -05006518 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6519
6520 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05006521 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05006522 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05006523 return NULL;
6524 }
6525
6526 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6527 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6528 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6529 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6530 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6531 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6532 hs->error_frames = pmb->un.varRdLnk.crcCnt;
6533
James Smart64ba8812006-08-02 15:24:34 -04006534 hs->link_failure_count -= lso->link_failure_count;
6535 hs->loss_of_sync_count -= lso->loss_of_sync_count;
6536 hs->loss_of_signal_count -= lso->loss_of_signal_count;
6537 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
6538 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
6539 hs->invalid_crc_count -= lso->invalid_crc_count;
6540 hs->error_frames -= lso->error_frames;
6541
James Smart76a95d72010-11-20 23:11:48 -05006542 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04006543 hs->lip_count = -1;
6544 hs->nos_count = (phba->link_events >> 1);
6545 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05006546 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05006547 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04006548 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05006549 hs->nos_count = -1;
6550 } else {
6551 hs->lip_count = -1;
6552 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04006553 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05006554 }
6555
6556 hs->dumped_frames = -1;
6557
Arnd Bergmannc4d6204d2018-06-18 17:28:23 +02006558 hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;
dea31012005-04-17 16:05:31 -05006559
James Smart1dcb58e2007-04-25 09:51:30 -04006560 mempool_free(pmboxq, phba->mbox_mem_pool);
6561
dea31012005-04-17 16:05:31 -05006562 return hs;
6563}
6564
James Smarte59058c2008-08-24 21:49:00 -04006565/**
James Smart3621a712009-04-06 18:47:14 -04006566 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04006567 * @shost: kernel scsi host pointer.
6568 **/
James Smart64ba8812006-08-02 15:24:34 -04006569static void
6570lpfc_reset_stats(struct Scsi_Host *shost)
6571{
James Smart2e0fef82007-06-17 19:56:36 -05006572 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6573 struct lpfc_hba *phba = vport->phba;
6574 struct lpfc_sli *psli = &phba->sli;
6575 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04006576 LPFC_MBOXQ_t *pmboxq;
6577 MAILBOX_t *pmb;
6578 int rc = 0;
6579
James Smart2e0fef82007-06-17 19:56:36 -05006580 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04006581 return;
6582
James Smart64ba8812006-08-02 15:24:34 -04006583 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6584 if (!pmboxq)
6585 return;
6586 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6587
James Smart04c68492009-05-22 14:52:52 -04006588 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04006589 pmb->mbxCommand = MBX_READ_STATUS;
6590 pmb->mbxOwner = OWN_HOST;
6591 pmb->un.varWords[0] = 0x1; /* reset request */
James Smart3e1f0712018-11-29 16:09:29 -08006592 pmboxq->ctx_buf = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006593 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04006594
James Smart2e0fef82007-06-17 19:56:36 -05006595 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04006596 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04006597 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6598 else
6599 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6600
6601 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05006602 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04006603 mempool_free(pmboxq, phba->mbox_mem_pool);
6604 return;
6605 }
6606
6607 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6608 pmb->mbxCommand = MBX_READ_LNK_STAT;
6609 pmb->mbxOwner = OWN_HOST;
James Smart3e1f0712018-11-29 16:09:29 -08006610 pmboxq->ctx_buf = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006611 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04006612
James Smart2e0fef82007-06-17 19:56:36 -05006613 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04006614 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04006615 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6616 else
6617 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6618
6619 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05006620 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04006621 mempool_free( pmboxq, phba->mbox_mem_pool);
6622 return;
6623 }
6624
6625 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6626 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6627 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6628 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6629 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6630 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6631 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05006632 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04006633 lso->link_events = (phba->link_events >> 1);
6634 else
6635 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04006636
Arnd Bergmannc4d6204d2018-06-18 17:28:23 +02006637 psli->stats_start = ktime_get_seconds();
James Smart64ba8812006-08-02 15:24:34 -04006638
James Smart1dcb58e2007-04-25 09:51:30 -04006639 mempool_free(pmboxq, phba->mbox_mem_pool);
6640
James Smart64ba8812006-08-02 15:24:34 -04006641 return;
6642}
dea31012005-04-17 16:05:31 -05006643
6644/*
6645 * The LPFC driver treats linkdown handling as target loss events so there
6646 * are no sysfs handlers for link_down_tmo.
6647 */
James Smart685f0bf2007-04-25 09:53:08 -04006648
James Smarte59058c2008-08-24 21:49:00 -04006649/**
James Smart3621a712009-04-06 18:47:14 -04006650 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04006651 * @starget: kernel scsi target pointer.
6652 *
6653 * Returns:
6654 * address of the node list if found
6655 * NULL target not found
6656 **/
James Smart685f0bf2007-04-25 09:53:08 -04006657static struct lpfc_nodelist *
6658lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05006659{
James Smart2e0fef82007-06-17 19:56:36 -05006660 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
6661 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04006662 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006663
6664 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04006665 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05006666 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05006667 if (NLP_CHK_NODE_ACT(ndlp) &&
6668 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04006669 starget->id == ndlp->nlp_sid) {
6670 spin_unlock_irq(shost->host_lock);
6671 return ndlp;
dea31012005-04-17 16:05:31 -05006672 }
6673 }
6674 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04006675 return NULL;
6676}
dea31012005-04-17 16:05:31 -05006677
James Smarte59058c2008-08-24 21:49:00 -04006678/**
James Smart3621a712009-04-06 18:47:14 -04006679 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04006680 * @starget: kernel scsi target pointer.
6681 **/
James Smart685f0bf2007-04-25 09:53:08 -04006682static void
6683lpfc_get_starget_port_id(struct scsi_target *starget)
6684{
6685 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6686
6687 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05006688}
6689
James Smarte59058c2008-08-24 21:49:00 -04006690/**
James Smart3621a712009-04-06 18:47:14 -04006691 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04006692 * @starget: kernel scsi target pointer.
6693 *
6694 * Description: Set the target node name to the ndlp node name wwn or zero.
6695 **/
dea31012005-04-17 16:05:31 -05006696static void
6697lpfc_get_starget_node_name(struct scsi_target *starget)
6698{
James Smart685f0bf2007-04-25 09:53:08 -04006699 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05006700
James Smart685f0bf2007-04-25 09:53:08 -04006701 fc_starget_node_name(starget) =
6702 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05006703}
6704
James Smarte59058c2008-08-24 21:49:00 -04006705/**
James Smart3621a712009-04-06 18:47:14 -04006706 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04006707 * @starget: kernel scsi target pointer.
6708 *
6709 * Description: set the target port name to the ndlp port name wwn or zero.
6710 **/
dea31012005-04-17 16:05:31 -05006711static void
6712lpfc_get_starget_port_name(struct scsi_target *starget)
6713{
James Smart685f0bf2007-04-25 09:53:08 -04006714 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05006715
James Smart685f0bf2007-04-25 09:53:08 -04006716 fc_starget_port_name(starget) =
6717 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05006718}
6719
James Smarte59058c2008-08-24 21:49:00 -04006720/**
James Smart3621a712009-04-06 18:47:14 -04006721 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04006722 * @rport: fc rport address.
6723 * @timeout: new value for dev loss tmo.
6724 *
6725 * Description:
6726 * If timeout is non zero set the dev_loss_tmo to timeout, else set
6727 * dev_loss_tmo to one.
6728 **/
dea31012005-04-17 16:05:31 -05006729static void
dea31012005-04-17 16:05:31 -05006730lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6731{
dea31012005-04-17 16:05:31 -05006732 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04006733 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05006734 else
James Smartc01f3202006-08-18 17:47:08 -04006735 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05006736}
6737
James Smarte59058c2008-08-24 21:49:00 -04006738/**
James Smart3621a712009-04-06 18:47:14 -04006739 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04006740 *
6741 * Description:
6742 * Macro that uses field to generate a function with the name lpfc_show_rport_
6743 *
6744 * lpfc_show_rport_##field: returns the bytes formatted in buf
6745 * @cdev: class converted to an fc_rport.
6746 * @buf: on return contains the target_field or zero.
6747 *
6748 * Returns: size of formatted string.
6749 **/
dea31012005-04-17 16:05:31 -05006750#define lpfc_rport_show_function(field, format_string, sz, cast) \
6751static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01006752lpfc_show_rport_##field (struct device *dev, \
6753 struct device_attribute *attr, \
6754 char *buf) \
dea31012005-04-17 16:05:31 -05006755{ \
Tony Jonesee959b02008-02-22 00:13:36 +01006756 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05006757 struct lpfc_rport_data *rdata = rport->hostdata; \
6758 return snprintf(buf, sz, format_string, \
6759 (rdata->target) ? cast rdata->target->field : 0); \
6760}
6761
6762#define lpfc_rport_rd_attr(field, format_string, sz) \
6763 lpfc_rport_show_function(field, format_string, sz, ) \
6764static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6765
James Smarteada2722008-12-04 22:39:13 -05006766/**
James Smart3621a712009-04-06 18:47:14 -04006767 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05006768 * @fc_vport: The fc_vport who's symbolic name has been changed.
6769 *
6770 * Description:
6771 * This function is called by the transport after the @fc_vport's symbolic name
6772 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006773 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05006774 **/
6775static void
6776lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6777{
6778 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6779
6780 if (vport->port_state == LPFC_VPORT_READY)
6781 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6782}
dea31012005-04-17 16:05:31 -05006783
James Smartf4b4c682009-05-22 14:53:12 -04006784/**
6785 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6786 * @phba: Pointer to lpfc_hba struct.
6787 *
6788 * This function is called by the lpfc_get_cfgparam() routine to set the
6789 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02006790 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04006791 * before hba port or vport created.
6792 **/
6793static void
6794lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6795{
6796 phba->cfg_log_verbose = verbose;
6797}
6798
dea31012005-04-17 16:05:31 -05006799struct fc_function_template lpfc_transport_functions = {
6800 /* fixed attributes the driver supports */
6801 .show_host_node_name = 1,
6802 .show_host_port_name = 1,
6803 .show_host_supported_classes = 1,
6804 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05006805 .show_host_supported_speeds = 1,
6806 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006807
6808 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006809 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05006810
6811 /* dynamic attributes the driver supports */
6812 .get_host_port_id = lpfc_get_host_port_id,
6813 .show_host_port_id = 1,
6814
6815 .get_host_port_type = lpfc_get_host_port_type,
6816 .show_host_port_type = 1,
6817
6818 .get_host_port_state = lpfc_get_host_port_state,
6819 .show_host_port_state = 1,
6820
6821 /* active_fc4s is shown but doesn't change (thus no get function) */
6822 .show_host_active_fc4s = 1,
6823
6824 .get_host_speed = lpfc_get_host_speed,
6825 .show_host_speed = 1,
6826
6827 .get_host_fabric_name = lpfc_get_host_fabric_name,
6828 .show_host_fabric_name = 1,
6829
6830 /*
6831 * The LPFC driver treats linkdown handling as target loss events
6832 * so there are no sysfs handlers for link_down_tmo.
6833 */
6834
6835 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04006836 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05006837
6838 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6839 .show_rport_maxframe_size = 1,
6840 .show_rport_supported_classes = 1,
6841
dea31012005-04-17 16:05:31 -05006842 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6843 .show_rport_dev_loss_tmo = 1,
6844
6845 .get_starget_port_id = lpfc_get_starget_port_id,
6846 .show_starget_port_id = 1,
6847
6848 .get_starget_node_name = lpfc_get_starget_node_name,
6849 .show_starget_node_name = 1,
6850
6851 .get_starget_port_name = lpfc_get_starget_port_name,
6852 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07006853
6854 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04006855 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6856 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05006857
James Smart92d7f7b2007-06-17 19:56:38 -05006858 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05006859
6860 .vport_disable = lpfc_vport_disable,
6861
6862 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04006863
6864 .bsg_request = lpfc_bsg_request,
6865 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05006866};
6867
James Smart98c9ea52007-10-27 13:37:33 -04006868struct fc_function_template lpfc_vport_transport_functions = {
6869 /* fixed attributes the driver supports */
6870 .show_host_node_name = 1,
6871 .show_host_port_name = 1,
6872 .show_host_supported_classes = 1,
6873 .show_host_supported_fc4s = 1,
6874 .show_host_supported_speeds = 1,
6875 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006876
6877 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006878 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04006879
6880 /* dynamic attributes the driver supports */
6881 .get_host_port_id = lpfc_get_host_port_id,
6882 .show_host_port_id = 1,
6883
6884 .get_host_port_type = lpfc_get_host_port_type,
6885 .show_host_port_type = 1,
6886
6887 .get_host_port_state = lpfc_get_host_port_state,
6888 .show_host_port_state = 1,
6889
6890 /* active_fc4s is shown but doesn't change (thus no get function) */
6891 .show_host_active_fc4s = 1,
6892
6893 .get_host_speed = lpfc_get_host_speed,
6894 .show_host_speed = 1,
6895
6896 .get_host_fabric_name = lpfc_get_host_fabric_name,
6897 .show_host_fabric_name = 1,
6898
6899 /*
6900 * The LPFC driver treats linkdown handling as target loss events
6901 * so there are no sysfs handlers for link_down_tmo.
6902 */
6903
6904 .get_fc_host_stats = lpfc_get_stats,
6905 .reset_fc_host_stats = lpfc_reset_stats,
6906
6907 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6908 .show_rport_maxframe_size = 1,
6909 .show_rport_supported_classes = 1,
6910
6911 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6912 .show_rport_dev_loss_tmo = 1,
6913
6914 .get_starget_port_id = lpfc_get_starget_port_id,
6915 .show_starget_port_id = 1,
6916
6917 .get_starget_node_name = lpfc_get_starget_node_name,
6918 .show_starget_node_name = 1,
6919
6920 .get_starget_port_name = lpfc_get_starget_port_name,
6921 .show_starget_port_name = 1,
6922
6923 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6924 .terminate_rport_io = lpfc_terminate_rport_io,
6925
6926 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05006927
6928 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04006929};
6930
James Smarte59058c2008-08-24 21:49:00 -04006931/**
James Smart3621a712009-04-06 18:47:14 -04006932 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04006933 * @phba: lpfc_hba pointer.
6934 **/
dea31012005-04-17 16:05:31 -05006935void
6936lpfc_get_cfgparam(struct lpfc_hba *phba)
6937{
James Smart49aa1432012-08-03 12:36:42 -04006938 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smart7ea92eb2018-10-23 13:41:10 -07006939 lpfc_ns_query_init(phba, lpfc_ns_query);
James Smarta6571c62012-10-31 14:44:42 -04006940 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006941 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6942 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05006943 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05006944 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6945 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006946 lpfc_ack0_init(phba, lpfc_ack0);
James Smartc4908502019-01-28 11:14:28 -08006947 lpfc_xri_rebalancing_init(phba, lpfc_xri_rebalancing);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006948 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006949 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05006950 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04006951 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04006952 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04006953 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05006954 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4258e982015-12-16 18:11:58 -05006955 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6956 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
James Smart4ff43242006-12-02 13:34:56 -05006957 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart895427b2017-02-12 13:52:30 -08006958 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
James Smart4e565cf2018-02-22 08:18:50 -08006959 lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);
James Smartda0436e2009-05-22 14:51:39 -04006960 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart32517fc2019-01-28 11:14:33 -08006961 lpfc_cq_poll_threshold_init(phba, lpfc_cq_poll_threshold);
6962 lpfc_cq_max_proc_limit_init(phba, lpfc_cq_max_proc_limit);
James Smart7bb03bb2013-04-17 20:19:16 -04006963 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart13815c82008-01-11 01:52:48 -05006964 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6965 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart2ea259e2017-02-12 13:52:27 -08006966
James Smart1ba981f2014-02-20 09:56:45 -05006967 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6968 if (phba->sli_rev != LPFC_SLI_REV4)
6969 phba->cfg_EnableXLane = 0;
6970 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
James Smart2ea259e2017-02-12 13:52:27 -08006971
James Smart1ba981f2014-02-20 09:56:45 -05006972 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6973 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6974 phba->cfg_oas_lun_state = 0;
6975 phba->cfg_oas_lun_status = 0;
6976 phba->cfg_oas_flags = 0;
James Smartc92c8412016-07-06 12:36:05 -07006977 phba->cfg_oas_priority = 0;
James Smart81301a92008-12-04 22:39:46 -05006978 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smartb3b98b72016-10-13 15:06:06 -07006979 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6980 lpfc_prot_guard_init(phba, lpfc_prot_guard);
James Smart45ed1192009-10-02 15:17:02 -04006981 if (phba->sli_rev == LPFC_SLI_REV4)
6982 phba->cfg_poll = 0;
6983 else
James Smart1ba981f2014-02-20 09:56:45 -05006984 phba->cfg_poll = lpfc_poll;
James Smartf44ac122018-03-05 12:04:08 -08006985
6986 if (phba->cfg_enable_bg)
6987 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
6988
James Smartf358dd02017-02-12 13:52:34 -08006989 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
James Smart4258e982015-12-16 18:11:58 -05006990
James Smart895427b2017-02-12 13:52:30 -08006991 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
James Smart2d7dbc42017-02-12 13:52:35 -08006992 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
James Smart2448e482018-04-09 14:24:24 -07006993 lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
James Smart895427b2017-02-12 13:52:30 -08006994
6995 /* Initialize first burst. Target vs Initiator are different. */
6996 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
James Smart2d7dbc42017-02-12 13:52:35 -08006997 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
James Smartcdb42be2019-01-28 11:14:21 -08006998 lpfc_hdw_queue_init(phba, lpfc_hdw_queue);
James Smart6a828b02019-01-28 11:14:31 -08006999 lpfc_irq_chann_init(phba, lpfc_irq_chann);
James Smart44fd7fe2017-08-23 16:55:47 -07007000 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
James Smart1351e692018-02-22 08:18:43 -08007001 lpfc_enable_dpp_init(phba, lpfc_enable_dpp);
James Smart895427b2017-02-12 13:52:30 -08007002
7003 if (phba->sli_rev != LPFC_SLI_REV4) {
7004 /* NVME only supported on SLI4 */
7005 phba->nvmet_support = 0;
7006 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
James Smart44fd7fe2017-08-23 16:55:47 -07007007 phba->cfg_enable_bbcr = 0;
James Smartc4908502019-01-28 11:14:28 -08007008 phba->cfg_xri_rebalancing = 0;
James Smart895427b2017-02-12 13:52:30 -08007009 } else {
7010 /* We MUST have FCP support */
7011 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
7012 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
7013 }
7014
James Smart32517fc2019-01-28 11:14:33 -08007015 phba->cfg_auto_imax = (phba->cfg_fcp_imax) ? 0 : 1;
James Smart0cf07f842017-06-01 21:07:10 -07007016
James Smart06b6fa382018-07-31 17:23:24 -07007017 phba->cfg_enable_pbde = 0;
7018
James Smart895427b2017-02-12 13:52:30 -08007019 /* A value of 0 means use the number of CPUs found in the system */
James Smartcdb42be2019-01-28 11:14:21 -08007020 if (phba->cfg_hdw_queue == 0)
7021 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
James Smart6a828b02019-01-28 11:14:31 -08007022 if (phba->cfg_irq_chann == 0)
7023 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7024 if (phba->cfg_irq_chann > phba->cfg_hdw_queue)
7025 phba->cfg_irq_chann = phba->cfg_hdw_queue;
James Smart4258e982015-12-16 18:11:58 -05007026
James Smart352e5fd2016-12-30 06:57:47 -08007027 phba->cfg_soft_wwnn = 0L;
7028 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05007029 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04007030 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04007031 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04007032 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04007033 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04007034 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05007035 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04007036 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart8eb8b962016-07-06 12:36:08 -07007037 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
James Smart12247e82016-07-06 12:36:09 -07007038 lpfc_sli_mode_init(phba, lpfc_sli_mode);
James Smartab56dc22011-02-16 12:39:57 -05007039 phba->cfg_enable_dss = 1;
James Smart7bdedb32016-07-06 12:36:00 -07007040 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
James Smartd2cc9bc2018-09-10 10:30:50 -07007041 lpfc_ras_fwlog_buffsize_init(phba, lpfc_ras_fwlog_buffsize);
7042 lpfc_ras_fwlog_level_init(phba, lpfc_ras_fwlog_level);
7043 lpfc_ras_fwlog_func_init(phba, lpfc_ras_fwlog_func);
7044
James Smartfaf0a5f2018-09-10 10:30:43 -07007045
7046 /* If the NVME FC4 type is enabled, scale the sg_seg_cnt to
7047 * accommodate 512K and 1M IOs in a single nvme buf and supply
7048 * enough NVME LS iocb buffers for larger connectivity counts.
7049 */
7050 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
7051 phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
7052 phba->cfg_iocb_cnt = 5;
7053 }
7054
James Smart3de2a652007-08-02 11:09:59 -04007055 return;
7056}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05007057
James Smarte59058c2008-08-24 21:49:00 -04007058/**
James Smart895427b2017-02-12 13:52:30 -08007059 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
7060 * dependencies between protocols and roles.
7061 * @phba: lpfc_hba pointer.
7062 **/
7063void
7064lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
7065{
James Smartcdb42be2019-01-28 11:14:21 -08007066 if (phba->cfg_hdw_queue > phba->sli4_hba.num_present_cpu)
7067 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
James Smart6a828b02019-01-28 11:14:31 -08007068 if (phba->cfg_irq_chann > phba->sli4_hba.num_present_cpu)
7069 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7070 if (phba->cfg_irq_chann > phba->cfg_hdw_queue)
7071 phba->cfg_irq_chann = phba->cfg_hdw_queue;
James Smart895427b2017-02-12 13:52:30 -08007072
James Smartf358dd02017-02-12 13:52:34 -08007073 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
7074 phba->nvmet_support) {
7075 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
James Smart2d7dbc42017-02-12 13:52:35 -08007076
7077 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
7078 "6013 %s x%x fb_size x%x, fb_max x%x\n",
7079 "NVME Target PRLI ACC enable_fb ",
7080 phba->cfg_nvme_enable_fb,
7081 phba->cfg_nvmet_fb_size,
7082 LPFC_NVMET_FB_SZ_MAX);
7083
7084 if (phba->cfg_nvme_enable_fb == 0)
7085 phba->cfg_nvmet_fb_size = 0;
7086 else {
7087 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
7088 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
7089 }
7090
James Smartbcb24f62017-11-20 16:00:36 -08007091 if (!phba->cfg_nvmet_mrq)
James Smart6a828b02019-01-28 11:14:31 -08007092 phba->cfg_nvmet_mrq = phba->cfg_irq_chann;
James Smartbcb24f62017-11-20 16:00:36 -08007093
James Smart2d7dbc42017-02-12 13:52:35 -08007094 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
James Smart6a828b02019-01-28 11:14:31 -08007095 if (phba->cfg_nvmet_mrq > phba->cfg_irq_chann) {
7096 phba->cfg_nvmet_mrq = phba->cfg_irq_chann;
James Smart2d7dbc42017-02-12 13:52:35 -08007097 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
7098 "6018 Adjust lpfc_nvmet_mrq to %d\n",
7099 phba->cfg_nvmet_mrq);
7100 }
James Smartbcb24f62017-11-20 16:00:36 -08007101 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
7102 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
7103
James Smart2d7dbc42017-02-12 13:52:35 -08007104 } else {
James Smartf358dd02017-02-12 13:52:34 -08007105 /* Not NVME Target mode. Turn off Target parameters. */
7106 phba->nvmet_support = 0;
James Smartbcb24f62017-11-20 16:00:36 -08007107 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF;
James Smart2d7dbc42017-02-12 13:52:35 -08007108 phba->cfg_nvmet_fb_size = 0;
7109 }
James Smart895427b2017-02-12 13:52:30 -08007110}
7111
7112/**
James Smart3621a712009-04-06 18:47:14 -04007113 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04007114 * @vport: lpfc_vport pointer.
7115 **/
James Smart3de2a652007-08-02 11:09:59 -04007116void
7117lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
7118{
James Smarte8b62012007-08-02 11:10:09 -04007119 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04007120 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04007121 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04007122 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
7123 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
7124 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
7125 lpfc_restrict_login_init(vport, lpfc_restrict_login);
7126 lpfc_fcp_class_init(vport, lpfc_fcp_class);
7127 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04007128 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04007129 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04007130 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
7131 lpfc_max_luns_init(vport, lpfc_max_luns);
7132 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04007133 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05007134 return;
7135}