| 1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 |
/* Copyright (c) 2025 Broadcom */ |
| 3 |
|
| 4 |
#ifndef _BNGE_HWRM_H_ |
| 5 |
#define _BNGE_HWRM_H_ |
| 6 |
|
| 7 |
#include <linux/bnge/hsi.h> |
| 8 |
|
| 9 |
enum bnge_hwrm_ctx_flags { |
| 10 |
BNGE_HWRM_INTERNAL_CTX_OWNED = BIT(0), |
| 11 |
BNGE_HWRM_INTERNAL_RESP_DIRTY = BIT(1), |
| 12 |
BNGE_HWRM_CTX_SILENT = BIT(2), |
| 13 |
BNGE_HWRM_FULL_WAIT = BIT(3), |
| 14 |
}; |
| 15 |
|
| 16 |
#define BNGE_HWRM_API_FLAGS (BNGE_HWRM_CTX_SILENT | BNGE_HWRM_FULL_WAIT) |
| 17 |
|
| 18 |
struct bnge_hwrm_ctx { |
| 19 |
u64 sentinel; |
| 20 |
dma_addr_t dma_handle; |
| 21 |
struct output *resp; |
| 22 |
struct input *req; |
| 23 |
dma_addr_t slice_handle; |
| 24 |
void *slice_addr; |
| 25 |
u32 slice_size; |
| 26 |
u32 req_len; |
| 27 |
enum bnge_hwrm_ctx_flags flags; |
| 28 |
unsigned int timeout; |
| 29 |
u32 allocated; |
| 30 |
gfp_t gfp; |
| 31 |
}; |
| 32 |
|
| 33 |
enum bnge_hwrm_wait_state { |
| 34 |
BNGE_HWRM_PENDING, |
| 35 |
BNGE_HWRM_DEFERRED, |
| 36 |
BNGE_HWRM_COMPLETE, |
| 37 |
BNGE_HWRM_CANCELLED, |
| 38 |
}; |
| 39 |
|
| 40 |
enum bnge_hwrm_chnl { BNGE_HWRM_CHNL_CHIMP, BNGE_HWRM_CHNL_KONG }; |
| 41 |
|
| 42 |
struct bnge_hwrm_wait_token { |
| 43 |
struct rcu_head rcu; |
| 44 |
struct hlist_node node; |
| 45 |
enum bnge_hwrm_wait_state state; |
| 46 |
enum bnge_hwrm_chnl dst; |
| 47 |
u16 seq_id; |
| 48 |
}; |
| 49 |
|
| 50 |
#define BNGE_DFLT_HWRM_CMD_TIMEOUT 500 |
| 51 |
|
| 52 |
#define BNGE_GRCPF_REG_CHIMP_COMM 0x0 |
| 53 |
#define BNGE_GRCPF_REG_CHIMP_COMM_TRIGGER 0x100 |
| 54 |
|
| 55 |
#define BNGE_HWRM_MAX_REQ_LEN (bd->hwrm_max_req_len) |
| 56 |
#define BNGE_HWRM_SHORT_REQ_LEN sizeof(struct hwrm_short_input) |
| 57 |
#define BNGE_HWRM_CMD_MAX_TIMEOUT 40000U |
| 58 |
#define BNGE_SHORT_HWRM_CMD_TIMEOUT 20 |
| 59 |
#define BNGE_HWRM_CMD_TIMEOUT (bd->hwrm_cmd_timeout) |
| 60 |
#define BNGE_HWRM_RESET_TIMEOUT ((BNGE_HWRM_CMD_TIMEOUT) * 4) |
| 61 |
#define BNGE_HWRM_TARGET 0xffff |
| 62 |
#define BNGE_HWRM_NO_CMPL_RING -1 |
| 63 |
#define BNGE_HWRM_REQ_MAX_SIZE 128 |
| 64 |
#define BNGE_HWRM_DMA_SIZE (2 * PAGE_SIZE) /* space for req+resp */ |
| 65 |
#define BNGE_HWRM_RESP_RESERVED PAGE_SIZE |
| 66 |
#define BNGE_HWRM_RESP_OFFSET (BNGE_HWRM_DMA_SIZE - \ |
| 67 |
BNGE_HWRM_RESP_RESERVED) |
| 68 |
#define BNGE_HWRM_CTX_OFFSET (BNGE_HWRM_RESP_OFFSET - \ |
| 69 |
sizeof(struct bnge_hwrm_ctx)) |
| 70 |
#define BNGE_HWRM_DMA_ALIGN 16 |
| 71 |
#define BNGE_HWRM_SENTINEL 0xb6e1f68a12e9a7eb /* arbitrary value */ |
| 72 |
#define BNGE_HWRM_SHORT_MIN_TIMEOUT 3 |
| 73 |
#define BNGE_HWRM_SHORT_MAX_TIMEOUT 10 |
| 74 |
#define BNGE_HWRM_SHORT_TIMEOUT_COUNTER 5 |
| 75 |
|
| 76 |
#define BNGE_HWRM_MIN_TIMEOUT 25 |
| 77 |
#define BNGE_HWRM_MAX_TIMEOUT 40 |
| 78 |
|
| 79 |
static inline unsigned int bnge_hwrm_timeout(unsigned int n) |
| 80 |
{ |
| 81 |
return n <= BNGE_HWRM_SHORT_TIMEOUT_COUNTER ? |
| 82 |
n * BNGE_HWRM_SHORT_MIN_TIMEOUT : |
| 83 |
BNGE_HWRM_SHORT_TIMEOUT_COUNTER * |
| 84 |
BNGE_HWRM_SHORT_MIN_TIMEOUT + |
| 85 |
(n - BNGE_HWRM_SHORT_TIMEOUT_COUNTER) * |
| 86 |
BNGE_HWRM_MIN_TIMEOUT; |
| 87 |
} |
| 88 |
|
| 89 |
#define BNGE_HWRM_FIN_WAIT_USEC 50000 |
| 90 |
|
| 91 |
void bnge_cleanup_hwrm_resources(struct bnge_dev *bd); |
| 92 |
int bnge_init_hwrm_resources(struct bnge_dev *bd); |
| 93 |
|
| 94 |
int bnge_hwrm_req_create(struct bnge_dev *bd, void **req, u16 req_type, |
| 95 |
u32 req_len); |
| 96 |
#define bnge_hwrm_req_init(bd, req, req_type) \ |
| 97 |
bnge_hwrm_req_create((bd), (void **)&(req), (req_type), \ |
| 98 |
sizeof(*(req))) |
| 99 |
void *bnge_hwrm_req_hold(struct bnge_dev *bd, void *req); |
| 100 |
void bnge_hwrm_req_drop(struct bnge_dev *bd, void *req); |
| 101 |
void bnge_hwrm_req_flags(struct bnge_dev *bd, void *req, |
| 102 |
enum bnge_hwrm_ctx_flags flags); |
| 103 |
void bnge_hwrm_req_timeout(struct bnge_dev *bd, void *req, |
| 104 |
unsigned int timeout); |
| 105 |
int bnge_hwrm_req_send(struct bnge_dev *bd, void *req); |
| 106 |
int bnge_hwrm_req_send_silent(struct bnge_dev *bd, void *req); |
| 107 |
void bnge_hwrm_req_alloc_flags(struct bnge_dev *bd, void *req, gfp_t flags); |
| 108 |
void *bnge_hwrm_req_dma_slice(struct bnge_dev *bd, void *req, u32 size, |
| 109 |
dma_addr_t *dma); |
| 110 |
int bnge_hwrm_req_replace(struct bnge_dev *bd, void *req, void *new_req, |
| 111 |
u32 len); |
| 112 |
#endif /* _BNGE_HWRM_H_ */ |