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