1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* Huawei HiNIC PCI Express Linux driver 3 * Copyright(c) 2017 Huawei Technologies Co., Ltd 4 */ 5 6 #ifndef HINIC_MBOX_H_ 7 #define HINIC_MBOX_H_ 8 9 #define HINIC_MBOX_PF_SEND_ERR 0x1 10 #define HINIC_MBOX_PF_BUSY_ACTIVE_FW 0x2 11 #define HINIC_MBOX_VF_CMD_ERROR 0x3 12 13 #define HINIC_MAX_FUNCTIONS 512 14 15 #define HINIC_MAX_PF_FUNCS 16 16 17 #define HINIC_MBOX_WQ_NAME "hinic_mbox" 18 19 #define HINIC_FUNC_CSR_MAILBOX_DATA_OFF 0x80 20 #define HINIC_FUNC_CSR_MAILBOX_CONTROL_OFF 0x0100 21 #define HINIC_FUNC_CSR_MAILBOX_INT_OFFSET_OFF 0x0104 22 #define HINIC_FUNC_CSR_MAILBOX_RESULT_H_OFF 0x0108 23 #define HINIC_FUNC_CSR_MAILBOX_RESULT_L_OFF 0x010C 24 25 enum hinic_mbox_ack_type { 26 MBOX_ACK, 27 MBOX_NO_ACK, 28 }; 29 30 struct mbox_msg_info { 31 u8 msg_id; 32 u8 status; 33 }; 34 35 struct hinic_recv_mbox { 36 struct completion recv_done; 37 void *mbox; 38 u8 cmd; 39 enum hinic_mod_type mod; 40 u16 mbox_len; 41 void *buf_out; 42 enum hinic_mbox_ack_type ack_type; 43 struct mbox_msg_info msg_info; 44 u8 seq_id; 45 atomic_t msg_cnt; 46 }; 47 48 struct hinic_send_mbox { 49 struct completion send_done; 50 u8 *data; 51 52 u64 *wb_status; 53 void *wb_vaddr; 54 dma_addr_t wb_paddr; 55 }; 56 57 typedef void (*hinic_vf_mbox_cb)(void *handle, u8 cmd, void *buf_in, 58 u16 in_size, void *buf_out, u16 *out_size); 59 typedef int (*hinic_pf_mbox_cb)(void *handle, u16 vf_id, u8 cmd, void *buf_in, 60 u16 in_size, void *buf_out, u16 *out_size); 61 62 enum mbox_event_state { 63 EVENT_START = 0, 64 EVENT_FAIL, 65 EVENT_TIMEOUT, 66 EVENT_END, 67 }; 68 69 enum hinic_mbox_cb_state { 70 HINIC_VF_MBOX_CB_REG = 0, 71 HINIC_VF_MBOX_CB_RUNNING, 72 HINIC_PF_MBOX_CB_REG, 73 HINIC_PF_MBOX_CB_RUNNING, 74 HINIC_PPF_MBOX_CB_REG, 75 HINIC_PPF_MBOX_CB_RUNNING, 76 HINIC_PPF_TO_PF_MBOX_CB_REG, 77 HINIC_PPF_TO_PF_MBOX_CB_RUNNIG, 78 }; 79 80 struct hinic_mbox_func_to_func { 81 struct hinic_hwdev *hwdev; 82 struct hinic_hwif *hwif; 83 84 struct semaphore mbox_send_sem; 85 struct semaphore msg_send_sem; 86 struct hinic_send_mbox send_mbox; 87 88 struct workqueue_struct *workq; 89 90 struct hinic_recv_mbox mbox_resp[HINIC_MAX_FUNCTIONS]; 91 struct hinic_recv_mbox mbox_send[HINIC_MAX_FUNCTIONS]; 92 93 hinic_vf_mbox_cb vf_mbox_cb[HINIC_MOD_MAX]; 94 hinic_pf_mbox_cb pf_mbox_cb[HINIC_MOD_MAX]; 95 unsigned long pf_mbox_cb_state[HINIC_MOD_MAX]; 96 unsigned long vf_mbox_cb_state[HINIC_MOD_MAX]; 97 98 u8 send_msg_id; 99 enum mbox_event_state event_flag; 100 101 /* lock for mbox event flag */ 102 spinlock_t mbox_lock; 103 }; 104 105 struct hinic_mbox_work { 106 struct work_struct work; 107 u16 src_func_idx; 108 struct hinic_mbox_func_to_func *func_to_func; 109 struct hinic_recv_mbox *recv_mbox; 110 }; 111 112 struct vf_cmd_msg_handle { 113 u8 cmd; 114 int (*cmd_msg_handler)(void *hwdev, u16 vf_id, 115 void *buf_in, u16 in_size, 116 void *buf_out, u16 *out_size); 117 }; 118 119 int hinic_register_pf_mbox_cb(struct hinic_hwdev *hwdev, 120 enum hinic_mod_type mod, 121 hinic_pf_mbox_cb callback); 122 123 int hinic_register_vf_mbox_cb(struct hinic_hwdev *hwdev, 124 enum hinic_mod_type mod, 125 hinic_vf_mbox_cb callback); 126 127 void hinic_unregister_pf_mbox_cb(struct hinic_hwdev *hwdev, 128 enum hinic_mod_type mod); 129 130 void hinic_unregister_vf_mbox_cb(struct hinic_hwdev *hwdev, 131 enum hinic_mod_type mod); 132 133 void hinic_mbox_func_aeqe_handler(void *handle, void *header, u8 size); 134 135 void hinic_mbox_self_aeqe_handler(void *handle, void *header, u8 size); 136 137 int hinic_func_to_func_init(struct hinic_hwdev *hwdev); 138 139 void hinic_func_to_func_free(struct hinic_hwdev *hwdev); 140 141 int hinic_mbox_to_pf(struct hinic_hwdev *hwdev, enum hinic_mod_type mod, 142 u8 cmd, void *buf_in, u16 in_size, void *buf_out, 143 u16 *out_size, u32 timeout); 144 145 int hinic_mbox_to_func(struct hinic_mbox_func_to_func *func_to_func, 146 enum hinic_mod_type mod, u16 cmd, u16 dst_func, 147 void *buf_in, u16 in_size, void *buf_out, 148 u16 *out_size, u32 timeout); 149 150 int hinic_mbox_to_vf(struct hinic_hwdev *hwdev, 151 enum hinic_mod_type mod, u16 vf_id, u8 cmd, void *buf_in, 152 u16 in_size, void *buf_out, u16 *out_size, u32 timeout); 153 154 #endif 155