1
2
3
4
5
6#include "e1000_api.h"
7
8
9STATIC s32 e1000_init_phy_params_vf(struct e1000_hw *hw);
10STATIC s32 e1000_init_nvm_params_vf(struct e1000_hw *hw);
11STATIC void e1000_release_vf(struct e1000_hw *hw);
12STATIC s32 e1000_acquire_vf(struct e1000_hw *hw);
13STATIC s32 e1000_setup_link_vf(struct e1000_hw *hw);
14STATIC s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw);
15STATIC s32 e1000_init_mac_params_vf(struct e1000_hw *hw);
16STATIC s32 e1000_check_for_link_vf(struct e1000_hw *hw);
17STATIC s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
18 u16 *duplex);
19STATIC s32 e1000_init_hw_vf(struct e1000_hw *hw);
20STATIC s32 e1000_reset_hw_vf(struct e1000_hw *hw);
21STATIC void e1000_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *, u32);
22STATIC int e1000_rar_set_vf(struct e1000_hw *, u8 *, u32);
23STATIC s32 e1000_read_mac_addr_vf(struct e1000_hw *);
24
25
26
27
28
29
30
31STATIC s32 e1000_init_phy_params_vf(struct e1000_hw *hw)
32{
33 DEBUGFUNC("e1000_init_phy_params_vf");
34 hw->phy.type = e1000_phy_vf;
35 hw->phy.ops.acquire = e1000_acquire_vf;
36 hw->phy.ops.release = e1000_release_vf;
37
38 return E1000_SUCCESS;
39}
40
41
42
43
44
45
46
47STATIC s32 e1000_init_nvm_params_vf(struct e1000_hw *hw)
48{
49 DEBUGFUNC("e1000_init_nvm_params_vf");
50 hw->nvm.type = e1000_nvm_none;
51 hw->nvm.ops.acquire = e1000_acquire_vf;
52 hw->nvm.ops.release = e1000_release_vf;
53
54 return E1000_SUCCESS;
55}
56
57
58
59
60
61STATIC s32 e1000_init_mac_params_vf(struct e1000_hw *hw)
62{
63 struct e1000_mac_info *mac = &hw->mac;
64
65 DEBUGFUNC("e1000_init_mac_params_vf");
66
67
68
69
70
71
72
73 hw->phy.media_type = e1000_media_type_unknown;
74
75
76 mac->asf_firmware_present = false;
77
78 mac->arc_subsystem_valid = false;
79
80 mac->adaptive_ifs = false;
81
82 mac->mta_reg_count = 128;
83
84 mac->rar_entry_count = 1;
85
86
87
88 mac->ops.setup_link = e1000_setup_link_vf;
89
90 mac->ops.get_bus_info = e1000_get_bus_info_pcie_vf;
91
92 mac->ops.reset_hw = e1000_reset_hw_vf;
93
94 mac->ops.init_hw = e1000_init_hw_vf;
95
96 mac->ops.check_for_link = e1000_check_for_link_vf;
97
98 mac->ops.get_link_up_info = e1000_get_link_up_info_vf;
99
100 mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_vf;
101
102 mac->ops.rar_set = e1000_rar_set_vf;
103
104 mac->ops.read_mac_addr = e1000_read_mac_addr_vf;
105
106
107 return E1000_SUCCESS;
108}
109
110
111
112
113
114void e1000_init_function_pointers_vf(struct e1000_hw *hw)
115{
116 DEBUGFUNC("e1000_init_function_pointers_vf");
117
118 hw->mac.ops.init_params = e1000_init_mac_params_vf;
119 hw->nvm.ops.init_params = e1000_init_nvm_params_vf;
120 hw->phy.ops.init_params = e1000_init_phy_params_vf;
121 hw->mbx.ops.init_params = e1000_init_mbx_params_vf;
122}
123
124
125
126
127
128
129
130
131
132STATIC s32 e1000_acquire_vf(struct e1000_hw E1000_UNUSEDARG *hw)
133{
134 UNREFERENCED_1PARAMETER(hw);
135 return -E1000_ERR_PHY;
136}
137
138
139
140
141
142
143
144
145
146STATIC void e1000_release_vf(struct e1000_hw E1000_UNUSEDARG *hw)
147{
148 UNREFERENCED_1PARAMETER(hw);
149 return;
150}
151
152
153
154
155
156
157
158STATIC s32 e1000_setup_link_vf(struct e1000_hw E1000_UNUSEDARG *hw)
159{
160 DEBUGFUNC("e1000_setup_link_vf");
161 UNREFERENCED_1PARAMETER(hw);
162
163 return E1000_SUCCESS;
164}
165
166
167
168
169
170
171
172STATIC s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw)
173{
174 struct e1000_bus_info *bus = &hw->bus;
175
176 DEBUGFUNC("e1000_get_bus_info_pcie_vf");
177
178
179 bus->type = e1000_bus_type_reserved;
180 bus->speed = e1000_bus_speed_2500;
181
182 return 0;
183}
184
185
186
187
188
189
190
191
192
193
194STATIC s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
195 u16 *duplex)
196{
197 s32 status;
198
199 DEBUGFUNC("e1000_get_link_up_info_vf");
200
201 status = E1000_READ_REG(hw, E1000_STATUS);
202 if (status & E1000_STATUS_SPEED_1000) {
203 *speed = SPEED_1000;
204 DEBUGOUT("1000 Mbs, ");
205 } else if (status & E1000_STATUS_SPEED_100) {
206 *speed = SPEED_100;
207 DEBUGOUT("100 Mbs, ");
208 } else {
209 *speed = SPEED_10;
210 DEBUGOUT("10 Mbs, ");
211 }
212
213 if (status & E1000_STATUS_FD) {
214 *duplex = FULL_DUPLEX;
215 DEBUGOUT("Full Duplex\n");
216 } else {
217 *duplex = HALF_DUPLEX;
218 DEBUGOUT("Half Duplex\n");
219 }
220
221 return E1000_SUCCESS;
222}
223
224
225
226
227
228
229
230
231STATIC s32 e1000_reset_hw_vf(struct e1000_hw *hw)
232{
233 struct e1000_mbx_info *mbx = &hw->mbx;
234 u32 timeout = E1000_VF_INIT_TIMEOUT;
235 s32 ret_val = -E1000_ERR_MAC_INIT;
236 u32 ctrl, msgbuf[3];
237 u8 *addr = (u8 *)(&msgbuf[1]);
238
239 DEBUGFUNC("e1000_reset_hw_vf");
240
241 DEBUGOUT("Issuing a function level reset to MAC\n");
242 ctrl = E1000_READ_REG(hw, E1000_CTRL);
243 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
244
245
246 while (!mbx->ops.check_for_rst(hw, 0) && timeout) {
247 timeout--;
248 usec_delay(5);
249 }
250
251 if (timeout) {
252
253 mbx->timeout = E1000_VF_MBX_INIT_TIMEOUT;
254
255 msgbuf[0] = E1000_VF_RESET;
256 mbx->ops.write_posted(hw, msgbuf, 1, 0);
257
258 msec_delay(10);
259
260
261 ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
262 if (!ret_val) {
263 if (msgbuf[0] == (E1000_VF_RESET |
264 E1000_VT_MSGTYPE_ACK))
265 memcpy(hw->mac.perm_addr, addr, 6);
266 else
267 ret_val = -E1000_ERR_MAC_INIT;
268 }
269 }
270
271 return ret_val;
272}
273
274
275
276
277
278
279
280STATIC s32 e1000_init_hw_vf(struct e1000_hw *hw)
281{
282 DEBUGFUNC("e1000_init_hw_vf");
283
284
285 e1000_rar_set_vf(hw, hw->mac.addr, 0);
286
287 return E1000_SUCCESS;
288}
289
290
291
292
293
294
295
296STATIC int e1000_rar_set_vf(struct e1000_hw *hw, u8 *addr,
297 u32 E1000_UNUSEDARG index)
298{
299 struct e1000_mbx_info *mbx = &hw->mbx;
300 u32 msgbuf[3];
301 u8 *msg_addr = (u8 *)(&msgbuf[1]);
302 s32 ret_val;
303
304 UNREFERENCED_1PARAMETER(index);
305 memset(msgbuf, 0, 12);
306 msgbuf[0] = E1000_VF_SET_MAC_ADDR;
307 memcpy(msg_addr, addr, 6);
308 ret_val = mbx->ops.write_posted(hw, msgbuf, 3, 0);
309
310 if (!ret_val)
311 ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
312
313 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
314
315
316 if (!ret_val &&
317 (msgbuf[0] == (E1000_VF_SET_MAC_ADDR | E1000_VT_MSGTYPE_NACK)))
318 e1000_read_mac_addr_vf(hw);
319
320 return E1000_SUCCESS;
321}
322
323
324
325
326
327
328
329
330
331STATIC u32 e1000_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
332{
333 u32 hash_value, hash_mask;
334 u8 bit_shift = 0;
335
336 DEBUGFUNC("e1000_hash_mc_addr_generic");
337
338
339 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
340
341
342
343
344
345 while (hash_mask >> bit_shift != 0xFF)
346 bit_shift++;
347
348 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
349 (((u16) mc_addr[5]) << bit_shift)));
350
351 return hash_value;
352}
353
354STATIC void e1000_write_msg_read_ack(struct e1000_hw *hw,
355 u32 *msg, u16 size)
356{
357 struct e1000_mbx_info *mbx = &hw->mbx;
358 u32 retmsg[E1000_VFMAILBOX_SIZE];
359 s32 retval = mbx->ops.write_posted(hw, msg, size, 0);
360
361 if (!retval)
362 mbx->ops.read_posted(hw, retmsg, E1000_VFMAILBOX_SIZE, 0);
363}
364
365
366
367
368
369
370
371
372
373
374void e1000_update_mc_addr_list_vf(struct e1000_hw *hw,
375 u8 *mc_addr_list, u32 mc_addr_count)
376{
377 u32 msgbuf[E1000_VFMAILBOX_SIZE];
378 u16 *hash_list = (u16 *)&msgbuf[1];
379 u32 hash_value;
380 u32 i;
381
382 DEBUGFUNC("e1000_update_mc_addr_list_vf");
383
384
385
386
387
388
389
390
391
392
393 DEBUGOUT1("MC Addr Count = %d\n", mc_addr_count);
394
395 msgbuf[0] = E1000_VF_SET_MULTICAST;
396
397 if (mc_addr_count > 30) {
398 msgbuf[0] |= E1000_VF_SET_MULTICAST_OVERFLOW;
399 mc_addr_count = 30;
400 }
401
402 msgbuf[0] |= mc_addr_count << E1000_VT_MSGINFO_SHIFT;
403
404 for (i = 0; i < mc_addr_count; i++) {
405 hash_value = e1000_hash_mc_addr_vf(hw, mc_addr_list);
406 DEBUGOUT1("Hash value = 0x%03X\n", hash_value);
407 hash_list[i] = hash_value & 0x0FFF;
408 mc_addr_list += ETH_ADDR_LEN;
409 }
410
411 e1000_write_msg_read_ack(hw, msgbuf, E1000_VFMAILBOX_SIZE);
412}
413
414
415
416
417
418
419
420void e1000_vfta_set_vf(struct e1000_hw *hw, u16 vid, bool set)
421{
422 u32 msgbuf[2];
423
424 msgbuf[0] = E1000_VF_SET_VLAN;
425 msgbuf[1] = vid;
426
427 if (set)
428 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
429
430 e1000_write_msg_read_ack(hw, msgbuf, 2);
431}
432
433
434
435
436
437void e1000_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
438{
439 u32 msgbuf[2];
440
441 msgbuf[0] = E1000_VF_SET_LPE;
442 msgbuf[1] = max_size;
443
444 e1000_write_msg_read_ack(hw, msgbuf, 2);
445}
446
447
448
449
450
451
452
453s32 e1000_promisc_set_vf(struct e1000_hw *hw, enum e1000_promisc_type type)
454{
455 struct e1000_mbx_info *mbx = &hw->mbx;
456 u32 msgbuf = E1000_VF_SET_PROMISC;
457 s32 ret_val;
458
459 switch (type) {
460 case e1000_promisc_multicast:
461 msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
462 break;
463 case e1000_promisc_enabled:
464 msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
465
466 case e1000_promisc_unicast:
467 msgbuf |= E1000_VF_SET_PROMISC_UNICAST;
468
469 case e1000_promisc_disabled:
470 break;
471 default:
472 return -E1000_ERR_MAC_INIT;
473 }
474
475 ret_val = mbx->ops.write_posted(hw, &msgbuf, 1, 0);
476
477 if (!ret_val)
478 ret_val = mbx->ops.read_posted(hw, &msgbuf, 1, 0);
479
480 if (!ret_val && !(msgbuf & E1000_VT_MSGTYPE_ACK))
481 ret_val = -E1000_ERR_MAC_INIT;
482
483 return ret_val;
484}
485
486
487
488
489
490STATIC s32 e1000_read_mac_addr_vf(struct e1000_hw *hw)
491{
492 int i;
493
494 for (i = 0; i < ETH_ADDR_LEN; i++)
495 hw->mac.addr[i] = hw->mac.perm_addr[i];
496
497 return E1000_SUCCESS;
498}
499
500
501
502
503
504
505
506
507
508STATIC s32 e1000_check_for_link_vf(struct e1000_hw *hw)
509{
510 struct e1000_mbx_info *mbx = &hw->mbx;
511 struct e1000_mac_info *mac = &hw->mac;
512 s32 ret_val = E1000_SUCCESS;
513 u32 in_msg = 0;
514
515 DEBUGFUNC("e1000_check_for_link_vf");
516
517
518
519
520
521
522
523
524 if (!mbx->ops.check_for_rst(hw, 0) || !mbx->timeout)
525 mac->get_link_status = true;
526
527 if (!mac->get_link_status)
528 goto out;
529
530
531 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
532 goto out;
533
534
535
536 if (mbx->ops.read(hw, &in_msg, 1, 0))
537 goto out;
538
539
540 if (!(in_msg & E1000_VT_MSGTYPE_CTS)) {
541
542 if (in_msg & E1000_VT_MSGTYPE_NACK)
543 ret_val = -E1000_ERR_MAC_INIT;
544 goto out;
545 }
546
547
548
549
550 if (!mbx->timeout) {
551 ret_val = -E1000_ERR_MAC_INIT;
552 goto out;
553 }
554
555
556
557 mac->get_link_status = false;
558
559out:
560 return ret_val;
561}
562
563