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