0001
0002
0003
0004 #ifndef _FM10K_MBX_H_
0005 #define _FM10K_MBX_H_
0006
0007
0008 struct fm10k_mbx_info;
0009
0010 #include "fm10k_type.h"
0011 #include "fm10k_tlv.h"
0012
0013
0014 #define FM10K_MBMEM(_n) ((_n) + 0x18000)
0015 #define FM10K_MBMEM_VF(_n, _m) (((_n) * 0x10) + (_m) + 0x18000)
0016 #define FM10K_MBMEM_SM(_n) ((_n) + 0x18400)
0017 #define FM10K_MBMEM_PF(_n) ((_n) + 0x18600)
0018
0019 #define FM10K_MBMEM_PF_XOR (FM10K_MBMEM_SM(0) ^ FM10K_MBMEM_PF(0))
0020 #define FM10K_MBX(_n) ((_n) + 0x18800)
0021 #define FM10K_MBX_REQ 0x00000002
0022 #define FM10K_MBX_ACK 0x00000004
0023 #define FM10K_MBX_REQ_INTERRUPT 0x00000008
0024 #define FM10K_MBX_ACK_INTERRUPT 0x00000010
0025 #define FM10K_MBX_INTERRUPT_ENABLE 0x00000020
0026 #define FM10K_MBX_INTERRUPT_DISABLE 0x00000040
0027 #define FM10K_MBX_GLOBAL_REQ_INTERRUPT 0x00000200
0028 #define FM10K_MBX_GLOBAL_ACK_INTERRUPT 0x00000400
0029 #define FM10K_MBICR(_n) ((_n) + 0x18840)
0030 #define FM10K_GMBX 0x18842
0031
0032
0033 #define FM10K_VFMBX 0x00010
0034 #define FM10K_VFMBMEM(_n) ((_n) + 0x00020)
0035 #define FM10K_VFMBMEM_LEN 16
0036 #define FM10K_VFMBMEM_VF_XOR (FM10K_VFMBMEM_LEN / 2)
0037
0038
0039 #define FM10K_MBX_DISCONNECT_TIMEOUT 500
0040 #define FM10K_MBX_POLL_DELAY 19
0041 #define FM10K_MBX_INT_DELAY 20
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080 enum fm10k_mbx_state {
0081 FM10K_STATE_CLOSED,
0082 FM10K_STATE_CONNECT,
0083 FM10K_STATE_OPEN,
0084 FM10K_STATE_DISCONNECT,
0085 };
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121 #define FM10K_MSG_HDR_MASK(name) \
0122 ((0x1u << FM10K_MSG_##name##_SIZE) - 1)
0123 #define FM10K_MSG_HDR_FIELD_SET(value, name) \
0124 (((u32)(value) & FM10K_MSG_HDR_MASK(name)) << FM10K_MSG_##name##_SHIFT)
0125 #define FM10K_MSG_HDR_FIELD_GET(value, name) \
0126 ((u16)((value) >> FM10K_MSG_##name##_SHIFT) & FM10K_MSG_HDR_MASK(name))
0127
0128
0129 #define FM10K_MSG_TYPE_SHIFT 0
0130 #define FM10K_MSG_TYPE_SIZE 4
0131 #define FM10K_MSG_TAIL_SHIFT 4
0132 #define FM10K_MSG_TAIL_SIZE 4
0133 #define FM10K_MSG_HEAD_SHIFT 8
0134 #define FM10K_MSG_HEAD_SIZE 4
0135 #define FM10K_MSG_RSVD0_SHIFT 12
0136 #define FM10K_MSG_RSVD0_SIZE 4
0137
0138
0139 #define FM10K_MSG_CRC_SHIFT 16
0140 #define FM10K_MSG_CRC_SIZE 16
0141
0142
0143 #define FM10K_MSG_CONNECT_SIZE_SHIFT 16
0144 #define FM10K_MSG_CONNECT_SIZE_SIZE 16
0145
0146
0147 #define FM10K_MSG_ERR_NO_SHIFT 16
0148 #define FM10K_MSG_ERR_NO_SIZE 16
0149
0150 enum fm10k_msg_type {
0151 FM10K_MSG_DATA = 0x8,
0152 FM10K_MSG_CONNECT = 0xC,
0153 FM10K_MSG_DISCONNECT = 0xD,
0154 FM10K_MSG_ERROR = 0xE,
0155 };
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183 #define FM10K_SM_MBX_VERSION 1
0184 #define FM10K_SM_MBX_FIFO_LEN (FM10K_MBMEM_PF_XOR - 1)
0185
0186
0187 #define FM10K_MSG_SM_TAIL_SHIFT 0
0188 #define FM10K_MSG_SM_TAIL_SIZE 12
0189 #define FM10K_MSG_SM_VER_SHIFT 12
0190 #define FM10K_MSG_SM_VER_SIZE 4
0191 #define FM10K_MSG_SM_HEAD_SHIFT 16
0192 #define FM10K_MSG_SM_HEAD_SIZE 12
0193 #define FM10K_MSG_SM_ERR_SHIFT 28
0194 #define FM10K_MSG_SM_ERR_SIZE 4
0195
0196
0197
0198
0199
0200
0201
0202 #define FM10K_MBX_ERR(_n) ((_n) - 512)
0203 #define FM10K_MBX_ERR_NO_MBX FM10K_MBX_ERR(0x01)
0204 #define FM10K_MBX_ERR_NO_SPACE FM10K_MBX_ERR(0x03)
0205 #define FM10K_MBX_ERR_TAIL FM10K_MBX_ERR(0x05)
0206 #define FM10K_MBX_ERR_HEAD FM10K_MBX_ERR(0x06)
0207 #define FM10K_MBX_ERR_SRC FM10K_MBX_ERR(0x08)
0208 #define FM10K_MBX_ERR_TYPE FM10K_MBX_ERR(0x09)
0209 #define FM10K_MBX_ERR_SIZE FM10K_MBX_ERR(0x0B)
0210 #define FM10K_MBX_ERR_BUSY FM10K_MBX_ERR(0x0C)
0211 #define FM10K_MBX_ERR_RSVD0 FM10K_MBX_ERR(0x0E)
0212 #define FM10K_MBX_ERR_CRC FM10K_MBX_ERR(0x0F)
0213
0214 #define FM10K_MBX_CRC_SEED 0xFFFF
0215
0216 struct fm10k_mbx_ops {
0217 s32 (*connect)(struct fm10k_hw *, struct fm10k_mbx_info *);
0218 void (*disconnect)(struct fm10k_hw *, struct fm10k_mbx_info *);
0219 bool (*rx_ready)(struct fm10k_mbx_info *);
0220 bool (*tx_ready)(struct fm10k_mbx_info *, u16);
0221 bool (*tx_complete)(struct fm10k_mbx_info *);
0222 s32 (*enqueue_tx)(struct fm10k_hw *, struct fm10k_mbx_info *,
0223 const u32 *);
0224 s32 (*process)(struct fm10k_hw *, struct fm10k_mbx_info *);
0225 s32 (*register_handlers)(struct fm10k_mbx_info *,
0226 const struct fm10k_msg_data *);
0227 };
0228
0229 struct fm10k_mbx_fifo {
0230 u32 *buffer;
0231 u16 head;
0232 u16 tail;
0233 u16 size;
0234 };
0235
0236
0237 #define FM10K_MBX_TX_BUFFER_SIZE 512
0238 #define FM10K_MBX_RX_BUFFER_SIZE 128
0239 #define FM10K_MBX_BUFFER_SIZE \
0240 (FM10K_MBX_TX_BUFFER_SIZE + FM10K_MBX_RX_BUFFER_SIZE)
0241
0242
0243 #define FM10K_MBX_MSG_MAX_SIZE \
0244 ((FM10K_MBX_TX_BUFFER_SIZE - 1) & (FM10K_MBX_RX_BUFFER_SIZE - 1))
0245 #define FM10K_VFMBX_MSG_MTU ((FM10K_VFMBMEM_LEN / 2) - 1)
0246
0247 #define FM10K_MBX_INIT_TIMEOUT 2000
0248 #define FM10K_MBX_INIT_DELAY 500
0249
0250 struct fm10k_mbx_info {
0251
0252 struct fm10k_mbx_ops ops;
0253 const struct fm10k_msg_data *msg_data;
0254
0255
0256 struct fm10k_mbx_fifo rx;
0257 struct fm10k_mbx_fifo tx;
0258
0259
0260 u32 timeout;
0261 u32 udelay;
0262
0263
0264 u32 mbx_reg, mbmem_reg, mbx_lock, mbx_hdr;
0265 u16 max_size, mbmem_len;
0266 u16 tail, tail_len, pulled;
0267 u16 head, head_len, pushed;
0268 u16 local, remote;
0269 enum fm10k_mbx_state state;
0270
0271
0272 s32 test_result;
0273
0274
0275 u64 tx_busy;
0276 u64 tx_dropped;
0277 u64 tx_messages;
0278 u64 tx_dwords;
0279 u64 tx_mbmem_pulled;
0280 u64 rx_messages;
0281 u64 rx_dwords;
0282 u64 rx_mbmem_pushed;
0283 u64 rx_parse_err;
0284
0285
0286 u32 buffer[FM10K_MBX_BUFFER_SIZE];
0287 };
0288
0289 s32 fm10k_pfvf_mbx_init(struct fm10k_hw *, struct fm10k_mbx_info *,
0290 const struct fm10k_msg_data *, u8);
0291 s32 fm10k_sm_mbx_init(struct fm10k_hw *, struct fm10k_mbx_info *,
0292 const struct fm10k_msg_data *);
0293
0294 #endif