18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Broadcom NetXtreme-E RoCE driver.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (c) 2016 - 2017, Broadcom. All rights reserved.  The term
58c2ecf20Sopenharmony_ci * Broadcom refers to Broadcom Limited and/or its subsidiaries.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
88c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
98c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
108c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
118c2ecf20Sopenharmony_ci * BSD license below:
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
148c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions
158c2ecf20Sopenharmony_ci * are met:
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
188c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
198c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
208c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in
218c2ecf20Sopenharmony_ci *    the documentation and/or other materials provided with the
228c2ecf20Sopenharmony_ci *    distribution.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
258c2ecf20Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
268c2ecf20Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
278c2ecf20Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
288c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
298c2ecf20Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
308c2ecf20Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
318c2ecf20Sopenharmony_ci * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
328c2ecf20Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
338c2ecf20Sopenharmony_ci * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
348c2ecf20Sopenharmony_ci * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
358c2ecf20Sopenharmony_ci *
368c2ecf20Sopenharmony_ci * Description: RDMA Controller HW interface (header)
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#ifndef __BNXT_QPLIB_RCFW_H__
408c2ecf20Sopenharmony_ci#define __BNXT_QPLIB_RCFW_H__
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define RCFW_CMDQ_TRIG_VAL		1
438c2ecf20Sopenharmony_ci#define RCFW_COMM_PCI_BAR_REGION	0
448c2ecf20Sopenharmony_ci#define RCFW_COMM_CONS_PCI_BAR_REGION	2
458c2ecf20Sopenharmony_ci#define RCFW_COMM_BASE_OFFSET		0x600
468c2ecf20Sopenharmony_ci#define RCFW_PF_COMM_PROD_OFFSET	0xc
478c2ecf20Sopenharmony_ci#define RCFW_VF_COMM_PROD_OFFSET	0xc
488c2ecf20Sopenharmony_ci#define RCFW_COMM_TRIG_OFFSET		0x100
498c2ecf20Sopenharmony_ci#define RCFW_COMM_SIZE			0x104
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define RCFW_DBR_PCI_BAR_REGION		2
528c2ecf20Sopenharmony_ci#define RCFW_DBR_BASE_PAGE_SHIFT	12
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define RCFW_CMD_PREP(req, CMD, cmd_flags)				\
558c2ecf20Sopenharmony_ci	do {								\
568c2ecf20Sopenharmony_ci		memset(&(req), 0, sizeof((req)));			\
578c2ecf20Sopenharmony_ci		(req).opcode = CMDQ_BASE_OPCODE_##CMD;			\
588c2ecf20Sopenharmony_ci		(req).cmd_size = sizeof((req));				\
598c2ecf20Sopenharmony_ci		(req).flags = cpu_to_le16(cmd_flags);			\
608c2ecf20Sopenharmony_ci	} while (0)
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#define RCFW_CMD_WAIT_TIME_MS		20000 /* 20 Seconds timeout */
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/* Cmdq contains a fix number of a 16-Byte slots */
658c2ecf20Sopenharmony_cistruct bnxt_qplib_cmdqe {
668c2ecf20Sopenharmony_ci	u8		data[16];
678c2ecf20Sopenharmony_ci};
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/* CMDQ elements */
708c2ecf20Sopenharmony_ci#define BNXT_QPLIB_CMDQE_MAX_CNT_256	256
718c2ecf20Sopenharmony_ci#define BNXT_QPLIB_CMDQE_MAX_CNT_8192	8192
728c2ecf20Sopenharmony_ci#define BNXT_QPLIB_CMDQE_UNITS		sizeof(struct bnxt_qplib_cmdqe)
738c2ecf20Sopenharmony_ci#define BNXT_QPLIB_CMDQE_BYTES(depth)	((depth) * BNXT_QPLIB_CMDQE_UNITS)
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cistatic inline u32 bnxt_qplib_cmdqe_npages(u32 depth)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	u32 npages;
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	npages = BNXT_QPLIB_CMDQE_BYTES(depth) / PAGE_SIZE;
808c2ecf20Sopenharmony_ci	if (BNXT_QPLIB_CMDQE_BYTES(depth) % PAGE_SIZE)
818c2ecf20Sopenharmony_ci		npages++;
828c2ecf20Sopenharmony_ci	return npages;
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistatic inline u32 bnxt_qplib_cmdqe_page_size(u32 depth)
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci	return (bnxt_qplib_cmdqe_npages(depth) * PAGE_SIZE);
888c2ecf20Sopenharmony_ci}
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci/* Set the cmd_size to a factor of CMDQE unit */
918c2ecf20Sopenharmony_cistatic inline void bnxt_qplib_set_cmd_slots(struct cmdq_base *req)
928c2ecf20Sopenharmony_ci{
938c2ecf20Sopenharmony_ci	req->cmd_size = (req->cmd_size + BNXT_QPLIB_CMDQE_UNITS - 1) /
948c2ecf20Sopenharmony_ci			 BNXT_QPLIB_CMDQE_UNITS;
958c2ecf20Sopenharmony_ci}
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci#define RCFW_MAX_COOKIE_VALUE		0x7FFF
988c2ecf20Sopenharmony_ci#define RCFW_CMD_IS_BLOCKING		0x8000
998c2ecf20Sopenharmony_ci#define RCFW_BLOCKED_CMD_WAIT_COUNT	0x4E20
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci#define HWRM_VERSION_RCFW_CMDQ_DEPTH_CHECK 0x1000900020011ULL
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/* Crsq buf is 1024-Byte */
1048c2ecf20Sopenharmony_cistruct bnxt_qplib_crsbe {
1058c2ecf20Sopenharmony_ci	u8			data[1024];
1068c2ecf20Sopenharmony_ci};
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/* CREQ */
1098c2ecf20Sopenharmony_ci/* Allocate 1 per QP for async error notification for now */
1108c2ecf20Sopenharmony_ci#define BNXT_QPLIB_CREQE_MAX_CNT	(64 * 1024)
1118c2ecf20Sopenharmony_ci#define BNXT_QPLIB_CREQE_UNITS		16	/* 16-Bytes per prod unit */
1128c2ecf20Sopenharmony_ci#define CREQ_CMP_VALID(hdr, raw_cons, cp_bit)			\
1138c2ecf20Sopenharmony_ci	(!!((hdr)->v & CREQ_BASE_V) ==				\
1148c2ecf20Sopenharmony_ci	   !((raw_cons) & (cp_bit)))
1158c2ecf20Sopenharmony_ci#define CREQ_ENTRY_POLL_BUDGET		0x100
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci/* HWQ */
1188c2ecf20Sopenharmony_citypedef int (*aeq_handler_t)(struct bnxt_qplib_rcfw *, void *, void *);
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_cistruct bnxt_qplib_crsqe {
1218c2ecf20Sopenharmony_ci	struct creq_qp_event	*resp;
1228c2ecf20Sopenharmony_ci	u32			req_size;
1238c2ecf20Sopenharmony_ci};
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_cistruct bnxt_qplib_rcfw_sbuf {
1268c2ecf20Sopenharmony_ci	void *sb;
1278c2ecf20Sopenharmony_ci	dma_addr_t dma_addr;
1288c2ecf20Sopenharmony_ci	u32 size;
1298c2ecf20Sopenharmony_ci};
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_cistruct bnxt_qplib_qp_node {
1328c2ecf20Sopenharmony_ci	u32 qp_id;              /* QP id */
1338c2ecf20Sopenharmony_ci	void *qp_handle;        /* ptr to qplib_qp */
1348c2ecf20Sopenharmony_ci};
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci#define BNXT_QPLIB_OOS_COUNT_MASK 0xFFFFFFFF
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci#define FIRMWARE_INITIALIZED_FLAG	(0)
1398c2ecf20Sopenharmony_ci#define FIRMWARE_FIRST_FLAG		(31)
1408c2ecf20Sopenharmony_ci#define FIRMWARE_TIMED_OUT		(3)
1418c2ecf20Sopenharmony_cistruct bnxt_qplib_cmdq_mbox {
1428c2ecf20Sopenharmony_ci	struct bnxt_qplib_reg_desc	reg;
1438c2ecf20Sopenharmony_ci	void __iomem			*prod;
1448c2ecf20Sopenharmony_ci	void __iomem			*db;
1458c2ecf20Sopenharmony_ci};
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_cistruct bnxt_qplib_cmdq_ctx {
1488c2ecf20Sopenharmony_ci	struct bnxt_qplib_hwq		hwq;
1498c2ecf20Sopenharmony_ci	struct bnxt_qplib_cmdq_mbox	cmdq_mbox;
1508c2ecf20Sopenharmony_ci	wait_queue_head_t		waitq;
1518c2ecf20Sopenharmony_ci	unsigned long			flags;
1528c2ecf20Sopenharmony_ci	unsigned long			*cmdq_bitmap;
1538c2ecf20Sopenharmony_ci	u32				seq_num;
1548c2ecf20Sopenharmony_ci};
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_cistruct bnxt_qplib_creq_db {
1578c2ecf20Sopenharmony_ci	struct bnxt_qplib_reg_desc	reg;
1588c2ecf20Sopenharmony_ci	struct bnxt_qplib_db_info	dbinfo;
1598c2ecf20Sopenharmony_ci};
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_cistruct bnxt_qplib_creq_stat {
1628c2ecf20Sopenharmony_ci	u64	creq_qp_event_processed;
1638c2ecf20Sopenharmony_ci	u64	creq_func_event_processed;
1648c2ecf20Sopenharmony_ci};
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_cistruct bnxt_qplib_creq_ctx {
1678c2ecf20Sopenharmony_ci	struct bnxt_qplib_hwq		hwq;
1688c2ecf20Sopenharmony_ci	struct bnxt_qplib_creq_db	creq_db;
1698c2ecf20Sopenharmony_ci	struct bnxt_qplib_creq_stat	stats;
1708c2ecf20Sopenharmony_ci	struct tasklet_struct		creq_tasklet;
1718c2ecf20Sopenharmony_ci	aeq_handler_t			aeq_handler;
1728c2ecf20Sopenharmony_ci	u16				ring_id;
1738c2ecf20Sopenharmony_ci	int				msix_vec;
1748c2ecf20Sopenharmony_ci	bool				requested; /*irq handler installed */
1758c2ecf20Sopenharmony_ci	char				*irq_name;
1768c2ecf20Sopenharmony_ci};
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci/* RCFW Communication Channels */
1798c2ecf20Sopenharmony_cistruct bnxt_qplib_rcfw {
1808c2ecf20Sopenharmony_ci	struct pci_dev		*pdev;
1818c2ecf20Sopenharmony_ci	struct bnxt_qplib_res	*res;
1828c2ecf20Sopenharmony_ci	struct bnxt_qplib_cmdq_ctx	cmdq;
1838c2ecf20Sopenharmony_ci	struct bnxt_qplib_creq_ctx	creq;
1848c2ecf20Sopenharmony_ci	struct bnxt_qplib_crsqe		*crsqe_tbl;
1858c2ecf20Sopenharmony_ci	int qp_tbl_size;
1868c2ecf20Sopenharmony_ci	struct bnxt_qplib_qp_node *qp_tbl;
1878c2ecf20Sopenharmony_ci	u64 oos_prev;
1888c2ecf20Sopenharmony_ci	u32 init_oos_stats;
1898c2ecf20Sopenharmony_ci	u32 cmdq_depth;
1908c2ecf20Sopenharmony_ci};
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_civoid bnxt_qplib_free_rcfw_channel(struct bnxt_qplib_rcfw *rcfw);
1938c2ecf20Sopenharmony_ciint bnxt_qplib_alloc_rcfw_channel(struct bnxt_qplib_res *res,
1948c2ecf20Sopenharmony_ci				  struct bnxt_qplib_rcfw *rcfw,
1958c2ecf20Sopenharmony_ci				  struct bnxt_qplib_ctx *ctx,
1968c2ecf20Sopenharmony_ci				  int qp_tbl_sz);
1978c2ecf20Sopenharmony_civoid bnxt_qplib_rcfw_stop_irq(struct bnxt_qplib_rcfw *rcfw, bool kill);
1988c2ecf20Sopenharmony_civoid bnxt_qplib_disable_rcfw_channel(struct bnxt_qplib_rcfw *rcfw);
1998c2ecf20Sopenharmony_ciint bnxt_qplib_rcfw_start_irq(struct bnxt_qplib_rcfw *rcfw, int msix_vector,
2008c2ecf20Sopenharmony_ci			      bool need_init);
2018c2ecf20Sopenharmony_ciint bnxt_qplib_enable_rcfw_channel(struct bnxt_qplib_rcfw *rcfw,
2028c2ecf20Sopenharmony_ci				   int msix_vector,
2038c2ecf20Sopenharmony_ci				   int cp_bar_reg_off, int virt_fn,
2048c2ecf20Sopenharmony_ci				   aeq_handler_t aeq_handler);
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_cistruct bnxt_qplib_rcfw_sbuf *bnxt_qplib_rcfw_alloc_sbuf(
2078c2ecf20Sopenharmony_ci				struct bnxt_qplib_rcfw *rcfw,
2088c2ecf20Sopenharmony_ci				u32 size);
2098c2ecf20Sopenharmony_civoid bnxt_qplib_rcfw_free_sbuf(struct bnxt_qplib_rcfw *rcfw,
2108c2ecf20Sopenharmony_ci			       struct bnxt_qplib_rcfw_sbuf *sbuf);
2118c2ecf20Sopenharmony_ciint bnxt_qplib_rcfw_send_message(struct bnxt_qplib_rcfw *rcfw,
2128c2ecf20Sopenharmony_ci				 struct cmdq_base *req, struct creq_base *resp,
2138c2ecf20Sopenharmony_ci				 void *sbuf, u8 is_block);
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ciint bnxt_qplib_deinit_rcfw(struct bnxt_qplib_rcfw *rcfw);
2168c2ecf20Sopenharmony_ciint bnxt_qplib_init_rcfw(struct bnxt_qplib_rcfw *rcfw,
2178c2ecf20Sopenharmony_ci			 struct bnxt_qplib_ctx *ctx, int is_virtfn);
2188c2ecf20Sopenharmony_civoid bnxt_qplib_mark_qp_error(void *qp_handle);
2198c2ecf20Sopenharmony_cistatic inline u32 map_qp_id_to_tbl_indx(u32 qid, struct bnxt_qplib_rcfw *rcfw)
2208c2ecf20Sopenharmony_ci{
2218c2ecf20Sopenharmony_ci	/* Last index of the qp_tbl is for QP1 ie. qp_tbl_size - 1*/
2228c2ecf20Sopenharmony_ci	return (qid == 1) ? rcfw->qp_tbl_size - 1 : qid % rcfw->qp_tbl_size - 2;
2238c2ecf20Sopenharmony_ci}
2248c2ecf20Sopenharmony_ci#endif /* __BNXT_QPLIB_RCFW_H__ */
225