Path: blob/main/sys/dev/bnxt/bnxt_re/qplib_rcfw.h
108456 views
/*1* Copyright (c) 2015-2024, Broadcom. All rights reserved. The term2* Broadcom refers to Broadcom Limited and/or its subsidiaries.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7*8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in12* the documentation and/or other materials provided with the13* distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''16* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,17* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR18* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS19* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR20* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF21* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR22* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,23* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE24* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN25* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.26*27* Description: RDMA Controller HW interface (header)28*/2930#ifndef __BNXT_QPLIB_RCFW_H__31#define __BNXT_QPLIB_RCFW_H__3233#include <linux/semaphore.h>34#include <linux/module.h>35#include <linux/netdevice.h>36#include <linux/mutex.h>37#include <linux/list.h>38#include <linux/rculist.h>39#include <linux/spinlock.h>40#include <linux/pci.h>41#include <net/ipv6.h>42#include <linux/if_ether.h>43#include <linux/debugfs.h>44#include <linux/seq_file.h>45#include <linux/interrupt.h>46#include <linux/vmalloc.h>47#include <linux/delay.h>4849#include "qplib_tlv.h"5051#define RCFW_CMDQ_TRIG_VAL 152#define RCFW_COMM_PCI_BAR_REGION 053#define RCFW_COMM_CONS_PCI_BAR_REGION 254#define RCFW_COMM_BASE_OFFSET 0x60055#define RCFW_PF_VF_COMM_PROD_OFFSET 0xc56#define RCFW_COMM_TRIG_OFFSET 0x10057#define RCFW_COMM_SIZE 0x1045859#define RCFW_DBR_PCI_BAR_REGION 260#define RCFW_DBR_BASE_PAGE_SHIFT 1261#define RCFW_MAX_LATENCY_SEC_SLAB_INDEX 12862#define RCFW_MAX_LATENCY_MSEC_SLAB_INDEX 300063#define RCFW_MAX_STAT_INDEX 0xFFFF64#define RCFW_FW_STALL_MAX_TIMEOUT 406566#define GET_OPCODE_TYPE(x) \67((x) == 0x1 ? "CREATE_QP": \68((x) == 0x2 ? "DESTROY_QP": \69((x) == 0x3 ? "MODIFY_QP": \70((x) == 0x4 ? "QUERY_QP": \71((x) == 0x5 ? "CREATE_SRQ": \72((x) == 0x6 ? "DESTROY_SRQ": \73((x) == 0x8 ? "QUERY_SRQ": \74((x) == 0x9 ? "CREATE_CQ": \75((x) == 0xa ? "DESTROY_CQ": \76((x) == 0xc ? "RESIZE_CQ": \77((x) == 0xd ? "ALLOCATE_MRW": \78((x) == 0xe ? "DEALLOCATE_KEY": \79((x) == 0xf ? "REGISTER_MR": \80((x) == 0x10 ? "DEREGISTER_MR": \81((x) == 0x11 ? "ADD_GID": \82((x) == 0x12 ? "DELETE_GID": \83((x) == 0x17 ? "MODIFY_GID": \84((x) == 0x18 ? "QUERY_GID": \85((x) == 0x13 ? "CREATE_QP1": \86((x) == 0x14 ? "DESTROY_QP1": \87((x) == 0x15 ? "CREATE_AH": \88((x) == 0x16 ? "DESTROY_AH": \89((x) == 0x80 ? "INITIALIZE_FW": \90((x) == 0x81 ? "DEINITIALIZE_FW": \91((x) == 0x82 ? "STOP_FUNC": \92((x) == 0x83 ? "QUERY_FUNC": \93((x) == 0x84 ? "SET_FUNC_RESOURCES": \94((x) == 0x85 ? "READ_CONTEXT": \95((x) == 0x86 ? "VF_BACKCHANNEL_REQUEST": \96((x) == 0x87 ? "READ_VF_MEMORY": \97((x) == 0x88 ? "COMPLETE_VF_REQUEST": \98((x) == 0x89 ? "EXTEND_CONTEXT_ARRRAY": \99((x) == 0x8a ? "MAP_TC_TO_COS": \100((x) == 0x8b ? "QUERY_VERSION": \101((x) == 0x8c ? "MODIFY_ROCE_CC": \102((x) == 0x8d ? "QUERY_ROCE_CC": \103((x) == 0x8e ? "QUERY_ROCE_STATS": \104((x) == 0x8f ? "SET_LINK_AGGR_MODE": \105((x) == 0x90 ? "MODIFY_CQ": \106((x) == 0x91 ? "QUERY_QP_EXTEND": \107((x) == 0x92 ? "QUERY_ROCE_STATS_EXT": \108"Unknown OPCODE" \109)))))))))))))))))))))))))))))))))))))))))110111extern unsigned int cmdq_shadow_qd;112/* Cmdq contains a fix number of a 16-Byte slots */113struct bnxt_qplib_cmdqe {114u8 data[16];115};116#define BNXT_QPLIB_CMDQE_UNITS sizeof(struct bnxt_qplib_cmdqe)117118static inline void bnxt_qplib_rcfw_cmd_prep(void *r, u8 opcode, u8 cmd_size)119{120struct cmdq_base *req = r;121122req->opcode = opcode;123req->cmd_size = cmd_size;124}125126/* Shadow queue depth for non blocking command */127#define RCFW_CMD_NON_BLOCKING_SHADOW_QD 64128#define RCFW_CMD_DEV_ERR_CHECK_TIME_MS 1000 /* 1 Second time out*/129#define RCFW_ERR_RETRY_COUNT (RCFW_CMD_WAIT_TIME_MS / RCFW_CMD_DEV_ERR_CHECK_TIME_MS)130131/* CMDQ elements */132#define BNXT_QPLIB_CMDQE_MAX_CNT 8192133#define BNXT_QPLIB_CMDQE_BYTES (BNXT_QPLIB_CMDQE_MAX_CNT * \134BNXT_QPLIB_CMDQE_UNITS)135#define BNXT_QPLIB_CMDQE_NPAGES ((BNXT_QPLIB_CMDQE_BYTES % \136PAGE_SIZE) ? \137((BNXT_QPLIB_CMDQE_BYTES / \138PAGE_SIZE) + 1) : \139(BNXT_QPLIB_CMDQE_BYTES / \140PAGE_SIZE))141#define BNXT_QPLIB_CMDQE_PAGE_SIZE (BNXT_QPLIB_CMDQE_NPAGES * \142PAGE_SIZE)143144#define RCFW_MAX_OUTSTANDING_CMD BNXT_QPLIB_CMDQE_MAX_CNT145#define RCFW_MAX_COOKIE_VALUE (BNXT_QPLIB_CMDQE_MAX_CNT - 1)146#define RCFW_CMD_IS_BLOCKING 0x8000147#define RCFW_NO_FW_ACCESS(rcfw) \148(test_bit(ERR_DEVICE_DETACHED, &(rcfw)->cmdq.flags) || \149pci_channel_offline((rcfw)->pdev))150151/* Crsq buf is 1024-Byte */152struct bnxt_qplib_crsbe {153u8 data[1024];154};155156/* Get the number of command units required for the req. The157* function returns correct value only if called before158* setting using bnxt_qplib_set_cmd_slots159*/160static inline u32 bnxt_qplib_get_cmd_slots(struct cmdq_base *req)161{162u32 cmd_units = 0;163164if (HAS_TLV_HEADER(req)) {165struct roce_tlv *tlv_req = (struct roce_tlv *)req;166cmd_units = tlv_req->total_size;167} else {168cmd_units = (req->cmd_size + BNXT_QPLIB_CMDQE_UNITS - 1) /169BNXT_QPLIB_CMDQE_UNITS;170}171return cmd_units;172}173174/* Set the cmd_size to a factor of CMDQE unit */175static inline u32 bnxt_qplib_set_cmd_slots(struct cmdq_base *req)176{177u32 cmd_byte = 0;178179if (HAS_TLV_HEADER(req)) {180struct roce_tlv *tlv_req = (struct roce_tlv *)req;181cmd_byte = tlv_req->total_size * BNXT_QPLIB_CMDQE_UNITS;182} else {183cmd_byte = req->cmd_size;184req->cmd_size = (req->cmd_size + BNXT_QPLIB_CMDQE_UNITS - 1) /185BNXT_QPLIB_CMDQE_UNITS;186}187188return cmd_byte;189}190191/* CREQ */192/* Allocate 1 per QP for async error notification for now */193#define BNXT_QPLIB_CREQE_MAX_CNT (64 * 1024)194#define BNXT_QPLIB_CREQE_UNITS 16 /* 16-Bytes per prod unit */195196#define CREQ_CMP_VALID(hdr, pass) \197(!!((hdr)->v & CREQ_BASE_V) == \198!(pass & BNXT_QPLIB_FLAG_EPOCH_CONS_MASK))199200#define CREQ_ENTRY_POLL_BUDGET 8201202typedef int (*aeq_handler_t)(struct bnxt_qplib_rcfw *, void *, void *);203204struct bnxt_qplib_crsqe {205struct creq_qp_event *resp;206u32 req_size;207bool is_waiter_alive;208bool is_internal_cmd;209bool is_in_used;210211/* Free slots at the time of submission */212u32 free_slots;213unsigned long send_timestamp;214u8 opcode;215u8 requested_qp_state;216};217218struct bnxt_qplib_rcfw_sbuf {219void *sb;220dma_addr_t dma_addr;221u32 size;222};223224#define BNXT_QPLIB_OOS_COUNT_MASK 0xFFFFFFFF225226#define FIRMWARE_INITIALIZED_FLAG (0)227#define FIRMWARE_FIRST_FLAG (31)228#define FIRMWARE_STALL_DETECTED (3)229#define ERR_DEVICE_DETACHED (4)230struct bnxt_qplib_cmdq_mbox {231struct bnxt_qplib_reg_desc reg;232void __iomem *prod;233void __iomem *db;234};235236struct bnxt_qplib_cmdq_ctx {237struct bnxt_qplib_hwq hwq;238struct bnxt_qplib_cmdq_mbox cmdq_mbox;239wait_queue_head_t waitq;240unsigned long flags;241unsigned long last_seen;242u32 seq_num;243};244245struct bnxt_qplib_creq_db {246struct bnxt_qplib_reg_desc reg;247void __iomem *db;248struct bnxt_qplib_db_info dbinfo;249};250251struct bnxt_qplib_creq_stat {252u64 creq_arm_count;253u64 creq_tasklet_schedule_count;254u64 creq_qp_event_processed;255u64 creq_func_event_processed;256};257258struct bnxt_qplib_creq_ctx {259struct bnxt_qplib_hwq hwq;260struct bnxt_qplib_creq_db creq_db;261struct bnxt_qplib_creq_stat stats;262aeq_handler_t aeq_handler;263u16 ring_id;264int msix_vec;265bool requested;266char *irq_name;267};268269/* RCFW Communication Channels */270#define BNXT_QPLIB_RCFW_SEND_RETRY_COUNT 4000271struct bnxt_qplib_rcfw {272struct pci_dev *pdev;273struct bnxt_qplib_res *res;274struct bnxt_qplib_cmdq_ctx cmdq;275struct bnxt_qplib_creq_ctx creq;276struct bnxt_qplib_crsqe *crsqe_tbl;277u32 rcfw_lat_slab_sec[RCFW_MAX_LATENCY_SEC_SLAB_INDEX];278279/* Slow path Perf Stats */280bool sp_perf_stats_enabled;281u32 *rcfw_lat_slab_msec;282u64 *qp_create_stats;283u64 *qp_destroy_stats;284u64 *qp_modify_stats;285u64 *mr_create_stats;286u64 *mr_destroy_stats;287u32 qp_create_stats_id;288u32 qp_destroy_stats_id;289u32 qp_modify_stats_id;290u32 mr_create_stats_id;291u32 mr_destroy_stats_id;292bool init_oos_stats;293u64 oos_prev;294u32 num_irq_stopped;295u32 num_irq_started;296u32 poll_in_intr_en;297u32 poll_in_intr_dis;298atomic_t rcfw_intr_enabled;299u32 cmdq_full_dbg;300struct semaphore rcfw_inflight;301unsigned int curr_shadow_qd;302atomic_t timeout_send;303/* cached from chip cctx for quick reference in slow path */304u16 max_timeout;305};306307struct bnxt_qplib_cmdqmsg {308struct cmdq_base *req;309struct creq_base *resp;310void *sb;311u32 req_sz;312u32 res_sz;313u8 block;314u8 qp_state;315};316317static inline void bnxt_qplib_fill_cmdqmsg(struct bnxt_qplib_cmdqmsg *msg,318void *req, void *resp, void *sb,319u32 req_sz, u32 res_sz, u8 block)320{321msg->req = req;322msg->resp = resp;323msg->sb = sb;324msg->req_sz = req_sz;325msg->res_sz = res_sz;326msg->block = block;327}328329void bnxt_qplib_free_rcfw_channel(struct bnxt_qplib_res *res);330int bnxt_qplib_alloc_rcfw_channel(struct bnxt_qplib_res *res);331void bnxt_qplib_rcfw_stop_irq(struct bnxt_qplib_rcfw *rcfw, bool kill);332void bnxt_qplib_disable_rcfw_channel(struct bnxt_qplib_rcfw *rcfw);333int bnxt_qplib_rcfw_start_irq(struct bnxt_qplib_rcfw *rcfw, int msix_vector,334bool need_init);335int bnxt_qplib_enable_rcfw_channel(struct bnxt_qplib_rcfw *rcfw,336int msix_vector,337int cp_bar_reg_off,338aeq_handler_t aeq_handler);339340struct bnxt_qplib_rcfw_sbuf *bnxt_qplib_rcfw_alloc_sbuf(341struct bnxt_qplib_rcfw *rcfw,342u32 size);343void bnxt_qplib_rcfw_free_sbuf(struct bnxt_qplib_rcfw *rcfw,344struct bnxt_qplib_rcfw_sbuf *sbuf);345int bnxt_qplib_rcfw_send_message(struct bnxt_qplib_rcfw *rcfw,346struct bnxt_qplib_cmdqmsg *msg);347348int bnxt_qplib_deinit_rcfw(struct bnxt_qplib_rcfw *rcfw);349int bnxt_qplib_init_rcfw(struct bnxt_qplib_rcfw *rcfw, int is_virtfn);350void bnxt_qplib_mark_qp_error(void *qp_handle);351int __check_cmdq_stall(struct bnxt_qplib_rcfw *rcfw,352u32 *cur_prod, u32 *cur_cons);353#endif354355356