1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include "vf.h"
28
29static s32 e1000_check_for_link_vf(struct e1000_hw *hw);
30static s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
31 u16 *duplex);
32static s32 e1000_init_hw_vf(struct e1000_hw *hw);
33static s32 e1000_reset_hw_vf(struct e1000_hw *hw);
34
35static void e1000_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *,
36 u32, u32, u32);
37static void e1000_rar_set_vf(struct e1000_hw *, u8 *, u32);
38static s32 e1000_read_mac_addr_vf(struct e1000_hw *);
39static s32 e1000_set_uc_addr_vf(struct e1000_hw *hw, u32 subcmd, u8 *addr);
40static s32 e1000_set_vfta_vf(struct e1000_hw *, u16, bool);
41
42
43
44
45
46static s32 e1000_init_mac_params_vf(struct e1000_hw *hw)
47{
48 struct e1000_mac_info *mac = &hw->mac;
49
50
51 mac->mta_reg_count = 128;
52
53 mac->rar_entry_count = 1;
54
55
56
57 mac->ops.reset_hw = e1000_reset_hw_vf;
58
59 mac->ops.init_hw = e1000_init_hw_vf;
60
61 mac->ops.check_for_link = e1000_check_for_link_vf;
62
63 mac->ops.get_link_up_info = e1000_get_link_up_info_vf;
64
65 mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_vf;
66
67 mac->ops.rar_set = e1000_rar_set_vf;
68
69 mac->ops.read_mac_addr = e1000_read_mac_addr_vf;
70
71 mac->ops.set_uc_addr = e1000_set_uc_addr_vf;
72
73 mac->ops.set_vfta = e1000_set_vfta_vf;
74
75 return E1000_SUCCESS;
76}
77
78
79
80
81
82void e1000_init_function_pointers_vf(struct e1000_hw *hw)
83{
84 hw->mac.ops.init_params = e1000_init_mac_params_vf;
85 hw->mbx.ops.init_params = e1000_init_mbx_params_vf;
86}
87
88
89
90
91
92
93
94
95
96
97static s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
98 u16 *duplex)
99{
100 s32 status;
101
102 status = er32(STATUS);
103 if (status & E1000_STATUS_SPEED_1000)
104 *speed = SPEED_1000;
105 else if (status & E1000_STATUS_SPEED_100)
106 *speed = SPEED_100;
107 else
108 *speed = SPEED_10;
109
110 if (status & E1000_STATUS_FD)
111 *duplex = FULL_DUPLEX;
112 else
113 *duplex = HALF_DUPLEX;
114
115 return E1000_SUCCESS;
116}
117
118
119
120
121
122
123
124
125static s32 e1000_reset_hw_vf(struct e1000_hw *hw)
126{
127 struct e1000_mbx_info *mbx = &hw->mbx;
128 u32 timeout = E1000_VF_INIT_TIMEOUT;
129 u32 ret_val = -E1000_ERR_MAC_INIT;
130 u32 msgbuf[3];
131 u8 *addr = (u8 *)(&msgbuf[1]);
132 u32 ctrl;
133
134
135 ctrl = er32(CTRL);
136 ew32(CTRL, ctrl | E1000_CTRL_RST);
137
138
139 while (!mbx->ops.check_for_rst(hw) && timeout) {
140 timeout--;
141 udelay(5);
142 }
143
144 if (timeout) {
145
146 mbx->timeout = E1000_VF_MBX_INIT_TIMEOUT;
147
148
149 msgbuf[0] = E1000_VF_RESET;
150 mbx->ops.write_posted(hw, msgbuf, 1);
151
152 mdelay(10);
153
154
155 ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
156 if (!ret_val) {
157 if (msgbuf[0] == (E1000_VF_RESET |
158 E1000_VT_MSGTYPE_ACK))
159 memcpy(hw->mac.perm_addr, addr, ETH_ALEN);
160 else
161 ret_val = -E1000_ERR_MAC_INIT;
162 }
163 }
164
165 return ret_val;
166}
167
168
169
170
171
172
173
174static s32 e1000_init_hw_vf(struct e1000_hw *hw)
175{
176
177 e1000_rar_set_vf(hw, hw->mac.addr, 0);
178
179 return E1000_SUCCESS;
180}
181
182
183
184
185
186
187
188
189
190
191static u32 e1000_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
192{
193 u32 hash_value, hash_mask;
194 u8 bit_shift = 0;
195
196
197 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
198
199
200
201
202 while (hash_mask >> bit_shift != 0xFF)
203 bit_shift++;
204
205 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
206 (((u16)mc_addr[5]) << bit_shift)));
207
208 return hash_value;
209}
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224static void e1000_update_mc_addr_list_vf(struct e1000_hw *hw,
225 u8 *mc_addr_list, u32 mc_addr_count,
226 u32 rar_used_count, u32 rar_count)
227{
228 struct e1000_mbx_info *mbx = &hw->mbx;
229 u32 msgbuf[E1000_VFMAILBOX_SIZE];
230 u16 *hash_list = (u16 *)&msgbuf[1];
231 u32 hash_value;
232 u32 cnt, i;
233 s32 ret_val;
234
235
236
237
238
239
240
241
242
243
244 cnt = (mc_addr_count > 30) ? 30 : mc_addr_count;
245 msgbuf[0] = E1000_VF_SET_MULTICAST;
246 msgbuf[0] |= cnt << E1000_VT_MSGINFO_SHIFT;
247
248 for (i = 0; i < cnt; i++) {
249 hash_value = e1000_hash_mc_addr_vf(hw, mc_addr_list);
250 hash_list[i] = hash_value & 0x0FFFF;
251 mc_addr_list += ETH_ALEN;
252 }
253
254 ret_val = mbx->ops.write_posted(hw, msgbuf, E1000_VFMAILBOX_SIZE);
255 if (!ret_val)
256 mbx->ops.read_posted(hw, msgbuf, 1);
257}
258
259
260
261
262
263
264
265static s32 e1000_set_vfta_vf(struct e1000_hw *hw, u16 vid, bool set)
266{
267 struct e1000_mbx_info *mbx = &hw->mbx;
268 u32 msgbuf[2];
269 s32 err;
270
271 msgbuf[0] = E1000_VF_SET_VLAN;
272 msgbuf[1] = vid;
273
274 if (set)
275 msgbuf[0] |= BIT(E1000_VT_MSGINFO_SHIFT);
276
277 mbx->ops.write_posted(hw, msgbuf, 2);
278
279 err = mbx->ops.read_posted(hw, msgbuf, 2);
280
281 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
282
283
284 if (!err && (msgbuf[0] == (E1000_VF_SET_VLAN | E1000_VT_MSGTYPE_NACK)))
285 err = -E1000_ERR_MAC_INIT;
286
287 return err;
288}
289
290
291
292
293
294
295void e1000_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
296{
297 struct e1000_mbx_info *mbx = &hw->mbx;
298 u32 msgbuf[2];
299 s32 ret_val;
300
301 msgbuf[0] = E1000_VF_SET_LPE;
302 msgbuf[1] = max_size;
303
304 ret_val = mbx->ops.write_posted(hw, msgbuf, 2);
305 if (!ret_val)
306 mbx->ops.read_posted(hw, msgbuf, 1);
307}
308
309
310
311
312
313
314
315static void e1000_rar_set_vf(struct e1000_hw *hw, u8 *addr, u32 index)
316{
317 struct e1000_mbx_info *mbx = &hw->mbx;
318 u32 msgbuf[3];
319 u8 *msg_addr = (u8 *)(&msgbuf[1]);
320 s32 ret_val;
321
322 memset(msgbuf, 0, 12);
323 msgbuf[0] = E1000_VF_SET_MAC_ADDR;
324 memcpy(msg_addr, addr, ETH_ALEN);
325 ret_val = mbx->ops.write_posted(hw, msgbuf, 3);
326
327 if (!ret_val)
328 ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
329
330 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
331
332
333 if (!ret_val &&
334 (msgbuf[0] == (E1000_VF_SET_MAC_ADDR | E1000_VT_MSGTYPE_NACK)))
335 e1000_read_mac_addr_vf(hw);
336}
337
338
339
340
341
342static s32 e1000_read_mac_addr_vf(struct e1000_hw *hw)
343{
344 memcpy(hw->mac.addr, hw->mac.perm_addr, ETH_ALEN);
345
346 return E1000_SUCCESS;
347}
348
349
350
351
352
353
354
355static s32 e1000_set_uc_addr_vf(struct e1000_hw *hw, u32 sub_cmd, u8 *addr)
356{
357 struct e1000_mbx_info *mbx = &hw->mbx;
358 u32 msgbuf[3], msgbuf_chk;
359 u8 *msg_addr = (u8 *)(&msgbuf[1]);
360 s32 ret_val;
361
362 memset(msgbuf, 0, sizeof(msgbuf));
363 msgbuf[0] |= sub_cmd;
364 msgbuf[0] |= E1000_VF_SET_MAC_ADDR;
365 msgbuf_chk = msgbuf[0];
366
367 if (addr)
368 memcpy(msg_addr, addr, ETH_ALEN);
369
370 ret_val = mbx->ops.write_posted(hw, msgbuf, 3);
371
372 if (!ret_val)
373 ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
374
375 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
376
377 if (!ret_val) {
378 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
379
380 if (msgbuf[0] == (msgbuf_chk | E1000_VT_MSGTYPE_NACK))
381 return -ENOSPC;
382 }
383
384 return ret_val;
385}
386
387
388
389
390
391
392
393
394
395static s32 e1000_check_for_link_vf(struct e1000_hw *hw)
396{
397 struct e1000_mbx_info *mbx = &hw->mbx;
398 struct e1000_mac_info *mac = &hw->mac;
399 s32 ret_val = E1000_SUCCESS;
400 u32 in_msg = 0;
401
402
403
404
405
406
407
408 if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
409 mac->get_link_status = true;
410
411 if (!mac->get_link_status)
412 goto out;
413
414
415 if (!(er32(STATUS) & E1000_STATUS_LU))
416 goto out;
417
418
419
420
421 if (mbx->ops.read(hw, &in_msg, 1))
422 goto out;
423
424
425 if (!(in_msg & E1000_VT_MSGTYPE_CTS)) {
426
427 if (in_msg & E1000_VT_MSGTYPE_NACK)
428 ret_val = -E1000_ERR_MAC_INIT;
429 goto out;
430 }
431
432
433 if (!mbx->timeout) {
434 ret_val = -E1000_ERR_MAC_INIT;
435 goto out;
436 }
437
438
439
440
441 mac->get_link_status = false;
442
443out:
444 return ret_val;
445}
446
447