ath_netbsd.c revision 1.17.8.1 1 /* $NetBSD: ath_netbsd.c,v 1.17.8.1 2011/02/08 16:19:48 bouyer Exp $ */
2
3 /*-
4 * Copyright (c) 2003, 2004 David Young
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: ath_netbsd.c,v 1.17.8.1 2011/02/08 16:19:48 bouyer Exp $");
30
31 #include <sys/param.h>
32 #include <sys/types.h>
33 #include <sys/errno.h>
34 #include <sys/systm.h>
35 #include <sys/sysctl.h>
36 #include <sys/mbuf.h>
37 #include <sys/malloc.h>
38 #include <sys/kernel.h>
39 #include <sys/socket.h>
40 #include <sys/sockio.h>
41 #include <sys/sysctl.h>
42 #include <sys/callout.h>
43 #include <sys/bus.h>
44 #include <machine/stdarg.h>
45 #include <sys/endian.h>
46 #include <sys/device.h>
47
48 #include <net/if.h>
49 #include <net/if_dl.h>
50 #include <net/if_media.h>
51 #include <net/if_arp.h>
52 #include <net/if_ether.h>
53 #include <net/if_llc.h>
54
55 #include <net80211/ieee80211_netbsd.h>
56 #include <net80211/ieee80211_var.h>
57 #include <dev/ic/ath_netbsd.h>
58 #include <dev/ic/athvar.h>
59
60 /*
61 * Setup sysctl(3) MIB, hw.ath.*.
62 *
63 * TBD condition CTLFLAG_PERMANENT on being a module or not
64 */
65 SYSCTL_SETUP(sysctl_ath, "sysctl ath subtree setup")
66 {
67 int rc;
68 const struct sysctlnode *cnode, *rnode;
69
70 if ((rnode = ath_sysctl_treetop(clog)) == NULL)
71 return;
72
73 if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE, "dwell",
74 "channel dwell time (ms) for AP/station scanning",
75 dwelltime)) != 0)
76 goto err;
77
78 if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE, "calibrate",
79 "chip calibration interval (secs)", calinterval)) != 0)
80 goto err;
81
82 if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE, "outdoor",
83 "outdoor operation", outdoor)) != 0)
84 goto err;
85
86 /* country code */
87 if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE,
88 "countrycode", "country code", countrycode)) != 0)
89 goto err;
90
91 /* regulatory domain */
92 if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE, "regdomain",
93 "EEPROM regdomain code", regdomain)) != 0)
94 goto err;
95
96 if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE, "debug",
97 "control debugging printfs", debug)) != 0)
98 goto err;
99
100 if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READONLY, "rxbuf",
101 "rx buffers allocated", rxbuf)) != 0)
102 goto err;
103 if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READONLY, "txbuf",
104 "tx buffers allocated", txbuf)) != 0)
105 goto err;
106
107 return;
108 err:
109 printf("%s: sysctl_createv failed (rc = %d)\n", __func__, rc);
110 }
111
112 static int
113 ath_sysctl_slottime(SYSCTLFN_ARGS)
114 {
115 struct ath_softc *sc;
116 struct sysctlnode node;
117 u_int slottime;
118 int error;
119
120 node = *rnode;
121 sc = (struct ath_softc *)node.sysctl_data;
122 slottime = ath_hal_getslottime(sc->sc_ah);
123 node.sysctl_data = &slottime;
124 error = sysctl_lookup(SYSCTLFN_CALL(&node));
125 if (error || newp == NULL)
126 return error;
127 return !ath_hal_setslottime(sc->sc_ah, slottime) ? EINVAL : 0;
128 }
129
130 static int
131 ath_sysctl_acktimeout(SYSCTLFN_ARGS)
132 {
133 struct ath_softc *sc;
134 struct sysctlnode node;
135 u_int acktimeout;
136 int error;
137
138 node = *rnode;
139 sc = (struct ath_softc *)node.sysctl_data;
140 acktimeout = ath_hal_getacktimeout(sc->sc_ah);
141 node.sysctl_data = &acktimeout;
142 error = sysctl_lookup(SYSCTLFN_CALL(&node));
143 if (error || newp == NULL)
144 return error;
145 return !ath_hal_setacktimeout(sc->sc_ah, acktimeout) ? EINVAL : 0;
146 }
147
148 static int
149 ath_sysctl_ctstimeout(SYSCTLFN_ARGS)
150 {
151 struct ath_softc *sc;
152 struct sysctlnode node;
153 u_int ctstimeout;
154 int error;
155
156 node = *rnode;
157 sc = (struct ath_softc *)node.sysctl_data;
158 ctstimeout = ath_hal_getctstimeout(sc->sc_ah);
159 node.sysctl_data = &ctstimeout;
160 error = sysctl_lookup(SYSCTLFN_CALL(&node));
161 if (error || newp == NULL)
162 return error;
163 return !ath_hal_setctstimeout(sc->sc_ah, ctstimeout) ? EINVAL : 0;
164 }
165
166 static int
167 ath_sysctl_softled(SYSCTLFN_ARGS)
168 {
169 struct ath_softc *sc;
170 struct sysctlnode node;
171 int softled;
172 int error;
173
174 node = *rnode;
175 sc = (struct ath_softc *)node.sysctl_data;
176 softled = sc->sc_softled;
177 node.sysctl_data = &softled;
178 error = sysctl_lookup(SYSCTLFN_CALL(&node));
179 if (error || newp == NULL)
180 return error;
181 softled = (softled != 0);
182 if (softled != sc->sc_softled) {
183 if (softled) {
184 /* NB: handle any sc_ledpin change */
185 ath_hal_gpioCfgOutput(sc->sc_ah, sc->sc_ledpin);
186 ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin,
187 !sc->sc_ledon);
188 }
189 sc->sc_softled = softled;
190 }
191 return 0;
192 }
193
194 static int
195 ath_sysctl_rxantenna(SYSCTLFN_ARGS)
196 {
197 struct ath_softc *sc;
198 struct sysctlnode node;
199 u_int defantenna;
200 int error;
201
202 node = *rnode;
203 sc = (struct ath_softc *)node.sysctl_data;
204 defantenna = ath_hal_getdefantenna(sc->sc_ah);
205 node.sysctl_data = &defantenna;
206 error = sysctl_lookup(SYSCTLFN_CALL(&node));
207 if (error || newp == NULL)
208 return error;
209 ath_hal_setdefantenna(sc->sc_ah, defantenna);
210 return 0;
211 }
212
213 static int
214 ath_sysctl_diversity(SYSCTLFN_ARGS)
215 {
216 struct ath_softc *sc;
217 struct sysctlnode node;
218 u_int diversity;
219 int error;
220
221 node = *rnode;
222 sc = (struct ath_softc *)node.sysctl_data;
223 diversity = sc->sc_diversity;
224 node.sysctl_data = &diversity;
225 error = sysctl_lookup(SYSCTLFN_CALL(&node));
226 if (error || newp == NULL)
227 return error;
228 if (!ath_hal_setdiversity(sc->sc_ah, diversity))
229 return EINVAL;
230 sc->sc_diversity = diversity;
231 return 0;
232 }
233
234 static int
235 ath_sysctl_diag(SYSCTLFN_ARGS)
236 {
237 struct ath_softc *sc;
238 struct sysctlnode node;
239 u_int32_t diag;
240 int error;
241
242 node = *rnode;
243 sc = (struct ath_softc *)node.sysctl_data;
244 if (!ath_hal_getdiag(sc->sc_ah, &diag))
245 return EINVAL;
246 node.sysctl_data = &diag;
247 error = sysctl_lookup(SYSCTLFN_CALL(&node));
248 if (error || newp == NULL)
249 return error;
250 return !ath_hal_setdiag(sc->sc_ah, diag) ? EINVAL : 0;
251 }
252
253 static int
254 ath_sysctl_tpscale(SYSCTLFN_ARGS)
255 {
256 struct ath_softc *sc;
257 struct sysctlnode node;
258 u_int32_t scale;
259 int error;
260
261 node = *rnode;
262 sc = (struct ath_softc *)node.sysctl_data;
263 (void)ath_hal_gettpscale(sc->sc_ah, &scale);
264 node.sysctl_data = &scale;
265 error = sysctl_lookup(SYSCTLFN_CALL(&node));
266 if (error || newp == NULL)
267 return error;
268 return !ath_hal_settpscale(sc->sc_ah, scale)
269 ? EINVAL
270 : ath_reset(&sc->sc_if);
271 }
272
273 static int
274 ath_sysctl_tpc(SYSCTLFN_ARGS)
275 {
276 struct ath_softc *sc;
277 struct sysctlnode node;
278 u_int tpc;
279 int error;
280
281 node = *rnode;
282 sc = (struct ath_softc *)node.sysctl_data;
283 tpc = ath_hal_gettpc(sc->sc_ah);
284 node.sysctl_data = &tpc;
285 error = sysctl_lookup(SYSCTLFN_CALL(&node));
286 if (error || newp == NULL)
287 return error;
288 return !ath_hal_settpc(sc->sc_ah, tpc) ? EINVAL : 0;
289 }
290
291 static int
292 ath_sysctl_rfkill(SYSCTLFN_ARGS)
293 {
294 struct ath_softc *sc;
295 struct sysctlnode node;
296 u_int rfkill;
297 int error;
298
299 node = *rnode;
300 sc = (struct ath_softc *)node.sysctl_data;
301 rfkill = ath_hal_getrfkill(sc->sc_ah);
302 node.sysctl_data = &rfkill;
303 error = sysctl_lookup(SYSCTLFN_CALL(&node));
304 if (error || newp == NULL)
305 return error;
306 return !ath_hal_setrfkill(sc->sc_ah, rfkill) ? EINVAL : 0;
307 }
308
309 static int
310 ath_sysctl_rfsilent(SYSCTLFN_ARGS)
311 {
312 struct ath_softc *sc;
313 struct sysctlnode node;
314 u_int rfsilent;
315 int error;
316
317 node = *rnode;
318 sc = (struct ath_softc *)node.sysctl_data;
319 (void)ath_hal_getrfsilent(sc->sc_ah, &rfsilent);
320 node.sysctl_data = &rfsilent;
321 error = sysctl_lookup(SYSCTLFN_CALL(&node));
322 if (error || newp == NULL)
323 return error;
324 return !ath_hal_setrfsilent(sc->sc_ah, rfsilent) ? EINVAL : 0;
325 }
326
327 static int
328 ath_sysctl_regdomain(SYSCTLFN_ARGS)
329 {
330 struct ath_softc *sc;
331 struct sysctlnode node;
332 u_int32_t rd;
333 int error;
334
335 node = *rnode;
336 sc = (struct ath_softc *)node.sysctl_data;
337 if (!ath_hal_getregdomain(sc->sc_ah, &rd))
338 return EINVAL;
339 node.sysctl_data = &rd;
340 error = sysctl_lookup(SYSCTLFN_CALL(&node));
341 if (error || newp == NULL)
342 return error;
343 return !ath_hal_setregdomain(sc->sc_ah, rd) ? EINVAL : 0;
344 }
345
346 static int
347 ath_sysctl_tpack(SYSCTLFN_ARGS)
348 {
349 struct ath_softc *sc;
350 struct sysctlnode node;
351 u_int32_t tpack;
352 int error;
353
354 node = *rnode;
355 sc = (struct ath_softc *)node.sysctl_data;
356 (void)ath_hal_gettpack(sc->sc_ah, &tpack);
357 node.sysctl_data = &tpack;
358 error = sysctl_lookup(SYSCTLFN_CALL(&node));
359 if (error || newp == NULL)
360 return error;
361 return !ath_hal_settpack(sc->sc_ah, tpack) ? EINVAL : 0;
362 }
363
364 static int
365 ath_sysctl_tpcts(SYSCTLFN_ARGS)
366 {
367 struct ath_softc *sc;
368 struct sysctlnode node;
369 u_int32_t tpcts;
370 int error;
371
372 node = *rnode;
373 sc = (struct ath_softc *)node.sysctl_data;
374 (void)ath_hal_gettpcts(sc->sc_ah, &tpcts);
375 node.sysctl_data = &tpcts;
376 error = sysctl_lookup(SYSCTLFN_CALL(&node));
377 if (error || newp == NULL)
378 return error;
379 return !ath_hal_settpcts(sc->sc_ah, tpcts) ? EINVAL : 0;
380 }
381
382 const struct sysctlnode *
383 ath_sysctl_instance(const char *dvname, struct sysctllog **log)
384 {
385 int rc;
386 const struct sysctlnode *rnode;
387
388 if ((rc = sysctl_createv(log, 0, NULL, &rnode,
389 CTLFLAG_PERMANENT, CTLTYPE_NODE, "hw", NULL,
390 NULL, 0, NULL, 0, CTL_HW, CTL_EOL)) != 0)
391 goto err;
392
393 if ((rc = sysctl_createv(log, 0, &rnode, &rnode,
394 CTLFLAG_PERMANENT, CTLTYPE_NODE, dvname,
395 SYSCTL_DESCR("ath information and options"),
396 NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
397 goto err;
398
399 return rnode;
400 err:
401 printf("%s: sysctl_createv failed, rc = %d\n", __func__, rc);
402 return NULL;
403 }
404
405 const struct sysctlnode *
406 ath_sysctl_treetop(struct sysctllog **log)
407 {
408 int rc;
409 const struct sysctlnode *rnode;
410
411 if ((rc = sysctl_createv(log, 0, NULL, &rnode,
412 CTLFLAG_PERMANENT, CTLTYPE_NODE, "hw", NULL,
413 NULL, 0, NULL, 0, CTL_HW, CTL_EOL)) != 0)
414 goto err;
415
416 if ((rc = sysctl_createv(log, 0, &rnode, &rnode,
417 CTLFLAG_PERMANENT, CTLTYPE_NODE, "ath",
418 SYSCTL_DESCR("ath information and options"),
419 NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
420 goto err;
421
422 return rnode;
423 err:
424 printf("%s: sysctl_createv failed, rc = %d\n", __func__, rc);
425 return NULL;
426 }
427
428 void
429 ath_sysctlattach(struct ath_softc *sc)
430 {
431 int rc;
432 struct sysctllog **log = &sc->sc_sysctllog;
433 const struct sysctlnode *cnode, *rnode;
434
435 ath_hal_getcountrycode(sc->sc_ah, &sc->sc_countrycode);
436 (void)ath_hal_getregdomain(sc->sc_ah, &sc->sc_regdomain);
437 sc->sc_debug = ath_debug;
438 sc->sc_txintrperiod = ATH_TXINTR_PERIOD;
439
440 if ((rnode = ath_sysctl_instance(device_xname(sc->sc_dev), log)) == NULL)
441 return;
442
443 if ((rc = SYSCTL_INT(0, countrycode, "EEPROM country code")) != 0)
444 goto err;
445
446 if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, debug,
447 "control debugging printfs")) != 0)
448 goto err;
449
450 #if 0
451 /* channel dwell time (ms) for AP/station scanning */
452 if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, dwell,
453 "Channel dwell time (ms) for scanning")) != 0)
454 goto err;
455 #endif
456
457 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, slottime,
458 "802.11 slot time (us)")) != 0)
459 goto err;
460 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, acktimeout,
461 "802.11 ACK timeout (us)")) != 0)
462 goto err;
463 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, ctstimeout,
464 "802.11 CTS timeout (us)")) != 0)
465 goto err;
466 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, softled,
467 "enable/disable software LED support")) != 0)
468 goto err;
469 if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, ledpin,
470 "GPIO pin connected to LED")) != 0)
471 goto err;
472 if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, ledon,
473 "setting to turn LED on")) != 0)
474 goto err;
475 if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, ledidle,
476 "idle time for inactivity LED (ticks)")) != 0)
477 goto err;
478 if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, txantenna,
479 "tx antenna (0=auto)")) != 0)
480 goto err;
481 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, rxantenna,
482 "default/rx antenna")) != 0)
483 goto err;
484 if (ath_hal_hasdiversity(sc->sc_ah)) {
485 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, diversity,
486 "antenna diversity")) != 0)
487 goto err;
488 }
489 if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, txintrperiod,
490 "tx descriptor batching")) != 0)
491 goto err;
492 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, diag,
493 "h/w diagnostic control")) != 0)
494 goto err;
495 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, tpscale,
496 "tx power scaling")) != 0)
497 goto err;
498 if (ath_hal_hastpc(sc->sc_ah)) {
499 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, tpc,
500 "enable/disable per-packet TPC")) != 0)
501 goto err;
502 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, tpack,
503 "tx power for ack frames")) != 0)
504 goto err;
505 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, tpcts,
506 "tx power for cts frames")) != 0)
507 goto err;
508 }
509 if (ath_hal_hasrfsilent(sc->sc_ah)) {
510 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, rfsilent,
511 "h/w RF silent config")) != 0)
512 goto err;
513 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, rfkill,
514 "enable/disable RF kill switch")) != 0)
515 goto err;
516 }
517 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, regdomain,
518 "EEPROM regdomain code")) != 0)
519 goto err;
520 return;
521 err:
522 printf("%s: sysctl_createv failed, rc = %d\n", __func__, rc);
523 }
524