18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright(c) 2007 Atheros Corporation. All rights reserved. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Derived from Intel e1000 driver 68c2ecf20Sopenharmony_ci * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved. 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include "atl1e.h" 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci/* This is the only thing that needs to be changed to adjust the 148c2ecf20Sopenharmony_ci * maximum number of ports that the driver can manage. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define ATL1E_MAX_NIC 32 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define OPTION_UNSET -1 208c2ecf20Sopenharmony_ci#define OPTION_DISABLED 0 218c2ecf20Sopenharmony_ci#define OPTION_ENABLED 1 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci/* All parameters are treated the same, as an integer array of values. 248c2ecf20Sopenharmony_ci * This macro just reduces the need to repeat the same declaration code 258c2ecf20Sopenharmony_ci * over and over (plus this helps to avoid typo bugs). 268c2ecf20Sopenharmony_ci */ 278c2ecf20Sopenharmony_ci#define ATL1E_PARAM_INIT { [0 ... ATL1E_MAX_NIC] = OPTION_UNSET } 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define ATL1E_PARAM(x, desc) \ 308c2ecf20Sopenharmony_ci static int x[ATL1E_MAX_NIC + 1] = ATL1E_PARAM_INIT; \ 318c2ecf20Sopenharmony_ci static unsigned int num_##x; \ 328c2ecf20Sopenharmony_ci module_param_array_named(x, x, int, &num_##x, 0); \ 338c2ecf20Sopenharmony_ci MODULE_PARM_DESC(x, desc); 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* Transmit Memory count 368c2ecf20Sopenharmony_ci * 378c2ecf20Sopenharmony_ci * Valid Range: 64-2048 388c2ecf20Sopenharmony_ci * 398c2ecf20Sopenharmony_ci * Default Value: 128 408c2ecf20Sopenharmony_ci */ 418c2ecf20Sopenharmony_ci#define ATL1E_MIN_TX_DESC_CNT 32 428c2ecf20Sopenharmony_ci#define ATL1E_MAX_TX_DESC_CNT 1020 438c2ecf20Sopenharmony_ci#define ATL1E_DEFAULT_TX_DESC_CNT 128 448c2ecf20Sopenharmony_ciATL1E_PARAM(tx_desc_cnt, "Transmit description count"); 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci/* Receive Memory Block Count 478c2ecf20Sopenharmony_ci * 488c2ecf20Sopenharmony_ci * Valid Range: 16-512 498c2ecf20Sopenharmony_ci * 508c2ecf20Sopenharmony_ci * Default Value: 128 518c2ecf20Sopenharmony_ci */ 528c2ecf20Sopenharmony_ci#define ATL1E_MIN_RX_MEM_SIZE 8 /* 8KB */ 538c2ecf20Sopenharmony_ci#define ATL1E_MAX_RX_MEM_SIZE 1024 /* 1MB */ 548c2ecf20Sopenharmony_ci#define ATL1E_DEFAULT_RX_MEM_SIZE 256 /* 128KB */ 558c2ecf20Sopenharmony_ciATL1E_PARAM(rx_mem_size, "memory size of rx buffer(KB)"); 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci/* User Specified MediaType Override 588c2ecf20Sopenharmony_ci * 598c2ecf20Sopenharmony_ci * Valid Range: 0-5 608c2ecf20Sopenharmony_ci * - 0 - auto-negotiate at all supported speeds 618c2ecf20Sopenharmony_ci * - 1 - only link at 100Mbps Full Duplex 628c2ecf20Sopenharmony_ci * - 2 - only link at 100Mbps Half Duplex 638c2ecf20Sopenharmony_ci * - 3 - only link at 10Mbps Full Duplex 648c2ecf20Sopenharmony_ci * - 4 - only link at 10Mbps Half Duplex 658c2ecf20Sopenharmony_ci * Default Value: 0 668c2ecf20Sopenharmony_ci */ 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ciATL1E_PARAM(media_type, "MediaType Select"); 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* Interrupt Moderate Timer in units of 2 us 718c2ecf20Sopenharmony_ci * 728c2ecf20Sopenharmony_ci * Valid Range: 10-65535 738c2ecf20Sopenharmony_ci * 748c2ecf20Sopenharmony_ci * Default Value: 45000(90ms) 758c2ecf20Sopenharmony_ci */ 768c2ecf20Sopenharmony_ci#define INT_MOD_DEFAULT_CNT 100 /* 200us */ 778c2ecf20Sopenharmony_ci#define INT_MOD_MAX_CNT 65000 788c2ecf20Sopenharmony_ci#define INT_MOD_MIN_CNT 50 798c2ecf20Sopenharmony_ciATL1E_PARAM(int_mod_timer, "Interrupt Moderator Timer"); 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci#define AUTONEG_ADV_DEFAULT 0x2F 828c2ecf20Sopenharmony_ci#define AUTONEG_ADV_MASK 0x2F 838c2ecf20Sopenharmony_ci#define FLOW_CONTROL_DEFAULT FLOW_CONTROL_FULL 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#define FLASH_VENDOR_DEFAULT 0 868c2ecf20Sopenharmony_ci#define FLASH_VENDOR_MIN 0 878c2ecf20Sopenharmony_ci#define FLASH_VENDOR_MAX 2 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_cistruct atl1e_option { 908c2ecf20Sopenharmony_ci enum { enable_option, range_option, list_option } type; 918c2ecf20Sopenharmony_ci char *name; 928c2ecf20Sopenharmony_ci char *err; 938c2ecf20Sopenharmony_ci int def; 948c2ecf20Sopenharmony_ci union { 958c2ecf20Sopenharmony_ci struct { /* range_option info */ 968c2ecf20Sopenharmony_ci int min; 978c2ecf20Sopenharmony_ci int max; 988c2ecf20Sopenharmony_ci } r; 998c2ecf20Sopenharmony_ci struct { /* list_option info */ 1008c2ecf20Sopenharmony_ci int nr; 1018c2ecf20Sopenharmony_ci struct atl1e_opt_list { int i; char *str; } *p; 1028c2ecf20Sopenharmony_ci } l; 1038c2ecf20Sopenharmony_ci } arg; 1048c2ecf20Sopenharmony_ci}; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_cistatic int atl1e_validate_option(int *value, struct atl1e_option *opt, 1078c2ecf20Sopenharmony_ci struct atl1e_adapter *adapter) 1088c2ecf20Sopenharmony_ci{ 1098c2ecf20Sopenharmony_ci if (*value == OPTION_UNSET) { 1108c2ecf20Sopenharmony_ci *value = opt->def; 1118c2ecf20Sopenharmony_ci return 0; 1128c2ecf20Sopenharmony_ci } 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci switch (opt->type) { 1158c2ecf20Sopenharmony_ci case enable_option: 1168c2ecf20Sopenharmony_ci switch (*value) { 1178c2ecf20Sopenharmony_ci case OPTION_ENABLED: 1188c2ecf20Sopenharmony_ci netdev_info(adapter->netdev, 1198c2ecf20Sopenharmony_ci "%s Enabled\n", opt->name); 1208c2ecf20Sopenharmony_ci return 0; 1218c2ecf20Sopenharmony_ci case OPTION_DISABLED: 1228c2ecf20Sopenharmony_ci netdev_info(adapter->netdev, 1238c2ecf20Sopenharmony_ci "%s Disabled\n", opt->name); 1248c2ecf20Sopenharmony_ci return 0; 1258c2ecf20Sopenharmony_ci } 1268c2ecf20Sopenharmony_ci break; 1278c2ecf20Sopenharmony_ci case range_option: 1288c2ecf20Sopenharmony_ci if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) { 1298c2ecf20Sopenharmony_ci netdev_info(adapter->netdev, "%s set to %i\n", 1308c2ecf20Sopenharmony_ci opt->name, *value); 1318c2ecf20Sopenharmony_ci return 0; 1328c2ecf20Sopenharmony_ci } 1338c2ecf20Sopenharmony_ci break; 1348c2ecf20Sopenharmony_ci case list_option:{ 1358c2ecf20Sopenharmony_ci int i; 1368c2ecf20Sopenharmony_ci struct atl1e_opt_list *ent; 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci for (i = 0; i < opt->arg.l.nr; i++) { 1398c2ecf20Sopenharmony_ci ent = &opt->arg.l.p[i]; 1408c2ecf20Sopenharmony_ci if (*value == ent->i) { 1418c2ecf20Sopenharmony_ci if (ent->str[0] != '\0') 1428c2ecf20Sopenharmony_ci netdev_info(adapter->netdev, 1438c2ecf20Sopenharmony_ci "%s\n", ent->str); 1448c2ecf20Sopenharmony_ci return 0; 1458c2ecf20Sopenharmony_ci } 1468c2ecf20Sopenharmony_ci } 1478c2ecf20Sopenharmony_ci break; 1488c2ecf20Sopenharmony_ci } 1498c2ecf20Sopenharmony_ci default: 1508c2ecf20Sopenharmony_ci BUG(); 1518c2ecf20Sopenharmony_ci } 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci netdev_info(adapter->netdev, "Invalid %s specified (%i) %s\n", 1548c2ecf20Sopenharmony_ci opt->name, *value, opt->err); 1558c2ecf20Sopenharmony_ci *value = opt->def; 1568c2ecf20Sopenharmony_ci return -1; 1578c2ecf20Sopenharmony_ci} 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci/** 1608c2ecf20Sopenharmony_ci * atl1e_check_options - Range Checking for Command Line Parameters 1618c2ecf20Sopenharmony_ci * @adapter: board private structure 1628c2ecf20Sopenharmony_ci * 1638c2ecf20Sopenharmony_ci * This routine checks all command line parameters for valid user 1648c2ecf20Sopenharmony_ci * input. If an invalid value is given, or if no user specified 1658c2ecf20Sopenharmony_ci * value exists, a default value is used. The final value is stored 1668c2ecf20Sopenharmony_ci * in a variable in the adapter structure. 1678c2ecf20Sopenharmony_ci */ 1688c2ecf20Sopenharmony_civoid atl1e_check_options(struct atl1e_adapter *adapter) 1698c2ecf20Sopenharmony_ci{ 1708c2ecf20Sopenharmony_ci int bd = adapter->bd_number; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci if (bd >= ATL1E_MAX_NIC) { 1738c2ecf20Sopenharmony_ci netdev_notice(adapter->netdev, 1748c2ecf20Sopenharmony_ci "no configuration for board #%i\n", bd); 1758c2ecf20Sopenharmony_ci netdev_notice(adapter->netdev, 1768c2ecf20Sopenharmony_ci "Using defaults for all values\n"); 1778c2ecf20Sopenharmony_ci } 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci { /* Transmit Ring Size */ 1808c2ecf20Sopenharmony_ci struct atl1e_option opt = { 1818c2ecf20Sopenharmony_ci .type = range_option, 1828c2ecf20Sopenharmony_ci .name = "Transmit Ddescription Count", 1838c2ecf20Sopenharmony_ci .err = "using default of " 1848c2ecf20Sopenharmony_ci __MODULE_STRING(ATL1E_DEFAULT_TX_DESC_CNT), 1858c2ecf20Sopenharmony_ci .def = ATL1E_DEFAULT_TX_DESC_CNT, 1868c2ecf20Sopenharmony_ci .arg = { .r = { .min = ATL1E_MIN_TX_DESC_CNT, 1878c2ecf20Sopenharmony_ci .max = ATL1E_MAX_TX_DESC_CNT} } 1888c2ecf20Sopenharmony_ci }; 1898c2ecf20Sopenharmony_ci int val; 1908c2ecf20Sopenharmony_ci if (num_tx_desc_cnt > bd) { 1918c2ecf20Sopenharmony_ci val = tx_desc_cnt[bd]; 1928c2ecf20Sopenharmony_ci atl1e_validate_option(&val, &opt, adapter); 1938c2ecf20Sopenharmony_ci adapter->tx_ring.count = (u16) val & 0xFFFC; 1948c2ecf20Sopenharmony_ci } else 1958c2ecf20Sopenharmony_ci adapter->tx_ring.count = (u16)opt.def; 1968c2ecf20Sopenharmony_ci } 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci { /* Receive Memory Block Count */ 1998c2ecf20Sopenharmony_ci struct atl1e_option opt = { 2008c2ecf20Sopenharmony_ci .type = range_option, 2018c2ecf20Sopenharmony_ci .name = "Memory size of rx buffer(KB)", 2028c2ecf20Sopenharmony_ci .err = "using default of " 2038c2ecf20Sopenharmony_ci __MODULE_STRING(ATL1E_DEFAULT_RX_MEM_SIZE), 2048c2ecf20Sopenharmony_ci .def = ATL1E_DEFAULT_RX_MEM_SIZE, 2058c2ecf20Sopenharmony_ci .arg = { .r = { .min = ATL1E_MIN_RX_MEM_SIZE, 2068c2ecf20Sopenharmony_ci .max = ATL1E_MAX_RX_MEM_SIZE} } 2078c2ecf20Sopenharmony_ci }; 2088c2ecf20Sopenharmony_ci int val; 2098c2ecf20Sopenharmony_ci if (num_rx_mem_size > bd) { 2108c2ecf20Sopenharmony_ci val = rx_mem_size[bd]; 2118c2ecf20Sopenharmony_ci atl1e_validate_option(&val, &opt, adapter); 2128c2ecf20Sopenharmony_ci adapter->rx_ring.page_size = (u32)val * 1024; 2138c2ecf20Sopenharmony_ci } else { 2148c2ecf20Sopenharmony_ci adapter->rx_ring.page_size = (u32)opt.def * 1024; 2158c2ecf20Sopenharmony_ci } 2168c2ecf20Sopenharmony_ci } 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci { /* Interrupt Moderate Timer */ 2198c2ecf20Sopenharmony_ci struct atl1e_option opt = { 2208c2ecf20Sopenharmony_ci .type = range_option, 2218c2ecf20Sopenharmony_ci .name = "Interrupt Moderate Timer", 2228c2ecf20Sopenharmony_ci .err = "using default of " 2238c2ecf20Sopenharmony_ci __MODULE_STRING(INT_MOD_DEFAULT_CNT), 2248c2ecf20Sopenharmony_ci .def = INT_MOD_DEFAULT_CNT, 2258c2ecf20Sopenharmony_ci .arg = { .r = { .min = INT_MOD_MIN_CNT, 2268c2ecf20Sopenharmony_ci .max = INT_MOD_MAX_CNT} } 2278c2ecf20Sopenharmony_ci } ; 2288c2ecf20Sopenharmony_ci int val; 2298c2ecf20Sopenharmony_ci if (num_int_mod_timer > bd) { 2308c2ecf20Sopenharmony_ci val = int_mod_timer[bd]; 2318c2ecf20Sopenharmony_ci atl1e_validate_option(&val, &opt, adapter); 2328c2ecf20Sopenharmony_ci adapter->hw.imt = (u16) val; 2338c2ecf20Sopenharmony_ci } else 2348c2ecf20Sopenharmony_ci adapter->hw.imt = (u16)(opt.def); 2358c2ecf20Sopenharmony_ci } 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci { /* MediaType */ 2388c2ecf20Sopenharmony_ci struct atl1e_option opt = { 2398c2ecf20Sopenharmony_ci .type = range_option, 2408c2ecf20Sopenharmony_ci .name = "Speed/Duplex Selection", 2418c2ecf20Sopenharmony_ci .err = "using default of " 2428c2ecf20Sopenharmony_ci __MODULE_STRING(MEDIA_TYPE_AUTO_SENSOR), 2438c2ecf20Sopenharmony_ci .def = MEDIA_TYPE_AUTO_SENSOR, 2448c2ecf20Sopenharmony_ci .arg = { .r = { .min = MEDIA_TYPE_AUTO_SENSOR, 2458c2ecf20Sopenharmony_ci .max = MEDIA_TYPE_10M_HALF} } 2468c2ecf20Sopenharmony_ci } ; 2478c2ecf20Sopenharmony_ci int val; 2488c2ecf20Sopenharmony_ci if (num_media_type > bd) { 2498c2ecf20Sopenharmony_ci val = media_type[bd]; 2508c2ecf20Sopenharmony_ci atl1e_validate_option(&val, &opt, adapter); 2518c2ecf20Sopenharmony_ci adapter->hw.media_type = (u16) val; 2528c2ecf20Sopenharmony_ci } else 2538c2ecf20Sopenharmony_ci adapter->hw.media_type = (u16)(opt.def); 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci } 2568c2ecf20Sopenharmony_ci} 257