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