xref: /linux/drivers/net/ethernet/huawei/hinic3/hinic3_mgmt.h (revision 37a93dd5c49b5fda807fd204edf2547c3493319c)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. */
3 
4 #ifndef _HINIC3_MGMT_H_
5 #define _HINIC3_MGMT_H_
6 
7 #include <linux/types.h>
8 
9 #include "hinic3_mbox.h"
10 #include "hinic3_hw_intf.h"
11 
12 struct hinic3_hwdev;
13 
14 struct hinic3_recv_msg {
15 	/* Preallocated buffer of size MAX_PF_MGMT_BUF_SIZE that accumulates
16 	 * receive message, segment-by-segment.
17 	 */
18 	void                 *msg;
19 	/* Message id for which segments are accumulated. */
20 	u8                   msg_id;
21 	/* Sequence id of last received segment of current message. */
22 	u8                   seq_id;
23 	u16                  msg_len;
24 	int                  async_mgmt_to_pf;
25 	enum mgmt_mod_type   mod;
26 	u16                  cmd;
27 	struct completion    recv_done;
28 };
29 
30 enum comm_pf_to_mgmt_event_state {
31 	COMM_SEND_EVENT_UNINIT,
32 	COMM_SEND_EVENT_START,
33 	COMM_SEND_EVENT_SUCCESS,
34 	COMM_SEND_EVENT_TIMEOUT,
35 };
36 
37 struct hinic3_msg_pf_to_mgmt {
38 	struct hinic3_hwdev              *hwdev;
39 	struct workqueue_struct          *workq;
40 	void                             *mgmt_ack_buf;
41 	struct hinic3_recv_msg           recv_msg_from_mgmt;
42 	struct hinic3_recv_msg           recv_resp_msg_from_mgmt;
43 	u16                              async_msg_id;
44 	u16                              sync_msg_id;
45 	void                             *async_msg_cb_data[MGMT_MOD_HW_MAX];
46 	/* synchronizes message send with message receives via event queue */
47 	spinlock_t                       sync_event_lock;
48 	enum comm_pf_to_mgmt_event_state event_flag;
49 };
50 
51 struct mgmt_msg_handle_work {
52 	struct work_struct           work;
53 	struct hinic3_msg_pf_to_mgmt *pf_to_mgmt;
54 	void                         *msg;
55 	u16                          msg_len;
56 	enum mgmt_mod_type           mod;
57 	u16                          cmd;
58 	u16                          msg_id;
59 	int                          async_mgmt_to_pf;
60 };
61 
62 int hinic3_pf_to_mgmt_init(struct hinic3_hwdev *hwdev);
63 void hinic3_pf_to_mgmt_free(struct hinic3_hwdev *hwdev);
64 void hinic3_flush_mgmt_workq(struct hinic3_hwdev *hwdev);
65 void hinic3_mgmt_msg_aeqe_handler(struct hinic3_hwdev *hwdev,
66 				  u8 *header, u8 size);
67 
68 #endif
69