| [13512] | 1 | /* |
|---|
| 2 | * wireless.c |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2009 Sebastian Gottschall <gottschall@dd-wrt.com> |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or |
|---|
| 7 | * modify it under the terms of the GNU General Public License |
|---|
| 8 | * as published by the Free Software Foundation; either version 2 |
|---|
| 9 | * of the License, or (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | * |
|---|
| 20 | * $Id: |
|---|
| 21 | * |
|---|
| 22 | * detects atheros wireless adapters and loads the drivers |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| [15144] | 25 | // extern int getath9kdevicecount(void); |
|---|
| [16916] | 26 | extern void delete_ath9k_devices(char *physical_iface); |
|---|
| [15143] | 27 | |
|---|
| [17367] | 28 | static void setWirelessLed(int phynum, int ledpin) |
|---|
| [17366] | 29 | { |
|---|
| [17396] | 30 | #ifdef HAVE_MADWIFI_MIMO |
|---|
| 31 | int triggergpio = ledpin; |
|---|
| 32 | #endif |
|---|
| [17366] | 33 | #ifdef HAVE_ATH9K |
|---|
| [17372] | 34 | char trigger[32]; |
|---|
| 35 | char sysname[32]; |
|---|
| 36 | sprintf(trigger, "phy%dtpt", phynum); |
|---|
| 37 | if (ledpin < 32) { |
|---|
| 38 | sprintf(sysname, "generic_%d", ledpin); |
|---|
| 39 | } else { |
|---|
| 40 | #ifdef HAVE_MADWIFI_MIMO |
|---|
| 41 | if (ledpin < 48) |
|---|
| 42 | triggergpio = ledpin - 32; |
|---|
| 43 | else |
|---|
| 44 | triggergpio = ledpin - 48; |
|---|
| 45 | #endif |
|---|
| 46 | sprintf(sysname, "wireless_generic_%d", ledpin - 32); |
|---|
| 47 | } |
|---|
| 48 | sysprintf("echo %s > /sys/devices/platform/leds-gpio/leds/%s/trigger", |
|---|
| 49 | trigger, sysname); |
|---|
| [17396] | 50 | #else |
|---|
| 51 | #ifdef HAVE_MADWIFI_MIMO |
|---|
| 52 | if (ledpin >= 32) { |
|---|
| 53 | if (ledpin < 48) |
|---|
| 54 | triggergpio = ledpin - 32; |
|---|
| 55 | else |
|---|
| 56 | triggergpio = ledpin - 48; |
|---|
| 57 | } |
|---|
| [17372] | 58 | #endif |
|---|
| [17396] | 59 | #endif |
|---|
| [17372] | 60 | #ifdef HAVE_MADWIFI_MIMO |
|---|
| 61 | sysprintf("echo %d >/proc/sys/dev/wifi%d/ledpin", triggergpio, phynum); |
|---|
| 62 | sysprintf("echo 1 >/proc/sys/dev/wifi%d/softled", phynum); |
|---|
| 63 | #endif |
|---|
| [17366] | 64 | } |
|---|
| 65 | |
|---|
| [17367] | 66 | #define setWirelessLedGeneric(a,b) setWirelessLed(a,b) |
|---|
| 67 | #define setWirelessLedPhy0(b) setWirelessLed(0,b+32) |
|---|
| 68 | #define setWirelessLedPhy1(b) setWirelessLed(1,b+48) |
|---|
| [17366] | 69 | |
|---|
| [18257] | 70 | static char *has_device(char *dev) |
|---|
| 71 | { |
|---|
| 72 | char path[64]; |
|---|
| 73 | static char devstr[32]; |
|---|
| 74 | sprintf(path, "/sys/bus/pci/devices/0000:00:%s/device", dev); |
|---|
| 75 | FILE *fp = fopen(path, "rb"); |
|---|
| 76 | if (fp) { |
|---|
| 77 | fscanf(fp, "%s", devstr); |
|---|
| 78 | fclose(fp); |
|---|
| 79 | return devstr; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | return ""; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | #define AR5416_DEVID_PCI 0x0023 |
|---|
| 86 | #define AR5416_DEVID_PCIE 0x0024 |
|---|
| 87 | #define AR9160_DEVID_PCI 0x0027 |
|---|
| 88 | #define AR9280_DEVID_PCI 0x0029 |
|---|
| 89 | #define AR9280_DEVID_PCIE 0x002a |
|---|
| 90 | #define AR9285_DEVID_PCIE 0x002b |
|---|
| 91 | #define AR2427_DEVID_PCIE 0x002c |
|---|
| 92 | #define AR9287_DEVID_PCI 0x002d |
|---|
| 93 | #define AR9287_DEVID_PCIE 0x002e |
|---|
| 94 | #define AR9300_DEVID_PCIE 0x0030 |
|---|
| 95 | #define AR9300_DEVID_AR9340 0x0031 |
|---|
| 96 | #define AR9300_DEVID_AR9485_PCIE 0x0032 |
|---|
| 97 | #define AR9300_DEVID_AR9580 0x0033 |
|---|
| 98 | #define AR9300_DEVID_AR9462 0x0034 |
|---|
| 99 | #define AR9300_DEVID_AR9330 0x0035 |
|---|
| 100 | |
|---|
| 101 | #define AR5416_AR9100_DEVID 0x000b |
|---|
| 102 | |
|---|
| [13512] | 103 | static void detect_wireless_devices(void) |
|---|
| 104 | { |
|---|
| [18257] | 105 | int loadath9k = 1; |
|---|
| 106 | int loadlegacy = 1; |
|---|
| [16653] | 107 | #ifdef HAVE_RT61 |
|---|
| [18257] | 108 | if (!strcmp(has_device("0e.00"), "0x3592")) |
|---|
| 109 | nvram_set("rtchip", "3062"); |
|---|
| 110 | else |
|---|
| [16653] | 111 | nvram_set("rtchip", "2860"); |
|---|
| 112 | #endif |
|---|
| [18257] | 113 | #ifdef HAVE_XSCALE |
|---|
| 114 | loadath9k = 0; |
|---|
| 115 | loadlegacy = 0; |
|---|
| 116 | char path[32]; |
|---|
| 117 | int i = 0; |
|---|
| 118 | for (i = 0; i < 5; i++) { |
|---|
| 119 | sprintf(path, "0%d.00", i); |
|---|
| 120 | if (!strcmp(has_device(path), "0x0023")) |
|---|
| 121 | loadath9k = 1; |
|---|
| 122 | if (!strcmp(has_device(path), "0x0024")) |
|---|
| 123 | loadath9k = 1; |
|---|
| 124 | if (!strcmp(has_device(path), "0x0027")) |
|---|
| 125 | loadath9k = 1; |
|---|
| 126 | if (!strcmp(has_device(path), "0x0029")) |
|---|
| 127 | loadath9k = 1; |
|---|
| 128 | if (!strcmp(has_device(path), "0x002a")) |
|---|
| 129 | loadath9k = 1; |
|---|
| 130 | if (!strcmp(has_device(path), "0x002b")) |
|---|
| 131 | loadath9k = 1; |
|---|
| 132 | if (!strcmp(has_device(path), "0x002c")) |
|---|
| 133 | loadath9k = 1; |
|---|
| 134 | if (!strcmp(has_device(path), "0x002d")) |
|---|
| 135 | loadath9k = 1; |
|---|
| 136 | if (!strcmp(has_device(path), "0x002e")) |
|---|
| 137 | loadath9k = 1; |
|---|
| 138 | if (!strcmp(has_device(path), "0x0030")) |
|---|
| 139 | loadath9k = 1; |
|---|
| 140 | if (!strcmp(has_device(path), "0x0031")) |
|---|
| 141 | loadath9k = 1; |
|---|
| 142 | if (!strcmp(has_device(path), "0x0032")) |
|---|
| 143 | loadath9k = 1; |
|---|
| 144 | if (!strcmp(has_device(path), "0x0034")) |
|---|
| 145 | loadath9k = 1; |
|---|
| 146 | if (!strcmp(has_device(path), "0x0035")) |
|---|
| 147 | loadath9k = 1; |
|---|
| 148 | if (!strcmp(has_device(path), "0x000b")) |
|---|
| 149 | loadath9k = 1; |
|---|
| 150 | if (!strcmp(has_device(path), "0x001b")) |
|---|
| 151 | loadlegacy = 1; |
|---|
| 152 | if (!strcmp(has_device(path), "0x0013")) |
|---|
| 153 | loadlegacy = 1; |
|---|
| 154 | if (!strcmp(has_device(path), "0x0207")) |
|---|
| 155 | loadlegacy = 1; |
|---|
| 156 | if (!strcmp(has_device(path), "0x0007")) |
|---|
| 157 | loadlegacy = 1; |
|---|
| 158 | if (!strcmp(has_device(path), "0xff16")) |
|---|
| 159 | loadlegacy = 1; |
|---|
| 160 | if (!strcmp(has_device(path), "0x0012")) |
|---|
| 161 | loadlegacy = 1; |
|---|
| 162 | if (!strcmp(has_device(path), "0x1014")) |
|---|
| 163 | loadlegacy = 1; |
|---|
| 164 | if (!strcmp(has_device(path), "0x101a")) |
|---|
| 165 | loadlegacy = 1; |
|---|
| 166 | if (!strcmp(has_device(path), "0x0015")) |
|---|
| 167 | loadlegacy = 1; |
|---|
| 168 | if (!strcmp(has_device(path), "0x0016")) |
|---|
| 169 | loadlegacy = 1; |
|---|
| 170 | if (!strcmp(has_device(path), "0x0017")) |
|---|
| 171 | loadlegacy = 1; |
|---|
| 172 | if (!strcmp(has_device(path), "0x0018")) |
|---|
| 173 | loadlegacy = 1; |
|---|
| 174 | if (!strcmp(has_device(path), "0x0019")) |
|---|
| 175 | loadlegacy = 1; |
|---|
| 176 | if (!strcmp(has_device(path), "0x001a")) |
|---|
| 177 | loadlegacy = 1; |
|---|
| 178 | if (!strcmp(has_device(path), "0x001b")) |
|---|
| 179 | loadlegacy = 1; |
|---|
| 180 | if (!strcmp(has_device(path), "0x018a")) |
|---|
| 181 | loadlegacy = 1; |
|---|
| 182 | if (!strcmp(has_device(path), "0x001c")) |
|---|
| 183 | loadlegacy = 1; |
|---|
| 184 | if (!strcmp(has_device(path), "0x001d")) |
|---|
| 185 | loadlegacy = 1; |
|---|
| 186 | if (!strcmp(has_device(path), "0x9013")) |
|---|
| 187 | loadlegacy = 1; |
|---|
| 188 | if (!strcmp(has_device(path), "0xff1a")) |
|---|
| 189 | loadlegacy = 1; |
|---|
| 190 | } |
|---|
| 191 | #endif |
|---|
| [13512] | 192 | #ifndef HAVE_NOWIFI |
|---|
| [16653] | 193 | nvram_default_get("rate_control", "minstrel"); |
|---|
| [13512] | 194 | #ifdef HAVE_MADWIFI |
|---|
| [18257] | 195 | if (loadlegacy) { |
|---|
| 196 | fprintf(stderr, "load ATH 802.11 a/b/g Driver\n"); |
|---|
| 197 | insmod("ath_hal"); |
|---|
| 198 | if (nvram_get("rate_control") != NULL) { |
|---|
| 199 | char rate[64]; |
|---|
| [13512] | 200 | |
|---|
| [18257] | 201 | sprintf(rate, "ratectl=%s", |
|---|
| 202 | nvram_safe_get("rate_control")); |
|---|
| 203 | eval("insmod", "ath_pci", rate); |
|---|
| 204 | eval("insmod", "ath_ahb", rate); |
|---|
| 205 | } else { |
|---|
| 206 | insmod("ath_pci"); |
|---|
| 207 | insmod("ath_ahb"); |
|---|
| 208 | } |
|---|
| [13512] | 209 | } |
|---|
| [15073] | 210 | #ifdef HAVE_ATH9K |
|---|
| [15379] | 211 | #ifndef HAVE_MADWIFI_MIMO |
|---|
| 212 | if (1) |
|---|
| 213 | #else |
|---|
| [15073] | 214 | if (nvram_match("mimo_driver", "ath9k")) |
|---|
| [15379] | 215 | #endif |
|---|
| [16653] | 216 | { |
|---|
| [18257] | 217 | if (loadath9k) { |
|---|
| 218 | fprintf(stderr, "load ATH9K 802.11n Driver\n"); |
|---|
| 219 | // some are just for future use and not (yet) there |
|---|
| 220 | insmod("/lib/ath9k/compat.ko"); |
|---|
| 221 | insmod("/lib/ath9k/compat_firmware_class.ko"); |
|---|
| 222 | insmod("/lib/ath9k/cfg80211.ko"); |
|---|
| 223 | insmod("/lib/ath9k/mac80211.ko"); |
|---|
| 224 | insmod("/lib/ath9k/ath.ko"); |
|---|
| 225 | insmod("/lib/ath9k/ath9k_hw.ko"); |
|---|
| 226 | insmod("/lib/ath9k/ath9k_common.ko"); |
|---|
| [15787] | 227 | #ifdef HAVE_WZRG450 |
|---|
| [18257] | 228 | system("/sbin/insmod /lib/ath9k/ath9k.ko blink=1"); |
|---|
| [15787] | 229 | #else |
|---|
| [18257] | 230 | insmod("/lib/ath9k/ath9k.ko"); |
|---|
| [15787] | 231 | #endif |
|---|
| [18257] | 232 | delete_ath9k_devices(NULL); |
|---|
| 233 | } |
|---|
| [16653] | 234 | } else { |
|---|
| [15073] | 235 | #endif |
|---|
| [13512] | 236 | #ifdef HAVE_MADWIFI_MIMO |
|---|
| [18257] | 237 | if (loadath9k) { |
|---|
| 238 | fprintf(stderr, "load ATH 802.11n Driver\n"); |
|---|
| 239 | insmod("/lib/80211n/ath_mimo_hal.ko"); |
|---|
| 240 | if (nvram_get("rate_control") != NULL) { |
|---|
| 241 | char rate[64]; |
|---|
| [13512] | 242 | |
|---|
| [18257] | 243 | sprintf(rate, "ratectl=%s", |
|---|
| 244 | nvram_safe_get("rate_control")); |
|---|
| 245 | insmod("/lib/80211n/ath_mimo_pci.ko"); |
|---|
| 246 | insmod("/lib/80211n/ath_mimo_ahb.ko"); |
|---|
| 247 | } else { |
|---|
| 248 | insmod("/lib/80211n/ath_mimo_pci.ko"); |
|---|
| 249 | insmod("/lib/80211n/ath_mimo_ahb.ko"); |
|---|
| 250 | } |
|---|
| [16653] | 251 | } |
|---|
| [13512] | 252 | #endif |
|---|
| [15073] | 253 | #ifdef HAVE_ATH9K |
|---|
| [16653] | 254 | } |
|---|
| [13512] | 255 | #endif |
|---|
| 256 | #endif |
|---|
| [15073] | 257 | #endif |
|---|
| [13512] | 258 | } |
|---|