blob: bb2d9e238225a43315fa846ddcab4052b4de1caa [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 Smart93dd1911c2016-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;
151 struct lpfc_nvme_lport *lport;
152 struct lpfc_nvme_rport *rport;
153 struct nvme_fc_remote_port *nrport;
154 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,
174 "NVME Target: Enabled State %s\n",
175 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 Smart547077a2017-05-15 15:20:40 -0700208 "FCP: Rcv %08x Release %08x Drop %08x\n",
James Smartf358dd02017-02-12 13:52:34 -0800209 atomic_read(&tgtp->rcv_fcp_cmd_in),
James Smart547077a2017-05-15 15:20:40 -0700210 atomic_read(&tgtp->xmt_fcp_release),
James Smartf358dd02017-02-12 13:52:34 -0800211 atomic_read(&tgtp->rcv_fcp_cmd_drop));
212
213 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
214 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
215 len += snprintf(buf+len, PAGE_SIZE-len,
216 "Rcv FCP: in %08x != out %08x\n",
217 atomic_read(&tgtp->rcv_fcp_cmd_in),
218 atomic_read(&tgtp->rcv_fcp_cmd_out));
219 }
220
221 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart547077a2017-05-15 15:20:40 -0700222 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
223 "drop %08x\n",
James Smartf358dd02017-02-12 13:52:34 -0800224 atomic_read(&tgtp->xmt_fcp_read),
225 atomic_read(&tgtp->xmt_fcp_read_rsp),
226 atomic_read(&tgtp->xmt_fcp_write),
James Smart547077a2017-05-15 15:20:40 -0700227 atomic_read(&tgtp->xmt_fcp_rsp),
James Smartf358dd02017-02-12 13:52:34 -0800228 atomic_read(&tgtp->xmt_fcp_drop));
229
230 len += snprintf(buf+len, PAGE_SIZE-len,
231 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
232 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
233 atomic_read(&tgtp->xmt_fcp_rsp_error),
234 atomic_read(&tgtp->xmt_fcp_rsp_drop));
235
236 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart547077a2017-05-15 15:20:40 -0700237 "ABORT: Xmt %08x Cmpl %08x\n",
238 atomic_read(&tgtp->xmt_fcp_abort),
239 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
240
241 len += snprintf(buf + len, PAGE_SIZE - len,
242 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
243 atomic_read(&tgtp->xmt_abort_sol),
244 atomic_read(&tgtp->xmt_abort_unsol),
James Smartf358dd02017-02-12 13:52:34 -0800245 atomic_read(&tgtp->xmt_abort_rsp),
James Smart547077a2017-05-15 15:20:40 -0700246 atomic_read(&tgtp->xmt_abort_rsp_error));
James Smartf358dd02017-02-12 13:52:34 -0800247
James Smarta8cf5df2017-05-15 15:20:46 -0700248 len += snprintf(buf + len, PAGE_SIZE - len,
249 "IO_CTX: %08x outstanding %08x total %x",
250 phba->sli4_hba.nvmet_ctx_cnt,
251 phba->sli4_hba.nvmet_io_wait_cnt,
252 phba->sli4_hba.nvmet_io_wait_total);
253
James Smartf358dd02017-02-12 13:52:34 -0800254 len += snprintf(buf+len, PAGE_SIZE-len, "\n");
255 return len;
256 }
James Smart895427b2017-02-12 13:52:30 -0800257
258 localport = vport->localport;
259 if (!localport) {
260 len = snprintf(buf, PAGE_SIZE,
261 "NVME Initiator x%llx is not allocated\n",
262 wwn_to_u64(vport->fc_portname.u.wwn));
263 return len;
264 }
265 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
266
267 spin_lock_irq(shost->host_lock);
268 lport = (struct lpfc_nvme_lport *)localport->private;
269
270 /* Port state is only one of two values for now. */
271 if (localport->port_id)
272 statep = "ONLINE";
273 else
274 statep = "UNKNOWN ";
275
276 len += snprintf(buf + len, PAGE_SIZE - len,
277 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
278 "NVME LPORT lpfc",
279 phba->brd_no,
280 wwn_to_u64(vport->fc_portname.u.wwn),
281 wwn_to_u64(vport->fc_nodename.u.wwn),
282 localport->port_id, statep);
283
284 list_for_each_entry(rport, &lport->rport_list, list) {
285 /* local short-hand pointer. */
286 nrport = rport->remoteport;
287
288 /* Port state is only one of two values for now. */
289 switch (nrport->port_state) {
290 case FC_OBJSTATE_ONLINE:
291 statep = "ONLINE";
292 break;
293 case FC_OBJSTATE_UNKNOWN:
294 statep = "UNKNOWN ";
295 break;
296 default:
297 statep = "UNSUPPORTED";
298 break;
299 }
300
301 /* Tab in to show lport ownership. */
302 len += snprintf(buf + len, PAGE_SIZE - len,
303 "NVME RPORT ");
304 if (phba->brd_no >= 10)
305 len += snprintf(buf + len, PAGE_SIZE - len, " ");
306
307 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ",
308 nrport->port_name);
309 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ",
310 nrport->node_name);
311 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ",
312 nrport->port_id);
313
314 switch (nrport->port_role) {
315 case FC_PORT_ROLE_NVME_INITIATOR:
316 len += snprintf(buf + len, PAGE_SIZE - len,
317 "INITIATOR ");
318 break;
319 case FC_PORT_ROLE_NVME_TARGET:
320 len += snprintf(buf + len, PAGE_SIZE - len,
321 "TARGET ");
322 break;
323 case FC_PORT_ROLE_NVME_DISCOVERY:
324 len += snprintf(buf + len, PAGE_SIZE - len,
325 "DISCOVERY ");
326 break;
327 default:
328 len += snprintf(buf + len, PAGE_SIZE - len,
329 "UNKNOWN_ROLE x%x",
330 nrport->port_role);
331 break;
332 }
333 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep);
334 /* Terminate the string. */
335 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
336 }
337 spin_unlock_irq(shost->host_lock);
338
Maurizio Lombardiea98ab32017-04-18 11:55:51 +0200339 len += snprintf(buf + len, PAGE_SIZE - len, "\nNVME Statistics\n");
James Smart895427b2017-02-12 13:52:30 -0800340 len += snprintf(buf+len, PAGE_SIZE-len,
341 "LS: Xmt %016llx Cmpl %016llx\n",
342 phba->fc4NvmeLsRequests,
343 phba->fc4NvmeLsCmpls);
344
345 len += snprintf(buf+len, PAGE_SIZE-len,
346 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
347 phba->fc4NvmeInputRequests,
348 phba->fc4NvmeOutputRequests,
349 phba->fc4NvmeControlRequests);
350
351 len += snprintf(buf+len, PAGE_SIZE-len,
352 " Cmpl %016llx\n", phba->fc4NvmeIoCmpls);
353
354 return len;
355}
356
357static ssize_t
James Smart81301a92008-12-04 22:39:46 -0500358lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
359 char *buf)
360{
361 struct Scsi_Host *shost = class_to_shost(dev);
362 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
363 struct lpfc_hba *phba = vport->phba;
364
365 if (phba->cfg_enable_bg)
366 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
367 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
368 else
369 return snprintf(buf, PAGE_SIZE,
370 "BlockGuard Not Supported\n");
371 else
372 return snprintf(buf, PAGE_SIZE,
373 "BlockGuard Disabled\n");
374}
375
376static ssize_t
377lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
378 char *buf)
379{
380 struct Scsi_Host *shost = class_to_shost(dev);
381 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
382 struct lpfc_hba *phba = vport->phba;
383
James Smart87b5c322008-12-16 10:34:09 -0500384 return snprintf(buf, PAGE_SIZE, "%llu\n",
385 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500386}
387
388static ssize_t
389lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
390 char *buf)
391{
392 struct Scsi_Host *shost = class_to_shost(dev);
393 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
394 struct lpfc_hba *phba = vport->phba;
395
James Smart87b5c322008-12-16 10:34:09 -0500396 return snprintf(buf, PAGE_SIZE, "%llu\n",
397 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500398}
399
400static ssize_t
401lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
402 char *buf)
403{
404 struct Scsi_Host *shost = class_to_shost(dev);
405 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
406 struct lpfc_hba *phba = vport->phba;
407
James Smart87b5c322008-12-16 10:34:09 -0500408 return snprintf(buf, PAGE_SIZE, "%llu\n",
409 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500410}
411
James Smarte59058c2008-08-24 21:49:00 -0400412/**
James Smart3621a712009-04-06 18:47:14 -0400413 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400414 * @dev: class converted to a Scsi_host structure.
415 * @attr: device attribute, not used.
416 * @buf: on return contains the formatted text from lpfc_info().
417 *
418 * Returns: size of formatted string.
419 **/
dea31012005-04-17 16:05:31 -0500420static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100421lpfc_info_show(struct device *dev, struct device_attribute *attr,
422 char *buf)
dea31012005-04-17 16:05:31 -0500423{
Tony Jonesee959b02008-02-22 00:13:36 +0100424 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500425
dea31012005-04-17 16:05:31 -0500426 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
427}
428
James Smarte59058c2008-08-24 21:49:00 -0400429/**
James Smart3621a712009-04-06 18:47:14 -0400430 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400431 * @dev: class converted to a Scsi_host structure.
432 * @attr: device attribute, not used.
433 * @buf: on return contains the formatted text serial number.
434 *
435 * Returns: size of formatted string.
436 **/
dea31012005-04-17 16:05:31 -0500437static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100438lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
439 char *buf)
dea31012005-04-17 16:05:31 -0500440{
Tony Jonesee959b02008-02-22 00:13:36 +0100441 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500442 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
443 struct lpfc_hba *phba = vport->phba;
444
dea31012005-04-17 16:05:31 -0500445 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
446}
447
James Smarte59058c2008-08-24 21:49:00 -0400448/**
James Smart3621a712009-04-06 18:47:14 -0400449 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400450 * @dev: class converted to a Scsi_host structure.
451 * @attr: device attribute, not used.
452 * @buf: on return contains the formatted support level.
453 *
454 * Description:
455 * Returns a number indicating the temperature sensor level currently
456 * supported, zero or one in ascii.
457 *
458 * Returns: size of formatted string.
459 **/
dea31012005-04-17 16:05:31 -0500460static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100461lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
462 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400463{
Tony Jonesee959b02008-02-22 00:13:36 +0100464 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400465 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
466 struct lpfc_hba *phba = vport->phba;
467 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
468}
469
James Smarte59058c2008-08-24 21:49:00 -0400470/**
James Smart3621a712009-04-06 18:47:14 -0400471 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400472 * @dev: class converted to a Scsi_host structure.
473 * @attr: device attribute, not used.
474 * @buf: on return contains the scsi vpd model description.
475 *
476 * Returns: size of formatted string.
477 **/
James Smart57127f12007-10-27 13:37:05 -0400478static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100479lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
480 char *buf)
dea31012005-04-17 16:05:31 -0500481{
Tony Jonesee959b02008-02-22 00:13:36 +0100482 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500483 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
484 struct lpfc_hba *phba = vport->phba;
485
dea31012005-04-17 16:05:31 -0500486 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
487}
488
James Smarte59058c2008-08-24 21:49:00 -0400489/**
James Smart3621a712009-04-06 18:47:14 -0400490 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400491 * @dev: class converted to a Scsi_host structure.
492 * @attr: device attribute, not used.
493 * @buf: on return contains the scsi vpd model name.
494 *
495 * Returns: size of formatted string.
496 **/
dea31012005-04-17 16:05:31 -0500497static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100498lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
499 char *buf)
dea31012005-04-17 16:05:31 -0500500{
Tony Jonesee959b02008-02-22 00:13:36 +0100501 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500502 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
503 struct lpfc_hba *phba = vport->phba;
504
dea31012005-04-17 16:05:31 -0500505 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
506}
507
James Smarte59058c2008-08-24 21:49:00 -0400508/**
James Smart3621a712009-04-06 18:47:14 -0400509 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400510 * @dev: class converted to a Scsi_host structure.
511 * @attr: device attribute, not used.
512 * @buf: on return contains the scsi vpd program type.
513 *
514 * Returns: size of formatted string.
515 **/
dea31012005-04-17 16:05:31 -0500516static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100517lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
518 char *buf)
dea31012005-04-17 16:05:31 -0500519{
Tony Jonesee959b02008-02-22 00:13:36 +0100520 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500521 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
522 struct lpfc_hba *phba = vport->phba;
523
dea31012005-04-17 16:05:31 -0500524 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
525}
526
James Smarte59058c2008-08-24 21:49:00 -0400527/**
James Smart3621a712009-04-06 18:47:14 -0400528 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400529 * @dev: class converted to a Scsi_host structure.
530 * @attr: device attribute, not used.
531 * @buf: on return contains the Menlo Maintenance sli flag.
532 *
533 * Returns: size of formatted string.
534 **/
535static ssize_t
536lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
537{
538 struct Scsi_Host *shost = class_to_shost(dev);
539 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
540 struct lpfc_hba *phba = vport->phba;
541
542 return snprintf(buf, PAGE_SIZE, "%d\n",
543 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
544}
545
546/**
James Smart3621a712009-04-06 18:47:14 -0400547 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400548 * @dev: class converted to a Scsi_host structure.
549 * @attr: device attribute, not used.
550 * @buf: on return contains scsi vpd program type.
551 *
552 * Returns: size of formatted string.
553 **/
dea31012005-04-17 16:05:31 -0500554static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100555lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
556 char *buf)
dea31012005-04-17 16:05:31 -0500557{
Tony Jonesee959b02008-02-22 00:13:36 +0100558 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500559 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
560 struct lpfc_hba *phba = vport->phba;
561
dea31012005-04-17 16:05:31 -0500562 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
563}
564
James Smarte59058c2008-08-24 21:49:00 -0400565/**
James Smart3621a712009-04-06 18:47:14 -0400566 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400567 * @dev: class converted to a Scsi_host structure.
568 * @attr: device attribute, not used.
569 * @buf: on return contains the scsi vpd program type.
570 *
571 * Returns: size of formatted string.
572 **/
dea31012005-04-17 16:05:31 -0500573static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100574lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
575 char *buf)
dea31012005-04-17 16:05:31 -0500576{
Tony Jonesee959b02008-02-22 00:13:36 +0100577 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500578 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
579 struct lpfc_hba *phba = vport->phba;
James Smart026abb82011-12-13 13:20:45 -0500580 uint32_t if_type;
581 uint8_t sli_family;
James Smart6b5151f2012-01-18 16:24:06 -0500582 char fwrev[FW_REV_STR_SIZE];
James Smart026abb82011-12-13 13:20:45 -0500583 int len;
James Smart2e0fef82007-06-17 19:56:36 -0500584
dea31012005-04-17 16:05:31 -0500585 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart026abb82011-12-13 13:20:45 -0500586 if_type = phba->sli4_hba.pc_sli4_params.if_type;
587 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
588
589 if (phba->sli_rev < LPFC_SLI_REV4)
590 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
591 fwrev, phba->sli_rev);
592 else
593 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
594 fwrev, phba->sli_rev, if_type, sli_family);
595
596 return len;
dea31012005-04-17 16:05:31 -0500597}
598
James Smarte59058c2008-08-24 21:49:00 -0400599/**
James Smart3621a712009-04-06 18:47:14 -0400600 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400601 * @dev: class converted to a Scsi_host structure.
602 * @attr: device attribute, not used.
603 * @buf: on return contains the scsi vpd program type.
604 *
605 * Returns: size of formatted string.
606 **/
dea31012005-04-17 16:05:31 -0500607static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100608lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500609{
610 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100611 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500612 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
613 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500614 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500615
dea31012005-04-17 16:05:31 -0500616 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
617 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
618}
James Smarte59058c2008-08-24 21:49:00 -0400619
620/**
James Smart3621a712009-04-06 18:47:14 -0400621 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400622 * @dev: class converted to a Scsi_host structure.
623 * @attr: device attribute, not used.
624 * @buf: on return contains the ROM and FCode ascii strings.
625 *
626 * Returns: size of formatted string.
627 **/
dea31012005-04-17 16:05:31 -0500628static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100629lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
630 char *buf)
dea31012005-04-17 16:05:31 -0500631{
Tony Jonesee959b02008-02-22 00:13:36 +0100632 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500633 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
634 struct lpfc_hba *phba = vport->phba;
James Smarta0683bf2015-04-07 15:07:16 -0400635 char fwrev[FW_REV_STR_SIZE];
James Smart2e0fef82007-06-17 19:56:36 -0500636
James Smarta0683bf2015-04-07 15:07:16 -0400637 if (phba->sli_rev < LPFC_SLI_REV4)
638 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
639
640 lpfc_decode_firmware_rev(phba, fwrev, 1);
641 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
dea31012005-04-17 16:05:31 -0500642}
James Smarte59058c2008-08-24 21:49:00 -0400643
644/**
James Smart3621a712009-04-06 18:47:14 -0400645 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400646 * @dev: class converted to a Scsi_host structure.
647 * @attr: device attribute, not used.
648 * @buf: on return contains text describing the state of the link.
649 *
650 * Notes:
651 * The switch statement has no default so zero will be returned.
652 *
653 * Returns: size of formatted string.
654 **/
dea31012005-04-17 16:05:31 -0500655static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100656lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
657 char *buf)
dea31012005-04-17 16:05:31 -0500658{
Tony Jonesee959b02008-02-22 00:13:36 +0100659 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500660 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
661 struct lpfc_hba *phba = vport->phba;
662 int len = 0;
663
664 switch (phba->link_state) {
665 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500666 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500667 case LPFC_INIT_START:
668 case LPFC_INIT_MBX_CMDS:
669 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500670 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400671 if (phba->hba_flag & LINK_DISABLED)
672 len += snprintf(buf + len, PAGE_SIZE-len,
673 "Link Down - User disabled\n");
674 else
675 len += snprintf(buf + len, PAGE_SIZE-len,
676 "Link Down\n");
dea31012005-04-17 16:05:31 -0500677 break;
678 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500679 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500680 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400681 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500682
683 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500684 case LPFC_LOCAL_CFG_LINK:
685 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500686 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500687 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500688 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500689 case LPFC_FLOGI:
690 case LPFC_FABRIC_CFG_LINK:
691 case LPFC_NS_REG:
692 case LPFC_NS_QRY:
693 case LPFC_BUILD_DISC_LIST:
694 case LPFC_DISC_AUTH:
695 len += snprintf(buf + len, PAGE_SIZE - len,
696 "Discovery\n");
697 break;
698 case LPFC_VPORT_READY:
699 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
700 break;
701
James Smart92d7f7b2007-06-17 19:56:38 -0500702 case LPFC_VPORT_FAILED:
703 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
704 break;
705
706 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500707 len += snprintf(buf + len, PAGE_SIZE - len,
708 "Unknown\n");
709 break;
710 }
James Smart84774a42008-08-24 21:50:06 -0400711 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
712 len += snprintf(buf + len, PAGE_SIZE-len,
713 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500714 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500715 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500716 len += snprintf(buf + len, PAGE_SIZE-len,
717 " Public Loop\n");
718 else
719 len += snprintf(buf + len, PAGE_SIZE-len,
720 " Private Loop\n");
721 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500722 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500723 len += snprintf(buf + len, PAGE_SIZE-len,
724 " Fabric\n");
725 else
726 len += snprintf(buf + len, PAGE_SIZE-len,
727 " Point-2-Point\n");
728 }
729 }
James Smart2e0fef82007-06-17 19:56:36 -0500730
dea31012005-04-17 16:05:31 -0500731 return len;
732}
733
James Smarte59058c2008-08-24 21:49:00 -0400734/**
James Smart026abb82011-12-13 13:20:45 -0500735 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
736 * @dev: class unused variable.
737 * @attr: device attribute, not used.
738 * @buf: on return contains the module description text.
739 *
740 * Returns: size of formatted string.
741 **/
742static ssize_t
743lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
744 char *buf)
745{
746 struct Scsi_Host *shost = class_to_shost(dev);
747 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
748 struct lpfc_hba *phba = vport->phba;
749
750 if (phba->sli_rev < LPFC_SLI_REV4)
751 return snprintf(buf, PAGE_SIZE, "fc\n");
752
753 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
754 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
755 return snprintf(buf, PAGE_SIZE, "fcoe\n");
756 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
757 return snprintf(buf, PAGE_SIZE, "fc\n");
758 }
759 return snprintf(buf, PAGE_SIZE, "unknown\n");
760}
761
762/**
James Smart1ba981f2014-02-20 09:56:45 -0500763 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
764 * (OAS) is supported.
765 * @dev: class unused variable.
766 * @attr: device attribute, not used.
767 * @buf: on return contains the module description text.
768 *
769 * Returns: size of formatted string.
770 **/
771static ssize_t
772lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
773 char *buf)
774{
775 struct Scsi_Host *shost = class_to_shost(dev);
776 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
777 struct lpfc_hba *phba = vport->phba;
778
779 return snprintf(buf, PAGE_SIZE, "%d\n",
780 phba->sli4_hba.pc_sli4_params.oas_supported);
781}
782
783/**
James Smart84d1b002010-02-12 14:42:33 -0500784 * lpfc_link_state_store - Transition the link_state on an HBA port
785 * @dev: class device that is converted into a Scsi_host.
786 * @attr: device attribute, not used.
787 * @buf: one or more lpfc_polling_flags values.
788 * @count: not used.
789 *
790 * Returns:
791 * -EINVAL if the buffer is not "up" or "down"
792 * return from link state change function if non-zero
793 * length of the buf on success
794 **/
795static ssize_t
796lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
797 const char *buf, size_t count)
798{
799 struct Scsi_Host *shost = class_to_shost(dev);
800 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
801 struct lpfc_hba *phba = vport->phba;
802
803 int status = -EINVAL;
804
805 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
806 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400807 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500808 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
809 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400810 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500811
812 if (status == 0)
813 return strlen(buf);
814 else
815 return status;
816}
817
818/**
James Smart3621a712009-04-06 18:47:14 -0400819 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400820 * @dev: class device that is converted into a Scsi_host.
821 * @attr: device attribute, not used.
822 * @buf: on return contains the sum of fc mapped and unmapped.
823 *
824 * Description:
825 * Returns the ascii text number of the sum of the fc mapped and unmapped
826 * vport counts.
827 *
828 * Returns: size of formatted string.
829 **/
dea31012005-04-17 16:05:31 -0500830static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100831lpfc_num_discovered_ports_show(struct device *dev,
832 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500833{
Tony Jonesee959b02008-02-22 00:13:36 +0100834 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500835 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
836
837 return snprintf(buf, PAGE_SIZE, "%d\n",
838 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500839}
840
James Smarte59058c2008-08-24 21:49:00 -0400841/**
James Smart3621a712009-04-06 18:47:14 -0400842 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400843 * @shost: Scsi_Host pointer.
844 *
845 * Description:
846 * Bring the link down gracefully then re-init the link. The firmware will
847 * re-init the fiber channel interface as required. Does not issue a LIP.
848 *
849 * Returns:
850 * -EPERM port offline or management commands are being blocked
851 * -ENOMEM cannot allocate memory for the mailbox command
852 * -EIO error sending the mailbox command
853 * zero for success
854 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700855static int
James Smart2e0fef82007-06-17 19:56:36 -0500856lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500857{
James Smart2e0fef82007-06-17 19:56:36 -0500858 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
859 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500860 LPFC_MBOXQ_t *pmboxq;
861 int mbxstatus = MBXERR_ERROR;
862
James Smart2e0fef82007-06-17 19:56:36 -0500863 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500864 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500865 return -EPERM;
866
867 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
868
869 if (!pmboxq)
870 return -ENOMEM;
871
872 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400873 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
874 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400875
James Smart33ccf8d2006-08-17 11:57:58 -0400876 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500877
James Smart04c68492009-05-22 14:52:52 -0400878 if ((mbxstatus == MBX_SUCCESS) &&
879 (pmboxq->u.mb.mbxStatus == 0 ||
880 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400881 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
882 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
883 phba->cfg_link_speed);
884 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
885 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400886 if ((mbxstatus == MBX_SUCCESS) &&
887 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
888 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
889 "2859 SLI authentication is required "
890 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400891 }
892
James Smart5b8bd0c2007-04-25 09:52:49 -0400893 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500894 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400895 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500896
897 if (mbxstatus == MBXERR_ERROR)
898 return -EIO;
899
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700900 return 0;
dea31012005-04-17 16:05:31 -0500901}
902
James Smart895427b2017-02-12 13:52:30 -0800903int
904lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
905{
906 int cnt = 0;
907
908 spin_lock_irq(lock);
909 while (!list_empty(q)) {
910 spin_unlock_irq(lock);
911 msleep(20);
912 if (cnt++ > 250) { /* 5 secs */
913 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
914 "0466 %s %s\n",
915 "Outstanding IO when ",
916 "bringing Adapter offline\n");
917 return 0;
918 }
919 spin_lock_irq(lock);
920 }
921 spin_unlock_irq(lock);
922 return 1;
923}
924
James Smarte59058c2008-08-24 21:49:00 -0400925/**
James Smart3621a712009-04-06 18:47:14 -0400926 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400927 * @phba: lpfc_hba pointer.
928 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
929 *
930 * Notes:
931 * Assumes any error from lpfc_do_offline() will be negative.
932 * Can wait up to 5 seconds for the port ring buffers count
933 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400934 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400935 *
936 * Returns:
937 * -EIO error posting the event
938 * zero for success
939 **/
James Smart40496f02006-07-06 15:50:22 -0400940static int
James Smart46fa3112007-04-25 09:51:45 -0400941lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
942{
943 struct completion online_compl;
James Smart895427b2017-02-12 13:52:30 -0800944 struct lpfc_queue *qp = NULL;
James Smart46fa3112007-04-25 09:51:45 -0400945 struct lpfc_sli_ring *pring;
946 struct lpfc_sli *psli;
947 int status = 0;
James Smart46fa3112007-04-25 09:51:45 -0400948 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500949 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400950
951 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500952 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400953 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500954 if (rc == 0)
955 return -ENOMEM;
956
James Smart46fa3112007-04-25 09:51:45 -0400957 wait_for_completion(&online_compl);
958
959 if (status != 0)
960 return -EIO;
961
962 psli = &phba->sli;
963
James Smart09372822008-01-11 01:52:54 -0500964 /* Wait a little for things to settle down, but not
965 * long enough for dev loss timeout to expire.
966 */
James Smart895427b2017-02-12 13:52:30 -0800967 if (phba->sli_rev != LPFC_SLI_REV4) {
968 for (i = 0; i < psli->num_rings; i++) {
969 pring = &psli->sli3_ring[i];
970 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
971 &phba->hbalock))
972 goto out;
973 }
974 } else {
975 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
976 pring = qp->pring;
977 if (!pring)
978 continue;
979 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
980 &pring->ring_lock))
981 goto out;
James Smart46fa3112007-04-25 09:51:45 -0400982 }
983 }
James Smart895427b2017-02-12 13:52:30 -0800984out:
James Smart46fa3112007-04-25 09:51:45 -0400985 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500986 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
987 if (rc == 0)
988 return -ENOMEM;
989
James Smart46fa3112007-04-25 09:51:45 -0400990 wait_for_completion(&online_compl);
991
992 if (status != 0)
993 return -EIO;
994
995 return 0;
996}
997
James Smarte59058c2008-08-24 21:49:00 -0400998/**
James Smart3621a712009-04-06 18:47:14 -0400999 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -04001000 * @phba: lpfc_hba pointer.
1001 *
1002 * Description:
1003 * If the port is configured to allow a reset then the hba is brought
1004 * offline then online.
1005 *
1006 * Notes:
1007 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -05001008 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -04001009 *
1010 * Returns:
1011 * lpfc_do_offline() return code if not zero
1012 * -EIO reset not configured or error posting the event
1013 * zero for success
1014 **/
James Smart7f860592011-03-11 16:05:52 -05001015int
James Smart40496f02006-07-06 15:50:22 -04001016lpfc_selective_reset(struct lpfc_hba *phba)
1017{
1018 struct completion online_compl;
1019 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001020 int rc;
James Smart40496f02006-07-06 15:50:22 -04001021
James Smart71157c92013-07-15 18:34:36 -04001022 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001023 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -05001024
James Smart71157c92013-07-15 18:34:36 -04001025 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1026 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -04001027
James Smart71157c92013-07-15 18:34:36 -04001028 if (status != 0)
1029 return status;
1030 }
James Smart40496f02006-07-06 15:50:22 -04001031
1032 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001033 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -04001034 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -05001035 if (rc == 0)
1036 return -ENOMEM;
1037
James Smart40496f02006-07-06 15:50:22 -04001038 wait_for_completion(&online_compl);
1039
1040 if (status != 0)
1041 return -EIO;
1042
1043 return 0;
1044}
1045
James Smarte59058c2008-08-24 21:49:00 -04001046/**
James Smart3621a712009-04-06 18:47:14 -04001047 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -04001048 * @dev: class device that is converted into a Scsi_host.
1049 * @attr: device attribute, not used.
1050 * @buf: containing the string "selective".
1051 * @count: unused variable.
1052 *
1053 * Description:
1054 * If the buf contains the string "selective" then lpfc_selective_reset()
1055 * is called to perform the reset.
1056 *
1057 * Notes:
1058 * Assumes any error from lpfc_selective_reset() will be negative.
1059 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001060 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -04001061 *
1062 * Returns:
1063 * -EINVAL if the buffer does not contain the string "selective"
1064 * length of buf if lpfc-selective_reset() if the call succeeds
1065 * return value of lpfc_selective_reset() if the call fails
1066**/
James Smart40496f02006-07-06 15:50:22 -04001067static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001068lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1069 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -04001070{
Tony Jonesee959b02008-02-22 00:13:36 +01001071 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001072 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1073 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -04001074 int status = -EINVAL;
1075
James Smart73d91e52011-10-10 21:32:10 -04001076 if (!phba->cfg_enable_hba_reset)
1077 return -EACCES;
1078
James Smart40496f02006-07-06 15:50:22 -04001079 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -05001080 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -04001081
1082 if (status == 0)
1083 return strlen(buf);
1084 else
1085 return status;
1086}
1087
James Smarte59058c2008-08-24 21:49:00 -04001088/**
James Smart88a2cfb2011-07-22 18:36:33 -04001089 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1090 * @phba: lpfc_hba pointer.
1091 *
1092 * Description:
1093 * SLI4 interface type-2 device to wait on the sliport status register for
1094 * the readyness after performing a firmware reset.
1095 *
1096 * Returns:
Masanari Iida0b1587b2013-07-17 04:37:44 +09001097 * zero for success, -EPERM when port does not have privilege to perform the
James Smart026abb82011-12-13 13:20:45 -05001098 * reset, -EIO when port timeout from recovering from the reset.
1099 *
1100 * Note:
1101 * As the caller will interpret the return code by value, be careful in making
1102 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -04001103 **/
James Smart73d91e52011-10-10 21:32:10 -04001104int
James Smart88a2cfb2011-07-22 18:36:33 -04001105lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1106{
James Smartf7a919b2011-08-21 21:49:16 -04001107 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -04001108 int i;
1109
James Smartf7a919b2011-08-21 21:49:16 -04001110 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -04001111 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1112 &portstat_reg.word0);
1113
Masanari Iida0b1587b2013-07-17 04:37:44 +09001114 /* verify if privileged for the request operation */
James Smartf7a919b2011-08-21 21:49:16 -04001115 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1116 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1117 return -EPERM;
1118
James Smart88a2cfb2011-07-22 18:36:33 -04001119 /* wait for the SLI port firmware ready after firmware reset */
1120 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1121 msleep(10);
1122 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1123 &portstat_reg.word0);
1124 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1125 continue;
1126 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1127 continue;
1128 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1129 continue;
1130 break;
1131 }
1132
1133 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1134 return 0;
1135 else
1136 return -EIO;
1137}
1138
1139/**
James Smart52d52442011-05-24 11:42:45 -04001140 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -04001141 * @phba: lpfc_hba pointer.
1142 *
1143 * Description:
James Smart52d52442011-05-24 11:42:45 -04001144 * Request SLI4 interface type-2 device to perform a physical register set
1145 * access.
James Smartc0c11512011-05-24 11:41:34 -04001146 *
1147 * Returns:
1148 * zero for success
1149 **/
1150static ssize_t
James Smart52d52442011-05-24 11:42:45 -04001151lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -04001152{
1153 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -04001154 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -05001155 uint32_t before_fc_flag;
1156 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -04001157 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -05001158 int status = 0, rc = 0;
1159 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -04001160
1161 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001162 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -04001163
James Smart52d52442011-05-24 11:42:45 -04001164 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1165 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1166 LPFC_SLI_INTF_IF_TYPE_2))
1167 return -EPERM;
1168
James Smart026abb82011-12-13 13:20:45 -05001169 /* Keep state if we need to restore back */
1170 before_fc_flag = phba->pport->fc_flag;
1171 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1172
James Smartb76f2dc2011-07-22 18:37:42 -04001173 /* Disable SR-IOV virtual functions if enabled */
1174 if (phba->cfg_sriov_nr_virtfn) {
1175 pci_disable_sriov(pdev);
1176 phba->cfg_sriov_nr_virtfn = 0;
1177 }
James Smart229adb02013-04-17 20:16:51 -04001178
James Smart02936352014-04-04 13:52:12 -04001179 if (opcode == LPFC_FW_DUMP)
1180 phba->hba_flag |= HBA_FW_DUMP_OP;
1181
James Smartc0c11512011-05-24 11:41:34 -04001182 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1183
James Smart02936352014-04-04 13:52:12 -04001184 if (status != 0) {
1185 phba->hba_flag &= ~HBA_FW_DUMP_OP;
James Smartc0c11512011-05-24 11:41:34 -04001186 return status;
James Smart02936352014-04-04 13:52:12 -04001187 }
James Smartc0c11512011-05-24 11:41:34 -04001188
1189 /* wait for the device to be quiesced before firmware reset */
1190 msleep(100);
1191
1192 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1193 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -04001194
1195 if (opcode == LPFC_FW_DUMP)
1196 reg_val |= LPFC_FW_DUMP_REQUEST;
1197 else if (opcode == LPFC_FW_RESET)
1198 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1199 else if (opcode == LPFC_DV_RESET)
1200 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1201
James Smartc0c11512011-05-24 11:41:34 -04001202 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1203 LPFC_CTL_PDEV_CTL_OFFSET);
1204 /* flush */
1205 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1206
1207 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -04001208 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1209
James Smart026abb82011-12-13 13:20:45 -05001210 if (rc == -EPERM) {
Masanari Iida0b1587b2013-07-17 04:37:44 +09001211 /* no privilege for reset */
James Smart6b5151f2012-01-18 16:24:06 -05001212 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
Masanari Iida0b1587b2013-07-17 04:37:44 +09001213 "3150 No privilege to perform the requested "
James Smart6b5151f2012-01-18 16:24:06 -05001214 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -05001215 } else if (rc == -EIO) {
1216 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -05001217 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1218 "3153 Fail to perform the requested "
1219 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -04001220 return rc;
James Smart026abb82011-12-13 13:20:45 -05001221 }
1222
1223 /* keep the original port state */
1224 if (before_fc_flag & FC_OFFLINE_MODE)
1225 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001226
1227 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -05001228 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1229 LPFC_EVT_ONLINE);
1230 if (!job_posted)
1231 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001232
1233 wait_for_completion(&online_compl);
1234
James Smart026abb82011-12-13 13:20:45 -05001235out:
1236 /* in any case, restore the virtual functions enabled as before */
1237 if (sriov_nr_virtfn) {
1238 sriov_err =
1239 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1240 if (!sriov_err)
1241 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1242 }
James Smartc0c11512011-05-24 11:41:34 -04001243
James Smart026abb82011-12-13 13:20:45 -05001244 /* return proper error code */
1245 if (!rc) {
1246 if (!job_posted)
1247 rc = -ENOMEM;
1248 else if (status)
1249 rc = -EIO;
1250 }
1251 return rc;
James Smartc0c11512011-05-24 11:41:34 -04001252}
1253
1254/**
James Smart3621a712009-04-06 18:47:14 -04001255 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -04001256 * @dev: class device that is converted into a Scsi_host.
1257 * @attr: device attribute, not used.
1258 * @buf: on return contains the ascii number of nport events.
1259 *
1260 * Returns: size of formatted string.
1261 **/
dea31012005-04-17 16:05:31 -05001262static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001263lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1264 char *buf)
dea31012005-04-17 16:05:31 -05001265{
Tony Jonesee959b02008-02-22 00:13:36 +01001266 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001267 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1268 struct lpfc_hba *phba = vport->phba;
1269
dea31012005-04-17 16:05:31 -05001270 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1271}
1272
James Smarte59058c2008-08-24 21:49:00 -04001273/**
James Smart3621a712009-04-06 18:47:14 -04001274 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -04001275 * @dev: class device that is converted into a Scsi_host.
1276 * @attr: device attribute, not used.
1277 * @buf: on return contains the state of the adapter.
1278 *
1279 * Returns: size of formatted string.
1280 **/
dea31012005-04-17 16:05:31 -05001281static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001282lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1283 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001284{
Tony Jonesee959b02008-02-22 00:13:36 +01001285 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001286 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1287 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001288 char * state;
1289
James Smart2e0fef82007-06-17 19:56:36 -05001290 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001291 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001292 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001293 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001294 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001295 state = "offline";
1296 else
1297 state = "online";
1298
1299 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1300}
1301
James Smarte59058c2008-08-24 21:49:00 -04001302/**
James Smart3621a712009-04-06 18:47:14 -04001303 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001304 * @dev: class device that is converted into a Scsi_host.
1305 * @attr: device attribute, not used.
1306 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1307 * @count: unused variable.
1308 *
1309 * Returns:
1310 * -EACCES if enable hba reset not enabled
1311 * -EINVAL if the buffer does not contain a valid string (see above)
1312 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1313 * buf length greater than zero indicates success
1314 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001315static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001316lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1317 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001318{
Tony Jonesee959b02008-02-22 00:13:36 +01001319 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001320 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1321 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001322 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001323 char *board_mode_str = NULL;
1324 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001325 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001326
James Smart026abb82011-12-13 13:20:45 -05001327 if (!phba->cfg_enable_hba_reset) {
1328 status = -EACCES;
1329 goto board_mode_out;
1330 }
James Smart88a2cfb2011-07-22 18:36:33 -04001331
1332 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001333 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001334
Jamie Wellnitz41415862006-02-28 19:25:27 -05001335 init_completion(&online_compl);
1336
James Smart46fa3112007-04-25 09:51:45 -04001337 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001338 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001339 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001340 if (rc == 0) {
1341 status = -ENOMEM;
1342 goto board_mode_out;
1343 }
James Smart46fa3112007-04-25 09:51:45 -04001344 wait_for_completion(&online_compl);
1345 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1346 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001347 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001348 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001349 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001350 else
1351 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001352 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001353 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001354 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001355 else
1356 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001357 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001358 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1359 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1360 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1361 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1362 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001363 else
James Smart026abb82011-12-13 13:20:45 -05001364 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001365
James Smart026abb82011-12-13 13:20:45 -05001366board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001367 if (!status)
1368 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001369 else {
1370 board_mode_str = strchr(buf, '\n');
1371 if (board_mode_str)
1372 *board_mode_str = '\0';
1373 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1374 "3097 Failed \"%s\", status(%d), "
1375 "fc_flag(x%x)\n",
1376 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001377 return status;
James Smart026abb82011-12-13 13:20:45 -05001378 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001379}
1380
James Smarte59058c2008-08-24 21:49:00 -04001381/**
James Smart3621a712009-04-06 18:47:14 -04001382 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001383 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001384 * @mxri: max xri count.
1385 * @axri: available xri count.
1386 * @mrpi: max rpi count.
1387 * @arpi: available rpi count.
1388 * @mvpi: max vpi count.
1389 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001390 *
1391 * Description:
1392 * If an integer pointer for an count is not null then the value for the
1393 * count is returned.
1394 *
1395 * Returns:
1396 * zero on error
1397 * one for success
1398 **/
James Smart311464e2007-08-02 11:10:37 -04001399static int
James Smart858c9f62007-06-17 19:56:39 -05001400lpfc_get_hba_info(struct lpfc_hba *phba,
1401 uint32_t *mxri, uint32_t *axri,
1402 uint32_t *mrpi, uint32_t *arpi,
1403 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001404{
James Smart04c68492009-05-22 14:52:52 -04001405 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001406 LPFC_MBOXQ_t *pmboxq;
1407 MAILBOX_t *pmb;
1408 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001409 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001410
1411 /*
1412 * prevent udev from issuing mailbox commands until the port is
1413 * configured.
1414 */
1415 if (phba->link_state < LPFC_LINK_DOWN ||
1416 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001417 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001418 return 0;
1419
1420 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1421 return 0;
1422
1423 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1424 if (!pmboxq)
1425 return 0;
1426 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1427
James Smart04c68492009-05-22 14:52:52 -04001428 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001429 pmb->mbxCommand = MBX_READ_CONFIG;
1430 pmb->mbxOwner = OWN_HOST;
1431 pmboxq->context1 = NULL;
1432
James Smart75baf692010-06-08 18:31:21 -04001433 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001434 rc = MBX_NOT_FINISHED;
1435 else
1436 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1437
1438 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001439 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001440 mempool_free(pmboxq, phba->mbox_mem_pool);
1441 return 0;
1442 }
1443
James Smartda0436e2009-05-22 14:51:39 -04001444 if (phba->sli_rev == LPFC_SLI_REV4) {
1445 rd_config = &pmboxq->u.mqe.un.rd_config;
1446 if (mrpi)
1447 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1448 if (arpi)
1449 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1450 phba->sli4_hba.max_cfg_param.rpi_used;
1451 if (mxri)
1452 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1453 if (axri)
1454 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1455 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001456
1457 /* Account for differences with SLI-3. Get vpi count from
1458 * mailbox data and subtract one for max vpi value.
1459 */
1460 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1461 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1462
James Smartda0436e2009-05-22 14:51:39 -04001463 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001464 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001465 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001466 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001467 } else {
1468 if (mrpi)
1469 *mrpi = pmb->un.varRdConfig.max_rpi;
1470 if (arpi)
1471 *arpi = pmb->un.varRdConfig.avail_rpi;
1472 if (mxri)
1473 *mxri = pmb->un.varRdConfig.max_xri;
1474 if (axri)
1475 *axri = pmb->un.varRdConfig.avail_xri;
1476 if (mvpi)
1477 *mvpi = pmb->un.varRdConfig.max_vpi;
1478 if (avpi)
1479 *avpi = pmb->un.varRdConfig.avail_vpi;
1480 }
James Smart92d7f7b2007-06-17 19:56:38 -05001481
1482 mempool_free(pmboxq, phba->mbox_mem_pool);
1483 return 1;
1484}
1485
James Smarte59058c2008-08-24 21:49:00 -04001486/**
James Smart3621a712009-04-06 18:47:14 -04001487 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001488 * @dev: class device that is converted into a Scsi_host.
1489 * @attr: device attribute, not used.
1490 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1491 *
1492 * Description:
1493 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1494 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1495 * to "Unknown" and the buffer length is returned, therefore the caller
1496 * must check for "Unknown" in the buffer to detect a failure.
1497 *
1498 * Returns: size of formatted string.
1499 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001500static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001501lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1502 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001503{
Tony Jonesee959b02008-02-22 00:13:36 +01001504 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001505 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1506 struct lpfc_hba *phba = vport->phba;
1507 uint32_t cnt;
1508
James Smart858c9f62007-06-17 19:56:39 -05001509 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001510 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1511 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1512}
1513
James Smarte59058c2008-08-24 21:49:00 -04001514/**
James Smart3621a712009-04-06 18:47:14 -04001515 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001516 * @dev: class device that is converted into a Scsi_host.
1517 * @attr: device attribute, not used.
1518 * @buf: containing the used rpi count in decimal or "Unknown".
1519 *
1520 * Description:
1521 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1522 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1523 * to "Unknown" and the buffer length is returned, therefore the caller
1524 * must check for "Unknown" in the buffer to detect a failure.
1525 *
1526 * Returns: size of formatted string.
1527 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001528static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001529lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1530 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001531{
Tony Jonesee959b02008-02-22 00:13:36 +01001532 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001533 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1534 struct lpfc_hba *phba = vport->phba;
1535 uint32_t cnt, acnt;
1536
James Smart858c9f62007-06-17 19:56:39 -05001537 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001538 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1539 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1540}
1541
James Smarte59058c2008-08-24 21:49:00 -04001542/**
James Smart3621a712009-04-06 18:47:14 -04001543 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001544 * @dev: class device that is converted into a Scsi_host.
1545 * @attr: device attribute, not used.
1546 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1547 *
1548 * Description:
1549 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1550 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1551 * to "Unknown" and the buffer length is returned, therefore the caller
1552 * must check for "Unknown" in the buffer to detect a failure.
1553 *
1554 * Returns: size of formatted string.
1555 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001556static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001557lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1558 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001559{
Tony Jonesee959b02008-02-22 00:13:36 +01001560 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001561 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1562 struct lpfc_hba *phba = vport->phba;
1563 uint32_t cnt;
1564
James Smart858c9f62007-06-17 19:56:39 -05001565 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001566 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1567 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1568}
1569
James Smarte59058c2008-08-24 21:49:00 -04001570/**
James Smart3621a712009-04-06 18:47:14 -04001571 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001572 * @dev: class device that is converted into a Scsi_host.
1573 * @attr: device attribute, not used.
1574 * @buf: on return contains the used xri count in decimal or "Unknown".
1575 *
1576 * Description:
1577 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1578 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1579 * to "Unknown" and the buffer length is returned, therefore the caller
1580 * must check for "Unknown" in the buffer to detect a failure.
1581 *
1582 * Returns: size of formatted string.
1583 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001584static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001585lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1586 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001587{
Tony Jonesee959b02008-02-22 00:13:36 +01001588 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001589 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1590 struct lpfc_hba *phba = vport->phba;
1591 uint32_t cnt, acnt;
1592
James Smart858c9f62007-06-17 19:56:39 -05001593 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1594 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1595 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1596}
1597
James Smarte59058c2008-08-24 21:49:00 -04001598/**
James Smart3621a712009-04-06 18:47:14 -04001599 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001600 * @dev: class device that is converted into a Scsi_host.
1601 * @attr: device attribute, not used.
1602 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1603 *
1604 * Description:
1605 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1606 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1607 * to "Unknown" and the buffer length is returned, therefore the caller
1608 * must check for "Unknown" in the buffer to detect a failure.
1609 *
1610 * Returns: size of formatted string.
1611 **/
James Smart858c9f62007-06-17 19:56:39 -05001612static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001613lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1614 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001615{
Tony Jonesee959b02008-02-22 00:13:36 +01001616 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001617 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1618 struct lpfc_hba *phba = vport->phba;
1619 uint32_t cnt;
1620
1621 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1622 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1623 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1624}
1625
James Smarte59058c2008-08-24 21:49:00 -04001626/**
James Smart3621a712009-04-06 18:47:14 -04001627 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001628 * @dev: class device that is converted into a Scsi_host.
1629 * @attr: device attribute, not used.
1630 * @buf: on return contains the used vpi count in decimal or "Unknown".
1631 *
1632 * Description:
1633 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1634 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1635 * to "Unknown" and the buffer length is returned, therefore the caller
1636 * must check for "Unknown" in the buffer to detect a failure.
1637 *
1638 * Returns: size of formatted string.
1639 **/
James Smart858c9f62007-06-17 19:56:39 -05001640static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001641lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1642 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001643{
Tony Jonesee959b02008-02-22 00:13:36 +01001644 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001645 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1646 struct lpfc_hba *phba = vport->phba;
1647 uint32_t cnt, acnt;
1648
1649 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001650 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1651 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1652}
1653
James Smarte59058c2008-08-24 21:49:00 -04001654/**
James Smart3621a712009-04-06 18:47:14 -04001655 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001656 * @dev: class device that is converted into a Scsi_host.
1657 * @attr: device attribute, not used.
1658 * @buf: text that must be interpreted to determine if npiv is supported.
1659 *
1660 * Description:
1661 * Buffer will contain text indicating npiv is not suppoerted on the port,
1662 * the port is an NPIV physical port, or it is an npiv virtual port with
1663 * the id of the vport.
1664 *
1665 * Returns: size of formatted string.
1666 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001667static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001668lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1669 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001670{
Tony Jonesee959b02008-02-22 00:13:36 +01001671 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001672 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1673 struct lpfc_hba *phba = vport->phba;
1674
1675 if (!(phba->max_vpi))
1676 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1677 if (vport->port_type == LPFC_PHYSICAL_PORT)
1678 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1679 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1680}
1681
James Smarte59058c2008-08-24 21:49:00 -04001682/**
James Smart3621a712009-04-06 18:47:14 -04001683 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001684 * @dev: class device that is converted into a Scsi_host.
1685 * @attr: device attribute, not used.
1686 * @buf: on return contains the cfg_poll in hex.
1687 *
1688 * Notes:
1689 * cfg_poll should be a lpfc_polling_flags type.
1690 *
1691 * Returns: size of formatted string.
1692 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001693static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001694lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1695 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001696{
Tony Jonesee959b02008-02-22 00:13:36 +01001697 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001698 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1699 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001700
1701 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1702}
1703
James Smarte59058c2008-08-24 21:49:00 -04001704/**
James Smart3621a712009-04-06 18:47:14 -04001705 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001706 * @dev: class device that is converted into a Scsi_host.
1707 * @attr: device attribute, not used.
1708 * @buf: one or more lpfc_polling_flags values.
1709 * @count: not used.
1710 *
1711 * Notes:
1712 * buf contents converted to integer and checked for a valid value.
1713 *
1714 * Returns:
1715 * -EINVAL if the buffer connot be converted or is out of range
1716 * length of the buf on success
1717 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001718static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001719lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1720 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001721{
Tony Jonesee959b02008-02-22 00:13:36 +01001722 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001723 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1724 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001725 uint32_t creg_val;
1726 uint32_t old_val;
1727 int val=0;
1728
1729 if (!isdigit(buf[0]))
1730 return -EINVAL;
1731
1732 if (sscanf(buf, "%i", &val) != 1)
1733 return -EINVAL;
1734
1735 if ((val & 0x3) != val)
1736 return -EINVAL;
1737
James Smart45ed1192009-10-02 15:17:02 -04001738 if (phba->sli_rev == LPFC_SLI_REV4)
1739 val = 0;
1740
James Smart88a2cfb2011-07-22 18:36:33 -04001741 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1742 "3051 lpfc_poll changed from %d to %d\n",
1743 phba->cfg_poll, val);
1744
James Smart2e0fef82007-06-17 19:56:36 -05001745 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001746
1747 old_val = phba->cfg_poll;
1748
1749 if (val & ENABLE_FCP_RING_POLLING) {
1750 if ((val & DISABLE_FCP_RING_INT) &&
1751 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001752 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1753 spin_unlock_irq(&phba->hbalock);
1754 return -EINVAL;
1755 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001756 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1757 writel(creg_val, phba->HCregaddr);
1758 readl(phba->HCregaddr); /* flush */
1759
1760 lpfc_poll_start_timer(phba);
1761 }
1762 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001763 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001764 return -EINVAL;
1765 }
1766
1767 if (!(val & DISABLE_FCP_RING_INT) &&
1768 (old_val & DISABLE_FCP_RING_INT))
1769 {
James Smart2e0fef82007-06-17 19:56:36 -05001770 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001771 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001772 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001773 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1774 spin_unlock_irq(&phba->hbalock);
1775 return -EINVAL;
1776 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001777 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1778 writel(creg_val, phba->HCregaddr);
1779 readl(phba->HCregaddr); /* flush */
1780 }
1781
1782 phba->cfg_poll = val;
1783
James Smart2e0fef82007-06-17 19:56:36 -05001784 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001785
1786 return strlen(buf);
1787}
dea31012005-04-17 16:05:31 -05001788
James Smarte59058c2008-08-24 21:49:00 -04001789/**
James Smartbc739052010-08-04 16:11:18 -04001790 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1791 * @dev: class unused variable.
1792 * @attr: device attribute, not used.
1793 * @buf: on return contains the module description text.
1794 *
1795 * Returns: size of formatted string.
1796 **/
1797static ssize_t
1798lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1799 char *buf)
1800{
1801 struct Scsi_Host *shost = class_to_shost(dev);
1802 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1803 struct lpfc_hba *phba = vport->phba;
1804
1805 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1806}
1807
1808/**
1809 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1810 * @dev: class unused variable.
1811 * @attr: device attribute, not used.
1812 * @buf: on return contains the module description text.
1813 *
1814 * Returns: size of formatted string.
1815 **/
1816static ssize_t
1817lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1818 char *buf)
1819{
1820 struct Scsi_Host *shost = class_to_shost(dev);
1821 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1822 struct lpfc_hba *phba = vport->phba;
1823
1824 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1825}
1826
1827/**
James Smartab56dc22011-02-16 12:39:57 -05001828 * lpfc_dss_show - Return the current state of dss and the configured state
1829 * @dev: class converted to a Scsi_host structure.
1830 * @attr: device attribute, not used.
1831 * @buf: on return contains the formatted text.
1832 *
1833 * Returns: size of formatted string.
1834 **/
1835static ssize_t
1836lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1837 char *buf)
1838{
1839 struct Scsi_Host *shost = class_to_shost(dev);
1840 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1841 struct lpfc_hba *phba = vport->phba;
1842
1843 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1844 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1845 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1846 "" : "Not ");
1847}
1848
1849/**
James Smart912e3ac2011-05-24 11:42:11 -04001850 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1851 * @dev: class converted to a Scsi_host structure.
1852 * @attr: device attribute, not used.
1853 * @buf: on return contains the formatted support level.
1854 *
1855 * Description:
1856 * Returns the maximum number of virtual functions a physical function can
1857 * support, 0 will be returned if called on virtual function.
1858 *
1859 * Returns: size of formatted string.
1860 **/
1861static ssize_t
1862lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1863 struct device_attribute *attr,
1864 char *buf)
1865{
1866 struct Scsi_Host *shost = class_to_shost(dev);
1867 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1868 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001869 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001870
James Smart0a96e972011-07-22 18:37:28 -04001871 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1872 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001873}
1874
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001875static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1876{
1877 return val >= min && val <= max;
1878}
1879
James Smart912e3ac2011-05-24 11:42:11 -04001880/**
James Smart3621a712009-04-06 18:47:14 -04001881 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001882 *
1883 * Description:
1884 * Macro that given an attr e.g. hba_queue_depth expands
1885 * into a function with the name lpfc_hba_queue_depth_show.
1886 *
1887 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1888 * @dev: class device that is converted into a Scsi_host.
1889 * @attr: device attribute, not used.
1890 * @buf: on return contains the attribute value in decimal.
1891 *
1892 * Returns: size of formatted string.
1893 **/
dea31012005-04-17 16:05:31 -05001894#define lpfc_param_show(attr) \
1895static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001896lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1897 char *buf) \
dea31012005-04-17 16:05:31 -05001898{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001899 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001900 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1901 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb7522005-10-28 20:29:13 -04001902 return snprintf(buf, PAGE_SIZE, "%d\n",\
1903 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001904}
1905
James Smarte59058c2008-08-24 21:49:00 -04001906/**
James Smart3621a712009-04-06 18:47:14 -04001907 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001908 *
1909 * Description:
1910 * Macro that given an attr e.g. hba_queue_depth expands
1911 * into a function with the name lpfc_hba_queue_depth_show
1912 *
1913 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1914 * @dev: class device that is converted into a Scsi_host.
1915 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001916 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001917 *
1918 * Returns: size of formatted string.
1919 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001920#define lpfc_param_hex_show(attr) \
1921static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001922lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1923 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001924{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001925 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001926 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1927 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001928 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001929 val = phba->cfg_##attr;\
1930 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1931 phba->cfg_##attr);\
1932}
1933
James Smarte59058c2008-08-24 21:49:00 -04001934/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001935 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001936 *
1937 * Description:
1938 * Macro that given an attr e.g. hba_queue_depth expands
1939 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1940 * takes a default argument, a minimum and maximum argument.
1941 *
1942 * lpfc_##attr##_init: Initializes an attribute.
1943 * @phba: pointer the the adapter structure.
1944 * @val: integer attribute value.
1945 *
1946 * Validates the min and max values then sets the adapter config field
1947 * accordingly, or uses the default if out of range and prints an error message.
1948 *
1949 * Returns:
1950 * zero on success
1951 * -EINVAL if default used
1952 **/
James.Smart@Emulex.Com7bcbb7522005-10-28 20:29:13 -04001953#define lpfc_param_init(attr, default, minval, maxval) \
1954static int \
James Smart84d1b002010-02-12 14:42:33 -05001955lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb7522005-10-28 20:29:13 -04001956{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001957 if (lpfc_rangecheck(val, minval, maxval)) {\
James.Smart@Emulex.Com7bcbb7522005-10-28 20:29:13 -04001958 phba->cfg_##attr = val;\
1959 return 0;\
1960 }\
1961 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001962 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1963 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb7522005-10-28 20:29:13 -04001964 phba->cfg_##attr = default;\
1965 return -EINVAL;\
1966}
1967
James Smarte59058c2008-08-24 21:49:00 -04001968/**
James Smart3621a712009-04-06 18:47:14 -04001969 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001970 *
1971 * Description:
1972 * Macro that given an attr e.g. hba_queue_depth expands
1973 * into a function with the name lpfc_hba_queue_depth_set
1974 *
1975 * lpfc_##attr##_set: Sets an attribute value.
1976 * @phba: pointer the the adapter structure.
1977 * @val: integer attribute value.
1978 *
1979 * Description:
1980 * Validates the min and max values then sets the
1981 * adapter config field if in the valid range. prints error message
1982 * and does not set the parameter if invalid.
1983 *
1984 * Returns:
1985 * zero on success
1986 * -EINVAL if val is invalid
1987 **/
James.Smart@Emulex.Com7bcbb7522005-10-28 20:29:13 -04001988#define lpfc_param_set(attr, default, minval, maxval) \
1989static int \
James Smart84d1b002010-02-12 14:42:33 -05001990lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb7522005-10-28 20:29:13 -04001991{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001992 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001993 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1994 "3052 lpfc_" #attr " changed from %d to %d\n", \
1995 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb7522005-10-28 20:29:13 -04001996 phba->cfg_##attr = val;\
1997 return 0;\
1998 }\
1999 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04002000 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2001 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb7522005-10-28 20:29:13 -04002002 return -EINVAL;\
2003}
2004
James Smarte59058c2008-08-24 21:49:00 -04002005/**
James Smart3621a712009-04-06 18:47:14 -04002006 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04002007 *
2008 * Description:
2009 * Macro that given an attr e.g. hba_queue_depth expands
2010 * into a function with the name lpfc_hba_queue_depth_store.
2011 *
2012 * lpfc_##attr##_store: Set an sttribute value.
2013 * @dev: class device that is converted into a Scsi_host.
2014 * @attr: device attribute, not used.
2015 * @buf: contains the attribute value in ascii.
2016 * @count: not used.
2017 *
2018 * Description:
2019 * Convert the ascii text number to an integer, then
2020 * use the lpfc_##attr##_set function to set the value.
2021 *
2022 * Returns:
2023 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2024 * length of buffer upon success.
2025 **/
James.Smart@Emulex.Com7bcbb7522005-10-28 20:29:13 -04002026#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05002027static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002028lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2029 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05002030{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002031 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002032 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2033 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05002034 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002035 if (!isdigit(buf[0]))\
2036 return -EINVAL;\
2037 if (sscanf(buf, "%i", &val) != 1)\
2038 return -EINVAL;\
James.Smart@Emulex.Com7bcbb7522005-10-28 20:29:13 -04002039 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04002040 return strlen(buf);\
James.Smart@Emulex.Com7bcbb7522005-10-28 20:29:13 -04002041 else \
2042 return -EINVAL;\
dea31012005-04-17 16:05:31 -05002043}
2044
James Smarte59058c2008-08-24 21:49:00 -04002045/**
James Smart3621a712009-04-06 18:47:14 -04002046 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04002047 *
2048 * Description:
2049 * Macro that given an attr e.g. hba_queue_depth expands
2050 * into a function with the name lpfc_hba_queue_depth_show
2051 *
2052 * lpfc_##attr##_show: prints the attribute value in decimal.
2053 * @dev: class device that is converted into a Scsi_host.
2054 * @attr: device attribute, not used.
2055 * @buf: on return contains the attribute value in decimal.
2056 *
2057 * Returns: length of formatted string.
2058 **/
James Smart3de2a652007-08-02 11:09:59 -04002059#define lpfc_vport_param_show(attr) \
2060static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002061lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2062 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002063{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002064 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002065 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002066 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2067}
2068
James Smarte59058c2008-08-24 21:49:00 -04002069/**
James Smart3621a712009-04-06 18:47:14 -04002070 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04002071 *
2072 * Description:
2073 * Macro that given an attr e.g.
2074 * hba_queue_depth expands into a function with the name
2075 * lpfc_hba_queue_depth_show
2076 *
James Smart3621a712009-04-06 18:47:14 -04002077 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002078 * @dev: class device that is converted into a Scsi_host.
2079 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002080 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002081 *
2082 * Returns: length of formatted string.
2083 **/
James Smart3de2a652007-08-02 11:09:59 -04002084#define lpfc_vport_param_hex_show(attr) \
2085static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002086lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2087 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002088{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002089 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002090 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002091 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2092}
2093
James Smarte59058c2008-08-24 21:49:00 -04002094/**
James Smart3621a712009-04-06 18:47:14 -04002095 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002096 *
2097 * Description:
2098 * Macro that given an attr e.g. hba_queue_depth expands
2099 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2100 * takes a default argument, a minimum and maximum argument.
2101 *
2102 * lpfc_##attr##_init: validates the min and max values then sets the
2103 * adapter config field accordingly, or uses the default if out of range
2104 * and prints an error message.
2105 * @phba: pointer the the adapter structure.
2106 * @val: integer attribute value.
2107 *
2108 * Returns:
2109 * zero on success
2110 * -EINVAL if default used
2111 **/
James Smart3de2a652007-08-02 11:09:59 -04002112#define lpfc_vport_param_init(attr, default, minval, maxval) \
2113static int \
James Smart84d1b002010-02-12 14:42:33 -05002114lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002115{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002116 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart3de2a652007-08-02 11:09:59 -04002117 vport->cfg_##attr = val;\
2118 return 0;\
2119 }\
James Smarte8b62012007-08-02 11:10:09 -04002120 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002121 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002122 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002123 vport->cfg_##attr = default;\
2124 return -EINVAL;\
2125}
2126
James Smarte59058c2008-08-24 21:49:00 -04002127/**
James Smart3621a712009-04-06 18:47:14 -04002128 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002129 *
2130 * Description:
2131 * Macro that given an attr e.g. hba_queue_depth expands
2132 * into a function with the name lpfc_hba_queue_depth_set
2133 *
2134 * lpfc_##attr##_set: validates the min and max values then sets the
2135 * adapter config field if in the valid range. prints error message
2136 * and does not set the parameter if invalid.
2137 * @phba: pointer the the adapter structure.
2138 * @val: integer attribute value.
2139 *
2140 * Returns:
2141 * zero on success
2142 * -EINVAL if val is invalid
2143 **/
James Smart3de2a652007-08-02 11:09:59 -04002144#define lpfc_vport_param_set(attr, default, minval, maxval) \
2145static int \
James Smart84d1b002010-02-12 14:42:33 -05002146lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002147{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002148 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002149 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04002150 "3053 lpfc_" #attr \
2151 " changed from %d (x%x) to %d (x%x)\n", \
2152 vport->cfg_##attr, vport->cfg_##attr, \
2153 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04002154 vport->cfg_##attr = val;\
2155 return 0;\
2156 }\
James Smarte8b62012007-08-02 11:10:09 -04002157 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002158 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002159 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002160 return -EINVAL;\
2161}
2162
James Smarte59058c2008-08-24 21:49:00 -04002163/**
James Smart3621a712009-04-06 18:47:14 -04002164 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04002165 *
2166 * Description:
2167 * Macro that given an attr e.g. hba_queue_depth
2168 * expands into a function with the name lpfc_hba_queue_depth_store
2169 *
2170 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2171 * use the lpfc_##attr##_set function to set the value.
2172 * @cdev: class device that is converted into a Scsi_host.
2173 * @buf: contains the attribute value in decimal.
2174 * @count: not used.
2175 *
2176 * Returns:
2177 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2178 * length of buffer upon success.
2179 **/
James Smart3de2a652007-08-02 11:09:59 -04002180#define lpfc_vport_param_store(attr) \
2181static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002182lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2183 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04002184{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002185 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002186 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05002187 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04002188 if (!isdigit(buf[0]))\
2189 return -EINVAL;\
2190 if (sscanf(buf, "%i", &val) != 1)\
2191 return -EINVAL;\
2192 if (lpfc_##attr##_set(vport, val) == 0) \
2193 return strlen(buf);\
2194 else \
2195 return -EINVAL;\
2196}
2197
2198
James Smart895427b2017-02-12 13:52:30 -08002199static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
James Smart81301a92008-12-04 22:39:46 -05002200static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2201static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2202static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2203static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002204static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2205static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2206static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2207static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2208static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2209static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2210static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2211static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002212static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2213 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002214static DEVICE_ATTR(option_rom_version, S_IRUGO,
2215 lpfc_option_rom_version_show, NULL);
2216static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2217 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002218static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002219static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2220static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04002221static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002222static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2223 lpfc_board_mode_show, lpfc_board_mode_store);
2224static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2225static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2226static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2227static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2228static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2229static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2230static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2231static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2232static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04002233static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2234static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05002235static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04002236static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2237 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smart026abb82011-12-13 13:20:45 -05002238static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05002239static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2240 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002241
James Smart352e5fd2016-12-30 06:57:47 -08002242static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smart1ba981f2014-02-20 09:56:45 -05002243#define WWN_SZ 8
2244/**
2245 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2246 * @buf: WWN string.
2247 * @cnt: Length of string.
2248 * @wwn: Array to receive converted wwn value.
2249 *
2250 * Returns:
2251 * -EINVAL if the buffer does not contain a valid wwn
2252 * 0 success
2253 **/
2254static size_t
2255lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2256{
2257 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002258
James Smart1ba981f2014-02-20 09:56:45 -05002259 /* Count may include a LF at end of string */
2260 if (buf[cnt-1] == '\n')
2261 cnt--;
2262
2263 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2264 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2265 return -EINVAL;
2266
2267 memset(wwn, 0, WWN_SZ);
2268
2269 /* Validate and store the new name */
2270 for (i = 0, j = 0; i < 16; i++) {
2271 if ((*buf >= 'a') && (*buf <= 'f'))
2272 j = ((j << 4) | ((*buf++ - 'a') + 10));
2273 else if ((*buf >= 'A') && (*buf <= 'F'))
2274 j = ((j << 4) | ((*buf++ - 'A') + 10));
2275 else if ((*buf >= '0') && (*buf <= '9'))
2276 j = ((j << 4) | (*buf++ - '0'));
2277 else
2278 return -EINVAL;
2279 if (i % 2) {
2280 wwn[i/2] = j & 0xff;
2281 j = 0;
2282 }
2283 }
2284 return 0;
2285}
James Smart352e5fd2016-12-30 06:57:47 -08002286/**
2287 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2288 * @dev: class device that is converted into a Scsi_host.
2289 * @attr: device attribute, not used.
2290 * @buf: containing the string lpfc_soft_wwn_key.
2291 * @count: must be size of lpfc_soft_wwn_key.
2292 *
2293 * Returns:
2294 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2295 * length of buf indicates success
2296 **/
2297static ssize_t
2298lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2299 const char *buf, size_t count)
2300{
2301 struct Scsi_Host *shost = class_to_shost(dev);
2302 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2303 struct lpfc_hba *phba = vport->phba;
2304 unsigned int cnt = count;
James Smartaeb3c812017-04-21 16:05:02 -07002305 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2306 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
James Smart352e5fd2016-12-30 06:57:47 -08002307
2308 /*
2309 * We're doing a simple sanity check for soft_wwpn setting.
2310 * We require that the user write a specific key to enable
2311 * the soft_wwpn attribute to be settable. Once the attribute
2312 * is written, the enable key resets. If further updates are
2313 * desired, the key must be written again to re-enable the
2314 * attribute.
2315 *
2316 * The "key" is not secret - it is a hardcoded string shown
2317 * here. The intent is to protect against the random user or
2318 * application that is just writing attributes.
2319 */
James Smartaeb3c812017-04-21 16:05:02 -07002320 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2322 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2323 " be enabled: fawwpn is enabled\n");
2324 return -EINVAL;
2325 }
James Smart352e5fd2016-12-30 06:57:47 -08002326
2327 /* count may include a LF at end of string */
2328 if (buf[cnt-1] == '\n')
2329 cnt--;
2330
2331 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2332 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2333 return -EINVAL;
2334
2335 phba->soft_wwn_enable = 1;
2336
2337 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2338 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2339 phba->brd_no);
2340 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2341 " The soft_wwpn feature is not supported by Broadcom.");
2342
2343 return count;
2344}
2345static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2346 lpfc_soft_wwn_enable_store);
2347
2348/**
2349 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2350 * @dev: class device that is converted into a Scsi_host.
2351 * @attr: device attribute, not used.
2352 * @buf: on return contains the wwpn in hexadecimal.
2353 *
2354 * Returns: size of formatted string.
2355 **/
2356static ssize_t
2357lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2358 char *buf)
2359{
2360 struct Scsi_Host *shost = class_to_shost(dev);
2361 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2362 struct lpfc_hba *phba = vport->phba;
2363
2364 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2365 (unsigned long long)phba->cfg_soft_wwpn);
2366}
2367
2368/**
2369 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2370 * @dev class device that is converted into a Scsi_host.
2371 * @attr: device attribute, not used.
2372 * @buf: contains the wwpn in hexadecimal.
2373 * @count: number of wwpn bytes in buf
2374 *
2375 * Returns:
2376 * -EACCES hba reset not enabled, adapter over temp
2377 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2378 * -EIO error taking adapter offline or online
2379 * value of count on success
2380 **/
2381static ssize_t
2382lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2383 const char *buf, size_t count)
2384{
2385 struct Scsi_Host *shost = class_to_shost(dev);
2386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2387 struct lpfc_hba *phba = vport->phba;
2388 struct completion online_compl;
2389 int stat1 = 0, stat2 = 0;
2390 unsigned int cnt = count;
2391 u8 wwpn[WWN_SZ];
2392 int rc;
2393
2394 if (!phba->cfg_enable_hba_reset)
2395 return -EACCES;
2396 spin_lock_irq(&phba->hbalock);
2397 if (phba->over_temp_state == HBA_OVER_TEMP) {
2398 spin_unlock_irq(&phba->hbalock);
2399 return -EACCES;
2400 }
2401 spin_unlock_irq(&phba->hbalock);
2402 /* count may include a LF at end of string */
2403 if (buf[cnt-1] == '\n')
2404 cnt--;
2405
2406 if (!phba->soft_wwn_enable)
2407 return -EINVAL;
2408
2409 /* lock setting wwpn, wwnn down */
2410 phba->soft_wwn_enable = 0;
2411
2412 rc = lpfc_wwn_set(buf, cnt, wwpn);
James Smarte2934ed2017-01-17 12:31:56 -08002413 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002414 /* not able to set wwpn, unlock it */
2415 phba->soft_wwn_enable = 1;
2416 return rc;
2417 }
2418
2419 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2420 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2421 if (phba->cfg_soft_wwnn)
2422 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2423
2424 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2425 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2426
2427 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2428 if (stat1)
2429 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2430 "0463 lpfc_soft_wwpn attribute set failed to "
2431 "reinit adapter - %d\n", stat1);
2432 init_completion(&online_compl);
2433 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2434 LPFC_EVT_ONLINE);
2435 if (rc == 0)
2436 return -ENOMEM;
2437
2438 wait_for_completion(&online_compl);
2439 if (stat2)
2440 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2441 "0464 lpfc_soft_wwpn attribute set failed to "
2442 "reinit adapter - %d\n", stat2);
2443 return (stat1 || stat2) ? -EIO : count;
2444}
2445static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
2446 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2447
2448/**
2449 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2450 * @dev: class device that is converted into a Scsi_host.
2451 * @attr: device attribute, not used.
2452 * @buf: on return contains the wwnn in hexadecimal.
2453 *
2454 * Returns: size of formatted string.
2455 **/
2456static ssize_t
2457lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2458 char *buf)
2459{
2460 struct Scsi_Host *shost = class_to_shost(dev);
2461 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2462 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2463 (unsigned long long)phba->cfg_soft_wwnn);
2464}
2465
2466/**
2467 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2468 * @cdev: class device that is converted into a Scsi_host.
2469 * @buf: contains the ww node name in hexadecimal.
2470 * @count: number of wwnn bytes in buf.
2471 *
2472 * Returns:
2473 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2474 * value of count on success
2475 **/
2476static ssize_t
2477lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2478 const char *buf, size_t count)
2479{
2480 struct Scsi_Host *shost = class_to_shost(dev);
2481 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2482 unsigned int cnt = count;
2483 u8 wwnn[WWN_SZ];
2484 int rc;
2485
2486 /* count may include a LF at end of string */
2487 if (buf[cnt-1] == '\n')
2488 cnt--;
2489
2490 if (!phba->soft_wwn_enable)
2491 return -EINVAL;
2492
2493 rc = lpfc_wwn_set(buf, cnt, wwnn);
James Smarte2934ed2017-01-17 12:31:56 -08002494 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002495 /* Allow wwnn to be set many times, as long as the enable
2496 * is set. However, once the wwpn is set, everything locks.
2497 */
2498 return rc;
2499 }
2500
2501 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2502
2503 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2504 "lpfc%d: soft_wwnn set. Value will take effect upon "
2505 "setting of the soft_wwpn\n", phba->brd_no);
2506
2507 return count;
2508}
2509static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
2510 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002511
James Smart1ba981f2014-02-20 09:56:45 -05002512/**
2513 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2514 * Optimized Access Storage (OAS) operations.
2515 * @dev: class device that is converted into a Scsi_host.
2516 * @attr: device attribute, not used.
2517 * @buf: buffer for passing information.
2518 *
2519 * Returns:
2520 * value of count
2521 **/
2522static ssize_t
2523lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2524 char *buf)
2525{
2526 struct Scsi_Host *shost = class_to_shost(dev);
2527 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2528
2529 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2530 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2531}
2532
2533/**
2534 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2535 * Optimized Access Storage (OAS) operations.
2536 * @dev: class device that is converted into a Scsi_host.
2537 * @attr: device attribute, not used.
2538 * @buf: buffer for passing information.
2539 * @count: Size of the data buffer.
2540 *
2541 * Returns:
2542 * -EINVAL count is invalid, invalid wwpn byte invalid
2543 * -EPERM oas is not supported by hba
2544 * value of count on success
2545 **/
2546static ssize_t
2547lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2548 const char *buf, size_t count)
2549{
2550 struct Scsi_Host *shost = class_to_shost(dev);
2551 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2552 unsigned int cnt = count;
2553 uint8_t wwpn[WWN_SZ];
2554 int rc;
2555
James Smartf38fa0b2014-04-04 13:52:21 -04002556 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002557 return -EPERM;
2558
2559 /* count may include a LF at end of string */
2560 if (buf[cnt-1] == '\n')
2561 cnt--;
2562
2563 rc = lpfc_wwn_set(buf, cnt, wwpn);
2564 if (rc)
2565 return rc;
2566
2567 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2568 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2569 if (wwn_to_u64(wwpn) == 0)
2570 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2571 else
2572 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2573 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2574 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2575 return count;
2576}
2577static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2578 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2579
2580/**
James Smartc92c8412016-07-06 12:36:05 -07002581 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2582 * Optimized Access Storage (OAS) operations.
2583 * @dev: class device that is converted into a Scsi_host.
2584 * @attr: device attribute, not used.
2585 * @buf: buffer for passing information.
2586 *
2587 * Returns:
2588 * value of count
2589 **/
2590static ssize_t
2591lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2592 char *buf)
2593{
2594 struct Scsi_Host *shost = class_to_shost(dev);
2595 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2596
2597 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2598}
2599
2600/**
2601 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2602 * Optimized Access Storage (OAS) operations.
2603 * @dev: class device that is converted into a Scsi_host.
2604 * @attr: device attribute, not used.
2605 * @buf: buffer for passing information.
2606 * @count: Size of the data buffer.
2607 *
2608 * Returns:
2609 * -EINVAL count is invalid, invalid wwpn byte invalid
2610 * -EPERM oas is not supported by hba
2611 * value of count on success
2612 **/
2613static ssize_t
2614lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2615 const char *buf, size_t count)
2616{
2617 struct Scsi_Host *shost = class_to_shost(dev);
2618 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2619 unsigned int cnt = count;
2620 unsigned long val;
2621 int ret;
2622
2623 if (!phba->cfg_fof)
2624 return -EPERM;
2625
2626 /* count may include a LF at end of string */
2627 if (buf[cnt-1] == '\n')
2628 cnt--;
2629
2630 ret = kstrtoul(buf, 0, &val);
2631 if (ret || (val > 0x7f))
2632 return -EINVAL;
2633
2634 if (val)
2635 phba->cfg_oas_priority = (uint8_t)val;
2636 else
2637 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2638 return count;
2639}
2640static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2641 lpfc_oas_priority_show, lpfc_oas_priority_store);
2642
2643/**
James Smart1ba981f2014-02-20 09:56:45 -05002644 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2645 * for Optimized Access Storage (OAS) operations.
2646 * @dev: class device that is converted into a Scsi_host.
2647 * @attr: device attribute, not used.
2648 * @buf: buffer for passing information.
2649 *
2650 * Returns:
2651 * value of count on success
2652 **/
2653static ssize_t
2654lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2655 char *buf)
2656{
2657 struct Scsi_Host *shost = class_to_shost(dev);
2658 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2659
2660 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2661 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2662}
2663
2664/**
2665 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2666 * for Optimized Access Storage (OAS) operations.
2667 * @dev: class device that is converted into a Scsi_host.
2668 * @attr: device attribute, not used.
2669 * @buf: buffer for passing information.
2670 * @count: Size of the data buffer.
2671 *
2672 * Returns:
2673 * -EINVAL count is invalid, invalid wwpn byte invalid
2674 * -EPERM oas is not supported by hba
2675 * value of count on success
2676 **/
2677static ssize_t
2678lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2679 const char *buf, size_t count)
2680{
2681 struct Scsi_Host *shost = class_to_shost(dev);
2682 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2683 unsigned int cnt = count;
2684 uint8_t wwpn[WWN_SZ];
2685 int rc;
2686
James Smartf38fa0b2014-04-04 13:52:21 -04002687 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002688 return -EPERM;
2689
2690 /* count may include a LF at end of string */
2691 if (buf[cnt-1] == '\n')
2692 cnt--;
2693
2694 rc = lpfc_wwn_set(buf, cnt, wwpn);
2695 if (rc)
2696 return rc;
2697
2698 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2699 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2700 if (wwn_to_u64(wwpn) == 0)
2701 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2702 else
2703 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2704 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
James Smartb5749fe2016-12-19 15:07:26 -08002705 if (phba->cfg_oas_priority == 0)
2706 phba->cfg_oas_priority = phba->cfg_XLanePriority;
James Smart1ba981f2014-02-20 09:56:45 -05002707 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2708 return count;
2709}
2710static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2711 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2712
2713/**
2714 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2715 * of whether luns will be enabled or disabled
2716 * for Optimized Access Storage (OAS) operations.
2717 * @dev: class device that is converted into a Scsi_host.
2718 * @attr: device attribute, not used.
2719 * @buf: buffer for passing information.
2720 *
2721 * Returns:
2722 * size of formatted string.
2723 **/
2724static ssize_t
2725lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2726 char *buf)
2727{
2728 struct Scsi_Host *shost = class_to_shost(dev);
2729 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2730
2731 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2732}
2733
2734/**
2735 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2736 * of whether luns will be enabled or disabled
2737 * for Optimized Access Storage (OAS) operations.
2738 * @dev: class device that is converted into a Scsi_host.
2739 * @attr: device attribute, not used.
2740 * @buf: buffer for passing information.
2741 * @count: Size of the data buffer.
2742 *
2743 * Returns:
2744 * -EINVAL count is invalid, invalid wwpn byte invalid
2745 * -EPERM oas is not supported by hba
2746 * value of count on success
2747 **/
2748static ssize_t
2749lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2750 const char *buf, size_t count)
2751{
2752 struct Scsi_Host *shost = class_to_shost(dev);
2753 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2754 int val = 0;
2755
James Smartf38fa0b2014-04-04 13:52:21 -04002756 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002757 return -EPERM;
2758
2759 if (!isdigit(buf[0]))
2760 return -EINVAL;
2761
2762 if (sscanf(buf, "%i", &val) != 1)
2763 return -EINVAL;
2764
2765 if ((val != 0) && (val != 1))
2766 return -EINVAL;
2767
2768 phba->cfg_oas_lun_state = val;
James Smart1ba981f2014-02-20 09:56:45 -05002769 return strlen(buf);
2770}
2771static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2772 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2773
2774/**
2775 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2776 * Storage (OAS) lun returned by the
2777 * lpfc_oas_lun_show function.
2778 * @dev: class device that is converted into a Scsi_host.
2779 * @attr: device attribute, not used.
2780 * @buf: buffer for passing information.
2781 *
2782 * Returns:
2783 * size of formatted string.
2784 **/
2785static ssize_t
2786lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2787 char *buf)
2788{
2789 struct Scsi_Host *shost = class_to_shost(dev);
2790 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2791
2792 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2793 return -EFAULT;
2794
2795 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2796}
2797static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2798 lpfc_oas_lun_status_show, NULL);
2799
2800
2801/**
2802 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2803 * (OAS) operations.
2804 * @phba: lpfc_hba pointer.
2805 * @ndlp: pointer to fcp target node.
2806 * @lun: the fc lun for setting oas state.
2807 * @oas_state: the oas state to be set to the lun.
2808 *
2809 * Returns:
2810 * SUCCESS : 0
2811 * -EPERM OAS is not enabled or not supported by this port.
2812 *
2813 */
2814static size_t
2815lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartc92c8412016-07-06 12:36:05 -07002816 uint8_t tgt_wwpn[], uint64_t lun,
2817 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002818{
2819
2820 int rc = 0;
2821
James Smartf38fa0b2014-04-04 13:52:21 -04002822 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002823 return -EPERM;
2824
2825 if (oas_state) {
2826 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002827 (struct lpfc_name *)tgt_wwpn,
2828 lun, pri))
James Smart1ba981f2014-02-20 09:56:45 -05002829 rc = -ENOMEM;
2830 } else {
2831 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002832 (struct lpfc_name *)tgt_wwpn, lun, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002833 }
2834 return rc;
2835
2836}
2837
2838/**
2839 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2840 * Access Storage (OAS) operations.
2841 * @phba: lpfc_hba pointer.
2842 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2843 * @tgt_wwpn: wwpn of the target associated with the returned lun
2844 * @lun_status: status of the lun returned lun
2845 *
2846 * Returns the first or next lun enabled for OAS operations for the vport/target
2847 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2848 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2849 *
2850 * Return:
2851 * lun that is OAS enabled for the vport/target
2852 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2853 */
2854static uint64_t
2855lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartb5749fe2016-12-19 15:07:26 -08002856 uint8_t tgt_wwpn[], uint32_t *lun_status,
2857 uint32_t *lun_pri)
James Smart1ba981f2014-02-20 09:56:45 -05002858{
2859 uint64_t found_lun;
2860
2861 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2862 return NOT_OAS_ENABLED_LUN;
2863 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2864 phba->sli4_hba.oas_next_vpt_wwpn,
2865 (struct lpfc_name *)
2866 phba->sli4_hba.oas_next_tgt_wwpn,
2867 &phba->sli4_hba.oas_next_lun,
2868 (struct lpfc_name *)vpt_wwpn,
2869 (struct lpfc_name *)tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002870 &found_lun, lun_status, lun_pri))
James Smart1ba981f2014-02-20 09:56:45 -05002871 return found_lun;
2872 else
2873 return NOT_OAS_ENABLED_LUN;
2874}
2875
2876/**
2877 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2878 * @phba: lpfc_hba pointer.
2879 * @vpt_wwpn: vport wwpn by reference.
2880 * @tgt_wwpn: target wwpn by reference.
2881 * @lun: the fc lun for setting oas state.
2882 * @oas_state: the oas state to be set to the oas_lun.
2883 *
2884 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2885 * a lun for OAS operations.
2886 *
2887 * Return:
2888 * SUCCESS: 0
2889 * -ENOMEM: failed to enable an lun for OAS operations
2890 * -EPERM: OAS is not enabled
2891 */
2892static ssize_t
2893lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2894 uint8_t tgt_wwpn[], uint64_t lun,
James Smartc92c8412016-07-06 12:36:05 -07002895 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002896{
2897
2898 int rc;
2899
2900 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
James Smartc92c8412016-07-06 12:36:05 -07002901 oas_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002902 return rc;
2903}
2904
2905/**
2906 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2907 * @dev: class device that is converted into a Scsi_host.
2908 * @attr: device attribute, not used.
2909 * @buf: buffer for passing information.
2910 *
2911 * This routine returns a lun enabled for OAS each time the function
2912 * is called.
2913 *
2914 * Returns:
2915 * SUCCESS: size of formatted string.
2916 * -EFAULT: target or vport wwpn was not set properly.
2917 * -EPERM: oas is not enabled.
2918 **/
2919static ssize_t
2920lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2921 char *buf)
2922{
2923 struct Scsi_Host *shost = class_to_shost(dev);
2924 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2925
2926 uint64_t oas_lun;
2927 int len = 0;
2928
James Smartf38fa0b2014-04-04 13:52:21 -04002929 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002930 return -EPERM;
2931
2932 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2933 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2934 return -EFAULT;
2935
2936 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2937 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2938 return -EFAULT;
2939
2940 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2941 phba->cfg_oas_tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002942 &phba->cfg_oas_lun_status,
2943 &phba->cfg_oas_priority);
James Smart1ba981f2014-02-20 09:56:45 -05002944 if (oas_lun != NOT_OAS_ENABLED_LUN)
2945 phba->cfg_oas_flags |= OAS_LUN_VALID;
2946
2947 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2948
2949 return len;
2950}
2951
2952/**
2953 * lpfc_oas_lun_store - Sets the OAS state for lun
2954 * @dev: class device that is converted into a Scsi_host.
2955 * @attr: device attribute, not used.
2956 * @buf: buffer for passing information.
2957 *
2958 * This function sets the OAS state for lun. Before this function is called,
2959 * the vport wwpn, target wwpn, and oas state need to be set.
2960 *
2961 * Returns:
2962 * SUCCESS: size of formatted string.
2963 * -EFAULT: target or vport wwpn was not set properly.
2964 * -EPERM: oas is not enabled.
2965 * size of formatted string.
2966 **/
2967static ssize_t
2968lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2969 const char *buf, size_t count)
2970{
2971 struct Scsi_Host *shost = class_to_shost(dev);
2972 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2973 uint64_t scsi_lun;
James Smartb5749fe2016-12-19 15:07:26 -08002974 uint32_t pri;
James Smart1ba981f2014-02-20 09:56:45 -05002975 ssize_t rc;
2976
James Smartf38fa0b2014-04-04 13:52:21 -04002977 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002978 return -EPERM;
2979
2980 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2981 return -EFAULT;
2982
2983 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2984 return -EFAULT;
2985
2986 if (!isdigit(buf[0]))
2987 return -EINVAL;
2988
2989 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
2990 return -EINVAL;
2991
James Smartb5749fe2016-12-19 15:07:26 -08002992 pri = phba->cfg_oas_priority;
2993 if (pri == 0)
2994 pri = phba->cfg_XLanePriority;
2995
James Smart1ba981f2014-02-20 09:56:45 -05002996 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartc92c8412016-07-06 12:36:05 -07002997 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
2998 "priority 0x%x with oas state %d\n",
James Smart1ba981f2014-02-20 09:56:45 -05002999 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3000 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08003001 pri, phba->cfg_oas_lun_state);
James Smart1ba981f2014-02-20 09:56:45 -05003002
3003 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07003004 phba->cfg_oas_tgt_wwpn, scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08003005 phba->cfg_oas_lun_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05003006 if (rc)
3007 return rc;
3008
3009 return count;
3010}
3011static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3012 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04003013
James Smartf358dd02017-02-12 13:52:34 -08003014int lpfc_enable_nvmet_cnt;
3015unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3016 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3017 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3018module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3019MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3020
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003021static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05003022module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003023MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3024 " 0 - none,"
3025 " 1 - poll with interrupts enabled"
3026 " 3 - poll and disable FCP ring interrupts");
3027
Tony Jonesee959b02008-02-22 00:13:36 +01003028static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
3029 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05003030
James Smart96418b52017-03-04 09:30:31 -08003031int lpfc_no_hba_reset_cnt;
3032unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3033 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3034module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3035MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3036
James Smart12247e82016-07-06 12:36:09 -07003037LPFC_ATTR(sli_mode, 0, 0, 3,
3038 "SLI mode selector:"
3039 " 0 - auto (SLI-3 if supported),"
3040 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3041 " 3 - select SLI-3");
James Smart92d7f7b2007-06-17 19:56:38 -05003042
James Smart458c0832016-07-06 12:36:07 -07003043LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3044 "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05003045
James Smart7d791df2011-07-22 18:37:52 -04003046LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3047 "FCF Fast failover=1 Priority failover=2");
3048
James Smarte5771b42013-03-01 16:37:14 -05003049/*
3050# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3051# 0x0 = disabled, XRI/OXID use not tracked.
3052# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3053# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3054*/
James Smart31202b02016-10-13 15:06:08 -07003055LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3056 "Enable RRQ functionality");
James Smart19ca7602010-11-20 23:11:55 -05003057
dea31012005-04-17 16:05:31 -05003058/*
James Smart84d1b002010-02-12 14:42:33 -05003059# lpfc_suppress_link_up: Bring link up at initialization
3060# 0x0 = bring link up (issue MBX_INIT_LINK)
3061# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3062# 0x2 = never bring up link
3063# Default value is 0.
3064*/
James Smarte40a02c2010-02-26 14:13:54 -05003065LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3066 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3067 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04003068/*
3069# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3070# 1 - (1024)
3071# 2 - (2048)
3072# 3 - (3072)
3073# 4 - (4096)
3074# 5 - (5120)
3075*/
3076static ssize_t
3077lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3078{
3079 struct Scsi_Host *shost = class_to_shost(dev);
3080 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3081
3082 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3083}
3084
3085static DEVICE_ATTR(iocb_hw, S_IRUGO,
3086 lpfc_iocb_hw_show, NULL);
3087static ssize_t
3088lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3089{
3090 struct Scsi_Host *shost = class_to_shost(dev);
3091 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003092 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003093
James Smart895427b2017-02-12 13:52:30 -08003094 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txq_max);
James Smart2a9bf3d2010-06-07 15:24:45 -04003095}
3096
3097static DEVICE_ATTR(txq_hw, S_IRUGO,
3098 lpfc_txq_hw_show, NULL);
3099static ssize_t
3100lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3101 char *buf)
3102{
3103 struct Scsi_Host *shost = class_to_shost(dev);
3104 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003105 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003106
James Smart895427b2017-02-12 13:52:30 -08003107 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txcmplq_max);
James Smart2a9bf3d2010-06-07 15:24:45 -04003108}
3109
3110static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3111 lpfc_txcmplq_hw_show, NULL);
3112
James Smart0d8c8ba2016-10-13 15:06:07 -07003113LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
James Smart2a9bf3d2010-06-07 15:24:45 -04003114 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
James Smart84d1b002010-02-12 14:42:33 -05003115
3116/*
James Smartc01f3202006-08-18 17:47:08 -04003117# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3118# until the timer expires. Value range is [0,255]. Default value is 30.
3119*/
3120static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3121static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3122module_param(lpfc_nodev_tmo, int, 0);
3123MODULE_PARM_DESC(lpfc_nodev_tmo,
3124 "Seconds driver will hold I/O waiting "
3125 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04003126
3127/**
James Smart3621a712009-04-06 18:47:14 -04003128 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04003129 * @dev: class converted to a Scsi_host structure.
3130 * @attr: device attribute, not used.
3131 * @buf: on return contains the dev loss timeout in decimal.
3132 *
3133 * Returns: size of formatted string.
3134 **/
James Smartc01f3202006-08-18 17:47:08 -04003135static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003136lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3137 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04003138{
Tony Jonesee959b02008-02-22 00:13:36 +01003139 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003140 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05003141
James Smart3de2a652007-08-02 11:09:59 -04003142 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003143}
3144
James Smarte59058c2008-08-24 21:49:00 -04003145/**
James Smart3621a712009-04-06 18:47:14 -04003146 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04003147 * @vport: lpfc vport structure pointer.
3148 * @val: contains the nodev timeout value.
3149 *
3150 * Description:
3151 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3152 * a kernel error message is printed and zero is returned.
3153 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3154 * Otherwise nodev tmo is set to the default value.
3155 *
3156 * Returns:
3157 * zero if already set or if val is in range
3158 * -EINVAL val out of range
3159 **/
James Smartc01f3202006-08-18 17:47:08 -04003160static int
James Smart3de2a652007-08-02 11:09:59 -04003161lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003162{
James Smart3de2a652007-08-02 11:09:59 -04003163 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3164 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3165 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04003166 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003167 "0407 Ignoring lpfc_nodev_tmo module "
3168 "parameter because lpfc_devloss_tmo "
3169 "is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003170 return 0;
3171 }
3172
3173 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003174 vport->cfg_nodev_tmo = val;
3175 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04003176 return 0;
3177 }
James Smarte8b62012007-08-02 11:10:09 -04003178 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3179 "0400 lpfc_nodev_tmo attribute cannot be set to"
3180 " %d, allowed range is [%d, %d]\n",
3181 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04003182 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04003183 return -EINVAL;
3184}
3185
James Smarte59058c2008-08-24 21:49:00 -04003186/**
James Smart3621a712009-04-06 18:47:14 -04003187 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04003188 * @vport: lpfc vport structure pointer.
3189 *
3190 * Description:
3191 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3192 **/
James Smart7054a602007-04-25 09:52:34 -04003193static void
James Smart3de2a652007-08-02 11:09:59 -04003194lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04003195{
James Smart858c9f62007-06-17 19:56:39 -05003196 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04003197 struct lpfc_nodelist *ndlp;
3198
James Smart51ef4c22007-08-02 11:10:31 -04003199 shost = lpfc_shost_from_vport(vport);
3200 spin_lock_irq(shost->host_lock);
3201 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05003202 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04003203 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3204 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04003205}
3206
James Smarte59058c2008-08-24 21:49:00 -04003207/**
James Smart3621a712009-04-06 18:47:14 -04003208 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04003209 * @vport: lpfc vport structure pointer.
3210 * @val: contains the tmo value.
3211 *
3212 * Description:
3213 * If the devloss tmo is already set or the vport dev loss tmo has changed
3214 * then a kernel error message is printed and zero is returned.
3215 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3216 * Otherwise nodev tmo is set to the default value.
3217 *
3218 * Returns:
3219 * zero if already set or if val is in range
3220 * -EINVAL val out of range
3221 **/
James Smartc01f3202006-08-18 17:47:08 -04003222static int
James Smart3de2a652007-08-02 11:09:59 -04003223lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003224{
James Smart3de2a652007-08-02 11:09:59 -04003225 if (vport->dev_loss_tmo_changed ||
3226 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04003227 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003228 "0401 Ignoring change to lpfc_nodev_tmo "
3229 "because lpfc_devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003230 return 0;
3231 }
James Smartc01f3202006-08-18 17:47:08 -04003232 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003233 vport->cfg_nodev_tmo = val;
3234 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05003235 /*
3236 * For compat: set the fc_host dev loss so new rports
3237 * will get the value.
3238 */
3239 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003240 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003241 return 0;
3242 }
James Smarte8b62012007-08-02 11:10:09 -04003243 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003244 "0403 lpfc_nodev_tmo attribute cannot be set to "
James Smarte8b62012007-08-02 11:10:09 -04003245 "%d, allowed range is [%d, %d]\n",
3246 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003247 return -EINVAL;
3248}
3249
James Smart3de2a652007-08-02 11:09:59 -04003250lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04003251
Tony Jonesee959b02008-02-22 00:13:36 +01003252static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3253 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003254
3255/*
3256# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3257# disappear until the timer expires. Value range is [0,255]. Default
3258# value is 30.
3259*/
James Smartab56dc22011-02-16 12:39:57 -05003260module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04003261MODULE_PARM_DESC(lpfc_devloss_tmo,
3262 "Seconds driver will hold I/O waiting "
3263 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04003264lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3265 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3266lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04003267
3268/**
James Smart3621a712009-04-06 18:47:14 -04003269 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04003270 * @vport: lpfc vport structure pointer.
3271 * @val: contains the tmo value.
3272 *
3273 * Description:
3274 * If val is in a valid range then set the vport nodev tmo,
3275 * devloss tmo, also set the vport dev loss tmo changed flag.
3276 * Else a kernel error message is printed.
3277 *
3278 * Returns:
3279 * zero if val is in range
3280 * -EINVAL val out of range
3281 **/
James Smartc01f3202006-08-18 17:47:08 -04003282static int
James Smart3de2a652007-08-02 11:09:59 -04003283lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003284{
3285 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003286 vport->cfg_nodev_tmo = val;
3287 vport->cfg_devloss_tmo = val;
3288 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05003289 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003290 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003291 return 0;
3292 }
3293
James Smarte8b62012007-08-02 11:10:09 -04003294 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003295 "0404 lpfc_devloss_tmo attribute cannot be set to "
3296 "%d, allowed range is [%d, %d]\n",
James Smarte8b62012007-08-02 11:10:09 -04003297 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003298 return -EINVAL;
3299}
3300
James Smart3de2a652007-08-02 11:09:59 -04003301lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01003302static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3303 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003304
3305/*
James Smartf358dd02017-02-12 13:52:34 -08003306 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3307 * lpfc_suppress_rsp = 0 Disable
3308 * lpfc_suppress_rsp = 1 Enable (default)
3309 *
3310 */
3311LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3312 "Enable suppress rsp feature is firmware supports it");
3313
3314/*
James Smart2d7dbc42017-02-12 13:52:35 -08003315 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3316 * lpfc_nvmet_mrq = 1 use a single RQ pair
3317 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3318 *
3319 */
3320LPFC_ATTR_R(nvmet_mrq,
3321 1, 1, 16,
3322 "Specify number of RQ pairs for processing NVMET cmds");
3323
3324/*
James Smart895427b2017-02-12 13:52:30 -08003325 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3326 * Supported Values: 1 - register just FCP
3327 * 3 - register both FCP and NVME
James Smart7d708032017-03-08 14:36:01 -08003328 * Supported values are [1,3]. Default value is 1
James Smart895427b2017-02-12 13:52:30 -08003329 */
James Smart7d708032017-03-08 14:36:01 -08003330LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP,
James Smart895427b2017-02-12 13:52:30 -08003331 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3332 "Define fc4 type to register with fabric.");
3333
3334/*
3335 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3336 * This parameter is only used if:
James Smartf358dd02017-02-12 13:52:34 -08003337 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3338 * port is not configured for NVMET.
James Smart895427b2017-02-12 13:52:30 -08003339 *
3340 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3341 * The remaining XRIs get split up based on lpfc_xri_split per port:
3342 *
3343 * Supported Values are in percentages
3344 * the xri_split value is the percentage the SCSI port will get. The remaining
3345 * percentage will go to NVME.
3346 */
3347LPFC_ATTR_R(xri_split, 50, 10, 90,
James Smart4410a672017-04-21 16:04:57 -07003348 "Division of XRI resources between SCSI and NVME");
James Smart895427b2017-02-12 13:52:30 -08003349
3350/*
dea31012005-04-17 16:05:31 -05003351# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3352# deluged with LOTS of information.
3353# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04003354# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05003355*/
James Smartf4b4c682009-05-22 14:53:12 -04003356LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04003357 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05003358
3359/*
James Smart7ee5d432007-10-27 13:37:17 -04003360# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3361# objects that have been registered with the nameserver after login.
3362*/
James Smartcf971242012-03-01 22:37:32 -05003363LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04003364 "Deregister nameserver objects before LOGO");
3365
3366/*
dea31012005-04-17 16:05:31 -05003367# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04003368# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3369# If this parameter value is greater than 1/8th the maximum number of exchanges
3370# supported by the HBA port, then the lun queue depth will be reduced to
3371# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05003372*/
James Smart572709e2013-07-15 18:32:43 -04003373LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04003374 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05003375
3376/*
James Smart7dc517d2010-07-14 15:32:10 -04003377# tgt_queue_depth: This parameter is used to limit the number of outstanding
3378# commands per target port. Value range is [10,65535]. Default value is 65535.
3379*/
3380LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
James Smart572709e2013-07-15 18:32:43 -04003381 "Max number of FCP commands we can queue to a specific target port");
James Smart7dc517d2010-07-14 15:32:10 -04003382
3383/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003384# hba_queue_depth: This parameter is used to limit the number of outstanding
3385# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3386# value is greater than the maximum number of exchanges supported by the HBA,
3387# then maximum number of exchanges supported by the HBA is used to determine
3388# the hba_queue_depth.
3389*/
3390LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3391 "Max number of FCP commands we can queue to a lpfc HBA");
3392
3393/*
James Smart92d7f7b2007-06-17 19:56:38 -05003394# peer_port_login: This parameter allows/prevents logins
3395# between peer ports hosted on the same physical port.
3396# When this parameter is set 0 peer ports of same physical port
3397# are not allowed to login to each other.
3398# When this parameter is set 1 peer ports of same physical port
3399# are allowed to login to each other.
3400# Default value of this parameter is 0.
3401*/
James Smart3de2a652007-08-02 11:09:59 -04003402LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3403 "Allow peer ports on the same physical port to login to each "
3404 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05003405
3406/*
James Smart3de2a652007-08-02 11:09:59 -04003407# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05003408# between Virtual Ports and remote initiators.
3409# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3410# other initiators and will attempt to PLOGI all remote ports.
3411# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3412# remote ports and will not attempt to PLOGI to other initiators.
3413# This parameter does not restrict to the physical port.
3414# This parameter does not restrict logins to Fabric resident remote ports.
3415# Default value of this parameter is 1.
3416*/
James Smart3de2a652007-08-02 11:09:59 -04003417static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05003418module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04003419MODULE_PARM_DESC(lpfc_restrict_login,
3420 "Restrict virtual ports login to remote initiators.");
3421lpfc_vport_param_show(restrict_login);
3422
James Smarte59058c2008-08-24 21:49:00 -04003423/**
James Smart3621a712009-04-06 18:47:14 -04003424 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003425 * @vport: lpfc vport structure pointer.
3426 * @val: contains the restrict login value.
3427 *
3428 * Description:
3429 * If val is not in a valid range then log a kernel error message and set
3430 * the vport restrict login to one.
3431 * If the port type is physical clear the restrict login flag and return.
3432 * Else set the restrict login flag to val.
3433 *
3434 * Returns:
3435 * zero if val is in range
3436 * -EINVAL val out of range
3437 **/
James Smart3de2a652007-08-02 11:09:59 -04003438static int
3439lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3440{
3441 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003442 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003443 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003444 "be set to %d, allowed range is [0, 1]\n",
3445 val);
James Smart3de2a652007-08-02 11:09:59 -04003446 vport->cfg_restrict_login = 1;
3447 return -EINVAL;
3448 }
3449 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3450 vport->cfg_restrict_login = 0;
3451 return 0;
3452 }
3453 vport->cfg_restrict_login = val;
3454 return 0;
3455}
3456
James Smarte59058c2008-08-24 21:49:00 -04003457/**
James Smart3621a712009-04-06 18:47:14 -04003458 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003459 * @vport: lpfc vport structure pointer.
3460 * @val: contains the restrict login value.
3461 *
3462 * Description:
3463 * If val is not in a valid range then log a kernel error message and set
3464 * the vport restrict login to one.
3465 * If the port type is physical and the val is not zero log a kernel
3466 * error message, clear the restrict login flag and return zero.
3467 * Else set the restrict login flag to val.
3468 *
3469 * Returns:
3470 * zero if val is in range
3471 * -EINVAL val out of range
3472 **/
James Smart3de2a652007-08-02 11:09:59 -04003473static int
3474lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3475{
3476 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003477 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003478 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003479 "be set to %d, allowed range is [0, 1]\n",
3480 val);
James Smart3de2a652007-08-02 11:09:59 -04003481 vport->cfg_restrict_login = 1;
3482 return -EINVAL;
3483 }
3484 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04003485 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3486 "0468 lpfc_restrict_login must be 0 for "
3487 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04003488 vport->cfg_restrict_login = 0;
3489 return 0;
3490 }
3491 vport->cfg_restrict_login = val;
3492 return 0;
3493}
3494lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01003495static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3496 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05003497
3498/*
dea31012005-04-17 16:05:31 -05003499# Some disk devices have a "select ID" or "select Target" capability.
3500# From a protocol standpoint "select ID" usually means select the
3501# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3502# annex" which contains a table that maps a "select ID" (a number
3503# between 0 and 7F) to an ALPA. By default, for compatibility with
3504# older drivers, the lpfc driver scans this table from low ALPA to high
3505# ALPA.
3506#
3507# Turning on the scan-down variable (on = 1, off = 0) will
3508# cause the lpfc driver to use an inverted table, effectively
3509# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3510#
3511# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3512# and will not work across a fabric. Also this parameter will take
3513# effect only in the case when ALPA map is not available.)
3514*/
James Smart3de2a652007-08-02 11:09:59 -04003515LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3516 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05003517
3518/*
dea31012005-04-17 16:05:31 -05003519# lpfc_topology: link topology for init link
3520# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05003521# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05003522# 0x02 = attempt point-to-point mode only
3523# 0x04 = attempt loop mode only
3524# 0x06 = attempt point-to-point mode then loop
3525# Set point-to-point mode if you want to run as an N_Port.
3526# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3527# Default value is 0.
3528*/
James Smart0a035432016-10-13 15:06:10 -07003529LPFC_ATTR(topology, 0, 0, 6,
3530 "Select Fibre Channel topology");
James Smarte59058c2008-08-24 21:49:00 -04003531
3532/**
James Smart3621a712009-04-06 18:47:14 -04003533 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04003534 * @phba: lpfc_hba pointer.
3535 * @val: topology value.
3536 *
3537 * Description:
3538 * If val is in a valid range then set the adapter's topology field and
3539 * issue a lip; if the lip fails reset the topology to the old value.
3540 *
3541 * If the value is not in range log a kernel error message and return an error.
3542 *
3543 * Returns:
3544 * zero if val is in range and lip okay
3545 * non-zero return value from lpfc_issue_lip()
3546 * -EINVAL val out of range
3547 **/
James Smarta257bf92009-04-06 18:48:10 -04003548static ssize_t
3549lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3550 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003551{
James Smarta257bf92009-04-06 18:48:10 -04003552 struct Scsi_Host *shost = class_to_shost(dev);
3553 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3554 struct lpfc_hba *phba = vport->phba;
3555 int val = 0;
3556 int nolip = 0;
3557 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003558 int err;
3559 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003560
3561 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3562 nolip = 1;
3563 val_buf = &buf[strlen("nolip ")];
3564 }
3565
3566 if (!isdigit(val_buf[0]))
3567 return -EINVAL;
3568 if (sscanf(val_buf, "%i", &val) != 1)
3569 return -EINVAL;
3570
James Smart83108bd2008-01-11 01:53:09 -05003571 if (val >= 0 && val <= 6) {
3572 prev_val = phba->cfg_topology;
James Smartff78d8f2011-12-13 13:21:35 -05003573 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3574 val == 4) {
3575 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3576 "3113 Loop mode not supported at speed %d\n",
James Smartd38dd522015-08-31 16:48:17 -04003577 val);
James Smartff78d8f2011-12-13 13:21:35 -05003578 return -EINVAL;
3579 }
James Smartd38dd522015-08-31 16:48:17 -04003580 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3581 val == 4) {
3582 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3583 "3114 Loop mode not supported\n");
3584 return -EINVAL;
3585 }
3586 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04003587 if (nolip)
3588 return strlen(buf);
3589
James Smart88a2cfb2011-07-22 18:36:33 -04003590 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3591 "3054 lpfc_topology changed from %d to %d\n",
3592 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04003593 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3594 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05003595 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003596 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003597 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003598 return -EINVAL;
3599 } else
3600 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003601 }
3602 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3603 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3604 "allowed range is [0, 6]\n",
3605 phba->brd_no, val);
3606 return -EINVAL;
3607}
James Smart0a035432016-10-13 15:06:10 -07003608
James Smart83108bd2008-01-11 01:53:09 -05003609lpfc_param_show(topology)
Tony Jonesee959b02008-02-22 00:13:36 +01003610static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05003611 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05003612
James Smart21e9a0a2009-05-22 14:53:21 -04003613/**
3614 * lpfc_static_vport_show: Read callback function for
3615 * lpfc_static_vport sysfs file.
3616 * @dev: Pointer to class device object.
3617 * @attr: device attribute structure.
3618 * @buf: Data buffer.
3619 *
3620 * This function is the read call back function for
3621 * lpfc_static_vport sysfs file. The lpfc_static_vport
3622 * sysfs file report the mageability of the vport.
3623 **/
3624static ssize_t
3625lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3626 char *buf)
3627{
3628 struct Scsi_Host *shost = class_to_shost(dev);
3629 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3630 if (vport->vport_flag & STATIC_VPORT)
3631 sprintf(buf, "1\n");
3632 else
3633 sprintf(buf, "0\n");
3634
3635 return strlen(buf);
3636}
3637
3638/*
3639 * Sysfs attribute to control the statistical data collection.
3640 */
3641static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3642 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04003643
3644/**
James Smart3621a712009-04-06 18:47:14 -04003645 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003646 * @dev: Pointer to class device.
3647 * @buf: Data buffer.
3648 * @count: Size of the data buffer.
3649 *
Masahiro Yamada9332ef92017-02-27 14:28:47 -08003650 * This function get called when a user write to the lpfc_stat_data_ctrl
James Smartea2151b2008-09-07 11:52:10 -04003651 * sysfs file. This function parse the command written to the sysfs file
3652 * and take appropriate action. These commands are used for controlling
3653 * driver statistical data collection.
3654 * Following are the command this function handles.
3655 *
3656 * setbucket <bucket_type> <base> <step>
3657 * = Set the latency buckets.
3658 * destroybucket = destroy all the buckets.
3659 * start = start data collection
3660 * stop = stop data collection
3661 * reset = reset the collected data
3662 **/
3663static ssize_t
3664lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3665 const char *buf, size_t count)
3666{
3667 struct Scsi_Host *shost = class_to_shost(dev);
3668 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3669 struct lpfc_hba *phba = vport->phba;
3670#define LPFC_MAX_DATA_CTRL_LEN 1024
3671 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3672 unsigned long i;
3673 char *str_ptr, *token;
3674 struct lpfc_vport **vports;
3675 struct Scsi_Host *v_shost;
3676 char *bucket_type_str, *base_str, *step_str;
3677 unsigned long base, step, bucket_type;
3678
3679 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04003680 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04003681 return -EINVAL;
3682
James Smarteb016562014-09-03 12:58:06 -04003683 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
James Smartea2151b2008-09-07 11:52:10 -04003684 str_ptr = &bucket_data[0];
3685 /* Ignore this token - this is command token */
3686 token = strsep(&str_ptr, "\t ");
3687 if (!token)
3688 return -EINVAL;
3689
3690 bucket_type_str = strsep(&str_ptr, "\t ");
3691 if (!bucket_type_str)
3692 return -EINVAL;
3693
3694 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3695 bucket_type = LPFC_LINEAR_BUCKET;
3696 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3697 bucket_type = LPFC_POWER2_BUCKET;
3698 else
3699 return -EINVAL;
3700
3701 base_str = strsep(&str_ptr, "\t ");
3702 if (!base_str)
3703 return -EINVAL;
3704 base = simple_strtoul(base_str, NULL, 0);
3705
3706 step_str = strsep(&str_ptr, "\t ");
3707 if (!step_str)
3708 return -EINVAL;
3709 step = simple_strtoul(step_str, NULL, 0);
3710 if (!step)
3711 return -EINVAL;
3712
3713 /* Block the data collection for every vport */
3714 vports = lpfc_create_vport_work_array(phba);
3715 if (vports == NULL)
3716 return -ENOMEM;
3717
James Smartf4b4c682009-05-22 14:53:12 -04003718 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003719 v_shost = lpfc_shost_from_vport(vports[i]);
3720 spin_lock_irq(v_shost->host_lock);
3721 /* Block and reset data collection */
3722 vports[i]->stat_data_blocked = 1;
3723 if (vports[i]->stat_data_enabled)
3724 lpfc_vport_reset_stat_data(vports[i]);
3725 spin_unlock_irq(v_shost->host_lock);
3726 }
3727
3728 /* Set the bucket attributes */
3729 phba->bucket_type = bucket_type;
3730 phba->bucket_base = base;
3731 phba->bucket_step = step;
3732
James Smartf4b4c682009-05-22 14:53:12 -04003733 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003734 v_shost = lpfc_shost_from_vport(vports[i]);
3735
3736 /* Unblock data collection */
3737 spin_lock_irq(v_shost->host_lock);
3738 vports[i]->stat_data_blocked = 0;
3739 spin_unlock_irq(v_shost->host_lock);
3740 }
3741 lpfc_destroy_vport_work_array(phba, vports);
3742 return strlen(buf);
3743 }
3744
3745 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3746 vports = lpfc_create_vport_work_array(phba);
3747 if (vports == NULL)
3748 return -ENOMEM;
3749
James Smartf4b4c682009-05-22 14:53:12 -04003750 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003751 v_shost = lpfc_shost_from_vport(vports[i]);
3752 spin_lock_irq(shost->host_lock);
3753 vports[i]->stat_data_blocked = 1;
3754 lpfc_free_bucket(vport);
3755 vport->stat_data_enabled = 0;
3756 vports[i]->stat_data_blocked = 0;
3757 spin_unlock_irq(shost->host_lock);
3758 }
3759 lpfc_destroy_vport_work_array(phba, vports);
3760 phba->bucket_type = LPFC_NO_BUCKET;
3761 phba->bucket_base = 0;
3762 phba->bucket_step = 0;
3763 return strlen(buf);
3764 }
3765
3766 if (!strncmp(buf, "start", strlen("start"))) {
3767 /* If no buckets configured return error */
3768 if (phba->bucket_type == LPFC_NO_BUCKET)
3769 return -EINVAL;
3770 spin_lock_irq(shost->host_lock);
3771 if (vport->stat_data_enabled) {
3772 spin_unlock_irq(shost->host_lock);
3773 return strlen(buf);
3774 }
3775 lpfc_alloc_bucket(vport);
3776 vport->stat_data_enabled = 1;
3777 spin_unlock_irq(shost->host_lock);
3778 return strlen(buf);
3779 }
3780
3781 if (!strncmp(buf, "stop", strlen("stop"))) {
3782 spin_lock_irq(shost->host_lock);
3783 if (vport->stat_data_enabled == 0) {
3784 spin_unlock_irq(shost->host_lock);
3785 return strlen(buf);
3786 }
3787 lpfc_free_bucket(vport);
3788 vport->stat_data_enabled = 0;
3789 spin_unlock_irq(shost->host_lock);
3790 return strlen(buf);
3791 }
3792
3793 if (!strncmp(buf, "reset", strlen("reset"))) {
3794 if ((phba->bucket_type == LPFC_NO_BUCKET)
3795 || !vport->stat_data_enabled)
3796 return strlen(buf);
3797 spin_lock_irq(shost->host_lock);
3798 vport->stat_data_blocked = 1;
3799 lpfc_vport_reset_stat_data(vport);
3800 vport->stat_data_blocked = 0;
3801 spin_unlock_irq(shost->host_lock);
3802 return strlen(buf);
3803 }
3804 return -EINVAL;
3805}
3806
3807
3808/**
James Smart3621a712009-04-06 18:47:14 -04003809 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003810 * @dev: Pointer to class device object.
3811 * @buf: Data buffer.
3812 *
3813 * This function is the read call back function for
3814 * lpfc_stat_data_ctrl sysfs file. This function report the
3815 * current statistical data collection state.
3816 **/
3817static ssize_t
3818lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3819 char *buf)
3820{
3821 struct Scsi_Host *shost = class_to_shost(dev);
3822 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3823 struct lpfc_hba *phba = vport->phba;
3824 int index = 0;
3825 int i;
3826 char *bucket_type;
3827 unsigned long bucket_value;
3828
3829 switch (phba->bucket_type) {
3830 case LPFC_LINEAR_BUCKET:
3831 bucket_type = "linear";
3832 break;
3833 case LPFC_POWER2_BUCKET:
3834 bucket_type = "power2";
3835 break;
3836 default:
3837 bucket_type = "No Bucket";
3838 break;
3839 }
3840
3841 sprintf(&buf[index], "Statistical Data enabled :%d, "
3842 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3843 " Bucket step :%d\nLatency Ranges :",
3844 vport->stat_data_enabled, vport->stat_data_blocked,
3845 bucket_type, phba->bucket_base, phba->bucket_step);
3846 index = strlen(buf);
3847 if (phba->bucket_type != LPFC_NO_BUCKET) {
3848 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3849 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3850 bucket_value = phba->bucket_base +
3851 phba->bucket_step * i;
3852 else
3853 bucket_value = phba->bucket_base +
3854 (1 << i) * phba->bucket_step;
3855
3856 if (index + 10 > PAGE_SIZE)
3857 break;
3858 sprintf(&buf[index], "%08ld ", bucket_value);
3859 index = strlen(buf);
3860 }
3861 }
3862 sprintf(&buf[index], "\n");
3863 return strlen(buf);
3864}
3865
3866/*
3867 * Sysfs attribute to control the statistical data collection.
3868 */
3869static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3870 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3871
3872/*
3873 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3874 */
3875
3876/*
3877 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3878 * for each target.
3879 */
3880#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3881#define MAX_STAT_DATA_SIZE_PER_TARGET \
3882 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3883
3884
3885/**
James Smart3621a712009-04-06 18:47:14 -04003886 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003887 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003888 * @kobj: Pointer to the kernel object
3889 * @bin_attr: Attribute object
3890 * @buff: Buffer pointer
3891 * @off: File offset
3892 * @count: Buffer size
3893 *
3894 * This function is the read call back function for lpfc_drvr_stat_data
3895 * sysfs file. This function export the statistical data to user
3896 * applications.
3897 **/
3898static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003899sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3900 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003901 char *buf, loff_t off, size_t count)
3902{
3903 struct device *dev = container_of(kobj, struct device,
3904 kobj);
3905 struct Scsi_Host *shost = class_to_shost(dev);
3906 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3907 struct lpfc_hba *phba = vport->phba;
3908 int i = 0, index = 0;
3909 unsigned long nport_index;
3910 struct lpfc_nodelist *ndlp = NULL;
3911 nport_index = (unsigned long)off /
3912 MAX_STAT_DATA_SIZE_PER_TARGET;
3913
3914 if (!vport->stat_data_enabled || vport->stat_data_blocked
3915 || (phba->bucket_type == LPFC_NO_BUCKET))
3916 return 0;
3917
3918 spin_lock_irq(shost->host_lock);
3919 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3920 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3921 continue;
3922
3923 if (nport_index > 0) {
3924 nport_index--;
3925 continue;
3926 }
3927
3928 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3929 > count)
3930 break;
3931
3932 if (!ndlp->lat_data)
3933 continue;
3934
3935 /* Print the WWN */
3936 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3937 ndlp->nlp_portname.u.wwn[0],
3938 ndlp->nlp_portname.u.wwn[1],
3939 ndlp->nlp_portname.u.wwn[2],
3940 ndlp->nlp_portname.u.wwn[3],
3941 ndlp->nlp_portname.u.wwn[4],
3942 ndlp->nlp_portname.u.wwn[5],
3943 ndlp->nlp_portname.u.wwn[6],
3944 ndlp->nlp_portname.u.wwn[7]);
3945
3946 index = strlen(buf);
3947
3948 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3949 sprintf(&buf[index], "%010u,",
3950 ndlp->lat_data[i].cmd_count);
3951 index = strlen(buf);
3952 }
3953 sprintf(&buf[index], "\n");
3954 index = strlen(buf);
3955 }
3956 spin_unlock_irq(shost->host_lock);
3957 return index;
3958}
3959
3960static struct bin_attribute sysfs_drvr_stat_data_attr = {
3961 .attr = {
3962 .name = "lpfc_drvr_stat_data",
3963 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003964 },
3965 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3966 .read = sysfs_drvr_stat_data_read,
3967 .write = NULL,
3968};
3969
dea31012005-04-17 16:05:31 -05003970/*
3971# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3972# connection.
James Smart76a95d72010-11-20 23:11:48 -05003973# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003974*/
James Smarte59058c2008-08-24 21:49:00 -04003975/**
James Smart3621a712009-04-06 18:47:14 -04003976 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003977 * @phba: lpfc_hba pointer.
3978 * @val: link speed value.
3979 *
3980 * Description:
3981 * If val is in a valid range then set the adapter's link speed field and
3982 * issue a lip; if the lip fails reset the link speed to the old value.
3983 *
3984 * Notes:
3985 * If the value is not in range log a kernel error message and return an error.
3986 *
3987 * Returns:
3988 * zero if val is in range and lip okay.
3989 * non-zero return value from lpfc_issue_lip()
3990 * -EINVAL val out of range
3991 **/
James Smarta257bf92009-04-06 18:48:10 -04003992static ssize_t
3993lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3994 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003995{
James Smarta257bf92009-04-06 18:48:10 -04003996 struct Scsi_Host *shost = class_to_shost(dev);
3997 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3998 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003999 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04004000 int nolip = 0;
4001 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05004002 int err;
James Smartc6918162016-10-13 15:06:16 -07004003 uint32_t prev_val, if_type;
4004
4005 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4006 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
4007 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4008 return -EPERM;
James Smart83108bd2008-01-11 01:53:09 -05004009
James Smarta257bf92009-04-06 18:48:10 -04004010 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4011 nolip = 1;
4012 val_buf = &buf[strlen("nolip ")];
4013 }
4014
4015 if (!isdigit(val_buf[0]))
4016 return -EINVAL;
4017 if (sscanf(val_buf, "%i", &val) != 1)
4018 return -EINVAL;
4019
James Smart88a2cfb2011-07-22 18:36:33 -04004020 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4021 "3055 lpfc_link_speed changed from %d to %d %s\n",
4022 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4023
James Smart76a95d72010-11-20 23:11:48 -05004024 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4025 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4026 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4027 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4028 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
James Smartd38dd522015-08-31 16:48:17 -04004029 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4030 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
James Smart76a95d72010-11-20 23:11:48 -05004031 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4032 "2879 lpfc_link_speed attribute cannot be set "
4033 "to %d. Speed is not supported by this port.\n",
4034 val);
James Smart83108bd2008-01-11 01:53:09 -05004035 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05004036 }
James Smartff78d8f2011-12-13 13:21:35 -05004037 if (val == LPFC_USER_LINK_SPEED_16G &&
4038 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4039 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4040 "3112 lpfc_link_speed attribute cannot be set "
4041 "to %d. Speed is not supported in loop mode.\n",
4042 val);
4043 return -EINVAL;
4044 }
James Smart76a95d72010-11-20 23:11:48 -05004045 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4046 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05004047 prev_val = phba->cfg_link_speed;
4048 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04004049 if (nolip)
4050 return strlen(buf);
4051
James Smart83108bd2008-01-11 01:53:09 -05004052 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04004053 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05004054 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04004055 return -EINVAL;
4056 } else
4057 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05004058 }
James Smart83108bd2008-01-11 01:53:09 -05004059 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05004060 "0469 lpfc_link_speed attribute cannot be set to %d, "
4061 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05004062 return -EINVAL;
4063}
4064
4065static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05004066module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05004067MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4068lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04004069
4070/**
James Smart3621a712009-04-06 18:47:14 -04004071 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004072 * @phba: lpfc_hba pointer.
4073 * @val: link speed value.
4074 *
4075 * Description:
4076 * If val is in a valid range then set the adapter's link speed field.
4077 *
4078 * Notes:
4079 * If the value is not in range log a kernel error message, clear the link
4080 * speed and return an error.
4081 *
4082 * Returns:
4083 * zero if val saved.
4084 * -EINVAL val out of range
4085 **/
James Smart83108bd2008-01-11 01:53:09 -05004086static int
4087lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4088{
James Smartff78d8f2011-12-13 13:21:35 -05004089 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4090 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4091 "3111 lpfc_link_speed of %d cannot "
4092 "support loop mode, setting topology to default.\n",
4093 val);
4094 phba->cfg_topology = 0;
4095 }
James Smart76a95d72010-11-20 23:11:48 -05004096 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4097 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05004098 phba->cfg_link_speed = val;
4099 return 0;
4100 }
4101 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004102 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05004103 "be set to %d, allowed values are "
4104 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05004105 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05004106 return -EINVAL;
4107}
4108
Tony Jonesee959b02008-02-22 00:13:36 +01004109static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05004110 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05004111
4112/*
James Smart0d878412009-10-02 15:16:56 -04004113# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4114# 0 = aer disabled or not supported
4115# 1 = aer supported and enabled (default)
4116# Value range is [0,1]. Default value is 1.
4117*/
James Smart506139a2016-10-13 15:06:09 -07004118LPFC_ATTR(aer_support, 1, 0, 1,
4119 "Enable PCIe device AER support");
4120lpfc_param_show(aer_support)
James Smart0d878412009-10-02 15:16:56 -04004121
4122/**
4123 * lpfc_aer_support_store - Set the adapter for aer support
4124 *
4125 * @dev: class device that is converted into a Scsi_host.
4126 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004127 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04004128 * @count: unused variable.
4129 *
4130 * Description:
4131 * If the val is 1 and currently the device's AER capability was not
4132 * enabled, invoke the kernel's enable AER helper routine, trying to
4133 * enable the device's AER capability. If the helper routine enabling
4134 * AER returns success, update the device's cfg_aer_support flag to
4135 * indicate AER is supported by the device; otherwise, if the device
4136 * AER capability is already enabled to support AER, then do nothing.
4137 *
4138 * If the val is 0 and currently the device's AER support was enabled,
4139 * invoke the kernel's disable AER helper routine. After that, update
4140 * the device's cfg_aer_support flag to indicate AER is not supported
4141 * by the device; otherwise, if the device AER capability is already
4142 * disabled from supporting AER, then do nothing.
4143 *
4144 * Returns:
4145 * length of the buf on success if val is in range the intended mode
4146 * is supported.
4147 * -EINVAL if val out of range or intended mode is not supported.
4148 **/
4149static ssize_t
4150lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4151 const char *buf, size_t count)
4152{
4153 struct Scsi_Host *shost = class_to_shost(dev);
4154 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4155 struct lpfc_hba *phba = vport->phba;
4156 int val = 0, rc = -EINVAL;
4157
4158 if (!isdigit(buf[0]))
4159 return -EINVAL;
4160 if (sscanf(buf, "%i", &val) != 1)
4161 return -EINVAL;
4162
4163 switch (val) {
4164 case 0:
4165 if (phba->hba_flag & HBA_AER_ENABLED) {
4166 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4167 if (!rc) {
4168 spin_lock_irq(&phba->hbalock);
4169 phba->hba_flag &= ~HBA_AER_ENABLED;
4170 spin_unlock_irq(&phba->hbalock);
4171 phba->cfg_aer_support = 0;
4172 rc = strlen(buf);
4173 } else
James Smart891478a2009-11-18 15:40:23 -05004174 rc = -EPERM;
4175 } else {
James Smart0d878412009-10-02 15:16:56 -04004176 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05004177 rc = strlen(buf);
4178 }
James Smart0d878412009-10-02 15:16:56 -04004179 break;
4180 case 1:
4181 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4182 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4183 if (!rc) {
4184 spin_lock_irq(&phba->hbalock);
4185 phba->hba_flag |= HBA_AER_ENABLED;
4186 spin_unlock_irq(&phba->hbalock);
4187 phba->cfg_aer_support = 1;
4188 rc = strlen(buf);
4189 } else
James Smart891478a2009-11-18 15:40:23 -05004190 rc = -EPERM;
4191 } else {
James Smart0d878412009-10-02 15:16:56 -04004192 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05004193 rc = strlen(buf);
4194 }
James Smart0d878412009-10-02 15:16:56 -04004195 break;
4196 default:
4197 rc = -EINVAL;
4198 break;
4199 }
4200 return rc;
4201}
4202
James Smart0d878412009-10-02 15:16:56 -04004203static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
4204 lpfc_aer_support_show, lpfc_aer_support_store);
4205
4206/**
4207 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4208 * @dev: class device that is converted into a Scsi_host.
4209 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004210 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04004211 * @count: unused variable.
4212 *
4213 * Description:
4214 * If the @buf contains 1 and the device currently has the AER support
4215 * enabled, then invokes the kernel AER helper routine
4216 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4217 * error status register.
4218 *
4219 * Notes:
4220 *
4221 * Returns:
4222 * -EINVAL if the buf does not contain the 1 or the device is not currently
4223 * enabled with the AER support.
4224 **/
4225static ssize_t
4226lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4227 const char *buf, size_t count)
4228{
4229 struct Scsi_Host *shost = class_to_shost(dev);
4230 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4231 struct lpfc_hba *phba = vport->phba;
4232 int val, rc = -1;
4233
4234 if (!isdigit(buf[0]))
4235 return -EINVAL;
4236 if (sscanf(buf, "%i", &val) != 1)
4237 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05004238 if (val != 1)
4239 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04004240
James Smart891478a2009-11-18 15:40:23 -05004241 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04004242 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4243
4244 if (rc == 0)
4245 return strlen(buf);
4246 else
James Smart891478a2009-11-18 15:40:23 -05004247 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04004248}
4249
4250static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4251 lpfc_aer_cleanup_state);
4252
James Smart912e3ac2011-05-24 11:42:11 -04004253/**
4254 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4255 *
4256 * @dev: class device that is converted into a Scsi_host.
4257 * @attr: device attribute, not used.
4258 * @buf: containing the string the number of vfs to be enabled.
4259 * @count: unused variable.
4260 *
4261 * Description:
4262 * When this api is called either through user sysfs, the driver shall
4263 * try to enable or disable SR-IOV virtual functions according to the
4264 * following:
4265 *
4266 * If zero virtual function has been enabled to the physical function,
4267 * the driver shall invoke the pci enable virtual function api trying
4268 * to enable the virtual functions. If the nr_vfn provided is greater
4269 * than the maximum supported, the maximum virtual function number will
4270 * be used for invoking the api; otherwise, the nr_vfn provided shall
4271 * be used for invoking the api. If the api call returned success, the
4272 * actual number of virtual functions enabled will be set to the driver
4273 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4274 * cfg_sriov_nr_virtfn remains zero.
4275 *
4276 * If none-zero virtual functions have already been enabled to the
4277 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4278 * -EINVAL will be returned and the driver does nothing;
4279 *
4280 * If the nr_vfn provided is zero and none-zero virtual functions have
4281 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4282 * disabling virtual function api shall be invoded to disable all the
4283 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4284 * zero. Otherwise, if zero virtual function has been enabled, do
4285 * nothing.
4286 *
4287 * Returns:
4288 * length of the buf on success if val is in range the intended mode
4289 * is supported.
4290 * -EINVAL if val out of range or intended mode is not supported.
4291 **/
4292static ssize_t
4293lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4294 const char *buf, size_t count)
4295{
4296 struct Scsi_Host *shost = class_to_shost(dev);
4297 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4298 struct lpfc_hba *phba = vport->phba;
4299 struct pci_dev *pdev = phba->pcidev;
4300 int val = 0, rc = -EINVAL;
4301
4302 /* Sanity check on user data */
4303 if (!isdigit(buf[0]))
4304 return -EINVAL;
4305 if (sscanf(buf, "%i", &val) != 1)
4306 return -EINVAL;
4307 if (val < 0)
4308 return -EINVAL;
4309
4310 /* Request disabling virtual functions */
4311 if (val == 0) {
4312 if (phba->cfg_sriov_nr_virtfn > 0) {
4313 pci_disable_sriov(pdev);
4314 phba->cfg_sriov_nr_virtfn = 0;
4315 }
4316 return strlen(buf);
4317 }
4318
4319 /* Request enabling virtual functions */
4320 if (phba->cfg_sriov_nr_virtfn > 0) {
4321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4322 "3018 There are %d virtual functions "
4323 "enabled on physical function.\n",
4324 phba->cfg_sriov_nr_virtfn);
4325 return -EEXIST;
4326 }
4327
4328 if (val <= LPFC_MAX_VFN_PER_PFN)
4329 phba->cfg_sriov_nr_virtfn = val;
4330 else {
4331 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4332 "3019 Enabling %d virtual functions is not "
4333 "allowed.\n", val);
4334 return -EINVAL;
4335 }
4336
4337 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4338 if (rc) {
4339 phba->cfg_sriov_nr_virtfn = 0;
4340 rc = -EPERM;
4341 } else
4342 rc = strlen(buf);
4343
4344 return rc;
4345}
4346
James Smart0cfbbf22016-10-13 15:06:12 -07004347LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4348 "Enable PCIe device SR-IOV virtual fn");
4349
James Smart912e3ac2011-05-24 11:42:11 -04004350lpfc_param_show(sriov_nr_virtfn)
James Smart912e3ac2011-05-24 11:42:11 -04004351static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4352 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4353
James Smart173edbb2012-06-12 13:54:50 -04004354/**
James Smartc71ab862012-10-31 14:44:33 -04004355 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4356 *
4357 * @dev: class device that is converted into a Scsi_host.
4358 * @attr: device attribute, not used.
4359 * @buf: containing the string the number of vfs to be enabled.
4360 * @count: unused variable.
4361 *
4362 * Description:
4363 *
4364 * Returns:
4365 * length of the buf on success if val is in range the intended mode
4366 * is supported.
4367 * -EINVAL if val out of range or intended mode is not supported.
4368 **/
4369static ssize_t
4370lpfc_request_firmware_upgrade_store(struct device *dev,
4371 struct device_attribute *attr,
4372 const char *buf, size_t count)
4373{
4374 struct Scsi_Host *shost = class_to_shost(dev);
4375 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4376 struct lpfc_hba *phba = vport->phba;
4377 int val = 0, rc = -EINVAL;
4378
4379 /* Sanity check on user data */
4380 if (!isdigit(buf[0]))
4381 return -EINVAL;
4382 if (sscanf(buf, "%i", &val) != 1)
4383 return -EINVAL;
4384 if (val != 1)
4385 return -EINVAL;
4386
4387 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4388 if (rc)
4389 rc = -EPERM;
4390 else
4391 rc = strlen(buf);
4392 return rc;
4393}
4394
4395static int lpfc_req_fw_upgrade;
4396module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4397MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4398lpfc_param_show(request_firmware_upgrade)
4399
4400/**
4401 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4402 * @phba: lpfc_hba pointer.
4403 * @val: 0 or 1.
4404 *
4405 * Description:
4406 * Set the initial Linux generic firmware upgrade enable or disable flag.
4407 *
4408 * Returns:
4409 * zero if val saved.
4410 * -EINVAL val out of range
4411 **/
4412static int
4413lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4414{
4415 if (val >= 0 && val <= 1) {
4416 phba->cfg_request_firmware_upgrade = val;
4417 return 0;
4418 }
4419 return -EINVAL;
4420}
4421static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4422 lpfc_request_firmware_upgrade_show,
4423 lpfc_request_firmware_upgrade_store);
4424
4425/**
James Smart173edbb2012-06-12 13:54:50 -04004426 * lpfc_fcp_imax_store
4427 *
4428 * @dev: class device that is converted into a Scsi_host.
4429 * @attr: device attribute, not used.
4430 * @buf: string with the number of fast-path FCP interrupts per second.
4431 * @count: unused variable.
4432 *
4433 * Description:
4434 * If val is in a valid range [636,651042], then set the adapter's
4435 * maximum number of fast-path FCP interrupts per second.
4436 *
4437 * Returns:
4438 * length of the buf on success if val is in range the intended mode
4439 * is supported.
4440 * -EINVAL if val out of range or intended mode is not supported.
4441 **/
4442static ssize_t
4443lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4444 const char *buf, size_t count)
4445{
4446 struct Scsi_Host *shost = class_to_shost(dev);
4447 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4448 struct lpfc_hba *phba = vport->phba;
4449 int val = 0, i;
4450
James Smartbf8dae82012-08-03 12:36:24 -04004451 /* fcp_imax is only valid for SLI4 */
4452 if (phba->sli_rev != LPFC_SLI_REV4)
4453 return -EINVAL;
4454
James Smart173edbb2012-06-12 13:54:50 -04004455 /* Sanity check on user data */
4456 if (!isdigit(buf[0]))
4457 return -EINVAL;
4458 if (sscanf(buf, "%i", &val) != 1)
4459 return -EINVAL;
4460
James Smartbf8dae82012-08-03 12:36:24 -04004461 /*
4462 * Value range for the HBA is [5000,5000000]
4463 * The value for each EQ depends on how many EQs are configured.
James Smart895427b2017-02-12 13:52:30 -08004464 * Allow value == 0
James Smartbf8dae82012-08-03 12:36:24 -04004465 */
James Smart895427b2017-02-12 13:52:30 -08004466 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
James Smart173edbb2012-06-12 13:54:50 -04004467 return -EINVAL;
4468
4469 phba->cfg_fcp_imax = (uint32_t)val;
James Smart43140ca2017-03-04 09:30:34 -08004470
4471 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart895427b2017-02-12 13:52:30 -08004472 lpfc_modify_hba_eq_delay(phba, i);
James Smart173edbb2012-06-12 13:54:50 -04004473
4474 return strlen(buf);
4475}
4476
4477/*
4478# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04004479# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04004480#
James Smartbf8dae82012-08-03 12:36:24 -04004481# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04004482*/
James Smartbf8dae82012-08-03 12:36:24 -04004483static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004484module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4485MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04004486 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04004487lpfc_param_show(fcp_imax)
4488
4489/**
4490 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4491 * @phba: lpfc_hba pointer.
4492 * @val: link speed value.
4493 *
4494 * Description:
4495 * If val is in a valid range [636,651042], then initialize the adapter's
4496 * maximum number of fast-path FCP interrupts per second.
4497 *
4498 * Returns:
4499 * zero if val saved.
4500 * -EINVAL val out of range
4501 **/
4502static int
4503lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4504{
James Smartbf8dae82012-08-03 12:36:24 -04004505 if (phba->sli_rev != LPFC_SLI_REV4) {
4506 phba->cfg_fcp_imax = 0;
4507 return 0;
4508 }
4509
James Smart895427b2017-02-12 13:52:30 -08004510 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4511 (val == 0)) {
James Smart173edbb2012-06-12 13:54:50 -04004512 phba->cfg_fcp_imax = val;
4513 return 0;
4514 }
4515
4516 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004517 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4518 val);
James Smartbf8dae82012-08-03 12:36:24 -04004519 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004520
4521 return 0;
4522}
4523
4524static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4525 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4526
James Smart7bb03bb2013-04-17 20:19:16 -04004527/**
4528 * lpfc_state_show - Display current driver CPU affinity
4529 * @dev: class converted to a Scsi_host structure.
4530 * @attr: device attribute, not used.
4531 * @buf: on return contains text describing the state of the link.
4532 *
4533 * Returns: size of formatted string.
4534 **/
4535static ssize_t
4536lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4537 char *buf)
4538{
4539 struct Scsi_Host *shost = class_to_shost(dev);
4540 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4541 struct lpfc_hba *phba = vport->phba;
4542 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05004543 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04004544
4545 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4546 (phba->intr_type != MSIX))
4547 return len;
4548
4549 switch (phba->cfg_fcp_cpu_map) {
4550 case 0:
4551 len += snprintf(buf + len, PAGE_SIZE-len,
4552 "fcp_cpu_map: No mapping (%d)\n",
4553 phba->cfg_fcp_cpu_map);
4554 return len;
4555 case 1:
4556 len += snprintf(buf + len, PAGE_SIZE-len,
4557 "fcp_cpu_map: HBA centric mapping (%d): "
4558 "%d online CPUs\n",
4559 phba->cfg_fcp_cpu_map,
4560 phba->sli4_hba.num_online_cpu);
4561 break;
4562 case 2:
4563 len += snprintf(buf + len, PAGE_SIZE-len,
4564 "fcp_cpu_map: Driver centric mapping (%d): "
4565 "%d online CPUs\n",
4566 phba->cfg_fcp_cpu_map,
4567 phba->sli4_hba.num_online_cpu);
4568 break;
4569 }
4570
James Smart76fd07a2014-02-20 09:57:18 -05004571 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4572 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4573
4574 /* margin should fit in this and the truncated message */
James Smart7bb03bb2013-04-17 20:19:16 -04004575 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4576 len += snprintf(buf + len, PAGE_SIZE-len,
4577 "CPU %02d io_chan %02d "
4578 "physid %d coreid %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004579 phba->sli4_hba.curr_disp_cpu,
4580 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004581 cpup->core_id);
4582 else
4583 len += snprintf(buf + len, PAGE_SIZE-len,
4584 "CPU %02d io_chan %02d "
4585 "physid %d coreid %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004586 phba->sli4_hba.curr_disp_cpu,
4587 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004588 cpup->core_id, cpup->irq);
4589
James Smart76fd07a2014-02-20 09:57:18 -05004590 phba->sli4_hba.curr_disp_cpu++;
4591
4592 /* display max number of CPUs keeping some margin */
4593 if (phba->sli4_hba.curr_disp_cpu <
4594 phba->sli4_hba.num_present_cpu &&
4595 (len >= (PAGE_SIZE - 64))) {
4596 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4597 break;
4598 }
James Smart7bb03bb2013-04-17 20:19:16 -04004599 }
James Smart76fd07a2014-02-20 09:57:18 -05004600
4601 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4602 phba->sli4_hba.curr_disp_cpu = 0;
4603
James Smart7bb03bb2013-04-17 20:19:16 -04004604 return len;
4605}
4606
4607/**
4608 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4609 * @dev: class device that is converted into a Scsi_host.
4610 * @attr: device attribute, not used.
4611 * @buf: one or more lpfc_polling_flags values.
4612 * @count: not used.
4613 *
4614 * Returns:
4615 * -EINVAL - Not implemented yet.
4616 **/
4617static ssize_t
4618lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4619 const char *buf, size_t count)
4620{
4621 int status = -EINVAL;
4622 return status;
4623}
4624
4625/*
4626# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4627# for the HBA.
4628#
4629# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4630# 0 - Do not affinitze IRQ vectors
4631# 1 - Affintize HBA vectors with respect to each HBA
4632# (start with CPU0 for each HBA)
4633# 2 - Affintize HBA vectors with respect to the entire driver
4634# (round robin thru all CPUs across all HBAs)
4635*/
4636static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4637module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4638MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4639 "Defines how to map CPUs to IRQ vectors per HBA");
4640
4641/**
4642 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4643 * @phba: lpfc_hba pointer.
4644 * @val: link speed value.
4645 *
4646 * Description:
4647 * If val is in a valid range [0-2], then affinitze the adapter's
4648 * MSIX vectors.
4649 *
4650 * Returns:
4651 * zero if val saved.
4652 * -EINVAL val out of range
4653 **/
4654static int
4655lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4656{
4657 if (phba->sli_rev != LPFC_SLI_REV4) {
4658 phba->cfg_fcp_cpu_map = 0;
4659 return 0;
4660 }
4661
4662 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4663 phba->cfg_fcp_cpu_map = val;
4664 return 0;
4665 }
4666
4667 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004668 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4669 "default\n", val);
James Smart7bb03bb2013-04-17 20:19:16 -04004670 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4671
4672 return 0;
4673}
4674
4675static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4676 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4677
James Smart0d878412009-10-02 15:16:56 -04004678/*
dea31012005-04-17 16:05:31 -05004679# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4680# Value range is [2,3]. Default value is 3.
4681*/
James Smart3de2a652007-08-02 11:09:59 -04004682LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4683 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05004684
4685/*
4686# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4687# is [0,1]. Default value is 0.
4688*/
James Smart3de2a652007-08-02 11:09:59 -04004689LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4690 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05004691
4692/*
James Smart3cb01c52013-07-15 18:35:04 -04004693# lpfc_first_burst_size: First burst size to use on the NPorts
4694# that support first burst.
4695# Value range is [0,65536]. Default value is 0.
4696*/
4697LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4698 "First burst size for Targets that support first burst");
4699
4700/*
James Smart2d7dbc42017-02-12 13:52:35 -08004701* lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4702* When the driver is configured as an NVME target, this value is
4703* communicated to the NVME initiator in the PRLI response. It is
4704* used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4705* parameters are set and the target is sending the PRLI RSP.
James Smart895427b2017-02-12 13:52:30 -08004706* Parameter supported on physical port only - no NPIV support.
James Smart2d7dbc42017-02-12 13:52:35 -08004707* Value range is [0,65536]. Default value is 0.
James Smart895427b2017-02-12 13:52:30 -08004708*/
James Smart2d7dbc42017-02-12 13:52:35 -08004709LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4710 "NVME Target mode first burst size in 512B increments.");
4711
4712/*
4713 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4714 * For the Initiator (I), enabling this parameter means that an NVMET
4715 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4716 * processed by the initiator for subsequent NVME FCP IO. For the target
4717 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4718 * driver parameter as the target function's first burst size returned to the
4719 * initiator in the target's NVME PRLI response. Parameter supported on physical
4720 * port only - no NPIV support.
4721 * Value range is [0,1]. Default value is 0 (disabled).
4722 */
James Smart895427b2017-02-12 13:52:30 -08004723LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4724 "Enable First Burst feature on I and T functions.");
4725
4726/*
James Smart977b5a02008-09-07 11:52:04 -04004727# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4728# depth. Default value is 0. When the value of this parameter is zero the
4729# SCSI command completion time is not used for controlling I/O queue depth. When
4730# the parameter is set to a non-zero value, the I/O queue depth is controlled
4731# to limit the I/O completion time to the parameter value.
4732# The value is set in milliseconds.
4733*/
James Smarted5b1522016-10-13 15:06:11 -07004734LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
James Smart977b5a02008-09-07 11:52:04 -04004735 "Use command completion time to control queue depth");
James Smarted5b1522016-10-13 15:06:11 -07004736
James Smart977b5a02008-09-07 11:52:04 -04004737lpfc_vport_param_show(max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04004738static int
4739lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4740{
4741 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4742 struct lpfc_nodelist *ndlp, *next_ndlp;
4743
4744 if (val == vport->cfg_max_scsicmpl_time)
4745 return 0;
4746 if ((val < 0) || (val > 60000))
4747 return -EINVAL;
4748 vport->cfg_max_scsicmpl_time = val;
4749
4750 spin_lock_irq(shost->host_lock);
4751 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4752 if (!NLP_CHK_NODE_ACT(ndlp))
4753 continue;
4754 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4755 continue;
James Smart7dc517d2010-07-14 15:32:10 -04004756 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04004757 }
4758 spin_unlock_irq(shost->host_lock);
4759 return 0;
4760}
4761lpfc_vport_param_store(max_scsicmpl_time);
4762static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4763 lpfc_max_scsicmpl_time_show,
4764 lpfc_max_scsicmpl_time_store);
4765
4766/*
dea31012005-04-17 16:05:31 -05004767# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4768# range is [0,1]. Default value is 0.
4769*/
4770LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4771
4772/*
James Smart895427b2017-02-12 13:52:30 -08004773 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4774 * range is [0,1]. Default value is 0.
4775 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4776 * For [1], FCP commands are issued to a Work Queue associated with the
4777 * current CPU.
4778 *
4779 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4780 * LPFC_FCP_SCHED_BY_CPU == 1
4781 *
4782 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4783 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4784 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4785 * through WQs will be used.
4786 */
4787LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4788 LPFC_FCP_SCHED_ROUND_ROBIN,
4789 LPFC_FCP_SCHED_BY_CPU,
4790 "Determine scheduling algorithm for "
4791 "issuing commands [0] - Round Robin, [1] - Current CPU");
James Smart49aa1432012-08-03 12:36:42 -04004792
4793/*
James Smarta6571c62012-10-31 14:44:42 -04004794# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4795# range is [0,1]. Default value is 0.
4796# For [0], bus reset issues target reset to ALL devices
4797# For [1], bus reset issues target reset to non-FCP2 devices
4798*/
4799LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4800 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4801
4802
4803/*
dea31012005-04-17 16:05:31 -05004804# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4805# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04004806# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05004807# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4808# cr_delay is set to 0.
4809*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004810LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05004811 "interrupt response is generated");
4812
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004813LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05004814 "interrupt response is generated");
4815
4816/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004817# lpfc_multi_ring_support: Determines how many rings to spread available
4818# cmd/rsp IOCB entries across.
4819# Value range is [1,2]. Default value is 1.
4820*/
4821LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4822 "SLI rings to spread IOCB entries across");
4823
4824/*
James Smarta4bc3372006-12-02 13:34:16 -05004825# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4826# identifies what rctl value to configure the additional ring for.
4827# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4828*/
James Smart6a9c52c2009-10-02 15:16:51 -04004829LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004830 255, "Identifies RCTL for additional ring configuration");
4831
4832/*
4833# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4834# identifies what type value to configure the additional ring for.
4835# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4836*/
James Smart6a9c52c2009-10-02 15:16:51 -04004837LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004838 255, "Identifies TYPE for additional ring configuration");
4839
4840/*
James Smart4258e982015-12-16 18:11:58 -05004841# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4842# 0 = SmartSAN functionality disabled (default)
4843# 1 = SmartSAN functionality enabled
4844# This parameter will override the value of lpfc_fdmi_on module parameter.
4845# Value range is [0,1]. Default value is 0.
dea31012005-04-17 16:05:31 -05004846*/
James Smart4258e982015-12-16 18:11:58 -05004847LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4848
4849/*
4850# lpfc_fdmi_on: Controls FDMI support.
4851# 0 No FDMI support (default)
4852# 1 Traditional FDMI support
James Smart8663cbb2016-03-31 14:12:33 -07004853# Traditional FDMI support means the driver will assume FDMI-2 support;
4854# however, if that fails, it will fallback to FDMI-1.
4855# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4856# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4857# lpfc_fdmi_on.
4858# Value range [0,1]. Default value is 0.
James Smart4258e982015-12-16 18:11:58 -05004859*/
James Smart8663cbb2016-03-31 14:12:33 -07004860LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05004861
4862/*
4863# Specifies the maximum number of ELS cmds we can have outstanding (for
4864# discovery). Value range is [1,64]. Default value = 32.
4865*/
James Smart3de2a652007-08-02 11:09:59 -04004866LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05004867 "during discovery");
4868
4869/*
James Smartc4a7c922013-05-31 17:04:59 -04004870# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4871# will be scanned by the SCSI midlayer when sequential scanning is
4872# used; and is also the highest LUN ID allowed when the SCSI midlayer
4873# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4874# LUN ID limit, but the SCSI midlayer requires this field for the uses
4875# above. The lpfc driver limits the default value to 255 for two reasons.
4876# As it bounds the sequential scan loop, scanning for thousands of luns
4877# on a target can take minutes of wall clock time. Additionally,
4878# there are FC targets, such as JBODs, that only recognize 8-bits of
4879# LUN ID. When they receive a value greater than 8 bits, they chop off
4880# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4881# and so on all as LUN ID 0. This causes the linux kernel, which sees
4882# valid responses at each of the LUN IDs, to believe there are multiple
4883# devices present, when in fact, there is only 1.
4884# A customer that is aware of their target behaviors, and the results as
4885# indicated above, is welcome to increase the lpfc_max_luns value.
4886# As mentioned, this value is not used by the lpfc driver, only the
4887# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04004888# Value range is [0,65535]. Default value is 255.
4889# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05004890*/
Hannes Reinecke1abf6352014-06-25 15:27:38 +02004891LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05004892
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004893/*
4894# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4895# Value range is [1,255], default value is 10.
4896*/
4897LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4898 "Milliseconds driver will wait between polling FCP ring");
4899
James Smart4ff43242006-12-02 13:34:56 -05004900/*
James Smart0c411222013-09-06 12:22:46 -04004901# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4902# to complete in seconds. Value range is [5,180], default value is 60.
4903*/
4904LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4905 "Maximum time to wait for task management commands to complete");
4906/*
James Smart4ff43242006-12-02 13:34:56 -05004907# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4908# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02004909# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05004910# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02004911# 2 = MSI-X enabled (default)
4912# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05004913*/
George Kadianakis8605c462010-01-17 21:19:31 +02004914LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05004915 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05004916
James Smart13815c82008-01-11 01:52:48 -05004917/*
James Smartf358dd02017-02-12 13:52:34 -08004918 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
James Smart895427b2017-02-12 13:52:30 -08004919 *
4920 * 0 = NVME OAS disabled
4921 * 1 = NVME OAS enabled
4922 *
4923 * Value range is [0,1]. Default value is 0.
4924 */
4925LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
4926 "Use OAS bit on NVME IOs");
4927
4928/*
4929 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
4930 * will advertise it supports to the SCSI layer. This also will map to
4931 * the number of WQs the driver will create.
4932 *
4933 * 0 = Configure the number of io channels to the number of active CPUs.
4934 * 1,32 = Manually specify how many io channels to use.
4935 *
4936 * Value range is [0,32]. Default value is 4.
4937 */
4938LPFC_ATTR_R(fcp_io_channel,
4939 LPFC_FCP_IO_CHAN_DEF,
4940 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
James Smart67d12732012-08-03 12:36:13 -04004941 "Set the number of FCP I/O channels");
4942
4943/*
James Smart895427b2017-02-12 13:52:30 -08004944 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
4945 * will advertise it supports to the NVME layer. This also will map to
4946 * the number of WQs the driver will create.
4947 *
4948 * This module parameter is valid when lpfc_enable_fc4_type is set
4949 * to support NVME.
4950 *
4951 * The NVME Layer will try to create this many, plus 1 administrative
4952 * hardware queue. The administrative queue will always map to WQ 0
4953 * A hardware IO queue maps (qidx) to a specific driver WQ.
4954 *
4955 * 0 = Configure the number of io channels to the number of active CPUs.
4956 * 1,32 = Manually specify how many io channels to use.
4957 *
4958 * Value range is [0,32]. Default value is 0.
4959 */
4960LPFC_ATTR_R(nvme_io_channel,
4961 LPFC_NVME_IO_CHAN_DEF,
4962 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4963 "Set the number of NVME I/O channels");
4964
4965/*
James Smart13815c82008-01-11 01:52:48 -05004966# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4967# 0 = HBA resets disabled
4968# 1 = HBA resets enabled (default)
4969# Value range is [0,1]. Default value is 1.
4970*/
4971LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04004972
James Smart13815c82008-01-11 01:52:48 -05004973/*
James Smarteb7a3392010-11-20 23:12:02 -05004974# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05004975# 0 = HBA Heartbeat disabled
4976# 1 = HBA Heartbeat enabled (default)
4977# Value range is [0,1]. Default value is 1.
4978*/
James Smarteb7a3392010-11-20 23:12:02 -05004979LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05004980
James Smart83108bd2008-01-11 01:53:09 -05004981/*
James Smart1ba981f2014-02-20 09:56:45 -05004982# lpfc_EnableXLane: Enable Express Lane Feature
4983# 0x0 Express Lane Feature disabled
4984# 0x1 Express Lane Feature enabled
4985# Value range is [0,1]. Default value is 0.
4986*/
4987LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
4988
4989/*
4990# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
4991# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
4992# Value range is [0x0,0x7f]. Default value is 0
4993*/
James Smart28d7f3d2014-05-21 08:05:28 -04004994LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
James Smart1ba981f2014-02-20 09:56:45 -05004995
4996/*
James Smart81301a92008-12-04 22:39:46 -05004997# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4998# 0 = BlockGuard disabled (default)
4999# 1 = BlockGuard enabled
5000# Value range is [0,1]. Default value is 0.
5001*/
5002LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5003
James Smart6fb120a2009-05-22 14:52:59 -04005004/*
James Smartba20c852012-08-03 12:36:52 -04005005# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5006# 0 = disabled (default)
5007# 1 = enabled
5008# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04005009#
5010# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04005011*/
5012unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5013
James Smartba20c852012-08-03 12:36:52 -04005014/*
James Smart81301a92008-12-04 22:39:46 -05005015# lpfc_prot_mask: i
5016# - Bit mask of host protection capabilities used to register with the
5017# SCSI mid-layer
5018# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5019# - Allows you to ultimately specify which profiles to use
5020# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04005021# - SHOST_DIF_TYPE1_PROTECTION 1
5022# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5023# - SHOST_DIX_TYPE0_PROTECTION 8
5024# HBA supports DIX Type 0: Host to HBA protection only
5025# - SHOST_DIX_TYPE1_PROTECTION 16
5026# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05005027#
5028*/
James Smartb3b98b72016-10-13 15:06:06 -07005029LPFC_ATTR(prot_mask,
5030 (SHOST_DIF_TYPE1_PROTECTION |
5031 SHOST_DIX_TYPE0_PROTECTION |
5032 SHOST_DIX_TYPE1_PROTECTION),
5033 0,
5034 (SHOST_DIF_TYPE1_PROTECTION |
5035 SHOST_DIX_TYPE0_PROTECTION |
5036 SHOST_DIX_TYPE1_PROTECTION),
5037 "T10-DIF host protection capabilities mask");
James Smart81301a92008-12-04 22:39:46 -05005038
5039/*
5040# lpfc_prot_guard: i
5041# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04005042# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05005043# - Allows you to ultimately specify which profiles to use
5044# - Default will result in registering capabilities for all guard types
5045#
5046*/
James Smartb3b98b72016-10-13 15:06:06 -07005047LPFC_ATTR(prot_guard,
5048 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5049 "T10-DIF host protection guard type");
James Smart81301a92008-12-04 22:39:46 -05005050
James Smart92494142011-02-16 12:39:44 -05005051/*
5052 * Delay initial NPort discovery when Clean Address bit is cleared in
5053 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5054 * This parameter can have value 0 or 1.
5055 * When this parameter is set to 0, no delay is added to the initial
5056 * discovery.
5057 * When this parameter is set to non-zero value, initial Nport discovery is
5058 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5059 * accept and FCID/Fabric name/Fabric portname is changed.
5060 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5061 * when Clean Address bit is cleared in FLOGI/FDISC
5062 * accept and FCID/Fabric name/Fabric portname is changed.
5063 * Default value is 0.
5064 */
James Smart8eb8b962016-07-06 12:36:08 -07005065LPFC_ATTR(delay_discovery, 0, 0, 1,
5066 "Delay NPort discovery when Clean Address bit is cleared.");
James Smart81301a92008-12-04 22:39:46 -05005067
5068/*
James Smart3621a712009-04-06 18:47:14 -04005069 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart96f70772013-04-17 20:16:15 -04005070 * This value can be set to values between 64 and 4096. The default value is
James Smart83108bd2008-01-11 01:53:09 -05005071 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5072 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04005073 * Because of the additional overhead involved in setting up T10-DIF,
5074 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5075 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05005076 */
5077LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
5078 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5079
James Smart96f70772013-04-17 20:16:15 -04005080/*
James Smart7bdedb32016-07-06 12:36:00 -07005081 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5082 * 0 = MDS Diagnostics disabled (default)
5083 * 1 = MDS Diagnostics enabled
5084 * Value range is [0,1]. Default value is 0.
5085 */
5086LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5087
Tony Jonesee959b02008-02-22 00:13:36 +01005088struct device_attribute *lpfc_hba_attrs[] = {
James Smart895427b2017-02-12 13:52:30 -08005089 &dev_attr_nvme_info,
James Smart81301a92008-12-04 22:39:46 -05005090 &dev_attr_bg_info,
5091 &dev_attr_bg_guard_err,
5092 &dev_attr_bg_apptag_err,
5093 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01005094 &dev_attr_info,
5095 &dev_attr_serialnum,
5096 &dev_attr_modeldesc,
5097 &dev_attr_modelname,
5098 &dev_attr_programtype,
5099 &dev_attr_portnum,
5100 &dev_attr_fwrev,
5101 &dev_attr_hdw,
5102 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005103 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005104 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04005105 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01005106 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04005107 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01005108 &dev_attr_lpfc_temp_sensor,
5109 &dev_attr_lpfc_log_verbose,
5110 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005111 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005112 &dev_attr_lpfc_hba_queue_depth,
5113 &dev_attr_lpfc_peer_port_login,
5114 &dev_attr_lpfc_nodev_tmo,
5115 &dev_attr_lpfc_devloss_tmo,
James Smart895427b2017-02-12 13:52:30 -08005116 &dev_attr_lpfc_enable_fc4_type,
5117 &dev_attr_lpfc_xri_split,
Tony Jonesee959b02008-02-22 00:13:36 +01005118 &dev_attr_lpfc_fcp_class,
5119 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005120 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005121 &dev_attr_lpfc_ack0,
5122 &dev_attr_lpfc_topology,
5123 &dev_attr_lpfc_scan_down,
5124 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04005125 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04005126 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01005127 &dev_attr_lpfc_cr_delay,
5128 &dev_attr_lpfc_cr_count,
5129 &dev_attr_lpfc_multi_ring_support,
5130 &dev_attr_lpfc_multi_ring_rctl,
5131 &dev_attr_lpfc_multi_ring_type,
5132 &dev_attr_lpfc_fdmi_on,
James Smart4258e982015-12-16 18:11:58 -05005133 &dev_attr_lpfc_enable_SmartSAN,
Tony Jonesee959b02008-02-22 00:13:36 +01005134 &dev_attr_lpfc_max_luns,
5135 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04005136 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05005137 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01005138 &dev_attr_nport_evt_cnt,
5139 &dev_attr_board_mode,
5140 &dev_attr_max_vpi,
5141 &dev_attr_used_vpi,
5142 &dev_attr_max_rpi,
5143 &dev_attr_used_rpi,
5144 &dev_attr_max_xri,
5145 &dev_attr_used_xri,
5146 &dev_attr_npiv_info,
5147 &dev_attr_issue_reset,
5148 &dev_attr_lpfc_poll,
5149 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04005150 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01005151 &dev_attr_lpfc_use_msi,
James Smart895427b2017-02-12 13:52:30 -08005152 &dev_attr_lpfc_nvme_oas,
James Smartda0436e2009-05-22 14:51:39 -04005153 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04005154 &dev_attr_lpfc_fcp_cpu_map,
James Smart67d12732012-08-03 12:36:13 -04005155 &dev_attr_lpfc_fcp_io_channel,
James Smartf358dd02017-02-12 13:52:34 -08005156 &dev_attr_lpfc_suppress_rsp,
James Smart895427b2017-02-12 13:52:30 -08005157 &dev_attr_lpfc_nvme_io_channel,
James Smart2d7dbc42017-02-12 13:52:35 -08005158 &dev_attr_lpfc_nvmet_mrq,
James Smart895427b2017-02-12 13:52:30 -08005159 &dev_attr_lpfc_nvme_enable_fb,
James Smart2d7dbc42017-02-12 13:52:35 -08005160 &dev_attr_lpfc_nvmet_fb_size,
James Smart81301a92008-12-04 22:39:46 -05005161 &dev_attr_lpfc_enable_bg,
James Smart352e5fd2016-12-30 06:57:47 -08005162 &dev_attr_lpfc_soft_wwnn,
5163 &dev_attr_lpfc_soft_wwpn,
5164 &dev_attr_lpfc_soft_wwn_enable,
Tony Jonesee959b02008-02-22 00:13:36 +01005165 &dev_attr_lpfc_enable_hba_reset,
5166 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05005167 &dev_attr_lpfc_EnableXLane,
5168 &dev_attr_lpfc_XLanePriority,
5169 &dev_attr_lpfc_xlane_lun,
5170 &dev_attr_lpfc_xlane_tgt,
5171 &dev_attr_lpfc_xlane_vpt,
5172 &dev_attr_lpfc_xlane_lun_state,
5173 &dev_attr_lpfc_xlane_lun_status,
James Smartc92c8412016-07-06 12:36:05 -07005174 &dev_attr_lpfc_xlane_priority,
Tony Jonesee959b02008-02-22 00:13:36 +01005175 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04005176 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04005177 &dev_attr_lpfc_stat_data_ctrl,
James Smart0d878412009-10-02 15:16:56 -04005178 &dev_attr_lpfc_aer_support,
5179 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04005180 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04005181 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05005182 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04005183 &dev_attr_lpfc_iocb_cnt,
5184 &dev_attr_iocb_hw,
5185 &dev_attr_txq_hw,
5186 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04005187 &dev_attr_lpfc_fips_level,
5188 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05005189 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04005190 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05005191 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05005192 &dev_attr_lpfc_xlane_supported,
James Smart7bdedb32016-07-06 12:36:00 -07005193 &dev_attr_lpfc_enable_mds_diags,
dea31012005-04-17 16:05:31 -05005194 NULL,
5195};
5196
Tony Jonesee959b02008-02-22 00:13:36 +01005197struct device_attribute *lpfc_vport_attrs[] = {
5198 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005199 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005200 &dev_attr_num_discovered_ports,
5201 &dev_attr_lpfc_drvr_version,
5202 &dev_attr_lpfc_log_verbose,
5203 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005204 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005205 &dev_attr_lpfc_nodev_tmo,
5206 &dev_attr_lpfc_devloss_tmo,
5207 &dev_attr_lpfc_hba_queue_depth,
5208 &dev_attr_lpfc_peer_port_login,
5209 &dev_attr_lpfc_restrict_login,
5210 &dev_attr_lpfc_fcp_class,
5211 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005212 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005213 &dev_attr_lpfc_max_luns,
5214 &dev_attr_nport_evt_cnt,
5215 &dev_attr_npiv_info,
5216 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04005217 &dev_attr_lpfc_max_scsicmpl_time,
5218 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04005219 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04005220 &dev_attr_lpfc_fips_level,
5221 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04005222 NULL,
5223};
5224
James Smarte59058c2008-08-24 21:49:00 -04005225/**
James Smart3621a712009-04-06 18:47:14 -04005226 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005227 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005228 * @kobj: kernel kobject that contains the kernel class device.
5229 * @bin_attr: kernel attributes passed to us.
5230 * @buf: contains the data to be written to the adapter IOREG space.
5231 * @off: offset into buffer to beginning of data.
5232 * @count: bytes to transfer.
5233 *
5234 * Description:
5235 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5236 * Uses the adapter io control registers to send buf contents to the adapter.
5237 *
5238 * Returns:
5239 * -ERANGE off and count combo out of range
5240 * -EINVAL off, count or buff address invalid
5241 * -EPERM adapter is offline
5242 * value of count, buf contents written
5243 **/
dea31012005-04-17 16:05:31 -05005244static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005245sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5246 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005247 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005248{
5249 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01005250 struct device *dev = container_of(kobj, struct device, kobj);
5251 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005252 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5253 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005254
James Smartf1126682009-06-10 17:22:44 -04005255 if (phba->sli_rev >= LPFC_SLI_REV4)
5256 return -EPERM;
5257
dea31012005-04-17 16:05:31 -05005258 if ((off + count) > FF_REG_AREA_SIZE)
5259 return -ERANGE;
5260
James Smartf7a919b2011-08-21 21:49:16 -04005261 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5262 return 0;
dea31012005-04-17 16:05:31 -05005263
5264 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5265 return -EINVAL;
5266
James Smartf7a919b2011-08-21 21:49:16 -04005267 /* This is to protect HBA registers from accidental writes. */
5268 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5269 return -EINVAL;
5270
5271 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05005272 return -EPERM;
dea31012005-04-17 16:05:31 -05005273
James Smart2e0fef82007-06-17 19:56:36 -05005274 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04005275 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5276 buf_off += sizeof(uint32_t))
5277 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05005278 phba->ctrl_regs_memmap_p + off + buf_off);
5279
James Smart2e0fef82007-06-17 19:56:36 -05005280 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005281
5282 return count;
5283}
5284
James Smarte59058c2008-08-24 21:49:00 -04005285/**
James Smart3621a712009-04-06 18:47:14 -04005286 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005287 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005288 * @kobj: kernel kobject that contains the kernel class device.
5289 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005290 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04005291 * @off: offset into buffer to beginning of data.
5292 * @count: bytes to transfer.
5293 *
5294 * Description:
5295 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5296 * Uses the adapter io control registers to read data into buf.
5297 *
5298 * Returns:
5299 * -ERANGE off and count combo out of range
5300 * -EINVAL off, count or buff address invalid
5301 * value of count, buf contents read
5302 **/
dea31012005-04-17 16:05:31 -05005303static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005304sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5305 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005306 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005307{
5308 size_t buf_off;
5309 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01005310 struct device *dev = container_of(kobj, struct device, kobj);
5311 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005312 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5313 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005314
James Smartf1126682009-06-10 17:22:44 -04005315 if (phba->sli_rev >= LPFC_SLI_REV4)
5316 return -EPERM;
5317
dea31012005-04-17 16:05:31 -05005318 if (off > FF_REG_AREA_SIZE)
5319 return -ERANGE;
5320
5321 if ((off + count) > FF_REG_AREA_SIZE)
5322 count = FF_REG_AREA_SIZE - off;
5323
5324 if (count == 0) return 0;
5325
5326 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5327 return -EINVAL;
5328
James Smart2e0fef82007-06-17 19:56:36 -05005329 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005330
5331 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5332 tmp_ptr = (uint32_t *)(buf + buf_off);
5333 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5334 }
5335
James Smart2e0fef82007-06-17 19:56:36 -05005336 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005337
5338 return count;
5339}
5340
5341static struct bin_attribute sysfs_ctlreg_attr = {
5342 .attr = {
5343 .name = "ctlreg",
5344 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005345 },
5346 .size = 256,
5347 .read = sysfs_ctlreg_read,
5348 .write = sysfs_ctlreg_write,
5349};
5350
James Smarte59058c2008-08-24 21:49:00 -04005351/**
James Smart3621a712009-04-06 18:47:14 -04005352 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005353 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005354 * @kobj: kernel kobject that contains the kernel class device.
5355 * @bin_attr: kernel attributes passed to us.
5356 * @buf: contains the data to be written to sysfs mbox.
5357 * @off: offset into buffer to beginning of data.
5358 * @count: bytes to transfer.
5359 *
5360 * Description:
James Smart026abb82011-12-13 13:20:45 -05005361 * Deprecated function. All mailbox access from user space is performed via the
5362 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005363 *
5364 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005365 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005366 **/
dea31012005-04-17 16:05:31 -05005367static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005368sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5369 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005370 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005371{
James Smart026abb82011-12-13 13:20:45 -05005372 return -EPERM;
dea31012005-04-17 16:05:31 -05005373}
5374
James Smarte59058c2008-08-24 21:49:00 -04005375/**
James Smart3621a712009-04-06 18:47:14 -04005376 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005377 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005378 * @kobj: kernel kobject that contains the kernel class device.
5379 * @bin_attr: kernel attributes passed to us.
5380 * @buf: contains the data to be read from sysfs mbox.
5381 * @off: offset into buffer to beginning of data.
5382 * @count: bytes to transfer.
5383 *
5384 * Description:
James Smart026abb82011-12-13 13:20:45 -05005385 * Deprecated function. All mailbox access from user space is performed via the
5386 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005387 *
5388 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005389 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005390 **/
dea31012005-04-17 16:05:31 -05005391static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005392sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5393 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005394 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005395{
James Smart026abb82011-12-13 13:20:45 -05005396 return -EPERM;
dea31012005-04-17 16:05:31 -05005397}
5398
5399static struct bin_attribute sysfs_mbox_attr = {
5400 .attr = {
5401 .name = "mbox",
5402 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005403 },
James Smartc0c11512011-05-24 11:41:34 -04005404 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05005405 .read = sysfs_mbox_read,
5406 .write = sysfs_mbox_write,
5407};
5408
James Smarte59058c2008-08-24 21:49:00 -04005409/**
James Smart3621a712009-04-06 18:47:14 -04005410 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005411 * @vport: address of lpfc vport structure.
5412 *
5413 * Return codes:
5414 * zero on success
5415 * error return code from sysfs_create_bin_file()
5416 **/
dea31012005-04-17 16:05:31 -05005417int
James Smart2e0fef82007-06-17 19:56:36 -05005418lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005419{
James Smart2e0fef82007-06-17 19:56:36 -05005420 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005421 int error;
5422
Tony Jonesee959b02008-02-22 00:13:36 +01005423 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05005424 &sysfs_drvr_stat_data_attr);
5425
5426 /* Virtual ports do not need ctrl_reg and mbox */
5427 if (error || vport->port_type == LPFC_NPIV_PORT)
5428 goto out;
5429
5430 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005431 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005432 if (error)
James Smarteada2722008-12-04 22:39:13 -05005433 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05005434
Tony Jonesee959b02008-02-22 00:13:36 +01005435 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005436 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05005437 if (error)
5438 goto out_remove_ctlreg_attr;
5439
5440 return 0;
5441out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01005442 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05005443out_remove_stat_attr:
5444 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5445 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05005446out:
5447 return error;
5448}
5449
James Smarte59058c2008-08-24 21:49:00 -04005450/**
James Smart3621a712009-04-06 18:47:14 -04005451 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005452 * @vport: address of lpfc vport structure.
5453 **/
dea31012005-04-17 16:05:31 -05005454void
James Smart2e0fef82007-06-17 19:56:36 -05005455lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005456{
James Smart2e0fef82007-06-17 19:56:36 -05005457 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04005458 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5459 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05005460 /* Virtual ports do not need ctrl_reg and mbox */
5461 if (vport->port_type == LPFC_NPIV_PORT)
5462 return;
Tony Jonesee959b02008-02-22 00:13:36 +01005463 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5464 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005465}
5466
dea31012005-04-17 16:05:31 -05005467/*
5468 * Dynamic FC Host Attributes Support
5469 */
5470
James Smarte59058c2008-08-24 21:49:00 -04005471/**
James Smart6c9231f2016-12-19 15:07:24 -08005472 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5473 * @shost: kernel scsi host pointer.
5474 **/
5475static void
5476lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5477{
5478 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5479
5480 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5481 sizeof fc_host_symbolic_name(shost));
5482}
5483
5484/**
James Smart3621a712009-04-06 18:47:14 -04005485 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04005486 * @shost: kernel scsi host pointer.
5487 **/
dea31012005-04-17 16:05:31 -05005488static void
5489lpfc_get_host_port_id(struct Scsi_Host *shost)
5490{
James Smart2e0fef82007-06-17 19:56:36 -05005491 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5492
dea31012005-04-17 16:05:31 -05005493 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05005494 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005495}
5496
James Smarte59058c2008-08-24 21:49:00 -04005497/**
James Smart3621a712009-04-06 18:47:14 -04005498 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04005499 * @shost: kernel scsi host pointer.
5500 **/
dea31012005-04-17 16:05:31 -05005501static void
5502lpfc_get_host_port_type(struct Scsi_Host *shost)
5503{
James Smart2e0fef82007-06-17 19:56:36 -05005504 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5505 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005506
5507 spin_lock_irq(shost->host_lock);
5508
James Smart92d7f7b2007-06-17 19:56:38 -05005509 if (vport->port_type == LPFC_NPIV_PORT) {
5510 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5511 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05005512 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05005513 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05005514 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5515 else
5516 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5517 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005518 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05005519 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5520 else
5521 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5522 }
5523 } else
5524 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5525
5526 spin_unlock_irq(shost->host_lock);
5527}
5528
James Smarte59058c2008-08-24 21:49:00 -04005529/**
James Smart3621a712009-04-06 18:47:14 -04005530 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04005531 * @shost: kernel scsi host pointer.
5532 **/
dea31012005-04-17 16:05:31 -05005533static void
5534lpfc_get_host_port_state(struct Scsi_Host *shost)
5535{
James Smart2e0fef82007-06-17 19:56:36 -05005536 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5537 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005538
5539 spin_lock_irq(shost->host_lock);
5540
James Smart2e0fef82007-06-17 19:56:36 -05005541 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005542 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5543 else {
James Smart2e0fef82007-06-17 19:56:36 -05005544 switch (phba->link_state) {
5545 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05005546 case LPFC_LINK_DOWN:
5547 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5548 break;
5549 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05005550 case LPFC_CLEAR_LA:
5551 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05005552 /* Links up, reports port state accordingly */
5553 if (vport->port_state < LPFC_VPORT_READY)
5554 fc_host_port_state(shost) =
5555 FC_PORTSTATE_BYPASSED;
5556 else
5557 fc_host_port_state(shost) =
5558 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05005559 break;
5560 case LPFC_HBA_ERROR:
5561 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5562 break;
5563 default:
5564 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5565 break;
5566 }
5567 }
5568
5569 spin_unlock_irq(shost->host_lock);
5570}
5571
James Smarte59058c2008-08-24 21:49:00 -04005572/**
James Smart3621a712009-04-06 18:47:14 -04005573 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04005574 * @shost: kernel scsi host pointer.
5575 **/
dea31012005-04-17 16:05:31 -05005576static void
5577lpfc_get_host_speed(struct Scsi_Host *shost)
5578{
James Smart2e0fef82007-06-17 19:56:36 -05005579 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5580 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005581
5582 spin_lock_irq(shost->host_lock);
5583
James Smarta085e872015-12-16 18:12:02 -05005584 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea31012005-04-17 16:05:31 -05005585 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05005586 case LPFC_LINK_SPEED_1GHZ:
5587 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05005588 break;
James Smart76a95d72010-11-20 23:11:48 -05005589 case LPFC_LINK_SPEED_2GHZ:
5590 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05005591 break;
James Smart76a95d72010-11-20 23:11:48 -05005592 case LPFC_LINK_SPEED_4GHZ:
5593 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05005594 break;
James Smart76a95d72010-11-20 23:11:48 -05005595 case LPFC_LINK_SPEED_8GHZ:
5596 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04005597 break;
James Smart76a95d72010-11-20 23:11:48 -05005598 case LPFC_LINK_SPEED_10GHZ:
5599 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04005600 break;
James Smart76a95d72010-11-20 23:11:48 -05005601 case LPFC_LINK_SPEED_16GHZ:
5602 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5603 break;
James Smartd38dd522015-08-31 16:48:17 -04005604 case LPFC_LINK_SPEED_32GHZ:
5605 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5606 break;
James Smart76a95d72010-11-20 23:11:48 -05005607 default:
5608 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005609 break;
5610 }
James Smart09372822008-01-11 01:52:54 -05005611 } else
5612 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005613
5614 spin_unlock_irq(shost->host_lock);
5615}
5616
James Smarte59058c2008-08-24 21:49:00 -04005617/**
James Smart3621a712009-04-06 18:47:14 -04005618 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04005619 * @shost: kernel scsi host pointer.
5620 **/
dea31012005-04-17 16:05:31 -05005621static void
5622lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5623{
James Smart2e0fef82007-06-17 19:56:36 -05005624 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5625 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005626 u64 node_name;
dea31012005-04-17 16:05:31 -05005627
5628 spin_lock_irq(shost->host_lock);
5629
James Smart73d91e52011-10-10 21:32:10 -04005630 if ((vport->port_state > LPFC_FLOGI) &&
5631 ((vport->fc_flag & FC_FABRIC) ||
5632 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5633 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07005634 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05005635 else
5636 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05005637 node_name = 0;
dea31012005-04-17 16:05:31 -05005638
5639 spin_unlock_irq(shost->host_lock);
5640
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005641 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05005642}
5643
James Smarte59058c2008-08-24 21:49:00 -04005644/**
James Smart3621a712009-04-06 18:47:14 -04005645 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04005646 * @shost: kernel scsi host pointer.
5647 *
5648 * Notes:
5649 * NULL on error for link down, no mbox pool, sli2 active,
5650 * management not allowed, memory allocation error, or mbox error.
5651 *
5652 * Returns:
5653 * NULL for error
5654 * address of the adapter host statistics
5655 **/
dea31012005-04-17 16:05:31 -05005656static struct fc_host_statistics *
5657lpfc_get_stats(struct Scsi_Host *shost)
5658{
James Smart2e0fef82007-06-17 19:56:36 -05005659 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5660 struct lpfc_hba *phba = vport->phba;
5661 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005662 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04005663 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05005664 LPFC_MBOXQ_t *pmboxq;
5665 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04005666 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005667 int rc = 0;
dea31012005-04-17 16:05:31 -05005668
James Smart92d7f7b2007-06-17 19:56:38 -05005669 /*
5670 * prevent udev from issuing mailbox commands until the port is
5671 * configured.
5672 */
James Smart2e0fef82007-06-17 19:56:36 -05005673 if (phba->link_state < LPFC_LINK_DOWN ||
5674 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04005675 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05005676 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005677
5678 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005679 return NULL;
5680
dea31012005-04-17 16:05:31 -05005681 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5682 if (!pmboxq)
5683 return NULL;
5684 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5685
James Smart04c68492009-05-22 14:52:52 -04005686 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05005687 pmb->mbxCommand = MBX_READ_STATUS;
5688 pmb->mbxOwner = OWN_HOST;
5689 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005690 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005691
James Smart75baf692010-06-08 18:31:21 -04005692 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005693 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005694 else
dea31012005-04-17 16:05:31 -05005695 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5696
5697 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005698 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005699 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005700 return NULL;
5701 }
5702
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005703 memset(hs, 0, sizeof (struct fc_host_statistics));
5704
dea31012005-04-17 16:05:31 -05005705 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005706 /*
5707 * The MBX_READ_STATUS returns tx_k_bytes which has to
5708 * converted to words
5709 */
5710 hs->tx_words = (uint64_t)
5711 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5712 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005713 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005714 hs->rx_words = (uint64_t)
5715 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5716 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005717
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005718 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05005719 pmb->mbxCommand = MBX_READ_LNK_STAT;
5720 pmb->mbxOwner = OWN_HOST;
5721 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005722 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005723
James Smart75baf692010-06-08 18:31:21 -04005724 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005725 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005726 else
dea31012005-04-17 16:05:31 -05005727 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5728
5729 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005730 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005731 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005732 return NULL;
5733 }
5734
5735 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5736 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5737 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5738 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5739 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5740 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5741 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5742
James Smart64ba8812006-08-02 15:24:34 -04005743 hs->link_failure_count -= lso->link_failure_count;
5744 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5745 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5746 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5747 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5748 hs->invalid_crc_count -= lso->invalid_crc_count;
5749 hs->error_frames -= lso->error_frames;
5750
James Smart76a95d72010-11-20 23:11:48 -05005751 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04005752 hs->lip_count = -1;
5753 hs->nos_count = (phba->link_events >> 1);
5754 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05005755 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005756 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005757 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005758 hs->nos_count = -1;
5759 } else {
5760 hs->lip_count = -1;
5761 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005762 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005763 }
5764
5765 hs->dumped_frames = -1;
5766
James Smart64ba8812006-08-02 15:24:34 -04005767 seconds = get_seconds();
5768 if (seconds < psli->stats_start)
5769 hs->seconds_since_last_reset = seconds +
5770 ((unsigned long)-1 - psli->stats_start);
5771 else
5772 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05005773
James Smart1dcb58e2007-04-25 09:51:30 -04005774 mempool_free(pmboxq, phba->mbox_mem_pool);
5775
dea31012005-04-17 16:05:31 -05005776 return hs;
5777}
5778
James Smarte59058c2008-08-24 21:49:00 -04005779/**
James Smart3621a712009-04-06 18:47:14 -04005780 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04005781 * @shost: kernel scsi host pointer.
5782 **/
James Smart64ba8812006-08-02 15:24:34 -04005783static void
5784lpfc_reset_stats(struct Scsi_Host *shost)
5785{
James Smart2e0fef82007-06-17 19:56:36 -05005786 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5787 struct lpfc_hba *phba = vport->phba;
5788 struct lpfc_sli *psli = &phba->sli;
5789 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04005790 LPFC_MBOXQ_t *pmboxq;
5791 MAILBOX_t *pmb;
5792 int rc = 0;
5793
James Smart2e0fef82007-06-17 19:56:36 -05005794 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005795 return;
5796
James Smart64ba8812006-08-02 15:24:34 -04005797 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5798 if (!pmboxq)
5799 return;
5800 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5801
James Smart04c68492009-05-22 14:52:52 -04005802 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04005803 pmb->mbxCommand = MBX_READ_STATUS;
5804 pmb->mbxOwner = OWN_HOST;
5805 pmb->un.varWords[0] = 0x1; /* reset request */
5806 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005807 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005808
James Smart2e0fef82007-06-17 19:56:36 -05005809 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005810 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005811 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5812 else
5813 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5814
5815 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005816 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005817 mempool_free(pmboxq, phba->mbox_mem_pool);
5818 return;
5819 }
5820
5821 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5822 pmb->mbxCommand = MBX_READ_LNK_STAT;
5823 pmb->mbxOwner = OWN_HOST;
5824 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005825 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005826
James Smart2e0fef82007-06-17 19:56:36 -05005827 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005828 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005829 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5830 else
5831 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5832
5833 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005834 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005835 mempool_free( pmboxq, phba->mbox_mem_pool);
5836 return;
5837 }
5838
5839 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5840 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5841 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5842 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5843 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5844 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5845 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05005846 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04005847 lso->link_events = (phba->link_events >> 1);
5848 else
5849 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005850
5851 psli->stats_start = get_seconds();
5852
James Smart1dcb58e2007-04-25 09:51:30 -04005853 mempool_free(pmboxq, phba->mbox_mem_pool);
5854
James Smart64ba8812006-08-02 15:24:34 -04005855 return;
5856}
dea31012005-04-17 16:05:31 -05005857
5858/*
5859 * The LPFC driver treats linkdown handling as target loss events so there
5860 * are no sysfs handlers for link_down_tmo.
5861 */
James Smart685f0bf2007-04-25 09:53:08 -04005862
James Smarte59058c2008-08-24 21:49:00 -04005863/**
James Smart3621a712009-04-06 18:47:14 -04005864 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04005865 * @starget: kernel scsi target pointer.
5866 *
5867 * Returns:
5868 * address of the node list if found
5869 * NULL target not found
5870 **/
James Smart685f0bf2007-04-25 09:53:08 -04005871static struct lpfc_nodelist *
5872lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05005873{
James Smart2e0fef82007-06-17 19:56:36 -05005874 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5875 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04005876 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005877
5878 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005879 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05005880 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005881 if (NLP_CHK_NODE_ACT(ndlp) &&
5882 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04005883 starget->id == ndlp->nlp_sid) {
5884 spin_unlock_irq(shost->host_lock);
5885 return ndlp;
dea31012005-04-17 16:05:31 -05005886 }
5887 }
5888 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005889 return NULL;
5890}
dea31012005-04-17 16:05:31 -05005891
James Smarte59058c2008-08-24 21:49:00 -04005892/**
James Smart3621a712009-04-06 18:47:14 -04005893 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04005894 * @starget: kernel scsi target pointer.
5895 **/
James Smart685f0bf2007-04-25 09:53:08 -04005896static void
5897lpfc_get_starget_port_id(struct scsi_target *starget)
5898{
5899 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5900
5901 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05005902}
5903
James Smarte59058c2008-08-24 21:49:00 -04005904/**
James Smart3621a712009-04-06 18:47:14 -04005905 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04005906 * @starget: kernel scsi target pointer.
5907 *
5908 * Description: Set the target node name to the ndlp node name wwn or zero.
5909 **/
dea31012005-04-17 16:05:31 -05005910static void
5911lpfc_get_starget_node_name(struct scsi_target *starget)
5912{
James Smart685f0bf2007-04-25 09:53:08 -04005913 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005914
James Smart685f0bf2007-04-25 09:53:08 -04005915 fc_starget_node_name(starget) =
5916 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005917}
5918
James Smarte59058c2008-08-24 21:49:00 -04005919/**
James Smart3621a712009-04-06 18:47:14 -04005920 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04005921 * @starget: kernel scsi target pointer.
5922 *
5923 * Description: set the target port name to the ndlp port name wwn or zero.
5924 **/
dea31012005-04-17 16:05:31 -05005925static void
5926lpfc_get_starget_port_name(struct scsi_target *starget)
5927{
James Smart685f0bf2007-04-25 09:53:08 -04005928 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005929
James Smart685f0bf2007-04-25 09:53:08 -04005930 fc_starget_port_name(starget) =
5931 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005932}
5933
James Smarte59058c2008-08-24 21:49:00 -04005934/**
James Smart3621a712009-04-06 18:47:14 -04005935 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04005936 * @rport: fc rport address.
5937 * @timeout: new value for dev loss tmo.
5938 *
5939 * Description:
5940 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5941 * dev_loss_tmo to one.
5942 **/
dea31012005-04-17 16:05:31 -05005943static void
dea31012005-04-17 16:05:31 -05005944lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5945{
dea31012005-04-17 16:05:31 -05005946 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04005947 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05005948 else
James Smartc01f3202006-08-18 17:47:08 -04005949 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05005950}
5951
James Smarte59058c2008-08-24 21:49:00 -04005952/**
James Smart3621a712009-04-06 18:47:14 -04005953 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04005954 *
5955 * Description:
5956 * Macro that uses field to generate a function with the name lpfc_show_rport_
5957 *
5958 * lpfc_show_rport_##field: returns the bytes formatted in buf
5959 * @cdev: class converted to an fc_rport.
5960 * @buf: on return contains the target_field or zero.
5961 *
5962 * Returns: size of formatted string.
5963 **/
dea31012005-04-17 16:05:31 -05005964#define lpfc_rport_show_function(field, format_string, sz, cast) \
5965static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01005966lpfc_show_rport_##field (struct device *dev, \
5967 struct device_attribute *attr, \
5968 char *buf) \
dea31012005-04-17 16:05:31 -05005969{ \
Tony Jonesee959b02008-02-22 00:13:36 +01005970 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05005971 struct lpfc_rport_data *rdata = rport->hostdata; \
5972 return snprintf(buf, sz, format_string, \
5973 (rdata->target) ? cast rdata->target->field : 0); \
5974}
5975
5976#define lpfc_rport_rd_attr(field, format_string, sz) \
5977 lpfc_rport_show_function(field, format_string, sz, ) \
5978static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5979
James Smarteada2722008-12-04 22:39:13 -05005980/**
James Smart3621a712009-04-06 18:47:14 -04005981 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05005982 * @fc_vport: The fc_vport who's symbolic name has been changed.
5983 *
5984 * Description:
5985 * This function is called by the transport after the @fc_vport's symbolic name
5986 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005987 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05005988 **/
5989static void
5990lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5991{
5992 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5993
5994 if (vport->port_state == LPFC_VPORT_READY)
5995 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5996}
dea31012005-04-17 16:05:31 -05005997
James Smartf4b4c682009-05-22 14:53:12 -04005998/**
5999 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6000 * @phba: Pointer to lpfc_hba struct.
6001 *
6002 * This function is called by the lpfc_get_cfgparam() routine to set the
6003 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02006004 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04006005 * before hba port or vport created.
6006 **/
6007static void
6008lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6009{
6010 phba->cfg_log_verbose = verbose;
6011}
6012
dea31012005-04-17 16:05:31 -05006013struct fc_function_template lpfc_transport_functions = {
6014 /* fixed attributes the driver supports */
6015 .show_host_node_name = 1,
6016 .show_host_port_name = 1,
6017 .show_host_supported_classes = 1,
6018 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05006019 .show_host_supported_speeds = 1,
6020 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006021
6022 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006023 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05006024
6025 /* dynamic attributes the driver supports */
6026 .get_host_port_id = lpfc_get_host_port_id,
6027 .show_host_port_id = 1,
6028
6029 .get_host_port_type = lpfc_get_host_port_type,
6030 .show_host_port_type = 1,
6031
6032 .get_host_port_state = lpfc_get_host_port_state,
6033 .show_host_port_state = 1,
6034
6035 /* active_fc4s is shown but doesn't change (thus no get function) */
6036 .show_host_active_fc4s = 1,
6037
6038 .get_host_speed = lpfc_get_host_speed,
6039 .show_host_speed = 1,
6040
6041 .get_host_fabric_name = lpfc_get_host_fabric_name,
6042 .show_host_fabric_name = 1,
6043
6044 /*
6045 * The LPFC driver treats linkdown handling as target loss events
6046 * so there are no sysfs handlers for link_down_tmo.
6047 */
6048
6049 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04006050 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05006051
6052 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6053 .show_rport_maxframe_size = 1,
6054 .show_rport_supported_classes = 1,
6055
dea31012005-04-17 16:05:31 -05006056 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6057 .show_rport_dev_loss_tmo = 1,
6058
6059 .get_starget_port_id = lpfc_get_starget_port_id,
6060 .show_starget_port_id = 1,
6061
6062 .get_starget_node_name = lpfc_get_starget_node_name,
6063 .show_starget_node_name = 1,
6064
6065 .get_starget_port_name = lpfc_get_starget_port_name,
6066 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07006067
6068 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04006069 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6070 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05006071
James Smart92d7f7b2007-06-17 19:56:38 -05006072 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05006073
6074 .vport_disable = lpfc_vport_disable,
6075
6076 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04006077
6078 .bsg_request = lpfc_bsg_request,
6079 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05006080};
6081
James Smart98c9ea52007-10-27 13:37:33 -04006082struct fc_function_template lpfc_vport_transport_functions = {
6083 /* fixed attributes the driver supports */
6084 .show_host_node_name = 1,
6085 .show_host_port_name = 1,
6086 .show_host_supported_classes = 1,
6087 .show_host_supported_fc4s = 1,
6088 .show_host_supported_speeds = 1,
6089 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006090
6091 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006092 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04006093
6094 /* dynamic attributes the driver supports */
6095 .get_host_port_id = lpfc_get_host_port_id,
6096 .show_host_port_id = 1,
6097
6098 .get_host_port_type = lpfc_get_host_port_type,
6099 .show_host_port_type = 1,
6100
6101 .get_host_port_state = lpfc_get_host_port_state,
6102 .show_host_port_state = 1,
6103
6104 /* active_fc4s is shown but doesn't change (thus no get function) */
6105 .show_host_active_fc4s = 1,
6106
6107 .get_host_speed = lpfc_get_host_speed,
6108 .show_host_speed = 1,
6109
6110 .get_host_fabric_name = lpfc_get_host_fabric_name,
6111 .show_host_fabric_name = 1,
6112
6113 /*
6114 * The LPFC driver treats linkdown handling as target loss events
6115 * so there are no sysfs handlers for link_down_tmo.
6116 */
6117
6118 .get_fc_host_stats = lpfc_get_stats,
6119 .reset_fc_host_stats = lpfc_reset_stats,
6120
6121 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6122 .show_rport_maxframe_size = 1,
6123 .show_rport_supported_classes = 1,
6124
6125 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6126 .show_rport_dev_loss_tmo = 1,
6127
6128 .get_starget_port_id = lpfc_get_starget_port_id,
6129 .show_starget_port_id = 1,
6130
6131 .get_starget_node_name = lpfc_get_starget_node_name,
6132 .show_starget_node_name = 1,
6133
6134 .get_starget_port_name = lpfc_get_starget_port_name,
6135 .show_starget_port_name = 1,
6136
6137 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6138 .terminate_rport_io = lpfc_terminate_rport_io,
6139
6140 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05006141
6142 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04006143};
6144
James Smarte59058c2008-08-24 21:49:00 -04006145/**
James Smart3621a712009-04-06 18:47:14 -04006146 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04006147 * @phba: lpfc_hba pointer.
6148 **/
dea31012005-04-17 16:05:31 -05006149void
6150lpfc_get_cfgparam(struct lpfc_hba *phba)
6151{
James Smart49aa1432012-08-03 12:36:42 -04006152 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04006153 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb7522005-10-28 20:29:13 -04006154 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6155 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05006156 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05006157 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6158 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb7522005-10-28 20:29:13 -04006159 lpfc_ack0_init(phba, lpfc_ack0);
6160 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb7522005-10-28 20:29:13 -04006161 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05006162 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04006163 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04006164 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04006165 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05006166 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4258e982015-12-16 18:11:58 -05006167 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6168 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
James Smart4ff43242006-12-02 13:34:56 -05006169 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart895427b2017-02-12 13:52:30 -08006170 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
James Smartda0436e2009-05-22 14:51:39 -04006171 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04006172 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart13815c82008-01-11 01:52:48 -05006173 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6174 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart2ea259e2017-02-12 13:52:27 -08006175
James Smart1ba981f2014-02-20 09:56:45 -05006176 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6177 if (phba->sli_rev != LPFC_SLI_REV4)
6178 phba->cfg_EnableXLane = 0;
6179 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
James Smart2ea259e2017-02-12 13:52:27 -08006180
James Smart1ba981f2014-02-20 09:56:45 -05006181 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6182 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6183 phba->cfg_oas_lun_state = 0;
6184 phba->cfg_oas_lun_status = 0;
6185 phba->cfg_oas_flags = 0;
James Smartc92c8412016-07-06 12:36:05 -07006186 phba->cfg_oas_priority = 0;
James Smart81301a92008-12-04 22:39:46 -05006187 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smartb3b98b72016-10-13 15:06:06 -07006188 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6189 lpfc_prot_guard_init(phba, lpfc_prot_guard);
James Smart45ed1192009-10-02 15:17:02 -04006190 if (phba->sli_rev == LPFC_SLI_REV4)
6191 phba->cfg_poll = 0;
6192 else
James Smart1ba981f2014-02-20 09:56:45 -05006193 phba->cfg_poll = lpfc_poll;
James Smartf358dd02017-02-12 13:52:34 -08006194 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
James Smart4258e982015-12-16 18:11:58 -05006195
James Smart895427b2017-02-12 13:52:30 -08006196 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
James Smart2d7dbc42017-02-12 13:52:35 -08006197 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
James Smart895427b2017-02-12 13:52:30 -08006198
6199 /* Initialize first burst. Target vs Initiator are different. */
6200 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
James Smart2d7dbc42017-02-12 13:52:35 -08006201 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
James Smart895427b2017-02-12 13:52:30 -08006202 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6203 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
6204
6205 if (phba->sli_rev != LPFC_SLI_REV4) {
6206 /* NVME only supported on SLI4 */
6207 phba->nvmet_support = 0;
6208 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
6209 } else {
6210 /* We MUST have FCP support */
6211 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6212 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6213 }
6214
6215 /* A value of 0 means use the number of CPUs found in the system */
James Smart895427b2017-02-12 13:52:30 -08006216 if (phba->cfg_fcp_io_channel == 0)
6217 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006218 if (phba->cfg_nvme_io_channel == 0)
6219 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smart895427b2017-02-12 13:52:30 -08006220
6221 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6222 phba->cfg_fcp_io_channel = 0;
6223
James Smartf358dd02017-02-12 13:52:34 -08006224 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6225 phba->cfg_nvme_io_channel = 0;
6226
James Smart895427b2017-02-12 13:52:30 -08006227 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6228 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6229 else
6230 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
James Smart4258e982015-12-16 18:11:58 -05006231
James Smart352e5fd2016-12-30 06:57:47 -08006232 phba->cfg_soft_wwnn = 0L;
6233 phba->cfg_soft_wwpn = 0L;
James Smart895427b2017-02-12 13:52:30 -08006234 lpfc_xri_split_init(phba, lpfc_xri_split);
James Smart83108bd2008-01-11 01:53:09 -05006235 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04006236 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04006237 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04006238 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04006239 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04006240 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05006241 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04006242 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart8eb8b962016-07-06 12:36:08 -07006243 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
James Smart12247e82016-07-06 12:36:09 -07006244 lpfc_sli_mode_init(phba, lpfc_sli_mode);
James Smartab56dc22011-02-16 12:39:57 -05006245 phba->cfg_enable_dss = 1;
James Smart7bdedb32016-07-06 12:36:00 -07006246 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
James Smart3de2a652007-08-02 11:09:59 -04006247 return;
6248}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05006249
James Smarte59058c2008-08-24 21:49:00 -04006250/**
James Smart895427b2017-02-12 13:52:30 -08006251 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6252 * dependencies between protocols and roles.
6253 * @phba: lpfc_hba pointer.
6254 **/
6255void
6256lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6257{
James Smart895427b2017-02-12 13:52:30 -08006258 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6259 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006260
James Smart895427b2017-02-12 13:52:30 -08006261 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6262 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6263
James Smartf358dd02017-02-12 13:52:34 -08006264 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6265 phba->nvmet_support) {
6266 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6267 phba->cfg_fcp_io_channel = 0;
James Smart2d7dbc42017-02-12 13:52:35 -08006268
6269 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6270 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6271 "NVME Target PRLI ACC enable_fb ",
6272 phba->cfg_nvme_enable_fb,
6273 phba->cfg_nvmet_fb_size,
6274 LPFC_NVMET_FB_SZ_MAX);
6275
6276 if (phba->cfg_nvme_enable_fb == 0)
6277 phba->cfg_nvmet_fb_size = 0;
6278 else {
6279 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6280 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6281 }
6282
6283 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6284 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6285 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6286 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6287 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6288 phba->cfg_nvmet_mrq);
6289 }
6290 } else {
James Smartf358dd02017-02-12 13:52:34 -08006291 /* Not NVME Target mode. Turn off Target parameters. */
6292 phba->nvmet_support = 0;
James Smart2d7dbc42017-02-12 13:52:35 -08006293 phba->cfg_nvmet_mrq = 0;
James Smart2d7dbc42017-02-12 13:52:35 -08006294 phba->cfg_nvmet_fb_size = 0;
6295 }
James Smartf358dd02017-02-12 13:52:34 -08006296
James Smart895427b2017-02-12 13:52:30 -08006297 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6298 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6299 else
6300 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6301}
6302
6303/**
James Smart3621a712009-04-06 18:47:14 -04006304 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04006305 * @vport: lpfc_vport pointer.
6306 **/
James Smart3de2a652007-08-02 11:09:59 -04006307void
6308lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6309{
James Smarte8b62012007-08-02 11:10:09 -04006310 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04006311 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04006312 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04006313 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6314 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6315 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6316 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6317 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6318 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04006319 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04006320 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04006321 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6322 lpfc_max_luns_init(vport, lpfc_max_luns);
6323 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04006324 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05006325 return;
6326}