brintos

brintos / linux-shallow public Read only

0
0
Text · 218.9 KiB · 39b5041 Raw
7414 lines · c
1/*******************************************************************2 * This file is part of the Emulex Linux Device Driver for         *3 * Fibre Channel Host Bus Adapters.                                *4 * Copyright (C) 2017-2024 Broadcom. All Rights Reserved. The term *5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.  *6 * Copyright (C) 2004-2016 Emulex.  All rights reserved.           *7 * EMULEX and SLI are trademarks of Emulex.                        *8 * www.broadcom.com                                                *9 * Portions Copyright (C) 2004-2005 Christoph Hellwig              *10 *                                                                 *11 * This program is free software; you can redistribute it and/or   *12 * 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.                                     *22 *******************************************************************/23 24#include <linux/ctype.h>25#include <linux/delay.h>26#include <linux/pci.h>27#include <linux/interrupt.h>28#include <linux/module.h>29#include <linux/aer.h>30#include <linux/gfp.h>31#include <linux/kernel.h>32 33#include <scsi/scsi.h>34#include <scsi/scsi_device.h>35#include <scsi/scsi_host.h>36#include <scsi/scsi_tcq.h>37#include <scsi/scsi_transport_fc.h>38#include <scsi/fc/fc_fs.h>39 40#include "lpfc_hw4.h"41#include "lpfc_hw.h"42#include "lpfc_sli.h"43#include "lpfc_sli4.h"44#include "lpfc_nl.h"45#include "lpfc_disc.h"46#include "lpfc.h"47#include "lpfc_scsi.h"48#include "lpfc_nvme.h"49#include "lpfc_logmsg.h"50#include "lpfc_version.h"51#include "lpfc_compat.h"52#include "lpfc_crtn.h"53#include "lpfc_vport.h"54#include "lpfc_attr.h"55 56#define LPFC_DEF_DEVLOSS_TMO	3057#define LPFC_MIN_DEVLOSS_TMO	158#define LPFC_MAX_DEVLOSS_TMO	25559 60#define LPFC_MAX_INFO_TMP_LEN	10061#define LPFC_INFO_MORE_STR	"\nCould be more info...\n"62/*63 * Write key size should be multiple of 4. If write key is changed64 * make sure that library write key is also changed.65 */66#define LPFC_REG_WRITE_KEY_SIZE	467#define LPFC_REG_WRITE_KEY	"EMLX"68 69const char *const trunk_errmsg[] = {	/* map errcode */70	"",	/* There is no such error code at index 0*/71	"link negotiated speed does not match existing"72		" trunk - link was \"low\" speed",73	"link negotiated speed does not match"74		" existing trunk - link was \"middle\" speed",75	"link negotiated speed does not match existing"76		" trunk - link was \"high\" speed",77	"Attached to non-trunking port - F_Port",78	"Attached to non-trunking port - N_Port",79	"FLOGI response timeout",80	"non-FLOGI frame received",81	"Invalid FLOGI response",82	"Trunking initialization protocol",83	"Trunk peer device mismatch",84};85 86/**87 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules88 * @incr: integer to convert.89 * @hdw: ascii string holding converted integer plus a string terminator.90 *91 * Description:92 * JEDEC Joint Electron Device Engineering Council.93 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii94 * character string. The string is then terminated with a NULL in byte 9.95 * Hex 0-9 becomes ascii '0' to '9'.96 * Hex a-f becomes ascii '=' to 'B' capital B.97 *98 * Notes:99 * Coded for 32 bit integers only.100 **/101static void102lpfc_jedec_to_ascii(int incr, char hdw[])103{104	int i, j;105	for (i = 0; i < 8; i++) {106		j = (incr & 0xf);107		if (j <= 9)108			hdw[7 - i] = 0x30 +  j;109		 else110			hdw[7 - i] = 0x61 + j - 10;111		incr = (incr >> 4);112	}113	hdw[8] = 0;114	return;115}116 117static ssize_t118lpfc_cmf_info_show(struct device *dev, struct device_attribute *attr,119		   char *buf)120{121	struct Scsi_Host  *shost = class_to_shost(dev);122	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;123	struct lpfc_hba   *phba = vport->phba;124	struct lpfc_cgn_info *cp = NULL;125	struct lpfc_cgn_stat *cgs;126	int  len = 0;127	int cpu;128	u64 rcv, total;129	char tmp[LPFC_MAX_INFO_TMP_LEN] = {0};130 131	if (phba->cgn_i)132		cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;133 134	scnprintf(tmp, sizeof(tmp),135		  "Congestion Mgmt Info: E2Eattr %d Ver %d "136		  "CMF %d cnt %d\n",137		  phba->sli4_hba.pc_sli4_params.mi_cap,138		  cp ? cp->cgn_info_version : 0,139		  phba->sli4_hba.pc_sli4_params.cmf, phba->cmf_timer_cnt);140 141	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)142		goto buffer_done;143 144	if (!phba->sli4_hba.pc_sli4_params.cmf)145		goto buffer_done;146 147	switch (phba->cgn_init_reg_signal) {148	case EDC_CG_SIG_WARN_ONLY:149		scnprintf(tmp, sizeof(tmp),150			  "Register: Init:  Signal:WARN  ");151		break;152	case EDC_CG_SIG_WARN_ALARM:153		scnprintf(tmp, sizeof(tmp),154			  "Register: Init:  Signal:WARN|ALARM  ");155		break;156	default:157		scnprintf(tmp, sizeof(tmp),158			  "Register: Init:  Signal:NONE  ");159		break;160	}161	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)162		goto buffer_done;163 164	switch (phba->cgn_init_reg_fpin) {165	case LPFC_CGN_FPIN_WARN:166		scnprintf(tmp, sizeof(tmp),167			  "FPIN:WARN\n");168		break;169	case LPFC_CGN_FPIN_ALARM:170		scnprintf(tmp, sizeof(tmp),171			  "FPIN:ALARM\n");172		break;173	case LPFC_CGN_FPIN_BOTH:174		scnprintf(tmp, sizeof(tmp),175			  "FPIN:WARN|ALARM\n");176		break;177	default:178		scnprintf(tmp, sizeof(tmp),179			  "FPIN:NONE\n");180		break;181	}182	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)183		goto buffer_done;184 185	switch (phba->cgn_reg_signal) {186	case EDC_CG_SIG_WARN_ONLY:187		scnprintf(tmp, sizeof(tmp),188			  "       Current:  Signal:WARN  ");189		break;190	case EDC_CG_SIG_WARN_ALARM:191		scnprintf(tmp, sizeof(tmp),192			  "       Current:  Signal:WARN|ALARM  ");193		break;194	default:195		scnprintf(tmp, sizeof(tmp),196			  "       Current:  Signal:NONE  ");197		break;198	}199	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)200		goto buffer_done;201 202	switch (phba->cgn_reg_fpin) {203	case LPFC_CGN_FPIN_WARN:204		scnprintf(tmp, sizeof(tmp),205			  "FPIN:WARN  ACQEcnt:%d\n", phba->cgn_acqe_cnt);206		break;207	case LPFC_CGN_FPIN_ALARM:208		scnprintf(tmp, sizeof(tmp),209			  "FPIN:ALARM  ACQEcnt:%d\n", phba->cgn_acqe_cnt);210		break;211	case LPFC_CGN_FPIN_BOTH:212		scnprintf(tmp, sizeof(tmp),213			  "FPIN:WARN|ALARM  ACQEcnt:%d\n", phba->cgn_acqe_cnt);214		break;215	default:216		scnprintf(tmp, sizeof(tmp),217			  "FPIN:NONE  ACQEcnt:%d\n", phba->cgn_acqe_cnt);218		break;219	}220	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)221		goto buffer_done;222 223	if (phba->cmf_active_mode != phba->cgn_p.cgn_param_mode) {224		switch (phba->cmf_active_mode) {225		case LPFC_CFG_OFF:226			scnprintf(tmp, sizeof(tmp), "Active: Mode:Off\n");227			break;228		case LPFC_CFG_MANAGED:229			scnprintf(tmp, sizeof(tmp), "Active: Mode:Managed\n");230			break;231		case LPFC_CFG_MONITOR:232			scnprintf(tmp, sizeof(tmp), "Active: Mode:Monitor\n");233			break;234		default:235			scnprintf(tmp, sizeof(tmp), "Active: Mode:Unknown\n");236		}237		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)238			goto buffer_done;239	}240 241	switch (phba->cgn_p.cgn_param_mode) {242	case LPFC_CFG_OFF:243		scnprintf(tmp, sizeof(tmp), "Config: Mode:Off  ");244		break;245	case LPFC_CFG_MANAGED:246		scnprintf(tmp, sizeof(tmp), "Config: Mode:Managed ");247		break;248	case LPFC_CFG_MONITOR:249		scnprintf(tmp, sizeof(tmp), "Config: Mode:Monitor ");250		break;251	default:252		scnprintf(tmp, sizeof(tmp), "Config: Mode:Unknown ");253	}254	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)255		goto buffer_done;256 257	total = 0;258	rcv = 0;259	for_each_present_cpu(cpu) {260		cgs = per_cpu_ptr(phba->cmf_stat, cpu);261		total += atomic64_read(&cgs->total_bytes);262		rcv += atomic64_read(&cgs->rcv_bytes);263	}264 265	scnprintf(tmp, sizeof(tmp),266		  "IObusy:%d Info:%d Bytes: Rcv:x%llx Total:x%llx\n",267		  atomic_read(&phba->cmf_busy),268		  phba->cmf_active_info, rcv, total);269	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)270		goto buffer_done;271 272	scnprintf(tmp, sizeof(tmp),273		  "Port_speed:%d  Link_byte_cnt:%ld  "274		  "Max_byte_per_interval:%ld\n",275		  lpfc_sli_port_speed_get(phba),276		  (unsigned long)phba->cmf_link_byte_count,277		  (unsigned long)phba->cmf_max_bytes_per_interval);278	strlcat(buf, tmp, PAGE_SIZE);279 280buffer_done:281	len = strnlen(buf, PAGE_SIZE);282 283	if (unlikely(len >= (PAGE_SIZE - 1))) {284		lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,285				"6312 Catching potential buffer "286				"overflow > PAGE_SIZE = %lu bytes\n",287				PAGE_SIZE);288		strscpy(buf + PAGE_SIZE - 1 - sizeof(LPFC_INFO_MORE_STR),289			LPFC_INFO_MORE_STR, sizeof(LPFC_INFO_MORE_STR) + 1);290	}291	return len;292}293 294/**295 * lpfc_drvr_version_show - Return the Emulex driver string with version number296 * @dev: class unused variable.297 * @attr: device attribute, not used.298 * @buf: on return contains the module description text.299 *300 * Returns: size of formatted string.301 **/302static ssize_t303lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,304		       char *buf)305{306	return scnprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");307}308 309/**310 * lpfc_enable_fip_show - Return the fip mode of the HBA311 * @dev: class unused variable.312 * @attr: device attribute, not used.313 * @buf: on return contains the module description text.314 *315 * Returns: size of formatted string.316 **/317static ssize_t318lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,319		       char *buf)320{321	struct Scsi_Host *shost = class_to_shost(dev);322	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;323	struct lpfc_hba   *phba = vport->phba;324 325	if (test_bit(HBA_FIP_SUPPORT, &phba->hba_flag))326		return scnprintf(buf, PAGE_SIZE, "1\n");327	else328		return scnprintf(buf, PAGE_SIZE, "0\n");329}330 331static ssize_t332lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,333		    char *buf)334{335	struct Scsi_Host *shost = class_to_shost(dev);336	struct lpfc_vport *vport = shost_priv(shost);337	struct lpfc_hba   *phba = vport->phba;338	struct lpfc_nvmet_tgtport *tgtp;339	struct nvme_fc_local_port *localport;340	struct lpfc_nvme_lport *lport;341	struct lpfc_nvme_rport *rport;342	struct lpfc_nodelist *ndlp;343	struct nvme_fc_remote_port *nrport;344	struct lpfc_fc4_ctrl_stat *cstat;345	uint64_t data1, data2, data3;346	uint64_t totin, totout, tot;347	unsigned long iflags;348	char *statep;349	int i;350	int len = 0;351	char tmp[LPFC_MAX_INFO_TMP_LEN] = {0};352 353	if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {354		len = scnprintf(buf, PAGE_SIZE, "NVME Disabled\n");355		return len;356	}357	if (phba->nvmet_support) {358		if (!phba->targetport) {359			len = scnprintf(buf, PAGE_SIZE,360					"NVME Target: x%llx is not allocated\n",361					wwn_to_u64(vport->fc_portname.u.wwn));362			return len;363		}364		/* Port state is only one of two values for now. */365		if (phba->targetport->port_id)366			statep = "REGISTERED";367		else368			statep = "INIT";369		scnprintf(tmp, sizeof(tmp),370			  "NVME Target Enabled  State %s\n",371			  statep);372		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)373			goto buffer_done;374 375		scnprintf(tmp, sizeof(tmp),376			  "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",377			  "NVME Target: lpfc",378			  phba->brd_no,379			  wwn_to_u64(vport->fc_portname.u.wwn),380			  wwn_to_u64(vport->fc_nodename.u.wwn),381			  phba->targetport->port_id);382		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)383			goto buffer_done;384 385		if (strlcat(buf, "\nNVME Target: Statistics\n", PAGE_SIZE)386		    >= PAGE_SIZE)387			goto buffer_done;388 389		tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;390		scnprintf(tmp, sizeof(tmp),391			  "LS: Rcv %08x Drop %08x Abort %08x\n",392			  atomic_read(&tgtp->rcv_ls_req_in),393			  atomic_read(&tgtp->rcv_ls_req_drop),394			  atomic_read(&tgtp->xmt_ls_abort));395		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)396			goto buffer_done;397 398		if (atomic_read(&tgtp->rcv_ls_req_in) !=399		    atomic_read(&tgtp->rcv_ls_req_out)) {400			scnprintf(tmp, sizeof(tmp),401				  "Rcv LS: in %08x != out %08x\n",402				  atomic_read(&tgtp->rcv_ls_req_in),403				  atomic_read(&tgtp->rcv_ls_req_out));404			if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)405				goto buffer_done;406		}407 408		scnprintf(tmp, sizeof(tmp),409			  "LS: Xmt %08x Drop %08x Cmpl %08x\n",410			  atomic_read(&tgtp->xmt_ls_rsp),411			  atomic_read(&tgtp->xmt_ls_drop),412			  atomic_read(&tgtp->xmt_ls_rsp_cmpl));413		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)414			goto buffer_done;415 416		scnprintf(tmp, sizeof(tmp),417			  "LS: RSP Abort %08x xb %08x Err %08x\n",418			  atomic_read(&tgtp->xmt_ls_rsp_aborted),419			  atomic_read(&tgtp->xmt_ls_rsp_xb_set),420			  atomic_read(&tgtp->xmt_ls_rsp_error));421		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)422			goto buffer_done;423 424		scnprintf(tmp, sizeof(tmp),425			  "FCP: Rcv %08x Defer %08x Release %08x "426			  "Drop %08x\n",427			  atomic_read(&tgtp->rcv_fcp_cmd_in),428			  atomic_read(&tgtp->rcv_fcp_cmd_defer),429			  atomic_read(&tgtp->xmt_fcp_release),430			  atomic_read(&tgtp->rcv_fcp_cmd_drop));431		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)432			goto buffer_done;433 434		if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=435		    atomic_read(&tgtp->rcv_fcp_cmd_out)) {436			scnprintf(tmp, sizeof(tmp),437				  "Rcv FCP: in %08x != out %08x\n",438				  atomic_read(&tgtp->rcv_fcp_cmd_in),439				  atomic_read(&tgtp->rcv_fcp_cmd_out));440			if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)441				goto buffer_done;442		}443 444		scnprintf(tmp, sizeof(tmp),445			  "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "446			  "drop %08x\n",447			  atomic_read(&tgtp->xmt_fcp_read),448			  atomic_read(&tgtp->xmt_fcp_read_rsp),449			  atomic_read(&tgtp->xmt_fcp_write),450			  atomic_read(&tgtp->xmt_fcp_rsp),451			  atomic_read(&tgtp->xmt_fcp_drop));452		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)453			goto buffer_done;454 455		scnprintf(tmp, sizeof(tmp),456			  "FCP Rsp Cmpl: %08x err %08x drop %08x\n",457			  atomic_read(&tgtp->xmt_fcp_rsp_cmpl),458			  atomic_read(&tgtp->xmt_fcp_rsp_error),459			  atomic_read(&tgtp->xmt_fcp_rsp_drop));460		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)461			goto buffer_done;462 463		scnprintf(tmp, sizeof(tmp),464			  "FCP Rsp Abort: %08x xb %08x xricqe  %08x\n",465			  atomic_read(&tgtp->xmt_fcp_rsp_aborted),466			  atomic_read(&tgtp->xmt_fcp_rsp_xb_set),467			  atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));468		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)469			goto buffer_done;470 471		scnprintf(tmp, sizeof(tmp),472			  "ABORT: Xmt %08x Cmpl %08x\n",473			  atomic_read(&tgtp->xmt_fcp_abort),474			  atomic_read(&tgtp->xmt_fcp_abort_cmpl));475		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)476			goto buffer_done;477 478		scnprintf(tmp, sizeof(tmp),479			  "ABORT: Sol %08x  Usol %08x Err %08x Cmpl %08x\n",480			  atomic_read(&tgtp->xmt_abort_sol),481			  atomic_read(&tgtp->xmt_abort_unsol),482			  atomic_read(&tgtp->xmt_abort_rsp),483			  atomic_read(&tgtp->xmt_abort_rsp_error));484		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)485			goto buffer_done;486 487		scnprintf(tmp, sizeof(tmp),488			  "DELAY: ctx %08x  fod %08x wqfull %08x\n",489			  atomic_read(&tgtp->defer_ctx),490			  atomic_read(&tgtp->defer_fod),491			  atomic_read(&tgtp->defer_wqfull));492		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)493			goto buffer_done;494 495		/* Calculate outstanding IOs */496		tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);497		tot += atomic_read(&tgtp->xmt_fcp_release);498		tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;499 500		scnprintf(tmp, sizeof(tmp),501			  "IO_CTX: %08x  WAIT: cur %08x tot %08x\n"502			  "CTX Outstanding %08llx\n\n",503			  phba->sli4_hba.nvmet_xri_cnt,504			  phba->sli4_hba.nvmet_io_wait_cnt,505			  phba->sli4_hba.nvmet_io_wait_total,506			  tot);507		strlcat(buf, tmp, PAGE_SIZE);508		goto buffer_done;509	}510 511	localport = vport->localport;512	if (!localport) {513		len = scnprintf(buf, PAGE_SIZE,514				"NVME Initiator x%llx is not allocated\n",515				wwn_to_u64(vport->fc_portname.u.wwn));516		return len;517	}518	lport = (struct lpfc_nvme_lport *)localport->private;519	if (strlcat(buf, "\nNVME Initiator Enabled\n", PAGE_SIZE) >= PAGE_SIZE)520		goto buffer_done;521 522	scnprintf(tmp, sizeof(tmp),523		  "XRI Dist lpfc%d Total %d IO %d ELS %d\n",524		  phba->brd_no,525		  phba->sli4_hba.max_cfg_param.max_xri,526		  phba->sli4_hba.io_xri_max,527		  lpfc_sli4_get_els_iocb_cnt(phba));528	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)529		goto buffer_done;530 531	/* Port state is only one of two values for now. */532	if (localport->port_id)533		statep = "ONLINE";534	else535		statep = "UNKNOWN ";536 537	scnprintf(tmp, sizeof(tmp),538		  "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",539		  "NVME LPORT lpfc",540		  phba->brd_no,541		  wwn_to_u64(vport->fc_portname.u.wwn),542		  wwn_to_u64(vport->fc_nodename.u.wwn),543		  localport->port_id, statep);544	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)545		goto buffer_done;546 547	spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);548 549	list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {550		nrport = NULL;551		spin_lock(&ndlp->lock);552		rport = lpfc_ndlp_get_nrport(ndlp);553		if (rport)554			nrport = rport->remoteport;555		spin_unlock(&ndlp->lock);556		if (!nrport)557			continue;558 559		/* Port state is only one of two values for now. */560		switch (nrport->port_state) {561		case FC_OBJSTATE_ONLINE:562			statep = "ONLINE";563			break;564		case FC_OBJSTATE_UNKNOWN:565			statep = "UNKNOWN ";566			break;567		default:568			statep = "UNSUPPORTED";569			break;570		}571 572		/* Tab in to show lport ownership. */573		if (strlcat(buf, "NVME RPORT       ", PAGE_SIZE) >= PAGE_SIZE)574			goto unlock_buf_done;575		if (phba->brd_no >= 10) {576			if (strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)577				goto unlock_buf_done;578		}579 580		scnprintf(tmp, sizeof(tmp), "WWPN x%llx ",581			  nrport->port_name);582		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)583			goto unlock_buf_done;584 585		scnprintf(tmp, sizeof(tmp), "WWNN x%llx ",586			  nrport->node_name);587		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)588			goto unlock_buf_done;589 590		scnprintf(tmp, sizeof(tmp), "DID x%06x ",591			  nrport->port_id);592		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)593			goto unlock_buf_done;594 595		/* An NVME rport can have multiple roles. */596		if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR) {597			if (strlcat(buf, "INITIATOR ", PAGE_SIZE) >= PAGE_SIZE)598				goto unlock_buf_done;599		}600		if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET) {601			if (strlcat(buf, "TARGET ", PAGE_SIZE) >= PAGE_SIZE)602				goto unlock_buf_done;603		}604		if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY) {605			if (strlcat(buf, "DISCSRVC ", PAGE_SIZE) >= PAGE_SIZE)606				goto unlock_buf_done;607		}608		if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |609					  FC_PORT_ROLE_NVME_TARGET |610					  FC_PORT_ROLE_NVME_DISCOVERY)) {611			scnprintf(tmp, sizeof(tmp), "UNKNOWN ROLE x%x",612				  nrport->port_role);613			if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)614				goto unlock_buf_done;615		}616 617		scnprintf(tmp, sizeof(tmp), "%s\n", statep);618		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)619			goto unlock_buf_done;620	}621	spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);622 623	if (!lport)624		goto buffer_done;625 626	if (strlcat(buf, "\nNVME Statistics\n", PAGE_SIZE) >= PAGE_SIZE)627		goto buffer_done;628 629	scnprintf(tmp, sizeof(tmp),630		  "LS: Xmt %010x Cmpl %010x Abort %08x\n",631		  atomic_read(&lport->fc4NvmeLsRequests),632		  atomic_read(&lport->fc4NvmeLsCmpls),633		  atomic_read(&lport->xmt_ls_abort));634	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)635		goto buffer_done;636 637	scnprintf(tmp, sizeof(tmp),638		  "LS XMIT: Err %08x  CMPL: xb %08x Err %08x\n",639		  atomic_read(&lport->xmt_ls_err),640		  atomic_read(&lport->cmpl_ls_xb),641		  atomic_read(&lport->cmpl_ls_err));642	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)643		goto buffer_done;644 645	totin = 0;646	totout = 0;647	for (i = 0; i < phba->cfg_hdw_queue; i++) {648		cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;649		tot = cstat->io_cmpls;650		totin += tot;651		data1 = cstat->input_requests;652		data2 = cstat->output_requests;653		data3 = cstat->control_requests;654		totout += (data1 + data2 + data3);655	}656	scnprintf(tmp, sizeof(tmp),657		  "Total FCP Cmpl %016llx Issue %016llx "658		  "OutIO %016llx\n",659		  totin, totout, totout - totin);660	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)661		goto buffer_done;662 663	scnprintf(tmp, sizeof(tmp),664		  "\tabort %08x noxri %08x nondlp %08x qdepth %08x "665		  "wqerr %08x err %08x\n",666		  atomic_read(&lport->xmt_fcp_abort),667		  atomic_read(&lport->xmt_fcp_noxri),668		  atomic_read(&lport->xmt_fcp_bad_ndlp),669		  atomic_read(&lport->xmt_fcp_qdepth),670		  atomic_read(&lport->xmt_fcp_wqerr),671		  atomic_read(&lport->xmt_fcp_err));672	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)673		goto buffer_done;674 675	scnprintf(tmp, sizeof(tmp),676		  "FCP CMPL: xb %08x Err %08x\n",677		  atomic_read(&lport->cmpl_fcp_xb),678		  atomic_read(&lport->cmpl_fcp_err));679	strlcat(buf, tmp, PAGE_SIZE);680 681	/* host_lock is already unlocked. */682	goto buffer_done;683 684 unlock_buf_done:685	spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);686 687 buffer_done:688	len = strnlen(buf, PAGE_SIZE);689 690	if (unlikely(len >= (PAGE_SIZE - 1))) {691		lpfc_printf_log(phba, KERN_INFO, LOG_NVME,692				"6314 Catching potential buffer "693				"overflow > PAGE_SIZE = %lu bytes\n",694				PAGE_SIZE);695		strscpy(buf + PAGE_SIZE - 1 - sizeof(LPFC_INFO_MORE_STR),696			LPFC_INFO_MORE_STR,697			sizeof(LPFC_INFO_MORE_STR) + 1);698	}699 700	return len;701}702 703static ssize_t704lpfc_scsi_stat_show(struct device *dev, struct device_attribute *attr,705		    char *buf)706{707	struct Scsi_Host *shost = class_to_shost(dev);708	struct lpfc_vport *vport = shost_priv(shost);709	struct lpfc_hba *phba = vport->phba;710	int len;711	struct lpfc_fc4_ctrl_stat *cstat;712	u64 data1, data2, data3;713	u64 tot, totin, totout;714	int i;715	char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};716 717	if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||718	    (phba->sli_rev != LPFC_SLI_REV4))719		return 0;720 721	scnprintf(buf, PAGE_SIZE, "SCSI HDWQ Statistics\n");722 723	totin = 0;724	totout = 0;725	for (i = 0; i < phba->cfg_hdw_queue; i++) {726		cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;727		tot = cstat->io_cmpls;728		totin += tot;729		data1 = cstat->input_requests;730		data2 = cstat->output_requests;731		data3 = cstat->control_requests;732		totout += (data1 + data2 + data3);733 734		scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "735			  "IO %016llx ", i, data1, data2, data3);736		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)737			goto buffer_done;738 739		scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",740			  tot, ((data1 + data2 + data3) - tot));741		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)742			goto buffer_done;743	}744	scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "745		  "OutIO %016llx\n", totin, totout, totout - totin);746	strlcat(buf, tmp, PAGE_SIZE);747 748buffer_done:749	len = strnlen(buf, PAGE_SIZE);750 751	return len;752}753 754static ssize_t755lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,756		  char *buf)757{758	struct Scsi_Host *shost = class_to_shost(dev);759	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;760	struct lpfc_hba   *phba = vport->phba;761 762	if (phba->cfg_enable_bg) {763		if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)764			return scnprintf(buf, PAGE_SIZE,765					"BlockGuard Enabled\n");766		else767			return scnprintf(buf, PAGE_SIZE,768					"BlockGuard Not Supported\n");769	} else770		return scnprintf(buf, PAGE_SIZE,771					"BlockGuard Disabled\n");772}773 774static ssize_t775lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,776		       char *buf)777{778	struct Scsi_Host *shost = class_to_shost(dev);779	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;780	struct lpfc_hba   *phba = vport->phba;781 782	return scnprintf(buf, PAGE_SIZE, "%llu\n",783			(unsigned long long)phba->bg_guard_err_cnt);784}785 786static ssize_t787lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,788			char *buf)789{790	struct Scsi_Host *shost = class_to_shost(dev);791	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;792	struct lpfc_hba   *phba = vport->phba;793 794	return scnprintf(buf, PAGE_SIZE, "%llu\n",795			(unsigned long long)phba->bg_apptag_err_cnt);796}797 798static ssize_t799lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,800			char *buf)801{802	struct Scsi_Host *shost = class_to_shost(dev);803	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;804	struct lpfc_hba   *phba = vport->phba;805 806	return scnprintf(buf, PAGE_SIZE, "%llu\n",807			(unsigned long long)phba->bg_reftag_err_cnt);808}809 810/**811 * lpfc_info_show - Return some pci info about the host in ascii812 * @dev: class converted to a Scsi_host structure.813 * @attr: device attribute, not used.814 * @buf: on return contains the formatted text from lpfc_info().815 *816 * Returns: size of formatted string.817 **/818static ssize_t819lpfc_info_show(struct device *dev, struct device_attribute *attr,820	       char *buf)821{822	struct Scsi_Host *host = class_to_shost(dev);823 824	return scnprintf(buf, PAGE_SIZE, "%s\n", lpfc_info(host));825}826 827/**828 * lpfc_serialnum_show - Return the hba serial number in ascii829 * @dev: class converted to a Scsi_host structure.830 * @attr: device attribute, not used.831 * @buf: on return contains the formatted text serial number.832 *833 * Returns: size of formatted string.834 **/835static ssize_t836lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,837		    char *buf)838{839	struct Scsi_Host  *shost = class_to_shost(dev);840	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;841	struct lpfc_hba   *phba = vport->phba;842 843	return scnprintf(buf, PAGE_SIZE, "%s\n", phba->SerialNumber);844}845 846/**847 * lpfc_temp_sensor_show - Return the temperature sensor level848 * @dev: class converted to a Scsi_host structure.849 * @attr: device attribute, not used.850 * @buf: on return contains the formatted support level.851 *852 * Description:853 * Returns a number indicating the temperature sensor level currently854 * supported, zero or one in ascii.855 *856 * Returns: size of formatted string.857 **/858static ssize_t859lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,860		      char *buf)861{862	struct Scsi_Host *shost = class_to_shost(dev);863	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;864	struct lpfc_hba   *phba = vport->phba;865	return scnprintf(buf, PAGE_SIZE, "%d\n", phba->temp_sensor_support);866}867 868/**869 * lpfc_modeldesc_show - Return the model description of the hba870 * @dev: class converted to a Scsi_host structure.871 * @attr: device attribute, not used.872 * @buf: on return contains the scsi vpd model description.873 *874 * Returns: size of formatted string.875 **/876static ssize_t877lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,878		    char *buf)879{880	struct Scsi_Host  *shost = class_to_shost(dev);881	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;882	struct lpfc_hba   *phba = vport->phba;883 884	return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelDesc);885}886 887/**888 * lpfc_modelname_show - Return the model name of the hba889 * @dev: class converted to a Scsi_host structure.890 * @attr: device attribute, not used.891 * @buf: on return contains the scsi vpd model name.892 *893 * Returns: size of formatted string.894 **/895static ssize_t896lpfc_modelname_show(struct device *dev, struct device_attribute *attr,897		    char *buf)898{899	struct Scsi_Host  *shost = class_to_shost(dev);900	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;901	struct lpfc_hba   *phba = vport->phba;902 903	return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelName);904}905 906/**907 * lpfc_programtype_show - Return the program type of the hba908 * @dev: class converted to a Scsi_host structure.909 * @attr: device attribute, not used.910 * @buf: on return contains the scsi vpd program type.911 *912 * Returns: size of formatted string.913 **/914static ssize_t915lpfc_programtype_show(struct device *dev, struct device_attribute *attr,916		      char *buf)917{918	struct Scsi_Host  *shost = class_to_shost(dev);919	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;920	struct lpfc_hba   *phba = vport->phba;921 922	return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ProgramType);923}924 925/**926 * lpfc_vportnum_show - Return the port number in ascii of the hba927 * @dev: class converted to a Scsi_host structure.928 * @attr: device attribute, not used.929 * @buf: on return contains scsi vpd program type.930 *931 * Returns: size of formatted string.932 **/933static ssize_t934lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,935		   char *buf)936{937	struct Scsi_Host  *shost = class_to_shost(dev);938	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;939	struct lpfc_hba   *phba = vport->phba;940 941	return scnprintf(buf, PAGE_SIZE, "%s\n", phba->Port);942}943 944/**945 * lpfc_fwrev_show - Return the firmware rev running in the hba946 * @dev: class converted to a Scsi_host structure.947 * @attr: device attribute, not used.948 * @buf: on return contains the scsi vpd program type.949 *950 * Returns: size of formatted string.951 **/952static ssize_t953lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,954		char *buf)955{956	struct Scsi_Host  *shost = class_to_shost(dev);957	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;958	struct lpfc_hba   *phba = vport->phba;959	uint32_t if_type;960	uint8_t sli_family;961	char fwrev[FW_REV_STR_SIZE];962	int len;963 964	lpfc_decode_firmware_rev(phba, fwrev, 1);965	if_type = phba->sli4_hba.pc_sli4_params.if_type;966	sli_family = phba->sli4_hba.pc_sli4_params.sli_family;967 968	if (phba->sli_rev < LPFC_SLI_REV4)969		len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d\n",970			       fwrev, phba->sli_rev);971	else972		len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",973			       fwrev, phba->sli_rev, if_type, sli_family);974 975	return len;976}977 978/**979 * lpfc_hdw_show - Return the jedec information about the hba980 * @dev: class converted to a Scsi_host structure.981 * @attr: device attribute, not used.982 * @buf: on return contains the scsi vpd program type.983 *984 * Returns: size of formatted string.985 **/986static ssize_t987lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)988{989	char hdw[9];990	struct Scsi_Host  *shost = class_to_shost(dev);991	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;992	struct lpfc_hba   *phba = vport->phba;993	lpfc_vpd_t *vp = &phba->vpd;994 995	lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);996	return scnprintf(buf, PAGE_SIZE, "%s %08x %08x\n", hdw,997			 vp->rev.smRev, vp->rev.smFwRev);998}999 1000/**1001 * lpfc_option_rom_version_show - Return the adapter ROM FCode version1002 * @dev: class converted to a Scsi_host structure.1003 * @attr: device attribute, not used.1004 * @buf: on return contains the ROM and FCode ascii strings.1005 *1006 * Returns: size of formatted string.1007 **/1008static ssize_t1009lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,1010			     char *buf)1011{1012	struct Scsi_Host  *shost = class_to_shost(dev);1013	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;1014	struct lpfc_hba   *phba = vport->phba;1015	char fwrev[FW_REV_STR_SIZE];1016 1017	if (phba->sli_rev < LPFC_SLI_REV4)1018		return scnprintf(buf, PAGE_SIZE, "%s\n",1019				phba->OptionROMVersion);1020 1021	lpfc_decode_firmware_rev(phba, fwrev, 1);1022	return scnprintf(buf, PAGE_SIZE, "%s\n", fwrev);1023}1024 1025/**1026 * lpfc_link_state_show - Return the link state of the port1027 * @dev: class converted to a Scsi_host structure.1028 * @attr: device attribute, not used.1029 * @buf: on return contains text describing the state of the link.1030 *1031 * Notes:1032 * The switch statement has no default so zero will be returned.1033 *1034 * Returns: size of formatted string.1035 **/1036static ssize_t1037lpfc_link_state_show(struct device *dev, struct device_attribute *attr,1038		     char *buf)1039{1040	struct Scsi_Host  *shost = class_to_shost(dev);1041	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;1042	struct lpfc_hba   *phba = vport->phba;1043	int  len = 0;1044 1045	switch (phba->link_state) {1046	case LPFC_LINK_UNKNOWN:1047	case LPFC_WARM_START:1048	case LPFC_INIT_START:1049	case LPFC_INIT_MBX_CMDS:1050	case LPFC_LINK_DOWN:1051	case LPFC_HBA_ERROR:1052		if (test_bit(LINK_DISABLED, &phba->hba_flag))1053			len += scnprintf(buf + len, PAGE_SIZE-len,1054				"Link Down - User disabled\n");1055		else1056			len += scnprintf(buf + len, PAGE_SIZE-len,1057				"Link Down\n");1058		break;1059	case LPFC_LINK_UP:1060	case LPFC_CLEAR_LA:1061	case LPFC_HBA_READY:1062		len += scnprintf(buf + len, PAGE_SIZE-len, "Link Up - ");1063 1064		switch (vport->port_state) {1065		case LPFC_LOCAL_CFG_LINK:1066			len += scnprintf(buf + len, PAGE_SIZE-len,1067					"Configuring Link\n");1068			break;1069		case LPFC_FDISC:1070		case LPFC_FLOGI:1071		case LPFC_FABRIC_CFG_LINK:1072		case LPFC_NS_REG:1073		case LPFC_NS_QRY:1074		case LPFC_BUILD_DISC_LIST:1075		case LPFC_DISC_AUTH:1076			len += scnprintf(buf + len, PAGE_SIZE - len,1077					"Discovery\n");1078			break;1079		case LPFC_VPORT_READY:1080			len += scnprintf(buf + len, PAGE_SIZE - len,1081					"Ready\n");1082			break;1083 1084		case LPFC_VPORT_FAILED:1085			len += scnprintf(buf + len, PAGE_SIZE - len,1086					"Failed\n");1087			break;1088 1089		case LPFC_VPORT_UNKNOWN:1090			len += scnprintf(buf + len, PAGE_SIZE - len,1091					"Unknown\n");1092			break;1093		}1094		if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {1095			if (test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))1096				len += scnprintf(buf + len, PAGE_SIZE-len,1097						"   Public Loop\n");1098			else1099				len += scnprintf(buf + len, PAGE_SIZE-len,1100						"   Private Loop\n");1101		} else {1102			if (test_bit(FC_FABRIC, &vport->fc_flag)) {1103				if (phba->sli_rev == LPFC_SLI_REV4 &&1104				    vport->port_type == LPFC_PHYSICAL_PORT &&1105				    phba->sli4_hba.fawwpn_flag &1106					LPFC_FAWWPN_FABRIC)1107					len += scnprintf(buf + len,1108							 PAGE_SIZE - len,1109							 "   Fabric FA-PWWN\n");1110				else1111					len += scnprintf(buf + len,1112							 PAGE_SIZE - len,1113							 "   Fabric\n");1114			} else {1115				len += scnprintf(buf + len, PAGE_SIZE-len,1116						"   Point-2-Point\n");1117			}1118		}1119	}1120 1121	if ((phba->sli_rev == LPFC_SLI_REV4) &&1122	    ((bf_get(lpfc_sli_intf_if_type,1123	     &phba->sli4_hba.sli_intf) ==1124	     LPFC_SLI_INTF_IF_TYPE_6))) {1125		struct lpfc_trunk_link link = phba->trunk_link;1126 1127		if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))1128			len += scnprintf(buf + len, PAGE_SIZE - len,1129				"Trunk port 0: Link %s %s\n",1130				(link.link0.state == LPFC_LINK_UP) ?1131				 "Up" : "Down. ",1132				trunk_errmsg[link.link0.fault]);1133 1134		if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))1135			len += scnprintf(buf + len, PAGE_SIZE - len,1136				"Trunk port 1: Link %s %s\n",1137				(link.link1.state == LPFC_LINK_UP) ?1138				 "Up" : "Down. ",1139				trunk_errmsg[link.link1.fault]);1140 1141		if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))1142			len += scnprintf(buf + len, PAGE_SIZE - len,1143				"Trunk port 2: Link %s %s\n",1144				(link.link2.state == LPFC_LINK_UP) ?1145				 "Up" : "Down. ",1146				trunk_errmsg[link.link2.fault]);1147 1148		if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))1149			len += scnprintf(buf + len, PAGE_SIZE - len,1150				"Trunk port 3: Link %s %s\n",1151				(link.link3.state == LPFC_LINK_UP) ?1152				 "Up" : "Down. ",1153				trunk_errmsg[link.link3.fault]);1154 1155	}1156 1157	return len;1158}1159 1160/**1161 * lpfc_sli4_protocol_show - Return the fip mode of the HBA1162 * @dev: class unused variable.1163 * @attr: device attribute, not used.1164 * @buf: on return contains the module description text.1165 *1166 * Returns: size of formatted string.1167 **/1168static ssize_t1169lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,1170			char *buf)1171{1172	struct Scsi_Host *shost = class_to_shost(dev);1173	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;1174	struct lpfc_hba *phba = vport->phba;1175 1176	if (phba->sli_rev < LPFC_SLI_REV4)1177		return scnprintf(buf, PAGE_SIZE, "fc\n");1178 1179	if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {1180		if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)1181			return scnprintf(buf, PAGE_SIZE, "fcoe\n");1182		if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)1183			return scnprintf(buf, PAGE_SIZE, "fc\n");1184	}1185	return scnprintf(buf, PAGE_SIZE, "unknown\n");1186}1187 1188/**1189 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage1190 *			    (OAS) is supported.1191 * @dev: class unused variable.1192 * @attr: device attribute, not used.1193 * @buf: on return contains the module description text.1194 *1195 * Returns: size of formatted string.1196 **/1197static ssize_t1198lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,1199			char *buf)1200{1201	struct Scsi_Host *shost = class_to_shost(dev);1202	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;1203	struct lpfc_hba *phba = vport->phba;1204 1205	return scnprintf(buf, PAGE_SIZE, "%d\n",1206			phba->sli4_hba.pc_sli4_params.oas_supported);1207}1208 1209/**1210 * lpfc_link_state_store - Transition the link_state on an HBA port1211 * @dev: class device that is converted into a Scsi_host.1212 * @attr: device attribute, not used.1213 * @buf: one or more lpfc_polling_flags values.1214 * @count: not used.1215 *1216 * Returns:1217 * -EINVAL if the buffer is not "up" or "down"1218 * return from link state change function if non-zero1219 * length of the buf on success1220 **/1221static ssize_t1222lpfc_link_state_store(struct device *dev, struct device_attribute *attr,1223		const char *buf, size_t count)1224{1225	struct Scsi_Host  *shost = class_to_shost(dev);1226	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;1227	struct lpfc_hba   *phba = vport->phba;1228 1229	int status = -EINVAL;1230 1231	if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&1232			(phba->link_state == LPFC_LINK_DOWN))1233		status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);1234	else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&1235			(phba->link_state >= LPFC_LINK_UP))1236		status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);1237 1238	if (status == 0)1239		return strlen(buf);1240	else1241		return status;1242}1243 1244/**1245 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports1246 * @dev: class device that is converted into a Scsi_host.1247 * @attr: device attribute, not used.1248 * @buf: on return contains the sum of fc mapped and unmapped.1249 *1250 * Description:1251 * Returns the ascii text number of the sum of the fc mapped and unmapped1252 * vport counts.1253 *1254 * Returns: size of formatted string.1255 **/1256static ssize_t1257lpfc_num_discovered_ports_show(struct device *dev,1258			       struct device_attribute *attr, char *buf)1259{1260	struct Scsi_Host  *shost = class_to_shost(dev);1261	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;1262 1263	return scnprintf(buf, PAGE_SIZE, "%d\n",1264			 atomic_read(&vport->fc_map_cnt) +1265			 atomic_read(&vport->fc_unmap_cnt));1266}1267 1268/**1269 * lpfc_issue_lip - Misnomer, name carried over from long ago1270 * @shost: Scsi_Host pointer.1271 *1272 * Description:1273 * Bring the link down gracefully then re-init the link. The firmware will1274 * re-init the fiber channel interface as required. Does not issue a LIP.1275 *1276 * Returns:1277 * -EPERM port offline or management commands are being blocked1278 * -ENOMEM cannot allocate memory for the mailbox command1279 * -EIO error sending the mailbox command1280 * zero for success1281 **/1282static int1283lpfc_issue_lip(struct Scsi_Host *shost)1284{1285	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;1286	struct lpfc_hba   *phba = vport->phba;1287	LPFC_MBOXQ_t *pmboxq;1288	int mbxstatus = MBXERR_ERROR;1289 1290	/*1291	 * If the link is offline, disabled or BLOCK_MGMT_IO1292	 * it doesn't make any sense to allow issue_lip1293	 */1294	if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag) ||1295	    test_bit(LINK_DISABLED, &phba->hba_flag) ||1296	    (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))1297		return -EPERM;1298 1299	pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);1300 1301	if (!pmboxq)1302		return -ENOMEM;1303 1304	memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));1305	pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;1306	pmboxq->u.mb.mbxOwner = OWN_HOST;1307 1308	if (test_bit(FC_PT2PT, &vport->fc_flag))1309		clear_bit(FC_PT2PT_NO_NVME, &vport->fc_flag);1310 1311	mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);1312 1313	if ((mbxstatus == MBX_SUCCESS) &&1314	    (pmboxq->u.mb.mbxStatus == 0 ||1315	     pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {1316		memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));1317		lpfc_init_link(phba, pmboxq, phba->cfg_topology,1318			       phba->cfg_link_speed);1319		mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,1320						     phba->fc_ratov * 2);1321		if ((mbxstatus == MBX_SUCCESS) &&1322		    (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))1323			lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,1324					"2859 SLI authentication is required "1325					"for INIT_LINK but has not done yet\n");1326	}1327 1328	lpfc_set_loopback_flag(phba);1329	if (mbxstatus != MBX_TIMEOUT)1330		mempool_free(pmboxq, phba->mbox_mem_pool);1331 1332	if (mbxstatus == MBXERR_ERROR)1333		return -EIO;1334 1335	return 0;1336}1337 1338int1339lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)1340{1341	int cnt = 0;1342 1343	spin_lock_irq(lock);1344	while (!list_empty(q)) {1345		spin_unlock_irq(lock);1346		msleep(20);1347		if (cnt++ > 250) {  /* 5 secs */1348			lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,1349					"0466 Outstanding IO when "1350					"bringing Adapter offline\n");1351				return 0;1352		}1353		spin_lock_irq(lock);1354	}1355	spin_unlock_irq(lock);1356	return 1;1357}1358 1359/**1360 * lpfc_do_offline - Issues a mailbox command to bring the link down1361 * @phba: lpfc_hba pointer.1362 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.1363 *1364 * Notes:1365 * Assumes any error from lpfc_do_offline() will be negative.1366 * Can wait up to 5 seconds for the port ring buffers count1367 * to reach zero, prints a warning if it is not zero and continues.1368 * lpfc_workq_post_event() returns a non-zero return code if call fails.1369 *1370 * Returns:1371 * -EIO error posting the event1372 * zero for success1373 **/1374static int1375lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)1376{1377	struct completion online_compl;1378	struct lpfc_queue *qp = NULL;1379	struct lpfc_sli_ring *pring;1380	struct lpfc_sli *psli;1381	int status = 0;1382	int i;1383	int rc;1384 1385	init_completion(&online_compl);1386	rc = lpfc_workq_post_event(phba, &status, &online_compl,1387			      LPFC_EVT_OFFLINE_PREP);1388	if (rc == 0)1389		return -ENOMEM;1390 1391	wait_for_completion(&online_compl);1392 1393	if (status != 0)1394		return -EIO;1395 1396	psli = &phba->sli;1397 1398	/*1399	 * If freeing the queues have already started, don't access them.1400	 * Otherwise set FREE_WAIT to indicate that queues are being used1401	 * to hold the freeing process until we finish.1402	 */1403	spin_lock_irq(&phba->hbalock);1404	if (!(psli->sli_flag & LPFC_QUEUE_FREE_INIT)) {1405		psli->sli_flag |= LPFC_QUEUE_FREE_WAIT;1406	} else {1407		spin_unlock_irq(&phba->hbalock);1408		goto skip_wait;1409	}1410	spin_unlock_irq(&phba->hbalock);1411 1412	/* Wait a little for things to settle down, but not1413	 * long enough for dev loss timeout to expire.1414	 */1415	if (phba->sli_rev != LPFC_SLI_REV4) {1416		for (i = 0; i < psli->num_rings; i++) {1417			pring = &psli->sli3_ring[i];1418			if (!lpfc_emptyq_wait(phba, &pring->txcmplq,1419					      &phba->hbalock))1420				goto out;1421		}1422	} else {1423		list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {1424			pring = qp->pring;1425			if (!pring)1426				continue;1427			if (!lpfc_emptyq_wait(phba, &pring->txcmplq,1428					      &pring->ring_lock))1429				goto out;1430		}1431	}1432out:1433	spin_lock_irq(&phba->hbalock);1434	psli->sli_flag &= ~LPFC_QUEUE_FREE_WAIT;1435	spin_unlock_irq(&phba->hbalock);1436 1437skip_wait:1438	init_completion(&online_compl);1439	rc = lpfc_workq_post_event(phba, &status, &online_compl, type);1440	if (rc == 0)1441		return -ENOMEM;1442 1443	wait_for_completion(&online_compl);1444 1445	if (status != 0)1446		return -EIO;1447 1448	return 0;1449}1450 1451/**1452 * lpfc_reset_pci_bus - resets PCI bridge controller's secondary bus of an HBA1453 * @phba: lpfc_hba pointer.1454 *1455 * Description:1456 * Issues a PCI secondary bus reset for the phba->pcidev.1457 *1458 * Notes:1459 * First walks the bus_list to ensure only PCI devices with Emulex1460 * vendor id, device ids that support hot reset, only one occurrence1461 * of function 0, and all ports on the bus are in offline mode to ensure the1462 * hot reset only affects one valid HBA.1463 *1464 * Returns:1465 * -ENOTSUPP, cfg_enable_hba_reset must be of value 21466 * -ENODEV,   NULL ptr to pcidev1467 * -EBADSLT,  detected invalid device1468 * -EBUSY,    port is not in offline state1469 *      0,    successful1470 */1471static int1472lpfc_reset_pci_bus(struct lpfc_hba *phba)1473{1474	struct pci_dev *pdev = phba->pcidev;1475	struct Scsi_Host *shost = NULL;1476	struct lpfc_hba *phba_other = NULL;1477	struct pci_dev *ptr = NULL;1478	int res;1479 1480	if (phba->cfg_enable_hba_reset != 2)1481		return -ENOTSUPP;1482 1483	if (!pdev) {1484		lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "8345 pdev NULL!\n");1485		return -ENODEV;1486	}1487 1488	res = lpfc_check_pci_resettable(phba);1489	if (res)1490		return res;1491 1492	/* Walk the list of devices on the pci_dev's bus */1493	list_for_each_entry(ptr, &pdev->bus->devices, bus_list) {1494		/* Check port is offline */1495		shost = pci_get_drvdata(ptr);1496		if (shost) {1497			phba_other =1498				((struct lpfc_vport *)shost->hostdata)->phba;1499			if (!test_bit(FC_OFFLINE_MODE,1500				      &phba_other->pport->fc_flag)) {1501				lpfc_printf_log(phba_other, KERN_INFO, LOG_INIT,1502						"8349 WWPN = 0x%02x%02x%02x%02x"1503						"%02x%02x%02x%02x is not "1504						"offline!\n",1505						phba_other->wwpn[0],1506						phba_other->wwpn[1],1507						phba_other->wwpn[2],1508						phba_other->wwpn[3],1509						phba_other->wwpn[4],1510						phba_other->wwpn[5],1511						phba_other->wwpn[6],1512						phba_other->wwpn[7]);1513				return -EBUSY;1514			}1515		}1516	}1517 1518	/* Issue PCI bus reset */1519	res = pci_reset_bus(pdev);1520	if (res) {1521		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,1522				"8350 PCI reset bus failed: %d\n", res);1523	}1524 1525	return res;1526}1527 1528/**1529 * lpfc_selective_reset - Offline then onlines the port1530 * @phba: lpfc_hba pointer.1531 *1532 * Description:1533 * If the port is configured to allow a reset then the hba is brought1534 * offline then online.1535 *1536 * Notes:1537 * Assumes any error from lpfc_do_offline() will be negative.1538 * Do not make this function static.1539 *1540 * Returns:1541 * lpfc_do_offline() return code if not zero1542 * -EIO reset not configured or error posting the event1543 * zero for success1544 **/1545int1546lpfc_selective_reset(struct lpfc_hba *phba)1547{1548	struct completion online_compl;1549	int status = 0;1550	int rc;1551 1552	if (!phba->cfg_enable_hba_reset)1553		return -EACCES;1554 1555	if (!test_bit(FC_OFFLINE_MODE, &phba->pport->fc_flag)) {1556		status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);1557 1558		if (status != 0)1559			return status;1560	}1561 1562	init_completion(&online_compl);1563	rc = lpfc_workq_post_event(phba, &status, &online_compl,1564			      LPFC_EVT_ONLINE);1565	if (rc == 0)1566		return -ENOMEM;1567 1568	wait_for_completion(&online_compl);1569 1570	if (status != 0)1571		return -EIO;1572 1573	return 0;1574}1575 1576/**1577 * lpfc_issue_reset - Selectively resets an adapter1578 * @dev: class device that is converted into a Scsi_host.1579 * @attr: device attribute, not used.1580 * @buf: containing the string "selective".1581 * @count: unused variable.1582 *1583 * Description:1584 * If the buf contains the string "selective" then lpfc_selective_reset()1585 * is called to perform the reset.1586 *1587 * Notes:1588 * Assumes any error from lpfc_selective_reset() will be negative.1589 * If lpfc_selective_reset() returns zero then the length of the buffer1590 * is returned which indicates success1591 *1592 * Returns:1593 * -EINVAL if the buffer does not contain the string "selective"1594 * length of buf if lpfc-selective_reset() if the call succeeds1595 * return value of lpfc_selective_reset() if the call fails1596**/1597static ssize_t1598lpfc_issue_reset(struct device *dev, struct device_attribute *attr,1599		 const char *buf, size_t count)1600{1601	struct Scsi_Host  *shost = class_to_shost(dev);1602	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;1603	struct lpfc_hba   *phba = vport->phba;1604	int status = -EINVAL;1605 1606	if (!phba->cfg_enable_hba_reset)1607		return -EACCES;1608 1609	if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)1610		status = phba->lpfc_selective_reset(phba);1611 1612	if (status == 0)1613		return strlen(buf);1614	else1615		return status;1616}1617 1618/**1619 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness1620 * @phba: lpfc_hba pointer.1621 *1622 * Description:1623 * SLI4 interface type-2 device to wait on the sliport status register for1624 * the readyness after performing a firmware reset.1625 *1626 * Returns:1627 * zero for success, -EPERM when port does not have privilege to perform the1628 * reset, -EIO when port timeout from recovering from the reset.1629 *1630 * Note:1631 * As the caller will interpret the return code by value, be careful in making1632 * change or addition to return codes.1633 **/1634int1635lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)1636{1637	struct lpfc_register portstat_reg = {0};1638	int i;1639 1640	msleep(100);1641	if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,1642		       &portstat_reg.word0))1643		return -EIO;1644 1645	/* verify if privileged for the request operation */1646	if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&1647	    !bf_get(lpfc_sliport_status_err, &portstat_reg))1648		return -EPERM;1649 1650	/* There is no point to wait if the port is in an unrecoverable1651	 * state.1652	 */1653	if (lpfc_sli4_unrecoverable_port(&portstat_reg))1654		return -EIO;1655 1656	/* wait for the SLI port firmware ready after firmware reset */1657	for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {1658		msleep(10);1659		if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,1660			       &portstat_reg.word0))1661			continue;1662		if (!bf_get(lpfc_sliport_status_err, &portstat_reg))1663			continue;1664		if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))1665			continue;1666		if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))1667			continue;1668		break;1669	}1670 1671	if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)1672		return 0;1673	else1674		return -EIO;1675}1676 1677/**1678 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc1679 * @phba: lpfc_hba pointer.1680 * @opcode: The sli4 config command opcode.1681 *1682 * Description:1683 * Request SLI4 interface type-2 device to perform a physical register set1684 * access.1685 *1686 * Returns:1687 * zero for success1688 **/1689static ssize_t1690lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)1691{1692	struct completion online_compl;1693	struct pci_dev *pdev = phba->pcidev;1694	unsigned long before_fc_flag;1695	uint32_t sriov_nr_virtfn;1696	uint32_t reg_val;1697	int status = 0, rc = 0;1698	int job_posted = 1, sriov_err;1699 1700	if (!phba->cfg_enable_hba_reset)1701		return -EACCES;1702 1703	if ((phba->sli_rev < LPFC_SLI_REV4) ||1704	    (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <1705	     LPFC_SLI_INTF_IF_TYPE_2))1706		return -EPERM;1707 1708	/* Keep state if we need to restore back */1709	before_fc_flag = phba->pport->fc_flag;1710	sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;1711 1712	if (opcode == LPFC_FW_DUMP) {1713		init_completion(&online_compl);1714		phba->fw_dump_cmpl = &online_compl;1715	} else {1716		/* Disable SR-IOV virtual functions if enabled */1717		if (phba->cfg_sriov_nr_virtfn) {1718			pci_disable_sriov(pdev);1719			phba->cfg_sriov_nr_virtfn = 0;1720		}1721 1722		status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);1723 1724		if (status != 0)1725			return status;1726 1727		/* wait for the device to be quiesced before firmware reset */1728		msleep(100);1729	}1730 1731	reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +1732			LPFC_CTL_PDEV_CTL_OFFSET);1733 1734	if (opcode == LPFC_FW_DUMP)1735		reg_val |= LPFC_FW_DUMP_REQUEST;1736	else if (opcode == LPFC_FW_RESET)1737		reg_val |= LPFC_CTL_PDEV_CTL_FRST;1738	else if (opcode == LPFC_DV_RESET)1739		reg_val |= LPFC_CTL_PDEV_CTL_DRST;1740 1741	writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +1742	       LPFC_CTL_PDEV_CTL_OFFSET);1743	/* flush */1744	readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);1745 1746	/* delay driver action following IF_TYPE_2 reset */1747	rc = lpfc_sli4_pdev_status_reg_wait(phba);1748 1749	if (rc == -EPERM) {1750		/* no privilege for reset */1751		lpfc_printf_log(phba, KERN_ERR, LOG_SLI,1752				"3150 No privilege to perform the requested "1753				"access: x%x\n", reg_val);1754	} else if (rc == -EIO) {1755		/* reset failed, there is nothing more we can do */1756		lpfc_printf_log(phba, KERN_ERR, LOG_SLI,1757				"3153 Fail to perform the requested "1758				"access: x%x\n", reg_val);1759		if (phba->fw_dump_cmpl)1760			phba->fw_dump_cmpl = NULL;1761		return rc;1762	}1763 1764	/* keep the original port state */1765	if (test_bit(FC_OFFLINE_MODE, &before_fc_flag)) {1766		if (phba->fw_dump_cmpl)1767			phba->fw_dump_cmpl = NULL;1768		goto out;1769	}1770 1771	/* Firmware dump will trigger an HA_ERATT event, and1772	 * lpfc_handle_eratt_s4 routine already handles bringing the port back1773	 * online.1774	 */1775	if (opcode == LPFC_FW_DUMP) {1776		wait_for_completion(phba->fw_dump_cmpl);1777	} else  {1778		init_completion(&online_compl);1779		job_posted = lpfc_workq_post_event(phba, &status, &online_compl,1780						   LPFC_EVT_ONLINE);1781		if (!job_posted)1782			goto out;1783 1784		wait_for_completion(&online_compl);1785	}1786out:1787	/* in any case, restore the virtual functions enabled as before */1788	if (sriov_nr_virtfn) {1789		/* If fw_dump was performed, first disable to clean up */1790		if (opcode == LPFC_FW_DUMP) {1791			pci_disable_sriov(pdev);1792			phba->cfg_sriov_nr_virtfn = 0;1793		}1794 1795		sriov_err =1796			lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);1797		if (!sriov_err)1798			phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;1799	}1800 1801	/* return proper error code */1802	if (!rc) {1803		if (!job_posted)1804			rc = -ENOMEM;1805		else if (status)1806			rc = -EIO;1807	}1808	return rc;1809}1810 1811/**1812 * lpfc_nport_evt_cnt_show - Return the number of nport events1813 * @dev: class device that is converted into a Scsi_host.1814 * @attr: device attribute, not used.1815 * @buf: on return contains the ascii number of nport events.1816 *1817 * Returns: size of formatted string.1818 **/1819static ssize_t1820lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,1821			char *buf)1822{1823	struct Scsi_Host  *shost = class_to_shost(dev);1824	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;1825	struct lpfc_hba   *phba = vport->phba;1826 1827	return scnprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);1828}1829 1830static int1831lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)1832{1833	LPFC_MBOXQ_t *mbox = NULL;1834	u32 payload_len;1835	unsigned long val = 0;1836	char *pval = NULL;1837	int rc = 0;1838 1839	if (!strncmp("enable", buff_out,1840				 strlen("enable"))) {1841		pval = buff_out + strlen("enable") + 1;1842		rc = kstrtoul(pval, 0, &val);1843		if (rc)1844			return rc; /* Invalid  number */1845	} else if (!strncmp("disable", buff_out,1846				 strlen("disable"))) {1847		val = 0;1848	} else {1849		return -EINVAL;  /* Invalid command */1850	}1851 1852	switch (val) {1853	case 0:1854		val = 0x0; /* Disable */1855		break;1856	case 2:1857		val = 0x1; /* Enable two port trunk */1858		break;1859	case 4:1860		val = 0x2; /* Enable four port trunk */1861		break;1862	default:1863		return -EINVAL;1864	}1865 1866	lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,1867			"0070 Set trunk mode with val %ld ", val);1868 1869	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);1870	if (!mbox)1871		return -ENOMEM;1872 1873	payload_len = sizeof(struct lpfc_mbx_set_trunk_mode) -1874		      sizeof(struct lpfc_sli4_cfg_mhdr);1875	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,1876			 LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,1877			 payload_len, LPFC_SLI4_MBX_EMBED);1878 1879	bf_set(lpfc_mbx_set_trunk_mode,1880	       &mbox->u.mqe.un.set_trunk_mode,1881	       val);1882	rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);1883	if (rc)1884		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,1885				"0071 Set trunk mode failed with status: %d",1886				rc);1887	mempool_free(mbox, phba->mbox_mem_pool);1888 1889	return 0;1890}1891 1892static ssize_t1893lpfc_xcvr_data_show(struct device *dev, struct device_attribute *attr,1894		    char *buf)1895{1896	struct Scsi_Host  *shost = class_to_shost(dev);1897	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;1898	struct lpfc_hba   *phba = vport->phba;1899	int rc;1900	int len = 0;1901	struct lpfc_rdp_context	*rdp_context;1902	u16 temperature;1903	u16 rx_power;1904	u16 tx_bias;1905	u16 tx_power;1906	u16 vcc;1907	char chbuf[128];1908	u16 wavelength = 0;1909	struct sff_trasnceiver_codes_byte7 *trasn_code_byte7;1910 1911	/* Get transceiver information */1912	rdp_context = kmalloc(sizeof(*rdp_context), GFP_KERNEL);1913	if (!rdp_context) {1914		len = scnprintf(buf, PAGE_SIZE - len,1915				"SPF info NA: alloc failure\n");1916		return len;1917	}1918 1919	rc = lpfc_get_sfp_info_wait(phba, rdp_context);1920	if (rc) {1921		len = scnprintf(buf, PAGE_SIZE - len, "SFP info NA:\n");1922		goto out_free_rdp;1923	}1924 1925	strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_NAME], 16);1926 1927	len = scnprintf(buf, PAGE_SIZE - len, "VendorName:\t%s\n", chbuf);1928	len += scnprintf(buf + len, PAGE_SIZE - len,1929			 "VendorOUI:\t%02x-%02x-%02x\n",1930			 (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI],1931			 (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI + 1],1932			 (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI + 2]);1933	strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_PN], 16);1934	len += scnprintf(buf + len, PAGE_SIZE - len, "VendorPN:\t%s\n", chbuf);1935	strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_SN], 16);1936	len += scnprintf(buf + len, PAGE_SIZE - len, "VendorSN:\t%s\n", chbuf);1937	strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_REV], 4);1938	len += scnprintf(buf + len, PAGE_SIZE - len, "VendorRev:\t%s\n", chbuf);1939	strscpy(chbuf, &rdp_context->page_a0[SSF_DATE_CODE], 8);1940	len += scnprintf(buf + len, PAGE_SIZE - len, "DateCode:\t%s\n", chbuf);1941	len += scnprintf(buf + len, PAGE_SIZE - len, "Identifier:\t%xh\n",1942			 (uint8_t)rdp_context->page_a0[SSF_IDENTIFIER]);1943	len += scnprintf(buf + len, PAGE_SIZE - len, "ExtIdentifier:\t%xh\n",1944			 (uint8_t)rdp_context->page_a0[SSF_EXT_IDENTIFIER]);1945	len += scnprintf(buf + len, PAGE_SIZE - len, "Connector:\t%xh\n",1946			 (uint8_t)rdp_context->page_a0[SSF_CONNECTOR]);1947	wavelength = (rdp_context->page_a0[SSF_WAVELENGTH_B1] << 8) |1948		      rdp_context->page_a0[SSF_WAVELENGTH_B0];1949 1950	len += scnprintf(buf + len, PAGE_SIZE - len, "Wavelength:\t%d nm\n",1951			 wavelength);1952	trasn_code_byte7 = (struct sff_trasnceiver_codes_byte7 *)1953			&rdp_context->page_a0[SSF_TRANSCEIVER_CODE_B7];1954 1955	len += scnprintf(buf + len, PAGE_SIZE - len, "Speeds: \t");1956	if (*(uint8_t *)trasn_code_byte7 == 0) {1957		len += scnprintf(buf + len, PAGE_SIZE - len, "Unknown\n");1958	} else {1959		if (trasn_code_byte7->fc_sp_100MB)1960			len += scnprintf(buf + len, PAGE_SIZE - len, "1 ");1961		if (trasn_code_byte7->fc_sp_200mb)1962			len += scnprintf(buf + len, PAGE_SIZE - len, "2 ");1963		if (trasn_code_byte7->fc_sp_400MB)1964			len += scnprintf(buf + len, PAGE_SIZE - len, "4 ");1965		if (trasn_code_byte7->fc_sp_800MB)1966			len += scnprintf(buf + len, PAGE_SIZE - len, "8 ");1967		if (trasn_code_byte7->fc_sp_1600MB)1968			len += scnprintf(buf + len, PAGE_SIZE - len, "16 ");1969		if (trasn_code_byte7->fc_sp_3200MB)1970			len += scnprintf(buf + len, PAGE_SIZE - len, "32 ");1971		if (trasn_code_byte7->speed_chk_ecc)1972			len += scnprintf(buf + len, PAGE_SIZE - len, "64 ");1973		len += scnprintf(buf + len, PAGE_SIZE - len, "GB\n");1974	}1975	temperature = (rdp_context->page_a2[SFF_TEMPERATURE_B1] << 8 |1976		       rdp_context->page_a2[SFF_TEMPERATURE_B0]);1977	vcc = (rdp_context->page_a2[SFF_VCC_B1] << 8 |1978	       rdp_context->page_a2[SFF_VCC_B0]);1979	tx_power = (rdp_context->page_a2[SFF_TXPOWER_B1] << 8 |1980		    rdp_context->page_a2[SFF_TXPOWER_B0]);1981	tx_bias = (rdp_context->page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |1982		   rdp_context->page_a2[SFF_TX_BIAS_CURRENT_B0]);1983	rx_power = (rdp_context->page_a2[SFF_RXPOWER_B1] << 8 |1984		    rdp_context->page_a2[SFF_RXPOWER_B0]);1985 1986	len += scnprintf(buf + len, PAGE_SIZE - len,1987			 "Temperature:\tx%04x C\n", temperature);1988	len += scnprintf(buf + len, PAGE_SIZE - len, "Vcc:\t\tx%04x V\n", vcc);1989	len += scnprintf(buf + len, PAGE_SIZE - len,1990			 "TxBiasCurrent:\tx%04x mA\n", tx_bias);1991	len += scnprintf(buf + len, PAGE_SIZE - len, "TxPower:\tx%04x mW\n",1992			 tx_power);1993	len += scnprintf(buf + len, PAGE_SIZE - len, "RxPower:\tx%04x mW\n",1994			 rx_power);1995out_free_rdp:1996	kfree(rdp_context);1997	return len;1998}1999 2000/**2001 * lpfc_board_mode_show - Return the state of the board2002 * @dev: class device that is converted into a Scsi_host.2003 * @attr: device attribute, not used.2004 * @buf: on return contains the state of the adapter.2005 *2006 * Returns: size of formatted string.2007 **/2008static ssize_t2009lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,2010		     char *buf)2011{2012	struct Scsi_Host  *shost = class_to_shost(dev);2013	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;2014	struct lpfc_hba   *phba = vport->phba;2015	char  * state;2016 2017	if (phba->link_state == LPFC_HBA_ERROR)2018		state = "error";2019	else if (phba->link_state == LPFC_WARM_START)2020		state = "warm start";2021	else if (phba->link_state == LPFC_INIT_START)2022		state = "offline";2023	else2024		state = "online";2025 2026	return scnprintf(buf, PAGE_SIZE, "%s\n", state);2027}2028 2029/**2030 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state2031 * @dev: class device that is converted into a Scsi_host.2032 * @attr: device attribute, not used.2033 * @buf: containing one of the strings "online", "offline", "warm" or "error".2034 * @count: unused variable.2035 *2036 * Returns:2037 * -EACCES if enable hba reset not enabled2038 * -EINVAL if the buffer does not contain a valid string (see above)2039 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails2040 * buf length greater than zero indicates success2041 **/2042static ssize_t2043lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,2044		      const char *buf, size_t count)2045{2046	struct Scsi_Host  *shost = class_to_shost(dev);2047	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;2048	struct lpfc_hba   *phba = vport->phba;2049	struct completion online_compl;2050	char *board_mode_str = NULL;2051	int status = 0;2052	int rc;2053 2054	if (!phba->cfg_enable_hba_reset) {2055		status = -EACCES;2056		goto board_mode_out;2057	}2058 2059	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,2060			 "3050 lpfc_board_mode set to %s\n", buf);2061 2062	init_completion(&online_compl);2063 2064	if(strncmp(buf, "online", sizeof("online") - 1) == 0) {2065		rc = lpfc_workq_post_event(phba, &status, &online_compl,2066				      LPFC_EVT_ONLINE);2067		if (rc == 0) {2068			status = -ENOMEM;2069			goto board_mode_out;2070		}2071		wait_for_completion(&online_compl);2072		if (status)2073			status = -EIO;2074	} else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)2075		status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);2076	else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)2077		if (phba->sli_rev == LPFC_SLI_REV4)2078			status = -EINVAL;2079		else2080			status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);2081	else if (strncmp(buf, "error", sizeof("error") - 1) == 0)2082		if (phba->sli_rev == LPFC_SLI_REV4)2083			status = -EINVAL;2084		else2085			status = lpfc_do_offline(phba, LPFC_EVT_KILL);2086	else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)2087		status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);2088	else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)2089		status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);2090	else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)2091		status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);2092	else if (strncmp(buf, "pci_bus_reset", sizeof("pci_bus_reset") - 1)2093		 == 0)2094		status = lpfc_reset_pci_bus(phba);2095	else if (strncmp(buf, "heartbeat", sizeof("heartbeat") - 1) == 0)2096		lpfc_issue_hb_tmo(phba);2097	else if (strncmp(buf, "trunk", sizeof("trunk") - 1) == 0)2098		status = lpfc_set_trunking(phba, (char *)buf + sizeof("trunk"));2099	else2100		status = -EINVAL;2101 2102board_mode_out:2103	if (!status)2104		return strlen(buf);2105	else {2106		board_mode_str = strchr(buf, '\n');2107		if (board_mode_str)2108			*board_mode_str = '\0';2109		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,2110				 "3097 Failed \"%s\", status(%d), "2111				 "fc_flag(x%lx)\n",2112				 buf, status, phba->pport->fc_flag);2113		return status;2114	}2115}2116 2117/**2118 * lpfc_get_hba_info - Return various bits of informaton about the adapter2119 * @phba: pointer to the adapter structure.2120 * @mxri: max xri count.2121 * @axri: available xri count.2122 * @mrpi: max rpi count.2123 * @arpi: available rpi count.2124 * @mvpi: max vpi count.2125 * @avpi: available vpi count.2126 *2127 * Description:2128 * If an integer pointer for an count is not null then the value for the2129 * count is returned.2130 *2131 * Returns:2132 * zero on error2133 * one for success2134 **/2135static int2136lpfc_get_hba_info(struct lpfc_hba *phba,2137		  uint32_t *mxri, uint32_t *axri,2138		  uint32_t *mrpi, uint32_t *arpi,2139		  uint32_t *mvpi, uint32_t *avpi)2140{2141	LPFC_MBOXQ_t *pmboxq;2142	MAILBOX_t *pmb;2143	int rc = 0;2144	struct lpfc_sli4_hba *sli4_hba;2145	struct lpfc_max_cfg_param *max_cfg_param;2146	u16 rsrc_ext_cnt, rsrc_ext_size, max_vpi;2147 2148	/*2149	 * prevent udev from issuing mailbox commands until the port is2150	 * configured.2151	 */2152	if (phba->link_state < LPFC_LINK_DOWN ||2153	    !phba->mbox_mem_pool ||2154	    (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)2155		return 0;2156 2157	if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)2158		return 0;2159 2160	pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);2161	if (!pmboxq)2162		return 0;2163	memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));2164 2165	pmb = &pmboxq->u.mb;2166	pmb->mbxCommand = MBX_READ_CONFIG;2167	pmb->mbxOwner = OWN_HOST;2168	pmboxq->ctx_buf = NULL;2169 2170	if (test_bit(FC_OFFLINE_MODE, &phba->pport->fc_flag))2171		rc = MBX_NOT_FINISHED;2172	else2173		rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);2174 2175	if (rc != MBX_SUCCESS) {2176		if (rc != MBX_TIMEOUT)2177			mempool_free(pmboxq, phba->mbox_mem_pool);2178		return 0;2179	}2180 2181	if (phba->sli_rev == LPFC_SLI_REV4) {2182		sli4_hba = &phba->sli4_hba;2183		max_cfg_param = &sli4_hba->max_cfg_param;2184 2185		/* Normally, extents are not used */2186		if (!phba->sli4_hba.extents_in_use) {2187			if (mrpi)2188				*mrpi = max_cfg_param->max_rpi;2189			if (mxri)2190				*mxri = max_cfg_param->max_xri;2191			if (mvpi) {2192				max_vpi = max_cfg_param->max_vpi;2193 2194				/* Limit the max we support */2195				if (max_vpi > LPFC_MAX_VPI)2196					max_vpi = LPFC_MAX_VPI;2197				*mvpi = max_vpi;2198			}2199		} else { /* Extents in use */2200			if (mrpi) {2201				if (lpfc_sli4_get_avail_extnt_rsrc(phba,2202								   LPFC_RSC_TYPE_FCOE_RPI,2203								   &rsrc_ext_cnt,2204								   &rsrc_ext_size)) {2205					rc = 0;2206					goto free_pmboxq;2207				}2208 2209				*mrpi = rsrc_ext_cnt * rsrc_ext_size;2210			}2211 2212			if (mxri) {2213				if (lpfc_sli4_get_avail_extnt_rsrc(phba,2214								   LPFC_RSC_TYPE_FCOE_XRI,2215								   &rsrc_ext_cnt,2216								   &rsrc_ext_size)) {2217					rc = 0;2218					goto free_pmboxq;2219				}2220 2221				*mxri = rsrc_ext_cnt * rsrc_ext_size;2222			}2223 2224			if (mvpi) {2225				if (lpfc_sli4_get_avail_extnt_rsrc(phba,2226								   LPFC_RSC_TYPE_FCOE_VPI,2227								   &rsrc_ext_cnt,2228								   &rsrc_ext_size)) {2229					rc = 0;2230					goto free_pmboxq;2231				}2232 2233				max_vpi = rsrc_ext_cnt * rsrc_ext_size;2234 2235				/* Limit the max we support */2236				if (max_vpi > LPFC_MAX_VPI)2237					max_vpi = LPFC_MAX_VPI;2238				*mvpi = max_vpi;2239			}2240		}2241	} else {2242		if (mrpi)2243			*mrpi = pmb->un.varRdConfig.max_rpi;2244		if (arpi)2245			*arpi = pmb->un.varRdConfig.avail_rpi;2246		if (mxri)2247			*mxri = pmb->un.varRdConfig.max_xri;2248		if (axri)2249			*axri = pmb->un.varRdConfig.avail_xri;2250		if (mvpi)2251			*mvpi = pmb->un.varRdConfig.max_vpi;2252		if (avpi) {2253			/* avail_vpi is only valid if link is up and ready */2254			if (phba->link_state == LPFC_HBA_READY)2255				*avpi = pmb->un.varRdConfig.avail_vpi;2256			else2257				*avpi = pmb->un.varRdConfig.max_vpi;2258		}2259	}2260 2261	/* Success */2262	rc = 1;2263 2264free_pmboxq:2265	mempool_free(pmboxq, phba->mbox_mem_pool);2266	return rc;2267}2268 2269/**2270 * lpfc_max_rpi_show - Return maximum rpi2271 * @dev: class device that is converted into a Scsi_host.2272 * @attr: device attribute, not used.2273 * @buf: on return contains the maximum rpi count in decimal or "Unknown".2274 *2275 * Description:2276 * Calls lpfc_get_hba_info() asking for just the mrpi count.2277 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set2278 * to "Unknown" and the buffer length is returned, therefore the caller2279 * must check for "Unknown" in the buffer to detect a failure.2280 *2281 * Returns: size of formatted string.2282 **/2283static ssize_t2284lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,2285		  char *buf)2286{2287	struct Scsi_Host  *shost = class_to_shost(dev);2288	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;2289	struct lpfc_hba   *phba = vport->phba;2290	uint32_t cnt;2291 2292	if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))2293		return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);2294	return scnprintf(buf, PAGE_SIZE, "Unknown\n");2295}2296 2297/**2298 * lpfc_used_rpi_show - Return maximum rpi minus available rpi2299 * @dev: class device that is converted into a Scsi_host.2300 * @attr: device attribute, not used.2301 * @buf: containing the used rpi count in decimal or "Unknown".2302 *2303 * Description:2304 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.2305 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set2306 * to "Unknown" and the buffer length is returned, therefore the caller2307 * must check for "Unknown" in the buffer to detect a failure.2308 *2309 * Returns: size of formatted string.2310 **/2311static ssize_t2312lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,2313		   char *buf)2314{2315	struct Scsi_Host  *shost = class_to_shost(dev);2316	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;2317	struct lpfc_hba   *phba = vport->phba;2318	struct lpfc_sli4_hba *sli4_hba;2319	struct lpfc_max_cfg_param *max_cfg_param;2320	u32 cnt = 0, acnt = 0;2321 2322	if (phba->sli_rev == LPFC_SLI_REV4) {2323		sli4_hba = &phba->sli4_hba;2324		max_cfg_param = &sli4_hba->max_cfg_param;2325		return scnprintf(buf, PAGE_SIZE, "%d\n",2326				 max_cfg_param->rpi_used);2327	} else {2328		if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))2329			return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));2330	}2331	return scnprintf(buf, PAGE_SIZE, "Unknown\n");2332}2333 2334/**2335 * lpfc_max_xri_show - Return maximum xri2336 * @dev: class device that is converted into a Scsi_host.2337 * @attr: device attribute, not used.2338 * @buf: on return contains the maximum xri count in decimal or "Unknown".2339 *2340 * Description:2341 * Calls lpfc_get_hba_info() asking for just the mrpi count.2342 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set2343 * to "Unknown" and the buffer length is returned, therefore the caller2344 * must check for "Unknown" in the buffer to detect a failure.2345 *2346 * Returns: size of formatted string.2347 **/2348static ssize_t2349lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,2350		  char *buf)2351{2352	struct Scsi_Host  *shost = class_to_shost(dev);2353	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;2354	struct lpfc_hba   *phba = vport->phba;2355	uint32_t cnt;2356 2357	if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))2358		return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);2359	return scnprintf(buf, PAGE_SIZE, "Unknown\n");2360}2361 2362/**2363 * lpfc_used_xri_show - Return maximum xpi minus the available xpi2364 * @dev: class device that is converted into a Scsi_host.2365 * @attr: device attribute, not used.2366 * @buf: on return contains the used xri count in decimal or "Unknown".2367 *2368 * Description:2369 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.2370 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set2371 * to "Unknown" and the buffer length is returned, therefore the caller2372 * must check for "Unknown" in the buffer to detect a failure.2373 *2374 * Returns: size of formatted string.2375 **/2376static ssize_t2377lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,2378		   char *buf)2379{2380	struct Scsi_Host  *shost = class_to_shost(dev);2381	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;2382	struct lpfc_hba   *phba = vport->phba;2383	struct lpfc_sli4_hba *sli4_hba;2384	struct lpfc_max_cfg_param *max_cfg_param;2385	u32 cnt = 0, acnt = 0;2386 2387	if (phba->sli_rev == LPFC_SLI_REV4) {2388		sli4_hba = &phba->sli4_hba;2389		max_cfg_param = &sli4_hba->max_cfg_param;2390		return scnprintf(buf, PAGE_SIZE, "%d\n",2391				 max_cfg_param->xri_used);2392	} else {2393		if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))2394			return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));2395	}2396	return scnprintf(buf, PAGE_SIZE, "Unknown\n");2397}2398 2399/**2400 * lpfc_max_vpi_show - Return maximum vpi2401 * @dev: class device that is converted into a Scsi_host.2402 * @attr: device attribute, not used.2403 * @buf: on return contains the maximum vpi count in decimal or "Unknown".2404 *2405 * Description:2406 * Calls lpfc_get_hba_info() asking for just the mvpi count.2407 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set2408 * to "Unknown" and the buffer length is returned, therefore the caller2409 * must check for "Unknown" in the buffer to detect a failure.2410 *2411 * Returns: size of formatted string.2412 **/2413static ssize_t2414lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,2415		  char *buf)2416{2417	struct Scsi_Host  *shost = class_to_shost(dev);2418	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;2419	struct lpfc_hba   *phba = vport->phba;2420	uint32_t cnt;2421 2422	if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))2423		return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);2424	return scnprintf(buf, PAGE_SIZE, "Unknown\n");2425}2426 2427/**2428 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi2429 * @dev: class device that is converted into a Scsi_host.2430 * @attr: device attribute, not used.2431 * @buf: on return contains the used vpi count in decimal or "Unknown".2432 *2433 * Description:2434 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.2435 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set2436 * to "Unknown" and the buffer length is returned, therefore the caller2437 * must check for "Unknown" in the buffer to detect a failure.2438 *2439 * Returns: size of formatted string.2440 **/2441static ssize_t2442lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,2443		   char *buf)2444{2445	struct Scsi_Host  *shost = class_to_shost(dev);2446	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;2447	struct lpfc_hba   *phba = vport->phba;2448	struct lpfc_sli4_hba *sli4_hba;2449	struct lpfc_max_cfg_param *max_cfg_param;2450	u32 cnt = 0, acnt = 0;2451 2452	if (phba->sli_rev == LPFC_SLI_REV4) {2453		sli4_hba = &phba->sli4_hba;2454		max_cfg_param = &sli4_hba->max_cfg_param;2455		return scnprintf(buf, PAGE_SIZE, "%d\n",2456				 max_cfg_param->vpi_used);2457	} else {2458		if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))2459			return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));2460	}2461	return scnprintf(buf, PAGE_SIZE, "Unknown\n");2462}2463 2464/**2465 * lpfc_npiv_info_show - Return text about NPIV support for the adapter2466 * @dev: class device that is converted into a Scsi_host.2467 * @attr: device attribute, not used.2468 * @buf: text that must be interpreted to determine if npiv is supported.2469 *2470 * Description:2471 * Buffer will contain text indicating npiv is not suppoerted on the port,2472 * the port is an NPIV physical port, or it is an npiv virtual port with2473 * the id of the vport.2474 *2475 * Returns: size of formatted string.2476 **/2477static ssize_t2478lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,2479		    char *buf)2480{2481	struct Scsi_Host  *shost = class_to_shost(dev);2482	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;2483	struct lpfc_hba   *phba = vport->phba;2484 2485	if (!(phba->max_vpi))2486		return scnprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");2487	if (vport->port_type == LPFC_PHYSICAL_PORT)2488		return scnprintf(buf, PAGE_SIZE, "NPIV Physical\n");2489	return scnprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);2490}2491 2492/**2493 * lpfc_poll_show - Return text about poll support for the adapter2494 * @dev: class device that is converted into a Scsi_host.2495 * @attr: device attribute, not used.2496 * @buf: on return contains the cfg_poll in hex.2497 *2498 * Notes:2499 * cfg_poll should be a lpfc_polling_flags type.2500 *2501 * Returns: size of formatted string.2502 **/2503static ssize_t2504lpfc_poll_show(struct device *dev, struct device_attribute *attr,2505	       char *buf)2506{2507	struct Scsi_Host  *shost = class_to_shost(dev);2508	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;2509	struct lpfc_hba   *phba = vport->phba;2510 2511	return scnprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);2512}2513 2514/**2515 * lpfc_poll_store - Set the value of cfg_poll for the adapter2516 * @dev: class device that is converted into a Scsi_host.2517 * @attr: device attribute, not used.2518 * @buf: one or more lpfc_polling_flags values.2519 * @count: not used.2520 *2521 * Notes:2522 * buf contents converted to integer and checked for a valid value.2523 *2524 * Returns:2525 * -EINVAL if the buffer connot be converted or is out of range2526 * length of the buf on success2527 **/2528static ssize_t2529lpfc_poll_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_vport *vport = (struct lpfc_vport *) shost->hostdata;2534	struct lpfc_hba   *phba = vport->phba;2535	uint32_t creg_val;2536	uint32_t old_val;2537	int val=0;2538 2539	if (!isdigit(buf[0]))2540		return -EINVAL;2541 2542	if (sscanf(buf, "%i", &val) != 1)2543		return -EINVAL;2544 2545	if ((val & 0x3) != val)2546		return -EINVAL;2547 2548	if (phba->sli_rev == LPFC_SLI_REV4)2549		val = 0;2550 2551	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,2552		"3051 lpfc_poll changed from %d to %d\n",2553		phba->cfg_poll, val);2554 2555	spin_lock_irq(&phba->hbalock);2556 2557	old_val = phba->cfg_poll;2558 2559	if (val & ENABLE_FCP_RING_POLLING) {2560		if ((val & DISABLE_FCP_RING_INT) &&2561		    !(old_val & DISABLE_FCP_RING_INT)) {2562			if (lpfc_readl(phba->HCregaddr, &creg_val)) {2563				spin_unlock_irq(&phba->hbalock);2564				return -EINVAL;2565			}2566			creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);2567			writel(creg_val, phba->HCregaddr);2568			readl(phba->HCregaddr); /* flush */2569 2570			lpfc_poll_start_timer(phba);2571		}2572	} else if (val != 0x0) {2573		spin_unlock_irq(&phba->hbalock);2574		return -EINVAL;2575	}2576 2577	if (!(val & DISABLE_FCP_RING_INT) &&2578	    (old_val & DISABLE_FCP_RING_INT))2579	{2580		spin_unlock_irq(&phba->hbalock);2581		del_timer(&phba->fcp_poll_timer);2582		spin_lock_irq(&phba->hbalock);2583		if (lpfc_readl(phba->HCregaddr, &creg_val)) {2584			spin_unlock_irq(&phba->hbalock);2585			return -EINVAL;2586		}2587		creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);2588		writel(creg_val, phba->HCregaddr);2589		readl(phba->HCregaddr); /* flush */2590	}2591 2592	phba->cfg_poll = val;2593 2594	spin_unlock_irq(&phba->hbalock);2595 2596	return strlen(buf);2597}2598 2599/**2600 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions2601 * @dev: class converted to a Scsi_host structure.2602 * @attr: device attribute, not used.2603 * @buf: on return contains the formatted support level.2604 *2605 * Description:2606 * Returns the maximum number of virtual functions a physical function can2607 * support, 0 will be returned if called on virtual function.2608 *2609 * Returns: size of formatted string.2610 **/2611static ssize_t2612lpfc_sriov_hw_max_virtfn_show(struct device *dev,2613			      struct device_attribute *attr,2614			      char *buf)2615{2616	struct Scsi_Host *shost = class_to_shost(dev);2617	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;2618	struct lpfc_hba *phba = vport->phba;2619	uint16_t max_nr_virtfn;2620 2621	max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);2622	return scnprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);2623}2624 2625/**2626 * lpfc_enable_bbcr_set: Sets an attribute value.2627 * @phba: pointer to the adapter structure.2628 * @val: integer attribute value.2629 *2630 * Description:2631 * Validates the min and max values then sets the2632 * adapter config field if in the valid range. prints error message2633 * and does not set the parameter if invalid.2634 *2635 * Returns:2636 * zero on success2637 * -EINVAL if val is invalid2638 */2639static ssize_t2640lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)2641{2642	if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {2643		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,2644				"3068 lpfc_enable_bbcr changed from %d to "2645				"%d\n", phba->cfg_enable_bbcr, val);2646		phba->cfg_enable_bbcr = val;2647		return 0;2648	}2649	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,2650			"0451 lpfc_enable_bbcr cannot set to %d, range is 0, "2651			"1\n", val);2652	return -EINVAL;2653}2654 2655/*2656 * lpfc_param_show - Return a cfg attribute value in decimal2657 *2658 * Description:2659 * Macro that given an attr e.g. hba_queue_depth expands2660 * into a function with the name lpfc_hba_queue_depth_show.2661 *2662 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.2663 * @dev: class device that is converted into a Scsi_host.2664 * @attr: device attribute, not used.2665 * @buf: on return contains the attribute value in decimal.2666 *2667 * Returns: size of formatted string.2668 **/2669#define lpfc_param_show(attr)	\2670static ssize_t \2671lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \2672		   char *buf) \2673{ \2674	struct Scsi_Host  *shost = class_to_shost(dev);\2675	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\2676	struct lpfc_hba   *phba = vport->phba;\2677	return scnprintf(buf, PAGE_SIZE, "%d\n",\2678			phba->cfg_##attr);\2679}2680 2681/*2682 * lpfc_param_hex_show - Return a cfg attribute value in hex2683 *2684 * Description:2685 * Macro that given an attr e.g. hba_queue_depth expands2686 * into a function with the name lpfc_hba_queue_depth_show2687 *2688 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.2689 * @dev: class device that is converted into a Scsi_host.2690 * @attr: device attribute, not used.2691 * @buf: on return contains the attribute value in hexadecimal.2692 *2693 * Returns: size of formatted string.2694 **/2695#define lpfc_param_hex_show(attr)	\2696static ssize_t \2697lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \2698		   char *buf) \2699{ \2700	struct Scsi_Host  *shost = class_to_shost(dev);\2701	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\2702	struct lpfc_hba   *phba = vport->phba;\2703	uint val = 0;\2704	val = phba->cfg_##attr;\2705	return scnprintf(buf, PAGE_SIZE, "%#x\n",\2706			phba->cfg_##attr);\2707}2708 2709/*2710 * lpfc_param_init - Initializes a cfg attribute2711 *2712 * Description:2713 * Macro that given an attr e.g. hba_queue_depth expands2714 * into a function with the name lpfc_hba_queue_depth_init. The macro also2715 * takes a default argument, a minimum and maximum argument.2716 *2717 * lpfc_##attr##_init: Initializes an attribute.2718 * @phba: pointer to the adapter structure.2719 * @val: integer attribute value.2720 *2721 * Validates the min and max values then sets the adapter config field2722 * accordingly, or uses the default if out of range and prints an error message.2723 *2724 * Returns:2725 * zero on success2726 * -EINVAL if default used2727 **/2728#define lpfc_param_init(attr, default, minval, maxval)	\2729static int \2730lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \2731{ \2732	if (lpfc_rangecheck(val, minval, maxval)) {\2733		phba->cfg_##attr = val;\2734		return 0;\2735	}\2736	lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \2737			"0449 lpfc_"#attr" attribute cannot be set to %d, "\2738			"allowed range is ["#minval", "#maxval"]\n", val); \2739	phba->cfg_##attr = default;\2740	return -EINVAL;\2741}2742 2743/*2744 * lpfc_param_set - Set a cfg attribute value2745 *2746 * Description:2747 * Macro that given an attr e.g. hba_queue_depth expands2748 * into a function with the name lpfc_hba_queue_depth_set2749 *2750 * lpfc_##attr##_set: Sets an attribute value.2751 * @phba: pointer to the adapter structure.2752 * @val: integer attribute value.2753 *2754 * Description:2755 * Validates the min and max values then sets the2756 * adapter config field if in the valid range. prints error message2757 * and does not set the parameter if invalid.2758 *2759 * Returns:2760 * zero on success2761 * -EINVAL if val is invalid2762 **/2763#define lpfc_param_set(attr, default, minval, maxval)	\2764static int \2765lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \2766{ \2767	if (lpfc_rangecheck(val, minval, maxval)) {\2768		lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \2769			"3052 lpfc_" #attr " changed from %d to %d\n", \2770			phba->cfg_##attr, val); \2771		phba->cfg_##attr = val;\2772		return 0;\2773	}\2774	lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \2775			"0450 lpfc_"#attr" attribute cannot be set to %d, "\2776			"allowed range is ["#minval", "#maxval"]\n", val); \2777	return -EINVAL;\2778}2779 2780/*2781 * lpfc_param_store - Set a vport attribute value2782 *2783 * Description:2784 * Macro that given an attr e.g. hba_queue_depth expands2785 * into a function with the name lpfc_hba_queue_depth_store.2786 *2787 * lpfc_##attr##_store: Set an sttribute value.2788 * @dev: class device that is converted into a Scsi_host.2789 * @attr: device attribute, not used.2790 * @buf: contains the attribute value in ascii.2791 * @count: not used.2792 *2793 * Description:2794 * Convert the ascii text number to an integer, then2795 * use the lpfc_##attr##_set function to set the value.2796 *2797 * Returns:2798 * -EINVAL if val is invalid or lpfc_##attr##_set() fails2799 * length of buffer upon success.2800 **/2801#define lpfc_param_store(attr)	\2802static ssize_t \2803lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \2804		    const char *buf, size_t count) \2805{ \2806	struct Scsi_Host  *shost = class_to_shost(dev);\2807	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\2808	struct lpfc_hba   *phba = vport->phba;\2809	uint val = 0;\2810	if (!isdigit(buf[0]))\2811		return -EINVAL;\2812	if (sscanf(buf, "%i", &val) != 1)\2813		return -EINVAL;\2814	if (lpfc_##attr##_set(phba, val) == 0) \2815		return strlen(buf);\2816	else \2817		return -EINVAL;\2818}2819 2820/*2821 * lpfc_vport_param_show - Return decimal formatted cfg attribute value2822 *2823 * Description:2824 * Macro that given an attr e.g. hba_queue_depth expands2825 * into a function with the name lpfc_hba_queue_depth_show2826 *2827 * lpfc_##attr##_show: prints the attribute value in decimal.2828 * @dev: class device that is converted into a Scsi_host.2829 * @attr: device attribute, not used.2830 * @buf: on return contains the attribute value in decimal.2831 *2832 * Returns: length of formatted string.2833 **/2834#define lpfc_vport_param_show(attr)	\2835static ssize_t \2836lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \2837		   char *buf) \2838{ \2839	struct Scsi_Host  *shost = class_to_shost(dev);\2840	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\2841	return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\2842}2843 2844/*2845 * lpfc_vport_param_hex_show - Return hex formatted attribute value2846 *2847 * Description:2848 * Macro that given an attr e.g.2849 * hba_queue_depth expands into a function with the name2850 * lpfc_hba_queue_depth_show2851 *2852 * lpfc_##attr##_show: prints the attribute value in hexadecimal.2853 * @dev: class device that is converted into a Scsi_host.2854 * @attr: device attribute, not used.2855 * @buf: on return contains the attribute value in hexadecimal.2856 *2857 * Returns: length of formatted string.2858 **/2859#define lpfc_vport_param_hex_show(attr)	\2860static ssize_t \2861lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \2862		   char *buf) \2863{ \2864	struct Scsi_Host  *shost = class_to_shost(dev);\2865	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\2866	return scnprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\2867}2868 2869/*2870 * lpfc_vport_param_init - Initialize a vport cfg attribute2871 *2872 * Description:2873 * Macro that given an attr e.g. hba_queue_depth expands2874 * into a function with the name lpfc_hba_queue_depth_init. The macro also2875 * takes a default argument, a minimum and maximum argument.2876 *2877 * lpfc_##attr##_init: validates the min and max values then sets the2878 * adapter config field accordingly, or uses the default if out of range2879 * and prints an error message.2880 * @phba: pointer to the adapter structure.2881 * @val: integer attribute value.2882 *2883 * Returns:2884 * zero on success2885 * -EINVAL if default used2886 **/2887#define lpfc_vport_param_init(attr, default, minval, maxval)	\2888static int \2889lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \2890{ \2891	if (lpfc_rangecheck(val, minval, maxval)) {\2892		vport->cfg_##attr = val;\2893		return 0;\2894	}\2895	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \2896			 "0423 lpfc_"#attr" attribute cannot be set to %d, "\2897			 "allowed range is ["#minval", "#maxval"]\n", val); \2898	vport->cfg_##attr = default;\2899	return -EINVAL;\2900}2901 2902/*2903 * lpfc_vport_param_set - Set a vport cfg attribute2904 *2905 * Description:2906 * Macro that given an attr e.g. hba_queue_depth expands2907 * into a function with the name lpfc_hba_queue_depth_set2908 *2909 * lpfc_##attr##_set: validates the min and max values then sets the2910 * adapter config field if in the valid range. prints error message2911 * and does not set the parameter if invalid.2912 * @phba: pointer to the adapter structure.2913 * @val:	integer attribute value.2914 *2915 * Returns:2916 * zero on success2917 * -EINVAL if val is invalid2918 **/2919#define lpfc_vport_param_set(attr, default, minval, maxval)	\2920static int \2921lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \2922{ \2923	if (lpfc_rangecheck(val, minval, maxval)) {\2924		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \2925			"3053 lpfc_" #attr \2926			" changed from %d (x%x) to %d (x%x)\n", \2927			vport->cfg_##attr, vport->cfg_##attr, \2928			val, val); \2929		vport->cfg_##attr = val;\2930		return 0;\2931	}\2932	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \2933			 "0424 lpfc_"#attr" attribute cannot be set to %d, "\2934			 "allowed range is ["#minval", "#maxval"]\n", val); \2935	return -EINVAL;\2936}2937 2938/*2939 * lpfc_vport_param_store - Set a vport attribute2940 *2941 * Description:2942 * Macro that given an attr e.g. hba_queue_depth2943 * expands into a function with the name lpfc_hba_queue_depth_store2944 *2945 * lpfc_##attr##_store: convert the ascii text number to an integer, then2946 * use the lpfc_##attr##_set function to set the value.2947 * @cdev: class device that is converted into a Scsi_host.2948 * @buf:	contains the attribute value in decimal.2949 * @count: not used.2950 *2951 * Returns:2952 * -EINVAL if val is invalid or lpfc_##attr##_set() fails2953 * length of buffer upon success.2954 **/2955#define lpfc_vport_param_store(attr)	\2956static ssize_t \2957lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \2958		    const char *buf, size_t count) \2959{ \2960	struct Scsi_Host  *shost = class_to_shost(dev);\2961	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\2962	uint val = 0;\2963	if (!isdigit(buf[0]))\2964		return -EINVAL;\2965	if (sscanf(buf, "%i", &val) != 1)\2966		return -EINVAL;\2967	if (lpfc_##attr##_set(vport, val) == 0) \2968		return strlen(buf);\2969	else \2970		return -EINVAL;\2971}2972 2973 2974static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);2975static DEVICE_ATTR(scsi_stat, 0444, lpfc_scsi_stat_show, NULL);2976static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);2977static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);2978static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);2979static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);2980static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);2981static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);2982static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);2983static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);2984static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);2985static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);2986static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);2987static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);2988static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,2989		lpfc_link_state_store);2990static DEVICE_ATTR(option_rom_version, S_IRUGO,2991		   lpfc_option_rom_version_show, NULL);2992static DEVICE_ATTR(num_discovered_ports, S_IRUGO,2993		   lpfc_num_discovered_ports_show, NULL);2994static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);2995static DEVICE_ATTR_RO(lpfc_drvr_version);2996static DEVICE_ATTR_RO(lpfc_enable_fip);2997static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,2998		   lpfc_board_mode_show, lpfc_board_mode_store);2999static DEVICE_ATTR_RO(lpfc_xcvr_data);3000static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);3001static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);3002static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);3003static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);3004static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);3005static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);3006static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);3007static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);3008static DEVICE_ATTR_RO(lpfc_temp_sensor);3009static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);3010static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);3011static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,3012		   NULL);3013static DEVICE_ATTR(cmf_info, 0444, lpfc_cmf_info_show, NULL);3014 3015#define WWN_SZ 83016/**3017 * lpfc_wwn_set - Convert string to the 8 byte WWN value.3018 * @buf: WWN string.3019 * @cnt: Length of string.3020 * @wwn: Array to receive converted wwn value.3021 *3022 * Returns:3023 * -EINVAL if the buffer does not contain a valid wwn3024 * 0 success3025 **/3026static size_t3027lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])3028{3029	unsigned int i, j;3030 3031	/* Count may include a LF at end of string */3032	if (buf[cnt-1] == '\n')3033		cnt--;3034 3035	if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||3036	    ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))3037		return -EINVAL;3038 3039	memset(wwn, 0, WWN_SZ);3040 3041	/* Validate and store the new name */3042	for (i = 0, j = 0; i < 16; i++) {3043		if ((*buf >= 'a') && (*buf <= 'f'))3044			j = ((j << 4) | ((*buf++ - 'a') + 10));3045		else if ((*buf >= 'A') && (*buf <= 'F'))3046			j = ((j << 4) | ((*buf++ - 'A') + 10));3047		else if ((*buf >= '0') && (*buf <= '9'))3048			j = ((j << 4) | (*buf++ - '0'));3049		else3050			return -EINVAL;3051		if (i % 2) {3052			wwn[i/2] = j & 0xff;3053			j = 0;3054		}3055	}3056	return 0;3057}3058 3059 3060/**3061 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for3062 *		      Optimized Access Storage (OAS) operations.3063 * @dev: class device that is converted into a Scsi_host.3064 * @attr: device attribute, not used.3065 * @buf: buffer for passing information.3066 *3067 * Returns:3068 * value of count3069 **/3070static ssize_t3071lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,3072		  char *buf)3073{3074	struct Scsi_Host *shost = class_to_shost(dev);3075	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;3076 3077	return scnprintf(buf, PAGE_SIZE, "0x%llx\n",3078			wwn_to_u64(phba->cfg_oas_tgt_wwpn));3079}3080 3081/**3082 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for3083 *		      Optimized Access Storage (OAS) operations.3084 * @dev: class device that is converted into a Scsi_host.3085 * @attr: device attribute, not used.3086 * @buf: buffer for passing information.3087 * @count: Size of the data buffer.3088 *3089 * Returns:3090 * -EINVAL count is invalid, invalid wwpn byte invalid3091 * -EPERM oas is not supported by hba3092 * value of count on success3093 **/3094static ssize_t3095lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,3096		   const char *buf, size_t count)3097{3098	struct Scsi_Host *shost = class_to_shost(dev);3099	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;3100	unsigned int cnt = count;3101	uint8_t wwpn[WWN_SZ];3102	int rc;3103 3104	if (!phba->cfg_fof)3105		return -EPERM;3106 3107	/* count may include a LF at end of string */3108	if (buf[cnt-1] == '\n')3109		cnt--;3110 3111	rc = lpfc_wwn_set(buf, cnt, wwpn);3112	if (rc)3113		return rc;3114 3115	memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));3116	memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));3117	if (wwn_to_u64(wwpn) == 0)3118		phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;3119	else3120		phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;3121	phba->cfg_oas_flags &= ~OAS_LUN_VALID;3122	phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;3123	return count;3124}3125static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,3126		   lpfc_oas_tgt_show, lpfc_oas_tgt_store);3127 3128/**3129 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for3130 *		      Optimized Access Storage (OAS) operations.3131 * @dev: class device that is converted into a Scsi_host.3132 * @attr: device attribute, not used.3133 * @buf: buffer for passing information.3134 *3135 * Returns:3136 * value of count3137 **/3138static ssize_t3139lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,3140		       char *buf)3141{3142	struct Scsi_Host *shost = class_to_shost(dev);3143	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;3144 3145	return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);3146}3147 3148/**3149 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for3150 *		      Optimized Access Storage (OAS) operations.3151 * @dev: class device that is converted into a Scsi_host.3152 * @attr: device attribute, not used.3153 * @buf: buffer for passing information.3154 * @count: Size of the data buffer.3155 *3156 * Returns:3157 * -EINVAL count is invalid, invalid wwpn byte invalid3158 * -EPERM oas is not supported by hba3159 * value of count on success3160 **/3161static ssize_t3162lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,3163			const char *buf, size_t count)3164{3165	struct Scsi_Host *shost = class_to_shost(dev);3166	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;3167	unsigned int cnt = count;3168	unsigned long val;3169	int ret;3170 3171	if (!phba->cfg_fof)3172		return -EPERM;3173 3174	/* count may include a LF at end of string */3175	if (buf[cnt-1] == '\n')3176		cnt--;3177 3178	ret = kstrtoul(buf, 0, &val);3179	if (ret || (val > 0x7f))3180		return -EINVAL;3181 3182	if (val)3183		phba->cfg_oas_priority = (uint8_t)val;3184	else3185		phba->cfg_oas_priority = phba->cfg_XLanePriority;3186	return count;3187}3188static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,3189		   lpfc_oas_priority_show, lpfc_oas_priority_store);3190 3191/**3192 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled3193 *		      for Optimized Access Storage (OAS) operations.3194 * @dev: class device that is converted into a Scsi_host.3195 * @attr: device attribute, not used.3196 * @buf: buffer for passing information.3197 *3198 * Returns:3199 * value of count on success3200 **/3201static ssize_t3202lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,3203		  char *buf)3204{3205	struct Scsi_Host *shost = class_to_shost(dev);3206	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;3207 3208	return scnprintf(buf, PAGE_SIZE, "0x%llx\n",3209			wwn_to_u64(phba->cfg_oas_vpt_wwpn));3210}3211 3212/**3213 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled3214 *		      for Optimized Access Storage (OAS) operations.3215 * @dev: class device that is converted into a Scsi_host.3216 * @attr: device attribute, not used.3217 * @buf: buffer for passing information.3218 * @count: Size of the data buffer.3219 *3220 * Returns:3221 * -EINVAL count is invalid, invalid wwpn byte invalid3222 * -EPERM oas is not supported by hba3223 * value of count on success3224 **/3225static ssize_t3226lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,3227		   const char *buf, size_t count)3228{3229	struct Scsi_Host *shost = class_to_shost(dev);3230	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;3231	unsigned int cnt = count;3232	uint8_t wwpn[WWN_SZ];3233	int rc;3234 3235	if (!phba->cfg_fof)3236		return -EPERM;3237 3238	/* count may include a LF at end of string */3239	if (buf[cnt-1] == '\n')3240		cnt--;3241 3242	rc = lpfc_wwn_set(buf, cnt, wwpn);3243	if (rc)3244		return rc;3245 3246	memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));3247	memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));3248	if (wwn_to_u64(wwpn) == 0)3249		phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;3250	else3251		phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;3252	phba->cfg_oas_flags &= ~OAS_LUN_VALID;3253	if (phba->cfg_oas_priority == 0)3254		phba->cfg_oas_priority = phba->cfg_XLanePriority;3255	phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;3256	return count;3257}3258static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,3259		   lpfc_oas_vpt_show, lpfc_oas_vpt_store);3260 3261/**3262 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)3263 *			    of whether luns will be enabled or disabled3264 *			    for Optimized Access Storage (OAS) operations.3265 * @dev: class device that is converted into a Scsi_host.3266 * @attr: device attribute, not used.3267 * @buf: buffer for passing information.3268 *3269 * Returns:3270 * size of formatted string.3271 **/3272static ssize_t3273lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,3274			char *buf)3275{3276	struct Scsi_Host *shost = class_to_shost(dev);3277	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;3278 3279	return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);3280}3281 3282/**3283 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)3284 *			    of whether luns will be enabled or disabled3285 *			    for Optimized Access Storage (OAS) operations.3286 * @dev: class device that is converted into a Scsi_host.3287 * @attr: device attribute, not used.3288 * @buf: buffer for passing information.3289 * @count: Size of the data buffer.3290 *3291 * Returns:3292 * -EINVAL count is invalid, invalid wwpn byte invalid3293 * -EPERM oas is not supported by hba3294 * value of count on success3295 **/3296static ssize_t3297lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,3298			 const char *buf, size_t count)3299{3300	struct Scsi_Host *shost = class_to_shost(dev);3301	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;3302	int val = 0;3303 3304	if (!phba->cfg_fof)3305		return -EPERM;3306 3307	if (!isdigit(buf[0]))3308		return -EINVAL;3309 3310	if (sscanf(buf, "%i", &val) != 1)3311		return -EINVAL;3312 3313	if ((val != 0) && (val != 1))3314		return -EINVAL;3315 3316	phba->cfg_oas_lun_state = val;3317	return strlen(buf);3318}3319static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,3320		   lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);3321 3322/**3323 * lpfc_oas_lun_status_show - Return the status of the Optimized Access3324 *                          Storage (OAS) lun returned by the3325 *                          lpfc_oas_lun_show function.3326 * @dev: class device that is converted into a Scsi_host.3327 * @attr: device attribute, not used.3328 * @buf: buffer for passing information.3329 *3330 * Returns:3331 * size of formatted string.3332 **/3333static ssize_t3334lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,3335			 char *buf)3336{3337	struct Scsi_Host *shost = class_to_shost(dev);3338	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;3339 3340	if (!(phba->cfg_oas_flags & OAS_LUN_VALID))3341		return -EFAULT;3342 3343	return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);3344}3345static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,3346		   lpfc_oas_lun_status_show, NULL);3347 3348 3349/**3350 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage3351 *			   (OAS) operations.3352 * @phba: lpfc_hba pointer.3353 * @vpt_wwpn: wwpn of the vport associated with the returned lun3354 * @tgt_wwpn: wwpn of the target associated with the returned lun3355 * @lun: the fc lun for setting oas state.3356 * @oas_state: the oas state to be set to the lun.3357 * @pri: priority3358 *3359 * Returns:3360 * SUCCESS : 03361 * -EPERM OAS is not enabled or not supported by this port.3362 *3363 */3364static size_t3365lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],3366		       uint8_t tgt_wwpn[], uint64_t lun,3367		       uint32_t oas_state, uint8_t pri)3368{3369 3370	int rc = 0;3371 3372	if (!phba->cfg_fof)3373		return -EPERM;3374 3375	if (oas_state) {3376		if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,3377					 (struct lpfc_name *)tgt_wwpn,3378					 lun, pri))3379			rc = -ENOMEM;3380	} else {3381		lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,3382				     (struct lpfc_name *)tgt_wwpn, lun, pri);3383	}3384	return rc;3385 3386}3387 3388/**3389 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized3390 *			  Access Storage (OAS) operations.3391 * @phba: lpfc_hba pointer.3392 * @vpt_wwpn: wwpn of the vport associated with the returned lun3393 * @tgt_wwpn: wwpn of the target associated with the returned lun3394 * @lun_status: status of the lun returned lun3395 * @lun_pri: priority of the lun returned lun3396 *3397 * Returns the first or next lun enabled for OAS operations for the vport/target3398 * specified.  If a lun is found, its vport wwpn, target wwpn and status is3399 * returned.  If the lun is not found, NOT_OAS_ENABLED_LUN is returned.3400 *3401 * Return:3402 * lun that is OAS enabled for the vport/target3403 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.3404 */3405static uint64_t3406lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],3407		      uint8_t tgt_wwpn[], uint32_t *lun_status,3408		      uint32_t *lun_pri)3409{3410	uint64_t found_lun;3411 3412	if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)3413		return NOT_OAS_ENABLED_LUN;3414	if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)3415				   phba->sli4_hba.oas_next_vpt_wwpn,3416				   (struct lpfc_name *)3417				   phba->sli4_hba.oas_next_tgt_wwpn,3418				   &phba->sli4_hba.oas_next_lun,3419				   (struct lpfc_name *)vpt_wwpn,3420				   (struct lpfc_name *)tgt_wwpn,3421				   &found_lun, lun_status, lun_pri))3422		return found_lun;3423	else3424		return NOT_OAS_ENABLED_LUN;3425}3426 3427/**3428 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations3429 * @phba: lpfc_hba pointer.3430 * @vpt_wwpn: vport wwpn by reference.3431 * @tgt_wwpn: target wwpn by reference.3432 * @lun: the fc lun for setting oas state.3433 * @oas_state: the oas state to be set to the oas_lun.3434 * @pri: priority3435 *3436 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)3437 * a lun for OAS operations.3438 *3439 * Return:3440 * SUCCESS: 03441 * -ENOMEM: failed to enable an lun for OAS operations3442 * -EPERM: OAS is not enabled3443 */3444static ssize_t3445lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],3446			  uint8_t tgt_wwpn[], uint64_t lun,3447			  uint32_t oas_state, uint8_t pri)3448{3449 3450	int rc;3451 3452	rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,3453				    oas_state, pri);3454	return rc;3455}3456 3457/**3458 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target3459 * @dev: class device that is converted into a Scsi_host.3460 * @attr: device attribute, not used.3461 * @buf: buffer for passing information.3462 *3463 * This routine returns a lun enabled for OAS each time the function3464 * is called.3465 *3466 * Returns:3467 * SUCCESS: size of formatted string.3468 * -EFAULT: target or vport wwpn was not set properly.3469 * -EPERM: oas is not enabled.3470 **/3471static ssize_t3472lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,3473		  char *buf)3474{3475	struct Scsi_Host *shost = class_to_shost(dev);3476	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;3477 3478	uint64_t oas_lun;3479	int len = 0;3480 3481	if (!phba->cfg_fof)3482		return -EPERM;3483 3484	if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)3485		if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))3486			return -EFAULT;3487 3488	if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)3489		if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))3490			return -EFAULT;3491 3492	oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,3493					phba->cfg_oas_tgt_wwpn,3494					&phba->cfg_oas_lun_status,3495					&phba->cfg_oas_priority);3496	if (oas_lun != NOT_OAS_ENABLED_LUN)3497		phba->cfg_oas_flags |= OAS_LUN_VALID;3498 3499	len += scnprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);3500 3501	return len;3502}3503 3504/**3505 * lpfc_oas_lun_store - Sets the OAS state for lun3506 * @dev: class device that is converted into a Scsi_host.3507 * @attr: device attribute, not used.3508 * @buf: buffer for passing information.3509 * @count: size of the formatting string3510 *3511 * This function sets the OAS state for lun.  Before this function is called,3512 * the vport wwpn, target wwpn, and oas state need to be set.3513 *3514 * Returns:3515 * SUCCESS: size of formatted string.3516 * -EFAULT: target or vport wwpn was not set properly.3517 * -EPERM: oas is not enabled.3518 * size of formatted string.3519 **/3520static ssize_t3521lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,3522		   const char *buf, size_t count)3523{3524	struct Scsi_Host *shost = class_to_shost(dev);3525	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;3526	uint64_t scsi_lun;3527	uint32_t pri;3528	ssize_t rc;3529 3530	if (!phba->cfg_fof)3531		return -EPERM;3532 3533	if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)3534		return -EFAULT;3535 3536	if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)3537		return -EFAULT;3538 3539	if (!isdigit(buf[0]))3540		return -EINVAL;3541 3542	if (sscanf(buf, "0x%llx", &scsi_lun) != 1)3543		return -EINVAL;3544 3545	pri = phba->cfg_oas_priority;3546	if (pri == 0)3547		pri = phba->cfg_XLanePriority;3548 3549	lpfc_printf_log(phba, KERN_INFO, LOG_INIT,3550			"3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "3551			"priority 0x%x with oas state %d\n",3552			wwn_to_u64(phba->cfg_oas_vpt_wwpn),3553			wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,3554			pri, phba->cfg_oas_lun_state);3555 3556	rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,3557				       phba->cfg_oas_tgt_wwpn, scsi_lun,3558				       phba->cfg_oas_lun_state, pri);3559	if (rc)3560		return rc;3561 3562	return count;3563}3564static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,3565		   lpfc_oas_lun_show, lpfc_oas_lun_store);3566 3567int lpfc_enable_nvmet_cnt;3568unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {3569	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,3570	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};3571module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);3572MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");3573 3574static int lpfc_poll = 0;3575module_param(lpfc_poll, int, S_IRUGO);3576MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"3577		 " 0 - none,"3578		 " 1 - poll with interrupts enabled"3579		 " 3 - poll and disable FCP ring interrupts");3580 3581static DEVICE_ATTR_RW(lpfc_poll);3582 3583int lpfc_no_hba_reset_cnt;3584unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {3585	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};3586module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);3587MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");3588 3589LPFC_ATTR(sli_mode, 3, 3, 3,3590	"SLI mode selector: 3 - select SLI-3");3591 3592LPFC_ATTR_R(enable_npiv, 1, 0, 1,3593	"Enable NPIV functionality");3594 3595LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,3596	"FCF Fast failover=1 Priority failover=2");3597 3598/*3599 * lpfc_fcp_wait_abts_rsp: Modifies criteria for reporting completion of3600 * aborted IO.3601 * The range is [0,1]. Default value is 03602 *      0, IO completes after ABTS issued (default).3603 *      1, IO completes after receipt of ABTS response or timeout.3604 */3605LPFC_ATTR_R(fcp_wait_abts_rsp, 0, 0, 1, "Wait for FCP ABTS completion");3606 3607/*3608# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures3609#	0x0 = disabled, XRI/OXID use not tracked.3610#	0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.3611#	0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.3612*/3613LPFC_ATTR_R(enable_rrq, 2, 0, 2,3614	"Enable RRQ functionality");3615 3616/*3617# lpfc_suppress_link_up:  Bring link up at initialization3618#            0x0  = bring link up (issue MBX_INIT_LINK)3619#            0x1  = do NOT bring link up at initialization(MBX_INIT_LINK)3620#            0x2  = never bring up link3621# Default value is 0.3622*/3623LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,3624		LPFC_DELAY_INIT_LINK_INDEFINITELY,3625		"Suppress Link Up at initialization");3626 3627static ssize_t3628lpfc_pls_show(struct device *dev, struct device_attribute *attr, char *buf)3629{3630	struct Scsi_Host  *shost = class_to_shost(dev);3631	struct lpfc_hba   *phba = ((struct lpfc_vport *)shost->hostdata)->phba;3632 3633	return scnprintf(buf, PAGE_SIZE, "%d\n",3634			 phba->sli4_hba.pc_sli4_params.pls);3635}3636static DEVICE_ATTR(pls, 0444,3637			 lpfc_pls_show, NULL);3638 3639static ssize_t3640lpfc_pt_show(struct device *dev, struct device_attribute *attr, char *buf)3641{3642	struct Scsi_Host  *shost = class_to_shost(dev);3643	struct lpfc_hba   *phba = ((struct lpfc_vport *)shost->hostdata)->phba;3644 3645	return scnprintf(buf, PAGE_SIZE, "%d\n",3646			 test_bit(HBA_PERSISTENT_TOPO,3647				  &phba->hba_flag) ? 1 : 0);3648}3649static DEVICE_ATTR(pt, 0444,3650			 lpfc_pt_show, NULL);3651 3652/*3653# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS3654#       1 - (1024)3655#       2 - (2048)3656#       3 - (3072)3657#       4 - (4096)3658#       5 - (5120)3659*/3660static ssize_t3661lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)3662{3663	struct Scsi_Host  *shost = class_to_shost(dev);3664	struct lpfc_hba   *phba = ((struct lpfc_vport *) shost->hostdata)->phba;3665 3666	return scnprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);3667}3668 3669static DEVICE_ATTR(iocb_hw, S_IRUGO,3670			 lpfc_iocb_hw_show, NULL);3671static ssize_t3672lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)3673{3674	struct Scsi_Host  *shost = class_to_shost(dev);3675	struct lpfc_hba   *phba = ((struct lpfc_vport *) shost->hostdata)->phba;3676	struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);3677 3678	return scnprintf(buf, PAGE_SIZE, "%d\n",3679			pring ? pring->txq_max : 0);3680}3681 3682static DEVICE_ATTR(txq_hw, S_IRUGO,3683			 lpfc_txq_hw_show, NULL);3684static ssize_t3685lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,3686 char *buf)3687{3688	struct Scsi_Host  *shost = class_to_shost(dev);3689	struct lpfc_hba   *phba = ((struct lpfc_vport *) shost->hostdata)->phba;3690	struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);3691 3692	return scnprintf(buf, PAGE_SIZE, "%d\n",3693			pring ? pring->txcmplq_max : 0);3694}3695 3696static DEVICE_ATTR(txcmplq_hw, S_IRUGO,3697			 lpfc_txcmplq_hw_show, NULL);3698 3699/*3700# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear3701# until the timer expires. Value range is [0,255]. Default value is 30.3702*/3703static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;3704static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;3705module_param(lpfc_nodev_tmo, int, 0);3706MODULE_PARM_DESC(lpfc_nodev_tmo,3707		 "Seconds driver will hold I/O waiting "3708		 "for a device to come back");3709 3710/**3711 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value3712 * @dev: class converted to a Scsi_host structure.3713 * @attr: device attribute, not used.3714 * @buf: on return contains the dev loss timeout in decimal.3715 *3716 * Returns: size of formatted string.3717 **/3718static ssize_t3719lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,3720		    char *buf)3721{3722	struct Scsi_Host  *shost = class_to_shost(dev);3723	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;3724 3725	return scnprintf(buf, PAGE_SIZE, "%d\n",	vport->cfg_devloss_tmo);3726}3727 3728/**3729 * lpfc_nodev_tmo_init - Set the hba nodev timeout value3730 * @vport: lpfc vport structure pointer.3731 * @val: contains the nodev timeout value.3732 *3733 * Description:3734 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,3735 * a kernel error message is printed and zero is returned.3736 * Else if val is in range then nodev tmo and devloss tmo are set to val.3737 * Otherwise nodev tmo is set to the default value.3738 *3739 * Returns:3740 * zero if already set or if val is in range3741 * -EINVAL val out of range3742 **/3743static int3744lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)3745{3746	if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {3747		vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;3748		if (val != LPFC_DEF_DEVLOSS_TMO)3749			lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,3750					 "0407 Ignoring lpfc_nodev_tmo module "3751					 "parameter because lpfc_devloss_tmo "3752					 "is set.\n");3753		return 0;3754	}3755 3756	if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {3757		vport->cfg_nodev_tmo = val;3758		vport->cfg_devloss_tmo = val;3759		return 0;3760	}3761	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,3762			 "0400 lpfc_nodev_tmo attribute cannot be set to"3763			 " %d, allowed range is [%d, %d]\n",3764			 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);3765	vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;3766	return -EINVAL;3767}3768 3769/**3770 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value3771 * @vport: lpfc vport structure pointer.3772 *3773 * Description:3774 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.3775 **/3776static void3777lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)3778{3779	struct lpfc_nodelist  *ndlp;3780	unsigned long iflags;3781#if (IS_ENABLED(CONFIG_NVME_FC))3782	struct lpfc_nvme_rport *rport;3783	struct nvme_fc_remote_port *remoteport = NULL;3784#endif3785 3786	spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);3787	list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {3788		if (ndlp->rport)3789			ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;3790#if (IS_ENABLED(CONFIG_NVME_FC))3791		spin_lock(&ndlp->lock);3792		rport = lpfc_ndlp_get_nrport(ndlp);3793		if (rport)3794			remoteport = rport->remoteport;3795		spin_unlock(&ndlp->lock);3796		if (rport && remoteport)3797			nvme_fc_set_remoteport_devloss(remoteport,3798						       vport->cfg_devloss_tmo);3799#endif3800	}3801	spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);3802}3803 3804/**3805 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values3806 * @vport: lpfc vport structure pointer.3807 * @val: contains the tmo value.3808 *3809 * Description:3810 * If the devloss tmo is already set or the vport dev loss tmo has changed3811 * then a kernel error message is printed and zero is returned.3812 * Else if val is in range then nodev tmo and devloss tmo are set to val.3813 * Otherwise nodev tmo is set to the default value.3814 *3815 * Returns:3816 * zero if already set or if val is in range3817 * -EINVAL val out of range3818 **/3819static int3820lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)3821{3822	if (vport->dev_loss_tmo_changed ||3823	    (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {3824		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,3825				 "0401 Ignoring change to lpfc_nodev_tmo "3826				 "because lpfc_devloss_tmo is set.\n");3827		return 0;3828	}3829	if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {3830		vport->cfg_nodev_tmo = val;3831		vport->cfg_devloss_tmo = val;3832		/*3833		 * For compat: set the fc_host dev loss so new rports3834		 * will get the value.3835		 */3836		fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;3837		lpfc_update_rport_devloss_tmo(vport);3838		return 0;3839	}3840	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,3841			 "0403 lpfc_nodev_tmo attribute cannot be set to "3842			 "%d, allowed range is [%d, %d]\n",3843			 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);3844	return -EINVAL;3845}3846 3847lpfc_vport_param_store(nodev_tmo)3848 3849static DEVICE_ATTR_RW(lpfc_nodev_tmo);3850 3851/*3852# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that3853# disappear until the timer expires. Value range is [0,255]. Default3854# value is 30.3855*/3856module_param(lpfc_devloss_tmo, int, S_IRUGO);3857MODULE_PARM_DESC(lpfc_devloss_tmo,3858		 "Seconds driver will hold I/O waiting "3859		 "for a device to come back");3860lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,3861		      LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)3862lpfc_vport_param_show(devloss_tmo)3863 3864/**3865 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit3866 * @vport: lpfc vport structure pointer.3867 * @val: contains the tmo value.3868 *3869 * Description:3870 * If val is in a valid range then set the vport nodev tmo,3871 * devloss tmo, also set the vport dev loss tmo changed flag.3872 * Else a kernel error message is printed.3873 *3874 * Returns:3875 * zero if val is in range3876 * -EINVAL val out of range3877 **/3878static int3879lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)3880{3881	if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {3882		vport->cfg_nodev_tmo = val;3883		vport->cfg_devloss_tmo = val;3884		vport->dev_loss_tmo_changed = 1;3885		fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;3886		lpfc_update_rport_devloss_tmo(vport);3887		return 0;3888	}3889 3890	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,3891			 "0404 lpfc_devloss_tmo attribute cannot be set to "3892			 "%d, allowed range is [%d, %d]\n",3893			 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);3894	return -EINVAL;3895}3896 3897lpfc_vport_param_store(devloss_tmo)3898static DEVICE_ATTR_RW(lpfc_devloss_tmo);3899 3900/*3901 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it3902 * lpfc_suppress_rsp = 0  Disable3903 * lpfc_suppress_rsp = 1  Enable (default)3904 *3905 */3906LPFC_ATTR_R(suppress_rsp, 1, 0, 1,3907	    "Enable suppress rsp feature is firmware supports it");3908 3909/*3910 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds3911 * lpfc_nvmet_mrq = 0  driver will calcualte optimal number of RQ pairs3912 * lpfc_nvmet_mrq = 1  use a single RQ pair3913 * lpfc_nvmet_mrq >= 2  use specified RQ pairs for MRQ3914 *3915 */3916LPFC_ATTR_R(nvmet_mrq,3917	    LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,3918	    "Specify number of RQ pairs for processing NVMET cmds");3919 3920/*3921 * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post3922 * to each NVMET RQ. Range 64 to 2048, default is 512.3923 */3924LPFC_ATTR_R(nvmet_mrq_post,3925	    LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,3926	    LPFC_NVMET_RQE_DEF_COUNT,3927	    "Specify number of RQ buffers to initially post");3928 3929/*3930 * lpfc_enable_fc4_type: Defines what FC4 types are supported.3931 * Supported Values:  1 - register just FCP3932 *                    3 - register both FCP and NVME3933 * Supported values are [1,3]. Default value is 33934 */3935LPFC_ATTR_R(enable_fc4_type, LPFC_DEF_ENBL_FC4_TYPE,3936	    LPFC_ENABLE_FCP, LPFC_MAX_ENBL_FC4_TYPE,3937	    "Enable FC4 Protocol support - FCP / NVME");3938 3939/*3940# lpfc_log_verbose: Only turn this flag on if you are willing to risk being3941# deluged with LOTS of information.3942# You can set a bit mask to record specific types of verbose messages:3943# See lpfc_logmsh.h for definitions.3944*/3945LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,3946		       "Verbose logging bit-mask");3947 3948/*3949# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters3950# objects that have been registered with the nameserver after login.3951*/3952LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,3953		  "Deregister nameserver objects before LOGO");3954 3955/*3956# lun_queue_depth:  This parameter is used to limit the number of outstanding3957# commands per FCP LUN.3958*/3959LPFC_VPORT_ATTR_R(lun_queue_depth, 64, 1, 512,3960		  "Max number of FCP commands we can queue to a specific LUN");3961 3962/*3963# tgt_queue_depth:  This parameter is used to limit the number of outstanding3964# commands per target port. Value range is [10,65535]. Default value is 65535.3965*/3966static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;3967module_param(lpfc_tgt_queue_depth, uint, 0444);3968MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");3969lpfc_vport_param_show(tgt_queue_depth);3970lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,3971		      LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);3972 3973/**3974 * lpfc_tgt_queue_depth_set: Sets an attribute value.3975 * @vport: lpfc vport structure pointer.3976 * @val: integer attribute value.3977 *3978 * Description: Sets the parameter to the new value.3979 *3980 * Returns:3981 * zero on success3982 * -EINVAL if val is invalid3983 */3984static int3985lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)3986{3987	struct lpfc_nodelist *ndlp;3988	unsigned long iflags;3989 3990	if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))3991		return -EINVAL;3992 3993	if (val == vport->cfg_tgt_queue_depth)3994		return 0;3995 3996	vport->cfg_tgt_queue_depth = val;3997 3998	/* Next loop thru nodelist and change cmd_qdepth */3999	spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);4000	list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)4001		ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;4002	spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);4003	return 0;4004}4005 4006lpfc_vport_param_store(tgt_queue_depth);4007static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);4008 4009/*4010# hba_queue_depth:  This parameter is used to limit the number of outstanding4011# commands per lpfc HBA. Value range is [32,8192]. If this parameter4012# value is greater than the maximum number of exchanges supported by the HBA,4013# then maximum number of exchanges supported by the HBA is used to determine4014# the hba_queue_depth.4015*/4016LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,4017	    "Max number of FCP commands we can queue to a lpfc HBA");4018 4019/*4020# peer_port_login:  This parameter allows/prevents logins4021# between peer ports hosted on the same physical port.4022# When this parameter is set 0 peer ports of same physical port4023# are not allowed to login to each other.4024# When this parameter is set 1 peer ports of same physical port4025# are allowed to login to each other.4026# Default value of this parameter is 0.4027*/4028LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,4029		  "Allow peer ports on the same physical port to login to each "4030		  "other.");4031 4032/*4033# restrict_login:  This parameter allows/prevents logins4034# between Virtual Ports and remote initiators.4035# When this parameter is not set (0) Virtual Ports will accept PLOGIs from4036# other initiators and will attempt to PLOGI all remote ports.4037# When this parameter is set (1) Virtual Ports will reject PLOGIs from4038# remote ports and will not attempt to PLOGI to other initiators.4039# This parameter does not restrict to the physical port.4040# This parameter does not restrict logins to Fabric resident remote ports.4041# Default value of this parameter is 1.4042*/4043static int lpfc_restrict_login = 1;4044module_param(lpfc_restrict_login, int, S_IRUGO);4045MODULE_PARM_DESC(lpfc_restrict_login,4046		 "Restrict virtual ports login to remote initiators.");4047lpfc_vport_param_show(restrict_login);4048 4049/**4050 * lpfc_restrict_login_init - Set the vport restrict login flag4051 * @vport: lpfc vport structure pointer.4052 * @val: contains the restrict login value.4053 *4054 * Description:4055 * If val is not in a valid range then log a kernel error message and set4056 * the vport restrict login to one.4057 * If the port type is physical clear the restrict login flag and return.4058 * Else set the restrict login flag to val.4059 *4060 * Returns:4061 * zero if val is in range4062 * -EINVAL val out of range4063 **/4064static int4065lpfc_restrict_login_init(struct lpfc_vport *vport, int val)4066{4067	if (val < 0 || val > 1) {4068		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,4069				 "0422 lpfc_restrict_login attribute cannot "4070				 "be set to %d, allowed range is [0, 1]\n",4071				 val);4072		vport->cfg_restrict_login = 1;4073		return -EINVAL;4074	}4075	if (vport->port_type == LPFC_PHYSICAL_PORT) {4076		vport->cfg_restrict_login = 0;4077		return 0;4078	}4079	vport->cfg_restrict_login = val;4080	return 0;4081}4082 4083/**4084 * lpfc_restrict_login_set - Set the vport restrict login flag4085 * @vport: lpfc vport structure pointer.4086 * @val: contains the restrict login value.4087 *4088 * Description:4089 * If val is not in a valid range then log a kernel error message and set4090 * the vport restrict login to one.4091 * If the port type is physical and the val is not zero log a kernel4092 * error message, clear the restrict login flag and return zero.4093 * Else set the restrict login flag to val.4094 *4095 * Returns:4096 * zero if val is in range4097 * -EINVAL val out of range4098 **/4099static int4100lpfc_restrict_login_set(struct lpfc_vport *vport, int val)4101{4102	if (val < 0 || val > 1) {4103		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,4104				 "0425 lpfc_restrict_login attribute cannot "4105				 "be set to %d, allowed range is [0, 1]\n",4106				 val);4107		vport->cfg_restrict_login = 1;4108		return -EINVAL;4109	}4110	if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {4111		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,4112				 "0468 lpfc_restrict_login must be 0 for "4113				 "Physical ports.\n");4114		vport->cfg_restrict_login = 0;4115		return 0;4116	}4117	vport->cfg_restrict_login = val;4118	return 0;4119}4120lpfc_vport_param_store(restrict_login);4121static DEVICE_ATTR_RW(lpfc_restrict_login);4122 4123/*4124# Some disk devices have a "select ID" or "select Target" capability.4125# From a protocol standpoint "select ID" usually means select the4126# Fibre channel "ALPA".  In the FC-AL Profile there is an "informative4127# annex" which contains a table that maps a "select ID" (a number4128# between 0 and 7F) to an ALPA.  By default, for compatibility with4129# older drivers, the lpfc driver scans this table from low ALPA to high4130# ALPA.4131#4132# Turning on the scan-down variable (on  = 1, off = 0) will4133# cause the lpfc driver to use an inverted table, effectively4134# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.4135#4136# (Note: This "select ID" functionality is a LOOP ONLY characteristic4137# and will not work across a fabric. Also this parameter will take4138# effect only in the case when ALPA map is not available.)4139*/4140LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,4141		  "Start scanning for devices from highest ALPA to lowest");4142 4143/*4144# lpfc_topology:  link topology for init link4145#            0x0  = attempt loop mode then point-to-point4146#            0x01 = internal loopback mode4147#            0x02 = attempt point-to-point mode only4148#            0x04 = attempt loop mode only4149#            0x06 = attempt point-to-point mode then loop4150# Set point-to-point mode if you want to run as an N_Port.4151# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].4152# Default value is 0.4153*/4154LPFC_ATTR(topology, 0, 0, 6,4155	"Select Fibre Channel topology");4156 4157/**4158 * lpfc_topology_store - Set the adapters topology field4159 * @dev: class device that is converted into a scsi_host.4160 * @attr:device attribute, not used.4161 * @buf: buffer for passing information.4162 * @count: size of the data buffer.4163 *4164 * Description:4165 * If val is in a valid range then set the adapter's topology field and4166 * issue a lip; if the lip fails reset the topology to the old value.4167 *4168 * If the value is not in range log a kernel error message and return an error.4169 *4170 * Returns:4171 * zero if val is in range and lip okay4172 * non-zero return value from lpfc_issue_lip()4173 * -EINVAL val out of range4174 **/4175static ssize_t4176lpfc_topology_store(struct device *dev, struct device_attribute *attr,4177			const char *buf, size_t count)4178{4179	struct Scsi_Host  *shost = class_to_shost(dev);4180	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;4181	struct lpfc_hba   *phba = vport->phba;4182	int val = 0;4183	int nolip = 0;4184	const char *val_buf = buf;4185	int err;4186	uint32_t prev_val;4187	u8 sli_family, if_type;4188 4189	if (!strncmp(buf, "nolip ", strlen("nolip "))) {4190		nolip = 1;4191		val_buf = &buf[strlen("nolip ")];4192	}4193 4194	if (!isdigit(val_buf[0]))4195		return -EINVAL;4196	if (sscanf(val_buf, "%i", &val) != 1)4197		return -EINVAL;4198 4199	if (val >= 0 && val <= 6) {4200		prev_val = phba->cfg_topology;4201		if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&4202			val == 4) {4203			lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,4204				"3113 Loop mode not supported at speed %d\n",4205				val);4206			return -EINVAL;4207		}4208		/*4209		 * The 'topology' is not a configurable parameter if :4210		 *   - persistent topology enabled4211		 *   - ASIC_GEN_NUM >= 0xC, with no private loop support4212		 */4213		sli_family = bf_get(lpfc_sli_intf_sli_family,4214				    &phba->sli4_hba.sli_intf);4215		if_type = bf_get(lpfc_sli_intf_if_type,4216				 &phba->sli4_hba.sli_intf);4217		if ((test_bit(HBA_PERSISTENT_TOPO, &phba->hba_flag) ||4218		     (!phba->sli4_hba.pc_sli4_params.pls &&4219		     (sli_family == LPFC_SLI_INTF_FAMILY_G6 ||4220		      if_type == LPFC_SLI_INTF_IF_TYPE_6))) &&4221		    val == 4) {4222			lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,4223				"3114 Loop mode not supported\n");4224			return -EINVAL;4225		}4226		phba->cfg_topology = val;4227		if (nolip)4228			return strlen(buf);4229 4230		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,4231			"3054 lpfc_topology changed from %d to %d\n",4232			prev_val, val);4233		if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)4234			phba->fc_topology_changed = 1;4235		err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));4236		if (err) {4237			phba->cfg_topology = prev_val;4238			return -EINVAL;4239		} else4240			return strlen(buf);4241	}4242	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,4243		"%d:0467 lpfc_topology attribute cannot be set to %d, "4244		"allowed range is [0, 6]\n",4245		phba->brd_no, val);4246	return -EINVAL;4247}4248 4249lpfc_param_show(topology)4250static DEVICE_ATTR_RW(lpfc_topology);4251 4252/**4253 * lpfc_static_vport_show: Read callback function for4254 *   lpfc_static_vport sysfs file.4255 * @dev: Pointer to class device object.4256 * @attr: device attribute structure.4257 * @buf: Data buffer.4258 *4259 * This function is the read call back function for4260 * lpfc_static_vport sysfs file. The lpfc_static_vport4261 * sysfs file report the mageability of the vport.4262 **/4263static ssize_t4264lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,4265			 char *buf)4266{4267	struct Scsi_Host  *shost = class_to_shost(dev);4268	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;4269	if (vport->vport_flag & STATIC_VPORT)4270		sprintf(buf, "1\n");4271	else4272		sprintf(buf, "0\n");4273 4274	return strlen(buf);4275}4276 4277/*4278 * Sysfs attribute to control the statistical data collection.4279 */4280static DEVICE_ATTR_RO(lpfc_static_vport);4281 4282/*4283# lpfc_link_speed: Link speed selection for initializing the Fibre Channel4284# connection.4285# Value range is [0,16]. Default value is 0.4286*/4287/**4288 * lpfc_link_speed_store - Set the adapters link speed4289 * @dev: Pointer to class device.4290 * @attr: Unused.4291 * @buf: Data buffer.4292 * @count: Size of the data buffer.4293 *4294 * Description:4295 * If val is in a valid range then set the adapter's link speed field and4296 * issue a lip; if the lip fails reset the link speed to the old value.4297 *4298 * Notes:4299 * If the value is not in range log a kernel error message and return an error.4300 *4301 * Returns:4302 * zero if val is in range and lip okay.4303 * non-zero return value from lpfc_issue_lip()4304 * -EINVAL val out of range4305 **/4306static ssize_t4307lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,4308		const char *buf, size_t count)4309{4310	struct Scsi_Host  *shost = class_to_shost(dev);4311	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;4312	struct lpfc_hba   *phba = vport->phba;4313	int val = LPFC_USER_LINK_SPEED_AUTO;4314	int nolip = 0;4315	const char *val_buf = buf;4316	int err;4317	uint32_t prev_val, if_type;4318 4319	if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);4320	if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&4321	    test_bit(HBA_FORCED_LINK_SPEED, &phba->hba_flag))4322		return -EPERM;4323 4324	if (!strncmp(buf, "nolip ", strlen("nolip "))) {4325		nolip = 1;4326		val_buf = &buf[strlen("nolip ")];4327	}4328 4329	if (!isdigit(val_buf[0]))4330		return -EINVAL;4331	if (sscanf(val_buf, "%i", &val) != 1)4332		return -EINVAL;4333 4334	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,4335		"3055 lpfc_link_speed changed from %d to %d %s\n",4336		phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");4337 4338	if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||4339	    ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||4340	    ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||4341	    ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||4342	    ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||4343	    ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||4344	    ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||4345	    ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {4346		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,4347				"2879 lpfc_link_speed attribute cannot be set "4348				"to %d. Speed is not supported by this port.\n",4349				val);4350		return -EINVAL;4351	}4352	if (val >= LPFC_USER_LINK_SPEED_16G &&4353	    phba->fc_topology == LPFC_TOPOLOGY_LOOP) {4354		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,4355				"3112 lpfc_link_speed attribute cannot be set "4356				"to %d. Speed is not supported in loop mode.\n",4357				val);4358		return -EINVAL;4359	}4360 4361	switch (val) {4362	case LPFC_USER_LINK_SPEED_AUTO:4363	case LPFC_USER_LINK_SPEED_1G:4364	case LPFC_USER_LINK_SPEED_2G:4365	case LPFC_USER_LINK_SPEED_4G:4366	case LPFC_USER_LINK_SPEED_8G:4367	case LPFC_USER_LINK_SPEED_16G:4368	case LPFC_USER_LINK_SPEED_32G:4369	case LPFC_USER_LINK_SPEED_64G:4370		prev_val = phba->cfg_link_speed;4371		phba->cfg_link_speed = val;4372		if (nolip)4373			return strlen(buf);4374 4375		err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));4376		if (err) {4377			phba->cfg_link_speed = prev_val;4378			return -EINVAL;4379		}4380		return strlen(buf);4381	default:4382		break;4383	}4384 4385	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,4386			"0469 lpfc_link_speed attribute cannot be set to %d, "4387			"allowed values are [%s]\n",4388			val, LPFC_LINK_SPEED_STRING);4389	return -EINVAL;4390 4391}4392 4393static int lpfc_link_speed = 0;4394module_param(lpfc_link_speed, int, S_IRUGO);4395MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");4396lpfc_param_show(link_speed)4397 4398/**4399 * lpfc_link_speed_init - Set the adapters link speed4400 * @phba: lpfc_hba pointer.4401 * @val: link speed value.4402 *4403 * Description:4404 * If val is in a valid range then set the adapter's link speed field.4405 *4406 * Notes:4407 * If the value is not in range log a kernel error message, clear the link4408 * speed and return an error.4409 *4410 * Returns:4411 * zero if val saved.4412 * -EINVAL val out of range4413 **/4414static int4415lpfc_link_speed_init(struct lpfc_hba *phba, int val)4416{4417	if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {4418		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,4419			"3111 lpfc_link_speed of %d cannot "4420			"support loop mode, setting topology to default.\n",4421			 val);4422		phba->cfg_topology = 0;4423	}4424 4425	switch (val) {4426	case LPFC_USER_LINK_SPEED_AUTO:4427	case LPFC_USER_LINK_SPEED_1G:4428	case LPFC_USER_LINK_SPEED_2G:4429	case LPFC_USER_LINK_SPEED_4G:4430	case LPFC_USER_LINK_SPEED_8G:4431	case LPFC_USER_LINK_SPEED_16G:4432	case LPFC_USER_LINK_SPEED_32G:4433	case LPFC_USER_LINK_SPEED_64G:4434		phba->cfg_link_speed = val;4435		return 0;4436	default:4437		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,4438				"0405 lpfc_link_speed attribute cannot "4439				"be set to %d, allowed values are "4440				"["LPFC_LINK_SPEED_STRING"]\n", val);4441		phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;4442		return -EINVAL;4443	}4444}4445 4446static DEVICE_ATTR_RW(lpfc_link_speed);4447 4448/*4449# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)4450#       1  = aer supported and enabled (default)4451# PCIe error reporting is always enabled by the PCI core, so this always4452# shows 1.4453#4454# N.B. Parts of LPFC_ATTR open-coded since some of the underlying4455# infrastructure (phba->cfg_aer_support) is gone.4456*/4457static uint lpfc_aer_support = 1;4458module_param(lpfc_aer_support, uint, S_IRUGO);4459MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");4460static ssize_t4461lpfc_aer_support_show(struct device *dev, struct device_attribute *attr,4462		      char *buf)4463{4464	return scnprintf(buf, PAGE_SIZE, "%d\n", lpfc_aer_support);4465}4466 4467/**4468 * lpfc_aer_support_store - Set the adapter for aer support4469 *4470 * @dev: class device that is converted into a Scsi_host.4471 * @attr: device attribute, not used.4472 * @buf: containing enable or disable aer flag.4473 * @count: unused variable.4474 *4475 * Description:4476 * PCIe error reporting is enabled by the PCI core, so drivers don't need4477 * to do anything.  Retain this interface for backwards compatibility,4478 * but do nothing.4479 *4480 * Returns:4481 * length of the buf on success4482 * -EINVAL if val out of range4483 **/4484static ssize_t4485lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,4486		       const char *buf, size_t count)4487{4488	int val = 0;4489 4490	if (!isdigit(buf[0]))4491		return -EINVAL;4492	if (sscanf(buf, "%i", &val) != 1)4493		return -EINVAL;4494 4495	dev_info_once(dev, "PCIe error reporting automatically enabled by the PCI core; sysfs write ignored\n");4496	return strlen(buf);4497}4498 4499static DEVICE_ATTR_RW(lpfc_aer_support);4500 4501/**4502 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device4503 * @dev: class device that is converted into a Scsi_host.4504 * @attr: device attribute, not used.4505 * @buf: containing flag 1 for aer cleanup state.4506 * @count: unused variable.4507 *4508 * Description:4509 * If the @buf contains 1, invokes the kernel AER helper routine4510 * pci_aer_clear_nonfatal_status() to clean up the uncorrectable4511 * error status register.4512 *4513 * Notes:4514 *4515 * Returns:4516 * -EINVAL if the buf does not contain 14517 * -EPERM if the OS cannot clear AER error status, i.e., when platform4518 * firmware owns the AER Capability4519 **/4520static ssize_t4521lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,4522		       const char *buf, size_t count)4523{4524	struct Scsi_Host  *shost = class_to_shost(dev);4525	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;4526	struct lpfc_hba   *phba = vport->phba;4527	int val, rc = -1;4528 4529	if (!isdigit(buf[0]))4530		return -EINVAL;4531	if (sscanf(buf, "%i", &val) != 1)4532		return -EINVAL;4533	if (val != 1)4534		return -EINVAL;4535 4536	rc = pci_aer_clear_nonfatal_status(phba->pcidev);4537 4538	if (rc == 0)4539		return strlen(buf);4540	else4541		return -EPERM;4542}4543 4544static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,4545		   lpfc_aer_cleanup_state);4546 4547/**4548 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions4549 *4550 * @dev: class device that is converted into a Scsi_host.4551 * @attr: device attribute, not used.4552 * @buf: containing the string the number of vfs to be enabled.4553 * @count: unused variable.4554 *4555 * Description:4556 * When this api is called either through user sysfs, the driver shall4557 * try to enable or disable SR-IOV virtual functions according to the4558 * following:4559 *4560 * If zero virtual function has been enabled to the physical function,4561 * the driver shall invoke the pci enable virtual function api trying4562 * to enable the virtual functions. If the nr_vfn provided is greater4563 * than the maximum supported, the maximum virtual function number will4564 * be used for invoking the api; otherwise, the nr_vfn provided shall4565 * be used for invoking the api. If the api call returned success, the4566 * actual number of virtual functions enabled will be set to the driver4567 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver4568 * cfg_sriov_nr_virtfn remains zero.4569 *4570 * If none-zero virtual functions have already been enabled to the4571 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,4572 * -EINVAL will be returned and the driver does nothing;4573 *4574 * If the nr_vfn provided is zero and none-zero virtual functions have4575 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the4576 * disabling virtual function api shall be invoded to disable all the4577 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to4578 * zero. Otherwise, if zero virtual function has been enabled, do4579 * nothing.4580 *4581 * Returns:4582 * length of the buf on success if val is in range the intended mode4583 * is supported.4584 * -EINVAL if val out of range or intended mode is not supported.4585 **/4586static ssize_t4587lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,4588			 const char *buf, size_t count)4589{4590	struct Scsi_Host *shost = class_to_shost(dev);4591	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;4592	struct lpfc_hba *phba = vport->phba;4593	struct pci_dev *pdev = phba->pcidev;4594	int val = 0, rc = -EINVAL;4595 4596	/* Sanity check on user data */4597	if (!isdigit(buf[0]))4598		return -EINVAL;4599	if (sscanf(buf, "%i", &val) != 1)4600		return -EINVAL;4601	if (val < 0)4602		return -EINVAL;4603 4604	/* Request disabling virtual functions */4605	if (val == 0) {4606		if (phba->cfg_sriov_nr_virtfn > 0) {4607			pci_disable_sriov(pdev);4608			phba->cfg_sriov_nr_virtfn = 0;4609		}4610		return strlen(buf);4611	}4612 4613	/* Request enabling virtual functions */4614	if (phba->cfg_sriov_nr_virtfn > 0) {4615		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,4616				"3018 There are %d virtual functions "4617				"enabled on physical function.\n",4618				phba->cfg_sriov_nr_virtfn);4619		return -EEXIST;4620	}4621 4622	if (val <= LPFC_MAX_VFN_PER_PFN)4623		phba->cfg_sriov_nr_virtfn = val;4624	else {4625		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,4626				"3019 Enabling %d virtual functions is not "4627				"allowed.\n", val);4628		return -EINVAL;4629	}4630 4631	rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);4632	if (rc) {4633		phba->cfg_sriov_nr_virtfn = 0;4634		rc = -EPERM;4635	} else4636		rc = strlen(buf);4637 4638	return rc;4639}4640 4641LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,4642	"Enable PCIe device SR-IOV virtual fn");4643 4644lpfc_param_show(sriov_nr_virtfn)4645static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);4646 4647/**4648 * lpfc_request_firmware_upgrade_store - Request for Linux generic firmware upgrade4649 *4650 * @dev: class device that is converted into a Scsi_host.4651 * @attr: device attribute, not used.4652 * @buf: containing the string the number of vfs to be enabled.4653 * @count: unused variable.4654 *4655 * Description:4656 *4657 * Returns:4658 * length of the buf on success if val is in range the intended mode4659 * is supported.4660 * -EINVAL if val out of range or intended mode is not supported.4661 **/4662static ssize_t4663lpfc_request_firmware_upgrade_store(struct device *dev,4664				    struct device_attribute *attr,4665				    const char *buf, size_t count)4666{4667	struct Scsi_Host *shost = class_to_shost(dev);4668	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;4669	struct lpfc_hba *phba = vport->phba;4670	int val = 0, rc;4671 4672	/* Sanity check on user data */4673	if (!isdigit(buf[0]))4674		return -EINVAL;4675	if (sscanf(buf, "%i", &val) != 1)4676		return -EINVAL;4677	if (val != 1)4678		return -EINVAL;4679 4680	rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);4681	if (rc)4682		rc = -EPERM;4683	else4684		rc = strlen(buf);4685	return rc;4686}4687 4688static int lpfc_req_fw_upgrade;4689module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);4690MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");4691lpfc_param_show(request_firmware_upgrade)4692 4693/**4694 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade4695 * @phba: lpfc_hba pointer.4696 * @val: 0 or 1.4697 *4698 * Description:4699 * Set the initial Linux generic firmware upgrade enable or disable flag.4700 *4701 * Returns:4702 * zero if val saved.4703 * -EINVAL val out of range4704 **/4705static int4706lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)4707{4708	if (val >= 0 && val <= 1) {4709		phba->cfg_request_firmware_upgrade = val;4710		return 0;4711	}4712	return -EINVAL;4713}4714static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,4715		   lpfc_request_firmware_upgrade_show,4716		   lpfc_request_firmware_upgrade_store);4717 4718/**4719 * lpfc_force_rscn_store4720 *4721 * @dev: class device that is converted into a Scsi_host.4722 * @attr: device attribute, not used.4723 * @buf: unused string4724 * @count: unused variable.4725 *4726 * Description:4727 * Force the switch to send a RSCN to all other NPorts in our zone4728 * If we are direct connect pt2pt, build the RSCN command ourself4729 * and send to the other NPort. Not supported for private loop.4730 *4731 * Returns:4732 * 0      - on success4733 * -EIO   - if command is not sent4734 **/4735static ssize_t4736lpfc_force_rscn_store(struct device *dev, struct device_attribute *attr,4737		      const char *buf, size_t count)4738{4739	struct Scsi_Host *shost = class_to_shost(dev);4740	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;4741	int i;4742 4743	i = lpfc_issue_els_rscn(vport, 0);4744	if (i)4745		return -EIO;4746	return strlen(buf);4747}4748 4749/*4750 * lpfc_force_rscn: Force an RSCN to be sent to all remote NPorts4751 * connected to  the HBA.4752 *4753 * Value range is any ascii value4754 */4755static int lpfc_force_rscn;4756module_param(lpfc_force_rscn, int, 0644);4757MODULE_PARM_DESC(lpfc_force_rscn,4758		 "Force an RSCN to be sent to all remote NPorts");4759lpfc_param_show(force_rscn)4760 4761/**4762 * lpfc_force_rscn_init - Force an RSCN to be sent to all remote NPorts4763 * @phba: lpfc_hba pointer.4764 * @val: unused value.4765 *4766 * Returns:4767 * zero if val saved.4768 **/4769static int4770lpfc_force_rscn_init(struct lpfc_hba *phba, int val)4771{4772	return 0;4773}4774static DEVICE_ATTR_RW(lpfc_force_rscn);4775 4776/**4777 * lpfc_fcp_imax_store4778 *4779 * @dev: class device that is converted into a Scsi_host.4780 * @attr: device attribute, not used.4781 * @buf: string with the number of fast-path FCP interrupts per second.4782 * @count: unused variable.4783 *4784 * Description:4785 * If val is in a valid range [636,651042], then set the adapter's4786 * maximum number of fast-path FCP interrupts per second.4787 *4788 * Returns:4789 * length of the buf on success if val is in range the intended mode4790 * is supported.4791 * -EINVAL if val out of range or intended mode is not supported.4792 **/4793static ssize_t4794lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,4795			 const char *buf, size_t count)4796{4797	struct Scsi_Host *shost = class_to_shost(dev);4798	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;4799	struct lpfc_hba *phba = vport->phba;4800	struct lpfc_eq_intr_info *eqi;4801	uint32_t usdelay;4802	int val = 0, i;4803 4804	/* fcp_imax is only valid for SLI4 */4805	if (phba->sli_rev != LPFC_SLI_REV4)4806		return -EINVAL;4807 4808	/* Sanity check on user data */4809	if (!isdigit(buf[0]))4810		return -EINVAL;4811	if (sscanf(buf, "%i", &val) != 1)4812		return -EINVAL;4813 4814	/*4815	 * Value range for the HBA is [5000,5000000]4816	 * The value for each EQ depends on how many EQs are configured.4817	 * Allow value == 04818	 */4819	if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))4820		return -EINVAL;4821 4822	phba->cfg_auto_imax = (val) ? 0 : 1;4823	if (phba->cfg_fcp_imax && !val) {4824		queue_delayed_work(phba->wq, &phba->eq_delay_work,4825				   msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));4826 4827		for_each_present_cpu(i) {4828			eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);4829			eqi->icnt = 0;4830		}4831	}4832 4833	phba->cfg_fcp_imax = (uint32_t)val;4834 4835	if (phba->cfg_fcp_imax)4836		usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;4837	else4838		usdelay = 0;4839 4840	for (i = 0; i < phba->cfg_irq_chann; i += LPFC_MAX_EQ_DELAY_EQID_CNT)4841		lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,4842					 usdelay);4843 4844	return strlen(buf);4845}4846 4847/*4848# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second4849# for the HBA.4850#4851# Value range is [5,000 to 5,000,000]. Default value is 50,000.4852*/4853static int lpfc_fcp_imax = LPFC_DEF_IMAX;4854module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);4855MODULE_PARM_DESC(lpfc_fcp_imax,4856	    "Set the maximum number of FCP interrupts per second per HBA");4857lpfc_param_show(fcp_imax)4858 4859/**4860 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable4861 * @phba: lpfc_hba pointer.4862 * @val: link speed value.4863 *4864 * Description:4865 * If val is in a valid range [636,651042], then initialize the adapter's4866 * maximum number of fast-path FCP interrupts per second.4867 *4868 * Returns:4869 * zero if val saved.4870 * -EINVAL val out of range4871 **/4872static int4873lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)4874{4875	if (phba->sli_rev != LPFC_SLI_REV4) {4876		phba->cfg_fcp_imax = 0;4877		return 0;4878	}4879 4880	if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||4881	    (val == 0)) {4882		phba->cfg_fcp_imax = val;4883		return 0;4884	}4885 4886	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,4887			"3016 lpfc_fcp_imax: %d out of range, using default\n",4888			val);4889	phba->cfg_fcp_imax = LPFC_DEF_IMAX;4890 4891	return 0;4892}4893 4894static DEVICE_ATTR_RW(lpfc_fcp_imax);4895 4896/**4897 * lpfc_cq_max_proc_limit_store4898 *4899 * @dev: class device that is converted into a Scsi_host.4900 * @attr: device attribute, not used.4901 * @buf: string with the cq max processing limit of cqes4902 * @count: unused variable.4903 *4904 * Description:4905 * If val is in a valid range, then set value on each cq4906 *4907 * Returns:4908 * The length of the buf: if successful4909 * -ERANGE: if val is not in the valid range4910 * -EINVAL: if bad value format or intended mode is not supported.4911 **/4912static ssize_t4913lpfc_cq_max_proc_limit_store(struct device *dev, struct device_attribute *attr,4914			 const char *buf, size_t count)4915{4916	struct Scsi_Host *shost = class_to_shost(dev);4917	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;4918	struct lpfc_hba *phba = vport->phba;4919	struct lpfc_queue *eq, *cq;4920	unsigned long val;4921	int i;4922 4923	/* cq_max_proc_limit is only valid for SLI4 */4924	if (phba->sli_rev != LPFC_SLI_REV4)4925		return -EINVAL;4926 4927	/* Sanity check on user data */4928	if (!isdigit(buf[0]))4929		return -EINVAL;4930	if (kstrtoul(buf, 0, &val))4931		return -EINVAL;4932 4933	if (val < LPFC_CQ_MIN_PROC_LIMIT || val > LPFC_CQ_MAX_PROC_LIMIT)4934		return -ERANGE;4935 4936	phba->cfg_cq_max_proc_limit = (uint32_t)val;4937 4938	/* set the values on the cq's */4939	for (i = 0; i < phba->cfg_irq_chann; i++) {4940		/* Get the EQ corresponding to the IRQ vector */4941		eq = phba->sli4_hba.hba_eq_hdl[i].eq;4942		if (!eq)4943			continue;4944 4945		list_for_each_entry(cq, &eq->child_list, list)4946			cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,4947						 cq->entry_count);4948	}4949 4950	return strlen(buf);4951}4952 4953/*4954 * lpfc_cq_max_proc_limit: The maximum number CQE entries processed in an4955 *   itteration of CQ processing.4956 */4957static int lpfc_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;4958module_param(lpfc_cq_max_proc_limit, int, 0644);4959MODULE_PARM_DESC(lpfc_cq_max_proc_limit,4960	    "Set the maximum number CQEs processed in an iteration of "4961	    "CQ processing");4962lpfc_param_show(cq_max_proc_limit)4963 4964/*4965 * lpfc_cq_poll_threshold: Set the threshold of CQE completions in a4966 *   single handler call which should request a polled completion rather4967 *   than re-enabling interrupts.4968 */4969LPFC_ATTR_RW(cq_poll_threshold, LPFC_CQ_DEF_THRESHOLD_TO_POLL,4970	     LPFC_CQ_MIN_THRESHOLD_TO_POLL,4971	     LPFC_CQ_MAX_THRESHOLD_TO_POLL,4972	     "CQE Processing Threshold to enable Polling");4973 4974/**4975 * lpfc_cq_max_proc_limit_init - Set the initial cq max_proc_limit4976 * @phba: lpfc_hba pointer.4977 * @val: entry limit4978 *4979 * Description:4980 * If val is in a valid range, then initialize the adapter's maximum4981 * value.4982 *4983 * Returns:4984 *  Always returns 0 for success, even if value not always set to4985 *  requested value. If value out of range or not supported, will fall4986 *  back to default.4987 **/4988static int4989lpfc_cq_max_proc_limit_init(struct lpfc_hba *phba, int val)4990{4991	phba->cfg_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;4992 4993	if (phba->sli_rev != LPFC_SLI_REV4)4994		return 0;4995 4996	if (val >= LPFC_CQ_MIN_PROC_LIMIT && val <= LPFC_CQ_MAX_PROC_LIMIT) {4997		phba->cfg_cq_max_proc_limit = val;4998		return 0;4999	}5000 5001	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,5002			"0371 lpfc_cq_max_proc_limit: %d out of range, using "5003			"default\n",5004			phba->cfg_cq_max_proc_limit);5005 5006	return 0;5007}5008 5009static DEVICE_ATTR_RW(lpfc_cq_max_proc_limit);5010 5011/**5012 * lpfc_fcp_cpu_map_show - Display current driver CPU affinity5013 * @dev: class converted to a Scsi_host structure.5014 * @attr: device attribute, not used.5015 * @buf: on return contains text describing the state of the link.5016 *5017 * Returns: size of formatted string.5018 **/5019static ssize_t5020lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,5021		      char *buf)5022{5023	struct Scsi_Host  *shost = class_to_shost(dev);5024	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;5025	struct lpfc_hba   *phba = vport->phba;5026	struct lpfc_vector_map_info *cpup;5027	int  len = 0;5028 5029	if ((phba->sli_rev != LPFC_SLI_REV4) ||5030	    (phba->intr_type != MSIX))5031		return len;5032 5033	switch (phba->cfg_fcp_cpu_map) {5034	case 0:5035		len += scnprintf(buf + len, PAGE_SIZE-len,5036				"fcp_cpu_map: No mapping (%d)\n",5037				phba->cfg_fcp_cpu_map);5038		return len;5039	case 1:5040		len += scnprintf(buf + len, PAGE_SIZE-len,5041				"fcp_cpu_map: HBA centric mapping (%d): "5042				"%d of %d CPUs online from %d possible CPUs\n",5043				phba->cfg_fcp_cpu_map, num_online_cpus(),5044				num_present_cpus(),5045				phba->sli4_hba.num_possible_cpu);5046		break;5047	}5048 5049	while (phba->sli4_hba.curr_disp_cpu <5050	       phba->sli4_hba.num_possible_cpu) {5051		cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];5052 5053		if (!cpu_present(phba->sli4_hba.curr_disp_cpu))5054			len += scnprintf(buf + len, PAGE_SIZE - len,5055					"CPU %02d not present\n",5056					phba->sli4_hba.curr_disp_cpu);5057		else if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {5058			if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)5059				len += scnprintf(5060					buf + len, PAGE_SIZE - len,5061					"CPU %02d hdwq None "5062					"physid %d coreid %d ht %d ua %d\n",5063					phba->sli4_hba.curr_disp_cpu,5064					cpup->phys_id, cpup->core_id,5065					(cpup->flag & LPFC_CPU_MAP_HYPER),5066					(cpup->flag & LPFC_CPU_MAP_UNASSIGN));5067			else5068				len += scnprintf(5069					buf + len, PAGE_SIZE - len,5070					"CPU %02d EQ None hdwq %04d "5071					"physid %d coreid %d ht %d ua %d\n",5072					phba->sli4_hba.curr_disp_cpu,5073					cpup->hdwq, cpup->phys_id,5074					cpup->core_id,5075					(cpup->flag & LPFC_CPU_MAP_HYPER),5076					(cpup->flag & LPFC_CPU_MAP_UNASSIGN));5077		} else {5078			if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)5079				len += scnprintf(5080					buf + len, PAGE_SIZE - len,5081					"CPU %02d hdwq None "5082					"physid %d coreid %d ht %d ua %d IRQ %d\n",5083					phba->sli4_hba.curr_disp_cpu,5084					cpup->phys_id,5085					cpup->core_id,5086					(cpup->flag & LPFC_CPU_MAP_HYPER),5087					(cpup->flag & LPFC_CPU_MAP_UNASSIGN),5088					lpfc_get_irq(cpup->eq));5089			else5090				len += scnprintf(5091					buf + len, PAGE_SIZE - len,5092					"CPU %02d EQ %04d hdwq %04d "5093					"physid %d coreid %d ht %d ua %d IRQ %d\n",5094					phba->sli4_hba.curr_disp_cpu,5095					cpup->eq, cpup->hdwq, cpup->phys_id,5096					cpup->core_id,5097					(cpup->flag & LPFC_CPU_MAP_HYPER),5098					(cpup->flag & LPFC_CPU_MAP_UNASSIGN),5099					lpfc_get_irq(cpup->eq));5100		}5101 5102		phba->sli4_hba.curr_disp_cpu++;5103 5104		/* display max number of CPUs keeping some margin */5105		if (phba->sli4_hba.curr_disp_cpu <5106				phba->sli4_hba.num_possible_cpu &&5107				(len >= (PAGE_SIZE - 64))) {5108			len += scnprintf(buf + len,5109					PAGE_SIZE - len, "more...\n");5110			break;5111		}5112	}5113 5114	if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_possible_cpu)5115		phba->sli4_hba.curr_disp_cpu = 0;5116 5117	return len;5118}5119 5120/**5121 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors5122 * @dev: class device that is converted into a Scsi_host.5123 * @attr: device attribute, not used.5124 * @buf: one or more lpfc_polling_flags values.5125 * @count: not used.5126 *5127 * Returns:5128 * -EINVAL  - Not implemented yet.5129 **/5130static ssize_t5131lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,5132		       const char *buf, size_t count)5133{5134	return -EINVAL;5135}5136 5137/*5138# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors5139# for the HBA.5140#5141# Value range is [0 to 1]. Default value is LPFC_HBA_CPU_MAP (1).5142#	0 - Do not affinitze IRQ vectors5143#	1 - Affintize HBA vectors with respect to each HBA5144#	    (start with CPU0 for each HBA)5145# This also defines how Hardware Queues are mapped to specific CPUs.5146*/5147static int lpfc_fcp_cpu_map = LPFC_HBA_CPU_MAP;5148module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);5149MODULE_PARM_DESC(lpfc_fcp_cpu_map,5150		 "Defines how to map CPUs to IRQ vectors per HBA");5151 5152/**5153 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable5154 * @phba: lpfc_hba pointer.5155 * @val: link speed value.5156 *5157 * Description:5158 * If val is in a valid range [0-2], then affinitze the adapter's5159 * MSIX vectors.5160 *5161 * Returns:5162 * zero if val saved.5163 * -EINVAL val out of range5164 **/5165static int5166lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)5167{5168	if (phba->sli_rev != LPFC_SLI_REV4) {5169		phba->cfg_fcp_cpu_map = 0;5170		return 0;5171	}5172 5173	if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {5174		phba->cfg_fcp_cpu_map = val;5175		return 0;5176	}5177 5178	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,5179			"3326 lpfc_fcp_cpu_map: %d out of range, using "5180			"default\n", val);5181	phba->cfg_fcp_cpu_map = LPFC_HBA_CPU_MAP;5182 5183	return 0;5184}5185 5186static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);5187 5188/*5189# lpfc_fcp_class:  Determines FC class to use for the FCP protocol.5190# Value range is [2,3]. Default value is 3.5191*/5192LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,5193		  "Select Fibre Channel class of service for FCP sequences");5194 5195/*5196# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range5197# is [0,1]. Default value is 1.5198*/5199LPFC_VPORT_ATTR_RW(use_adisc, 1, 0, 1,5200		   "Use ADISC on rediscovery to authenticate FCP devices");5201 5202/*5203# lpfc_first_burst_size: First burst size to use on the NPorts5204# that support first burst.5205# Value range is [0,65536]. Default value is 0.5206*/5207LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,5208		   "First burst size for Targets that support first burst");5209 5210/*5211* lpfc_nvmet_fb_size: NVME Target mode supported first burst size.5212* When the driver is configured as an NVME target, this value is5213* communicated to the NVME initiator in the PRLI response.  It is5214* used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support5215* parameters are set and the target is sending the PRLI RSP.5216* Parameter supported on physical port only - no NPIV support.5217* Value range is [0,65536]. Default value is 0.5218*/5219LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,5220	     "NVME Target mode first burst size in 512B increments.");5221 5222/*5223 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.5224 * For the Initiator (I), enabling this parameter means that an NVMET5225 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be5226 * processed by the initiator for subsequent NVME FCP IO.5227 * Currently, this feature is not supported on the NVME target5228 * Value range is [0,1]. Default value is 0 (disabled).5229 */5230LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,5231	     "Enable First Burst feature for NVME Initiator.");5232 5233/*5234# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue5235# depth. Default value is 0. When the value of this parameter is zero the5236# SCSI command completion time is not used for controlling I/O queue depth. When5237# the parameter is set to a non-zero value, the I/O queue depth is controlled5238# to limit the I/O completion time to the parameter value.5239# The value is set in milliseconds.5240*/5241LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,5242	"Use command completion time to control queue depth");5243 5244lpfc_vport_param_show(max_scsicmpl_time);5245static int5246lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)5247{5248	struct lpfc_nodelist *ndlp, *next_ndlp;5249	unsigned long iflags;5250 5251	if (val == vport->cfg_max_scsicmpl_time)5252		return 0;5253	if ((val < 0) || (val > 60000))5254		return -EINVAL;5255	vport->cfg_max_scsicmpl_time = val;5256 5257	spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);5258	list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {5259		if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)5260			continue;5261		ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;5262	}5263	spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);5264	return 0;5265}5266lpfc_vport_param_store(max_scsicmpl_time);5267static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);5268 5269/*5270# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value5271# range is [0,1]. Default value is 0.5272*/5273LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");5274 5275/*5276# lpfc_xri_rebalancing: enable or disable XRI rebalancing feature5277# range is [0,1]. Default value is 1.5278*/5279LPFC_ATTR_R(xri_rebalancing, 1, 0, 1, "Enable/Disable XRI rebalancing");5280 5281/*5282 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds5283 * range is [0,1]. Default value is 0.5284 * For [0], FCP commands are issued to Work Queues based on upper layer5285 * hardware queue index.5286 * For [1], FCP commands are issued to a Work Queue associated with the5287 *          current CPU.5288 *5289 * LPFC_FCP_SCHED_BY_HDWQ == 05290 * LPFC_FCP_SCHED_BY_CPU == 15291 *5292 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu5293 * affinity for FCP/NVME I/Os through Work Queues associated with the current5294 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os5295 * through WQs will be used.5296 */5297LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_BY_CPU,5298	     LPFC_FCP_SCHED_BY_HDWQ,5299	     LPFC_FCP_SCHED_BY_CPU,5300	     "Determine scheduling algorithm for "5301	     "issuing commands [0] - Hardware Queue, [1] - Current CPU");5302 5303/*5304 * lpfc_ns_query: Determine algrithmn for NameServer queries after RSCN5305 * range is [0,1]. Default value is 0.5306 * For [0], GID_FT is used for NameServer queries after RSCN (default)5307 * For [1], GID_PT is used for NameServer queries after RSCN5308 *5309 */5310LPFC_ATTR_RW(ns_query, LPFC_NS_QUERY_GID_FT,5311	     LPFC_NS_QUERY_GID_FT, LPFC_NS_QUERY_GID_PT,5312	     "Determine algorithm NameServer queries after RSCN "5313	     "[0] - GID_FT, [1] - GID_PT");5314 5315/*5316# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior5317# range is [0,1]. Default value is 0.5318# For [0], bus reset issues target reset to ALL devices5319# For [1], bus reset issues target reset to non-FCP2 devices5320*/5321LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "5322	     "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");5323 5324 5325/*5326# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing5327# cr_delay (msec) or cr_count outstanding commands. cr_delay can take5328# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay5329# is 0. Default value of cr_count is 1. The cr_count feature is disabled if5330# cr_delay is set to 0.5331*/5332LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "5333		"interrupt response is generated");5334 5335LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "5336		"interrupt response is generated");5337 5338/*5339# lpfc_multi_ring_support:  Determines how many rings to spread available5340# cmd/rsp IOCB entries across.5341# Value range is [1,2]. Default value is 1.5342*/5343LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "5344		"SLI rings to spread IOCB entries across");5345 5346/*5347# lpfc_multi_ring_rctl:  If lpfc_multi_ring_support is enabled, this5348# identifies what rctl value to configure the additional ring for.5349# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).5350*/5351LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,5352	     255, "Identifies RCTL for additional ring configuration");5353 5354/*5355# lpfc_multi_ring_type:  If lpfc_multi_ring_support is enabled, this5356# identifies what type value to configure the additional ring for.5357# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).5358*/5359LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,5360	     255, "Identifies TYPE for additional ring configuration");5361 5362/*5363# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN5364#       0  = SmartSAN functionality disabled (default)5365#       1  = SmartSAN functionality enabled5366# This parameter will override the value of lpfc_fdmi_on module parameter.5367# Value range is [0,1]. Default value is 0.5368*/5369LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");5370 5371/*5372# lpfc_fdmi_on: Controls FDMI support.5373#       0       No FDMI support5374#       1       Traditional FDMI support (default)5375# Traditional FDMI support means the driver will assume FDMI-2 support;5376# however, if that fails, it will fallback to FDMI-1.5377# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.5378# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of5379# lpfc_fdmi_on.5380# Value range [0,1]. Default value is 1.5381*/5382LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");5383 5384/*5385# Specifies the maximum number of ELS cmds we can have outstanding (for5386# discovery). Value range is [1,64]. Default value = 32.5387*/5388LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "5389		 "during discovery");5390 5391/*5392# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that5393#    will be scanned by the SCSI midlayer when sequential scanning is5394#    used; and is also the highest LUN ID allowed when the SCSI midlayer5395#    parses REPORT_LUN responses. The lpfc driver has no LUN count or5396#    LUN ID limit, but the SCSI midlayer requires this field for the uses5397#    above. The lpfc driver limits the default value to 255 for two reasons.5398#    As it bounds the sequential scan loop, scanning for thousands of luns5399#    on a target can take minutes of wall clock time.  Additionally,5400#    there are FC targets, such as JBODs, that only recognize 8-bits of5401#    LUN ID. When they receive a value greater than 8 bits, they chop off5402#    the high order bits. In other words, they see LUN IDs 0, 256, 512,5403#    and so on all as LUN ID 0. This causes the linux kernel, which sees5404#    valid responses at each of the LUN IDs, to believe there are multiple5405#    devices present, when in fact, there is only 1.5406#    A customer that is aware of their target behaviors, and the results as5407#    indicated above, is welcome to increase the lpfc_max_luns value.5408#    As mentioned, this value is not used by the lpfc driver, only the5409#    SCSI midlayer.5410# Value range is [0,65535]. Default value is 255.5411# NOTE: The SCSI layer might probe all allowed LUN on some old targets.5412*/5413LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");5414 5415/*5416# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.5417# Value range is [1,255], default value is 10.5418*/5419LPFC_ATTR_RW(poll_tmo, 10, 1, 255,5420	     "Milliseconds driver will wait between polling FCP ring");5421 5422/*5423# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands5424# to complete in seconds. Value range is [5,180], default value is 60.5425*/5426LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,5427	     "Maximum time to wait for task management commands to complete");5428/*5429# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that5430#		support this feature5431#       0  = MSI disabled5432#       1  = MSI enabled5433#       2  = MSI-X enabled (default)5434# Value range is [0,2]. Default value is 2.5435*/5436LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "5437	    "MSI-X (2), if possible");5438 5439/*5440 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs5441 *5442 *      0  = NVME OAS disabled5443 *      1  = NVME OAS enabled5444 *5445 * Value range is [0,1]. Default value is 0.5446 */5447LPFC_ATTR_RW(nvme_oas, 0, 0, 1,5448	     "Use OAS bit on NVME IOs");5449 5450/*5451 * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs5452 *5453 *      0  = Put NVME Command in SGL5454 *      1  = Embed NVME Command in WQE (unless G7)5455 *      2 =  Embed NVME Command in WQE (force)5456 *5457 * Value range is [0,2]. Default value is 1.5458 */5459LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,5460	     "Embed NVME Command in WQE");5461 5462/*5463 * lpfc_fcp_mq_threshold: Set the maximum number of Hardware Queues5464 * the driver will advertise it supports to the SCSI layer.5465 *5466 *      0    = Set nr_hw_queues by the number of CPUs or HW queues.5467 *      1,256 = Manually specify nr_hw_queue value to be advertised,5468 *5469 * Value range is [0,256]. Default value is 8.5470 */5471LPFC_ATTR_R(fcp_mq_threshold, LPFC_FCP_MQ_THRESHOLD_DEF,5472	    LPFC_FCP_MQ_THRESHOLD_MIN, LPFC_FCP_MQ_THRESHOLD_MAX,5473	    "Set the number of SCSI Queues advertised");5474 5475/*5476 * lpfc_hdw_queue: Set the number of Hardware Queues the driver5477 * will advertise it supports to the NVME and  SCSI layers. This also5478 * will map to the number of CQ/WQ pairs the driver will create.5479 *5480 * The NVME Layer will try to create this many, plus 1 administrative5481 * hardware queue. The administrative queue will always map to WQ 05482 * A hardware IO queue maps (qidx) to a specific driver CQ/WQ.5483 *5484 *      0    = Configure the number of hdw queues to the number of active CPUs.5485 *      1,256 = Manually specify how many hdw queues to use.5486 *5487 * Value range is [0,256]. Default value is 0.5488 */5489LPFC_ATTR_R(hdw_queue,5490	    LPFC_HBA_HDWQ_DEF,5491	    LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,5492	    "Set the number of I/O Hardware Queues");5493 5494#if IS_ENABLED(CONFIG_X86)5495/**5496 * lpfc_cpumask_irq_mode_init - initalizes cpumask of phba based on5497 *				irq_chann_mode5498 * @phba: Pointer to HBA context object.5499 **/5500static void5501lpfc_cpumask_irq_mode_init(struct lpfc_hba *phba)5502{5503	unsigned int cpu, first_cpu, numa_node = NUMA_NO_NODE;5504	const struct cpumask *sibling_mask;5505	struct cpumask *aff_mask = &phba->sli4_hba.irq_aff_mask;5506 5507	cpumask_clear(aff_mask);5508 5509	if (phba->irq_chann_mode == NUMA_MODE) {5510		/* Check if we're a NUMA architecture */5511		numa_node = dev_to_node(&phba->pcidev->dev);5512		if (numa_node == NUMA_NO_NODE) {5513			phba->irq_chann_mode = NORMAL_MODE;5514			return;5515		}5516	}5517 5518	for_each_possible_cpu(cpu) {5519		switch (phba->irq_chann_mode) {5520		case NUMA_MODE:5521			if (cpu_to_node(cpu) == numa_node)5522				cpumask_set_cpu(cpu, aff_mask);5523			break;5524		case NHT_MODE:5525			sibling_mask = topology_sibling_cpumask(cpu);5526			first_cpu = cpumask_first(sibling_mask);5527			if (first_cpu < nr_cpu_ids)5528				cpumask_set_cpu(first_cpu, aff_mask);5529			break;5530		default:5531			break;5532		}5533	}5534}5535#endif5536 5537static void5538lpfc_assign_default_irq_chann(struct lpfc_hba *phba)5539{5540#if IS_ENABLED(CONFIG_X86)5541	switch (boot_cpu_data.x86_vendor) {5542	case X86_VENDOR_AMD:5543		/* If AMD architecture, then default is NUMA_MODE */5544		phba->irq_chann_mode = NUMA_MODE;5545		break;5546	case X86_VENDOR_INTEL:5547		/* If Intel architecture, then default is no hyperthread mode */5548		phba->irq_chann_mode = NHT_MODE;5549		break;5550	default:5551		phba->irq_chann_mode = NORMAL_MODE;5552		break;5553	}5554	lpfc_cpumask_irq_mode_init(phba);5555#else5556	phba->irq_chann_mode = NORMAL_MODE;5557#endif5558}5559 5560/*5561 * lpfc_irq_chann: Set the number of IRQ vectors that are available5562 * for Hardware Queues to utilize.  This also will map to the number5563 * of EQ / MSI-X vectors the driver will create. This should never be5564 * more than the number of Hardware Queues5565 *5566 *	0		= Configure number of IRQ Channels to:5567 *			  if AMD architecture, number of CPUs on HBA's NUMA node5568 *			  if Intel architecture, number of physical CPUs.5569 *			  otherwise, number of active CPUs.5570 *	[1,256]		= Manually specify how many IRQ Channels to use.5571 *5572 * Value range is [0,256]. Default value is [0].5573 */5574static uint lpfc_irq_chann = LPFC_IRQ_CHANN_DEF;5575module_param(lpfc_irq_chann, uint, 0444);5576MODULE_PARM_DESC(lpfc_irq_chann, "Set number of interrupt vectors to allocate");5577 5578/* lpfc_irq_chann_init - Set the hba irq_chann initial value5579 * @phba: lpfc_hba pointer.5580 * @val: contains the initial value5581 *5582 * Description:5583 * Validates the initial value is within range and assigns it to the5584 * adapter. If not in range, an error message is posted and the5585 * default value is assigned.5586 *5587 * Returns:5588 * zero if value is in range and is set5589 * -EINVAL if value was out of range5590 **/5591static int5592lpfc_irq_chann_init(struct lpfc_hba *phba, uint32_t val)5593{5594	const struct cpumask *aff_mask;5595 5596	if (phba->cfg_use_msi != 2) {5597		lpfc_printf_log(phba, KERN_INFO, LOG_INIT,5598				"8532 use_msi = %u ignoring cfg_irq_numa\n",5599				phba->cfg_use_msi);5600		phba->irq_chann_mode = NORMAL_MODE;5601		phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;5602		return 0;5603	}5604 5605	/* Check if default setting was passed */5606	if (val == LPFC_IRQ_CHANN_DEF &&5607	    phba->cfg_hdw_queue == LPFC_HBA_HDWQ_DEF &&5608	    phba->sli_rev == LPFC_SLI_REV4)5609		lpfc_assign_default_irq_chann(phba);5610 5611	if (phba->irq_chann_mode != NORMAL_MODE) {5612		aff_mask = &phba->sli4_hba.irq_aff_mask;5613 5614		if (cpumask_empty(aff_mask)) {5615			lpfc_printf_log(phba, KERN_INFO, LOG_INIT,5616					"8533 Could not identify CPUS for "5617					"mode %d, ignoring\n",5618					phba->irq_chann_mode);5619			phba->irq_chann_mode = NORMAL_MODE;5620			phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;5621		} else {5622			phba->cfg_irq_chann = cpumask_weight(aff_mask);5623 5624			/* If no hyperthread mode, then set hdwq count to5625			 * aff_mask weight as well5626			 */5627			if (phba->irq_chann_mode == NHT_MODE)5628				phba->cfg_hdw_queue = phba->cfg_irq_chann;5629 5630			lpfc_printf_log(phba, KERN_INFO, LOG_INIT,5631					"8543 lpfc_irq_chann set to %u "5632					"(mode: %d)\n", phba->cfg_irq_chann,5633					phba->irq_chann_mode);5634		}5635	} else {5636		if (val > LPFC_IRQ_CHANN_MAX) {5637			lpfc_printf_log(phba, KERN_INFO, LOG_INIT,5638					"8545 lpfc_irq_chann attribute cannot "5639					"be set to %u, allowed range is "5640					"[%u,%u]\n",5641					val,5642					LPFC_IRQ_CHANN_MIN,5643					LPFC_IRQ_CHANN_MAX);5644			phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;5645			return -EINVAL;5646		}5647		if (phba->sli_rev == LPFC_SLI_REV4) {5648			phba->cfg_irq_chann = val;5649		} else {5650			phba->cfg_irq_chann = 2;5651			phba->cfg_hdw_queue = 1;5652		}5653	}5654 5655	return 0;5656}5657 5658/**5659 * lpfc_irq_chann_show - Display value of irq_chann5660 * @dev: class converted to a Scsi_host structure.5661 * @attr: device attribute, not used.5662 * @buf: on return contains a string with the list sizes5663 *5664 * Returns: size of formatted string.5665 **/5666static ssize_t5667lpfc_irq_chann_show(struct device *dev, struct device_attribute *attr,5668		    char *buf)5669{5670	struct Scsi_Host *shost = class_to_shost(dev);5671	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;5672	struct lpfc_hba *phba = vport->phba;5673 5674	return scnprintf(buf, PAGE_SIZE, "%u\n", phba->cfg_irq_chann);5675}5676 5677static DEVICE_ATTR_RO(lpfc_irq_chann);5678 5679/*5680# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.5681#       0  = HBA resets disabled5682#       1  = HBA resets enabled (default)5683#       2  = HBA reset via PCI bus reset enabled5684# Value range is [0,2]. Default value is 1.5685*/5686LPFC_ATTR_RW(enable_hba_reset, 1, 0, 2, "Enable HBA resets from the driver.");5687 5688/*5689# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..5690#       0  = HBA Heartbeat disabled5691#       1  = HBA Heartbeat enabled (default)5692# Value range is [0,1]. Default value is 1.5693*/5694LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");5695 5696/*5697# lpfc_EnableXLane: Enable Express Lane Feature5698#      0x0   Express Lane Feature disabled5699#      0x1   Express Lane Feature enabled5700# Value range is [0,1]. Default value is 0.5701*/5702LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");5703 5704/*5705# lpfc_XLanePriority:  Define CS_CTL priority for Express Lane Feature5706#       0x0 - 0x7f  = CS_CTL field in FC header (high 7 bits)5707# Value range is [0x0,0x7f]. Default value is 05708*/5709LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");5710 5711/*5712# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)5713#       0  = BlockGuard disabled (default)5714#       1  = BlockGuard enabled5715# Value range is [0,1]. Default value is 0.5716*/5717LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");5718 5719/*5720# lpfc_prot_mask:5721#	- Bit mask of host protection capabilities used to register with the5722#	  SCSI mid-layer5723# 	- Only meaningful if BG is turned on (lpfc_enable_bg=1).5724#	- Allows you to ultimately specify which profiles to use5725#	- Default will result in registering capabilities for all profiles.5726#	- SHOST_DIF_TYPE1_PROTECTION	15727#		HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection5728#	- SHOST_DIX_TYPE0_PROTECTION	85729#		HBA supports DIX Type 0: Host to HBA protection only5730#	- SHOST_DIX_TYPE1_PROTECTION	165731#		HBA supports DIX Type 1: Host to HBA  Type 1 protection5732#5733*/5734LPFC_ATTR(prot_mask,5735	(SHOST_DIF_TYPE1_PROTECTION |5736	SHOST_DIX_TYPE0_PROTECTION |5737	SHOST_DIX_TYPE1_PROTECTION),5738	0,5739	(SHOST_DIF_TYPE1_PROTECTION |5740	SHOST_DIX_TYPE0_PROTECTION |5741	SHOST_DIX_TYPE1_PROTECTION),5742	"T10-DIF host protection capabilities mask");5743 5744/*5745# lpfc_prot_guard:5746#	- Bit mask of protection guard types to register with the SCSI mid-layer5747#	- Guard types are currently either 1) T10-DIF CRC 2) IP checksum5748#	- Allows you to ultimately specify which profiles to use5749#	- Default will result in registering capabilities for all guard types5750#5751*/5752LPFC_ATTR(prot_guard,5753	SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,5754	"T10-DIF host protection guard type");5755 5756/*5757 * Delay initial NPort discovery when Clean Address bit is cleared in5758 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.5759 * This parameter can have value 0 or 1.5760 * When this parameter is set to 0, no delay is added to the initial5761 * discovery.5762 * When this parameter is set to non-zero value, initial Nport discovery is5763 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC5764 * accept and FCID/Fabric name/Fabric portname is changed.5765 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion5766 * when Clean Address bit is cleared in FLOGI/FDISC5767 * accept and FCID/Fabric name/Fabric portname is changed.5768 * Default value is 0.5769 */5770LPFC_ATTR(delay_discovery, 0, 0, 1,5771	"Delay NPort discovery when Clean Address bit is cleared.");5772 5773/*5774 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count5775 * This value can be set to values between 64 and 4096. The default value5776 * is 64, but may be increased to allow for larger Max I/O sizes. The scsi5777 * and nvme layers will allow I/O sizes up to (MAX_SEG_COUNT * SEG_SIZE).5778 * Because of the additional overhead involved in setting up T10-DIF,5779 * this parameter will be limited to 128 if BlockGuard is enabled under SLI45780 * and will be limited to 512 if BlockGuard is enabled under SLI3.5781 */5782static uint lpfc_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;5783module_param(lpfc_sg_seg_cnt, uint, 0444);5784MODULE_PARM_DESC(lpfc_sg_seg_cnt, "Max Scatter Gather Segment Count");5785 5786/**5787 * lpfc_sg_seg_cnt_show - Display the scatter/gather list sizes5788 *    configured for the adapter5789 * @dev: class converted to a Scsi_host structure.5790 * @attr: device attribute, not used.5791 * @buf: on return contains a string with the list sizes5792 *5793 * Returns: size of formatted string.5794 **/5795static ssize_t5796lpfc_sg_seg_cnt_show(struct device *dev, struct device_attribute *attr,5797		     char *buf)5798{5799	struct Scsi_Host  *shost = class_to_shost(dev);5800	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;5801	struct lpfc_hba   *phba = vport->phba;5802	int len;5803 5804	len = scnprintf(buf, PAGE_SIZE, "SGL sz: %d  total SGEs: %d\n",5805		       phba->cfg_sg_dma_buf_size, phba->cfg_total_seg_cnt);5806 5807	len += scnprintf(buf + len, PAGE_SIZE - len,5808			"Cfg: %d  SCSI: %d  NVME: %d\n",5809			phba->cfg_sg_seg_cnt, phba->cfg_scsi_seg_cnt,5810			phba->cfg_nvme_seg_cnt);5811	return len;5812}5813 5814static DEVICE_ATTR_RO(lpfc_sg_seg_cnt);5815 5816/**5817 * lpfc_sg_seg_cnt_init - Set the hba sg_seg_cnt initial value5818 * @phba: lpfc_hba pointer.5819 * @val: contains the initial value5820 *5821 * Description:5822 * Validates the initial value is within range and assigns it to the5823 * adapter. If not in range, an error message is posted and the5824 * default value is assigned.5825 *5826 * Returns:5827 * zero if value is in range and is set5828 * -EINVAL if value was out of range5829 **/5830static int5831lpfc_sg_seg_cnt_init(struct lpfc_hba *phba, int val)5832{5833	if (val >= LPFC_MIN_SG_SEG_CNT && val <= LPFC_MAX_SG_SEG_CNT) {5834		phba->cfg_sg_seg_cnt = val;5835		return 0;5836	}5837	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,5838			"0409 lpfc_sg_seg_cnt attribute cannot be set to %d, "5839			"allowed range is [%d, %d]\n",5840			val, LPFC_MIN_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT);5841	phba->cfg_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;5842	return -EINVAL;5843}5844 5845/*5846 * lpfc_enable_mds_diags: Enable MDS Diagnostics5847 *       0  = MDS Diagnostics disabled (default)5848 *       1  = MDS Diagnostics enabled5849 * Value range is [0,1]. Default value is 0.5850 */5851LPFC_ATTR_RW(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");5852 5853/*5854 * lpfc_ras_fwlog_buffsize: Firmware logging host buffer size5855 *	0 = Disable firmware logging (default)5856 *	[1-4] = Multiple of 1/4th Mb of host memory for FW logging5857 * Value range [0..4]. Default value is 05858 */5859LPFC_ATTR(ras_fwlog_buffsize, 0, 0, 4, "Host memory for FW logging");5860lpfc_param_show(ras_fwlog_buffsize);5861 5862static ssize_t5863lpfc_ras_fwlog_buffsize_set(struct lpfc_hba  *phba, uint val)5864{5865	int ret = 0;5866	enum ras_state state;5867 5868	if (!lpfc_rangecheck(val, 0, 4))5869		return -EINVAL;5870 5871	if (phba->cfg_ras_fwlog_buffsize == val)5872		return 0;5873 5874	if (phba->cfg_ras_fwlog_func != PCI_FUNC(phba->pcidev->devfn))5875		return -EINVAL;5876 5877	spin_lock_irq(&phba->ras_fwlog_lock);5878	state = phba->ras_fwlog.state;5879	spin_unlock_irq(&phba->ras_fwlog_lock);5880 5881	if (state == REG_INPROGRESS) {5882		lpfc_printf_log(phba, KERN_ERR, LOG_SLI, "6147 RAS Logging "5883				"registration is in progress\n");5884		return -EBUSY;5885	}5886 5887	/* For disable logging: stop the logs and free the DMA.5888	 * For ras_fwlog_buffsize size change we still need to free and5889	 * reallocate the DMA in lpfc_sli4_ras_fwlog_init.5890	 */5891	phba->cfg_ras_fwlog_buffsize = val;5892	if (state == ACTIVE) {5893		lpfc_ras_stop_fwlog(phba);5894		lpfc_sli4_ras_dma_free(phba);5895	}5896 5897	lpfc_sli4_ras_init(phba);5898	if (phba->ras_fwlog.ras_enabled)5899		ret = lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,5900					       LPFC_RAS_ENABLE_LOGGING);5901	return ret;5902}5903 5904lpfc_param_store(ras_fwlog_buffsize);5905static DEVICE_ATTR_RW(lpfc_ras_fwlog_buffsize);5906 5907/*5908 * lpfc_ras_fwlog_level: Firmware logging verbosity level5909 * Valid only if firmware logging is enabled5910 * 0(Least Verbosity) 4 (most verbosity)5911 * Value range is [0..4]. Default value is 05912 */5913LPFC_ATTR_RW(ras_fwlog_level, 0, 0, 4, "Firmware Logging Level");5914 5915/*5916 * lpfc_ras_fwlog_func: Firmware logging enabled on function number5917 * Default function which has RAS support : 05918 * Value Range is [0..3].5919 * FW logging is a global action and enablement is via a specific5920 * port.5921 */5922LPFC_ATTR_RW(ras_fwlog_func, 0, 0, 3, "Firmware Logging Enabled on Function");5923 5924/*5925 * lpfc_enable_bbcr: Enable BB Credit Recovery5926 *       0  = BB Credit Recovery disabled5927 *       1  = BB Credit Recovery enabled (default)5928 * Value range is [0,1]. Default value is 1.5929 */5930LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");5931 5932/* Signaling module parameters */5933int lpfc_fabric_cgn_frequency = 100; /* 100 ms default */5934module_param(lpfc_fabric_cgn_frequency, int, 0444);5935MODULE_PARM_DESC(lpfc_fabric_cgn_frequency, "Congestion signaling fabric freq");5936 5937unsigned char lpfc_acqe_cgn_frequency = 10; /* 10 sec default */5938module_param(lpfc_acqe_cgn_frequency, byte, 0444);5939MODULE_PARM_DESC(lpfc_acqe_cgn_frequency, "Congestion signaling ACQE freq");5940 5941int lpfc_use_cgn_signal = 1; /* 0 - only use FPINs, 1 - Use signals if avail  */5942module_param(lpfc_use_cgn_signal, int, 0444);5943MODULE_PARM_DESC(lpfc_use_cgn_signal, "Use Congestion signaling if available");5944 5945/*5946 * lpfc_enable_dpp: Enable DPP on G75947 *       0  = DPP on G7 disabled5948 *       1  = DPP on G7 enabled (default)5949 * Value range is [0,1]. Default value is 1.5950 */5951LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");5952 5953/*5954 * lpfc_enable_mi: Enable FDMI MIB5955 *       0  = disabled5956 *       1  = enabled (default)5957 * Value range is [0,1].5958 */5959LPFC_ATTR_R(enable_mi, 1, 0, 1, "Enable MI");5960 5961/*5962 * lpfc_max_vmid: Maximum number of VMs to be tagged. This is valid only if5963 * either vmid_app_header or vmid_priority_tagging is enabled.5964 *       4 - 255  = vmid support enabled for 4-255 VMs5965 *       Value range is [4,255].5966 */5967LPFC_ATTR_R(max_vmid, LPFC_MIN_VMID, LPFC_MIN_VMID, LPFC_MAX_VMID,5968	     "Maximum number of VMs supported");5969 5970/*5971 * lpfc_vmid_inactivity_timeout: Inactivity timeout duration in hours5972 *       0  = Timeout is disabled5973 * Value range is [0,24].5974 */5975LPFC_ATTR_R(vmid_inactivity_timeout, 4, 0, 24,5976	     "Inactivity timeout in hours");5977 5978/*5979 * lpfc_vmid_app_header: Enable App Header VMID support5980 *       0  = Support is disabled (default)5981 *       1  = Support is enabled5982 * Value range is [0,1].5983 */5984LPFC_ATTR_R(vmid_app_header, LPFC_VMID_APP_HEADER_DISABLE,5985	     LPFC_VMID_APP_HEADER_DISABLE, LPFC_VMID_APP_HEADER_ENABLE,5986	     "Enable App Header VMID support");5987 5988/*5989 * lpfc_vmid_priority_tagging: Enable Priority Tagging VMID support5990 *       0  = Support is disabled (default)5991 *       1  = Allow supported targets only5992 *       2  = Allow all targets5993 * Value range is [0,2].5994 */5995LPFC_ATTR_R(vmid_priority_tagging, LPFC_VMID_PRIO_TAG_DISABLE,5996	     LPFC_VMID_PRIO_TAG_DISABLE,5997	     LPFC_VMID_PRIO_TAG_ALL_TARGETS,5998	     "Enable Priority Tagging VMID support");5999 6000static struct attribute *lpfc_hba_attrs[] = {6001	&dev_attr_nvme_info.attr,6002	&dev_attr_scsi_stat.attr,6003	&dev_attr_bg_info.attr,6004	&dev_attr_bg_guard_err.attr,6005	&dev_attr_bg_apptag_err.attr,6006	&dev_attr_bg_reftag_err.attr,6007	&dev_attr_info.attr,6008	&dev_attr_serialnum.attr,6009	&dev_attr_modeldesc.attr,6010	&dev_attr_modelname.attr,6011	&dev_attr_programtype.attr,6012	&dev_attr_portnum.attr,6013	&dev_attr_fwrev.attr,6014	&dev_attr_hdw.attr,6015	&dev_attr_option_rom_version.attr,6016	&dev_attr_link_state.attr,6017	&dev_attr_num_discovered_ports.attr,6018	&dev_attr_lpfc_drvr_version.attr,6019	&dev_attr_lpfc_enable_fip.attr,6020	&dev_attr_lpfc_temp_sensor.attr,6021	&dev_attr_lpfc_log_verbose.attr,6022	&dev_attr_lpfc_lun_queue_depth.attr,6023	&dev_attr_lpfc_tgt_queue_depth.attr,6024	&dev_attr_lpfc_hba_queue_depth.attr,6025	&dev_attr_lpfc_peer_port_login.attr,6026	&dev_attr_lpfc_nodev_tmo.attr,6027	&dev_attr_lpfc_devloss_tmo.attr,6028	&dev_attr_lpfc_enable_fc4_type.attr,6029	&dev_attr_lpfc_fcp_class.attr,6030	&dev_attr_lpfc_use_adisc.attr,6031	&dev_attr_lpfc_first_burst_size.attr,6032	&dev_attr_lpfc_ack0.attr,6033	&dev_attr_lpfc_xri_rebalancing.attr,6034	&dev_attr_lpfc_topology.attr,6035	&dev_attr_lpfc_scan_down.attr,6036	&dev_attr_lpfc_link_speed.attr,6037	&dev_attr_lpfc_fcp_io_sched.attr,6038	&dev_attr_lpfc_ns_query.attr,6039	&dev_attr_lpfc_fcp2_no_tgt_reset.attr,6040	&dev_attr_lpfc_cr_delay.attr,6041	&dev_attr_lpfc_cr_count.attr,6042	&dev_attr_lpfc_multi_ring_support.attr,6043	&dev_attr_lpfc_multi_ring_rctl.attr,6044	&dev_attr_lpfc_multi_ring_type.attr,6045	&dev_attr_lpfc_fdmi_on.attr,6046	&dev_attr_lpfc_enable_SmartSAN.attr,6047	&dev_attr_lpfc_max_luns.attr,6048	&dev_attr_lpfc_enable_npiv.attr,6049	&dev_attr_lpfc_fcf_failover_policy.attr,6050	&dev_attr_lpfc_enable_rrq.attr,6051	&dev_attr_lpfc_fcp_wait_abts_rsp.attr,6052	&dev_attr_nport_evt_cnt.attr,6053	&dev_attr_board_mode.attr,6054	&dev_attr_lpfc_xcvr_data.attr,6055	&dev_attr_max_vpi.attr,6056	&dev_attr_used_vpi.attr,6057	&dev_attr_max_rpi.attr,6058	&dev_attr_used_rpi.attr,6059	&dev_attr_max_xri.attr,6060	&dev_attr_used_xri.attr,6061	&dev_attr_npiv_info.attr,6062	&dev_attr_issue_reset.attr,6063	&dev_attr_lpfc_poll.attr,6064	&dev_attr_lpfc_poll_tmo.attr,6065	&dev_attr_lpfc_task_mgmt_tmo.attr,6066	&dev_attr_lpfc_use_msi.attr,6067	&dev_attr_lpfc_nvme_oas.attr,6068	&dev_attr_lpfc_nvme_embed_cmd.attr,6069	&dev_attr_lpfc_fcp_imax.attr,6070	&dev_attr_lpfc_force_rscn.attr,6071	&dev_attr_lpfc_cq_poll_threshold.attr,6072	&dev_attr_lpfc_cq_max_proc_limit.attr,6073	&dev_attr_lpfc_fcp_cpu_map.attr,6074	&dev_attr_lpfc_fcp_mq_threshold.attr,6075	&dev_attr_lpfc_hdw_queue.attr,6076	&dev_attr_lpfc_irq_chann.attr,6077	&dev_attr_lpfc_suppress_rsp.attr,6078	&dev_attr_lpfc_nvmet_mrq.attr,6079	&dev_attr_lpfc_nvmet_mrq_post.attr,6080	&dev_attr_lpfc_nvme_enable_fb.attr,6081	&dev_attr_lpfc_nvmet_fb_size.attr,6082	&dev_attr_lpfc_enable_bg.attr,6083	&dev_attr_lpfc_enable_hba_reset.attr,6084	&dev_attr_lpfc_enable_hba_heartbeat.attr,6085	&dev_attr_lpfc_EnableXLane.attr,6086	&dev_attr_lpfc_XLanePriority.attr,6087	&dev_attr_lpfc_xlane_lun.attr,6088	&dev_attr_lpfc_xlane_tgt.attr,6089	&dev_attr_lpfc_xlane_vpt.attr,6090	&dev_attr_lpfc_xlane_lun_state.attr,6091	&dev_attr_lpfc_xlane_lun_status.attr,6092	&dev_attr_lpfc_xlane_priority.attr,6093	&dev_attr_lpfc_sg_seg_cnt.attr,6094	&dev_attr_lpfc_max_scsicmpl_time.attr,6095	&dev_attr_lpfc_aer_support.attr,6096	&dev_attr_lpfc_aer_state_cleanup.attr,6097	&dev_attr_lpfc_sriov_nr_virtfn.attr,6098	&dev_attr_lpfc_req_fw_upgrade.attr,6099	&dev_attr_lpfc_suppress_link_up.attr,6100	&dev_attr_iocb_hw.attr,6101	&dev_attr_pls.attr,6102	&dev_attr_pt.attr,6103	&dev_attr_txq_hw.attr,6104	&dev_attr_txcmplq_hw.attr,6105	&dev_attr_lpfc_sriov_hw_max_virtfn.attr,6106	&dev_attr_protocol.attr,6107	&dev_attr_lpfc_xlane_supported.attr,6108	&dev_attr_lpfc_enable_mds_diags.attr,6109	&dev_attr_lpfc_ras_fwlog_buffsize.attr,6110	&dev_attr_lpfc_ras_fwlog_level.attr,6111	&dev_attr_lpfc_ras_fwlog_func.attr,6112	&dev_attr_lpfc_enable_bbcr.attr,6113	&dev_attr_lpfc_enable_dpp.attr,6114	&dev_attr_lpfc_enable_mi.attr,6115	&dev_attr_cmf_info.attr,6116	&dev_attr_lpfc_max_vmid.attr,6117	&dev_attr_lpfc_vmid_inactivity_timeout.attr,6118	&dev_attr_lpfc_vmid_app_header.attr,6119	&dev_attr_lpfc_vmid_priority_tagging.attr,6120	NULL,6121};6122 6123static const struct attribute_group lpfc_hba_attr_group = {6124	.attrs = lpfc_hba_attrs6125};6126 6127const struct attribute_group *lpfc_hba_groups[] = {6128	&lpfc_hba_attr_group,6129	NULL6130};6131 6132static struct attribute *lpfc_vport_attrs[] = {6133	&dev_attr_info.attr,6134	&dev_attr_link_state.attr,6135	&dev_attr_num_discovered_ports.attr,6136	&dev_attr_lpfc_drvr_version.attr,6137	&dev_attr_lpfc_log_verbose.attr,6138	&dev_attr_lpfc_lun_queue_depth.attr,6139	&dev_attr_lpfc_tgt_queue_depth.attr,6140	&dev_attr_lpfc_nodev_tmo.attr,6141	&dev_attr_lpfc_devloss_tmo.attr,6142	&dev_attr_lpfc_hba_queue_depth.attr,6143	&dev_attr_lpfc_peer_port_login.attr,6144	&dev_attr_lpfc_restrict_login.attr,6145	&dev_attr_lpfc_fcp_class.attr,6146	&dev_attr_lpfc_use_adisc.attr,6147	&dev_attr_lpfc_first_burst_size.attr,6148	&dev_attr_lpfc_max_luns.attr,6149	&dev_attr_nport_evt_cnt.attr,6150	&dev_attr_npiv_info.attr,6151	&dev_attr_lpfc_enable_da_id.attr,6152	&dev_attr_lpfc_max_scsicmpl_time.attr,6153	&dev_attr_lpfc_static_vport.attr,6154	&dev_attr_cmf_info.attr,6155	NULL,6156};6157 6158static const struct attribute_group lpfc_vport_attr_group = {6159	.attrs = lpfc_vport_attrs6160};6161 6162const struct attribute_group *lpfc_vport_groups[] = {6163	&lpfc_vport_attr_group,6164	NULL6165};6166 6167/**6168 * sysfs_ctlreg_write - Write method for writing to ctlreg6169 * @filp: open sysfs file6170 * @kobj: kernel kobject that contains the kernel class device.6171 * @bin_attr: kernel attributes passed to us.6172 * @buf: contains the data to be written to the adapter IOREG space.6173 * @off: offset into buffer to beginning of data.6174 * @count: bytes to transfer.6175 *6176 * Description:6177 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.6178 * Uses the adapter io control registers to send buf contents to the adapter.6179 *6180 * Returns:6181 * -ERANGE off and count combo out of range6182 * -EINVAL off, count or buff address invalid6183 * -EPERM adapter is offline6184 * value of count, buf contents written6185 **/6186static ssize_t6187sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,6188		   struct bin_attribute *bin_attr,6189		   char *buf, loff_t off, size_t count)6190{6191	size_t buf_off;6192	struct device *dev = container_of(kobj, struct device, kobj);6193	struct Scsi_Host  *shost = class_to_shost(dev);6194	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;6195	struct lpfc_hba   *phba = vport->phba;6196 6197	if (phba->sli_rev >= LPFC_SLI_REV4)6198		return -EPERM;6199 6200	if ((off + count) > FF_REG_AREA_SIZE)6201		return -ERANGE;6202 6203	if (count <= LPFC_REG_WRITE_KEY_SIZE)6204		return 0;6205 6206	if (off % 4 || count % 4 || (unsigned long)buf % 4)6207		return -EINVAL;6208 6209	/* This is to protect HBA registers from accidental writes. */6210	if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))6211		return -EINVAL;6212 6213	if (!test_bit(FC_OFFLINE_MODE, &vport->fc_flag))6214		return -EPERM;6215 6216	spin_lock_irq(&phba->hbalock);6217	for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;6218			buf_off += sizeof(uint32_t))6219		writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),6220		       phba->ctrl_regs_memmap_p + off + buf_off);6221 6222	spin_unlock_irq(&phba->hbalock);6223 6224	return count;6225}6226 6227/**6228 * sysfs_ctlreg_read - Read method for reading from ctlreg6229 * @filp: open sysfs file6230 * @kobj: kernel kobject that contains the kernel class device.6231 * @bin_attr: kernel attributes passed to us.6232 * @buf: if successful contains the data from the adapter IOREG space.6233 * @off: offset into buffer to beginning of data.6234 * @count: bytes to transfer.6235 *6236 * Description:6237 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.6238 * Uses the adapter io control registers to read data into buf.6239 *6240 * Returns:6241 * -ERANGE off and count combo out of range6242 * -EINVAL off, count or buff address invalid6243 * value of count, buf contents read6244 **/6245static ssize_t6246sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,6247		  struct bin_attribute *bin_attr,6248		  char *buf, loff_t off, size_t count)6249{6250	size_t buf_off;6251	uint32_t * tmp_ptr;6252	struct device *dev = container_of(kobj, struct device, kobj);6253	struct Scsi_Host  *shost = class_to_shost(dev);6254	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;6255	struct lpfc_hba   *phba = vport->phba;6256 6257	if (phba->sli_rev >= LPFC_SLI_REV4)6258		return -EPERM;6259 6260	if (off > FF_REG_AREA_SIZE)6261		return -ERANGE;6262 6263	if ((off + count) > FF_REG_AREA_SIZE)6264		count = FF_REG_AREA_SIZE - off;6265 6266	if (count == 0) return 0;6267 6268	if (off % 4 || count % 4 || (unsigned long)buf % 4)6269		return -EINVAL;6270 6271	spin_lock_irq(&phba->hbalock);6272 6273	for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {6274		tmp_ptr = (uint32_t *)(buf + buf_off);6275		*tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);6276	}6277 6278	spin_unlock_irq(&phba->hbalock);6279 6280	return count;6281}6282 6283static struct bin_attribute sysfs_ctlreg_attr = {6284	.attr = {6285		.name = "ctlreg",6286		.mode = S_IRUSR | S_IWUSR,6287	},6288	.size = 256,6289	.read = sysfs_ctlreg_read,6290	.write = sysfs_ctlreg_write,6291};6292 6293/**6294 * sysfs_mbox_write - Write method for writing information via mbox6295 * @filp: open sysfs file6296 * @kobj: kernel kobject that contains the kernel class device.6297 * @bin_attr: kernel attributes passed to us.6298 * @buf: contains the data to be written to sysfs mbox.6299 * @off: offset into buffer to beginning of data.6300 * @count: bytes to transfer.6301 *6302 * Description:6303 * Deprecated function. All mailbox access from user space is performed via the6304 * bsg interface.6305 *6306 * Returns:6307 * -EPERM operation not permitted6308 **/6309static ssize_t6310sysfs_mbox_write(struct file *filp, struct kobject *kobj,6311		 struct bin_attribute *bin_attr,6312		 char *buf, loff_t off, size_t count)6313{6314	return -EPERM;6315}6316 6317/**6318 * sysfs_mbox_read - Read method for reading information via mbox6319 * @filp: open sysfs file6320 * @kobj: kernel kobject that contains the kernel class device.6321 * @bin_attr: kernel attributes passed to us.6322 * @buf: contains the data to be read from sysfs mbox.6323 * @off: offset into buffer to beginning of data.6324 * @count: bytes to transfer.6325 *6326 * Description:6327 * Deprecated function. All mailbox access from user space is performed via the6328 * bsg interface.6329 *6330 * Returns:6331 * -EPERM operation not permitted6332 **/6333static ssize_t6334sysfs_mbox_read(struct file *filp, struct kobject *kobj,6335		struct bin_attribute *bin_attr,6336		char *buf, loff_t off, size_t count)6337{6338	return -EPERM;6339}6340 6341static struct bin_attribute sysfs_mbox_attr = {6342	.attr = {6343		.name = "mbox",6344		.mode = S_IRUSR | S_IWUSR,6345	},6346	.size = MAILBOX_SYSFS_MAX,6347	.read = sysfs_mbox_read,6348	.write = sysfs_mbox_write,6349};6350 6351/**6352 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries6353 * @vport: address of lpfc vport structure.6354 *6355 * Return codes:6356 * zero on success6357 * error return code from sysfs_create_bin_file()6358 **/6359int6360lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)6361{6362	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);6363	int error;6364 6365	/* Virtual ports do not need ctrl_reg and mbox */6366	if (vport->port_type == LPFC_NPIV_PORT)6367		return 0;6368 6369	error = sysfs_create_bin_file(&shost->shost_dev.kobj,6370				      &sysfs_ctlreg_attr);6371	if (error)6372		goto out;6373 6374	error = sysfs_create_bin_file(&shost->shost_dev.kobj,6375				      &sysfs_mbox_attr);6376	if (error)6377		goto out_remove_ctlreg_attr;6378 6379	return 0;6380out_remove_ctlreg_attr:6381	sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);6382out:6383	return error;6384}6385 6386/**6387 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries6388 * @vport: address of lpfc vport structure.6389 **/6390void6391lpfc_free_sysfs_attr(struct lpfc_vport *vport)6392{6393	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);6394 6395	/* Virtual ports do not need ctrl_reg and mbox */6396	if (vport->port_type == LPFC_NPIV_PORT)6397		return;6398	sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);6399	sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);6400}6401 6402/*6403 * Dynamic FC Host Attributes Support6404 */6405 6406/**6407 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host6408 * @shost: kernel scsi host pointer.6409 **/6410static void6411lpfc_get_host_symbolic_name(struct Scsi_Host *shost)6412{6413	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;6414 6415	lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),6416				      sizeof fc_host_symbolic_name(shost));6417}6418 6419/**6420 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id6421 * @shost: kernel scsi host pointer.6422 **/6423static void6424lpfc_get_host_port_id(struct Scsi_Host *shost)6425{6426	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;6427 6428	/* note: fc_myDID already in cpu endianness */6429	fc_host_port_id(shost) = vport->fc_myDID;6430}6431 6432/**6433 * lpfc_get_host_port_type - Set the value of the scsi host port type6434 * @shost: kernel scsi host pointer.6435 **/6436static void6437lpfc_get_host_port_type(struct Scsi_Host *shost)6438{6439	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;6440	struct lpfc_hba   *phba = vport->phba;6441 6442	if (vport->port_type == LPFC_NPIV_PORT) {6443		fc_host_port_type(shost) = FC_PORTTYPE_NPIV;6444	} else if (lpfc_is_link_up(phba)) {6445		if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {6446			if (test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))6447				fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;6448			else6449				fc_host_port_type(shost) = FC_PORTTYPE_LPORT;6450		} else {6451			if (test_bit(FC_FABRIC, &vport->fc_flag))6452				fc_host_port_type(shost) = FC_PORTTYPE_NPORT;6453			else6454				fc_host_port_type(shost) = FC_PORTTYPE_PTP;6455		}6456	} else6457		fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;6458}6459 6460/**6461 * lpfc_get_host_port_state - Set the value of the scsi host port state6462 * @shost: kernel scsi host pointer.6463 **/6464static void6465lpfc_get_host_port_state(struct Scsi_Host *shost)6466{6467	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;6468	struct lpfc_hba   *phba = vport->phba;6469 6470	if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag))6471		fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;6472	else {6473		switch (phba->link_state) {6474		case LPFC_LINK_UNKNOWN:6475		case LPFC_LINK_DOWN:6476			fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;6477			break;6478		case LPFC_LINK_UP:6479		case LPFC_CLEAR_LA:6480		case LPFC_HBA_READY:6481			/* Links up, reports port state accordingly */6482			if (vport->port_state < LPFC_VPORT_READY)6483				fc_host_port_state(shost) =6484							FC_PORTSTATE_BYPASSED;6485			else6486				fc_host_port_state(shost) =6487							FC_PORTSTATE_ONLINE;6488			break;6489		case LPFC_HBA_ERROR:6490			fc_host_port_state(shost) = FC_PORTSTATE_ERROR;6491			break;6492		default:6493			fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;6494			break;6495		}6496	}6497}6498 6499/**6500 * lpfc_get_host_speed - Set the value of the scsi host speed6501 * @shost: kernel scsi host pointer.6502 **/6503static void6504lpfc_get_host_speed(struct Scsi_Host *shost)6505{6506	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;6507	struct lpfc_hba   *phba = vport->phba;6508 6509	if ((lpfc_is_link_up(phba)) &&6510	    !test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {6511		switch(phba->fc_linkspeed) {6512		case LPFC_LINK_SPEED_1GHZ:6513			fc_host_speed(shost) = FC_PORTSPEED_1GBIT;6514			break;6515		case LPFC_LINK_SPEED_2GHZ:6516			fc_host_speed(shost) = FC_PORTSPEED_2GBIT;6517			break;6518		case LPFC_LINK_SPEED_4GHZ:6519			fc_host_speed(shost) = FC_PORTSPEED_4GBIT;6520			break;6521		case LPFC_LINK_SPEED_8GHZ:6522			fc_host_speed(shost) = FC_PORTSPEED_8GBIT;6523			break;6524		case LPFC_LINK_SPEED_10GHZ:6525			fc_host_speed(shost) = FC_PORTSPEED_10GBIT;6526			break;6527		case LPFC_LINK_SPEED_16GHZ:6528			fc_host_speed(shost) = FC_PORTSPEED_16GBIT;6529			break;6530		case LPFC_LINK_SPEED_32GHZ:6531			fc_host_speed(shost) = FC_PORTSPEED_32GBIT;6532			break;6533		case LPFC_LINK_SPEED_64GHZ:6534			fc_host_speed(shost) = FC_PORTSPEED_64GBIT;6535			break;6536		case LPFC_LINK_SPEED_128GHZ:6537			fc_host_speed(shost) = FC_PORTSPEED_128GBIT;6538			break;6539		case LPFC_LINK_SPEED_256GHZ:6540			fc_host_speed(shost) = FC_PORTSPEED_256GBIT;6541			break;6542		default:6543			fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;6544			break;6545		}6546	} else if (lpfc_is_link_up(phba) &&6547		   test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {6548		switch (phba->fc_linkspeed) {6549		case LPFC_ASYNC_LINK_SPEED_1GBPS:6550			fc_host_speed(shost) = FC_PORTSPEED_1GBIT;6551			break;6552		case LPFC_ASYNC_LINK_SPEED_10GBPS:6553			fc_host_speed(shost) = FC_PORTSPEED_10GBIT;6554			break;6555		case LPFC_ASYNC_LINK_SPEED_20GBPS:6556			fc_host_speed(shost) = FC_PORTSPEED_20GBIT;6557			break;6558		case LPFC_ASYNC_LINK_SPEED_25GBPS:6559			fc_host_speed(shost) = FC_PORTSPEED_25GBIT;6560			break;6561		case LPFC_ASYNC_LINK_SPEED_40GBPS:6562			fc_host_speed(shost) = FC_PORTSPEED_40GBIT;6563			break;6564		case LPFC_ASYNC_LINK_SPEED_100GBPS:6565			fc_host_speed(shost) = FC_PORTSPEED_100GBIT;6566			break;6567		default:6568			fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;6569			break;6570		}6571	} else6572		fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;6573}6574 6575/**6576 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name6577 * @shost: kernel scsi host pointer.6578 **/6579static void6580lpfc_get_host_fabric_name (struct Scsi_Host *shost)6581{6582	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;6583	struct lpfc_hba   *phba = vport->phba;6584	u64 node_name;6585 6586	if (vport->port_state > LPFC_FLOGI &&6587	    (test_bit(FC_FABRIC, &vport->fc_flag) ||6588	     (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&6589	      test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))))6590		node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);6591	else6592		/* fabric is local port if there is no F/FL_Port */6593		node_name = 0;6594 6595	fc_host_fabric_name(shost) = node_name;6596}6597 6598/**6599 * lpfc_get_stats - Return statistical information about the adapter6600 * @shost: kernel scsi host pointer.6601 *6602 * Notes:6603 * NULL on error for link down, no mbox pool, sli2 active,6604 * management not allowed, memory allocation error, or mbox error.6605 *6606 * Returns:6607 * NULL for error6608 * address of the adapter host statistics6609 **/6610static struct fc_host_statistics *6611lpfc_get_stats(struct Scsi_Host *shost)6612{6613	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;6614	struct lpfc_hba   *phba = vport->phba;6615	struct lpfc_sli   *psli = &phba->sli;6616	struct fc_host_statistics *hs = &phba->link_stats;6617	struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;6618	LPFC_MBOXQ_t *pmboxq;6619	MAILBOX_t *pmb;6620	int rc = 0;6621 6622	/*6623	 * prevent udev from issuing mailbox commands until the port is6624	 * configured.6625	 */6626	if (phba->link_state < LPFC_LINK_DOWN ||6627	    !phba->mbox_mem_pool ||6628	    (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)6629		return NULL;6630 6631	if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)6632		return NULL;6633 6634	pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);6635	if (!pmboxq)6636		return NULL;6637	memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));6638 6639	pmb = &pmboxq->u.mb;6640	pmb->mbxCommand = MBX_READ_STATUS;6641	pmb->mbxOwner = OWN_HOST;6642	pmboxq->ctx_buf = NULL;6643	pmboxq->vport = vport;6644 6645	if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag)) {6646		rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);6647		if (rc != MBX_SUCCESS) {6648			mempool_free(pmboxq, phba->mbox_mem_pool);6649			return NULL;6650		}6651	} else {6652		rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);6653		if (rc != MBX_SUCCESS) {6654			if (rc != MBX_TIMEOUT)6655				mempool_free(pmboxq, phba->mbox_mem_pool);6656			return NULL;6657		}6658	}6659 6660	memset(hs, 0, sizeof (struct fc_host_statistics));6661 6662	hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;6663	hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;6664 6665	/*6666	 * The MBX_READ_STATUS returns tx_k_bytes which has to be6667	 * converted to words.6668	 *6669	 * Check if extended byte flag is set, to know when to collect upper6670	 * bits of 64 bit wide statistics counter.6671	 */6672	if (pmb->un.varRdStatus.xkb & RD_ST_XKB) {6673		hs->tx_words = (u64)6674			       ((((u64)(pmb->un.varRdStatus.xmit_xkb &6675					RD_ST_XMIT_XKB_MASK) << 32) |6676				(u64)pmb->un.varRdStatus.xmitByteCnt) *6677				(u64)256);6678		hs->rx_words = (u64)6679			       ((((u64)(pmb->un.varRdStatus.rcv_xkb &6680					RD_ST_RCV_XKB_MASK) << 32) |6681				(u64)pmb->un.varRdStatus.rcvByteCnt) *6682				(u64)256);6683	} else {6684		hs->tx_words = (uint64_t)6685				((uint64_t)pmb->un.varRdStatus.xmitByteCnt6686				* (uint64_t)256);6687		hs->rx_words = (uint64_t)6688				((uint64_t)pmb->un.varRdStatus.rcvByteCnt6689				 * (uint64_t)256);6690	}6691 6692	memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));6693	pmb->mbxCommand = MBX_READ_LNK_STAT;6694	pmb->mbxOwner = OWN_HOST;6695	pmboxq->ctx_buf = NULL;6696	pmboxq->vport = vport;6697 6698	if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag)) {6699		rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);6700		if (rc != MBX_SUCCESS) {6701			mempool_free(pmboxq, phba->mbox_mem_pool);6702			return NULL;6703		}6704	} else {6705		rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);6706		if (rc != MBX_SUCCESS) {6707			if (rc != MBX_TIMEOUT)6708				mempool_free(pmboxq, phba->mbox_mem_pool);6709			return NULL;6710		}6711	}6712 6713	hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;6714	hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;6715	hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;6716	hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;6717	hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;6718	hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;6719	hs->error_frames = pmb->un.varRdLnk.crcCnt;6720 6721	hs->cn_sig_warn = atomic64_read(&phba->cgn_acqe_stat.warn);6722	hs->cn_sig_alarm = atomic64_read(&phba->cgn_acqe_stat.alarm);6723 6724	hs->link_failure_count -= lso->link_failure_count;6725	hs->loss_of_sync_count -= lso->loss_of_sync_count;6726	hs->loss_of_signal_count -= lso->loss_of_signal_count;6727	hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;6728	hs->invalid_tx_word_count -= lso->invalid_tx_word_count;6729	hs->invalid_crc_count -= lso->invalid_crc_count;6730	hs->error_frames -= lso->error_frames;6731 6732	if (test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {6733		hs->lip_count = -1;6734		hs->nos_count = (phba->link_events >> 1);6735		hs->nos_count -= lso->link_events;6736	} else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {6737		hs->lip_count = (phba->fc_eventTag >> 1);6738		hs->lip_count -= lso->link_events;6739		hs->nos_count = -1;6740	} else {6741		hs->lip_count = -1;6742		hs->nos_count = (phba->fc_eventTag >> 1);6743		hs->nos_count -= lso->link_events;6744	}6745 6746	hs->dumped_frames = -1;6747 6748	hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;6749 6750	mempool_free(pmboxq, phba->mbox_mem_pool);6751 6752	return hs;6753}6754 6755/**6756 * lpfc_reset_stats - Copy the adapter link stats information6757 * @shost: kernel scsi host pointer.6758 **/6759static void6760lpfc_reset_stats(struct Scsi_Host *shost)6761{6762	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;6763	struct lpfc_hba   *phba = vport->phba;6764	struct lpfc_sli   *psli = &phba->sli;6765	struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;6766	LPFC_MBOXQ_t *pmboxq;6767	MAILBOX_t *pmb;6768	int rc = 0;6769 6770	if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)6771		return;6772 6773	pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);6774	if (!pmboxq)6775		return;6776	memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));6777 6778	pmb = &pmboxq->u.mb;6779	pmb->mbxCommand = MBX_READ_STATUS;6780	pmb->mbxOwner = OWN_HOST;6781	pmb->un.varWords[0] = 0x1; /* reset request */6782	pmboxq->ctx_buf = NULL;6783	pmboxq->vport = vport;6784 6785	if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag) ||6786	    !(psli->sli_flag & LPFC_SLI_ACTIVE)) {6787		rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);6788		if (rc != MBX_SUCCESS) {6789			mempool_free(pmboxq, phba->mbox_mem_pool);6790			return;6791		}6792	} else {6793		rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);6794		if (rc != MBX_SUCCESS) {6795			if (rc != MBX_TIMEOUT)6796				mempool_free(pmboxq, phba->mbox_mem_pool);6797			return;6798		}6799	}6800 6801	memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));6802	pmb->mbxCommand = MBX_READ_LNK_STAT;6803	pmb->mbxOwner = OWN_HOST;6804	pmboxq->ctx_buf = NULL;6805	pmboxq->vport = vport;6806 6807	if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag) ||6808	    !(psli->sli_flag & LPFC_SLI_ACTIVE)) {6809		rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);6810		if (rc != MBX_SUCCESS) {6811			mempool_free(pmboxq, phba->mbox_mem_pool);6812			return;6813		}6814	} else {6815		rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);6816		if (rc != MBX_SUCCESS) {6817			if (rc != MBX_TIMEOUT)6818				mempool_free(pmboxq, phba->mbox_mem_pool);6819			return;6820		}6821	}6822 6823	lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;6824	lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;6825	lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;6826	lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;6827	lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;6828	lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;6829	lso->error_frames = pmb->un.varRdLnk.crcCnt;6830	if (test_bit(HBA_FCOE_MODE, &phba->hba_flag))6831		lso->link_events = (phba->link_events >> 1);6832	else6833		lso->link_events = (phba->fc_eventTag >> 1);6834 6835	atomic64_set(&phba->cgn_acqe_stat.warn, 0);6836	atomic64_set(&phba->cgn_acqe_stat.alarm, 0);6837 6838	memset(&shost_to_fc_host(shost)->fpin_stats, 0,6839	       sizeof(shost_to_fc_host(shost)->fpin_stats));6840 6841	psli->stats_start = ktime_get_seconds();6842 6843	mempool_free(pmboxq, phba->mbox_mem_pool);6844 6845	return;6846}6847 6848/*6849 * The LPFC driver treats linkdown handling as target loss events so there6850 * are no sysfs handlers for link_down_tmo.6851 */6852 6853/**6854 * lpfc_get_node_by_target - Return the nodelist for a target6855 * @starget: kernel scsi target pointer.6856 *6857 * Returns:6858 * address of the node list if found6859 * NULL target not found6860 **/6861static struct lpfc_nodelist *6862lpfc_get_node_by_target(struct scsi_target *starget)6863{6864	struct Scsi_Host  *shost = dev_to_shost(starget->dev.parent);6865	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;6866	struct lpfc_nodelist *ndlp;6867	unsigned long iflags;6868 6869	spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);6870	/* Search for this, mapped, target ID */6871	list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {6872		if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&6873		    starget->id == ndlp->nlp_sid) {6874			spin_unlock_irqrestore(&vport->fc_nodes_list_lock,6875					       iflags);6876			return ndlp;6877		}6878	}6879	spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);6880	return NULL;6881}6882 6883/**6884 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -16885 * @starget: kernel scsi target pointer.6886 **/6887static void6888lpfc_get_starget_port_id(struct scsi_target *starget)6889{6890	struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);6891 6892	fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;6893}6894 6895/**6896 * lpfc_get_starget_node_name - Set the target node name6897 * @starget: kernel scsi target pointer.6898 *6899 * Description: Set the target node name to the ndlp node name wwn or zero.6900 **/6901static void6902lpfc_get_starget_node_name(struct scsi_target *starget)6903{6904	struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);6905 6906	fc_starget_node_name(starget) =6907		ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;6908}6909 6910/**6911 * lpfc_get_starget_port_name - Set the target port name6912 * @starget: kernel scsi target pointer.6913 *6914 * Description:  set the target port name to the ndlp port name wwn or zero.6915 **/6916static void6917lpfc_get_starget_port_name(struct scsi_target *starget)6918{6919	struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);6920 6921	fc_starget_port_name(starget) =6922		ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;6923}6924 6925/**6926 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo6927 * @rport: fc rport address.6928 * @timeout: new value for dev loss tmo.6929 *6930 * Description:6931 * If timeout is non zero set the dev_loss_tmo to timeout, else set6932 * dev_loss_tmo to one.6933 **/6934static void6935lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)6936{6937	struct lpfc_rport_data *rdata = rport->dd_data;6938	struct lpfc_nodelist *ndlp = rdata->pnode;6939#if (IS_ENABLED(CONFIG_NVME_FC))6940	struct lpfc_nvme_rport *nrport = NULL;6941#endif6942 6943	if (timeout)6944		rport->dev_loss_tmo = timeout;6945	else6946		rport->dev_loss_tmo = 1;6947 6948	if (!ndlp) {6949		dev_info(&rport->dev, "Cannot find remote node to "6950				      "set rport dev loss tmo, port_id x%x\n",6951				      rport->port_id);6952		return;6953	}6954 6955#if (IS_ENABLED(CONFIG_NVME_FC))6956	nrport = lpfc_ndlp_get_nrport(ndlp);6957 6958	if (nrport && nrport->remoteport)6959		nvme_fc_set_remoteport_devloss(nrport->remoteport,6960					       rport->dev_loss_tmo);6961#endif6962}6963 6964/*6965 * lpfc_rport_show_function - Return rport target information6966 *6967 * Description:6968 * Macro that uses field to generate a function with the name lpfc_show_rport_6969 *6970 * lpfc_show_rport_##field: returns the bytes formatted in buf6971 * @cdev: class converted to an fc_rport.6972 * @buf: on return contains the target_field or zero.6973 *6974 * Returns: size of formatted string.6975 **/6976#define lpfc_rport_show_function(field, format_string, sz, cast)	\6977static ssize_t								\6978lpfc_show_rport_##field (struct device *dev,				\6979			 struct device_attribute *attr,			\6980			 char *buf)					\6981{									\6982	struct fc_rport *rport = transport_class_to_rport(dev);		\6983	struct lpfc_rport_data *rdata = rport->hostdata;		\6984	return scnprintf(buf, sz, format_string,			\6985		(rdata->target) ? cast rdata->target->field : 0);	\6986}6987 6988#define lpfc_rport_rd_attr(field, format_string, sz)			\6989	lpfc_rport_show_function(field, format_string, sz, )		\6990static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)6991 6992/**6993 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name6994 * @fc_vport: The fc_vport who's symbolic name has been changed.6995 *6996 * Description:6997 * This function is called by the transport after the @fc_vport's symbolic name6998 * has been changed. This function re-registers the symbolic name with the6999 * switch to propagate the change into the fabric if the vport is active.7000 **/7001static void7002lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)7003{7004	struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;7005 7006	if (vport->port_state == LPFC_VPORT_READY)7007		lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);7008}7009 7010/**7011 * lpfc_hba_log_verbose_init - Set hba's log verbose level7012 * @phba: Pointer to lpfc_hba struct.7013 * @verbose: Verbose level to set.7014 *7015 * This function is called by the lpfc_get_cfgparam() routine to set the7016 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with7017 * log message according to the module's lpfc_log_verbose parameter setting7018 * before hba port or vport created.7019 **/7020static void7021lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)7022{7023	phba->cfg_log_verbose = verbose;7024}7025 7026struct fc_function_template lpfc_transport_functions = {7027	/* fixed attributes the driver supports */7028	.show_host_node_name = 1,7029	.show_host_port_name = 1,7030	.show_host_supported_classes = 1,7031	.show_host_supported_fc4s = 1,7032	.show_host_supported_speeds = 1,7033	.show_host_maxframe_size = 1,7034 7035	.get_host_symbolic_name = lpfc_get_host_symbolic_name,7036	.show_host_symbolic_name = 1,7037 7038	/* dynamic attributes the driver supports */7039	.get_host_port_id = lpfc_get_host_port_id,7040	.show_host_port_id = 1,7041 7042	.get_host_port_type = lpfc_get_host_port_type,7043	.show_host_port_type = 1,7044 7045	.get_host_port_state = lpfc_get_host_port_state,7046	.show_host_port_state = 1,7047 7048	/* active_fc4s is shown but doesn't change (thus no get function) */7049	.show_host_active_fc4s = 1,7050 7051	.get_host_speed = lpfc_get_host_speed,7052	.show_host_speed = 1,7053 7054	.get_host_fabric_name = lpfc_get_host_fabric_name,7055	.show_host_fabric_name = 1,7056 7057	/*7058	 * The LPFC driver treats linkdown handling as target loss events7059	 * so there are no sysfs handlers for link_down_tmo.7060	 */7061 7062	.get_fc_host_stats = lpfc_get_stats,7063	.reset_fc_host_stats = lpfc_reset_stats,7064 7065	.dd_fcrport_size = sizeof(struct lpfc_rport_data),7066	.show_rport_maxframe_size = 1,7067	.show_rport_supported_classes = 1,7068 7069	.set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,7070	.show_rport_dev_loss_tmo = 1,7071 7072	.get_starget_port_id  = lpfc_get_starget_port_id,7073	.show_starget_port_id = 1,7074 7075	.get_starget_node_name = lpfc_get_starget_node_name,7076	.show_starget_node_name = 1,7077 7078	.get_starget_port_name = lpfc_get_starget_port_name,7079	.show_starget_port_name = 1,7080 7081	.issue_fc_host_lip = lpfc_issue_lip,7082	.dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,7083	.terminate_rport_io = lpfc_terminate_rport_io,7084 7085	.dd_fcvport_size = sizeof(struct lpfc_vport *),7086 7087	.vport_disable = lpfc_vport_disable,7088 7089	.set_vport_symbolic_name = lpfc_set_vport_symbolic_name,7090 7091	.bsg_request = lpfc_bsg_request,7092	.bsg_timeout = lpfc_bsg_timeout,7093};7094 7095struct fc_function_template lpfc_vport_transport_functions = {7096	/* fixed attributes the driver supports */7097	.show_host_node_name = 1,7098	.show_host_port_name = 1,7099	.show_host_supported_classes = 1,7100	.show_host_supported_fc4s = 1,7101	.show_host_supported_speeds = 1,7102	.show_host_maxframe_size = 1,7103 7104	.get_host_symbolic_name = lpfc_get_host_symbolic_name,7105	.show_host_symbolic_name = 1,7106 7107	/* dynamic attributes the driver supports */7108	.get_host_port_id = lpfc_get_host_port_id,7109	.show_host_port_id = 1,7110 7111	.get_host_port_type = lpfc_get_host_port_type,7112	.show_host_port_type = 1,7113 7114	.get_host_port_state = lpfc_get_host_port_state,7115	.show_host_port_state = 1,7116 7117	/* active_fc4s is shown but doesn't change (thus no get function) */7118	.show_host_active_fc4s = 1,7119 7120	.get_host_speed = lpfc_get_host_speed,7121	.show_host_speed = 1,7122 7123	.get_host_fabric_name = lpfc_get_host_fabric_name,7124	.show_host_fabric_name = 1,7125 7126	/*7127	 * The LPFC driver treats linkdown handling as target loss events7128	 * so there are no sysfs handlers for link_down_tmo.7129	 */7130 7131	.get_fc_host_stats = lpfc_get_stats,7132	.reset_fc_host_stats = lpfc_reset_stats,7133 7134	.dd_fcrport_size = sizeof(struct lpfc_rport_data),7135	.show_rport_maxframe_size = 1,7136	.show_rport_supported_classes = 1,7137 7138	.set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,7139	.show_rport_dev_loss_tmo = 1,7140 7141	.get_starget_port_id  = lpfc_get_starget_port_id,7142	.show_starget_port_id = 1,7143 7144	.get_starget_node_name = lpfc_get_starget_node_name,7145	.show_starget_node_name = 1,7146 7147	.get_starget_port_name = lpfc_get_starget_port_name,7148	.show_starget_port_name = 1,7149 7150	.dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,7151	.terminate_rport_io = lpfc_terminate_rport_io,7152 7153	.vport_disable = lpfc_vport_disable,7154 7155	.set_vport_symbolic_name = lpfc_set_vport_symbolic_name,7156};7157 7158/**7159 * lpfc_get_hba_function_mode - Used to determine the HBA function in FCoE7160 * Mode7161 * @phba: lpfc_hba pointer.7162 **/7163static void7164lpfc_get_hba_function_mode(struct lpfc_hba *phba)7165{7166	/* If the adapter supports FCoE mode */7167	switch (phba->pcidev->device) {7168	case PCI_DEVICE_ID_SKYHAWK:7169	case PCI_DEVICE_ID_SKYHAWK_VF:7170	case PCI_DEVICE_ID_LANCER_FCOE:7171	case PCI_DEVICE_ID_LANCER_FCOE_VF:7172	case PCI_DEVICE_ID_ZEPHYR_DCSP:7173	case PCI_DEVICE_ID_TIGERSHARK:7174	case PCI_DEVICE_ID_TOMCAT:7175		set_bit(HBA_FCOE_MODE, &phba->hba_flag);7176		break;7177	default:7178	/* for others, clear the flag */7179		clear_bit(HBA_FCOE_MODE, &phba->hba_flag);7180	}7181}7182 7183/**7184 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure7185 * @phba: lpfc_hba pointer.7186 **/7187void7188lpfc_get_cfgparam(struct lpfc_hba *phba)7189{7190	lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);7191	lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);7192	lpfc_ns_query_init(phba, lpfc_ns_query);7193	lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);7194	lpfc_cr_delay_init(phba, lpfc_cr_delay);7195	lpfc_cr_count_init(phba, lpfc_cr_count);7196	lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);7197	lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);7198	lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);7199	lpfc_ack0_init(phba, lpfc_ack0);7200	lpfc_xri_rebalancing_init(phba, lpfc_xri_rebalancing);7201	lpfc_topology_init(phba, lpfc_topology);7202	lpfc_link_speed_init(phba, lpfc_link_speed);7203	lpfc_poll_tmo_init(phba, lpfc_poll_tmo);7204	lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);7205	lpfc_enable_npiv_init(phba, lpfc_enable_npiv);7206	lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);7207	lpfc_enable_rrq_init(phba, lpfc_enable_rrq);7208	lpfc_fcp_wait_abts_rsp_init(phba, lpfc_fcp_wait_abts_rsp);7209	lpfc_fdmi_on_init(phba, lpfc_fdmi_on);7210	lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);7211	lpfc_use_msi_init(phba, lpfc_use_msi);7212	lpfc_nvme_oas_init(phba, lpfc_nvme_oas);7213	lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);7214	lpfc_fcp_imax_init(phba, lpfc_fcp_imax);7215	lpfc_force_rscn_init(phba, lpfc_force_rscn);7216	lpfc_cq_poll_threshold_init(phba, lpfc_cq_poll_threshold);7217	lpfc_cq_max_proc_limit_init(phba, lpfc_cq_max_proc_limit);7218	lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);7219	lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);7220	lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);7221 7222	lpfc_EnableXLane_init(phba, lpfc_EnableXLane);7223	/* VMID Inits */7224	lpfc_max_vmid_init(phba, lpfc_max_vmid);7225	lpfc_vmid_inactivity_timeout_init(phba, lpfc_vmid_inactivity_timeout);7226	lpfc_vmid_app_header_init(phba, lpfc_vmid_app_header);7227	lpfc_vmid_priority_tagging_init(phba, lpfc_vmid_priority_tagging);7228	if (phba->sli_rev != LPFC_SLI_REV4)7229		phba->cfg_EnableXLane = 0;7230	lpfc_XLanePriority_init(phba, lpfc_XLanePriority);7231 7232	memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));7233	memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));7234	phba->cfg_oas_lun_state = 0;7235	phba->cfg_oas_lun_status = 0;7236	phba->cfg_oas_flags = 0;7237	phba->cfg_oas_priority = 0;7238	lpfc_enable_bg_init(phba, lpfc_enable_bg);7239	lpfc_prot_mask_init(phba, lpfc_prot_mask);7240	lpfc_prot_guard_init(phba, lpfc_prot_guard);7241	if (phba->sli_rev == LPFC_SLI_REV4)7242		phba->cfg_poll = 0;7243	else7244		phba->cfg_poll = lpfc_poll;7245 7246	/* Get the function mode */7247	lpfc_get_hba_function_mode(phba);7248 7249	/* BlockGuard allowed for FC only. */7250	if (phba->cfg_enable_bg && test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {7251		lpfc_printf_log(phba, KERN_INFO, LOG_INIT,7252				"0581 BlockGuard feature not supported\n");7253		/* If set, clear the BlockGuard support param */7254		phba->cfg_enable_bg = 0;7255	} else if (phba->cfg_enable_bg) {7256		phba->sli3_options |= LPFC_SLI3_BG_ENABLED;7257	}7258 7259	lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);7260 7261	lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);7262	lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);7263	lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);7264 7265	/* Initialize first burst. Target vs Initiator are different. */7266	lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);7267	lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);7268	lpfc_fcp_mq_threshold_init(phba, lpfc_fcp_mq_threshold);7269	lpfc_hdw_queue_init(phba, lpfc_hdw_queue);7270	lpfc_irq_chann_init(phba, lpfc_irq_chann);7271	lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);7272	lpfc_enable_dpp_init(phba, lpfc_enable_dpp);7273	lpfc_enable_mi_init(phba, lpfc_enable_mi);7274 7275	phba->cgn_p.cgn_param_mode = LPFC_CFG_OFF;7276	phba->cmf_active_mode = LPFC_CFG_OFF;7277	if (lpfc_fabric_cgn_frequency > EDC_CG_SIGFREQ_CNT_MAX ||7278	   lpfc_fabric_cgn_frequency < EDC_CG_SIGFREQ_CNT_MIN)7279		lpfc_fabric_cgn_frequency = 100; /* 100 ms default */7280 7281	if (phba->sli_rev != LPFC_SLI_REV4) {7282		/* NVME only supported on SLI4 */7283		phba->nvmet_support = 0;7284		phba->cfg_nvmet_mrq = 0;7285		phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;7286		phba->cfg_enable_bbcr = 0;7287		phba->cfg_xri_rebalancing = 0;7288	} else {7289		/* We MUST have FCP support */7290		if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))7291			phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;7292	}7293 7294	phba->cfg_auto_imax = (phba->cfg_fcp_imax) ? 0 : 1;7295 7296	phba->cfg_enable_pbde = 0;7297 7298	/* A value of 0 means use the number of CPUs found in the system */7299	if (phba->cfg_hdw_queue == 0)7300		phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;7301	if (phba->cfg_irq_chann == 0)7302		phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;7303	if (phba->cfg_irq_chann > phba->cfg_hdw_queue &&7304	    phba->sli_rev == LPFC_SLI_REV4)7305		phba->cfg_irq_chann = phba->cfg_hdw_queue;7306 7307	lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);7308	lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);7309	lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);7310	lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);7311	lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);7312	lpfc_delay_discovery_init(phba, lpfc_delay_discovery);7313	lpfc_sli_mode_init(phba, lpfc_sli_mode);7314	lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);7315	lpfc_ras_fwlog_buffsize_init(phba, lpfc_ras_fwlog_buffsize);7316	lpfc_ras_fwlog_level_init(phba, lpfc_ras_fwlog_level);7317	lpfc_ras_fwlog_func_init(phba, lpfc_ras_fwlog_func);7318 7319	return;7320}7321 7322/**7323 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on7324 * dependencies between protocols and roles.7325 * @phba: lpfc_hba pointer.7326 **/7327void7328lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)7329{7330	int  logit = 0;7331 7332	if (phba->cfg_hdw_queue > phba->sli4_hba.num_present_cpu) {7333		phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;7334		logit = 1;7335	}7336	if (phba->cfg_irq_chann > phba->sli4_hba.num_present_cpu) {7337		phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;7338		logit = 1;7339	}7340	if (phba->cfg_irq_chann > phba->cfg_hdw_queue) {7341		phba->cfg_irq_chann = phba->cfg_hdw_queue;7342		logit = 1;7343	}7344	if (logit)7345		lpfc_printf_log(phba, KERN_ERR, LOG_SLI,7346				"2006 Reducing Queues - CPU limitation: "7347				"IRQ %d HDWQ %d\n",7348				phba->cfg_irq_chann,7349				phba->cfg_hdw_queue);7350 7351	if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&7352	    phba->nvmet_support) {7353		phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;7354 7355		lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,7356				"6013 %s x%x fb_size x%x, fb_max x%x\n",7357				"NVME Target PRLI ACC enable_fb ",7358				phba->cfg_nvme_enable_fb,7359				phba->cfg_nvmet_fb_size,7360				LPFC_NVMET_FB_SZ_MAX);7361 7362		if (phba->cfg_nvme_enable_fb == 0)7363			phba->cfg_nvmet_fb_size = 0;7364		else {7365			if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)7366				phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;7367		}7368 7369		if (!phba->cfg_nvmet_mrq)7370			phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;7371 7372		/* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */7373		if (phba->cfg_nvmet_mrq > phba->cfg_hdw_queue) {7374			phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;7375			lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,7376					"6018 Adjust lpfc_nvmet_mrq to %d\n",7377					phba->cfg_nvmet_mrq);7378		}7379		if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)7380			phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;7381 7382	} else {7383		/* Not NVME Target mode.  Turn off Target parameters. */7384		phba->nvmet_support = 0;7385		phba->cfg_nvmet_mrq = 0;7386		phba->cfg_nvmet_fb_size = 0;7387	}7388}7389 7390/**7391 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure7392 * @vport: lpfc_vport pointer.7393 **/7394void7395lpfc_get_vport_cfgparam(struct lpfc_vport *vport)7396{7397	lpfc_log_verbose_init(vport, lpfc_log_verbose);7398	lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);7399	lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);7400	lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);7401	lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);7402	lpfc_peer_port_login_init(vport, lpfc_peer_port_login);7403	lpfc_restrict_login_init(vport, lpfc_restrict_login);7404	lpfc_fcp_class_init(vport, lpfc_fcp_class);7405	lpfc_use_adisc_init(vport, lpfc_use_adisc);7406	lpfc_first_burst_size_init(vport, lpfc_first_burst_size);7407	lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);7408	lpfc_discovery_threads_init(vport, lpfc_discovery_threads);7409	lpfc_max_luns_init(vport, lpfc_max_luns);7410	lpfc_scan_down_init(vport, lpfc_scan_down);7411	lpfc_enable_da_id_init(vport, lpfc_enable_da_id);7412	return;7413}7414