blob: 2eb7fa0f223b64188fb22aa6856e5a11194d2e8d [file] [log] [blame]
Angel Pons3ef916f2020-04-02 23:49:13 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Duncan Laurie57d5e472019-03-01 15:40:48 +08003
4/*
5 * The Realtek r8152 driver in the Linux kernel supports a MAC address
Simon Glassaa215742019-05-16 14:51:51 -06006 * dock pass-through feature which can result in the dock ethernet port
7 * using the same MAC address that is assigned to the internal NIC. This
8 * is done by calling an ACPI method at \_SB.AMAC() which returns a
9 * formatted string (as a buffer) containing the MAC address for the
10 * dock to use.
Duncan Laurie57d5e472019-03-01 15:40:48 +080011 *
12 * The Linux kernel implementation can be found at
13 * drivers/net/usb/r8152.c:vendor_mac_passthru_addr_read()
14 *
15 * For Chrome OS, the policy which controls where the dock MAC address
Simon Glassaa215742019-05-16 14:51:51 -060016 * comes from is written into RW_VPD property "dock_passthrough":
Duncan Laurie57d5e472019-03-01 15:40:48 +080017 *
18 * "dock_mac" or empty: Use MAC address from RO_VPD value "dock_mac"
19 * "ethernet_mac0": Use MAC address from RO_VPD value "ethernet_mac0"
20 * "builtin": existing dock MAC address (return nothing)
21 */
22
23Scope (\_SB)
24{
25 Method (AMAC, 0, Serialized)
26 {
27 /* Format expected by the Linux kernel r8152 driver */
28 Name (MACA, "_AUXMAC_#XXXXXXXXXXXX#")
29
Simon Glassaa215742019-05-16 14:51:51 -060030 /* Get "dock_passthrough" value from RW_VPD */
31 Local0 = \VPD.VPDF ("RW", "dock_passthrough")
Duncan Laurie57d5e472019-03-01 15:40:48 +080032
Duncan Laurie643daed2019-05-08 15:09:29 -060033 Local1 = Zero
Duncan Laurie57d5e472019-03-01 15:40:48 +080034 Switch (ToString (Local0))
35 {
36 Case ("ethernet_mac0") {
37 Local1 = \VPD.VPDF ("RO", "ethernet_mac0")
38 }
39 Case ("builtin") {
40 Return (Zero)
41 }
42 /* "dock_mac" or policy not found. */
43 Default {
44 Local1 = \VPD.VPDF ("RO", "dock_mac")
45 }
46 }
Duncan Laurie643daed2019-05-08 15:09:29 -060047 If (Local1 == Zero) {
Duncan Laurie57d5e472019-03-01 15:40:48 +080048 Return (Zero)
49 }
50 Printf ("MAC address returned from VPD: %o", Local1)
51
52 /* Verify MAC address format is AA:BB:CC:DD:EE:FF */
53 For (Local3 = 2, Local3 < 17, Local3 += 3) {
54 If (ToString (DerefOf (Local1[Local3])) != ":") {
55 Printf ("Invalid MAC address byte %o", Local3)
56 Return (Zero)
57 }
58 }
59
60 /* Convert MAC address into format specified by MACA */
61 Local2 = ToBuffer (MACA)
62 Local4 = 0 /* First MAC address byte in input buffer */
63 Local5 = 9 /* First MAC address byte in output buffer */
64 For (Local3 = 0, Local3 < 6, Local3++) {
65 Local2[Local5] = DerefOf (Local1[Local4])
66 Local2[Local5 + 1] = DerefOf (Local1[Local4 + 1])
67 Local5 += 2
68 Local4 += 3 /* Skip ":" in address from VPD */
69 }
70
71 Printf ("AMAC = %o", ToString (Local2))
Duncan Laurie8d8cead2019-03-07 22:24:43 +080072 Return (Local2)
Duncan Laurie57d5e472019-03-01 15:40:48 +080073 }
74}