blob: e6f10aef0be3c663ee2df75029e66a80841fc7f9 [file] [log] [blame]
Angel Pons3ef916f2020-04-02 23:49:13 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Laurie57d5e472019-03-01 15:40:48 +08002
3/*
4 * The Realtek r8152 driver in the Linux kernel supports a MAC address
Simon Glassaa215742019-05-16 14:51:51 -06005 * dock pass-through feature which can result in the dock ethernet port
6 * using the same MAC address that is assigned to the internal NIC. This
7 * is done by calling an ACPI method at \_SB.AMAC() which returns a
8 * formatted string (as a buffer) containing the MAC address for the
9 * dock to use.
Duncan Laurie57d5e472019-03-01 15:40:48 +080010 *
11 * The Linux kernel implementation can be found at
12 * drivers/net/usb/r8152.c:vendor_mac_passthru_addr_read()
13 *
Jon Murphyc4e90452022-06-28 10:36:23 -060014 * For ChromeOS, the policy which controls where the dock MAC address
Simon Glassaa215742019-05-16 14:51:51 -060015 * comes from is written into RW_VPD property "dock_passthrough":
Duncan Laurie57d5e472019-03-01 15:40:48 +080016 *
17 * "dock_mac" or empty: Use MAC address from RO_VPD value "dock_mac"
18 * "ethernet_mac0": Use MAC address from RO_VPD value "ethernet_mac0"
19 * "builtin": existing dock MAC address (return nothing)
20 */
21
22Scope (\_SB)
23{
24 Method (AMAC, 0, Serialized)
25 {
26 /* Format expected by the Linux kernel r8152 driver */
27 Name (MACA, "_AUXMAC_#XXXXXXXXXXXX#")
28
Simon Glassaa215742019-05-16 14:51:51 -060029 /* Get "dock_passthrough" value from RW_VPD */
30 Local0 = \VPD.VPDF ("RW", "dock_passthrough")
Duncan Laurie57d5e472019-03-01 15:40:48 +080031
Felix Singer9df60d32022-12-26 09:43:07 +010032 Local1 = 0
Duncan Laurie57d5e472019-03-01 15:40:48 +080033 Switch (ToString (Local0))
34 {
35 Case ("ethernet_mac0") {
36 Local1 = \VPD.VPDF ("RO", "ethernet_mac0")
37 }
38 Case ("builtin") {
Felix Singer9df60d32022-12-26 09:43:07 +010039 Return (0)
Duncan Laurie57d5e472019-03-01 15:40:48 +080040 }
41 /* "dock_mac" or policy not found. */
42 Default {
43 Local1 = \VPD.VPDF ("RO", "dock_mac")
44 }
45 }
Felix Singer9df60d32022-12-26 09:43:07 +010046 If (Local1 == 0) {
47 Return (0)
Duncan Laurie57d5e472019-03-01 15:40:48 +080048 }
49 Printf ("MAC address returned from VPD: %o", Local1)
50
51 /* Verify MAC address format is AA:BB:CC:DD:EE:FF */
52 For (Local3 = 2, Local3 < 17, Local3 += 3) {
53 If (ToString (DerefOf (Local1[Local3])) != ":") {
54 Printf ("Invalid MAC address byte %o", Local3)
Felix Singer9df60d32022-12-26 09:43:07 +010055 Return (0)
Duncan Laurie57d5e472019-03-01 15:40:48 +080056 }
57 }
58
59 /* Convert MAC address into format specified by MACA */
60 Local2 = ToBuffer (MACA)
61 Local4 = 0 /* First MAC address byte in input buffer */
62 Local5 = 9 /* First MAC address byte in output buffer */
63 For (Local3 = 0, Local3 < 6, Local3++) {
64 Local2[Local5] = DerefOf (Local1[Local4])
65 Local2[Local5 + 1] = DerefOf (Local1[Local4 + 1])
66 Local5 += 2
67 Local4 += 3 /* Skip ":" in address from VPD */
68 }
69
70 Printf ("AMAC = %o", ToString (Local2))
Duncan Laurie8d8cead2019-03-07 22:24:43 +080071 Return (Local2)
Duncan Laurie57d5e472019-03-01 15:40:48 +080072 }
73}