Changeset 18257


Ignore:
Timestamp:
01/21/12 18:09:05 (16 months ago)
Author:
BrainSlayer
Message:

save memory if these devices arent used. so just do not load the drivers if they arent needed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/router/services/sysinit/devices/wireless.c

    r17396 r18257  
    6868#define setWirelessLedPhy1(b) setWirelessLed(1,b+48) 
    6969 
     70static 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 
    70103static void detect_wireless_devices(void) 
    71104{ 
     105        int loadath9k = 1; 
     106        int loadlegacy = 1; 
    72107#ifdef HAVE_RT61 
    73         FILE *fp = fopen("/sys/bus/pci/devices/0000:00:0e.0/device", "rb"); 
    74         if (fp) { 
    75                 char str[32]; 
    76                 fscanf(fp, "%s", str); 
    77                 fclose(fp); 
    78                 if (!strcmp(str, "0x3592")) 
    79                         nvram_set("rtchip", "3062"); 
    80                 else 
    81                         nvram_set("rtchip", "2860"); 
    82         } else 
     108        if (!strcmp(has_device("0e.00"), "0x3592")) 
     109                nvram_set("rtchip", "3062"); 
     110        else 
    83111                nvram_set("rtchip", "2860"); 
    84  
     112#endif 
     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        } 
    85191#endif 
    86192#ifndef HAVE_NOWIFI 
    87193        nvram_default_get("rate_control", "minstrel"); 
    88194#ifdef HAVE_MADWIFI 
    89         fprintf(stderr, "load ATH 802.11 a/b/g Driver\n"); 
    90         insmod("ath_hal"); 
    91         if (nvram_get("rate_control") != NULL) { 
    92                 char rate[64]; 
    93  
    94                 sprintf(rate, "ratectl=%s", nvram_safe_get("rate_control")); 
    95                 eval("insmod", "ath_pci", rate); 
    96                 eval("insmod", "ath_ahb", rate); 
    97         } else { 
    98                 insmod("ath_pci"); 
    99                 insmod("ath_ahb"); 
     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]; 
     200 
     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                } 
    100209        } 
    101210#ifdef HAVE_ATH9K 
     
    106215#endif 
    107216        { 
    108                 fprintf(stderr, "load ATH9K 802.11n Driver\n"); 
    109                 // some are just for future use and not (yet) there 
    110                 insmod("/lib/ath9k/compat.ko"); 
    111                 insmod("/lib/ath9k/compat_firmware_class.ko"); 
    112                 insmod("/lib/ath9k/cfg80211.ko"); 
    113                 insmod("/lib/ath9k/mac80211.ko"); 
    114                 insmod("/lib/ath9k/ath.ko"); 
    115                 insmod("/lib/ath9k/ath9k_hw.ko"); 
    116                 insmod("/lib/ath9k/ath9k_common.ko"); 
     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"); 
    117227#ifdef HAVE_WZRG450 
    118                 system("/sbin/insmod /lib/ath9k/ath9k.ko blink=1"); 
     228                        system("/sbin/insmod /lib/ath9k/ath9k.ko blink=1"); 
    119229#else 
    120                 insmod("/lib/ath9k/ath9k.ko"); 
    121 #endif 
    122                 delete_ath9k_devices(NULL); 
     230                        insmod("/lib/ath9k/ath9k.ko"); 
     231#endif 
     232                        delete_ath9k_devices(NULL); 
     233                } 
    123234        } else { 
    124235#endif 
    125236#ifdef HAVE_MADWIFI_MIMO 
    126                 fprintf(stderr, "load ATH 802.11n Driver\n"); 
    127                 insmod("/lib/80211n/ath_mimo_hal.ko"); 
    128                 if (nvram_get("rate_control") != NULL) { 
    129                         char rate[64]; 
    130  
    131                         sprintf(rate, "ratectl=%s", 
    132                                 nvram_safe_get("rate_control")); 
    133                         insmod("/lib/80211n/ath_mimo_pci.ko"); 
    134                         insmod("/lib/80211n/ath_mimo_ahb.ko"); 
    135                 } else { 
    136                         insmod("/lib/80211n/ath_mimo_pci.ko"); 
    137                         insmod("/lib/80211n/ath_mimo_ahb.ko"); 
     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]; 
     242 
     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                        } 
    138251                } 
    139252#endif 
Note: See TracChangeset for help on using the changeset viewer.