hinic: add support to handle hw abnormal event
[linux-2.6-microblaze.git] / drivers / net / ethernet / huawei / hinic / hinic_hw_mgmt.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Huawei HiNIC PCI Express Linux driver
4  * Copyright(c) 2017 Huawei Technologies Co., Ltd
5  */
6
7 #ifndef HINIC_HW_MGMT_H
8 #define HINIC_HW_MGMT_H
9
10 #include <linux/types.h>
11 #include <linux/semaphore.h>
12 #include <linux/completion.h>
13 #include <linux/bitops.h>
14
15 #include "hinic_hw_if.h"
16 #include "hinic_hw_api_cmd.h"
17
18 #define HINIC_MSG_HEADER_MSG_LEN_SHIFT                          0
19 #define HINIC_MSG_HEADER_MODULE_SHIFT                           11
20 #define HINIC_MSG_HEADER_SEG_LEN_SHIFT                          16
21 #define HINIC_MSG_HEADER_NO_ACK_SHIFT                           22
22 #define HINIC_MSG_HEADER_ASYNC_MGMT_TO_PF_SHIFT                 23
23 #define HINIC_MSG_HEADER_SEQID_SHIFT                            24
24 #define HINIC_MSG_HEADER_LAST_SHIFT                             30
25 #define HINIC_MSG_HEADER_DIRECTION_SHIFT                        31
26 #define HINIC_MSG_HEADER_CMD_SHIFT                              32
27 #define HINIC_MSG_HEADER_ZEROS_SHIFT                            40
28 #define HINIC_MSG_HEADER_PCI_INTF_SHIFT                         48
29 #define HINIC_MSG_HEADER_PF_IDX_SHIFT                           50
30 #define HINIC_MSG_HEADER_MSG_ID_SHIFT                           54
31
32 #define HINIC_MSG_HEADER_MSG_LEN_MASK                           0x7FF
33 #define HINIC_MSG_HEADER_MODULE_MASK                            0x1F
34 #define HINIC_MSG_HEADER_SEG_LEN_MASK                           0x3F
35 #define HINIC_MSG_HEADER_NO_ACK_MASK                            0x1
36 #define HINIC_MSG_HEADER_ASYNC_MGMT_TO_PF_MASK                  0x1
37 #define HINIC_MSG_HEADER_SEQID_MASK                             0x3F
38 #define HINIC_MSG_HEADER_LAST_MASK                              0x1
39 #define HINIC_MSG_HEADER_DIRECTION_MASK                         0x1
40 #define HINIC_MSG_HEADER_CMD_MASK                               0xFF
41 #define HINIC_MSG_HEADER_ZEROS_MASK                             0xFF
42 #define HINIC_MSG_HEADER_PCI_INTF_MASK                          0x3
43 #define HINIC_MSG_HEADER_PF_IDX_MASK                            0xF
44 #define HINIC_MSG_HEADER_MSG_ID_MASK                            0x3FF
45
46 #define HINIC_MSG_HEADER_SET(val, member)                       \
47                 ((u64)((val) & HINIC_MSG_HEADER_##member##_MASK) << \
48                  HINIC_MSG_HEADER_##member##_SHIFT)
49
50 #define HINIC_MSG_HEADER_GET(val, member)                       \
51                 (((val) >> HINIC_MSG_HEADER_##member##_SHIFT) & \
52                  HINIC_MSG_HEADER_##member##_MASK)
53
54 enum hinic_mgmt_msg_type {
55         HINIC_MGMT_MSG_SYNC = 1,
56 };
57
58 enum hinic_cfg_cmd {
59         HINIC_CFG_NIC_CAP = 0,
60 };
61
62 enum hinic_comm_cmd {
63         HINIC_COMM_CMD_START_FLR          = 0x1,
64         HINIC_COMM_CMD_IO_STATUS_GET    = 0x3,
65         HINIC_COMM_CMD_DMA_ATTR_SET         = 0x4,
66
67         HINIC_COMM_CMD_CMDQ_CTXT_SET    = 0x10,
68         HINIC_COMM_CMD_CMDQ_CTXT_GET    = 0x11,
69
70         HINIC_COMM_CMD_HWCTXT_SET       = 0x12,
71         HINIC_COMM_CMD_HWCTXT_GET       = 0x13,
72
73         HINIC_COMM_CMD_SQ_HI_CI_SET     = 0x14,
74
75         HINIC_COMM_CMD_RES_STATE_SET    = 0x24,
76
77         HINIC_COMM_CMD_IO_RES_CLEAR     = 0x29,
78
79         HINIC_COMM_CMD_CEQ_CTRL_REG_WR_BY_UP = 0x33,
80
81         HINIC_COMM_CMD_MSI_CTRL_REG_WR_BY_UP,
82         HINIC_COMM_CMD_MSI_CTRL_REG_RD_BY_UP,
83
84         HINIC_COMM_CMD_FAULT_REPORT     = 0x37,
85
86         HINIC_COMM_CMD_SET_LED_STATUS   = 0x4a,
87
88         HINIC_COMM_CMD_L2NIC_RESET      = 0x4b,
89
90         HINIC_COMM_CMD_PAGESIZE_SET     = 0x50,
91
92         HINIC_COMM_CMD_GET_BOARD_INFO   = 0x52,
93
94         HINIC_COMM_CMD_WATCHDOG_INFO    = 0x56,
95
96         HINIC_COMM_CMD_MAX,
97 };
98
99 enum hinic_mgmt_cb_state {
100         HINIC_MGMT_CB_ENABLED = BIT(0),
101         HINIC_MGMT_CB_RUNNING = BIT(1),
102 };
103
104 struct hinic_recv_msg {
105         u8                      *msg;
106         u8                      *buf_out;
107
108         struct completion       recv_done;
109
110         u16                     cmd;
111         enum hinic_mod_type     mod;
112         int                     async_mgmt_to_pf;
113
114         u16                     msg_len;
115         u16                     msg_id;
116 };
117
118 struct hinic_mgmt_cb {
119         void    (*cb)(void *handle, u8 cmd,
120                       void *buf_in, u16 in_size,
121                       void *buf_out, u16 *out_size);
122
123         void            *handle;
124         unsigned long   state;
125 };
126
127 struct hinic_pf_to_mgmt {
128         struct hinic_hwif               *hwif;
129         struct hinic_hwdev              *hwdev;
130         struct semaphore                sync_msg_lock;
131         u16                             sync_msg_id;
132         u8                              *sync_msg_buf;
133         void                            *mgmt_ack_buf;
134
135         struct hinic_recv_msg           recv_resp_msg_from_mgmt;
136         struct hinic_recv_msg           recv_msg_from_mgmt;
137
138         struct hinic_api_cmd_chain      *cmd_chain[HINIC_API_CMD_MAX];
139
140         struct hinic_mgmt_cb            mgmt_cb[HINIC_MOD_MAX];
141
142         struct workqueue_struct         *workq;
143 };
144
145 struct hinic_mgmt_msg_handle_work {
146         struct work_struct work;
147         struct hinic_pf_to_mgmt *pf_to_mgmt;
148
149         void                    *msg;
150         u16                     msg_len;
151
152         enum hinic_mod_type     mod;
153         u8                      cmd;
154         u16                     msg_id;
155         int                     async_mgmt_to_pf;
156 };
157
158 void hinic_register_mgmt_msg_cb(struct hinic_pf_to_mgmt *pf_to_mgmt,
159                                 enum hinic_mod_type mod,
160                                 void *handle,
161                                 void (*callback)(void *handle,
162                                                  u8 cmd, void *buf_in,
163                                                  u16 in_size, void *buf_out,
164                                                  u16 *out_size));
165
166 void hinic_unregister_mgmt_msg_cb(struct hinic_pf_to_mgmt *pf_to_mgmt,
167                                   enum hinic_mod_type mod);
168
169 int hinic_msg_to_mgmt(struct hinic_pf_to_mgmt *pf_to_mgmt,
170                       enum hinic_mod_type mod, u8 cmd,
171                       void *buf_in, u16 in_size, void *buf_out, u16 *out_size,
172                       enum hinic_mgmt_msg_type sync);
173
174 int hinic_pf_to_mgmt_init(struct hinic_pf_to_mgmt *pf_to_mgmt,
175                           struct hinic_hwif *hwif);
176
177 void hinic_pf_to_mgmt_free(struct hinic_pf_to_mgmt *pf_to_mgmt);
178
179 #endif