0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BNXT_HWRM_H
0011 #define BNXT_HWRM_H
0012
0013 #include "bnxt_hsi.h"
0014
0015 enum bnxt_hwrm_ctx_flags {
0016
0017 BNXT_HWRM_INTERNAL_CTX_OWNED = BIT(0),
0018 BNXT_HWRM_INTERNAL_RESP_DIRTY = BIT(1),
0019 BNXT_HWRM_CTX_SILENT = BIT(2),
0020 BNXT_HWRM_FULL_WAIT = BIT(3),
0021 };
0022
0023 #define HWRM_API_FLAGS (BNXT_HWRM_CTX_SILENT | BNXT_HWRM_FULL_WAIT)
0024
0025 struct bnxt_hwrm_ctx {
0026 u64 sentinel;
0027 dma_addr_t dma_handle;
0028 struct output *resp;
0029 struct input *req;
0030 dma_addr_t slice_handle;
0031 void *slice_addr;
0032 u32 slice_size;
0033 u32 req_len;
0034 enum bnxt_hwrm_ctx_flags flags;
0035 unsigned int timeout;
0036 u32 allocated;
0037 gfp_t gfp;
0038 };
0039
0040 enum bnxt_hwrm_wait_state {
0041 BNXT_HWRM_PENDING,
0042 BNXT_HWRM_DEFERRED,
0043 BNXT_HWRM_COMPLETE,
0044 BNXT_HWRM_CANCELLED,
0045 };
0046
0047 enum bnxt_hwrm_chnl { BNXT_HWRM_CHNL_CHIMP, BNXT_HWRM_CHNL_KONG };
0048
0049 struct bnxt_hwrm_wait_token {
0050 struct rcu_head rcu;
0051 struct hlist_node node;
0052 enum bnxt_hwrm_wait_state state;
0053 enum bnxt_hwrm_chnl dst;
0054 u16 seq_id;
0055 };
0056
0057 void hwrm_update_token(struct bnxt *bp, u16 seq, enum bnxt_hwrm_wait_state s);
0058
0059 #define BNXT_HWRM_MAX_REQ_LEN (bp->hwrm_max_req_len)
0060 #define BNXT_HWRM_SHORT_REQ_LEN sizeof(struct hwrm_short_input)
0061 #define HWRM_CMD_MAX_TIMEOUT 40000U
0062 #define SHORT_HWRM_CMD_TIMEOUT 20
0063 #define HWRM_CMD_TIMEOUT (bp->hwrm_cmd_timeout)
0064 #define HWRM_RESET_TIMEOUT ((HWRM_CMD_TIMEOUT) * 4)
0065 #define BNXT_HWRM_TARGET 0xffff
0066 #define BNXT_HWRM_NO_CMPL_RING -1
0067 #define BNXT_HWRM_REQ_MAX_SIZE 128
0068 #define BNXT_HWRM_DMA_SIZE (2 * PAGE_SIZE)
0069 #define BNXT_HWRM_RESP_RESERVED PAGE_SIZE
0070 #define BNXT_HWRM_RESP_OFFSET (BNXT_HWRM_DMA_SIZE - \
0071 BNXT_HWRM_RESP_RESERVED)
0072 #define BNXT_HWRM_CTX_OFFSET (BNXT_HWRM_RESP_OFFSET - \
0073 sizeof(struct bnxt_hwrm_ctx))
0074 #define BNXT_HWRM_DMA_ALIGN 16
0075 #define BNXT_HWRM_SENTINEL 0xb6e1f68a12e9a7eb
0076 #define BNXT_HWRM_REQS_PER_PAGE (BNXT_PAGE_SIZE / \
0077 BNXT_HWRM_REQ_MAX_SIZE)
0078 #define HWRM_SHORT_MIN_TIMEOUT 3
0079 #define HWRM_SHORT_MAX_TIMEOUT 10
0080 #define HWRM_SHORT_TIMEOUT_COUNTER 5
0081
0082 #define HWRM_MIN_TIMEOUT 25
0083 #define HWRM_MAX_TIMEOUT 40
0084
0085 static inline unsigned int hwrm_total_timeout(unsigned int n)
0086 {
0087 return n <= HWRM_SHORT_TIMEOUT_COUNTER ? n * HWRM_SHORT_MIN_TIMEOUT :
0088 HWRM_SHORT_TIMEOUT_COUNTER * HWRM_SHORT_MIN_TIMEOUT +
0089 (n - HWRM_SHORT_TIMEOUT_COUNTER) * HWRM_MIN_TIMEOUT;
0090 }
0091
0092
0093 #define HWRM_VALID_BIT_DELAY_USEC 50000
0094
0095 static inline bool bnxt_cfa_hwrm_message(u16 req_type)
0096 {
0097 switch (req_type) {
0098 case HWRM_CFA_ENCAP_RECORD_ALLOC:
0099 case HWRM_CFA_ENCAP_RECORD_FREE:
0100 case HWRM_CFA_DECAP_FILTER_ALLOC:
0101 case HWRM_CFA_DECAP_FILTER_FREE:
0102 case HWRM_CFA_EM_FLOW_ALLOC:
0103 case HWRM_CFA_EM_FLOW_FREE:
0104 case HWRM_CFA_EM_FLOW_CFG:
0105 case HWRM_CFA_FLOW_ALLOC:
0106 case HWRM_CFA_FLOW_FREE:
0107 case HWRM_CFA_FLOW_INFO:
0108 case HWRM_CFA_FLOW_FLUSH:
0109 case HWRM_CFA_FLOW_STATS:
0110 case HWRM_CFA_METER_PROFILE_ALLOC:
0111 case HWRM_CFA_METER_PROFILE_FREE:
0112 case HWRM_CFA_METER_PROFILE_CFG:
0113 case HWRM_CFA_METER_INSTANCE_ALLOC:
0114 case HWRM_CFA_METER_INSTANCE_FREE:
0115 return true;
0116 default:
0117 return false;
0118 }
0119 }
0120
0121 static inline bool bnxt_kong_hwrm_message(struct bnxt *bp, struct input *req)
0122 {
0123 return (bp->fw_cap & BNXT_FW_CAP_KONG_MB_CHNL &&
0124 (bnxt_cfa_hwrm_message(le16_to_cpu(req->req_type)) ||
0125 le16_to_cpu(req->target_id) == HWRM_TARGET_ID_KONG));
0126 }
0127
0128 int __hwrm_req_init(struct bnxt *bp, void **req, u16 req_type, u32 req_len);
0129 #define hwrm_req_init(bp, req, req_type) \
0130 __hwrm_req_init((bp), (void **)&(req), (req_type), sizeof(*(req)))
0131 void *hwrm_req_hold(struct bnxt *bp, void *req);
0132 void hwrm_req_drop(struct bnxt *bp, void *req);
0133 void hwrm_req_flags(struct bnxt *bp, void *req, enum bnxt_hwrm_ctx_flags flags);
0134 void hwrm_req_timeout(struct bnxt *bp, void *req, unsigned int timeout);
0135 int hwrm_req_send(struct bnxt *bp, void *req);
0136 int hwrm_req_send_silent(struct bnxt *bp, void *req);
0137 int hwrm_req_replace(struct bnxt *bp, void *req, void *new_req, u32 len);
0138 void hwrm_req_alloc_flags(struct bnxt *bp, void *req, gfp_t flags);
0139 void *hwrm_req_dma_slice(struct bnxt *bp, void *req, u32 size, dma_addr_t *dma);
0140 #endif