0001
0002
0003
0004 #include "vf.h"
0005
0006 static s32 e1000_check_for_link_vf(struct e1000_hw *hw);
0007 static s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
0008 u16 *duplex);
0009 static s32 e1000_init_hw_vf(struct e1000_hw *hw);
0010 static s32 e1000_reset_hw_vf(struct e1000_hw *hw);
0011
0012 static void e1000_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *,
0013 u32, u32, u32);
0014 static void e1000_rar_set_vf(struct e1000_hw *, u8 *, u32);
0015 static s32 e1000_read_mac_addr_vf(struct e1000_hw *);
0016 static s32 e1000_set_uc_addr_vf(struct e1000_hw *hw, u32 subcmd, u8 *addr);
0017 static s32 e1000_set_vfta_vf(struct e1000_hw *, u16, bool);
0018
0019
0020
0021
0022
0023 static s32 e1000_init_mac_params_vf(struct e1000_hw *hw)
0024 {
0025 struct e1000_mac_info *mac = &hw->mac;
0026
0027
0028 mac->mta_reg_count = 128;
0029
0030 mac->rar_entry_count = 1;
0031
0032
0033
0034 mac->ops.reset_hw = e1000_reset_hw_vf;
0035
0036 mac->ops.init_hw = e1000_init_hw_vf;
0037
0038 mac->ops.check_for_link = e1000_check_for_link_vf;
0039
0040 mac->ops.get_link_up_info = e1000_get_link_up_info_vf;
0041
0042 mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_vf;
0043
0044 mac->ops.rar_set = e1000_rar_set_vf;
0045
0046 mac->ops.read_mac_addr = e1000_read_mac_addr_vf;
0047
0048 mac->ops.set_uc_addr = e1000_set_uc_addr_vf;
0049
0050 mac->ops.set_vfta = e1000_set_vfta_vf;
0051
0052 return E1000_SUCCESS;
0053 }
0054
0055
0056
0057
0058
0059 void e1000_init_function_pointers_vf(struct e1000_hw *hw)
0060 {
0061 hw->mac.ops.init_params = e1000_init_mac_params_vf;
0062 hw->mbx.ops.init_params = e1000_init_mbx_params_vf;
0063 }
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074 static s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
0075 u16 *duplex)
0076 {
0077 s32 status;
0078
0079 status = er32(STATUS);
0080 if (status & E1000_STATUS_SPEED_1000)
0081 *speed = SPEED_1000;
0082 else if (status & E1000_STATUS_SPEED_100)
0083 *speed = SPEED_100;
0084 else
0085 *speed = SPEED_10;
0086
0087 if (status & E1000_STATUS_FD)
0088 *duplex = FULL_DUPLEX;
0089 else
0090 *duplex = HALF_DUPLEX;
0091
0092 return E1000_SUCCESS;
0093 }
0094
0095
0096
0097
0098
0099
0100
0101
0102 static s32 e1000_reset_hw_vf(struct e1000_hw *hw)
0103 {
0104 struct e1000_mbx_info *mbx = &hw->mbx;
0105 u32 timeout = E1000_VF_INIT_TIMEOUT;
0106 u32 ret_val = -E1000_ERR_MAC_INIT;
0107 u32 msgbuf[3];
0108 u8 *addr = (u8 *)(&msgbuf[1]);
0109 u32 ctrl;
0110
0111
0112 ctrl = er32(CTRL);
0113 ew32(CTRL, ctrl | E1000_CTRL_RST);
0114
0115
0116 while (!mbx->ops.check_for_rst(hw) && timeout) {
0117 timeout--;
0118 udelay(5);
0119 }
0120
0121 if (timeout) {
0122
0123 mbx->timeout = E1000_VF_MBX_INIT_TIMEOUT;
0124
0125
0126 msgbuf[0] = E1000_VF_RESET;
0127 mbx->ops.write_posted(hw, msgbuf, 1);
0128
0129 mdelay(10);
0130
0131
0132 ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
0133 if (!ret_val) {
0134 if (msgbuf[0] == (E1000_VF_RESET |
0135 E1000_VT_MSGTYPE_ACK))
0136 memcpy(hw->mac.perm_addr, addr, ETH_ALEN);
0137 else
0138 ret_val = -E1000_ERR_MAC_INIT;
0139 }
0140 }
0141
0142 return ret_val;
0143 }
0144
0145
0146
0147
0148
0149
0150
0151 static s32 e1000_init_hw_vf(struct e1000_hw *hw)
0152 {
0153
0154 e1000_rar_set_vf(hw, hw->mac.addr, 0);
0155
0156 return E1000_SUCCESS;
0157 }
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168 static u32 e1000_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
0169 {
0170 u32 hash_value, hash_mask;
0171 u8 bit_shift = 0;
0172
0173
0174 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
0175
0176
0177
0178
0179 while (hash_mask >> bit_shift != 0xFF)
0180 bit_shift++;
0181
0182 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
0183 (((u16)mc_addr[5]) << bit_shift)));
0184
0185 return hash_value;
0186 }
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201 static void e1000_update_mc_addr_list_vf(struct e1000_hw *hw,
0202 u8 *mc_addr_list, u32 mc_addr_count,
0203 u32 rar_used_count, u32 rar_count)
0204 {
0205 struct e1000_mbx_info *mbx = &hw->mbx;
0206 u32 msgbuf[E1000_VFMAILBOX_SIZE];
0207 u16 *hash_list = (u16 *)&msgbuf[1];
0208 u32 hash_value;
0209 u32 cnt, i;
0210 s32 ret_val;
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221 cnt = (mc_addr_count > 30) ? 30 : mc_addr_count;
0222 msgbuf[0] = E1000_VF_SET_MULTICAST;
0223 msgbuf[0] |= cnt << E1000_VT_MSGINFO_SHIFT;
0224
0225 for (i = 0; i < cnt; i++) {
0226 hash_value = e1000_hash_mc_addr_vf(hw, mc_addr_list);
0227 hash_list[i] = hash_value & 0x0FFFF;
0228 mc_addr_list += ETH_ALEN;
0229 }
0230
0231 ret_val = mbx->ops.write_posted(hw, msgbuf, E1000_VFMAILBOX_SIZE);
0232 if (!ret_val)
0233 mbx->ops.read_posted(hw, msgbuf, 1);
0234 }
0235
0236
0237
0238
0239
0240
0241
0242 static s32 e1000_set_vfta_vf(struct e1000_hw *hw, u16 vid, bool set)
0243 {
0244 struct e1000_mbx_info *mbx = &hw->mbx;
0245 u32 msgbuf[2];
0246 s32 err;
0247
0248 msgbuf[0] = E1000_VF_SET_VLAN;
0249 msgbuf[1] = vid;
0250
0251 if (set)
0252 msgbuf[0] |= BIT(E1000_VT_MSGINFO_SHIFT);
0253
0254 mbx->ops.write_posted(hw, msgbuf, 2);
0255
0256 err = mbx->ops.read_posted(hw, msgbuf, 2);
0257
0258 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
0259
0260
0261 if (!err && (msgbuf[0] == (E1000_VF_SET_VLAN | E1000_VT_MSGTYPE_NACK)))
0262 err = -E1000_ERR_MAC_INIT;
0263
0264 return err;
0265 }
0266
0267
0268
0269
0270
0271
0272 void e1000_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
0273 {
0274 struct e1000_mbx_info *mbx = &hw->mbx;
0275 u32 msgbuf[2];
0276 s32 ret_val;
0277
0278 msgbuf[0] = E1000_VF_SET_LPE;
0279 msgbuf[1] = max_size;
0280
0281 ret_val = mbx->ops.write_posted(hw, msgbuf, 2);
0282 if (!ret_val)
0283 mbx->ops.read_posted(hw, msgbuf, 1);
0284 }
0285
0286
0287
0288
0289
0290
0291
0292 static void e1000_rar_set_vf(struct e1000_hw *hw, u8 *addr, u32 index)
0293 {
0294 struct e1000_mbx_info *mbx = &hw->mbx;
0295 u32 msgbuf[3];
0296 u8 *msg_addr = (u8 *)(&msgbuf[1]);
0297 s32 ret_val;
0298
0299 memset(msgbuf, 0, 12);
0300 msgbuf[0] = E1000_VF_SET_MAC_ADDR;
0301 memcpy(msg_addr, addr, ETH_ALEN);
0302 ret_val = mbx->ops.write_posted(hw, msgbuf, 3);
0303
0304 if (!ret_val)
0305 ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
0306
0307 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
0308
0309
0310 if (!ret_val &&
0311 (msgbuf[0] == (E1000_VF_SET_MAC_ADDR | E1000_VT_MSGTYPE_NACK)))
0312 e1000_read_mac_addr_vf(hw);
0313 }
0314
0315
0316
0317
0318
0319 static s32 e1000_read_mac_addr_vf(struct e1000_hw *hw)
0320 {
0321 memcpy(hw->mac.addr, hw->mac.perm_addr, ETH_ALEN);
0322
0323 return E1000_SUCCESS;
0324 }
0325
0326
0327
0328
0329
0330
0331
0332 static s32 e1000_set_uc_addr_vf(struct e1000_hw *hw, u32 sub_cmd, u8 *addr)
0333 {
0334 struct e1000_mbx_info *mbx = &hw->mbx;
0335 u32 msgbuf[3], msgbuf_chk;
0336 u8 *msg_addr = (u8 *)(&msgbuf[1]);
0337 s32 ret_val;
0338
0339 memset(msgbuf, 0, sizeof(msgbuf));
0340 msgbuf[0] |= sub_cmd;
0341 msgbuf[0] |= E1000_VF_SET_MAC_ADDR;
0342 msgbuf_chk = msgbuf[0];
0343
0344 if (addr)
0345 memcpy(msg_addr, addr, ETH_ALEN);
0346
0347 ret_val = mbx->ops.write_posted(hw, msgbuf, 3);
0348
0349 if (!ret_val)
0350 ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
0351
0352 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
0353
0354 if (!ret_val) {
0355 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
0356
0357 if (msgbuf[0] == (msgbuf_chk | E1000_VT_MSGTYPE_NACK))
0358 return -ENOSPC;
0359 }
0360
0361 return ret_val;
0362 }
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372 static s32 e1000_check_for_link_vf(struct e1000_hw *hw)
0373 {
0374 struct e1000_mbx_info *mbx = &hw->mbx;
0375 struct e1000_mac_info *mac = &hw->mac;
0376 s32 ret_val = E1000_SUCCESS;
0377 u32 in_msg = 0;
0378
0379
0380
0381
0382
0383
0384
0385 if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
0386 mac->get_link_status = true;
0387
0388 if (!mac->get_link_status)
0389 goto out;
0390
0391
0392 if (!(er32(STATUS) & E1000_STATUS_LU))
0393 goto out;
0394
0395
0396
0397
0398 if (mbx->ops.read(hw, &in_msg, 1))
0399 goto out;
0400
0401
0402 if (!(in_msg & E1000_VT_MSGTYPE_CTS)) {
0403
0404 if (in_msg & E1000_VT_MSGTYPE_NACK)
0405 ret_val = -E1000_ERR_MAC_INIT;
0406 goto out;
0407 }
0408
0409
0410 if (!mbx->timeout) {
0411 ret_val = -E1000_ERR_MAC_INIT;
0412 goto out;
0413 }
0414
0415
0416
0417
0418 mac->get_link_status = false;
0419
0420 out:
0421 return ret_val;
0422 }
0423