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-E Gigabit Ethernet" },␊ |
63 | // { 0x10EC, 0x8167, "Realtek 8169/8110 Gigabit Ethernet" },␊ |
64 | ␉{ 0x10EC, 0x8136, "Realtek RTL8101E/RTL8102E PCI-E 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, 0x4320, "Marvell Yukon Gigabit Adapter 88E8001 Singleport Copper SA" },␊ |
70 | ␉{ 0x11AB, 0x4364, "Marvell Yukon Gigabit Adapter 88E8056 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 | ␉{ 0x1969, 0x1026, "Atheros AR8121/AR8113/AR8114 Ethernet" },␊ |
89 | ␉{ 0x1969, 0x1083, "Atheros GbE LAN chip (10/100/1000 Mbit)" },␊ |
90 | ␉{ 0x197B, 0x0250, "JMicron PCI Express Gigabit Ethernet Adapter (10/1000MBit)" },␊ |
91 | // Intel 8255x Ethernet␊ |
92 | // { 0x8086, 0x1051, "Intel 8255x Ethernet" },␊ |
93 | // { 0x8086, 0x1050, "Intel 8255x Ethernet" },␊ |
94 | // { 0x8086, 0x1029, "Intel 8255x Ethernet" },␊ |
95 | // { 0x8086, 0x1030, "Intel 8255x Ethernet" },␊ |
96 | ␉{ 0x8086, 0x10CE, "Intel(R) 82567V-2 PCI-E Gigabit Network" },␊ |
97 | ␉{ 0x8086, 0x10D3, "Intel(R) 82574L Gigabit Network Connection" },␊ |
98 | // { 0x8086, 0x1209, "Intel 8255x Ethernet" },␊ |
99 | // { 0x8086, 0x1227, "Intel 8255x Ethernet" },␊ |
100 | // { 0x8086, 0x1228, "Intel 8255x Ethernet" },␊ |
101 | // { 0x8086, 0x1229, "Intel 8255x Ethernet" },␊ |
102 | // { 0x8086, 0x1503, "Intel 82579V Gigabit Network Controller" },␊ |
103 | // { 0x8086, 0x2449, "Intel 8255x Ethernet" },␊ |
104 | // { 0x8086, 0x2459, "Intel 8255x Ethernet" },␊ |
105 | // { 0x8086, 0x245D, "Intel 8255x Ethernet" },␊ |
106 | // { 0x8086, 0x1091, "Intel 8255x Ethernet" },␊ |
107 | // { 0x8086, 0x1060, "Intel 8255x Ethernet" },␊ |
108 | // Atheros AR8151 Ethernet␊ |
109 | // { 0x1969, 0x1083, "Qualcomm Atheros AR8151 v2.0 Gigabit Ethernet" },␊ |
110 | };␊ |
111 | ␊ |
112 | static network_device generic_ethernet_cards[] =␊ |
113 | {␊ |
114 | { 0x0000, 0x0000, "Generic Ethernet Controller" },␊ |
115 | { 0x10EC, 0x0000, "Realtek Ethernet Controller" },␊ |
116 | { 0x11AB, 0x0000, "Marvell Ethernet Controller" },␊ |
117 | ␉{ 0x1969, 0x0000, "Atheros Ethernet Controller" },␊ |
118 | { 0x8086, 0x0000, "Intel(R) Ethernet Controller" },␊ |
119 | };␊ |
120 | ␊ |
121 | char *get_ethernet_model(uint32_t vendor_id, uint32_t device_id)␊ |
122 | {␊ |
123 | int i = 0;␊ |
124 | for( ; i < sizeof(known_ethernet_cards) / sizeof(known_ethernet_cards[0]); i++)␊ |
125 | {␊ |
126 | if(vendor_id == known_ethernet_cards[i].vendor_id &&␊ |
127 | device_id == known_ethernet_cards[i].device_id)␊ |
128 | {␊ |
129 | return known_ethernet_cards[i].model;␊ |
130 | }␊ |
131 | }␊ |
132 | i = 0;␊ |
133 | for ( ; i < sizeof(generic_ethernet_cards) / sizeof(generic_ethernet_cards[0]); i++)␊ |
134 | {␊ |
135 | if (vendor_id == generic_ethernet_cards[i].vendor_id)␊ |
136 | {␊ |
137 | return generic_ethernet_cards[i].model;␊ |
138 | }␊ |
139 | }␊ |
140 | return generic_ethernet_cards[0].model;␊ |
141 | }␊ |
142 | ␊ |
143 | void setup_eth_builtin(pci_dt_t *eth_dev)␊ |
144 | {␊ |
145 | ␉char *devicepath = get_pci_dev_path(eth_dev);␊ |
146 | char *name_model = NULL;␊ |
147 | ␊ |
148 | ␉DevPropDevice *device = (DevPropDevice*)malloc(sizeof(DevPropDevice));␊ |
149 | ␊ |
150 | ␉verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath);␊ |
151 | ␊ |
152 | ␉if (!string)␊ |
153 | ␉{␊ |
154 | ␉␉string = devprop_create_string();␊ |
155 | ␉␉if (!string)␊ |
156 | ␉␉{␊ |
157 | ␉␉␉return;␊ |
158 | ␉␉}␊ |
159 | ␉}␊ |
160 | ␊ |
161 | ␉device = devprop_add_device(string, devicepath);␊ |
162 | ␉if(device)␊ |
163 | ␉{␊ |
164 | ␉␉verbose("Setting up lan keys\n");␊ |
165 | ␉␉name_model = get_ethernet_model(eth_dev->vendor_id, eth_dev->device_id);␊ |
166 | ␊ |
167 | ␉␉devprop_add_network_template(device, eth_dev->vendor_id);␊ |
168 | ␉␉devprop_add_value(device, "model", (uint8_t*)name_model, (strlen(name_model) + 1));␊ |
169 | ␉␉devprop_add_value(device, "device_type", (uint8_t*)"ethernet", 9);␊ |
170 | ␉␉stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);␊ |
171 | ␉␉if(stringdata)␊ |
172 | ␉␉{␊ |
173 | ␉␉␉memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);␊ |
174 | ␉␉␉stringlength = string->length;␊ |
175 | ␉␉}␊ |
176 | ␉}␊ |
177 | }␊ |
178 | ␊ |
179 | static network_device known_wifi_cards[] =␊ |
180 | {␊ |
181 | ␉{0x14e4, 0x4312, "Broadcom BCM4311 802.11a/b/g"},␊ |
182 | ␉{0x14e4, 0x4315, "Broadcom BCM4312 802.11b/g Wireless LAN Controller"},␊ |
183 | ␉{0x14e4, 0x4319, "Broadcom BCM4318 [AirForce 54g] 802.11a/b/g PCI Express Transceiver"},␊ |
184 | ␉{0x14e4, 0x432b, "Broadcom BCM4322 802.11a/b/g/n Wireless LAN Controller"},␊ |
185 | ␉{0x14e4, 0x432c, "Broadcom BCM4322 802.11b/g/n"},␊ |
186 | ␉{0x14e4, 0x4331, "Broadcom BCM4331 802.11a/b/g/n"},␊ |
187 | ␉{0x14e4, 0x4359, "Broadcom BCM43228 802.11a/b/g/n"},␊ |
188 | ␉{0x168C, 0x0020, "Atheros AR5513 802.11abg Wireless NIC"},␊ |
189 | ␉{0x168C, 0x0023, "Atheros AR5416 Wireless Network Adapter [AR5008 802.11(a)bgn]"},␊ |
190 | ␉{0x168C, 0x0024, "Atheros AR5418 Wireless Network Adapter [AR5008E 802.11(a)bgn]"},␊ |
191 | ␉{0x168C, 0x0027, "Atheros AR9160 Wireless Network Adapter [AR9001 802.11(a)bgn]"},␊ |
192 | ␉{0x168C, 0x0029, "Atheros AR922X Wireless Network Adapter"},␊ |
193 | ␉{0x168C, 0x002A, "Atheros AR928X Wireless Network Adapter"}, // "pci168c,2a"␊ |
194 | ␉{0x168C, 0x002B, "Atheros AR9285 Wireless Network Adapter"},␊ |
195 | };␊ |
196 | ␊ |
197 | void setup_wifi_airport(pci_dt_t *wlan_dev) // ARPT␊ |
198 | {␊ |
199 | ␉char tmp[16];␊ |
200 | ␉uint8_t␉␉BuiltIn = 0x00;␊ |
201 | ␉DevPropDevice *device ;␊ |
202 | ␉char *devicepath = get_pci_dev_path(wlan_dev);␊ |
203 | ␊ |
204 | ␉verbose("Wifi Controller [%04x:%04x]\n", wlan_dev->vendor_id, wlan_dev->device_id);␊ |
205 | ␊ |
206 | ␉if (!string)␊ |
207 | ␉{␊ |
208 | ␉␉string = devprop_create_string();␊ |
209 | ␉␉if (!string)␊ |
210 | ␉␉{␊ |
211 | ␉␉␉return;␊ |
212 | ␉␉}␊ |
213 | ␉}␊ |
214 | ␊ |
215 | ␉device = devprop_add_device(string, devicepath);␊ |
216 | ␉if(device)␊ |
217 | ␉{␊ |
218 | ␉␉//sprintf(tmp, sizeof(tmp),"Airport");␊ |
219 | ␉␉sprintf(tmp, "AirPort");␊ |
220 | ␉␉devprop_add_value(device, "AAPL,slot-name", (uint8_t *) tmp, strlen(tmp) + 1);␊ |
221 | ␉␉devprop_add_value(device, "device_type", (uint8_t *) tmp, strlen(tmp) + 1);␊ |
222 | ␉␉devprop_add_value(device, "built-in", (uint8_t *)&BuiltIn, 1);␊ |
223 | ␊ |
224 | ␉␉int i = 0;␊ |
225 | ␉␉for( ; i < sizeof(known_wifi_cards) / sizeof(known_wifi_cards[0]); i++)␊ |
226 | ␉␉{␊ |
227 | ␉␉␉if(wlan_dev->vendor_id == known_wifi_cards[i].vendor_id && wlan_dev->device_id == known_wifi_cards[i].device_id)␊ |
228 | ␉␉␉{␊ |
229 | ␉␉␉␉verbose("Setting up wifi keys\n");␊ |
230 | ␉␉␉␉devprop_add_value(device, "model", (uint8_t*)known_wifi_cards[i].model, (strlen(known_wifi_cards[i].model) + 1));␊ |
231 | ␉␉␉␉// NOTE: I would set the subsystem id and subsystem vendor id here,␊ |
232 | ␉␉␉␉// however, those values seem to be ovverriden in the boot process.␊ |
233 | ␉␉␉␉// A better method would be injecting the DTGP dsdt method␊ |
234 | ␉␉␉␉// and then injecting the subsystem id there.␊ |
235 | ␊ |
236 | ␉␉␉␉stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);␊ |
237 | ␉␉␉␉if(stringdata)␊ |
238 | ␉␉␉␉{␊ |
239 | ␉␉␉␉␉memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);␊ |
240 | ␉␉␉␉␉stringlength = string->length;␊ |
241 | ␉␉␉␉}␊ |
242 | ␉␉␉␉return;␊ |
243 | ␉␉␉}␊ |
244 | ␉␉}␊ |
245 | ␉}␊ |
246 | }␊ |
247 | |