2 * Huawei HiNIC PCI Express Linux driver
3 * Copyright(c) 2017 Huawei Technologies Co., Ltd
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #ifndef HINIC_HW_MGMT_H
17 #define HINIC_HW_MGMT_H
19 #include <linux/types.h>
20 #include <linux/semaphore.h>
21 #include <linux/completion.h>
22 #include <linux/bitops.h>
24 #include "hinic_hw_if.h"
25 #include "hinic_hw_api_cmd.h"
27 #define HINIC_MSG_HEADER_MSG_LEN_SHIFT 0
28 #define HINIC_MSG_HEADER_MODULE_SHIFT 11
29 #define HINIC_MSG_HEADER_SEG_LEN_SHIFT 16
30 #define HINIC_MSG_HEADER_NO_ACK_SHIFT 22
31 #define HINIC_MSG_HEADER_ASYNC_MGMT_TO_PF_SHIFT 23
32 #define HINIC_MSG_HEADER_SEQID_SHIFT 24
33 #define HINIC_MSG_HEADER_LAST_SHIFT 30
34 #define HINIC_MSG_HEADER_DIRECTION_SHIFT 31
35 #define HINIC_MSG_HEADER_CMD_SHIFT 32
36 #define HINIC_MSG_HEADER_ZEROS_SHIFT 40
37 #define HINIC_MSG_HEADER_PCI_INTF_SHIFT 48
38 #define HINIC_MSG_HEADER_PF_IDX_SHIFT 50
39 #define HINIC_MSG_HEADER_MSG_ID_SHIFT 54
41 #define HINIC_MSG_HEADER_MSG_LEN_MASK 0x7FF
42 #define HINIC_MSG_HEADER_MODULE_MASK 0x1F
43 #define HINIC_MSG_HEADER_SEG_LEN_MASK 0x3F
44 #define HINIC_MSG_HEADER_NO_ACK_MASK 0x1
45 #define HINIC_MSG_HEADER_ASYNC_MGMT_TO_PF_MASK 0x1
46 #define HINIC_MSG_HEADER_SEQID_MASK 0x3F
47 #define HINIC_MSG_HEADER_LAST_MASK 0x1
48 #define HINIC_MSG_HEADER_DIRECTION_MASK 0x1
49 #define HINIC_MSG_HEADER_CMD_MASK 0xFF
50 #define HINIC_MSG_HEADER_ZEROS_MASK 0xFF
51 #define HINIC_MSG_HEADER_PCI_INTF_MASK 0x3
52 #define HINIC_MSG_HEADER_PF_IDX_MASK 0xF
53 #define HINIC_MSG_HEADER_MSG_ID_MASK 0x3FF
55 #define HINIC_MSG_HEADER_SET(val, member) \
56 ((u64)((val) & HINIC_MSG_HEADER_##member##_MASK) << \
57 HINIC_MSG_HEADER_##member##_SHIFT)
59 #define HINIC_MSG_HEADER_GET(val, member) \
60 (((val) >> HINIC_MSG_HEADER_##member##_SHIFT) & \
61 HINIC_MSG_HEADER_##member##_MASK)
63 enum hinic_mgmt_msg_type
{
64 HINIC_MGMT_MSG_SYNC
= 1,
68 HINIC_CFG_NIC_CAP
= 0,
72 HINIC_COMM_CMD_IO_STATUS_GET
= 0x3,
74 HINIC_COMM_CMD_CMDQ_CTXT_SET
= 0x10,
75 HINIC_COMM_CMD_CMDQ_CTXT_GET
= 0x11,
77 HINIC_COMM_CMD_HWCTXT_SET
= 0x12,
78 HINIC_COMM_CMD_HWCTXT_GET
= 0x13,
80 HINIC_COMM_CMD_SQ_HI_CI_SET
= 0x14,
82 HINIC_COMM_CMD_RES_STATE_SET
= 0x24,
84 HINIC_COMM_CMD_IO_RES_CLEAR
= 0x29,
86 HINIC_COMM_CMD_MAX
= 0x32,
89 enum hinic_mgmt_cb_state
{
90 HINIC_MGMT_CB_ENABLED
= BIT(0),
91 HINIC_MGMT_CB_RUNNING
= BIT(1),
94 struct hinic_recv_msg
{
98 struct completion recv_done
;
101 enum hinic_mod_type mod
;
102 int async_mgmt_to_pf
;
108 struct hinic_mgmt_cb
{
109 void (*cb
)(void *handle
, u8 cmd
,
110 void *buf_in
, u16 in_size
,
111 void *buf_out
, u16
*out_size
);
117 struct hinic_pf_to_mgmt
{
118 struct hinic_hwif
*hwif
;
120 struct semaphore sync_msg_lock
;
124 struct hinic_recv_msg recv_resp_msg_from_mgmt
;
125 struct hinic_recv_msg recv_msg_from_mgmt
;
127 struct hinic_api_cmd_chain
*cmd_chain
[HINIC_API_CMD_MAX
];
129 struct hinic_mgmt_cb mgmt_cb
[HINIC_MOD_MAX
];
132 void hinic_register_mgmt_msg_cb(struct hinic_pf_to_mgmt
*pf_to_mgmt
,
133 enum hinic_mod_type mod
,
135 void (*callback
)(void *handle
,
136 u8 cmd
, void *buf_in
,
137 u16 in_size
, void *buf_out
,
140 void hinic_unregister_mgmt_msg_cb(struct hinic_pf_to_mgmt
*pf_to_mgmt
,
141 enum hinic_mod_type mod
);
143 int hinic_msg_to_mgmt(struct hinic_pf_to_mgmt
*pf_to_mgmt
,
144 enum hinic_mod_type mod
, u8 cmd
,
145 void *buf_in
, u16 in_size
, void *buf_out
, u16
*out_size
,
146 enum hinic_mgmt_msg_type sync
);
148 int hinic_pf_to_mgmt_init(struct hinic_pf_to_mgmt
*pf_to_mgmt
,
149 struct hinic_hwif
*hwif
);
151 void hinic_pf_to_mgmt_free(struct hinic_pf_to_mgmt
*pf_to_mgmt
);