11f4d4ed6SAlexander Lobakin // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
21e128c81SArun Easi /* QLogic qed NIC Driver
31e128c81SArun Easi  * Copyright (c) 2015-2017  QLogic Corporation
4663eacd8SAlexander Lobakin  * Copyright (c) 2019-2020 Marvell International Ltd.
51e128c81SArun Easi  */
61e128c81SArun Easi 
71e128c81SArun Easi #include <linux/types.h>
81e128c81SArun Easi #include <asm/byteorder.h>
91e128c81SArun Easi #include <asm/param.h>
101e128c81SArun Easi #include <linux/delay.h>
111e128c81SArun Easi #include <linux/dma-mapping.h>
121e128c81SArun Easi #include <linux/interrupt.h>
131e128c81SArun Easi #include <linux/kernel.h>
141e128c81SArun Easi #include <linux/log2.h>
151e128c81SArun Easi #include <linux/module.h>
161e128c81SArun Easi #include <linux/pci.h>
171e128c81SArun Easi #include <linux/slab.h>
181e128c81SArun Easi #include <linux/stddef.h>
191e128c81SArun Easi #include <linux/string.h>
201e128c81SArun Easi #include <linux/workqueue.h>
211e128c81SArun Easi #include <linux/errno.h>
221e128c81SArun Easi #include <linux/list.h>
231e128c81SArun Easi #include <linux/spinlock.h>
241e128c81SArun Easi #define __PREVENT_DUMP_MEM_ARR__
251e128c81SArun Easi #define __PREVENT_PXP_GLOBAL_WIN__
261e128c81SArun Easi #include "qed.h"
271e128c81SArun Easi #include "qed_cxt.h"
281e128c81SArun Easi #include "qed_dev_api.h"
291e128c81SArun Easi #include "qed_fcoe.h"
301e128c81SArun Easi #include "qed_hsi.h"
311e128c81SArun Easi #include "qed_hw.h"
321e128c81SArun Easi #include "qed_int.h"
33ee824f4bSOmkar Kulkarni #include "qed_iro_hsi.h"
341e128c81SArun Easi #include "qed_ll2.h"
351e128c81SArun Easi #include "qed_mcp.h"
361e128c81SArun Easi #include "qed_reg_addr.h"
371e128c81SArun Easi #include "qed_sp.h"
381e128c81SArun Easi #include "qed_sriov.h"
391e128c81SArun Easi #include <linux/qed/qed_fcoe_if.h>
401e128c81SArun Easi 
411e128c81SArun Easi struct qed_fcoe_conn {
421e128c81SArun Easi 	struct list_head list_entry;
431e128c81SArun Easi 	bool free_on_delete;
441e128c81SArun Easi 
451e128c81SArun Easi 	u16 conn_id;
461e128c81SArun Easi 	u32 icid;
471e128c81SArun Easi 	u32 fw_cid;
481e128c81SArun Easi 	u8 layer_code;
491e128c81SArun Easi 
501e128c81SArun Easi 	dma_addr_t sq_pbl_addr;
511e128c81SArun Easi 	dma_addr_t sq_curr_page_addr;
521e128c81SArun Easi 	dma_addr_t sq_next_page_addr;
531e128c81SArun Easi 	dma_addr_t xferq_pbl_addr;
541e128c81SArun Easi 	void *xferq_pbl_addr_virt_addr;
551e128c81SArun Easi 	dma_addr_t xferq_addr[4];
561e128c81SArun Easi 	void *xferq_addr_virt_addr[4];
571e128c81SArun Easi 	dma_addr_t confq_pbl_addr;
581e128c81SArun Easi 	void *confq_pbl_addr_virt_addr;
591e128c81SArun Easi 	dma_addr_t confq_addr[2];
601e128c81SArun Easi 	void *confq_addr_virt_addr[2];
611e128c81SArun Easi 
621e128c81SArun Easi 	dma_addr_t terminate_params;
631e128c81SArun Easi 
641e128c81SArun Easi 	u16 dst_mac_addr_lo;
651e128c81SArun Easi 	u16 dst_mac_addr_mid;
661e128c81SArun Easi 	u16 dst_mac_addr_hi;
671e128c81SArun Easi 	u16 src_mac_addr_lo;
681e128c81SArun Easi 	u16 src_mac_addr_mid;
691e128c81SArun Easi 	u16 src_mac_addr_hi;
701e128c81SArun Easi 
711e128c81SArun Easi 	u16 tx_max_fc_pay_len;
721e128c81SArun Easi 	u16 e_d_tov_timer_val;
731e128c81SArun Easi 	u16 rec_tov_timer_val;
741e128c81SArun Easi 	u16 rx_max_fc_pay_len;
751e128c81SArun Easi 	u16 vlan_tag;
761e128c81SArun Easi 	u16 physical_q0;
771e128c81SArun Easi 
781e128c81SArun Easi 	struct fc_addr_nw s_id;
791e128c81SArun Easi 	u8 max_conc_seqs_c3;
801e128c81SArun Easi 	struct fc_addr_nw d_id;
811e128c81SArun Easi 	u8 flags;
821e128c81SArun Easi 	u8 def_q_idx;
831e128c81SArun Easi };
841e128c81SArun Easi 
851e128c81SArun Easi static int
qed_sp_fcoe_func_start(struct qed_hwfn * p_hwfn,enum spq_mode comp_mode,struct qed_spq_comp_cb * p_comp_addr)861e128c81SArun Easi qed_sp_fcoe_func_start(struct qed_hwfn *p_hwfn,
871e128c81SArun Easi 		       enum spq_mode comp_mode,
881e128c81SArun Easi 		       struct qed_spq_comp_cb *p_comp_addr)
891e128c81SArun Easi {
901e128c81SArun Easi 	struct qed_fcoe_pf_params *fcoe_pf_params = NULL;
911e128c81SArun Easi 	struct fcoe_init_ramrod_params *p_ramrod = NULL;
921e128c81SArun Easi 	struct fcoe_init_func_ramrod_data *p_data;
93fb09a1edSShai Malin 	struct fcoe_conn_context *p_cxt = NULL;
941e128c81SArun Easi 	struct qed_spq_entry *p_ent = NULL;
951e128c81SArun Easi 	struct qed_sp_init_data init_data;
961e128c81SArun Easi 	struct qed_cxt_info cxt_info;
971e128c81SArun Easi 	u32 dummy_cid;
981e128c81SArun Easi 	int rc = 0;
995ab90341SAlexander Lobakin 	__le16 tmp;
1001e128c81SArun Easi 	u8 i;
1011e128c81SArun Easi 
1021e128c81SArun Easi 	/* Get SPQ entry */
1031e128c81SArun Easi 	memset(&init_data, 0, sizeof(init_data));
1041e128c81SArun Easi 	init_data.cid = qed_spq_get_cid(p_hwfn);
1051e128c81SArun Easi 	init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1061e128c81SArun Easi 	init_data.comp_mode = comp_mode;
1071e128c81SArun Easi 	init_data.p_comp_data = p_comp_addr;
1081e128c81SArun Easi 
1091e128c81SArun Easi 	rc = qed_sp_init_request(p_hwfn, &p_ent,
1101e128c81SArun Easi 				 FCOE_RAMROD_CMD_ID_INIT_FUNC,
1111e128c81SArun Easi 				 PROTOCOLID_FCOE, &init_data);
1121e128c81SArun Easi 	if (rc)
1131e128c81SArun Easi 		return rc;
1141e128c81SArun Easi 
1151e128c81SArun Easi 	p_ramrod = &p_ent->ramrod.fcoe_init;
1161e128c81SArun Easi 	p_data = &p_ramrod->init_ramrod_data;
1171e128c81SArun Easi 	fcoe_pf_params = &p_hwfn->pf_params.fcoe_pf_params;
1181e128c81SArun Easi 
1193c5da942SMintz, Yuval 	/* Sanity */
1203c5da942SMintz, Yuval 	if (fcoe_pf_params->num_cqs > p_hwfn->hw_info.feat_num[QED_FCOE_CQ]) {
1213c5da942SMintz, Yuval 		DP_ERR(p_hwfn,
1223c5da942SMintz, Yuval 		       "Cannot satisfy CQ amount. CQs requested %d, CQs available %d. Aborting function start\n",
1233c5da942SMintz, Yuval 		       fcoe_pf_params->num_cqs,
1243c5da942SMintz, Yuval 		       p_hwfn->hw_info.feat_num[QED_FCOE_CQ]);
125fb5e7438SDenis Bolotin 		rc = -EINVAL;
126fb5e7438SDenis Bolotin 		goto err;
1273c5da942SMintz, Yuval 	}
1283c5da942SMintz, Yuval 
1291e128c81SArun Easi 	p_data->mtu = cpu_to_le16(fcoe_pf_params->mtu);
1301e128c81SArun Easi 	tmp = cpu_to_le16(fcoe_pf_params->sq_num_pbl_pages);
1311e128c81SArun Easi 	p_data->sq_num_pages_in_pbl = tmp;
1321e128c81SArun Easi 
1331e128c81SArun Easi 	rc = qed_cxt_acquire_cid(p_hwfn, PROTOCOLID_FCOE, &dummy_cid);
1341e128c81SArun Easi 	if (rc)
135fb5e7438SDenis Bolotin 		goto err;
1361e128c81SArun Easi 
1371e128c81SArun Easi 	cxt_info.iid = dummy_cid;
1381e128c81SArun Easi 	rc = qed_cxt_get_cid_info(p_hwfn, &cxt_info);
1391e128c81SArun Easi 	if (rc) {
1401e128c81SArun Easi 		DP_NOTICE(p_hwfn, "Cannot find context info for dummy cid=%d\n",
1411e128c81SArun Easi 			  dummy_cid);
142fb5e7438SDenis Bolotin 		goto err;
1431e128c81SArun Easi 	}
1441e128c81SArun Easi 	p_cxt = cxt_info.p_cxt;
1456459d936SMichal Kalderon 	memset(p_cxt, 0, sizeof(*p_cxt));
1466459d936SMichal Kalderon 
1471e128c81SArun Easi 	SET_FIELD(p_cxt->tstorm_ag_context.flags3,
148fb09a1edSShai Malin 		  TSTORM_FCOE_CONN_AG_CTX_DUMMY_TIMER_CF_EN, 1);
1491e128c81SArun Easi 
1501e128c81SArun Easi 	fcoe_pf_params->dummy_icid = (u16)dummy_cid;
1511e128c81SArun Easi 
1521e128c81SArun Easi 	tmp = cpu_to_le16(fcoe_pf_params->num_tasks);
1531e128c81SArun Easi 	p_data->func_params.num_tasks = tmp;
1541e128c81SArun Easi 	p_data->func_params.log_page_size = fcoe_pf_params->log_page_size;
1551e128c81SArun Easi 	p_data->func_params.debug_mode = fcoe_pf_params->debug_mode;
1561e128c81SArun Easi 
1571e128c81SArun Easi 	DMA_REGPAIR_LE(p_data->q_params.glbl_q_params_addr,
1581e128c81SArun Easi 		       fcoe_pf_params->glbl_q_params_addr);
1591e128c81SArun Easi 
1601e128c81SArun Easi 	tmp = cpu_to_le16(fcoe_pf_params->cq_num_entries);
1611e128c81SArun Easi 	p_data->q_params.cq_num_entries = tmp;
1621e128c81SArun Easi 
1631e128c81SArun Easi 	tmp = cpu_to_le16(fcoe_pf_params->cmdq_num_entries);
1641e128c81SArun Easi 	p_data->q_params.cmdq_num_entries = tmp;
1651e128c81SArun Easi 
1665ab90341SAlexander Lobakin 	p_data->q_params.num_queues = fcoe_pf_params->num_cqs;
1671e128c81SArun Easi 
1685ab90341SAlexander Lobakin 	tmp = (__force __le16)p_hwfn->hw_info.resc_start[QED_CMDQS_CQS];
1695ab90341SAlexander Lobakin 	p_data->q_params.queue_relative_offset = (__force u8)tmp;
1701e128c81SArun Easi 
1711e128c81SArun Easi 	for (i = 0; i < fcoe_pf_params->num_cqs; i++) {
1725ab90341SAlexander Lobakin 		tmp = cpu_to_le16(qed_get_igu_sb_id(p_hwfn, i));
1731e128c81SArun Easi 		p_data->q_params.cq_cmdq_sb_num_arr[i] = tmp;
1741e128c81SArun Easi 	}
1751e128c81SArun Easi 
1761e128c81SArun Easi 	p_data->q_params.cq_sb_pi = fcoe_pf_params->gl_rq_pi;
1771e128c81SArun Easi 	p_data->q_params.cmdq_sb_pi = fcoe_pf_params->gl_cmd_pi;
1781e128c81SArun Easi 
179d0d40a73SMintz, Yuval 	p_data->q_params.bdq_resource_id = (u8)RESC_START(p_hwfn, QED_BDQ);
1801e128c81SArun Easi 
1811e128c81SArun Easi 	DMA_REGPAIR_LE(p_data->q_params.bdq_pbl_base_address[BDQ_ID_RQ],
1821e128c81SArun Easi 		       fcoe_pf_params->bdq_pbl_base_addr[BDQ_ID_RQ]);
1831e128c81SArun Easi 	p_data->q_params.bdq_pbl_num_entries[BDQ_ID_RQ] =
1841e128c81SArun Easi 	    fcoe_pf_params->bdq_pbl_num_entries[BDQ_ID_RQ];
1855ab90341SAlexander Lobakin 	tmp = cpu_to_le16(fcoe_pf_params->bdq_xoff_threshold[BDQ_ID_RQ]);
1865ab90341SAlexander Lobakin 	p_data->q_params.bdq_xoff_threshold[BDQ_ID_RQ] = tmp;
1875ab90341SAlexander Lobakin 	tmp = cpu_to_le16(fcoe_pf_params->bdq_xon_threshold[BDQ_ID_RQ]);
1885ab90341SAlexander Lobakin 	p_data->q_params.bdq_xon_threshold[BDQ_ID_RQ] = tmp;
1891e128c81SArun Easi 
1901e128c81SArun Easi 	DMA_REGPAIR_LE(p_data->q_params.bdq_pbl_base_address[BDQ_ID_IMM_DATA],
1911e128c81SArun Easi 		       fcoe_pf_params->bdq_pbl_base_addr[BDQ_ID_IMM_DATA]);
1921e128c81SArun Easi 	p_data->q_params.bdq_pbl_num_entries[BDQ_ID_IMM_DATA] =
1931e128c81SArun Easi 	    fcoe_pf_params->bdq_pbl_num_entries[BDQ_ID_IMM_DATA];
1945ab90341SAlexander Lobakin 	tmp = cpu_to_le16(fcoe_pf_params->bdq_xoff_threshold[BDQ_ID_IMM_DATA]);
1955ab90341SAlexander Lobakin 	p_data->q_params.bdq_xoff_threshold[BDQ_ID_IMM_DATA] = tmp;
1965ab90341SAlexander Lobakin 	tmp = cpu_to_le16(fcoe_pf_params->bdq_xon_threshold[BDQ_ID_IMM_DATA]);
1975ab90341SAlexander Lobakin 	p_data->q_params.bdq_xon_threshold[BDQ_ID_IMM_DATA] = tmp;
1985ab90341SAlexander Lobakin 	tmp = cpu_to_le16(fcoe_pf_params->rq_buffer_size);
1995ab90341SAlexander Lobakin 	p_data->q_params.rq_buffer_size = tmp;
2001e128c81SArun Easi 
2011e128c81SArun Easi 	if (fcoe_pf_params->is_target) {
2021e128c81SArun Easi 		SET_FIELD(p_data->q_params.q_validity,
2031e128c81SArun Easi 			  SCSI_INIT_FUNC_QUEUES_RQ_VALID, 1);
2041e128c81SArun Easi 		if (p_data->q_params.bdq_pbl_num_entries[BDQ_ID_IMM_DATA])
2051e128c81SArun Easi 			SET_FIELD(p_data->q_params.q_validity,
2061e128c81SArun Easi 				  SCSI_INIT_FUNC_QUEUES_IMM_DATA_VALID, 1);
2071e128c81SArun Easi 		SET_FIELD(p_data->q_params.q_validity,
2081e128c81SArun Easi 			  SCSI_INIT_FUNC_QUEUES_CMD_VALID, 1);
2091e128c81SArun Easi 	} else {
2101e128c81SArun Easi 		SET_FIELD(p_data->q_params.q_validity,
2111e128c81SArun Easi 			  SCSI_INIT_FUNC_QUEUES_RQ_VALID, 1);
2121e128c81SArun Easi 	}
2131e128c81SArun Easi 
2141e128c81SArun Easi 	rc = qed_spq_post(p_hwfn, p_ent, NULL);
2151e128c81SArun Easi 
2161e128c81SArun Easi 	return rc;
217fb5e7438SDenis Bolotin 
218fb5e7438SDenis Bolotin err:
219fb5e7438SDenis Bolotin 	qed_sp_destroy_request(p_hwfn, p_ent);
220fb5e7438SDenis Bolotin 	return rc;
2211e128c81SArun Easi }
2221e128c81SArun Easi 
2231e128c81SArun Easi static int
qed_sp_fcoe_conn_offload(struct qed_hwfn * p_hwfn,struct qed_fcoe_conn * p_conn,enum spq_mode comp_mode,struct qed_spq_comp_cb * p_comp_addr)2241e128c81SArun Easi qed_sp_fcoe_conn_offload(struct qed_hwfn *p_hwfn,
2251e128c81SArun Easi 			 struct qed_fcoe_conn *p_conn,
2261e128c81SArun Easi 			 enum spq_mode comp_mode,
2271e128c81SArun Easi 			 struct qed_spq_comp_cb *p_comp_addr)
2281e128c81SArun Easi {
2291e128c81SArun Easi 	struct fcoe_conn_offload_ramrod_params *p_ramrod = NULL;
2301e128c81SArun Easi 	struct fcoe_conn_offload_ramrod_data *p_data;
2311e128c81SArun Easi 	struct qed_spq_entry *p_ent = NULL;
2321e128c81SArun Easi 	struct qed_sp_init_data init_data;
2335ab90341SAlexander Lobakin 	u16 physical_q0;
2345ab90341SAlexander Lobakin 	__le16 tmp;
2351e128c81SArun Easi 	int rc;
2361e128c81SArun Easi 
2371e128c81SArun Easi 	/* Get SPQ entry */
2381e128c81SArun Easi 	memset(&init_data, 0, sizeof(init_data));
2391e128c81SArun Easi 	init_data.cid = p_conn->icid;
2401e128c81SArun Easi 	init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
2411e128c81SArun Easi 	init_data.comp_mode = comp_mode;
2421e128c81SArun Easi 	init_data.p_comp_data = p_comp_addr;
2431e128c81SArun Easi 
2441e128c81SArun Easi 	rc = qed_sp_init_request(p_hwfn, &p_ent,
2451e128c81SArun Easi 				 FCOE_RAMROD_CMD_ID_OFFLOAD_CONN,
2461e128c81SArun Easi 				 PROTOCOLID_FCOE, &init_data);
2471e128c81SArun Easi 	if (rc)
2481e128c81SArun Easi 		return rc;
2491e128c81SArun Easi 
2501e128c81SArun Easi 	p_ramrod = &p_ent->ramrod.fcoe_conn_ofld;
2511e128c81SArun Easi 	p_data = &p_ramrod->offload_ramrod_data;
2521e128c81SArun Easi 
2531e128c81SArun Easi 	/* Transmission PQ is the first of the PF */
254b5a9ee7cSAriel Elior 	physical_q0 = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD);
2555ab90341SAlexander Lobakin 	p_conn->physical_q0 = physical_q0;
256b5a9ee7cSAriel Elior 	p_data->physical_q0 = cpu_to_le16(physical_q0);
2571e128c81SArun Easi 
2581e128c81SArun Easi 	p_data->conn_id = cpu_to_le16(p_conn->conn_id);
2591e128c81SArun Easi 	DMA_REGPAIR_LE(p_data->sq_pbl_addr, p_conn->sq_pbl_addr);
2601e128c81SArun Easi 	DMA_REGPAIR_LE(p_data->sq_curr_page_addr, p_conn->sq_curr_page_addr);
2611e128c81SArun Easi 	DMA_REGPAIR_LE(p_data->sq_next_page_addr, p_conn->sq_next_page_addr);
2621e128c81SArun Easi 	DMA_REGPAIR_LE(p_data->xferq_pbl_addr, p_conn->xferq_pbl_addr);
2631e128c81SArun Easi 	DMA_REGPAIR_LE(p_data->xferq_curr_page_addr, p_conn->xferq_addr[0]);
2641e128c81SArun Easi 	DMA_REGPAIR_LE(p_data->xferq_next_page_addr, p_conn->xferq_addr[1]);
2651e128c81SArun Easi 
2661e128c81SArun Easi 	DMA_REGPAIR_LE(p_data->respq_pbl_addr, p_conn->confq_pbl_addr);
2671e128c81SArun Easi 	DMA_REGPAIR_LE(p_data->respq_curr_page_addr, p_conn->confq_addr[0]);
2681e128c81SArun Easi 	DMA_REGPAIR_LE(p_data->respq_next_page_addr, p_conn->confq_addr[1]);
2691e128c81SArun Easi 
2701e128c81SArun Easi 	p_data->dst_mac_addr_lo = cpu_to_le16(p_conn->dst_mac_addr_lo);
2711e128c81SArun Easi 	p_data->dst_mac_addr_mid = cpu_to_le16(p_conn->dst_mac_addr_mid);
2721e128c81SArun Easi 	p_data->dst_mac_addr_hi = cpu_to_le16(p_conn->dst_mac_addr_hi);
2731e128c81SArun Easi 	p_data->src_mac_addr_lo = cpu_to_le16(p_conn->src_mac_addr_lo);
2741e128c81SArun Easi 	p_data->src_mac_addr_mid = cpu_to_le16(p_conn->src_mac_addr_mid);
2751e128c81SArun Easi 	p_data->src_mac_addr_hi = cpu_to_le16(p_conn->src_mac_addr_hi);
2761e128c81SArun Easi 
2771e128c81SArun Easi 	tmp = cpu_to_le16(p_conn->tx_max_fc_pay_len);
2781e128c81SArun Easi 	p_data->tx_max_fc_pay_len = tmp;
2791e128c81SArun Easi 	tmp = cpu_to_le16(p_conn->e_d_tov_timer_val);
2801e128c81SArun Easi 	p_data->e_d_tov_timer_val = tmp;
2811e128c81SArun Easi 	tmp = cpu_to_le16(p_conn->rec_tov_timer_val);
2821e128c81SArun Easi 	p_data->rec_rr_tov_timer_val = tmp;
2831e128c81SArun Easi 	tmp = cpu_to_le16(p_conn->rx_max_fc_pay_len);
2841e128c81SArun Easi 	p_data->rx_max_fc_pay_len = tmp;
2851e128c81SArun Easi 
2861e128c81SArun Easi 	p_data->vlan_tag = cpu_to_le16(p_conn->vlan_tag);
2871e128c81SArun Easi 	p_data->s_id.addr_hi = p_conn->s_id.addr_hi;
2881e128c81SArun Easi 	p_data->s_id.addr_mid = p_conn->s_id.addr_mid;
2891e128c81SArun Easi 	p_data->s_id.addr_lo = p_conn->s_id.addr_lo;
2901e128c81SArun Easi 	p_data->max_conc_seqs_c3 = p_conn->max_conc_seqs_c3;
2911e128c81SArun Easi 	p_data->d_id.addr_hi = p_conn->d_id.addr_hi;
2921e128c81SArun Easi 	p_data->d_id.addr_mid = p_conn->d_id.addr_mid;
2931e128c81SArun Easi 	p_data->d_id.addr_lo = p_conn->d_id.addr_lo;
2941e128c81SArun Easi 	p_data->flags = p_conn->flags;
295cac6f691SSudarsana Reddy Kalluru 	if (test_bit(QED_MF_UFP_SPECIFIC, &p_hwfn->cdev->mf_bits))
296cac6f691SSudarsana Reddy Kalluru 		SET_FIELD(p_data->flags,
297cac6f691SSudarsana Reddy Kalluru 			  FCOE_CONN_OFFLOAD_RAMROD_DATA_B_SINGLE_VLAN, 1);
2981e128c81SArun Easi 	p_data->def_q_idx = p_conn->def_q_idx;
2991e128c81SArun Easi 
3001e128c81SArun Easi 	return qed_spq_post(p_hwfn, p_ent, NULL);
3011e128c81SArun Easi }
3021e128c81SArun Easi 
3031e128c81SArun Easi static int
qed_sp_fcoe_conn_destroy(struct qed_hwfn * p_hwfn,struct qed_fcoe_conn * p_conn,enum spq_mode comp_mode,struct qed_spq_comp_cb * p_comp_addr)3041e128c81SArun Easi qed_sp_fcoe_conn_destroy(struct qed_hwfn *p_hwfn,
3051e128c81SArun Easi 			 struct qed_fcoe_conn *p_conn,
3061e128c81SArun Easi 			 enum spq_mode comp_mode,
3071e128c81SArun Easi 			 struct qed_spq_comp_cb *p_comp_addr)
3081e128c81SArun Easi {
3091e128c81SArun Easi 	struct fcoe_conn_terminate_ramrod_params *p_ramrod = NULL;
3101e128c81SArun Easi 	struct qed_spq_entry *p_ent = NULL;
3111e128c81SArun Easi 	struct qed_sp_init_data init_data;
3121e128c81SArun Easi 	int rc = 0;
3131e128c81SArun Easi 
3141e128c81SArun Easi 	/* Get SPQ entry */
3151e128c81SArun Easi 	memset(&init_data, 0, sizeof(init_data));
3161e128c81SArun Easi 	init_data.cid = p_conn->icid;
3171e128c81SArun Easi 	init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
3181e128c81SArun Easi 	init_data.comp_mode = comp_mode;
3191e128c81SArun Easi 	init_data.p_comp_data = p_comp_addr;
3201e128c81SArun Easi 
3211e128c81SArun Easi 	rc = qed_sp_init_request(p_hwfn, &p_ent,
3221e128c81SArun Easi 				 FCOE_RAMROD_CMD_ID_TERMINATE_CONN,
3231e128c81SArun Easi 				 PROTOCOLID_FCOE, &init_data);
3241e128c81SArun Easi 	if (rc)
3251e128c81SArun Easi 		return rc;
3261e128c81SArun Easi 
3271e128c81SArun Easi 	p_ramrod = &p_ent->ramrod.fcoe_conn_terminate;
3281e128c81SArun Easi 	DMA_REGPAIR_LE(p_ramrod->terminate_ramrod_data.terminate_params_addr,
3291e128c81SArun Easi 		       p_conn->terminate_params);
3301e128c81SArun Easi 
3311e128c81SArun Easi 	return qed_spq_post(p_hwfn, p_ent, NULL);
3321e128c81SArun Easi }
3331e128c81SArun Easi 
3341e128c81SArun Easi static int
qed_sp_fcoe_func_stop(struct qed_hwfn * p_hwfn,struct qed_ptt * p_ptt,enum spq_mode comp_mode,struct qed_spq_comp_cb * p_comp_addr)3351e128c81SArun Easi qed_sp_fcoe_func_stop(struct qed_hwfn *p_hwfn,
33615582962SRahul Verma 		      struct qed_ptt *p_ptt,
3371e128c81SArun Easi 		      enum spq_mode comp_mode,
3381e128c81SArun Easi 		      struct qed_spq_comp_cb *p_comp_addr)
3391e128c81SArun Easi {
3401e128c81SArun Easi 	struct qed_spq_entry *p_ent = NULL;
3411e128c81SArun Easi 	struct qed_sp_init_data init_data;
3421e128c81SArun Easi 	u32 active_segs = 0;
3431e128c81SArun Easi 	int rc = 0;
3441e128c81SArun Easi 
3451e128c81SArun Easi 	/* Get SPQ entry */
3461e128c81SArun Easi 	memset(&init_data, 0, sizeof(init_data));
3471e128c81SArun Easi 	init_data.cid = p_hwfn->pf_params.fcoe_pf_params.dummy_icid;
3481e128c81SArun Easi 	init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
3491e128c81SArun Easi 	init_data.comp_mode = comp_mode;
3501e128c81SArun Easi 	init_data.p_comp_data = p_comp_addr;
3511e128c81SArun Easi 
3521e128c81SArun Easi 	rc = qed_sp_init_request(p_hwfn, &p_ent,
3531e128c81SArun Easi 				 FCOE_RAMROD_CMD_ID_DESTROY_FUNC,
3541e128c81SArun Easi 				 PROTOCOLID_FCOE, &init_data);
3551e128c81SArun Easi 	if (rc)
3561e128c81SArun Easi 		return rc;
3571e128c81SArun Easi 
3581e128c81SArun Easi 	active_segs = qed_rd(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK);
3591e128c81SArun Easi 	active_segs &= ~BIT(QED_CXT_FCOE_TID_SEG);
3601e128c81SArun Easi 	qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, active_segs);
3611e128c81SArun Easi 
3621e128c81SArun Easi 	return qed_spq_post(p_hwfn, p_ent, NULL);
3631e128c81SArun Easi }
3641e128c81SArun Easi 
3651e128c81SArun Easi static int
qed_fcoe_allocate_connection(struct qed_hwfn * p_hwfn,struct qed_fcoe_conn ** p_out_conn)3661e128c81SArun Easi qed_fcoe_allocate_connection(struct qed_hwfn *p_hwfn,
3671e128c81SArun Easi 			     struct qed_fcoe_conn **p_out_conn)
3681e128c81SArun Easi {
3691e128c81SArun Easi 	struct qed_fcoe_conn *p_conn = NULL;
3701e128c81SArun Easi 	void *p_addr;
3711e128c81SArun Easi 	u32 i;
3721e128c81SArun Easi 
3731e128c81SArun Easi 	spin_lock_bh(&p_hwfn->p_fcoe_info->lock);
3741e128c81SArun Easi 	if (!list_empty(&p_hwfn->p_fcoe_info->free_list))
3751e128c81SArun Easi 		p_conn =
3761e128c81SArun Easi 		    list_first_entry(&p_hwfn->p_fcoe_info->free_list,
3771e128c81SArun Easi 				     struct qed_fcoe_conn, list_entry);
3781e128c81SArun Easi 	if (p_conn) {
3791e128c81SArun Easi 		list_del(&p_conn->list_entry);
3801e128c81SArun Easi 		spin_unlock_bh(&p_hwfn->p_fcoe_info->lock);
3811e128c81SArun Easi 		*p_out_conn = p_conn;
3821e128c81SArun Easi 		return 0;
3831e128c81SArun Easi 	}
3841e128c81SArun Easi 	spin_unlock_bh(&p_hwfn->p_fcoe_info->lock);
3851e128c81SArun Easi 
3861e128c81SArun Easi 	p_conn = kzalloc(sizeof(*p_conn), GFP_KERNEL);
3871e128c81SArun Easi 	if (!p_conn)
3881e128c81SArun Easi 		return -ENOMEM;
3891e128c81SArun Easi 
3901e128c81SArun Easi 	p_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
3911e128c81SArun Easi 				    QED_CHAIN_PAGE_SIZE,
3921e128c81SArun Easi 				    &p_conn->xferq_pbl_addr, GFP_KERNEL);
3931e128c81SArun Easi 	if (!p_addr)
3941e128c81SArun Easi 		goto nomem_pbl_xferq;
3951e128c81SArun Easi 	p_conn->xferq_pbl_addr_virt_addr = p_addr;
3961e128c81SArun Easi 
3971e128c81SArun Easi 	for (i = 0; i < ARRAY_SIZE(p_conn->xferq_addr); i++) {
3981e128c81SArun Easi 		p_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
3991e128c81SArun Easi 					    QED_CHAIN_PAGE_SIZE,
4001e128c81SArun Easi 					    &p_conn->xferq_addr[i], GFP_KERNEL);
4011e128c81SArun Easi 		if (!p_addr)
4021e128c81SArun Easi 			goto nomem_xferq;
4031e128c81SArun Easi 		p_conn->xferq_addr_virt_addr[i] = p_addr;
4041e128c81SArun Easi 
4051e128c81SArun Easi 		p_addr = p_conn->xferq_pbl_addr_virt_addr;
4061e128c81SArun Easi 		((dma_addr_t *)p_addr)[i] = p_conn->xferq_addr[i];
4071e128c81SArun Easi 	}
4081e128c81SArun Easi 
4091e128c81SArun Easi 	p_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
4101e128c81SArun Easi 				    QED_CHAIN_PAGE_SIZE,
4111e128c81SArun Easi 				    &p_conn->confq_pbl_addr, GFP_KERNEL);
4121e128c81SArun Easi 	if (!p_addr)
4131e128c81SArun Easi 		goto nomem_xferq;
4141e128c81SArun Easi 	p_conn->confq_pbl_addr_virt_addr = p_addr;
4151e128c81SArun Easi 
4161e128c81SArun Easi 	for (i = 0; i < ARRAY_SIZE(p_conn->confq_addr); i++) {
4171e128c81SArun Easi 		p_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
4181e128c81SArun Easi 					    QED_CHAIN_PAGE_SIZE,
4191e128c81SArun Easi 					    &p_conn->confq_addr[i], GFP_KERNEL);
4201e128c81SArun Easi 		if (!p_addr)
4211e128c81SArun Easi 			goto nomem_confq;
4221e128c81SArun Easi 		p_conn->confq_addr_virt_addr[i] = p_addr;
4231e128c81SArun Easi 
4241e128c81SArun Easi 		p_addr = p_conn->confq_pbl_addr_virt_addr;
4251e128c81SArun Easi 		((dma_addr_t *)p_addr)[i] = p_conn->confq_addr[i];
4261e128c81SArun Easi 	}
4271e128c81SArun Easi 
4281e128c81SArun Easi 	p_conn->free_on_delete = true;
4291e128c81SArun Easi 	*p_out_conn = p_conn;
4301e128c81SArun Easi 	return 0;
4311e128c81SArun Easi 
4321e128c81SArun Easi nomem_confq:
4331e128c81SArun Easi 	dma_free_coherent(&p_hwfn->cdev->pdev->dev,
4341e128c81SArun Easi 			  QED_CHAIN_PAGE_SIZE,
4351e128c81SArun Easi 			  p_conn->confq_pbl_addr_virt_addr,
4361e128c81SArun Easi 			  p_conn->confq_pbl_addr);
4371e128c81SArun Easi 	for (i = 0; i < ARRAY_SIZE(p_conn->confq_addr); i++)
4381e128c81SArun Easi 		if (p_conn->confq_addr_virt_addr[i])
4391e128c81SArun Easi 			dma_free_coherent(&p_hwfn->cdev->pdev->dev,
4401e128c81SArun Easi 					  QED_CHAIN_PAGE_SIZE,
4411e128c81SArun Easi 					  p_conn->confq_addr_virt_addr[i],
4421e128c81SArun Easi 					  p_conn->confq_addr[i]);
4431e128c81SArun Easi nomem_xferq:
4441e128c81SArun Easi 	dma_free_coherent(&p_hwfn->cdev->pdev->dev,
4451e128c81SArun Easi 			  QED_CHAIN_PAGE_SIZE,
4461e128c81SArun Easi 			  p_conn->xferq_pbl_addr_virt_addr,
4471e128c81SArun Easi 			  p_conn->xferq_pbl_addr);
4481e128c81SArun Easi 	for (i = 0; i < ARRAY_SIZE(p_conn->xferq_addr); i++)
4491e128c81SArun Easi 		if (p_conn->xferq_addr_virt_addr[i])
4501e128c81SArun Easi 			dma_free_coherent(&p_hwfn->cdev->pdev->dev,
4511e128c81SArun Easi 					  QED_CHAIN_PAGE_SIZE,
4521e128c81SArun Easi 					  p_conn->xferq_addr_virt_addr[i],
4531e128c81SArun Easi 					  p_conn->xferq_addr[i]);
4541e128c81SArun Easi nomem_pbl_xferq:
4551e128c81SArun Easi 	kfree(p_conn);
4561e128c81SArun Easi 	return -ENOMEM;
4571e128c81SArun Easi }
4581e128c81SArun Easi 
qed_fcoe_free_connection(struct qed_hwfn * p_hwfn,struct qed_fcoe_conn * p_conn)4591e128c81SArun Easi static void qed_fcoe_free_connection(struct qed_hwfn *p_hwfn,
4601e128c81SArun Easi 				     struct qed_fcoe_conn *p_conn)
4611e128c81SArun Easi {
4621e128c81SArun Easi 	u32 i;
4631e128c81SArun Easi 
4641e128c81SArun Easi 	if (!p_conn)
4651e128c81SArun Easi 		return;
4661e128c81SArun Easi 
4671e128c81SArun Easi 	if (p_conn->confq_pbl_addr_virt_addr)
4681e128c81SArun Easi 		dma_free_coherent(&p_hwfn->cdev->pdev->dev,
4691e128c81SArun Easi 				  QED_CHAIN_PAGE_SIZE,
4701e128c81SArun Easi 				  p_conn->confq_pbl_addr_virt_addr,
4711e128c81SArun Easi 				  p_conn->confq_pbl_addr);
4721e128c81SArun Easi 
4731e128c81SArun Easi 	for (i = 0; i < ARRAY_SIZE(p_conn->confq_addr); i++) {
4741e128c81SArun Easi 		if (!p_conn->confq_addr_virt_addr[i])
4751e128c81SArun Easi 			continue;
4761e128c81SArun Easi 		dma_free_coherent(&p_hwfn->cdev->pdev->dev,
4771e128c81SArun Easi 				  QED_CHAIN_PAGE_SIZE,
4781e128c81SArun Easi 				  p_conn->confq_addr_virt_addr[i],
4791e128c81SArun Easi 				  p_conn->confq_addr[i]);
4801e128c81SArun Easi 	}
4811e128c81SArun Easi 
4821e128c81SArun Easi 	if (p_conn->xferq_pbl_addr_virt_addr)
4831e128c81SArun Easi 		dma_free_coherent(&p_hwfn->cdev->pdev->dev,
4841e128c81SArun Easi 				  QED_CHAIN_PAGE_SIZE,
4851e128c81SArun Easi 				  p_conn->xferq_pbl_addr_virt_addr,
4861e128c81SArun Easi 				  p_conn->xferq_pbl_addr);
4871e128c81SArun Easi 
4881e128c81SArun Easi 	for (i = 0; i < ARRAY_SIZE(p_conn->xferq_addr); i++) {
4891e128c81SArun Easi 		if (!p_conn->xferq_addr_virt_addr[i])
4901e128c81SArun Easi 			continue;
4911e128c81SArun Easi 		dma_free_coherent(&p_hwfn->cdev->pdev->dev,
4921e128c81SArun Easi 				  QED_CHAIN_PAGE_SIZE,
4931e128c81SArun Easi 				  p_conn->xferq_addr_virt_addr[i],
4941e128c81SArun Easi 				  p_conn->xferq_addr[i]);
4951e128c81SArun Easi 	}
4961e128c81SArun Easi 	kfree(p_conn);
4971e128c81SArun Easi }
4981e128c81SArun Easi 
qed_fcoe_get_db_addr(struct qed_hwfn * p_hwfn,u32 cid)4991e128c81SArun Easi static void __iomem *qed_fcoe_get_db_addr(struct qed_hwfn *p_hwfn, u32 cid)
5001e128c81SArun Easi {
5011e128c81SArun Easi 	return (u8 __iomem *)p_hwfn->doorbells +
5021e128c81SArun Easi 	       qed_db_addr(cid, DQ_DEMS_LEGACY);
5031e128c81SArun Easi }
5041e128c81SArun Easi 
qed_fcoe_get_primary_bdq_prod(struct qed_hwfn * p_hwfn,u8 bdq_id)5051e128c81SArun Easi static void __iomem *qed_fcoe_get_primary_bdq_prod(struct qed_hwfn *p_hwfn,
5061e128c81SArun Easi 						   u8 bdq_id)
5071e128c81SArun Easi {
508d0d40a73SMintz, Yuval 	if (RESC_NUM(p_hwfn, QED_BDQ)) {
509d0d40a73SMintz, Yuval 		return (u8 __iomem *)p_hwfn->regview +
510e2dbc223SPrabhakar Kushwaha 		    GET_GTT_BDQ_REG_ADDR(GTT_BAR0_MAP_REG_MSDM_RAM,
511e2dbc223SPrabhakar Kushwaha 					 MSTORM_SCSI_BDQ_EXT_PROD,
512e2dbc223SPrabhakar Kushwaha 					 RESC_START(p_hwfn, QED_BDQ), bdq_id);
513d0d40a73SMintz, Yuval 	} else {
514d0d40a73SMintz, Yuval 		DP_NOTICE(p_hwfn, "BDQ is not allocated!\n");
515d0d40a73SMintz, Yuval 		return NULL;
516d0d40a73SMintz, Yuval 	}
5171e128c81SArun Easi }
5181e128c81SArun Easi 
qed_fcoe_get_secondary_bdq_prod(struct qed_hwfn * p_hwfn,u8 bdq_id)5191e128c81SArun Easi static void __iomem *qed_fcoe_get_secondary_bdq_prod(struct qed_hwfn *p_hwfn,
5201e128c81SArun Easi 						     u8 bdq_id)
5211e128c81SArun Easi {
522d0d40a73SMintz, Yuval 	if (RESC_NUM(p_hwfn, QED_BDQ)) {
523d0d40a73SMintz, Yuval 		return (u8 __iomem *)p_hwfn->regview +
524e2dbc223SPrabhakar Kushwaha 		    GET_GTT_BDQ_REG_ADDR(GTT_BAR0_MAP_REG_TSDM_RAM,
525e2dbc223SPrabhakar Kushwaha 					 TSTORM_SCSI_BDQ_EXT_PROD,
526e2dbc223SPrabhakar Kushwaha 					 RESC_START(p_hwfn, QED_BDQ), bdq_id);
527d0d40a73SMintz, Yuval 	} else {
528d0d40a73SMintz, Yuval 		DP_NOTICE(p_hwfn, "BDQ is not allocated!\n");
529d0d40a73SMintz, Yuval 		return NULL;
530d0d40a73SMintz, Yuval 	}
5311e128c81SArun Easi }
5321e128c81SArun Easi 
qed_fcoe_alloc(struct qed_hwfn * p_hwfn)5333587cb87STomer Tayar int qed_fcoe_alloc(struct qed_hwfn *p_hwfn)
5341e128c81SArun Easi {
5351e128c81SArun Easi 	struct qed_fcoe_info *p_fcoe_info;
5361e128c81SArun Easi 
5371e128c81SArun Easi 	/* Allocate LL2's set struct */
5381e128c81SArun Easi 	p_fcoe_info = kzalloc(sizeof(*p_fcoe_info), GFP_KERNEL);
5391e128c81SArun Easi 	if (!p_fcoe_info) {
5401e128c81SArun Easi 		DP_NOTICE(p_hwfn, "Failed to allocate qed_fcoe_info'\n");
5413587cb87STomer Tayar 		return -ENOMEM;
5421e128c81SArun Easi 	}
5431e128c81SArun Easi 	INIT_LIST_HEAD(&p_fcoe_info->free_list);
5443587cb87STomer Tayar 
5453587cb87STomer Tayar 	p_hwfn->p_fcoe_info = p_fcoe_info;
5463587cb87STomer Tayar 	return 0;
5471e128c81SArun Easi }
5481e128c81SArun Easi 
qed_fcoe_setup(struct qed_hwfn * p_hwfn)5493587cb87STomer Tayar void qed_fcoe_setup(struct qed_hwfn *p_hwfn)
5501e128c81SArun Easi {
551fb09a1edSShai Malin 	struct fcoe_task_context *p_task_ctx = NULL;
5525ab90341SAlexander Lobakin 	u32 i, lc;
5531e128c81SArun Easi 	int rc;
5541e128c81SArun Easi 
5553587cb87STomer Tayar 	spin_lock_init(&p_hwfn->p_fcoe_info->lock);
5561e128c81SArun Easi 	for (i = 0; i < p_hwfn->pf_params.fcoe_pf_params.num_tasks; i++) {
5571e128c81SArun Easi 		rc = qed_cxt_get_task_ctx(p_hwfn, i,
5581e128c81SArun Easi 					  QED_CTX_WORKING_MEM,
5591e128c81SArun Easi 					  (void **)&p_task_ctx);
5601e128c81SArun Easi 		if (rc)
5611e128c81SArun Easi 			continue;
5621e128c81SArun Easi 
563fb09a1edSShai Malin 		memset(p_task_ctx, 0, sizeof(struct fcoe_task_context));
5645ab90341SAlexander Lobakin 
5655ab90341SAlexander Lobakin 		lc = 0;
5665ab90341SAlexander Lobakin 		SET_FIELD(lc, TIMERS_CONTEXT_VALIDLC0, 1);
5675ab90341SAlexander Lobakin 		p_task_ctx->timer_context.logical_client_0 = cpu_to_le32(lc);
5685ab90341SAlexander Lobakin 
5695ab90341SAlexander Lobakin 		lc = 0;
5705ab90341SAlexander Lobakin 		SET_FIELD(lc, TIMERS_CONTEXT_VALIDLC1, 1);
5715ab90341SAlexander Lobakin 		p_task_ctx->timer_context.logical_client_1 = cpu_to_le32(lc);
5725ab90341SAlexander Lobakin 
5731e128c81SArun Easi 		SET_FIELD(p_task_ctx->tstorm_ag_context.flags0,
574fb09a1edSShai Malin 			  TSTORM_FCOE_TASK_AG_CTX_CONNECTION_TYPE, 1);
5751e128c81SArun Easi 	}
5761e128c81SArun Easi }
5771e128c81SArun Easi 
qed_fcoe_free(struct qed_hwfn * p_hwfn)5783587cb87STomer Tayar void qed_fcoe_free(struct qed_hwfn *p_hwfn)
5791e128c81SArun Easi {
5801e128c81SArun Easi 	struct qed_fcoe_conn *p_conn = NULL;
5811e128c81SArun Easi 
5823587cb87STomer Tayar 	if (!p_hwfn->p_fcoe_info)
5831e128c81SArun Easi 		return;
5841e128c81SArun Easi 
5853587cb87STomer Tayar 	while (!list_empty(&p_hwfn->p_fcoe_info->free_list)) {
5863587cb87STomer Tayar 		p_conn = list_first_entry(&p_hwfn->p_fcoe_info->free_list,
5871e128c81SArun Easi 					  struct qed_fcoe_conn, list_entry);
5881e128c81SArun Easi 		if (!p_conn)
5891e128c81SArun Easi 			break;
5901e128c81SArun Easi 		list_del(&p_conn->list_entry);
5911e128c81SArun Easi 		qed_fcoe_free_connection(p_hwfn, p_conn);
5921e128c81SArun Easi 	}
5931e128c81SArun Easi 
5943587cb87STomer Tayar 	kfree(p_hwfn->p_fcoe_info);
5953587cb87STomer Tayar 	p_hwfn->p_fcoe_info = NULL;
5961e128c81SArun Easi }
5971e128c81SArun Easi 
5981e128c81SArun Easi static int
qed_fcoe_acquire_connection(struct qed_hwfn * p_hwfn,struct qed_fcoe_conn * p_in_conn,struct qed_fcoe_conn ** p_out_conn)5991e128c81SArun Easi qed_fcoe_acquire_connection(struct qed_hwfn *p_hwfn,
6001e128c81SArun Easi 			    struct qed_fcoe_conn *p_in_conn,
6011e128c81SArun Easi 			    struct qed_fcoe_conn **p_out_conn)
6021e128c81SArun Easi {
6031e128c81SArun Easi 	struct qed_fcoe_conn *p_conn = NULL;
6041e128c81SArun Easi 	int rc = 0;
6051e128c81SArun Easi 	u32 icid;
6061e128c81SArun Easi 
6071e128c81SArun Easi 	spin_lock_bh(&p_hwfn->p_fcoe_info->lock);
6081e128c81SArun Easi 	rc = qed_cxt_acquire_cid(p_hwfn, PROTOCOLID_FCOE, &icid);
6091e128c81SArun Easi 	spin_unlock_bh(&p_hwfn->p_fcoe_info->lock);
6101e128c81SArun Easi 	if (rc)
6111e128c81SArun Easi 		return rc;
6121e128c81SArun Easi 
6131e128c81SArun Easi 	/* Use input connection [if provided] or allocate a new one */
6141e128c81SArun Easi 	if (p_in_conn) {
6151e128c81SArun Easi 		p_conn = p_in_conn;
6161e128c81SArun Easi 	} else {
6171e128c81SArun Easi 		rc = qed_fcoe_allocate_connection(p_hwfn, &p_conn);
6181e128c81SArun Easi 		if (rc) {
6191e128c81SArun Easi 			spin_lock_bh(&p_hwfn->p_fcoe_info->lock);
6201e128c81SArun Easi 			qed_cxt_release_cid(p_hwfn, icid);
6211e128c81SArun Easi 			spin_unlock_bh(&p_hwfn->p_fcoe_info->lock);
6221e128c81SArun Easi 			return rc;
6231e128c81SArun Easi 		}
6241e128c81SArun Easi 	}
6251e128c81SArun Easi 
6261e128c81SArun Easi 	p_conn->icid = icid;
6271e128c81SArun Easi 	p_conn->fw_cid = (p_hwfn->hw_info.opaque_fid << 16) | icid;
6281e128c81SArun Easi 	*p_out_conn = p_conn;
6291e128c81SArun Easi 
6301e128c81SArun Easi 	return rc;
6311e128c81SArun Easi }
6321e128c81SArun Easi 
qed_fcoe_release_connection(struct qed_hwfn * p_hwfn,struct qed_fcoe_conn * p_conn)6331e128c81SArun Easi static void qed_fcoe_release_connection(struct qed_hwfn *p_hwfn,
6341e128c81SArun Easi 					struct qed_fcoe_conn *p_conn)
6351e128c81SArun Easi {
6361e128c81SArun Easi 	spin_lock_bh(&p_hwfn->p_fcoe_info->lock);
6371e128c81SArun Easi 	list_add_tail(&p_conn->list_entry, &p_hwfn->p_fcoe_info->free_list);
6381e128c81SArun Easi 	qed_cxt_release_cid(p_hwfn, p_conn->icid);
6391e128c81SArun Easi 	spin_unlock_bh(&p_hwfn->p_fcoe_info->lock);
6401e128c81SArun Easi }
6411e128c81SArun Easi 
_qed_fcoe_get_tstats(struct qed_hwfn * p_hwfn,struct qed_ptt * p_ptt,struct qed_fcoe_stats * p_stats)6421e128c81SArun Easi static void _qed_fcoe_get_tstats(struct qed_hwfn *p_hwfn,
6431e128c81SArun Easi 				 struct qed_ptt *p_ptt,
6441e128c81SArun Easi 				 struct qed_fcoe_stats *p_stats)
6451e128c81SArun Easi {
6461e128c81SArun Easi 	struct fcoe_rx_stat tstats;
6471e128c81SArun Easi 	u32 tstats_addr;
6481e128c81SArun Easi 
6491e128c81SArun Easi 	memset(&tstats, 0, sizeof(tstats));
6501e128c81SArun Easi 	tstats_addr = BAR0_MAP_REG_TSDM_RAM +
6511e128c81SArun Easi 	    TSTORM_FCOE_RX_STATS_OFFSET(p_hwfn->rel_pf_id);
6521e128c81SArun Easi 	qed_memcpy_from(p_hwfn, p_ptt, &tstats, tstats_addr, sizeof(tstats));
6531e128c81SArun Easi 
6541e128c81SArun Easi 	p_stats->fcoe_rx_byte_cnt = HILO_64_REGPAIR(tstats.fcoe_rx_byte_cnt);
6551e128c81SArun Easi 	p_stats->fcoe_rx_data_pkt_cnt =
6561e128c81SArun Easi 	    HILO_64_REGPAIR(tstats.fcoe_rx_data_pkt_cnt);
6571e128c81SArun Easi 	p_stats->fcoe_rx_xfer_pkt_cnt =
6581e128c81SArun Easi 	    HILO_64_REGPAIR(tstats.fcoe_rx_xfer_pkt_cnt);
6591e128c81SArun Easi 	p_stats->fcoe_rx_other_pkt_cnt =
6601e128c81SArun Easi 	    HILO_64_REGPAIR(tstats.fcoe_rx_other_pkt_cnt);
6611e128c81SArun Easi 
6621e128c81SArun Easi 	p_stats->fcoe_silent_drop_pkt_cmdq_full_cnt =
6631e128c81SArun Easi 	    le32_to_cpu(tstats.fcoe_silent_drop_pkt_cmdq_full_cnt);
6641e128c81SArun Easi 	p_stats->fcoe_silent_drop_pkt_rq_full_cnt =
6651e128c81SArun Easi 	    le32_to_cpu(tstats.fcoe_silent_drop_pkt_rq_full_cnt);
6661e128c81SArun Easi 	p_stats->fcoe_silent_drop_pkt_crc_error_cnt =
6671e128c81SArun Easi 	    le32_to_cpu(tstats.fcoe_silent_drop_pkt_crc_error_cnt);
6681e128c81SArun Easi 	p_stats->fcoe_silent_drop_pkt_task_invalid_cnt =
6691e128c81SArun Easi 	    le32_to_cpu(tstats.fcoe_silent_drop_pkt_task_invalid_cnt);
6701e128c81SArun Easi 	p_stats->fcoe_silent_drop_total_pkt_cnt =
6711e128c81SArun Easi 	    le32_to_cpu(tstats.fcoe_silent_drop_total_pkt_cnt);
6721e128c81SArun Easi }
6731e128c81SArun Easi 
_qed_fcoe_get_pstats(struct qed_hwfn * p_hwfn,struct qed_ptt * p_ptt,struct qed_fcoe_stats * p_stats)6741e128c81SArun Easi static void _qed_fcoe_get_pstats(struct qed_hwfn *p_hwfn,
6751e128c81SArun Easi 				 struct qed_ptt *p_ptt,
6761e128c81SArun Easi 				 struct qed_fcoe_stats *p_stats)
6771e128c81SArun Easi {
6781e128c81SArun Easi 	struct fcoe_tx_stat pstats;
6791e128c81SArun Easi 	u32 pstats_addr;
6801e128c81SArun Easi 
6811e128c81SArun Easi 	memset(&pstats, 0, sizeof(pstats));
6821e128c81SArun Easi 	pstats_addr = BAR0_MAP_REG_PSDM_RAM +
6831e128c81SArun Easi 	    PSTORM_FCOE_TX_STATS_OFFSET(p_hwfn->rel_pf_id);
6841e128c81SArun Easi 	qed_memcpy_from(p_hwfn, p_ptt, &pstats, pstats_addr, sizeof(pstats));
6851e128c81SArun Easi 
6861e128c81SArun Easi 	p_stats->fcoe_tx_byte_cnt = HILO_64_REGPAIR(pstats.fcoe_tx_byte_cnt);
6871e128c81SArun Easi 	p_stats->fcoe_tx_data_pkt_cnt =
6881e128c81SArun Easi 	    HILO_64_REGPAIR(pstats.fcoe_tx_data_pkt_cnt);
6891e128c81SArun Easi 	p_stats->fcoe_tx_xfer_pkt_cnt =
6901e128c81SArun Easi 	    HILO_64_REGPAIR(pstats.fcoe_tx_xfer_pkt_cnt);
6911e128c81SArun Easi 	p_stats->fcoe_tx_other_pkt_cnt =
6921e128c81SArun Easi 	    HILO_64_REGPAIR(pstats.fcoe_tx_other_pkt_cnt);
6931e128c81SArun Easi }
6941e128c81SArun Easi 
qed_fcoe_get_stats(struct qed_hwfn * p_hwfn,struct qed_fcoe_stats * p_stats,bool is_atomic)6951e128c81SArun Easi static int qed_fcoe_get_stats(struct qed_hwfn *p_hwfn,
696*e346e231SKonstantin Khorenko 			      struct qed_fcoe_stats *p_stats,
697*e346e231SKonstantin Khorenko 			      bool is_atomic)
6981e128c81SArun Easi {
6991e128c81SArun Easi 	struct qed_ptt *p_ptt;
7001e128c81SArun Easi 
7011e128c81SArun Easi 	memset(p_stats, 0, sizeof(*p_stats));
7021e128c81SArun Easi 
703*e346e231SKonstantin Khorenko 	p_ptt = qed_ptt_acquire_context(p_hwfn, is_atomic);
7041e128c81SArun Easi 
7051e128c81SArun Easi 	if (!p_ptt) {
7061e128c81SArun Easi 		DP_ERR(p_hwfn, "Failed to acquire ptt\n");
7071e128c81SArun Easi 		return -EINVAL;
7081e128c81SArun Easi 	}
7091e128c81SArun Easi 
7101e128c81SArun Easi 	_qed_fcoe_get_tstats(p_hwfn, p_ptt, p_stats);
7111e128c81SArun Easi 	_qed_fcoe_get_pstats(p_hwfn, p_ptt, p_stats);
7121e128c81SArun Easi 
7131e128c81SArun Easi 	qed_ptt_release(p_hwfn, p_ptt);
7141e128c81SArun Easi 
7151e128c81SArun Easi 	return 0;
7161e128c81SArun Easi }
7171e128c81SArun Easi 
7181e128c81SArun Easi struct qed_hash_fcoe_con {
7191e128c81SArun Easi 	struct hlist_node node;
7201e128c81SArun Easi 	struct qed_fcoe_conn *con;
7211e128c81SArun Easi };
7221e128c81SArun Easi 
qed_fill_fcoe_dev_info(struct qed_dev * cdev,struct qed_dev_fcoe_info * info)7231e128c81SArun Easi static int qed_fill_fcoe_dev_info(struct qed_dev *cdev,
7241e128c81SArun Easi 				  struct qed_dev_fcoe_info *info)
7251e128c81SArun Easi {
7267e50769cSMichal Kalderon 	struct qed_hwfn *hwfn = QED_AFFIN_HWFN(cdev);
7271e128c81SArun Easi 	int rc;
7281e128c81SArun Easi 
7291e128c81SArun Easi 	memset(info, 0, sizeof(*info));
7301e128c81SArun Easi 	rc = qed_fill_dev_info(cdev, &info->common);
7311e128c81SArun Easi 
7321e128c81SArun Easi 	info->primary_dbq_rq_addr =
7331e128c81SArun Easi 	    qed_fcoe_get_primary_bdq_prod(hwfn, BDQ_ID_RQ);
7341e128c81SArun Easi 	info->secondary_bdq_rq_addr =
7351e128c81SArun Easi 	    qed_fcoe_get_secondary_bdq_prod(hwfn, BDQ_ID_RQ);
7361e128c81SArun Easi 
7373c5da942SMintz, Yuval 	info->wwpn = hwfn->mcp_info->func_info.wwn_port;
7383c5da942SMintz, Yuval 	info->wwnn = hwfn->mcp_info->func_info.wwn_node;
7393c5da942SMintz, Yuval 
7403c5da942SMintz, Yuval 	info->num_cqs = FEAT_NUM(hwfn, QED_FCOE_CQ);
7413c5da942SMintz, Yuval 
7421e128c81SArun Easi 	return rc;
7431e128c81SArun Easi }
7441e128c81SArun Easi 
qed_register_fcoe_ops(struct qed_dev * cdev,struct qed_fcoe_cb_ops * ops,void * cookie)7451e128c81SArun Easi static void qed_register_fcoe_ops(struct qed_dev *cdev,
7461e128c81SArun Easi 				  struct qed_fcoe_cb_ops *ops, void *cookie)
7471e128c81SArun Easi {
7481e128c81SArun Easi 	cdev->protocol_ops.fcoe = ops;
7491e128c81SArun Easi 	cdev->ops_cookie = cookie;
7501e128c81SArun Easi }
7511e128c81SArun Easi 
qed_fcoe_get_hash(struct qed_dev * cdev,u32 handle)7521e128c81SArun Easi static struct qed_hash_fcoe_con *qed_fcoe_get_hash(struct qed_dev *cdev,
7531e128c81SArun Easi 						   u32 handle)
7541e128c81SArun Easi {
7551e128c81SArun Easi 	struct qed_hash_fcoe_con *hash_con = NULL;
7561e128c81SArun Easi 
7571e128c81SArun Easi 	if (!(cdev->flags & QED_FLAG_STORAGE_STARTED))
7581e128c81SArun Easi 		return NULL;
7591e128c81SArun Easi 
7601e128c81SArun Easi 	hash_for_each_possible(cdev->connections, hash_con, node, handle) {
7611e128c81SArun Easi 		if (hash_con->con->icid == handle)
7621e128c81SArun Easi 			break;
7631e128c81SArun Easi 	}
7641e128c81SArun Easi 
7651e128c81SArun Easi 	if (!hash_con || (hash_con->con->icid != handle))
7661e128c81SArun Easi 		return NULL;
7671e128c81SArun Easi 
7681e128c81SArun Easi 	return hash_con;
7691e128c81SArun Easi }
7701e128c81SArun Easi 
qed_fcoe_stop(struct qed_dev * cdev)7711e128c81SArun Easi static int qed_fcoe_stop(struct qed_dev *cdev)
7721e128c81SArun Easi {
77315582962SRahul Verma 	struct qed_ptt *p_ptt;
7741e128c81SArun Easi 	int rc;
7751e128c81SArun Easi 
7761e128c81SArun Easi 	if (!(cdev->flags & QED_FLAG_STORAGE_STARTED)) {
7771e128c81SArun Easi 		DP_NOTICE(cdev, "fcoe already stopped\n");
7781e128c81SArun Easi 		return 0;
7791e128c81SArun Easi 	}
7801e128c81SArun Easi 
7811e128c81SArun Easi 	if (!hash_empty(cdev->connections)) {
7821e128c81SArun Easi 		DP_NOTICE(cdev,
7831e128c81SArun Easi 			  "Can't stop fcoe - not all connections were returned\n");
7841e128c81SArun Easi 		return -EINVAL;
7851e128c81SArun Easi 	}
7861e128c81SArun Easi 
7877e50769cSMichal Kalderon 	p_ptt = qed_ptt_acquire(QED_AFFIN_HWFN(cdev));
78815582962SRahul Verma 	if (!p_ptt)
78915582962SRahul Verma 		return -EAGAIN;
79015582962SRahul Verma 
7911e128c81SArun Easi 	/* Stop the fcoe */
7927e50769cSMichal Kalderon 	rc = qed_sp_fcoe_func_stop(QED_AFFIN_HWFN(cdev), p_ptt,
7931e128c81SArun Easi 				   QED_SPQ_MODE_EBLOCK, NULL);
7941e128c81SArun Easi 	cdev->flags &= ~QED_FLAG_STORAGE_STARTED;
7957e50769cSMichal Kalderon 	qed_ptt_release(QED_AFFIN_HWFN(cdev), p_ptt);
7961e128c81SArun Easi 
7971e128c81SArun Easi 	return rc;
7981e128c81SArun Easi }
7991e128c81SArun Easi 
qed_fcoe_start(struct qed_dev * cdev,struct qed_fcoe_tid * tasks)8001e128c81SArun Easi static int qed_fcoe_start(struct qed_dev *cdev, struct qed_fcoe_tid *tasks)
8011e128c81SArun Easi {
8021e128c81SArun Easi 	int rc;
8031e128c81SArun Easi 
8041e128c81SArun Easi 	if (cdev->flags & QED_FLAG_STORAGE_STARTED) {
8051e128c81SArun Easi 		DP_NOTICE(cdev, "fcoe already started;\n");
8061e128c81SArun Easi 		return 0;
8071e128c81SArun Easi 	}
8081e128c81SArun Easi 
8097e50769cSMichal Kalderon 	rc = qed_sp_fcoe_func_start(QED_AFFIN_HWFN(cdev), QED_SPQ_MODE_EBLOCK,
8107e50769cSMichal Kalderon 				    NULL);
8111e128c81SArun Easi 	if (rc) {
8121e128c81SArun Easi 		DP_NOTICE(cdev, "Failed to start fcoe\n");
8131e128c81SArun Easi 		return rc;
8141e128c81SArun Easi 	}
8151e128c81SArun Easi 
8161e128c81SArun Easi 	cdev->flags |= QED_FLAG_STORAGE_STARTED;
8171e128c81SArun Easi 	hash_init(cdev->connections);
8181e128c81SArun Easi 
8191e128c81SArun Easi 	if (tasks) {
8201e128c81SArun Easi 		struct qed_tid_mem *tid_info = kzalloc(sizeof(*tid_info),
8211e128c81SArun Easi 						       GFP_ATOMIC);
8221e128c81SArun Easi 
8231e128c81SArun Easi 		if (!tid_info) {
8241e128c81SArun Easi 			DP_NOTICE(cdev,
8251e128c81SArun Easi 				  "Failed to allocate tasks information\n");
8261e128c81SArun Easi 			qed_fcoe_stop(cdev);
8271e128c81SArun Easi 			return -ENOMEM;
8281e128c81SArun Easi 		}
8291e128c81SArun Easi 
8307e50769cSMichal Kalderon 		rc = qed_cxt_get_tid_mem_info(QED_AFFIN_HWFN(cdev), tid_info);
8311e128c81SArun Easi 		if (rc) {
8321e128c81SArun Easi 			DP_NOTICE(cdev, "Failed to gather task information\n");
8331e128c81SArun Easi 			qed_fcoe_stop(cdev);
8341e128c81SArun Easi 			kfree(tid_info);
8351e128c81SArun Easi 			return rc;
8361e128c81SArun Easi 		}
8371e128c81SArun Easi 
8381e128c81SArun Easi 		/* Fill task information */
8391e128c81SArun Easi 		tasks->size = tid_info->tid_size;
8401e128c81SArun Easi 		tasks->num_tids_per_block = tid_info->num_tids_per_block;
8411e128c81SArun Easi 		memcpy(tasks->blocks, tid_info->blocks,
8421e128c81SArun Easi 		       MAX_TID_BLOCKS_FCOE * sizeof(u8 *));
8431e128c81SArun Easi 
8441e128c81SArun Easi 		kfree(tid_info);
8451e128c81SArun Easi 	}
8461e128c81SArun Easi 
8471e128c81SArun Easi 	return 0;
8481e128c81SArun Easi }
8491e128c81SArun Easi 
qed_fcoe_acquire_conn(struct qed_dev * cdev,u32 * handle,u32 * fw_cid,void __iomem ** p_doorbell)8501e128c81SArun Easi static int qed_fcoe_acquire_conn(struct qed_dev *cdev,
8511e128c81SArun Easi 				 u32 *handle,
8521e128c81SArun Easi 				 u32 *fw_cid, void __iomem **p_doorbell)
8531e128c81SArun Easi {
8541e128c81SArun Easi 	struct qed_hash_fcoe_con *hash_con;
8551e128c81SArun Easi 	int rc;
8561e128c81SArun Easi 
8571e128c81SArun Easi 	/* Allocate a hashed connection */
8581e128c81SArun Easi 	hash_con = kzalloc(sizeof(*hash_con), GFP_KERNEL);
8591e128c81SArun Easi 	if (!hash_con) {
8601e128c81SArun Easi 		DP_NOTICE(cdev, "Failed to allocate hashed connection\n");
8611e128c81SArun Easi 		return -ENOMEM;
8621e128c81SArun Easi 	}
8631e128c81SArun Easi 
8641e128c81SArun Easi 	/* Acquire the connection */
8657e50769cSMichal Kalderon 	rc = qed_fcoe_acquire_connection(QED_AFFIN_HWFN(cdev), NULL,
8661e128c81SArun Easi 					 &hash_con->con);
8671e128c81SArun Easi 	if (rc) {
8681e128c81SArun Easi 		DP_NOTICE(cdev, "Failed to acquire Connection\n");
8691e128c81SArun Easi 		kfree(hash_con);
8701e128c81SArun Easi 		return rc;
8711e128c81SArun Easi 	}
8721e128c81SArun Easi 
8731e128c81SArun Easi 	/* Added the connection to hash table */
8741e128c81SArun Easi 	*handle = hash_con->con->icid;
8751e128c81SArun Easi 	*fw_cid = hash_con->con->fw_cid;
8761e128c81SArun Easi 	hash_add(cdev->connections, &hash_con->node, *handle);
8771e128c81SArun Easi 
8781e128c81SArun Easi 	if (p_doorbell)
8797e50769cSMichal Kalderon 		*p_doorbell = qed_fcoe_get_db_addr(QED_AFFIN_HWFN(cdev),
8801e128c81SArun Easi 						   *handle);
8811e128c81SArun Easi 
8821e128c81SArun Easi 	return 0;
8831e128c81SArun Easi }
8841e128c81SArun Easi 
qed_fcoe_release_conn(struct qed_dev * cdev,u32 handle)8851e128c81SArun Easi static int qed_fcoe_release_conn(struct qed_dev *cdev, u32 handle)
8861e128c81SArun Easi {
8871e128c81SArun Easi 	struct qed_hash_fcoe_con *hash_con;
8881e128c81SArun Easi 
8891e128c81SArun Easi 	hash_con = qed_fcoe_get_hash(cdev, handle);
8901e128c81SArun Easi 	if (!hash_con) {
8911e128c81SArun Easi 		DP_NOTICE(cdev, "Failed to find connection for handle %d\n",
8921e128c81SArun Easi 			  handle);
8931e128c81SArun Easi 		return -EINVAL;
8941e128c81SArun Easi 	}
8951e128c81SArun Easi 
8961e128c81SArun Easi 	hlist_del(&hash_con->node);
8977e50769cSMichal Kalderon 	qed_fcoe_release_connection(QED_AFFIN_HWFN(cdev), hash_con->con);
8981e128c81SArun Easi 	kfree(hash_con);
8991e128c81SArun Easi 
9001e128c81SArun Easi 	return 0;
9011e128c81SArun Easi }
9021e128c81SArun Easi 
qed_fcoe_offload_conn(struct qed_dev * cdev,u32 handle,struct qed_fcoe_params_offload * conn_info)9031e128c81SArun Easi static int qed_fcoe_offload_conn(struct qed_dev *cdev,
9041e128c81SArun Easi 				 u32 handle,
9051e128c81SArun Easi 				 struct qed_fcoe_params_offload *conn_info)
9061e128c81SArun Easi {
9071e128c81SArun Easi 	struct qed_hash_fcoe_con *hash_con;
9081e128c81SArun Easi 	struct qed_fcoe_conn *con;
9091e128c81SArun Easi 
9101e128c81SArun Easi 	hash_con = qed_fcoe_get_hash(cdev, handle);
9111e128c81SArun Easi 	if (!hash_con) {
9121e128c81SArun Easi 		DP_NOTICE(cdev, "Failed to find connection for handle %d\n",
9131e128c81SArun Easi 			  handle);
9141e128c81SArun Easi 		return -EINVAL;
9151e128c81SArun Easi 	}
9161e128c81SArun Easi 
9171e128c81SArun Easi 	/* Update the connection with information from the params */
9181e128c81SArun Easi 	con = hash_con->con;
9191e128c81SArun Easi 
9201e128c81SArun Easi 	con->sq_pbl_addr = conn_info->sq_pbl_addr;
9211e128c81SArun Easi 	con->sq_curr_page_addr = conn_info->sq_curr_page_addr;
9221e128c81SArun Easi 	con->sq_next_page_addr = conn_info->sq_next_page_addr;
9231e128c81SArun Easi 	con->tx_max_fc_pay_len = conn_info->tx_max_fc_pay_len;
9241e128c81SArun Easi 	con->e_d_tov_timer_val = conn_info->e_d_tov_timer_val;
9251e128c81SArun Easi 	con->rec_tov_timer_val = conn_info->rec_tov_timer_val;
9261e128c81SArun Easi 	con->rx_max_fc_pay_len = conn_info->rx_max_fc_pay_len;
9271e128c81SArun Easi 	con->vlan_tag = conn_info->vlan_tag;
9281e128c81SArun Easi 	con->max_conc_seqs_c3 = conn_info->max_conc_seqs_c3;
9291e128c81SArun Easi 	con->flags = conn_info->flags;
9301e128c81SArun Easi 	con->def_q_idx = conn_info->def_q_idx;
9311e128c81SArun Easi 
9321e128c81SArun Easi 	con->src_mac_addr_hi = (conn_info->src_mac[5] << 8) |
9331e128c81SArun Easi 	    conn_info->src_mac[4];
9341e128c81SArun Easi 	con->src_mac_addr_mid = (conn_info->src_mac[3] << 8) |
9351e128c81SArun Easi 	    conn_info->src_mac[2];
9361e128c81SArun Easi 	con->src_mac_addr_lo = (conn_info->src_mac[1] << 8) |
9371e128c81SArun Easi 	    conn_info->src_mac[0];
9381e128c81SArun Easi 	con->dst_mac_addr_hi = (conn_info->dst_mac[5] << 8) |
9391e128c81SArun Easi 	    conn_info->dst_mac[4];
9401e128c81SArun Easi 	con->dst_mac_addr_mid = (conn_info->dst_mac[3] << 8) |
9411e128c81SArun Easi 	    conn_info->dst_mac[2];
9421e128c81SArun Easi 	con->dst_mac_addr_lo = (conn_info->dst_mac[1] << 8) |
9431e128c81SArun Easi 	    conn_info->dst_mac[0];
9441e128c81SArun Easi 
9451e128c81SArun Easi 	con->s_id.addr_hi = conn_info->s_id.addr_hi;
9461e128c81SArun Easi 	con->s_id.addr_mid = conn_info->s_id.addr_mid;
9471e128c81SArun Easi 	con->s_id.addr_lo = conn_info->s_id.addr_lo;
9481e128c81SArun Easi 	con->d_id.addr_hi = conn_info->d_id.addr_hi;
9491e128c81SArun Easi 	con->d_id.addr_mid = conn_info->d_id.addr_mid;
9501e128c81SArun Easi 	con->d_id.addr_lo = conn_info->d_id.addr_lo;
9511e128c81SArun Easi 
9527e50769cSMichal Kalderon 	return qed_sp_fcoe_conn_offload(QED_AFFIN_HWFN(cdev), con,
9531e128c81SArun Easi 					QED_SPQ_MODE_EBLOCK, NULL);
9541e128c81SArun Easi }
9551e128c81SArun Easi 
qed_fcoe_destroy_conn(struct qed_dev * cdev,u32 handle,dma_addr_t terminate_params)9561e128c81SArun Easi static int qed_fcoe_destroy_conn(struct qed_dev *cdev,
9571e128c81SArun Easi 				 u32 handle, dma_addr_t terminate_params)
9581e128c81SArun Easi {
9591e128c81SArun Easi 	struct qed_hash_fcoe_con *hash_con;
9601e128c81SArun Easi 	struct qed_fcoe_conn *con;
9611e128c81SArun Easi 
9621e128c81SArun Easi 	hash_con = qed_fcoe_get_hash(cdev, handle);
9631e128c81SArun Easi 	if (!hash_con) {
9641e128c81SArun Easi 		DP_NOTICE(cdev, "Failed to find connection for handle %d\n",
9651e128c81SArun Easi 			  handle);
9661e128c81SArun Easi 		return -EINVAL;
9671e128c81SArun Easi 	}
9681e128c81SArun Easi 
9691e128c81SArun Easi 	/* Update the connection with information from the params */
9701e128c81SArun Easi 	con = hash_con->con;
9711e128c81SArun Easi 	con->terminate_params = terminate_params;
9721e128c81SArun Easi 
9737e50769cSMichal Kalderon 	return qed_sp_fcoe_conn_destroy(QED_AFFIN_HWFN(cdev), con,
9741e128c81SArun Easi 					QED_SPQ_MODE_EBLOCK, NULL);
9751e128c81SArun Easi }
9761e128c81SArun Easi 
qed_fcoe_stats_context(struct qed_dev * cdev,struct qed_fcoe_stats * stats,bool is_atomic)977*e346e231SKonstantin Khorenko static int qed_fcoe_stats_context(struct qed_dev *cdev,
978*e346e231SKonstantin Khorenko 				  struct qed_fcoe_stats *stats,
979*e346e231SKonstantin Khorenko 				  bool is_atomic)
980*e346e231SKonstantin Khorenko {
981*e346e231SKonstantin Khorenko 	return qed_fcoe_get_stats(QED_AFFIN_HWFN(cdev), stats, is_atomic);
982*e346e231SKonstantin Khorenko }
983*e346e231SKonstantin Khorenko 
qed_fcoe_stats(struct qed_dev * cdev,struct qed_fcoe_stats * stats)9841e128c81SArun Easi static int qed_fcoe_stats(struct qed_dev *cdev, struct qed_fcoe_stats *stats)
9851e128c81SArun Easi {
986*e346e231SKonstantin Khorenko 	return qed_fcoe_stats_context(cdev, stats, false);
9871e128c81SArun Easi }
9881e128c81SArun Easi 
qed_get_protocol_stats_fcoe(struct qed_dev * cdev,struct qed_mcp_fcoe_stats * stats,bool is_atomic)9891e128c81SArun Easi void qed_get_protocol_stats_fcoe(struct qed_dev *cdev,
990*e346e231SKonstantin Khorenko 				 struct qed_mcp_fcoe_stats *stats,
991*e346e231SKonstantin Khorenko 				 bool is_atomic)
9921e128c81SArun Easi {
9931e128c81SArun Easi 	struct qed_fcoe_stats proto_stats;
9941e128c81SArun Easi 
9951e128c81SArun Easi 	/* Retrieve FW statistics */
9961e128c81SArun Easi 	memset(&proto_stats, 0, sizeof(proto_stats));
997*e346e231SKonstantin Khorenko 	if (qed_fcoe_stats_context(cdev, &proto_stats, is_atomic)) {
9981e128c81SArun Easi 		DP_VERBOSE(cdev, QED_MSG_STORAGE,
9991e128c81SArun Easi 			   "Failed to collect FCoE statistics\n");
10001e128c81SArun Easi 		return;
10011e128c81SArun Easi 	}
10021e128c81SArun Easi 
10031e128c81SArun Easi 	/* Translate FW statistics into struct */
10041e128c81SArun Easi 	stats->rx_pkts = proto_stats.fcoe_rx_data_pkt_cnt +
10051e128c81SArun Easi 			 proto_stats.fcoe_rx_xfer_pkt_cnt +
10061e128c81SArun Easi 			 proto_stats.fcoe_rx_other_pkt_cnt;
10071e128c81SArun Easi 	stats->tx_pkts = proto_stats.fcoe_tx_data_pkt_cnt +
10081e128c81SArun Easi 			 proto_stats.fcoe_tx_xfer_pkt_cnt +
10091e128c81SArun Easi 			 proto_stats.fcoe_tx_other_pkt_cnt;
10101e128c81SArun Easi 	stats->fcs_err = proto_stats.fcoe_silent_drop_pkt_crc_error_cnt;
10111e128c81SArun Easi 
10121e128c81SArun Easi 	/* Request protocol driver to fill-in the rest */
10131e128c81SArun Easi 	if (cdev->protocol_ops.fcoe && cdev->ops_cookie) {
10141e128c81SArun Easi 		struct qed_fcoe_cb_ops *ops = cdev->protocol_ops.fcoe;
10151e128c81SArun Easi 		void *cookie = cdev->ops_cookie;
10161e128c81SArun Easi 
10171e128c81SArun Easi 		if (ops->get_login_failures)
10181e128c81SArun Easi 			stats->login_failure = ops->get_login_failures(cookie);
10191e128c81SArun Easi 	}
10201e128c81SArun Easi }
10211e128c81SArun Easi 
10221e128c81SArun Easi static const struct qed_fcoe_ops qed_fcoe_ops_pass = {
10231e128c81SArun Easi 	.common = &qed_common_ops_pass,
10241e128c81SArun Easi 	.ll2 = &qed_ll2_ops_pass,
10251e128c81SArun Easi 	.fill_dev_info = &qed_fill_fcoe_dev_info,
10261e128c81SArun Easi 	.start = &qed_fcoe_start,
10271e128c81SArun Easi 	.stop = &qed_fcoe_stop,
10281e128c81SArun Easi 	.register_ops = &qed_register_fcoe_ops,
10291e128c81SArun Easi 	.acquire_conn = &qed_fcoe_acquire_conn,
10301e128c81SArun Easi 	.release_conn = &qed_fcoe_release_conn,
10311e128c81SArun Easi 	.offload_conn = &qed_fcoe_offload_conn,
10321e128c81SArun Easi 	.destroy_conn = &qed_fcoe_destroy_conn,
10331e128c81SArun Easi 	.get_stats = &qed_fcoe_stats,
10341e128c81SArun Easi };
10351e128c81SArun Easi 
qed_get_fcoe_ops(void)10361e128c81SArun Easi const struct qed_fcoe_ops *qed_get_fcoe_ops(void)
10371e128c81SArun Easi {
10381e128c81SArun Easi 	return &qed_fcoe_ops_pass;
10391e128c81SArun Easi }
10401e128c81SArun Easi EXPORT_SYMBOL(qed_get_fcoe_ops);
10411e128c81SArun Easi 
qed_put_fcoe_ops(void)10421e128c81SArun Easi void qed_put_fcoe_ops(void)
10431e128c81SArun Easi {
10441e128c81SArun Easi }
10451e128c81SArun Easi EXPORT_SYMBOL(qed_put_fcoe_ops);
1046