blob: ea8d382bc2eb059099ec1873c083e2028387a35b [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 Smartd080abe2017-02-12 13:52:39 -08004 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “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 Smart80cc0042017-06-01 21:06:56 -0700151 struct lpfc_nodelist *ndlp;
James Smart895427b2017-02-12 13:52:30 -0800152 struct nvme_fc_remote_port *nrport;
James Smart2cee7802017-06-01 21:07:02 -0700153 uint64_t data1, data2, data3, tot;
James Smart895427b2017-02-12 13:52:30 -0800154 char *statep;
155 int len = 0;
156
157 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
158 len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n");
159 return len;
160 }
James Smartf358dd02017-02-12 13:52:34 -0800161 if (phba->nvmet_support) {
162 if (!phba->targetport) {
163 len = snprintf(buf, PAGE_SIZE,
164 "NVME Target: x%llx is not allocated\n",
165 wwn_to_u64(vport->fc_portname.u.wwn));
166 return len;
167 }
168 /* Port state is only one of two values for now. */
169 if (phba->targetport->port_id)
170 statep = "REGISTERED";
171 else
172 statep = "INIT";
173 len += snprintf(buf + len, PAGE_SIZE - len,
James Smartb4fd6812017-06-15 22:56:42 -0700174 "NVME Target Enabled State %s\n",
James Smartf358dd02017-02-12 13:52:34 -0800175 statep);
176 len += snprintf(buf + len, PAGE_SIZE - len,
177 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
178 "NVME Target: lpfc",
179 phba->brd_no,
180 wwn_to_u64(vport->fc_portname.u.wwn),
181 wwn_to_u64(vport->fc_nodename.u.wwn),
182 phba->targetport->port_id);
183
Maurizio Lombardiea98ab32017-04-18 11:55:51 +0200184 len += snprintf(buf + len, PAGE_SIZE - len,
James Smartf358dd02017-02-12 13:52:34 -0800185 "\nNVME Target: Statistics\n");
186 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
187 len += snprintf(buf+len, PAGE_SIZE-len,
188 "LS: Rcv %08x Drop %08x Abort %08x\n",
189 atomic_read(&tgtp->rcv_ls_req_in),
190 atomic_read(&tgtp->rcv_ls_req_drop),
191 atomic_read(&tgtp->xmt_ls_abort));
192 if (atomic_read(&tgtp->rcv_ls_req_in) !=
193 atomic_read(&tgtp->rcv_ls_req_out)) {
194 len += snprintf(buf+len, PAGE_SIZE-len,
195 "Rcv LS: in %08x != out %08x\n",
196 atomic_read(&tgtp->rcv_ls_req_in),
197 atomic_read(&tgtp->rcv_ls_req_out));
198 }
199
200 len += snprintf(buf+len, PAGE_SIZE-len,
201 "LS: Xmt %08x Drop %08x Cmpl %08x Err %08x\n",
202 atomic_read(&tgtp->xmt_ls_rsp),
203 atomic_read(&tgtp->xmt_ls_drop),
204 atomic_read(&tgtp->xmt_ls_rsp_cmpl),
205 atomic_read(&tgtp->xmt_ls_rsp_error));
206
207 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart50738422017-08-01 15:12:40 -0700208 "FCP: Rcv %08x Defer %08x Release %08x "
209 "Drop %08x\n",
James Smartf358dd02017-02-12 13:52:34 -0800210 atomic_read(&tgtp->rcv_fcp_cmd_in),
James Smart50738422017-08-01 15:12:40 -0700211 atomic_read(&tgtp->rcv_fcp_cmd_defer),
James Smart547077a2017-05-15 15:20:40 -0700212 atomic_read(&tgtp->xmt_fcp_release),
James Smartf358dd02017-02-12 13:52:34 -0800213 atomic_read(&tgtp->rcv_fcp_cmd_drop));
214
215 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
216 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
217 len += snprintf(buf+len, PAGE_SIZE-len,
218 "Rcv FCP: in %08x != out %08x\n",
219 atomic_read(&tgtp->rcv_fcp_cmd_in),
220 atomic_read(&tgtp->rcv_fcp_cmd_out));
221 }
222
223 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart547077a2017-05-15 15:20:40 -0700224 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
225 "drop %08x\n",
James Smartf358dd02017-02-12 13:52:34 -0800226 atomic_read(&tgtp->xmt_fcp_read),
227 atomic_read(&tgtp->xmt_fcp_read_rsp),
228 atomic_read(&tgtp->xmt_fcp_write),
James Smart547077a2017-05-15 15:20:40 -0700229 atomic_read(&tgtp->xmt_fcp_rsp),
James Smartf358dd02017-02-12 13:52:34 -0800230 atomic_read(&tgtp->xmt_fcp_drop));
231
232 len += snprintf(buf+len, PAGE_SIZE-len,
233 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
234 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
235 atomic_read(&tgtp->xmt_fcp_rsp_error),
236 atomic_read(&tgtp->xmt_fcp_rsp_drop));
237
238 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart547077a2017-05-15 15:20:40 -0700239 "ABORT: Xmt %08x Cmpl %08x\n",
240 atomic_read(&tgtp->xmt_fcp_abort),
241 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
242
243 len += snprintf(buf + len, PAGE_SIZE - len,
244 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
245 atomic_read(&tgtp->xmt_abort_sol),
246 atomic_read(&tgtp->xmt_abort_unsol),
James Smartf358dd02017-02-12 13:52:34 -0800247 atomic_read(&tgtp->xmt_abort_rsp),
James Smart547077a2017-05-15 15:20:40 -0700248 atomic_read(&tgtp->xmt_abort_rsp_error));
James Smartf358dd02017-02-12 13:52:34 -0800249
Dick Kennedy66d7ce92017-08-23 16:55:42 -0700250 /* Calculate outstanding IOs */
251 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
252 tot += atomic_read(&tgtp->xmt_fcp_release);
253 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
James Smart2cee7802017-06-01 21:07:02 -0700254
James Smarta8cf5df2017-05-15 15:20:46 -0700255 len += snprintf(buf + len, PAGE_SIZE - len,
James Smart2cee7802017-06-01 21:07:02 -0700256 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
257 "CTX Outstanding %08llx\n",
James Smart966bb5b2017-06-15 22:56:45 -0700258 phba->sli4_hba.nvmet_xri_cnt,
James Smarta8cf5df2017-05-15 15:20:46 -0700259 phba->sli4_hba.nvmet_io_wait_cnt,
James Smart2cee7802017-06-01 21:07:02 -0700260 phba->sli4_hba.nvmet_io_wait_total,
261 tot);
James Smarta8cf5df2017-05-15 15:20:46 -0700262
James Smartf358dd02017-02-12 13:52:34 -0800263 len += snprintf(buf+len, PAGE_SIZE-len, "\n");
264 return len;
265 }
James Smart895427b2017-02-12 13:52:30 -0800266
267 localport = vport->localport;
268 if (!localport) {
269 len = snprintf(buf, PAGE_SIZE,
270 "NVME Initiator x%llx is not allocated\n",
271 wwn_to_u64(vport->fc_portname.u.wwn));
272 return len;
273 }
274 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
275
276 spin_lock_irq(shost->host_lock);
James Smart895427b2017-02-12 13:52:30 -0800277
278 /* Port state is only one of two values for now. */
279 if (localport->port_id)
280 statep = "ONLINE";
281 else
282 statep = "UNKNOWN ";
283
284 len += snprintf(buf + len, PAGE_SIZE - len,
285 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
286 "NVME LPORT lpfc",
287 phba->brd_no,
288 wwn_to_u64(vport->fc_portname.u.wwn),
289 wwn_to_u64(vport->fc_nodename.u.wwn),
290 localport->port_id, statep);
291
James Smart80cc0042017-06-01 21:06:56 -0700292 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
293 if (!ndlp->nrport)
294 continue;
295
James Smart895427b2017-02-12 13:52:30 -0800296 /* local short-hand pointer. */
James Smart80cc0042017-06-01 21:06:56 -0700297 nrport = ndlp->nrport->remoteport;
James Smart895427b2017-02-12 13:52:30 -0800298
299 /* Port state is only one of two values for now. */
300 switch (nrport->port_state) {
301 case FC_OBJSTATE_ONLINE:
302 statep = "ONLINE";
303 break;
304 case FC_OBJSTATE_UNKNOWN:
305 statep = "UNKNOWN ";
306 break;
307 default:
308 statep = "UNSUPPORTED";
309 break;
310 }
311
312 /* Tab in to show lport ownership. */
313 len += snprintf(buf + len, PAGE_SIZE - len,
314 "NVME RPORT ");
315 if (phba->brd_no >= 10)
316 len += snprintf(buf + len, PAGE_SIZE - len, " ");
317
318 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ",
319 nrport->port_name);
320 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ",
321 nrport->node_name);
322 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ",
323 nrport->port_id);
324
James Smart7d790f02017-06-01 21:06:57 -0700325 /* An NVME rport can have multiple roles. */
326 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
James Smart895427b2017-02-12 13:52:30 -0800327 len += snprintf(buf + len, PAGE_SIZE - len,
328 "INITIATOR ");
James Smart7d790f02017-06-01 21:06:57 -0700329 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
James Smart895427b2017-02-12 13:52:30 -0800330 len += snprintf(buf + len, PAGE_SIZE - len,
331 "TARGET ");
James Smart7d790f02017-06-01 21:06:57 -0700332 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
James Smart895427b2017-02-12 13:52:30 -0800333 len += snprintf(buf + len, PAGE_SIZE - len,
James Smart7d790f02017-06-01 21:06:57 -0700334 "DISCSRVC ");
335 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
336 FC_PORT_ROLE_NVME_TARGET |
337 FC_PORT_ROLE_NVME_DISCOVERY))
James Smart895427b2017-02-12 13:52:30 -0800338 len += snprintf(buf + len, PAGE_SIZE - len,
James Smart7d790f02017-06-01 21:06:57 -0700339 "UNKNOWN ROLE x%x",
James Smart895427b2017-02-12 13:52:30 -0800340 nrport->port_role);
James Smart7d790f02017-06-01 21:06:57 -0700341
James Smart895427b2017-02-12 13:52:30 -0800342 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep);
343 /* Terminate the string. */
344 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
345 }
346 spin_unlock_irq(shost->host_lock);
347
Maurizio Lombardiea98ab32017-04-18 11:55:51 +0200348 len += snprintf(buf + len, PAGE_SIZE - len, "\nNVME Statistics\n");
James Smart895427b2017-02-12 13:52:30 -0800349 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart2cee7802017-06-01 21:07:02 -0700350 "LS: Xmt %016x Cmpl %016x\n",
351 atomic_read(&phba->fc4NvmeLsRequests),
352 atomic_read(&phba->fc4NvmeLsCmpls));
James Smart895427b2017-02-12 13:52:30 -0800353
James Smart2cee7802017-06-01 21:07:02 -0700354 tot = atomic_read(&phba->fc4NvmeIoCmpls);
355 data1 = atomic_read(&phba->fc4NvmeInputRequests);
356 data2 = atomic_read(&phba->fc4NvmeOutputRequests);
357 data3 = atomic_read(&phba->fc4NvmeControlRequests);
James Smart895427b2017-02-12 13:52:30 -0800358 len += snprintf(buf+len, PAGE_SIZE-len,
359 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
James Smart2cee7802017-06-01 21:07:02 -0700360 data1, data2, data3);
James Smart895427b2017-02-12 13:52:30 -0800361
362 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart2cee7802017-06-01 21:07:02 -0700363 " Cmpl %016llx Outstanding %016llx\n",
364 tot, (data1 + data2 + data3) - tot);
James Smart895427b2017-02-12 13:52:30 -0800365 return len;
366}
367
368static ssize_t
James Smart81301a92008-12-04 22:39:46 -0500369lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
370 char *buf)
371{
372 struct Scsi_Host *shost = class_to_shost(dev);
373 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
374 struct lpfc_hba *phba = vport->phba;
375
376 if (phba->cfg_enable_bg)
377 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
378 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
379 else
380 return snprintf(buf, PAGE_SIZE,
381 "BlockGuard Not Supported\n");
382 else
383 return snprintf(buf, PAGE_SIZE,
384 "BlockGuard Disabled\n");
385}
386
387static ssize_t
388lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
389 char *buf)
390{
391 struct Scsi_Host *shost = class_to_shost(dev);
392 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
393 struct lpfc_hba *phba = vport->phba;
394
James Smart87b5c322008-12-16 10:34:09 -0500395 return snprintf(buf, PAGE_SIZE, "%llu\n",
396 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500397}
398
399static ssize_t
400lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
401 char *buf)
402{
403 struct Scsi_Host *shost = class_to_shost(dev);
404 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
405 struct lpfc_hba *phba = vport->phba;
406
James Smart87b5c322008-12-16 10:34:09 -0500407 return snprintf(buf, PAGE_SIZE, "%llu\n",
408 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500409}
410
411static ssize_t
412lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
413 char *buf)
414{
415 struct Scsi_Host *shost = class_to_shost(dev);
416 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
417 struct lpfc_hba *phba = vport->phba;
418
James Smart87b5c322008-12-16 10:34:09 -0500419 return snprintf(buf, PAGE_SIZE, "%llu\n",
420 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500421}
422
James Smarte59058c2008-08-24 21:49:00 -0400423/**
James Smart3621a712009-04-06 18:47:14 -0400424 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400425 * @dev: class converted to a Scsi_host structure.
426 * @attr: device attribute, not used.
427 * @buf: on return contains the formatted text from lpfc_info().
428 *
429 * Returns: size of formatted string.
430 **/
dea31012005-04-17 16:05:31 -0500431static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100432lpfc_info_show(struct device *dev, struct device_attribute *attr,
433 char *buf)
dea31012005-04-17 16:05:31 -0500434{
Tony Jonesee959b02008-02-22 00:13:36 +0100435 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500436
dea31012005-04-17 16:05:31 -0500437 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
438}
439
James Smarte59058c2008-08-24 21:49:00 -0400440/**
James Smart3621a712009-04-06 18:47:14 -0400441 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400442 * @dev: class converted to a Scsi_host structure.
443 * @attr: device attribute, not used.
444 * @buf: on return contains the formatted text serial number.
445 *
446 * Returns: size of formatted string.
447 **/
dea31012005-04-17 16:05:31 -0500448static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100449lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
450 char *buf)
dea31012005-04-17 16:05:31 -0500451{
Tony Jonesee959b02008-02-22 00:13:36 +0100452 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500453 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
454 struct lpfc_hba *phba = vport->phba;
455
dea31012005-04-17 16:05:31 -0500456 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
457}
458
James Smarte59058c2008-08-24 21:49:00 -0400459/**
James Smart3621a712009-04-06 18:47:14 -0400460 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400461 * @dev: class converted to a Scsi_host structure.
462 * @attr: device attribute, not used.
463 * @buf: on return contains the formatted support level.
464 *
465 * Description:
466 * Returns a number indicating the temperature sensor level currently
467 * supported, zero or one in ascii.
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_temp_sensor_show(struct device *dev, struct device_attribute *attr,
473 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400474{
Tony Jonesee959b02008-02-22 00:13:36 +0100475 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400476 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
477 struct lpfc_hba *phba = vport->phba;
478 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
479}
480
James Smarte59058c2008-08-24 21:49:00 -0400481/**
James Smart3621a712009-04-06 18:47:14 -0400482 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400483 * @dev: class converted to a Scsi_host structure.
484 * @attr: device attribute, not used.
485 * @buf: on return contains the scsi vpd model description.
486 *
487 * Returns: size of formatted string.
488 **/
James Smart57127f12007-10-27 13:37:05 -0400489static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100490lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
491 char *buf)
dea31012005-04-17 16:05:31 -0500492{
Tony Jonesee959b02008-02-22 00:13:36 +0100493 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500494 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
495 struct lpfc_hba *phba = vport->phba;
496
dea31012005-04-17 16:05:31 -0500497 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
498}
499
James Smarte59058c2008-08-24 21:49:00 -0400500/**
James Smart3621a712009-04-06 18:47:14 -0400501 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400502 * @dev: class converted to a Scsi_host structure.
503 * @attr: device attribute, not used.
504 * @buf: on return contains the scsi vpd model name.
505 *
506 * Returns: size of formatted string.
507 **/
dea31012005-04-17 16:05:31 -0500508static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100509lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
510 char *buf)
dea31012005-04-17 16:05:31 -0500511{
Tony Jonesee959b02008-02-22 00:13:36 +0100512 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500513 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
514 struct lpfc_hba *phba = vport->phba;
515
dea31012005-04-17 16:05:31 -0500516 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
517}
518
James Smarte59058c2008-08-24 21:49:00 -0400519/**
James Smart3621a712009-04-06 18:47:14 -0400520 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400521 * @dev: class converted to a Scsi_host structure.
522 * @attr: device attribute, not used.
523 * @buf: on return contains the scsi vpd program type.
524 *
525 * Returns: size of formatted string.
526 **/
dea31012005-04-17 16:05:31 -0500527static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100528lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
529 char *buf)
dea31012005-04-17 16:05:31 -0500530{
Tony Jonesee959b02008-02-22 00:13:36 +0100531 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500532 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
533 struct lpfc_hba *phba = vport->phba;
534
dea31012005-04-17 16:05:31 -0500535 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
536}
537
James Smarte59058c2008-08-24 21:49:00 -0400538/**
James Smart3621a712009-04-06 18:47:14 -0400539 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400540 * @dev: class converted to a Scsi_host structure.
541 * @attr: device attribute, not used.
542 * @buf: on return contains the Menlo Maintenance sli flag.
543 *
544 * Returns: size of formatted string.
545 **/
546static ssize_t
547lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
548{
549 struct Scsi_Host *shost = class_to_shost(dev);
550 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
551 struct lpfc_hba *phba = vport->phba;
552
553 return snprintf(buf, PAGE_SIZE, "%d\n",
554 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
555}
556
557/**
James Smart3621a712009-04-06 18:47:14 -0400558 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400559 * @dev: class converted to a Scsi_host structure.
560 * @attr: device attribute, not used.
561 * @buf: on return contains scsi vpd program type.
562 *
563 * Returns: size of formatted string.
564 **/
dea31012005-04-17 16:05:31 -0500565static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100566lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
567 char *buf)
dea31012005-04-17 16:05:31 -0500568{
Tony Jonesee959b02008-02-22 00:13:36 +0100569 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500570 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
571 struct lpfc_hba *phba = vport->phba;
572
dea31012005-04-17 16:05:31 -0500573 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
574}
575
James Smarte59058c2008-08-24 21:49:00 -0400576/**
James Smart3621a712009-04-06 18:47:14 -0400577 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400578 * @dev: class converted to a Scsi_host structure.
579 * @attr: device attribute, not used.
580 * @buf: on return contains the scsi vpd program type.
581 *
582 * Returns: size of formatted string.
583 **/
dea31012005-04-17 16:05:31 -0500584static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100585lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
586 char *buf)
dea31012005-04-17 16:05:31 -0500587{
Tony Jonesee959b02008-02-22 00:13:36 +0100588 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500589 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
590 struct lpfc_hba *phba = vport->phba;
James Smart026abb82011-12-13 13:20:45 -0500591 uint32_t if_type;
592 uint8_t sli_family;
James Smart6b5151f2012-01-18 16:24:06 -0500593 char fwrev[FW_REV_STR_SIZE];
James Smart026abb82011-12-13 13:20:45 -0500594 int len;
James Smart2e0fef82007-06-17 19:56:36 -0500595
dea31012005-04-17 16:05:31 -0500596 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart026abb82011-12-13 13:20:45 -0500597 if_type = phba->sli4_hba.pc_sli4_params.if_type;
598 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
599
600 if (phba->sli_rev < LPFC_SLI_REV4)
601 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
602 fwrev, phba->sli_rev);
603 else
604 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
605 fwrev, phba->sli_rev, if_type, sli_family);
606
607 return len;
dea31012005-04-17 16:05:31 -0500608}
609
James Smarte59058c2008-08-24 21:49:00 -0400610/**
James Smart3621a712009-04-06 18:47:14 -0400611 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400612 * @dev: class converted to a Scsi_host structure.
613 * @attr: device attribute, not used.
614 * @buf: on return contains the scsi vpd program type.
615 *
616 * Returns: size of formatted string.
617 **/
dea31012005-04-17 16:05:31 -0500618static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100619lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500620{
621 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100622 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500623 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
624 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500625 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500626
dea31012005-04-17 16:05:31 -0500627 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
628 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
629}
James Smarte59058c2008-08-24 21:49:00 -0400630
631/**
James Smart3621a712009-04-06 18:47:14 -0400632 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400633 * @dev: class converted to a Scsi_host structure.
634 * @attr: device attribute, not used.
635 * @buf: on return contains the ROM and FCode ascii strings.
636 *
637 * Returns: size of formatted string.
638 **/
dea31012005-04-17 16:05:31 -0500639static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100640lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
641 char *buf)
dea31012005-04-17 16:05:31 -0500642{
Tony Jonesee959b02008-02-22 00:13:36 +0100643 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500644 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
645 struct lpfc_hba *phba = vport->phba;
James Smarta0683bf2015-04-07 15:07:16 -0400646 char fwrev[FW_REV_STR_SIZE];
James Smart2e0fef82007-06-17 19:56:36 -0500647
James Smarta0683bf2015-04-07 15:07:16 -0400648 if (phba->sli_rev < LPFC_SLI_REV4)
649 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
650
651 lpfc_decode_firmware_rev(phba, fwrev, 1);
652 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
dea31012005-04-17 16:05:31 -0500653}
James Smarte59058c2008-08-24 21:49:00 -0400654
655/**
James Smart3621a712009-04-06 18:47:14 -0400656 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400657 * @dev: class converted to a Scsi_host structure.
658 * @attr: device attribute, not used.
659 * @buf: on return contains text describing the state of the link.
660 *
661 * Notes:
662 * The switch statement has no default so zero will be returned.
663 *
664 * Returns: size of formatted string.
665 **/
dea31012005-04-17 16:05:31 -0500666static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100667lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
668 char *buf)
dea31012005-04-17 16:05:31 -0500669{
Tony Jonesee959b02008-02-22 00:13:36 +0100670 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500671 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
672 struct lpfc_hba *phba = vport->phba;
673 int len = 0;
674
675 switch (phba->link_state) {
676 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500677 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500678 case LPFC_INIT_START:
679 case LPFC_INIT_MBX_CMDS:
680 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500681 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400682 if (phba->hba_flag & LINK_DISABLED)
683 len += snprintf(buf + len, PAGE_SIZE-len,
684 "Link Down - User disabled\n");
685 else
686 len += snprintf(buf + len, PAGE_SIZE-len,
687 "Link Down\n");
dea31012005-04-17 16:05:31 -0500688 break;
689 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500690 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500691 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400692 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500693
694 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500695 case LPFC_LOCAL_CFG_LINK:
696 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500697 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500698 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500699 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500700 case LPFC_FLOGI:
701 case LPFC_FABRIC_CFG_LINK:
702 case LPFC_NS_REG:
703 case LPFC_NS_QRY:
704 case LPFC_BUILD_DISC_LIST:
705 case LPFC_DISC_AUTH:
706 len += snprintf(buf + len, PAGE_SIZE - len,
707 "Discovery\n");
708 break;
709 case LPFC_VPORT_READY:
710 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
711 break;
712
James Smart92d7f7b2007-06-17 19:56:38 -0500713 case LPFC_VPORT_FAILED:
714 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
715 break;
716
717 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500718 len += snprintf(buf + len, PAGE_SIZE - len,
719 "Unknown\n");
720 break;
721 }
James Smart84774a42008-08-24 21:50:06 -0400722 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
723 len += snprintf(buf + len, PAGE_SIZE-len,
724 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500725 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500726 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500727 len += snprintf(buf + len, PAGE_SIZE-len,
728 " Public Loop\n");
729 else
730 len += snprintf(buf + len, PAGE_SIZE-len,
731 " Private Loop\n");
732 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500733 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500734 len += snprintf(buf + len, PAGE_SIZE-len,
735 " Fabric\n");
736 else
737 len += snprintf(buf + len, PAGE_SIZE-len,
738 " Point-2-Point\n");
739 }
740 }
James Smart2e0fef82007-06-17 19:56:36 -0500741
dea31012005-04-17 16:05:31 -0500742 return len;
743}
744
James Smarte59058c2008-08-24 21:49:00 -0400745/**
James Smart026abb82011-12-13 13:20:45 -0500746 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
747 * @dev: class unused variable.
748 * @attr: device attribute, not used.
749 * @buf: on return contains the module description text.
750 *
751 * Returns: size of formatted string.
752 **/
753static ssize_t
754lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
755 char *buf)
756{
757 struct Scsi_Host *shost = class_to_shost(dev);
758 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
759 struct lpfc_hba *phba = vport->phba;
760
761 if (phba->sli_rev < LPFC_SLI_REV4)
762 return snprintf(buf, PAGE_SIZE, "fc\n");
763
764 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
765 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
766 return snprintf(buf, PAGE_SIZE, "fcoe\n");
767 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
768 return snprintf(buf, PAGE_SIZE, "fc\n");
769 }
770 return snprintf(buf, PAGE_SIZE, "unknown\n");
771}
772
773/**
James Smart1ba981f2014-02-20 09:56:45 -0500774 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
775 * (OAS) is supported.
776 * @dev: class unused variable.
777 * @attr: device attribute, not used.
778 * @buf: on return contains the module description text.
779 *
780 * Returns: size of formatted string.
781 **/
782static ssize_t
783lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
784 char *buf)
785{
786 struct Scsi_Host *shost = class_to_shost(dev);
787 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
788 struct lpfc_hba *phba = vport->phba;
789
790 return snprintf(buf, PAGE_SIZE, "%d\n",
791 phba->sli4_hba.pc_sli4_params.oas_supported);
792}
793
794/**
James Smart84d1b002010-02-12 14:42:33 -0500795 * lpfc_link_state_store - Transition the link_state on an HBA port
796 * @dev: class device that is converted into a Scsi_host.
797 * @attr: device attribute, not used.
798 * @buf: one or more lpfc_polling_flags values.
799 * @count: not used.
800 *
801 * Returns:
802 * -EINVAL if the buffer is not "up" or "down"
803 * return from link state change function if non-zero
804 * length of the buf on success
805 **/
806static ssize_t
807lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
808 const char *buf, size_t count)
809{
810 struct Scsi_Host *shost = class_to_shost(dev);
811 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
812 struct lpfc_hba *phba = vport->phba;
813
814 int status = -EINVAL;
815
816 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
817 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400818 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500819 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
820 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400821 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500822
823 if (status == 0)
824 return strlen(buf);
825 else
826 return status;
827}
828
829/**
James Smart3621a712009-04-06 18:47:14 -0400830 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400831 * @dev: class device that is converted into a Scsi_host.
832 * @attr: device attribute, not used.
833 * @buf: on return contains the sum of fc mapped and unmapped.
834 *
835 * Description:
836 * Returns the ascii text number of the sum of the fc mapped and unmapped
837 * vport counts.
838 *
839 * Returns: size of formatted string.
840 **/
dea31012005-04-17 16:05:31 -0500841static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100842lpfc_num_discovered_ports_show(struct device *dev,
843 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500844{
Tony Jonesee959b02008-02-22 00:13:36 +0100845 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500846 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
847
848 return snprintf(buf, PAGE_SIZE, "%d\n",
849 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500850}
851
James Smarte59058c2008-08-24 21:49:00 -0400852/**
James Smart3621a712009-04-06 18:47:14 -0400853 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400854 * @shost: Scsi_Host pointer.
855 *
856 * Description:
857 * Bring the link down gracefully then re-init the link. The firmware will
858 * re-init the fiber channel interface as required. Does not issue a LIP.
859 *
860 * Returns:
861 * -EPERM port offline or management commands are being blocked
862 * -ENOMEM cannot allocate memory for the mailbox command
863 * -EIO error sending the mailbox command
864 * zero for success
865 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700866static int
James Smart2e0fef82007-06-17 19:56:36 -0500867lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500868{
James Smart2e0fef82007-06-17 19:56:36 -0500869 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
870 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500871 LPFC_MBOXQ_t *pmboxq;
872 int mbxstatus = MBXERR_ERROR;
873
James Smart2e0fef82007-06-17 19:56:36 -0500874 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500875 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500876 return -EPERM;
877
878 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
879
880 if (!pmboxq)
881 return -ENOMEM;
882
883 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400884 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
885 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400886
James Smart33ccf8d2006-08-17 11:57:58 -0400887 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500888
James Smart04c68492009-05-22 14:52:52 -0400889 if ((mbxstatus == MBX_SUCCESS) &&
890 (pmboxq->u.mb.mbxStatus == 0 ||
891 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400892 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
893 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
894 phba->cfg_link_speed);
895 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
896 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400897 if ((mbxstatus == MBX_SUCCESS) &&
898 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
899 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
900 "2859 SLI authentication is required "
901 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400902 }
903
James Smart5b8bd0c2007-04-25 09:52:49 -0400904 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500905 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400906 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500907
908 if (mbxstatus == MBXERR_ERROR)
909 return -EIO;
910
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700911 return 0;
dea31012005-04-17 16:05:31 -0500912}
913
James Smart895427b2017-02-12 13:52:30 -0800914int
915lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
916{
917 int cnt = 0;
918
919 spin_lock_irq(lock);
920 while (!list_empty(q)) {
921 spin_unlock_irq(lock);
922 msleep(20);
923 if (cnt++ > 250) { /* 5 secs */
924 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
925 "0466 %s %s\n",
926 "Outstanding IO when ",
927 "bringing Adapter offline\n");
928 return 0;
929 }
930 spin_lock_irq(lock);
931 }
932 spin_unlock_irq(lock);
933 return 1;
934}
935
James Smarte59058c2008-08-24 21:49:00 -0400936/**
James Smart3621a712009-04-06 18:47:14 -0400937 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400938 * @phba: lpfc_hba pointer.
939 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
940 *
941 * Notes:
942 * Assumes any error from lpfc_do_offline() will be negative.
943 * Can wait up to 5 seconds for the port ring buffers count
944 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400945 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400946 *
947 * Returns:
948 * -EIO error posting the event
949 * zero for success
950 **/
James Smart40496f02006-07-06 15:50:22 -0400951static int
James Smart46fa3112007-04-25 09:51:45 -0400952lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
953{
954 struct completion online_compl;
James Smart895427b2017-02-12 13:52:30 -0800955 struct lpfc_queue *qp = NULL;
James Smart46fa3112007-04-25 09:51:45 -0400956 struct lpfc_sli_ring *pring;
957 struct lpfc_sli *psli;
958 int status = 0;
James Smart46fa3112007-04-25 09:51:45 -0400959 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500960 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400961
962 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500963 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400964 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500965 if (rc == 0)
966 return -ENOMEM;
967
James Smart46fa3112007-04-25 09:51:45 -0400968 wait_for_completion(&online_compl);
969
970 if (status != 0)
971 return -EIO;
972
973 psli = &phba->sli;
974
James Smart09372822008-01-11 01:52:54 -0500975 /* Wait a little for things to settle down, but not
976 * long enough for dev loss timeout to expire.
977 */
James Smart895427b2017-02-12 13:52:30 -0800978 if (phba->sli_rev != LPFC_SLI_REV4) {
979 for (i = 0; i < psli->num_rings; i++) {
980 pring = &psli->sli3_ring[i];
981 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
982 &phba->hbalock))
983 goto out;
984 }
985 } else {
986 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
987 pring = qp->pring;
988 if (!pring)
989 continue;
990 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
991 &pring->ring_lock))
992 goto out;
James Smart46fa3112007-04-25 09:51:45 -0400993 }
994 }
James Smart895427b2017-02-12 13:52:30 -0800995out:
James Smart46fa3112007-04-25 09:51:45 -0400996 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500997 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
998 if (rc == 0)
999 return -ENOMEM;
1000
James Smart46fa3112007-04-25 09:51:45 -04001001 wait_for_completion(&online_compl);
1002
1003 if (status != 0)
1004 return -EIO;
1005
1006 return 0;
1007}
1008
James Smarte59058c2008-08-24 21:49:00 -04001009/**
James Smart3621a712009-04-06 18:47:14 -04001010 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -04001011 * @phba: lpfc_hba pointer.
1012 *
1013 * Description:
1014 * If the port is configured to allow a reset then the hba is brought
1015 * offline then online.
1016 *
1017 * Notes:
1018 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -05001019 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -04001020 *
1021 * Returns:
1022 * lpfc_do_offline() return code if not zero
1023 * -EIO reset not configured or error posting the event
1024 * zero for success
1025 **/
James Smart7f860592011-03-11 16:05:52 -05001026int
James Smart40496f02006-07-06 15:50:22 -04001027lpfc_selective_reset(struct lpfc_hba *phba)
1028{
1029 struct completion online_compl;
1030 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001031 int rc;
James Smart40496f02006-07-06 15:50:22 -04001032
James Smart71157c92013-07-15 18:34:36 -04001033 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001034 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -05001035
James Smart71157c92013-07-15 18:34:36 -04001036 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1037 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -04001038
James Smart71157c92013-07-15 18:34:36 -04001039 if (status != 0)
1040 return status;
1041 }
James Smart40496f02006-07-06 15:50:22 -04001042
1043 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001044 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -04001045 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -05001046 if (rc == 0)
1047 return -ENOMEM;
1048
James Smart40496f02006-07-06 15:50:22 -04001049 wait_for_completion(&online_compl);
1050
1051 if (status != 0)
1052 return -EIO;
1053
1054 return 0;
1055}
1056
James Smarte59058c2008-08-24 21:49:00 -04001057/**
James Smart3621a712009-04-06 18:47:14 -04001058 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -04001059 * @dev: class device that is converted into a Scsi_host.
1060 * @attr: device attribute, not used.
1061 * @buf: containing the string "selective".
1062 * @count: unused variable.
1063 *
1064 * Description:
1065 * If the buf contains the string "selective" then lpfc_selective_reset()
1066 * is called to perform the reset.
1067 *
1068 * Notes:
1069 * Assumes any error from lpfc_selective_reset() will be negative.
1070 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001071 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -04001072 *
1073 * Returns:
1074 * -EINVAL if the buffer does not contain the string "selective"
1075 * length of buf if lpfc-selective_reset() if the call succeeds
1076 * return value of lpfc_selective_reset() if the call fails
1077**/
James Smart40496f02006-07-06 15:50:22 -04001078static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001079lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1080 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -04001081{
Tony Jonesee959b02008-02-22 00:13:36 +01001082 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001083 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1084 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -04001085 int status = -EINVAL;
1086
James Smart73d91e52011-10-10 21:32:10 -04001087 if (!phba->cfg_enable_hba_reset)
1088 return -EACCES;
1089
James Smart40496f02006-07-06 15:50:22 -04001090 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -05001091 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -04001092
1093 if (status == 0)
1094 return strlen(buf);
1095 else
1096 return status;
1097}
1098
James Smarte59058c2008-08-24 21:49:00 -04001099/**
James Smart88a2cfb2011-07-22 18:36:33 -04001100 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1101 * @phba: lpfc_hba pointer.
1102 *
1103 * Description:
1104 * SLI4 interface type-2 device to wait on the sliport status register for
1105 * the readyness after performing a firmware reset.
1106 *
1107 * Returns:
Masanari Iida0b1587b2013-07-17 04:37:44 +09001108 * zero for success, -EPERM when port does not have privilege to perform the
James Smart026abb82011-12-13 13:20:45 -05001109 * reset, -EIO when port timeout from recovering from the reset.
1110 *
1111 * Note:
1112 * As the caller will interpret the return code by value, be careful in making
1113 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -04001114 **/
James Smart73d91e52011-10-10 21:32:10 -04001115int
James Smart88a2cfb2011-07-22 18:36:33 -04001116lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1117{
James Smartf7a919b2011-08-21 21:49:16 -04001118 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -04001119 int i;
1120
James Smartf7a919b2011-08-21 21:49:16 -04001121 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -04001122 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1123 &portstat_reg.word0);
1124
Masanari Iida0b1587b2013-07-17 04:37:44 +09001125 /* verify if privileged for the request operation */
James Smartf7a919b2011-08-21 21:49:16 -04001126 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1127 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1128 return -EPERM;
1129
James Smart88a2cfb2011-07-22 18:36:33 -04001130 /* wait for the SLI port firmware ready after firmware reset */
1131 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1132 msleep(10);
1133 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1134 &portstat_reg.word0);
1135 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1136 continue;
1137 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1138 continue;
1139 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1140 continue;
1141 break;
1142 }
1143
1144 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1145 return 0;
1146 else
1147 return -EIO;
1148}
1149
1150/**
James Smart52d52442011-05-24 11:42:45 -04001151 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -04001152 * @phba: lpfc_hba pointer.
1153 *
1154 * Description:
James Smart52d52442011-05-24 11:42:45 -04001155 * Request SLI4 interface type-2 device to perform a physical register set
1156 * access.
James Smartc0c11512011-05-24 11:41:34 -04001157 *
1158 * Returns:
1159 * zero for success
1160 **/
1161static ssize_t
James Smart52d52442011-05-24 11:42:45 -04001162lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -04001163{
1164 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -04001165 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -05001166 uint32_t before_fc_flag;
1167 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -04001168 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -05001169 int status = 0, rc = 0;
1170 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -04001171
1172 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001173 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -04001174
James Smart52d52442011-05-24 11:42:45 -04001175 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1176 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1177 LPFC_SLI_INTF_IF_TYPE_2))
1178 return -EPERM;
1179
James Smart026abb82011-12-13 13:20:45 -05001180 /* Keep state if we need to restore back */
1181 before_fc_flag = phba->pport->fc_flag;
1182 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1183
James Smartb76f2dc2011-07-22 18:37:42 -04001184 /* Disable SR-IOV virtual functions if enabled */
1185 if (phba->cfg_sriov_nr_virtfn) {
1186 pci_disable_sriov(pdev);
1187 phba->cfg_sriov_nr_virtfn = 0;
1188 }
James Smart229adb02013-04-17 20:16:51 -04001189
James Smart02936352014-04-04 13:52:12 -04001190 if (opcode == LPFC_FW_DUMP)
1191 phba->hba_flag |= HBA_FW_DUMP_OP;
1192
James Smartc0c11512011-05-24 11:41:34 -04001193 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1194
James Smart02936352014-04-04 13:52:12 -04001195 if (status != 0) {
1196 phba->hba_flag &= ~HBA_FW_DUMP_OP;
James Smartc0c11512011-05-24 11:41:34 -04001197 return status;
James Smart02936352014-04-04 13:52:12 -04001198 }
James Smartc0c11512011-05-24 11:41:34 -04001199
1200 /* wait for the device to be quiesced before firmware reset */
1201 msleep(100);
1202
1203 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1204 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -04001205
1206 if (opcode == LPFC_FW_DUMP)
1207 reg_val |= LPFC_FW_DUMP_REQUEST;
1208 else if (opcode == LPFC_FW_RESET)
1209 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1210 else if (opcode == LPFC_DV_RESET)
1211 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1212
James Smartc0c11512011-05-24 11:41:34 -04001213 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1214 LPFC_CTL_PDEV_CTL_OFFSET);
1215 /* flush */
1216 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1217
1218 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -04001219 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1220
James Smart026abb82011-12-13 13:20:45 -05001221 if (rc == -EPERM) {
Masanari Iida0b1587b2013-07-17 04:37:44 +09001222 /* no privilege for reset */
James Smart6b5151f2012-01-18 16:24:06 -05001223 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
Masanari Iida0b1587b2013-07-17 04:37:44 +09001224 "3150 No privilege to perform the requested "
James Smart6b5151f2012-01-18 16:24:06 -05001225 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -05001226 } else if (rc == -EIO) {
1227 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -05001228 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1229 "3153 Fail to perform the requested "
1230 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -04001231 return rc;
James Smart026abb82011-12-13 13:20:45 -05001232 }
1233
1234 /* keep the original port state */
1235 if (before_fc_flag & FC_OFFLINE_MODE)
1236 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001237
1238 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -05001239 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1240 LPFC_EVT_ONLINE);
1241 if (!job_posted)
1242 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001243
1244 wait_for_completion(&online_compl);
1245
James Smart026abb82011-12-13 13:20:45 -05001246out:
1247 /* in any case, restore the virtual functions enabled as before */
1248 if (sriov_nr_virtfn) {
1249 sriov_err =
1250 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1251 if (!sriov_err)
1252 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1253 }
James Smartc0c11512011-05-24 11:41:34 -04001254
James Smart026abb82011-12-13 13:20:45 -05001255 /* return proper error code */
1256 if (!rc) {
1257 if (!job_posted)
1258 rc = -ENOMEM;
1259 else if (status)
1260 rc = -EIO;
1261 }
1262 return rc;
James Smartc0c11512011-05-24 11:41:34 -04001263}
1264
1265/**
James Smart3621a712009-04-06 18:47:14 -04001266 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -04001267 * @dev: class device that is converted into a Scsi_host.
1268 * @attr: device attribute, not used.
1269 * @buf: on return contains the ascii number of nport events.
1270 *
1271 * Returns: size of formatted string.
1272 **/
dea31012005-04-17 16:05:31 -05001273static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001274lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1275 char *buf)
dea31012005-04-17 16:05:31 -05001276{
Tony Jonesee959b02008-02-22 00:13:36 +01001277 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001278 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1279 struct lpfc_hba *phba = vport->phba;
1280
dea31012005-04-17 16:05:31 -05001281 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1282}
1283
James Smarte59058c2008-08-24 21:49:00 -04001284/**
James Smart3621a712009-04-06 18:47:14 -04001285 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -04001286 * @dev: class device that is converted into a Scsi_host.
1287 * @attr: device attribute, not used.
1288 * @buf: on return contains the state of the adapter.
1289 *
1290 * Returns: size of formatted string.
1291 **/
dea31012005-04-17 16:05:31 -05001292static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001293lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1294 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001295{
Tony Jonesee959b02008-02-22 00:13:36 +01001296 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001297 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1298 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001299 char * state;
1300
James Smart2e0fef82007-06-17 19:56:36 -05001301 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001302 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001303 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001304 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001305 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001306 state = "offline";
1307 else
1308 state = "online";
1309
1310 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1311}
1312
James Smarte59058c2008-08-24 21:49:00 -04001313/**
James Smart3621a712009-04-06 18:47:14 -04001314 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001315 * @dev: class device that is converted into a Scsi_host.
1316 * @attr: device attribute, not used.
1317 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1318 * @count: unused variable.
1319 *
1320 * Returns:
1321 * -EACCES if enable hba reset not enabled
1322 * -EINVAL if the buffer does not contain a valid string (see above)
1323 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1324 * buf length greater than zero indicates success
1325 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001326static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001327lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1328 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001329{
Tony Jonesee959b02008-02-22 00:13:36 +01001330 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001331 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1332 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001333 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001334 char *board_mode_str = NULL;
1335 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001336 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001337
James Smart026abb82011-12-13 13:20:45 -05001338 if (!phba->cfg_enable_hba_reset) {
1339 status = -EACCES;
1340 goto board_mode_out;
1341 }
James Smart88a2cfb2011-07-22 18:36:33 -04001342
1343 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001344 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001345
Jamie Wellnitz41415862006-02-28 19:25:27 -05001346 init_completion(&online_compl);
1347
James Smart46fa3112007-04-25 09:51:45 -04001348 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001349 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001350 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001351 if (rc == 0) {
1352 status = -ENOMEM;
1353 goto board_mode_out;
1354 }
James Smart46fa3112007-04-25 09:51:45 -04001355 wait_for_completion(&online_compl);
James Smart522dcee2017-06-01 21:07:03 -07001356 if (status)
1357 status = -EIO;
James Smart46fa3112007-04-25 09:51:45 -04001358 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1359 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001360 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001361 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001362 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001363 else
1364 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001365 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001366 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001367 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001368 else
1369 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001370 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001371 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1372 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1373 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1374 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1375 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001376 else
James Smart026abb82011-12-13 13:20:45 -05001377 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001378
James Smart026abb82011-12-13 13:20:45 -05001379board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001380 if (!status)
1381 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001382 else {
1383 board_mode_str = strchr(buf, '\n');
1384 if (board_mode_str)
1385 *board_mode_str = '\0';
1386 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1387 "3097 Failed \"%s\", status(%d), "
1388 "fc_flag(x%x)\n",
1389 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001390 return status;
James Smart026abb82011-12-13 13:20:45 -05001391 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001392}
1393
James Smarte59058c2008-08-24 21:49:00 -04001394/**
James Smart3621a712009-04-06 18:47:14 -04001395 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001396 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001397 * @mxri: max xri count.
1398 * @axri: available xri count.
1399 * @mrpi: max rpi count.
1400 * @arpi: available rpi count.
1401 * @mvpi: max vpi count.
1402 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001403 *
1404 * Description:
1405 * If an integer pointer for an count is not null then the value for the
1406 * count is returned.
1407 *
1408 * Returns:
1409 * zero on error
1410 * one for success
1411 **/
James Smart311464e2007-08-02 11:10:37 -04001412static int
James Smart858c9f62007-06-17 19:56:39 -05001413lpfc_get_hba_info(struct lpfc_hba *phba,
1414 uint32_t *mxri, uint32_t *axri,
1415 uint32_t *mrpi, uint32_t *arpi,
1416 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001417{
James Smart04c68492009-05-22 14:52:52 -04001418 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001419 LPFC_MBOXQ_t *pmboxq;
1420 MAILBOX_t *pmb;
1421 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001422 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001423
1424 /*
1425 * prevent udev from issuing mailbox commands until the port is
1426 * configured.
1427 */
1428 if (phba->link_state < LPFC_LINK_DOWN ||
1429 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001430 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001431 return 0;
1432
1433 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1434 return 0;
1435
1436 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1437 if (!pmboxq)
1438 return 0;
1439 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1440
James Smart04c68492009-05-22 14:52:52 -04001441 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001442 pmb->mbxCommand = MBX_READ_CONFIG;
1443 pmb->mbxOwner = OWN_HOST;
1444 pmboxq->context1 = NULL;
1445
James Smart75baf692010-06-08 18:31:21 -04001446 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001447 rc = MBX_NOT_FINISHED;
1448 else
1449 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1450
1451 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001452 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001453 mempool_free(pmboxq, phba->mbox_mem_pool);
1454 return 0;
1455 }
1456
James Smartda0436e2009-05-22 14:51:39 -04001457 if (phba->sli_rev == LPFC_SLI_REV4) {
1458 rd_config = &pmboxq->u.mqe.un.rd_config;
1459 if (mrpi)
1460 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1461 if (arpi)
1462 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1463 phba->sli4_hba.max_cfg_param.rpi_used;
1464 if (mxri)
1465 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1466 if (axri)
1467 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1468 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001469
1470 /* Account for differences with SLI-3. Get vpi count from
1471 * mailbox data and subtract one for max vpi value.
1472 */
1473 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1474 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1475
James Smartda0436e2009-05-22 14:51:39 -04001476 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001477 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001478 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001479 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001480 } else {
1481 if (mrpi)
1482 *mrpi = pmb->un.varRdConfig.max_rpi;
1483 if (arpi)
1484 *arpi = pmb->un.varRdConfig.avail_rpi;
1485 if (mxri)
1486 *mxri = pmb->un.varRdConfig.max_xri;
1487 if (axri)
1488 *axri = pmb->un.varRdConfig.avail_xri;
1489 if (mvpi)
1490 *mvpi = pmb->un.varRdConfig.max_vpi;
1491 if (avpi)
1492 *avpi = pmb->un.varRdConfig.avail_vpi;
1493 }
James Smart92d7f7b2007-06-17 19:56:38 -05001494
1495 mempool_free(pmboxq, phba->mbox_mem_pool);
1496 return 1;
1497}
1498
James Smarte59058c2008-08-24 21:49:00 -04001499/**
James Smart3621a712009-04-06 18:47:14 -04001500 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001501 * @dev: class device that is converted into a Scsi_host.
1502 * @attr: device attribute, not used.
1503 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1504 *
1505 * Description:
1506 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1507 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1508 * to "Unknown" and the buffer length is returned, therefore the caller
1509 * must check for "Unknown" in the buffer to detect a failure.
1510 *
1511 * Returns: size of formatted string.
1512 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001513static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001514lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1515 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001516{
Tony Jonesee959b02008-02-22 00:13:36 +01001517 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001518 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1519 struct lpfc_hba *phba = vport->phba;
1520 uint32_t cnt;
1521
James Smart858c9f62007-06-17 19:56:39 -05001522 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001523 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1524 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1525}
1526
James Smarte59058c2008-08-24 21:49:00 -04001527/**
James Smart3621a712009-04-06 18:47:14 -04001528 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001529 * @dev: class device that is converted into a Scsi_host.
1530 * @attr: device attribute, not used.
1531 * @buf: containing the used rpi count in decimal or "Unknown".
1532 *
1533 * Description:
1534 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1535 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1536 * to "Unknown" and the buffer length is returned, therefore the caller
1537 * must check for "Unknown" in the buffer to detect a failure.
1538 *
1539 * Returns: size of formatted string.
1540 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001541static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001542lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1543 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001544{
Tony Jonesee959b02008-02-22 00:13:36 +01001545 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001546 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1547 struct lpfc_hba *phba = vport->phba;
1548 uint32_t cnt, acnt;
1549
James Smart858c9f62007-06-17 19:56:39 -05001550 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001551 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1552 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1553}
1554
James Smarte59058c2008-08-24 21:49:00 -04001555/**
James Smart3621a712009-04-06 18:47:14 -04001556 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001557 * @dev: class device that is converted into a Scsi_host.
1558 * @attr: device attribute, not used.
1559 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1560 *
1561 * Description:
1562 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1563 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1564 * to "Unknown" and the buffer length is returned, therefore the caller
1565 * must check for "Unknown" in the buffer to detect a failure.
1566 *
1567 * Returns: size of formatted string.
1568 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001569static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001570lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1571 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001572{
Tony Jonesee959b02008-02-22 00:13:36 +01001573 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001574 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1575 struct lpfc_hba *phba = vport->phba;
1576 uint32_t cnt;
1577
James Smart858c9f62007-06-17 19:56:39 -05001578 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001579 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1580 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1581}
1582
James Smarte59058c2008-08-24 21:49:00 -04001583/**
James Smart3621a712009-04-06 18:47:14 -04001584 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001585 * @dev: class device that is converted into a Scsi_host.
1586 * @attr: device attribute, not used.
1587 * @buf: on return contains the used xri count in decimal or "Unknown".
1588 *
1589 * Description:
1590 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1591 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1592 * to "Unknown" and the buffer length is returned, therefore the caller
1593 * must check for "Unknown" in the buffer to detect a failure.
1594 *
1595 * Returns: size of formatted string.
1596 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001597static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001598lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1599 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001600{
Tony Jonesee959b02008-02-22 00:13:36 +01001601 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001602 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1603 struct lpfc_hba *phba = vport->phba;
1604 uint32_t cnt, acnt;
1605
James Smart858c9f62007-06-17 19:56:39 -05001606 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1607 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1608 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1609}
1610
James Smarte59058c2008-08-24 21:49:00 -04001611/**
James Smart3621a712009-04-06 18:47:14 -04001612 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001613 * @dev: class device that is converted into a Scsi_host.
1614 * @attr: device attribute, not used.
1615 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1616 *
1617 * Description:
1618 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1619 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1620 * to "Unknown" and the buffer length is returned, therefore the caller
1621 * must check for "Unknown" in the buffer to detect a failure.
1622 *
1623 * Returns: size of formatted string.
1624 **/
James Smart858c9f62007-06-17 19:56:39 -05001625static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001626lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1627 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001628{
Tony Jonesee959b02008-02-22 00:13:36 +01001629 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001630 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1631 struct lpfc_hba *phba = vport->phba;
1632 uint32_t cnt;
1633
1634 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1635 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1636 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1637}
1638
James Smarte59058c2008-08-24 21:49:00 -04001639/**
James Smart3621a712009-04-06 18:47:14 -04001640 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001641 * @dev: class device that is converted into a Scsi_host.
1642 * @attr: device attribute, not used.
1643 * @buf: on return contains the used vpi count in decimal or "Unknown".
1644 *
1645 * Description:
1646 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1647 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1648 * to "Unknown" and the buffer length is returned, therefore the caller
1649 * must check for "Unknown" in the buffer to detect a failure.
1650 *
1651 * Returns: size of formatted string.
1652 **/
James Smart858c9f62007-06-17 19:56:39 -05001653static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001654lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1655 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001656{
Tony Jonesee959b02008-02-22 00:13:36 +01001657 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001658 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1659 struct lpfc_hba *phba = vport->phba;
1660 uint32_t cnt, acnt;
1661
1662 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001663 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1664 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1665}
1666
James Smarte59058c2008-08-24 21:49:00 -04001667/**
James Smart3621a712009-04-06 18:47:14 -04001668 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001669 * @dev: class device that is converted into a Scsi_host.
1670 * @attr: device attribute, not used.
1671 * @buf: text that must be interpreted to determine if npiv is supported.
1672 *
1673 * Description:
1674 * Buffer will contain text indicating npiv is not suppoerted on the port,
1675 * the port is an NPIV physical port, or it is an npiv virtual port with
1676 * the id of the vport.
1677 *
1678 * Returns: size of formatted string.
1679 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001680static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001681lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1682 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001683{
Tony Jonesee959b02008-02-22 00:13:36 +01001684 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001685 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1686 struct lpfc_hba *phba = vport->phba;
1687
1688 if (!(phba->max_vpi))
1689 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1690 if (vport->port_type == LPFC_PHYSICAL_PORT)
1691 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1692 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1693}
1694
James Smarte59058c2008-08-24 21:49:00 -04001695/**
James Smart3621a712009-04-06 18:47:14 -04001696 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001697 * @dev: class device that is converted into a Scsi_host.
1698 * @attr: device attribute, not used.
1699 * @buf: on return contains the cfg_poll in hex.
1700 *
1701 * Notes:
1702 * cfg_poll should be a lpfc_polling_flags type.
1703 *
1704 * Returns: size of formatted string.
1705 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001706static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001707lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1708 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001709{
Tony Jonesee959b02008-02-22 00:13:36 +01001710 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001711 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1712 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001713
1714 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1715}
1716
James Smarte59058c2008-08-24 21:49:00 -04001717/**
James Smart3621a712009-04-06 18:47:14 -04001718 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001719 * @dev: class device that is converted into a Scsi_host.
1720 * @attr: device attribute, not used.
1721 * @buf: one or more lpfc_polling_flags values.
1722 * @count: not used.
1723 *
1724 * Notes:
1725 * buf contents converted to integer and checked for a valid value.
1726 *
1727 * Returns:
1728 * -EINVAL if the buffer connot be converted or is out of range
1729 * length of the buf on success
1730 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001731static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001732lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1733 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001734{
Tony Jonesee959b02008-02-22 00:13:36 +01001735 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001736 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1737 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001738 uint32_t creg_val;
1739 uint32_t old_val;
1740 int val=0;
1741
1742 if (!isdigit(buf[0]))
1743 return -EINVAL;
1744
1745 if (sscanf(buf, "%i", &val) != 1)
1746 return -EINVAL;
1747
1748 if ((val & 0x3) != val)
1749 return -EINVAL;
1750
James Smart45ed1192009-10-02 15:17:02 -04001751 if (phba->sli_rev == LPFC_SLI_REV4)
1752 val = 0;
1753
James Smart88a2cfb2011-07-22 18:36:33 -04001754 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1755 "3051 lpfc_poll changed from %d to %d\n",
1756 phba->cfg_poll, val);
1757
James Smart2e0fef82007-06-17 19:56:36 -05001758 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001759
1760 old_val = phba->cfg_poll;
1761
1762 if (val & ENABLE_FCP_RING_POLLING) {
1763 if ((val & DISABLE_FCP_RING_INT) &&
1764 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001765 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1766 spin_unlock_irq(&phba->hbalock);
1767 return -EINVAL;
1768 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001769 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1770 writel(creg_val, phba->HCregaddr);
1771 readl(phba->HCregaddr); /* flush */
1772
1773 lpfc_poll_start_timer(phba);
1774 }
1775 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001776 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001777 return -EINVAL;
1778 }
1779
1780 if (!(val & DISABLE_FCP_RING_INT) &&
1781 (old_val & DISABLE_FCP_RING_INT))
1782 {
James Smart2e0fef82007-06-17 19:56:36 -05001783 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001784 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001785 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001786 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1787 spin_unlock_irq(&phba->hbalock);
1788 return -EINVAL;
1789 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001790 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1791 writel(creg_val, phba->HCregaddr);
1792 readl(phba->HCregaddr); /* flush */
1793 }
1794
1795 phba->cfg_poll = val;
1796
James Smart2e0fef82007-06-17 19:56:36 -05001797 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001798
1799 return strlen(buf);
1800}
dea31012005-04-17 16:05:31 -05001801
James Smarte59058c2008-08-24 21:49:00 -04001802/**
James Smartbc739052010-08-04 16:11:18 -04001803 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1804 * @dev: class unused variable.
1805 * @attr: device attribute, not used.
1806 * @buf: on return contains the module description text.
1807 *
1808 * Returns: size of formatted string.
1809 **/
1810static ssize_t
1811lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1812 char *buf)
1813{
1814 struct Scsi_Host *shost = class_to_shost(dev);
1815 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1816 struct lpfc_hba *phba = vport->phba;
1817
1818 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1819}
1820
1821/**
1822 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1823 * @dev: class unused variable.
1824 * @attr: device attribute, not used.
1825 * @buf: on return contains the module description text.
1826 *
1827 * Returns: size of formatted string.
1828 **/
1829static ssize_t
1830lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1831 char *buf)
1832{
1833 struct Scsi_Host *shost = class_to_shost(dev);
1834 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1835 struct lpfc_hba *phba = vport->phba;
1836
1837 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1838}
1839
1840/**
James Smartab56dc22011-02-16 12:39:57 -05001841 * lpfc_dss_show - Return the current state of dss and the configured state
1842 * @dev: class converted to a Scsi_host structure.
1843 * @attr: device attribute, not used.
1844 * @buf: on return contains the formatted text.
1845 *
1846 * Returns: size of formatted string.
1847 **/
1848static ssize_t
1849lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1850 char *buf)
1851{
1852 struct Scsi_Host *shost = class_to_shost(dev);
1853 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1854 struct lpfc_hba *phba = vport->phba;
1855
1856 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1857 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1858 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1859 "" : "Not ");
1860}
1861
1862/**
James Smart912e3ac2011-05-24 11:42:11 -04001863 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1864 * @dev: class converted to a Scsi_host structure.
1865 * @attr: device attribute, not used.
1866 * @buf: on return contains the formatted support level.
1867 *
1868 * Description:
1869 * Returns the maximum number of virtual functions a physical function can
1870 * support, 0 will be returned if called on virtual function.
1871 *
1872 * Returns: size of formatted string.
1873 **/
1874static ssize_t
1875lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1876 struct device_attribute *attr,
1877 char *buf)
1878{
1879 struct Scsi_Host *shost = class_to_shost(dev);
1880 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1881 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001882 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001883
James Smart0a96e972011-07-22 18:37:28 -04001884 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1885 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001886}
1887
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001888static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1889{
1890 return val >= min && val <= max;
1891}
1892
James Smart912e3ac2011-05-24 11:42:11 -04001893/**
James Smart44fd7fe2017-08-23 16:55:47 -07001894 * lpfc_enable_bbcr_set: Sets an attribute value.
1895 * @phba: pointer the the adapter structure.
1896 * @val: integer attribute value.
1897 *
1898 * Description:
1899 * Validates the min and max values then sets the
1900 * adapter config field if in the valid range. prints error message
1901 * and does not set the parameter if invalid.
1902 *
1903 * Returns:
1904 * zero on success
1905 * -EINVAL if val is invalid
1906 */
1907static ssize_t
1908lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
1909{
1910 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
1911 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1912 "3068 %s_enable_bbcr changed from %d to %d\n",
1913 LPFC_DRIVER_NAME, phba->cfg_enable_bbcr, val);
1914 phba->cfg_enable_bbcr = val;
1915 return 0;
1916 }
1917 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1918 "0451 %s_enable_bbcr cannot set to %d, range is 0, 1\n",
1919 LPFC_DRIVER_NAME, val);
1920 return -EINVAL;
1921}
1922
1923/**
James Smart3621a712009-04-06 18:47:14 -04001924 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001925 *
1926 * Description:
1927 * Macro that given an attr e.g. hba_queue_depth expands
1928 * into a function with the name lpfc_hba_queue_depth_show.
1929 *
1930 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1931 * @dev: class device that is converted into a Scsi_host.
1932 * @attr: device attribute, not used.
1933 * @buf: on return contains the attribute value in decimal.
1934 *
1935 * Returns: size of formatted string.
1936 **/
dea31012005-04-17 16:05:31 -05001937#define lpfc_param_show(attr) \
1938static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001939lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1940 char *buf) \
dea31012005-04-17 16:05:31 -05001941{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001942 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001943 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1944 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001945 return snprintf(buf, PAGE_SIZE, "%d\n",\
1946 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001947}
1948
James Smarte59058c2008-08-24 21:49:00 -04001949/**
James Smart3621a712009-04-06 18:47:14 -04001950 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001951 *
1952 * Description:
1953 * Macro that given an attr e.g. hba_queue_depth expands
1954 * into a function with the name lpfc_hba_queue_depth_show
1955 *
1956 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1957 * @dev: class device that is converted into a Scsi_host.
1958 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001959 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001960 *
1961 * Returns: size of formatted string.
1962 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001963#define lpfc_param_hex_show(attr) \
1964static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001965lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1966 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001967{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001968 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001969 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1970 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001971 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001972 val = phba->cfg_##attr;\
1973 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1974 phba->cfg_##attr);\
1975}
1976
James Smarte59058c2008-08-24 21:49:00 -04001977/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001978 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001979 *
1980 * Description:
1981 * Macro that given an attr e.g. hba_queue_depth expands
1982 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1983 * takes a default argument, a minimum and maximum argument.
1984 *
1985 * lpfc_##attr##_init: Initializes an attribute.
1986 * @phba: pointer the the adapter structure.
1987 * @val: integer attribute value.
1988 *
1989 * Validates the min and max values then sets the adapter config field
1990 * accordingly, or uses the default if out of range and prints an error message.
1991 *
1992 * Returns:
1993 * zero on success
1994 * -EINVAL if default used
1995 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001996#define lpfc_param_init(attr, default, minval, maxval) \
1997static int \
James Smart84d1b002010-02-12 14:42:33 -05001998lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001999{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002000 if (lpfc_rangecheck(val, minval, maxval)) {\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002001 phba->cfg_##attr = val;\
2002 return 0;\
2003 }\
2004 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04002005 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2006 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002007 phba->cfg_##attr = default;\
2008 return -EINVAL;\
2009}
2010
James Smarte59058c2008-08-24 21:49:00 -04002011/**
James Smart3621a712009-04-06 18:47:14 -04002012 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04002013 *
2014 * Description:
2015 * Macro that given an attr e.g. hba_queue_depth expands
2016 * into a function with the name lpfc_hba_queue_depth_set
2017 *
2018 * lpfc_##attr##_set: Sets an attribute value.
2019 * @phba: pointer the the adapter structure.
2020 * @val: integer attribute value.
2021 *
2022 * Description:
2023 * Validates the min and max values then sets the
2024 * adapter config field if in the valid range. prints error message
2025 * and does not set the parameter if invalid.
2026 *
2027 * Returns:
2028 * zero on success
2029 * -EINVAL if val is invalid
2030 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002031#define lpfc_param_set(attr, default, minval, maxval) \
2032static int \
James Smart84d1b002010-02-12 14:42:33 -05002033lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002034{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002035 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002036 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2037 "3052 lpfc_" #attr " changed from %d to %d\n", \
2038 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002039 phba->cfg_##attr = val;\
2040 return 0;\
2041 }\
2042 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04002043 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2044 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002045 return -EINVAL;\
2046}
2047
James Smarte59058c2008-08-24 21:49:00 -04002048/**
James Smart3621a712009-04-06 18:47:14 -04002049 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04002050 *
2051 * Description:
2052 * Macro that given an attr e.g. hba_queue_depth expands
2053 * into a function with the name lpfc_hba_queue_depth_store.
2054 *
2055 * lpfc_##attr##_store: Set an sttribute value.
2056 * @dev: class device that is converted into a Scsi_host.
2057 * @attr: device attribute, not used.
2058 * @buf: contains the attribute value in ascii.
2059 * @count: not used.
2060 *
2061 * Description:
2062 * Convert the ascii text number to an integer, then
2063 * use the lpfc_##attr##_set function to set the value.
2064 *
2065 * Returns:
2066 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2067 * length of buffer upon success.
2068 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002069#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05002070static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002071lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2072 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05002073{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002074 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002075 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2076 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05002077 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002078 if (!isdigit(buf[0]))\
2079 return -EINVAL;\
2080 if (sscanf(buf, "%i", &val) != 1)\
2081 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002082 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04002083 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002084 else \
2085 return -EINVAL;\
dea31012005-04-17 16:05:31 -05002086}
2087
James Smarte59058c2008-08-24 21:49:00 -04002088/**
James Smart3621a712009-04-06 18:47:14 -04002089 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04002090 *
2091 * Description:
2092 * Macro that given an attr e.g. hba_queue_depth expands
2093 * into a function with the name lpfc_hba_queue_depth_show
2094 *
2095 * lpfc_##attr##_show: prints the attribute value in decimal.
2096 * @dev: class device that is converted into a Scsi_host.
2097 * @attr: device attribute, not used.
2098 * @buf: on return contains the attribute value in decimal.
2099 *
2100 * Returns: length of formatted string.
2101 **/
James Smart3de2a652007-08-02 11:09:59 -04002102#define lpfc_vport_param_show(attr) \
2103static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002104lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2105 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002106{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002107 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002108 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002109 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2110}
2111
James Smarte59058c2008-08-24 21:49:00 -04002112/**
James Smart3621a712009-04-06 18:47:14 -04002113 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04002114 *
2115 * Description:
2116 * Macro that given an attr e.g.
2117 * hba_queue_depth expands into a function with the name
2118 * lpfc_hba_queue_depth_show
2119 *
James Smart3621a712009-04-06 18:47:14 -04002120 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002121 * @dev: class device that is converted into a Scsi_host.
2122 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002123 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002124 *
2125 * Returns: length of formatted string.
2126 **/
James Smart3de2a652007-08-02 11:09:59 -04002127#define lpfc_vport_param_hex_show(attr) \
2128static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002129lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2130 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002131{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002132 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002134 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2135}
2136
James Smarte59058c2008-08-24 21:49:00 -04002137/**
James Smart3621a712009-04-06 18:47:14 -04002138 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002139 *
2140 * Description:
2141 * Macro that given an attr e.g. hba_queue_depth expands
2142 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2143 * takes a default argument, a minimum and maximum argument.
2144 *
2145 * lpfc_##attr##_init: validates the min and max values then sets the
2146 * adapter config field accordingly, or uses the default if out of range
2147 * and prints an error message.
2148 * @phba: pointer the the adapter structure.
2149 * @val: integer attribute value.
2150 *
2151 * Returns:
2152 * zero on success
2153 * -EINVAL if default used
2154 **/
James Smart3de2a652007-08-02 11:09:59 -04002155#define lpfc_vport_param_init(attr, default, minval, maxval) \
2156static int \
James Smart84d1b002010-02-12 14:42:33 -05002157lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002158{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002159 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart3de2a652007-08-02 11:09:59 -04002160 vport->cfg_##attr = val;\
2161 return 0;\
2162 }\
James Smarte8b62012007-08-02 11:10:09 -04002163 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002164 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002165 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002166 vport->cfg_##attr = default;\
2167 return -EINVAL;\
2168}
2169
James Smarte59058c2008-08-24 21:49:00 -04002170/**
James Smart3621a712009-04-06 18:47:14 -04002171 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002172 *
2173 * Description:
2174 * Macro that given an attr e.g. hba_queue_depth expands
2175 * into a function with the name lpfc_hba_queue_depth_set
2176 *
2177 * lpfc_##attr##_set: validates the min and max values then sets the
2178 * adapter config field if in the valid range. prints error message
2179 * and does not set the parameter if invalid.
2180 * @phba: pointer the the adapter structure.
2181 * @val: integer attribute value.
2182 *
2183 * Returns:
2184 * zero on success
2185 * -EINVAL if val is invalid
2186 **/
James Smart3de2a652007-08-02 11:09:59 -04002187#define lpfc_vport_param_set(attr, default, minval, maxval) \
2188static int \
James Smart84d1b002010-02-12 14:42:33 -05002189lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002190{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002191 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002192 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04002193 "3053 lpfc_" #attr \
2194 " changed from %d (x%x) to %d (x%x)\n", \
2195 vport->cfg_##attr, vport->cfg_##attr, \
2196 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04002197 vport->cfg_##attr = val;\
2198 return 0;\
2199 }\
James Smarte8b62012007-08-02 11:10:09 -04002200 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002201 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002202 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002203 return -EINVAL;\
2204}
2205
James Smarte59058c2008-08-24 21:49:00 -04002206/**
James Smart3621a712009-04-06 18:47:14 -04002207 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04002208 *
2209 * Description:
2210 * Macro that given an attr e.g. hba_queue_depth
2211 * expands into a function with the name lpfc_hba_queue_depth_store
2212 *
2213 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2214 * use the lpfc_##attr##_set function to set the value.
2215 * @cdev: class device that is converted into a Scsi_host.
2216 * @buf: contains the attribute value in decimal.
2217 * @count: not used.
2218 *
2219 * Returns:
2220 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2221 * length of buffer upon success.
2222 **/
James Smart3de2a652007-08-02 11:09:59 -04002223#define lpfc_vport_param_store(attr) \
2224static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002225lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2226 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04002227{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002228 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002229 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05002230 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04002231 if (!isdigit(buf[0]))\
2232 return -EINVAL;\
2233 if (sscanf(buf, "%i", &val) != 1)\
2234 return -EINVAL;\
2235 if (lpfc_##attr##_set(vport, val) == 0) \
2236 return strlen(buf);\
2237 else \
2238 return -EINVAL;\
2239}
2240
2241
James Smart895427b2017-02-12 13:52:30 -08002242static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
James Smart81301a92008-12-04 22:39:46 -05002243static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2244static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2245static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2246static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002247static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2248static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2249static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2250static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2251static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2252static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2253static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2254static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002255static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2256 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002257static DEVICE_ATTR(option_rom_version, S_IRUGO,
2258 lpfc_option_rom_version_show, NULL);
2259static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2260 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002261static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002262static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
Joe Perchesc828a892017-12-19 10:15:08 -08002263static DEVICE_ATTR_RO(lpfc_drvr_version);
2264static DEVICE_ATTR_RO(lpfc_enable_fip);
Tony Jonesee959b02008-02-22 00:13:36 +01002265static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2266 lpfc_board_mode_show, lpfc_board_mode_store);
2267static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2268static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2269static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2270static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2271static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2272static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2273static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2274static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
Joe Perchesc828a892017-12-19 10:15:08 -08002275static DEVICE_ATTR_RO(lpfc_temp_sensor);
2276static DEVICE_ATTR_RO(lpfc_fips_level);
2277static DEVICE_ATTR_RO(lpfc_fips_rev);
2278static DEVICE_ATTR_RO(lpfc_dss);
2279static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
James Smart026abb82011-12-13 13:20:45 -05002280static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05002281static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2282 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002283
James Smart352e5fd2016-12-30 06:57:47 -08002284static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smart1ba981f2014-02-20 09:56:45 -05002285#define WWN_SZ 8
2286/**
2287 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2288 * @buf: WWN string.
2289 * @cnt: Length of string.
2290 * @wwn: Array to receive converted wwn value.
2291 *
2292 * Returns:
2293 * -EINVAL if the buffer does not contain a valid wwn
2294 * 0 success
2295 **/
2296static size_t
2297lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2298{
2299 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002300
James Smart1ba981f2014-02-20 09:56:45 -05002301 /* Count may include a LF at end of string */
2302 if (buf[cnt-1] == '\n')
2303 cnt--;
2304
2305 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2306 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2307 return -EINVAL;
2308
2309 memset(wwn, 0, WWN_SZ);
2310
2311 /* Validate and store the new name */
2312 for (i = 0, j = 0; i < 16; i++) {
2313 if ((*buf >= 'a') && (*buf <= 'f'))
2314 j = ((j << 4) | ((*buf++ - 'a') + 10));
2315 else if ((*buf >= 'A') && (*buf <= 'F'))
2316 j = ((j << 4) | ((*buf++ - 'A') + 10));
2317 else if ((*buf >= '0') && (*buf <= '9'))
2318 j = ((j << 4) | (*buf++ - '0'));
2319 else
2320 return -EINVAL;
2321 if (i % 2) {
2322 wwn[i/2] = j & 0xff;
2323 j = 0;
2324 }
2325 }
2326 return 0;
2327}
James Smart352e5fd2016-12-30 06:57:47 -08002328/**
2329 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2330 * @dev: class device that is converted into a Scsi_host.
2331 * @attr: device attribute, not used.
2332 * @buf: containing the string lpfc_soft_wwn_key.
2333 * @count: must be size of lpfc_soft_wwn_key.
2334 *
2335 * Returns:
2336 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2337 * length of buf indicates success
2338 **/
2339static ssize_t
2340lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2341 const char *buf, size_t count)
2342{
2343 struct Scsi_Host *shost = class_to_shost(dev);
2344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2345 struct lpfc_hba *phba = vport->phba;
2346 unsigned int cnt = count;
James Smartaeb3c812017-04-21 16:05:02 -07002347 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2348 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
James Smart352e5fd2016-12-30 06:57:47 -08002349
2350 /*
2351 * We're doing a simple sanity check for soft_wwpn setting.
2352 * We require that the user write a specific key to enable
2353 * the soft_wwpn attribute to be settable. Once the attribute
2354 * is written, the enable key resets. If further updates are
2355 * desired, the key must be written again to re-enable the
2356 * attribute.
2357 *
2358 * The "key" is not secret - it is a hardcoded string shown
2359 * here. The intent is to protect against the random user or
2360 * application that is just writing attributes.
2361 */
James Smartaeb3c812017-04-21 16:05:02 -07002362 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2363 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2364 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2365 " be enabled: fawwpn is enabled\n");
2366 return -EINVAL;
2367 }
James Smart352e5fd2016-12-30 06:57:47 -08002368
2369 /* count may include a LF at end of string */
2370 if (buf[cnt-1] == '\n')
2371 cnt--;
2372
2373 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2374 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2375 return -EINVAL;
2376
2377 phba->soft_wwn_enable = 1;
2378
2379 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2380 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2381 phba->brd_no);
2382 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2383 " The soft_wwpn feature is not supported by Broadcom.");
2384
2385 return count;
2386}
2387static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2388 lpfc_soft_wwn_enable_store);
2389
2390/**
2391 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2392 * @dev: class device that is converted into a Scsi_host.
2393 * @attr: device attribute, not used.
2394 * @buf: on return contains the wwpn in hexadecimal.
2395 *
2396 * Returns: size of formatted string.
2397 **/
2398static ssize_t
2399lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2400 char *buf)
2401{
2402 struct Scsi_Host *shost = class_to_shost(dev);
2403 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2404 struct lpfc_hba *phba = vport->phba;
2405
2406 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2407 (unsigned long long)phba->cfg_soft_wwpn);
2408}
2409
2410/**
2411 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2412 * @dev class device that is converted into a Scsi_host.
2413 * @attr: device attribute, not used.
2414 * @buf: contains the wwpn in hexadecimal.
2415 * @count: number of wwpn bytes in buf
2416 *
2417 * Returns:
2418 * -EACCES hba reset not enabled, adapter over temp
2419 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2420 * -EIO error taking adapter offline or online
2421 * value of count on success
2422 **/
2423static ssize_t
2424lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2425 const char *buf, size_t count)
2426{
2427 struct Scsi_Host *shost = class_to_shost(dev);
2428 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2429 struct lpfc_hba *phba = vport->phba;
2430 struct completion online_compl;
2431 int stat1 = 0, stat2 = 0;
2432 unsigned int cnt = count;
2433 u8 wwpn[WWN_SZ];
2434 int rc;
2435
2436 if (!phba->cfg_enable_hba_reset)
2437 return -EACCES;
2438 spin_lock_irq(&phba->hbalock);
2439 if (phba->over_temp_state == HBA_OVER_TEMP) {
2440 spin_unlock_irq(&phba->hbalock);
2441 return -EACCES;
2442 }
2443 spin_unlock_irq(&phba->hbalock);
2444 /* count may include a LF at end of string */
2445 if (buf[cnt-1] == '\n')
2446 cnt--;
2447
2448 if (!phba->soft_wwn_enable)
2449 return -EINVAL;
2450
2451 /* lock setting wwpn, wwnn down */
2452 phba->soft_wwn_enable = 0;
2453
2454 rc = lpfc_wwn_set(buf, cnt, wwpn);
James Smarte2934ed2017-01-17 12:31:56 -08002455 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002456 /* not able to set wwpn, unlock it */
2457 phba->soft_wwn_enable = 1;
2458 return rc;
2459 }
2460
2461 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2462 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2463 if (phba->cfg_soft_wwnn)
2464 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2465
2466 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2467 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2468
2469 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2470 if (stat1)
2471 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2472 "0463 lpfc_soft_wwpn attribute set failed to "
2473 "reinit adapter - %d\n", stat1);
2474 init_completion(&online_compl);
2475 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2476 LPFC_EVT_ONLINE);
2477 if (rc == 0)
2478 return -ENOMEM;
2479
2480 wait_for_completion(&online_compl);
2481 if (stat2)
2482 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2483 "0464 lpfc_soft_wwpn attribute set failed to "
2484 "reinit adapter - %d\n", stat2);
2485 return (stat1 || stat2) ? -EIO : count;
2486}
Joe Perchesb6b996b2017-12-19 10:15:07 -08002487static DEVICE_ATTR_RW(lpfc_soft_wwpn);
James Smart352e5fd2016-12-30 06:57:47 -08002488
2489/**
2490 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2491 * @dev: class device that is converted into a Scsi_host.
2492 * @attr: device attribute, not used.
2493 * @buf: on return contains the wwnn in hexadecimal.
2494 *
2495 * Returns: size of formatted string.
2496 **/
2497static ssize_t
2498lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2499 char *buf)
2500{
2501 struct Scsi_Host *shost = class_to_shost(dev);
2502 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2503 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2504 (unsigned long long)phba->cfg_soft_wwnn);
2505}
2506
2507/**
2508 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2509 * @cdev: class device that is converted into a Scsi_host.
2510 * @buf: contains the ww node name in hexadecimal.
2511 * @count: number of wwnn bytes in buf.
2512 *
2513 * Returns:
2514 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2515 * value of count on success
2516 **/
2517static ssize_t
2518lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2519 const char *buf, size_t count)
2520{
2521 struct Scsi_Host *shost = class_to_shost(dev);
2522 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2523 unsigned int cnt = count;
2524 u8 wwnn[WWN_SZ];
2525 int rc;
2526
2527 /* count may include a LF at end of string */
2528 if (buf[cnt-1] == '\n')
2529 cnt--;
2530
2531 if (!phba->soft_wwn_enable)
2532 return -EINVAL;
2533
2534 rc = lpfc_wwn_set(buf, cnt, wwnn);
James Smarte2934ed2017-01-17 12:31:56 -08002535 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002536 /* Allow wwnn to be set many times, as long as the enable
2537 * is set. However, once the wwpn is set, everything locks.
2538 */
2539 return rc;
2540 }
2541
2542 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2543
2544 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2545 "lpfc%d: soft_wwnn set. Value will take effect upon "
2546 "setting of the soft_wwpn\n", phba->brd_no);
2547
2548 return count;
2549}
Joe Perchesb6b996b2017-12-19 10:15:07 -08002550static DEVICE_ATTR_RW(lpfc_soft_wwnn);
James Smarta12e07b2006-12-02 13:35:30 -05002551
James Smart1ba981f2014-02-20 09:56:45 -05002552/**
2553 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2554 * Optimized Access Storage (OAS) operations.
2555 * @dev: class device that is converted into a Scsi_host.
2556 * @attr: device attribute, not used.
2557 * @buf: buffer for passing information.
2558 *
2559 * Returns:
2560 * value of count
2561 **/
2562static ssize_t
2563lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2564 char *buf)
2565{
2566 struct Scsi_Host *shost = class_to_shost(dev);
2567 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2568
2569 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2570 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2571}
2572
2573/**
2574 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2575 * Optimized Access Storage (OAS) operations.
2576 * @dev: class device that is converted into a Scsi_host.
2577 * @attr: device attribute, not used.
2578 * @buf: buffer for passing information.
2579 * @count: Size of the data buffer.
2580 *
2581 * Returns:
2582 * -EINVAL count is invalid, invalid wwpn byte invalid
2583 * -EPERM oas is not supported by hba
2584 * value of count on success
2585 **/
2586static ssize_t
2587lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2588 const char *buf, size_t count)
2589{
2590 struct Scsi_Host *shost = class_to_shost(dev);
2591 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2592 unsigned int cnt = count;
2593 uint8_t wwpn[WWN_SZ];
2594 int rc;
2595
James Smartf38fa0b2014-04-04 13:52:21 -04002596 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002597 return -EPERM;
2598
2599 /* count may include a LF at end of string */
2600 if (buf[cnt-1] == '\n')
2601 cnt--;
2602
2603 rc = lpfc_wwn_set(buf, cnt, wwpn);
2604 if (rc)
2605 return rc;
2606
2607 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2608 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2609 if (wwn_to_u64(wwpn) == 0)
2610 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2611 else
2612 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2613 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2614 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2615 return count;
2616}
2617static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2618 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2619
2620/**
James Smartc92c8412016-07-06 12:36:05 -07002621 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2622 * Optimized Access Storage (OAS) operations.
2623 * @dev: class device that is converted into a Scsi_host.
2624 * @attr: device attribute, not used.
2625 * @buf: buffer for passing information.
2626 *
2627 * Returns:
2628 * value of count
2629 **/
2630static ssize_t
2631lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2632 char *buf)
2633{
2634 struct Scsi_Host *shost = class_to_shost(dev);
2635 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2636
2637 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2638}
2639
2640/**
2641 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2642 * Optimized Access Storage (OAS) operations.
2643 * @dev: class device that is converted into a Scsi_host.
2644 * @attr: device attribute, not used.
2645 * @buf: buffer for passing information.
2646 * @count: Size of the data buffer.
2647 *
2648 * Returns:
2649 * -EINVAL count is invalid, invalid wwpn byte invalid
2650 * -EPERM oas is not supported by hba
2651 * value of count on success
2652 **/
2653static ssize_t
2654lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2655 const char *buf, size_t count)
2656{
2657 struct Scsi_Host *shost = class_to_shost(dev);
2658 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2659 unsigned int cnt = count;
2660 unsigned long val;
2661 int ret;
2662
2663 if (!phba->cfg_fof)
2664 return -EPERM;
2665
2666 /* count may include a LF at end of string */
2667 if (buf[cnt-1] == '\n')
2668 cnt--;
2669
2670 ret = kstrtoul(buf, 0, &val);
2671 if (ret || (val > 0x7f))
2672 return -EINVAL;
2673
2674 if (val)
2675 phba->cfg_oas_priority = (uint8_t)val;
2676 else
2677 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2678 return count;
2679}
2680static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2681 lpfc_oas_priority_show, lpfc_oas_priority_store);
2682
2683/**
James Smart1ba981f2014-02-20 09:56:45 -05002684 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2685 * for Optimized Access Storage (OAS) operations.
2686 * @dev: class device that is converted into a Scsi_host.
2687 * @attr: device attribute, not used.
2688 * @buf: buffer for passing information.
2689 *
2690 * Returns:
2691 * value of count on success
2692 **/
2693static ssize_t
2694lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2695 char *buf)
2696{
2697 struct Scsi_Host *shost = class_to_shost(dev);
2698 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2699
2700 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2701 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2702}
2703
2704/**
2705 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2706 * for Optimized Access Storage (OAS) operations.
2707 * @dev: class device that is converted into a Scsi_host.
2708 * @attr: device attribute, not used.
2709 * @buf: buffer for passing information.
2710 * @count: Size of the data buffer.
2711 *
2712 * Returns:
2713 * -EINVAL count is invalid, invalid wwpn byte invalid
2714 * -EPERM oas is not supported by hba
2715 * value of count on success
2716 **/
2717static ssize_t
2718lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2719 const char *buf, size_t count)
2720{
2721 struct Scsi_Host *shost = class_to_shost(dev);
2722 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2723 unsigned int cnt = count;
2724 uint8_t wwpn[WWN_SZ];
2725 int rc;
2726
James Smartf38fa0b2014-04-04 13:52:21 -04002727 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002728 return -EPERM;
2729
2730 /* count may include a LF at end of string */
2731 if (buf[cnt-1] == '\n')
2732 cnt--;
2733
2734 rc = lpfc_wwn_set(buf, cnt, wwpn);
2735 if (rc)
2736 return rc;
2737
2738 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2739 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2740 if (wwn_to_u64(wwpn) == 0)
2741 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2742 else
2743 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2744 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
James Smartb5749fe2016-12-19 15:07:26 -08002745 if (phba->cfg_oas_priority == 0)
2746 phba->cfg_oas_priority = phba->cfg_XLanePriority;
James Smart1ba981f2014-02-20 09:56:45 -05002747 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2748 return count;
2749}
2750static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2751 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2752
2753/**
2754 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2755 * of whether luns will be enabled or disabled
2756 * for Optimized Access Storage (OAS) operations.
2757 * @dev: class device that is converted into a Scsi_host.
2758 * @attr: device attribute, not used.
2759 * @buf: buffer for passing information.
2760 *
2761 * Returns:
2762 * size of formatted string.
2763 **/
2764static ssize_t
2765lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2766 char *buf)
2767{
2768 struct Scsi_Host *shost = class_to_shost(dev);
2769 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2770
2771 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2772}
2773
2774/**
2775 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2776 * of whether luns will be enabled or disabled
2777 * for Optimized Access Storage (OAS) operations.
2778 * @dev: class device that is converted into a Scsi_host.
2779 * @attr: device attribute, not used.
2780 * @buf: buffer for passing information.
2781 * @count: Size of the data buffer.
2782 *
2783 * Returns:
2784 * -EINVAL count is invalid, invalid wwpn byte invalid
2785 * -EPERM oas is not supported by hba
2786 * value of count on success
2787 **/
2788static ssize_t
2789lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2790 const char *buf, size_t count)
2791{
2792 struct Scsi_Host *shost = class_to_shost(dev);
2793 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2794 int val = 0;
2795
James Smartf38fa0b2014-04-04 13:52:21 -04002796 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002797 return -EPERM;
2798
2799 if (!isdigit(buf[0]))
2800 return -EINVAL;
2801
2802 if (sscanf(buf, "%i", &val) != 1)
2803 return -EINVAL;
2804
2805 if ((val != 0) && (val != 1))
2806 return -EINVAL;
2807
2808 phba->cfg_oas_lun_state = val;
James Smart1ba981f2014-02-20 09:56:45 -05002809 return strlen(buf);
2810}
2811static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2812 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2813
2814/**
2815 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2816 * Storage (OAS) lun returned by the
2817 * lpfc_oas_lun_show function.
2818 * @dev: class device that is converted into a Scsi_host.
2819 * @attr: device attribute, not used.
2820 * @buf: buffer for passing information.
2821 *
2822 * Returns:
2823 * size of formatted string.
2824 **/
2825static ssize_t
2826lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2827 char *buf)
2828{
2829 struct Scsi_Host *shost = class_to_shost(dev);
2830 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2831
2832 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2833 return -EFAULT;
2834
2835 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2836}
2837static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2838 lpfc_oas_lun_status_show, NULL);
2839
2840
2841/**
2842 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2843 * (OAS) operations.
2844 * @phba: lpfc_hba pointer.
2845 * @ndlp: pointer to fcp target node.
2846 * @lun: the fc lun for setting oas state.
2847 * @oas_state: the oas state to be set to the lun.
2848 *
2849 * Returns:
2850 * SUCCESS : 0
2851 * -EPERM OAS is not enabled or not supported by this port.
2852 *
2853 */
2854static size_t
2855lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartc92c8412016-07-06 12:36:05 -07002856 uint8_t tgt_wwpn[], uint64_t lun,
2857 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002858{
2859
2860 int rc = 0;
2861
James Smartf38fa0b2014-04-04 13:52:21 -04002862 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002863 return -EPERM;
2864
2865 if (oas_state) {
2866 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002867 (struct lpfc_name *)tgt_wwpn,
2868 lun, pri))
James Smart1ba981f2014-02-20 09:56:45 -05002869 rc = -ENOMEM;
2870 } else {
2871 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002872 (struct lpfc_name *)tgt_wwpn, lun, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002873 }
2874 return rc;
2875
2876}
2877
2878/**
2879 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2880 * Access Storage (OAS) operations.
2881 * @phba: lpfc_hba pointer.
2882 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2883 * @tgt_wwpn: wwpn of the target associated with the returned lun
2884 * @lun_status: status of the lun returned lun
2885 *
2886 * Returns the first or next lun enabled for OAS operations for the vport/target
2887 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2888 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2889 *
2890 * Return:
2891 * lun that is OAS enabled for the vport/target
2892 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2893 */
2894static uint64_t
2895lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartb5749fe2016-12-19 15:07:26 -08002896 uint8_t tgt_wwpn[], uint32_t *lun_status,
2897 uint32_t *lun_pri)
James Smart1ba981f2014-02-20 09:56:45 -05002898{
2899 uint64_t found_lun;
2900
2901 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2902 return NOT_OAS_ENABLED_LUN;
2903 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2904 phba->sli4_hba.oas_next_vpt_wwpn,
2905 (struct lpfc_name *)
2906 phba->sli4_hba.oas_next_tgt_wwpn,
2907 &phba->sli4_hba.oas_next_lun,
2908 (struct lpfc_name *)vpt_wwpn,
2909 (struct lpfc_name *)tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002910 &found_lun, lun_status, lun_pri))
James Smart1ba981f2014-02-20 09:56:45 -05002911 return found_lun;
2912 else
2913 return NOT_OAS_ENABLED_LUN;
2914}
2915
2916/**
2917 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2918 * @phba: lpfc_hba pointer.
2919 * @vpt_wwpn: vport wwpn by reference.
2920 * @tgt_wwpn: target wwpn by reference.
2921 * @lun: the fc lun for setting oas state.
2922 * @oas_state: the oas state to be set to the oas_lun.
2923 *
2924 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2925 * a lun for OAS operations.
2926 *
2927 * Return:
2928 * SUCCESS: 0
2929 * -ENOMEM: failed to enable an lun for OAS operations
2930 * -EPERM: OAS is not enabled
2931 */
2932static ssize_t
2933lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2934 uint8_t tgt_wwpn[], uint64_t lun,
James Smartc92c8412016-07-06 12:36:05 -07002935 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002936{
2937
2938 int rc;
2939
2940 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
James Smartc92c8412016-07-06 12:36:05 -07002941 oas_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002942 return rc;
2943}
2944
2945/**
2946 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2947 * @dev: class device that is converted into a Scsi_host.
2948 * @attr: device attribute, not used.
2949 * @buf: buffer for passing information.
2950 *
2951 * This routine returns a lun enabled for OAS each time the function
2952 * is called.
2953 *
2954 * Returns:
2955 * SUCCESS: size of formatted string.
2956 * -EFAULT: target or vport wwpn was not set properly.
2957 * -EPERM: oas is not enabled.
2958 **/
2959static ssize_t
2960lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2961 char *buf)
2962{
2963 struct Scsi_Host *shost = class_to_shost(dev);
2964 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2965
2966 uint64_t oas_lun;
2967 int len = 0;
2968
James Smartf38fa0b2014-04-04 13:52:21 -04002969 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002970 return -EPERM;
2971
2972 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2973 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2974 return -EFAULT;
2975
2976 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2977 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2978 return -EFAULT;
2979
2980 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2981 phba->cfg_oas_tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002982 &phba->cfg_oas_lun_status,
2983 &phba->cfg_oas_priority);
James Smart1ba981f2014-02-20 09:56:45 -05002984 if (oas_lun != NOT_OAS_ENABLED_LUN)
2985 phba->cfg_oas_flags |= OAS_LUN_VALID;
2986
2987 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2988
2989 return len;
2990}
2991
2992/**
2993 * lpfc_oas_lun_store - Sets the OAS state for lun
2994 * @dev: class device that is converted into a Scsi_host.
2995 * @attr: device attribute, not used.
2996 * @buf: buffer for passing information.
2997 *
2998 * This function sets the OAS state for lun. Before this function is called,
2999 * the vport wwpn, target wwpn, and oas state need to be set.
3000 *
3001 * Returns:
3002 * SUCCESS: size of formatted string.
3003 * -EFAULT: target or vport wwpn was not set properly.
3004 * -EPERM: oas is not enabled.
3005 * size of formatted string.
3006 **/
3007static ssize_t
3008lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3009 const char *buf, size_t count)
3010{
3011 struct Scsi_Host *shost = class_to_shost(dev);
3012 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3013 uint64_t scsi_lun;
James Smartb5749fe2016-12-19 15:07:26 -08003014 uint32_t pri;
James Smart1ba981f2014-02-20 09:56:45 -05003015 ssize_t rc;
3016
James Smartf38fa0b2014-04-04 13:52:21 -04003017 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003018 return -EPERM;
3019
3020 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3021 return -EFAULT;
3022
3023 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3024 return -EFAULT;
3025
3026 if (!isdigit(buf[0]))
3027 return -EINVAL;
3028
3029 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3030 return -EINVAL;
3031
James Smartb5749fe2016-12-19 15:07:26 -08003032 pri = phba->cfg_oas_priority;
3033 if (pri == 0)
3034 pri = phba->cfg_XLanePriority;
3035
James Smart1ba981f2014-02-20 09:56:45 -05003036 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartc92c8412016-07-06 12:36:05 -07003037 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3038 "priority 0x%x with oas state %d\n",
James Smart1ba981f2014-02-20 09:56:45 -05003039 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3040 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08003041 pri, phba->cfg_oas_lun_state);
James Smart1ba981f2014-02-20 09:56:45 -05003042
3043 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07003044 phba->cfg_oas_tgt_wwpn, scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08003045 phba->cfg_oas_lun_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05003046 if (rc)
3047 return rc;
3048
3049 return count;
3050}
3051static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3052 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04003053
James Smartf358dd02017-02-12 13:52:34 -08003054int lpfc_enable_nvmet_cnt;
3055unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3056 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3057 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3058module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3059MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3060
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003061static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05003062module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003063MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3064 " 0 - none,"
3065 " 1 - poll with interrupts enabled"
3066 " 3 - poll and disable FCP ring interrupts");
3067
Joe Perchesb6b996b2017-12-19 10:15:07 -08003068static DEVICE_ATTR_RW(lpfc_poll);
dea31012005-04-17 16:05:31 -05003069
James Smart96418b52017-03-04 09:30:31 -08003070int lpfc_no_hba_reset_cnt;
3071unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3072 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3073module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3074MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3075
James Smart12247e82016-07-06 12:36:09 -07003076LPFC_ATTR(sli_mode, 0, 0, 3,
3077 "SLI mode selector:"
3078 " 0 - auto (SLI-3 if supported),"
3079 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3080 " 3 - select SLI-3");
James Smart92d7f7b2007-06-17 19:56:38 -05003081
James Smart458c0832016-07-06 12:36:07 -07003082LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3083 "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05003084
James Smart7d791df2011-07-22 18:37:52 -04003085LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3086 "FCF Fast failover=1 Priority failover=2");
3087
James Smarte5771b42013-03-01 16:37:14 -05003088/*
3089# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3090# 0x0 = disabled, XRI/OXID use not tracked.
3091# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3092# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3093*/
James Smart31202b02016-10-13 15:06:08 -07003094LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3095 "Enable RRQ functionality");
James Smart19ca7602010-11-20 23:11:55 -05003096
dea31012005-04-17 16:05:31 -05003097/*
James Smart84d1b002010-02-12 14:42:33 -05003098# lpfc_suppress_link_up: Bring link up at initialization
3099# 0x0 = bring link up (issue MBX_INIT_LINK)
3100# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3101# 0x2 = never bring up link
3102# Default value is 0.
3103*/
James Smarte40a02c2010-02-26 14:13:54 -05003104LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3105 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3106 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04003107/*
3108# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3109# 1 - (1024)
3110# 2 - (2048)
3111# 3 - (3072)
3112# 4 - (4096)
3113# 5 - (5120)
3114*/
3115static ssize_t
3116lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3117{
3118 struct Scsi_Host *shost = class_to_shost(dev);
3119 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3120
3121 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3122}
3123
3124static DEVICE_ATTR(iocb_hw, S_IRUGO,
3125 lpfc_iocb_hw_show, NULL);
3126static ssize_t
3127lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3128{
3129 struct Scsi_Host *shost = class_to_shost(dev);
3130 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003131 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003132
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003133 return snprintf(buf, PAGE_SIZE, "%d\n",
3134 pring ? pring->txq_max : 0);
James Smart2a9bf3d2010-06-07 15:24:45 -04003135}
3136
3137static DEVICE_ATTR(txq_hw, S_IRUGO,
3138 lpfc_txq_hw_show, NULL);
3139static ssize_t
3140lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3141 char *buf)
3142{
3143 struct Scsi_Host *shost = class_to_shost(dev);
3144 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003145 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003146
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003147 return snprintf(buf, PAGE_SIZE, "%d\n",
3148 pring ? pring->txcmplq_max : 0);
James Smart2a9bf3d2010-06-07 15:24:45 -04003149}
3150
3151static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3152 lpfc_txcmplq_hw_show, NULL);
3153
James Smart0d8c8ba2016-10-13 15:06:07 -07003154LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
James Smart2a9bf3d2010-06-07 15:24:45 -04003155 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
James Smart84d1b002010-02-12 14:42:33 -05003156
3157/*
James Smartc01f3202006-08-18 17:47:08 -04003158# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3159# until the timer expires. Value range is [0,255]. Default value is 30.
3160*/
3161static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3162static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3163module_param(lpfc_nodev_tmo, int, 0);
3164MODULE_PARM_DESC(lpfc_nodev_tmo,
3165 "Seconds driver will hold I/O waiting "
3166 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04003167
3168/**
James Smart3621a712009-04-06 18:47:14 -04003169 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04003170 * @dev: class converted to a Scsi_host structure.
3171 * @attr: device attribute, not used.
3172 * @buf: on return contains the dev loss timeout in decimal.
3173 *
3174 * Returns: size of formatted string.
3175 **/
James Smartc01f3202006-08-18 17:47:08 -04003176static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003177lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3178 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04003179{
Tony Jonesee959b02008-02-22 00:13:36 +01003180 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003181 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05003182
James Smart3de2a652007-08-02 11:09:59 -04003183 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003184}
3185
James Smarte59058c2008-08-24 21:49:00 -04003186/**
James Smart3621a712009-04-06 18:47:14 -04003187 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04003188 * @vport: lpfc vport structure pointer.
3189 * @val: contains the nodev timeout value.
3190 *
3191 * Description:
3192 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3193 * a kernel error message is printed and zero is returned.
3194 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3195 * Otherwise nodev tmo is set to the default value.
3196 *
3197 * Returns:
3198 * zero if already set or if val is in range
3199 * -EINVAL val out of range
3200 **/
James Smartc01f3202006-08-18 17:47:08 -04003201static int
James Smart3de2a652007-08-02 11:09:59 -04003202lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003203{
James Smart3de2a652007-08-02 11:09:59 -04003204 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3205 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3206 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04003207 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003208 "0407 Ignoring lpfc_nodev_tmo module "
3209 "parameter because lpfc_devloss_tmo "
3210 "is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003211 return 0;
3212 }
3213
3214 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003215 vport->cfg_nodev_tmo = val;
3216 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04003217 return 0;
3218 }
James Smarte8b62012007-08-02 11:10:09 -04003219 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3220 "0400 lpfc_nodev_tmo attribute cannot be set to"
3221 " %d, allowed range is [%d, %d]\n",
3222 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04003223 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04003224 return -EINVAL;
3225}
3226
James Smarte59058c2008-08-24 21:49:00 -04003227/**
James Smart3621a712009-04-06 18:47:14 -04003228 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04003229 * @vport: lpfc vport structure pointer.
3230 *
3231 * Description:
3232 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3233 **/
James Smart7054a602007-04-25 09:52:34 -04003234static void
James Smart3de2a652007-08-02 11:09:59 -04003235lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04003236{
James Smart858c9f62007-06-17 19:56:39 -05003237 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04003238 struct lpfc_nodelist *ndlp;
3239
James Smart51ef4c22007-08-02 11:10:31 -04003240 shost = lpfc_shost_from_vport(vport);
3241 spin_lock_irq(shost->host_lock);
James Smart7a06dcd2017-06-01 21:06:55 -07003242 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3243 if (!NLP_CHK_NODE_ACT(ndlp))
3244 continue;
3245 if (ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04003246 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
James Smart6ddcf0a2017-11-03 09:33:30 -07003247#if (IS_ENABLED(CONFIG_NVME_FC))
3248 if (ndlp->nrport)
3249 nvme_fc_set_remoteport_devloss(ndlp->nrport->remoteport,
3250 vport->cfg_devloss_tmo);
3251#endif
James Smart7a06dcd2017-06-01 21:06:55 -07003252 }
James Smart51ef4c22007-08-02 11:10:31 -04003253 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04003254}
3255
James Smarte59058c2008-08-24 21:49:00 -04003256/**
James Smart3621a712009-04-06 18:47:14 -04003257 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04003258 * @vport: lpfc vport structure pointer.
3259 * @val: contains the tmo value.
3260 *
3261 * Description:
3262 * If the devloss tmo is already set or the vport dev loss tmo has changed
3263 * then a kernel error message is printed and zero is returned.
3264 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3265 * Otherwise nodev tmo is set to the default value.
3266 *
3267 * Returns:
3268 * zero if already set or if val is in range
3269 * -EINVAL val out of range
3270 **/
James Smartc01f3202006-08-18 17:47:08 -04003271static int
James Smart3de2a652007-08-02 11:09:59 -04003272lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003273{
James Smart3de2a652007-08-02 11:09:59 -04003274 if (vport->dev_loss_tmo_changed ||
3275 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04003276 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003277 "0401 Ignoring change to lpfc_nodev_tmo "
3278 "because lpfc_devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003279 return 0;
3280 }
James Smartc01f3202006-08-18 17:47:08 -04003281 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003282 vport->cfg_nodev_tmo = val;
3283 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05003284 /*
3285 * For compat: set the fc_host dev loss so new rports
3286 * will get the value.
3287 */
3288 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003289 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003290 return 0;
3291 }
James Smarte8b62012007-08-02 11:10:09 -04003292 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003293 "0403 lpfc_nodev_tmo attribute cannot be set to "
James Smarte8b62012007-08-02 11:10:09 -04003294 "%d, allowed range is [%d, %d]\n",
3295 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003296 return -EINVAL;
3297}
3298
James Smart3de2a652007-08-02 11:09:59 -04003299lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04003300
Joe Perchesb6b996b2017-12-19 10:15:07 -08003301static DEVICE_ATTR_RW(lpfc_nodev_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003302
3303/*
3304# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3305# disappear until the timer expires. Value range is [0,255]. Default
3306# value is 30.
3307*/
James Smartab56dc22011-02-16 12:39:57 -05003308module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04003309MODULE_PARM_DESC(lpfc_devloss_tmo,
3310 "Seconds driver will hold I/O waiting "
3311 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04003312lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3313 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3314lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04003315
3316/**
James Smart3621a712009-04-06 18:47:14 -04003317 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04003318 * @vport: lpfc vport structure pointer.
3319 * @val: contains the tmo value.
3320 *
3321 * Description:
3322 * If val is in a valid range then set the vport nodev tmo,
3323 * devloss tmo, also set the vport dev loss tmo changed flag.
3324 * Else a kernel error message is printed.
3325 *
3326 * Returns:
3327 * zero if val is in range
3328 * -EINVAL val out of range
3329 **/
James Smartc01f3202006-08-18 17:47:08 -04003330static int
James Smart3de2a652007-08-02 11:09:59 -04003331lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003332{
3333 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003334 vport->cfg_nodev_tmo = val;
3335 vport->cfg_devloss_tmo = val;
3336 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05003337 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003338 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003339 return 0;
3340 }
3341
James Smarte8b62012007-08-02 11:10:09 -04003342 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003343 "0404 lpfc_devloss_tmo attribute cannot be set to "
3344 "%d, allowed range is [%d, %d]\n",
James Smarte8b62012007-08-02 11:10:09 -04003345 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003346 return -EINVAL;
3347}
3348
James Smart3de2a652007-08-02 11:09:59 -04003349lpfc_vport_param_store(devloss_tmo)
Joe Perchesb6b996b2017-12-19 10:15:07 -08003350static DEVICE_ATTR_RW(lpfc_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003351
3352/*
James Smartf358dd02017-02-12 13:52:34 -08003353 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3354 * lpfc_suppress_rsp = 0 Disable
3355 * lpfc_suppress_rsp = 1 Enable (default)
3356 *
3357 */
3358LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3359 "Enable suppress rsp feature is firmware supports it");
3360
3361/*
James Smart2d7dbc42017-02-12 13:52:35 -08003362 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3363 * lpfc_nvmet_mrq = 1 use a single RQ pair
3364 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3365 *
3366 */
3367LPFC_ATTR_R(nvmet_mrq,
3368 1, 1, 16,
3369 "Specify number of RQ pairs for processing NVMET cmds");
3370
3371/*
James Smart895427b2017-02-12 13:52:30 -08003372 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3373 * Supported Values: 1 - register just FCP
3374 * 3 - register both FCP and NVME
James Smart7d708032017-03-08 14:36:01 -08003375 * Supported values are [1,3]. Default value is 1
James Smart895427b2017-02-12 13:52:30 -08003376 */
James Smart7d708032017-03-08 14:36:01 -08003377LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP,
James Smart895427b2017-02-12 13:52:30 -08003378 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
Dick Kennedycf4c8c82017-09-29 17:34:38 -07003379 "Enable FC4 Protocol support - FCP / NVME");
James Smart895427b2017-02-12 13:52:30 -08003380
3381/*
3382 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3383 * This parameter is only used if:
James Smartf358dd02017-02-12 13:52:34 -08003384 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3385 * port is not configured for NVMET.
James Smart895427b2017-02-12 13:52:30 -08003386 *
3387 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3388 * The remaining XRIs get split up based on lpfc_xri_split per port:
3389 *
3390 * Supported Values are in percentages
3391 * the xri_split value is the percentage the SCSI port will get. The remaining
3392 * percentage will go to NVME.
3393 */
3394LPFC_ATTR_R(xri_split, 50, 10, 90,
Dick Kennedycf4c8c82017-09-29 17:34:38 -07003395 "Percentage of FCP XRI resources versus NVME");
James Smart895427b2017-02-12 13:52:30 -08003396
3397/*
dea31012005-04-17 16:05:31 -05003398# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3399# deluged with LOTS of information.
3400# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04003401# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05003402*/
James Smartf4b4c682009-05-22 14:53:12 -04003403LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04003404 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05003405
3406/*
James Smart7ee5d432007-10-27 13:37:17 -04003407# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3408# objects that have been registered with the nameserver after login.
3409*/
James Smartcf971242012-03-01 22:37:32 -05003410LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04003411 "Deregister nameserver objects before LOGO");
3412
3413/*
dea31012005-04-17 16:05:31 -05003414# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04003415# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3416# If this parameter value is greater than 1/8th the maximum number of exchanges
3417# supported by the HBA port, then the lun queue depth will be reduced to
3418# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05003419*/
James Smart572709e2013-07-15 18:32:43 -04003420LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04003421 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05003422
3423/*
James Smart7dc517d2010-07-14 15:32:10 -04003424# tgt_queue_depth: This parameter is used to limit the number of outstanding
3425# commands per target port. Value range is [10,65535]. Default value is 65535.
3426*/
3427LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
James Smart572709e2013-07-15 18:32:43 -04003428 "Max number of FCP commands we can queue to a specific target port");
James Smart7dc517d2010-07-14 15:32:10 -04003429
3430/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003431# hba_queue_depth: This parameter is used to limit the number of outstanding
3432# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3433# value is greater than the maximum number of exchanges supported by the HBA,
3434# then maximum number of exchanges supported by the HBA is used to determine
3435# the hba_queue_depth.
3436*/
3437LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3438 "Max number of FCP commands we can queue to a lpfc HBA");
3439
3440/*
James Smart92d7f7b2007-06-17 19:56:38 -05003441# peer_port_login: This parameter allows/prevents logins
3442# between peer ports hosted on the same physical port.
3443# When this parameter is set 0 peer ports of same physical port
3444# are not allowed to login to each other.
3445# When this parameter is set 1 peer ports of same physical port
3446# are allowed to login to each other.
3447# Default value of this parameter is 0.
3448*/
James Smart3de2a652007-08-02 11:09:59 -04003449LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3450 "Allow peer ports on the same physical port to login to each "
3451 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05003452
3453/*
James Smart3de2a652007-08-02 11:09:59 -04003454# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05003455# between Virtual Ports and remote initiators.
3456# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3457# other initiators and will attempt to PLOGI all remote ports.
3458# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3459# remote ports and will not attempt to PLOGI to other initiators.
3460# This parameter does not restrict to the physical port.
3461# This parameter does not restrict logins to Fabric resident remote ports.
3462# Default value of this parameter is 1.
3463*/
James Smart3de2a652007-08-02 11:09:59 -04003464static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05003465module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04003466MODULE_PARM_DESC(lpfc_restrict_login,
3467 "Restrict virtual ports login to remote initiators.");
3468lpfc_vport_param_show(restrict_login);
3469
James Smarte59058c2008-08-24 21:49:00 -04003470/**
James Smart3621a712009-04-06 18:47:14 -04003471 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003472 * @vport: lpfc vport structure pointer.
3473 * @val: contains the restrict login value.
3474 *
3475 * Description:
3476 * If val is not in a valid range then log a kernel error message and set
3477 * the vport restrict login to one.
3478 * If the port type is physical clear the restrict login flag and return.
3479 * Else set the restrict login flag to val.
3480 *
3481 * Returns:
3482 * zero if val is in range
3483 * -EINVAL val out of range
3484 **/
James Smart3de2a652007-08-02 11:09:59 -04003485static int
3486lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3487{
3488 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003489 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003490 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003491 "be set to %d, allowed range is [0, 1]\n",
3492 val);
James Smart3de2a652007-08-02 11:09:59 -04003493 vport->cfg_restrict_login = 1;
3494 return -EINVAL;
3495 }
3496 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3497 vport->cfg_restrict_login = 0;
3498 return 0;
3499 }
3500 vport->cfg_restrict_login = val;
3501 return 0;
3502}
3503
James Smarte59058c2008-08-24 21:49:00 -04003504/**
James Smart3621a712009-04-06 18:47:14 -04003505 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003506 * @vport: lpfc vport structure pointer.
3507 * @val: contains the restrict login value.
3508 *
3509 * Description:
3510 * If val is not in a valid range then log a kernel error message and set
3511 * the vport restrict login to one.
3512 * If the port type is physical and the val is not zero log a kernel
3513 * error message, clear the restrict login flag and return zero.
3514 * Else set the restrict login flag to val.
3515 *
3516 * Returns:
3517 * zero if val is in range
3518 * -EINVAL val out of range
3519 **/
James Smart3de2a652007-08-02 11:09:59 -04003520static int
3521lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3522{
3523 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003524 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003525 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003526 "be set to %d, allowed range is [0, 1]\n",
3527 val);
James Smart3de2a652007-08-02 11:09:59 -04003528 vport->cfg_restrict_login = 1;
3529 return -EINVAL;
3530 }
3531 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04003532 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3533 "0468 lpfc_restrict_login must be 0 for "
3534 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04003535 vport->cfg_restrict_login = 0;
3536 return 0;
3537 }
3538 vport->cfg_restrict_login = val;
3539 return 0;
3540}
3541lpfc_vport_param_store(restrict_login);
Joe Perchesb6b996b2017-12-19 10:15:07 -08003542static DEVICE_ATTR_RW(lpfc_restrict_login);
James Smart92d7f7b2007-06-17 19:56:38 -05003543
3544/*
dea31012005-04-17 16:05:31 -05003545# Some disk devices have a "select ID" or "select Target" capability.
3546# From a protocol standpoint "select ID" usually means select the
3547# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3548# annex" which contains a table that maps a "select ID" (a number
3549# between 0 and 7F) to an ALPA. By default, for compatibility with
3550# older drivers, the lpfc driver scans this table from low ALPA to high
3551# ALPA.
3552#
3553# Turning on the scan-down variable (on = 1, off = 0) will
3554# cause the lpfc driver to use an inverted table, effectively
3555# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3556#
3557# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3558# and will not work across a fabric. Also this parameter will take
3559# effect only in the case when ALPA map is not available.)
3560*/
James Smart3de2a652007-08-02 11:09:59 -04003561LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3562 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05003563
3564/*
dea31012005-04-17 16:05:31 -05003565# lpfc_topology: link topology for init link
3566# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05003567# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05003568# 0x02 = attempt point-to-point mode only
3569# 0x04 = attempt loop mode only
3570# 0x06 = attempt point-to-point mode then loop
3571# Set point-to-point mode if you want to run as an N_Port.
3572# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3573# Default value is 0.
3574*/
James Smart0a035432016-10-13 15:06:10 -07003575LPFC_ATTR(topology, 0, 0, 6,
3576 "Select Fibre Channel topology");
James Smarte59058c2008-08-24 21:49:00 -04003577
3578/**
James Smart3621a712009-04-06 18:47:14 -04003579 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04003580 * @phba: lpfc_hba pointer.
3581 * @val: topology value.
3582 *
3583 * Description:
3584 * If val is in a valid range then set the adapter's topology field and
3585 * issue a lip; if the lip fails reset the topology to the old value.
3586 *
3587 * If the value is not in range log a kernel error message and return an error.
3588 *
3589 * Returns:
3590 * zero if val is in range and lip okay
3591 * non-zero return value from lpfc_issue_lip()
3592 * -EINVAL val out of range
3593 **/
James Smarta257bf92009-04-06 18:48:10 -04003594static ssize_t
3595lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3596 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003597{
James Smarta257bf92009-04-06 18:48:10 -04003598 struct Scsi_Host *shost = class_to_shost(dev);
3599 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3600 struct lpfc_hba *phba = vport->phba;
3601 int val = 0;
3602 int nolip = 0;
3603 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003604 int err;
3605 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003606
3607 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3608 nolip = 1;
3609 val_buf = &buf[strlen("nolip ")];
3610 }
3611
3612 if (!isdigit(val_buf[0]))
3613 return -EINVAL;
3614 if (sscanf(val_buf, "%i", &val) != 1)
3615 return -EINVAL;
3616
James Smart83108bd2008-01-11 01:53:09 -05003617 if (val >= 0 && val <= 6) {
3618 prev_val = phba->cfg_topology;
James Smartff78d8f2011-12-13 13:21:35 -05003619 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3620 val == 4) {
3621 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3622 "3113 Loop mode not supported at speed %d\n",
James Smartd38dd522015-08-31 16:48:17 -04003623 val);
James Smartff78d8f2011-12-13 13:21:35 -05003624 return -EINVAL;
3625 }
James Smartd38dd522015-08-31 16:48:17 -04003626 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3627 val == 4) {
3628 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3629 "3114 Loop mode not supported\n");
3630 return -EINVAL;
3631 }
3632 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04003633 if (nolip)
3634 return strlen(buf);
3635
James Smart88a2cfb2011-07-22 18:36:33 -04003636 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3637 "3054 lpfc_topology changed from %d to %d\n",
3638 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04003639 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3640 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05003641 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003642 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003643 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003644 return -EINVAL;
3645 } else
3646 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003647 }
3648 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3649 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3650 "allowed range is [0, 6]\n",
3651 phba->brd_no, val);
3652 return -EINVAL;
3653}
James Smart0a035432016-10-13 15:06:10 -07003654
James Smart83108bd2008-01-11 01:53:09 -05003655lpfc_param_show(topology)
Joe Perchesb6b996b2017-12-19 10:15:07 -08003656static DEVICE_ATTR_RW(lpfc_topology);
dea31012005-04-17 16:05:31 -05003657
James Smart21e9a0a2009-05-22 14:53:21 -04003658/**
3659 * lpfc_static_vport_show: Read callback function for
3660 * lpfc_static_vport sysfs file.
3661 * @dev: Pointer to class device object.
3662 * @attr: device attribute structure.
3663 * @buf: Data buffer.
3664 *
3665 * This function is the read call back function for
3666 * lpfc_static_vport sysfs file. The lpfc_static_vport
3667 * sysfs file report the mageability of the vport.
3668 **/
3669static ssize_t
3670lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3671 char *buf)
3672{
3673 struct Scsi_Host *shost = class_to_shost(dev);
3674 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3675 if (vport->vport_flag & STATIC_VPORT)
3676 sprintf(buf, "1\n");
3677 else
3678 sprintf(buf, "0\n");
3679
3680 return strlen(buf);
3681}
3682
3683/*
3684 * Sysfs attribute to control the statistical data collection.
3685 */
Joe Perchesc828a892017-12-19 10:15:08 -08003686static DEVICE_ATTR_RO(lpfc_static_vport);
James Smartea2151b2008-09-07 11:52:10 -04003687
3688/**
James Smart3621a712009-04-06 18:47:14 -04003689 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003690 * @dev: Pointer to class device.
3691 * @buf: Data buffer.
3692 * @count: Size of the data buffer.
3693 *
Masahiro Yamada9332ef92017-02-27 14:28:47 -08003694 * This function get called when a user write to the lpfc_stat_data_ctrl
James Smartea2151b2008-09-07 11:52:10 -04003695 * sysfs file. This function parse the command written to the sysfs file
3696 * and take appropriate action. These commands are used for controlling
3697 * driver statistical data collection.
3698 * Following are the command this function handles.
3699 *
3700 * setbucket <bucket_type> <base> <step>
3701 * = Set the latency buckets.
3702 * destroybucket = destroy all the buckets.
3703 * start = start data collection
3704 * stop = stop data collection
3705 * reset = reset the collected data
3706 **/
3707static ssize_t
3708lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3709 const char *buf, size_t count)
3710{
3711 struct Scsi_Host *shost = class_to_shost(dev);
3712 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3713 struct lpfc_hba *phba = vport->phba;
3714#define LPFC_MAX_DATA_CTRL_LEN 1024
3715 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3716 unsigned long i;
3717 char *str_ptr, *token;
3718 struct lpfc_vport **vports;
3719 struct Scsi_Host *v_shost;
3720 char *bucket_type_str, *base_str, *step_str;
3721 unsigned long base, step, bucket_type;
3722
3723 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04003724 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04003725 return -EINVAL;
3726
James Smarteb016562014-09-03 12:58:06 -04003727 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
James Smartea2151b2008-09-07 11:52:10 -04003728 str_ptr = &bucket_data[0];
3729 /* Ignore this token - this is command token */
3730 token = strsep(&str_ptr, "\t ");
3731 if (!token)
3732 return -EINVAL;
3733
3734 bucket_type_str = strsep(&str_ptr, "\t ");
3735 if (!bucket_type_str)
3736 return -EINVAL;
3737
3738 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3739 bucket_type = LPFC_LINEAR_BUCKET;
3740 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3741 bucket_type = LPFC_POWER2_BUCKET;
3742 else
3743 return -EINVAL;
3744
3745 base_str = strsep(&str_ptr, "\t ");
3746 if (!base_str)
3747 return -EINVAL;
3748 base = simple_strtoul(base_str, NULL, 0);
3749
3750 step_str = strsep(&str_ptr, "\t ");
3751 if (!step_str)
3752 return -EINVAL;
3753 step = simple_strtoul(step_str, NULL, 0);
3754 if (!step)
3755 return -EINVAL;
3756
3757 /* Block the data collection for every vport */
3758 vports = lpfc_create_vport_work_array(phba);
3759 if (vports == NULL)
3760 return -ENOMEM;
3761
James Smartf4b4c682009-05-22 14:53:12 -04003762 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003763 v_shost = lpfc_shost_from_vport(vports[i]);
3764 spin_lock_irq(v_shost->host_lock);
3765 /* Block and reset data collection */
3766 vports[i]->stat_data_blocked = 1;
3767 if (vports[i]->stat_data_enabled)
3768 lpfc_vport_reset_stat_data(vports[i]);
3769 spin_unlock_irq(v_shost->host_lock);
3770 }
3771
3772 /* Set the bucket attributes */
3773 phba->bucket_type = bucket_type;
3774 phba->bucket_base = base;
3775 phba->bucket_step = step;
3776
James Smartf4b4c682009-05-22 14:53:12 -04003777 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003778 v_shost = lpfc_shost_from_vport(vports[i]);
3779
3780 /* Unblock data collection */
3781 spin_lock_irq(v_shost->host_lock);
3782 vports[i]->stat_data_blocked = 0;
3783 spin_unlock_irq(v_shost->host_lock);
3784 }
3785 lpfc_destroy_vport_work_array(phba, vports);
3786 return strlen(buf);
3787 }
3788
3789 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3790 vports = lpfc_create_vport_work_array(phba);
3791 if (vports == NULL)
3792 return -ENOMEM;
3793
James Smartf4b4c682009-05-22 14:53:12 -04003794 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003795 v_shost = lpfc_shost_from_vport(vports[i]);
3796 spin_lock_irq(shost->host_lock);
3797 vports[i]->stat_data_blocked = 1;
3798 lpfc_free_bucket(vport);
3799 vport->stat_data_enabled = 0;
3800 vports[i]->stat_data_blocked = 0;
3801 spin_unlock_irq(shost->host_lock);
3802 }
3803 lpfc_destroy_vport_work_array(phba, vports);
3804 phba->bucket_type = LPFC_NO_BUCKET;
3805 phba->bucket_base = 0;
3806 phba->bucket_step = 0;
3807 return strlen(buf);
3808 }
3809
3810 if (!strncmp(buf, "start", strlen("start"))) {
3811 /* If no buckets configured return error */
3812 if (phba->bucket_type == LPFC_NO_BUCKET)
3813 return -EINVAL;
3814 spin_lock_irq(shost->host_lock);
3815 if (vport->stat_data_enabled) {
3816 spin_unlock_irq(shost->host_lock);
3817 return strlen(buf);
3818 }
3819 lpfc_alloc_bucket(vport);
3820 vport->stat_data_enabled = 1;
3821 spin_unlock_irq(shost->host_lock);
3822 return strlen(buf);
3823 }
3824
3825 if (!strncmp(buf, "stop", strlen("stop"))) {
3826 spin_lock_irq(shost->host_lock);
3827 if (vport->stat_data_enabled == 0) {
3828 spin_unlock_irq(shost->host_lock);
3829 return strlen(buf);
3830 }
3831 lpfc_free_bucket(vport);
3832 vport->stat_data_enabled = 0;
3833 spin_unlock_irq(shost->host_lock);
3834 return strlen(buf);
3835 }
3836
3837 if (!strncmp(buf, "reset", strlen("reset"))) {
3838 if ((phba->bucket_type == LPFC_NO_BUCKET)
3839 || !vport->stat_data_enabled)
3840 return strlen(buf);
3841 spin_lock_irq(shost->host_lock);
3842 vport->stat_data_blocked = 1;
3843 lpfc_vport_reset_stat_data(vport);
3844 vport->stat_data_blocked = 0;
3845 spin_unlock_irq(shost->host_lock);
3846 return strlen(buf);
3847 }
3848 return -EINVAL;
3849}
3850
3851
3852/**
James Smart3621a712009-04-06 18:47:14 -04003853 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003854 * @dev: Pointer to class device object.
3855 * @buf: Data buffer.
3856 *
3857 * This function is the read call back function for
3858 * lpfc_stat_data_ctrl sysfs file. This function report the
3859 * current statistical data collection state.
3860 **/
3861static ssize_t
3862lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3863 char *buf)
3864{
3865 struct Scsi_Host *shost = class_to_shost(dev);
3866 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3867 struct lpfc_hba *phba = vport->phba;
3868 int index = 0;
3869 int i;
3870 char *bucket_type;
3871 unsigned long bucket_value;
3872
3873 switch (phba->bucket_type) {
3874 case LPFC_LINEAR_BUCKET:
3875 bucket_type = "linear";
3876 break;
3877 case LPFC_POWER2_BUCKET:
3878 bucket_type = "power2";
3879 break;
3880 default:
3881 bucket_type = "No Bucket";
3882 break;
3883 }
3884
3885 sprintf(&buf[index], "Statistical Data enabled :%d, "
3886 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3887 " Bucket step :%d\nLatency Ranges :",
3888 vport->stat_data_enabled, vport->stat_data_blocked,
3889 bucket_type, phba->bucket_base, phba->bucket_step);
3890 index = strlen(buf);
3891 if (phba->bucket_type != LPFC_NO_BUCKET) {
3892 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3893 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3894 bucket_value = phba->bucket_base +
3895 phba->bucket_step * i;
3896 else
3897 bucket_value = phba->bucket_base +
3898 (1 << i) * phba->bucket_step;
3899
3900 if (index + 10 > PAGE_SIZE)
3901 break;
3902 sprintf(&buf[index], "%08ld ", bucket_value);
3903 index = strlen(buf);
3904 }
3905 }
3906 sprintf(&buf[index], "\n");
3907 return strlen(buf);
3908}
3909
3910/*
3911 * Sysfs attribute to control the statistical data collection.
3912 */
Joe Perchesb6b996b2017-12-19 10:15:07 -08003913static DEVICE_ATTR_RW(lpfc_stat_data_ctrl);
James Smartea2151b2008-09-07 11:52:10 -04003914
3915/*
3916 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3917 */
3918
3919/*
3920 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3921 * for each target.
3922 */
3923#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3924#define MAX_STAT_DATA_SIZE_PER_TARGET \
3925 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3926
3927
3928/**
James Smart3621a712009-04-06 18:47:14 -04003929 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003930 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003931 * @kobj: Pointer to the kernel object
3932 * @bin_attr: Attribute object
3933 * @buff: Buffer pointer
3934 * @off: File offset
3935 * @count: Buffer size
3936 *
3937 * This function is the read call back function for lpfc_drvr_stat_data
3938 * sysfs file. This function export the statistical data to user
3939 * applications.
3940 **/
3941static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003942sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3943 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003944 char *buf, loff_t off, size_t count)
3945{
3946 struct device *dev = container_of(kobj, struct device,
3947 kobj);
3948 struct Scsi_Host *shost = class_to_shost(dev);
3949 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3950 struct lpfc_hba *phba = vport->phba;
3951 int i = 0, index = 0;
3952 unsigned long nport_index;
3953 struct lpfc_nodelist *ndlp = NULL;
3954 nport_index = (unsigned long)off /
3955 MAX_STAT_DATA_SIZE_PER_TARGET;
3956
3957 if (!vport->stat_data_enabled || vport->stat_data_blocked
3958 || (phba->bucket_type == LPFC_NO_BUCKET))
3959 return 0;
3960
3961 spin_lock_irq(shost->host_lock);
3962 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3963 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3964 continue;
3965
3966 if (nport_index > 0) {
3967 nport_index--;
3968 continue;
3969 }
3970
3971 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3972 > count)
3973 break;
3974
3975 if (!ndlp->lat_data)
3976 continue;
3977
3978 /* Print the WWN */
3979 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3980 ndlp->nlp_portname.u.wwn[0],
3981 ndlp->nlp_portname.u.wwn[1],
3982 ndlp->nlp_portname.u.wwn[2],
3983 ndlp->nlp_portname.u.wwn[3],
3984 ndlp->nlp_portname.u.wwn[4],
3985 ndlp->nlp_portname.u.wwn[5],
3986 ndlp->nlp_portname.u.wwn[6],
3987 ndlp->nlp_portname.u.wwn[7]);
3988
3989 index = strlen(buf);
3990
3991 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3992 sprintf(&buf[index], "%010u,",
3993 ndlp->lat_data[i].cmd_count);
3994 index = strlen(buf);
3995 }
3996 sprintf(&buf[index], "\n");
3997 index = strlen(buf);
3998 }
3999 spin_unlock_irq(shost->host_lock);
4000 return index;
4001}
4002
4003static struct bin_attribute sysfs_drvr_stat_data_attr = {
4004 .attr = {
4005 .name = "lpfc_drvr_stat_data",
4006 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04004007 },
4008 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
4009 .read = sysfs_drvr_stat_data_read,
4010 .write = NULL,
4011};
4012
dea31012005-04-17 16:05:31 -05004013/*
4014# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4015# connection.
James Smart76a95d72010-11-20 23:11:48 -05004016# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05004017*/
James Smarte59058c2008-08-24 21:49:00 -04004018/**
James Smart3621a712009-04-06 18:47:14 -04004019 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004020 * @phba: lpfc_hba pointer.
4021 * @val: link speed value.
4022 *
4023 * Description:
4024 * If val is in a valid range then set the adapter's link speed field and
4025 * issue a lip; if the lip fails reset the link speed to the old value.
4026 *
4027 * Notes:
4028 * If the value is not in range log a kernel error message and return an error.
4029 *
4030 * Returns:
4031 * zero if val is in range and lip okay.
4032 * non-zero return value from lpfc_issue_lip()
4033 * -EINVAL val out of range
4034 **/
James Smarta257bf92009-04-06 18:48:10 -04004035static ssize_t
4036lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4037 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05004038{
James Smarta257bf92009-04-06 18:48:10 -04004039 struct Scsi_Host *shost = class_to_shost(dev);
4040 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4041 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05004042 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04004043 int nolip = 0;
4044 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05004045 int err;
James Smartc6918162016-10-13 15:06:16 -07004046 uint32_t prev_val, if_type;
4047
4048 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4049 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
4050 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4051 return -EPERM;
James Smart83108bd2008-01-11 01:53:09 -05004052
James Smarta257bf92009-04-06 18:48:10 -04004053 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4054 nolip = 1;
4055 val_buf = &buf[strlen("nolip ")];
4056 }
4057
4058 if (!isdigit(val_buf[0]))
4059 return -EINVAL;
4060 if (sscanf(val_buf, "%i", &val) != 1)
4061 return -EINVAL;
4062
James Smart88a2cfb2011-07-22 18:36:33 -04004063 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4064 "3055 lpfc_link_speed changed from %d to %d %s\n",
4065 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4066
James Smart76a95d72010-11-20 23:11:48 -05004067 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4068 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4069 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4070 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4071 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
James Smartd38dd522015-08-31 16:48:17 -04004072 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4073 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
James Smart76a95d72010-11-20 23:11:48 -05004074 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4075 "2879 lpfc_link_speed attribute cannot be set "
4076 "to %d. Speed is not supported by this port.\n",
4077 val);
James Smart83108bd2008-01-11 01:53:09 -05004078 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05004079 }
James Smartff78d8f2011-12-13 13:21:35 -05004080 if (val == LPFC_USER_LINK_SPEED_16G &&
4081 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4082 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4083 "3112 lpfc_link_speed attribute cannot be set "
4084 "to %d. Speed is not supported in loop mode.\n",
4085 val);
4086 return -EINVAL;
4087 }
James Smart76a95d72010-11-20 23:11:48 -05004088 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4089 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05004090 prev_val = phba->cfg_link_speed;
4091 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04004092 if (nolip)
4093 return strlen(buf);
4094
James Smart83108bd2008-01-11 01:53:09 -05004095 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04004096 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05004097 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04004098 return -EINVAL;
4099 } else
4100 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05004101 }
James Smart83108bd2008-01-11 01:53:09 -05004102 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05004103 "0469 lpfc_link_speed attribute cannot be set to %d, "
4104 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05004105 return -EINVAL;
4106}
4107
4108static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05004109module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05004110MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4111lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04004112
4113/**
James Smart3621a712009-04-06 18:47:14 -04004114 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004115 * @phba: lpfc_hba pointer.
4116 * @val: link speed value.
4117 *
4118 * Description:
4119 * If val is in a valid range then set the adapter's link speed field.
4120 *
4121 * Notes:
4122 * If the value is not in range log a kernel error message, clear the link
4123 * speed and return an error.
4124 *
4125 * Returns:
4126 * zero if val saved.
4127 * -EINVAL val out of range
4128 **/
James Smart83108bd2008-01-11 01:53:09 -05004129static int
4130lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4131{
James Smartff78d8f2011-12-13 13:21:35 -05004132 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4133 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4134 "3111 lpfc_link_speed of %d cannot "
4135 "support loop mode, setting topology to default.\n",
4136 val);
4137 phba->cfg_topology = 0;
4138 }
James Smart76a95d72010-11-20 23:11:48 -05004139 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4140 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05004141 phba->cfg_link_speed = val;
4142 return 0;
4143 }
4144 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004145 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05004146 "be set to %d, allowed values are "
4147 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05004148 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05004149 return -EINVAL;
4150}
4151
Joe Perchesb6b996b2017-12-19 10:15:07 -08004152static DEVICE_ATTR_RW(lpfc_link_speed);
dea31012005-04-17 16:05:31 -05004153
4154/*
James Smart0d878412009-10-02 15:16:56 -04004155# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4156# 0 = aer disabled or not supported
4157# 1 = aer supported and enabled (default)
4158# Value range is [0,1]. Default value is 1.
4159*/
James Smart506139a2016-10-13 15:06:09 -07004160LPFC_ATTR(aer_support, 1, 0, 1,
4161 "Enable PCIe device AER support");
4162lpfc_param_show(aer_support)
James Smart0d878412009-10-02 15:16:56 -04004163
4164/**
4165 * lpfc_aer_support_store - Set the adapter for aer support
4166 *
4167 * @dev: class device that is converted into a Scsi_host.
4168 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004169 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04004170 * @count: unused variable.
4171 *
4172 * Description:
4173 * If the val is 1 and currently the device's AER capability was not
4174 * enabled, invoke the kernel's enable AER helper routine, trying to
4175 * enable the device's AER capability. If the helper routine enabling
4176 * AER returns success, update the device's cfg_aer_support flag to
4177 * indicate AER is supported by the device; otherwise, if the device
4178 * AER capability is already enabled to support AER, then do nothing.
4179 *
4180 * If the val is 0 and currently the device's AER support was enabled,
4181 * invoke the kernel's disable AER helper routine. After that, update
4182 * the device's cfg_aer_support flag to indicate AER is not supported
4183 * by the device; otherwise, if the device AER capability is already
4184 * disabled from supporting AER, then do nothing.
4185 *
4186 * Returns:
4187 * length of the buf on success if val is in range the intended mode
4188 * is supported.
4189 * -EINVAL if val out of range or intended mode is not supported.
4190 **/
4191static ssize_t
4192lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4193 const char *buf, size_t count)
4194{
4195 struct Scsi_Host *shost = class_to_shost(dev);
4196 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4197 struct lpfc_hba *phba = vport->phba;
4198 int val = 0, rc = -EINVAL;
4199
4200 if (!isdigit(buf[0]))
4201 return -EINVAL;
4202 if (sscanf(buf, "%i", &val) != 1)
4203 return -EINVAL;
4204
4205 switch (val) {
4206 case 0:
4207 if (phba->hba_flag & HBA_AER_ENABLED) {
4208 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4209 if (!rc) {
4210 spin_lock_irq(&phba->hbalock);
4211 phba->hba_flag &= ~HBA_AER_ENABLED;
4212 spin_unlock_irq(&phba->hbalock);
4213 phba->cfg_aer_support = 0;
4214 rc = strlen(buf);
4215 } else
James Smart891478a2009-11-18 15:40:23 -05004216 rc = -EPERM;
4217 } else {
James Smart0d878412009-10-02 15:16:56 -04004218 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05004219 rc = strlen(buf);
4220 }
James Smart0d878412009-10-02 15:16:56 -04004221 break;
4222 case 1:
4223 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4224 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4225 if (!rc) {
4226 spin_lock_irq(&phba->hbalock);
4227 phba->hba_flag |= HBA_AER_ENABLED;
4228 spin_unlock_irq(&phba->hbalock);
4229 phba->cfg_aer_support = 1;
4230 rc = strlen(buf);
4231 } else
James Smart891478a2009-11-18 15:40:23 -05004232 rc = -EPERM;
4233 } else {
James Smart0d878412009-10-02 15:16:56 -04004234 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05004235 rc = strlen(buf);
4236 }
James Smart0d878412009-10-02 15:16:56 -04004237 break;
4238 default:
4239 rc = -EINVAL;
4240 break;
4241 }
4242 return rc;
4243}
4244
Joe Perchesb6b996b2017-12-19 10:15:07 -08004245static DEVICE_ATTR_RW(lpfc_aer_support);
James Smart0d878412009-10-02 15:16:56 -04004246
4247/**
4248 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4249 * @dev: class device that is converted into a Scsi_host.
4250 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004251 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04004252 * @count: unused variable.
4253 *
4254 * Description:
4255 * If the @buf contains 1 and the device currently has the AER support
4256 * enabled, then invokes the kernel AER helper routine
4257 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4258 * error status register.
4259 *
4260 * Notes:
4261 *
4262 * Returns:
4263 * -EINVAL if the buf does not contain the 1 or the device is not currently
4264 * enabled with the AER support.
4265 **/
4266static ssize_t
4267lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4268 const char *buf, size_t count)
4269{
4270 struct Scsi_Host *shost = class_to_shost(dev);
4271 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4272 struct lpfc_hba *phba = vport->phba;
4273 int val, rc = -1;
4274
4275 if (!isdigit(buf[0]))
4276 return -EINVAL;
4277 if (sscanf(buf, "%i", &val) != 1)
4278 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05004279 if (val != 1)
4280 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04004281
James Smart891478a2009-11-18 15:40:23 -05004282 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04004283 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4284
4285 if (rc == 0)
4286 return strlen(buf);
4287 else
James Smart891478a2009-11-18 15:40:23 -05004288 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04004289}
4290
4291static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4292 lpfc_aer_cleanup_state);
4293
James Smart912e3ac2011-05-24 11:42:11 -04004294/**
4295 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4296 *
4297 * @dev: class device that is converted into a Scsi_host.
4298 * @attr: device attribute, not used.
4299 * @buf: containing the string the number of vfs to be enabled.
4300 * @count: unused variable.
4301 *
4302 * Description:
4303 * When this api is called either through user sysfs, the driver shall
4304 * try to enable or disable SR-IOV virtual functions according to the
4305 * following:
4306 *
4307 * If zero virtual function has been enabled to the physical function,
4308 * the driver shall invoke the pci enable virtual function api trying
4309 * to enable the virtual functions. If the nr_vfn provided is greater
4310 * than the maximum supported, the maximum virtual function number will
4311 * be used for invoking the api; otherwise, the nr_vfn provided shall
4312 * be used for invoking the api. If the api call returned success, the
4313 * actual number of virtual functions enabled will be set to the driver
4314 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4315 * cfg_sriov_nr_virtfn remains zero.
4316 *
4317 * If none-zero virtual functions have already been enabled to the
4318 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4319 * -EINVAL will be returned and the driver does nothing;
4320 *
4321 * If the nr_vfn provided is zero and none-zero virtual functions have
4322 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4323 * disabling virtual function api shall be invoded to disable all the
4324 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4325 * zero. Otherwise, if zero virtual function has been enabled, do
4326 * nothing.
4327 *
4328 * Returns:
4329 * length of the buf on success if val is in range the intended mode
4330 * is supported.
4331 * -EINVAL if val out of range or intended mode is not supported.
4332 **/
4333static ssize_t
4334lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4335 const char *buf, size_t count)
4336{
4337 struct Scsi_Host *shost = class_to_shost(dev);
4338 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4339 struct lpfc_hba *phba = vport->phba;
4340 struct pci_dev *pdev = phba->pcidev;
4341 int val = 0, rc = -EINVAL;
4342
4343 /* Sanity check on user data */
4344 if (!isdigit(buf[0]))
4345 return -EINVAL;
4346 if (sscanf(buf, "%i", &val) != 1)
4347 return -EINVAL;
4348 if (val < 0)
4349 return -EINVAL;
4350
4351 /* Request disabling virtual functions */
4352 if (val == 0) {
4353 if (phba->cfg_sriov_nr_virtfn > 0) {
4354 pci_disable_sriov(pdev);
4355 phba->cfg_sriov_nr_virtfn = 0;
4356 }
4357 return strlen(buf);
4358 }
4359
4360 /* Request enabling virtual functions */
4361 if (phba->cfg_sriov_nr_virtfn > 0) {
4362 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4363 "3018 There are %d virtual functions "
4364 "enabled on physical function.\n",
4365 phba->cfg_sriov_nr_virtfn);
4366 return -EEXIST;
4367 }
4368
4369 if (val <= LPFC_MAX_VFN_PER_PFN)
4370 phba->cfg_sriov_nr_virtfn = val;
4371 else {
4372 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4373 "3019 Enabling %d virtual functions is not "
4374 "allowed.\n", val);
4375 return -EINVAL;
4376 }
4377
4378 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4379 if (rc) {
4380 phba->cfg_sriov_nr_virtfn = 0;
4381 rc = -EPERM;
4382 } else
4383 rc = strlen(buf);
4384
4385 return rc;
4386}
4387
James Smart0cfbbf22016-10-13 15:06:12 -07004388LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4389 "Enable PCIe device SR-IOV virtual fn");
4390
James Smart912e3ac2011-05-24 11:42:11 -04004391lpfc_param_show(sriov_nr_virtfn)
Joe Perchesb6b996b2017-12-19 10:15:07 -08004392static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04004393
James Smart173edbb2012-06-12 13:54:50 -04004394/**
James Smartc71ab862012-10-31 14:44:33 -04004395 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4396 *
4397 * @dev: class device that is converted into a Scsi_host.
4398 * @attr: device attribute, not used.
4399 * @buf: containing the string the number of vfs to be enabled.
4400 * @count: unused variable.
4401 *
4402 * Description:
4403 *
4404 * Returns:
4405 * length of the buf on success if val is in range the intended mode
4406 * is supported.
4407 * -EINVAL if val out of range or intended mode is not supported.
4408 **/
4409static ssize_t
4410lpfc_request_firmware_upgrade_store(struct device *dev,
4411 struct device_attribute *attr,
4412 const char *buf, size_t count)
4413{
4414 struct Scsi_Host *shost = class_to_shost(dev);
4415 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4416 struct lpfc_hba *phba = vport->phba;
4417 int val = 0, rc = -EINVAL;
4418
4419 /* Sanity check on user data */
4420 if (!isdigit(buf[0]))
4421 return -EINVAL;
4422 if (sscanf(buf, "%i", &val) != 1)
4423 return -EINVAL;
4424 if (val != 1)
4425 return -EINVAL;
4426
4427 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4428 if (rc)
4429 rc = -EPERM;
4430 else
4431 rc = strlen(buf);
4432 return rc;
4433}
4434
4435static int lpfc_req_fw_upgrade;
4436module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4437MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4438lpfc_param_show(request_firmware_upgrade)
4439
4440/**
4441 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4442 * @phba: lpfc_hba pointer.
4443 * @val: 0 or 1.
4444 *
4445 * Description:
4446 * Set the initial Linux generic firmware upgrade enable or disable flag.
4447 *
4448 * Returns:
4449 * zero if val saved.
4450 * -EINVAL val out of range
4451 **/
4452static int
4453lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4454{
4455 if (val >= 0 && val <= 1) {
4456 phba->cfg_request_firmware_upgrade = val;
4457 return 0;
4458 }
4459 return -EINVAL;
4460}
4461static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4462 lpfc_request_firmware_upgrade_show,
4463 lpfc_request_firmware_upgrade_store);
4464
4465/**
James Smart173edbb2012-06-12 13:54:50 -04004466 * lpfc_fcp_imax_store
4467 *
4468 * @dev: class device that is converted into a Scsi_host.
4469 * @attr: device attribute, not used.
4470 * @buf: string with the number of fast-path FCP interrupts per second.
4471 * @count: unused variable.
4472 *
4473 * Description:
4474 * If val is in a valid range [636,651042], then set the adapter's
4475 * maximum number of fast-path FCP interrupts per second.
4476 *
4477 * Returns:
4478 * length of the buf on success if val is in range the intended mode
4479 * is supported.
4480 * -EINVAL if val out of range or intended mode is not supported.
4481 **/
4482static ssize_t
4483lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4484 const char *buf, size_t count)
4485{
4486 struct Scsi_Host *shost = class_to_shost(dev);
4487 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4488 struct lpfc_hba *phba = vport->phba;
4489 int val = 0, i;
4490
James Smartbf8dae82012-08-03 12:36:24 -04004491 /* fcp_imax is only valid for SLI4 */
4492 if (phba->sli_rev != LPFC_SLI_REV4)
4493 return -EINVAL;
4494
James Smart173edbb2012-06-12 13:54:50 -04004495 /* Sanity check on user data */
4496 if (!isdigit(buf[0]))
4497 return -EINVAL;
4498 if (sscanf(buf, "%i", &val) != 1)
4499 return -EINVAL;
4500
James Smartbf8dae82012-08-03 12:36:24 -04004501 /*
4502 * Value range for the HBA is [5000,5000000]
4503 * The value for each EQ depends on how many EQs are configured.
James Smart895427b2017-02-12 13:52:30 -08004504 * Allow value == 0
James Smartbf8dae82012-08-03 12:36:24 -04004505 */
James Smart895427b2017-02-12 13:52:30 -08004506 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
James Smart173edbb2012-06-12 13:54:50 -04004507 return -EINVAL;
4508
4509 phba->cfg_fcp_imax = (uint32_t)val;
James Smart0cf07f842017-06-01 21:07:10 -07004510 phba->initial_imax = phba->cfg_fcp_imax;
James Smart43140ca2017-03-04 09:30:34 -08004511
4512 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart0cf07f842017-06-01 21:07:10 -07004513 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4514 val);
James Smart173edbb2012-06-12 13:54:50 -04004515
4516 return strlen(buf);
4517}
4518
4519/*
4520# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04004521# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04004522#
James Smartbf8dae82012-08-03 12:36:24 -04004523# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04004524*/
James Smartbf8dae82012-08-03 12:36:24 -04004525static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004526module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4527MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04004528 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04004529lpfc_param_show(fcp_imax)
4530
4531/**
4532 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4533 * @phba: lpfc_hba pointer.
4534 * @val: link speed value.
4535 *
4536 * Description:
4537 * If val is in a valid range [636,651042], then initialize the adapter's
4538 * maximum number of fast-path FCP interrupts per second.
4539 *
4540 * Returns:
4541 * zero if val saved.
4542 * -EINVAL val out of range
4543 **/
4544static int
4545lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4546{
James Smartbf8dae82012-08-03 12:36:24 -04004547 if (phba->sli_rev != LPFC_SLI_REV4) {
4548 phba->cfg_fcp_imax = 0;
4549 return 0;
4550 }
4551
James Smart895427b2017-02-12 13:52:30 -08004552 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4553 (val == 0)) {
James Smart173edbb2012-06-12 13:54:50 -04004554 phba->cfg_fcp_imax = val;
4555 return 0;
4556 }
4557
4558 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004559 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4560 val);
James Smartbf8dae82012-08-03 12:36:24 -04004561 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004562
4563 return 0;
4564}
4565
Joe Perchesb6b996b2017-12-19 10:15:07 -08004566static DEVICE_ATTR_RW(lpfc_fcp_imax);
James Smart173edbb2012-06-12 13:54:50 -04004567
James Smart0cf07f842017-06-01 21:07:10 -07004568/*
4569 * lpfc_auto_imax: Controls Auto-interrupt coalescing values support.
4570 * 0 No auto_imax support
4571 * 1 auto imax on
4572 * Auto imax will change the value of fcp_imax on a per EQ basis, using
4573 * the EQ Delay Multiplier, depending on the activity for that EQ.
4574 * Value range [0,1]. Default value is 1.
4575 */
4576LPFC_ATTR_RW(auto_imax, 1, 0, 1, "Enable Auto imax");
4577
James Smart7bb03bb2013-04-17 20:19:16 -04004578/**
4579 * lpfc_state_show - Display current driver CPU affinity
4580 * @dev: class converted to a Scsi_host structure.
4581 * @attr: device attribute, not used.
4582 * @buf: on return contains text describing the state of the link.
4583 *
4584 * Returns: size of formatted string.
4585 **/
4586static ssize_t
4587lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4588 char *buf)
4589{
4590 struct Scsi_Host *shost = class_to_shost(dev);
4591 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4592 struct lpfc_hba *phba = vport->phba;
4593 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05004594 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04004595
4596 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4597 (phba->intr_type != MSIX))
4598 return len;
4599
4600 switch (phba->cfg_fcp_cpu_map) {
4601 case 0:
4602 len += snprintf(buf + len, PAGE_SIZE-len,
4603 "fcp_cpu_map: No mapping (%d)\n",
4604 phba->cfg_fcp_cpu_map);
4605 return len;
4606 case 1:
4607 len += snprintf(buf + len, PAGE_SIZE-len,
4608 "fcp_cpu_map: HBA centric mapping (%d): "
4609 "%d online CPUs\n",
4610 phba->cfg_fcp_cpu_map,
4611 phba->sli4_hba.num_online_cpu);
4612 break;
4613 case 2:
4614 len += snprintf(buf + len, PAGE_SIZE-len,
4615 "fcp_cpu_map: Driver centric mapping (%d): "
4616 "%d online CPUs\n",
4617 phba->cfg_fcp_cpu_map,
4618 phba->sli4_hba.num_online_cpu);
4619 break;
4620 }
4621
James Smart76fd07a2014-02-20 09:57:18 -05004622 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4623 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4624
4625 /* margin should fit in this and the truncated message */
James Smart7bb03bb2013-04-17 20:19:16 -04004626 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4627 len += snprintf(buf + len, PAGE_SIZE-len,
4628 "CPU %02d io_chan %02d "
4629 "physid %d coreid %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004630 phba->sli4_hba.curr_disp_cpu,
4631 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004632 cpup->core_id);
4633 else
4634 len += snprintf(buf + len, PAGE_SIZE-len,
4635 "CPU %02d io_chan %02d "
4636 "physid %d coreid %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004637 phba->sli4_hba.curr_disp_cpu,
4638 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004639 cpup->core_id, cpup->irq);
4640
James Smart76fd07a2014-02-20 09:57:18 -05004641 phba->sli4_hba.curr_disp_cpu++;
4642
4643 /* display max number of CPUs keeping some margin */
4644 if (phba->sli4_hba.curr_disp_cpu <
4645 phba->sli4_hba.num_present_cpu &&
4646 (len >= (PAGE_SIZE - 64))) {
4647 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4648 break;
4649 }
James Smart7bb03bb2013-04-17 20:19:16 -04004650 }
James Smart76fd07a2014-02-20 09:57:18 -05004651
4652 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4653 phba->sli4_hba.curr_disp_cpu = 0;
4654
James Smart7bb03bb2013-04-17 20:19:16 -04004655 return len;
4656}
4657
4658/**
4659 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4660 * @dev: class device that is converted into a Scsi_host.
4661 * @attr: device attribute, not used.
4662 * @buf: one or more lpfc_polling_flags values.
4663 * @count: not used.
4664 *
4665 * Returns:
4666 * -EINVAL - Not implemented yet.
4667 **/
4668static ssize_t
4669lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4670 const char *buf, size_t count)
4671{
4672 int status = -EINVAL;
4673 return status;
4674}
4675
4676/*
4677# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4678# for the HBA.
4679#
4680# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4681# 0 - Do not affinitze IRQ vectors
4682# 1 - Affintize HBA vectors with respect to each HBA
4683# (start with CPU0 for each HBA)
4684# 2 - Affintize HBA vectors with respect to the entire driver
4685# (round robin thru all CPUs across all HBAs)
4686*/
4687static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4688module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4689MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4690 "Defines how to map CPUs to IRQ vectors per HBA");
4691
4692/**
4693 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4694 * @phba: lpfc_hba pointer.
4695 * @val: link speed value.
4696 *
4697 * Description:
4698 * If val is in a valid range [0-2], then affinitze the adapter's
4699 * MSIX vectors.
4700 *
4701 * Returns:
4702 * zero if val saved.
4703 * -EINVAL val out of range
4704 **/
4705static int
4706lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4707{
4708 if (phba->sli_rev != LPFC_SLI_REV4) {
4709 phba->cfg_fcp_cpu_map = 0;
4710 return 0;
4711 }
4712
4713 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4714 phba->cfg_fcp_cpu_map = val;
4715 return 0;
4716 }
4717
4718 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004719 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4720 "default\n", val);
James Smart7bb03bb2013-04-17 20:19:16 -04004721 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4722
4723 return 0;
4724}
4725
Joe Perchesb6b996b2017-12-19 10:15:07 -08004726static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
James Smart7bb03bb2013-04-17 20:19:16 -04004727
James Smart0d878412009-10-02 15:16:56 -04004728/*
dea31012005-04-17 16:05:31 -05004729# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4730# Value range is [2,3]. Default value is 3.
4731*/
James Smart3de2a652007-08-02 11:09:59 -04004732LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4733 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05004734
4735/*
4736# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4737# is [0,1]. Default value is 0.
4738*/
James Smart3de2a652007-08-02 11:09:59 -04004739LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4740 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05004741
4742/*
James Smart3cb01c52013-07-15 18:35:04 -04004743# lpfc_first_burst_size: First burst size to use on the NPorts
4744# that support first burst.
4745# Value range is [0,65536]. Default value is 0.
4746*/
4747LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4748 "First burst size for Targets that support first burst");
4749
4750/*
James Smart2d7dbc42017-02-12 13:52:35 -08004751* lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4752* When the driver is configured as an NVME target, this value is
4753* communicated to the NVME initiator in the PRLI response. It is
4754* used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4755* parameters are set and the target is sending the PRLI RSP.
James Smart895427b2017-02-12 13:52:30 -08004756* Parameter supported on physical port only - no NPIV support.
James Smart2d7dbc42017-02-12 13:52:35 -08004757* Value range is [0,65536]. Default value is 0.
James Smart895427b2017-02-12 13:52:30 -08004758*/
James Smart2d7dbc42017-02-12 13:52:35 -08004759LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4760 "NVME Target mode first burst size in 512B increments.");
4761
4762/*
4763 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4764 * For the Initiator (I), enabling this parameter means that an NVMET
4765 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4766 * processed by the initiator for subsequent NVME FCP IO. For the target
4767 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4768 * driver parameter as the target function's first burst size returned to the
4769 * initiator in the target's NVME PRLI response. Parameter supported on physical
4770 * port only - no NPIV support.
4771 * Value range is [0,1]. Default value is 0 (disabled).
4772 */
James Smart895427b2017-02-12 13:52:30 -08004773LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4774 "Enable First Burst feature on I and T functions.");
4775
4776/*
James Smart977b5a02008-09-07 11:52:04 -04004777# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4778# depth. Default value is 0. When the value of this parameter is zero the
4779# SCSI command completion time is not used for controlling I/O queue depth. When
4780# the parameter is set to a non-zero value, the I/O queue depth is controlled
4781# to limit the I/O completion time to the parameter value.
4782# The value is set in milliseconds.
4783*/
James Smarted5b1522016-10-13 15:06:11 -07004784LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
James Smart977b5a02008-09-07 11:52:04 -04004785 "Use command completion time to control queue depth");
James Smarted5b1522016-10-13 15:06:11 -07004786
James Smart977b5a02008-09-07 11:52:04 -04004787lpfc_vport_param_show(max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04004788static int
4789lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4790{
4791 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4792 struct lpfc_nodelist *ndlp, *next_ndlp;
4793
4794 if (val == vport->cfg_max_scsicmpl_time)
4795 return 0;
4796 if ((val < 0) || (val > 60000))
4797 return -EINVAL;
4798 vport->cfg_max_scsicmpl_time = val;
4799
4800 spin_lock_irq(shost->host_lock);
4801 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4802 if (!NLP_CHK_NODE_ACT(ndlp))
4803 continue;
4804 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4805 continue;
James Smart7dc517d2010-07-14 15:32:10 -04004806 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04004807 }
4808 spin_unlock_irq(shost->host_lock);
4809 return 0;
4810}
4811lpfc_vport_param_store(max_scsicmpl_time);
Joe Perchesb6b996b2017-12-19 10:15:07 -08004812static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04004813
4814/*
dea31012005-04-17 16:05:31 -05004815# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4816# range is [0,1]. Default value is 0.
4817*/
4818LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4819
4820/*
James Smart895427b2017-02-12 13:52:30 -08004821 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4822 * range is [0,1]. Default value is 0.
4823 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4824 * For [1], FCP commands are issued to a Work Queue associated with the
4825 * current CPU.
4826 *
4827 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4828 * LPFC_FCP_SCHED_BY_CPU == 1
4829 *
4830 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4831 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4832 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4833 * through WQs will be used.
4834 */
4835LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4836 LPFC_FCP_SCHED_ROUND_ROBIN,
4837 LPFC_FCP_SCHED_BY_CPU,
4838 "Determine scheduling algorithm for "
4839 "issuing commands [0] - Round Robin, [1] - Current CPU");
James Smart49aa1432012-08-03 12:36:42 -04004840
4841/*
James Smarta6571c62012-10-31 14:44:42 -04004842# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4843# range is [0,1]. Default value is 0.
4844# For [0], bus reset issues target reset to ALL devices
4845# For [1], bus reset issues target reset to non-FCP2 devices
4846*/
4847LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4848 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4849
4850
4851/*
dea31012005-04-17 16:05:31 -05004852# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4853# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04004854# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05004855# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4856# cr_delay is set to 0.
4857*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004858LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05004859 "interrupt response is generated");
4860
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004861LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05004862 "interrupt response is generated");
4863
4864/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004865# lpfc_multi_ring_support: Determines how many rings to spread available
4866# cmd/rsp IOCB entries across.
4867# Value range is [1,2]. Default value is 1.
4868*/
4869LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4870 "SLI rings to spread IOCB entries across");
4871
4872/*
James Smarta4bc3372006-12-02 13:34:16 -05004873# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4874# identifies what rctl value to configure the additional ring for.
4875# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4876*/
James Smart6a9c52c2009-10-02 15:16:51 -04004877LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004878 255, "Identifies RCTL for additional ring configuration");
4879
4880/*
4881# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4882# identifies what type value to configure the additional ring for.
4883# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4884*/
James Smart6a9c52c2009-10-02 15:16:51 -04004885LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004886 255, "Identifies TYPE for additional ring configuration");
4887
4888/*
James Smart4258e982015-12-16 18:11:58 -05004889# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4890# 0 = SmartSAN functionality disabled (default)
4891# 1 = SmartSAN functionality enabled
4892# This parameter will override the value of lpfc_fdmi_on module parameter.
4893# Value range is [0,1]. Default value is 0.
dea31012005-04-17 16:05:31 -05004894*/
James Smart4258e982015-12-16 18:11:58 -05004895LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4896
4897/*
4898# lpfc_fdmi_on: Controls FDMI support.
4899# 0 No FDMI support (default)
4900# 1 Traditional FDMI support
James Smart8663cbb2016-03-31 14:12:33 -07004901# Traditional FDMI support means the driver will assume FDMI-2 support;
4902# however, if that fails, it will fallback to FDMI-1.
4903# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4904# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4905# lpfc_fdmi_on.
4906# Value range [0,1]. Default value is 0.
James Smart4258e982015-12-16 18:11:58 -05004907*/
James Smart8663cbb2016-03-31 14:12:33 -07004908LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05004909
4910/*
4911# Specifies the maximum number of ELS cmds we can have outstanding (for
4912# discovery). Value range is [1,64]. Default value = 32.
4913*/
James Smart3de2a652007-08-02 11:09:59 -04004914LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05004915 "during discovery");
4916
4917/*
James Smartc4a7c922013-05-31 17:04:59 -04004918# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4919# will be scanned by the SCSI midlayer when sequential scanning is
4920# used; and is also the highest LUN ID allowed when the SCSI midlayer
4921# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4922# LUN ID limit, but the SCSI midlayer requires this field for the uses
4923# above. The lpfc driver limits the default value to 255 for two reasons.
4924# As it bounds the sequential scan loop, scanning for thousands of luns
4925# on a target can take minutes of wall clock time. Additionally,
4926# there are FC targets, such as JBODs, that only recognize 8-bits of
4927# LUN ID. When they receive a value greater than 8 bits, they chop off
4928# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4929# and so on all as LUN ID 0. This causes the linux kernel, which sees
4930# valid responses at each of the LUN IDs, to believe there are multiple
4931# devices present, when in fact, there is only 1.
4932# A customer that is aware of their target behaviors, and the results as
4933# indicated above, is welcome to increase the lpfc_max_luns value.
4934# As mentioned, this value is not used by the lpfc driver, only the
4935# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04004936# Value range is [0,65535]. Default value is 255.
4937# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05004938*/
Hannes Reinecke1abf6352014-06-25 15:27:38 +02004939LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05004940
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004941/*
4942# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4943# Value range is [1,255], default value is 10.
4944*/
4945LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4946 "Milliseconds driver will wait between polling FCP ring");
4947
James Smart4ff43242006-12-02 13:34:56 -05004948/*
James Smart0c411222013-09-06 12:22:46 -04004949# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4950# to complete in seconds. Value range is [5,180], default value is 60.
4951*/
4952LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4953 "Maximum time to wait for task management commands to complete");
4954/*
James Smart4ff43242006-12-02 13:34:56 -05004955# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4956# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02004957# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05004958# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02004959# 2 = MSI-X enabled (default)
4960# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05004961*/
George Kadianakis8605c462010-01-17 21:19:31 +02004962LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05004963 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05004964
James Smart13815c82008-01-11 01:52:48 -05004965/*
James Smartf358dd02017-02-12 13:52:34 -08004966 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
James Smart895427b2017-02-12 13:52:30 -08004967 *
4968 * 0 = NVME OAS disabled
4969 * 1 = NVME OAS enabled
4970 *
4971 * Value range is [0,1]. Default value is 0.
4972 */
4973LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
4974 "Use OAS bit on NVME IOs");
4975
4976/*
4977 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
4978 * will advertise it supports to the SCSI layer. This also will map to
4979 * the number of WQs the driver will create.
4980 *
4981 * 0 = Configure the number of io channels to the number of active CPUs.
4982 * 1,32 = Manually specify how many io channels to use.
4983 *
4984 * Value range is [0,32]. Default value is 4.
4985 */
4986LPFC_ATTR_R(fcp_io_channel,
4987 LPFC_FCP_IO_CHAN_DEF,
4988 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
James Smart67d12732012-08-03 12:36:13 -04004989 "Set the number of FCP I/O channels");
4990
4991/*
James Smart895427b2017-02-12 13:52:30 -08004992 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
4993 * will advertise it supports to the NVME layer. This also will map to
4994 * the number of WQs the driver will create.
4995 *
4996 * This module parameter is valid when lpfc_enable_fc4_type is set
4997 * to support NVME.
4998 *
4999 * The NVME Layer will try to create this many, plus 1 administrative
5000 * hardware queue. The administrative queue will always map to WQ 0
5001 * A hardware IO queue maps (qidx) to a specific driver WQ.
5002 *
5003 * 0 = Configure the number of io channels to the number of active CPUs.
5004 * 1,32 = Manually specify how many io channels to use.
5005 *
5006 * Value range is [0,32]. Default value is 0.
5007 */
5008LPFC_ATTR_R(nvme_io_channel,
5009 LPFC_NVME_IO_CHAN_DEF,
5010 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
5011 "Set the number of NVME I/O channels");
5012
5013/*
James Smart13815c82008-01-11 01:52:48 -05005014# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5015# 0 = HBA resets disabled
5016# 1 = HBA resets enabled (default)
5017# Value range is [0,1]. Default value is 1.
5018*/
5019LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04005020
James Smart13815c82008-01-11 01:52:48 -05005021/*
James Smarteb7a3392010-11-20 23:12:02 -05005022# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05005023# 0 = HBA Heartbeat disabled
5024# 1 = HBA Heartbeat enabled (default)
5025# Value range is [0,1]. Default value is 1.
5026*/
James Smarteb7a3392010-11-20 23:12:02 -05005027LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05005028
James Smart83108bd2008-01-11 01:53:09 -05005029/*
James Smart1ba981f2014-02-20 09:56:45 -05005030# lpfc_EnableXLane: Enable Express Lane Feature
5031# 0x0 Express Lane Feature disabled
5032# 0x1 Express Lane Feature enabled
5033# Value range is [0,1]. Default value is 0.
5034*/
5035LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5036
5037/*
5038# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5039# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5040# Value range is [0x0,0x7f]. Default value is 0
5041*/
James Smart28d7f3d2014-05-21 08:05:28 -04005042LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
James Smart1ba981f2014-02-20 09:56:45 -05005043
5044/*
James Smart81301a92008-12-04 22:39:46 -05005045# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5046# 0 = BlockGuard disabled (default)
5047# 1 = BlockGuard enabled
5048# Value range is [0,1]. Default value is 0.
5049*/
5050LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5051
James Smart6fb120a2009-05-22 14:52:59 -04005052/*
James Smartba20c852012-08-03 12:36:52 -04005053# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5054# 0 = disabled (default)
5055# 1 = enabled
5056# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04005057#
5058# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04005059*/
5060unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5061
James Smartba20c852012-08-03 12:36:52 -04005062/*
James Smart81301a92008-12-04 22:39:46 -05005063# lpfc_prot_mask: i
5064# - Bit mask of host protection capabilities used to register with the
5065# SCSI mid-layer
5066# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5067# - Allows you to ultimately specify which profiles to use
5068# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04005069# - SHOST_DIF_TYPE1_PROTECTION 1
5070# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5071# - SHOST_DIX_TYPE0_PROTECTION 8
5072# HBA supports DIX Type 0: Host to HBA protection only
5073# - SHOST_DIX_TYPE1_PROTECTION 16
5074# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05005075#
5076*/
James Smartb3b98b72016-10-13 15:06:06 -07005077LPFC_ATTR(prot_mask,
5078 (SHOST_DIF_TYPE1_PROTECTION |
5079 SHOST_DIX_TYPE0_PROTECTION |
5080 SHOST_DIX_TYPE1_PROTECTION),
5081 0,
5082 (SHOST_DIF_TYPE1_PROTECTION |
5083 SHOST_DIX_TYPE0_PROTECTION |
5084 SHOST_DIX_TYPE1_PROTECTION),
5085 "T10-DIF host protection capabilities mask");
James Smart81301a92008-12-04 22:39:46 -05005086
5087/*
5088# lpfc_prot_guard: i
5089# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04005090# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05005091# - Allows you to ultimately specify which profiles to use
5092# - Default will result in registering capabilities for all guard types
5093#
5094*/
James Smartb3b98b72016-10-13 15:06:06 -07005095LPFC_ATTR(prot_guard,
5096 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5097 "T10-DIF host protection guard type");
James Smart81301a92008-12-04 22:39:46 -05005098
James Smart92494142011-02-16 12:39:44 -05005099/*
5100 * Delay initial NPort discovery when Clean Address bit is cleared in
5101 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5102 * This parameter can have value 0 or 1.
5103 * When this parameter is set to 0, no delay is added to the initial
5104 * discovery.
5105 * When this parameter is set to non-zero value, initial Nport discovery is
5106 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5107 * accept and FCID/Fabric name/Fabric portname is changed.
5108 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5109 * when Clean Address bit is cleared in FLOGI/FDISC
5110 * accept and FCID/Fabric name/Fabric portname is changed.
5111 * Default value is 0.
5112 */
James Smart8eb8b962016-07-06 12:36:08 -07005113LPFC_ATTR(delay_discovery, 0, 0, 1,
5114 "Delay NPort discovery when Clean Address bit is cleared.");
James Smart81301a92008-12-04 22:39:46 -05005115
5116/*
James Smart3621a712009-04-06 18:47:14 -04005117 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart96f70772013-04-17 20:16:15 -04005118 * This value can be set to values between 64 and 4096. The default value is
James Smart83108bd2008-01-11 01:53:09 -05005119 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5120 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04005121 * Because of the additional overhead involved in setting up T10-DIF,
5122 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5123 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05005124 */
5125LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
5126 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5127
James Smart96f70772013-04-17 20:16:15 -04005128/*
James Smart7bdedb32016-07-06 12:36:00 -07005129 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5130 * 0 = MDS Diagnostics disabled (default)
5131 * 1 = MDS Diagnostics enabled
5132 * Value range is [0,1]. Default value is 0.
5133 */
5134LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5135
James Smart44fd7fe2017-08-23 16:55:47 -07005136/*
5137 * lpfc_enable_bbcr: Enable BB Credit Recovery
5138 * 0 = BB Credit Recovery disabled
5139 * 1 = BB Credit Recovery enabled (default)
5140 * Value range is [0,1]. Default value is 1.
5141 */
5142LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5143
Tony Jonesee959b02008-02-22 00:13:36 +01005144struct device_attribute *lpfc_hba_attrs[] = {
James Smart895427b2017-02-12 13:52:30 -08005145 &dev_attr_nvme_info,
James Smart81301a92008-12-04 22:39:46 -05005146 &dev_attr_bg_info,
5147 &dev_attr_bg_guard_err,
5148 &dev_attr_bg_apptag_err,
5149 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01005150 &dev_attr_info,
5151 &dev_attr_serialnum,
5152 &dev_attr_modeldesc,
5153 &dev_attr_modelname,
5154 &dev_attr_programtype,
5155 &dev_attr_portnum,
5156 &dev_attr_fwrev,
5157 &dev_attr_hdw,
5158 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005159 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005160 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04005161 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01005162 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04005163 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01005164 &dev_attr_lpfc_temp_sensor,
5165 &dev_attr_lpfc_log_verbose,
5166 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005167 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005168 &dev_attr_lpfc_hba_queue_depth,
5169 &dev_attr_lpfc_peer_port_login,
5170 &dev_attr_lpfc_nodev_tmo,
5171 &dev_attr_lpfc_devloss_tmo,
James Smart895427b2017-02-12 13:52:30 -08005172 &dev_attr_lpfc_enable_fc4_type,
5173 &dev_attr_lpfc_xri_split,
Tony Jonesee959b02008-02-22 00:13:36 +01005174 &dev_attr_lpfc_fcp_class,
5175 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005176 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005177 &dev_attr_lpfc_ack0,
5178 &dev_attr_lpfc_topology,
5179 &dev_attr_lpfc_scan_down,
5180 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04005181 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04005182 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01005183 &dev_attr_lpfc_cr_delay,
5184 &dev_attr_lpfc_cr_count,
5185 &dev_attr_lpfc_multi_ring_support,
5186 &dev_attr_lpfc_multi_ring_rctl,
5187 &dev_attr_lpfc_multi_ring_type,
5188 &dev_attr_lpfc_fdmi_on,
James Smart4258e982015-12-16 18:11:58 -05005189 &dev_attr_lpfc_enable_SmartSAN,
Tony Jonesee959b02008-02-22 00:13:36 +01005190 &dev_attr_lpfc_max_luns,
5191 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04005192 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05005193 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01005194 &dev_attr_nport_evt_cnt,
5195 &dev_attr_board_mode,
5196 &dev_attr_max_vpi,
5197 &dev_attr_used_vpi,
5198 &dev_attr_max_rpi,
5199 &dev_attr_used_rpi,
5200 &dev_attr_max_xri,
5201 &dev_attr_used_xri,
5202 &dev_attr_npiv_info,
5203 &dev_attr_issue_reset,
5204 &dev_attr_lpfc_poll,
5205 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04005206 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01005207 &dev_attr_lpfc_use_msi,
James Smart895427b2017-02-12 13:52:30 -08005208 &dev_attr_lpfc_nvme_oas,
James Smart0cf07f842017-06-01 21:07:10 -07005209 &dev_attr_lpfc_auto_imax,
James Smartda0436e2009-05-22 14:51:39 -04005210 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04005211 &dev_attr_lpfc_fcp_cpu_map,
James Smart67d12732012-08-03 12:36:13 -04005212 &dev_attr_lpfc_fcp_io_channel,
James Smartf358dd02017-02-12 13:52:34 -08005213 &dev_attr_lpfc_suppress_rsp,
James Smart895427b2017-02-12 13:52:30 -08005214 &dev_attr_lpfc_nvme_io_channel,
James Smart2d7dbc42017-02-12 13:52:35 -08005215 &dev_attr_lpfc_nvmet_mrq,
James Smart895427b2017-02-12 13:52:30 -08005216 &dev_attr_lpfc_nvme_enable_fb,
James Smart2d7dbc42017-02-12 13:52:35 -08005217 &dev_attr_lpfc_nvmet_fb_size,
James Smart81301a92008-12-04 22:39:46 -05005218 &dev_attr_lpfc_enable_bg,
James Smart352e5fd2016-12-30 06:57:47 -08005219 &dev_attr_lpfc_soft_wwnn,
5220 &dev_attr_lpfc_soft_wwpn,
5221 &dev_attr_lpfc_soft_wwn_enable,
Tony Jonesee959b02008-02-22 00:13:36 +01005222 &dev_attr_lpfc_enable_hba_reset,
5223 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05005224 &dev_attr_lpfc_EnableXLane,
5225 &dev_attr_lpfc_XLanePriority,
5226 &dev_attr_lpfc_xlane_lun,
5227 &dev_attr_lpfc_xlane_tgt,
5228 &dev_attr_lpfc_xlane_vpt,
5229 &dev_attr_lpfc_xlane_lun_state,
5230 &dev_attr_lpfc_xlane_lun_status,
James Smartc92c8412016-07-06 12:36:05 -07005231 &dev_attr_lpfc_xlane_priority,
Tony Jonesee959b02008-02-22 00:13:36 +01005232 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04005233 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04005234 &dev_attr_lpfc_stat_data_ctrl,
James Smart0d878412009-10-02 15:16:56 -04005235 &dev_attr_lpfc_aer_support,
5236 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04005237 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04005238 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05005239 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04005240 &dev_attr_lpfc_iocb_cnt,
5241 &dev_attr_iocb_hw,
5242 &dev_attr_txq_hw,
5243 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04005244 &dev_attr_lpfc_fips_level,
5245 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05005246 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04005247 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05005248 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05005249 &dev_attr_lpfc_xlane_supported,
James Smart7bdedb32016-07-06 12:36:00 -07005250 &dev_attr_lpfc_enable_mds_diags,
James Smart44fd7fe2017-08-23 16:55:47 -07005251 &dev_attr_lpfc_enable_bbcr,
dea31012005-04-17 16:05:31 -05005252 NULL,
5253};
5254
Tony Jonesee959b02008-02-22 00:13:36 +01005255struct device_attribute *lpfc_vport_attrs[] = {
5256 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005257 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005258 &dev_attr_num_discovered_ports,
5259 &dev_attr_lpfc_drvr_version,
5260 &dev_attr_lpfc_log_verbose,
5261 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005262 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005263 &dev_attr_lpfc_nodev_tmo,
5264 &dev_attr_lpfc_devloss_tmo,
5265 &dev_attr_lpfc_hba_queue_depth,
5266 &dev_attr_lpfc_peer_port_login,
5267 &dev_attr_lpfc_restrict_login,
5268 &dev_attr_lpfc_fcp_class,
5269 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005270 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005271 &dev_attr_lpfc_max_luns,
5272 &dev_attr_nport_evt_cnt,
5273 &dev_attr_npiv_info,
5274 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04005275 &dev_attr_lpfc_max_scsicmpl_time,
5276 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04005277 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04005278 &dev_attr_lpfc_fips_level,
5279 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04005280 NULL,
5281};
5282
James Smarte59058c2008-08-24 21:49:00 -04005283/**
James Smart3621a712009-04-06 18:47:14 -04005284 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005285 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005286 * @kobj: kernel kobject that contains the kernel class device.
5287 * @bin_attr: kernel attributes passed to us.
5288 * @buf: contains the data to be written to the adapter IOREG space.
5289 * @off: offset into buffer to beginning of data.
5290 * @count: bytes to transfer.
5291 *
5292 * Description:
5293 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5294 * Uses the adapter io control registers to send buf contents to the adapter.
5295 *
5296 * Returns:
5297 * -ERANGE off and count combo out of range
5298 * -EINVAL off, count or buff address invalid
5299 * -EPERM adapter is offline
5300 * value of count, buf contents written
5301 **/
dea31012005-04-17 16:05:31 -05005302static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005303sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5304 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005305 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005306{
5307 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01005308 struct device *dev = container_of(kobj, struct device, kobj);
5309 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005310 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5311 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005312
James Smartf1126682009-06-10 17:22:44 -04005313 if (phba->sli_rev >= LPFC_SLI_REV4)
5314 return -EPERM;
5315
dea31012005-04-17 16:05:31 -05005316 if ((off + count) > FF_REG_AREA_SIZE)
5317 return -ERANGE;
5318
James Smartf7a919b2011-08-21 21:49:16 -04005319 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5320 return 0;
dea31012005-04-17 16:05:31 -05005321
5322 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5323 return -EINVAL;
5324
James Smartf7a919b2011-08-21 21:49:16 -04005325 /* This is to protect HBA registers from accidental writes. */
5326 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5327 return -EINVAL;
5328
5329 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05005330 return -EPERM;
dea31012005-04-17 16:05:31 -05005331
James Smart2e0fef82007-06-17 19:56:36 -05005332 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04005333 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5334 buf_off += sizeof(uint32_t))
5335 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05005336 phba->ctrl_regs_memmap_p + off + buf_off);
5337
James Smart2e0fef82007-06-17 19:56:36 -05005338 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005339
5340 return count;
5341}
5342
James Smarte59058c2008-08-24 21:49:00 -04005343/**
James Smart3621a712009-04-06 18:47:14 -04005344 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005345 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005346 * @kobj: kernel kobject that contains the kernel class device.
5347 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005348 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04005349 * @off: offset into buffer to beginning of data.
5350 * @count: bytes to transfer.
5351 *
5352 * Description:
5353 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5354 * Uses the adapter io control registers to read data into buf.
5355 *
5356 * Returns:
5357 * -ERANGE off and count combo out of range
5358 * -EINVAL off, count or buff address invalid
5359 * value of count, buf contents read
5360 **/
dea31012005-04-17 16:05:31 -05005361static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005362sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5363 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005364 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005365{
5366 size_t buf_off;
5367 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01005368 struct device *dev = container_of(kobj, struct device, kobj);
5369 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005370 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5371 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005372
James Smartf1126682009-06-10 17:22:44 -04005373 if (phba->sli_rev >= LPFC_SLI_REV4)
5374 return -EPERM;
5375
dea31012005-04-17 16:05:31 -05005376 if (off > FF_REG_AREA_SIZE)
5377 return -ERANGE;
5378
5379 if ((off + count) > FF_REG_AREA_SIZE)
5380 count = FF_REG_AREA_SIZE - off;
5381
5382 if (count == 0) return 0;
5383
5384 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5385 return -EINVAL;
5386
James Smart2e0fef82007-06-17 19:56:36 -05005387 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005388
5389 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5390 tmp_ptr = (uint32_t *)(buf + buf_off);
5391 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5392 }
5393
James Smart2e0fef82007-06-17 19:56:36 -05005394 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005395
5396 return count;
5397}
5398
5399static struct bin_attribute sysfs_ctlreg_attr = {
5400 .attr = {
5401 .name = "ctlreg",
5402 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005403 },
5404 .size = 256,
5405 .read = sysfs_ctlreg_read,
5406 .write = sysfs_ctlreg_write,
5407};
5408
James Smarte59058c2008-08-24 21:49:00 -04005409/**
James Smart3621a712009-04-06 18:47:14 -04005410 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005411 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005412 * @kobj: kernel kobject that contains the kernel class device.
5413 * @bin_attr: kernel attributes passed to us.
5414 * @buf: contains the data to be written to sysfs mbox.
5415 * @off: offset into buffer to beginning of data.
5416 * @count: bytes to transfer.
5417 *
5418 * Description:
James Smart026abb82011-12-13 13:20:45 -05005419 * Deprecated function. All mailbox access from user space is performed via the
5420 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005421 *
5422 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005423 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005424 **/
dea31012005-04-17 16:05:31 -05005425static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005426sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5427 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005428 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005429{
James Smart026abb82011-12-13 13:20:45 -05005430 return -EPERM;
dea31012005-04-17 16:05:31 -05005431}
5432
James Smarte59058c2008-08-24 21:49:00 -04005433/**
James Smart3621a712009-04-06 18:47:14 -04005434 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005435 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005436 * @kobj: kernel kobject that contains the kernel class device.
5437 * @bin_attr: kernel attributes passed to us.
5438 * @buf: contains the data to be read from sysfs mbox.
5439 * @off: offset into buffer to beginning of data.
5440 * @count: bytes to transfer.
5441 *
5442 * Description:
James Smart026abb82011-12-13 13:20:45 -05005443 * Deprecated function. All mailbox access from user space is performed via the
5444 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005445 *
5446 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005447 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005448 **/
dea31012005-04-17 16:05:31 -05005449static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005450sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5451 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005452 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005453{
James Smart026abb82011-12-13 13:20:45 -05005454 return -EPERM;
dea31012005-04-17 16:05:31 -05005455}
5456
5457static struct bin_attribute sysfs_mbox_attr = {
5458 .attr = {
5459 .name = "mbox",
5460 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005461 },
James Smartc0c11512011-05-24 11:41:34 -04005462 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05005463 .read = sysfs_mbox_read,
5464 .write = sysfs_mbox_write,
5465};
5466
James Smarte59058c2008-08-24 21:49:00 -04005467/**
James Smart3621a712009-04-06 18:47:14 -04005468 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005469 * @vport: address of lpfc vport structure.
5470 *
5471 * Return codes:
5472 * zero on success
5473 * error return code from sysfs_create_bin_file()
5474 **/
dea31012005-04-17 16:05:31 -05005475int
James Smart2e0fef82007-06-17 19:56:36 -05005476lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005477{
James Smart2e0fef82007-06-17 19:56:36 -05005478 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005479 int error;
5480
Tony Jonesee959b02008-02-22 00:13:36 +01005481 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05005482 &sysfs_drvr_stat_data_attr);
5483
5484 /* Virtual ports do not need ctrl_reg and mbox */
5485 if (error || vport->port_type == LPFC_NPIV_PORT)
5486 goto out;
5487
5488 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005489 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005490 if (error)
James Smarteada2722008-12-04 22:39:13 -05005491 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05005492
Tony Jonesee959b02008-02-22 00:13:36 +01005493 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005494 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05005495 if (error)
5496 goto out_remove_ctlreg_attr;
5497
5498 return 0;
5499out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01005500 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05005501out_remove_stat_attr:
5502 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5503 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05005504out:
5505 return error;
5506}
5507
James Smarte59058c2008-08-24 21:49:00 -04005508/**
James Smart3621a712009-04-06 18:47:14 -04005509 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005510 * @vport: address of lpfc vport structure.
5511 **/
dea31012005-04-17 16:05:31 -05005512void
James Smart2e0fef82007-06-17 19:56:36 -05005513lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005514{
James Smart2e0fef82007-06-17 19:56:36 -05005515 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04005516 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5517 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05005518 /* Virtual ports do not need ctrl_reg and mbox */
5519 if (vport->port_type == LPFC_NPIV_PORT)
5520 return;
Tony Jonesee959b02008-02-22 00:13:36 +01005521 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5522 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005523}
5524
dea31012005-04-17 16:05:31 -05005525/*
5526 * Dynamic FC Host Attributes Support
5527 */
5528
James Smarte59058c2008-08-24 21:49:00 -04005529/**
James Smart6c9231f2016-12-19 15:07:24 -08005530 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5531 * @shost: kernel scsi host pointer.
5532 **/
5533static void
5534lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5535{
5536 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5537
5538 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5539 sizeof fc_host_symbolic_name(shost));
5540}
5541
5542/**
James Smart3621a712009-04-06 18:47:14 -04005543 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04005544 * @shost: kernel scsi host pointer.
5545 **/
dea31012005-04-17 16:05:31 -05005546static void
5547lpfc_get_host_port_id(struct Scsi_Host *shost)
5548{
James Smart2e0fef82007-06-17 19:56:36 -05005549 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5550
dea31012005-04-17 16:05:31 -05005551 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05005552 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005553}
5554
James Smarte59058c2008-08-24 21:49:00 -04005555/**
James Smart3621a712009-04-06 18:47:14 -04005556 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04005557 * @shost: kernel scsi host pointer.
5558 **/
dea31012005-04-17 16:05:31 -05005559static void
5560lpfc_get_host_port_type(struct Scsi_Host *shost)
5561{
James Smart2e0fef82007-06-17 19:56:36 -05005562 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5563 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005564
5565 spin_lock_irq(shost->host_lock);
5566
James Smart92d7f7b2007-06-17 19:56:38 -05005567 if (vport->port_type == LPFC_NPIV_PORT) {
5568 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5569 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05005570 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05005571 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05005572 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5573 else
5574 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5575 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005576 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05005577 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5578 else
5579 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5580 }
5581 } else
5582 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5583
5584 spin_unlock_irq(shost->host_lock);
5585}
5586
James Smarte59058c2008-08-24 21:49:00 -04005587/**
James Smart3621a712009-04-06 18:47:14 -04005588 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04005589 * @shost: kernel scsi host pointer.
5590 **/
dea31012005-04-17 16:05:31 -05005591static void
5592lpfc_get_host_port_state(struct Scsi_Host *shost)
5593{
James Smart2e0fef82007-06-17 19:56:36 -05005594 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5595 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005596
5597 spin_lock_irq(shost->host_lock);
5598
James Smart2e0fef82007-06-17 19:56:36 -05005599 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005600 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5601 else {
James Smart2e0fef82007-06-17 19:56:36 -05005602 switch (phba->link_state) {
5603 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05005604 case LPFC_LINK_DOWN:
5605 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5606 break;
5607 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05005608 case LPFC_CLEAR_LA:
5609 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05005610 /* Links up, reports port state accordingly */
5611 if (vport->port_state < LPFC_VPORT_READY)
5612 fc_host_port_state(shost) =
5613 FC_PORTSTATE_BYPASSED;
5614 else
5615 fc_host_port_state(shost) =
5616 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05005617 break;
5618 case LPFC_HBA_ERROR:
5619 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5620 break;
5621 default:
5622 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5623 break;
5624 }
5625 }
5626
5627 spin_unlock_irq(shost->host_lock);
5628}
5629
James Smarte59058c2008-08-24 21:49:00 -04005630/**
James Smart3621a712009-04-06 18:47:14 -04005631 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04005632 * @shost: kernel scsi host pointer.
5633 **/
dea31012005-04-17 16:05:31 -05005634static void
5635lpfc_get_host_speed(struct Scsi_Host *shost)
5636{
James Smart2e0fef82007-06-17 19:56:36 -05005637 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5638 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005639
5640 spin_lock_irq(shost->host_lock);
5641
James Smarta085e872015-12-16 18:12:02 -05005642 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea31012005-04-17 16:05:31 -05005643 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05005644 case LPFC_LINK_SPEED_1GHZ:
5645 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05005646 break;
James Smart76a95d72010-11-20 23:11:48 -05005647 case LPFC_LINK_SPEED_2GHZ:
5648 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05005649 break;
James Smart76a95d72010-11-20 23:11:48 -05005650 case LPFC_LINK_SPEED_4GHZ:
5651 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05005652 break;
James Smart76a95d72010-11-20 23:11:48 -05005653 case LPFC_LINK_SPEED_8GHZ:
5654 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04005655 break;
James Smart76a95d72010-11-20 23:11:48 -05005656 case LPFC_LINK_SPEED_10GHZ:
5657 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04005658 break;
James Smart76a95d72010-11-20 23:11:48 -05005659 case LPFC_LINK_SPEED_16GHZ:
5660 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5661 break;
James Smartd38dd522015-08-31 16:48:17 -04005662 case LPFC_LINK_SPEED_32GHZ:
5663 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5664 break;
James Smart76a95d72010-11-20 23:11:48 -05005665 default:
5666 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005667 break;
5668 }
James Smart09372822008-01-11 01:52:54 -05005669 } else
5670 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005671
5672 spin_unlock_irq(shost->host_lock);
5673}
5674
James Smarte59058c2008-08-24 21:49:00 -04005675/**
James Smart3621a712009-04-06 18:47:14 -04005676 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04005677 * @shost: kernel scsi host pointer.
5678 **/
dea31012005-04-17 16:05:31 -05005679static void
5680lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5681{
James Smart2e0fef82007-06-17 19:56:36 -05005682 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5683 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005684 u64 node_name;
dea31012005-04-17 16:05:31 -05005685
5686 spin_lock_irq(shost->host_lock);
5687
James Smart73d91e52011-10-10 21:32:10 -04005688 if ((vport->port_state > LPFC_FLOGI) &&
5689 ((vport->fc_flag & FC_FABRIC) ||
5690 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5691 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07005692 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05005693 else
5694 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05005695 node_name = 0;
dea31012005-04-17 16:05:31 -05005696
5697 spin_unlock_irq(shost->host_lock);
5698
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005699 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05005700}
5701
James Smarte59058c2008-08-24 21:49:00 -04005702/**
James Smart3621a712009-04-06 18:47:14 -04005703 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04005704 * @shost: kernel scsi host pointer.
5705 *
5706 * Notes:
5707 * NULL on error for link down, no mbox pool, sli2 active,
5708 * management not allowed, memory allocation error, or mbox error.
5709 *
5710 * Returns:
5711 * NULL for error
5712 * address of the adapter host statistics
5713 **/
dea31012005-04-17 16:05:31 -05005714static struct fc_host_statistics *
5715lpfc_get_stats(struct Scsi_Host *shost)
5716{
James Smart2e0fef82007-06-17 19:56:36 -05005717 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5718 struct lpfc_hba *phba = vport->phba;
5719 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005720 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04005721 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05005722 LPFC_MBOXQ_t *pmboxq;
5723 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04005724 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005725 int rc = 0;
dea31012005-04-17 16:05:31 -05005726
James Smart92d7f7b2007-06-17 19:56:38 -05005727 /*
5728 * prevent udev from issuing mailbox commands until the port is
5729 * configured.
5730 */
James Smart2e0fef82007-06-17 19:56:36 -05005731 if (phba->link_state < LPFC_LINK_DOWN ||
5732 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04005733 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05005734 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005735
5736 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005737 return NULL;
5738
dea31012005-04-17 16:05:31 -05005739 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5740 if (!pmboxq)
5741 return NULL;
5742 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5743
James Smart04c68492009-05-22 14:52:52 -04005744 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05005745 pmb->mbxCommand = MBX_READ_STATUS;
5746 pmb->mbxOwner = OWN_HOST;
5747 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005748 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005749
James Smart75baf692010-06-08 18:31:21 -04005750 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005751 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005752 else
dea31012005-04-17 16:05:31 -05005753 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5754
5755 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005756 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005757 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005758 return NULL;
5759 }
5760
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005761 memset(hs, 0, sizeof (struct fc_host_statistics));
5762
dea31012005-04-17 16:05:31 -05005763 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005764 /*
5765 * The MBX_READ_STATUS returns tx_k_bytes which has to
5766 * converted to words
5767 */
5768 hs->tx_words = (uint64_t)
5769 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5770 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005771 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005772 hs->rx_words = (uint64_t)
5773 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5774 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005775
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005776 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05005777 pmb->mbxCommand = MBX_READ_LNK_STAT;
5778 pmb->mbxOwner = OWN_HOST;
5779 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005780 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005781
James Smart75baf692010-06-08 18:31:21 -04005782 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005783 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005784 else
dea31012005-04-17 16:05:31 -05005785 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5786
5787 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005788 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005789 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005790 return NULL;
5791 }
5792
5793 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5794 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5795 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5796 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5797 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5798 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5799 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5800
James Smart64ba8812006-08-02 15:24:34 -04005801 hs->link_failure_count -= lso->link_failure_count;
5802 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5803 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5804 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5805 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5806 hs->invalid_crc_count -= lso->invalid_crc_count;
5807 hs->error_frames -= lso->error_frames;
5808
James Smart76a95d72010-11-20 23:11:48 -05005809 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04005810 hs->lip_count = -1;
5811 hs->nos_count = (phba->link_events >> 1);
5812 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05005813 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005814 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005815 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005816 hs->nos_count = -1;
5817 } else {
5818 hs->lip_count = -1;
5819 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005820 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005821 }
5822
5823 hs->dumped_frames = -1;
5824
James Smart64ba8812006-08-02 15:24:34 -04005825 seconds = get_seconds();
5826 if (seconds < psli->stats_start)
5827 hs->seconds_since_last_reset = seconds +
5828 ((unsigned long)-1 - psli->stats_start);
5829 else
5830 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05005831
James Smart1dcb58e2007-04-25 09:51:30 -04005832 mempool_free(pmboxq, phba->mbox_mem_pool);
5833
dea31012005-04-17 16:05:31 -05005834 return hs;
5835}
5836
James Smarte59058c2008-08-24 21:49:00 -04005837/**
James Smart3621a712009-04-06 18:47:14 -04005838 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04005839 * @shost: kernel scsi host pointer.
5840 **/
James Smart64ba8812006-08-02 15:24:34 -04005841static void
5842lpfc_reset_stats(struct Scsi_Host *shost)
5843{
James Smart2e0fef82007-06-17 19:56:36 -05005844 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5845 struct lpfc_hba *phba = vport->phba;
5846 struct lpfc_sli *psli = &phba->sli;
5847 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04005848 LPFC_MBOXQ_t *pmboxq;
5849 MAILBOX_t *pmb;
5850 int rc = 0;
5851
James Smart2e0fef82007-06-17 19:56:36 -05005852 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005853 return;
5854
James Smart64ba8812006-08-02 15:24:34 -04005855 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5856 if (!pmboxq)
5857 return;
5858 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5859
James Smart04c68492009-05-22 14:52:52 -04005860 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04005861 pmb->mbxCommand = MBX_READ_STATUS;
5862 pmb->mbxOwner = OWN_HOST;
5863 pmb->un.varWords[0] = 0x1; /* reset request */
5864 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005865 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005866
James Smart2e0fef82007-06-17 19:56:36 -05005867 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005868 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005869 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5870 else
5871 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5872
5873 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005874 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005875 mempool_free(pmboxq, phba->mbox_mem_pool);
5876 return;
5877 }
5878
5879 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5880 pmb->mbxCommand = MBX_READ_LNK_STAT;
5881 pmb->mbxOwner = OWN_HOST;
5882 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005883 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005884
James Smart2e0fef82007-06-17 19:56:36 -05005885 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005886 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005887 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5888 else
5889 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5890
5891 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005892 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005893 mempool_free( pmboxq, phba->mbox_mem_pool);
5894 return;
5895 }
5896
5897 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5898 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5899 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5900 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5901 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5902 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5903 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05005904 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04005905 lso->link_events = (phba->link_events >> 1);
5906 else
5907 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005908
5909 psli->stats_start = get_seconds();
5910
James Smart1dcb58e2007-04-25 09:51:30 -04005911 mempool_free(pmboxq, phba->mbox_mem_pool);
5912
James Smart64ba8812006-08-02 15:24:34 -04005913 return;
5914}
dea31012005-04-17 16:05:31 -05005915
5916/*
5917 * The LPFC driver treats linkdown handling as target loss events so there
5918 * are no sysfs handlers for link_down_tmo.
5919 */
James Smart685f0bf2007-04-25 09:53:08 -04005920
James Smarte59058c2008-08-24 21:49:00 -04005921/**
James Smart3621a712009-04-06 18:47:14 -04005922 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04005923 * @starget: kernel scsi target pointer.
5924 *
5925 * Returns:
5926 * address of the node list if found
5927 * NULL target not found
5928 **/
James Smart685f0bf2007-04-25 09:53:08 -04005929static struct lpfc_nodelist *
5930lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05005931{
James Smart2e0fef82007-06-17 19:56:36 -05005932 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5933 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04005934 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005935
5936 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005937 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05005938 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005939 if (NLP_CHK_NODE_ACT(ndlp) &&
5940 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04005941 starget->id == ndlp->nlp_sid) {
5942 spin_unlock_irq(shost->host_lock);
5943 return ndlp;
dea31012005-04-17 16:05:31 -05005944 }
5945 }
5946 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005947 return NULL;
5948}
dea31012005-04-17 16:05:31 -05005949
James Smarte59058c2008-08-24 21:49:00 -04005950/**
James Smart3621a712009-04-06 18:47:14 -04005951 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04005952 * @starget: kernel scsi target pointer.
5953 **/
James Smart685f0bf2007-04-25 09:53:08 -04005954static void
5955lpfc_get_starget_port_id(struct scsi_target *starget)
5956{
5957 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5958
5959 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05005960}
5961
James Smarte59058c2008-08-24 21:49:00 -04005962/**
James Smart3621a712009-04-06 18:47:14 -04005963 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04005964 * @starget: kernel scsi target pointer.
5965 *
5966 * Description: Set the target node name to the ndlp node name wwn or zero.
5967 **/
dea31012005-04-17 16:05:31 -05005968static void
5969lpfc_get_starget_node_name(struct scsi_target *starget)
5970{
James Smart685f0bf2007-04-25 09:53:08 -04005971 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005972
James Smart685f0bf2007-04-25 09:53:08 -04005973 fc_starget_node_name(starget) =
5974 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005975}
5976
James Smarte59058c2008-08-24 21:49:00 -04005977/**
James Smart3621a712009-04-06 18:47:14 -04005978 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04005979 * @starget: kernel scsi target pointer.
5980 *
5981 * Description: set the target port name to the ndlp port name wwn or zero.
5982 **/
dea31012005-04-17 16:05:31 -05005983static void
5984lpfc_get_starget_port_name(struct scsi_target *starget)
5985{
James Smart685f0bf2007-04-25 09:53:08 -04005986 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005987
James Smart685f0bf2007-04-25 09:53:08 -04005988 fc_starget_port_name(starget) =
5989 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005990}
5991
James Smarte59058c2008-08-24 21:49:00 -04005992/**
James Smart3621a712009-04-06 18:47:14 -04005993 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04005994 * @rport: fc rport address.
5995 * @timeout: new value for dev loss tmo.
5996 *
5997 * Description:
5998 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5999 * dev_loss_tmo to one.
6000 **/
dea31012005-04-17 16:05:31 -05006001static void
dea31012005-04-17 16:05:31 -05006002lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6003{
dea31012005-04-17 16:05:31 -05006004 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04006005 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05006006 else
James Smartc01f3202006-08-18 17:47:08 -04006007 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05006008}
6009
James Smarte59058c2008-08-24 21:49:00 -04006010/**
James Smart3621a712009-04-06 18:47:14 -04006011 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04006012 *
6013 * Description:
6014 * Macro that uses field to generate a function with the name lpfc_show_rport_
6015 *
6016 * lpfc_show_rport_##field: returns the bytes formatted in buf
6017 * @cdev: class converted to an fc_rport.
6018 * @buf: on return contains the target_field or zero.
6019 *
6020 * Returns: size of formatted string.
6021 **/
dea31012005-04-17 16:05:31 -05006022#define lpfc_rport_show_function(field, format_string, sz, cast) \
6023static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01006024lpfc_show_rport_##field (struct device *dev, \
6025 struct device_attribute *attr, \
6026 char *buf) \
dea31012005-04-17 16:05:31 -05006027{ \
Tony Jonesee959b02008-02-22 00:13:36 +01006028 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05006029 struct lpfc_rport_data *rdata = rport->hostdata; \
6030 return snprintf(buf, sz, format_string, \
6031 (rdata->target) ? cast rdata->target->field : 0); \
6032}
6033
6034#define lpfc_rport_rd_attr(field, format_string, sz) \
6035 lpfc_rport_show_function(field, format_string, sz, ) \
6036static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6037
James Smarteada2722008-12-04 22:39:13 -05006038/**
James Smart3621a712009-04-06 18:47:14 -04006039 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05006040 * @fc_vport: The fc_vport who's symbolic name has been changed.
6041 *
6042 * Description:
6043 * This function is called by the transport after the @fc_vport's symbolic name
6044 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006045 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05006046 **/
6047static void
6048lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6049{
6050 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6051
6052 if (vport->port_state == LPFC_VPORT_READY)
6053 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6054}
dea31012005-04-17 16:05:31 -05006055
James Smartf4b4c682009-05-22 14:53:12 -04006056/**
6057 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6058 * @phba: Pointer to lpfc_hba struct.
6059 *
6060 * This function is called by the lpfc_get_cfgparam() routine to set the
6061 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02006062 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04006063 * before hba port or vport created.
6064 **/
6065static void
6066lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6067{
6068 phba->cfg_log_verbose = verbose;
6069}
6070
dea31012005-04-17 16:05:31 -05006071struct fc_function_template lpfc_transport_functions = {
6072 /* fixed attributes the driver supports */
6073 .show_host_node_name = 1,
6074 .show_host_port_name = 1,
6075 .show_host_supported_classes = 1,
6076 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05006077 .show_host_supported_speeds = 1,
6078 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006079
6080 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006081 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05006082
6083 /* dynamic attributes the driver supports */
6084 .get_host_port_id = lpfc_get_host_port_id,
6085 .show_host_port_id = 1,
6086
6087 .get_host_port_type = lpfc_get_host_port_type,
6088 .show_host_port_type = 1,
6089
6090 .get_host_port_state = lpfc_get_host_port_state,
6091 .show_host_port_state = 1,
6092
6093 /* active_fc4s is shown but doesn't change (thus no get function) */
6094 .show_host_active_fc4s = 1,
6095
6096 .get_host_speed = lpfc_get_host_speed,
6097 .show_host_speed = 1,
6098
6099 .get_host_fabric_name = lpfc_get_host_fabric_name,
6100 .show_host_fabric_name = 1,
6101
6102 /*
6103 * The LPFC driver treats linkdown handling as target loss events
6104 * so there are no sysfs handlers for link_down_tmo.
6105 */
6106
6107 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04006108 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05006109
6110 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6111 .show_rport_maxframe_size = 1,
6112 .show_rport_supported_classes = 1,
6113
dea31012005-04-17 16:05:31 -05006114 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6115 .show_rport_dev_loss_tmo = 1,
6116
6117 .get_starget_port_id = lpfc_get_starget_port_id,
6118 .show_starget_port_id = 1,
6119
6120 .get_starget_node_name = lpfc_get_starget_node_name,
6121 .show_starget_node_name = 1,
6122
6123 .get_starget_port_name = lpfc_get_starget_port_name,
6124 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07006125
6126 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04006127 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6128 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05006129
James Smart92d7f7b2007-06-17 19:56:38 -05006130 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05006131
6132 .vport_disable = lpfc_vport_disable,
6133
6134 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04006135
6136 .bsg_request = lpfc_bsg_request,
6137 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05006138};
6139
James Smart98c9ea52007-10-27 13:37:33 -04006140struct fc_function_template lpfc_vport_transport_functions = {
6141 /* fixed attributes the driver supports */
6142 .show_host_node_name = 1,
6143 .show_host_port_name = 1,
6144 .show_host_supported_classes = 1,
6145 .show_host_supported_fc4s = 1,
6146 .show_host_supported_speeds = 1,
6147 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006148
6149 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006150 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04006151
6152 /* dynamic attributes the driver supports */
6153 .get_host_port_id = lpfc_get_host_port_id,
6154 .show_host_port_id = 1,
6155
6156 .get_host_port_type = lpfc_get_host_port_type,
6157 .show_host_port_type = 1,
6158
6159 .get_host_port_state = lpfc_get_host_port_state,
6160 .show_host_port_state = 1,
6161
6162 /* active_fc4s is shown but doesn't change (thus no get function) */
6163 .show_host_active_fc4s = 1,
6164
6165 .get_host_speed = lpfc_get_host_speed,
6166 .show_host_speed = 1,
6167
6168 .get_host_fabric_name = lpfc_get_host_fabric_name,
6169 .show_host_fabric_name = 1,
6170
6171 /*
6172 * The LPFC driver treats linkdown handling as target loss events
6173 * so there are no sysfs handlers for link_down_tmo.
6174 */
6175
6176 .get_fc_host_stats = lpfc_get_stats,
6177 .reset_fc_host_stats = lpfc_reset_stats,
6178
6179 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6180 .show_rport_maxframe_size = 1,
6181 .show_rport_supported_classes = 1,
6182
6183 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6184 .show_rport_dev_loss_tmo = 1,
6185
6186 .get_starget_port_id = lpfc_get_starget_port_id,
6187 .show_starget_port_id = 1,
6188
6189 .get_starget_node_name = lpfc_get_starget_node_name,
6190 .show_starget_node_name = 1,
6191
6192 .get_starget_port_name = lpfc_get_starget_port_name,
6193 .show_starget_port_name = 1,
6194
6195 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6196 .terminate_rport_io = lpfc_terminate_rport_io,
6197
6198 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05006199
6200 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04006201};
6202
James Smarte59058c2008-08-24 21:49:00 -04006203/**
James Smart3621a712009-04-06 18:47:14 -04006204 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04006205 * @phba: lpfc_hba pointer.
6206 **/
dea31012005-04-17 16:05:31 -05006207void
6208lpfc_get_cfgparam(struct lpfc_hba *phba)
6209{
James Smart49aa1432012-08-03 12:36:42 -04006210 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04006211 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006212 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6213 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05006214 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05006215 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6216 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006217 lpfc_ack0_init(phba, lpfc_ack0);
6218 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006219 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05006220 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04006221 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04006222 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04006223 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05006224 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4258e982015-12-16 18:11:58 -05006225 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6226 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
James Smart4ff43242006-12-02 13:34:56 -05006227 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart895427b2017-02-12 13:52:30 -08006228 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
James Smart0cf07f842017-06-01 21:07:10 -07006229 lpfc_auto_imax_init(phba, lpfc_auto_imax);
James Smartda0436e2009-05-22 14:51:39 -04006230 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04006231 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart13815c82008-01-11 01:52:48 -05006232 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6233 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart2ea259e2017-02-12 13:52:27 -08006234
James Smart1ba981f2014-02-20 09:56:45 -05006235 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6236 if (phba->sli_rev != LPFC_SLI_REV4)
6237 phba->cfg_EnableXLane = 0;
6238 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
James Smart2ea259e2017-02-12 13:52:27 -08006239
James Smart1ba981f2014-02-20 09:56:45 -05006240 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6241 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6242 phba->cfg_oas_lun_state = 0;
6243 phba->cfg_oas_lun_status = 0;
6244 phba->cfg_oas_flags = 0;
James Smartc92c8412016-07-06 12:36:05 -07006245 phba->cfg_oas_priority = 0;
James Smart81301a92008-12-04 22:39:46 -05006246 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smartb3b98b72016-10-13 15:06:06 -07006247 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6248 lpfc_prot_guard_init(phba, lpfc_prot_guard);
James Smart45ed1192009-10-02 15:17:02 -04006249 if (phba->sli_rev == LPFC_SLI_REV4)
6250 phba->cfg_poll = 0;
6251 else
James Smart1ba981f2014-02-20 09:56:45 -05006252 phba->cfg_poll = lpfc_poll;
James Smartf358dd02017-02-12 13:52:34 -08006253 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
James Smart4258e982015-12-16 18:11:58 -05006254
James Smart895427b2017-02-12 13:52:30 -08006255 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
James Smart2d7dbc42017-02-12 13:52:35 -08006256 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
James Smart895427b2017-02-12 13:52:30 -08006257
6258 /* Initialize first burst. Target vs Initiator are different. */
6259 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
James Smart2d7dbc42017-02-12 13:52:35 -08006260 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
James Smart895427b2017-02-12 13:52:30 -08006261 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6262 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
James Smart44fd7fe2017-08-23 16:55:47 -07006263 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
James Smart895427b2017-02-12 13:52:30 -08006264
6265 if (phba->sli_rev != LPFC_SLI_REV4) {
6266 /* NVME only supported on SLI4 */
6267 phba->nvmet_support = 0;
6268 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
James Smart44fd7fe2017-08-23 16:55:47 -07006269 phba->cfg_enable_bbcr = 0;
James Smart895427b2017-02-12 13:52:30 -08006270 } else {
6271 /* We MUST have FCP support */
6272 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6273 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6274 }
6275
James Smart0cf07f842017-06-01 21:07:10 -07006276 if (phba->cfg_auto_imax && !phba->cfg_fcp_imax)
6277 phba->cfg_auto_imax = 0;
6278 phba->initial_imax = phba->cfg_fcp_imax;
6279
James Smart895427b2017-02-12 13:52:30 -08006280 /* A value of 0 means use the number of CPUs found in the system */
James Smart895427b2017-02-12 13:52:30 -08006281 if (phba->cfg_fcp_io_channel == 0)
6282 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006283 if (phba->cfg_nvme_io_channel == 0)
6284 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smart895427b2017-02-12 13:52:30 -08006285
6286 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6287 phba->cfg_fcp_io_channel = 0;
6288
James Smartf358dd02017-02-12 13:52:34 -08006289 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6290 phba->cfg_nvme_io_channel = 0;
6291
James Smart895427b2017-02-12 13:52:30 -08006292 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6293 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6294 else
6295 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
James Smart4258e982015-12-16 18:11:58 -05006296
James Smart352e5fd2016-12-30 06:57:47 -08006297 phba->cfg_soft_wwnn = 0L;
6298 phba->cfg_soft_wwpn = 0L;
James Smart895427b2017-02-12 13:52:30 -08006299 lpfc_xri_split_init(phba, lpfc_xri_split);
James Smart83108bd2008-01-11 01:53:09 -05006300 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04006301 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04006302 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04006303 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04006304 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04006305 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05006306 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04006307 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart8eb8b962016-07-06 12:36:08 -07006308 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
James Smart12247e82016-07-06 12:36:09 -07006309 lpfc_sli_mode_init(phba, lpfc_sli_mode);
James Smartab56dc22011-02-16 12:39:57 -05006310 phba->cfg_enable_dss = 1;
James Smart7bdedb32016-07-06 12:36:00 -07006311 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
James Smart3de2a652007-08-02 11:09:59 -04006312 return;
6313}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05006314
James Smarte59058c2008-08-24 21:49:00 -04006315/**
James Smart895427b2017-02-12 13:52:30 -08006316 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6317 * dependencies between protocols and roles.
6318 * @phba: lpfc_hba pointer.
6319 **/
6320void
6321lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6322{
James Smart895427b2017-02-12 13:52:30 -08006323 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6324 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006325
James Smart895427b2017-02-12 13:52:30 -08006326 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6327 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6328
James Smartf358dd02017-02-12 13:52:34 -08006329 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6330 phba->nvmet_support) {
6331 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6332 phba->cfg_fcp_io_channel = 0;
James Smart2d7dbc42017-02-12 13:52:35 -08006333
6334 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6335 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6336 "NVME Target PRLI ACC enable_fb ",
6337 phba->cfg_nvme_enable_fb,
6338 phba->cfg_nvmet_fb_size,
6339 LPFC_NVMET_FB_SZ_MAX);
6340
6341 if (phba->cfg_nvme_enable_fb == 0)
6342 phba->cfg_nvmet_fb_size = 0;
6343 else {
6344 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6345 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6346 }
6347
6348 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6349 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6350 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6351 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6352 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6353 phba->cfg_nvmet_mrq);
6354 }
6355 } else {
James Smartf358dd02017-02-12 13:52:34 -08006356 /* Not NVME Target mode. Turn off Target parameters. */
6357 phba->nvmet_support = 0;
James Smart2d7dbc42017-02-12 13:52:35 -08006358 phba->cfg_nvmet_mrq = 0;
James Smart2d7dbc42017-02-12 13:52:35 -08006359 phba->cfg_nvmet_fb_size = 0;
6360 }
James Smartf358dd02017-02-12 13:52:34 -08006361
James Smart895427b2017-02-12 13:52:30 -08006362 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6363 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6364 else
6365 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6366}
6367
6368/**
James Smart3621a712009-04-06 18:47:14 -04006369 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04006370 * @vport: lpfc_vport pointer.
6371 **/
James Smart3de2a652007-08-02 11:09:59 -04006372void
6373lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6374{
James Smarte8b62012007-08-02 11:10:09 -04006375 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04006376 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04006377 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04006378 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6379 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6380 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6381 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6382 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6383 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04006384 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04006385 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04006386 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6387 lpfc_max_luns_init(vport, lpfc_max_luns);
6388 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04006389 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05006390 return;
6391}