0001
0002
0003
0004 #include "mbx.h"
0005
0006
0007
0008
0009
0010
0011
0012 static s32 e1000_poll_for_msg(struct e1000_hw *hw)
0013 {
0014 struct e1000_mbx_info *mbx = &hw->mbx;
0015 int countdown = mbx->timeout;
0016
0017 if (!mbx->ops.check_for_msg)
0018 goto out;
0019
0020 while (countdown && mbx->ops.check_for_msg(hw)) {
0021 countdown--;
0022 udelay(mbx->usec_delay);
0023 }
0024
0025
0026 if (!countdown)
0027 mbx->timeout = 0;
0028 out:
0029 return countdown ? E1000_SUCCESS : -E1000_ERR_MBX;
0030 }
0031
0032
0033
0034
0035
0036
0037
0038 static s32 e1000_poll_for_ack(struct e1000_hw *hw)
0039 {
0040 struct e1000_mbx_info *mbx = &hw->mbx;
0041 int countdown = mbx->timeout;
0042
0043 if (!mbx->ops.check_for_ack)
0044 goto out;
0045
0046 while (countdown && mbx->ops.check_for_ack(hw)) {
0047 countdown--;
0048 udelay(mbx->usec_delay);
0049 }
0050
0051
0052 if (!countdown)
0053 mbx->timeout = 0;
0054 out:
0055 return countdown ? E1000_SUCCESS : -E1000_ERR_MBX;
0056 }
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 static s32 e1000_read_posted_mbx(struct e1000_hw *hw, u32 *msg, u16 size)
0068 {
0069 struct e1000_mbx_info *mbx = &hw->mbx;
0070 s32 ret_val = -E1000_ERR_MBX;
0071
0072 if (!mbx->ops.read)
0073 goto out;
0074
0075 ret_val = e1000_poll_for_msg(hw);
0076
0077
0078 if (!ret_val)
0079 ret_val = mbx->ops.read(hw, msg, size);
0080 out:
0081 return ret_val;
0082 }
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093 static s32 e1000_write_posted_mbx(struct e1000_hw *hw, u32 *msg, u16 size)
0094 {
0095 struct e1000_mbx_info *mbx = &hw->mbx;
0096 s32 ret_val = -E1000_ERR_MBX;
0097
0098
0099 if (!mbx->ops.write || !mbx->timeout)
0100 goto out;
0101
0102
0103 ret_val = mbx->ops.write(hw, msg, size);
0104
0105
0106 if (!ret_val)
0107 ret_val = e1000_poll_for_ack(hw);
0108 out:
0109 return ret_val;
0110 }
0111
0112
0113
0114
0115
0116
0117
0118
0119 static u32 e1000_read_v2p_mailbox(struct e1000_hw *hw)
0120 {
0121 u32 v2p_mailbox = er32(V2PMAILBOX(0));
0122
0123 v2p_mailbox |= hw->dev_spec.vf.v2p_mailbox;
0124 hw->dev_spec.vf.v2p_mailbox |= v2p_mailbox & E1000_V2PMAILBOX_R2C_BITS;
0125
0126 return v2p_mailbox;
0127 }
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137 static s32 e1000_check_for_bit_vf(struct e1000_hw *hw, u32 mask)
0138 {
0139 u32 v2p_mailbox = e1000_read_v2p_mailbox(hw);
0140 s32 ret_val = -E1000_ERR_MBX;
0141
0142 if (v2p_mailbox & mask)
0143 ret_val = E1000_SUCCESS;
0144
0145 hw->dev_spec.vf.v2p_mailbox &= ~mask;
0146
0147 return ret_val;
0148 }
0149
0150
0151
0152
0153
0154
0155
0156 static s32 e1000_check_for_msg_vf(struct e1000_hw *hw)
0157 {
0158 s32 ret_val = -E1000_ERR_MBX;
0159
0160 if (!e1000_check_for_bit_vf(hw, E1000_V2PMAILBOX_PFSTS)) {
0161 ret_val = E1000_SUCCESS;
0162 hw->mbx.stats.reqs++;
0163 }
0164
0165 return ret_val;
0166 }
0167
0168
0169
0170
0171
0172
0173
0174 static s32 e1000_check_for_ack_vf(struct e1000_hw *hw)
0175 {
0176 s32 ret_val = -E1000_ERR_MBX;
0177
0178 if (!e1000_check_for_bit_vf(hw, E1000_V2PMAILBOX_PFACK)) {
0179 ret_val = E1000_SUCCESS;
0180 hw->mbx.stats.acks++;
0181 }
0182
0183 return ret_val;
0184 }
0185
0186
0187
0188
0189
0190
0191
0192 static s32 e1000_check_for_rst_vf(struct e1000_hw *hw)
0193 {
0194 s32 ret_val = -E1000_ERR_MBX;
0195
0196 if (!e1000_check_for_bit_vf(hw, (E1000_V2PMAILBOX_RSTD |
0197 E1000_V2PMAILBOX_RSTI))) {
0198 ret_val = E1000_SUCCESS;
0199 hw->mbx.stats.rsts++;
0200 }
0201
0202 return ret_val;
0203 }
0204
0205
0206
0207
0208
0209
0210
0211 static s32 e1000_obtain_mbx_lock_vf(struct e1000_hw *hw)
0212 {
0213 s32 ret_val = -E1000_ERR_MBX;
0214 int count = 10;
0215
0216 do {
0217
0218 ew32(V2PMAILBOX(0), E1000_V2PMAILBOX_VFU);
0219
0220
0221 if (e1000_read_v2p_mailbox(hw) & E1000_V2PMAILBOX_VFU) {
0222 ret_val = 0;
0223 break;
0224 }
0225 udelay(1000);
0226 } while (count-- > 0);
0227
0228 return ret_val;
0229 }
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239 static s32 e1000_write_mbx_vf(struct e1000_hw *hw, u32 *msg, u16 size)
0240 {
0241 s32 err;
0242 u16 i;
0243
0244 lockdep_assert_held(&hw->mbx_lock);
0245
0246
0247 err = e1000_obtain_mbx_lock_vf(hw);
0248 if (err)
0249 goto out_no_write;
0250
0251
0252 e1000_check_for_ack_vf(hw);
0253 e1000_check_for_msg_vf(hw);
0254
0255
0256 for (i = 0; i < size; i++)
0257 array_ew32(VMBMEM(0), i, msg[i]);
0258
0259
0260 hw->mbx.stats.msgs_tx++;
0261
0262
0263 ew32(V2PMAILBOX(0), E1000_V2PMAILBOX_REQ);
0264
0265 out_no_write:
0266 return err;
0267 }
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277 static s32 e1000_read_mbx_vf(struct e1000_hw *hw, u32 *msg, u16 size)
0278 {
0279 s32 err;
0280 u16 i;
0281
0282 lockdep_assert_held(&hw->mbx_lock);
0283
0284
0285 err = e1000_obtain_mbx_lock_vf(hw);
0286 if (err)
0287 goto out_no_read;
0288
0289
0290 for (i = 0; i < size; i++)
0291 msg[i] = array_er32(VMBMEM(0), i);
0292
0293
0294 ew32(V2PMAILBOX(0), E1000_V2PMAILBOX_ACK);
0295
0296
0297 hw->mbx.stats.msgs_rx++;
0298
0299 out_no_read:
0300 return err;
0301 }
0302
0303
0304
0305
0306
0307
0308
0309 s32 e1000_init_mbx_params_vf(struct e1000_hw *hw)
0310 {
0311 struct e1000_mbx_info *mbx = &hw->mbx;
0312
0313
0314
0315
0316 mbx->timeout = 0;
0317 mbx->usec_delay = E1000_VF_MBX_INIT_DELAY;
0318
0319 mbx->size = E1000_VFMAILBOX_SIZE;
0320
0321 mbx->ops.read = e1000_read_mbx_vf;
0322 mbx->ops.write = e1000_write_mbx_vf;
0323 mbx->ops.read_posted = e1000_read_posted_mbx;
0324 mbx->ops.write_posted = e1000_write_posted_mbx;
0325 mbx->ops.check_for_msg = e1000_check_for_msg_vf;
0326 mbx->ops.check_for_ack = e1000_check_for_ack_vf;
0327 mbx->ops.check_for_rst = e1000_check_for_rst_vf;
0328
0329 mbx->stats.msgs_tx = 0;
0330 mbx->stats.msgs_rx = 0;
0331 mbx->stats.reqs = 0;
0332 mbx->stats.acks = 0;
0333 mbx->stats.rsts = 0;
0334
0335 return E1000_SUCCESS;
0336 }