| 1 |
|
| 2 |
|
| 3 |
#include <cbfs.h> |
| 4 |
#include <types.h> |
| 5 |
#include <arch/io.h> |
| 6 |
#include <device/pci_ops.h> |
| 7 |
#include <console/console.h> |
| 8 |
#include <device/device.h> |
| 9 |
#include <fmap.h> |
| 10 |
#include <variant/onboard.h> |
| 11 |
|
| 12 |
static unsigned int search(char *p, u8 *a, unsigned int lengthp, |
| 13 |
unsigned int lengtha) |
| 14 |
{ |
| 15 |
int i, j; |
| 16 |
|
| 17 |
|
| 18 |
for (j = 0; j <= lengtha - lengthp; j++) { |
| 19 |
for (i = 0; i < lengthp && p[i] == a[i + j]; i++) |
| 20 |
; |
| 21 |
if (i >= lengthp) |
| 22 |
return j; |
| 23 |
} |
| 24 |
return lengtha; |
| 25 |
} |
| 26 |
|
| 27 |
static unsigned char get_hex_digit(u8 *offset) |
| 28 |
{ |
| 29 |
unsigned char retval = 0; |
| 30 |
|
| 31 |
retval = *offset - '0'; |
| 32 |
if (retval > 0x09) { |
| 33 |
retval = *offset - 'A' + 0x0A; |
| 34 |
if (retval > 0x0F) |
| 35 |
retval = *offset - 'a' + 0x0a; |
| 36 |
} |
| 37 |
if (retval > 0x0F) { |
| 38 |
printk(BIOS_ERR, "Invalid Hex digit found: %c - 0x%02x\n", *offset, *offset); |
| 39 |
retval = 0; |
| 40 |
} |
| 41 |
|
| 42 |
return retval; |
| 43 |
} |
| 44 |
|
| 45 |
static int get_mac_address(u32 *high_dword, u32 *low_dword, |
| 46 |
u8 *search_address, u32 search_length) |
| 47 |
{ |
| 48 |
char key[] = "ethernet_mac"; |
| 49 |
unsigned int offset; |
| 50 |
int i; |
| 51 |
|
| 52 |
offset = search(key, search_address, sizeof(key) - 1, search_length); |
| 53 |
if (offset == search_length) { |
| 54 |
printk(BIOS_ERR, "Could not locate '%s' in VPD\n", key); |
| 55 |
return 0; |
| 56 |
} |
| 57 |
printk(BIOS_DEBUG, "Located '%s' in VPD\n", key); |
| 58 |
|
| 59 |
offset += sizeof(key); |
| 60 |
*high_dword = 0; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
for (i = 0; i < 4; i++) { |
| 72 |
*high_dword |= (get_hex_digit(search_address + offset) |
| 73 |
<< (4 + (i * 8))); |
| 74 |
*high_dword |= (get_hex_digit(search_address + offset + 1) |
| 75 |
<< (i * 8)); |
| 76 |
offset += 3; |
| 77 |
} |
| 78 |
|
| 79 |
*low_dword = 0; |
| 80 |
for (i = 0; i < 2; i++) { |
| 81 |
*low_dword |= (get_hex_digit(search_address + offset) |
| 82 |
<< (4 + (i * 8))); |
| 83 |
*low_dword |= (get_hex_digit(search_address + offset + 1) |
| 84 |
<< (i * 8)); |
| 85 |
offset += 3; |
| 86 |
} |
| 87 |
|
| 88 |
return *high_dword | *low_dword; |
| 89 |
} |
| 90 |
|
| 91 |
static void program_mac_address(u16 io_base) |
| 92 |
{ |
| 93 |
void *search_address = NULL; |
| 94 |
size_t search_length = -1; |
| 95 |
|
| 96 |
|
| 97 |
u32 high_dword = 0xD0BA00A0; |
| 98 |
u32 low_dword = 0x0000AD0B; |
| 99 |
|
| 100 |
if (CONFIG(VPD)) { |
| 101 |
struct region_device rdev; |
| 102 |
|
| 103 |
if (fmap_locate_area_as_rdev("RO_VPD", &rdev) == 0) { |
| 104 |
search_address = rdev_mmap_full(&rdev); |
| 105 |
|
| 106 |
if (search_address != NULL) |
| 107 |
search_length = region_device_sz(&rdev); |
| 108 |
} |
| 109 |
} else { |
| 110 |
search_address = cbfs_map("vpd.bin", &search_length); |
| 111 |
} |
| 112 |
|
| 113 |
if (search_address == NULL) |
| 114 |
printk(BIOS_ERR, "LAN: VPD not found.\n"); |
| 115 |
else |
| 116 |
get_mac_address(&high_dword, &low_dword, search_address, |
| 117 |
search_length); |
| 118 |
|
| 119 |
if (io_base) { |
| 120 |
printk(BIOS_DEBUG, "Realtek NIC io_base = 0x%04x\n", io_base); |
| 121 |
printk(BIOS_DEBUG, "Programming MAC Address\n"); |
| 122 |
|
| 123 |
|
| 124 |
outb(0xc0, io_base + 0x50); |
| 125 |
outl(high_dword, io_base); |
| 126 |
outl(low_dword, io_base + 0x04); |
| 127 |
outb(0x60, io_base + 54); |
| 128 |
|
| 129 |
outb(0x00, io_base + 0x50); |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
void lan_init(void) |
| 134 |
{ |
| 135 |
u16 io_base = 0; |
| 136 |
struct device *ethernet_dev = NULL; |
| 137 |
|
| 138 |
|
| 139 |
ethernet_dev = dev_find_device(SUMO_NIC_VENDOR_ID, |
| 140 |
SUMO_NIC_DEVICE_ID, 0); |
| 141 |
if (ethernet_dev != NULL) { |
| 142 |
io_base = pci_read_config16(ethernet_dev, 0x10) & 0xfffe; |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
pci_write_config8(ethernet_dev, 0x81, 0x01); |
| 150 |
} |
| 151 |
|
| 152 |
if (io_base) { |
| 153 |
|
| 154 |
program_mac_address(io_base); |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
outb(0xc0, io_base + 0x50); |
| 170 |
outb((SUMO_NIC_LED_MODE << 6) | 0x0f, io_base + 0x52); |
| 171 |
outb(0x00, io_base + 0x50); |
| 172 |
} |
| 173 |
} |