1 | /*␊ |
2 | * Copyright (c) 2009 Evan Lojewski. All rights reserved.␊ |
3 | *␊ |
4 | * Merge into file from module compcept by ErmaC and Marchrius ␊ |
5 | *␊ |
6 | */␊ |
7 | ␊ |
8 | #include "boot.h"␊ |
9 | #include "bootstruct.h"␊ |
10 | #include "pci.h"␊ |
11 | #include "platform.h"␊ |
12 | #include "device_inject.h"␊ |
13 | #include "networking.h"␊ |
14 | ␊ |
15 | #ifndef DEBUG_NETWORKING␊ |
16 | #define DEBUG_NETWORKING 0␊ |
17 | #endif␊ |
18 | ␊ |
19 | #if DEBUG_NETWORKING␊ |
20 | #define DBG(x...)␉printf(x)␊ |
21 | #else␊ |
22 | #define DBG(x...)␊ |
23 | #endif␊ |
24 | ␊ |
25 | uint32_t builtin_set␉␉= 0;␊ |
26 | extern uint32_t devices_number;␊ |
27 | //extern uint32_t onboard_number;␊ |
28 | ␊ |
29 | int devprop_add_network_template(DevPropDevice *device, uint16_t vendor_id)␊ |
30 | {␊ |
31 | ␉uint8_t builtin = 0x00;␊ |
32 | ␉if(device)␊ |
33 | ␉{␊ |
34 | ␊ |
35 | ␉␉if((vendor_id != 0x168c) && (builtin_set == 0))␊ |
36 | ␉␉{␊ |
37 | ␉␉␉builtin_set = 1;␊ |
38 | ␉␉␉builtin = 0x01;␊ |
39 | ␉␉}␊ |
40 | ␉␉if(!devprop_add_value(device, "device_type", (uint8_t*)"ethernet", 8))␊ |
41 | ␉␉{␊ |
42 | ␉␉␉return 0;␊ |
43 | ␉␉}␊ |
44 | ␉␉if(!devprop_add_value(device, "built-in", (uint8_t*)&builtin, 1))␊ |
45 | ␉␉{␊ |
46 | ␉␉␉return 0;␊ |
47 | ␉␉}␊ |
48 | ␉␉devices_number++;␊ |
49 | ␉␉return 1;␊ |
50 | ␉}␊ |
51 | ␉else␊ |
52 | ␉{␊ |
53 | ␉␉return 0;␊ |
54 | ␉}␊ |
55 | }␊ |
56 | ␊ |
57 | static network_device known_ethernet_cards[] =␊ |
58 | {␊ |
59 | // { 0x0000, 0x0000, "Unknown" },␊ |
60 | // 8169␊ |
61 | // { 0x10EC, 0x8169, "Realtek 8169/8110 Gigabit Ethernet" },␊ |
62 | { 0x10EC, 0x8168, "Realtek RTL8111/8168 PCI Express Gigabit Ethernet" },␊ |
63 | // { 0x10EC, 0x8167, "Realtek 8169/8110 Gigabit Ethernet" },␊ |
64 | { 0x10EC, 0x8136, "Realtek RTL8101E/RTL8102E PCI Express Fast Ethernet Controller" },␊ |
65 | // 8139␊ |
66 | // { 0x10EC, 0x8139, "Realtek RTL8139/810x Family Fast Ethernet" },␊ |
67 | // { 0x1186, 0x1300, "Realtek RTL8139/810x Family Fast Ethernet" },␊ |
68 | // { 0x1113, 0x1211, "Realtek RTL8139/810x Family Fast Ethernet" },␊ |
69 | { 0x11AB, 0x4364, "Marvell Yukon Gigabit Adapter 88E8056 Singleport Copper SA" },␊ |
70 | { 0x11AB, 0x4320, "Marvell Yukon Gigabit Adapter 88E8001 Singleport Copper SA" },␊ |
71 | // Broadcom 57XX␊ |
72 | // { 0x14e4, 0x1600, "Broadcom 5751 Ethernet" },␊ |
73 | // { 0x14e4, 0x1659, "Broadcom 57XX Ethernet" },␊ |
74 | // { 0x14e4, 0x165A, "BCM5722 NetXtreme Server Gigabit Ethernet" },␊ |
75 | // { 0x14e4, 0x166A, "Broadcom 57XX Ethernet" },␊ |
76 | // { 0x14e4, 0x1672, "BCM5754M NetXtreme Gigabit Ethernet" },␊ |
77 | // { 0x14e4, 0x1673, "BCM5755M NetXtreme Gigabit Ethernet" },␊ |
78 | // { 0x14e4, 0x167A, "BCM5754 NetXtreme Gigabit Ethernet" },␊ |
79 | // { 0x14e4, 0x167B, "BCM5755 NetXtreme Gigabit Ethernet" },␊ |
80 | // { 0x14e4, 0x1684, "Broadcom 57XX Ethernet" },␊ |
81 | // { 0x14e4, 0x1691, "BCM57788 NetLink (TM) Gigabit Ethernet" },␊ |
82 | // { 0x14e4, 0x1693, "BCM5787M NetLink (TM) Gigabit Ethernet" },␊ |
83 | // { 0x14e4, 0x169B, "BCM5787 NetLink (TM) Gigabit Ethernet" },␊ |
84 | // { 0x14e4, 0x16B4, "Broadcom 57XX Ethernet" },␊ |
85 | // { 0x14e4, 0x16B5, "BCM57785 Gigabit Ethernet PCIe" },␊ |
86 | // { 0x14e4, 0x1712, "BCM5906 NetLink (TM) Fast Ethernet" },␊ |
87 | // { 0x14e4, 0x1713, "BCM5906M NetLink (TM) Fast Ethernet" },␊ |
88 | // Intel 8255x Ethernet␊ |
89 | // { 0x8086, 0x1051, "Intel 8255x Ethernet" },␊ |
90 | // { 0x8086, 0x1050, "Intel 8255x Ethernet" },␊ |
91 | // { 0x8086, 0x1029, "Intel 8255x Ethernet" },␊ |
92 | // { 0x8086, 0x1030, "Intel 8255x Ethernet" },␊ |
93 | { 0x8086, 0x10CE, "Intel(R) 82567V-2 PCI Express Gigabit Network" },␊ |
94 | // { 0x8086, 0x1209, "Intel 8255x Ethernet" },␊ |
95 | // { 0x8086, 0x1227, "Intel 8255x Ethernet" },␊ |
96 | // { 0x8086, 0x1228, "Intel 8255x Ethernet" },␊ |
97 | // { 0x8086, 0x1229, "Intel 8255x Ethernet" },␊ |
98 | // { 0x8086, 0x1503, "Intel 82579V Gigabit Network Controller" },␊ |
99 | // { 0x8086, 0x2449, "Intel 8255x Ethernet" },␊ |
100 | // { 0x8086, 0x2459, "Intel 8255x Ethernet" },␊ |
101 | // { 0x8086, 0x245D, "Intel 8255x Ethernet" },␊ |
102 | // { 0x8086, 0x1091, "Intel 8255x Ethernet" },␊ |
103 | // { 0x8086, 0x1060, "Intel 8255x Ethernet" },␊ |
104 | // Atheros AR8151 Ethernet␊ |
105 | // { 0x1969, 0x1083, "Qualcomm Atheros AR8151 v2.0 Gigabit Ethernet" },␊ |
106 | ␉{ 0x1969, 0x1026, "Atheros AR8121/AR8113/AR8114 Ethernet" },␊ |
107 | };␊ |
108 | ␊ |
109 | static network_device generic_ethernet_cards[] =␊ |
110 | {␊ |
111 | { 0x0000, 0x0000, "Generic Ethernet Controller" },␊ |
112 | { 0x10EC, 0x0000, "Realtek Ethernet Controller" },␊ |
113 | { 0x11AB, 0x0000, "Marvell Ethernet Controller" },␊ |
114 | ␉{ 0x1969, 0x0000, "Atheros Ethernet Controller" },␊ |
115 | { 0x8086, 0x0000, "Intel(R) Ethernet Controller" },␊ |
116 | };␊ |
117 | ␊ |
118 | char *get_ethernet_model(uint32_t vendor_id, uint32_t device_id)␊ |
119 | {␊ |
120 | int i = 0;␊ |
121 | for( ; i < sizeof(known_ethernet_cards) / sizeof(known_ethernet_cards[0]); i++)␊ |
122 | {␊ |
123 | if(vendor_id == known_ethernet_cards[i].vendor_id &&␊ |
124 | device_id == known_ethernet_cards[i].device_id)␊ |
125 | {␊ |
126 | return known_ethernet_cards[i].model;␊ |
127 | }␊ |
128 | }␊ |
129 | i = 0;␊ |
130 | for ( ; i < sizeof(generic_ethernet_cards) / sizeof(generic_ethernet_cards[0]); i++)␊ |
131 | {␊ |
132 | if (vendor_id == generic_ethernet_cards[i].vendor_id)␊ |
133 | {␊ |
134 | return generic_ethernet_cards[i].model;␊ |
135 | }␊ |
136 | }␊ |
137 | return generic_ethernet_cards[0].model;␊ |
138 | }␊ |
139 | ␊ |
140 | void setup_eth_builtin(pci_dt_t *eth_dev)␊ |
141 | {␊ |
142 | ␉char *devicepath = get_pci_dev_path(eth_dev);␊ |
143 | char *name_model = NULL;␊ |
144 | ␊ |
145 | ␉DevPropDevice *device = (DevPropDevice*)malloc(sizeof(DevPropDevice));␊ |
146 | ␊ |
147 | ␉verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath);␊ |
148 | ␊ |
149 | ␉if (!string)␊ |
150 | ␉{␊ |
151 | ␉␉string = devprop_create_string();␊ |
152 | ␉␉if (!string)␊ |
153 | ␉␉{␊ |
154 | ␉␉␉return;␊ |
155 | ␉␉}␊ |
156 | ␉}␊ |
157 | ␊ |
158 | ␉device = devprop_add_device(string, devicepath);␊ |
159 | ␉if(device)␊ |
160 | ␉{␊ |
161 | ␉␉verbose("Setting up lan keys\n");␊ |
162 | name_model = get_ethernet_model(eth_dev->vendor_id, eth_dev->device_id);␊ |
163 | ␊ |
164 | ␉␉devprop_add_network_template(device, eth_dev->vendor_id);␊ |
165 | devprop_add_value(device, "model", (uint8_t*)name_model, (strlen(name_model) + 1));␊ |
166 | ␊ |
167 | ␉␉stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);␊ |
168 | ␉␉if(stringdata)␊ |
169 | ␉␉{␊ |
170 | ␉␉␉memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);␊ |
171 | ␉␉␉stringlength = string->length;␊ |
172 | ␉␉}␊ |
173 | ␉}␊ |
174 | }␊ |
175 | ␊ |
176 | static network_device known_wifi_cards[] =␊ |
177 | {␊ |
178 | ␉{0x14e4, 0x4312, "Broadcom BCM4311 802.11a/b/g"},␊ |
179 | ␉{0x14e4, 0x4315, "Broadcom BCM4312 802.11b/g Wireless LAN Controller"},␊ |
180 | ␉{0x14e4, 0x4319, "Broadcom BCM4318 [AirForce 54g] 802.11a/b/g PCI Express Transceiver"},␊ |
181 | ␉{0x14e4, 0x432b, "Broadcom BCM4322 802.11a/b/g/n Wireless LAN Controller"},␊ |
182 | ␉{0x14e4, 0x432c, "Broadcom BCM4322 802.11b/g/n"},␊ |
183 | ␉{0x14e4, 0x4331, "Broadcom BCM4331 802.11a/b/g/n"},␊ |
184 | ␉{0x14e4, 0x4359, "Broadcom BCM43228 802.11a/b/g/n"},␊ |
185 | ␉{0x168C, 0x0020, "Atheros AR5513 802.11abg Wireless NIC"},␊ |
186 | ␉{0x168C, 0x0023, "Atheros AR5416 Wireless Network Adapter [AR5008 802.11(a)bgn]"},␊ |
187 | ␉{0x168C, 0x0024, "Atheros AR5418 Wireless Network Adapter [AR5008E 802.11(a)bgn]"},␊ |
188 | ␉{0x168C, 0x0027, "Atheros AR9160 Wireless Network Adapter [AR9001 802.11(a)bgn]"},␊ |
189 | ␉{0x168C, 0x0029, "Atheros AR922X Wireless Network Adapter"},␊ |
190 | ␉{0x168C, 0x002A, "Atheros AR928X Wireless Network Adapter"}, // "pci168c,2a"␊ |
191 | ␉{0x168C, 0x002B, "Atheros AR9285 Wireless Network Adapter"},␊ |
192 | };␊ |
193 | ␊ |
194 | void setup_wifi_airport(pci_dt_t *wlan_dev) // ARPT␊ |
195 | {␊ |
196 | ␉char tmp[16];␊ |
197 | ␉uint8_t␉␉BuiltIn = 0x00;␊ |
198 | ␉DevPropDevice *device ;␊ |
199 | ␉char *devicepath = get_pci_dev_path(wlan_dev);␊ |
200 | ␊ |
201 | ␉verbose("Wifi Controller [%04x:%04x]\n", wlan_dev->vendor_id, wlan_dev->device_id);␊ |
202 | ␊ |
203 | ␉if (!string)␊ |
204 | ␉{␊ |
205 | ␉␉string = devprop_create_string();␊ |
206 | ␉␉if (!string)␊ |
207 | ␉␉{␊ |
208 | ␉␉␉return;␊ |
209 | ␉␉}␊ |
210 | ␉}␊ |
211 | ␊ |
212 | ␉device = devprop_add_device(string, devicepath);␊ |
213 | ␉if(device)␊ |
214 | ␉{␊ |
215 | ␉␉//sprintf(tmp, sizeof(tmp),"Airport");␊ |
216 | ␉␉sprintf(tmp, "AirPort");␊ |
217 | ␉␉devprop_add_value(device, "AAPL,slot-name", (uint8_t *) tmp, strlen(tmp) + 1);␊ |
218 | ␉␉devprop_add_value(device, "device_type", (uint8_t *) tmp, strlen(tmp) + 1);␊ |
219 | ␉␉devprop_add_value(device, "built-in", (uint8_t *)&BuiltIn, 1);␊ |
220 | ␊ |
221 | ␉␉int i = 0;␊ |
222 | ␉␉for( ; i < sizeof(known_wifi_cards) / sizeof(known_wifi_cards[0]); i++)␊ |
223 | ␉␉{␊ |
224 | ␉␉␉if(wlan_dev->vendor_id == known_wifi_cards[i].vendor_id && wlan_dev->device_id == known_wifi_cards[i].device_id)␊ |
225 | ␉␉␉{␊ |
226 | ␉␉␉␉verbose("Setting up wifi keys\n");␊ |
227 | ␉␉␉␉devprop_add_value(device, "model", (uint8_t*)known_wifi_cards[i].model, (strlen(known_wifi_cards[i].model) + 1));␊ |
228 | ␉␉␉␉// NOTE: I would set the subsystem id and subsystem vendor id here,␊ |
229 | ␉␉␉␉// however, those values seem to be ovverriden in the boot process.␊ |
230 | ␉␉␉␉// A better method would be injecting the DTGP dsdt method␊ |
231 | ␉␉␉␉// and then injecting the subsystem id there.␊ |
232 | ␊ |
233 | ␉␉␉␉stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);␊ |
234 | ␉␉␉␉if(stringdata)␊ |
235 | ␉␉␉␉{␊ |
236 | ␉␉␉␉␉memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);␊ |
237 | ␉␉␉␉␉stringlength = string->length;␊ |
238 | ␉␉␉␉}␊ |
239 | ␉␉␉␉return;␊ |
240 | ␉␉␉}␊ |
241 | ␉␉}␊ |
242 | ␉}␊ |
243 | }␊ |
244 | |