162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * Broadcom NetXtreme-E RoCE driver. 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright (c) 2016 - 2017, Broadcom. All rights reserved. The term 562306a36Sopenharmony_ci * Broadcom refers to Broadcom Limited and/or its subsidiaries. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * This software is available to you under a choice of one of two 862306a36Sopenharmony_ci * licenses. You may choose to be licensed under the terms of the GNU 962306a36Sopenharmony_ci * General Public License (GPL) Version 2, available from the file 1062306a36Sopenharmony_ci * COPYING in the main directory of this source tree, or the 1162306a36Sopenharmony_ci * BSD license below: 1262306a36Sopenharmony_ci * 1362306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 1462306a36Sopenharmony_ci * modification, are permitted provided that the following conditions 1562306a36Sopenharmony_ci * are met: 1662306a36Sopenharmony_ci * 1762306a36Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 1862306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 1962306a36Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 2062306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer in 2162306a36Sopenharmony_ci * the documentation and/or other materials provided with the 2262306a36Sopenharmony_ci * distribution. 2362306a36Sopenharmony_ci * 2462306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 2562306a36Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 2662306a36Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2762306a36Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS 2862306a36Sopenharmony_ci * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2962306a36Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3062306a36Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 3162306a36Sopenharmony_ci * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 3262306a36Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 3362306a36Sopenharmony_ci * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 3462306a36Sopenharmony_ci * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3562306a36Sopenharmony_ci * 3662306a36Sopenharmony_ci * Description: Slow Path Operators (header) 3762306a36Sopenharmony_ci * 3862306a36Sopenharmony_ci */ 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci#ifndef __BNXT_RE_H__ 4162306a36Sopenharmony_ci#define __BNXT_RE_H__ 4262306a36Sopenharmony_ci#include <rdma/uverbs_ioctl.h> 4362306a36Sopenharmony_ci#include "hw_counters.h" 4462306a36Sopenharmony_ci#define ROCE_DRV_MODULE_NAME "bnxt_re" 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci#define BNXT_RE_DESC "Broadcom NetXtreme-C/E RoCE Driver" 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci#define BNXT_RE_PAGE_SHIFT_1G (30) 4962306a36Sopenharmony_ci#define BNXT_RE_PAGE_SIZE_SUPPORTED 0x7FFFF000 /* 4kb - 1G */ 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci#define BNXT_RE_MAX_MR_SIZE_LOW BIT_ULL(BNXT_RE_PAGE_SHIFT_1G) 5262306a36Sopenharmony_ci#define BNXT_RE_MAX_MR_SIZE_HIGH BIT_ULL(39) 5362306a36Sopenharmony_ci#define BNXT_RE_MAX_MR_SIZE BNXT_RE_MAX_MR_SIZE_HIGH 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci#define BNXT_RE_MAX_QPC_COUNT (64 * 1024) 5662306a36Sopenharmony_ci#define BNXT_RE_MAX_MRW_COUNT (64 * 1024) 5762306a36Sopenharmony_ci#define BNXT_RE_MAX_SRQC_COUNT (64 * 1024) 5862306a36Sopenharmony_ci#define BNXT_RE_MAX_CQ_COUNT (64 * 1024) 5962306a36Sopenharmony_ci#define BNXT_RE_MAX_MRW_COUNT_64K (64 * 1024) 6062306a36Sopenharmony_ci#define BNXT_RE_MAX_MRW_COUNT_256K (256 * 1024) 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci/* Number of MRs to reserve for PF, leaving remainder for VFs */ 6362306a36Sopenharmony_ci#define BNXT_RE_RESVD_MR_FOR_PF (32 * 1024) 6462306a36Sopenharmony_ci#define BNXT_RE_MAX_GID_PER_VF 128 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci/* 6762306a36Sopenharmony_ci * Percentage of resources of each type reserved for PF. 6862306a36Sopenharmony_ci * Remaining resources are divided equally among VFs. 6962306a36Sopenharmony_ci * [0, 100] 7062306a36Sopenharmony_ci */ 7162306a36Sopenharmony_ci#define BNXT_RE_PCT_RSVD_FOR_PF 50 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci#define BNXT_RE_UD_QP_HW_STALL 0x400000 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci#define BNXT_RE_RQ_WQE_THRESHOLD 32 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci/* 7862306a36Sopenharmony_ci * Setting the default ack delay value to 16, which means 7962306a36Sopenharmony_ci * the default timeout is approx. 260ms(4 usec * 2 ^(timeout)) 8062306a36Sopenharmony_ci */ 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci#define BNXT_RE_DEFAULT_ACK_DELAY 16 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_cistruct bnxt_re_ring_attr { 8562306a36Sopenharmony_ci dma_addr_t *dma_arr; 8662306a36Sopenharmony_ci int pages; 8762306a36Sopenharmony_ci int type; 8862306a36Sopenharmony_ci u32 depth; 8962306a36Sopenharmony_ci u32 lrid; /* Logical ring id */ 9062306a36Sopenharmony_ci u8 mode; 9162306a36Sopenharmony_ci}; 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_cistruct bnxt_re_sqp_entries { 9462306a36Sopenharmony_ci struct bnxt_qplib_sge sge; 9562306a36Sopenharmony_ci u64 wrid; 9662306a36Sopenharmony_ci /* For storing the actual qp1 cqe */ 9762306a36Sopenharmony_ci struct bnxt_qplib_cqe cqe; 9862306a36Sopenharmony_ci struct bnxt_re_qp *qp1_qp; 9962306a36Sopenharmony_ci}; 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci#define BNXT_RE_MAX_GSI_SQP_ENTRIES 1024 10262306a36Sopenharmony_cistruct bnxt_re_gsi_context { 10362306a36Sopenharmony_ci struct bnxt_re_qp *gsi_qp; 10462306a36Sopenharmony_ci struct bnxt_re_qp *gsi_sqp; 10562306a36Sopenharmony_ci struct bnxt_re_ah *gsi_sah; 10662306a36Sopenharmony_ci struct bnxt_re_sqp_entries *sqp_tbl; 10762306a36Sopenharmony_ci}; 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci#define BNXT_RE_MIN_MSIX 2 11062306a36Sopenharmony_ci#define BNXT_RE_MAX_MSIX 9 11162306a36Sopenharmony_ci#define BNXT_RE_AEQ_IDX 0 11262306a36Sopenharmony_ci#define BNXT_RE_NQ_IDX 1 11362306a36Sopenharmony_ci#define BNXT_RE_GEN_P5_MAX_VF 64 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_cistruct bnxt_re_pacing { 11662306a36Sopenharmony_ci u64 dbr_db_fifo_reg_off; 11762306a36Sopenharmony_ci void *dbr_page; 11862306a36Sopenharmony_ci u64 dbr_bar_addr; 11962306a36Sopenharmony_ci u32 pacing_algo_th; 12062306a36Sopenharmony_ci u32 do_pacing_save; 12162306a36Sopenharmony_ci u32 dbq_pacing_time; /* ms */ 12262306a36Sopenharmony_ci u32 dbr_def_do_pacing; 12362306a36Sopenharmony_ci bool dbr_pacing; 12462306a36Sopenharmony_ci struct mutex dbq_lock; /* synchronize db pacing algo */ 12562306a36Sopenharmony_ci}; 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci#define BNXT_RE_MAX_DBR_DO_PACING 0xFFFF 12862306a36Sopenharmony_ci#define BNXT_RE_DBR_PACING_TIME 5 /* ms */ 12962306a36Sopenharmony_ci#define BNXT_RE_PACING_ALGO_THRESHOLD 250 /* Entries in DB FIFO */ 13062306a36Sopenharmony_ci#define BNXT_RE_PACING_ALARM_TH_MULTIPLE 2 /* Multiple of pacing algo threshold */ 13162306a36Sopenharmony_ci/* Default do_pacing value when there is no congestion */ 13262306a36Sopenharmony_ci#define BNXT_RE_DBR_DO_PACING_NO_CONGESTION 0x7F /* 1 in 512 probability */ 13362306a36Sopenharmony_ci#define BNXT_RE_DB_FIFO_ROOM_MASK 0x1FFF8000 13462306a36Sopenharmony_ci#define BNXT_RE_MAX_FIFO_DEPTH 0x2c00 13562306a36Sopenharmony_ci#define BNXT_RE_DB_FIFO_ROOM_SHIFT 15 13662306a36Sopenharmony_ci#define BNXT_RE_GRC_FIFO_REG_BASE 0x2000 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_cistruct bnxt_re_dev { 13962306a36Sopenharmony_ci struct ib_device ibdev; 14062306a36Sopenharmony_ci struct list_head list; 14162306a36Sopenharmony_ci unsigned long flags; 14262306a36Sopenharmony_ci#define BNXT_RE_FLAG_NETDEV_REGISTERED 0 14362306a36Sopenharmony_ci#define BNXT_RE_FLAG_HAVE_L2_REF 3 14462306a36Sopenharmony_ci#define BNXT_RE_FLAG_RCFW_CHANNEL_EN 4 14562306a36Sopenharmony_ci#define BNXT_RE_FLAG_QOS_WORK_REG 5 14662306a36Sopenharmony_ci#define BNXT_RE_FLAG_RESOURCES_ALLOCATED 7 14762306a36Sopenharmony_ci#define BNXT_RE_FLAG_RESOURCES_INITIALIZED 8 14862306a36Sopenharmony_ci#define BNXT_RE_FLAG_ERR_DEVICE_DETACHED 17 14962306a36Sopenharmony_ci#define BNXT_RE_FLAG_ISSUE_ROCE_STATS 29 15062306a36Sopenharmony_ci struct net_device *netdev; 15162306a36Sopenharmony_ci struct notifier_block nb; 15262306a36Sopenharmony_ci unsigned int version, major, minor; 15362306a36Sopenharmony_ci struct bnxt_qplib_chip_ctx *chip_ctx; 15462306a36Sopenharmony_ci struct bnxt_en_dev *en_dev; 15562306a36Sopenharmony_ci int num_msix; 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci int id; 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci struct delayed_work worker; 16062306a36Sopenharmony_ci u8 cur_prio_map; 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci /* FP Notification Queue (CQ & SRQ) */ 16362306a36Sopenharmony_ci struct tasklet_struct nq_task; 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ci /* RCFW Channel */ 16662306a36Sopenharmony_ci struct bnxt_qplib_rcfw rcfw; 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_ci /* NQ */ 16962306a36Sopenharmony_ci struct bnxt_qplib_nq nq[BNXT_RE_MAX_MSIX]; 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ci /* Device Resources */ 17262306a36Sopenharmony_ci struct bnxt_qplib_dev_attr dev_attr; 17362306a36Sopenharmony_ci struct bnxt_qplib_ctx qplib_ctx; 17462306a36Sopenharmony_ci struct bnxt_qplib_res qplib_res; 17562306a36Sopenharmony_ci struct bnxt_qplib_dpi dpi_privileged; 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci struct mutex qp_lock; /* protect qp list */ 17862306a36Sopenharmony_ci struct list_head qp_list; 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ci /* Max of 2 lossless traffic class supported per port */ 18162306a36Sopenharmony_ci u16 cosq[2]; 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_ci /* QP for handling QP1 packets */ 18462306a36Sopenharmony_ci struct bnxt_re_gsi_context gsi_ctx; 18562306a36Sopenharmony_ci struct bnxt_re_stats stats; 18662306a36Sopenharmony_ci atomic_t nq_alloc_cnt; 18762306a36Sopenharmony_ci u32 is_virtfn; 18862306a36Sopenharmony_ci u32 num_vfs; 18962306a36Sopenharmony_ci struct bnxt_re_pacing pacing; 19062306a36Sopenharmony_ci struct work_struct dbq_fifo_check_work; 19162306a36Sopenharmony_ci struct delayed_work dbq_pacing_work; 19262306a36Sopenharmony_ci}; 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ci#define to_bnxt_re_dev(ptr, member) \ 19562306a36Sopenharmony_ci container_of((ptr), struct bnxt_re_dev, member) 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ci#define BNXT_RE_ROCE_V1_PACKET 0 19862306a36Sopenharmony_ci#define BNXT_RE_ROCEV2_IPV4_PACKET 2 19962306a36Sopenharmony_ci#define BNXT_RE_ROCEV2_IPV6_PACKET 3 20062306a36Sopenharmony_ci 20162306a36Sopenharmony_ci#define BNXT_RE_CHECK_RC(x) ((x) && ((x) != -ETIMEDOUT)) 20262306a36Sopenharmony_civoid bnxt_re_pacing_alert(struct bnxt_re_dev *rdev); 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_cistatic inline struct device *rdev_to_dev(struct bnxt_re_dev *rdev) 20562306a36Sopenharmony_ci{ 20662306a36Sopenharmony_ci if (rdev) 20762306a36Sopenharmony_ci return &rdev->ibdev.dev; 20862306a36Sopenharmony_ci return NULL; 20962306a36Sopenharmony_ci} 21062306a36Sopenharmony_ci 21162306a36Sopenharmony_ciextern const struct uapi_definition bnxt_re_uapi_defs[]; 21262306a36Sopenharmony_ci#endif 213