Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 3 | |
| 4 | /* |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 5 | * This driver resets the 10ec:8168 NIC then tries to read |
| 6 | * "macaddress" string XX:XX:XX:XX:XX:XX from CBFS. |
| 7 | * If no MAC is found, it programs a default MAC address in the device |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 8 | * so that if the EEPROM/efuse is unconfigured it still has a default MAC. |
| 9 | */ |
| 10 | |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 11 | #include <cbfs.h> |
Gaggery Tsai | 6919a93 | 2017-11-16 17:21:23 +0800 | [diff] [blame] | 12 | #include <arch/acpi_device.h> |
| 13 | #include <arch/acpigen.h> |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 14 | #include <string.h> |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 15 | #include <arch/io.h> |
Shelley Chen | 0528b61 | 2017-06-12 18:29:24 -0700 | [diff] [blame] | 16 | #include <console/console.h> |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 17 | #include <device/device.h> |
| 18 | #include <device/pci.h> |
| 19 | #include <device/pci_ops.h> |
| 20 | #include <device/pci_def.h> |
| 21 | #include <delay.h> |
Shelley Chen | 0528b61 | 2017-06-12 18:29:24 -0700 | [diff] [blame] | 22 | #include <fmap.h> |
Elyes HAOUAS | bd1683d | 2019-05-15 21:05:37 +0200 | [diff] [blame] | 23 | #include <types.h> |
| 24 | |
Gaggery Tsai | 65623ef | 2017-09-29 11:15:23 +0800 | [diff] [blame] | 25 | #include "chip.h" |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 26 | |
| 27 | #define NIC_TIMEOUT 1000 |
| 28 | |
| 29 | #define CMD_REG 0x37 |
| 30 | #define CMD_REG_RESET 0x10 |
Gaggery Tsai | 65623ef | 2017-09-29 11:15:23 +0800 | [diff] [blame] | 31 | #define CMD_LED0_LED1 0x18 |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 32 | |
| 33 | #define CFG_9346 0x50 |
| 34 | #define CFG_9346_LOCK 0x00 |
| 35 | #define CFG_9346_UNLOCK 0xc0 |
| 36 | |
Gaggery Tsai | 1f84704 | 2017-12-26 17:13:52 +0800 | [diff] [blame] | 37 | #define DEVICE_INDEX_BYTE 12 |
| 38 | #define MAX_DEVICE_SUPPORT 10 |
Shelley Chen | 0528b61 | 2017-06-12 18:29:24 -0700 | [diff] [blame] | 39 | /** |
| 40 | * search: Find first instance of string in a given region |
| 41 | * @param p string to find |
| 42 | * @param a start address of region to search |
| 43 | * @param lengthp length of string to search for |
| 44 | * @param lengtha length of region to search in |
| 45 | * @return offset offset from start address a where string was found. |
| 46 | * If string not found, return lengtha. |
| 47 | */ |
| 48 | static size_t search(const char *p, const u8 *a, size_t lengthp, |
| 49 | size_t lengtha) |
| 50 | { |
| 51 | size_t i, j; |
| 52 | |
| 53 | if (lengtha < lengthp) |
| 54 | return lengtha; |
| 55 | /* Searching */ |
| 56 | for (j = 0; j <= lengtha - lengthp; j++) { |
| 57 | for (i = 0; i < lengthp && p[i] == a[i + j]; i++) |
| 58 | ; |
David Wu | 9a0d9e0 | 2018-05-04 15:37:37 +0800 | [diff] [blame] | 59 | if (i >= lengthp && a[j - 1] == lengthp) |
Shelley Chen | 0528b61 | 2017-06-12 18:29:24 -0700 | [diff] [blame] | 60 | return j; |
| 61 | } |
| 62 | return lengtha; |
| 63 | } |
| 64 | |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 65 | static u8 get_hex_digit(const u8 c) |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 66 | { |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 67 | u8 ret = 0; |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 68 | |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 69 | ret = c - '0'; |
| 70 | if (ret > 0x09) { |
| 71 | ret = c - 'A' + 0x0a; |
| 72 | if (ret > 0x0f) |
| 73 | ret = c - 'a' + 0x0a; |
| 74 | } |
| 75 | if (ret > 0x0f) { |
Shelley Chen | 0528b61 | 2017-06-12 18:29:24 -0700 | [diff] [blame] | 76 | printk(BIOS_ERR, "Error: Invalid hex digit found: " |
| 77 | "%c - 0x%02x\n", (char)c, c); |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 78 | ret = 0; |
| 79 | } |
| 80 | return ret; |
| 81 | } |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 82 | |
Shelley Chen | 0528b61 | 2017-06-12 18:29:24 -0700 | [diff] [blame] | 83 | #define MACLEN 17 |
| 84 | |
Edward O'Callaghan | 2a82f74 | 2020-03-25 12:52:50 +1100 | [diff] [blame] | 85 | /* Returns MAC address based on the key that is passed in. */ |
| 86 | static enum cb_err fetch_mac_vpd_key(u8 *macstrbuf, const char *vpd_key) |
Shelley Chen | 0528b61 | 2017-06-12 18:29:24 -0700 | [diff] [blame] | 87 | { |
| 88 | struct region_device rdev; |
| 89 | void *search_address; |
| 90 | size_t search_length; |
| 91 | size_t offset; |
Edward O'Callaghan | 2a82f74 | 2020-03-25 12:52:50 +1100 | [diff] [blame] | 92 | |
| 93 | if (fmap_locate_area_as_rdev("RO_VPD", &rdev)) { |
| 94 | printk(BIOS_ERR, "Error: Couldn't find RO_VPD region."); |
| 95 | return CB_ERR; |
| 96 | } |
| 97 | search_address = rdev_mmap_full(&rdev); |
| 98 | if (search_address == NULL) { |
| 99 | printk(BIOS_ERR, "LAN: VPD not found.\n"); |
| 100 | return CB_ERR; |
| 101 | } |
| 102 | |
| 103 | search_length = region_device_sz(&rdev); |
| 104 | offset = search(vpd_key, search_address, strlen(vpd_key), |
| 105 | search_length); |
| 106 | |
| 107 | if (offset == search_length) { |
| 108 | printk(BIOS_ERR, |
| 109 | "Error: Could not locate '%s' in VPD\n", vpd_key); |
Edward O'Callaghan | d08bc5a | 2020-03-26 14:37:37 +1100 | [diff] [blame] | 110 | rdev_munmap(&rdev, search_address); |
Edward O'Callaghan | 2a82f74 | 2020-03-25 12:52:50 +1100 | [diff] [blame] | 111 | return CB_ERR; |
| 112 | } |
| 113 | printk(BIOS_DEBUG, "Located '%s' in VPD\n", vpd_key); |
| 114 | |
| 115 | offset += strlen(vpd_key) + 1; /* move to next character */ |
| 116 | |
| 117 | if (offset + MACLEN > search_length) { |
Edward O'Callaghan | d08bc5a | 2020-03-26 14:37:37 +1100 | [diff] [blame] | 118 | rdev_munmap(&rdev, search_address); |
Edward O'Callaghan | 2a82f74 | 2020-03-25 12:52:50 +1100 | [diff] [blame] | 119 | printk(BIOS_ERR, "Search result too small!\n"); |
| 120 | return CB_ERR; |
| 121 | } |
| 122 | memcpy(macstrbuf, search_address + offset, MACLEN); |
Edward O'Callaghan | d08bc5a | 2020-03-26 14:37:37 +1100 | [diff] [blame] | 123 | rdev_munmap(&rdev, search_address); |
Edward O'Callaghan | 2a82f74 | 2020-03-25 12:52:50 +1100 | [diff] [blame] | 124 | |
| 125 | return CB_SUCCESS; |
| 126 | } |
| 127 | |
| 128 | /* Prepares vpd_key by concatenating ethernet_mac with device_index */ |
| 129 | static enum cb_err fetch_mac_vpd_dev_idx(u8 *macstrbuf, u8 device_index) |
| 130 | { |
Gaggery Tsai | 1f84704 | 2017-12-26 17:13:52 +0800 | [diff] [blame] | 131 | char key[] = "ethernet_mac "; /* Leave a space at tail to stuff an index */ |
| 132 | |
| 133 | /* |
Edward O'Callaghan | 0e13806 | 2020-03-23 13:06:42 +1100 | [diff] [blame] | 134 | * Map each NIC on the DUT to "ethernet_macN", where N is [0-9]. |
| 135 | * Translate index number from integer to ascii by adding '0' char. |
Gaggery Tsai | 1f84704 | 2017-12-26 17:13:52 +0800 | [diff] [blame] | 136 | */ |
Edward O'Callaghan | 0e13806 | 2020-03-23 13:06:42 +1100 | [diff] [blame] | 137 | key[DEVICE_INDEX_BYTE] = device_index + '0'; |
Shelley Chen | 0528b61 | 2017-06-12 18:29:24 -0700 | [diff] [blame] | 138 | |
Edward O'Callaghan | 2a82f74 | 2020-03-25 12:52:50 +1100 | [diff] [blame] | 139 | return fetch_mac_vpd_key(macstrbuf, key); |
| 140 | } |
| 141 | |
| 142 | static void fetch_mac_string_vpd(struct drivers_net_config *config, u8 *macstrbuf) |
| 143 | { |
| 144 | if (!config) |
| 145 | return; |
| 146 | |
| 147 | /* Current implementation is up to 10 NIC cards */ |
| 148 | if (config->device_index > MAX_DEVICE_SUPPORT) { |
| 149 | printk(BIOS_ERR, "r8168: the maximum device_index should be less then %d\n." |
| 150 | " Using default 00:e0:4c:00:c0:b0\n", MAX_DEVICE_SUPPORT); |
| 151 | return; |
Shelley Chen | 0528b61 | 2017-06-12 18:29:24 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Edward O'Callaghan | 0e13806 | 2020-03-23 13:06:42 +1100 | [diff] [blame] | 154 | if (fetch_mac_vpd_dev_idx(macstrbuf, config->device_index) == CB_SUCCESS) |
Edward O'Callaghan | 2a82f74 | 2020-03-25 12:52:50 +1100 | [diff] [blame] | 155 | return; |
Gaggery Tsai | 1f84704 | 2017-12-26 17:13:52 +0800 | [diff] [blame] | 156 | |
Edward O'Callaghan | 0e13806 | 2020-03-23 13:06:42 +1100 | [diff] [blame] | 157 | if (!CONFIG(RT8168_SUPPORT_LEGACY_VPD_MAC)) { |
| 158 | printk(BIOS_ERR, "r8168: mac address not found in VPD," |
| 159 | " using default 00:e0:4c:00:c0:b0\n"); |
| 160 | return; |
| 161 | } |
| 162 | |
Edward O'Callaghan | 2a0a02f | 2020-03-26 16:47:55 +1100 | [diff] [blame] | 163 | if (fetch_mac_vpd_key(macstrbuf, "ethernet_mac") != CB_SUCCESS) |
Edward O'Callaghan | 2a82f74 | 2020-03-25 12:52:50 +1100 | [diff] [blame] | 164 | printk(BIOS_ERR, "r8168: mac address not found in VPD," |
| 165 | " using default 00:e0:4c:00:c0:b0\n"); |
Shelley Chen | 0528b61 | 2017-06-12 18:29:24 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | static enum cb_err fetch_mac_string_cbfs(u8 *macstrbuf) |
| 169 | { |
| 170 | struct cbfsf fh; |
| 171 | uint32_t matchraw = CBFS_TYPE_RAW; |
| 172 | |
| 173 | if (!cbfs_boot_locate(&fh, "rt8168-macaddress", &matchraw)) { |
| 174 | /* check the cbfs for the mac address */ |
| 175 | if (rdev_readat(&fh.data, macstrbuf, 0, MACLEN) != MACLEN) { |
| 176 | printk(BIOS_ERR, "r8168: Error reading MAC from CBFS\n"); |
| 177 | return CB_ERR; |
| 178 | } |
| 179 | return CB_SUCCESS; |
| 180 | } |
| 181 | return CB_ERR; |
| 182 | } |
| 183 | |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 184 | static void get_mac_address(u8 *macaddr, const u8 *strbuf) |
| 185 | { |
| 186 | size_t offset = 0; |
| 187 | int i; |
| 188 | |
Shelley Chen | 0528b61 | 2017-06-12 18:29:24 -0700 | [diff] [blame] | 189 | if ((strbuf[2] != ':') || (strbuf[5] != ':') || |
| 190 | (strbuf[8] != ':') || (strbuf[11] != ':') || |
| 191 | (strbuf[14] != ':')) { |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 192 | printk(BIOS_ERR, "r8168: ignore invalid MAC address in cbfs\n"); |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | for (i = 0; i < 6; i++) { |
| 197 | macaddr[i] = 0; |
| 198 | macaddr[i] |= get_hex_digit(strbuf[offset]) << 4; |
| 199 | macaddr[i] |= get_hex_digit(strbuf[offset + 1]); |
| 200 | offset += 3; |
| 201 | } |
| 202 | } |
| 203 | |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 204 | static void program_mac_address(struct device *dev, u16 io_base) |
| 205 | { |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 206 | u8 macstrbuf[MACLEN] = { 0 }; |
| 207 | int i = 0; |
Shelley Chen | 0528b61 | 2017-06-12 18:29:24 -0700 | [diff] [blame] | 208 | /* Default MAC Address of 00:E0:4C:00:C0:B0 */ |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 209 | u8 mac[6] = { 0x00, 0xe0, 0x4c, 0x00, 0xc0, 0xb0 }; |
Gaggery Tsai | 1f84704 | 2017-12-26 17:13:52 +0800 | [diff] [blame] | 210 | struct drivers_net_config *config = dev->chip_info; |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 211 | |
Shelley Chen | 0528b61 | 2017-06-12 18:29:24 -0700 | [diff] [blame] | 212 | /* check the VPD for the mac address */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 213 | if (CONFIG(RT8168_GET_MAC_FROM_VPD)) { |
Edward O'Callaghan | 2a82f74 | 2020-03-25 12:52:50 +1100 | [diff] [blame] | 214 | fetch_mac_string_vpd(config, macstrbuf); |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 215 | } else { |
Shelley Chen | 0528b61 | 2017-06-12 18:29:24 -0700 | [diff] [blame] | 216 | if (fetch_mac_string_cbfs(macstrbuf) != CB_SUCCESS) |
| 217 | printk(BIOS_ERR, "r8168: Error reading MAC from CBFS," |
Gaggery Tsai | 1f84704 | 2017-12-26 17:13:52 +0800 | [diff] [blame] | 218 | " using default 00:e0:4c:00:c0:b0\n"); |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 219 | } |
Shelley Chen | 0528b61 | 2017-06-12 18:29:24 -0700 | [diff] [blame] | 220 | get_mac_address(mac, macstrbuf); |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 221 | |
| 222 | /* Reset NIC */ |
| 223 | printk(BIOS_DEBUG, "r8168: Resetting NIC..."); |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 224 | outb(CMD_REG_RESET, io_base + CMD_REG); |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 225 | |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 226 | /* Poll for reset, with 1sec timeout */ |
| 227 | while (i < NIC_TIMEOUT && (inb(io_base + CMD_REG) & CMD_REG_RESET)) { |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 228 | udelay(1000); |
| 229 | if (++i >= NIC_TIMEOUT) |
Shelley Chen | 0528b61 | 2017-06-12 18:29:24 -0700 | [diff] [blame] | 230 | printk(BIOS_ERR, "timeout waiting for nic to reset\n"); |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 231 | } |
| 232 | if (i < NIC_TIMEOUT) |
| 233 | printk(BIOS_DEBUG, "done\n"); |
| 234 | |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 235 | printk(BIOS_DEBUG, "r8168: Programming MAC Address..."); |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 236 | |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 237 | /* Disable register protection */ |
| 238 | outb(CFG_9346_UNLOCK, io_base + CFG_9346); |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 239 | |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 240 | /* Set MAC address: only 4-byte write accesses allowed */ |
| 241 | outl(mac[4] | mac[5] << 8, io_base + 4); |
| 242 | inl(io_base + 4); |
| 243 | outl(mac[0] | mac[1] << 8 | mac[2] << 16 | mac[3] << 24, |
| 244 | io_base); |
| 245 | inl(io_base); |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 246 | /* Lock config regs */ |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 247 | outb(CFG_9346_LOCK, io_base + CFG_9346); |
| 248 | |
| 249 | printk(BIOS_DEBUG, "done\n"); |
| 250 | } |
| 251 | |
Gaggery Tsai | 65623ef | 2017-09-29 11:15:23 +0800 | [diff] [blame] | 252 | static void r8168_set_customized_led(struct device *dev, u16 io_base) |
| 253 | { |
| 254 | struct drivers_net_config *config = dev->chip_info; |
| 255 | |
| 256 | if (!config) |
| 257 | return; |
| 258 | |
| 259 | /* Read the customized LED setting from devicetree */ |
| 260 | printk(BIOS_DEBUG, "r8168: Customized LED 0x%x\n", config->customized_leds); |
| 261 | |
| 262 | /* |
| 263 | * Refer to RTL8111H datasheet 7.2 Customizable LED Configuration |
| 264 | * Starting from offset 0x18 |
| 265 | * Bit[15:12] LED Feature Control(FC) |
| 266 | * Bit[11:08] LED Select for PINLED2 |
| 267 | * Bit[07:04] LED Select for PINLED1 |
| 268 | * Bit[03:00] LED Select for PINLED0 |
| 269 | * |
| 270 | * Speed Link10M Link100M Link1000M ACT/Full |
| 271 | * LED0 Bit0 Bit1 Bit2 Bit3 |
| 272 | * LED1 Bit4 Bit5 Bit6 Bit7 |
| 273 | * LED2 Bit8 Bit9 Bit10 Bit11 |
| 274 | * FC Bit12 Bit13 Bit14 Bit15 |
| 275 | */ |
| 276 | |
| 277 | /* Set customized LED registers */ |
| 278 | outw(config->customized_leds, io_base + CMD_LED0_LED1); |
| 279 | printk(BIOS_DEBUG, "r8168: read back LED setting as 0x%x\n", |
| 280 | inw(io_base + CMD_LED0_LED1)); |
| 281 | } |
| 282 | |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 283 | static void r8168_init(struct device *dev) |
| 284 | { |
| 285 | /* Get the resource of the NIC mmio */ |
| 286 | struct resource *nic_res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 287 | u16 io_base = (u16)nic_res->base; |
| 288 | |
Gaggery Tsai | 65623ef | 2017-09-29 11:15:23 +0800 | [diff] [blame] | 289 | /* Check if the base is invalid */ |
| 290 | if (!io_base) { |
| 291 | printk(BIOS_ERR, "r8168: Error cant find IO resource\n"); |
| 292 | return; |
| 293 | } |
Damien Zammit | f5dd23f | 2016-12-01 23:29:34 +1100 | [diff] [blame] | 294 | /* Enable but do not set bus master */ |
| 295 | pci_write_config16(dev, PCI_COMMAND, |
| 296 | PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
| 297 | |
| 298 | /* Program MAC address based on CBFS "macaddress" containing |
| 299 | * a string AA:BB:CC:DD:EE:FF */ |
Gaggery Tsai | 65623ef | 2017-09-29 11:15:23 +0800 | [diff] [blame] | 300 | program_mac_address(dev, io_base); |
| 301 | |
| 302 | /* Program customized LED mode */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 303 | if (CONFIG(RT8168_SET_LED_MODE)) |
Gaggery Tsai | 65623ef | 2017-09-29 11:15:23 +0800 | [diff] [blame] | 304 | r8168_set_customized_led(dev, io_base); |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 305 | } |
| 306 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 307 | #if CONFIG(HAVE_ACPI_TABLES) |
Gaggery Tsai | 6919a93 | 2017-11-16 17:21:23 +0800 | [diff] [blame] | 308 | #define R8168_ACPI_HID "R8168" |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 309 | static void r8168_net_fill_ssdt(const struct device *dev) |
Gaggery Tsai | 6919a93 | 2017-11-16 17:21:23 +0800 | [diff] [blame] | 310 | { |
| 311 | struct drivers_net_config *config = dev->chip_info; |
| 312 | const char *path = acpi_device_path(dev->bus->dev); |
| 313 | u32 address; |
| 314 | |
| 315 | if (!path || !config) |
| 316 | return; |
| 317 | |
| 318 | /* Device */ |
| 319 | acpigen_write_scope(path); |
| 320 | acpigen_write_device(acpi_device_name(dev)); |
| 321 | acpigen_write_name_string("_HID", R8168_ACPI_HID); |
Patrick Rudolph | c83bab6 | 2019-12-13 12:16:06 +0100 | [diff] [blame] | 322 | acpi_device_write_uid(dev); |
| 323 | |
Gaggery Tsai | 6919a93 | 2017-11-16 17:21:23 +0800 | [diff] [blame] | 324 | if (dev->chip_ops) |
| 325 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
| 326 | |
Edward O'Callaghan | b765fa6 | 2020-01-21 21:01:32 +1100 | [diff] [blame] | 327 | /* Power Resource */ |
| 328 | if (config->has_power_resource) { |
| 329 | const struct acpi_power_res_params power_res_params = { |
| 330 | .stop_gpio = &config->stop_gpio, |
| 331 | .stop_delay_ms = config->stop_delay_ms, |
| 332 | .stop_off_delay_ms = config->stop_off_delay_ms |
| 333 | }; |
| 334 | acpi_device_add_power_res(&power_res_params); |
| 335 | } |
| 336 | |
Gaggery Tsai | 6919a93 | 2017-11-16 17:21:23 +0800 | [diff] [blame] | 337 | /* Address */ |
| 338 | address = PCI_SLOT(dev->path.pci.devfn) & 0xffff; |
| 339 | address <<= 16; |
| 340 | address |= PCI_FUNC(dev->path.pci.devfn) & 0xffff; |
| 341 | acpigen_write_name_dword("_ADR", address); |
| 342 | |
| 343 | /* Wake capabilities */ |
| 344 | if (config->wake) |
| 345 | acpigen_write_PRW(config->wake, 3); |
| 346 | |
| 347 | acpigen_pop_len(); /* Device */ |
| 348 | acpigen_pop_len(); /* Scope */ |
| 349 | |
| 350 | printk(BIOS_INFO, "%s.%s: %s %s\n", path, acpi_device_name(dev), |
| 351 | dev->chip_ops ? dev->chip_ops->name : "", dev_path(dev)); |
| 352 | } |
| 353 | |
| 354 | static const char *r8168_net_acpi_name(const struct device *dev) |
| 355 | { |
| 356 | return "RLTK"; |
| 357 | } |
| 358 | #endif |
| 359 | |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 360 | static struct device_operations r8168_ops = { |
Martin Roth | b9810a4 | 2017-07-23 20:00:04 -0600 | [diff] [blame] | 361 | .read_resources = pci_dev_read_resources, |
| 362 | .set_resources = pci_dev_set_resources, |
| 363 | .enable_resources = pci_dev_enable_resources, |
| 364 | .init = r8168_init, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 365 | #if CONFIG(HAVE_ACPI_TABLES) |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 366 | .acpi_name = r8168_net_acpi_name, |
| 367 | .acpi_fill_ssdt = r8168_net_fill_ssdt, |
Gaggery Tsai | 6919a93 | 2017-11-16 17:21:23 +0800 | [diff] [blame] | 368 | #endif |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 369 | }; |
| 370 | |
| 371 | static const struct pci_driver r8168_driver __pci_driver = { |
Martin Roth | b9810a4 | 2017-07-23 20:00:04 -0600 | [diff] [blame] | 372 | .ops = &r8168_ops, |
| 373 | .vendor = 0x10ec, |
| 374 | .device = 0x8168, |
Damien Zammit | e983f0c | 2016-05-21 02:24:19 +1000 | [diff] [blame] | 375 | }; |
Gaggery Tsai | 6919a93 | 2017-11-16 17:21:23 +0800 | [diff] [blame] | 376 | |
| 377 | struct chip_operations drivers_net_ops = { |
| 378 | CHIP_NAME("Realtek r8168") |
| 379 | }; |