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: Slow Path Operators (header) 378c2ecf20Sopenharmony_ci * 388c2ecf20Sopenharmony_ci */ 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#ifndef __BNXT_RE_H__ 418c2ecf20Sopenharmony_ci#define __BNXT_RE_H__ 428c2ecf20Sopenharmony_ci#define ROCE_DRV_MODULE_NAME "bnxt_re" 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#define BNXT_RE_DESC "Broadcom NetXtreme-C/E RoCE Driver" 458c2ecf20Sopenharmony_ci#define BNXT_RE_PAGE_SHIFT_4K (12) 468c2ecf20Sopenharmony_ci#define BNXT_RE_PAGE_SHIFT_8K (13) 478c2ecf20Sopenharmony_ci#define BNXT_RE_PAGE_SHIFT_64K (16) 488c2ecf20Sopenharmony_ci#define BNXT_RE_PAGE_SHIFT_2M (21) 498c2ecf20Sopenharmony_ci#define BNXT_RE_PAGE_SHIFT_8M (23) 508c2ecf20Sopenharmony_ci#define BNXT_RE_PAGE_SHIFT_1G (30) 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci#define BNXT_RE_PAGE_SIZE_4K BIT(BNXT_RE_PAGE_SHIFT_4K) 538c2ecf20Sopenharmony_ci#define BNXT_RE_PAGE_SIZE_8K BIT(BNXT_RE_PAGE_SHIFT_8K) 548c2ecf20Sopenharmony_ci#define BNXT_RE_PAGE_SIZE_64K BIT(BNXT_RE_PAGE_SHIFT_64K) 558c2ecf20Sopenharmony_ci#define BNXT_RE_PAGE_SIZE_2M BIT(BNXT_RE_PAGE_SHIFT_2M) 568c2ecf20Sopenharmony_ci#define BNXT_RE_PAGE_SIZE_8M BIT(BNXT_RE_PAGE_SHIFT_8M) 578c2ecf20Sopenharmony_ci#define BNXT_RE_PAGE_SIZE_1G BIT(BNXT_RE_PAGE_SHIFT_1G) 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci#define BNXT_RE_MAX_MR_SIZE_LOW BIT_ULL(BNXT_RE_PAGE_SHIFT_1G) 608c2ecf20Sopenharmony_ci#define BNXT_RE_MAX_MR_SIZE_HIGH BIT_ULL(39) 618c2ecf20Sopenharmony_ci#define BNXT_RE_MAX_MR_SIZE BNXT_RE_MAX_MR_SIZE_HIGH 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci#define BNXT_RE_MAX_QPC_COUNT (64 * 1024) 648c2ecf20Sopenharmony_ci#define BNXT_RE_MAX_MRW_COUNT (64 * 1024) 658c2ecf20Sopenharmony_ci#define BNXT_RE_MAX_SRQC_COUNT (64 * 1024) 668c2ecf20Sopenharmony_ci#define BNXT_RE_MAX_CQ_COUNT (64 * 1024) 678c2ecf20Sopenharmony_ci#define BNXT_RE_MAX_MRW_COUNT_64K (64 * 1024) 688c2ecf20Sopenharmony_ci#define BNXT_RE_MAX_MRW_COUNT_256K (256 * 1024) 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* Number of MRs to reserve for PF, leaving remainder for VFs */ 718c2ecf20Sopenharmony_ci#define BNXT_RE_RESVD_MR_FOR_PF (32 * 1024) 728c2ecf20Sopenharmony_ci#define BNXT_RE_MAX_GID_PER_VF 128 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci/* 758c2ecf20Sopenharmony_ci * Percentage of resources of each type reserved for PF. 768c2ecf20Sopenharmony_ci * Remaining resources are divided equally among VFs. 778c2ecf20Sopenharmony_ci * [0, 100] 788c2ecf20Sopenharmony_ci */ 798c2ecf20Sopenharmony_ci#define BNXT_RE_PCT_RSVD_FOR_PF 50 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci#define BNXT_RE_UD_QP_HW_STALL 0x400000 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#define BNXT_RE_RQ_WQE_THRESHOLD 32 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/* 868c2ecf20Sopenharmony_ci * Setting the default ack delay value to 16, which means 878c2ecf20Sopenharmony_ci * the default timeout is approx. 260ms(4 usec * 2 ^(timeout)) 888c2ecf20Sopenharmony_ci */ 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci#define BNXT_RE_DEFAULT_ACK_DELAY 16 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_cistruct bnxt_re_ring_attr { 938c2ecf20Sopenharmony_ci dma_addr_t *dma_arr; 948c2ecf20Sopenharmony_ci int pages; 958c2ecf20Sopenharmony_ci int type; 968c2ecf20Sopenharmony_ci u32 depth; 978c2ecf20Sopenharmony_ci u32 lrid; /* Logical ring id */ 988c2ecf20Sopenharmony_ci u8 mode; 998c2ecf20Sopenharmony_ci}; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_cistruct bnxt_re_work { 1028c2ecf20Sopenharmony_ci struct work_struct work; 1038c2ecf20Sopenharmony_ci unsigned long event; 1048c2ecf20Sopenharmony_ci struct bnxt_re_dev *rdev; 1058c2ecf20Sopenharmony_ci struct net_device *vlan_dev; 1068c2ecf20Sopenharmony_ci}; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistruct bnxt_re_sqp_entries { 1098c2ecf20Sopenharmony_ci struct bnxt_qplib_sge sge; 1108c2ecf20Sopenharmony_ci u64 wrid; 1118c2ecf20Sopenharmony_ci /* For storing the actual qp1 cqe */ 1128c2ecf20Sopenharmony_ci struct bnxt_qplib_cqe cqe; 1138c2ecf20Sopenharmony_ci struct bnxt_re_qp *qp1_qp; 1148c2ecf20Sopenharmony_ci}; 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci#define BNXT_RE_MAX_GSI_SQP_ENTRIES 1024 1178c2ecf20Sopenharmony_cistruct bnxt_re_gsi_context { 1188c2ecf20Sopenharmony_ci struct bnxt_re_qp *gsi_qp; 1198c2ecf20Sopenharmony_ci struct bnxt_re_qp *gsi_sqp; 1208c2ecf20Sopenharmony_ci struct bnxt_re_ah *gsi_sah; 1218c2ecf20Sopenharmony_ci struct bnxt_re_sqp_entries *sqp_tbl; 1228c2ecf20Sopenharmony_ci}; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci#define BNXT_RE_MIN_MSIX 2 1258c2ecf20Sopenharmony_ci#define BNXT_RE_MAX_MSIX 9 1268c2ecf20Sopenharmony_ci#define BNXT_RE_AEQ_IDX 0 1278c2ecf20Sopenharmony_ci#define BNXT_RE_NQ_IDX 1 1288c2ecf20Sopenharmony_ci#define BNXT_RE_GEN_P5_MAX_VF 64 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_cistruct bnxt_re_dev { 1318c2ecf20Sopenharmony_ci struct ib_device ibdev; 1328c2ecf20Sopenharmony_ci struct list_head list; 1338c2ecf20Sopenharmony_ci unsigned long flags; 1348c2ecf20Sopenharmony_ci#define BNXT_RE_FLAG_NETDEV_REGISTERED 0 1358c2ecf20Sopenharmony_ci#define BNXT_RE_FLAG_GOT_MSIX 2 1368c2ecf20Sopenharmony_ci#define BNXT_RE_FLAG_HAVE_L2_REF 3 1378c2ecf20Sopenharmony_ci#define BNXT_RE_FLAG_RCFW_CHANNEL_EN 4 1388c2ecf20Sopenharmony_ci#define BNXT_RE_FLAG_QOS_WORK_REG 5 1398c2ecf20Sopenharmony_ci#define BNXT_RE_FLAG_RESOURCES_ALLOCATED 7 1408c2ecf20Sopenharmony_ci#define BNXT_RE_FLAG_RESOURCES_INITIALIZED 8 1418c2ecf20Sopenharmony_ci#define BNXT_RE_FLAG_ISSUE_ROCE_STATS 29 1428c2ecf20Sopenharmony_ci struct net_device *netdev; 1438c2ecf20Sopenharmony_ci unsigned int version, major, minor; 1448c2ecf20Sopenharmony_ci struct bnxt_qplib_chip_ctx *chip_ctx; 1458c2ecf20Sopenharmony_ci struct bnxt_en_dev *en_dev; 1468c2ecf20Sopenharmony_ci struct bnxt_msix_entry msix_entries[BNXT_RE_MAX_MSIX]; 1478c2ecf20Sopenharmony_ci int num_msix; 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci int id; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci struct delayed_work worker; 1528c2ecf20Sopenharmony_ci u8 cur_prio_map; 1538c2ecf20Sopenharmony_ci u16 active_speed; 1548c2ecf20Sopenharmony_ci u8 active_width; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci /* FP Notification Queue (CQ & SRQ) */ 1578c2ecf20Sopenharmony_ci struct tasklet_struct nq_task; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci /* RCFW Channel */ 1608c2ecf20Sopenharmony_ci struct bnxt_qplib_rcfw rcfw; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci /* NQ */ 1638c2ecf20Sopenharmony_ci struct bnxt_qplib_nq nq[BNXT_RE_MAX_MSIX]; 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci /* Device Resources */ 1668c2ecf20Sopenharmony_ci struct bnxt_qplib_dev_attr dev_attr; 1678c2ecf20Sopenharmony_ci struct bnxt_qplib_ctx qplib_ctx; 1688c2ecf20Sopenharmony_ci struct bnxt_qplib_res qplib_res; 1698c2ecf20Sopenharmony_ci struct bnxt_qplib_dpi dpi_privileged; 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci atomic_t qp_count; 1728c2ecf20Sopenharmony_ci struct mutex qp_lock; /* protect qp list */ 1738c2ecf20Sopenharmony_ci struct list_head qp_list; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci atomic_t cq_count; 1768c2ecf20Sopenharmony_ci atomic_t srq_count; 1778c2ecf20Sopenharmony_ci atomic_t mr_count; 1788c2ecf20Sopenharmony_ci atomic_t mw_count; 1798c2ecf20Sopenharmony_ci /* Max of 2 lossless traffic class supported per port */ 1808c2ecf20Sopenharmony_ci u16 cosq[2]; 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci /* QP for for handling QP1 packets */ 1838c2ecf20Sopenharmony_ci struct bnxt_re_gsi_context gsi_ctx; 1848c2ecf20Sopenharmony_ci atomic_t nq_alloc_cnt; 1858c2ecf20Sopenharmony_ci u32 is_virtfn; 1868c2ecf20Sopenharmony_ci u32 num_vfs; 1878c2ecf20Sopenharmony_ci struct bnxt_qplib_roce_stats stats; 1888c2ecf20Sopenharmony_ci}; 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci#define to_bnxt_re_dev(ptr, member) \ 1918c2ecf20Sopenharmony_ci container_of((ptr), struct bnxt_re_dev, member) 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci#define BNXT_RE_ROCE_V1_PACKET 0 1948c2ecf20Sopenharmony_ci#define BNXT_RE_ROCEV2_IPV4_PACKET 2 1958c2ecf20Sopenharmony_ci#define BNXT_RE_ROCEV2_IPV6_PACKET 3 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_cistatic inline struct device *rdev_to_dev(struct bnxt_re_dev *rdev) 1988c2ecf20Sopenharmony_ci{ 1998c2ecf20Sopenharmony_ci if (rdev) 2008c2ecf20Sopenharmony_ci return &rdev->ibdev.dev; 2018c2ecf20Sopenharmony_ci return NULL; 2028c2ecf20Sopenharmony_ci} 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci#endif 205