pasemi_mac: Add SKB reuse / copy-break
[linux-2.6] / drivers / net / atl1 / atl1_param.c
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>
25 #include <linux/moduleparam.h>
26 #include "atl1.h"
27
28 /*
29  * This is the only thing that needs to be changed to adjust the
30  * maximum number of ports that the driver can manage.
31  */
32 #define ATL1_MAX_NIC 4
33
34 #define OPTION_UNSET    -1
35 #define OPTION_DISABLED 0
36 #define OPTION_ENABLED  1
37
38 #define ATL1_PARAM_INIT { [0 ... ATL1_MAX_NIC] = OPTION_UNSET }
39
40 /*
41  * Interrupt Moderate Timer in units of 2 us
42  *
43  * Valid Range: 10-65535
44  *
45  * Default Value: 100 (200us)
46  */
47 static int __devinitdata int_mod_timer[ATL1_MAX_NIC+1] = ATL1_PARAM_INIT;
48 static int num_int_mod_timer = 0;
49 module_param_array_named(int_mod_timer, int_mod_timer, int, &num_int_mod_timer, 0);
50 MODULE_PARM_DESC(int_mod_timer, "Interrupt moderator timer");
51
52 /*
53  * flash_vendor
54  *
55  * Valid Range: 0-2
56  *
57  * 0 - Atmel
58  * 1 - SST
59  * 2 - ST
60  *
61  * Default Value: 0
62  */
63 static int __devinitdata flash_vendor[ATL1_MAX_NIC+1] = ATL1_PARAM_INIT;
64 static int num_flash_vendor = 0;
65 module_param_array_named(flash_vendor, flash_vendor, int, &num_flash_vendor, 0);
66 MODULE_PARM_DESC(flash_vendor, "SPI flash vendor");
67
68 #define DEFAULT_INT_MOD_CNT     100     /* 200us */
69 #define MAX_INT_MOD_CNT         65000
70 #define MIN_INT_MOD_CNT         50
71
72 #define FLASH_VENDOR_DEFAULT    0
73 #define FLASH_VENDOR_MIN        0
74 #define FLASH_VENDOR_MAX        2
75
76 struct atl1_option {
77         enum { enable_option, range_option, list_option } type;
78         char *name;
79         char *err;
80         int def;
81         union {
82                 struct {        /* range_option info */
83                         int min;
84                         int max;
85                 } r;
86                 struct {        /* list_option info */
87                         int nr;
88                         struct atl1_opt_list {
89                                 int i;
90                                 char *str;
91                         } *p;
92                 } l;
93         } arg;
94 };
95
96 static int __devinit atl1_validate_option(int *value, struct atl1_option *opt, struct pci_dev *pdev)
97 {
98         if (*value == OPTION_UNSET) {
99                 *value = opt->def;
100                 return 0;
101         }
102
103         switch (opt->type) {
104         case enable_option:
105                 switch (*value) {
106                 case OPTION_ENABLED:
107                         dev_info(&pdev->dev, "%s enabled\n", opt->name);
108                         return 0;
109                 case OPTION_DISABLED:
110                         dev_info(&pdev->dev, "%s disabled\n", opt->name);
111                         return 0;
112                 }
113                 break;
114         case range_option:
115                 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
116                         dev_info(&pdev->dev, "%s set to %i\n", opt->name,
117                                 *value);
118                         return 0;
119                 }
120                 break;
121         case list_option:{
122                         int i;
123                         struct atl1_opt_list *ent;
124
125                         for (i = 0; i < opt->arg.l.nr; i++) {
126                                 ent = &opt->arg.l.p[i];
127                                 if (*value == ent->i) {
128                                         if (ent->str[0] != '\0')
129                                                 dev_info(&pdev->dev, "%s\n",
130                                                         ent->str);
131                                         return 0;
132                                 }
133                         }
134                 }
135                 break;
136
137         default:
138                 break;
139         }
140
141         dev_info(&pdev->dev, "invalid %s specified (%i) %s\n",
142                 opt->name, *value, opt->err);
143         *value = opt->def;
144         return -1;
145 }
146
147 /*
148  * atl1_check_options - Range Checking for Command Line Parameters
149  * @adapter: board private structure
150  *
151  * This routine checks all command line parameters for valid user
152  * input.  If an invalid value is given, or if no user specified
153  * value exists, a default value is used.  The final value is stored
154  * in a variable in the adapter structure.
155  */
156 void __devinit atl1_check_options(struct atl1_adapter *adapter)
157 {
158         struct pci_dev *pdev = adapter->pdev;
159         int bd = adapter->bd_number;
160         if (bd >= ATL1_MAX_NIC) {
161                 dev_notice(&pdev->dev, "no configuration for board#%i\n", bd);
162                 dev_notice(&pdev->dev, "using defaults for all values\n");
163         }
164         {                       /* Interrupt Moderate Timer */
165                 struct atl1_option opt = {
166                         .type = range_option,
167                         .name = "Interrupt Moderator Timer",
168                         .err = "using default of "
169                                 __MODULE_STRING(DEFAULT_INT_MOD_CNT),
170                         .def = DEFAULT_INT_MOD_CNT,
171                         .arg = {.r =
172                                 {.min = MIN_INT_MOD_CNT,.max = MAX_INT_MOD_CNT}}
173                 };
174                 int val;
175                 if (num_int_mod_timer > bd) {
176                         val = int_mod_timer[bd];
177                         atl1_validate_option(&val, &opt, pdev);
178                         adapter->imt = (u16) val;
179                 } else
180                         adapter->imt = (u16) (opt.def);
181         }
182
183         {                       /* Flash Vendor */
184                 struct atl1_option opt = {
185                         .type = range_option,
186                         .name = "SPI Flash Vendor",
187                         .err = "using default of "
188                                 __MODULE_STRING(FLASH_VENDOR_DEFAULT),
189                         .def = DEFAULT_INT_MOD_CNT,
190                         .arg = {.r =
191                                 {.min = FLASH_VENDOR_MIN,.max =
192                                  FLASH_VENDOR_MAX}}
193                 };
194                 int val;
195                 if (num_flash_vendor > bd) {
196                         val = flash_vendor[bd];
197                         atl1_validate_option(&val, &opt, pdev);
198                         adapter->hw.flash_vendor = (u8) val;
199                 } else
200                         adapter->hw.flash_vendor = (u8) (opt.def);
201         }
202 }