ath_netbsd.c revision 1.20
1/* $NetBSD: ath_netbsd.c,v 1.20 2011/03/07 11:25:41 cegger 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.20 2011/03/07 11:25:41 cegger 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#include <sys/module.h> 48 49#include <net/if.h> 50#include <net/if_dl.h> 51#include <net/if_media.h> 52#include <net/if_arp.h> 53#include <net/if_ether.h> 54#include <net/if_llc.h> 55 56#include <net80211/ieee80211_netbsd.h> 57#include <net80211/ieee80211_var.h> 58#include <dev/ic/ath_netbsd.h> 59#include <dev/ic/athvar.h> 60 61/* 62 * Setup sysctl(3) MIB, hw.ath.*. 63 * 64 * TBD condition CTLFLAG_PERMANENT on being a module or not 65 */ 66SYSCTL_SETUP(sysctl_ath, "sysctl ath subtree setup") 67{ 68 int rc; 69 const struct sysctlnode *cnode, *rnode; 70 71 if ((rnode = ath_sysctl_treetop(clog)) == NULL) 72 return; 73 74 if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE, "dwell", 75 "channel dwell time (ms) for AP/station scanning", 76 dwelltime)) != 0) 77 goto err; 78 79 if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE, "calibrate", 80 "chip calibration interval (secs)", calinterval)) != 0) 81 goto err; 82 83 if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE, "outdoor", 84 "outdoor operation", outdoor)) != 0) 85 goto err; 86 87 /* country code */ 88 if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE, 89 "countrycode", "country code", countrycode)) != 0) 90 goto err; 91 92 /* regulatory domain */ 93 if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE, "regdomain", 94 "EEPROM regdomain code", regdomain)) != 0) 95 goto err; 96 97 if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE, "debug", 98 "control debugging printfs", debug)) != 0) 99 goto err; 100 101 if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READONLY, "rxbuf", 102 "rx buffers allocated", rxbuf)) != 0) 103 goto err; 104 if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READONLY, "txbuf", 105 "tx buffers allocated", txbuf)) != 0) 106 goto err; 107 108 return; 109err: 110 printf("%s: sysctl_createv failed (rc = %d)\n", __func__, rc); 111} 112 113static int 114ath_sysctl_slottime(SYSCTLFN_ARGS) 115{ 116 struct ath_softc *sc; 117 struct sysctlnode node; 118 u_int slottime; 119 int error; 120 121 node = *rnode; 122 sc = (struct ath_softc *)node.sysctl_data; 123 slottime = ath_hal_getslottime(sc->sc_ah); 124 node.sysctl_data = &slottime; 125 error = sysctl_lookup(SYSCTLFN_CALL(&node)); 126 if (error || newp == NULL) 127 return error; 128 return !ath_hal_setslottime(sc->sc_ah, slottime) ? EINVAL : 0; 129} 130 131static int 132ath_sysctl_acktimeout(SYSCTLFN_ARGS) 133{ 134 struct ath_softc *sc; 135 struct sysctlnode node; 136 u_int acktimeout; 137 int error; 138 139 node = *rnode; 140 sc = (struct ath_softc *)node.sysctl_data; 141 acktimeout = ath_hal_getacktimeout(sc->sc_ah); 142 node.sysctl_data = &acktimeout; 143 error = sysctl_lookup(SYSCTLFN_CALL(&node)); 144 if (error || newp == NULL) 145 return error; 146 return !ath_hal_setacktimeout(sc->sc_ah, acktimeout) ? EINVAL : 0; 147} 148 149static int 150ath_sysctl_ctstimeout(SYSCTLFN_ARGS) 151{ 152 struct ath_softc *sc; 153 struct sysctlnode node; 154 u_int ctstimeout; 155 int error; 156 157 node = *rnode; 158 sc = (struct ath_softc *)node.sysctl_data; 159 ctstimeout = ath_hal_getctstimeout(sc->sc_ah); 160 node.sysctl_data = &ctstimeout; 161 error = sysctl_lookup(SYSCTLFN_CALL(&node)); 162 if (error || newp == NULL) 163 return error; 164 return !ath_hal_setctstimeout(sc->sc_ah, ctstimeout) ? EINVAL : 0; 165} 166 167static int 168ath_sysctl_softled(SYSCTLFN_ARGS) 169{ 170 struct ath_softc *sc; 171 struct sysctlnode node; 172 int softled; 173 int error; 174 175 node = *rnode; 176 sc = (struct ath_softc *)node.sysctl_data; 177 softled = sc->sc_softled; 178 node.sysctl_data = &softled; 179 error = sysctl_lookup(SYSCTLFN_CALL(&node)); 180 if (error || newp == NULL) 181 return error; 182 softled = (softled != 0); 183 if (softled != sc->sc_softled) { 184 if (softled) { 185 /* NB: handle any sc_ledpin change */ 186 ath_hal_gpioCfgOutput(sc->sc_ah, sc->sc_ledpin, 187 HAL_GPIO_MUX_MAC_NETWORK_LED); 188 ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin, 189 !sc->sc_ledon); 190 } 191 sc->sc_softled = softled; 192 } 193 return 0; 194} 195 196static int 197ath_sysctl_rxantenna(SYSCTLFN_ARGS) 198{ 199 struct ath_softc *sc; 200 struct sysctlnode node; 201 u_int defantenna; 202 int error; 203 204 node = *rnode; 205 sc = (struct ath_softc *)node.sysctl_data; 206 defantenna = ath_hal_getdefantenna(sc->sc_ah); 207 node.sysctl_data = &defantenna; 208 error = sysctl_lookup(SYSCTLFN_CALL(&node)); 209 if (error || newp == NULL) 210 return error; 211 ath_hal_setdefantenna(sc->sc_ah, defantenna); 212 return 0; 213} 214 215static int 216ath_sysctl_diversity(SYSCTLFN_ARGS) 217{ 218 struct ath_softc *sc; 219 struct sysctlnode node; 220 u_int diversity; 221 int error; 222 223 node = *rnode; 224 sc = (struct ath_softc *)node.sysctl_data; 225 diversity = sc->sc_diversity; 226 node.sysctl_data = &diversity; 227 error = sysctl_lookup(SYSCTLFN_CALL(&node)); 228 if (error || newp == NULL) 229 return error; 230 if (!ath_hal_setdiversity(sc->sc_ah, diversity)) 231 return EINVAL; 232 sc->sc_diversity = diversity; 233 return 0; 234} 235 236static int 237ath_sysctl_diag(SYSCTLFN_ARGS) 238{ 239 struct ath_softc *sc; 240 struct sysctlnode node; 241 u_int32_t diag; 242 int error; 243 244 node = *rnode; 245 sc = (struct ath_softc *)node.sysctl_data; 246 if (!ath_hal_getdiag(sc->sc_ah, &diag)) 247 return EINVAL; 248 node.sysctl_data = &diag; 249 error = sysctl_lookup(SYSCTLFN_CALL(&node)); 250 if (error || newp == NULL) 251 return error; 252 return !ath_hal_setdiag(sc->sc_ah, diag) ? EINVAL : 0; 253} 254 255static int 256ath_sysctl_tpscale(SYSCTLFN_ARGS) 257{ 258 struct ath_softc *sc; 259 struct sysctlnode node; 260 u_int32_t scale; 261 int error; 262 263 node = *rnode; 264 sc = (struct ath_softc *)node.sysctl_data; 265 (void)ath_hal_gettpscale(sc->sc_ah, &scale); 266 node.sysctl_data = &scale; 267 error = sysctl_lookup(SYSCTLFN_CALL(&node)); 268 if (error || newp == NULL) 269 return error; 270 return !ath_hal_settpscale(sc->sc_ah, scale) 271 ? EINVAL 272 : ath_reset(&sc->sc_if); 273} 274 275static int 276ath_sysctl_tpc(SYSCTLFN_ARGS) 277{ 278 struct ath_softc *sc; 279 struct sysctlnode node; 280 u_int tpc; 281 int error; 282 283 node = *rnode; 284 sc = (struct ath_softc *)node.sysctl_data; 285 tpc = ath_hal_gettpc(sc->sc_ah); 286 node.sysctl_data = &tpc; 287 error = sysctl_lookup(SYSCTLFN_CALL(&node)); 288 if (error || newp == NULL) 289 return error; 290 return !ath_hal_settpc(sc->sc_ah, tpc) ? EINVAL : 0; 291} 292 293static int 294ath_sysctl_rfkill(SYSCTLFN_ARGS) 295{ 296 struct ath_softc *sc; 297 struct sysctlnode node; 298 u_int rfkill; 299 int error; 300 301 node = *rnode; 302 sc = (struct ath_softc *)node.sysctl_data; 303 rfkill = ath_hal_getrfkill(sc->sc_ah); 304 node.sysctl_data = &rfkill; 305 error = sysctl_lookup(SYSCTLFN_CALL(&node)); 306 if (error || newp == NULL) 307 return error; 308 return !ath_hal_setrfkill(sc->sc_ah, rfkill) ? EINVAL : 0; 309} 310 311static int 312ath_sysctl_rfsilent(SYSCTLFN_ARGS) 313{ 314 struct ath_softc *sc; 315 struct sysctlnode node; 316 u_int rfsilent; 317 int error; 318 319 node = *rnode; 320 sc = (struct ath_softc *)node.sysctl_data; 321 (void)ath_hal_getrfsilent(sc->sc_ah, &rfsilent); 322 node.sysctl_data = &rfsilent; 323 error = sysctl_lookup(SYSCTLFN_CALL(&node)); 324 if (error || newp == NULL) 325 return error; 326 return !ath_hal_setrfsilent(sc->sc_ah, rfsilent) ? EINVAL : 0; 327} 328 329static int 330ath_sysctl_regdomain(SYSCTLFN_ARGS) 331{ 332 struct ath_softc *sc; 333 struct sysctlnode node; 334 u_int32_t rd; 335 int error; 336 337 node = *rnode; 338 sc = (struct ath_softc *)node.sysctl_data; 339 if (!ath_hal_getregdomain(sc->sc_ah, &rd)) 340 return EINVAL; 341 node.sysctl_data = &rd; 342 error = sysctl_lookup(SYSCTLFN_CALL(&node)); 343 if (error || newp == NULL) 344 return error; 345 return !ath_hal_setregdomain(sc->sc_ah, rd) ? EINVAL : 0; 346} 347 348static int 349ath_sysctl_tpack(SYSCTLFN_ARGS) 350{ 351 struct ath_softc *sc; 352 struct sysctlnode node; 353 u_int32_t tpack; 354 int error; 355 356 node = *rnode; 357 sc = (struct ath_softc *)node.sysctl_data; 358 (void)ath_hal_gettpack(sc->sc_ah, &tpack); 359 node.sysctl_data = &tpack; 360 error = sysctl_lookup(SYSCTLFN_CALL(&node)); 361 if (error || newp == NULL) 362 return error; 363 return !ath_hal_settpack(sc->sc_ah, tpack) ? EINVAL : 0; 364} 365 366static int 367ath_sysctl_tpcts(SYSCTLFN_ARGS) 368{ 369 struct ath_softc *sc; 370 struct sysctlnode node; 371 u_int32_t tpcts; 372 int error; 373 374 node = *rnode; 375 sc = (struct ath_softc *)node.sysctl_data; 376 (void)ath_hal_gettpcts(sc->sc_ah, &tpcts); 377 node.sysctl_data = &tpcts; 378 error = sysctl_lookup(SYSCTLFN_CALL(&node)); 379 if (error || newp == NULL) 380 return error; 381 return !ath_hal_settpcts(sc->sc_ah, tpcts) ? EINVAL : 0; 382} 383 384const struct sysctlnode * 385ath_sysctl_instance(const char *dvname, struct sysctllog **log) 386{ 387 int rc; 388 const struct sysctlnode *rnode; 389 390 if ((rc = sysctl_createv(log, 0, NULL, &rnode, 391 CTLFLAG_PERMANENT, CTLTYPE_NODE, "hw", NULL, 392 NULL, 0, NULL, 0, CTL_HW, CTL_EOL)) != 0) 393 goto err; 394 395 if ((rc = sysctl_createv(log, 0, &rnode, &rnode, 396 CTLFLAG_PERMANENT, CTLTYPE_NODE, dvname, 397 SYSCTL_DESCR("ath information and options"), 398 NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0) 399 goto err; 400 401 return rnode; 402err: 403 printf("%s: sysctl_createv failed, rc = %d\n", __func__, rc); 404 return NULL; 405} 406 407const struct sysctlnode * 408ath_sysctl_treetop(struct sysctllog **log) 409{ 410 int rc; 411 const struct sysctlnode *rnode; 412 413 if ((rc = sysctl_createv(log, 0, NULL, &rnode, 414 CTLFLAG_PERMANENT, CTLTYPE_NODE, "hw", NULL, 415 NULL, 0, NULL, 0, CTL_HW, CTL_EOL)) != 0) 416 goto err; 417 418 if ((rc = sysctl_createv(log, 0, &rnode, &rnode, 419 CTLFLAG_PERMANENT, CTLTYPE_NODE, "ath", 420 SYSCTL_DESCR("ath information and options"), 421 NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0) 422 goto err; 423 424 return rnode; 425err: 426 printf("%s: sysctl_createv failed, rc = %d\n", __func__, rc); 427 return NULL; 428} 429 430void 431ath_sysctlattach(struct ath_softc *sc) 432{ 433 int rc; 434 struct sysctllog **log = &sc->sc_sysctllog; 435 const struct sysctlnode *cnode, *rnode; 436 437 ath_hal_getcountrycode(sc->sc_ah, &sc->sc_countrycode); 438 (void)ath_hal_getregdomain(sc->sc_ah, &sc->sc_regdomain); 439 sc->sc_debug = ath_debug; 440 sc->sc_txintrperiod = ATH_TXINTR_PERIOD; 441 442 if ((rnode = ath_sysctl_instance(device_xname(sc->sc_dev), log)) == NULL) 443 return; 444 445 if ((rc = SYSCTL_INT(0, countrycode, "EEPROM country code")) != 0) 446 goto err; 447 448 if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, debug, 449 "control debugging printfs")) != 0) 450 goto err; 451 452#if 0 453 /* channel dwell time (ms) for AP/station scanning */ 454 if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, dwell, 455 "Channel dwell time (ms) for scanning")) != 0) 456 goto err; 457#endif 458 459 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, slottime, 460 "802.11 slot time (us)")) != 0) 461 goto err; 462 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, acktimeout, 463 "802.11 ACK timeout (us)")) != 0) 464 goto err; 465 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, ctstimeout, 466 "802.11 CTS timeout (us)")) != 0) 467 goto err; 468 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, softled, 469 "enable/disable software LED support")) != 0) 470 goto err; 471 if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, ledpin, 472 "GPIO pin connected to LED")) != 0) 473 goto err; 474 if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, ledon, 475 "setting to turn LED on")) != 0) 476 goto err; 477 if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, ledidle, 478 "idle time for inactivity LED (ticks)")) != 0) 479 goto err; 480 if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, txantenna, 481 "tx antenna (0=auto)")) != 0) 482 goto err; 483 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, rxantenna, 484 "default/rx antenna")) != 0) 485 goto err; 486 if (ath_hal_hasdiversity(sc->sc_ah)) { 487 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, diversity, 488 "antenna diversity")) != 0) 489 goto err; 490 } 491 if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, txintrperiod, 492 "tx descriptor batching")) != 0) 493 goto err; 494 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, diag, 495 "h/w diagnostic control")) != 0) 496 goto err; 497 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, tpscale, 498 "tx power scaling")) != 0) 499 goto err; 500 if (ath_hal_hastpc(sc->sc_ah)) { 501 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, tpc, 502 "enable/disable per-packet TPC")) != 0) 503 goto err; 504 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, tpack, 505 "tx power for ack frames")) != 0) 506 goto err; 507 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, tpcts, 508 "tx power for cts frames")) != 0) 509 goto err; 510 } 511 if (ath_hal_hasrfsilent(sc->sc_ah)) { 512 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, rfsilent, 513 "h/w RF silent config")) != 0) 514 goto err; 515 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, rfkill, 516 "enable/disable RF kill switch")) != 0) 517 goto err; 518 } 519 if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, regdomain, 520 "EEPROM regdomain code")) != 0) 521 goto err; 522 return; 523err: 524 printf("%s: sysctl_createv failed, rc = %d\n", __func__, rc); 525} 526 527MODULE(MODULE_CLASS_MISC, ath, "ath_hal"); 528 529static int 530ath_modcmd(modcmd_t cmd, void *opaque) 531{ 532 switch (cmd) { 533 case MODULE_CMD_INIT: 534 case MODULE_CMD_FINI: 535 return 0; 536 default: 537 return ENOTTY; 538 } 539} 540