| Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright(c) 2005 - 2006 Attansic Corporation. All rights reserved. | 
|  | 3 | * Copyright(c) 2006 Chris Snook <csnook@redhat.com> | 
|  | 4 | * Copyright(c) 2006 Jay Cliburn <jcliburn@gmail.com> | 
|  | 5 | * | 
|  | 6 | * Derived from Intel e1000 driver | 
|  | 7 | * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved. | 
|  | 8 | * | 
|  | 9 | * This program is free software; you can redistribute it and/or modify it | 
|  | 10 | * under the terms of the GNU General Public License as published by the Free | 
|  | 11 | * Software Foundation; either version 2 of the License, or (at your option) | 
|  | 12 | * any later version. | 
|  | 13 | * | 
|  | 14 | * This program is distributed in the hope that it will be useful, but WITHOUT | 
|  | 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 
|  | 16 | * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for | 
|  | 17 | * more details. | 
|  | 18 | * | 
|  | 19 | * You should have received a copy of the GNU General Public License along with | 
|  | 20 | * this program; if not, write to the Free Software Foundation, Inc., 59 | 
|  | 21 | * Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
|  | 22 | */ | 
|  | 23 |  | 
|  | 24 | #include <linux/types.h> | 
| Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 25 | #include <linux/moduleparam.h> | 
| Jeff Garzik | e824f78 | 2007-05-08 02:32:17 -0400 | [diff] [blame] | 26 | #include <linux/pci.h> | 
| Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 27 | #include "atl1.h" | 
|  | 28 |  | 
|  | 29 | /* | 
|  | 30 | * This is the only thing that needs to be changed to adjust the | 
|  | 31 | * maximum number of ports that the driver can manage. | 
|  | 32 | */ | 
|  | 33 | #define ATL1_MAX_NIC 4 | 
|  | 34 |  | 
|  | 35 | #define OPTION_UNSET    -1 | 
|  | 36 | #define OPTION_DISABLED 0 | 
|  | 37 | #define OPTION_ENABLED  1 | 
|  | 38 |  | 
|  | 39 | #define ATL1_PARAM_INIT { [0 ... ATL1_MAX_NIC] = OPTION_UNSET } | 
|  | 40 |  | 
|  | 41 | /* | 
|  | 42 | * Interrupt Moderate Timer in units of 2 us | 
|  | 43 | * | 
|  | 44 | * Valid Range: 10-65535 | 
|  | 45 | * | 
|  | 46 | * Default Value: 100 (200us) | 
|  | 47 | */ | 
|  | 48 | static int __devinitdata int_mod_timer[ATL1_MAX_NIC+1] = ATL1_PARAM_INIT; | 
|  | 49 | static int num_int_mod_timer = 0; | 
|  | 50 | module_param_array_named(int_mod_timer, int_mod_timer, int, &num_int_mod_timer, 0); | 
|  | 51 | MODULE_PARM_DESC(int_mod_timer, "Interrupt moderator timer"); | 
|  | 52 |  | 
|  | 53 | /* | 
|  | 54 | * flash_vendor | 
|  | 55 | * | 
|  | 56 | * Valid Range: 0-2 | 
|  | 57 | * | 
|  | 58 | * 0 - Atmel | 
|  | 59 | * 1 - SST | 
|  | 60 | * 2 - ST | 
|  | 61 | * | 
|  | 62 | * Default Value: 0 | 
|  | 63 | */ | 
|  | 64 | static int __devinitdata flash_vendor[ATL1_MAX_NIC+1] = ATL1_PARAM_INIT; | 
|  | 65 | static int num_flash_vendor = 0; | 
|  | 66 | module_param_array_named(flash_vendor, flash_vendor, int, &num_flash_vendor, 0); | 
|  | 67 | MODULE_PARM_DESC(flash_vendor, "SPI flash vendor"); | 
|  | 68 |  | 
|  | 69 | #define DEFAULT_INT_MOD_CNT	100	/* 200us */ | 
|  | 70 | #define MAX_INT_MOD_CNT		65000 | 
|  | 71 | #define MIN_INT_MOD_CNT		50 | 
|  | 72 |  | 
|  | 73 | #define FLASH_VENDOR_DEFAULT	0 | 
|  | 74 | #define FLASH_VENDOR_MIN	0 | 
|  | 75 | #define FLASH_VENDOR_MAX	2 | 
|  | 76 |  | 
|  | 77 | struct atl1_option { | 
|  | 78 | enum { enable_option, range_option, list_option } type; | 
|  | 79 | char *name; | 
|  | 80 | char *err; | 
|  | 81 | int def; | 
|  | 82 | union { | 
|  | 83 | struct {	/* range_option info */ | 
|  | 84 | int min; | 
|  | 85 | int max; | 
|  | 86 | } r; | 
|  | 87 | struct {	/* list_option info */ | 
|  | 88 | int nr; | 
|  | 89 | struct atl1_opt_list { | 
|  | 90 | int i; | 
|  | 91 | char *str; | 
|  | 92 | } *p; | 
|  | 93 | } l; | 
|  | 94 | } arg; | 
|  | 95 | }; | 
|  | 96 |  | 
| Jay Cliburn | 1e00636 | 2007-04-29 21:42:10 -0500 | [diff] [blame] | 97 | static int __devinit atl1_validate_option(int *value, struct atl1_option *opt, struct pci_dev *pdev) | 
| Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 98 | { | 
|  | 99 | if (*value == OPTION_UNSET) { | 
|  | 100 | *value = opt->def; | 
|  | 101 | return 0; | 
|  | 102 | } | 
|  | 103 |  | 
|  | 104 | switch (opt->type) { | 
|  | 105 | case enable_option: | 
|  | 106 | switch (*value) { | 
|  | 107 | case OPTION_ENABLED: | 
| Jay Cliburn | 1e00636 | 2007-04-29 21:42:10 -0500 | [diff] [blame] | 108 | dev_info(&pdev->dev, "%s enabled\n", opt->name); | 
| Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 109 | return 0; | 
|  | 110 | case OPTION_DISABLED: | 
| Jay Cliburn | 1e00636 | 2007-04-29 21:42:10 -0500 | [diff] [blame] | 111 | dev_info(&pdev->dev, "%s disabled\n", opt->name); | 
| Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 112 | return 0; | 
|  | 113 | } | 
|  | 114 | break; | 
|  | 115 | case range_option: | 
|  | 116 | if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) { | 
| Jay Cliburn | 1e00636 | 2007-04-29 21:42:10 -0500 | [diff] [blame] | 117 | dev_info(&pdev->dev, "%s set to %i\n", opt->name, | 
|  | 118 | *value); | 
| Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 119 | return 0; | 
|  | 120 | } | 
|  | 121 | break; | 
|  | 122 | case list_option:{ | 
|  | 123 | int i; | 
|  | 124 | struct atl1_opt_list *ent; | 
|  | 125 |  | 
|  | 126 | for (i = 0; i < opt->arg.l.nr; i++) { | 
|  | 127 | ent = &opt->arg.l.p[i]; | 
|  | 128 | if (*value == ent->i) { | 
|  | 129 | if (ent->str[0] != '\0') | 
| Jay Cliburn | 1e00636 | 2007-04-29 21:42:10 -0500 | [diff] [blame] | 130 | dev_info(&pdev->dev, "%s\n", | 
|  | 131 | ent->str); | 
| Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 132 | return 0; | 
|  | 133 | } | 
|  | 134 | } | 
|  | 135 | } | 
|  | 136 | break; | 
|  | 137 |  | 
|  | 138 | default: | 
|  | 139 | break; | 
|  | 140 | } | 
|  | 141 |  | 
| Jay Cliburn | 1e00636 | 2007-04-29 21:42:10 -0500 | [diff] [blame] | 142 | dev_info(&pdev->dev, "invalid %s specified (%i) %s\n", | 
|  | 143 | opt->name, *value, opt->err); | 
| Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 144 | *value = opt->def; | 
|  | 145 | return -1; | 
|  | 146 | } | 
|  | 147 |  | 
|  | 148 | /* | 
|  | 149 | * atl1_check_options - Range Checking for Command Line Parameters | 
|  | 150 | * @adapter: board private structure | 
|  | 151 | * | 
|  | 152 | * This routine checks all command line parameters for valid user | 
|  | 153 | * input.  If an invalid value is given, or if no user specified | 
|  | 154 | * value exists, a default value is used.  The final value is stored | 
|  | 155 | * in a variable in the adapter structure. | 
|  | 156 | */ | 
|  | 157 | void __devinit atl1_check_options(struct atl1_adapter *adapter) | 
|  | 158 | { | 
| Jay Cliburn | 1e00636 | 2007-04-29 21:42:10 -0500 | [diff] [blame] | 159 | struct pci_dev *pdev = adapter->pdev; | 
| Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 160 | int bd = adapter->bd_number; | 
|  | 161 | if (bd >= ATL1_MAX_NIC) { | 
| Jay Cliburn | 1e00636 | 2007-04-29 21:42:10 -0500 | [diff] [blame] | 162 | dev_notice(&pdev->dev, "no configuration for board#%i\n", bd); | 
|  | 163 | dev_notice(&pdev->dev, "using defaults for all values\n"); | 
| Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 164 | } | 
|  | 165 | {			/* Interrupt Moderate Timer */ | 
|  | 166 | struct atl1_option opt = { | 
|  | 167 | .type = range_option, | 
|  | 168 | .name = "Interrupt Moderator Timer", | 
|  | 169 | .err = "using default of " | 
|  | 170 | __MODULE_STRING(DEFAULT_INT_MOD_CNT), | 
|  | 171 | .def = DEFAULT_INT_MOD_CNT, | 
|  | 172 | .arg = {.r = | 
|  | 173 | {.min = MIN_INT_MOD_CNT,.max = MAX_INT_MOD_CNT}} | 
|  | 174 | }; | 
|  | 175 | int val; | 
|  | 176 | if (num_int_mod_timer > bd) { | 
|  | 177 | val = int_mod_timer[bd]; | 
| Jay Cliburn | 1e00636 | 2007-04-29 21:42:10 -0500 | [diff] [blame] | 178 | atl1_validate_option(&val, &opt, pdev); | 
| Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 179 | adapter->imt = (u16) val; | 
|  | 180 | } else | 
|  | 181 | adapter->imt = (u16) (opt.def); | 
|  | 182 | } | 
|  | 183 |  | 
|  | 184 | {			/* Flash Vendor */ | 
|  | 185 | struct atl1_option opt = { | 
|  | 186 | .type = range_option, | 
|  | 187 | .name = "SPI Flash Vendor", | 
|  | 188 | .err = "using default of " | 
|  | 189 | __MODULE_STRING(FLASH_VENDOR_DEFAULT), | 
|  | 190 | .def = DEFAULT_INT_MOD_CNT, | 
|  | 191 | .arg = {.r = | 
|  | 192 | {.min = FLASH_VENDOR_MIN,.max = | 
|  | 193 | FLASH_VENDOR_MAX}} | 
|  | 194 | }; | 
|  | 195 | int val; | 
|  | 196 | if (num_flash_vendor > bd) { | 
|  | 197 | val = flash_vendor[bd]; | 
| Jay Cliburn | 1e00636 | 2007-04-29 21:42:10 -0500 | [diff] [blame] | 198 | atl1_validate_option(&val, &opt, pdev); | 
| Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 199 | adapter->hw.flash_vendor = (u8) val; | 
|  | 200 | } else | 
|  | 201 | adapter->hw.flash_vendor = (u8) (opt.def); | 
|  | 202 | } | 
|  | 203 | } |