2 * Copyright (c) 2012 Adrian Chadd
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/module.h>
38 #include <sys/sysctl.h>
40 #include <sys/malloc.h>
44 #include <sys/mutex.h>
46 #include <sys/endian.h>
49 #include <dev/ath/if_ath_alq.h>
53 if_ath_alq_get(struct if_ath_alq *alq, int len)
57 if (alq->sc_alq_isactive == 0)
60 ale = alq_getn(alq->sc_alq_alq, len, ALQ_NOWAIT);
62 alq->sc_alq_numlost++;
67 if_ath_alq_init(struct if_ath_alq *alq, const char *devname)
70 bzero(alq, sizeof(*alq));
72 strncpy(alq->sc_alq_devname, devname, ATH_ALQ_DEVNAME_LEN);
73 printf("%s (%s): attached\n", __func__, alq->sc_alq_devname);
74 snprintf(alq->sc_alq_filename, ATH_ALQ_FILENAME_LEN,
75 "/tmp/ath_%s_alq.log", alq->sc_alq_devname);
77 /* XXX too conservative, right? */
78 alq->sc_alq_qsize = (64*1024);
82 if_ath_alq_setcfg(struct if_ath_alq *alq, uint32_t macVer,
83 uint32_t macRev, uint32_t phyRev, uint32_t halMagic)
86 /* Store these in network order */
87 alq->sc_alq_cfg.sc_mac_version = htobe32(macVer);
88 alq->sc_alq_cfg.sc_mac_revision = htobe32(macRev);
89 alq->sc_alq_cfg.sc_phy_rev = htobe32(phyRev);
90 alq->sc_alq_cfg.sc_hal_magic = htobe32(halMagic);
94 if_ath_alq_tidyup(struct if_ath_alq *alq)
98 printf("%s (%s): detached\n", __func__, alq->sc_alq_devname);
99 bzero(alq, sizeof(*alq));
103 if_ath_alq_start(struct if_ath_alq *alq)
107 if (alq->sc_alq_isactive)
111 * Create a variable-length ALQ.
113 error = alq_open(&alq->sc_alq_alq, alq->sc_alq_filename,
114 curthread->td_ucred, ALQ_DEFAULT_CMODE,
115 alq->sc_alq_qsize, 0);
118 printf("%s (%s): failed, err=%d\n", __func__,
119 alq->sc_alq_devname, error);
121 printf("%s (%s): opened\n", __func__, alq->sc_alq_devname);
122 alq->sc_alq_isactive = 1;
123 if_ath_alq_post(alq, ATH_ALQ_INIT_STATE,
124 sizeof (struct if_ath_alq_init_state),
125 (char *) &alq->sc_alq_cfg);
131 if_ath_alq_stop(struct if_ath_alq *alq)
134 if (alq->sc_alq_isactive == 0)
137 printf("%s (%s): closed\n", __func__, alq->sc_alq_devname);
139 alq->sc_alq_isactive = 0;
140 alq_close(alq->sc_alq_alq);
141 alq->sc_alq_alq = NULL;
147 * Post a debug message to the ALQ.
149 * "len" is the size of the buf payload in bytes.
152 if_ath_alq_post(struct if_ath_alq *alq, uint16_t op, uint16_t len,
155 struct if_ath_alq_hdr *ap;
159 if (! if_ath_alq_checkdebug(alq, op))
165 * Enforce some semblence of sanity on 'len'.
166 * Although strictly speaking, any length is possible -
167 * just be conservative so things don't get out of hand.
169 if (len > ATH_ALQ_PAYLOAD_LEN)
170 len = ATH_ALQ_PAYLOAD_LEN;
172 ale = if_ath_alq_get(alq, len + sizeof(struct if_ath_alq_hdr));
177 ap = (struct if_ath_alq_hdr *) ale->ae_data;
178 ap->threadid = htobe64((uint64_t) curthread->td_tid);
179 ap->tstamp_sec = htobe32((uint32_t) tv.tv_sec);
180 ap->tstamp_usec = htobe32((uint32_t) tv.tv_usec);
181 ap->op = htobe16(op);
182 ap->len = htobe16(len);
185 * Copy the payload _after_ the header field.
188 memcpy(((char *) ap) + sizeof(struct if_ath_alq_hdr),
193 alq_post(alq->sc_alq_alq, ale);
195 #endif /* ATH_DEBUG */