blob: c89ffad1f43d7411697a7c515c1e8ecb48a40a5b [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 Smartd080abe2017-02-12 13:52:39 -08005 * “Broadcom” refers to Broadcom Limited 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 Smart80cc0042017-06-01 21:06:56 -0700152 struct lpfc_nodelist *ndlp;
James Smart895427b2017-02-12 13:52:30 -0800153 struct nvme_fc_remote_port *nrport;
James Smart2cee7802017-06-01 21:07:02 -0700154 uint64_t data1, data2, data3, tot;
James Smart895427b2017-02-12 13:52:30 -0800155 char *statep;
156 int len = 0;
157
158 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
159 len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n");
160 return len;
161 }
James Smartf358dd02017-02-12 13:52:34 -0800162 if (phba->nvmet_support) {
163 if (!phba->targetport) {
164 len = snprintf(buf, PAGE_SIZE,
165 "NVME Target: x%llx is not allocated\n",
166 wwn_to_u64(vport->fc_portname.u.wwn));
167 return len;
168 }
169 /* Port state is only one of two values for now. */
170 if (phba->targetport->port_id)
171 statep = "REGISTERED";
172 else
173 statep = "INIT";
174 len += snprintf(buf + len, PAGE_SIZE - len,
James Smartb4fd6812017-06-15 22:56:42 -0700175 "NVME Target Enabled State %s\n",
James Smartf358dd02017-02-12 13:52:34 -0800176 statep);
177 len += snprintf(buf + len, PAGE_SIZE - len,
178 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
179 "NVME Target: lpfc",
180 phba->brd_no,
181 wwn_to_u64(vport->fc_portname.u.wwn),
182 wwn_to_u64(vport->fc_nodename.u.wwn),
183 phba->targetport->port_id);
184
Maurizio Lombardiea98ab32017-04-18 11:55:51 +0200185 len += snprintf(buf + len, PAGE_SIZE - len,
James Smartf358dd02017-02-12 13:52:34 -0800186 "\nNVME Target: Statistics\n");
187 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
188 len += snprintf(buf+len, PAGE_SIZE-len,
189 "LS: Rcv %08x Drop %08x Abort %08x\n",
190 atomic_read(&tgtp->rcv_ls_req_in),
191 atomic_read(&tgtp->rcv_ls_req_drop),
192 atomic_read(&tgtp->xmt_ls_abort));
193 if (atomic_read(&tgtp->rcv_ls_req_in) !=
194 atomic_read(&tgtp->rcv_ls_req_out)) {
195 len += snprintf(buf+len, PAGE_SIZE-len,
196 "Rcv LS: in %08x != out %08x\n",
197 atomic_read(&tgtp->rcv_ls_req_in),
198 atomic_read(&tgtp->rcv_ls_req_out));
199 }
200
201 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart4b056682017-12-08 17:18:10 -0800202 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
James Smartf358dd02017-02-12 13:52:34 -0800203 atomic_read(&tgtp->xmt_ls_rsp),
204 atomic_read(&tgtp->xmt_ls_drop),
James Smart4b056682017-12-08 17:18:10 -0800205 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
206
207 len += snprintf(buf + len, PAGE_SIZE - len,
208 "LS: RSP Abort %08x xb %08x Err %08x\n",
209 atomic_read(&tgtp->xmt_ls_rsp_aborted),
210 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
James Smartf358dd02017-02-12 13:52:34 -0800211 atomic_read(&tgtp->xmt_ls_rsp_error));
212
213 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart50738422017-08-01 15:12:40 -0700214 "FCP: Rcv %08x Defer %08x Release %08x "
215 "Drop %08x\n",
James Smartf358dd02017-02-12 13:52:34 -0800216 atomic_read(&tgtp->rcv_fcp_cmd_in),
James Smart50738422017-08-01 15:12:40 -0700217 atomic_read(&tgtp->rcv_fcp_cmd_defer),
James Smart547077a2017-05-15 15:20:40 -0700218 atomic_read(&tgtp->xmt_fcp_release),
James Smartf358dd02017-02-12 13:52:34 -0800219 atomic_read(&tgtp->rcv_fcp_cmd_drop));
220
221 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
222 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
223 len += snprintf(buf+len, PAGE_SIZE-len,
224 "Rcv FCP: in %08x != out %08x\n",
225 atomic_read(&tgtp->rcv_fcp_cmd_in),
226 atomic_read(&tgtp->rcv_fcp_cmd_out));
227 }
228
229 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart547077a2017-05-15 15:20:40 -0700230 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
231 "drop %08x\n",
James Smartf358dd02017-02-12 13:52:34 -0800232 atomic_read(&tgtp->xmt_fcp_read),
233 atomic_read(&tgtp->xmt_fcp_read_rsp),
234 atomic_read(&tgtp->xmt_fcp_write),
James Smart547077a2017-05-15 15:20:40 -0700235 atomic_read(&tgtp->xmt_fcp_rsp),
James Smartf358dd02017-02-12 13:52:34 -0800236 atomic_read(&tgtp->xmt_fcp_drop));
237
238 len += snprintf(buf+len, PAGE_SIZE-len,
239 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
240 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
241 atomic_read(&tgtp->xmt_fcp_rsp_error),
242 atomic_read(&tgtp->xmt_fcp_rsp_drop));
243
244 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart4b056682017-12-08 17:18:10 -0800245 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
246 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
247 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
248 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
249
250 len += snprintf(buf + len, PAGE_SIZE - len,
James Smart547077a2017-05-15 15:20:40 -0700251 "ABORT: Xmt %08x Cmpl %08x\n",
252 atomic_read(&tgtp->xmt_fcp_abort),
253 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
254
255 len += snprintf(buf + len, PAGE_SIZE - len,
256 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
257 atomic_read(&tgtp->xmt_abort_sol),
258 atomic_read(&tgtp->xmt_abort_unsol),
James Smartf358dd02017-02-12 13:52:34 -0800259 atomic_read(&tgtp->xmt_abort_rsp),
James Smart547077a2017-05-15 15:20:40 -0700260 atomic_read(&tgtp->xmt_abort_rsp_error));
James Smartf358dd02017-02-12 13:52:34 -0800261
James Smart411de512018-01-30 15:58:52 -0800262 len += snprintf(buf + len, PAGE_SIZE - len,
263 "DELAY: ctx %08x fod %08x wqfull %08x\n",
264 atomic_read(&tgtp->defer_ctx),
265 atomic_read(&tgtp->defer_fod),
266 atomic_read(&tgtp->defer_wqfull));
267
Dick Kennedy66d7ce92017-08-23 16:55:42 -0700268 /* Calculate outstanding IOs */
269 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
270 tot += atomic_read(&tgtp->xmt_fcp_release);
271 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
James Smart2cee7802017-06-01 21:07:02 -0700272
James Smarta8cf5df2017-05-15 15:20:46 -0700273 len += snprintf(buf + len, PAGE_SIZE - len,
James Smart2cee7802017-06-01 21:07:02 -0700274 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
275 "CTX Outstanding %08llx\n",
James Smart966bb5b2017-06-15 22:56:45 -0700276 phba->sli4_hba.nvmet_xri_cnt,
James Smarta8cf5df2017-05-15 15:20:46 -0700277 phba->sli4_hba.nvmet_io_wait_cnt,
James Smart2cee7802017-06-01 21:07:02 -0700278 phba->sli4_hba.nvmet_io_wait_total,
279 tot);
James Smarta8cf5df2017-05-15 15:20:46 -0700280
James Smartf358dd02017-02-12 13:52:34 -0800281 len += snprintf(buf+len, PAGE_SIZE-len, "\n");
282 return len;
283 }
James Smart895427b2017-02-12 13:52:30 -0800284
285 localport = vport->localport;
286 if (!localport) {
287 len = snprintf(buf, PAGE_SIZE,
288 "NVME Initiator x%llx is not allocated\n",
289 wwn_to_u64(vport->fc_portname.u.wwn));
290 return len;
291 }
Colin Ian King5c665ae2017-12-22 00:28:52 +0000292 lport = (struct lpfc_nvme_lport *)localport->private;
James Smart895427b2017-02-12 13:52:30 -0800293 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
294
295 spin_lock_irq(shost->host_lock);
James Smart895427b2017-02-12 13:52:30 -0800296
297 /* Port state is only one of two values for now. */
298 if (localport->port_id)
299 statep = "ONLINE";
300 else
301 statep = "UNKNOWN ";
302
303 len += snprintf(buf + len, PAGE_SIZE - len,
304 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
305 "NVME LPORT lpfc",
306 phba->brd_no,
307 wwn_to_u64(vport->fc_portname.u.wwn),
308 wwn_to_u64(vport->fc_nodename.u.wwn),
309 localport->port_id, statep);
310
James Smart80cc0042017-06-01 21:06:56 -0700311 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
312 if (!ndlp->nrport)
313 continue;
314
James Smart895427b2017-02-12 13:52:30 -0800315 /* local short-hand pointer. */
James Smart80cc0042017-06-01 21:06:56 -0700316 nrport = ndlp->nrport->remoteport;
James Smart895427b2017-02-12 13:52:30 -0800317
318 /* Port state is only one of two values for now. */
319 switch (nrport->port_state) {
320 case FC_OBJSTATE_ONLINE:
321 statep = "ONLINE";
322 break;
323 case FC_OBJSTATE_UNKNOWN:
324 statep = "UNKNOWN ";
325 break;
326 default:
327 statep = "UNSUPPORTED";
328 break;
329 }
330
331 /* Tab in to show lport ownership. */
332 len += snprintf(buf + len, PAGE_SIZE - len,
333 "NVME RPORT ");
334 if (phba->brd_no >= 10)
335 len += snprintf(buf + len, PAGE_SIZE - len, " ");
336
337 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ",
338 nrport->port_name);
339 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ",
340 nrport->node_name);
341 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ",
342 nrport->port_id);
343
James Smart7d790f02017-06-01 21:06:57 -0700344 /* An NVME rport can have multiple roles. */
345 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
James Smart895427b2017-02-12 13:52:30 -0800346 len += snprintf(buf + len, PAGE_SIZE - len,
347 "INITIATOR ");
James Smart7d790f02017-06-01 21:06:57 -0700348 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
James Smart895427b2017-02-12 13:52:30 -0800349 len += snprintf(buf + len, PAGE_SIZE - len,
350 "TARGET ");
James Smart7d790f02017-06-01 21:06:57 -0700351 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
James Smart895427b2017-02-12 13:52:30 -0800352 len += snprintf(buf + len, PAGE_SIZE - len,
James Smart7d790f02017-06-01 21:06:57 -0700353 "DISCSRVC ");
354 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
355 FC_PORT_ROLE_NVME_TARGET |
356 FC_PORT_ROLE_NVME_DISCOVERY))
James Smart895427b2017-02-12 13:52:30 -0800357 len += snprintf(buf + len, PAGE_SIZE - len,
James Smart7d790f02017-06-01 21:06:57 -0700358 "UNKNOWN ROLE x%x",
James Smart895427b2017-02-12 13:52:30 -0800359 nrport->port_role);
James Smart7d790f02017-06-01 21:06:57 -0700360
James Smart895427b2017-02-12 13:52:30 -0800361 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep);
362 /* Terminate the string. */
363 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
364 }
365 spin_unlock_irq(shost->host_lock);
366
Maurizio Lombardiea98ab32017-04-18 11:55:51 +0200367 len += snprintf(buf + len, PAGE_SIZE - len, "\nNVME Statistics\n");
James Smart895427b2017-02-12 13:52:30 -0800368 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart4b056682017-12-08 17:18:10 -0800369 "LS: Xmt %010x Cmpl %010x Abort %08x\n",
James Smart2cee7802017-06-01 21:07:02 -0700370 atomic_read(&phba->fc4NvmeLsRequests),
James Smart4b056682017-12-08 17:18:10 -0800371 atomic_read(&phba->fc4NvmeLsCmpls),
372 atomic_read(&lport->xmt_ls_abort));
373
374 len += snprintf(buf + len, PAGE_SIZE - len,
375 "LS XMIT: Err %08x CMPL: xb %08x Err %08x\n",
376 atomic_read(&lport->xmt_ls_err),
377 atomic_read(&lport->cmpl_ls_xb),
378 atomic_read(&lport->cmpl_ls_err));
James Smart895427b2017-02-12 13:52:30 -0800379
James Smart2cee7802017-06-01 21:07:02 -0700380 tot = atomic_read(&phba->fc4NvmeIoCmpls);
381 data1 = atomic_read(&phba->fc4NvmeInputRequests);
382 data2 = atomic_read(&phba->fc4NvmeOutputRequests);
383 data3 = atomic_read(&phba->fc4NvmeControlRequests);
James Smart895427b2017-02-12 13:52:30 -0800384 len += snprintf(buf+len, PAGE_SIZE-len,
385 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
James Smart2cee7802017-06-01 21:07:02 -0700386 data1, data2, data3);
James Smart895427b2017-02-12 13:52:30 -0800387
388 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart4b056682017-12-08 17:18:10 -0800389 " noxri %08x nondlp %08x qdepth %08x "
390 "wqerr %08x\n",
391 atomic_read(&lport->xmt_fcp_noxri),
392 atomic_read(&lport->xmt_fcp_bad_ndlp),
393 atomic_read(&lport->xmt_fcp_qdepth),
394 atomic_read(&lport->xmt_fcp_wqerr));
395
396 len += snprintf(buf + len, PAGE_SIZE - len,
397 " Cmpl %016llx Outstanding %016llx Abort %08x\n",
398 tot, ((data1 + data2 + data3) - tot),
399 atomic_read(&lport->xmt_fcp_abort));
400
401 len += snprintf(buf + len, PAGE_SIZE - len,
402 "FCP CMPL: xb %08x Err %08x\n",
403 atomic_read(&lport->cmpl_fcp_xb),
404 atomic_read(&lport->cmpl_fcp_err));
James Smart895427b2017-02-12 13:52:30 -0800405 return len;
406}
407
408static ssize_t
James Smart81301a92008-12-04 22:39:46 -0500409lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
410 char *buf)
411{
412 struct Scsi_Host *shost = class_to_shost(dev);
413 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
414 struct lpfc_hba *phba = vport->phba;
415
416 if (phba->cfg_enable_bg)
417 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
418 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
419 else
420 return snprintf(buf, PAGE_SIZE,
421 "BlockGuard Not Supported\n");
422 else
423 return snprintf(buf, PAGE_SIZE,
424 "BlockGuard Disabled\n");
425}
426
427static ssize_t
428lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
429 char *buf)
430{
431 struct Scsi_Host *shost = class_to_shost(dev);
432 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
433 struct lpfc_hba *phba = vport->phba;
434
James Smart87b5c322008-12-16 10:34:09 -0500435 return snprintf(buf, PAGE_SIZE, "%llu\n",
436 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500437}
438
439static ssize_t
440lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
441 char *buf)
442{
443 struct Scsi_Host *shost = class_to_shost(dev);
444 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
445 struct lpfc_hba *phba = vport->phba;
446
James Smart87b5c322008-12-16 10:34:09 -0500447 return snprintf(buf, PAGE_SIZE, "%llu\n",
448 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500449}
450
451static ssize_t
452lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
453 char *buf)
454{
455 struct Scsi_Host *shost = class_to_shost(dev);
456 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
457 struct lpfc_hba *phba = vport->phba;
458
James Smart87b5c322008-12-16 10:34:09 -0500459 return snprintf(buf, PAGE_SIZE, "%llu\n",
460 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500461}
462
James Smarte59058c2008-08-24 21:49:00 -0400463/**
James Smart3621a712009-04-06 18:47:14 -0400464 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400465 * @dev: class converted to a Scsi_host structure.
466 * @attr: device attribute, not used.
467 * @buf: on return contains the formatted text from lpfc_info().
468 *
469 * Returns: size of formatted string.
470 **/
dea31012005-04-17 16:05:31 -0500471static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100472lpfc_info_show(struct device *dev, struct device_attribute *attr,
473 char *buf)
dea31012005-04-17 16:05:31 -0500474{
Tony Jonesee959b02008-02-22 00:13:36 +0100475 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500476
dea31012005-04-17 16:05:31 -0500477 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
478}
479
James Smarte59058c2008-08-24 21:49:00 -0400480/**
James Smart3621a712009-04-06 18:47:14 -0400481 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400482 * @dev: class converted to a Scsi_host structure.
483 * @attr: device attribute, not used.
484 * @buf: on return contains the formatted text serial number.
485 *
486 * Returns: size of formatted string.
487 **/
dea31012005-04-17 16:05:31 -0500488static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100489lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
490 char *buf)
dea31012005-04-17 16:05:31 -0500491{
Tony Jonesee959b02008-02-22 00:13:36 +0100492 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500493 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
494 struct lpfc_hba *phba = vport->phba;
495
dea31012005-04-17 16:05:31 -0500496 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
497}
498
James Smarte59058c2008-08-24 21:49:00 -0400499/**
James Smart3621a712009-04-06 18:47:14 -0400500 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400501 * @dev: class converted to a Scsi_host structure.
502 * @attr: device attribute, not used.
503 * @buf: on return contains the formatted support level.
504 *
505 * Description:
506 * Returns a number indicating the temperature sensor level currently
507 * supported, zero or one in ascii.
508 *
509 * Returns: size of formatted string.
510 **/
dea31012005-04-17 16:05:31 -0500511static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100512lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
513 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400514{
Tony Jonesee959b02008-02-22 00:13:36 +0100515 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
517 struct lpfc_hba *phba = vport->phba;
518 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
519}
520
James Smarte59058c2008-08-24 21:49:00 -0400521/**
James Smart3621a712009-04-06 18:47:14 -0400522 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400523 * @dev: class converted to a Scsi_host structure.
524 * @attr: device attribute, not used.
525 * @buf: on return contains the scsi vpd model description.
526 *
527 * Returns: size of formatted string.
528 **/
James Smart57127f12007-10-27 13:37:05 -0400529static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100530lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
531 char *buf)
dea31012005-04-17 16:05:31 -0500532{
Tony Jonesee959b02008-02-22 00:13:36 +0100533 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
535 struct lpfc_hba *phba = vport->phba;
536
dea31012005-04-17 16:05:31 -0500537 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
538}
539
James Smarte59058c2008-08-24 21:49:00 -0400540/**
James Smart3621a712009-04-06 18:47:14 -0400541 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400542 * @dev: class converted to a Scsi_host structure.
543 * @attr: device attribute, not used.
544 * @buf: on return contains the scsi vpd model name.
545 *
546 * Returns: size of formatted string.
547 **/
dea31012005-04-17 16:05:31 -0500548static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100549lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
550 char *buf)
dea31012005-04-17 16:05:31 -0500551{
Tony Jonesee959b02008-02-22 00:13:36 +0100552 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500553 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
554 struct lpfc_hba *phba = vport->phba;
555
dea31012005-04-17 16:05:31 -0500556 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
557}
558
James Smarte59058c2008-08-24 21:49:00 -0400559/**
James Smart3621a712009-04-06 18:47:14 -0400560 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400561 * @dev: class converted to a Scsi_host structure.
562 * @attr: device attribute, not used.
563 * @buf: on return contains the scsi vpd program type.
564 *
565 * Returns: size of formatted string.
566 **/
dea31012005-04-17 16:05:31 -0500567static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100568lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
569 char *buf)
dea31012005-04-17 16:05:31 -0500570{
Tony Jonesee959b02008-02-22 00:13:36 +0100571 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500572 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
573 struct lpfc_hba *phba = vport->phba;
574
dea31012005-04-17 16:05:31 -0500575 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
576}
577
James Smarte59058c2008-08-24 21:49:00 -0400578/**
James Smart3621a712009-04-06 18:47:14 -0400579 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400580 * @dev: class converted to a Scsi_host structure.
581 * @attr: device attribute, not used.
582 * @buf: on return contains the Menlo Maintenance sli flag.
583 *
584 * Returns: size of formatted string.
585 **/
586static ssize_t
587lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
588{
589 struct Scsi_Host *shost = class_to_shost(dev);
590 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
591 struct lpfc_hba *phba = vport->phba;
592
593 return snprintf(buf, PAGE_SIZE, "%d\n",
594 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
595}
596
597/**
James Smart3621a712009-04-06 18:47:14 -0400598 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400599 * @dev: class converted to a Scsi_host structure.
600 * @attr: device attribute, not used.
601 * @buf: on return contains scsi vpd program type.
602 *
603 * Returns: size of formatted string.
604 **/
dea31012005-04-17 16:05:31 -0500605static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100606lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
607 char *buf)
dea31012005-04-17 16:05:31 -0500608{
Tony Jonesee959b02008-02-22 00:13:36 +0100609 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500610 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
611 struct lpfc_hba *phba = vport->phba;
612
dea31012005-04-17 16:05:31 -0500613 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
614}
615
James Smarte59058c2008-08-24 21:49:00 -0400616/**
James Smart3621a712009-04-06 18:47:14 -0400617 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400618 * @dev: class converted to a Scsi_host structure.
619 * @attr: device attribute, not used.
620 * @buf: on return contains the scsi vpd program type.
621 *
622 * Returns: size of formatted string.
623 **/
dea31012005-04-17 16:05:31 -0500624static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100625lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
626 char *buf)
dea31012005-04-17 16:05:31 -0500627{
Tony Jonesee959b02008-02-22 00:13:36 +0100628 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500629 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
630 struct lpfc_hba *phba = vport->phba;
James Smart026abb82011-12-13 13:20:45 -0500631 uint32_t if_type;
632 uint8_t sli_family;
James Smart6b5151f2012-01-18 16:24:06 -0500633 char fwrev[FW_REV_STR_SIZE];
James Smart026abb82011-12-13 13:20:45 -0500634 int len;
James Smart2e0fef82007-06-17 19:56:36 -0500635
dea31012005-04-17 16:05:31 -0500636 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart026abb82011-12-13 13:20:45 -0500637 if_type = phba->sli4_hba.pc_sli4_params.if_type;
638 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
639
640 if (phba->sli_rev < LPFC_SLI_REV4)
641 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
642 fwrev, phba->sli_rev);
643 else
644 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
645 fwrev, phba->sli_rev, if_type, sli_family);
646
647 return len;
dea31012005-04-17 16:05:31 -0500648}
649
James Smarte59058c2008-08-24 21:49:00 -0400650/**
James Smart3621a712009-04-06 18:47:14 -0400651 * lpfc_hdw_show - Return the jedec information about the hba
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 scsi vpd program type.
655 *
656 * Returns: size of formatted string.
657 **/
dea31012005-04-17 16:05:31 -0500658static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100659lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500660{
661 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100662 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500663 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
664 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500665 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500666
dea31012005-04-17 16:05:31 -0500667 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
668 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
669}
James Smarte59058c2008-08-24 21:49:00 -0400670
671/**
James Smart3621a712009-04-06 18:47:14 -0400672 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400673 * @dev: class converted to a Scsi_host structure.
674 * @attr: device attribute, not used.
675 * @buf: on return contains the ROM and FCode ascii strings.
676 *
677 * Returns: size of formatted string.
678 **/
dea31012005-04-17 16:05:31 -0500679static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100680lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
681 char *buf)
dea31012005-04-17 16:05:31 -0500682{
Tony Jonesee959b02008-02-22 00:13:36 +0100683 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500684 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
685 struct lpfc_hba *phba = vport->phba;
James Smarta0683bf2015-04-07 15:07:16 -0400686 char fwrev[FW_REV_STR_SIZE];
James Smart2e0fef82007-06-17 19:56:36 -0500687
James Smarta0683bf2015-04-07 15:07:16 -0400688 if (phba->sli_rev < LPFC_SLI_REV4)
689 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
690
691 lpfc_decode_firmware_rev(phba, fwrev, 1);
692 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
dea31012005-04-17 16:05:31 -0500693}
James Smarte59058c2008-08-24 21:49:00 -0400694
695/**
James Smart3621a712009-04-06 18:47:14 -0400696 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400697 * @dev: class converted to a Scsi_host structure.
698 * @attr: device attribute, not used.
699 * @buf: on return contains text describing the state of the link.
700 *
701 * Notes:
702 * The switch statement has no default so zero will be returned.
703 *
704 * Returns: size of formatted string.
705 **/
dea31012005-04-17 16:05:31 -0500706static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100707lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
708 char *buf)
dea31012005-04-17 16:05:31 -0500709{
Tony Jonesee959b02008-02-22 00:13:36 +0100710 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500711 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
712 struct lpfc_hba *phba = vport->phba;
713 int len = 0;
714
715 switch (phba->link_state) {
716 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500717 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500718 case LPFC_INIT_START:
719 case LPFC_INIT_MBX_CMDS:
720 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500721 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400722 if (phba->hba_flag & LINK_DISABLED)
723 len += snprintf(buf + len, PAGE_SIZE-len,
724 "Link Down - User disabled\n");
725 else
726 len += snprintf(buf + len, PAGE_SIZE-len,
727 "Link Down\n");
dea31012005-04-17 16:05:31 -0500728 break;
729 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500730 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500731 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400732 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500733
734 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500735 case LPFC_LOCAL_CFG_LINK:
736 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500737 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500738 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500739 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500740 case LPFC_FLOGI:
741 case LPFC_FABRIC_CFG_LINK:
742 case LPFC_NS_REG:
743 case LPFC_NS_QRY:
744 case LPFC_BUILD_DISC_LIST:
745 case LPFC_DISC_AUTH:
746 len += snprintf(buf + len, PAGE_SIZE - len,
747 "Discovery\n");
748 break;
749 case LPFC_VPORT_READY:
750 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
751 break;
752
James Smart92d7f7b2007-06-17 19:56:38 -0500753 case LPFC_VPORT_FAILED:
754 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
755 break;
756
757 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500758 len += snprintf(buf + len, PAGE_SIZE - len,
759 "Unknown\n");
760 break;
761 }
James Smart84774a42008-08-24 21:50:06 -0400762 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
763 len += snprintf(buf + len, PAGE_SIZE-len,
764 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500765 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500766 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500767 len += snprintf(buf + len, PAGE_SIZE-len,
768 " Public Loop\n");
769 else
770 len += snprintf(buf + len, PAGE_SIZE-len,
771 " Private Loop\n");
772 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500773 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500774 len += snprintf(buf + len, PAGE_SIZE-len,
775 " Fabric\n");
776 else
777 len += snprintf(buf + len, PAGE_SIZE-len,
778 " Point-2-Point\n");
779 }
780 }
James Smart2e0fef82007-06-17 19:56:36 -0500781
dea31012005-04-17 16:05:31 -0500782 return len;
783}
784
James Smarte59058c2008-08-24 21:49:00 -0400785/**
James Smart026abb82011-12-13 13:20:45 -0500786 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
787 * @dev: class unused variable.
788 * @attr: device attribute, not used.
789 * @buf: on return contains the module description text.
790 *
791 * Returns: size of formatted string.
792 **/
793static ssize_t
794lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
795 char *buf)
796{
797 struct Scsi_Host *shost = class_to_shost(dev);
798 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
799 struct lpfc_hba *phba = vport->phba;
800
801 if (phba->sli_rev < LPFC_SLI_REV4)
802 return snprintf(buf, PAGE_SIZE, "fc\n");
803
804 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
805 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
806 return snprintf(buf, PAGE_SIZE, "fcoe\n");
807 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
808 return snprintf(buf, PAGE_SIZE, "fc\n");
809 }
810 return snprintf(buf, PAGE_SIZE, "unknown\n");
811}
812
813/**
James Smart1ba981f2014-02-20 09:56:45 -0500814 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
815 * (OAS) is supported.
816 * @dev: class unused variable.
817 * @attr: device attribute, not used.
818 * @buf: on return contains the module description text.
819 *
820 * Returns: size of formatted string.
821 **/
822static ssize_t
823lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
824 char *buf)
825{
826 struct Scsi_Host *shost = class_to_shost(dev);
827 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
828 struct lpfc_hba *phba = vport->phba;
829
830 return snprintf(buf, PAGE_SIZE, "%d\n",
831 phba->sli4_hba.pc_sli4_params.oas_supported);
832}
833
834/**
James Smart84d1b002010-02-12 14:42:33 -0500835 * lpfc_link_state_store - Transition the link_state on an HBA port
836 * @dev: class device that is converted into a Scsi_host.
837 * @attr: device attribute, not used.
838 * @buf: one or more lpfc_polling_flags values.
839 * @count: not used.
840 *
841 * Returns:
842 * -EINVAL if the buffer is not "up" or "down"
843 * return from link state change function if non-zero
844 * length of the buf on success
845 **/
846static ssize_t
847lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
848 const char *buf, size_t count)
849{
850 struct Scsi_Host *shost = class_to_shost(dev);
851 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
852 struct lpfc_hba *phba = vport->phba;
853
854 int status = -EINVAL;
855
856 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
857 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400858 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500859 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
860 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400861 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500862
863 if (status == 0)
864 return strlen(buf);
865 else
866 return status;
867}
868
869/**
James Smart3621a712009-04-06 18:47:14 -0400870 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400871 * @dev: class device that is converted into a Scsi_host.
872 * @attr: device attribute, not used.
873 * @buf: on return contains the sum of fc mapped and unmapped.
874 *
875 * Description:
876 * Returns the ascii text number of the sum of the fc mapped and unmapped
877 * vport counts.
878 *
879 * Returns: size of formatted string.
880 **/
dea31012005-04-17 16:05:31 -0500881static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100882lpfc_num_discovered_ports_show(struct device *dev,
883 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500884{
Tony Jonesee959b02008-02-22 00:13:36 +0100885 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500886 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
887
888 return snprintf(buf, PAGE_SIZE, "%d\n",
889 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500890}
891
James Smarte59058c2008-08-24 21:49:00 -0400892/**
James Smart3621a712009-04-06 18:47:14 -0400893 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400894 * @shost: Scsi_Host pointer.
895 *
896 * Description:
897 * Bring the link down gracefully then re-init the link. The firmware will
898 * re-init the fiber channel interface as required. Does not issue a LIP.
899 *
900 * Returns:
901 * -EPERM port offline or management commands are being blocked
902 * -ENOMEM cannot allocate memory for the mailbox command
903 * -EIO error sending the mailbox command
904 * zero for success
905 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700906static int
James Smart2e0fef82007-06-17 19:56:36 -0500907lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500908{
James Smart2e0fef82007-06-17 19:56:36 -0500909 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
910 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500911 LPFC_MBOXQ_t *pmboxq;
912 int mbxstatus = MBXERR_ERROR;
913
James Smart2289e952018-01-30 15:58:55 -0800914 /*
915 * If the link is offline, disabled or BLOCK_MGMT_IO
916 * it doesn't make any sense to allow issue_lip
917 */
James Smart2e0fef82007-06-17 19:56:36 -0500918 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart2289e952018-01-30 15:58:55 -0800919 (phba->hba_flag & LINK_DISABLED) ||
James Smart83108bd2008-01-11 01:53:09 -0500920 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500921 return -EPERM;
922
923 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
924
925 if (!pmboxq)
926 return -ENOMEM;
927
928 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400929 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
930 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400931
James Smart33ccf8d2006-08-17 11:57:58 -0400932 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500933
James Smart04c68492009-05-22 14:52:52 -0400934 if ((mbxstatus == MBX_SUCCESS) &&
935 (pmboxq->u.mb.mbxStatus == 0 ||
936 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400937 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
938 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
939 phba->cfg_link_speed);
940 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
941 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400942 if ((mbxstatus == MBX_SUCCESS) &&
943 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
944 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
945 "2859 SLI authentication is required "
946 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400947 }
948
James Smart5b8bd0c2007-04-25 09:52:49 -0400949 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500950 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400951 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500952
953 if (mbxstatus == MBXERR_ERROR)
954 return -EIO;
955
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700956 return 0;
dea31012005-04-17 16:05:31 -0500957}
958
James Smart895427b2017-02-12 13:52:30 -0800959int
960lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
961{
962 int cnt = 0;
963
964 spin_lock_irq(lock);
965 while (!list_empty(q)) {
966 spin_unlock_irq(lock);
967 msleep(20);
968 if (cnt++ > 250) { /* 5 secs */
969 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
970 "0466 %s %s\n",
971 "Outstanding IO when ",
972 "bringing Adapter offline\n");
973 return 0;
974 }
975 spin_lock_irq(lock);
976 }
977 spin_unlock_irq(lock);
978 return 1;
979}
980
James Smarte59058c2008-08-24 21:49:00 -0400981/**
James Smart3621a712009-04-06 18:47:14 -0400982 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400983 * @phba: lpfc_hba pointer.
984 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
985 *
986 * Notes:
987 * Assumes any error from lpfc_do_offline() will be negative.
988 * Can wait up to 5 seconds for the port ring buffers count
989 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400990 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400991 *
992 * Returns:
993 * -EIO error posting the event
994 * zero for success
995 **/
James Smart40496f02006-07-06 15:50:22 -0400996static int
James Smart46fa3112007-04-25 09:51:45 -0400997lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
998{
999 struct completion online_compl;
James Smart895427b2017-02-12 13:52:30 -08001000 struct lpfc_queue *qp = NULL;
James Smart46fa3112007-04-25 09:51:45 -04001001 struct lpfc_sli_ring *pring;
1002 struct lpfc_sli *psli;
1003 int status = 0;
James Smart46fa3112007-04-25 09:51:45 -04001004 int i;
James Smartfedd3b72011-02-16 12:39:24 -05001005 int rc;
James Smart46fa3112007-04-25 09:51:45 -04001006
1007 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001008 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -04001009 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -05001010 if (rc == 0)
1011 return -ENOMEM;
1012
James Smart46fa3112007-04-25 09:51:45 -04001013 wait_for_completion(&online_compl);
1014
1015 if (status != 0)
1016 return -EIO;
1017
1018 psli = &phba->sli;
1019
James Smart09372822008-01-11 01:52:54 -05001020 /* Wait a little for things to settle down, but not
1021 * long enough for dev loss timeout to expire.
1022 */
James Smart895427b2017-02-12 13:52:30 -08001023 if (phba->sli_rev != LPFC_SLI_REV4) {
1024 for (i = 0; i < psli->num_rings; i++) {
1025 pring = &psli->sli3_ring[i];
1026 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1027 &phba->hbalock))
1028 goto out;
1029 }
1030 } else {
1031 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1032 pring = qp->pring;
1033 if (!pring)
1034 continue;
1035 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1036 &pring->ring_lock))
1037 goto out;
James Smart46fa3112007-04-25 09:51:45 -04001038 }
1039 }
James Smart895427b2017-02-12 13:52:30 -08001040out:
James Smart46fa3112007-04-25 09:51:45 -04001041 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001042 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1043 if (rc == 0)
1044 return -ENOMEM;
1045
James Smart46fa3112007-04-25 09:51:45 -04001046 wait_for_completion(&online_compl);
1047
1048 if (status != 0)
1049 return -EIO;
1050
1051 return 0;
1052}
1053
James Smarte59058c2008-08-24 21:49:00 -04001054/**
James Smart3621a712009-04-06 18:47:14 -04001055 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -04001056 * @phba: lpfc_hba pointer.
1057 *
1058 * Description:
1059 * If the port is configured to allow a reset then the hba is brought
1060 * offline then online.
1061 *
1062 * Notes:
1063 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -05001064 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -04001065 *
1066 * Returns:
1067 * lpfc_do_offline() return code if not zero
1068 * -EIO reset not configured or error posting the event
1069 * zero for success
1070 **/
James Smart7f860592011-03-11 16:05:52 -05001071int
James Smart40496f02006-07-06 15:50:22 -04001072lpfc_selective_reset(struct lpfc_hba *phba)
1073{
1074 struct completion online_compl;
1075 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001076 int rc;
James Smart40496f02006-07-06 15:50:22 -04001077
James Smart71157c92013-07-15 18:34:36 -04001078 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001079 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -05001080
James Smart71157c92013-07-15 18:34:36 -04001081 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1082 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -04001083
James Smart71157c92013-07-15 18:34:36 -04001084 if (status != 0)
1085 return status;
1086 }
James Smart40496f02006-07-06 15:50:22 -04001087
1088 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001089 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -04001090 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -05001091 if (rc == 0)
1092 return -ENOMEM;
1093
James Smart40496f02006-07-06 15:50:22 -04001094 wait_for_completion(&online_compl);
1095
1096 if (status != 0)
1097 return -EIO;
1098
1099 return 0;
1100}
1101
James Smarte59058c2008-08-24 21:49:00 -04001102/**
James Smart3621a712009-04-06 18:47:14 -04001103 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -04001104 * @dev: class device that is converted into a Scsi_host.
1105 * @attr: device attribute, not used.
1106 * @buf: containing the string "selective".
1107 * @count: unused variable.
1108 *
1109 * Description:
1110 * If the buf contains the string "selective" then lpfc_selective_reset()
1111 * is called to perform the reset.
1112 *
1113 * Notes:
1114 * Assumes any error from lpfc_selective_reset() will be negative.
1115 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001116 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -04001117 *
1118 * Returns:
1119 * -EINVAL if the buffer does not contain the string "selective"
1120 * length of buf if lpfc-selective_reset() if the call succeeds
1121 * return value of lpfc_selective_reset() if the call fails
1122**/
James Smart40496f02006-07-06 15:50:22 -04001123static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001124lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1125 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -04001126{
Tony Jonesee959b02008-02-22 00:13:36 +01001127 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1129 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -04001130 int status = -EINVAL;
1131
James Smart73d91e52011-10-10 21:32:10 -04001132 if (!phba->cfg_enable_hba_reset)
1133 return -EACCES;
1134
James Smart40496f02006-07-06 15:50:22 -04001135 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -05001136 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -04001137
1138 if (status == 0)
1139 return strlen(buf);
1140 else
1141 return status;
1142}
1143
James Smarte59058c2008-08-24 21:49:00 -04001144/**
James Smart88a2cfb2011-07-22 18:36:33 -04001145 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1146 * @phba: lpfc_hba pointer.
1147 *
1148 * Description:
1149 * SLI4 interface type-2 device to wait on the sliport status register for
1150 * the readyness after performing a firmware reset.
1151 *
1152 * Returns:
Masanari Iida0b1587b2013-07-17 04:37:44 +09001153 * zero for success, -EPERM when port does not have privilege to perform the
James Smart026abb82011-12-13 13:20:45 -05001154 * reset, -EIO when port timeout from recovering from the reset.
1155 *
1156 * Note:
1157 * As the caller will interpret the return code by value, be careful in making
1158 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -04001159 **/
James Smart73d91e52011-10-10 21:32:10 -04001160int
James Smart88a2cfb2011-07-22 18:36:33 -04001161lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1162{
James Smartf7a919b2011-08-21 21:49:16 -04001163 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -04001164 int i;
1165
James Smartf7a919b2011-08-21 21:49:16 -04001166 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -04001167 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1168 &portstat_reg.word0);
1169
Masanari Iida0b1587b2013-07-17 04:37:44 +09001170 /* verify if privileged for the request operation */
James Smartf7a919b2011-08-21 21:49:16 -04001171 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1172 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1173 return -EPERM;
1174
James Smart88a2cfb2011-07-22 18:36:33 -04001175 /* wait for the SLI port firmware ready after firmware reset */
1176 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1177 msleep(10);
1178 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1179 &portstat_reg.word0);
1180 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1181 continue;
1182 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1183 continue;
1184 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1185 continue;
1186 break;
1187 }
1188
1189 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1190 return 0;
1191 else
1192 return -EIO;
1193}
1194
1195/**
James Smart52d52442011-05-24 11:42:45 -04001196 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -04001197 * @phba: lpfc_hba pointer.
1198 *
1199 * Description:
James Smart52d52442011-05-24 11:42:45 -04001200 * Request SLI4 interface type-2 device to perform a physical register set
1201 * access.
James Smartc0c11512011-05-24 11:41:34 -04001202 *
1203 * Returns:
1204 * zero for success
1205 **/
1206static ssize_t
James Smart52d52442011-05-24 11:42:45 -04001207lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -04001208{
1209 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -04001210 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -05001211 uint32_t before_fc_flag;
1212 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -04001213 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -05001214 int status = 0, rc = 0;
1215 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -04001216
1217 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001218 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -04001219
James Smart52d52442011-05-24 11:42:45 -04001220 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1221 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1222 LPFC_SLI_INTF_IF_TYPE_2))
1223 return -EPERM;
1224
James Smart026abb82011-12-13 13:20:45 -05001225 /* Keep state if we need to restore back */
1226 before_fc_flag = phba->pport->fc_flag;
1227 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1228
James Smartb76f2dc2011-07-22 18:37:42 -04001229 /* Disable SR-IOV virtual functions if enabled */
1230 if (phba->cfg_sriov_nr_virtfn) {
1231 pci_disable_sriov(pdev);
1232 phba->cfg_sriov_nr_virtfn = 0;
1233 }
James Smart229adb02013-04-17 20:16:51 -04001234
James Smart02936352014-04-04 13:52:12 -04001235 if (opcode == LPFC_FW_DUMP)
1236 phba->hba_flag |= HBA_FW_DUMP_OP;
1237
James Smartc0c11512011-05-24 11:41:34 -04001238 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1239
James Smart02936352014-04-04 13:52:12 -04001240 if (status != 0) {
1241 phba->hba_flag &= ~HBA_FW_DUMP_OP;
James Smartc0c11512011-05-24 11:41:34 -04001242 return status;
James Smart02936352014-04-04 13:52:12 -04001243 }
James Smartc0c11512011-05-24 11:41:34 -04001244
1245 /* wait for the device to be quiesced before firmware reset */
1246 msleep(100);
1247
1248 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1249 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -04001250
1251 if (opcode == LPFC_FW_DUMP)
1252 reg_val |= LPFC_FW_DUMP_REQUEST;
1253 else if (opcode == LPFC_FW_RESET)
1254 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1255 else if (opcode == LPFC_DV_RESET)
1256 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1257
James Smartc0c11512011-05-24 11:41:34 -04001258 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1259 LPFC_CTL_PDEV_CTL_OFFSET);
1260 /* flush */
1261 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1262
1263 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -04001264 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1265
James Smart026abb82011-12-13 13:20:45 -05001266 if (rc == -EPERM) {
Masanari Iida0b1587b2013-07-17 04:37:44 +09001267 /* no privilege for reset */
James Smart6b5151f2012-01-18 16:24:06 -05001268 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
Masanari Iida0b1587b2013-07-17 04:37:44 +09001269 "3150 No privilege to perform the requested "
James Smart6b5151f2012-01-18 16:24:06 -05001270 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -05001271 } else if (rc == -EIO) {
1272 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -05001273 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1274 "3153 Fail to perform the requested "
1275 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -04001276 return rc;
James Smart026abb82011-12-13 13:20:45 -05001277 }
1278
1279 /* keep the original port state */
1280 if (before_fc_flag & FC_OFFLINE_MODE)
1281 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001282
1283 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -05001284 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1285 LPFC_EVT_ONLINE);
1286 if (!job_posted)
1287 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001288
1289 wait_for_completion(&online_compl);
1290
James Smart026abb82011-12-13 13:20:45 -05001291out:
1292 /* in any case, restore the virtual functions enabled as before */
1293 if (sriov_nr_virtfn) {
1294 sriov_err =
1295 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1296 if (!sriov_err)
1297 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1298 }
James Smartc0c11512011-05-24 11:41:34 -04001299
James Smart026abb82011-12-13 13:20:45 -05001300 /* return proper error code */
1301 if (!rc) {
1302 if (!job_posted)
1303 rc = -ENOMEM;
1304 else if (status)
1305 rc = -EIO;
1306 }
1307 return rc;
James Smartc0c11512011-05-24 11:41:34 -04001308}
1309
1310/**
James Smart3621a712009-04-06 18:47:14 -04001311 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -04001312 * @dev: class device that is converted into a Scsi_host.
1313 * @attr: device attribute, not used.
1314 * @buf: on return contains the ascii number of nport events.
1315 *
1316 * Returns: size of formatted string.
1317 **/
dea31012005-04-17 16:05:31 -05001318static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001319lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1320 char *buf)
dea31012005-04-17 16:05:31 -05001321{
Tony Jonesee959b02008-02-22 00:13:36 +01001322 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001323 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1324 struct lpfc_hba *phba = vport->phba;
1325
dea31012005-04-17 16:05:31 -05001326 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1327}
1328
James Smarte59058c2008-08-24 21:49:00 -04001329/**
James Smart3621a712009-04-06 18:47:14 -04001330 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -04001331 * @dev: class device that is converted into a Scsi_host.
1332 * @attr: device attribute, not used.
1333 * @buf: on return contains the state of the adapter.
1334 *
1335 * Returns: size of formatted string.
1336 **/
dea31012005-04-17 16:05:31 -05001337static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001338lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1339 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001340{
Tony Jonesee959b02008-02-22 00:13:36 +01001341 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001342 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1343 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001344 char * state;
1345
James Smart2e0fef82007-06-17 19:56:36 -05001346 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001347 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001348 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001349 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001350 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001351 state = "offline";
1352 else
1353 state = "online";
1354
1355 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1356}
1357
James Smarte59058c2008-08-24 21:49:00 -04001358/**
James Smart3621a712009-04-06 18:47:14 -04001359 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001360 * @dev: class device that is converted into a Scsi_host.
1361 * @attr: device attribute, not used.
1362 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1363 * @count: unused variable.
1364 *
1365 * Returns:
1366 * -EACCES if enable hba reset not enabled
1367 * -EINVAL if the buffer does not contain a valid string (see above)
1368 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1369 * buf length greater than zero indicates success
1370 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001371static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001372lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1373 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001374{
Tony Jonesee959b02008-02-22 00:13:36 +01001375 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001376 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1377 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001378 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001379 char *board_mode_str = NULL;
1380 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001381 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001382
James Smart026abb82011-12-13 13:20:45 -05001383 if (!phba->cfg_enable_hba_reset) {
1384 status = -EACCES;
1385 goto board_mode_out;
1386 }
James Smart88a2cfb2011-07-22 18:36:33 -04001387
1388 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001389 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001390
Jamie Wellnitz41415862006-02-28 19:25:27 -05001391 init_completion(&online_compl);
1392
James Smart46fa3112007-04-25 09:51:45 -04001393 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001394 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001395 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001396 if (rc == 0) {
1397 status = -ENOMEM;
1398 goto board_mode_out;
1399 }
James Smart46fa3112007-04-25 09:51:45 -04001400 wait_for_completion(&online_compl);
James Smart522dcee2017-06-01 21:07:03 -07001401 if (status)
1402 status = -EIO;
James Smart46fa3112007-04-25 09:51:45 -04001403 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1404 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001405 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001406 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001407 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001408 else
1409 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001410 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001411 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001412 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001413 else
1414 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001415 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001416 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1417 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1418 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1419 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1420 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001421 else
James Smart026abb82011-12-13 13:20:45 -05001422 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001423
James Smart026abb82011-12-13 13:20:45 -05001424board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001425 if (!status)
1426 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001427 else {
1428 board_mode_str = strchr(buf, '\n');
1429 if (board_mode_str)
1430 *board_mode_str = '\0';
1431 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1432 "3097 Failed \"%s\", status(%d), "
1433 "fc_flag(x%x)\n",
1434 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001435 return status;
James Smart026abb82011-12-13 13:20:45 -05001436 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001437}
1438
James Smarte59058c2008-08-24 21:49:00 -04001439/**
James Smart3621a712009-04-06 18:47:14 -04001440 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001441 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001442 * @mxri: max xri count.
1443 * @axri: available xri count.
1444 * @mrpi: max rpi count.
1445 * @arpi: available rpi count.
1446 * @mvpi: max vpi count.
1447 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001448 *
1449 * Description:
1450 * If an integer pointer for an count is not null then the value for the
1451 * count is returned.
1452 *
1453 * Returns:
1454 * zero on error
1455 * one for success
1456 **/
James Smart311464e2007-08-02 11:10:37 -04001457static int
James Smart858c9f62007-06-17 19:56:39 -05001458lpfc_get_hba_info(struct lpfc_hba *phba,
1459 uint32_t *mxri, uint32_t *axri,
1460 uint32_t *mrpi, uint32_t *arpi,
1461 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001462{
James Smart04c68492009-05-22 14:52:52 -04001463 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001464 LPFC_MBOXQ_t *pmboxq;
1465 MAILBOX_t *pmb;
1466 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001467 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001468
1469 /*
1470 * prevent udev from issuing mailbox commands until the port is
1471 * configured.
1472 */
1473 if (phba->link_state < LPFC_LINK_DOWN ||
1474 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001475 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001476 return 0;
1477
1478 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1479 return 0;
1480
1481 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1482 if (!pmboxq)
1483 return 0;
1484 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1485
James Smart04c68492009-05-22 14:52:52 -04001486 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001487 pmb->mbxCommand = MBX_READ_CONFIG;
1488 pmb->mbxOwner = OWN_HOST;
1489 pmboxq->context1 = NULL;
1490
James Smart75baf692010-06-08 18:31:21 -04001491 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001492 rc = MBX_NOT_FINISHED;
1493 else
1494 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1495
1496 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001497 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001498 mempool_free(pmboxq, phba->mbox_mem_pool);
1499 return 0;
1500 }
1501
James Smartda0436e2009-05-22 14:51:39 -04001502 if (phba->sli_rev == LPFC_SLI_REV4) {
1503 rd_config = &pmboxq->u.mqe.un.rd_config;
1504 if (mrpi)
1505 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1506 if (arpi)
1507 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1508 phba->sli4_hba.max_cfg_param.rpi_used;
1509 if (mxri)
1510 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1511 if (axri)
1512 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1513 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001514
1515 /* Account for differences with SLI-3. Get vpi count from
1516 * mailbox data and subtract one for max vpi value.
1517 */
1518 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1519 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1520
James Smartda0436e2009-05-22 14:51:39 -04001521 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001522 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001523 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001524 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001525 } else {
1526 if (mrpi)
1527 *mrpi = pmb->un.varRdConfig.max_rpi;
1528 if (arpi)
1529 *arpi = pmb->un.varRdConfig.avail_rpi;
1530 if (mxri)
1531 *mxri = pmb->un.varRdConfig.max_xri;
1532 if (axri)
1533 *axri = pmb->un.varRdConfig.avail_xri;
1534 if (mvpi)
1535 *mvpi = pmb->un.varRdConfig.max_vpi;
1536 if (avpi)
1537 *avpi = pmb->un.varRdConfig.avail_vpi;
1538 }
James Smart92d7f7b2007-06-17 19:56:38 -05001539
1540 mempool_free(pmboxq, phba->mbox_mem_pool);
1541 return 1;
1542}
1543
James Smarte59058c2008-08-24 21:49:00 -04001544/**
James Smart3621a712009-04-06 18:47:14 -04001545 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001546 * @dev: class device that is converted into a Scsi_host.
1547 * @attr: device attribute, not used.
1548 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1549 *
1550 * Description:
1551 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1552 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1553 * to "Unknown" and the buffer length is returned, therefore the caller
1554 * must check for "Unknown" in the buffer to detect a failure.
1555 *
1556 * Returns: size of formatted string.
1557 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001558static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001559lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1560 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001561{
Tony Jonesee959b02008-02-22 00:13:36 +01001562 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001563 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1564 struct lpfc_hba *phba = vport->phba;
1565 uint32_t cnt;
1566
James Smart858c9f62007-06-17 19:56:39 -05001567 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001568 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1569 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1570}
1571
James Smarte59058c2008-08-24 21:49:00 -04001572/**
James Smart3621a712009-04-06 18:47:14 -04001573 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001574 * @dev: class device that is converted into a Scsi_host.
1575 * @attr: device attribute, not used.
1576 * @buf: containing the used rpi count in decimal or "Unknown".
1577 *
1578 * Description:
1579 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1580 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1581 * to "Unknown" and the buffer length is returned, therefore the caller
1582 * must check for "Unknown" in the buffer to detect a failure.
1583 *
1584 * Returns: size of formatted string.
1585 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001586static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001587lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1588 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001589{
Tony Jonesee959b02008-02-22 00:13:36 +01001590 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001591 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1592 struct lpfc_hba *phba = vport->phba;
1593 uint32_t cnt, acnt;
1594
James Smart858c9f62007-06-17 19:56:39 -05001595 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001596 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1597 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1598}
1599
James Smarte59058c2008-08-24 21:49:00 -04001600/**
James Smart3621a712009-04-06 18:47:14 -04001601 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001602 * @dev: class device that is converted into a Scsi_host.
1603 * @attr: device attribute, not used.
1604 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1605 *
1606 * Description:
1607 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1608 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1609 * to "Unknown" and the buffer length is returned, therefore the caller
1610 * must check for "Unknown" in the buffer to detect a failure.
1611 *
1612 * Returns: size of formatted string.
1613 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001614static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001615lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1616 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001617{
Tony Jonesee959b02008-02-22 00:13:36 +01001618 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001619 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1620 struct lpfc_hba *phba = vport->phba;
1621 uint32_t cnt;
1622
James Smart858c9f62007-06-17 19:56:39 -05001623 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001624 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1625 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1626}
1627
James Smarte59058c2008-08-24 21:49:00 -04001628/**
James Smart3621a712009-04-06 18:47:14 -04001629 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001630 * @dev: class device that is converted into a Scsi_host.
1631 * @attr: device attribute, not used.
1632 * @buf: on return contains the used xri count in decimal or "Unknown".
1633 *
1634 * Description:
1635 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1636 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1637 * to "Unknown" and the buffer length is returned, therefore the caller
1638 * must check for "Unknown" in the buffer to detect a failure.
1639 *
1640 * Returns: size of formatted string.
1641 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001642static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001643lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1644 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001645{
Tony Jonesee959b02008-02-22 00:13:36 +01001646 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001647 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1648 struct lpfc_hba *phba = vport->phba;
1649 uint32_t cnt, acnt;
1650
James Smart858c9f62007-06-17 19:56:39 -05001651 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1652 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1653 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1654}
1655
James Smarte59058c2008-08-24 21:49:00 -04001656/**
James Smart3621a712009-04-06 18:47:14 -04001657 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001658 * @dev: class device that is converted into a Scsi_host.
1659 * @attr: device attribute, not used.
1660 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1661 *
1662 * Description:
1663 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1664 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1665 * to "Unknown" and the buffer length is returned, therefore the caller
1666 * must check for "Unknown" in the buffer to detect a failure.
1667 *
1668 * Returns: size of formatted string.
1669 **/
James Smart858c9f62007-06-17 19:56:39 -05001670static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001671lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1672 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001673{
Tony Jonesee959b02008-02-22 00:13:36 +01001674 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001675 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1676 struct lpfc_hba *phba = vport->phba;
1677 uint32_t cnt;
1678
1679 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1680 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1681 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1682}
1683
James Smarte59058c2008-08-24 21:49:00 -04001684/**
James Smart3621a712009-04-06 18:47:14 -04001685 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001686 * @dev: class device that is converted into a Scsi_host.
1687 * @attr: device attribute, not used.
1688 * @buf: on return contains the used vpi count in decimal or "Unknown".
1689 *
1690 * Description:
1691 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1692 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1693 * to "Unknown" and the buffer length is returned, therefore the caller
1694 * must check for "Unknown" in the buffer to detect a failure.
1695 *
1696 * Returns: size of formatted string.
1697 **/
James Smart858c9f62007-06-17 19:56:39 -05001698static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001699lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1700 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001701{
Tony Jonesee959b02008-02-22 00:13:36 +01001702 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001703 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1704 struct lpfc_hba *phba = vport->phba;
1705 uint32_t cnt, acnt;
1706
1707 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001708 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1709 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1710}
1711
James Smarte59058c2008-08-24 21:49:00 -04001712/**
James Smart3621a712009-04-06 18:47:14 -04001713 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001714 * @dev: class device that is converted into a Scsi_host.
1715 * @attr: device attribute, not used.
1716 * @buf: text that must be interpreted to determine if npiv is supported.
1717 *
1718 * Description:
1719 * Buffer will contain text indicating npiv is not suppoerted on the port,
1720 * the port is an NPIV physical port, or it is an npiv virtual port with
1721 * the id of the vport.
1722 *
1723 * Returns: size of formatted string.
1724 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001725static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001726lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1727 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001728{
Tony Jonesee959b02008-02-22 00:13:36 +01001729 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001730 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1731 struct lpfc_hba *phba = vport->phba;
1732
1733 if (!(phba->max_vpi))
1734 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1735 if (vport->port_type == LPFC_PHYSICAL_PORT)
1736 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1737 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1738}
1739
James Smarte59058c2008-08-24 21:49:00 -04001740/**
James Smart3621a712009-04-06 18:47:14 -04001741 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001742 * @dev: class device that is converted into a Scsi_host.
1743 * @attr: device attribute, not used.
1744 * @buf: on return contains the cfg_poll in hex.
1745 *
1746 * Notes:
1747 * cfg_poll should be a lpfc_polling_flags type.
1748 *
1749 * Returns: size of formatted string.
1750 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001751static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001752lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1753 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001754{
Tony Jonesee959b02008-02-22 00:13:36 +01001755 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001756 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1757 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001758
1759 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1760}
1761
James Smarte59058c2008-08-24 21:49:00 -04001762/**
James Smart3621a712009-04-06 18:47:14 -04001763 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001764 * @dev: class device that is converted into a Scsi_host.
1765 * @attr: device attribute, not used.
1766 * @buf: one or more lpfc_polling_flags values.
1767 * @count: not used.
1768 *
1769 * Notes:
1770 * buf contents converted to integer and checked for a valid value.
1771 *
1772 * Returns:
1773 * -EINVAL if the buffer connot be converted or is out of range
1774 * length of the buf on success
1775 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001776static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001777lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1778 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001779{
Tony Jonesee959b02008-02-22 00:13:36 +01001780 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001781 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1782 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001783 uint32_t creg_val;
1784 uint32_t old_val;
1785 int val=0;
1786
1787 if (!isdigit(buf[0]))
1788 return -EINVAL;
1789
1790 if (sscanf(buf, "%i", &val) != 1)
1791 return -EINVAL;
1792
1793 if ((val & 0x3) != val)
1794 return -EINVAL;
1795
James Smart45ed1192009-10-02 15:17:02 -04001796 if (phba->sli_rev == LPFC_SLI_REV4)
1797 val = 0;
1798
James Smart88a2cfb2011-07-22 18:36:33 -04001799 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1800 "3051 lpfc_poll changed from %d to %d\n",
1801 phba->cfg_poll, val);
1802
James Smart2e0fef82007-06-17 19:56:36 -05001803 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001804
1805 old_val = phba->cfg_poll;
1806
1807 if (val & ENABLE_FCP_RING_POLLING) {
1808 if ((val & DISABLE_FCP_RING_INT) &&
1809 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001810 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1811 spin_unlock_irq(&phba->hbalock);
1812 return -EINVAL;
1813 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001814 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1815 writel(creg_val, phba->HCregaddr);
1816 readl(phba->HCregaddr); /* flush */
1817
1818 lpfc_poll_start_timer(phba);
1819 }
1820 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001821 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001822 return -EINVAL;
1823 }
1824
1825 if (!(val & DISABLE_FCP_RING_INT) &&
1826 (old_val & DISABLE_FCP_RING_INT))
1827 {
James Smart2e0fef82007-06-17 19:56:36 -05001828 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001829 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001830 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001831 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1832 spin_unlock_irq(&phba->hbalock);
1833 return -EINVAL;
1834 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001835 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1836 writel(creg_val, phba->HCregaddr);
1837 readl(phba->HCregaddr); /* flush */
1838 }
1839
1840 phba->cfg_poll = val;
1841
James Smart2e0fef82007-06-17 19:56:36 -05001842 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001843
1844 return strlen(buf);
1845}
dea31012005-04-17 16:05:31 -05001846
James Smarte59058c2008-08-24 21:49:00 -04001847/**
James Smartbc739052010-08-04 16:11:18 -04001848 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1849 * @dev: class unused variable.
1850 * @attr: device attribute, not used.
1851 * @buf: on return contains the module description text.
1852 *
1853 * Returns: size of formatted string.
1854 **/
1855static ssize_t
1856lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1857 char *buf)
1858{
1859 struct Scsi_Host *shost = class_to_shost(dev);
1860 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1861 struct lpfc_hba *phba = vport->phba;
1862
1863 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1864}
1865
1866/**
1867 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1868 * @dev: class unused variable.
1869 * @attr: device attribute, not used.
1870 * @buf: on return contains the module description text.
1871 *
1872 * Returns: size of formatted string.
1873 **/
1874static ssize_t
1875lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1876 char *buf)
1877{
1878 struct Scsi_Host *shost = class_to_shost(dev);
1879 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1880 struct lpfc_hba *phba = vport->phba;
1881
1882 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1883}
1884
1885/**
James Smartab56dc22011-02-16 12:39:57 -05001886 * lpfc_dss_show - Return the current state of dss and the configured state
1887 * @dev: class converted to a Scsi_host structure.
1888 * @attr: device attribute, not used.
1889 * @buf: on return contains the formatted text.
1890 *
1891 * Returns: size of formatted string.
1892 **/
1893static ssize_t
1894lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1895 char *buf)
1896{
1897 struct Scsi_Host *shost = class_to_shost(dev);
1898 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1899 struct lpfc_hba *phba = vport->phba;
1900
1901 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1902 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1903 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1904 "" : "Not ");
1905}
1906
1907/**
James Smart912e3ac2011-05-24 11:42:11 -04001908 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1909 * @dev: class converted to a Scsi_host structure.
1910 * @attr: device attribute, not used.
1911 * @buf: on return contains the formatted support level.
1912 *
1913 * Description:
1914 * Returns the maximum number of virtual functions a physical function can
1915 * support, 0 will be returned if called on virtual function.
1916 *
1917 * Returns: size of formatted string.
1918 **/
1919static ssize_t
1920lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1921 struct device_attribute *attr,
1922 char *buf)
1923{
1924 struct Scsi_Host *shost = class_to_shost(dev);
1925 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1926 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001927 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001928
James Smart0a96e972011-07-22 18:37:28 -04001929 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1930 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001931}
1932
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001933static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1934{
1935 return val >= min && val <= max;
1936}
1937
James Smart912e3ac2011-05-24 11:42:11 -04001938/**
James Smart44fd7fe2017-08-23 16:55:47 -07001939 * lpfc_enable_bbcr_set: Sets an attribute value.
1940 * @phba: pointer the the adapter structure.
1941 * @val: integer attribute value.
1942 *
1943 * Description:
1944 * Validates the min and max values then sets the
1945 * adapter config field if in the valid range. prints error message
1946 * and does not set the parameter if invalid.
1947 *
1948 * Returns:
1949 * zero on success
1950 * -EINVAL if val is invalid
1951 */
1952static ssize_t
1953lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
1954{
1955 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
1956 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1957 "3068 %s_enable_bbcr changed from %d to %d\n",
1958 LPFC_DRIVER_NAME, phba->cfg_enable_bbcr, val);
1959 phba->cfg_enable_bbcr = val;
1960 return 0;
1961 }
1962 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1963 "0451 %s_enable_bbcr cannot set to %d, range is 0, 1\n",
1964 LPFC_DRIVER_NAME, val);
1965 return -EINVAL;
1966}
1967
1968/**
James Smart3621a712009-04-06 18:47:14 -04001969 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001970 *
1971 * Description:
1972 * Macro that given an attr e.g. hba_queue_depth expands
1973 * into a function with the name lpfc_hba_queue_depth_show.
1974 *
1975 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1976 * @dev: class device that is converted into a Scsi_host.
1977 * @attr: device attribute, not used.
1978 * @buf: on return contains the attribute value in decimal.
1979 *
1980 * Returns: size of formatted string.
1981 **/
dea31012005-04-17 16:05:31 -05001982#define lpfc_param_show(attr) \
1983static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001984lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1985 char *buf) \
dea31012005-04-17 16:05:31 -05001986{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001987 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001988 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1989 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001990 return snprintf(buf, PAGE_SIZE, "%d\n",\
1991 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001992}
1993
James Smarte59058c2008-08-24 21:49:00 -04001994/**
James Smart3621a712009-04-06 18:47:14 -04001995 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001996 *
1997 * Description:
1998 * Macro that given an attr e.g. hba_queue_depth expands
1999 * into a function with the name lpfc_hba_queue_depth_show
2000 *
2001 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
2002 * @dev: class device that is converted into a Scsi_host.
2003 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002004 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002005 *
2006 * Returns: size of formatted string.
2007 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002008#define lpfc_param_hex_show(attr) \
2009static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002010lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2011 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002012{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002013 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002014 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2015 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05002016 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002017 val = phba->cfg_##attr;\
2018 return snprintf(buf, PAGE_SIZE, "%#x\n",\
2019 phba->cfg_##attr);\
2020}
2021
James Smarte59058c2008-08-24 21:49:00 -04002022/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04002023 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002024 *
2025 * Description:
2026 * Macro that given an attr e.g. hba_queue_depth expands
2027 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2028 * takes a default argument, a minimum and maximum argument.
2029 *
2030 * lpfc_##attr##_init: Initializes an attribute.
2031 * @phba: pointer the the adapter structure.
2032 * @val: integer attribute value.
2033 *
2034 * Validates the min and max values then sets the adapter config field
2035 * accordingly, or uses the default if out of range and prints an error message.
2036 *
2037 * Returns:
2038 * zero on success
2039 * -EINVAL if default used
2040 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002041#define lpfc_param_init(attr, default, minval, maxval) \
2042static int \
James Smart84d1b002010-02-12 14:42:33 -05002043lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002044{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002045 if (lpfc_rangecheck(val, minval, maxval)) {\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002046 phba->cfg_##attr = val;\
2047 return 0;\
2048 }\
2049 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04002050 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2051 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002052 phba->cfg_##attr = default;\
2053 return -EINVAL;\
2054}
2055
James Smarte59058c2008-08-24 21:49:00 -04002056/**
James Smart3621a712009-04-06 18:47:14 -04002057 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04002058 *
2059 * Description:
2060 * Macro that given an attr e.g. hba_queue_depth expands
2061 * into a function with the name lpfc_hba_queue_depth_set
2062 *
2063 * lpfc_##attr##_set: Sets an attribute value.
2064 * @phba: pointer the the adapter structure.
2065 * @val: integer attribute value.
2066 *
2067 * Description:
2068 * Validates the min and max values then sets the
2069 * adapter config field if in the valid range. prints error message
2070 * and does not set the parameter if invalid.
2071 *
2072 * Returns:
2073 * zero on success
2074 * -EINVAL if val is invalid
2075 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002076#define lpfc_param_set(attr, default, minval, maxval) \
2077static int \
James Smart84d1b002010-02-12 14:42:33 -05002078lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002079{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002080 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002081 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2082 "3052 lpfc_" #attr " changed from %d to %d\n", \
2083 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002084 phba->cfg_##attr = val;\
2085 return 0;\
2086 }\
2087 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04002088 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2089 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002090 return -EINVAL;\
2091}
2092
James Smarte59058c2008-08-24 21:49:00 -04002093/**
James Smart3621a712009-04-06 18:47:14 -04002094 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04002095 *
2096 * Description:
2097 * Macro that given an attr e.g. hba_queue_depth expands
2098 * into a function with the name lpfc_hba_queue_depth_store.
2099 *
2100 * lpfc_##attr##_store: Set an sttribute value.
2101 * @dev: class device that is converted into a Scsi_host.
2102 * @attr: device attribute, not used.
2103 * @buf: contains the attribute value in ascii.
2104 * @count: not used.
2105 *
2106 * Description:
2107 * Convert the ascii text number to an integer, then
2108 * use the lpfc_##attr##_set function to set the value.
2109 *
2110 * Returns:
2111 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2112 * length of buffer upon success.
2113 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002114#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05002115static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002116lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2117 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05002118{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002119 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002120 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2121 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05002122 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002123 if (!isdigit(buf[0]))\
2124 return -EINVAL;\
2125 if (sscanf(buf, "%i", &val) != 1)\
2126 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002127 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04002128 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002129 else \
2130 return -EINVAL;\
dea31012005-04-17 16:05:31 -05002131}
2132
James Smarte59058c2008-08-24 21:49:00 -04002133/**
James Smart3621a712009-04-06 18:47:14 -04002134 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04002135 *
2136 * Description:
2137 * Macro that given an attr e.g. hba_queue_depth expands
2138 * into a function with the name lpfc_hba_queue_depth_show
2139 *
2140 * lpfc_##attr##_show: prints the attribute value in decimal.
2141 * @dev: class device that is converted into a Scsi_host.
2142 * @attr: device attribute, not used.
2143 * @buf: on return contains the attribute value in decimal.
2144 *
2145 * Returns: length of formatted string.
2146 **/
James Smart3de2a652007-08-02 11:09:59 -04002147#define lpfc_vport_param_show(attr) \
2148static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002149lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2150 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002151{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002152 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002153 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002154 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2155}
2156
James Smarte59058c2008-08-24 21:49:00 -04002157/**
James Smart3621a712009-04-06 18:47:14 -04002158 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04002159 *
2160 * Description:
2161 * Macro that given an attr e.g.
2162 * hba_queue_depth expands into a function with the name
2163 * lpfc_hba_queue_depth_show
2164 *
James Smart3621a712009-04-06 18:47:14 -04002165 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002166 * @dev: class device that is converted into a Scsi_host.
2167 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002168 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002169 *
2170 * Returns: length of formatted string.
2171 **/
James Smart3de2a652007-08-02 11:09:59 -04002172#define lpfc_vport_param_hex_show(attr) \
2173static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002174lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2175 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002176{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002177 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002178 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002179 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2180}
2181
James Smarte59058c2008-08-24 21:49:00 -04002182/**
James Smart3621a712009-04-06 18:47:14 -04002183 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002184 *
2185 * Description:
2186 * Macro that given an attr e.g. hba_queue_depth expands
2187 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2188 * takes a default argument, a minimum and maximum argument.
2189 *
2190 * lpfc_##attr##_init: validates the min and max values then sets the
2191 * adapter config field accordingly, or uses the default if out of range
2192 * and prints an error message.
2193 * @phba: pointer the the adapter structure.
2194 * @val: integer attribute value.
2195 *
2196 * Returns:
2197 * zero on success
2198 * -EINVAL if default used
2199 **/
James Smart3de2a652007-08-02 11:09:59 -04002200#define lpfc_vport_param_init(attr, default, minval, maxval) \
2201static int \
James Smart84d1b002010-02-12 14:42:33 -05002202lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002203{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002204 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart3de2a652007-08-02 11:09:59 -04002205 vport->cfg_##attr = val;\
2206 return 0;\
2207 }\
James Smarte8b62012007-08-02 11:10:09 -04002208 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002209 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002210 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002211 vport->cfg_##attr = default;\
2212 return -EINVAL;\
2213}
2214
James Smarte59058c2008-08-24 21:49:00 -04002215/**
James Smart3621a712009-04-06 18:47:14 -04002216 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002217 *
2218 * Description:
2219 * Macro that given an attr e.g. hba_queue_depth expands
2220 * into a function with the name lpfc_hba_queue_depth_set
2221 *
2222 * lpfc_##attr##_set: validates the min and max values then sets the
2223 * adapter config field if in the valid range. prints error message
2224 * and does not set the parameter if invalid.
2225 * @phba: pointer the the adapter structure.
2226 * @val: integer attribute value.
2227 *
2228 * Returns:
2229 * zero on success
2230 * -EINVAL if val is invalid
2231 **/
James Smart3de2a652007-08-02 11:09:59 -04002232#define lpfc_vport_param_set(attr, default, minval, maxval) \
2233static int \
James Smart84d1b002010-02-12 14:42:33 -05002234lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002235{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002236 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002237 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04002238 "3053 lpfc_" #attr \
2239 " changed from %d (x%x) to %d (x%x)\n", \
2240 vport->cfg_##attr, vport->cfg_##attr, \
2241 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04002242 vport->cfg_##attr = val;\
2243 return 0;\
2244 }\
James Smarte8b62012007-08-02 11:10:09 -04002245 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002246 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002247 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002248 return -EINVAL;\
2249}
2250
James Smarte59058c2008-08-24 21:49:00 -04002251/**
James Smart3621a712009-04-06 18:47:14 -04002252 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04002253 *
2254 * Description:
2255 * Macro that given an attr e.g. hba_queue_depth
2256 * expands into a function with the name lpfc_hba_queue_depth_store
2257 *
2258 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2259 * use the lpfc_##attr##_set function to set the value.
2260 * @cdev: class device that is converted into a Scsi_host.
2261 * @buf: contains the attribute value in decimal.
2262 * @count: not used.
2263 *
2264 * Returns:
2265 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2266 * length of buffer upon success.
2267 **/
James Smart3de2a652007-08-02 11:09:59 -04002268#define lpfc_vport_param_store(attr) \
2269static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002270lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2271 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04002272{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002273 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002274 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05002275 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04002276 if (!isdigit(buf[0]))\
2277 return -EINVAL;\
2278 if (sscanf(buf, "%i", &val) != 1)\
2279 return -EINVAL;\
2280 if (lpfc_##attr##_set(vport, val) == 0) \
2281 return strlen(buf);\
2282 else \
2283 return -EINVAL;\
2284}
2285
2286
James Smart895427b2017-02-12 13:52:30 -08002287static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
James Smart81301a92008-12-04 22:39:46 -05002288static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2289static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2290static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2291static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002292static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2293static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2294static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2295static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2296static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2297static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2298static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2299static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002300static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2301 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002302static DEVICE_ATTR(option_rom_version, S_IRUGO,
2303 lpfc_option_rom_version_show, NULL);
2304static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2305 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002306static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002307static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
Joe Perchesc828a892017-12-19 10:15:08 -08002308static DEVICE_ATTR_RO(lpfc_drvr_version);
2309static DEVICE_ATTR_RO(lpfc_enable_fip);
Tony Jonesee959b02008-02-22 00:13:36 +01002310static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2311 lpfc_board_mode_show, lpfc_board_mode_store);
2312static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2313static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2314static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2315static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2316static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2317static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2318static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2319static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
Joe Perchesc828a892017-12-19 10:15:08 -08002320static DEVICE_ATTR_RO(lpfc_temp_sensor);
2321static DEVICE_ATTR_RO(lpfc_fips_level);
2322static DEVICE_ATTR_RO(lpfc_fips_rev);
2323static DEVICE_ATTR_RO(lpfc_dss);
2324static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
James Smart026abb82011-12-13 13:20:45 -05002325static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05002326static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2327 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002328
James Smart352e5fd2016-12-30 06:57:47 -08002329static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smart1ba981f2014-02-20 09:56:45 -05002330#define WWN_SZ 8
2331/**
2332 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2333 * @buf: WWN string.
2334 * @cnt: Length of string.
2335 * @wwn: Array to receive converted wwn value.
2336 *
2337 * Returns:
2338 * -EINVAL if the buffer does not contain a valid wwn
2339 * 0 success
2340 **/
2341static size_t
2342lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2343{
2344 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002345
James Smart1ba981f2014-02-20 09:56:45 -05002346 /* Count may include a LF at end of string */
2347 if (buf[cnt-1] == '\n')
2348 cnt--;
2349
2350 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2351 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2352 return -EINVAL;
2353
2354 memset(wwn, 0, WWN_SZ);
2355
2356 /* Validate and store the new name */
2357 for (i = 0, j = 0; i < 16; i++) {
2358 if ((*buf >= 'a') && (*buf <= 'f'))
2359 j = ((j << 4) | ((*buf++ - 'a') + 10));
2360 else if ((*buf >= 'A') && (*buf <= 'F'))
2361 j = ((j << 4) | ((*buf++ - 'A') + 10));
2362 else if ((*buf >= '0') && (*buf <= '9'))
2363 j = ((j << 4) | (*buf++ - '0'));
2364 else
2365 return -EINVAL;
2366 if (i % 2) {
2367 wwn[i/2] = j & 0xff;
2368 j = 0;
2369 }
2370 }
2371 return 0;
2372}
James Smart352e5fd2016-12-30 06:57:47 -08002373/**
2374 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2375 * @dev: class device that is converted into a Scsi_host.
2376 * @attr: device attribute, not used.
2377 * @buf: containing the string lpfc_soft_wwn_key.
2378 * @count: must be size of lpfc_soft_wwn_key.
2379 *
2380 * Returns:
2381 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2382 * length of buf indicates success
2383 **/
2384static ssize_t
2385lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2386 const char *buf, size_t count)
2387{
2388 struct Scsi_Host *shost = class_to_shost(dev);
2389 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2390 struct lpfc_hba *phba = vport->phba;
2391 unsigned int cnt = count;
James Smartaeb3c812017-04-21 16:05:02 -07002392 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2393 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
James Smart352e5fd2016-12-30 06:57:47 -08002394
2395 /*
2396 * We're doing a simple sanity check for soft_wwpn setting.
2397 * We require that the user write a specific key to enable
2398 * the soft_wwpn attribute to be settable. Once the attribute
2399 * is written, the enable key resets. If further updates are
2400 * desired, the key must be written again to re-enable the
2401 * attribute.
2402 *
2403 * The "key" is not secret - it is a hardcoded string shown
2404 * here. The intent is to protect against the random user or
2405 * application that is just writing attributes.
2406 */
James Smartaeb3c812017-04-21 16:05:02 -07002407 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2408 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2409 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2410 " be enabled: fawwpn is enabled\n");
2411 return -EINVAL;
2412 }
James Smart352e5fd2016-12-30 06:57:47 -08002413
2414 /* count may include a LF at end of string */
2415 if (buf[cnt-1] == '\n')
2416 cnt--;
2417
2418 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2419 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2420 return -EINVAL;
2421
2422 phba->soft_wwn_enable = 1;
2423
2424 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2425 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2426 phba->brd_no);
2427 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2428 " The soft_wwpn feature is not supported by Broadcom.");
2429
2430 return count;
2431}
Joe Perches6cbaefb2017-12-19 10:15:09 -08002432static DEVICE_ATTR_WO(lpfc_soft_wwn_enable);
James Smart352e5fd2016-12-30 06:57:47 -08002433
2434/**
2435 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2436 * @dev: class device that is converted into a Scsi_host.
2437 * @attr: device attribute, not used.
2438 * @buf: on return contains the wwpn in hexadecimal.
2439 *
2440 * Returns: size of formatted string.
2441 **/
2442static ssize_t
2443lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2444 char *buf)
2445{
2446 struct Scsi_Host *shost = class_to_shost(dev);
2447 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2448 struct lpfc_hba *phba = vport->phba;
2449
2450 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2451 (unsigned long long)phba->cfg_soft_wwpn);
2452}
2453
2454/**
2455 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2456 * @dev class device that is converted into a Scsi_host.
2457 * @attr: device attribute, not used.
2458 * @buf: contains the wwpn in hexadecimal.
2459 * @count: number of wwpn bytes in buf
2460 *
2461 * Returns:
2462 * -EACCES hba reset not enabled, adapter over temp
2463 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2464 * -EIO error taking adapter offline or online
2465 * value of count on success
2466 **/
2467static ssize_t
2468lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2469 const char *buf, size_t count)
2470{
2471 struct Scsi_Host *shost = class_to_shost(dev);
2472 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2473 struct lpfc_hba *phba = vport->phba;
2474 struct completion online_compl;
2475 int stat1 = 0, stat2 = 0;
2476 unsigned int cnt = count;
2477 u8 wwpn[WWN_SZ];
2478 int rc;
2479
2480 if (!phba->cfg_enable_hba_reset)
2481 return -EACCES;
2482 spin_lock_irq(&phba->hbalock);
2483 if (phba->over_temp_state == HBA_OVER_TEMP) {
2484 spin_unlock_irq(&phba->hbalock);
2485 return -EACCES;
2486 }
2487 spin_unlock_irq(&phba->hbalock);
2488 /* count may include a LF at end of string */
2489 if (buf[cnt-1] == '\n')
2490 cnt--;
2491
2492 if (!phba->soft_wwn_enable)
2493 return -EINVAL;
2494
2495 /* lock setting wwpn, wwnn down */
2496 phba->soft_wwn_enable = 0;
2497
2498 rc = lpfc_wwn_set(buf, cnt, wwpn);
James Smarte2934ed2017-01-17 12:31:56 -08002499 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002500 /* not able to set wwpn, unlock it */
2501 phba->soft_wwn_enable = 1;
2502 return rc;
2503 }
2504
2505 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2506 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2507 if (phba->cfg_soft_wwnn)
2508 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2509
2510 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2511 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2512
2513 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2514 if (stat1)
2515 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2516 "0463 lpfc_soft_wwpn attribute set failed to "
2517 "reinit adapter - %d\n", stat1);
2518 init_completion(&online_compl);
2519 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2520 LPFC_EVT_ONLINE);
2521 if (rc == 0)
2522 return -ENOMEM;
2523
2524 wait_for_completion(&online_compl);
2525 if (stat2)
2526 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2527 "0464 lpfc_soft_wwpn attribute set failed to "
2528 "reinit adapter - %d\n", stat2);
2529 return (stat1 || stat2) ? -EIO : count;
2530}
Joe Perchesb6b996b2017-12-19 10:15:07 -08002531static DEVICE_ATTR_RW(lpfc_soft_wwpn);
James Smart352e5fd2016-12-30 06:57:47 -08002532
2533/**
2534 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2535 * @dev: class device that is converted into a Scsi_host.
2536 * @attr: device attribute, not used.
2537 * @buf: on return contains the wwnn in hexadecimal.
2538 *
2539 * Returns: size of formatted string.
2540 **/
2541static ssize_t
2542lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2543 char *buf)
2544{
2545 struct Scsi_Host *shost = class_to_shost(dev);
2546 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2547 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2548 (unsigned long long)phba->cfg_soft_wwnn);
2549}
2550
2551/**
2552 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2553 * @cdev: class device that is converted into a Scsi_host.
2554 * @buf: contains the ww node name in hexadecimal.
2555 * @count: number of wwnn bytes in buf.
2556 *
2557 * Returns:
2558 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2559 * value of count on success
2560 **/
2561static ssize_t
2562lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2563 const char *buf, size_t count)
2564{
2565 struct Scsi_Host *shost = class_to_shost(dev);
2566 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2567 unsigned int cnt = count;
2568 u8 wwnn[WWN_SZ];
2569 int rc;
2570
2571 /* count may include a LF at end of string */
2572 if (buf[cnt-1] == '\n')
2573 cnt--;
2574
2575 if (!phba->soft_wwn_enable)
2576 return -EINVAL;
2577
2578 rc = lpfc_wwn_set(buf, cnt, wwnn);
James Smarte2934ed2017-01-17 12:31:56 -08002579 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002580 /* Allow wwnn to be set many times, as long as the enable
2581 * is set. However, once the wwpn is set, everything locks.
2582 */
2583 return rc;
2584 }
2585
2586 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2587
2588 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2589 "lpfc%d: soft_wwnn set. Value will take effect upon "
2590 "setting of the soft_wwpn\n", phba->brd_no);
2591
2592 return count;
2593}
Joe Perchesb6b996b2017-12-19 10:15:07 -08002594static DEVICE_ATTR_RW(lpfc_soft_wwnn);
James Smarta12e07b2006-12-02 13:35:30 -05002595
James Smart1ba981f2014-02-20 09:56:45 -05002596/**
2597 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2598 * Optimized Access Storage (OAS) operations.
2599 * @dev: class device that is converted into a Scsi_host.
2600 * @attr: device attribute, not used.
2601 * @buf: buffer for passing information.
2602 *
2603 * Returns:
2604 * value of count
2605 **/
2606static ssize_t
2607lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2608 char *buf)
2609{
2610 struct Scsi_Host *shost = class_to_shost(dev);
2611 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2612
2613 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2614 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2615}
2616
2617/**
2618 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2619 * Optimized Access Storage (OAS) operations.
2620 * @dev: class device that is converted into a Scsi_host.
2621 * @attr: device attribute, not used.
2622 * @buf: buffer for passing information.
2623 * @count: Size of the data buffer.
2624 *
2625 * Returns:
2626 * -EINVAL count is invalid, invalid wwpn byte invalid
2627 * -EPERM oas is not supported by hba
2628 * value of count on success
2629 **/
2630static ssize_t
2631lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2632 const char *buf, size_t count)
2633{
2634 struct Scsi_Host *shost = class_to_shost(dev);
2635 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2636 unsigned int cnt = count;
2637 uint8_t wwpn[WWN_SZ];
2638 int rc;
2639
James Smartf38fa0b2014-04-04 13:52:21 -04002640 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002641 return -EPERM;
2642
2643 /* count may include a LF at end of string */
2644 if (buf[cnt-1] == '\n')
2645 cnt--;
2646
2647 rc = lpfc_wwn_set(buf, cnt, wwpn);
2648 if (rc)
2649 return rc;
2650
2651 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2652 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2653 if (wwn_to_u64(wwpn) == 0)
2654 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2655 else
2656 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2657 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2658 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2659 return count;
2660}
2661static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2662 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2663
2664/**
James Smartc92c8412016-07-06 12:36:05 -07002665 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2666 * Optimized Access Storage (OAS) operations.
2667 * @dev: class device that is converted into a Scsi_host.
2668 * @attr: device attribute, not used.
2669 * @buf: buffer for passing information.
2670 *
2671 * Returns:
2672 * value of count
2673 **/
2674static ssize_t
2675lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2676 char *buf)
2677{
2678 struct Scsi_Host *shost = class_to_shost(dev);
2679 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2680
2681 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2682}
2683
2684/**
2685 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2686 * Optimized Access Storage (OAS) operations.
2687 * @dev: class device that is converted into a Scsi_host.
2688 * @attr: device attribute, not used.
2689 * @buf: buffer for passing information.
2690 * @count: Size of the data buffer.
2691 *
2692 * Returns:
2693 * -EINVAL count is invalid, invalid wwpn byte invalid
2694 * -EPERM oas is not supported by hba
2695 * value of count on success
2696 **/
2697static ssize_t
2698lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2699 const char *buf, size_t count)
2700{
2701 struct Scsi_Host *shost = class_to_shost(dev);
2702 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2703 unsigned int cnt = count;
2704 unsigned long val;
2705 int ret;
2706
2707 if (!phba->cfg_fof)
2708 return -EPERM;
2709
2710 /* count may include a LF at end of string */
2711 if (buf[cnt-1] == '\n')
2712 cnt--;
2713
2714 ret = kstrtoul(buf, 0, &val);
2715 if (ret || (val > 0x7f))
2716 return -EINVAL;
2717
2718 if (val)
2719 phba->cfg_oas_priority = (uint8_t)val;
2720 else
2721 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2722 return count;
2723}
2724static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2725 lpfc_oas_priority_show, lpfc_oas_priority_store);
2726
2727/**
James Smart1ba981f2014-02-20 09:56:45 -05002728 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2729 * for Optimized Access Storage (OAS) operations.
2730 * @dev: class device that is converted into a Scsi_host.
2731 * @attr: device attribute, not used.
2732 * @buf: buffer for passing information.
2733 *
2734 * Returns:
2735 * value of count on success
2736 **/
2737static ssize_t
2738lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2739 char *buf)
2740{
2741 struct Scsi_Host *shost = class_to_shost(dev);
2742 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2743
2744 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2745 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2746}
2747
2748/**
2749 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2750 * for Optimized Access Storage (OAS) operations.
2751 * @dev: class device that is converted into a Scsi_host.
2752 * @attr: device attribute, not used.
2753 * @buf: buffer for passing information.
2754 * @count: Size of the data buffer.
2755 *
2756 * Returns:
2757 * -EINVAL count is invalid, invalid wwpn byte invalid
2758 * -EPERM oas is not supported by hba
2759 * value of count on success
2760 **/
2761static ssize_t
2762lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2763 const char *buf, size_t count)
2764{
2765 struct Scsi_Host *shost = class_to_shost(dev);
2766 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2767 unsigned int cnt = count;
2768 uint8_t wwpn[WWN_SZ];
2769 int rc;
2770
James Smartf38fa0b2014-04-04 13:52:21 -04002771 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002772 return -EPERM;
2773
2774 /* count may include a LF at end of string */
2775 if (buf[cnt-1] == '\n')
2776 cnt--;
2777
2778 rc = lpfc_wwn_set(buf, cnt, wwpn);
2779 if (rc)
2780 return rc;
2781
2782 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2783 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2784 if (wwn_to_u64(wwpn) == 0)
2785 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2786 else
2787 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2788 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
James Smartb5749fe2016-12-19 15:07:26 -08002789 if (phba->cfg_oas_priority == 0)
2790 phba->cfg_oas_priority = phba->cfg_XLanePriority;
James Smart1ba981f2014-02-20 09:56:45 -05002791 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2792 return count;
2793}
2794static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2795 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2796
2797/**
2798 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2799 * of whether luns will be enabled or disabled
2800 * for Optimized Access Storage (OAS) operations.
2801 * @dev: class device that is converted into a Scsi_host.
2802 * @attr: device attribute, not used.
2803 * @buf: buffer for passing information.
2804 *
2805 * Returns:
2806 * size of formatted string.
2807 **/
2808static ssize_t
2809lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2810 char *buf)
2811{
2812 struct Scsi_Host *shost = class_to_shost(dev);
2813 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2814
2815 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2816}
2817
2818/**
2819 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2820 * of whether luns will be enabled or disabled
2821 * for Optimized Access Storage (OAS) operations.
2822 * @dev: class device that is converted into a Scsi_host.
2823 * @attr: device attribute, not used.
2824 * @buf: buffer for passing information.
2825 * @count: Size of the data buffer.
2826 *
2827 * Returns:
2828 * -EINVAL count is invalid, invalid wwpn byte invalid
2829 * -EPERM oas is not supported by hba
2830 * value of count on success
2831 **/
2832static ssize_t
2833lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2834 const char *buf, size_t count)
2835{
2836 struct Scsi_Host *shost = class_to_shost(dev);
2837 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2838 int val = 0;
2839
James Smartf38fa0b2014-04-04 13:52:21 -04002840 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002841 return -EPERM;
2842
2843 if (!isdigit(buf[0]))
2844 return -EINVAL;
2845
2846 if (sscanf(buf, "%i", &val) != 1)
2847 return -EINVAL;
2848
2849 if ((val != 0) && (val != 1))
2850 return -EINVAL;
2851
2852 phba->cfg_oas_lun_state = val;
James Smart1ba981f2014-02-20 09:56:45 -05002853 return strlen(buf);
2854}
2855static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2856 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2857
2858/**
2859 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2860 * Storage (OAS) lun returned by the
2861 * lpfc_oas_lun_show function.
2862 * @dev: class device that is converted into a Scsi_host.
2863 * @attr: device attribute, not used.
2864 * @buf: buffer for passing information.
2865 *
2866 * Returns:
2867 * size of formatted string.
2868 **/
2869static ssize_t
2870lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2871 char *buf)
2872{
2873 struct Scsi_Host *shost = class_to_shost(dev);
2874 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2875
2876 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2877 return -EFAULT;
2878
2879 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2880}
2881static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2882 lpfc_oas_lun_status_show, NULL);
2883
2884
2885/**
2886 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2887 * (OAS) operations.
2888 * @phba: lpfc_hba pointer.
2889 * @ndlp: pointer to fcp target node.
2890 * @lun: the fc lun for setting oas state.
2891 * @oas_state: the oas state to be set to the lun.
2892 *
2893 * Returns:
2894 * SUCCESS : 0
2895 * -EPERM OAS is not enabled or not supported by this port.
2896 *
2897 */
2898static size_t
2899lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartc92c8412016-07-06 12:36:05 -07002900 uint8_t tgt_wwpn[], uint64_t lun,
2901 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002902{
2903
2904 int rc = 0;
2905
James Smartf38fa0b2014-04-04 13:52:21 -04002906 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002907 return -EPERM;
2908
2909 if (oas_state) {
2910 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002911 (struct lpfc_name *)tgt_wwpn,
2912 lun, pri))
James Smart1ba981f2014-02-20 09:56:45 -05002913 rc = -ENOMEM;
2914 } else {
2915 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002916 (struct lpfc_name *)tgt_wwpn, lun, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002917 }
2918 return rc;
2919
2920}
2921
2922/**
2923 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2924 * Access Storage (OAS) operations.
2925 * @phba: lpfc_hba pointer.
2926 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2927 * @tgt_wwpn: wwpn of the target associated with the returned lun
2928 * @lun_status: status of the lun returned lun
2929 *
2930 * Returns the first or next lun enabled for OAS operations for the vport/target
2931 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2932 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2933 *
2934 * Return:
2935 * lun that is OAS enabled for the vport/target
2936 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2937 */
2938static uint64_t
2939lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartb5749fe2016-12-19 15:07:26 -08002940 uint8_t tgt_wwpn[], uint32_t *lun_status,
2941 uint32_t *lun_pri)
James Smart1ba981f2014-02-20 09:56:45 -05002942{
2943 uint64_t found_lun;
2944
2945 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2946 return NOT_OAS_ENABLED_LUN;
2947 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2948 phba->sli4_hba.oas_next_vpt_wwpn,
2949 (struct lpfc_name *)
2950 phba->sli4_hba.oas_next_tgt_wwpn,
2951 &phba->sli4_hba.oas_next_lun,
2952 (struct lpfc_name *)vpt_wwpn,
2953 (struct lpfc_name *)tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002954 &found_lun, lun_status, lun_pri))
James Smart1ba981f2014-02-20 09:56:45 -05002955 return found_lun;
2956 else
2957 return NOT_OAS_ENABLED_LUN;
2958}
2959
2960/**
2961 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2962 * @phba: lpfc_hba pointer.
2963 * @vpt_wwpn: vport wwpn by reference.
2964 * @tgt_wwpn: target wwpn by reference.
2965 * @lun: the fc lun for setting oas state.
2966 * @oas_state: the oas state to be set to the oas_lun.
2967 *
2968 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2969 * a lun for OAS operations.
2970 *
2971 * Return:
2972 * SUCCESS: 0
2973 * -ENOMEM: failed to enable an lun for OAS operations
2974 * -EPERM: OAS is not enabled
2975 */
2976static ssize_t
2977lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2978 uint8_t tgt_wwpn[], uint64_t lun,
James Smartc92c8412016-07-06 12:36:05 -07002979 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002980{
2981
2982 int rc;
2983
2984 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
James Smartc92c8412016-07-06 12:36:05 -07002985 oas_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002986 return rc;
2987}
2988
2989/**
2990 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2991 * @dev: class device that is converted into a Scsi_host.
2992 * @attr: device attribute, not used.
2993 * @buf: buffer for passing information.
2994 *
2995 * This routine returns a lun enabled for OAS each time the function
2996 * is called.
2997 *
2998 * Returns:
2999 * SUCCESS: size of formatted string.
3000 * -EFAULT: target or vport wwpn was not set properly.
3001 * -EPERM: oas is not enabled.
3002 **/
3003static ssize_t
3004lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3005 char *buf)
3006{
3007 struct Scsi_Host *shost = class_to_shost(dev);
3008 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3009
3010 uint64_t oas_lun;
3011 int len = 0;
3012
James Smartf38fa0b2014-04-04 13:52:21 -04003013 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003014 return -EPERM;
3015
3016 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3017 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3018 return -EFAULT;
3019
3020 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3021 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3022 return -EFAULT;
3023
3024 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3025 phba->cfg_oas_tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08003026 &phba->cfg_oas_lun_status,
3027 &phba->cfg_oas_priority);
James Smart1ba981f2014-02-20 09:56:45 -05003028 if (oas_lun != NOT_OAS_ENABLED_LUN)
3029 phba->cfg_oas_flags |= OAS_LUN_VALID;
3030
3031 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3032
3033 return len;
3034}
3035
3036/**
3037 * lpfc_oas_lun_store - Sets the OAS state for lun
3038 * @dev: class device that is converted into a Scsi_host.
3039 * @attr: device attribute, not used.
3040 * @buf: buffer for passing information.
3041 *
3042 * This function sets the OAS state for lun. Before this function is called,
3043 * the vport wwpn, target wwpn, and oas state need to be set.
3044 *
3045 * Returns:
3046 * SUCCESS: size of formatted string.
3047 * -EFAULT: target or vport wwpn was not set properly.
3048 * -EPERM: oas is not enabled.
3049 * size of formatted string.
3050 **/
3051static ssize_t
3052lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3053 const char *buf, size_t count)
3054{
3055 struct Scsi_Host *shost = class_to_shost(dev);
3056 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3057 uint64_t scsi_lun;
James Smartb5749fe2016-12-19 15:07:26 -08003058 uint32_t pri;
James Smart1ba981f2014-02-20 09:56:45 -05003059 ssize_t rc;
3060
James Smartf38fa0b2014-04-04 13:52:21 -04003061 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003062 return -EPERM;
3063
3064 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3065 return -EFAULT;
3066
3067 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3068 return -EFAULT;
3069
3070 if (!isdigit(buf[0]))
3071 return -EINVAL;
3072
3073 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3074 return -EINVAL;
3075
James Smartb5749fe2016-12-19 15:07:26 -08003076 pri = phba->cfg_oas_priority;
3077 if (pri == 0)
3078 pri = phba->cfg_XLanePriority;
3079
James Smart1ba981f2014-02-20 09:56:45 -05003080 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartc92c8412016-07-06 12:36:05 -07003081 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3082 "priority 0x%x with oas state %d\n",
James Smart1ba981f2014-02-20 09:56:45 -05003083 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3084 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08003085 pri, phba->cfg_oas_lun_state);
James Smart1ba981f2014-02-20 09:56:45 -05003086
3087 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07003088 phba->cfg_oas_tgt_wwpn, scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08003089 phba->cfg_oas_lun_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05003090 if (rc)
3091 return rc;
3092
3093 return count;
3094}
3095static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3096 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04003097
James Smartf358dd02017-02-12 13:52:34 -08003098int lpfc_enable_nvmet_cnt;
3099unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3102module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3103MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3104
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003105static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05003106module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003107MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3108 " 0 - none,"
3109 " 1 - poll with interrupts enabled"
3110 " 3 - poll and disable FCP ring interrupts");
3111
Joe Perchesb6b996b2017-12-19 10:15:07 -08003112static DEVICE_ATTR_RW(lpfc_poll);
dea31012005-04-17 16:05:31 -05003113
James Smart96418b52017-03-04 09:30:31 -08003114int lpfc_no_hba_reset_cnt;
3115unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3117module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3118MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3119
James Smart12247e82016-07-06 12:36:09 -07003120LPFC_ATTR(sli_mode, 0, 0, 3,
3121 "SLI mode selector:"
3122 " 0 - auto (SLI-3 if supported),"
3123 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3124 " 3 - select SLI-3");
James Smart92d7f7b2007-06-17 19:56:38 -05003125
James Smart458c0832016-07-06 12:36:07 -07003126LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3127 "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05003128
James Smart7d791df2011-07-22 18:37:52 -04003129LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3130 "FCF Fast failover=1 Priority failover=2");
3131
James Smarte5771b42013-03-01 16:37:14 -05003132/*
3133# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3134# 0x0 = disabled, XRI/OXID use not tracked.
3135# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3136# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3137*/
James Smart31202b02016-10-13 15:06:08 -07003138LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3139 "Enable RRQ functionality");
James Smart19ca7602010-11-20 23:11:55 -05003140
dea31012005-04-17 16:05:31 -05003141/*
James Smart84d1b002010-02-12 14:42:33 -05003142# lpfc_suppress_link_up: Bring link up at initialization
3143# 0x0 = bring link up (issue MBX_INIT_LINK)
3144# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3145# 0x2 = never bring up link
3146# Default value is 0.
3147*/
James Smarte40a02c2010-02-26 14:13:54 -05003148LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3149 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3150 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04003151/*
3152# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3153# 1 - (1024)
3154# 2 - (2048)
3155# 3 - (3072)
3156# 4 - (4096)
3157# 5 - (5120)
3158*/
3159static ssize_t
3160lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3161{
3162 struct Scsi_Host *shost = class_to_shost(dev);
3163 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3164
3165 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3166}
3167
3168static DEVICE_ATTR(iocb_hw, S_IRUGO,
3169 lpfc_iocb_hw_show, NULL);
3170static ssize_t
3171lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3172{
3173 struct Scsi_Host *shost = class_to_shost(dev);
3174 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003175 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003176
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003177 return snprintf(buf, PAGE_SIZE, "%d\n",
3178 pring ? pring->txq_max : 0);
James Smart2a9bf3d2010-06-07 15:24:45 -04003179}
3180
3181static DEVICE_ATTR(txq_hw, S_IRUGO,
3182 lpfc_txq_hw_show, NULL);
3183static ssize_t
3184lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3185 char *buf)
3186{
3187 struct Scsi_Host *shost = class_to_shost(dev);
3188 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003189 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003190
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003191 return snprintf(buf, PAGE_SIZE, "%d\n",
3192 pring ? pring->txcmplq_max : 0);
James Smart2a9bf3d2010-06-07 15:24:45 -04003193}
3194
3195static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3196 lpfc_txcmplq_hw_show, NULL);
3197
James Smart0d8c8ba2016-10-13 15:06:07 -07003198LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
James Smart2a9bf3d2010-06-07 15:24:45 -04003199 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
James Smart84d1b002010-02-12 14:42:33 -05003200
3201/*
James Smartc01f3202006-08-18 17:47:08 -04003202# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3203# until the timer expires. Value range is [0,255]. Default value is 30.
3204*/
3205static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3206static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3207module_param(lpfc_nodev_tmo, int, 0);
3208MODULE_PARM_DESC(lpfc_nodev_tmo,
3209 "Seconds driver will hold I/O waiting "
3210 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04003211
3212/**
James Smart3621a712009-04-06 18:47:14 -04003213 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04003214 * @dev: class converted to a Scsi_host structure.
3215 * @attr: device attribute, not used.
3216 * @buf: on return contains the dev loss timeout in decimal.
3217 *
3218 * Returns: size of formatted string.
3219 **/
James Smartc01f3202006-08-18 17:47:08 -04003220static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003221lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3222 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04003223{
Tony Jonesee959b02008-02-22 00:13:36 +01003224 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003225 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05003226
James Smart3de2a652007-08-02 11:09:59 -04003227 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003228}
3229
James Smarte59058c2008-08-24 21:49:00 -04003230/**
James Smart3621a712009-04-06 18:47:14 -04003231 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04003232 * @vport: lpfc vport structure pointer.
3233 * @val: contains the nodev timeout value.
3234 *
3235 * Description:
3236 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3237 * a kernel error message is printed and zero is returned.
3238 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3239 * Otherwise nodev tmo is set to the default value.
3240 *
3241 * Returns:
3242 * zero if already set or if val is in range
3243 * -EINVAL val out of range
3244 **/
James Smartc01f3202006-08-18 17:47:08 -04003245static int
James Smart3de2a652007-08-02 11:09:59 -04003246lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003247{
James Smart3de2a652007-08-02 11:09:59 -04003248 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3249 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3250 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04003251 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003252 "0407 Ignoring lpfc_nodev_tmo module "
3253 "parameter because lpfc_devloss_tmo "
3254 "is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003255 return 0;
3256 }
3257
3258 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003259 vport->cfg_nodev_tmo = val;
3260 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04003261 return 0;
3262 }
James Smarte8b62012007-08-02 11:10:09 -04003263 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3264 "0400 lpfc_nodev_tmo attribute cannot be set to"
3265 " %d, allowed range is [%d, %d]\n",
3266 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04003267 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04003268 return -EINVAL;
3269}
3270
James Smarte59058c2008-08-24 21:49:00 -04003271/**
James Smart3621a712009-04-06 18:47:14 -04003272 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04003273 * @vport: lpfc vport structure pointer.
3274 *
3275 * Description:
3276 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3277 **/
James Smart7054a602007-04-25 09:52:34 -04003278static void
James Smart3de2a652007-08-02 11:09:59 -04003279lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04003280{
James Smart858c9f62007-06-17 19:56:39 -05003281 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04003282 struct lpfc_nodelist *ndlp;
3283
James Smart51ef4c22007-08-02 11:10:31 -04003284 shost = lpfc_shost_from_vport(vport);
3285 spin_lock_irq(shost->host_lock);
James Smart7a06dcd2017-06-01 21:06:55 -07003286 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3287 if (!NLP_CHK_NODE_ACT(ndlp))
3288 continue;
3289 if (ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04003290 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
James Smart6ddcf0a2017-11-03 09:33:30 -07003291#if (IS_ENABLED(CONFIG_NVME_FC))
3292 if (ndlp->nrport)
3293 nvme_fc_set_remoteport_devloss(ndlp->nrport->remoteport,
3294 vport->cfg_devloss_tmo);
3295#endif
James Smart7a06dcd2017-06-01 21:06:55 -07003296 }
James Smart51ef4c22007-08-02 11:10:31 -04003297 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04003298}
3299
James Smarte59058c2008-08-24 21:49:00 -04003300/**
James Smart3621a712009-04-06 18:47:14 -04003301 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04003302 * @vport: lpfc vport structure pointer.
3303 * @val: contains the tmo value.
3304 *
3305 * Description:
3306 * If the devloss tmo is already set or the vport dev loss tmo has changed
3307 * then a kernel error message is printed and zero is returned.
3308 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3309 * Otherwise nodev tmo is set to the default value.
3310 *
3311 * Returns:
3312 * zero if already set or if val is in range
3313 * -EINVAL val out of range
3314 **/
James Smartc01f3202006-08-18 17:47:08 -04003315static int
James Smart3de2a652007-08-02 11:09:59 -04003316lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003317{
James Smart3de2a652007-08-02 11:09:59 -04003318 if (vport->dev_loss_tmo_changed ||
3319 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04003320 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003321 "0401 Ignoring change to lpfc_nodev_tmo "
3322 "because lpfc_devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003323 return 0;
3324 }
James Smartc01f3202006-08-18 17:47:08 -04003325 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003326 vport->cfg_nodev_tmo = val;
3327 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05003328 /*
3329 * For compat: set the fc_host dev loss so new rports
3330 * will get the value.
3331 */
3332 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003333 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003334 return 0;
3335 }
James Smarte8b62012007-08-02 11:10:09 -04003336 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003337 "0403 lpfc_nodev_tmo attribute cannot be set to "
James Smarte8b62012007-08-02 11:10:09 -04003338 "%d, allowed range is [%d, %d]\n",
3339 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003340 return -EINVAL;
3341}
3342
James Smart3de2a652007-08-02 11:09:59 -04003343lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04003344
Joe Perchesb6b996b2017-12-19 10:15:07 -08003345static DEVICE_ATTR_RW(lpfc_nodev_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003346
3347/*
3348# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3349# disappear until the timer expires. Value range is [0,255]. Default
3350# value is 30.
3351*/
James Smartab56dc22011-02-16 12:39:57 -05003352module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04003353MODULE_PARM_DESC(lpfc_devloss_tmo,
3354 "Seconds driver will hold I/O waiting "
3355 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04003356lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3357 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3358lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04003359
3360/**
James Smart3621a712009-04-06 18:47:14 -04003361 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04003362 * @vport: lpfc vport structure pointer.
3363 * @val: contains the tmo value.
3364 *
3365 * Description:
3366 * If val is in a valid range then set the vport nodev tmo,
3367 * devloss tmo, also set the vport dev loss tmo changed flag.
3368 * Else a kernel error message is printed.
3369 *
3370 * Returns:
3371 * zero if val is in range
3372 * -EINVAL val out of range
3373 **/
James Smartc01f3202006-08-18 17:47:08 -04003374static int
James Smart3de2a652007-08-02 11:09:59 -04003375lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003376{
3377 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003378 vport->cfg_nodev_tmo = val;
3379 vport->cfg_devloss_tmo = val;
3380 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05003381 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003382 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003383 return 0;
3384 }
3385
James Smarte8b62012007-08-02 11:10:09 -04003386 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003387 "0404 lpfc_devloss_tmo attribute cannot be set to "
3388 "%d, allowed range is [%d, %d]\n",
James Smarte8b62012007-08-02 11:10:09 -04003389 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003390 return -EINVAL;
3391}
3392
James Smart3de2a652007-08-02 11:09:59 -04003393lpfc_vport_param_store(devloss_tmo)
Joe Perchesb6b996b2017-12-19 10:15:07 -08003394static DEVICE_ATTR_RW(lpfc_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003395
3396/*
James Smartf358dd02017-02-12 13:52:34 -08003397 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3398 * lpfc_suppress_rsp = 0 Disable
3399 * lpfc_suppress_rsp = 1 Enable (default)
3400 *
3401 */
3402LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3403 "Enable suppress rsp feature is firmware supports it");
3404
3405/*
James Smart2d7dbc42017-02-12 13:52:35 -08003406 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
James Smartbcb24f62017-11-20 16:00:36 -08003407 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
James Smart2d7dbc42017-02-12 13:52:35 -08003408 * lpfc_nvmet_mrq = 1 use a single RQ pair
3409 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3410 *
3411 */
3412LPFC_ATTR_R(nvmet_mrq,
James Smartbcb24f62017-11-20 16:00:36 -08003413 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
James Smart2d7dbc42017-02-12 13:52:35 -08003414 "Specify number of RQ pairs for processing NVMET cmds");
3415
3416/*
James Smart895427b2017-02-12 13:52:30 -08003417 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3418 * Supported Values: 1 - register just FCP
3419 * 3 - register both FCP and NVME
James Smart7d708032017-03-08 14:36:01 -08003420 * Supported values are [1,3]. Default value is 1
James Smart895427b2017-02-12 13:52:30 -08003421 */
James Smart7d708032017-03-08 14:36:01 -08003422LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP,
James Smart895427b2017-02-12 13:52:30 -08003423 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
Dick Kennedycf4c8c82017-09-29 17:34:38 -07003424 "Enable FC4 Protocol support - FCP / NVME");
James Smart895427b2017-02-12 13:52:30 -08003425
3426/*
3427 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3428 * This parameter is only used if:
James Smartf358dd02017-02-12 13:52:34 -08003429 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3430 * port is not configured for NVMET.
James Smart895427b2017-02-12 13:52:30 -08003431 *
3432 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3433 * The remaining XRIs get split up based on lpfc_xri_split per port:
3434 *
3435 * Supported Values are in percentages
3436 * the xri_split value is the percentage the SCSI port will get. The remaining
3437 * percentage will go to NVME.
3438 */
3439LPFC_ATTR_R(xri_split, 50, 10, 90,
Dick Kennedycf4c8c82017-09-29 17:34:38 -07003440 "Percentage of FCP XRI resources versus NVME");
James Smart895427b2017-02-12 13:52:30 -08003441
3442/*
dea31012005-04-17 16:05:31 -05003443# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3444# deluged with LOTS of information.
3445# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04003446# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05003447*/
James Smartf4b4c682009-05-22 14:53:12 -04003448LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04003449 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05003450
3451/*
James Smart7ee5d432007-10-27 13:37:17 -04003452# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3453# objects that have been registered with the nameserver after login.
3454*/
James Smartcf971242012-03-01 22:37:32 -05003455LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04003456 "Deregister nameserver objects before LOGO");
3457
3458/*
dea31012005-04-17 16:05:31 -05003459# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04003460# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3461# If this parameter value is greater than 1/8th the maximum number of exchanges
3462# supported by the HBA port, then the lun queue depth will be reduced to
3463# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05003464*/
James Smart572709e2013-07-15 18:32:43 -04003465LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04003466 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05003467
3468/*
James Smart7dc517d2010-07-14 15:32:10 -04003469# tgt_queue_depth: This parameter is used to limit the number of outstanding
3470# commands per target port. Value range is [10,65535]. Default value is 65535.
3471*/
James Smartf91bc592018-04-09 14:24:22 -07003472static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
3473module_param(lpfc_tgt_queue_depth, uint, 0444);
3474MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
3475lpfc_vport_param_show(tgt_queue_depth);
3476lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
3477 LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
3478
3479/**
3480 * lpfc_tgt_queue_depth_store: Sets an attribute value.
3481 * @phba: pointer the the adapter structure.
3482 * @val: integer attribute value.
3483 *
3484 * Description: Sets the parameter to the new value.
3485 *
3486 * Returns:
3487 * zero on success
3488 * -EINVAL if val is invalid
3489 */
3490static int
3491lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
3492{
3493 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3494 struct lpfc_nodelist *ndlp;
3495
3496 if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
3497 return -EINVAL;
3498
3499 if (val == vport->cfg_tgt_queue_depth)
3500 return 0;
3501
3502 spin_lock_irq(shost->host_lock);
3503 vport->cfg_tgt_queue_depth = val;
3504
3505 /* Next loop thru nodelist and change cmd_qdepth */
3506 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3507 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3508
3509 spin_unlock_irq(shost->host_lock);
3510 return 0;
3511}
3512
3513lpfc_vport_param_store(tgt_queue_depth);
3514static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04003515
3516/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003517# hba_queue_depth: This parameter is used to limit the number of outstanding
3518# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3519# value is greater than the maximum number of exchanges supported by the HBA,
3520# then maximum number of exchanges supported by the HBA is used to determine
3521# the hba_queue_depth.
3522*/
3523LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3524 "Max number of FCP commands we can queue to a lpfc HBA");
3525
3526/*
James Smart92d7f7b2007-06-17 19:56:38 -05003527# peer_port_login: This parameter allows/prevents logins
3528# between peer ports hosted on the same physical port.
3529# When this parameter is set 0 peer ports of same physical port
3530# are not allowed to login to each other.
3531# When this parameter is set 1 peer ports of same physical port
3532# are allowed to login to each other.
3533# Default value of this parameter is 0.
3534*/
James Smart3de2a652007-08-02 11:09:59 -04003535LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3536 "Allow peer ports on the same physical port to login to each "
3537 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05003538
3539/*
James Smart3de2a652007-08-02 11:09:59 -04003540# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05003541# between Virtual Ports and remote initiators.
3542# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3543# other initiators and will attempt to PLOGI all remote ports.
3544# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3545# remote ports and will not attempt to PLOGI to other initiators.
3546# This parameter does not restrict to the physical port.
3547# This parameter does not restrict logins to Fabric resident remote ports.
3548# Default value of this parameter is 1.
3549*/
James Smart3de2a652007-08-02 11:09:59 -04003550static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05003551module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04003552MODULE_PARM_DESC(lpfc_restrict_login,
3553 "Restrict virtual ports login to remote initiators.");
3554lpfc_vport_param_show(restrict_login);
3555
James Smarte59058c2008-08-24 21:49:00 -04003556/**
James Smart3621a712009-04-06 18:47:14 -04003557 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003558 * @vport: lpfc vport structure pointer.
3559 * @val: contains the restrict login value.
3560 *
3561 * Description:
3562 * If val is not in a valid range then log a kernel error message and set
3563 * the vport restrict login to one.
3564 * If the port type is physical clear the restrict login flag and return.
3565 * Else set the restrict login flag to val.
3566 *
3567 * Returns:
3568 * zero if val is in range
3569 * -EINVAL val out of range
3570 **/
James Smart3de2a652007-08-02 11:09:59 -04003571static int
3572lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3573{
3574 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003575 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003576 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003577 "be set to %d, allowed range is [0, 1]\n",
3578 val);
James Smart3de2a652007-08-02 11:09:59 -04003579 vport->cfg_restrict_login = 1;
3580 return -EINVAL;
3581 }
3582 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3583 vport->cfg_restrict_login = 0;
3584 return 0;
3585 }
3586 vport->cfg_restrict_login = val;
3587 return 0;
3588}
3589
James Smarte59058c2008-08-24 21:49:00 -04003590/**
James Smart3621a712009-04-06 18:47:14 -04003591 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003592 * @vport: lpfc vport structure pointer.
3593 * @val: contains the restrict login value.
3594 *
3595 * Description:
3596 * If val is not in a valid range then log a kernel error message and set
3597 * the vport restrict login to one.
3598 * If the port type is physical and the val is not zero log a kernel
3599 * error message, clear the restrict login flag and return zero.
3600 * Else set the restrict login flag to val.
3601 *
3602 * Returns:
3603 * zero if val is in range
3604 * -EINVAL val out of range
3605 **/
James Smart3de2a652007-08-02 11:09:59 -04003606static int
3607lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3608{
3609 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003610 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003611 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003612 "be set to %d, allowed range is [0, 1]\n",
3613 val);
James Smart3de2a652007-08-02 11:09:59 -04003614 vport->cfg_restrict_login = 1;
3615 return -EINVAL;
3616 }
3617 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04003618 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3619 "0468 lpfc_restrict_login must be 0 for "
3620 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04003621 vport->cfg_restrict_login = 0;
3622 return 0;
3623 }
3624 vport->cfg_restrict_login = val;
3625 return 0;
3626}
3627lpfc_vport_param_store(restrict_login);
Joe Perchesb6b996b2017-12-19 10:15:07 -08003628static DEVICE_ATTR_RW(lpfc_restrict_login);
James Smart92d7f7b2007-06-17 19:56:38 -05003629
3630/*
dea31012005-04-17 16:05:31 -05003631# Some disk devices have a "select ID" or "select Target" capability.
3632# From a protocol standpoint "select ID" usually means select the
3633# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3634# annex" which contains a table that maps a "select ID" (a number
3635# between 0 and 7F) to an ALPA. By default, for compatibility with
3636# older drivers, the lpfc driver scans this table from low ALPA to high
3637# ALPA.
3638#
3639# Turning on the scan-down variable (on = 1, off = 0) will
3640# cause the lpfc driver to use an inverted table, effectively
3641# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3642#
3643# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3644# and will not work across a fabric. Also this parameter will take
3645# effect only in the case when ALPA map is not available.)
3646*/
James Smart3de2a652007-08-02 11:09:59 -04003647LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3648 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05003649
3650/*
dea31012005-04-17 16:05:31 -05003651# lpfc_topology: link topology for init link
3652# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05003653# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05003654# 0x02 = attempt point-to-point mode only
3655# 0x04 = attempt loop mode only
3656# 0x06 = attempt point-to-point mode then loop
3657# Set point-to-point mode if you want to run as an N_Port.
3658# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3659# Default value is 0.
3660*/
James Smart0a035432016-10-13 15:06:10 -07003661LPFC_ATTR(topology, 0, 0, 6,
3662 "Select Fibre Channel topology");
James Smarte59058c2008-08-24 21:49:00 -04003663
3664/**
James Smart3621a712009-04-06 18:47:14 -04003665 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04003666 * @phba: lpfc_hba pointer.
3667 * @val: topology value.
3668 *
3669 * Description:
3670 * If val is in a valid range then set the adapter's topology field and
3671 * issue a lip; if the lip fails reset the topology to the old value.
3672 *
3673 * If the value is not in range log a kernel error message and return an error.
3674 *
3675 * Returns:
3676 * zero if val is in range and lip okay
3677 * non-zero return value from lpfc_issue_lip()
3678 * -EINVAL val out of range
3679 **/
James Smarta257bf92009-04-06 18:48:10 -04003680static ssize_t
3681lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3682 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003683{
James Smarta257bf92009-04-06 18:48:10 -04003684 struct Scsi_Host *shost = class_to_shost(dev);
3685 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3686 struct lpfc_hba *phba = vport->phba;
3687 int val = 0;
3688 int nolip = 0;
3689 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003690 int err;
3691 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003692
3693 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3694 nolip = 1;
3695 val_buf = &buf[strlen("nolip ")];
3696 }
3697
3698 if (!isdigit(val_buf[0]))
3699 return -EINVAL;
3700 if (sscanf(val_buf, "%i", &val) != 1)
3701 return -EINVAL;
3702
James Smart83108bd2008-01-11 01:53:09 -05003703 if (val >= 0 && val <= 6) {
3704 prev_val = phba->cfg_topology;
James Smartff78d8f2011-12-13 13:21:35 -05003705 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3706 val == 4) {
3707 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3708 "3113 Loop mode not supported at speed %d\n",
James Smartd38dd522015-08-31 16:48:17 -04003709 val);
James Smartff78d8f2011-12-13 13:21:35 -05003710 return -EINVAL;
3711 }
James Smartd38dd522015-08-31 16:48:17 -04003712 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3713 val == 4) {
3714 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3715 "3114 Loop mode not supported\n");
3716 return -EINVAL;
3717 }
3718 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04003719 if (nolip)
3720 return strlen(buf);
3721
James Smart88a2cfb2011-07-22 18:36:33 -04003722 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3723 "3054 lpfc_topology changed from %d to %d\n",
3724 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04003725 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3726 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05003727 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003728 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003729 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003730 return -EINVAL;
3731 } else
3732 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003733 }
3734 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3735 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3736 "allowed range is [0, 6]\n",
3737 phba->brd_no, val);
3738 return -EINVAL;
3739}
James Smart0a035432016-10-13 15:06:10 -07003740
James Smart83108bd2008-01-11 01:53:09 -05003741lpfc_param_show(topology)
Joe Perchesb6b996b2017-12-19 10:15:07 -08003742static DEVICE_ATTR_RW(lpfc_topology);
dea31012005-04-17 16:05:31 -05003743
James Smart21e9a0a2009-05-22 14:53:21 -04003744/**
3745 * lpfc_static_vport_show: Read callback function for
3746 * lpfc_static_vport sysfs file.
3747 * @dev: Pointer to class device object.
3748 * @attr: device attribute structure.
3749 * @buf: Data buffer.
3750 *
3751 * This function is the read call back function for
3752 * lpfc_static_vport sysfs file. The lpfc_static_vport
3753 * sysfs file report the mageability of the vport.
3754 **/
3755static ssize_t
3756lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3757 char *buf)
3758{
3759 struct Scsi_Host *shost = class_to_shost(dev);
3760 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3761 if (vport->vport_flag & STATIC_VPORT)
3762 sprintf(buf, "1\n");
3763 else
3764 sprintf(buf, "0\n");
3765
3766 return strlen(buf);
3767}
3768
3769/*
3770 * Sysfs attribute to control the statistical data collection.
3771 */
Joe Perchesc828a892017-12-19 10:15:08 -08003772static DEVICE_ATTR_RO(lpfc_static_vport);
James Smartea2151b2008-09-07 11:52:10 -04003773
3774/**
James Smart3621a712009-04-06 18:47:14 -04003775 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003776 * @dev: Pointer to class device.
3777 * @buf: Data buffer.
3778 * @count: Size of the data buffer.
3779 *
Masahiro Yamada9332ef92017-02-27 14:28:47 -08003780 * This function get called when a user write to the lpfc_stat_data_ctrl
James Smartea2151b2008-09-07 11:52:10 -04003781 * sysfs file. This function parse the command written to the sysfs file
3782 * and take appropriate action. These commands are used for controlling
3783 * driver statistical data collection.
3784 * Following are the command this function handles.
3785 *
3786 * setbucket <bucket_type> <base> <step>
3787 * = Set the latency buckets.
3788 * destroybucket = destroy all the buckets.
3789 * start = start data collection
3790 * stop = stop data collection
3791 * reset = reset the collected data
3792 **/
3793static ssize_t
3794lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3795 const char *buf, size_t count)
3796{
3797 struct Scsi_Host *shost = class_to_shost(dev);
3798 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3799 struct lpfc_hba *phba = vport->phba;
3800#define LPFC_MAX_DATA_CTRL_LEN 1024
3801 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3802 unsigned long i;
3803 char *str_ptr, *token;
3804 struct lpfc_vport **vports;
3805 struct Scsi_Host *v_shost;
3806 char *bucket_type_str, *base_str, *step_str;
3807 unsigned long base, step, bucket_type;
3808
3809 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04003810 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04003811 return -EINVAL;
3812
James Smarteb016562014-09-03 12:58:06 -04003813 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
James Smartea2151b2008-09-07 11:52:10 -04003814 str_ptr = &bucket_data[0];
3815 /* Ignore this token - this is command token */
3816 token = strsep(&str_ptr, "\t ");
3817 if (!token)
3818 return -EINVAL;
3819
3820 bucket_type_str = strsep(&str_ptr, "\t ");
3821 if (!bucket_type_str)
3822 return -EINVAL;
3823
3824 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3825 bucket_type = LPFC_LINEAR_BUCKET;
3826 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3827 bucket_type = LPFC_POWER2_BUCKET;
3828 else
3829 return -EINVAL;
3830
3831 base_str = strsep(&str_ptr, "\t ");
3832 if (!base_str)
3833 return -EINVAL;
3834 base = simple_strtoul(base_str, NULL, 0);
3835
3836 step_str = strsep(&str_ptr, "\t ");
3837 if (!step_str)
3838 return -EINVAL;
3839 step = simple_strtoul(step_str, NULL, 0);
3840 if (!step)
3841 return -EINVAL;
3842
3843 /* Block the data collection for every vport */
3844 vports = lpfc_create_vport_work_array(phba);
3845 if (vports == NULL)
3846 return -ENOMEM;
3847
James Smartf4b4c682009-05-22 14:53:12 -04003848 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003849 v_shost = lpfc_shost_from_vport(vports[i]);
3850 spin_lock_irq(v_shost->host_lock);
3851 /* Block and reset data collection */
3852 vports[i]->stat_data_blocked = 1;
3853 if (vports[i]->stat_data_enabled)
3854 lpfc_vport_reset_stat_data(vports[i]);
3855 spin_unlock_irq(v_shost->host_lock);
3856 }
3857
3858 /* Set the bucket attributes */
3859 phba->bucket_type = bucket_type;
3860 phba->bucket_base = base;
3861 phba->bucket_step = step;
3862
James Smartf4b4c682009-05-22 14:53:12 -04003863 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003864 v_shost = lpfc_shost_from_vport(vports[i]);
3865
3866 /* Unblock data collection */
3867 spin_lock_irq(v_shost->host_lock);
3868 vports[i]->stat_data_blocked = 0;
3869 spin_unlock_irq(v_shost->host_lock);
3870 }
3871 lpfc_destroy_vport_work_array(phba, vports);
3872 return strlen(buf);
3873 }
3874
3875 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3876 vports = lpfc_create_vport_work_array(phba);
3877 if (vports == NULL)
3878 return -ENOMEM;
3879
James Smartf4b4c682009-05-22 14:53:12 -04003880 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003881 v_shost = lpfc_shost_from_vport(vports[i]);
3882 spin_lock_irq(shost->host_lock);
3883 vports[i]->stat_data_blocked = 1;
3884 lpfc_free_bucket(vport);
3885 vport->stat_data_enabled = 0;
3886 vports[i]->stat_data_blocked = 0;
3887 spin_unlock_irq(shost->host_lock);
3888 }
3889 lpfc_destroy_vport_work_array(phba, vports);
3890 phba->bucket_type = LPFC_NO_BUCKET;
3891 phba->bucket_base = 0;
3892 phba->bucket_step = 0;
3893 return strlen(buf);
3894 }
3895
3896 if (!strncmp(buf, "start", strlen("start"))) {
3897 /* If no buckets configured return error */
3898 if (phba->bucket_type == LPFC_NO_BUCKET)
3899 return -EINVAL;
3900 spin_lock_irq(shost->host_lock);
3901 if (vport->stat_data_enabled) {
3902 spin_unlock_irq(shost->host_lock);
3903 return strlen(buf);
3904 }
3905 lpfc_alloc_bucket(vport);
3906 vport->stat_data_enabled = 1;
3907 spin_unlock_irq(shost->host_lock);
3908 return strlen(buf);
3909 }
3910
3911 if (!strncmp(buf, "stop", strlen("stop"))) {
3912 spin_lock_irq(shost->host_lock);
3913 if (vport->stat_data_enabled == 0) {
3914 spin_unlock_irq(shost->host_lock);
3915 return strlen(buf);
3916 }
3917 lpfc_free_bucket(vport);
3918 vport->stat_data_enabled = 0;
3919 spin_unlock_irq(shost->host_lock);
3920 return strlen(buf);
3921 }
3922
3923 if (!strncmp(buf, "reset", strlen("reset"))) {
3924 if ((phba->bucket_type == LPFC_NO_BUCKET)
3925 || !vport->stat_data_enabled)
3926 return strlen(buf);
3927 spin_lock_irq(shost->host_lock);
3928 vport->stat_data_blocked = 1;
3929 lpfc_vport_reset_stat_data(vport);
3930 vport->stat_data_blocked = 0;
3931 spin_unlock_irq(shost->host_lock);
3932 return strlen(buf);
3933 }
3934 return -EINVAL;
3935}
3936
3937
3938/**
James Smart3621a712009-04-06 18:47:14 -04003939 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003940 * @dev: Pointer to class device object.
3941 * @buf: Data buffer.
3942 *
3943 * This function is the read call back function for
3944 * lpfc_stat_data_ctrl sysfs file. This function report the
3945 * current statistical data collection state.
3946 **/
3947static ssize_t
3948lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3949 char *buf)
3950{
3951 struct Scsi_Host *shost = class_to_shost(dev);
3952 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3953 struct lpfc_hba *phba = vport->phba;
3954 int index = 0;
3955 int i;
3956 char *bucket_type;
3957 unsigned long bucket_value;
3958
3959 switch (phba->bucket_type) {
3960 case LPFC_LINEAR_BUCKET:
3961 bucket_type = "linear";
3962 break;
3963 case LPFC_POWER2_BUCKET:
3964 bucket_type = "power2";
3965 break;
3966 default:
3967 bucket_type = "No Bucket";
3968 break;
3969 }
3970
3971 sprintf(&buf[index], "Statistical Data enabled :%d, "
3972 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3973 " Bucket step :%d\nLatency Ranges :",
3974 vport->stat_data_enabled, vport->stat_data_blocked,
3975 bucket_type, phba->bucket_base, phba->bucket_step);
3976 index = strlen(buf);
3977 if (phba->bucket_type != LPFC_NO_BUCKET) {
3978 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3979 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3980 bucket_value = phba->bucket_base +
3981 phba->bucket_step * i;
3982 else
3983 bucket_value = phba->bucket_base +
3984 (1 << i) * phba->bucket_step;
3985
3986 if (index + 10 > PAGE_SIZE)
3987 break;
3988 sprintf(&buf[index], "%08ld ", bucket_value);
3989 index = strlen(buf);
3990 }
3991 }
3992 sprintf(&buf[index], "\n");
3993 return strlen(buf);
3994}
3995
3996/*
3997 * Sysfs attribute to control the statistical data collection.
3998 */
Joe Perchesb6b996b2017-12-19 10:15:07 -08003999static DEVICE_ATTR_RW(lpfc_stat_data_ctrl);
James Smartea2151b2008-09-07 11:52:10 -04004000
4001/*
4002 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
4003 */
4004
4005/*
4006 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
4007 * for each target.
4008 */
4009#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
4010#define MAX_STAT_DATA_SIZE_PER_TARGET \
4011 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
4012
4013
4014/**
James Smart3621a712009-04-06 18:47:14 -04004015 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07004016 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04004017 * @kobj: Pointer to the kernel object
4018 * @bin_attr: Attribute object
4019 * @buff: Buffer pointer
4020 * @off: File offset
4021 * @count: Buffer size
4022 *
4023 * This function is the read call back function for lpfc_drvr_stat_data
4024 * sysfs file. This function export the statistical data to user
4025 * applications.
4026 **/
4027static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07004028sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
4029 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04004030 char *buf, loff_t off, size_t count)
4031{
4032 struct device *dev = container_of(kobj, struct device,
4033 kobj);
4034 struct Scsi_Host *shost = class_to_shost(dev);
4035 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4036 struct lpfc_hba *phba = vport->phba;
4037 int i = 0, index = 0;
4038 unsigned long nport_index;
4039 struct lpfc_nodelist *ndlp = NULL;
4040 nport_index = (unsigned long)off /
4041 MAX_STAT_DATA_SIZE_PER_TARGET;
4042
4043 if (!vport->stat_data_enabled || vport->stat_data_blocked
4044 || (phba->bucket_type == LPFC_NO_BUCKET))
4045 return 0;
4046
4047 spin_lock_irq(shost->host_lock);
4048 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4049 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
4050 continue;
4051
4052 if (nport_index > 0) {
4053 nport_index--;
4054 continue;
4055 }
4056
4057 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
4058 > count)
4059 break;
4060
4061 if (!ndlp->lat_data)
4062 continue;
4063
4064 /* Print the WWN */
4065 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
4066 ndlp->nlp_portname.u.wwn[0],
4067 ndlp->nlp_portname.u.wwn[1],
4068 ndlp->nlp_portname.u.wwn[2],
4069 ndlp->nlp_portname.u.wwn[3],
4070 ndlp->nlp_portname.u.wwn[4],
4071 ndlp->nlp_portname.u.wwn[5],
4072 ndlp->nlp_portname.u.wwn[6],
4073 ndlp->nlp_portname.u.wwn[7]);
4074
4075 index = strlen(buf);
4076
4077 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4078 sprintf(&buf[index], "%010u,",
4079 ndlp->lat_data[i].cmd_count);
4080 index = strlen(buf);
4081 }
4082 sprintf(&buf[index], "\n");
4083 index = strlen(buf);
4084 }
4085 spin_unlock_irq(shost->host_lock);
4086 return index;
4087}
4088
4089static struct bin_attribute sysfs_drvr_stat_data_attr = {
4090 .attr = {
4091 .name = "lpfc_drvr_stat_data",
4092 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04004093 },
4094 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
4095 .read = sysfs_drvr_stat_data_read,
4096 .write = NULL,
4097};
4098
dea31012005-04-17 16:05:31 -05004099/*
4100# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4101# connection.
James Smart76a95d72010-11-20 23:11:48 -05004102# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05004103*/
James Smarte59058c2008-08-24 21:49:00 -04004104/**
James Smart3621a712009-04-06 18:47:14 -04004105 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004106 * @phba: lpfc_hba pointer.
4107 * @val: link speed value.
4108 *
4109 * Description:
4110 * If val is in a valid range then set the adapter's link speed field and
4111 * issue a lip; if the lip fails reset the link speed to the old value.
4112 *
4113 * Notes:
4114 * If the value is not in range log a kernel error message and return an error.
4115 *
4116 * Returns:
4117 * zero if val is in range and lip okay.
4118 * non-zero return value from lpfc_issue_lip()
4119 * -EINVAL val out of range
4120 **/
James Smarta257bf92009-04-06 18:48:10 -04004121static ssize_t
4122lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4123 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05004124{
James Smarta257bf92009-04-06 18:48:10 -04004125 struct Scsi_Host *shost = class_to_shost(dev);
4126 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4127 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05004128 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04004129 int nolip = 0;
4130 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05004131 int err;
James Smartc6918162016-10-13 15:06:16 -07004132 uint32_t prev_val, if_type;
4133
4134 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4135 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
4136 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4137 return -EPERM;
James Smart83108bd2008-01-11 01:53:09 -05004138
James Smarta257bf92009-04-06 18:48:10 -04004139 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4140 nolip = 1;
4141 val_buf = &buf[strlen("nolip ")];
4142 }
4143
4144 if (!isdigit(val_buf[0]))
4145 return -EINVAL;
4146 if (sscanf(val_buf, "%i", &val) != 1)
4147 return -EINVAL;
4148
James Smart88a2cfb2011-07-22 18:36:33 -04004149 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4150 "3055 lpfc_link_speed changed from %d to %d %s\n",
4151 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4152
James Smart76a95d72010-11-20 23:11:48 -05004153 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4154 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4155 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4156 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4157 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
James Smartd38dd522015-08-31 16:48:17 -04004158 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
James Smartfbd8a6b2018-02-22 08:18:45 -08004159 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||
4160 ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {
James Smart76a95d72010-11-20 23:11:48 -05004161 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4162 "2879 lpfc_link_speed attribute cannot be set "
4163 "to %d. Speed is not supported by this port.\n",
4164 val);
James Smart83108bd2008-01-11 01:53:09 -05004165 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05004166 }
James Smartfbd8a6b2018-02-22 08:18:45 -08004167 if (val >= LPFC_USER_LINK_SPEED_16G &&
4168 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smartff78d8f2011-12-13 13:21:35 -05004169 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4170 "3112 lpfc_link_speed attribute cannot be set "
4171 "to %d. Speed is not supported in loop mode.\n",
4172 val);
4173 return -EINVAL;
4174 }
James Smartfbd8a6b2018-02-22 08:18:45 -08004175
4176 switch (val) {
4177 case LPFC_USER_LINK_SPEED_AUTO:
4178 case LPFC_USER_LINK_SPEED_1G:
4179 case LPFC_USER_LINK_SPEED_2G:
4180 case LPFC_USER_LINK_SPEED_4G:
4181 case LPFC_USER_LINK_SPEED_8G:
4182 case LPFC_USER_LINK_SPEED_16G:
4183 case LPFC_USER_LINK_SPEED_32G:
4184 case LPFC_USER_LINK_SPEED_64G:
James Smart83108bd2008-01-11 01:53:09 -05004185 prev_val = phba->cfg_link_speed;
4186 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04004187 if (nolip)
4188 return strlen(buf);
4189
James Smart83108bd2008-01-11 01:53:09 -05004190 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04004191 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05004192 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04004193 return -EINVAL;
James Smartfbd8a6b2018-02-22 08:18:45 -08004194 }
4195 return strlen(buf);
4196 default:
4197 break;
James Smart83108bd2008-01-11 01:53:09 -05004198 }
James Smartfbd8a6b2018-02-22 08:18:45 -08004199
James Smart83108bd2008-01-11 01:53:09 -05004200 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartfbd8a6b2018-02-22 08:18:45 -08004201 "0469 lpfc_link_speed attribute cannot be set to %d, "
4202 "allowed values are [%s]\n",
4203 val, LPFC_LINK_SPEED_STRING);
James Smart83108bd2008-01-11 01:53:09 -05004204 return -EINVAL;
James Smartfbd8a6b2018-02-22 08:18:45 -08004205
James Smart83108bd2008-01-11 01:53:09 -05004206}
4207
4208static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05004209module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05004210MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4211lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04004212
4213/**
James Smart3621a712009-04-06 18:47:14 -04004214 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004215 * @phba: lpfc_hba pointer.
4216 * @val: link speed value.
4217 *
4218 * Description:
4219 * If val is in a valid range then set the adapter's link speed field.
4220 *
4221 * Notes:
4222 * If the value is not in range log a kernel error message, clear the link
4223 * speed and return an error.
4224 *
4225 * Returns:
4226 * zero if val saved.
4227 * -EINVAL val out of range
4228 **/
James Smart83108bd2008-01-11 01:53:09 -05004229static int
4230lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4231{
James Smartfbd8a6b2018-02-22 08:18:45 -08004232 if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
James Smartff78d8f2011-12-13 13:21:35 -05004233 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4234 "3111 lpfc_link_speed of %d cannot "
4235 "support loop mode, setting topology to default.\n",
4236 val);
4237 phba->cfg_topology = 0;
4238 }
James Smartfbd8a6b2018-02-22 08:18:45 -08004239
4240 switch (val) {
4241 case LPFC_USER_LINK_SPEED_AUTO:
4242 case LPFC_USER_LINK_SPEED_1G:
4243 case LPFC_USER_LINK_SPEED_2G:
4244 case LPFC_USER_LINK_SPEED_4G:
4245 case LPFC_USER_LINK_SPEED_8G:
4246 case LPFC_USER_LINK_SPEED_16G:
4247 case LPFC_USER_LINK_SPEED_32G:
4248 case LPFC_USER_LINK_SPEED_64G:
James Smart83108bd2008-01-11 01:53:09 -05004249 phba->cfg_link_speed = val;
4250 return 0;
James Smartfbd8a6b2018-02-22 08:18:45 -08004251 default:
4252 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4253 "0405 lpfc_link_speed attribute cannot "
4254 "be set to %d, allowed values are "
4255 "["LPFC_LINK_SPEED_STRING"]\n", val);
4256 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4257 return -EINVAL;
James Smart83108bd2008-01-11 01:53:09 -05004258 }
James Smart83108bd2008-01-11 01:53:09 -05004259}
4260
Joe Perchesb6b996b2017-12-19 10:15:07 -08004261static DEVICE_ATTR_RW(lpfc_link_speed);
dea31012005-04-17 16:05:31 -05004262
4263/*
James Smart0d878412009-10-02 15:16:56 -04004264# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4265# 0 = aer disabled or not supported
4266# 1 = aer supported and enabled (default)
4267# Value range is [0,1]. Default value is 1.
4268*/
James Smart506139a2016-10-13 15:06:09 -07004269LPFC_ATTR(aer_support, 1, 0, 1,
4270 "Enable PCIe device AER support");
4271lpfc_param_show(aer_support)
James Smart0d878412009-10-02 15:16:56 -04004272
4273/**
4274 * lpfc_aer_support_store - Set the adapter for aer support
4275 *
4276 * @dev: class device that is converted into a Scsi_host.
4277 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004278 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04004279 * @count: unused variable.
4280 *
4281 * Description:
4282 * If the val is 1 and currently the device's AER capability was not
4283 * enabled, invoke the kernel's enable AER helper routine, trying to
4284 * enable the device's AER capability. If the helper routine enabling
4285 * AER returns success, update the device's cfg_aer_support flag to
4286 * indicate AER is supported by the device; otherwise, if the device
4287 * AER capability is already enabled to support AER, then do nothing.
4288 *
4289 * If the val is 0 and currently the device's AER support was enabled,
4290 * invoke the kernel's disable AER helper routine. After that, update
4291 * the device's cfg_aer_support flag to indicate AER is not supported
4292 * by the device; otherwise, if the device AER capability is already
4293 * disabled from supporting AER, then do nothing.
4294 *
4295 * Returns:
4296 * length of the buf on success if val is in range the intended mode
4297 * is supported.
4298 * -EINVAL if val out of range or intended mode is not supported.
4299 **/
4300static ssize_t
4301lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4302 const char *buf, size_t count)
4303{
4304 struct Scsi_Host *shost = class_to_shost(dev);
4305 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4306 struct lpfc_hba *phba = vport->phba;
4307 int val = 0, rc = -EINVAL;
4308
4309 if (!isdigit(buf[0]))
4310 return -EINVAL;
4311 if (sscanf(buf, "%i", &val) != 1)
4312 return -EINVAL;
4313
4314 switch (val) {
4315 case 0:
4316 if (phba->hba_flag & HBA_AER_ENABLED) {
4317 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4318 if (!rc) {
4319 spin_lock_irq(&phba->hbalock);
4320 phba->hba_flag &= ~HBA_AER_ENABLED;
4321 spin_unlock_irq(&phba->hbalock);
4322 phba->cfg_aer_support = 0;
4323 rc = strlen(buf);
4324 } else
James Smart891478a2009-11-18 15:40:23 -05004325 rc = -EPERM;
4326 } else {
James Smart0d878412009-10-02 15:16:56 -04004327 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05004328 rc = strlen(buf);
4329 }
James Smart0d878412009-10-02 15:16:56 -04004330 break;
4331 case 1:
4332 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4333 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4334 if (!rc) {
4335 spin_lock_irq(&phba->hbalock);
4336 phba->hba_flag |= HBA_AER_ENABLED;
4337 spin_unlock_irq(&phba->hbalock);
4338 phba->cfg_aer_support = 1;
4339 rc = strlen(buf);
4340 } else
James Smart891478a2009-11-18 15:40:23 -05004341 rc = -EPERM;
4342 } else {
James Smart0d878412009-10-02 15:16:56 -04004343 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05004344 rc = strlen(buf);
4345 }
James Smart0d878412009-10-02 15:16:56 -04004346 break;
4347 default:
4348 rc = -EINVAL;
4349 break;
4350 }
4351 return rc;
4352}
4353
Joe Perchesb6b996b2017-12-19 10:15:07 -08004354static DEVICE_ATTR_RW(lpfc_aer_support);
James Smart0d878412009-10-02 15:16:56 -04004355
4356/**
4357 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4358 * @dev: class device that is converted into a Scsi_host.
4359 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004360 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04004361 * @count: unused variable.
4362 *
4363 * Description:
4364 * If the @buf contains 1 and the device currently has the AER support
4365 * enabled, then invokes the kernel AER helper routine
4366 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4367 * error status register.
4368 *
4369 * Notes:
4370 *
4371 * Returns:
4372 * -EINVAL if the buf does not contain the 1 or the device is not currently
4373 * enabled with the AER support.
4374 **/
4375static ssize_t
4376lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4377 const char *buf, size_t count)
4378{
4379 struct Scsi_Host *shost = class_to_shost(dev);
4380 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4381 struct lpfc_hba *phba = vport->phba;
4382 int val, rc = -1;
4383
4384 if (!isdigit(buf[0]))
4385 return -EINVAL;
4386 if (sscanf(buf, "%i", &val) != 1)
4387 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05004388 if (val != 1)
4389 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04004390
James Smart891478a2009-11-18 15:40:23 -05004391 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04004392 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4393
4394 if (rc == 0)
4395 return strlen(buf);
4396 else
James Smart891478a2009-11-18 15:40:23 -05004397 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04004398}
4399
4400static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4401 lpfc_aer_cleanup_state);
4402
James Smart912e3ac2011-05-24 11:42:11 -04004403/**
4404 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4405 *
4406 * @dev: class device that is converted into a Scsi_host.
4407 * @attr: device attribute, not used.
4408 * @buf: containing the string the number of vfs to be enabled.
4409 * @count: unused variable.
4410 *
4411 * Description:
4412 * When this api is called either through user sysfs, the driver shall
4413 * try to enable or disable SR-IOV virtual functions according to the
4414 * following:
4415 *
4416 * If zero virtual function has been enabled to the physical function,
4417 * the driver shall invoke the pci enable virtual function api trying
4418 * to enable the virtual functions. If the nr_vfn provided is greater
4419 * than the maximum supported, the maximum virtual function number will
4420 * be used for invoking the api; otherwise, the nr_vfn provided shall
4421 * be used for invoking the api. If the api call returned success, the
4422 * actual number of virtual functions enabled will be set to the driver
4423 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4424 * cfg_sriov_nr_virtfn remains zero.
4425 *
4426 * If none-zero virtual functions have already been enabled to the
4427 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4428 * -EINVAL will be returned and the driver does nothing;
4429 *
4430 * If the nr_vfn provided is zero and none-zero virtual functions have
4431 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4432 * disabling virtual function api shall be invoded to disable all the
4433 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4434 * zero. Otherwise, if zero virtual function has been enabled, do
4435 * nothing.
4436 *
4437 * Returns:
4438 * length of the buf on success if val is in range the intended mode
4439 * is supported.
4440 * -EINVAL if val out of range or intended mode is not supported.
4441 **/
4442static ssize_t
4443lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4444 const char *buf, size_t count)
4445{
4446 struct Scsi_Host *shost = class_to_shost(dev);
4447 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4448 struct lpfc_hba *phba = vport->phba;
4449 struct pci_dev *pdev = phba->pcidev;
4450 int val = 0, rc = -EINVAL;
4451
4452 /* Sanity check on user data */
4453 if (!isdigit(buf[0]))
4454 return -EINVAL;
4455 if (sscanf(buf, "%i", &val) != 1)
4456 return -EINVAL;
4457 if (val < 0)
4458 return -EINVAL;
4459
4460 /* Request disabling virtual functions */
4461 if (val == 0) {
4462 if (phba->cfg_sriov_nr_virtfn > 0) {
4463 pci_disable_sriov(pdev);
4464 phba->cfg_sriov_nr_virtfn = 0;
4465 }
4466 return strlen(buf);
4467 }
4468
4469 /* Request enabling virtual functions */
4470 if (phba->cfg_sriov_nr_virtfn > 0) {
4471 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4472 "3018 There are %d virtual functions "
4473 "enabled on physical function.\n",
4474 phba->cfg_sriov_nr_virtfn);
4475 return -EEXIST;
4476 }
4477
4478 if (val <= LPFC_MAX_VFN_PER_PFN)
4479 phba->cfg_sriov_nr_virtfn = val;
4480 else {
4481 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4482 "3019 Enabling %d virtual functions is not "
4483 "allowed.\n", val);
4484 return -EINVAL;
4485 }
4486
4487 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4488 if (rc) {
4489 phba->cfg_sriov_nr_virtfn = 0;
4490 rc = -EPERM;
4491 } else
4492 rc = strlen(buf);
4493
4494 return rc;
4495}
4496
James Smart0cfbbf22016-10-13 15:06:12 -07004497LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4498 "Enable PCIe device SR-IOV virtual fn");
4499
James Smart912e3ac2011-05-24 11:42:11 -04004500lpfc_param_show(sriov_nr_virtfn)
Joe Perchesb6b996b2017-12-19 10:15:07 -08004501static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04004502
James Smart173edbb2012-06-12 13:54:50 -04004503/**
James Smartc71ab862012-10-31 14:44:33 -04004504 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4505 *
4506 * @dev: class device that is converted into a Scsi_host.
4507 * @attr: device attribute, not used.
4508 * @buf: containing the string the number of vfs to be enabled.
4509 * @count: unused variable.
4510 *
4511 * Description:
4512 *
4513 * Returns:
4514 * length of the buf on success if val is in range the intended mode
4515 * is supported.
4516 * -EINVAL if val out of range or intended mode is not supported.
4517 **/
4518static ssize_t
4519lpfc_request_firmware_upgrade_store(struct device *dev,
4520 struct device_attribute *attr,
4521 const char *buf, size_t count)
4522{
4523 struct Scsi_Host *shost = class_to_shost(dev);
4524 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4525 struct lpfc_hba *phba = vport->phba;
4526 int val = 0, rc = -EINVAL;
4527
4528 /* Sanity check on user data */
4529 if (!isdigit(buf[0]))
4530 return -EINVAL;
4531 if (sscanf(buf, "%i", &val) != 1)
4532 return -EINVAL;
4533 if (val != 1)
4534 return -EINVAL;
4535
4536 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4537 if (rc)
4538 rc = -EPERM;
4539 else
4540 rc = strlen(buf);
4541 return rc;
4542}
4543
4544static int lpfc_req_fw_upgrade;
4545module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4546MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4547lpfc_param_show(request_firmware_upgrade)
4548
4549/**
4550 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4551 * @phba: lpfc_hba pointer.
4552 * @val: 0 or 1.
4553 *
4554 * Description:
4555 * Set the initial Linux generic firmware upgrade enable or disable flag.
4556 *
4557 * Returns:
4558 * zero if val saved.
4559 * -EINVAL val out of range
4560 **/
4561static int
4562lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4563{
4564 if (val >= 0 && val <= 1) {
4565 phba->cfg_request_firmware_upgrade = val;
4566 return 0;
4567 }
4568 return -EINVAL;
4569}
4570static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4571 lpfc_request_firmware_upgrade_show,
4572 lpfc_request_firmware_upgrade_store);
4573
4574/**
James Smart173edbb2012-06-12 13:54:50 -04004575 * lpfc_fcp_imax_store
4576 *
4577 * @dev: class device that is converted into a Scsi_host.
4578 * @attr: device attribute, not used.
4579 * @buf: string with the number of fast-path FCP interrupts per second.
4580 * @count: unused variable.
4581 *
4582 * Description:
4583 * If val is in a valid range [636,651042], then set the adapter's
4584 * maximum number of fast-path FCP interrupts per second.
4585 *
4586 * Returns:
4587 * length of the buf on success if val is in range the intended mode
4588 * is supported.
4589 * -EINVAL if val out of range or intended mode is not supported.
4590 **/
4591static ssize_t
4592lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4593 const char *buf, size_t count)
4594{
4595 struct Scsi_Host *shost = class_to_shost(dev);
4596 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4597 struct lpfc_hba *phba = vport->phba;
4598 int val = 0, i;
4599
James Smartbf8dae82012-08-03 12:36:24 -04004600 /* fcp_imax is only valid for SLI4 */
4601 if (phba->sli_rev != LPFC_SLI_REV4)
4602 return -EINVAL;
4603
James Smart173edbb2012-06-12 13:54:50 -04004604 /* Sanity check on user data */
4605 if (!isdigit(buf[0]))
4606 return -EINVAL;
4607 if (sscanf(buf, "%i", &val) != 1)
4608 return -EINVAL;
4609
James Smartbf8dae82012-08-03 12:36:24 -04004610 /*
4611 * Value range for the HBA is [5000,5000000]
4612 * The value for each EQ depends on how many EQs are configured.
James Smart895427b2017-02-12 13:52:30 -08004613 * Allow value == 0
James Smartbf8dae82012-08-03 12:36:24 -04004614 */
James Smart895427b2017-02-12 13:52:30 -08004615 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
James Smart173edbb2012-06-12 13:54:50 -04004616 return -EINVAL;
4617
4618 phba->cfg_fcp_imax = (uint32_t)val;
James Smart0cf07f842017-06-01 21:07:10 -07004619 phba->initial_imax = phba->cfg_fcp_imax;
James Smart43140ca2017-03-04 09:30:34 -08004620
4621 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart0cf07f842017-06-01 21:07:10 -07004622 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4623 val);
James Smart173edbb2012-06-12 13:54:50 -04004624
4625 return strlen(buf);
4626}
4627
4628/*
4629# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04004630# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04004631#
James Smartbf8dae82012-08-03 12:36:24 -04004632# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04004633*/
James Smartbf8dae82012-08-03 12:36:24 -04004634static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004635module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4636MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04004637 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04004638lpfc_param_show(fcp_imax)
4639
4640/**
4641 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4642 * @phba: lpfc_hba pointer.
4643 * @val: link speed value.
4644 *
4645 * Description:
4646 * If val is in a valid range [636,651042], then initialize the adapter's
4647 * maximum number of fast-path FCP interrupts per second.
4648 *
4649 * Returns:
4650 * zero if val saved.
4651 * -EINVAL val out of range
4652 **/
4653static int
4654lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4655{
James Smartbf8dae82012-08-03 12:36:24 -04004656 if (phba->sli_rev != LPFC_SLI_REV4) {
4657 phba->cfg_fcp_imax = 0;
4658 return 0;
4659 }
4660
James Smart895427b2017-02-12 13:52:30 -08004661 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4662 (val == 0)) {
James Smart173edbb2012-06-12 13:54:50 -04004663 phba->cfg_fcp_imax = val;
4664 return 0;
4665 }
4666
4667 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004668 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4669 val);
James Smartbf8dae82012-08-03 12:36:24 -04004670 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004671
4672 return 0;
4673}
4674
Joe Perchesb6b996b2017-12-19 10:15:07 -08004675static DEVICE_ATTR_RW(lpfc_fcp_imax);
James Smart173edbb2012-06-12 13:54:50 -04004676
James Smart0cf07f842017-06-01 21:07:10 -07004677/*
4678 * lpfc_auto_imax: Controls Auto-interrupt coalescing values support.
4679 * 0 No auto_imax support
4680 * 1 auto imax on
4681 * Auto imax will change the value of fcp_imax on a per EQ basis, using
4682 * the EQ Delay Multiplier, depending on the activity for that EQ.
4683 * Value range [0,1]. Default value is 1.
4684 */
4685LPFC_ATTR_RW(auto_imax, 1, 0, 1, "Enable Auto imax");
4686
James Smart7bb03bb2013-04-17 20:19:16 -04004687/**
4688 * lpfc_state_show - Display current driver CPU affinity
4689 * @dev: class converted to a Scsi_host structure.
4690 * @attr: device attribute, not used.
4691 * @buf: on return contains text describing the state of the link.
4692 *
4693 * Returns: size of formatted string.
4694 **/
4695static ssize_t
4696lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4697 char *buf)
4698{
4699 struct Scsi_Host *shost = class_to_shost(dev);
4700 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4701 struct lpfc_hba *phba = vport->phba;
4702 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05004703 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04004704
4705 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4706 (phba->intr_type != MSIX))
4707 return len;
4708
4709 switch (phba->cfg_fcp_cpu_map) {
4710 case 0:
4711 len += snprintf(buf + len, PAGE_SIZE-len,
4712 "fcp_cpu_map: No mapping (%d)\n",
4713 phba->cfg_fcp_cpu_map);
4714 return len;
4715 case 1:
4716 len += snprintf(buf + len, PAGE_SIZE-len,
4717 "fcp_cpu_map: HBA centric mapping (%d): "
4718 "%d online CPUs\n",
4719 phba->cfg_fcp_cpu_map,
4720 phba->sli4_hba.num_online_cpu);
4721 break;
4722 case 2:
4723 len += snprintf(buf + len, PAGE_SIZE-len,
4724 "fcp_cpu_map: Driver centric mapping (%d): "
4725 "%d online CPUs\n",
4726 phba->cfg_fcp_cpu_map,
4727 phba->sli4_hba.num_online_cpu);
4728 break;
4729 }
4730
James Smart76fd07a2014-02-20 09:57:18 -05004731 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4732 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4733
4734 /* margin should fit in this and the truncated message */
James Smart7bb03bb2013-04-17 20:19:16 -04004735 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4736 len += snprintf(buf + len, PAGE_SIZE-len,
4737 "CPU %02d io_chan %02d "
4738 "physid %d coreid %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004739 phba->sli4_hba.curr_disp_cpu,
4740 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004741 cpup->core_id);
4742 else
4743 len += snprintf(buf + len, PAGE_SIZE-len,
4744 "CPU %02d io_chan %02d "
4745 "physid %d coreid %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004746 phba->sli4_hba.curr_disp_cpu,
4747 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004748 cpup->core_id, cpup->irq);
4749
James Smart76fd07a2014-02-20 09:57:18 -05004750 phba->sli4_hba.curr_disp_cpu++;
4751
4752 /* display max number of CPUs keeping some margin */
4753 if (phba->sli4_hba.curr_disp_cpu <
4754 phba->sli4_hba.num_present_cpu &&
4755 (len >= (PAGE_SIZE - 64))) {
4756 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4757 break;
4758 }
James Smart7bb03bb2013-04-17 20:19:16 -04004759 }
James Smart76fd07a2014-02-20 09:57:18 -05004760
4761 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4762 phba->sli4_hba.curr_disp_cpu = 0;
4763
James Smart7bb03bb2013-04-17 20:19:16 -04004764 return len;
4765}
4766
4767/**
4768 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4769 * @dev: class device that is converted into a Scsi_host.
4770 * @attr: device attribute, not used.
4771 * @buf: one or more lpfc_polling_flags values.
4772 * @count: not used.
4773 *
4774 * Returns:
4775 * -EINVAL - Not implemented yet.
4776 **/
4777static ssize_t
4778lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4779 const char *buf, size_t count)
4780{
4781 int status = -EINVAL;
4782 return status;
4783}
4784
4785/*
4786# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4787# for the HBA.
4788#
4789# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4790# 0 - Do not affinitze IRQ vectors
4791# 1 - Affintize HBA vectors with respect to each HBA
4792# (start with CPU0 for each HBA)
4793# 2 - Affintize HBA vectors with respect to the entire driver
4794# (round robin thru all CPUs across all HBAs)
4795*/
4796static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4797module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4798MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4799 "Defines how to map CPUs to IRQ vectors per HBA");
4800
4801/**
4802 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4803 * @phba: lpfc_hba pointer.
4804 * @val: link speed value.
4805 *
4806 * Description:
4807 * If val is in a valid range [0-2], then affinitze the adapter's
4808 * MSIX vectors.
4809 *
4810 * Returns:
4811 * zero if val saved.
4812 * -EINVAL val out of range
4813 **/
4814static int
4815lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4816{
4817 if (phba->sli_rev != LPFC_SLI_REV4) {
4818 phba->cfg_fcp_cpu_map = 0;
4819 return 0;
4820 }
4821
4822 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4823 phba->cfg_fcp_cpu_map = val;
4824 return 0;
4825 }
4826
4827 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004828 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4829 "default\n", val);
James Smart7bb03bb2013-04-17 20:19:16 -04004830 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4831
4832 return 0;
4833}
4834
Joe Perchesb6b996b2017-12-19 10:15:07 -08004835static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
James Smart7bb03bb2013-04-17 20:19:16 -04004836
James Smart0d878412009-10-02 15:16:56 -04004837/*
dea31012005-04-17 16:05:31 -05004838# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4839# Value range is [2,3]. Default value is 3.
4840*/
James Smart3de2a652007-08-02 11:09:59 -04004841LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4842 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05004843
4844/*
4845# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4846# is [0,1]. Default value is 0.
4847*/
James Smart3de2a652007-08-02 11:09:59 -04004848LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4849 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05004850
4851/*
James Smart3cb01c52013-07-15 18:35:04 -04004852# lpfc_first_burst_size: First burst size to use on the NPorts
4853# that support first burst.
4854# Value range is [0,65536]. Default value is 0.
4855*/
4856LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4857 "First burst size for Targets that support first burst");
4858
4859/*
James Smart2d7dbc42017-02-12 13:52:35 -08004860* lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4861* When the driver is configured as an NVME target, this value is
4862* communicated to the NVME initiator in the PRLI response. It is
4863* used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4864* parameters are set and the target is sending the PRLI RSP.
James Smart895427b2017-02-12 13:52:30 -08004865* Parameter supported on physical port only - no NPIV support.
James Smart2d7dbc42017-02-12 13:52:35 -08004866* Value range is [0,65536]. Default value is 0.
James Smart895427b2017-02-12 13:52:30 -08004867*/
James Smart2d7dbc42017-02-12 13:52:35 -08004868LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4869 "NVME Target mode first burst size in 512B increments.");
4870
4871/*
4872 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4873 * For the Initiator (I), enabling this parameter means that an NVMET
4874 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4875 * processed by the initiator for subsequent NVME FCP IO. For the target
4876 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4877 * driver parameter as the target function's first burst size returned to the
4878 * initiator in the target's NVME PRLI response. Parameter supported on physical
4879 * port only - no NPIV support.
4880 * Value range is [0,1]. Default value is 0 (disabled).
4881 */
James Smart895427b2017-02-12 13:52:30 -08004882LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4883 "Enable First Burst feature on I and T functions.");
4884
4885/*
James Smart977b5a02008-09-07 11:52:04 -04004886# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4887# depth. Default value is 0. When the value of this parameter is zero the
4888# SCSI command completion time is not used for controlling I/O queue depth. When
4889# the parameter is set to a non-zero value, the I/O queue depth is controlled
4890# to limit the I/O completion time to the parameter value.
4891# The value is set in milliseconds.
4892*/
James Smarted5b1522016-10-13 15:06:11 -07004893LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
James Smart977b5a02008-09-07 11:52:04 -04004894 "Use command completion time to control queue depth");
James Smarted5b1522016-10-13 15:06:11 -07004895
James Smart977b5a02008-09-07 11:52:04 -04004896lpfc_vport_param_show(max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04004897static int
4898lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4899{
4900 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4901 struct lpfc_nodelist *ndlp, *next_ndlp;
4902
4903 if (val == vport->cfg_max_scsicmpl_time)
4904 return 0;
4905 if ((val < 0) || (val > 60000))
4906 return -EINVAL;
4907 vport->cfg_max_scsicmpl_time = val;
4908
4909 spin_lock_irq(shost->host_lock);
4910 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4911 if (!NLP_CHK_NODE_ACT(ndlp))
4912 continue;
4913 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4914 continue;
James Smart7dc517d2010-07-14 15:32:10 -04004915 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04004916 }
4917 spin_unlock_irq(shost->host_lock);
4918 return 0;
4919}
4920lpfc_vport_param_store(max_scsicmpl_time);
Joe Perchesb6b996b2017-12-19 10:15:07 -08004921static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04004922
4923/*
dea31012005-04-17 16:05:31 -05004924# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4925# range is [0,1]. Default value is 0.
4926*/
4927LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4928
4929/*
James Smart895427b2017-02-12 13:52:30 -08004930 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4931 * range is [0,1]. Default value is 0.
4932 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4933 * For [1], FCP commands are issued to a Work Queue associated with the
4934 * current CPU.
4935 *
4936 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4937 * LPFC_FCP_SCHED_BY_CPU == 1
4938 *
4939 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4940 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4941 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4942 * through WQs will be used.
4943 */
4944LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4945 LPFC_FCP_SCHED_ROUND_ROBIN,
4946 LPFC_FCP_SCHED_BY_CPU,
4947 "Determine scheduling algorithm for "
4948 "issuing commands [0] - Round Robin, [1] - Current CPU");
James Smart49aa1432012-08-03 12:36:42 -04004949
4950/*
James Smarta6571c62012-10-31 14:44:42 -04004951# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4952# range is [0,1]. Default value is 0.
4953# For [0], bus reset issues target reset to ALL devices
4954# For [1], bus reset issues target reset to non-FCP2 devices
4955*/
4956LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4957 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4958
4959
4960/*
dea31012005-04-17 16:05:31 -05004961# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4962# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04004963# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05004964# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4965# cr_delay is set to 0.
4966*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004967LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05004968 "interrupt response is generated");
4969
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004970LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05004971 "interrupt response is generated");
4972
4973/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004974# lpfc_multi_ring_support: Determines how many rings to spread available
4975# cmd/rsp IOCB entries across.
4976# Value range is [1,2]. Default value is 1.
4977*/
4978LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4979 "SLI rings to spread IOCB entries across");
4980
4981/*
James Smarta4bc3372006-12-02 13:34:16 -05004982# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4983# identifies what rctl value to configure the additional ring for.
4984# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4985*/
James Smart6a9c52c2009-10-02 15:16:51 -04004986LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004987 255, "Identifies RCTL for additional ring configuration");
4988
4989/*
4990# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4991# identifies what type value to configure the additional ring for.
4992# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4993*/
James Smart6a9c52c2009-10-02 15:16:51 -04004994LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004995 255, "Identifies TYPE for additional ring configuration");
4996
4997/*
James Smart4258e982015-12-16 18:11:58 -05004998# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4999# 0 = SmartSAN functionality disabled (default)
5000# 1 = SmartSAN functionality enabled
5001# This parameter will override the value of lpfc_fdmi_on module parameter.
5002# Value range is [0,1]. Default value is 0.
dea31012005-04-17 16:05:31 -05005003*/
James Smart4258e982015-12-16 18:11:58 -05005004LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
5005
5006/*
5007# lpfc_fdmi_on: Controls FDMI support.
5008# 0 No FDMI support (default)
5009# 1 Traditional FDMI support
James Smart8663cbb2016-03-31 14:12:33 -07005010# Traditional FDMI support means the driver will assume FDMI-2 support;
5011# however, if that fails, it will fallback to FDMI-1.
5012# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5013# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5014# lpfc_fdmi_on.
5015# Value range [0,1]. Default value is 0.
James Smart4258e982015-12-16 18:11:58 -05005016*/
James Smart8663cbb2016-03-31 14:12:33 -07005017LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05005018
5019/*
5020# Specifies the maximum number of ELS cmds we can have outstanding (for
5021# discovery). Value range is [1,64]. Default value = 32.
5022*/
James Smart3de2a652007-08-02 11:09:59 -04005023LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05005024 "during discovery");
5025
5026/*
James Smartc4a7c922013-05-31 17:04:59 -04005027# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
5028# will be scanned by the SCSI midlayer when sequential scanning is
5029# used; and is also the highest LUN ID allowed when the SCSI midlayer
5030# parses REPORT_LUN responses. The lpfc driver has no LUN count or
5031# LUN ID limit, but the SCSI midlayer requires this field for the uses
5032# above. The lpfc driver limits the default value to 255 for two reasons.
5033# As it bounds the sequential scan loop, scanning for thousands of luns
5034# on a target can take minutes of wall clock time. Additionally,
5035# there are FC targets, such as JBODs, that only recognize 8-bits of
5036# LUN ID. When they receive a value greater than 8 bits, they chop off
5037# the high order bits. In other words, they see LUN IDs 0, 256, 512,
5038# and so on all as LUN ID 0. This causes the linux kernel, which sees
5039# valid responses at each of the LUN IDs, to believe there are multiple
5040# devices present, when in fact, there is only 1.
5041# A customer that is aware of their target behaviors, and the results as
5042# indicated above, is welcome to increase the lpfc_max_luns value.
5043# As mentioned, this value is not used by the lpfc driver, only the
5044# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04005045# Value range is [0,65535]. Default value is 255.
5046# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05005047*/
Hannes Reinecke1abf6352014-06-25 15:27:38 +02005048LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05005049
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005050/*
5051# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
5052# Value range is [1,255], default value is 10.
5053*/
5054LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
5055 "Milliseconds driver will wait between polling FCP ring");
5056
James Smart4ff43242006-12-02 13:34:56 -05005057/*
James Smart0c411222013-09-06 12:22:46 -04005058# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
5059# to complete in seconds. Value range is [5,180], default value is 60.
5060*/
5061LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
5062 "Maximum time to wait for task management commands to complete");
5063/*
James Smart4ff43242006-12-02 13:34:56 -05005064# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5065# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02005066# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05005067# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02005068# 2 = MSI-X enabled (default)
5069# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05005070*/
George Kadianakis8605c462010-01-17 21:19:31 +02005071LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05005072 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05005073
James Smart13815c82008-01-11 01:52:48 -05005074/*
James Smartf358dd02017-02-12 13:52:34 -08005075 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
James Smart895427b2017-02-12 13:52:30 -08005076 *
5077 * 0 = NVME OAS disabled
5078 * 1 = NVME OAS enabled
5079 *
5080 * Value range is [0,1]. Default value is 0.
5081 */
5082LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5083 "Use OAS bit on NVME IOs");
5084
5085/*
James Smart4e565cf2018-02-22 08:18:50 -08005086 * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
5087 *
5088 * 0 = Put NVME Command in SGL
5089 * 1 = Embed NVME Command in WQE (unless G7)
5090 * 2 = Embed NVME Command in WQE (force)
5091 *
5092 * Value range is [0,2]. Default value is 1.
5093 */
5094LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,
5095 "Embed NVME Command in WQE");
5096
5097/*
James Smart895427b2017-02-12 13:52:30 -08005098 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
5099 * will advertise it supports to the SCSI layer. This also will map to
5100 * the number of WQs the driver will create.
5101 *
5102 * 0 = Configure the number of io channels to the number of active CPUs.
5103 * 1,32 = Manually specify how many io channels to use.
5104 *
5105 * Value range is [0,32]. Default value is 4.
5106 */
5107LPFC_ATTR_R(fcp_io_channel,
5108 LPFC_FCP_IO_CHAN_DEF,
5109 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
James Smart67d12732012-08-03 12:36:13 -04005110 "Set the number of FCP I/O channels");
5111
5112/*
James Smart895427b2017-02-12 13:52:30 -08005113 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
5114 * will advertise it supports to the NVME layer. This also will map to
5115 * the number of WQs the driver will create.
5116 *
5117 * This module parameter is valid when lpfc_enable_fc4_type is set
5118 * to support NVME.
5119 *
5120 * The NVME Layer will try to create this many, plus 1 administrative
5121 * hardware queue. The administrative queue will always map to WQ 0
5122 * A hardware IO queue maps (qidx) to a specific driver WQ.
5123 *
5124 * 0 = Configure the number of io channels to the number of active CPUs.
5125 * 1,32 = Manually specify how many io channels to use.
5126 *
5127 * Value range is [0,32]. Default value is 0.
5128 */
5129LPFC_ATTR_R(nvme_io_channel,
5130 LPFC_NVME_IO_CHAN_DEF,
5131 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
5132 "Set the number of NVME I/O channels");
5133
5134/*
James Smart13815c82008-01-11 01:52:48 -05005135# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5136# 0 = HBA resets disabled
5137# 1 = HBA resets enabled (default)
5138# Value range is [0,1]. Default value is 1.
5139*/
5140LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04005141
James Smart13815c82008-01-11 01:52:48 -05005142/*
James Smarteb7a3392010-11-20 23:12:02 -05005143# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05005144# 0 = HBA Heartbeat disabled
5145# 1 = HBA Heartbeat enabled (default)
5146# Value range is [0,1]. Default value is 1.
5147*/
James Smarteb7a3392010-11-20 23:12:02 -05005148LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05005149
James Smart83108bd2008-01-11 01:53:09 -05005150/*
James Smart1ba981f2014-02-20 09:56:45 -05005151# lpfc_EnableXLane: Enable Express Lane Feature
5152# 0x0 Express Lane Feature disabled
5153# 0x1 Express Lane Feature enabled
5154# Value range is [0,1]. Default value is 0.
5155*/
5156LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5157
5158/*
5159# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5160# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5161# Value range is [0x0,0x7f]. Default value is 0
5162*/
James Smart28d7f3d2014-05-21 08:05:28 -04005163LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
James Smart1ba981f2014-02-20 09:56:45 -05005164
5165/*
James Smart81301a92008-12-04 22:39:46 -05005166# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5167# 0 = BlockGuard disabled (default)
5168# 1 = BlockGuard enabled
5169# Value range is [0,1]. Default value is 0.
5170*/
5171LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5172
James Smart6fb120a2009-05-22 14:52:59 -04005173/*
James Smartba20c852012-08-03 12:36:52 -04005174# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5175# 0 = disabled (default)
5176# 1 = enabled
5177# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04005178#
5179# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04005180*/
5181unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5182
James Smartba20c852012-08-03 12:36:52 -04005183/*
James Smart81301a92008-12-04 22:39:46 -05005184# lpfc_prot_mask: i
5185# - Bit mask of host protection capabilities used to register with the
5186# SCSI mid-layer
5187# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5188# - Allows you to ultimately specify which profiles to use
5189# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04005190# - SHOST_DIF_TYPE1_PROTECTION 1
5191# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5192# - SHOST_DIX_TYPE0_PROTECTION 8
5193# HBA supports DIX Type 0: Host to HBA protection only
5194# - SHOST_DIX_TYPE1_PROTECTION 16
5195# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05005196#
5197*/
James Smartb3b98b72016-10-13 15:06:06 -07005198LPFC_ATTR(prot_mask,
5199 (SHOST_DIF_TYPE1_PROTECTION |
5200 SHOST_DIX_TYPE0_PROTECTION |
5201 SHOST_DIX_TYPE1_PROTECTION),
5202 0,
5203 (SHOST_DIF_TYPE1_PROTECTION |
5204 SHOST_DIX_TYPE0_PROTECTION |
5205 SHOST_DIX_TYPE1_PROTECTION),
5206 "T10-DIF host protection capabilities mask");
James Smart81301a92008-12-04 22:39:46 -05005207
5208/*
5209# lpfc_prot_guard: i
5210# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04005211# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05005212# - Allows you to ultimately specify which profiles to use
5213# - Default will result in registering capabilities for all guard types
5214#
5215*/
James Smartb3b98b72016-10-13 15:06:06 -07005216LPFC_ATTR(prot_guard,
5217 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5218 "T10-DIF host protection guard type");
James Smart81301a92008-12-04 22:39:46 -05005219
James Smart92494142011-02-16 12:39:44 -05005220/*
5221 * Delay initial NPort discovery when Clean Address bit is cleared in
5222 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5223 * This parameter can have value 0 or 1.
5224 * When this parameter is set to 0, no delay is added to the initial
5225 * discovery.
5226 * When this parameter is set to non-zero value, initial Nport discovery is
5227 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5228 * accept and FCID/Fabric name/Fabric portname is changed.
5229 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5230 * when Clean Address bit is cleared in FLOGI/FDISC
5231 * accept and FCID/Fabric name/Fabric portname is changed.
5232 * Default value is 0.
5233 */
James Smart8eb8b962016-07-06 12:36:08 -07005234LPFC_ATTR(delay_discovery, 0, 0, 1,
5235 "Delay NPort discovery when Clean Address bit is cleared.");
James Smart81301a92008-12-04 22:39:46 -05005236
5237/*
James Smart3621a712009-04-06 18:47:14 -04005238 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart96f70772013-04-17 20:16:15 -04005239 * This value can be set to values between 64 and 4096. The default value is
James Smart83108bd2008-01-11 01:53:09 -05005240 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5241 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04005242 * Because of the additional overhead involved in setting up T10-DIF,
5243 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5244 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05005245 */
James Smartb996ce32017-12-19 10:57:50 -08005246LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_MIN_SG_SEG_CNT,
James Smart83108bd2008-01-11 01:53:09 -05005247 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5248
James Smart96f70772013-04-17 20:16:15 -04005249/*
James Smart7bdedb32016-07-06 12:36:00 -07005250 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5251 * 0 = MDS Diagnostics disabled (default)
5252 * 1 = MDS Diagnostics enabled
5253 * Value range is [0,1]. Default value is 0.
5254 */
5255LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5256
James Smart44fd7fe2017-08-23 16:55:47 -07005257/*
5258 * lpfc_enable_bbcr: Enable BB Credit Recovery
5259 * 0 = BB Credit Recovery disabled
5260 * 1 = BB Credit Recovery enabled (default)
5261 * Value range is [0,1]. Default value is 1.
5262 */
5263LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5264
James Smart1351e692018-02-22 08:18:43 -08005265/*
5266 * lpfc_enable_dpp: Enable DPP on G7
5267 * 0 = DPP on G7 disabled
5268 * 1 = DPP on G7 enabled (default)
5269 * Value range is [0,1]. Default value is 1.
5270 */
5271LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");
5272
Tony Jonesee959b02008-02-22 00:13:36 +01005273struct device_attribute *lpfc_hba_attrs[] = {
James Smart895427b2017-02-12 13:52:30 -08005274 &dev_attr_nvme_info,
James Smart81301a92008-12-04 22:39:46 -05005275 &dev_attr_bg_info,
5276 &dev_attr_bg_guard_err,
5277 &dev_attr_bg_apptag_err,
5278 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01005279 &dev_attr_info,
5280 &dev_attr_serialnum,
5281 &dev_attr_modeldesc,
5282 &dev_attr_modelname,
5283 &dev_attr_programtype,
5284 &dev_attr_portnum,
5285 &dev_attr_fwrev,
5286 &dev_attr_hdw,
5287 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005288 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005289 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04005290 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01005291 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04005292 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01005293 &dev_attr_lpfc_temp_sensor,
5294 &dev_attr_lpfc_log_verbose,
5295 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005296 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005297 &dev_attr_lpfc_hba_queue_depth,
5298 &dev_attr_lpfc_peer_port_login,
5299 &dev_attr_lpfc_nodev_tmo,
5300 &dev_attr_lpfc_devloss_tmo,
James Smart895427b2017-02-12 13:52:30 -08005301 &dev_attr_lpfc_enable_fc4_type,
5302 &dev_attr_lpfc_xri_split,
Tony Jonesee959b02008-02-22 00:13:36 +01005303 &dev_attr_lpfc_fcp_class,
5304 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005305 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005306 &dev_attr_lpfc_ack0,
5307 &dev_attr_lpfc_topology,
5308 &dev_attr_lpfc_scan_down,
5309 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04005310 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04005311 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01005312 &dev_attr_lpfc_cr_delay,
5313 &dev_attr_lpfc_cr_count,
5314 &dev_attr_lpfc_multi_ring_support,
5315 &dev_attr_lpfc_multi_ring_rctl,
5316 &dev_attr_lpfc_multi_ring_type,
5317 &dev_attr_lpfc_fdmi_on,
James Smart4258e982015-12-16 18:11:58 -05005318 &dev_attr_lpfc_enable_SmartSAN,
Tony Jonesee959b02008-02-22 00:13:36 +01005319 &dev_attr_lpfc_max_luns,
5320 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04005321 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05005322 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01005323 &dev_attr_nport_evt_cnt,
5324 &dev_attr_board_mode,
5325 &dev_attr_max_vpi,
5326 &dev_attr_used_vpi,
5327 &dev_attr_max_rpi,
5328 &dev_attr_used_rpi,
5329 &dev_attr_max_xri,
5330 &dev_attr_used_xri,
5331 &dev_attr_npiv_info,
5332 &dev_attr_issue_reset,
5333 &dev_attr_lpfc_poll,
5334 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04005335 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01005336 &dev_attr_lpfc_use_msi,
James Smart895427b2017-02-12 13:52:30 -08005337 &dev_attr_lpfc_nvme_oas,
James Smart4e565cf2018-02-22 08:18:50 -08005338 &dev_attr_lpfc_nvme_embed_cmd,
James Smart0cf07f842017-06-01 21:07:10 -07005339 &dev_attr_lpfc_auto_imax,
James Smartda0436e2009-05-22 14:51:39 -04005340 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04005341 &dev_attr_lpfc_fcp_cpu_map,
James Smart67d12732012-08-03 12:36:13 -04005342 &dev_attr_lpfc_fcp_io_channel,
James Smartf358dd02017-02-12 13:52:34 -08005343 &dev_attr_lpfc_suppress_rsp,
James Smart895427b2017-02-12 13:52:30 -08005344 &dev_attr_lpfc_nvme_io_channel,
James Smart2d7dbc42017-02-12 13:52:35 -08005345 &dev_attr_lpfc_nvmet_mrq,
James Smart895427b2017-02-12 13:52:30 -08005346 &dev_attr_lpfc_nvme_enable_fb,
James Smart2d7dbc42017-02-12 13:52:35 -08005347 &dev_attr_lpfc_nvmet_fb_size,
James Smart81301a92008-12-04 22:39:46 -05005348 &dev_attr_lpfc_enable_bg,
James Smart352e5fd2016-12-30 06:57:47 -08005349 &dev_attr_lpfc_soft_wwnn,
5350 &dev_attr_lpfc_soft_wwpn,
5351 &dev_attr_lpfc_soft_wwn_enable,
Tony Jonesee959b02008-02-22 00:13:36 +01005352 &dev_attr_lpfc_enable_hba_reset,
5353 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05005354 &dev_attr_lpfc_EnableXLane,
5355 &dev_attr_lpfc_XLanePriority,
5356 &dev_attr_lpfc_xlane_lun,
5357 &dev_attr_lpfc_xlane_tgt,
5358 &dev_attr_lpfc_xlane_vpt,
5359 &dev_attr_lpfc_xlane_lun_state,
5360 &dev_attr_lpfc_xlane_lun_status,
James Smartc92c8412016-07-06 12:36:05 -07005361 &dev_attr_lpfc_xlane_priority,
Tony Jonesee959b02008-02-22 00:13:36 +01005362 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04005363 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04005364 &dev_attr_lpfc_stat_data_ctrl,
James Smart0d878412009-10-02 15:16:56 -04005365 &dev_attr_lpfc_aer_support,
5366 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04005367 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04005368 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05005369 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04005370 &dev_attr_lpfc_iocb_cnt,
5371 &dev_attr_iocb_hw,
5372 &dev_attr_txq_hw,
5373 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04005374 &dev_attr_lpfc_fips_level,
5375 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05005376 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04005377 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05005378 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05005379 &dev_attr_lpfc_xlane_supported,
James Smart7bdedb32016-07-06 12:36:00 -07005380 &dev_attr_lpfc_enable_mds_diags,
James Smart44fd7fe2017-08-23 16:55:47 -07005381 &dev_attr_lpfc_enable_bbcr,
James Smart1351e692018-02-22 08:18:43 -08005382 &dev_attr_lpfc_enable_dpp,
dea31012005-04-17 16:05:31 -05005383 NULL,
5384};
5385
Tony Jonesee959b02008-02-22 00:13:36 +01005386struct device_attribute *lpfc_vport_attrs[] = {
5387 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005388 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005389 &dev_attr_num_discovered_ports,
5390 &dev_attr_lpfc_drvr_version,
5391 &dev_attr_lpfc_log_verbose,
5392 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005393 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005394 &dev_attr_lpfc_nodev_tmo,
5395 &dev_attr_lpfc_devloss_tmo,
5396 &dev_attr_lpfc_hba_queue_depth,
5397 &dev_attr_lpfc_peer_port_login,
5398 &dev_attr_lpfc_restrict_login,
5399 &dev_attr_lpfc_fcp_class,
5400 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005401 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005402 &dev_attr_lpfc_max_luns,
5403 &dev_attr_nport_evt_cnt,
5404 &dev_attr_npiv_info,
5405 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04005406 &dev_attr_lpfc_max_scsicmpl_time,
5407 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04005408 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04005409 &dev_attr_lpfc_fips_level,
5410 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04005411 NULL,
5412};
5413
James Smarte59058c2008-08-24 21:49:00 -04005414/**
James Smart3621a712009-04-06 18:47:14 -04005415 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005416 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005417 * @kobj: kernel kobject that contains the kernel class device.
5418 * @bin_attr: kernel attributes passed to us.
5419 * @buf: contains the data to be written to the adapter IOREG space.
5420 * @off: offset into buffer to beginning of data.
5421 * @count: bytes to transfer.
5422 *
5423 * Description:
5424 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5425 * Uses the adapter io control registers to send buf contents to the adapter.
5426 *
5427 * Returns:
5428 * -ERANGE off and count combo out of range
5429 * -EINVAL off, count or buff address invalid
5430 * -EPERM adapter is offline
5431 * value of count, buf contents written
5432 **/
dea31012005-04-17 16:05:31 -05005433static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005434sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5435 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005436 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005437{
5438 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01005439 struct device *dev = container_of(kobj, struct device, kobj);
5440 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005441 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5442 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005443
James Smartf1126682009-06-10 17:22:44 -04005444 if (phba->sli_rev >= LPFC_SLI_REV4)
5445 return -EPERM;
5446
dea31012005-04-17 16:05:31 -05005447 if ((off + count) > FF_REG_AREA_SIZE)
5448 return -ERANGE;
5449
James Smartf7a919b2011-08-21 21:49:16 -04005450 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5451 return 0;
dea31012005-04-17 16:05:31 -05005452
5453 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5454 return -EINVAL;
5455
James Smartf7a919b2011-08-21 21:49:16 -04005456 /* This is to protect HBA registers from accidental writes. */
5457 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5458 return -EINVAL;
5459
5460 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05005461 return -EPERM;
dea31012005-04-17 16:05:31 -05005462
James Smart2e0fef82007-06-17 19:56:36 -05005463 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04005464 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5465 buf_off += sizeof(uint32_t))
5466 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05005467 phba->ctrl_regs_memmap_p + off + buf_off);
5468
James Smart2e0fef82007-06-17 19:56:36 -05005469 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005470
5471 return count;
5472}
5473
James Smarte59058c2008-08-24 21:49:00 -04005474/**
James Smart3621a712009-04-06 18:47:14 -04005475 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005476 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005477 * @kobj: kernel kobject that contains the kernel class device.
5478 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005479 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04005480 * @off: offset into buffer to beginning of data.
5481 * @count: bytes to transfer.
5482 *
5483 * Description:
5484 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5485 * Uses the adapter io control registers to read data into buf.
5486 *
5487 * Returns:
5488 * -ERANGE off and count combo out of range
5489 * -EINVAL off, count or buff address invalid
5490 * value of count, buf contents read
5491 **/
dea31012005-04-17 16:05:31 -05005492static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005493sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5494 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005495 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005496{
5497 size_t buf_off;
5498 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01005499 struct device *dev = container_of(kobj, struct device, kobj);
5500 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005501 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5502 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005503
James Smartf1126682009-06-10 17:22:44 -04005504 if (phba->sli_rev >= LPFC_SLI_REV4)
5505 return -EPERM;
5506
dea31012005-04-17 16:05:31 -05005507 if (off > FF_REG_AREA_SIZE)
5508 return -ERANGE;
5509
5510 if ((off + count) > FF_REG_AREA_SIZE)
5511 count = FF_REG_AREA_SIZE - off;
5512
5513 if (count == 0) return 0;
5514
5515 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5516 return -EINVAL;
5517
James Smart2e0fef82007-06-17 19:56:36 -05005518 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005519
5520 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5521 tmp_ptr = (uint32_t *)(buf + buf_off);
5522 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5523 }
5524
James Smart2e0fef82007-06-17 19:56:36 -05005525 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005526
5527 return count;
5528}
5529
5530static struct bin_attribute sysfs_ctlreg_attr = {
5531 .attr = {
5532 .name = "ctlreg",
5533 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005534 },
5535 .size = 256,
5536 .read = sysfs_ctlreg_read,
5537 .write = sysfs_ctlreg_write,
5538};
5539
James Smarte59058c2008-08-24 21:49:00 -04005540/**
James Smart3621a712009-04-06 18:47:14 -04005541 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005542 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005543 * @kobj: kernel kobject that contains the kernel class device.
5544 * @bin_attr: kernel attributes passed to us.
5545 * @buf: contains the data to be written to sysfs mbox.
5546 * @off: offset into buffer to beginning of data.
5547 * @count: bytes to transfer.
5548 *
5549 * Description:
James Smart026abb82011-12-13 13:20:45 -05005550 * Deprecated function. All mailbox access from user space is performed via the
5551 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005552 *
5553 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005554 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005555 **/
dea31012005-04-17 16:05:31 -05005556static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005557sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5558 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005559 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005560{
James Smart026abb82011-12-13 13:20:45 -05005561 return -EPERM;
dea31012005-04-17 16:05:31 -05005562}
5563
James Smarte59058c2008-08-24 21:49:00 -04005564/**
James Smart3621a712009-04-06 18:47:14 -04005565 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005566 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005567 * @kobj: kernel kobject that contains the kernel class device.
5568 * @bin_attr: kernel attributes passed to us.
5569 * @buf: contains the data to be read from sysfs mbox.
5570 * @off: offset into buffer to beginning of data.
5571 * @count: bytes to transfer.
5572 *
5573 * Description:
James Smart026abb82011-12-13 13:20:45 -05005574 * Deprecated function. All mailbox access from user space is performed via the
5575 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005576 *
5577 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005578 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005579 **/
dea31012005-04-17 16:05:31 -05005580static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005581sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5582 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005583 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005584{
James Smart026abb82011-12-13 13:20:45 -05005585 return -EPERM;
dea31012005-04-17 16:05:31 -05005586}
5587
5588static struct bin_attribute sysfs_mbox_attr = {
5589 .attr = {
5590 .name = "mbox",
5591 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005592 },
James Smartc0c11512011-05-24 11:41:34 -04005593 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05005594 .read = sysfs_mbox_read,
5595 .write = sysfs_mbox_write,
5596};
5597
James Smarte59058c2008-08-24 21:49:00 -04005598/**
James Smart3621a712009-04-06 18:47:14 -04005599 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005600 * @vport: address of lpfc vport structure.
5601 *
5602 * Return codes:
5603 * zero on success
5604 * error return code from sysfs_create_bin_file()
5605 **/
dea31012005-04-17 16:05:31 -05005606int
James Smart2e0fef82007-06-17 19:56:36 -05005607lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005608{
James Smart2e0fef82007-06-17 19:56:36 -05005609 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005610 int error;
5611
Tony Jonesee959b02008-02-22 00:13:36 +01005612 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05005613 &sysfs_drvr_stat_data_attr);
5614
5615 /* Virtual ports do not need ctrl_reg and mbox */
5616 if (error || vport->port_type == LPFC_NPIV_PORT)
5617 goto out;
5618
5619 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005620 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005621 if (error)
James Smarteada2722008-12-04 22:39:13 -05005622 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05005623
Tony Jonesee959b02008-02-22 00:13:36 +01005624 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005625 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05005626 if (error)
5627 goto out_remove_ctlreg_attr;
5628
5629 return 0;
5630out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01005631 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05005632out_remove_stat_attr:
5633 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5634 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05005635out:
5636 return error;
5637}
5638
James Smarte59058c2008-08-24 21:49:00 -04005639/**
James Smart3621a712009-04-06 18:47:14 -04005640 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005641 * @vport: address of lpfc vport structure.
5642 **/
dea31012005-04-17 16:05:31 -05005643void
James Smart2e0fef82007-06-17 19:56:36 -05005644lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005645{
James Smart2e0fef82007-06-17 19:56:36 -05005646 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04005647 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5648 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05005649 /* Virtual ports do not need ctrl_reg and mbox */
5650 if (vport->port_type == LPFC_NPIV_PORT)
5651 return;
Tony Jonesee959b02008-02-22 00:13:36 +01005652 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5653 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005654}
5655
dea31012005-04-17 16:05:31 -05005656/*
5657 * Dynamic FC Host Attributes Support
5658 */
5659
James Smarte59058c2008-08-24 21:49:00 -04005660/**
James Smart6c9231f2016-12-19 15:07:24 -08005661 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5662 * @shost: kernel scsi host pointer.
5663 **/
5664static void
5665lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5666{
5667 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5668
5669 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5670 sizeof fc_host_symbolic_name(shost));
5671}
5672
5673/**
James Smart3621a712009-04-06 18:47:14 -04005674 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04005675 * @shost: kernel scsi host pointer.
5676 **/
dea31012005-04-17 16:05:31 -05005677static void
5678lpfc_get_host_port_id(struct Scsi_Host *shost)
5679{
James Smart2e0fef82007-06-17 19:56:36 -05005680 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5681
dea31012005-04-17 16:05:31 -05005682 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05005683 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005684}
5685
James Smarte59058c2008-08-24 21:49:00 -04005686/**
James Smart3621a712009-04-06 18:47:14 -04005687 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04005688 * @shost: kernel scsi host pointer.
5689 **/
dea31012005-04-17 16:05:31 -05005690static void
5691lpfc_get_host_port_type(struct Scsi_Host *shost)
5692{
James Smart2e0fef82007-06-17 19:56:36 -05005693 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5694 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005695
5696 spin_lock_irq(shost->host_lock);
5697
James Smart92d7f7b2007-06-17 19:56:38 -05005698 if (vport->port_type == LPFC_NPIV_PORT) {
5699 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5700 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05005701 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05005702 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05005703 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5704 else
5705 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5706 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005707 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05005708 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5709 else
5710 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5711 }
5712 } else
5713 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5714
5715 spin_unlock_irq(shost->host_lock);
5716}
5717
James Smarte59058c2008-08-24 21:49:00 -04005718/**
James Smart3621a712009-04-06 18:47:14 -04005719 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04005720 * @shost: kernel scsi host pointer.
5721 **/
dea31012005-04-17 16:05:31 -05005722static void
5723lpfc_get_host_port_state(struct Scsi_Host *shost)
5724{
James Smart2e0fef82007-06-17 19:56:36 -05005725 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5726 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005727
5728 spin_lock_irq(shost->host_lock);
5729
James Smart2e0fef82007-06-17 19:56:36 -05005730 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005731 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5732 else {
James Smart2e0fef82007-06-17 19:56:36 -05005733 switch (phba->link_state) {
5734 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05005735 case LPFC_LINK_DOWN:
5736 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5737 break;
5738 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05005739 case LPFC_CLEAR_LA:
5740 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05005741 /* Links up, reports port state accordingly */
5742 if (vport->port_state < LPFC_VPORT_READY)
5743 fc_host_port_state(shost) =
5744 FC_PORTSTATE_BYPASSED;
5745 else
5746 fc_host_port_state(shost) =
5747 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05005748 break;
5749 case LPFC_HBA_ERROR:
5750 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5751 break;
5752 default:
5753 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5754 break;
5755 }
5756 }
5757
5758 spin_unlock_irq(shost->host_lock);
5759}
5760
James Smarte59058c2008-08-24 21:49:00 -04005761/**
James Smart3621a712009-04-06 18:47:14 -04005762 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04005763 * @shost: kernel scsi host pointer.
5764 **/
dea31012005-04-17 16:05:31 -05005765static void
5766lpfc_get_host_speed(struct Scsi_Host *shost)
5767{
James Smart2e0fef82007-06-17 19:56:36 -05005768 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5769 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005770
5771 spin_lock_irq(shost->host_lock);
5772
James Smarta085e872015-12-16 18:12:02 -05005773 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea31012005-04-17 16:05:31 -05005774 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05005775 case LPFC_LINK_SPEED_1GHZ:
5776 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05005777 break;
James Smart76a95d72010-11-20 23:11:48 -05005778 case LPFC_LINK_SPEED_2GHZ:
5779 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05005780 break;
James Smart76a95d72010-11-20 23:11:48 -05005781 case LPFC_LINK_SPEED_4GHZ:
5782 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05005783 break;
James Smart76a95d72010-11-20 23:11:48 -05005784 case LPFC_LINK_SPEED_8GHZ:
5785 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04005786 break;
James Smart76a95d72010-11-20 23:11:48 -05005787 case LPFC_LINK_SPEED_10GHZ:
5788 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04005789 break;
James Smart76a95d72010-11-20 23:11:48 -05005790 case LPFC_LINK_SPEED_16GHZ:
5791 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5792 break;
James Smartd38dd522015-08-31 16:48:17 -04005793 case LPFC_LINK_SPEED_32GHZ:
5794 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5795 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08005796 case LPFC_LINK_SPEED_64GHZ:
5797 fc_host_speed(shost) = FC_PORTSPEED_64GBIT;
5798 break;
James Smart76a95d72010-11-20 23:11:48 -05005799 default:
5800 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005801 break;
5802 }
James Smart09372822008-01-11 01:52:54 -05005803 } else
5804 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005805
5806 spin_unlock_irq(shost->host_lock);
5807}
5808
James Smarte59058c2008-08-24 21:49:00 -04005809/**
James Smart3621a712009-04-06 18:47:14 -04005810 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04005811 * @shost: kernel scsi host pointer.
5812 **/
dea31012005-04-17 16:05:31 -05005813static void
5814lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5815{
James Smart2e0fef82007-06-17 19:56:36 -05005816 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5817 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005818 u64 node_name;
dea31012005-04-17 16:05:31 -05005819
5820 spin_lock_irq(shost->host_lock);
5821
James Smart73d91e52011-10-10 21:32:10 -04005822 if ((vport->port_state > LPFC_FLOGI) &&
5823 ((vport->fc_flag & FC_FABRIC) ||
5824 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5825 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07005826 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05005827 else
5828 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05005829 node_name = 0;
dea31012005-04-17 16:05:31 -05005830
5831 spin_unlock_irq(shost->host_lock);
5832
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005833 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05005834}
5835
James Smarte59058c2008-08-24 21:49:00 -04005836/**
James Smart3621a712009-04-06 18:47:14 -04005837 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04005838 * @shost: kernel scsi host pointer.
5839 *
5840 * Notes:
5841 * NULL on error for link down, no mbox pool, sli2 active,
5842 * management not allowed, memory allocation error, or mbox error.
5843 *
5844 * Returns:
5845 * NULL for error
5846 * address of the adapter host statistics
5847 **/
dea31012005-04-17 16:05:31 -05005848static struct fc_host_statistics *
5849lpfc_get_stats(struct Scsi_Host *shost)
5850{
James Smart2e0fef82007-06-17 19:56:36 -05005851 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5852 struct lpfc_hba *phba = vport->phba;
5853 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005854 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04005855 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05005856 LPFC_MBOXQ_t *pmboxq;
5857 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04005858 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005859 int rc = 0;
dea31012005-04-17 16:05:31 -05005860
James Smart92d7f7b2007-06-17 19:56:38 -05005861 /*
5862 * prevent udev from issuing mailbox commands until the port is
5863 * configured.
5864 */
James Smart2e0fef82007-06-17 19:56:36 -05005865 if (phba->link_state < LPFC_LINK_DOWN ||
5866 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04005867 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05005868 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005869
5870 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005871 return NULL;
5872
dea31012005-04-17 16:05:31 -05005873 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5874 if (!pmboxq)
5875 return NULL;
5876 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5877
James Smart04c68492009-05-22 14:52:52 -04005878 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05005879 pmb->mbxCommand = MBX_READ_STATUS;
5880 pmb->mbxOwner = OWN_HOST;
5881 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005882 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005883
James Smart75baf692010-06-08 18:31:21 -04005884 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005885 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005886 else
dea31012005-04-17 16:05:31 -05005887 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5888
5889 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005890 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005891 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005892 return NULL;
5893 }
5894
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005895 memset(hs, 0, sizeof (struct fc_host_statistics));
5896
dea31012005-04-17 16:05:31 -05005897 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005898 /*
5899 * The MBX_READ_STATUS returns tx_k_bytes which has to
5900 * converted to words
5901 */
5902 hs->tx_words = (uint64_t)
5903 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5904 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005905 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005906 hs->rx_words = (uint64_t)
5907 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5908 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005909
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005910 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05005911 pmb->mbxCommand = MBX_READ_LNK_STAT;
5912 pmb->mbxOwner = OWN_HOST;
5913 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005914 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005915
James Smart75baf692010-06-08 18:31:21 -04005916 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005917 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005918 else
dea31012005-04-17 16:05:31 -05005919 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5920
5921 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005922 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005923 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005924 return NULL;
5925 }
5926
5927 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5928 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5929 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5930 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5931 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5932 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5933 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5934
James Smart64ba8812006-08-02 15:24:34 -04005935 hs->link_failure_count -= lso->link_failure_count;
5936 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5937 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5938 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5939 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5940 hs->invalid_crc_count -= lso->invalid_crc_count;
5941 hs->error_frames -= lso->error_frames;
5942
James Smart76a95d72010-11-20 23:11:48 -05005943 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04005944 hs->lip_count = -1;
5945 hs->nos_count = (phba->link_events >> 1);
5946 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05005947 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005948 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005949 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005950 hs->nos_count = -1;
5951 } else {
5952 hs->lip_count = -1;
5953 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005954 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005955 }
5956
5957 hs->dumped_frames = -1;
5958
James Smart64ba8812006-08-02 15:24:34 -04005959 seconds = get_seconds();
5960 if (seconds < psli->stats_start)
5961 hs->seconds_since_last_reset = seconds +
5962 ((unsigned long)-1 - psli->stats_start);
5963 else
5964 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05005965
James Smart1dcb58e2007-04-25 09:51:30 -04005966 mempool_free(pmboxq, phba->mbox_mem_pool);
5967
dea31012005-04-17 16:05:31 -05005968 return hs;
5969}
5970
James Smarte59058c2008-08-24 21:49:00 -04005971/**
James Smart3621a712009-04-06 18:47:14 -04005972 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04005973 * @shost: kernel scsi host pointer.
5974 **/
James Smart64ba8812006-08-02 15:24:34 -04005975static void
5976lpfc_reset_stats(struct Scsi_Host *shost)
5977{
James Smart2e0fef82007-06-17 19:56:36 -05005978 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5979 struct lpfc_hba *phba = vport->phba;
5980 struct lpfc_sli *psli = &phba->sli;
5981 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04005982 LPFC_MBOXQ_t *pmboxq;
5983 MAILBOX_t *pmb;
5984 int rc = 0;
5985
James Smart2e0fef82007-06-17 19:56:36 -05005986 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005987 return;
5988
James Smart64ba8812006-08-02 15:24:34 -04005989 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5990 if (!pmboxq)
5991 return;
5992 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5993
James Smart04c68492009-05-22 14:52:52 -04005994 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04005995 pmb->mbxCommand = MBX_READ_STATUS;
5996 pmb->mbxOwner = OWN_HOST;
5997 pmb->un.varWords[0] = 0x1; /* reset request */
5998 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005999 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04006000
James Smart2e0fef82007-06-17 19:56:36 -05006001 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04006002 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04006003 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6004 else
6005 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6006
6007 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05006008 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04006009 mempool_free(pmboxq, phba->mbox_mem_pool);
6010 return;
6011 }
6012
6013 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6014 pmb->mbxCommand = MBX_READ_LNK_STAT;
6015 pmb->mbxOwner = OWN_HOST;
6016 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006017 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04006018
James Smart2e0fef82007-06-17 19:56:36 -05006019 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04006020 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04006021 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6022 else
6023 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6024
6025 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05006026 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04006027 mempool_free( pmboxq, phba->mbox_mem_pool);
6028 return;
6029 }
6030
6031 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6032 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6033 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6034 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6035 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6036 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6037 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05006038 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04006039 lso->link_events = (phba->link_events >> 1);
6040 else
6041 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04006042
6043 psli->stats_start = get_seconds();
6044
James Smart1dcb58e2007-04-25 09:51:30 -04006045 mempool_free(pmboxq, phba->mbox_mem_pool);
6046
James Smart64ba8812006-08-02 15:24:34 -04006047 return;
6048}
dea31012005-04-17 16:05:31 -05006049
6050/*
6051 * The LPFC driver treats linkdown handling as target loss events so there
6052 * are no sysfs handlers for link_down_tmo.
6053 */
James Smart685f0bf2007-04-25 09:53:08 -04006054
James Smarte59058c2008-08-24 21:49:00 -04006055/**
James Smart3621a712009-04-06 18:47:14 -04006056 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04006057 * @starget: kernel scsi target pointer.
6058 *
6059 * Returns:
6060 * address of the node list if found
6061 * NULL target not found
6062 **/
James Smart685f0bf2007-04-25 09:53:08 -04006063static struct lpfc_nodelist *
6064lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05006065{
James Smart2e0fef82007-06-17 19:56:36 -05006066 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
6067 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04006068 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006069
6070 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04006071 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05006072 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05006073 if (NLP_CHK_NODE_ACT(ndlp) &&
6074 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04006075 starget->id == ndlp->nlp_sid) {
6076 spin_unlock_irq(shost->host_lock);
6077 return ndlp;
dea31012005-04-17 16:05:31 -05006078 }
6079 }
6080 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04006081 return NULL;
6082}
dea31012005-04-17 16:05:31 -05006083
James Smarte59058c2008-08-24 21:49:00 -04006084/**
James Smart3621a712009-04-06 18:47:14 -04006085 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04006086 * @starget: kernel scsi target pointer.
6087 **/
James Smart685f0bf2007-04-25 09:53:08 -04006088static void
6089lpfc_get_starget_port_id(struct scsi_target *starget)
6090{
6091 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6092
6093 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05006094}
6095
James Smarte59058c2008-08-24 21:49:00 -04006096/**
James Smart3621a712009-04-06 18:47:14 -04006097 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04006098 * @starget: kernel scsi target pointer.
6099 *
6100 * Description: Set the target node name to the ndlp node name wwn or zero.
6101 **/
dea31012005-04-17 16:05:31 -05006102static void
6103lpfc_get_starget_node_name(struct scsi_target *starget)
6104{
James Smart685f0bf2007-04-25 09:53:08 -04006105 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05006106
James Smart685f0bf2007-04-25 09:53:08 -04006107 fc_starget_node_name(starget) =
6108 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05006109}
6110
James Smarte59058c2008-08-24 21:49:00 -04006111/**
James Smart3621a712009-04-06 18:47:14 -04006112 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04006113 * @starget: kernel scsi target pointer.
6114 *
6115 * Description: set the target port name to the ndlp port name wwn or zero.
6116 **/
dea31012005-04-17 16:05:31 -05006117static void
6118lpfc_get_starget_port_name(struct scsi_target *starget)
6119{
James Smart685f0bf2007-04-25 09:53:08 -04006120 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05006121
James Smart685f0bf2007-04-25 09:53:08 -04006122 fc_starget_port_name(starget) =
6123 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05006124}
6125
James Smarte59058c2008-08-24 21:49:00 -04006126/**
James Smart3621a712009-04-06 18:47:14 -04006127 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04006128 * @rport: fc rport address.
6129 * @timeout: new value for dev loss tmo.
6130 *
6131 * Description:
6132 * If timeout is non zero set the dev_loss_tmo to timeout, else set
6133 * dev_loss_tmo to one.
6134 **/
dea31012005-04-17 16:05:31 -05006135static void
dea31012005-04-17 16:05:31 -05006136lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6137{
dea31012005-04-17 16:05:31 -05006138 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04006139 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05006140 else
James Smartc01f3202006-08-18 17:47:08 -04006141 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05006142}
6143
James Smarte59058c2008-08-24 21:49:00 -04006144/**
James Smart3621a712009-04-06 18:47:14 -04006145 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04006146 *
6147 * Description:
6148 * Macro that uses field to generate a function with the name lpfc_show_rport_
6149 *
6150 * lpfc_show_rport_##field: returns the bytes formatted in buf
6151 * @cdev: class converted to an fc_rport.
6152 * @buf: on return contains the target_field or zero.
6153 *
6154 * Returns: size of formatted string.
6155 **/
dea31012005-04-17 16:05:31 -05006156#define lpfc_rport_show_function(field, format_string, sz, cast) \
6157static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01006158lpfc_show_rport_##field (struct device *dev, \
6159 struct device_attribute *attr, \
6160 char *buf) \
dea31012005-04-17 16:05:31 -05006161{ \
Tony Jonesee959b02008-02-22 00:13:36 +01006162 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05006163 struct lpfc_rport_data *rdata = rport->hostdata; \
6164 return snprintf(buf, sz, format_string, \
6165 (rdata->target) ? cast rdata->target->field : 0); \
6166}
6167
6168#define lpfc_rport_rd_attr(field, format_string, sz) \
6169 lpfc_rport_show_function(field, format_string, sz, ) \
6170static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6171
James Smarteada2722008-12-04 22:39:13 -05006172/**
James Smart3621a712009-04-06 18:47:14 -04006173 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05006174 * @fc_vport: The fc_vport who's symbolic name has been changed.
6175 *
6176 * Description:
6177 * This function is called by the transport after the @fc_vport's symbolic name
6178 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006179 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05006180 **/
6181static void
6182lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6183{
6184 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6185
6186 if (vport->port_state == LPFC_VPORT_READY)
6187 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6188}
dea31012005-04-17 16:05:31 -05006189
James Smartf4b4c682009-05-22 14:53:12 -04006190/**
6191 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6192 * @phba: Pointer to lpfc_hba struct.
6193 *
6194 * This function is called by the lpfc_get_cfgparam() routine to set the
6195 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02006196 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04006197 * before hba port or vport created.
6198 **/
6199static void
6200lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6201{
6202 phba->cfg_log_verbose = verbose;
6203}
6204
dea31012005-04-17 16:05:31 -05006205struct fc_function_template lpfc_transport_functions = {
6206 /* fixed attributes the driver supports */
6207 .show_host_node_name = 1,
6208 .show_host_port_name = 1,
6209 .show_host_supported_classes = 1,
6210 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05006211 .show_host_supported_speeds = 1,
6212 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006213
6214 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006215 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05006216
6217 /* dynamic attributes the driver supports */
6218 .get_host_port_id = lpfc_get_host_port_id,
6219 .show_host_port_id = 1,
6220
6221 .get_host_port_type = lpfc_get_host_port_type,
6222 .show_host_port_type = 1,
6223
6224 .get_host_port_state = lpfc_get_host_port_state,
6225 .show_host_port_state = 1,
6226
6227 /* active_fc4s is shown but doesn't change (thus no get function) */
6228 .show_host_active_fc4s = 1,
6229
6230 .get_host_speed = lpfc_get_host_speed,
6231 .show_host_speed = 1,
6232
6233 .get_host_fabric_name = lpfc_get_host_fabric_name,
6234 .show_host_fabric_name = 1,
6235
6236 /*
6237 * The LPFC driver treats linkdown handling as target loss events
6238 * so there are no sysfs handlers for link_down_tmo.
6239 */
6240
6241 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04006242 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05006243
6244 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6245 .show_rport_maxframe_size = 1,
6246 .show_rport_supported_classes = 1,
6247
dea31012005-04-17 16:05:31 -05006248 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6249 .show_rport_dev_loss_tmo = 1,
6250
6251 .get_starget_port_id = lpfc_get_starget_port_id,
6252 .show_starget_port_id = 1,
6253
6254 .get_starget_node_name = lpfc_get_starget_node_name,
6255 .show_starget_node_name = 1,
6256
6257 .get_starget_port_name = lpfc_get_starget_port_name,
6258 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07006259
6260 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04006261 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6262 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05006263
James Smart92d7f7b2007-06-17 19:56:38 -05006264 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05006265
6266 .vport_disable = lpfc_vport_disable,
6267
6268 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04006269
6270 .bsg_request = lpfc_bsg_request,
6271 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05006272};
6273
James Smart98c9ea52007-10-27 13:37:33 -04006274struct fc_function_template lpfc_vport_transport_functions = {
6275 /* fixed attributes the driver supports */
6276 .show_host_node_name = 1,
6277 .show_host_port_name = 1,
6278 .show_host_supported_classes = 1,
6279 .show_host_supported_fc4s = 1,
6280 .show_host_supported_speeds = 1,
6281 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006282
6283 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006284 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04006285
6286 /* dynamic attributes the driver supports */
6287 .get_host_port_id = lpfc_get_host_port_id,
6288 .show_host_port_id = 1,
6289
6290 .get_host_port_type = lpfc_get_host_port_type,
6291 .show_host_port_type = 1,
6292
6293 .get_host_port_state = lpfc_get_host_port_state,
6294 .show_host_port_state = 1,
6295
6296 /* active_fc4s is shown but doesn't change (thus no get function) */
6297 .show_host_active_fc4s = 1,
6298
6299 .get_host_speed = lpfc_get_host_speed,
6300 .show_host_speed = 1,
6301
6302 .get_host_fabric_name = lpfc_get_host_fabric_name,
6303 .show_host_fabric_name = 1,
6304
6305 /*
6306 * The LPFC driver treats linkdown handling as target loss events
6307 * so there are no sysfs handlers for link_down_tmo.
6308 */
6309
6310 .get_fc_host_stats = lpfc_get_stats,
6311 .reset_fc_host_stats = lpfc_reset_stats,
6312
6313 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6314 .show_rport_maxframe_size = 1,
6315 .show_rport_supported_classes = 1,
6316
6317 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6318 .show_rport_dev_loss_tmo = 1,
6319
6320 .get_starget_port_id = lpfc_get_starget_port_id,
6321 .show_starget_port_id = 1,
6322
6323 .get_starget_node_name = lpfc_get_starget_node_name,
6324 .show_starget_node_name = 1,
6325
6326 .get_starget_port_name = lpfc_get_starget_port_name,
6327 .show_starget_port_name = 1,
6328
6329 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6330 .terminate_rport_io = lpfc_terminate_rport_io,
6331
6332 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05006333
6334 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04006335};
6336
James Smarte59058c2008-08-24 21:49:00 -04006337/**
James Smart3621a712009-04-06 18:47:14 -04006338 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04006339 * @phba: lpfc_hba pointer.
6340 **/
dea31012005-04-17 16:05:31 -05006341void
6342lpfc_get_cfgparam(struct lpfc_hba *phba)
6343{
James Smart49aa1432012-08-03 12:36:42 -04006344 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04006345 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006346 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6347 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05006348 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05006349 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6350 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006351 lpfc_ack0_init(phba, lpfc_ack0);
6352 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006353 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05006354 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04006355 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04006356 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04006357 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05006358 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4258e982015-12-16 18:11:58 -05006359 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6360 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
James Smart4ff43242006-12-02 13:34:56 -05006361 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart895427b2017-02-12 13:52:30 -08006362 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
James Smart4e565cf2018-02-22 08:18:50 -08006363 lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);
James Smart0cf07f842017-06-01 21:07:10 -07006364 lpfc_auto_imax_init(phba, lpfc_auto_imax);
James Smartda0436e2009-05-22 14:51:39 -04006365 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04006366 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart13815c82008-01-11 01:52:48 -05006367 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6368 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart2ea259e2017-02-12 13:52:27 -08006369
James Smart1ba981f2014-02-20 09:56:45 -05006370 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6371 if (phba->sli_rev != LPFC_SLI_REV4)
6372 phba->cfg_EnableXLane = 0;
6373 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
James Smart2ea259e2017-02-12 13:52:27 -08006374
James Smart1ba981f2014-02-20 09:56:45 -05006375 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6376 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6377 phba->cfg_oas_lun_state = 0;
6378 phba->cfg_oas_lun_status = 0;
6379 phba->cfg_oas_flags = 0;
James Smartc92c8412016-07-06 12:36:05 -07006380 phba->cfg_oas_priority = 0;
James Smart81301a92008-12-04 22:39:46 -05006381 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smartb3b98b72016-10-13 15:06:06 -07006382 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6383 lpfc_prot_guard_init(phba, lpfc_prot_guard);
James Smart45ed1192009-10-02 15:17:02 -04006384 if (phba->sli_rev == LPFC_SLI_REV4)
6385 phba->cfg_poll = 0;
6386 else
James Smart1ba981f2014-02-20 09:56:45 -05006387 phba->cfg_poll = lpfc_poll;
James Smartf44ac122018-03-05 12:04:08 -08006388
6389 if (phba->cfg_enable_bg)
6390 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
6391
James Smartf358dd02017-02-12 13:52:34 -08006392 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
James Smart4258e982015-12-16 18:11:58 -05006393
James Smart895427b2017-02-12 13:52:30 -08006394 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
James Smart2d7dbc42017-02-12 13:52:35 -08006395 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
James Smart895427b2017-02-12 13:52:30 -08006396
6397 /* Initialize first burst. Target vs Initiator are different. */
6398 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
James Smart2d7dbc42017-02-12 13:52:35 -08006399 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
James Smart895427b2017-02-12 13:52:30 -08006400 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6401 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
James Smart44fd7fe2017-08-23 16:55:47 -07006402 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
James Smart1351e692018-02-22 08:18:43 -08006403 lpfc_enable_dpp_init(phba, lpfc_enable_dpp);
James Smart895427b2017-02-12 13:52:30 -08006404
6405 if (phba->sli_rev != LPFC_SLI_REV4) {
6406 /* NVME only supported on SLI4 */
6407 phba->nvmet_support = 0;
6408 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
James Smart44fd7fe2017-08-23 16:55:47 -07006409 phba->cfg_enable_bbcr = 0;
James Smart895427b2017-02-12 13:52:30 -08006410 } else {
6411 /* We MUST have FCP support */
6412 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6413 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6414 }
6415
James Smart0cf07f842017-06-01 21:07:10 -07006416 if (phba->cfg_auto_imax && !phba->cfg_fcp_imax)
6417 phba->cfg_auto_imax = 0;
6418 phba->initial_imax = phba->cfg_fcp_imax;
6419
James Smart895427b2017-02-12 13:52:30 -08006420 /* A value of 0 means use the number of CPUs found in the system */
James Smart895427b2017-02-12 13:52:30 -08006421 if (phba->cfg_fcp_io_channel == 0)
6422 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006423 if (phba->cfg_nvme_io_channel == 0)
6424 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smart895427b2017-02-12 13:52:30 -08006425
6426 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6427 phba->cfg_fcp_io_channel = 0;
6428
James Smartf358dd02017-02-12 13:52:34 -08006429 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6430 phba->cfg_nvme_io_channel = 0;
6431
James Smart895427b2017-02-12 13:52:30 -08006432 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6433 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6434 else
6435 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
James Smart4258e982015-12-16 18:11:58 -05006436
James Smart352e5fd2016-12-30 06:57:47 -08006437 phba->cfg_soft_wwnn = 0L;
6438 phba->cfg_soft_wwpn = 0L;
James Smart895427b2017-02-12 13:52:30 -08006439 lpfc_xri_split_init(phba, lpfc_xri_split);
James Smart83108bd2008-01-11 01:53:09 -05006440 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04006441 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04006442 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04006443 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04006444 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04006445 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05006446 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04006447 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart8eb8b962016-07-06 12:36:08 -07006448 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
James Smart12247e82016-07-06 12:36:09 -07006449 lpfc_sli_mode_init(phba, lpfc_sli_mode);
James Smartab56dc22011-02-16 12:39:57 -05006450 phba->cfg_enable_dss = 1;
James Smart7bdedb32016-07-06 12:36:00 -07006451 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
James Smart3de2a652007-08-02 11:09:59 -04006452 return;
6453}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05006454
James Smarte59058c2008-08-24 21:49:00 -04006455/**
James Smart895427b2017-02-12 13:52:30 -08006456 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6457 * dependencies between protocols and roles.
6458 * @phba: lpfc_hba pointer.
6459 **/
6460void
6461lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6462{
James Smart895427b2017-02-12 13:52:30 -08006463 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6464 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006465
James Smart895427b2017-02-12 13:52:30 -08006466 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6467 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6468
James Smartf358dd02017-02-12 13:52:34 -08006469 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6470 phba->nvmet_support) {
6471 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6472 phba->cfg_fcp_io_channel = 0;
James Smart2d7dbc42017-02-12 13:52:35 -08006473
6474 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6475 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6476 "NVME Target PRLI ACC enable_fb ",
6477 phba->cfg_nvme_enable_fb,
6478 phba->cfg_nvmet_fb_size,
6479 LPFC_NVMET_FB_SZ_MAX);
6480
6481 if (phba->cfg_nvme_enable_fb == 0)
6482 phba->cfg_nvmet_fb_size = 0;
6483 else {
6484 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6485 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6486 }
6487
James Smartbcb24f62017-11-20 16:00:36 -08006488 if (!phba->cfg_nvmet_mrq)
6489 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6490
James Smart2d7dbc42017-02-12 13:52:35 -08006491 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6492 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6493 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6494 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6495 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6496 phba->cfg_nvmet_mrq);
6497 }
James Smartbcb24f62017-11-20 16:00:36 -08006498 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
6499 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
6500
James Smart2d7dbc42017-02-12 13:52:35 -08006501 } else {
James Smartf358dd02017-02-12 13:52:34 -08006502 /* Not NVME Target mode. Turn off Target parameters. */
6503 phba->nvmet_support = 0;
James Smartbcb24f62017-11-20 16:00:36 -08006504 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF;
James Smart2d7dbc42017-02-12 13:52:35 -08006505 phba->cfg_nvmet_fb_size = 0;
6506 }
James Smartf358dd02017-02-12 13:52:34 -08006507
James Smart895427b2017-02-12 13:52:30 -08006508 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6509 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6510 else
6511 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6512}
6513
6514/**
James Smart3621a712009-04-06 18:47:14 -04006515 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04006516 * @vport: lpfc_vport pointer.
6517 **/
James Smart3de2a652007-08-02 11:09:59 -04006518void
6519lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6520{
James Smarte8b62012007-08-02 11:10:09 -04006521 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04006522 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04006523 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04006524 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6525 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6526 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6527 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6528 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6529 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04006530 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04006531 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04006532 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6533 lpfc_max_luns_init(vport, lpfc_max_luns);
6534 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04006535 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05006536 return;
6537}