0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 #ifndef __BNXT_QPLIB_RCFW_H__
0040 #define __BNXT_QPLIB_RCFW_H__
0041
0042 #define RCFW_CMDQ_TRIG_VAL 1
0043 #define RCFW_COMM_PCI_BAR_REGION 0
0044 #define RCFW_COMM_CONS_PCI_BAR_REGION 2
0045 #define RCFW_COMM_BASE_OFFSET 0x600
0046 #define RCFW_PF_COMM_PROD_OFFSET 0xc
0047 #define RCFW_VF_COMM_PROD_OFFSET 0xc
0048 #define RCFW_COMM_TRIG_OFFSET 0x100
0049 #define RCFW_COMM_SIZE 0x104
0050
0051 #define RCFW_DBR_PCI_BAR_REGION 2
0052 #define RCFW_DBR_BASE_PAGE_SHIFT 12
0053
0054 #define RCFW_CMD_PREP(req, CMD, cmd_flags) \
0055 do { \
0056 memset(&(req), 0, sizeof((req))); \
0057 (req).opcode = CMDQ_BASE_OPCODE_##CMD; \
0058 (req).cmd_size = sizeof((req)); \
0059 (req).flags = cpu_to_le16(cmd_flags); \
0060 } while (0)
0061
0062 #define RCFW_CMD_WAIT_TIME_MS 20000
0063
0064
0065 struct bnxt_qplib_cmdqe {
0066 u8 data[16];
0067 };
0068
0069
0070 #define BNXT_QPLIB_CMDQE_MAX_CNT_256 256
0071 #define BNXT_QPLIB_CMDQE_MAX_CNT_8192 8192
0072 #define BNXT_QPLIB_CMDQE_UNITS sizeof(struct bnxt_qplib_cmdqe)
0073 #define BNXT_QPLIB_CMDQE_BYTES(depth) ((depth) * BNXT_QPLIB_CMDQE_UNITS)
0074
0075 static inline u32 bnxt_qplib_cmdqe_npages(u32 depth)
0076 {
0077 u32 npages;
0078
0079 npages = BNXT_QPLIB_CMDQE_BYTES(depth) / PAGE_SIZE;
0080 if (BNXT_QPLIB_CMDQE_BYTES(depth) % PAGE_SIZE)
0081 npages++;
0082 return npages;
0083 }
0084
0085 static inline u32 bnxt_qplib_cmdqe_page_size(u32 depth)
0086 {
0087 return (bnxt_qplib_cmdqe_npages(depth) * PAGE_SIZE);
0088 }
0089
0090
0091 static inline void bnxt_qplib_set_cmd_slots(struct cmdq_base *req)
0092 {
0093 req->cmd_size = (req->cmd_size + BNXT_QPLIB_CMDQE_UNITS - 1) /
0094 BNXT_QPLIB_CMDQE_UNITS;
0095 }
0096
0097 #define RCFW_MAX_COOKIE_VALUE 0x7FFF
0098 #define RCFW_CMD_IS_BLOCKING 0x8000
0099 #define RCFW_BLOCKED_CMD_WAIT_COUNT 20000000UL
0100
0101 #define HWRM_VERSION_RCFW_CMDQ_DEPTH_CHECK 0x1000900020011ULL
0102
0103
0104 struct bnxt_qplib_crsbe {
0105 u8 data[1024];
0106 };
0107
0108
0109
0110 #define BNXT_QPLIB_CREQE_MAX_CNT (64 * 1024)
0111 #define BNXT_QPLIB_CREQE_UNITS 16
0112 #define CREQ_CMP_VALID(hdr, raw_cons, cp_bit) \
0113 (!!((hdr)->v & CREQ_BASE_V) == \
0114 !((raw_cons) & (cp_bit)))
0115 #define CREQ_ENTRY_POLL_BUDGET 0x100
0116
0117
0118 typedef int (*aeq_handler_t)(struct bnxt_qplib_rcfw *, void *, void *);
0119
0120 struct bnxt_qplib_crsqe {
0121 struct creq_qp_event *resp;
0122 u32 req_size;
0123 };
0124
0125 struct bnxt_qplib_rcfw_sbuf {
0126 void *sb;
0127 dma_addr_t dma_addr;
0128 u32 size;
0129 };
0130
0131 struct bnxt_qplib_qp_node {
0132 u32 qp_id;
0133 void *qp_handle;
0134 };
0135
0136 #define BNXT_QPLIB_OOS_COUNT_MASK 0xFFFFFFFF
0137
0138 #define FIRMWARE_INITIALIZED_FLAG (0)
0139 #define FIRMWARE_FIRST_FLAG (31)
0140 #define FIRMWARE_TIMED_OUT (3)
0141 #define ERR_DEVICE_DETACHED (4)
0142
0143 struct bnxt_qplib_cmdq_mbox {
0144 struct bnxt_qplib_reg_desc reg;
0145 void __iomem *prod;
0146 void __iomem *db;
0147 };
0148
0149 struct bnxt_qplib_cmdq_ctx {
0150 struct bnxt_qplib_hwq hwq;
0151 struct bnxt_qplib_cmdq_mbox cmdq_mbox;
0152 wait_queue_head_t waitq;
0153 unsigned long flags;
0154 unsigned long *cmdq_bitmap;
0155 u32 seq_num;
0156 };
0157
0158 struct bnxt_qplib_creq_db {
0159 struct bnxt_qplib_reg_desc reg;
0160 struct bnxt_qplib_db_info dbinfo;
0161 };
0162
0163 struct bnxt_qplib_creq_stat {
0164 u64 creq_qp_event_processed;
0165 u64 creq_func_event_processed;
0166 };
0167
0168 struct bnxt_qplib_creq_ctx {
0169 struct bnxt_qplib_hwq hwq;
0170 struct bnxt_qplib_creq_db creq_db;
0171 struct bnxt_qplib_creq_stat stats;
0172 struct tasklet_struct creq_tasklet;
0173 aeq_handler_t aeq_handler;
0174 u16 ring_id;
0175 int msix_vec;
0176 bool requested;
0177 };
0178
0179
0180 struct bnxt_qplib_rcfw {
0181 struct pci_dev *pdev;
0182 struct bnxt_qplib_res *res;
0183 struct bnxt_qplib_cmdq_ctx cmdq;
0184 struct bnxt_qplib_creq_ctx creq;
0185 struct bnxt_qplib_crsqe *crsqe_tbl;
0186 int qp_tbl_size;
0187 struct bnxt_qplib_qp_node *qp_tbl;
0188 u64 oos_prev;
0189 u32 init_oos_stats;
0190 u32 cmdq_depth;
0191 };
0192
0193 void bnxt_qplib_free_rcfw_channel(struct bnxt_qplib_rcfw *rcfw);
0194 int bnxt_qplib_alloc_rcfw_channel(struct bnxt_qplib_res *res,
0195 struct bnxt_qplib_rcfw *rcfw,
0196 struct bnxt_qplib_ctx *ctx,
0197 int qp_tbl_sz);
0198 void bnxt_qplib_rcfw_stop_irq(struct bnxt_qplib_rcfw *rcfw, bool kill);
0199 void bnxt_qplib_disable_rcfw_channel(struct bnxt_qplib_rcfw *rcfw);
0200 int bnxt_qplib_rcfw_start_irq(struct bnxt_qplib_rcfw *rcfw, int msix_vector,
0201 bool need_init);
0202 int bnxt_qplib_enable_rcfw_channel(struct bnxt_qplib_rcfw *rcfw,
0203 int msix_vector,
0204 int cp_bar_reg_off, int virt_fn,
0205 aeq_handler_t aeq_handler);
0206
0207 struct bnxt_qplib_rcfw_sbuf *bnxt_qplib_rcfw_alloc_sbuf(
0208 struct bnxt_qplib_rcfw *rcfw,
0209 u32 size);
0210 void bnxt_qplib_rcfw_free_sbuf(struct bnxt_qplib_rcfw *rcfw,
0211 struct bnxt_qplib_rcfw_sbuf *sbuf);
0212 int bnxt_qplib_rcfw_send_message(struct bnxt_qplib_rcfw *rcfw,
0213 struct cmdq_base *req, struct creq_base *resp,
0214 void *sbuf, u8 is_block);
0215
0216 int bnxt_qplib_deinit_rcfw(struct bnxt_qplib_rcfw *rcfw);
0217 int bnxt_qplib_init_rcfw(struct bnxt_qplib_rcfw *rcfw,
0218 struct bnxt_qplib_ctx *ctx, int is_virtfn);
0219 void bnxt_qplib_mark_qp_error(void *qp_handle);
0220 static inline u32 map_qp_id_to_tbl_indx(u32 qid, struct bnxt_qplib_rcfw *rcfw)
0221 {
0222
0223 return (qid == 1) ? rcfw->qp_tbl_size - 1 : qid % rcfw->qp_tbl_size - 2;
0224 }
0225 #endif