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