FreeBSD kernel E1000 device code
e1000_vf.c
Go to the documentation of this file.
1/******************************************************************************
2 SPDX-License-Identifier: BSD-3-Clause
3
4 Copyright (c) 2001-2020, Intel Corporation
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
16
17 3. Neither the name of the Intel Corporation nor the names of its
18 contributors may be used to endorse or promote products derived from
19 this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 POSSIBILITY OF SUCH DAMAGE.
32
33******************************************************************************/
34/*$FreeBSD$*/
35
36
37#include "e1000_api.h"
38
39
40static s32 e1000_init_phy_params_vf(struct e1000_hw *hw);
41static s32 e1000_init_nvm_params_vf(struct e1000_hw *hw);
42static void e1000_release_vf(struct e1000_hw *hw);
43static s32 e1000_acquire_vf(struct e1000_hw *hw);
44static s32 e1000_setup_link_vf(struct e1000_hw *hw);
45static s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw);
46static s32 e1000_init_mac_params_vf(struct e1000_hw *hw);
47static s32 e1000_check_for_link_vf(struct e1000_hw *hw);
48static s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
49 u16 *duplex);
50static s32 e1000_init_hw_vf(struct e1000_hw *hw);
51static s32 e1000_reset_hw_vf(struct e1000_hw *hw);
52static void e1000_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *, u32);
53static int e1000_rar_set_vf(struct e1000_hw *, u8 *, u32);
54static s32 e1000_read_mac_addr_vf(struct e1000_hw *);
55
63{
64 DEBUGFUNC("e1000_init_phy_params_vf");
65 hw->phy.type = e1000_phy_vf;
68
69 return E1000_SUCCESS;
70}
71
79{
80 DEBUGFUNC("e1000_init_nvm_params_vf");
84
85 return E1000_SUCCESS;
86}
87
93{
94 struct e1000_mac_info *mac = &hw->mac;
95
96 DEBUGFUNC("e1000_init_mac_params_vf");
97
98 /* Set media type */
99 /*
100 * Virtual functions don't care what they're media type is as they
101 * have no direct access to the PHY, or the media. That is handled
102 * by the physical function driver.
103 */
105
106 /* No ASF features for the VF driver */
107 mac->asf_firmware_present = false;
108 /* ARC subsystem not supported */
109 mac->arc_subsystem_valid = false;
110 /* Disable adaptive IFS mode so the generic funcs don't do anything */
111 mac->adaptive_ifs = false;
112 /* VF's have no MTA Registers - PF feature only */
113 mac->mta_reg_count = 128;
114 /* VF's have no access to RAR entries */
115 mac->rar_entry_count = 1;
116
117 /* Function pointers */
118 /* link setup */
120 /* bus type/speed/width */
122 /* reset */
124 /* hw initialization */
126 /* check for link */
128 /* link info */
130 /* multicast address update */
132 /* set mac address */
134 /* read mac address */
136
137
138 return E1000_SUCCESS;
139}
140
146{
147 DEBUGFUNC("e1000_init_function_pointers_vf");
148
153}
154
164{
165 return -E1000_ERR_PHY;
166}
167
177{
178 return;
179}
180
188{
189 DEBUGFUNC("e1000_setup_link_vf");
190
191 return E1000_SUCCESS;
192}
193
201{
202 struct e1000_bus_info *bus = &hw->bus;
203
204 DEBUGFUNC("e1000_get_bus_info_pcie_vf");
205
206 /* Do not set type PCI-E because we don't want disable master to run */
209
210 return 0;
211}
212
223 u16 *duplex)
224{
225 s32 status;
226
227 DEBUGFUNC("e1000_get_link_up_info_vf");
228
229 status = E1000_READ_REG(hw, E1000_STATUS);
230 if (status & E1000_STATUS_SPEED_1000) {
231 *speed = SPEED_1000;
232 DEBUGOUT("1000 Mbs, ");
233 } else if (status & E1000_STATUS_SPEED_100) {
234 *speed = SPEED_100;
235 DEBUGOUT("100 Mbs, ");
236 } else {
237 *speed = SPEED_10;
238 DEBUGOUT("10 Mbs, ");
239 }
240
241 if (status & E1000_STATUS_FD) {
242 *duplex = FULL_DUPLEX;
243 DEBUGOUT("Full Duplex\n");
244 } else {
245 *duplex = HALF_DUPLEX;
246 DEBUGOUT("Half Duplex\n");
247 }
248
249 return E1000_SUCCESS;
250}
251
260{
261 struct e1000_mbx_info *mbx = &hw->mbx;
263 s32 ret_val = -E1000_ERR_MAC_INIT;
264 u32 ctrl, msgbuf[3];
265 u8 *addr = (u8 *)(&msgbuf[1]);
266
267 DEBUGFUNC("e1000_reset_hw_vf");
268
269 DEBUGOUT("Issuing a function level reset to MAC\n");
270 ctrl = E1000_READ_REG(hw, E1000_CTRL);
272
273 /* we cannot reset while the RSTI / RSTD bits are asserted */
274 while (!mbx->ops.check_for_rst(hw, 0) && timeout) {
275 timeout--;
276 usec_delay(5);
277 }
278
279 if (timeout) {
280 /* mailbox timeout can now become active */
282
283 msgbuf[0] = E1000_VF_RESET;
284 mbx->ops.write_posted(hw, msgbuf, 1, 0);
285
286 msec_delay(10);
287
288 /* set our "perm_addr" based on info provided by PF */
289 ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
290 if (!ret_val) {
291 if (msgbuf[0] == (E1000_VF_RESET |
293 memcpy(hw->mac.perm_addr, addr, 6);
294 else
295 ret_val = -E1000_ERR_MAC_INIT;
296 }
297 }
298
299 return ret_val;
300}
301
308static s32 e1000_init_hw_vf(struct e1000_hw *hw)
309{
310 DEBUGFUNC("e1000_init_hw_vf");
311
312 /* attempt to set and restore our mac address */
313 e1000_rar_set_vf(hw, hw->mac.addr, 0);
314
315 return E1000_SUCCESS;
316}
317
324static int e1000_rar_set_vf(struct e1000_hw *hw, u8 *addr,
325 u32 E1000_UNUSEDARG index)
326{
327 struct e1000_mbx_info *mbx = &hw->mbx;
328 u32 msgbuf[3];
329 u8 *msg_addr = (u8 *)(&msgbuf[1]);
330 s32 ret_val;
331
332 memset(msgbuf, 0, 12);
333 msgbuf[0] = E1000_VF_SET_MAC_ADDR;
334 memcpy(msg_addr, addr, 6);
335 ret_val = mbx->ops.write_posted(hw, msgbuf, 3, 0);
336
337 if (!ret_val)
338 ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
339
340 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
341
342 /* if nacked the address was rejected, use "perm_addr" */
343 if (!ret_val &&
346
347 return E1000_SUCCESS;
348}
349
358static u32 e1000_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
359{
360 u32 hash_value, hash_mask;
361 u8 bit_shift = 0;
362
363 DEBUGFUNC("e1000_hash_mc_addr_generic");
364
365 /* Register count multiplied by bits per register */
366 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
367
368 /*
369 * The bit_shift is the number of left-shifts
370 * where 0xFF would still fall within the hash mask.
371 */
372 while (hash_mask >> bit_shift != 0xFF)
373 bit_shift++;
374
375 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
376 (((u16) mc_addr[5]) << bit_shift)));
377
378 return hash_value;
379}
380
381static void e1000_write_msg_read_ack(struct e1000_hw *hw,
382 u32 *msg, u16 size)
383{
384 struct e1000_mbx_info *mbx = &hw->mbx;
386 s32 retval = mbx->ops.write_posted(hw, msg, size, 0);
387
388 if (!retval)
389 mbx->ops.read_posted(hw, retmsg, E1000_VFMAILBOX_SIZE, 0);
390}
391
402 u8 *mc_addr_list, u32 mc_addr_count)
403{
405 u16 *hash_list = (u16 *)&msgbuf[1];
406 u32 hash_value;
407 u32 i;
408
409 DEBUGFUNC("e1000_update_mc_addr_list_vf");
410
411 /* Each entry in the list uses 1 16 bit word. We have 30
412 * 16 bit words available in our HW msg buffer (minus 1 for the
413 * msg type). That's 30 hash values if we pack 'em right. If
414 * there are more than 30 MC addresses to add then punt the
415 * extras for now and then add code to handle more than 30 later.
416 * It would be unusual for a server to request that many multi-cast
417 * addresses except for in large enterprise network environments.
418 */
419
420 DEBUGOUT1("MC Addr Count = %d\n", mc_addr_count);
421
422 msgbuf[0] = E1000_VF_SET_MULTICAST;
423
424 if (mc_addr_count > 30) {
426 mc_addr_count = 30;
427 }
428
429 msgbuf[0] |= mc_addr_count << E1000_VT_MSGINFO_SHIFT;
430
431 for (i = 0; i < mc_addr_count; i++) {
432 hash_value = e1000_hash_mc_addr_vf(hw, mc_addr_list);
433 DEBUGOUT1("Hash value = 0x%03X\n", hash_value);
434 hash_list[i] = hash_value & 0x0FFF;
435 mc_addr_list += ETHER_ADDR_LEN;
436 }
437
439}
440
447void e1000_vfta_set_vf(struct e1000_hw *hw, u16 vid, bool set)
448{
449 u32 msgbuf[2];
450
451 msgbuf[0] = E1000_VF_SET_VLAN;
452 msgbuf[1] = vid;
453 /* Setting the 8 bit field MSG INFO to true indicates "add" */
454 if (set)
455 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
456
457 e1000_write_msg_read_ack(hw, msgbuf, 2);
458}
459
464void e1000_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
465{
466 u32 msgbuf[2];
467
468 msgbuf[0] = E1000_VF_SET_LPE;
469 msgbuf[1] = max_size;
470
471 e1000_write_msg_read_ack(hw, msgbuf, 2);
472}
473
481{
482 struct e1000_mbx_info *mbx = &hw->mbx;
483 u32 msgbuf = E1000_VF_SET_PROMISC;
484 s32 ret_val;
485
486 switch (type) {
489 break;
492 /* FALLTHROUGH */
495 /* FALLTHROUGH */
497 break;
498 default:
499 return -E1000_ERR_MAC_INIT;
500 }
501
502 ret_val = mbx->ops.write_posted(hw, &msgbuf, 1, 0);
503
504 if (!ret_val)
505 ret_val = mbx->ops.read_posted(hw, &msgbuf, 1, 0);
506
507 if (!ret_val && !(msgbuf & E1000_VT_MSGTYPE_ACK))
508 ret_val = -E1000_ERR_MAC_INIT;
509
510 return ret_val;
511}
512
518{
519 int i;
520
521 for (i = 0; i < ETHER_ADDR_LEN; i++)
522 hw->mac.addr[i] = hw->mac.perm_addr[i];
523
524 return E1000_SUCCESS;
525}
526
536{
537 struct e1000_mbx_info *mbx = &hw->mbx;
538 struct e1000_mac_info *mac = &hw->mac;
539 s32 ret_val = E1000_SUCCESS;
540 u32 in_msg = 0;
541
542 DEBUGFUNC("e1000_check_for_link_vf");
543
544 /*
545 * We only want to run this if there has been a rst asserted.
546 * in this case that could mean a link change, device reset,
547 * or a virtual function reset
548 */
549
550 /* If we were hit with a reset or timeout drop the link */
551 if (!mbx->ops.check_for_rst(hw, 0) || !mbx->timeout)
552 mac->get_link_status = true;
553
554 if (!mac->get_link_status)
555 goto out;
556
557 /* if link status is down no point in checking to see if pf is up */
559 goto out;
560
561 /* if the read failed it could just be a mailbox collision, best wait
562 * until we are called again and don't report an error */
563 if (mbx->ops.read(hw, &in_msg, 1, 0))
564 goto out;
565
566 /* if incoming message isn't clear to send we are waiting on response */
567 if (!(in_msg & E1000_VT_MSGTYPE_CTS)) {
568 /* message is not CTS and is NACK we have lost CTS status */
569 if (in_msg & E1000_VT_MSGTYPE_NACK)
570 ret_val = -E1000_ERR_MAC_INIT;
571 goto out;
572 }
573
574 /* at this point we know the PF is talking to us, check and see if
575 * we are still accepting timeout or if we had a timeout failure.
576 * if we failed then we will need to reinit */
577 if (!mbx->timeout) {
578 ret_val = -E1000_ERR_MAC_INIT;
579 goto out;
580 }
581
582 /* if we passed all the tests above then the link is up and we no
583 * longer need to check for link */
584 mac->get_link_status = false;
585
586out:
587 return ret_val;
588}
589
e1000_promisc_type
Definition: e1000_82575.h:398
@ e1000_promisc_enabled
Definition: e1000_82575.h:402
@ e1000_promisc_unicast
Definition: e1000_82575.h:400
@ e1000_promisc_disabled
Definition: e1000_82575.h:399
@ e1000_promisc_multicast
Definition: e1000_82575.h:401
#define E1000_VF_INIT_TIMEOUT
Definition: e1000_82575.h:368
#define E1000_ERR_PHY
#define SPEED_100
#define E1000_STATUS_SPEED_1000
#define SPEED_1000
#define HALF_DUPLEX
#define E1000_STATUS_SPEED_100
#define E1000_STATUS_FD
#define E1000_CTRL_RST
#define E1000_STATUS_LU
#define SPEED_10
#define E1000_SUCCESS
#define E1000_UNUSEDARG
#define FULL_DUPLEX
#define E1000_ERR_MAC_INIT
@ e1000_phy_vf
Definition: e1000_hw.h:322
@ e1000_bus_type_reserved
Definition: e1000_hw.h:331
@ e1000_bus_speed_2500
Definition: e1000_hw.h:341
@ e1000_media_type_unknown
Definition: e1000_hw.h:282
@ e1000_nvm_none
Definition: e1000_hw.h:291
s32 e1000_init_mbx_params_vf(struct e1000_hw *hw)
Definition: e1000_mbx.c:536
#define E1000_VF_SET_PROMISC_UNICAST
Definition: e1000_mbx.h:88
#define E1000_VF_SET_LPE
Definition: e1000_mbx.h:86
#define E1000_VF_SET_PROMISC
Definition: e1000_mbx.h:87
#define E1000_VF_SET_MAC_ADDR
Definition: e1000_mbx.h:80
#define E1000_VT_MSGTYPE_CTS
Definition: e1000_mbx.h:74
#define E1000_VFMAILBOX_SIZE
Definition: e1000_mbx.h:63
#define E1000_VF_SET_VLAN_ADD
Definition: e1000_mbx.h:85
#define E1000_VF_SET_PROMISC_MULTICAST
Definition: e1000_mbx.h:89
#define E1000_VF_MBX_INIT_TIMEOUT
Definition: e1000_mbx.h:93
#define E1000_VF_RESET
Definition: e1000_mbx.h:79
#define E1000_VT_MSGTYPE_ACK
Definition: e1000_mbx.h:70
#define E1000_VF_SET_MULTICAST_OVERFLOW
Definition: e1000_mbx.h:83
#define E1000_VF_SET_VLAN
Definition: e1000_mbx.h:84
#define E1000_VT_MSGTYPE_NACK
Definition: e1000_mbx.h:72
#define E1000_VT_MSGINFO_SHIFT
Definition: e1000_mbx.h:75
#define E1000_VF_SET_MULTICAST
Definition: e1000_mbx.h:81
#define DEBUGOUT1(...)
Definition: e1000_osdep.h:111
#define msec_delay(x)
Definition: e1000_osdep.h:103
#define usec_delay(x)
Definition: e1000_osdep.h:101
uint8_t u8
Definition: e1000_osdep.h:124
#define DEBUGFUNC(F)
Definition: e1000_osdep.h:115
#define E1000_WRITE_REG(hw, reg, value)
Definition: e1000_osdep.h:196
uint16_t u16
Definition: e1000_osdep.h:123
#define DEBUGOUT(...)
Definition: e1000_osdep.h:109
#define E1000_READ_REG(hw, reg)
Definition: e1000_osdep.h:191
int32_t s32
Definition: e1000_osdep.h:126
uint32_t u32
Definition: e1000_osdep.h:122
#define E1000_STATUS
Definition: e1000_regs.h:41
#define E1000_CTRL
Definition: e1000_regs.h:39
void e1000_vfta_set_vf(struct e1000_hw *hw, u16 vid, bool set)
Definition: e1000_vf.c:447
static s32 e1000_init_mac_params_vf(struct e1000_hw *hw)
Definition: e1000_vf.c:92
static s32 e1000_reset_hw_vf(struct e1000_hw *hw)
Definition: e1000_vf.c:259
static s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw)
Definition: e1000_vf.c:200
static void e1000_release_vf(struct e1000_hw *hw)
static s32 e1000_init_hw_vf(struct e1000_hw *hw)
Definition: e1000_vf.c:308
static s32 e1000_acquire_vf(struct e1000_hw *hw)
static void e1000_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *, u32)
Definition: e1000_vf.c:401
static s32 e1000_setup_link_vf(struct e1000_hw *hw)
void e1000_init_function_pointers_vf(struct e1000_hw *hw)
Definition: e1000_vf.c:145
static s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed, u16 *duplex)
Definition: e1000_vf.c:222
void e1000_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
Definition: e1000_vf.c:464
static s32 e1000_read_mac_addr_vf(struct e1000_hw *)
Definition: e1000_vf.c:517
static s32 e1000_init_nvm_params_vf(struct e1000_hw *hw)
Definition: e1000_vf.c:78
static u32 e1000_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
Definition: e1000_vf.c:358
s32 e1000_promisc_set_vf(struct e1000_hw *hw, enum e1000_promisc_type type)
Definition: e1000_vf.c:480
static int e1000_rar_set_vf(struct e1000_hw *, u8 *, u32)
static s32 e1000_init_phy_params_vf(struct e1000_hw *hw)
Definition: e1000_vf.c:62
static s32 e1000_check_for_link_vf(struct e1000_hw *hw)
Definition: e1000_vf.c:535
static void e1000_write_msg_read_ack(struct e1000_hw *hw, u32 *msg, u16 size)
Definition: e1000_vf.c:381
enum e1000_bus_speed speed
Definition: e1000_hw.h:905
enum e1000_bus_type type
Definition: e1000_hw.h:904
struct e1000_bus_info bus
Definition: e1000_hw.h:1032
struct e1000_mac_info mac
Definition: e1000_hw.h:1028
struct e1000_nvm_info nvm
Definition: e1000_hw.h:1031
struct e1000_mbx_info mbx
Definition: e1000_hw.h:1033
struct e1000_phy_info phy
Definition: e1000_hw.h:1030
u8 addr[ETHER_ADDR_LEN]
Definition: e1000_hw.h:812
bool adaptive_ifs
Definition: e1000_hw.h:840
bool arc_subsystem_valid
Definition: e1000_hw.h:842
bool get_link_status
Definition: e1000_hw.h:846
bool asf_firmware_present
Definition: e1000_hw.h:843
u16 mta_reg_count
Definition: e1000_hw.h:830
u16 rar_entry_count
Definition: e1000_hw.h:836
struct e1000_mac_operations ops
Definition: e1000_hw.h:811
u8 perm_addr[ETHER_ADDR_LEN]
Definition: e1000_hw.h:813
s32(* get_link_up_info)(struct e1000_hw *, u16 *, u16 *)
Definition: e1000_hw.h:734
s32(* check_for_link)(struct e1000_hw *)
Definition: e1000_hw.h:728
s32(* reset_hw)(struct e1000_hw *)
Definition: e1000_hw.h:738
s32(* read_mac_addr)(struct e1000_hw *)
Definition: e1000_hw.h:748
int(* rar_set)(struct e1000_hw *, u8 *, u32)
Definition: e1000_hw.h:747
s32(* init_hw)(struct e1000_hw *)
Definition: e1000_hw.h:739
s32(* setup_link)(struct e1000_hw *)
Definition: e1000_hw.h:742
void(* update_mc_addr_list)(struct e1000_hw *, u8 *, u32)
Definition: e1000_hw.h:737
s32(* get_bus_info)(struct e1000_hw *)
Definition: e1000_hw.h:732
s32(* init_params)(struct e1000_hw *)
Definition: e1000_hw.h:724
struct e1000_mbx_operations ops
Definition: e1000_hw.h:944
s32(* init_params)(struct e1000_hw *hw)
Definition: e1000_hw.h:924
s32(* write_posted)(struct e1000_hw *, u32 *, u16, u16)
Definition: e1000_hw.h:928
s32(* check_for_rst)(struct e1000_hw *, u16)
Definition: e1000_hw.h:931
s32(* read)(struct e1000_hw *, u32 *, u16, u16)
Definition: e1000_hw.h:925
s32(* read_posted)(struct e1000_hw *, u32 *, u16, u16)
Definition: e1000_hw.h:927
struct e1000_nvm_operations ops
Definition: e1000_hw.h:889
enum e1000_nvm_type type
Definition: e1000_hw.h:890
void(* release)(struct e1000_hw *)
Definition: e1000_hw.h:802
s32(* init_params)(struct e1000_hw *)
Definition: e1000_hw.h:799
s32(* acquire)(struct e1000_hw *)
Definition: e1000_hw.h:800
enum e1000_media_type media_type
Definition: e1000_hw.h:871
struct e1000_phy_operations ops
Definition: e1000_hw.h:856
enum e1000_phy_type type
Definition: e1000_hw.h:857
s32(* init_params)(struct e1000_hw *)
Definition: e1000_hw.h:770
void(* release)(struct e1000_hw *)
Definition: e1000_hw.h:784
s32(* acquire)(struct e1000_hw *)
Definition: e1000_hw.h:771