blob: b741dcb8ee64abf6b1eb3e48a4c4e6633f6e015e [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd080abe2017-02-12 13:52:39 -08004 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -050010 * *
11 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
dea31012005-04-17 16:05:31 -050022 *******************************************************************/
23
dea31012005-04-17 16:05:31 -050024#include <linux/ctype.h>
James Smart46fa3112007-04-25 09:51:45 -040025#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050026#include <linux/pci.h>
27#include <linux/interrupt.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040028#include <linux/module.h>
James Smart0d878412009-10-02 15:16:56 -040029#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/gfp.h>
Andy Shevchenkoecc30992010-08-10 18:01:27 -070031#include <linux/kernel.h>
dea31012005-04-17 16:05:31 -050032
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040033#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050034#include <scsi/scsi_device.h>
35#include <scsi/scsi_host.h>
36#include <scsi/scsi_tcq.h>
37#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040038#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050039
James Smart895427b2017-02-12 13:52:30 -080040#include <linux/nvme-fc-driver.h>
41
James Smartda0436e2009-05-22 14:51:39 -040042#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050043#include "lpfc_hw.h"
44#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040045#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040046#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050047#include "lpfc_disc.h"
dea31012005-04-17 16:05:31 -050048#include "lpfc.h"
James Smart895427b2017-02-12 13:52:30 -080049#include "lpfc_scsi.h"
50#include "lpfc_nvme.h"
James Smartf358dd02017-02-12 13:52:34 -080051#include "lpfc_nvmet.h"
dea31012005-04-17 16:05:31 -050052#include "lpfc_logmsg.h"
53#include "lpfc_version.h"
54#include "lpfc_compat.h"
55#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050056#include "lpfc_vport.h"
James Smart93dd1912016-07-06 12:36:10 -070057#include "lpfc_attr.h"
dea31012005-04-17 16:05:31 -050058
James Smart2ea259e2017-02-12 13:52:27 -080059#define LPFC_DEF_DEVLOSS_TMO 30
60#define LPFC_MIN_DEVLOSS_TMO 1
61#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050062
James Smart2d7dbc42017-02-12 13:52:35 -080063#define LPFC_DEF_MRQ_POST 256
64#define LPFC_MIN_MRQ_POST 32
65#define LPFC_MAX_MRQ_POST 512
66
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
184 len += snprintf(buf + len, PAGE_SIZE,
185 "\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,
208 "FCP: Rcv %08x Drop %08x\n",
209 atomic_read(&tgtp->rcv_fcp_cmd_in),
210 atomic_read(&tgtp->rcv_fcp_cmd_drop));
211
212 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
213 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
214 len += snprintf(buf+len, PAGE_SIZE-len,
215 "Rcv FCP: in %08x != out %08x\n",
216 atomic_read(&tgtp->rcv_fcp_cmd_in),
217 atomic_read(&tgtp->rcv_fcp_cmd_out));
218 }
219
220 len += snprintf(buf+len, PAGE_SIZE-len,
221 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x\n",
222 atomic_read(&tgtp->xmt_fcp_read),
223 atomic_read(&tgtp->xmt_fcp_read_rsp),
224 atomic_read(&tgtp->xmt_fcp_write),
225 atomic_read(&tgtp->xmt_fcp_rsp));
226
227 len += snprintf(buf+len, PAGE_SIZE-len,
228 "FCP Rsp: abort %08x drop %08x\n",
229 atomic_read(&tgtp->xmt_fcp_abort),
230 atomic_read(&tgtp->xmt_fcp_drop));
231
232 len += snprintf(buf+len, PAGE_SIZE-len,
233 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
234 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
235 atomic_read(&tgtp->xmt_fcp_rsp_error),
236 atomic_read(&tgtp->xmt_fcp_rsp_drop));
237
238 len += snprintf(buf+len, PAGE_SIZE-len,
239 "ABORT: Xmt %08x Err %08x Cmpl %08x",
240 atomic_read(&tgtp->xmt_abort_rsp),
241 atomic_read(&tgtp->xmt_abort_rsp_error),
242 atomic_read(&tgtp->xmt_abort_cmpl));
243
244 len += snprintf(buf+len, PAGE_SIZE-len, "\n");
245 return len;
246 }
James Smart895427b2017-02-12 13:52:30 -0800247
248 localport = vport->localport;
249 if (!localport) {
250 len = snprintf(buf, PAGE_SIZE,
251 "NVME Initiator x%llx is not allocated\n",
252 wwn_to_u64(vport->fc_portname.u.wwn));
253 return len;
254 }
255 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
256
257 spin_lock_irq(shost->host_lock);
258 lport = (struct lpfc_nvme_lport *)localport->private;
259
260 /* Port state is only one of two values for now. */
261 if (localport->port_id)
262 statep = "ONLINE";
263 else
264 statep = "UNKNOWN ";
265
266 len += snprintf(buf + len, PAGE_SIZE - len,
267 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
268 "NVME LPORT lpfc",
269 phba->brd_no,
270 wwn_to_u64(vport->fc_portname.u.wwn),
271 wwn_to_u64(vport->fc_nodename.u.wwn),
272 localport->port_id, statep);
273
274 list_for_each_entry(rport, &lport->rport_list, list) {
275 /* local short-hand pointer. */
276 nrport = rport->remoteport;
277
278 /* Port state is only one of two values for now. */
279 switch (nrport->port_state) {
280 case FC_OBJSTATE_ONLINE:
281 statep = "ONLINE";
282 break;
283 case FC_OBJSTATE_UNKNOWN:
284 statep = "UNKNOWN ";
285 break;
286 default:
287 statep = "UNSUPPORTED";
288 break;
289 }
290
291 /* Tab in to show lport ownership. */
292 len += snprintf(buf + len, PAGE_SIZE - len,
293 "NVME RPORT ");
294 if (phba->brd_no >= 10)
295 len += snprintf(buf + len, PAGE_SIZE - len, " ");
296
297 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ",
298 nrport->port_name);
299 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ",
300 nrport->node_name);
301 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ",
302 nrport->port_id);
303
304 switch (nrport->port_role) {
305 case FC_PORT_ROLE_NVME_INITIATOR:
306 len += snprintf(buf + len, PAGE_SIZE - len,
307 "INITIATOR ");
308 break;
309 case FC_PORT_ROLE_NVME_TARGET:
310 len += snprintf(buf + len, PAGE_SIZE - len,
311 "TARGET ");
312 break;
313 case FC_PORT_ROLE_NVME_DISCOVERY:
314 len += snprintf(buf + len, PAGE_SIZE - len,
315 "DISCOVERY ");
316 break;
317 default:
318 len += snprintf(buf + len, PAGE_SIZE - len,
319 "UNKNOWN_ROLE x%x",
320 nrport->port_role);
321 break;
322 }
323 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep);
324 /* Terminate the string. */
325 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
326 }
327 spin_unlock_irq(shost->host_lock);
328
329 len += snprintf(buf + len, PAGE_SIZE, "\nNVME Statistics\n");
330 len += snprintf(buf+len, PAGE_SIZE-len,
331 "LS: Xmt %016llx Cmpl %016llx\n",
332 phba->fc4NvmeLsRequests,
333 phba->fc4NvmeLsCmpls);
334
335 len += snprintf(buf+len, PAGE_SIZE-len,
336 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
337 phba->fc4NvmeInputRequests,
338 phba->fc4NvmeOutputRequests,
339 phba->fc4NvmeControlRequests);
340
341 len += snprintf(buf+len, PAGE_SIZE-len,
342 " Cmpl %016llx\n", phba->fc4NvmeIoCmpls);
343
344 return len;
345}
346
347static ssize_t
James Smart81301a92008-12-04 22:39:46 -0500348lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
349 char *buf)
350{
351 struct Scsi_Host *shost = class_to_shost(dev);
352 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
353 struct lpfc_hba *phba = vport->phba;
354
355 if (phba->cfg_enable_bg)
356 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
357 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
358 else
359 return snprintf(buf, PAGE_SIZE,
360 "BlockGuard Not Supported\n");
361 else
362 return snprintf(buf, PAGE_SIZE,
363 "BlockGuard Disabled\n");
364}
365
366static ssize_t
367lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
368 char *buf)
369{
370 struct Scsi_Host *shost = class_to_shost(dev);
371 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
372 struct lpfc_hba *phba = vport->phba;
373
James Smart87b5c322008-12-16 10:34:09 -0500374 return snprintf(buf, PAGE_SIZE, "%llu\n",
375 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500376}
377
378static ssize_t
379lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
380 char *buf)
381{
382 struct Scsi_Host *shost = class_to_shost(dev);
383 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
384 struct lpfc_hba *phba = vport->phba;
385
James Smart87b5c322008-12-16 10:34:09 -0500386 return snprintf(buf, PAGE_SIZE, "%llu\n",
387 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500388}
389
390static ssize_t
391lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
392 char *buf)
393{
394 struct Scsi_Host *shost = class_to_shost(dev);
395 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
396 struct lpfc_hba *phba = vport->phba;
397
James Smart87b5c322008-12-16 10:34:09 -0500398 return snprintf(buf, PAGE_SIZE, "%llu\n",
399 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500400}
401
James Smarte59058c2008-08-24 21:49:00 -0400402/**
James Smart3621a712009-04-06 18:47:14 -0400403 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400404 * @dev: class converted to a Scsi_host structure.
405 * @attr: device attribute, not used.
406 * @buf: on return contains the formatted text from lpfc_info().
407 *
408 * Returns: size of formatted string.
409 **/
dea31012005-04-17 16:05:31 -0500410static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100411lpfc_info_show(struct device *dev, struct device_attribute *attr,
412 char *buf)
dea31012005-04-17 16:05:31 -0500413{
Tony Jonesee959b02008-02-22 00:13:36 +0100414 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500415
dea31012005-04-17 16:05:31 -0500416 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
417}
418
James Smarte59058c2008-08-24 21:49:00 -0400419/**
James Smart3621a712009-04-06 18:47:14 -0400420 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400421 * @dev: class converted to a Scsi_host structure.
422 * @attr: device attribute, not used.
423 * @buf: on return contains the formatted text serial number.
424 *
425 * Returns: size of formatted string.
426 **/
dea31012005-04-17 16:05:31 -0500427static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100428lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
429 char *buf)
dea31012005-04-17 16:05:31 -0500430{
Tony Jonesee959b02008-02-22 00:13:36 +0100431 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500432 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
433 struct lpfc_hba *phba = vport->phba;
434
dea31012005-04-17 16:05:31 -0500435 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
436}
437
James Smarte59058c2008-08-24 21:49:00 -0400438/**
James Smart3621a712009-04-06 18:47:14 -0400439 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400440 * @dev: class converted to a Scsi_host structure.
441 * @attr: device attribute, not used.
442 * @buf: on return contains the formatted support level.
443 *
444 * Description:
445 * Returns a number indicating the temperature sensor level currently
446 * supported, zero or one in ascii.
447 *
448 * Returns: size of formatted string.
449 **/
dea31012005-04-17 16:05:31 -0500450static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100451lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
452 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400453{
Tony Jonesee959b02008-02-22 00:13:36 +0100454 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400455 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
456 struct lpfc_hba *phba = vport->phba;
457 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
458}
459
James Smarte59058c2008-08-24 21:49:00 -0400460/**
James Smart3621a712009-04-06 18:47:14 -0400461 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400462 * @dev: class converted to a Scsi_host structure.
463 * @attr: device attribute, not used.
464 * @buf: on return contains the scsi vpd model description.
465 *
466 * Returns: size of formatted string.
467 **/
James Smart57127f12007-10-27 13:37:05 -0400468static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100469lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
470 char *buf)
dea31012005-04-17 16:05:31 -0500471{
Tony Jonesee959b02008-02-22 00:13:36 +0100472 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500473 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
474 struct lpfc_hba *phba = vport->phba;
475
dea31012005-04-17 16:05:31 -0500476 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
477}
478
James Smarte59058c2008-08-24 21:49:00 -0400479/**
James Smart3621a712009-04-06 18:47:14 -0400480 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400481 * @dev: class converted to a Scsi_host structure.
482 * @attr: device attribute, not used.
483 * @buf: on return contains the scsi vpd model name.
484 *
485 * Returns: size of formatted string.
486 **/
dea31012005-04-17 16:05:31 -0500487static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100488lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
489 char *buf)
dea31012005-04-17 16:05:31 -0500490{
Tony Jonesee959b02008-02-22 00:13:36 +0100491 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500492 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
493 struct lpfc_hba *phba = vport->phba;
494
dea31012005-04-17 16:05:31 -0500495 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
496}
497
James Smarte59058c2008-08-24 21:49:00 -0400498/**
James Smart3621a712009-04-06 18:47:14 -0400499 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400500 * @dev: class converted to a Scsi_host structure.
501 * @attr: device attribute, not used.
502 * @buf: on return contains the scsi vpd program type.
503 *
504 * Returns: size of formatted string.
505 **/
dea31012005-04-17 16:05:31 -0500506static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100507lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
508 char *buf)
dea31012005-04-17 16:05:31 -0500509{
Tony Jonesee959b02008-02-22 00:13:36 +0100510 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500511 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
512 struct lpfc_hba *phba = vport->phba;
513
dea31012005-04-17 16:05:31 -0500514 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
515}
516
James Smarte59058c2008-08-24 21:49:00 -0400517/**
James Smart3621a712009-04-06 18:47:14 -0400518 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400519 * @dev: class converted to a Scsi_host structure.
520 * @attr: device attribute, not used.
521 * @buf: on return contains the Menlo Maintenance sli flag.
522 *
523 * Returns: size of formatted string.
524 **/
525static ssize_t
526lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
527{
528 struct Scsi_Host *shost = class_to_shost(dev);
529 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
530 struct lpfc_hba *phba = vport->phba;
531
532 return snprintf(buf, PAGE_SIZE, "%d\n",
533 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
534}
535
536/**
James Smart3621a712009-04-06 18:47:14 -0400537 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400538 * @dev: class converted to a Scsi_host structure.
539 * @attr: device attribute, not used.
540 * @buf: on return contains scsi vpd program type.
541 *
542 * Returns: size of formatted string.
543 **/
dea31012005-04-17 16:05:31 -0500544static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100545lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
546 char *buf)
dea31012005-04-17 16:05:31 -0500547{
Tony Jonesee959b02008-02-22 00:13:36 +0100548 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500549 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
550 struct lpfc_hba *phba = vport->phba;
551
dea31012005-04-17 16:05:31 -0500552 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
553}
554
James Smarte59058c2008-08-24 21:49:00 -0400555/**
James Smart3621a712009-04-06 18:47:14 -0400556 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400557 * @dev: class converted to a Scsi_host structure.
558 * @attr: device attribute, not used.
559 * @buf: on return contains the scsi vpd program type.
560 *
561 * Returns: size of formatted string.
562 **/
dea31012005-04-17 16:05:31 -0500563static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100564lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
565 char *buf)
dea31012005-04-17 16:05:31 -0500566{
Tony Jonesee959b02008-02-22 00:13:36 +0100567 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500568 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
569 struct lpfc_hba *phba = vport->phba;
James Smart026abb82011-12-13 13:20:45 -0500570 uint32_t if_type;
571 uint8_t sli_family;
James Smart6b5151f2012-01-18 16:24:06 -0500572 char fwrev[FW_REV_STR_SIZE];
James Smart026abb82011-12-13 13:20:45 -0500573 int len;
James Smart2e0fef82007-06-17 19:56:36 -0500574
dea31012005-04-17 16:05:31 -0500575 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart026abb82011-12-13 13:20:45 -0500576 if_type = phba->sli4_hba.pc_sli4_params.if_type;
577 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
578
579 if (phba->sli_rev < LPFC_SLI_REV4)
580 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
581 fwrev, phba->sli_rev);
582 else
583 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
584 fwrev, phba->sli_rev, if_type, sli_family);
585
586 return len;
dea31012005-04-17 16:05:31 -0500587}
588
James Smarte59058c2008-08-24 21:49:00 -0400589/**
James Smart3621a712009-04-06 18:47:14 -0400590 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400591 * @dev: class converted to a Scsi_host structure.
592 * @attr: device attribute, not used.
593 * @buf: on return contains the scsi vpd program type.
594 *
595 * Returns: size of formatted string.
596 **/
dea31012005-04-17 16:05:31 -0500597static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100598lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500599{
600 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100601 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500602 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
603 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500604 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500605
dea31012005-04-17 16:05:31 -0500606 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
607 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
608}
James Smarte59058c2008-08-24 21:49:00 -0400609
610/**
James Smart3621a712009-04-06 18:47:14 -0400611 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400612 * @dev: class converted to a Scsi_host structure.
613 * @attr: device attribute, not used.
614 * @buf: on return contains the ROM and FCode ascii strings.
615 *
616 * Returns: size of formatted string.
617 **/
dea31012005-04-17 16:05:31 -0500618static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100619lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
620 char *buf)
dea31012005-04-17 16:05:31 -0500621{
Tony Jonesee959b02008-02-22 00:13:36 +0100622 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500623 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
624 struct lpfc_hba *phba = vport->phba;
James Smarta0683bf2015-04-07 15:07:16 -0400625 char fwrev[FW_REV_STR_SIZE];
James Smart2e0fef82007-06-17 19:56:36 -0500626
James Smarta0683bf2015-04-07 15:07:16 -0400627 if (phba->sli_rev < LPFC_SLI_REV4)
628 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
629
630 lpfc_decode_firmware_rev(phba, fwrev, 1);
631 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
dea31012005-04-17 16:05:31 -0500632}
James Smarte59058c2008-08-24 21:49:00 -0400633
634/**
James Smart3621a712009-04-06 18:47:14 -0400635 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400636 * @dev: class converted to a Scsi_host structure.
637 * @attr: device attribute, not used.
638 * @buf: on return contains text describing the state of the link.
639 *
640 * Notes:
641 * The switch statement has no default so zero will be returned.
642 *
643 * Returns: size of formatted string.
644 **/
dea31012005-04-17 16:05:31 -0500645static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100646lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
647 char *buf)
dea31012005-04-17 16:05:31 -0500648{
Tony Jonesee959b02008-02-22 00:13:36 +0100649 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500650 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
651 struct lpfc_hba *phba = vport->phba;
652 int len = 0;
653
654 switch (phba->link_state) {
655 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500656 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500657 case LPFC_INIT_START:
658 case LPFC_INIT_MBX_CMDS:
659 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500660 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400661 if (phba->hba_flag & LINK_DISABLED)
662 len += snprintf(buf + len, PAGE_SIZE-len,
663 "Link Down - User disabled\n");
664 else
665 len += snprintf(buf + len, PAGE_SIZE-len,
666 "Link Down\n");
dea31012005-04-17 16:05:31 -0500667 break;
668 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500669 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500670 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400671 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500672
673 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500674 case LPFC_LOCAL_CFG_LINK:
675 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500676 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500677 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500678 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500679 case LPFC_FLOGI:
680 case LPFC_FABRIC_CFG_LINK:
681 case LPFC_NS_REG:
682 case LPFC_NS_QRY:
683 case LPFC_BUILD_DISC_LIST:
684 case LPFC_DISC_AUTH:
685 len += snprintf(buf + len, PAGE_SIZE - len,
686 "Discovery\n");
687 break;
688 case LPFC_VPORT_READY:
689 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
690 break;
691
James Smart92d7f7b2007-06-17 19:56:38 -0500692 case LPFC_VPORT_FAILED:
693 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
694 break;
695
696 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500697 len += snprintf(buf + len, PAGE_SIZE - len,
698 "Unknown\n");
699 break;
700 }
James Smart84774a42008-08-24 21:50:06 -0400701 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
702 len += snprintf(buf + len, PAGE_SIZE-len,
703 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500704 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500705 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500706 len += snprintf(buf + len, PAGE_SIZE-len,
707 " Public Loop\n");
708 else
709 len += snprintf(buf + len, PAGE_SIZE-len,
710 " Private Loop\n");
711 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500712 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500713 len += snprintf(buf + len, PAGE_SIZE-len,
714 " Fabric\n");
715 else
716 len += snprintf(buf + len, PAGE_SIZE-len,
717 " Point-2-Point\n");
718 }
719 }
James Smart2e0fef82007-06-17 19:56:36 -0500720
dea31012005-04-17 16:05:31 -0500721 return len;
722}
723
James Smarte59058c2008-08-24 21:49:00 -0400724/**
James Smart026abb82011-12-13 13:20:45 -0500725 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
726 * @dev: class unused variable.
727 * @attr: device attribute, not used.
728 * @buf: on return contains the module description text.
729 *
730 * Returns: size of formatted string.
731 **/
732static ssize_t
733lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
734 char *buf)
735{
736 struct Scsi_Host *shost = class_to_shost(dev);
737 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
738 struct lpfc_hba *phba = vport->phba;
739
740 if (phba->sli_rev < LPFC_SLI_REV4)
741 return snprintf(buf, PAGE_SIZE, "fc\n");
742
743 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
744 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
745 return snprintf(buf, PAGE_SIZE, "fcoe\n");
746 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
747 return snprintf(buf, PAGE_SIZE, "fc\n");
748 }
749 return snprintf(buf, PAGE_SIZE, "unknown\n");
750}
751
752/**
James Smart1ba981f2014-02-20 09:56:45 -0500753 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
754 * (OAS) is supported.
755 * @dev: class unused variable.
756 * @attr: device attribute, not used.
757 * @buf: on return contains the module description text.
758 *
759 * Returns: size of formatted string.
760 **/
761static ssize_t
762lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
763 char *buf)
764{
765 struct Scsi_Host *shost = class_to_shost(dev);
766 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
767 struct lpfc_hba *phba = vport->phba;
768
769 return snprintf(buf, PAGE_SIZE, "%d\n",
770 phba->sli4_hba.pc_sli4_params.oas_supported);
771}
772
773/**
James Smart84d1b002010-02-12 14:42:33 -0500774 * lpfc_link_state_store - Transition the link_state on an HBA port
775 * @dev: class device that is converted into a Scsi_host.
776 * @attr: device attribute, not used.
777 * @buf: one or more lpfc_polling_flags values.
778 * @count: not used.
779 *
780 * Returns:
781 * -EINVAL if the buffer is not "up" or "down"
782 * return from link state change function if non-zero
783 * length of the buf on success
784 **/
785static ssize_t
786lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
787 const char *buf, size_t count)
788{
789 struct Scsi_Host *shost = class_to_shost(dev);
790 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
791 struct lpfc_hba *phba = vport->phba;
792
793 int status = -EINVAL;
794
795 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
796 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400797 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500798 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
799 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400800 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500801
802 if (status == 0)
803 return strlen(buf);
804 else
805 return status;
806}
807
808/**
James Smart3621a712009-04-06 18:47:14 -0400809 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400810 * @dev: class device that is converted into a Scsi_host.
811 * @attr: device attribute, not used.
812 * @buf: on return contains the sum of fc mapped and unmapped.
813 *
814 * Description:
815 * Returns the ascii text number of the sum of the fc mapped and unmapped
816 * vport counts.
817 *
818 * Returns: size of formatted string.
819 **/
dea31012005-04-17 16:05:31 -0500820static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100821lpfc_num_discovered_ports_show(struct device *dev,
822 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500823{
Tony Jonesee959b02008-02-22 00:13:36 +0100824 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500825 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
826
827 return snprintf(buf, PAGE_SIZE, "%d\n",
828 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500829}
830
James Smarte59058c2008-08-24 21:49:00 -0400831/**
James Smart3621a712009-04-06 18:47:14 -0400832 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400833 * @shost: Scsi_Host pointer.
834 *
835 * Description:
836 * Bring the link down gracefully then re-init the link. The firmware will
837 * re-init the fiber channel interface as required. Does not issue a LIP.
838 *
839 * Returns:
840 * -EPERM port offline or management commands are being blocked
841 * -ENOMEM cannot allocate memory for the mailbox command
842 * -EIO error sending the mailbox command
843 * zero for success
844 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700845static int
James Smart2e0fef82007-06-17 19:56:36 -0500846lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500847{
James Smart2e0fef82007-06-17 19:56:36 -0500848 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
849 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500850 LPFC_MBOXQ_t *pmboxq;
851 int mbxstatus = MBXERR_ERROR;
852
James Smart2e0fef82007-06-17 19:56:36 -0500853 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500854 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500855 return -EPERM;
856
857 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
858
859 if (!pmboxq)
860 return -ENOMEM;
861
862 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400863 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
864 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400865
James Smart33ccf8d2006-08-17 11:57:58 -0400866 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500867
James Smart04c68492009-05-22 14:52:52 -0400868 if ((mbxstatus == MBX_SUCCESS) &&
869 (pmboxq->u.mb.mbxStatus == 0 ||
870 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400871 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
872 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
873 phba->cfg_link_speed);
874 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
875 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400876 if ((mbxstatus == MBX_SUCCESS) &&
877 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
878 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
879 "2859 SLI authentication is required "
880 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400881 }
882
James Smart5b8bd0c2007-04-25 09:52:49 -0400883 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500884 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400885 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500886
887 if (mbxstatus == MBXERR_ERROR)
888 return -EIO;
889
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700890 return 0;
dea31012005-04-17 16:05:31 -0500891}
892
James Smart895427b2017-02-12 13:52:30 -0800893int
894lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
895{
896 int cnt = 0;
897
898 spin_lock_irq(lock);
899 while (!list_empty(q)) {
900 spin_unlock_irq(lock);
901 msleep(20);
902 if (cnt++ > 250) { /* 5 secs */
903 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
904 "0466 %s %s\n",
905 "Outstanding IO when ",
906 "bringing Adapter offline\n");
907 return 0;
908 }
909 spin_lock_irq(lock);
910 }
911 spin_unlock_irq(lock);
912 return 1;
913}
914
James Smarte59058c2008-08-24 21:49:00 -0400915/**
James Smart3621a712009-04-06 18:47:14 -0400916 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400917 * @phba: lpfc_hba pointer.
918 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
919 *
920 * Notes:
921 * Assumes any error from lpfc_do_offline() will be negative.
922 * Can wait up to 5 seconds for the port ring buffers count
923 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400924 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400925 *
926 * Returns:
927 * -EIO error posting the event
928 * zero for success
929 **/
James Smart40496f02006-07-06 15:50:22 -0400930static int
James Smart46fa3112007-04-25 09:51:45 -0400931lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
932{
933 struct completion online_compl;
James Smart895427b2017-02-12 13:52:30 -0800934 struct lpfc_queue *qp = NULL;
James Smart46fa3112007-04-25 09:51:45 -0400935 struct lpfc_sli_ring *pring;
936 struct lpfc_sli *psli;
937 int status = 0;
James Smart46fa3112007-04-25 09:51:45 -0400938 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500939 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400940
941 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500942 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400943 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500944 if (rc == 0)
945 return -ENOMEM;
946
James Smart46fa3112007-04-25 09:51:45 -0400947 wait_for_completion(&online_compl);
948
949 if (status != 0)
950 return -EIO;
951
952 psli = &phba->sli;
953
James Smart09372822008-01-11 01:52:54 -0500954 /* Wait a little for things to settle down, but not
955 * long enough for dev loss timeout to expire.
956 */
James Smart895427b2017-02-12 13:52:30 -0800957 if (phba->sli_rev != LPFC_SLI_REV4) {
958 for (i = 0; i < psli->num_rings; i++) {
959 pring = &psli->sli3_ring[i];
960 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
961 &phba->hbalock))
962 goto out;
963 }
964 } else {
965 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
966 pring = qp->pring;
967 if (!pring)
968 continue;
969 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
970 &pring->ring_lock))
971 goto out;
James Smart46fa3112007-04-25 09:51:45 -0400972 }
973 }
James Smart895427b2017-02-12 13:52:30 -0800974out:
James Smart46fa3112007-04-25 09:51:45 -0400975 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500976 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
977 if (rc == 0)
978 return -ENOMEM;
979
James Smart46fa3112007-04-25 09:51:45 -0400980 wait_for_completion(&online_compl);
981
982 if (status != 0)
983 return -EIO;
984
985 return 0;
986}
987
James Smarte59058c2008-08-24 21:49:00 -0400988/**
James Smart3621a712009-04-06 18:47:14 -0400989 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400990 * @phba: lpfc_hba pointer.
991 *
992 * Description:
993 * If the port is configured to allow a reset then the hba is brought
994 * offline then online.
995 *
996 * Notes:
997 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500998 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400999 *
1000 * Returns:
1001 * lpfc_do_offline() return code if not zero
1002 * -EIO reset not configured or error posting the event
1003 * zero for success
1004 **/
James Smart7f860592011-03-11 16:05:52 -05001005int
James Smart40496f02006-07-06 15:50:22 -04001006lpfc_selective_reset(struct lpfc_hba *phba)
1007{
1008 struct completion online_compl;
1009 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001010 int rc;
James Smart40496f02006-07-06 15:50:22 -04001011
James Smart71157c92013-07-15 18:34:36 -04001012 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001013 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -05001014
James Smart71157c92013-07-15 18:34:36 -04001015 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1016 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -04001017
James Smart71157c92013-07-15 18:34:36 -04001018 if (status != 0)
1019 return status;
1020 }
James Smart40496f02006-07-06 15:50:22 -04001021
1022 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001023 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -04001024 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -05001025 if (rc == 0)
1026 return -ENOMEM;
1027
James Smart40496f02006-07-06 15:50:22 -04001028 wait_for_completion(&online_compl);
1029
1030 if (status != 0)
1031 return -EIO;
1032
1033 return 0;
1034}
1035
James Smarte59058c2008-08-24 21:49:00 -04001036/**
James Smart3621a712009-04-06 18:47:14 -04001037 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -04001038 * @dev: class device that is converted into a Scsi_host.
1039 * @attr: device attribute, not used.
1040 * @buf: containing the string "selective".
1041 * @count: unused variable.
1042 *
1043 * Description:
1044 * If the buf contains the string "selective" then lpfc_selective_reset()
1045 * is called to perform the reset.
1046 *
1047 * Notes:
1048 * Assumes any error from lpfc_selective_reset() will be negative.
1049 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001050 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -04001051 *
1052 * Returns:
1053 * -EINVAL if the buffer does not contain the string "selective"
1054 * length of buf if lpfc-selective_reset() if the call succeeds
1055 * return value of lpfc_selective_reset() if the call fails
1056**/
James Smart40496f02006-07-06 15:50:22 -04001057static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001058lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1059 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -04001060{
Tony Jonesee959b02008-02-22 00:13:36 +01001061 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001062 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1063 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -04001064 int status = -EINVAL;
1065
James Smart73d91e52011-10-10 21:32:10 -04001066 if (!phba->cfg_enable_hba_reset)
1067 return -EACCES;
1068
James Smart40496f02006-07-06 15:50:22 -04001069 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -05001070 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -04001071
1072 if (status == 0)
1073 return strlen(buf);
1074 else
1075 return status;
1076}
1077
James Smarte59058c2008-08-24 21:49:00 -04001078/**
James Smart88a2cfb2011-07-22 18:36:33 -04001079 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1080 * @phba: lpfc_hba pointer.
1081 *
1082 * Description:
1083 * SLI4 interface type-2 device to wait on the sliport status register for
1084 * the readyness after performing a firmware reset.
1085 *
1086 * Returns:
Masanari Iida0b1587b2013-07-17 04:37:44 +09001087 * zero for success, -EPERM when port does not have privilege to perform the
James Smart026abb82011-12-13 13:20:45 -05001088 * reset, -EIO when port timeout from recovering from the reset.
1089 *
1090 * Note:
1091 * As the caller will interpret the return code by value, be careful in making
1092 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -04001093 **/
James Smart73d91e52011-10-10 21:32:10 -04001094int
James Smart88a2cfb2011-07-22 18:36:33 -04001095lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1096{
James Smartf7a919b2011-08-21 21:49:16 -04001097 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -04001098 int i;
1099
James Smartf7a919b2011-08-21 21:49:16 -04001100 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -04001101 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1102 &portstat_reg.word0);
1103
Masanari Iida0b1587b2013-07-17 04:37:44 +09001104 /* verify if privileged for the request operation */
James Smartf7a919b2011-08-21 21:49:16 -04001105 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1106 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1107 return -EPERM;
1108
James Smart88a2cfb2011-07-22 18:36:33 -04001109 /* wait for the SLI port firmware ready after firmware reset */
1110 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1111 msleep(10);
1112 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1113 &portstat_reg.word0);
1114 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1115 continue;
1116 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1117 continue;
1118 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1119 continue;
1120 break;
1121 }
1122
1123 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1124 return 0;
1125 else
1126 return -EIO;
1127}
1128
1129/**
James Smart52d52442011-05-24 11:42:45 -04001130 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -04001131 * @phba: lpfc_hba pointer.
1132 *
1133 * Description:
James Smart52d52442011-05-24 11:42:45 -04001134 * Request SLI4 interface type-2 device to perform a physical register set
1135 * access.
James Smartc0c11512011-05-24 11:41:34 -04001136 *
1137 * Returns:
1138 * zero for success
1139 **/
1140static ssize_t
James Smart52d52442011-05-24 11:42:45 -04001141lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -04001142{
1143 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -04001144 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -05001145 uint32_t before_fc_flag;
1146 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -04001147 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -05001148 int status = 0, rc = 0;
1149 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -04001150
1151 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001152 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -04001153
James Smart52d52442011-05-24 11:42:45 -04001154 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1155 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1156 LPFC_SLI_INTF_IF_TYPE_2))
1157 return -EPERM;
1158
James Smart026abb82011-12-13 13:20:45 -05001159 /* Keep state if we need to restore back */
1160 before_fc_flag = phba->pport->fc_flag;
1161 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1162
James Smartb76f2dc2011-07-22 18:37:42 -04001163 /* Disable SR-IOV virtual functions if enabled */
1164 if (phba->cfg_sriov_nr_virtfn) {
1165 pci_disable_sriov(pdev);
1166 phba->cfg_sriov_nr_virtfn = 0;
1167 }
James Smart229adb02013-04-17 20:16:51 -04001168
James Smart02936352014-04-04 13:52:12 -04001169 if (opcode == LPFC_FW_DUMP)
1170 phba->hba_flag |= HBA_FW_DUMP_OP;
1171
James Smartc0c11512011-05-24 11:41:34 -04001172 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1173
James Smart02936352014-04-04 13:52:12 -04001174 if (status != 0) {
1175 phba->hba_flag &= ~HBA_FW_DUMP_OP;
James Smartc0c11512011-05-24 11:41:34 -04001176 return status;
James Smart02936352014-04-04 13:52:12 -04001177 }
James Smartc0c11512011-05-24 11:41:34 -04001178
1179 /* wait for the device to be quiesced before firmware reset */
1180 msleep(100);
1181
1182 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1183 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -04001184
1185 if (opcode == LPFC_FW_DUMP)
1186 reg_val |= LPFC_FW_DUMP_REQUEST;
1187 else if (opcode == LPFC_FW_RESET)
1188 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1189 else if (opcode == LPFC_DV_RESET)
1190 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1191
James Smartc0c11512011-05-24 11:41:34 -04001192 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1193 LPFC_CTL_PDEV_CTL_OFFSET);
1194 /* flush */
1195 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1196
1197 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -04001198 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1199
James Smart026abb82011-12-13 13:20:45 -05001200 if (rc == -EPERM) {
Masanari Iida0b1587b2013-07-17 04:37:44 +09001201 /* no privilege for reset */
James Smart6b5151f2012-01-18 16:24:06 -05001202 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
Masanari Iida0b1587b2013-07-17 04:37:44 +09001203 "3150 No privilege to perform the requested "
James Smart6b5151f2012-01-18 16:24:06 -05001204 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -05001205 } else if (rc == -EIO) {
1206 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -05001207 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1208 "3153 Fail to perform the requested "
1209 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -04001210 return rc;
James Smart026abb82011-12-13 13:20:45 -05001211 }
1212
1213 /* keep the original port state */
1214 if (before_fc_flag & FC_OFFLINE_MODE)
1215 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001216
1217 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -05001218 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1219 LPFC_EVT_ONLINE);
1220 if (!job_posted)
1221 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001222
1223 wait_for_completion(&online_compl);
1224
James Smart026abb82011-12-13 13:20:45 -05001225out:
1226 /* in any case, restore the virtual functions enabled as before */
1227 if (sriov_nr_virtfn) {
1228 sriov_err =
1229 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1230 if (!sriov_err)
1231 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1232 }
James Smartc0c11512011-05-24 11:41:34 -04001233
James Smart026abb82011-12-13 13:20:45 -05001234 /* return proper error code */
1235 if (!rc) {
1236 if (!job_posted)
1237 rc = -ENOMEM;
1238 else if (status)
1239 rc = -EIO;
1240 }
1241 return rc;
James Smartc0c11512011-05-24 11:41:34 -04001242}
1243
1244/**
James Smart3621a712009-04-06 18:47:14 -04001245 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -04001246 * @dev: class device that is converted into a Scsi_host.
1247 * @attr: device attribute, not used.
1248 * @buf: on return contains the ascii number of nport events.
1249 *
1250 * Returns: size of formatted string.
1251 **/
dea31012005-04-17 16:05:31 -05001252static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001253lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1254 char *buf)
dea31012005-04-17 16:05:31 -05001255{
Tony Jonesee959b02008-02-22 00:13:36 +01001256 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001257 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1258 struct lpfc_hba *phba = vport->phba;
1259
dea31012005-04-17 16:05:31 -05001260 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1261}
1262
James Smarte59058c2008-08-24 21:49:00 -04001263/**
James Smart3621a712009-04-06 18:47:14 -04001264 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -04001265 * @dev: class device that is converted into a Scsi_host.
1266 * @attr: device attribute, not used.
1267 * @buf: on return contains the state of the adapter.
1268 *
1269 * Returns: size of formatted string.
1270 **/
dea31012005-04-17 16:05:31 -05001271static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001272lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1273 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001274{
Tony Jonesee959b02008-02-22 00:13:36 +01001275 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001276 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1277 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001278 char * state;
1279
James Smart2e0fef82007-06-17 19:56:36 -05001280 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001281 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001282 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001283 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001284 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001285 state = "offline";
1286 else
1287 state = "online";
1288
1289 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1290}
1291
James Smarte59058c2008-08-24 21:49:00 -04001292/**
James Smart3621a712009-04-06 18:47:14 -04001293 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001294 * @dev: class device that is converted into a Scsi_host.
1295 * @attr: device attribute, not used.
1296 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1297 * @count: unused variable.
1298 *
1299 * Returns:
1300 * -EACCES if enable hba reset not enabled
1301 * -EINVAL if the buffer does not contain a valid string (see above)
1302 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1303 * buf length greater than zero indicates success
1304 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001305static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001306lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1307 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001308{
Tony Jonesee959b02008-02-22 00:13:36 +01001309 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001310 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1311 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001312 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001313 char *board_mode_str = NULL;
1314 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001315 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001316
James Smart026abb82011-12-13 13:20:45 -05001317 if (!phba->cfg_enable_hba_reset) {
1318 status = -EACCES;
1319 goto board_mode_out;
1320 }
James Smart88a2cfb2011-07-22 18:36:33 -04001321
1322 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001323 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001324
Jamie Wellnitz41415862006-02-28 19:25:27 -05001325 init_completion(&online_compl);
1326
James Smart46fa3112007-04-25 09:51:45 -04001327 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001328 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001329 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001330 if (rc == 0) {
1331 status = -ENOMEM;
1332 goto board_mode_out;
1333 }
James Smart46fa3112007-04-25 09:51:45 -04001334 wait_for_completion(&online_compl);
1335 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1336 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001337 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001338 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001339 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001340 else
1341 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001342 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001343 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001344 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001345 else
1346 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001347 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001348 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1349 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1350 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1351 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1352 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001353 else
James Smart026abb82011-12-13 13:20:45 -05001354 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001355
James Smart026abb82011-12-13 13:20:45 -05001356board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001357 if (!status)
1358 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001359 else {
1360 board_mode_str = strchr(buf, '\n');
1361 if (board_mode_str)
1362 *board_mode_str = '\0';
1363 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1364 "3097 Failed \"%s\", status(%d), "
1365 "fc_flag(x%x)\n",
1366 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001367 return status;
James Smart026abb82011-12-13 13:20:45 -05001368 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001369}
1370
James Smarte59058c2008-08-24 21:49:00 -04001371/**
James Smart3621a712009-04-06 18:47:14 -04001372 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001373 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001374 * @mxri: max xri count.
1375 * @axri: available xri count.
1376 * @mrpi: max rpi count.
1377 * @arpi: available rpi count.
1378 * @mvpi: max vpi count.
1379 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001380 *
1381 * Description:
1382 * If an integer pointer for an count is not null then the value for the
1383 * count is returned.
1384 *
1385 * Returns:
1386 * zero on error
1387 * one for success
1388 **/
James Smart311464e2007-08-02 11:10:37 -04001389static int
James Smart858c9f62007-06-17 19:56:39 -05001390lpfc_get_hba_info(struct lpfc_hba *phba,
1391 uint32_t *mxri, uint32_t *axri,
1392 uint32_t *mrpi, uint32_t *arpi,
1393 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001394{
James Smart04c68492009-05-22 14:52:52 -04001395 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001396 LPFC_MBOXQ_t *pmboxq;
1397 MAILBOX_t *pmb;
1398 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001399 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001400
1401 /*
1402 * prevent udev from issuing mailbox commands until the port is
1403 * configured.
1404 */
1405 if (phba->link_state < LPFC_LINK_DOWN ||
1406 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001407 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001408 return 0;
1409
1410 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1411 return 0;
1412
1413 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1414 if (!pmboxq)
1415 return 0;
1416 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1417
James Smart04c68492009-05-22 14:52:52 -04001418 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001419 pmb->mbxCommand = MBX_READ_CONFIG;
1420 pmb->mbxOwner = OWN_HOST;
1421 pmboxq->context1 = NULL;
1422
James Smart75baf692010-06-08 18:31:21 -04001423 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001424 rc = MBX_NOT_FINISHED;
1425 else
1426 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1427
1428 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001429 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001430 mempool_free(pmboxq, phba->mbox_mem_pool);
1431 return 0;
1432 }
1433
James Smartda0436e2009-05-22 14:51:39 -04001434 if (phba->sli_rev == LPFC_SLI_REV4) {
1435 rd_config = &pmboxq->u.mqe.un.rd_config;
1436 if (mrpi)
1437 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1438 if (arpi)
1439 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1440 phba->sli4_hba.max_cfg_param.rpi_used;
1441 if (mxri)
1442 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1443 if (axri)
1444 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1445 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001446
1447 /* Account for differences with SLI-3. Get vpi count from
1448 * mailbox data and subtract one for max vpi value.
1449 */
1450 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1451 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1452
James Smartda0436e2009-05-22 14:51:39 -04001453 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001454 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001455 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001456 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001457 } else {
1458 if (mrpi)
1459 *mrpi = pmb->un.varRdConfig.max_rpi;
1460 if (arpi)
1461 *arpi = pmb->un.varRdConfig.avail_rpi;
1462 if (mxri)
1463 *mxri = pmb->un.varRdConfig.max_xri;
1464 if (axri)
1465 *axri = pmb->un.varRdConfig.avail_xri;
1466 if (mvpi)
1467 *mvpi = pmb->un.varRdConfig.max_vpi;
1468 if (avpi)
1469 *avpi = pmb->un.varRdConfig.avail_vpi;
1470 }
James Smart92d7f7b2007-06-17 19:56:38 -05001471
1472 mempool_free(pmboxq, phba->mbox_mem_pool);
1473 return 1;
1474}
1475
James Smarte59058c2008-08-24 21:49:00 -04001476/**
James Smart3621a712009-04-06 18:47:14 -04001477 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001478 * @dev: class device that is converted into a Scsi_host.
1479 * @attr: device attribute, not used.
1480 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1481 *
1482 * Description:
1483 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1484 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1485 * to "Unknown" and the buffer length is returned, therefore the caller
1486 * must check for "Unknown" in the buffer to detect a failure.
1487 *
1488 * Returns: size of formatted string.
1489 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001490static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001491lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1492 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001493{
Tony Jonesee959b02008-02-22 00:13:36 +01001494 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001495 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1496 struct lpfc_hba *phba = vport->phba;
1497 uint32_t cnt;
1498
James Smart858c9f62007-06-17 19:56:39 -05001499 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001500 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1501 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1502}
1503
James Smarte59058c2008-08-24 21:49:00 -04001504/**
James Smart3621a712009-04-06 18:47:14 -04001505 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001506 * @dev: class device that is converted into a Scsi_host.
1507 * @attr: device attribute, not used.
1508 * @buf: containing the used rpi count in decimal or "Unknown".
1509 *
1510 * Description:
1511 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1512 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1513 * to "Unknown" and the buffer length is returned, therefore the caller
1514 * must check for "Unknown" in the buffer to detect a failure.
1515 *
1516 * Returns: size of formatted string.
1517 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001518static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001519lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1520 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001521{
Tony Jonesee959b02008-02-22 00:13:36 +01001522 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001523 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1524 struct lpfc_hba *phba = vport->phba;
1525 uint32_t cnt, acnt;
1526
James Smart858c9f62007-06-17 19:56:39 -05001527 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001528 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1529 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1530}
1531
James Smarte59058c2008-08-24 21:49:00 -04001532/**
James Smart3621a712009-04-06 18:47:14 -04001533 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001534 * @dev: class device that is converted into a Scsi_host.
1535 * @attr: device attribute, not used.
1536 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1537 *
1538 * Description:
1539 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1540 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1541 * to "Unknown" and the buffer length is returned, therefore the caller
1542 * must check for "Unknown" in the buffer to detect a failure.
1543 *
1544 * Returns: size of formatted string.
1545 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001546static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001547lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1548 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001549{
Tony Jonesee959b02008-02-22 00:13:36 +01001550 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001551 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1552 struct lpfc_hba *phba = vport->phba;
1553 uint32_t cnt;
1554
James Smart858c9f62007-06-17 19:56:39 -05001555 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001556 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1557 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1558}
1559
James Smarte59058c2008-08-24 21:49:00 -04001560/**
James Smart3621a712009-04-06 18:47:14 -04001561 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001562 * @dev: class device that is converted into a Scsi_host.
1563 * @attr: device attribute, not used.
1564 * @buf: on return contains the used xri count in decimal or "Unknown".
1565 *
1566 * Description:
1567 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1568 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1569 * to "Unknown" and the buffer length is returned, therefore the caller
1570 * must check for "Unknown" in the buffer to detect a failure.
1571 *
1572 * Returns: size of formatted string.
1573 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001574static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001575lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1576 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001577{
Tony Jonesee959b02008-02-22 00:13:36 +01001578 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001579 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1580 struct lpfc_hba *phba = vport->phba;
1581 uint32_t cnt, acnt;
1582
James Smart858c9f62007-06-17 19:56:39 -05001583 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1584 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1585 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1586}
1587
James Smarte59058c2008-08-24 21:49:00 -04001588/**
James Smart3621a712009-04-06 18:47:14 -04001589 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001590 * @dev: class device that is converted into a Scsi_host.
1591 * @attr: device attribute, not used.
1592 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1593 *
1594 * Description:
1595 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1596 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1597 * to "Unknown" and the buffer length is returned, therefore the caller
1598 * must check for "Unknown" in the buffer to detect a failure.
1599 *
1600 * Returns: size of formatted string.
1601 **/
James Smart858c9f62007-06-17 19:56:39 -05001602static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001603lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1604 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001605{
Tony Jonesee959b02008-02-22 00:13:36 +01001606 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001607 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1608 struct lpfc_hba *phba = vport->phba;
1609 uint32_t cnt;
1610
1611 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1612 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1613 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1614}
1615
James Smarte59058c2008-08-24 21:49:00 -04001616/**
James Smart3621a712009-04-06 18:47:14 -04001617 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001618 * @dev: class device that is converted into a Scsi_host.
1619 * @attr: device attribute, not used.
1620 * @buf: on return contains the used vpi count in decimal or "Unknown".
1621 *
1622 * Description:
1623 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1624 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1625 * to "Unknown" and the buffer length is returned, therefore the caller
1626 * must check for "Unknown" in the buffer to detect a failure.
1627 *
1628 * Returns: size of formatted string.
1629 **/
James Smart858c9f62007-06-17 19:56:39 -05001630static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001631lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1632 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001633{
Tony Jonesee959b02008-02-22 00:13:36 +01001634 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001635 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1636 struct lpfc_hba *phba = vport->phba;
1637 uint32_t cnt, acnt;
1638
1639 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001640 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1641 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1642}
1643
James Smarte59058c2008-08-24 21:49:00 -04001644/**
James Smart3621a712009-04-06 18:47:14 -04001645 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001646 * @dev: class device that is converted into a Scsi_host.
1647 * @attr: device attribute, not used.
1648 * @buf: text that must be interpreted to determine if npiv is supported.
1649 *
1650 * Description:
1651 * Buffer will contain text indicating npiv is not suppoerted on the port,
1652 * the port is an NPIV physical port, or it is an npiv virtual port with
1653 * the id of the vport.
1654 *
1655 * Returns: size of formatted string.
1656 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001657static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001658lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1659 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001660{
Tony Jonesee959b02008-02-22 00:13:36 +01001661 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001662 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1663 struct lpfc_hba *phba = vport->phba;
1664
1665 if (!(phba->max_vpi))
1666 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1667 if (vport->port_type == LPFC_PHYSICAL_PORT)
1668 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1669 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1670}
1671
James Smarte59058c2008-08-24 21:49:00 -04001672/**
James Smart3621a712009-04-06 18:47:14 -04001673 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001674 * @dev: class device that is converted into a Scsi_host.
1675 * @attr: device attribute, not used.
1676 * @buf: on return contains the cfg_poll in hex.
1677 *
1678 * Notes:
1679 * cfg_poll should be a lpfc_polling_flags type.
1680 *
1681 * Returns: size of formatted string.
1682 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001683static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001684lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1685 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001686{
Tony Jonesee959b02008-02-22 00:13:36 +01001687 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001688 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1689 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001690
1691 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1692}
1693
James Smarte59058c2008-08-24 21:49:00 -04001694/**
James Smart3621a712009-04-06 18:47:14 -04001695 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001696 * @dev: class device that is converted into a Scsi_host.
1697 * @attr: device attribute, not used.
1698 * @buf: one or more lpfc_polling_flags values.
1699 * @count: not used.
1700 *
1701 * Notes:
1702 * buf contents converted to integer and checked for a valid value.
1703 *
1704 * Returns:
1705 * -EINVAL if the buffer connot be converted or is out of range
1706 * length of the buf on success
1707 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001708static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001709lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1710 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001711{
Tony Jonesee959b02008-02-22 00:13:36 +01001712 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001713 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1714 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001715 uint32_t creg_val;
1716 uint32_t old_val;
1717 int val=0;
1718
1719 if (!isdigit(buf[0]))
1720 return -EINVAL;
1721
1722 if (sscanf(buf, "%i", &val) != 1)
1723 return -EINVAL;
1724
1725 if ((val & 0x3) != val)
1726 return -EINVAL;
1727
James Smart45ed1192009-10-02 15:17:02 -04001728 if (phba->sli_rev == LPFC_SLI_REV4)
1729 val = 0;
1730
James Smart88a2cfb2011-07-22 18:36:33 -04001731 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1732 "3051 lpfc_poll changed from %d to %d\n",
1733 phba->cfg_poll, val);
1734
James Smart2e0fef82007-06-17 19:56:36 -05001735 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001736
1737 old_val = phba->cfg_poll;
1738
1739 if (val & ENABLE_FCP_RING_POLLING) {
1740 if ((val & DISABLE_FCP_RING_INT) &&
1741 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001742 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1743 spin_unlock_irq(&phba->hbalock);
1744 return -EINVAL;
1745 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001746 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1747 writel(creg_val, phba->HCregaddr);
1748 readl(phba->HCregaddr); /* flush */
1749
1750 lpfc_poll_start_timer(phba);
1751 }
1752 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001753 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001754 return -EINVAL;
1755 }
1756
1757 if (!(val & DISABLE_FCP_RING_INT) &&
1758 (old_val & DISABLE_FCP_RING_INT))
1759 {
James Smart2e0fef82007-06-17 19:56:36 -05001760 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001761 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001762 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001763 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1764 spin_unlock_irq(&phba->hbalock);
1765 return -EINVAL;
1766 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001767 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1768 writel(creg_val, phba->HCregaddr);
1769 readl(phba->HCregaddr); /* flush */
1770 }
1771
1772 phba->cfg_poll = val;
1773
James Smart2e0fef82007-06-17 19:56:36 -05001774 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001775
1776 return strlen(buf);
1777}
dea31012005-04-17 16:05:31 -05001778
James Smarte59058c2008-08-24 21:49:00 -04001779/**
James Smartbc739052010-08-04 16:11:18 -04001780 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1781 * @dev: class unused variable.
1782 * @attr: device attribute, not used.
1783 * @buf: on return contains the module description text.
1784 *
1785 * Returns: size of formatted string.
1786 **/
1787static ssize_t
1788lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1789 char *buf)
1790{
1791 struct Scsi_Host *shost = class_to_shost(dev);
1792 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1793 struct lpfc_hba *phba = vport->phba;
1794
1795 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1796}
1797
1798/**
1799 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1800 * @dev: class unused variable.
1801 * @attr: device attribute, not used.
1802 * @buf: on return contains the module description text.
1803 *
1804 * Returns: size of formatted string.
1805 **/
1806static ssize_t
1807lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1808 char *buf)
1809{
1810 struct Scsi_Host *shost = class_to_shost(dev);
1811 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1812 struct lpfc_hba *phba = vport->phba;
1813
1814 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1815}
1816
1817/**
James Smartab56dc22011-02-16 12:39:57 -05001818 * lpfc_dss_show - Return the current state of dss and the configured state
1819 * @dev: class converted to a Scsi_host structure.
1820 * @attr: device attribute, not used.
1821 * @buf: on return contains the formatted text.
1822 *
1823 * Returns: size of formatted string.
1824 **/
1825static ssize_t
1826lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1827 char *buf)
1828{
1829 struct Scsi_Host *shost = class_to_shost(dev);
1830 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1831 struct lpfc_hba *phba = vport->phba;
1832
1833 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1834 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1835 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1836 "" : "Not ");
1837}
1838
1839/**
James Smart912e3ac2011-05-24 11:42:11 -04001840 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1841 * @dev: class converted to a Scsi_host structure.
1842 * @attr: device attribute, not used.
1843 * @buf: on return contains the formatted support level.
1844 *
1845 * Description:
1846 * Returns the maximum number of virtual functions a physical function can
1847 * support, 0 will be returned if called on virtual function.
1848 *
1849 * Returns: size of formatted string.
1850 **/
1851static ssize_t
1852lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1853 struct device_attribute *attr,
1854 char *buf)
1855{
1856 struct Scsi_Host *shost = class_to_shost(dev);
1857 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1858 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001859 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001860
James Smart0a96e972011-07-22 18:37:28 -04001861 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1862 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001863}
1864
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001865static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1866{
1867 return val >= min && val <= max;
1868}
1869
James Smart912e3ac2011-05-24 11:42:11 -04001870/**
James Smart3621a712009-04-06 18:47:14 -04001871 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001872 *
1873 * Description:
1874 * Macro that given an attr e.g. hba_queue_depth expands
1875 * into a function with the name lpfc_hba_queue_depth_show.
1876 *
1877 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1878 * @dev: class device that is converted into a Scsi_host.
1879 * @attr: device attribute, not used.
1880 * @buf: on return contains the attribute value in decimal.
1881 *
1882 * Returns: size of formatted string.
1883 **/
dea31012005-04-17 16:05:31 -05001884#define lpfc_param_show(attr) \
1885static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001886lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1887 char *buf) \
dea31012005-04-17 16:05:31 -05001888{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001889 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001890 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1891 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001892 return snprintf(buf, PAGE_SIZE, "%d\n",\
1893 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001894}
1895
James Smarte59058c2008-08-24 21:49:00 -04001896/**
James Smart3621a712009-04-06 18:47:14 -04001897 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001898 *
1899 * Description:
1900 * Macro that given an attr e.g. hba_queue_depth expands
1901 * into a function with the name lpfc_hba_queue_depth_show
1902 *
1903 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1904 * @dev: class device that is converted into a Scsi_host.
1905 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001906 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001907 *
1908 * Returns: size of formatted string.
1909 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001910#define lpfc_param_hex_show(attr) \
1911static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001912lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1913 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001914{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001915 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001916 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1917 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001918 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001919 val = phba->cfg_##attr;\
1920 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1921 phba->cfg_##attr);\
1922}
1923
James Smarte59058c2008-08-24 21:49:00 -04001924/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001925 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001926 *
1927 * Description:
1928 * Macro that given an attr e.g. hba_queue_depth expands
1929 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1930 * takes a default argument, a minimum and maximum argument.
1931 *
1932 * lpfc_##attr##_init: Initializes an attribute.
1933 * @phba: pointer the the adapter structure.
1934 * @val: integer attribute value.
1935 *
1936 * Validates the min and max values then sets the adapter config field
1937 * accordingly, or uses the default if out of range and prints an error message.
1938 *
1939 * Returns:
1940 * zero on success
1941 * -EINVAL if default used
1942 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001943#define lpfc_param_init(attr, default, minval, maxval) \
1944static int \
James Smart84d1b002010-02-12 14:42:33 -05001945lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001946{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001947 if (lpfc_rangecheck(val, minval, maxval)) {\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001948 phba->cfg_##attr = val;\
1949 return 0;\
1950 }\
1951 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001952 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1953 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001954 phba->cfg_##attr = default;\
1955 return -EINVAL;\
1956}
1957
James Smarte59058c2008-08-24 21:49:00 -04001958/**
James Smart3621a712009-04-06 18:47:14 -04001959 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001960 *
1961 * Description:
1962 * Macro that given an attr e.g. hba_queue_depth expands
1963 * into a function with the name lpfc_hba_queue_depth_set
1964 *
1965 * lpfc_##attr##_set: Sets an attribute value.
1966 * @phba: pointer the the adapter structure.
1967 * @val: integer attribute value.
1968 *
1969 * Description:
1970 * Validates the min and max values then sets the
1971 * adapter config field if in the valid range. prints error message
1972 * and does not set the parameter if invalid.
1973 *
1974 * Returns:
1975 * zero on success
1976 * -EINVAL if val is invalid
1977 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001978#define lpfc_param_set(attr, default, minval, maxval) \
1979static int \
James Smart84d1b002010-02-12 14:42:33 -05001980lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001981{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001982 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001983 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1984 "3052 lpfc_" #attr " changed from %d to %d\n", \
1985 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001986 phba->cfg_##attr = val;\
1987 return 0;\
1988 }\
1989 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001990 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1991 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001992 return -EINVAL;\
1993}
1994
James Smarte59058c2008-08-24 21:49:00 -04001995/**
James Smart3621a712009-04-06 18:47:14 -04001996 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001997 *
1998 * Description:
1999 * Macro that given an attr e.g. hba_queue_depth expands
2000 * into a function with the name lpfc_hba_queue_depth_store.
2001 *
2002 * lpfc_##attr##_store: Set an sttribute value.
2003 * @dev: class device that is converted into a Scsi_host.
2004 * @attr: device attribute, not used.
2005 * @buf: contains the attribute value in ascii.
2006 * @count: not used.
2007 *
2008 * Description:
2009 * Convert the ascii text number to an integer, then
2010 * use the lpfc_##attr##_set function to set the value.
2011 *
2012 * Returns:
2013 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2014 * length of buffer upon success.
2015 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002016#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05002017static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002018lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2019 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05002020{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002021 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002022 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2023 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05002024 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002025 if (!isdigit(buf[0]))\
2026 return -EINVAL;\
2027 if (sscanf(buf, "%i", &val) != 1)\
2028 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002029 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04002030 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002031 else \
2032 return -EINVAL;\
dea31012005-04-17 16:05:31 -05002033}
2034
James Smarte59058c2008-08-24 21:49:00 -04002035/**
James Smart3621a712009-04-06 18:47:14 -04002036 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04002037 *
2038 * Description:
2039 * Macro that given an attr e.g. hba_queue_depth expands
2040 * into a function with the name lpfc_hba_queue_depth_show
2041 *
2042 * lpfc_##attr##_show: prints the attribute value in decimal.
2043 * @dev: class device that is converted into a Scsi_host.
2044 * @attr: device attribute, not used.
2045 * @buf: on return contains the attribute value in decimal.
2046 *
2047 * Returns: length of formatted string.
2048 **/
James Smart3de2a652007-08-02 11:09:59 -04002049#define lpfc_vport_param_show(attr) \
2050static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002051lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2052 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002053{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002054 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002055 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002056 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2057}
2058
James Smarte59058c2008-08-24 21:49:00 -04002059/**
James Smart3621a712009-04-06 18:47:14 -04002060 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04002061 *
2062 * Description:
2063 * Macro that given an attr e.g.
2064 * hba_queue_depth expands into a function with the name
2065 * lpfc_hba_queue_depth_show
2066 *
James Smart3621a712009-04-06 18:47:14 -04002067 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002068 * @dev: class device that is converted into a Scsi_host.
2069 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002070 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002071 *
2072 * Returns: length of formatted string.
2073 **/
James Smart3de2a652007-08-02 11:09:59 -04002074#define lpfc_vport_param_hex_show(attr) \
2075static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002076lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2077 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002078{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002079 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002080 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002081 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2082}
2083
James Smarte59058c2008-08-24 21:49:00 -04002084/**
James Smart3621a712009-04-06 18:47:14 -04002085 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002086 *
2087 * Description:
2088 * Macro that given an attr e.g. hba_queue_depth expands
2089 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2090 * takes a default argument, a minimum and maximum argument.
2091 *
2092 * lpfc_##attr##_init: validates the min and max values then sets the
2093 * adapter config field accordingly, or uses the default if out of range
2094 * and prints an error message.
2095 * @phba: pointer the the adapter structure.
2096 * @val: integer attribute value.
2097 *
2098 * Returns:
2099 * zero on success
2100 * -EINVAL if default used
2101 **/
James Smart3de2a652007-08-02 11:09:59 -04002102#define lpfc_vport_param_init(attr, default, minval, maxval) \
2103static int \
James Smart84d1b002010-02-12 14:42:33 -05002104lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002105{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002106 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart3de2a652007-08-02 11:09:59 -04002107 vport->cfg_##attr = val;\
2108 return 0;\
2109 }\
James Smarte8b62012007-08-02 11:10:09 -04002110 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002111 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002112 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002113 vport->cfg_##attr = default;\
2114 return -EINVAL;\
2115}
2116
James Smarte59058c2008-08-24 21:49:00 -04002117/**
James Smart3621a712009-04-06 18:47:14 -04002118 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002119 *
2120 * Description:
2121 * Macro that given an attr e.g. hba_queue_depth expands
2122 * into a function with the name lpfc_hba_queue_depth_set
2123 *
2124 * lpfc_##attr##_set: validates the min and max values then sets the
2125 * adapter config field if in the valid range. prints error message
2126 * and does not set the parameter if invalid.
2127 * @phba: pointer the the adapter structure.
2128 * @val: integer attribute value.
2129 *
2130 * Returns:
2131 * zero on success
2132 * -EINVAL if val is invalid
2133 **/
James Smart3de2a652007-08-02 11:09:59 -04002134#define lpfc_vport_param_set(attr, default, minval, maxval) \
2135static int \
James Smart84d1b002010-02-12 14:42:33 -05002136lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002137{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002138 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002139 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04002140 "3053 lpfc_" #attr \
2141 " changed from %d (x%x) to %d (x%x)\n", \
2142 vport->cfg_##attr, vport->cfg_##attr, \
2143 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04002144 vport->cfg_##attr = val;\
2145 return 0;\
2146 }\
James Smarte8b62012007-08-02 11:10:09 -04002147 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002148 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002149 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002150 return -EINVAL;\
2151}
2152
James Smarte59058c2008-08-24 21:49:00 -04002153/**
James Smart3621a712009-04-06 18:47:14 -04002154 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04002155 *
2156 * Description:
2157 * Macro that given an attr e.g. hba_queue_depth
2158 * expands into a function with the name lpfc_hba_queue_depth_store
2159 *
2160 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2161 * use the lpfc_##attr##_set function to set the value.
2162 * @cdev: class device that is converted into a Scsi_host.
2163 * @buf: contains the attribute value in decimal.
2164 * @count: not used.
2165 *
2166 * Returns:
2167 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2168 * length of buffer upon success.
2169 **/
James Smart3de2a652007-08-02 11:09:59 -04002170#define lpfc_vport_param_store(attr) \
2171static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002172lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2173 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04002174{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002175 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002176 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05002177 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04002178 if (!isdigit(buf[0]))\
2179 return -EINVAL;\
2180 if (sscanf(buf, "%i", &val) != 1)\
2181 return -EINVAL;\
2182 if (lpfc_##attr##_set(vport, val) == 0) \
2183 return strlen(buf);\
2184 else \
2185 return -EINVAL;\
2186}
2187
2188
James Smart895427b2017-02-12 13:52:30 -08002189static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
James Smart81301a92008-12-04 22:39:46 -05002190static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2191static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2192static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2193static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002194static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2195static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2196static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2197static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2198static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2199static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2200static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2201static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002202static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2203 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002204static DEVICE_ATTR(option_rom_version, S_IRUGO,
2205 lpfc_option_rom_version_show, NULL);
2206static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2207 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002208static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002209static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2210static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04002211static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002212static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2213 lpfc_board_mode_show, lpfc_board_mode_store);
2214static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2215static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2216static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2217static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2218static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2219static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2220static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2221static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2222static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04002223static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2224static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05002225static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04002226static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2227 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smart026abb82011-12-13 13:20:45 -05002228static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05002229static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2230 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002231
James Smart352e5fd2016-12-30 06:57:47 -08002232static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smart1ba981f2014-02-20 09:56:45 -05002233#define WWN_SZ 8
2234/**
2235 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2236 * @buf: WWN string.
2237 * @cnt: Length of string.
2238 * @wwn: Array to receive converted wwn value.
2239 *
2240 * Returns:
2241 * -EINVAL if the buffer does not contain a valid wwn
2242 * 0 success
2243 **/
2244static size_t
2245lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2246{
2247 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002248
James Smart1ba981f2014-02-20 09:56:45 -05002249 /* Count may include a LF at end of string */
2250 if (buf[cnt-1] == '\n')
2251 cnt--;
2252
2253 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2254 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2255 return -EINVAL;
2256
2257 memset(wwn, 0, WWN_SZ);
2258
2259 /* Validate and store the new name */
2260 for (i = 0, j = 0; i < 16; i++) {
2261 if ((*buf >= 'a') && (*buf <= 'f'))
2262 j = ((j << 4) | ((*buf++ - 'a') + 10));
2263 else if ((*buf >= 'A') && (*buf <= 'F'))
2264 j = ((j << 4) | ((*buf++ - 'A') + 10));
2265 else if ((*buf >= '0') && (*buf <= '9'))
2266 j = ((j << 4) | (*buf++ - '0'));
2267 else
2268 return -EINVAL;
2269 if (i % 2) {
2270 wwn[i/2] = j & 0xff;
2271 j = 0;
2272 }
2273 }
2274 return 0;
2275}
James Smart352e5fd2016-12-30 06:57:47 -08002276/**
2277 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2278 * @dev: class device that is converted into a Scsi_host.
2279 * @attr: device attribute, not used.
2280 * @buf: containing the string lpfc_soft_wwn_key.
2281 * @count: must be size of lpfc_soft_wwn_key.
2282 *
2283 * Returns:
2284 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2285 * length of buf indicates success
2286 **/
2287static ssize_t
2288lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2289 const char *buf, size_t count)
2290{
2291 struct Scsi_Host *shost = class_to_shost(dev);
2292 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2293 struct lpfc_hba *phba = vport->phba;
2294 unsigned int cnt = count;
2295
2296 /*
2297 * We're doing a simple sanity check for soft_wwpn setting.
2298 * We require that the user write a specific key to enable
2299 * the soft_wwpn attribute to be settable. Once the attribute
2300 * is written, the enable key resets. If further updates are
2301 * desired, the key must be written again to re-enable the
2302 * attribute.
2303 *
2304 * The "key" is not secret - it is a hardcoded string shown
2305 * here. The intent is to protect against the random user or
2306 * application that is just writing attributes.
2307 */
2308
2309 /* count may include a LF at end of string */
2310 if (buf[cnt-1] == '\n')
2311 cnt--;
2312
2313 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2314 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2315 return -EINVAL;
2316
2317 phba->soft_wwn_enable = 1;
2318
2319 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2320 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2321 phba->brd_no);
2322 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2323 " The soft_wwpn feature is not supported by Broadcom.");
2324
2325 return count;
2326}
2327static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2328 lpfc_soft_wwn_enable_store);
2329
2330/**
2331 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2332 * @dev: class device that is converted into a Scsi_host.
2333 * @attr: device attribute, not used.
2334 * @buf: on return contains the wwpn in hexadecimal.
2335 *
2336 * Returns: size of formatted string.
2337 **/
2338static ssize_t
2339lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2340 char *buf)
2341{
2342 struct Scsi_Host *shost = class_to_shost(dev);
2343 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2344 struct lpfc_hba *phba = vport->phba;
2345
2346 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2347 (unsigned long long)phba->cfg_soft_wwpn);
2348}
2349
2350/**
2351 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2352 * @dev class device that is converted into a Scsi_host.
2353 * @attr: device attribute, not used.
2354 * @buf: contains the wwpn in hexadecimal.
2355 * @count: number of wwpn bytes in buf
2356 *
2357 * Returns:
2358 * -EACCES hba reset not enabled, adapter over temp
2359 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2360 * -EIO error taking adapter offline or online
2361 * value of count on success
2362 **/
2363static ssize_t
2364lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2365 const char *buf, size_t count)
2366{
2367 struct Scsi_Host *shost = class_to_shost(dev);
2368 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2369 struct lpfc_hba *phba = vport->phba;
2370 struct completion online_compl;
2371 int stat1 = 0, stat2 = 0;
2372 unsigned int cnt = count;
2373 u8 wwpn[WWN_SZ];
2374 int rc;
2375
2376 if (!phba->cfg_enable_hba_reset)
2377 return -EACCES;
2378 spin_lock_irq(&phba->hbalock);
2379 if (phba->over_temp_state == HBA_OVER_TEMP) {
2380 spin_unlock_irq(&phba->hbalock);
2381 return -EACCES;
2382 }
2383 spin_unlock_irq(&phba->hbalock);
2384 /* count may include a LF at end of string */
2385 if (buf[cnt-1] == '\n')
2386 cnt--;
2387
2388 if (!phba->soft_wwn_enable)
2389 return -EINVAL;
2390
2391 /* lock setting wwpn, wwnn down */
2392 phba->soft_wwn_enable = 0;
2393
2394 rc = lpfc_wwn_set(buf, cnt, wwpn);
James Smarte2934ed2017-01-17 12:31:56 -08002395 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002396 /* not able to set wwpn, unlock it */
2397 phba->soft_wwn_enable = 1;
2398 return rc;
2399 }
2400
2401 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2402 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2403 if (phba->cfg_soft_wwnn)
2404 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2405
2406 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2407 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2408
2409 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2410 if (stat1)
2411 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2412 "0463 lpfc_soft_wwpn attribute set failed to "
2413 "reinit adapter - %d\n", stat1);
2414 init_completion(&online_compl);
2415 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2416 LPFC_EVT_ONLINE);
2417 if (rc == 0)
2418 return -ENOMEM;
2419
2420 wait_for_completion(&online_compl);
2421 if (stat2)
2422 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2423 "0464 lpfc_soft_wwpn attribute set failed to "
2424 "reinit adapter - %d\n", stat2);
2425 return (stat1 || stat2) ? -EIO : count;
2426}
2427static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
2428 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2429
2430/**
2431 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2432 * @dev: class device that is converted into a Scsi_host.
2433 * @attr: device attribute, not used.
2434 * @buf: on return contains the wwnn in hexadecimal.
2435 *
2436 * Returns: size of formatted string.
2437 **/
2438static ssize_t
2439lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2440 char *buf)
2441{
2442 struct Scsi_Host *shost = class_to_shost(dev);
2443 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2444 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2445 (unsigned long long)phba->cfg_soft_wwnn);
2446}
2447
2448/**
2449 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2450 * @cdev: class device that is converted into a Scsi_host.
2451 * @buf: contains the ww node name in hexadecimal.
2452 * @count: number of wwnn bytes in buf.
2453 *
2454 * Returns:
2455 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2456 * value of count on success
2457 **/
2458static ssize_t
2459lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2460 const char *buf, size_t count)
2461{
2462 struct Scsi_Host *shost = class_to_shost(dev);
2463 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2464 unsigned int cnt = count;
2465 u8 wwnn[WWN_SZ];
2466 int rc;
2467
2468 /* count may include a LF at end of string */
2469 if (buf[cnt-1] == '\n')
2470 cnt--;
2471
2472 if (!phba->soft_wwn_enable)
2473 return -EINVAL;
2474
2475 rc = lpfc_wwn_set(buf, cnt, wwnn);
James Smarte2934ed2017-01-17 12:31:56 -08002476 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002477 /* Allow wwnn to be set many times, as long as the enable
2478 * is set. However, once the wwpn is set, everything locks.
2479 */
2480 return rc;
2481 }
2482
2483 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2484
2485 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2486 "lpfc%d: soft_wwnn set. Value will take effect upon "
2487 "setting of the soft_wwpn\n", phba->brd_no);
2488
2489 return count;
2490}
2491static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
2492 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002493
James Smart1ba981f2014-02-20 09:56:45 -05002494/**
2495 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2496 * Optimized Access Storage (OAS) operations.
2497 * @dev: class device that is converted into a Scsi_host.
2498 * @attr: device attribute, not used.
2499 * @buf: buffer for passing information.
2500 *
2501 * Returns:
2502 * value of count
2503 **/
2504static ssize_t
2505lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2506 char *buf)
2507{
2508 struct Scsi_Host *shost = class_to_shost(dev);
2509 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2510
2511 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2512 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2513}
2514
2515/**
2516 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2517 * Optimized Access Storage (OAS) operations.
2518 * @dev: class device that is converted into a Scsi_host.
2519 * @attr: device attribute, not used.
2520 * @buf: buffer for passing information.
2521 * @count: Size of the data buffer.
2522 *
2523 * Returns:
2524 * -EINVAL count is invalid, invalid wwpn byte invalid
2525 * -EPERM oas is not supported by hba
2526 * value of count on success
2527 **/
2528static ssize_t
2529lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2530 const char *buf, size_t count)
2531{
2532 struct Scsi_Host *shost = class_to_shost(dev);
2533 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2534 unsigned int cnt = count;
2535 uint8_t wwpn[WWN_SZ];
2536 int rc;
2537
James Smartf38fa0b2014-04-04 13:52:21 -04002538 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002539 return -EPERM;
2540
2541 /* count may include a LF at end of string */
2542 if (buf[cnt-1] == '\n')
2543 cnt--;
2544
2545 rc = lpfc_wwn_set(buf, cnt, wwpn);
2546 if (rc)
2547 return rc;
2548
2549 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2550 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2551 if (wwn_to_u64(wwpn) == 0)
2552 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2553 else
2554 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2555 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2556 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2557 return count;
2558}
2559static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2560 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2561
2562/**
James Smartc92c8412016-07-06 12:36:05 -07002563 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2564 * Optimized Access Storage (OAS) operations.
2565 * @dev: class device that is converted into a Scsi_host.
2566 * @attr: device attribute, not used.
2567 * @buf: buffer for passing information.
2568 *
2569 * Returns:
2570 * value of count
2571 **/
2572static ssize_t
2573lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2574 char *buf)
2575{
2576 struct Scsi_Host *shost = class_to_shost(dev);
2577 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2578
2579 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2580}
2581
2582/**
2583 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2584 * Optimized Access Storage (OAS) operations.
2585 * @dev: class device that is converted into a Scsi_host.
2586 * @attr: device attribute, not used.
2587 * @buf: buffer for passing information.
2588 * @count: Size of the data buffer.
2589 *
2590 * Returns:
2591 * -EINVAL count is invalid, invalid wwpn byte invalid
2592 * -EPERM oas is not supported by hba
2593 * value of count on success
2594 **/
2595static ssize_t
2596lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2597 const char *buf, size_t count)
2598{
2599 struct Scsi_Host *shost = class_to_shost(dev);
2600 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2601 unsigned int cnt = count;
2602 unsigned long val;
2603 int ret;
2604
2605 if (!phba->cfg_fof)
2606 return -EPERM;
2607
2608 /* count may include a LF at end of string */
2609 if (buf[cnt-1] == '\n')
2610 cnt--;
2611
2612 ret = kstrtoul(buf, 0, &val);
2613 if (ret || (val > 0x7f))
2614 return -EINVAL;
2615
2616 if (val)
2617 phba->cfg_oas_priority = (uint8_t)val;
2618 else
2619 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2620 return count;
2621}
2622static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2623 lpfc_oas_priority_show, lpfc_oas_priority_store);
2624
2625/**
James Smart1ba981f2014-02-20 09:56:45 -05002626 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2627 * for Optimized Access Storage (OAS) operations.
2628 * @dev: class device that is converted into a Scsi_host.
2629 * @attr: device attribute, not used.
2630 * @buf: buffer for passing information.
2631 *
2632 * Returns:
2633 * value of count on success
2634 **/
2635static ssize_t
2636lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2637 char *buf)
2638{
2639 struct Scsi_Host *shost = class_to_shost(dev);
2640 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2641
2642 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2643 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2644}
2645
2646/**
2647 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2648 * for Optimized Access Storage (OAS) operations.
2649 * @dev: class device that is converted into a Scsi_host.
2650 * @attr: device attribute, not used.
2651 * @buf: buffer for passing information.
2652 * @count: Size of the data buffer.
2653 *
2654 * Returns:
2655 * -EINVAL count is invalid, invalid wwpn byte invalid
2656 * -EPERM oas is not supported by hba
2657 * value of count on success
2658 **/
2659static ssize_t
2660lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2661 const char *buf, size_t count)
2662{
2663 struct Scsi_Host *shost = class_to_shost(dev);
2664 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2665 unsigned int cnt = count;
2666 uint8_t wwpn[WWN_SZ];
2667 int rc;
2668
James Smartf38fa0b2014-04-04 13:52:21 -04002669 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002670 return -EPERM;
2671
2672 /* count may include a LF at end of string */
2673 if (buf[cnt-1] == '\n')
2674 cnt--;
2675
2676 rc = lpfc_wwn_set(buf, cnt, wwpn);
2677 if (rc)
2678 return rc;
2679
2680 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2681 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2682 if (wwn_to_u64(wwpn) == 0)
2683 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2684 else
2685 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2686 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
James Smartb5749fe2016-12-19 15:07:26 -08002687 if (phba->cfg_oas_priority == 0)
2688 phba->cfg_oas_priority = phba->cfg_XLanePriority;
James Smart1ba981f2014-02-20 09:56:45 -05002689 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2690 return count;
2691}
2692static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2693 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2694
2695/**
2696 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2697 * of whether luns will be enabled or disabled
2698 * for Optimized Access Storage (OAS) operations.
2699 * @dev: class device that is converted into a Scsi_host.
2700 * @attr: device attribute, not used.
2701 * @buf: buffer for passing information.
2702 *
2703 * Returns:
2704 * size of formatted string.
2705 **/
2706static ssize_t
2707lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2708 char *buf)
2709{
2710 struct Scsi_Host *shost = class_to_shost(dev);
2711 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2712
2713 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2714}
2715
2716/**
2717 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2718 * of whether luns will be enabled or disabled
2719 * for Optimized Access Storage (OAS) operations.
2720 * @dev: class device that is converted into a Scsi_host.
2721 * @attr: device attribute, not used.
2722 * @buf: buffer for passing information.
2723 * @count: Size of the data buffer.
2724 *
2725 * Returns:
2726 * -EINVAL count is invalid, invalid wwpn byte invalid
2727 * -EPERM oas is not supported by hba
2728 * value of count on success
2729 **/
2730static ssize_t
2731lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2732 const char *buf, size_t count)
2733{
2734 struct Scsi_Host *shost = class_to_shost(dev);
2735 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2736 int val = 0;
2737
James Smartf38fa0b2014-04-04 13:52:21 -04002738 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002739 return -EPERM;
2740
2741 if (!isdigit(buf[0]))
2742 return -EINVAL;
2743
2744 if (sscanf(buf, "%i", &val) != 1)
2745 return -EINVAL;
2746
2747 if ((val != 0) && (val != 1))
2748 return -EINVAL;
2749
2750 phba->cfg_oas_lun_state = val;
James Smart1ba981f2014-02-20 09:56:45 -05002751 return strlen(buf);
2752}
2753static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2754 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2755
2756/**
2757 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2758 * Storage (OAS) lun returned by the
2759 * lpfc_oas_lun_show function.
2760 * @dev: class device that is converted into a Scsi_host.
2761 * @attr: device attribute, not used.
2762 * @buf: buffer for passing information.
2763 *
2764 * Returns:
2765 * size of formatted string.
2766 **/
2767static ssize_t
2768lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2769 char *buf)
2770{
2771 struct Scsi_Host *shost = class_to_shost(dev);
2772 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2773
2774 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2775 return -EFAULT;
2776
2777 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2778}
2779static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2780 lpfc_oas_lun_status_show, NULL);
2781
2782
2783/**
2784 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2785 * (OAS) operations.
2786 * @phba: lpfc_hba pointer.
2787 * @ndlp: pointer to fcp target node.
2788 * @lun: the fc lun for setting oas state.
2789 * @oas_state: the oas state to be set to the lun.
2790 *
2791 * Returns:
2792 * SUCCESS : 0
2793 * -EPERM OAS is not enabled or not supported by this port.
2794 *
2795 */
2796static size_t
2797lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartc92c8412016-07-06 12:36:05 -07002798 uint8_t tgt_wwpn[], uint64_t lun,
2799 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002800{
2801
2802 int rc = 0;
2803
James Smartf38fa0b2014-04-04 13:52:21 -04002804 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002805 return -EPERM;
2806
2807 if (oas_state) {
2808 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002809 (struct lpfc_name *)tgt_wwpn,
2810 lun, pri))
James Smart1ba981f2014-02-20 09:56:45 -05002811 rc = -ENOMEM;
2812 } else {
2813 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002814 (struct lpfc_name *)tgt_wwpn, lun, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002815 }
2816 return rc;
2817
2818}
2819
2820/**
2821 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2822 * Access Storage (OAS) operations.
2823 * @phba: lpfc_hba pointer.
2824 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2825 * @tgt_wwpn: wwpn of the target associated with the returned lun
2826 * @lun_status: status of the lun returned lun
2827 *
2828 * Returns the first or next lun enabled for OAS operations for the vport/target
2829 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2830 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2831 *
2832 * Return:
2833 * lun that is OAS enabled for the vport/target
2834 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2835 */
2836static uint64_t
2837lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartb5749fe2016-12-19 15:07:26 -08002838 uint8_t tgt_wwpn[], uint32_t *lun_status,
2839 uint32_t *lun_pri)
James Smart1ba981f2014-02-20 09:56:45 -05002840{
2841 uint64_t found_lun;
2842
2843 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2844 return NOT_OAS_ENABLED_LUN;
2845 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2846 phba->sli4_hba.oas_next_vpt_wwpn,
2847 (struct lpfc_name *)
2848 phba->sli4_hba.oas_next_tgt_wwpn,
2849 &phba->sli4_hba.oas_next_lun,
2850 (struct lpfc_name *)vpt_wwpn,
2851 (struct lpfc_name *)tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002852 &found_lun, lun_status, lun_pri))
James Smart1ba981f2014-02-20 09:56:45 -05002853 return found_lun;
2854 else
2855 return NOT_OAS_ENABLED_LUN;
2856}
2857
2858/**
2859 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2860 * @phba: lpfc_hba pointer.
2861 * @vpt_wwpn: vport wwpn by reference.
2862 * @tgt_wwpn: target wwpn by reference.
2863 * @lun: the fc lun for setting oas state.
2864 * @oas_state: the oas state to be set to the oas_lun.
2865 *
2866 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2867 * a lun for OAS operations.
2868 *
2869 * Return:
2870 * SUCCESS: 0
2871 * -ENOMEM: failed to enable an lun for OAS operations
2872 * -EPERM: OAS is not enabled
2873 */
2874static ssize_t
2875lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2876 uint8_t tgt_wwpn[], uint64_t lun,
James Smartc92c8412016-07-06 12:36:05 -07002877 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002878{
2879
2880 int rc;
2881
2882 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
James Smartc92c8412016-07-06 12:36:05 -07002883 oas_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002884 return rc;
2885}
2886
2887/**
2888 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2889 * @dev: class device that is converted into a Scsi_host.
2890 * @attr: device attribute, not used.
2891 * @buf: buffer for passing information.
2892 *
2893 * This routine returns a lun enabled for OAS each time the function
2894 * is called.
2895 *
2896 * Returns:
2897 * SUCCESS: size of formatted string.
2898 * -EFAULT: target or vport wwpn was not set properly.
2899 * -EPERM: oas is not enabled.
2900 **/
2901static ssize_t
2902lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2903 char *buf)
2904{
2905 struct Scsi_Host *shost = class_to_shost(dev);
2906 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2907
2908 uint64_t oas_lun;
2909 int len = 0;
2910
James Smartf38fa0b2014-04-04 13:52:21 -04002911 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002912 return -EPERM;
2913
2914 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2915 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2916 return -EFAULT;
2917
2918 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2919 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2920 return -EFAULT;
2921
2922 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2923 phba->cfg_oas_tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002924 &phba->cfg_oas_lun_status,
2925 &phba->cfg_oas_priority);
James Smart1ba981f2014-02-20 09:56:45 -05002926 if (oas_lun != NOT_OAS_ENABLED_LUN)
2927 phba->cfg_oas_flags |= OAS_LUN_VALID;
2928
2929 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2930
2931 return len;
2932}
2933
2934/**
2935 * lpfc_oas_lun_store - Sets the OAS state for lun
2936 * @dev: class device that is converted into a Scsi_host.
2937 * @attr: device attribute, not used.
2938 * @buf: buffer for passing information.
2939 *
2940 * This function sets the OAS state for lun. Before this function is called,
2941 * the vport wwpn, target wwpn, and oas state need to be set.
2942 *
2943 * Returns:
2944 * SUCCESS: size of formatted string.
2945 * -EFAULT: target or vport wwpn was not set properly.
2946 * -EPERM: oas is not enabled.
2947 * size of formatted string.
2948 **/
2949static ssize_t
2950lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2951 const char *buf, size_t count)
2952{
2953 struct Scsi_Host *shost = class_to_shost(dev);
2954 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2955 uint64_t scsi_lun;
James Smartb5749fe2016-12-19 15:07:26 -08002956 uint32_t pri;
James Smart1ba981f2014-02-20 09:56:45 -05002957 ssize_t rc;
2958
James Smartf38fa0b2014-04-04 13:52:21 -04002959 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002960 return -EPERM;
2961
2962 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2963 return -EFAULT;
2964
2965 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2966 return -EFAULT;
2967
2968 if (!isdigit(buf[0]))
2969 return -EINVAL;
2970
2971 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
2972 return -EINVAL;
2973
James Smartb5749fe2016-12-19 15:07:26 -08002974 pri = phba->cfg_oas_priority;
2975 if (pri == 0)
2976 pri = phba->cfg_XLanePriority;
2977
James Smart1ba981f2014-02-20 09:56:45 -05002978 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartc92c8412016-07-06 12:36:05 -07002979 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
2980 "priority 0x%x with oas state %d\n",
James Smart1ba981f2014-02-20 09:56:45 -05002981 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
2982 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08002983 pri, phba->cfg_oas_lun_state);
James Smart1ba981f2014-02-20 09:56:45 -05002984
2985 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002986 phba->cfg_oas_tgt_wwpn, scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08002987 phba->cfg_oas_lun_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002988 if (rc)
2989 return rc;
2990
2991 return count;
2992}
2993static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
2994 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04002995
James Smartf358dd02017-02-12 13:52:34 -08002996int lpfc_enable_nvmet_cnt;
2997unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
2998 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2999 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3000module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3001MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3002
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003003static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05003004module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003005MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3006 " 0 - none,"
3007 " 1 - poll with interrupts enabled"
3008 " 3 - poll and disable FCP ring interrupts");
3009
Tony Jonesee959b02008-02-22 00:13:36 +01003010static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
3011 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05003012
James Smart96418b52017-03-04 09:30:31 -08003013int lpfc_no_hba_reset_cnt;
3014unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3015 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3016module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3017MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3018
James Smart12247e82016-07-06 12:36:09 -07003019LPFC_ATTR(sli_mode, 0, 0, 3,
3020 "SLI mode selector:"
3021 " 0 - auto (SLI-3 if supported),"
3022 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3023 " 3 - select SLI-3");
James Smart92d7f7b2007-06-17 19:56:38 -05003024
James Smart458c0832016-07-06 12:36:07 -07003025LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3026 "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05003027
James Smart7d791df2011-07-22 18:37:52 -04003028LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3029 "FCF Fast failover=1 Priority failover=2");
3030
James Smarte5771b42013-03-01 16:37:14 -05003031/*
3032# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3033# 0x0 = disabled, XRI/OXID use not tracked.
3034# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3035# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3036*/
James Smart31202b02016-10-13 15:06:08 -07003037LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3038 "Enable RRQ functionality");
James Smart19ca7602010-11-20 23:11:55 -05003039
dea31012005-04-17 16:05:31 -05003040/*
James Smart84d1b002010-02-12 14:42:33 -05003041# lpfc_suppress_link_up: Bring link up at initialization
3042# 0x0 = bring link up (issue MBX_INIT_LINK)
3043# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3044# 0x2 = never bring up link
3045# Default value is 0.
3046*/
James Smarte40a02c2010-02-26 14:13:54 -05003047LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3048 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3049 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04003050/*
3051# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3052# 1 - (1024)
3053# 2 - (2048)
3054# 3 - (3072)
3055# 4 - (4096)
3056# 5 - (5120)
3057*/
3058static ssize_t
3059lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3060{
3061 struct Scsi_Host *shost = class_to_shost(dev);
3062 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3063
3064 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3065}
3066
3067static DEVICE_ATTR(iocb_hw, S_IRUGO,
3068 lpfc_iocb_hw_show, NULL);
3069static ssize_t
3070lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3071{
3072 struct Scsi_Host *shost = class_to_shost(dev);
3073 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003074 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003075
James Smart895427b2017-02-12 13:52:30 -08003076 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txq_max);
James Smart2a9bf3d2010-06-07 15:24:45 -04003077}
3078
3079static DEVICE_ATTR(txq_hw, S_IRUGO,
3080 lpfc_txq_hw_show, NULL);
3081static ssize_t
3082lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3083 char *buf)
3084{
3085 struct Scsi_Host *shost = class_to_shost(dev);
3086 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003087 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003088
James Smart895427b2017-02-12 13:52:30 -08003089 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txcmplq_max);
James Smart2a9bf3d2010-06-07 15:24:45 -04003090}
3091
3092static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3093 lpfc_txcmplq_hw_show, NULL);
3094
James Smart0d8c8ba2016-10-13 15:06:07 -07003095LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
James Smart2a9bf3d2010-06-07 15:24:45 -04003096 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
James Smart84d1b002010-02-12 14:42:33 -05003097
3098/*
James Smartc01f3202006-08-18 17:47:08 -04003099# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3100# until the timer expires. Value range is [0,255]. Default value is 30.
3101*/
3102static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3103static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3104module_param(lpfc_nodev_tmo, int, 0);
3105MODULE_PARM_DESC(lpfc_nodev_tmo,
3106 "Seconds driver will hold I/O waiting "
3107 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04003108
3109/**
James Smart3621a712009-04-06 18:47:14 -04003110 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04003111 * @dev: class converted to a Scsi_host structure.
3112 * @attr: device attribute, not used.
3113 * @buf: on return contains the dev loss timeout in decimal.
3114 *
3115 * Returns: size of formatted string.
3116 **/
James Smartc01f3202006-08-18 17:47:08 -04003117static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003118lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3119 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04003120{
Tony Jonesee959b02008-02-22 00:13:36 +01003121 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003122 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05003123
James Smart3de2a652007-08-02 11:09:59 -04003124 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003125}
3126
James Smarte59058c2008-08-24 21:49:00 -04003127/**
James Smart3621a712009-04-06 18:47:14 -04003128 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04003129 * @vport: lpfc vport structure pointer.
3130 * @val: contains the nodev timeout value.
3131 *
3132 * Description:
3133 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3134 * a kernel error message is printed and zero is returned.
3135 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3136 * Otherwise nodev tmo is set to the default value.
3137 *
3138 * Returns:
3139 * zero if already set or if val is in range
3140 * -EINVAL val out of range
3141 **/
James Smartc01f3202006-08-18 17:47:08 -04003142static int
James Smart3de2a652007-08-02 11:09:59 -04003143lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003144{
James Smart3de2a652007-08-02 11:09:59 -04003145 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3146 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3147 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04003148 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003149 "0407 Ignoring lpfc_nodev_tmo module "
3150 "parameter because lpfc_devloss_tmo "
3151 "is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003152 return 0;
3153 }
3154
3155 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003156 vport->cfg_nodev_tmo = val;
3157 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04003158 return 0;
3159 }
James Smarte8b62012007-08-02 11:10:09 -04003160 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3161 "0400 lpfc_nodev_tmo attribute cannot be set to"
3162 " %d, allowed range is [%d, %d]\n",
3163 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04003164 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04003165 return -EINVAL;
3166}
3167
James Smarte59058c2008-08-24 21:49:00 -04003168/**
James Smart3621a712009-04-06 18:47:14 -04003169 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04003170 * @vport: lpfc vport structure pointer.
3171 *
3172 * Description:
3173 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3174 **/
James Smart7054a602007-04-25 09:52:34 -04003175static void
James Smart3de2a652007-08-02 11:09:59 -04003176lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04003177{
James Smart858c9f62007-06-17 19:56:39 -05003178 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04003179 struct lpfc_nodelist *ndlp;
3180
James Smart51ef4c22007-08-02 11:10:31 -04003181 shost = lpfc_shost_from_vport(vport);
3182 spin_lock_irq(shost->host_lock);
3183 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05003184 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04003185 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3186 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04003187}
3188
James Smarte59058c2008-08-24 21:49:00 -04003189/**
James Smart3621a712009-04-06 18:47:14 -04003190 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04003191 * @vport: lpfc vport structure pointer.
3192 * @val: contains the tmo value.
3193 *
3194 * Description:
3195 * If the devloss tmo is already set or the vport dev loss tmo has changed
3196 * then a kernel error message is printed and zero is returned.
3197 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3198 * Otherwise nodev tmo is set to the default value.
3199 *
3200 * Returns:
3201 * zero if already set or if val is in range
3202 * -EINVAL val out of range
3203 **/
James Smartc01f3202006-08-18 17:47:08 -04003204static int
James Smart3de2a652007-08-02 11:09:59 -04003205lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003206{
James Smart3de2a652007-08-02 11:09:59 -04003207 if (vport->dev_loss_tmo_changed ||
3208 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04003209 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003210 "0401 Ignoring change to lpfc_nodev_tmo "
3211 "because lpfc_devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003212 return 0;
3213 }
James Smartc01f3202006-08-18 17:47:08 -04003214 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003215 vport->cfg_nodev_tmo = val;
3216 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05003217 /*
3218 * For compat: set the fc_host dev loss so new rports
3219 * will get the value.
3220 */
3221 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003222 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003223 return 0;
3224 }
James Smarte8b62012007-08-02 11:10:09 -04003225 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003226 "0403 lpfc_nodev_tmo attribute cannot be set to "
James Smarte8b62012007-08-02 11:10:09 -04003227 "%d, allowed range is [%d, %d]\n",
3228 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003229 return -EINVAL;
3230}
3231
James Smart3de2a652007-08-02 11:09:59 -04003232lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04003233
Tony Jonesee959b02008-02-22 00:13:36 +01003234static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3235 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003236
3237/*
3238# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3239# disappear until the timer expires. Value range is [0,255]. Default
3240# value is 30.
3241*/
James Smartab56dc22011-02-16 12:39:57 -05003242module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04003243MODULE_PARM_DESC(lpfc_devloss_tmo,
3244 "Seconds driver will hold I/O waiting "
3245 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04003246lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3247 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3248lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04003249
3250/**
James Smart3621a712009-04-06 18:47:14 -04003251 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04003252 * @vport: lpfc vport structure pointer.
3253 * @val: contains the tmo value.
3254 *
3255 * Description:
3256 * If val is in a valid range then set the vport nodev tmo,
3257 * devloss tmo, also set the vport dev loss tmo changed flag.
3258 * Else a kernel error message is printed.
3259 *
3260 * Returns:
3261 * zero if val is in range
3262 * -EINVAL val out of range
3263 **/
James Smartc01f3202006-08-18 17:47:08 -04003264static int
James Smart3de2a652007-08-02 11:09:59 -04003265lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003266{
3267 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003268 vport->cfg_nodev_tmo = val;
3269 vport->cfg_devloss_tmo = val;
3270 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05003271 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003272 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003273 return 0;
3274 }
3275
James Smarte8b62012007-08-02 11:10:09 -04003276 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003277 "0404 lpfc_devloss_tmo attribute cannot be set to "
3278 "%d, allowed range is [%d, %d]\n",
James Smarte8b62012007-08-02 11:10:09 -04003279 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003280 return -EINVAL;
3281}
3282
James Smart3de2a652007-08-02 11:09:59 -04003283lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01003284static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3285 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003286
3287/*
James Smartf358dd02017-02-12 13:52:34 -08003288 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3289 * lpfc_suppress_rsp = 0 Disable
3290 * lpfc_suppress_rsp = 1 Enable (default)
3291 *
3292 */
3293LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3294 "Enable suppress rsp feature is firmware supports it");
3295
3296/*
James Smart2d7dbc42017-02-12 13:52:35 -08003297 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3298 * lpfc_nvmet_mrq = 1 use a single RQ pair
3299 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3300 *
3301 */
3302LPFC_ATTR_R(nvmet_mrq,
3303 1, 1, 16,
3304 "Specify number of RQ pairs for processing NVMET cmds");
3305
3306/*
3307 * lpfc_nvmet_mrq_post: Specify number buffers to post on every MRQ
3308 *
3309 */
3310LPFC_ATTR_R(nvmet_mrq_post, LPFC_DEF_MRQ_POST,
3311 LPFC_MIN_MRQ_POST, LPFC_MAX_MRQ_POST,
3312 "Specify number of buffers to post on every MRQ");
3313
3314/*
James Smart895427b2017-02-12 13:52:30 -08003315 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3316 * Supported Values: 1 - register just FCP
3317 * 3 - register both FCP and NVME
3318 * Supported values are [1,3]. Default value is 3
3319 */
3320LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_BOTH,
3321 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3322 "Define fc4 type to register with fabric.");
3323
3324/*
3325 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3326 * This parameter is only used if:
James Smartf358dd02017-02-12 13:52:34 -08003327 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3328 * port is not configured for NVMET.
James Smart895427b2017-02-12 13:52:30 -08003329 *
3330 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3331 * The remaining XRIs get split up based on lpfc_xri_split per port:
3332 *
3333 * Supported Values are in percentages
3334 * the xri_split value is the percentage the SCSI port will get. The remaining
3335 * percentage will go to NVME.
3336 */
3337LPFC_ATTR_R(xri_split, 50, 10, 90,
3338 "Division of XRI resources between SCSI and NVME");
3339
3340/*
dea31012005-04-17 16:05:31 -05003341# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3342# deluged with LOTS of information.
3343# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04003344# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05003345*/
James Smartf4b4c682009-05-22 14:53:12 -04003346LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04003347 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05003348
3349/*
James Smart7ee5d432007-10-27 13:37:17 -04003350# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3351# objects that have been registered with the nameserver after login.
3352*/
James Smartcf971242012-03-01 22:37:32 -05003353LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04003354 "Deregister nameserver objects before LOGO");
3355
3356/*
dea31012005-04-17 16:05:31 -05003357# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04003358# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3359# If this parameter value is greater than 1/8th the maximum number of exchanges
3360# supported by the HBA port, then the lun queue depth will be reduced to
3361# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05003362*/
James Smart572709e2013-07-15 18:32:43 -04003363LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04003364 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05003365
3366/*
James Smart7dc517d2010-07-14 15:32:10 -04003367# tgt_queue_depth: This parameter is used to limit the number of outstanding
3368# commands per target port. Value range is [10,65535]. Default value is 65535.
3369*/
3370LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
James Smart572709e2013-07-15 18:32:43 -04003371 "Max number of FCP commands we can queue to a specific target port");
James Smart7dc517d2010-07-14 15:32:10 -04003372
3373/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003374# hba_queue_depth: This parameter is used to limit the number of outstanding
3375# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3376# value is greater than the maximum number of exchanges supported by the HBA,
3377# then maximum number of exchanges supported by the HBA is used to determine
3378# the hba_queue_depth.
3379*/
3380LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3381 "Max number of FCP commands we can queue to a lpfc HBA");
3382
3383/*
James Smart92d7f7b2007-06-17 19:56:38 -05003384# peer_port_login: This parameter allows/prevents logins
3385# between peer ports hosted on the same physical port.
3386# When this parameter is set 0 peer ports of same physical port
3387# are not allowed to login to each other.
3388# When this parameter is set 1 peer ports of same physical port
3389# are allowed to login to each other.
3390# Default value of this parameter is 0.
3391*/
James Smart3de2a652007-08-02 11:09:59 -04003392LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3393 "Allow peer ports on the same physical port to login to each "
3394 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05003395
3396/*
James Smart3de2a652007-08-02 11:09:59 -04003397# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05003398# between Virtual Ports and remote initiators.
3399# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3400# other initiators and will attempt to PLOGI all remote ports.
3401# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3402# remote ports and will not attempt to PLOGI to other initiators.
3403# This parameter does not restrict to the physical port.
3404# This parameter does not restrict logins to Fabric resident remote ports.
3405# Default value of this parameter is 1.
3406*/
James Smart3de2a652007-08-02 11:09:59 -04003407static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05003408module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04003409MODULE_PARM_DESC(lpfc_restrict_login,
3410 "Restrict virtual ports login to remote initiators.");
3411lpfc_vport_param_show(restrict_login);
3412
James Smarte59058c2008-08-24 21:49:00 -04003413/**
James Smart3621a712009-04-06 18:47:14 -04003414 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003415 * @vport: lpfc vport structure pointer.
3416 * @val: contains the restrict login value.
3417 *
3418 * Description:
3419 * If val is not in a valid range then log a kernel error message and set
3420 * the vport restrict login to one.
3421 * If the port type is physical clear the restrict login flag and return.
3422 * Else set the restrict login flag to val.
3423 *
3424 * Returns:
3425 * zero if val is in range
3426 * -EINVAL val out of range
3427 **/
James Smart3de2a652007-08-02 11:09:59 -04003428static int
3429lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3430{
3431 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003432 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003433 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003434 "be set to %d, allowed range is [0, 1]\n",
3435 val);
James Smart3de2a652007-08-02 11:09:59 -04003436 vport->cfg_restrict_login = 1;
3437 return -EINVAL;
3438 }
3439 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3440 vport->cfg_restrict_login = 0;
3441 return 0;
3442 }
3443 vport->cfg_restrict_login = val;
3444 return 0;
3445}
3446
James Smarte59058c2008-08-24 21:49:00 -04003447/**
James Smart3621a712009-04-06 18:47:14 -04003448 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003449 * @vport: lpfc vport structure pointer.
3450 * @val: contains the restrict login value.
3451 *
3452 * Description:
3453 * If val is not in a valid range then log a kernel error message and set
3454 * the vport restrict login to one.
3455 * If the port type is physical and the val is not zero log a kernel
3456 * error message, clear the restrict login flag and return zero.
3457 * Else set the restrict login flag to val.
3458 *
3459 * Returns:
3460 * zero if val is in range
3461 * -EINVAL val out of range
3462 **/
James Smart3de2a652007-08-02 11:09:59 -04003463static int
3464lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3465{
3466 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003467 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003468 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003469 "be set to %d, allowed range is [0, 1]\n",
3470 val);
James Smart3de2a652007-08-02 11:09:59 -04003471 vport->cfg_restrict_login = 1;
3472 return -EINVAL;
3473 }
3474 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04003475 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3476 "0468 lpfc_restrict_login must be 0 for "
3477 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04003478 vport->cfg_restrict_login = 0;
3479 return 0;
3480 }
3481 vport->cfg_restrict_login = val;
3482 return 0;
3483}
3484lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01003485static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3486 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05003487
3488/*
dea31012005-04-17 16:05:31 -05003489# Some disk devices have a "select ID" or "select Target" capability.
3490# From a protocol standpoint "select ID" usually means select the
3491# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3492# annex" which contains a table that maps a "select ID" (a number
3493# between 0 and 7F) to an ALPA. By default, for compatibility with
3494# older drivers, the lpfc driver scans this table from low ALPA to high
3495# ALPA.
3496#
3497# Turning on the scan-down variable (on = 1, off = 0) will
3498# cause the lpfc driver to use an inverted table, effectively
3499# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3500#
3501# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3502# and will not work across a fabric. Also this parameter will take
3503# effect only in the case when ALPA map is not available.)
3504*/
James Smart3de2a652007-08-02 11:09:59 -04003505LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3506 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05003507
3508/*
dea31012005-04-17 16:05:31 -05003509# lpfc_topology: link topology for init link
3510# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05003511# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05003512# 0x02 = attempt point-to-point mode only
3513# 0x04 = attempt loop mode only
3514# 0x06 = attempt point-to-point mode then loop
3515# Set point-to-point mode if you want to run as an N_Port.
3516# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3517# Default value is 0.
3518*/
James Smart0a035432016-10-13 15:06:10 -07003519LPFC_ATTR(topology, 0, 0, 6,
3520 "Select Fibre Channel topology");
James Smarte59058c2008-08-24 21:49:00 -04003521
3522/**
James Smart3621a712009-04-06 18:47:14 -04003523 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04003524 * @phba: lpfc_hba pointer.
3525 * @val: topology value.
3526 *
3527 * Description:
3528 * If val is in a valid range then set the adapter's topology field and
3529 * issue a lip; if the lip fails reset the topology to the old value.
3530 *
3531 * If the value is not in range log a kernel error message and return an error.
3532 *
3533 * Returns:
3534 * zero if val is in range and lip okay
3535 * non-zero return value from lpfc_issue_lip()
3536 * -EINVAL val out of range
3537 **/
James Smarta257bf92009-04-06 18:48:10 -04003538static ssize_t
3539lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3540 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003541{
James Smarta257bf92009-04-06 18:48:10 -04003542 struct Scsi_Host *shost = class_to_shost(dev);
3543 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3544 struct lpfc_hba *phba = vport->phba;
3545 int val = 0;
3546 int nolip = 0;
3547 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003548 int err;
3549 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003550
3551 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3552 nolip = 1;
3553 val_buf = &buf[strlen("nolip ")];
3554 }
3555
3556 if (!isdigit(val_buf[0]))
3557 return -EINVAL;
3558 if (sscanf(val_buf, "%i", &val) != 1)
3559 return -EINVAL;
3560
James Smart83108bd2008-01-11 01:53:09 -05003561 if (val >= 0 && val <= 6) {
3562 prev_val = phba->cfg_topology;
James Smartff78d8f2011-12-13 13:21:35 -05003563 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3564 val == 4) {
3565 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3566 "3113 Loop mode not supported at speed %d\n",
James Smartd38dd522015-08-31 16:48:17 -04003567 val);
James Smartff78d8f2011-12-13 13:21:35 -05003568 return -EINVAL;
3569 }
James Smartd38dd522015-08-31 16:48:17 -04003570 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3571 val == 4) {
3572 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3573 "3114 Loop mode not supported\n");
3574 return -EINVAL;
3575 }
3576 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04003577 if (nolip)
3578 return strlen(buf);
3579
James Smart88a2cfb2011-07-22 18:36:33 -04003580 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3581 "3054 lpfc_topology changed from %d to %d\n",
3582 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04003583 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3584 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05003585 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003586 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003587 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003588 return -EINVAL;
3589 } else
3590 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003591 }
3592 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3593 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3594 "allowed range is [0, 6]\n",
3595 phba->brd_no, val);
3596 return -EINVAL;
3597}
James Smart0a035432016-10-13 15:06:10 -07003598
James Smart83108bd2008-01-11 01:53:09 -05003599lpfc_param_show(topology)
Tony Jonesee959b02008-02-22 00:13:36 +01003600static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05003601 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05003602
James Smart21e9a0a2009-05-22 14:53:21 -04003603/**
3604 * lpfc_static_vport_show: Read callback function for
3605 * lpfc_static_vport sysfs file.
3606 * @dev: Pointer to class device object.
3607 * @attr: device attribute structure.
3608 * @buf: Data buffer.
3609 *
3610 * This function is the read call back function for
3611 * lpfc_static_vport sysfs file. The lpfc_static_vport
3612 * sysfs file report the mageability of the vport.
3613 **/
3614static ssize_t
3615lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3616 char *buf)
3617{
3618 struct Scsi_Host *shost = class_to_shost(dev);
3619 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3620 if (vport->vport_flag & STATIC_VPORT)
3621 sprintf(buf, "1\n");
3622 else
3623 sprintf(buf, "0\n");
3624
3625 return strlen(buf);
3626}
3627
3628/*
3629 * Sysfs attribute to control the statistical data collection.
3630 */
3631static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3632 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04003633
3634/**
James Smart3621a712009-04-06 18:47:14 -04003635 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003636 * @dev: Pointer to class device.
3637 * @buf: Data buffer.
3638 * @count: Size of the data buffer.
3639 *
3640 * This function get called when an user write to the lpfc_stat_data_ctrl
3641 * sysfs file. This function parse the command written to the sysfs file
3642 * and take appropriate action. These commands are used for controlling
3643 * driver statistical data collection.
3644 * Following are the command this function handles.
3645 *
3646 * setbucket <bucket_type> <base> <step>
3647 * = Set the latency buckets.
3648 * destroybucket = destroy all the buckets.
3649 * start = start data collection
3650 * stop = stop data collection
3651 * reset = reset the collected data
3652 **/
3653static ssize_t
3654lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3655 const char *buf, size_t count)
3656{
3657 struct Scsi_Host *shost = class_to_shost(dev);
3658 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3659 struct lpfc_hba *phba = vport->phba;
3660#define LPFC_MAX_DATA_CTRL_LEN 1024
3661 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3662 unsigned long i;
3663 char *str_ptr, *token;
3664 struct lpfc_vport **vports;
3665 struct Scsi_Host *v_shost;
3666 char *bucket_type_str, *base_str, *step_str;
3667 unsigned long base, step, bucket_type;
3668
3669 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04003670 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04003671 return -EINVAL;
3672
James Smarteb016562014-09-03 12:58:06 -04003673 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
James Smartea2151b2008-09-07 11:52:10 -04003674 str_ptr = &bucket_data[0];
3675 /* Ignore this token - this is command token */
3676 token = strsep(&str_ptr, "\t ");
3677 if (!token)
3678 return -EINVAL;
3679
3680 bucket_type_str = strsep(&str_ptr, "\t ");
3681 if (!bucket_type_str)
3682 return -EINVAL;
3683
3684 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3685 bucket_type = LPFC_LINEAR_BUCKET;
3686 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3687 bucket_type = LPFC_POWER2_BUCKET;
3688 else
3689 return -EINVAL;
3690
3691 base_str = strsep(&str_ptr, "\t ");
3692 if (!base_str)
3693 return -EINVAL;
3694 base = simple_strtoul(base_str, NULL, 0);
3695
3696 step_str = strsep(&str_ptr, "\t ");
3697 if (!step_str)
3698 return -EINVAL;
3699 step = simple_strtoul(step_str, NULL, 0);
3700 if (!step)
3701 return -EINVAL;
3702
3703 /* Block the data collection for every vport */
3704 vports = lpfc_create_vport_work_array(phba);
3705 if (vports == NULL)
3706 return -ENOMEM;
3707
James Smartf4b4c682009-05-22 14:53:12 -04003708 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003709 v_shost = lpfc_shost_from_vport(vports[i]);
3710 spin_lock_irq(v_shost->host_lock);
3711 /* Block and reset data collection */
3712 vports[i]->stat_data_blocked = 1;
3713 if (vports[i]->stat_data_enabled)
3714 lpfc_vport_reset_stat_data(vports[i]);
3715 spin_unlock_irq(v_shost->host_lock);
3716 }
3717
3718 /* Set the bucket attributes */
3719 phba->bucket_type = bucket_type;
3720 phba->bucket_base = base;
3721 phba->bucket_step = step;
3722
James Smartf4b4c682009-05-22 14:53:12 -04003723 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003724 v_shost = lpfc_shost_from_vport(vports[i]);
3725
3726 /* Unblock data collection */
3727 spin_lock_irq(v_shost->host_lock);
3728 vports[i]->stat_data_blocked = 0;
3729 spin_unlock_irq(v_shost->host_lock);
3730 }
3731 lpfc_destroy_vport_work_array(phba, vports);
3732 return strlen(buf);
3733 }
3734
3735 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3736 vports = lpfc_create_vport_work_array(phba);
3737 if (vports == NULL)
3738 return -ENOMEM;
3739
James Smartf4b4c682009-05-22 14:53:12 -04003740 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003741 v_shost = lpfc_shost_from_vport(vports[i]);
3742 spin_lock_irq(shost->host_lock);
3743 vports[i]->stat_data_blocked = 1;
3744 lpfc_free_bucket(vport);
3745 vport->stat_data_enabled = 0;
3746 vports[i]->stat_data_blocked = 0;
3747 spin_unlock_irq(shost->host_lock);
3748 }
3749 lpfc_destroy_vport_work_array(phba, vports);
3750 phba->bucket_type = LPFC_NO_BUCKET;
3751 phba->bucket_base = 0;
3752 phba->bucket_step = 0;
3753 return strlen(buf);
3754 }
3755
3756 if (!strncmp(buf, "start", strlen("start"))) {
3757 /* If no buckets configured return error */
3758 if (phba->bucket_type == LPFC_NO_BUCKET)
3759 return -EINVAL;
3760 spin_lock_irq(shost->host_lock);
3761 if (vport->stat_data_enabled) {
3762 spin_unlock_irq(shost->host_lock);
3763 return strlen(buf);
3764 }
3765 lpfc_alloc_bucket(vport);
3766 vport->stat_data_enabled = 1;
3767 spin_unlock_irq(shost->host_lock);
3768 return strlen(buf);
3769 }
3770
3771 if (!strncmp(buf, "stop", strlen("stop"))) {
3772 spin_lock_irq(shost->host_lock);
3773 if (vport->stat_data_enabled == 0) {
3774 spin_unlock_irq(shost->host_lock);
3775 return strlen(buf);
3776 }
3777 lpfc_free_bucket(vport);
3778 vport->stat_data_enabled = 0;
3779 spin_unlock_irq(shost->host_lock);
3780 return strlen(buf);
3781 }
3782
3783 if (!strncmp(buf, "reset", strlen("reset"))) {
3784 if ((phba->bucket_type == LPFC_NO_BUCKET)
3785 || !vport->stat_data_enabled)
3786 return strlen(buf);
3787 spin_lock_irq(shost->host_lock);
3788 vport->stat_data_blocked = 1;
3789 lpfc_vport_reset_stat_data(vport);
3790 vport->stat_data_blocked = 0;
3791 spin_unlock_irq(shost->host_lock);
3792 return strlen(buf);
3793 }
3794 return -EINVAL;
3795}
3796
3797
3798/**
James Smart3621a712009-04-06 18:47:14 -04003799 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003800 * @dev: Pointer to class device object.
3801 * @buf: Data buffer.
3802 *
3803 * This function is the read call back function for
3804 * lpfc_stat_data_ctrl sysfs file. This function report the
3805 * current statistical data collection state.
3806 **/
3807static ssize_t
3808lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3809 char *buf)
3810{
3811 struct Scsi_Host *shost = class_to_shost(dev);
3812 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3813 struct lpfc_hba *phba = vport->phba;
3814 int index = 0;
3815 int i;
3816 char *bucket_type;
3817 unsigned long bucket_value;
3818
3819 switch (phba->bucket_type) {
3820 case LPFC_LINEAR_BUCKET:
3821 bucket_type = "linear";
3822 break;
3823 case LPFC_POWER2_BUCKET:
3824 bucket_type = "power2";
3825 break;
3826 default:
3827 bucket_type = "No Bucket";
3828 break;
3829 }
3830
3831 sprintf(&buf[index], "Statistical Data enabled :%d, "
3832 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3833 " Bucket step :%d\nLatency Ranges :",
3834 vport->stat_data_enabled, vport->stat_data_blocked,
3835 bucket_type, phba->bucket_base, phba->bucket_step);
3836 index = strlen(buf);
3837 if (phba->bucket_type != LPFC_NO_BUCKET) {
3838 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3839 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3840 bucket_value = phba->bucket_base +
3841 phba->bucket_step * i;
3842 else
3843 bucket_value = phba->bucket_base +
3844 (1 << i) * phba->bucket_step;
3845
3846 if (index + 10 > PAGE_SIZE)
3847 break;
3848 sprintf(&buf[index], "%08ld ", bucket_value);
3849 index = strlen(buf);
3850 }
3851 }
3852 sprintf(&buf[index], "\n");
3853 return strlen(buf);
3854}
3855
3856/*
3857 * Sysfs attribute to control the statistical data collection.
3858 */
3859static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3860 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3861
3862/*
3863 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3864 */
3865
3866/*
3867 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3868 * for each target.
3869 */
3870#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3871#define MAX_STAT_DATA_SIZE_PER_TARGET \
3872 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3873
3874
3875/**
James Smart3621a712009-04-06 18:47:14 -04003876 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003877 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003878 * @kobj: Pointer to the kernel object
3879 * @bin_attr: Attribute object
3880 * @buff: Buffer pointer
3881 * @off: File offset
3882 * @count: Buffer size
3883 *
3884 * This function is the read call back function for lpfc_drvr_stat_data
3885 * sysfs file. This function export the statistical data to user
3886 * applications.
3887 **/
3888static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003889sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3890 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003891 char *buf, loff_t off, size_t count)
3892{
3893 struct device *dev = container_of(kobj, struct device,
3894 kobj);
3895 struct Scsi_Host *shost = class_to_shost(dev);
3896 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3897 struct lpfc_hba *phba = vport->phba;
3898 int i = 0, index = 0;
3899 unsigned long nport_index;
3900 struct lpfc_nodelist *ndlp = NULL;
3901 nport_index = (unsigned long)off /
3902 MAX_STAT_DATA_SIZE_PER_TARGET;
3903
3904 if (!vport->stat_data_enabled || vport->stat_data_blocked
3905 || (phba->bucket_type == LPFC_NO_BUCKET))
3906 return 0;
3907
3908 spin_lock_irq(shost->host_lock);
3909 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3910 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3911 continue;
3912
3913 if (nport_index > 0) {
3914 nport_index--;
3915 continue;
3916 }
3917
3918 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3919 > count)
3920 break;
3921
3922 if (!ndlp->lat_data)
3923 continue;
3924
3925 /* Print the WWN */
3926 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3927 ndlp->nlp_portname.u.wwn[0],
3928 ndlp->nlp_portname.u.wwn[1],
3929 ndlp->nlp_portname.u.wwn[2],
3930 ndlp->nlp_portname.u.wwn[3],
3931 ndlp->nlp_portname.u.wwn[4],
3932 ndlp->nlp_portname.u.wwn[5],
3933 ndlp->nlp_portname.u.wwn[6],
3934 ndlp->nlp_portname.u.wwn[7]);
3935
3936 index = strlen(buf);
3937
3938 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3939 sprintf(&buf[index], "%010u,",
3940 ndlp->lat_data[i].cmd_count);
3941 index = strlen(buf);
3942 }
3943 sprintf(&buf[index], "\n");
3944 index = strlen(buf);
3945 }
3946 spin_unlock_irq(shost->host_lock);
3947 return index;
3948}
3949
3950static struct bin_attribute sysfs_drvr_stat_data_attr = {
3951 .attr = {
3952 .name = "lpfc_drvr_stat_data",
3953 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003954 },
3955 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3956 .read = sysfs_drvr_stat_data_read,
3957 .write = NULL,
3958};
3959
dea31012005-04-17 16:05:31 -05003960/*
3961# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3962# connection.
James Smart76a95d72010-11-20 23:11:48 -05003963# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003964*/
James Smarte59058c2008-08-24 21:49:00 -04003965/**
James Smart3621a712009-04-06 18:47:14 -04003966 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003967 * @phba: lpfc_hba pointer.
3968 * @val: link speed value.
3969 *
3970 * Description:
3971 * If val is in a valid range then set the adapter's link speed field and
3972 * issue a lip; if the lip fails reset the link speed to the old value.
3973 *
3974 * Notes:
3975 * If the value is not in range log a kernel error message and return an error.
3976 *
3977 * Returns:
3978 * zero if val is in range and lip okay.
3979 * non-zero return value from lpfc_issue_lip()
3980 * -EINVAL val out of range
3981 **/
James Smarta257bf92009-04-06 18:48:10 -04003982static ssize_t
3983lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3984 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003985{
James Smarta257bf92009-04-06 18:48:10 -04003986 struct Scsi_Host *shost = class_to_shost(dev);
3987 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3988 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003989 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003990 int nolip = 0;
3991 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003992 int err;
James Smartc6918162016-10-13 15:06:16 -07003993 uint32_t prev_val, if_type;
3994
3995 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
3996 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
3997 phba->hba_flag & HBA_FORCED_LINK_SPEED)
3998 return -EPERM;
James Smart83108bd2008-01-11 01:53:09 -05003999
James Smarta257bf92009-04-06 18:48:10 -04004000 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4001 nolip = 1;
4002 val_buf = &buf[strlen("nolip ")];
4003 }
4004
4005 if (!isdigit(val_buf[0]))
4006 return -EINVAL;
4007 if (sscanf(val_buf, "%i", &val) != 1)
4008 return -EINVAL;
4009
James Smart88a2cfb2011-07-22 18:36:33 -04004010 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4011 "3055 lpfc_link_speed changed from %d to %d %s\n",
4012 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4013
James Smart76a95d72010-11-20 23:11:48 -05004014 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4015 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4016 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4017 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4018 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
James Smartd38dd522015-08-31 16:48:17 -04004019 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4020 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
James Smart76a95d72010-11-20 23:11:48 -05004021 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4022 "2879 lpfc_link_speed attribute cannot be set "
4023 "to %d. Speed is not supported by this port.\n",
4024 val);
James Smart83108bd2008-01-11 01:53:09 -05004025 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05004026 }
James Smartff78d8f2011-12-13 13:21:35 -05004027 if (val == LPFC_USER_LINK_SPEED_16G &&
4028 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4029 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4030 "3112 lpfc_link_speed attribute cannot be set "
4031 "to %d. Speed is not supported in loop mode.\n",
4032 val);
4033 return -EINVAL;
4034 }
James Smart76a95d72010-11-20 23:11:48 -05004035 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4036 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05004037 prev_val = phba->cfg_link_speed;
4038 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04004039 if (nolip)
4040 return strlen(buf);
4041
James Smart83108bd2008-01-11 01:53:09 -05004042 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04004043 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05004044 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04004045 return -EINVAL;
4046 } else
4047 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05004048 }
James Smart83108bd2008-01-11 01:53:09 -05004049 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05004050 "0469 lpfc_link_speed attribute cannot be set to %d, "
4051 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05004052 return -EINVAL;
4053}
4054
4055static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05004056module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05004057MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4058lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04004059
4060/**
James Smart3621a712009-04-06 18:47:14 -04004061 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004062 * @phba: lpfc_hba pointer.
4063 * @val: link speed value.
4064 *
4065 * Description:
4066 * If val is in a valid range then set the adapter's link speed field.
4067 *
4068 * Notes:
4069 * If the value is not in range log a kernel error message, clear the link
4070 * speed and return an error.
4071 *
4072 * Returns:
4073 * zero if val saved.
4074 * -EINVAL val out of range
4075 **/
James Smart83108bd2008-01-11 01:53:09 -05004076static int
4077lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4078{
James Smartff78d8f2011-12-13 13:21:35 -05004079 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4080 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4081 "3111 lpfc_link_speed of %d cannot "
4082 "support loop mode, setting topology to default.\n",
4083 val);
4084 phba->cfg_topology = 0;
4085 }
James Smart76a95d72010-11-20 23:11:48 -05004086 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4087 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05004088 phba->cfg_link_speed = val;
4089 return 0;
4090 }
4091 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004092 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05004093 "be set to %d, allowed values are "
4094 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05004095 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05004096 return -EINVAL;
4097}
4098
Tony Jonesee959b02008-02-22 00:13:36 +01004099static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05004100 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05004101
4102/*
James Smart0d878412009-10-02 15:16:56 -04004103# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4104# 0 = aer disabled or not supported
4105# 1 = aer supported and enabled (default)
4106# Value range is [0,1]. Default value is 1.
4107*/
James Smart506139a2016-10-13 15:06:09 -07004108LPFC_ATTR(aer_support, 1, 0, 1,
4109 "Enable PCIe device AER support");
4110lpfc_param_show(aer_support)
James Smart0d878412009-10-02 15:16:56 -04004111
4112/**
4113 * lpfc_aer_support_store - Set the adapter for aer support
4114 *
4115 * @dev: class device that is converted into a Scsi_host.
4116 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004117 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04004118 * @count: unused variable.
4119 *
4120 * Description:
4121 * If the val is 1 and currently the device's AER capability was not
4122 * enabled, invoke the kernel's enable AER helper routine, trying to
4123 * enable the device's AER capability. If the helper routine enabling
4124 * AER returns success, update the device's cfg_aer_support flag to
4125 * indicate AER is supported by the device; otherwise, if the device
4126 * AER capability is already enabled to support AER, then do nothing.
4127 *
4128 * If the val is 0 and currently the device's AER support was enabled,
4129 * invoke the kernel's disable AER helper routine. After that, update
4130 * the device's cfg_aer_support flag to indicate AER is not supported
4131 * by the device; otherwise, if the device AER capability is already
4132 * disabled from supporting AER, then do nothing.
4133 *
4134 * Returns:
4135 * length of the buf on success if val is in range the intended mode
4136 * is supported.
4137 * -EINVAL if val out of range or intended mode is not supported.
4138 **/
4139static ssize_t
4140lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4141 const char *buf, size_t count)
4142{
4143 struct Scsi_Host *shost = class_to_shost(dev);
4144 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4145 struct lpfc_hba *phba = vport->phba;
4146 int val = 0, rc = -EINVAL;
4147
4148 if (!isdigit(buf[0]))
4149 return -EINVAL;
4150 if (sscanf(buf, "%i", &val) != 1)
4151 return -EINVAL;
4152
4153 switch (val) {
4154 case 0:
4155 if (phba->hba_flag & HBA_AER_ENABLED) {
4156 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4157 if (!rc) {
4158 spin_lock_irq(&phba->hbalock);
4159 phba->hba_flag &= ~HBA_AER_ENABLED;
4160 spin_unlock_irq(&phba->hbalock);
4161 phba->cfg_aer_support = 0;
4162 rc = strlen(buf);
4163 } else
James Smart891478a2009-11-18 15:40:23 -05004164 rc = -EPERM;
4165 } else {
James Smart0d878412009-10-02 15:16:56 -04004166 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05004167 rc = strlen(buf);
4168 }
James Smart0d878412009-10-02 15:16:56 -04004169 break;
4170 case 1:
4171 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4172 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4173 if (!rc) {
4174 spin_lock_irq(&phba->hbalock);
4175 phba->hba_flag |= HBA_AER_ENABLED;
4176 spin_unlock_irq(&phba->hbalock);
4177 phba->cfg_aer_support = 1;
4178 rc = strlen(buf);
4179 } else
James Smart891478a2009-11-18 15:40:23 -05004180 rc = -EPERM;
4181 } else {
James Smart0d878412009-10-02 15:16:56 -04004182 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05004183 rc = strlen(buf);
4184 }
James Smart0d878412009-10-02 15:16:56 -04004185 break;
4186 default:
4187 rc = -EINVAL;
4188 break;
4189 }
4190 return rc;
4191}
4192
James Smart0d878412009-10-02 15:16:56 -04004193static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
4194 lpfc_aer_support_show, lpfc_aer_support_store);
4195
4196/**
4197 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4198 * @dev: class device that is converted into a Scsi_host.
4199 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004200 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04004201 * @count: unused variable.
4202 *
4203 * Description:
4204 * If the @buf contains 1 and the device currently has the AER support
4205 * enabled, then invokes the kernel AER helper routine
4206 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4207 * error status register.
4208 *
4209 * Notes:
4210 *
4211 * Returns:
4212 * -EINVAL if the buf does not contain the 1 or the device is not currently
4213 * enabled with the AER support.
4214 **/
4215static ssize_t
4216lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4217 const char *buf, size_t count)
4218{
4219 struct Scsi_Host *shost = class_to_shost(dev);
4220 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4221 struct lpfc_hba *phba = vport->phba;
4222 int val, rc = -1;
4223
4224 if (!isdigit(buf[0]))
4225 return -EINVAL;
4226 if (sscanf(buf, "%i", &val) != 1)
4227 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05004228 if (val != 1)
4229 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04004230
James Smart891478a2009-11-18 15:40:23 -05004231 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04004232 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4233
4234 if (rc == 0)
4235 return strlen(buf);
4236 else
James Smart891478a2009-11-18 15:40:23 -05004237 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04004238}
4239
4240static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4241 lpfc_aer_cleanup_state);
4242
James Smart912e3ac2011-05-24 11:42:11 -04004243/**
4244 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4245 *
4246 * @dev: class device that is converted into a Scsi_host.
4247 * @attr: device attribute, not used.
4248 * @buf: containing the string the number of vfs to be enabled.
4249 * @count: unused variable.
4250 *
4251 * Description:
4252 * When this api is called either through user sysfs, the driver shall
4253 * try to enable or disable SR-IOV virtual functions according to the
4254 * following:
4255 *
4256 * If zero virtual function has been enabled to the physical function,
4257 * the driver shall invoke the pci enable virtual function api trying
4258 * to enable the virtual functions. If the nr_vfn provided is greater
4259 * than the maximum supported, the maximum virtual function number will
4260 * be used for invoking the api; otherwise, the nr_vfn provided shall
4261 * be used for invoking the api. If the api call returned success, the
4262 * actual number of virtual functions enabled will be set to the driver
4263 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4264 * cfg_sriov_nr_virtfn remains zero.
4265 *
4266 * If none-zero virtual functions have already been enabled to the
4267 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4268 * -EINVAL will be returned and the driver does nothing;
4269 *
4270 * If the nr_vfn provided is zero and none-zero virtual functions have
4271 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4272 * disabling virtual function api shall be invoded to disable all the
4273 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4274 * zero. Otherwise, if zero virtual function has been enabled, do
4275 * nothing.
4276 *
4277 * Returns:
4278 * length of the buf on success if val is in range the intended mode
4279 * is supported.
4280 * -EINVAL if val out of range or intended mode is not supported.
4281 **/
4282static ssize_t
4283lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4284 const char *buf, size_t count)
4285{
4286 struct Scsi_Host *shost = class_to_shost(dev);
4287 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4288 struct lpfc_hba *phba = vport->phba;
4289 struct pci_dev *pdev = phba->pcidev;
4290 int val = 0, rc = -EINVAL;
4291
4292 /* Sanity check on user data */
4293 if (!isdigit(buf[0]))
4294 return -EINVAL;
4295 if (sscanf(buf, "%i", &val) != 1)
4296 return -EINVAL;
4297 if (val < 0)
4298 return -EINVAL;
4299
4300 /* Request disabling virtual functions */
4301 if (val == 0) {
4302 if (phba->cfg_sriov_nr_virtfn > 0) {
4303 pci_disable_sriov(pdev);
4304 phba->cfg_sriov_nr_virtfn = 0;
4305 }
4306 return strlen(buf);
4307 }
4308
4309 /* Request enabling virtual functions */
4310 if (phba->cfg_sriov_nr_virtfn > 0) {
4311 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4312 "3018 There are %d virtual functions "
4313 "enabled on physical function.\n",
4314 phba->cfg_sriov_nr_virtfn);
4315 return -EEXIST;
4316 }
4317
4318 if (val <= LPFC_MAX_VFN_PER_PFN)
4319 phba->cfg_sriov_nr_virtfn = val;
4320 else {
4321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4322 "3019 Enabling %d virtual functions is not "
4323 "allowed.\n", val);
4324 return -EINVAL;
4325 }
4326
4327 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4328 if (rc) {
4329 phba->cfg_sriov_nr_virtfn = 0;
4330 rc = -EPERM;
4331 } else
4332 rc = strlen(buf);
4333
4334 return rc;
4335}
4336
James Smart0cfbbf22016-10-13 15:06:12 -07004337LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4338 "Enable PCIe device SR-IOV virtual fn");
4339
James Smart912e3ac2011-05-24 11:42:11 -04004340lpfc_param_show(sriov_nr_virtfn)
James Smart912e3ac2011-05-24 11:42:11 -04004341static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4342 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4343
James Smart173edbb2012-06-12 13:54:50 -04004344/**
James Smartc71ab862012-10-31 14:44:33 -04004345 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4346 *
4347 * @dev: class device that is converted into a Scsi_host.
4348 * @attr: device attribute, not used.
4349 * @buf: containing the string the number of vfs to be enabled.
4350 * @count: unused variable.
4351 *
4352 * Description:
4353 *
4354 * Returns:
4355 * length of the buf on success if val is in range the intended mode
4356 * is supported.
4357 * -EINVAL if val out of range or intended mode is not supported.
4358 **/
4359static ssize_t
4360lpfc_request_firmware_upgrade_store(struct device *dev,
4361 struct device_attribute *attr,
4362 const char *buf, size_t count)
4363{
4364 struct Scsi_Host *shost = class_to_shost(dev);
4365 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4366 struct lpfc_hba *phba = vport->phba;
4367 int val = 0, rc = -EINVAL;
4368
4369 /* Sanity check on user data */
4370 if (!isdigit(buf[0]))
4371 return -EINVAL;
4372 if (sscanf(buf, "%i", &val) != 1)
4373 return -EINVAL;
4374 if (val != 1)
4375 return -EINVAL;
4376
4377 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4378 if (rc)
4379 rc = -EPERM;
4380 else
4381 rc = strlen(buf);
4382 return rc;
4383}
4384
4385static int lpfc_req_fw_upgrade;
4386module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4387MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4388lpfc_param_show(request_firmware_upgrade)
4389
4390/**
4391 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4392 * @phba: lpfc_hba pointer.
4393 * @val: 0 or 1.
4394 *
4395 * Description:
4396 * Set the initial Linux generic firmware upgrade enable or disable flag.
4397 *
4398 * Returns:
4399 * zero if val saved.
4400 * -EINVAL val out of range
4401 **/
4402static int
4403lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4404{
4405 if (val >= 0 && val <= 1) {
4406 phba->cfg_request_firmware_upgrade = val;
4407 return 0;
4408 }
4409 return -EINVAL;
4410}
4411static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4412 lpfc_request_firmware_upgrade_show,
4413 lpfc_request_firmware_upgrade_store);
4414
4415/**
James Smart173edbb2012-06-12 13:54:50 -04004416 * lpfc_fcp_imax_store
4417 *
4418 * @dev: class device that is converted into a Scsi_host.
4419 * @attr: device attribute, not used.
4420 * @buf: string with the number of fast-path FCP interrupts per second.
4421 * @count: unused variable.
4422 *
4423 * Description:
4424 * If val is in a valid range [636,651042], then set the adapter's
4425 * maximum number of fast-path FCP interrupts per second.
4426 *
4427 * Returns:
4428 * length of the buf on success if val is in range the intended mode
4429 * is supported.
4430 * -EINVAL if val out of range or intended mode is not supported.
4431 **/
4432static ssize_t
4433lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4434 const char *buf, size_t count)
4435{
4436 struct Scsi_Host *shost = class_to_shost(dev);
4437 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4438 struct lpfc_hba *phba = vport->phba;
4439 int val = 0, i;
4440
James Smartbf8dae82012-08-03 12:36:24 -04004441 /* fcp_imax is only valid for SLI4 */
4442 if (phba->sli_rev != LPFC_SLI_REV4)
4443 return -EINVAL;
4444
James Smart173edbb2012-06-12 13:54:50 -04004445 /* Sanity check on user data */
4446 if (!isdigit(buf[0]))
4447 return -EINVAL;
4448 if (sscanf(buf, "%i", &val) != 1)
4449 return -EINVAL;
4450
James Smartbf8dae82012-08-03 12:36:24 -04004451 /*
4452 * Value range for the HBA is [5000,5000000]
4453 * The value for each EQ depends on how many EQs are configured.
James Smart895427b2017-02-12 13:52:30 -08004454 * Allow value == 0
James Smartbf8dae82012-08-03 12:36:24 -04004455 */
James Smart895427b2017-02-12 13:52:30 -08004456 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
James Smart173edbb2012-06-12 13:54:50 -04004457 return -EINVAL;
4458
4459 phba->cfg_fcp_imax = (uint32_t)val;
James Smart895427b2017-02-12 13:52:30 -08004460 for (i = 0; i < phba->io_channel_irqs; i++)
4461 lpfc_modify_hba_eq_delay(phba, i);
James Smart173edbb2012-06-12 13:54:50 -04004462
4463 return strlen(buf);
4464}
4465
4466/*
4467# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04004468# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04004469#
James Smartbf8dae82012-08-03 12:36:24 -04004470# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04004471*/
James Smartbf8dae82012-08-03 12:36:24 -04004472static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004473module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4474MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04004475 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04004476lpfc_param_show(fcp_imax)
4477
4478/**
4479 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4480 * @phba: lpfc_hba pointer.
4481 * @val: link speed value.
4482 *
4483 * Description:
4484 * If val is in a valid range [636,651042], then initialize the adapter's
4485 * maximum number of fast-path FCP interrupts per second.
4486 *
4487 * Returns:
4488 * zero if val saved.
4489 * -EINVAL val out of range
4490 **/
4491static int
4492lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4493{
James Smartbf8dae82012-08-03 12:36:24 -04004494 if (phba->sli_rev != LPFC_SLI_REV4) {
4495 phba->cfg_fcp_imax = 0;
4496 return 0;
4497 }
4498
James Smart895427b2017-02-12 13:52:30 -08004499 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4500 (val == 0)) {
James Smart173edbb2012-06-12 13:54:50 -04004501 phba->cfg_fcp_imax = val;
4502 return 0;
4503 }
4504
4505 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004506 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4507 val);
James Smartbf8dae82012-08-03 12:36:24 -04004508 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004509
4510 return 0;
4511}
4512
4513static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4514 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4515
James Smart7bb03bb2013-04-17 20:19:16 -04004516/**
4517 * lpfc_state_show - Display current driver CPU affinity
4518 * @dev: class converted to a Scsi_host structure.
4519 * @attr: device attribute, not used.
4520 * @buf: on return contains text describing the state of the link.
4521 *
4522 * Returns: size of formatted string.
4523 **/
4524static ssize_t
4525lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4526 char *buf)
4527{
4528 struct Scsi_Host *shost = class_to_shost(dev);
4529 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4530 struct lpfc_hba *phba = vport->phba;
4531 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05004532 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04004533
4534 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4535 (phba->intr_type != MSIX))
4536 return len;
4537
4538 switch (phba->cfg_fcp_cpu_map) {
4539 case 0:
4540 len += snprintf(buf + len, PAGE_SIZE-len,
4541 "fcp_cpu_map: No mapping (%d)\n",
4542 phba->cfg_fcp_cpu_map);
4543 return len;
4544 case 1:
4545 len += snprintf(buf + len, PAGE_SIZE-len,
4546 "fcp_cpu_map: HBA centric mapping (%d): "
4547 "%d online CPUs\n",
4548 phba->cfg_fcp_cpu_map,
4549 phba->sli4_hba.num_online_cpu);
4550 break;
4551 case 2:
4552 len += snprintf(buf + len, PAGE_SIZE-len,
4553 "fcp_cpu_map: Driver centric mapping (%d): "
4554 "%d online CPUs\n",
4555 phba->cfg_fcp_cpu_map,
4556 phba->sli4_hba.num_online_cpu);
4557 break;
4558 }
4559
James Smart76fd07a2014-02-20 09:57:18 -05004560 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4561 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4562
4563 /* margin should fit in this and the truncated message */
James Smart7bb03bb2013-04-17 20:19:16 -04004564 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4565 len += snprintf(buf + len, PAGE_SIZE-len,
4566 "CPU %02d io_chan %02d "
4567 "physid %d coreid %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004568 phba->sli4_hba.curr_disp_cpu,
4569 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004570 cpup->core_id);
4571 else
4572 len += snprintf(buf + len, PAGE_SIZE-len,
4573 "CPU %02d io_chan %02d "
4574 "physid %d coreid %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004575 phba->sli4_hba.curr_disp_cpu,
4576 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004577 cpup->core_id, cpup->irq);
4578
James Smart76fd07a2014-02-20 09:57:18 -05004579 phba->sli4_hba.curr_disp_cpu++;
4580
4581 /* display max number of CPUs keeping some margin */
4582 if (phba->sli4_hba.curr_disp_cpu <
4583 phba->sli4_hba.num_present_cpu &&
4584 (len >= (PAGE_SIZE - 64))) {
4585 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4586 break;
4587 }
James Smart7bb03bb2013-04-17 20:19:16 -04004588 }
James Smart76fd07a2014-02-20 09:57:18 -05004589
4590 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4591 phba->sli4_hba.curr_disp_cpu = 0;
4592
James Smart7bb03bb2013-04-17 20:19:16 -04004593 return len;
4594}
4595
4596/**
4597 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4598 * @dev: class device that is converted into a Scsi_host.
4599 * @attr: device attribute, not used.
4600 * @buf: one or more lpfc_polling_flags values.
4601 * @count: not used.
4602 *
4603 * Returns:
4604 * -EINVAL - Not implemented yet.
4605 **/
4606static ssize_t
4607lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4608 const char *buf, size_t count)
4609{
4610 int status = -EINVAL;
4611 return status;
4612}
4613
4614/*
4615# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4616# for the HBA.
4617#
4618# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4619# 0 - Do not affinitze IRQ vectors
4620# 1 - Affintize HBA vectors with respect to each HBA
4621# (start with CPU0 for each HBA)
4622# 2 - Affintize HBA vectors with respect to the entire driver
4623# (round robin thru all CPUs across all HBAs)
4624*/
4625static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4626module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4627MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4628 "Defines how to map CPUs to IRQ vectors per HBA");
4629
4630/**
4631 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4632 * @phba: lpfc_hba pointer.
4633 * @val: link speed value.
4634 *
4635 * Description:
4636 * If val is in a valid range [0-2], then affinitze the adapter's
4637 * MSIX vectors.
4638 *
4639 * Returns:
4640 * zero if val saved.
4641 * -EINVAL val out of range
4642 **/
4643static int
4644lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4645{
4646 if (phba->sli_rev != LPFC_SLI_REV4) {
4647 phba->cfg_fcp_cpu_map = 0;
4648 return 0;
4649 }
4650
4651 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4652 phba->cfg_fcp_cpu_map = val;
4653 return 0;
4654 }
4655
4656 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004657 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4658 "default\n", val);
James Smart7bb03bb2013-04-17 20:19:16 -04004659 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4660
4661 return 0;
4662}
4663
4664static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4665 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4666
James Smart0d878412009-10-02 15:16:56 -04004667/*
dea31012005-04-17 16:05:31 -05004668# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4669# Value range is [2,3]. Default value is 3.
4670*/
James Smart3de2a652007-08-02 11:09:59 -04004671LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4672 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05004673
4674/*
4675# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4676# is [0,1]. Default value is 0.
4677*/
James Smart3de2a652007-08-02 11:09:59 -04004678LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4679 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05004680
4681/*
James Smart3cb01c52013-07-15 18:35:04 -04004682# lpfc_first_burst_size: First burst size to use on the NPorts
4683# that support first burst.
4684# Value range is [0,65536]. Default value is 0.
4685*/
4686LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4687 "First burst size for Targets that support first burst");
4688
4689/*
James Smart2d7dbc42017-02-12 13:52:35 -08004690* lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4691* When the driver is configured as an NVME target, this value is
4692* communicated to the NVME initiator in the PRLI response. It is
4693* used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4694* parameters are set and the target is sending the PRLI RSP.
James Smart895427b2017-02-12 13:52:30 -08004695* Parameter supported on physical port only - no NPIV support.
James Smart2d7dbc42017-02-12 13:52:35 -08004696* Value range is [0,65536]. Default value is 0.
James Smart895427b2017-02-12 13:52:30 -08004697*/
James Smart2d7dbc42017-02-12 13:52:35 -08004698LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4699 "NVME Target mode first burst size in 512B increments.");
4700
4701/*
4702 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4703 * For the Initiator (I), enabling this parameter means that an NVMET
4704 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4705 * processed by the initiator for subsequent NVME FCP IO. For the target
4706 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4707 * driver parameter as the target function's first burst size returned to the
4708 * initiator in the target's NVME PRLI response. Parameter supported on physical
4709 * port only - no NPIV support.
4710 * Value range is [0,1]. Default value is 0 (disabled).
4711 */
James Smart895427b2017-02-12 13:52:30 -08004712LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4713 "Enable First Burst feature on I and T functions.");
4714
4715/*
James Smart977b5a02008-09-07 11:52:04 -04004716# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4717# depth. Default value is 0. When the value of this parameter is zero the
4718# SCSI command completion time is not used for controlling I/O queue depth. When
4719# the parameter is set to a non-zero value, the I/O queue depth is controlled
4720# to limit the I/O completion time to the parameter value.
4721# The value is set in milliseconds.
4722*/
James Smarted5b1522016-10-13 15:06:11 -07004723LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
James Smart977b5a02008-09-07 11:52:04 -04004724 "Use command completion time to control queue depth");
James Smarted5b1522016-10-13 15:06:11 -07004725
James Smart977b5a02008-09-07 11:52:04 -04004726lpfc_vport_param_show(max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04004727static int
4728lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4729{
4730 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4731 struct lpfc_nodelist *ndlp, *next_ndlp;
4732
4733 if (val == vport->cfg_max_scsicmpl_time)
4734 return 0;
4735 if ((val < 0) || (val > 60000))
4736 return -EINVAL;
4737 vport->cfg_max_scsicmpl_time = val;
4738
4739 spin_lock_irq(shost->host_lock);
4740 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4741 if (!NLP_CHK_NODE_ACT(ndlp))
4742 continue;
4743 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4744 continue;
James Smart7dc517d2010-07-14 15:32:10 -04004745 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04004746 }
4747 spin_unlock_irq(shost->host_lock);
4748 return 0;
4749}
4750lpfc_vport_param_store(max_scsicmpl_time);
4751static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4752 lpfc_max_scsicmpl_time_show,
4753 lpfc_max_scsicmpl_time_store);
4754
4755/*
dea31012005-04-17 16:05:31 -05004756# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4757# range is [0,1]. Default value is 0.
4758*/
4759LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4760
4761/*
James Smart895427b2017-02-12 13:52:30 -08004762 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4763 * range is [0,1]. Default value is 0.
4764 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4765 * For [1], FCP commands are issued to a Work Queue associated with the
4766 * current CPU.
4767 *
4768 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4769 * LPFC_FCP_SCHED_BY_CPU == 1
4770 *
4771 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4772 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4773 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4774 * through WQs will be used.
4775 */
4776LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4777 LPFC_FCP_SCHED_ROUND_ROBIN,
4778 LPFC_FCP_SCHED_BY_CPU,
4779 "Determine scheduling algorithm for "
4780 "issuing commands [0] - Round Robin, [1] - Current CPU");
James Smart49aa1432012-08-03 12:36:42 -04004781
4782/*
James Smarta6571c62012-10-31 14:44:42 -04004783# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4784# range is [0,1]. Default value is 0.
4785# For [0], bus reset issues target reset to ALL devices
4786# For [1], bus reset issues target reset to non-FCP2 devices
4787*/
4788LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4789 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4790
4791
4792/*
dea31012005-04-17 16:05:31 -05004793# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4794# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04004795# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05004796# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4797# cr_delay is set to 0.
4798*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004799LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05004800 "interrupt response is generated");
4801
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004802LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05004803 "interrupt response is generated");
4804
4805/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004806# lpfc_multi_ring_support: Determines how many rings to spread available
4807# cmd/rsp IOCB entries across.
4808# Value range is [1,2]. Default value is 1.
4809*/
4810LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4811 "SLI rings to spread IOCB entries across");
4812
4813/*
James Smarta4bc3372006-12-02 13:34:16 -05004814# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4815# identifies what rctl value to configure the additional ring for.
4816# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4817*/
James Smart6a9c52c2009-10-02 15:16:51 -04004818LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004819 255, "Identifies RCTL for additional ring configuration");
4820
4821/*
4822# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4823# identifies what type value to configure the additional ring for.
4824# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4825*/
James Smart6a9c52c2009-10-02 15:16:51 -04004826LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004827 255, "Identifies TYPE for additional ring configuration");
4828
4829/*
James Smart4258e982015-12-16 18:11:58 -05004830# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4831# 0 = SmartSAN functionality disabled (default)
4832# 1 = SmartSAN functionality enabled
4833# This parameter will override the value of lpfc_fdmi_on module parameter.
4834# Value range is [0,1]. Default value is 0.
dea31012005-04-17 16:05:31 -05004835*/
James Smart4258e982015-12-16 18:11:58 -05004836LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4837
4838/*
4839# lpfc_fdmi_on: Controls FDMI support.
4840# 0 No FDMI support (default)
4841# 1 Traditional FDMI support
James Smart8663cbb2016-03-31 14:12:33 -07004842# Traditional FDMI support means the driver will assume FDMI-2 support;
4843# however, if that fails, it will fallback to FDMI-1.
4844# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4845# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4846# lpfc_fdmi_on.
4847# Value range [0,1]. Default value is 0.
James Smart4258e982015-12-16 18:11:58 -05004848*/
James Smart8663cbb2016-03-31 14:12:33 -07004849LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05004850
4851/*
4852# Specifies the maximum number of ELS cmds we can have outstanding (for
4853# discovery). Value range is [1,64]. Default value = 32.
4854*/
James Smart3de2a652007-08-02 11:09:59 -04004855LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05004856 "during discovery");
4857
4858/*
James Smartc4a7c922013-05-31 17:04:59 -04004859# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4860# will be scanned by the SCSI midlayer when sequential scanning is
4861# used; and is also the highest LUN ID allowed when the SCSI midlayer
4862# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4863# LUN ID limit, but the SCSI midlayer requires this field for the uses
4864# above. The lpfc driver limits the default value to 255 for two reasons.
4865# As it bounds the sequential scan loop, scanning for thousands of luns
4866# on a target can take minutes of wall clock time. Additionally,
4867# there are FC targets, such as JBODs, that only recognize 8-bits of
4868# LUN ID. When they receive a value greater than 8 bits, they chop off
4869# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4870# and so on all as LUN ID 0. This causes the linux kernel, which sees
4871# valid responses at each of the LUN IDs, to believe there are multiple
4872# devices present, when in fact, there is only 1.
4873# A customer that is aware of their target behaviors, and the results as
4874# indicated above, is welcome to increase the lpfc_max_luns value.
4875# As mentioned, this value is not used by the lpfc driver, only the
4876# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04004877# Value range is [0,65535]. Default value is 255.
4878# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05004879*/
Hannes Reinecke1abf6352014-06-25 15:27:38 +02004880LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05004881
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004882/*
4883# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4884# Value range is [1,255], default value is 10.
4885*/
4886LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4887 "Milliseconds driver will wait between polling FCP ring");
4888
James Smart4ff43242006-12-02 13:34:56 -05004889/*
James Smart0c411222013-09-06 12:22:46 -04004890# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4891# to complete in seconds. Value range is [5,180], default value is 60.
4892*/
4893LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4894 "Maximum time to wait for task management commands to complete");
4895/*
James Smart4ff43242006-12-02 13:34:56 -05004896# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4897# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02004898# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05004899# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02004900# 2 = MSI-X enabled (default)
4901# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05004902*/
George Kadianakis8605c462010-01-17 21:19:31 +02004903LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05004904 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05004905
James Smart13815c82008-01-11 01:52:48 -05004906/*
James Smartf358dd02017-02-12 13:52:34 -08004907 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
James Smart895427b2017-02-12 13:52:30 -08004908 *
4909 * 0 = NVME OAS disabled
4910 * 1 = NVME OAS enabled
4911 *
4912 * Value range is [0,1]. Default value is 0.
4913 */
4914LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
4915 "Use OAS bit on NVME IOs");
4916
4917/*
4918 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
4919 * will advertise it supports to the SCSI layer. This also will map to
4920 * the number of WQs the driver will create.
4921 *
4922 * 0 = Configure the number of io channels to the number of active CPUs.
4923 * 1,32 = Manually specify how many io channels to use.
4924 *
4925 * Value range is [0,32]. Default value is 4.
4926 */
4927LPFC_ATTR_R(fcp_io_channel,
4928 LPFC_FCP_IO_CHAN_DEF,
4929 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
James Smart67d12732012-08-03 12:36:13 -04004930 "Set the number of FCP I/O channels");
4931
4932/*
James Smart895427b2017-02-12 13:52:30 -08004933 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
4934 * will advertise it supports to the NVME layer. This also will map to
4935 * the number of WQs the driver will create.
4936 *
4937 * This module parameter is valid when lpfc_enable_fc4_type is set
4938 * to support NVME.
4939 *
4940 * The NVME Layer will try to create this many, plus 1 administrative
4941 * hardware queue. The administrative queue will always map to WQ 0
4942 * A hardware IO queue maps (qidx) to a specific driver WQ.
4943 *
4944 * 0 = Configure the number of io channels to the number of active CPUs.
4945 * 1,32 = Manually specify how many io channels to use.
4946 *
4947 * Value range is [0,32]. Default value is 0.
4948 */
4949LPFC_ATTR_R(nvme_io_channel,
4950 LPFC_NVME_IO_CHAN_DEF,
4951 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4952 "Set the number of NVME I/O channels");
4953
4954/*
James Smart13815c82008-01-11 01:52:48 -05004955# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4956# 0 = HBA resets disabled
4957# 1 = HBA resets enabled (default)
4958# Value range is [0,1]. Default value is 1.
4959*/
4960LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04004961
James Smart13815c82008-01-11 01:52:48 -05004962/*
James Smarteb7a3392010-11-20 23:12:02 -05004963# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05004964# 0 = HBA Heartbeat disabled
4965# 1 = HBA Heartbeat enabled (default)
4966# Value range is [0,1]. Default value is 1.
4967*/
James Smarteb7a3392010-11-20 23:12:02 -05004968LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05004969
James Smart83108bd2008-01-11 01:53:09 -05004970/*
James Smart1ba981f2014-02-20 09:56:45 -05004971# lpfc_EnableXLane: Enable Express Lane Feature
4972# 0x0 Express Lane Feature disabled
4973# 0x1 Express Lane Feature enabled
4974# Value range is [0,1]. Default value is 0.
4975*/
4976LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
4977
4978/*
4979# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
4980# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
4981# Value range is [0x0,0x7f]. Default value is 0
4982*/
James Smart28d7f3d2014-05-21 08:05:28 -04004983LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
James Smart1ba981f2014-02-20 09:56:45 -05004984
4985/*
James Smart81301a92008-12-04 22:39:46 -05004986# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4987# 0 = BlockGuard disabled (default)
4988# 1 = BlockGuard enabled
4989# Value range is [0,1]. Default value is 0.
4990*/
4991LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
4992
James Smart6fb120a2009-05-22 14:52:59 -04004993/*
James Smartba20c852012-08-03 12:36:52 -04004994# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
4995# 0 = disabled (default)
4996# 1 = enabled
4997# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04004998#
4999# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04005000*/
5001unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5002
James Smartba20c852012-08-03 12:36:52 -04005003/*
James Smart81301a92008-12-04 22:39:46 -05005004# lpfc_prot_mask: i
5005# - Bit mask of host protection capabilities used to register with the
5006# SCSI mid-layer
5007# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5008# - Allows you to ultimately specify which profiles to use
5009# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04005010# - SHOST_DIF_TYPE1_PROTECTION 1
5011# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5012# - SHOST_DIX_TYPE0_PROTECTION 8
5013# HBA supports DIX Type 0: Host to HBA protection only
5014# - SHOST_DIX_TYPE1_PROTECTION 16
5015# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05005016#
5017*/
James Smartb3b98b72016-10-13 15:06:06 -07005018LPFC_ATTR(prot_mask,
5019 (SHOST_DIF_TYPE1_PROTECTION |
5020 SHOST_DIX_TYPE0_PROTECTION |
5021 SHOST_DIX_TYPE1_PROTECTION),
5022 0,
5023 (SHOST_DIF_TYPE1_PROTECTION |
5024 SHOST_DIX_TYPE0_PROTECTION |
5025 SHOST_DIX_TYPE1_PROTECTION),
5026 "T10-DIF host protection capabilities mask");
James Smart81301a92008-12-04 22:39:46 -05005027
5028/*
5029# lpfc_prot_guard: i
5030# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04005031# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05005032# - Allows you to ultimately specify which profiles to use
5033# - Default will result in registering capabilities for all guard types
5034#
5035*/
James Smartb3b98b72016-10-13 15:06:06 -07005036LPFC_ATTR(prot_guard,
5037 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5038 "T10-DIF host protection guard type");
James Smart81301a92008-12-04 22:39:46 -05005039
James Smart92494142011-02-16 12:39:44 -05005040/*
5041 * Delay initial NPort discovery when Clean Address bit is cleared in
5042 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5043 * This parameter can have value 0 or 1.
5044 * When this parameter is set to 0, no delay is added to the initial
5045 * discovery.
5046 * When this parameter is set to non-zero value, initial Nport discovery is
5047 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5048 * accept and FCID/Fabric name/Fabric portname is changed.
5049 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5050 * when Clean Address bit is cleared in FLOGI/FDISC
5051 * accept and FCID/Fabric name/Fabric portname is changed.
5052 * Default value is 0.
5053 */
James Smart8eb8b962016-07-06 12:36:08 -07005054LPFC_ATTR(delay_discovery, 0, 0, 1,
5055 "Delay NPort discovery when Clean Address bit is cleared.");
James Smart81301a92008-12-04 22:39:46 -05005056
5057/*
James Smart3621a712009-04-06 18:47:14 -04005058 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart96f70772013-04-17 20:16:15 -04005059 * This value can be set to values between 64 and 4096. The default value is
James Smart83108bd2008-01-11 01:53:09 -05005060 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5061 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04005062 * Because of the additional overhead involved in setting up T10-DIF,
5063 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5064 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05005065 */
5066LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
5067 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5068
James Smart96f70772013-04-17 20:16:15 -04005069/*
James Smart7bdedb32016-07-06 12:36:00 -07005070 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5071 * 0 = MDS Diagnostics disabled (default)
5072 * 1 = MDS Diagnostics enabled
5073 * Value range is [0,1]. Default value is 0.
5074 */
5075LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5076
Tony Jonesee959b02008-02-22 00:13:36 +01005077struct device_attribute *lpfc_hba_attrs[] = {
James Smart895427b2017-02-12 13:52:30 -08005078 &dev_attr_nvme_info,
James Smart81301a92008-12-04 22:39:46 -05005079 &dev_attr_bg_info,
5080 &dev_attr_bg_guard_err,
5081 &dev_attr_bg_apptag_err,
5082 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01005083 &dev_attr_info,
5084 &dev_attr_serialnum,
5085 &dev_attr_modeldesc,
5086 &dev_attr_modelname,
5087 &dev_attr_programtype,
5088 &dev_attr_portnum,
5089 &dev_attr_fwrev,
5090 &dev_attr_hdw,
5091 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005092 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005093 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04005094 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01005095 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04005096 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01005097 &dev_attr_lpfc_temp_sensor,
5098 &dev_attr_lpfc_log_verbose,
5099 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005100 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005101 &dev_attr_lpfc_hba_queue_depth,
5102 &dev_attr_lpfc_peer_port_login,
5103 &dev_attr_lpfc_nodev_tmo,
5104 &dev_attr_lpfc_devloss_tmo,
James Smart895427b2017-02-12 13:52:30 -08005105 &dev_attr_lpfc_enable_fc4_type,
5106 &dev_attr_lpfc_xri_split,
Tony Jonesee959b02008-02-22 00:13:36 +01005107 &dev_attr_lpfc_fcp_class,
5108 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005109 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005110 &dev_attr_lpfc_ack0,
5111 &dev_attr_lpfc_topology,
5112 &dev_attr_lpfc_scan_down,
5113 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04005114 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04005115 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01005116 &dev_attr_lpfc_cr_delay,
5117 &dev_attr_lpfc_cr_count,
5118 &dev_attr_lpfc_multi_ring_support,
5119 &dev_attr_lpfc_multi_ring_rctl,
5120 &dev_attr_lpfc_multi_ring_type,
5121 &dev_attr_lpfc_fdmi_on,
James Smart4258e982015-12-16 18:11:58 -05005122 &dev_attr_lpfc_enable_SmartSAN,
Tony Jonesee959b02008-02-22 00:13:36 +01005123 &dev_attr_lpfc_max_luns,
5124 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04005125 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05005126 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01005127 &dev_attr_nport_evt_cnt,
5128 &dev_attr_board_mode,
5129 &dev_attr_max_vpi,
5130 &dev_attr_used_vpi,
5131 &dev_attr_max_rpi,
5132 &dev_attr_used_rpi,
5133 &dev_attr_max_xri,
5134 &dev_attr_used_xri,
5135 &dev_attr_npiv_info,
5136 &dev_attr_issue_reset,
5137 &dev_attr_lpfc_poll,
5138 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04005139 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01005140 &dev_attr_lpfc_use_msi,
James Smart895427b2017-02-12 13:52:30 -08005141 &dev_attr_lpfc_nvme_oas,
James Smartda0436e2009-05-22 14:51:39 -04005142 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04005143 &dev_attr_lpfc_fcp_cpu_map,
James Smart67d12732012-08-03 12:36:13 -04005144 &dev_attr_lpfc_fcp_io_channel,
James Smartf358dd02017-02-12 13:52:34 -08005145 &dev_attr_lpfc_suppress_rsp,
James Smart895427b2017-02-12 13:52:30 -08005146 &dev_attr_lpfc_nvme_io_channel,
James Smart2d7dbc42017-02-12 13:52:35 -08005147 &dev_attr_lpfc_nvmet_mrq,
5148 &dev_attr_lpfc_nvmet_mrq_post,
James Smart895427b2017-02-12 13:52:30 -08005149 &dev_attr_lpfc_nvme_enable_fb,
James Smart2d7dbc42017-02-12 13:52:35 -08005150 &dev_attr_lpfc_nvmet_fb_size,
James Smart81301a92008-12-04 22:39:46 -05005151 &dev_attr_lpfc_enable_bg,
James Smart352e5fd2016-12-30 06:57:47 -08005152 &dev_attr_lpfc_soft_wwnn,
5153 &dev_attr_lpfc_soft_wwpn,
5154 &dev_attr_lpfc_soft_wwn_enable,
Tony Jonesee959b02008-02-22 00:13:36 +01005155 &dev_attr_lpfc_enable_hba_reset,
5156 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05005157 &dev_attr_lpfc_EnableXLane,
5158 &dev_attr_lpfc_XLanePriority,
5159 &dev_attr_lpfc_xlane_lun,
5160 &dev_attr_lpfc_xlane_tgt,
5161 &dev_attr_lpfc_xlane_vpt,
5162 &dev_attr_lpfc_xlane_lun_state,
5163 &dev_attr_lpfc_xlane_lun_status,
James Smartc92c8412016-07-06 12:36:05 -07005164 &dev_attr_lpfc_xlane_priority,
Tony Jonesee959b02008-02-22 00:13:36 +01005165 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04005166 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04005167 &dev_attr_lpfc_stat_data_ctrl,
James Smart0d878412009-10-02 15:16:56 -04005168 &dev_attr_lpfc_aer_support,
5169 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04005170 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04005171 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05005172 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04005173 &dev_attr_lpfc_iocb_cnt,
5174 &dev_attr_iocb_hw,
5175 &dev_attr_txq_hw,
5176 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04005177 &dev_attr_lpfc_fips_level,
5178 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05005179 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04005180 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05005181 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05005182 &dev_attr_lpfc_xlane_supported,
James Smart7bdedb32016-07-06 12:36:00 -07005183 &dev_attr_lpfc_enable_mds_diags,
dea31012005-04-17 16:05:31 -05005184 NULL,
5185};
5186
Tony Jonesee959b02008-02-22 00:13:36 +01005187struct device_attribute *lpfc_vport_attrs[] = {
5188 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005189 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005190 &dev_attr_num_discovered_ports,
5191 &dev_attr_lpfc_drvr_version,
5192 &dev_attr_lpfc_log_verbose,
5193 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005194 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005195 &dev_attr_lpfc_nodev_tmo,
5196 &dev_attr_lpfc_devloss_tmo,
5197 &dev_attr_lpfc_hba_queue_depth,
5198 &dev_attr_lpfc_peer_port_login,
5199 &dev_attr_lpfc_restrict_login,
5200 &dev_attr_lpfc_fcp_class,
5201 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005202 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005203 &dev_attr_lpfc_max_luns,
5204 &dev_attr_nport_evt_cnt,
5205 &dev_attr_npiv_info,
5206 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04005207 &dev_attr_lpfc_max_scsicmpl_time,
5208 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04005209 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04005210 &dev_attr_lpfc_fips_level,
5211 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04005212 NULL,
5213};
5214
James Smarte59058c2008-08-24 21:49:00 -04005215/**
James Smart3621a712009-04-06 18:47:14 -04005216 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005217 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005218 * @kobj: kernel kobject that contains the kernel class device.
5219 * @bin_attr: kernel attributes passed to us.
5220 * @buf: contains the data to be written to the adapter IOREG space.
5221 * @off: offset into buffer to beginning of data.
5222 * @count: bytes to transfer.
5223 *
5224 * Description:
5225 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5226 * Uses the adapter io control registers to send buf contents to the adapter.
5227 *
5228 * Returns:
5229 * -ERANGE off and count combo out of range
5230 * -EINVAL off, count or buff address invalid
5231 * -EPERM adapter is offline
5232 * value of count, buf contents written
5233 **/
dea31012005-04-17 16:05:31 -05005234static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005235sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5236 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005237 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005238{
5239 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01005240 struct device *dev = container_of(kobj, struct device, kobj);
5241 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005242 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5243 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005244
James Smartf1126682009-06-10 17:22:44 -04005245 if (phba->sli_rev >= LPFC_SLI_REV4)
5246 return -EPERM;
5247
dea31012005-04-17 16:05:31 -05005248 if ((off + count) > FF_REG_AREA_SIZE)
5249 return -ERANGE;
5250
James Smartf7a919b2011-08-21 21:49:16 -04005251 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5252 return 0;
dea31012005-04-17 16:05:31 -05005253
5254 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5255 return -EINVAL;
5256
James Smartf7a919b2011-08-21 21:49:16 -04005257 /* This is to protect HBA registers from accidental writes. */
5258 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5259 return -EINVAL;
5260
5261 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05005262 return -EPERM;
dea31012005-04-17 16:05:31 -05005263
James Smart2e0fef82007-06-17 19:56:36 -05005264 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04005265 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5266 buf_off += sizeof(uint32_t))
5267 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05005268 phba->ctrl_regs_memmap_p + off + buf_off);
5269
James Smart2e0fef82007-06-17 19:56:36 -05005270 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005271
5272 return count;
5273}
5274
James Smarte59058c2008-08-24 21:49:00 -04005275/**
James Smart3621a712009-04-06 18:47:14 -04005276 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005277 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005278 * @kobj: kernel kobject that contains the kernel class device.
5279 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005280 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04005281 * @off: offset into buffer to beginning of data.
5282 * @count: bytes to transfer.
5283 *
5284 * Description:
5285 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5286 * Uses the adapter io control registers to read data into buf.
5287 *
5288 * Returns:
5289 * -ERANGE off and count combo out of range
5290 * -EINVAL off, count or buff address invalid
5291 * value of count, buf contents read
5292 **/
dea31012005-04-17 16:05:31 -05005293static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005294sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5295 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005296 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005297{
5298 size_t buf_off;
5299 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01005300 struct device *dev = container_of(kobj, struct device, kobj);
5301 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005302 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5303 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005304
James Smartf1126682009-06-10 17:22:44 -04005305 if (phba->sli_rev >= LPFC_SLI_REV4)
5306 return -EPERM;
5307
dea31012005-04-17 16:05:31 -05005308 if (off > FF_REG_AREA_SIZE)
5309 return -ERANGE;
5310
5311 if ((off + count) > FF_REG_AREA_SIZE)
5312 count = FF_REG_AREA_SIZE - off;
5313
5314 if (count == 0) return 0;
5315
5316 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5317 return -EINVAL;
5318
James Smart2e0fef82007-06-17 19:56:36 -05005319 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005320
5321 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5322 tmp_ptr = (uint32_t *)(buf + buf_off);
5323 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5324 }
5325
James Smart2e0fef82007-06-17 19:56:36 -05005326 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005327
5328 return count;
5329}
5330
5331static struct bin_attribute sysfs_ctlreg_attr = {
5332 .attr = {
5333 .name = "ctlreg",
5334 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005335 },
5336 .size = 256,
5337 .read = sysfs_ctlreg_read,
5338 .write = sysfs_ctlreg_write,
5339};
5340
James Smarte59058c2008-08-24 21:49:00 -04005341/**
James Smart3621a712009-04-06 18:47:14 -04005342 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005343 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005344 * @kobj: kernel kobject that contains the kernel class device.
5345 * @bin_attr: kernel attributes passed to us.
5346 * @buf: contains the data to be written to sysfs mbox.
5347 * @off: offset into buffer to beginning of data.
5348 * @count: bytes to transfer.
5349 *
5350 * Description:
James Smart026abb82011-12-13 13:20:45 -05005351 * Deprecated function. All mailbox access from user space is performed via the
5352 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005353 *
5354 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005355 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005356 **/
dea31012005-04-17 16:05:31 -05005357static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005358sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5359 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005360 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005361{
James Smart026abb82011-12-13 13:20:45 -05005362 return -EPERM;
dea31012005-04-17 16:05:31 -05005363}
5364
James Smarte59058c2008-08-24 21:49:00 -04005365/**
James Smart3621a712009-04-06 18:47:14 -04005366 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005367 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005368 * @kobj: kernel kobject that contains the kernel class device.
5369 * @bin_attr: kernel attributes passed to us.
5370 * @buf: contains the data to be read from sysfs mbox.
5371 * @off: offset into buffer to beginning of data.
5372 * @count: bytes to transfer.
5373 *
5374 * Description:
James Smart026abb82011-12-13 13:20:45 -05005375 * Deprecated function. All mailbox access from user space is performed via the
5376 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005377 *
5378 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005379 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005380 **/
dea31012005-04-17 16:05:31 -05005381static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005382sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5383 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005384 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005385{
James Smart026abb82011-12-13 13:20:45 -05005386 return -EPERM;
dea31012005-04-17 16:05:31 -05005387}
5388
5389static struct bin_attribute sysfs_mbox_attr = {
5390 .attr = {
5391 .name = "mbox",
5392 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005393 },
James Smartc0c11512011-05-24 11:41:34 -04005394 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05005395 .read = sysfs_mbox_read,
5396 .write = sysfs_mbox_write,
5397};
5398
James Smarte59058c2008-08-24 21:49:00 -04005399/**
James Smart3621a712009-04-06 18:47:14 -04005400 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005401 * @vport: address of lpfc vport structure.
5402 *
5403 * Return codes:
5404 * zero on success
5405 * error return code from sysfs_create_bin_file()
5406 **/
dea31012005-04-17 16:05:31 -05005407int
James Smart2e0fef82007-06-17 19:56:36 -05005408lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005409{
James Smart2e0fef82007-06-17 19:56:36 -05005410 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005411 int error;
5412
Tony Jonesee959b02008-02-22 00:13:36 +01005413 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05005414 &sysfs_drvr_stat_data_attr);
5415
5416 /* Virtual ports do not need ctrl_reg and mbox */
5417 if (error || vport->port_type == LPFC_NPIV_PORT)
5418 goto out;
5419
5420 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005421 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005422 if (error)
James Smarteada2722008-12-04 22:39:13 -05005423 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05005424
Tony Jonesee959b02008-02-22 00:13:36 +01005425 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005426 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05005427 if (error)
5428 goto out_remove_ctlreg_attr;
5429
5430 return 0;
5431out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01005432 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05005433out_remove_stat_attr:
5434 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5435 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05005436out:
5437 return error;
5438}
5439
James Smarte59058c2008-08-24 21:49:00 -04005440/**
James Smart3621a712009-04-06 18:47:14 -04005441 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005442 * @vport: address of lpfc vport structure.
5443 **/
dea31012005-04-17 16:05:31 -05005444void
James Smart2e0fef82007-06-17 19:56:36 -05005445lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005446{
James Smart2e0fef82007-06-17 19:56:36 -05005447 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04005448 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5449 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05005450 /* Virtual ports do not need ctrl_reg and mbox */
5451 if (vport->port_type == LPFC_NPIV_PORT)
5452 return;
Tony Jonesee959b02008-02-22 00:13:36 +01005453 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5454 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005455}
5456
dea31012005-04-17 16:05:31 -05005457/*
5458 * Dynamic FC Host Attributes Support
5459 */
5460
James Smarte59058c2008-08-24 21:49:00 -04005461/**
James Smart6c9231f2016-12-19 15:07:24 -08005462 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5463 * @shost: kernel scsi host pointer.
5464 **/
5465static void
5466lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5467{
5468 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5469
5470 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5471 sizeof fc_host_symbolic_name(shost));
5472}
5473
5474/**
James Smart3621a712009-04-06 18:47:14 -04005475 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04005476 * @shost: kernel scsi host pointer.
5477 **/
dea31012005-04-17 16:05:31 -05005478static void
5479lpfc_get_host_port_id(struct Scsi_Host *shost)
5480{
James Smart2e0fef82007-06-17 19:56:36 -05005481 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5482
dea31012005-04-17 16:05:31 -05005483 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05005484 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005485}
5486
James Smarte59058c2008-08-24 21:49:00 -04005487/**
James Smart3621a712009-04-06 18:47:14 -04005488 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04005489 * @shost: kernel scsi host pointer.
5490 **/
dea31012005-04-17 16:05:31 -05005491static void
5492lpfc_get_host_port_type(struct Scsi_Host *shost)
5493{
James Smart2e0fef82007-06-17 19:56:36 -05005494 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5495 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005496
5497 spin_lock_irq(shost->host_lock);
5498
James Smart92d7f7b2007-06-17 19:56:38 -05005499 if (vport->port_type == LPFC_NPIV_PORT) {
5500 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5501 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05005502 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05005503 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05005504 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5505 else
5506 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5507 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005508 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05005509 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5510 else
5511 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5512 }
5513 } else
5514 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5515
5516 spin_unlock_irq(shost->host_lock);
5517}
5518
James Smarte59058c2008-08-24 21:49:00 -04005519/**
James Smart3621a712009-04-06 18:47:14 -04005520 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04005521 * @shost: kernel scsi host pointer.
5522 **/
dea31012005-04-17 16:05:31 -05005523static void
5524lpfc_get_host_port_state(struct Scsi_Host *shost)
5525{
James Smart2e0fef82007-06-17 19:56:36 -05005526 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5527 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005528
5529 spin_lock_irq(shost->host_lock);
5530
James Smart2e0fef82007-06-17 19:56:36 -05005531 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005532 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5533 else {
James Smart2e0fef82007-06-17 19:56:36 -05005534 switch (phba->link_state) {
5535 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05005536 case LPFC_LINK_DOWN:
5537 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5538 break;
5539 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05005540 case LPFC_CLEAR_LA:
5541 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05005542 /* Links up, reports port state accordingly */
5543 if (vport->port_state < LPFC_VPORT_READY)
5544 fc_host_port_state(shost) =
5545 FC_PORTSTATE_BYPASSED;
5546 else
5547 fc_host_port_state(shost) =
5548 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05005549 break;
5550 case LPFC_HBA_ERROR:
5551 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5552 break;
5553 default:
5554 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5555 break;
5556 }
5557 }
5558
5559 spin_unlock_irq(shost->host_lock);
5560}
5561
James Smarte59058c2008-08-24 21:49:00 -04005562/**
James Smart3621a712009-04-06 18:47:14 -04005563 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04005564 * @shost: kernel scsi host pointer.
5565 **/
dea31012005-04-17 16:05:31 -05005566static void
5567lpfc_get_host_speed(struct Scsi_Host *shost)
5568{
James Smart2e0fef82007-06-17 19:56:36 -05005569 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5570 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005571
5572 spin_lock_irq(shost->host_lock);
5573
James Smarta085e872015-12-16 18:12:02 -05005574 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea31012005-04-17 16:05:31 -05005575 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05005576 case LPFC_LINK_SPEED_1GHZ:
5577 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05005578 break;
James Smart76a95d72010-11-20 23:11:48 -05005579 case LPFC_LINK_SPEED_2GHZ:
5580 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05005581 break;
James Smart76a95d72010-11-20 23:11:48 -05005582 case LPFC_LINK_SPEED_4GHZ:
5583 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05005584 break;
James Smart76a95d72010-11-20 23:11:48 -05005585 case LPFC_LINK_SPEED_8GHZ:
5586 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04005587 break;
James Smart76a95d72010-11-20 23:11:48 -05005588 case LPFC_LINK_SPEED_10GHZ:
5589 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04005590 break;
James Smart76a95d72010-11-20 23:11:48 -05005591 case LPFC_LINK_SPEED_16GHZ:
5592 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5593 break;
James Smartd38dd522015-08-31 16:48:17 -04005594 case LPFC_LINK_SPEED_32GHZ:
5595 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5596 break;
James Smart76a95d72010-11-20 23:11:48 -05005597 default:
5598 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005599 break;
5600 }
James Smart09372822008-01-11 01:52:54 -05005601 } else
5602 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005603
5604 spin_unlock_irq(shost->host_lock);
5605}
5606
James Smarte59058c2008-08-24 21:49:00 -04005607/**
James Smart3621a712009-04-06 18:47:14 -04005608 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04005609 * @shost: kernel scsi host pointer.
5610 **/
dea31012005-04-17 16:05:31 -05005611static void
5612lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5613{
James Smart2e0fef82007-06-17 19:56:36 -05005614 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5615 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005616 u64 node_name;
dea31012005-04-17 16:05:31 -05005617
5618 spin_lock_irq(shost->host_lock);
5619
James Smart73d91e52011-10-10 21:32:10 -04005620 if ((vport->port_state > LPFC_FLOGI) &&
5621 ((vport->fc_flag & FC_FABRIC) ||
5622 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5623 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07005624 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05005625 else
5626 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05005627 node_name = 0;
dea31012005-04-17 16:05:31 -05005628
5629 spin_unlock_irq(shost->host_lock);
5630
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005631 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05005632}
5633
James Smarte59058c2008-08-24 21:49:00 -04005634/**
James Smart3621a712009-04-06 18:47:14 -04005635 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04005636 * @shost: kernel scsi host pointer.
5637 *
5638 * Notes:
5639 * NULL on error for link down, no mbox pool, sli2 active,
5640 * management not allowed, memory allocation error, or mbox error.
5641 *
5642 * Returns:
5643 * NULL for error
5644 * address of the adapter host statistics
5645 **/
dea31012005-04-17 16:05:31 -05005646static struct fc_host_statistics *
5647lpfc_get_stats(struct Scsi_Host *shost)
5648{
James Smart2e0fef82007-06-17 19:56:36 -05005649 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5650 struct lpfc_hba *phba = vport->phba;
5651 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005652 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04005653 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05005654 LPFC_MBOXQ_t *pmboxq;
5655 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04005656 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005657 int rc = 0;
dea31012005-04-17 16:05:31 -05005658
James Smart92d7f7b2007-06-17 19:56:38 -05005659 /*
5660 * prevent udev from issuing mailbox commands until the port is
5661 * configured.
5662 */
James Smart2e0fef82007-06-17 19:56:36 -05005663 if (phba->link_state < LPFC_LINK_DOWN ||
5664 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04005665 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05005666 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005667
5668 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005669 return NULL;
5670
dea31012005-04-17 16:05:31 -05005671 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5672 if (!pmboxq)
5673 return NULL;
5674 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5675
James Smart04c68492009-05-22 14:52:52 -04005676 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05005677 pmb->mbxCommand = MBX_READ_STATUS;
5678 pmb->mbxOwner = OWN_HOST;
5679 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005680 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005681
James Smart75baf692010-06-08 18:31:21 -04005682 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005683 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005684 else
dea31012005-04-17 16:05:31 -05005685 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5686
5687 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005688 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005689 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005690 return NULL;
5691 }
5692
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005693 memset(hs, 0, sizeof (struct fc_host_statistics));
5694
dea31012005-04-17 16:05:31 -05005695 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005696 /*
5697 * The MBX_READ_STATUS returns tx_k_bytes which has to
5698 * converted to words
5699 */
5700 hs->tx_words = (uint64_t)
5701 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5702 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005703 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005704 hs->rx_words = (uint64_t)
5705 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5706 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005707
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005708 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05005709 pmb->mbxCommand = MBX_READ_LNK_STAT;
5710 pmb->mbxOwner = OWN_HOST;
5711 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005712 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005713
James Smart75baf692010-06-08 18:31:21 -04005714 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005715 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005716 else
dea31012005-04-17 16:05:31 -05005717 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5718
5719 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005720 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005721 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005722 return NULL;
5723 }
5724
5725 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5726 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5727 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5728 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5729 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5730 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5731 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5732
James Smart64ba8812006-08-02 15:24:34 -04005733 hs->link_failure_count -= lso->link_failure_count;
5734 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5735 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5736 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5737 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5738 hs->invalid_crc_count -= lso->invalid_crc_count;
5739 hs->error_frames -= lso->error_frames;
5740
James Smart76a95d72010-11-20 23:11:48 -05005741 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04005742 hs->lip_count = -1;
5743 hs->nos_count = (phba->link_events >> 1);
5744 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05005745 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005746 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005747 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005748 hs->nos_count = -1;
5749 } else {
5750 hs->lip_count = -1;
5751 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005752 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005753 }
5754
5755 hs->dumped_frames = -1;
5756
James Smart64ba8812006-08-02 15:24:34 -04005757 seconds = get_seconds();
5758 if (seconds < psli->stats_start)
5759 hs->seconds_since_last_reset = seconds +
5760 ((unsigned long)-1 - psli->stats_start);
5761 else
5762 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05005763
James Smart1dcb58e2007-04-25 09:51:30 -04005764 mempool_free(pmboxq, phba->mbox_mem_pool);
5765
dea31012005-04-17 16:05:31 -05005766 return hs;
5767}
5768
James Smarte59058c2008-08-24 21:49:00 -04005769/**
James Smart3621a712009-04-06 18:47:14 -04005770 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04005771 * @shost: kernel scsi host pointer.
5772 **/
James Smart64ba8812006-08-02 15:24:34 -04005773static void
5774lpfc_reset_stats(struct Scsi_Host *shost)
5775{
James Smart2e0fef82007-06-17 19:56:36 -05005776 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5777 struct lpfc_hba *phba = vport->phba;
5778 struct lpfc_sli *psli = &phba->sli;
5779 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04005780 LPFC_MBOXQ_t *pmboxq;
5781 MAILBOX_t *pmb;
5782 int rc = 0;
5783
James Smart2e0fef82007-06-17 19:56:36 -05005784 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005785 return;
5786
James Smart64ba8812006-08-02 15:24:34 -04005787 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5788 if (!pmboxq)
5789 return;
5790 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5791
James Smart04c68492009-05-22 14:52:52 -04005792 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04005793 pmb->mbxCommand = MBX_READ_STATUS;
5794 pmb->mbxOwner = OWN_HOST;
5795 pmb->un.varWords[0] = 0x1; /* reset request */
5796 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005797 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005798
James Smart2e0fef82007-06-17 19:56:36 -05005799 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005800 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005801 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5802 else
5803 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5804
5805 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005806 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005807 mempool_free(pmboxq, phba->mbox_mem_pool);
5808 return;
5809 }
5810
5811 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5812 pmb->mbxCommand = MBX_READ_LNK_STAT;
5813 pmb->mbxOwner = OWN_HOST;
5814 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005815 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005816
James Smart2e0fef82007-06-17 19:56:36 -05005817 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005818 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005819 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5820 else
5821 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5822
5823 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005824 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005825 mempool_free( pmboxq, phba->mbox_mem_pool);
5826 return;
5827 }
5828
5829 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5830 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5831 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5832 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5833 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5834 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5835 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05005836 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04005837 lso->link_events = (phba->link_events >> 1);
5838 else
5839 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005840
5841 psli->stats_start = get_seconds();
5842
James Smart1dcb58e2007-04-25 09:51:30 -04005843 mempool_free(pmboxq, phba->mbox_mem_pool);
5844
James Smart64ba8812006-08-02 15:24:34 -04005845 return;
5846}
dea31012005-04-17 16:05:31 -05005847
5848/*
5849 * The LPFC driver treats linkdown handling as target loss events so there
5850 * are no sysfs handlers for link_down_tmo.
5851 */
James Smart685f0bf2007-04-25 09:53:08 -04005852
James Smarte59058c2008-08-24 21:49:00 -04005853/**
James Smart3621a712009-04-06 18:47:14 -04005854 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04005855 * @starget: kernel scsi target pointer.
5856 *
5857 * Returns:
5858 * address of the node list if found
5859 * NULL target not found
5860 **/
James Smart685f0bf2007-04-25 09:53:08 -04005861static struct lpfc_nodelist *
5862lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05005863{
James Smart2e0fef82007-06-17 19:56:36 -05005864 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5865 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04005866 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005867
5868 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005869 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05005870 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005871 if (NLP_CHK_NODE_ACT(ndlp) &&
5872 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04005873 starget->id == ndlp->nlp_sid) {
5874 spin_unlock_irq(shost->host_lock);
5875 return ndlp;
dea31012005-04-17 16:05:31 -05005876 }
5877 }
5878 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005879 return NULL;
5880}
dea31012005-04-17 16:05:31 -05005881
James Smarte59058c2008-08-24 21:49:00 -04005882/**
James Smart3621a712009-04-06 18:47:14 -04005883 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04005884 * @starget: kernel scsi target pointer.
5885 **/
James Smart685f0bf2007-04-25 09:53:08 -04005886static void
5887lpfc_get_starget_port_id(struct scsi_target *starget)
5888{
5889 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5890
5891 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05005892}
5893
James Smarte59058c2008-08-24 21:49:00 -04005894/**
James Smart3621a712009-04-06 18:47:14 -04005895 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04005896 * @starget: kernel scsi target pointer.
5897 *
5898 * Description: Set the target node name to the ndlp node name wwn or zero.
5899 **/
dea31012005-04-17 16:05:31 -05005900static void
5901lpfc_get_starget_node_name(struct scsi_target *starget)
5902{
James Smart685f0bf2007-04-25 09:53:08 -04005903 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005904
James Smart685f0bf2007-04-25 09:53:08 -04005905 fc_starget_node_name(starget) =
5906 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005907}
5908
James Smarte59058c2008-08-24 21:49:00 -04005909/**
James Smart3621a712009-04-06 18:47:14 -04005910 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04005911 * @starget: kernel scsi target pointer.
5912 *
5913 * Description: set the target port name to the ndlp port name wwn or zero.
5914 **/
dea31012005-04-17 16:05:31 -05005915static void
5916lpfc_get_starget_port_name(struct scsi_target *starget)
5917{
James Smart685f0bf2007-04-25 09:53:08 -04005918 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005919
James Smart685f0bf2007-04-25 09:53:08 -04005920 fc_starget_port_name(starget) =
5921 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005922}
5923
James Smarte59058c2008-08-24 21:49:00 -04005924/**
James Smart3621a712009-04-06 18:47:14 -04005925 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04005926 * @rport: fc rport address.
5927 * @timeout: new value for dev loss tmo.
5928 *
5929 * Description:
5930 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5931 * dev_loss_tmo to one.
5932 **/
dea31012005-04-17 16:05:31 -05005933static void
dea31012005-04-17 16:05:31 -05005934lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5935{
dea31012005-04-17 16:05:31 -05005936 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04005937 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05005938 else
James Smartc01f3202006-08-18 17:47:08 -04005939 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05005940}
5941
James Smarte59058c2008-08-24 21:49:00 -04005942/**
James Smart3621a712009-04-06 18:47:14 -04005943 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04005944 *
5945 * Description:
5946 * Macro that uses field to generate a function with the name lpfc_show_rport_
5947 *
5948 * lpfc_show_rport_##field: returns the bytes formatted in buf
5949 * @cdev: class converted to an fc_rport.
5950 * @buf: on return contains the target_field or zero.
5951 *
5952 * Returns: size of formatted string.
5953 **/
dea31012005-04-17 16:05:31 -05005954#define lpfc_rport_show_function(field, format_string, sz, cast) \
5955static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01005956lpfc_show_rport_##field (struct device *dev, \
5957 struct device_attribute *attr, \
5958 char *buf) \
dea31012005-04-17 16:05:31 -05005959{ \
Tony Jonesee959b02008-02-22 00:13:36 +01005960 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05005961 struct lpfc_rport_data *rdata = rport->hostdata; \
5962 return snprintf(buf, sz, format_string, \
5963 (rdata->target) ? cast rdata->target->field : 0); \
5964}
5965
5966#define lpfc_rport_rd_attr(field, format_string, sz) \
5967 lpfc_rport_show_function(field, format_string, sz, ) \
5968static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5969
James Smarteada2722008-12-04 22:39:13 -05005970/**
James Smart3621a712009-04-06 18:47:14 -04005971 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05005972 * @fc_vport: The fc_vport who's symbolic name has been changed.
5973 *
5974 * Description:
5975 * This function is called by the transport after the @fc_vport's symbolic name
5976 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005977 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05005978 **/
5979static void
5980lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5981{
5982 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5983
5984 if (vport->port_state == LPFC_VPORT_READY)
5985 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5986}
dea31012005-04-17 16:05:31 -05005987
James Smartf4b4c682009-05-22 14:53:12 -04005988/**
5989 * lpfc_hba_log_verbose_init - Set hba's log verbose level
5990 * @phba: Pointer to lpfc_hba struct.
5991 *
5992 * This function is called by the lpfc_get_cfgparam() routine to set the
5993 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02005994 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04005995 * before hba port or vport created.
5996 **/
5997static void
5998lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
5999{
6000 phba->cfg_log_verbose = verbose;
6001}
6002
dea31012005-04-17 16:05:31 -05006003struct fc_function_template lpfc_transport_functions = {
6004 /* fixed attributes the driver supports */
6005 .show_host_node_name = 1,
6006 .show_host_port_name = 1,
6007 .show_host_supported_classes = 1,
6008 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05006009 .show_host_supported_speeds = 1,
6010 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006011
6012 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006013 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05006014
6015 /* dynamic attributes the driver supports */
6016 .get_host_port_id = lpfc_get_host_port_id,
6017 .show_host_port_id = 1,
6018
6019 .get_host_port_type = lpfc_get_host_port_type,
6020 .show_host_port_type = 1,
6021
6022 .get_host_port_state = lpfc_get_host_port_state,
6023 .show_host_port_state = 1,
6024
6025 /* active_fc4s is shown but doesn't change (thus no get function) */
6026 .show_host_active_fc4s = 1,
6027
6028 .get_host_speed = lpfc_get_host_speed,
6029 .show_host_speed = 1,
6030
6031 .get_host_fabric_name = lpfc_get_host_fabric_name,
6032 .show_host_fabric_name = 1,
6033
6034 /*
6035 * The LPFC driver treats linkdown handling as target loss events
6036 * so there are no sysfs handlers for link_down_tmo.
6037 */
6038
6039 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04006040 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05006041
6042 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6043 .show_rport_maxframe_size = 1,
6044 .show_rport_supported_classes = 1,
6045
dea31012005-04-17 16:05:31 -05006046 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6047 .show_rport_dev_loss_tmo = 1,
6048
6049 .get_starget_port_id = lpfc_get_starget_port_id,
6050 .show_starget_port_id = 1,
6051
6052 .get_starget_node_name = lpfc_get_starget_node_name,
6053 .show_starget_node_name = 1,
6054
6055 .get_starget_port_name = lpfc_get_starget_port_name,
6056 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07006057
6058 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04006059 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6060 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05006061
James Smart92d7f7b2007-06-17 19:56:38 -05006062 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05006063
6064 .vport_disable = lpfc_vport_disable,
6065
6066 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04006067
6068 .bsg_request = lpfc_bsg_request,
6069 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05006070};
6071
James Smart98c9ea52007-10-27 13:37:33 -04006072struct fc_function_template lpfc_vport_transport_functions = {
6073 /* fixed attributes the driver supports */
6074 .show_host_node_name = 1,
6075 .show_host_port_name = 1,
6076 .show_host_supported_classes = 1,
6077 .show_host_supported_fc4s = 1,
6078 .show_host_supported_speeds = 1,
6079 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006080
6081 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006082 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04006083
6084 /* dynamic attributes the driver supports */
6085 .get_host_port_id = lpfc_get_host_port_id,
6086 .show_host_port_id = 1,
6087
6088 .get_host_port_type = lpfc_get_host_port_type,
6089 .show_host_port_type = 1,
6090
6091 .get_host_port_state = lpfc_get_host_port_state,
6092 .show_host_port_state = 1,
6093
6094 /* active_fc4s is shown but doesn't change (thus no get function) */
6095 .show_host_active_fc4s = 1,
6096
6097 .get_host_speed = lpfc_get_host_speed,
6098 .show_host_speed = 1,
6099
6100 .get_host_fabric_name = lpfc_get_host_fabric_name,
6101 .show_host_fabric_name = 1,
6102
6103 /*
6104 * The LPFC driver treats linkdown handling as target loss events
6105 * so there are no sysfs handlers for link_down_tmo.
6106 */
6107
6108 .get_fc_host_stats = lpfc_get_stats,
6109 .reset_fc_host_stats = lpfc_reset_stats,
6110
6111 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6112 .show_rport_maxframe_size = 1,
6113 .show_rport_supported_classes = 1,
6114
6115 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6116 .show_rport_dev_loss_tmo = 1,
6117
6118 .get_starget_port_id = lpfc_get_starget_port_id,
6119 .show_starget_port_id = 1,
6120
6121 .get_starget_node_name = lpfc_get_starget_node_name,
6122 .show_starget_node_name = 1,
6123
6124 .get_starget_port_name = lpfc_get_starget_port_name,
6125 .show_starget_port_name = 1,
6126
6127 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6128 .terminate_rport_io = lpfc_terminate_rport_io,
6129
6130 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05006131
6132 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04006133};
6134
James Smarte59058c2008-08-24 21:49:00 -04006135/**
James Smart3621a712009-04-06 18:47:14 -04006136 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04006137 * @phba: lpfc_hba pointer.
6138 **/
dea31012005-04-17 16:05:31 -05006139void
6140lpfc_get_cfgparam(struct lpfc_hba *phba)
6141{
James Smart49aa1432012-08-03 12:36:42 -04006142 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04006143 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006144 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6145 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05006146 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05006147 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6148 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006149 lpfc_ack0_init(phba, lpfc_ack0);
6150 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006151 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05006152 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04006153 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04006154 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04006155 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05006156 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4258e982015-12-16 18:11:58 -05006157 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6158 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
James Smart4ff43242006-12-02 13:34:56 -05006159 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart895427b2017-02-12 13:52:30 -08006160 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
James Smartda0436e2009-05-22 14:51:39 -04006161 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04006162 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart13815c82008-01-11 01:52:48 -05006163 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6164 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart2ea259e2017-02-12 13:52:27 -08006165
James Smart1ba981f2014-02-20 09:56:45 -05006166 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6167 if (phba->sli_rev != LPFC_SLI_REV4)
6168 phba->cfg_EnableXLane = 0;
6169 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
James Smart2ea259e2017-02-12 13:52:27 -08006170
James Smart1ba981f2014-02-20 09:56:45 -05006171 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6172 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6173 phba->cfg_oas_lun_state = 0;
6174 phba->cfg_oas_lun_status = 0;
6175 phba->cfg_oas_flags = 0;
James Smartc92c8412016-07-06 12:36:05 -07006176 phba->cfg_oas_priority = 0;
James Smart81301a92008-12-04 22:39:46 -05006177 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smartb3b98b72016-10-13 15:06:06 -07006178 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6179 lpfc_prot_guard_init(phba, lpfc_prot_guard);
James Smart45ed1192009-10-02 15:17:02 -04006180 if (phba->sli_rev == LPFC_SLI_REV4)
6181 phba->cfg_poll = 0;
6182 else
James Smart1ba981f2014-02-20 09:56:45 -05006183 phba->cfg_poll = lpfc_poll;
James Smartf358dd02017-02-12 13:52:34 -08006184 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
James Smart4258e982015-12-16 18:11:58 -05006185
James Smart895427b2017-02-12 13:52:30 -08006186 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
James Smart2d7dbc42017-02-12 13:52:35 -08006187 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
6188 lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
James Smart895427b2017-02-12 13:52:30 -08006189
6190 /* Initialize first burst. Target vs Initiator are different. */
6191 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
James Smart2d7dbc42017-02-12 13:52:35 -08006192 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
James Smart895427b2017-02-12 13:52:30 -08006193 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6194 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
6195
6196 if (phba->sli_rev != LPFC_SLI_REV4) {
6197 /* NVME only supported on SLI4 */
6198 phba->nvmet_support = 0;
6199 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
6200 } else {
6201 /* We MUST have FCP support */
6202 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6203 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6204 }
6205
6206 /* A value of 0 means use the number of CPUs found in the system */
James Smart895427b2017-02-12 13:52:30 -08006207 if (phba->cfg_fcp_io_channel == 0)
6208 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006209 if (phba->cfg_nvme_io_channel == 0)
6210 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smart895427b2017-02-12 13:52:30 -08006211
6212 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6213 phba->cfg_fcp_io_channel = 0;
6214
James Smartf358dd02017-02-12 13:52:34 -08006215 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6216 phba->cfg_nvme_io_channel = 0;
6217
James Smart895427b2017-02-12 13:52:30 -08006218 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6219 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6220 else
6221 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6222
James Smart352e5fd2016-12-30 06:57:47 -08006223 phba->cfg_soft_wwnn = 0L;
6224 phba->cfg_soft_wwpn = 0L;
James Smart895427b2017-02-12 13:52:30 -08006225 lpfc_xri_split_init(phba, lpfc_xri_split);
James Smart83108bd2008-01-11 01:53:09 -05006226 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04006227 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04006228 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04006229 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04006230 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04006231 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05006232 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04006233 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart8eb8b962016-07-06 12:36:08 -07006234 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
James Smart12247e82016-07-06 12:36:09 -07006235 lpfc_sli_mode_init(phba, lpfc_sli_mode);
James Smartab56dc22011-02-16 12:39:57 -05006236 phba->cfg_enable_dss = 1;
James Smart7bdedb32016-07-06 12:36:00 -07006237 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
James Smart3de2a652007-08-02 11:09:59 -04006238 return;
6239}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05006240
James Smarte59058c2008-08-24 21:49:00 -04006241/**
James Smart895427b2017-02-12 13:52:30 -08006242 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6243 * dependencies between protocols and roles.
6244 * @phba: lpfc_hba pointer.
6245 **/
6246void
6247lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6248{
James Smart895427b2017-02-12 13:52:30 -08006249 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6250 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006251
James Smart895427b2017-02-12 13:52:30 -08006252 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6253 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6254
James Smartf358dd02017-02-12 13:52:34 -08006255 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6256 phba->nvmet_support) {
6257 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6258 phba->cfg_fcp_io_channel = 0;
James Smart2d7dbc42017-02-12 13:52:35 -08006259
6260 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6261 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6262 "NVME Target PRLI ACC enable_fb ",
6263 phba->cfg_nvme_enable_fb,
6264 phba->cfg_nvmet_fb_size,
6265 LPFC_NVMET_FB_SZ_MAX);
6266
6267 if (phba->cfg_nvme_enable_fb == 0)
6268 phba->cfg_nvmet_fb_size = 0;
6269 else {
6270 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6271 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6272 }
6273
6274 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6275 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6276 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6277 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6278 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6279 phba->cfg_nvmet_mrq);
6280 }
6281 } else {
James Smartf358dd02017-02-12 13:52:34 -08006282 /* Not NVME Target mode. Turn off Target parameters. */
6283 phba->nvmet_support = 0;
James Smart2d7dbc42017-02-12 13:52:35 -08006284 phba->cfg_nvmet_mrq = 0;
6285 phba->cfg_nvmet_mrq_post = 0;
6286 phba->cfg_nvmet_fb_size = 0;
6287 }
James Smartf358dd02017-02-12 13:52:34 -08006288
James Smart895427b2017-02-12 13:52:30 -08006289 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6290 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6291 else
6292 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6293}
6294
6295/**
James Smart3621a712009-04-06 18:47:14 -04006296 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04006297 * @vport: lpfc_vport pointer.
6298 **/
James Smart3de2a652007-08-02 11:09:59 -04006299void
6300lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6301{
James Smarte8b62012007-08-02 11:10:09 -04006302 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04006303 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04006304 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04006305 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6306 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6307 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6308 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6309 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6310 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04006311 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04006312 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04006313 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6314 lpfc_max_luns_init(vport, lpfc_max_luns);
6315 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04006316 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05006317 return;
6318}