2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2012 Adrian Chadd
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer,
12 * without modification.
13 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
15 * redistribution must be conditioned upon including a substantially
16 * similar Disclaimer requirement for further binary redistribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
22 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
24 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 * THE POSSIBILITY OF SUCH DAMAGES.
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/module.h>
40 #include <sys/sysctl.h>
42 #include <sys/malloc.h>
46 #include <sys/mutex.h>
48 #include <sys/endian.h>
51 #include <dev/ath/if_ath_alq.h>
55 if_ath_alq_get(struct if_ath_alq *alq, int len)
59 if (alq->sc_alq_isactive == 0)
62 ale = alq_getn(alq->sc_alq_alq, len, ALQ_NOWAIT);
64 alq->sc_alq_numlost++;
69 if_ath_alq_init(struct if_ath_alq *alq, const char *devname)
72 bzero(alq, sizeof(*alq));
74 strncpy(alq->sc_alq_devname, devname, ATH_ALQ_DEVNAME_LEN);
75 printf("%s (%s): attached\n", __func__, alq->sc_alq_devname);
76 snprintf(alq->sc_alq_filename, ATH_ALQ_FILENAME_LEN,
77 "/tmp/ath_%s_alq.log", alq->sc_alq_devname);
79 /* XXX too conservative, right? */
80 alq->sc_alq_qsize = (64*1024);
84 if_ath_alq_setcfg(struct if_ath_alq *alq, uint32_t macVer,
85 uint32_t macRev, uint32_t phyRev, uint32_t halMagic)
88 /* Store these in network order */
89 alq->sc_alq_cfg.sc_mac_version = htobe32(macVer);
90 alq->sc_alq_cfg.sc_mac_revision = htobe32(macRev);
91 alq->sc_alq_cfg.sc_phy_rev = htobe32(phyRev);
92 alq->sc_alq_cfg.sc_hal_magic = htobe32(halMagic);
96 if_ath_alq_tidyup(struct if_ath_alq *alq)
100 printf("%s (%s): detached\n", __func__, alq->sc_alq_devname);
101 bzero(alq, sizeof(*alq));
105 if_ath_alq_start(struct if_ath_alq *alq)
109 if (alq->sc_alq_isactive)
113 * Create a variable-length ALQ.
115 error = alq_open(&alq->sc_alq_alq, alq->sc_alq_filename,
116 curthread->td_ucred, ALQ_DEFAULT_CMODE,
117 alq->sc_alq_qsize, 0);
120 printf("%s (%s): failed, err=%d\n", __func__,
121 alq->sc_alq_devname, error);
123 printf("%s (%s): opened\n", __func__, alq->sc_alq_devname);
124 alq->sc_alq_isactive = 1;
125 if_ath_alq_post(alq, ATH_ALQ_INIT_STATE,
126 sizeof (struct if_ath_alq_init_state),
127 (char *) &alq->sc_alq_cfg);
133 if_ath_alq_stop(struct if_ath_alq *alq)
136 if (alq->sc_alq_isactive == 0)
139 printf("%s (%s): closed\n", __func__, alq->sc_alq_devname);
141 alq->sc_alq_isactive = 0;
142 alq_close(alq->sc_alq_alq);
143 alq->sc_alq_alq = NULL;
149 * Post a debug message to the ALQ.
151 * "len" is the size of the buf payload in bytes.
154 if_ath_alq_post(struct if_ath_alq *alq, uint16_t op, uint16_t len,
157 struct if_ath_alq_hdr *ap;
161 if (! if_ath_alq_checkdebug(alq, op))
167 * Enforce some semblence of sanity on 'len'.
168 * Although strictly speaking, any length is possible -
169 * just be conservative so things don't get out of hand.
171 if (len > ATH_ALQ_PAYLOAD_LEN)
172 len = ATH_ALQ_PAYLOAD_LEN;
174 ale = if_ath_alq_get(alq, len + sizeof(struct if_ath_alq_hdr));
179 ap = (struct if_ath_alq_hdr *) ale->ae_data;
180 ap->threadid = htobe64((uint64_t) curthread->td_tid);
181 ap->tstamp_sec = htobe32((uint32_t) tv.tv_sec);
182 ap->tstamp_usec = htobe32((uint32_t) tv.tv_usec);
183 ap->op = htobe16(op);
184 ap->len = htobe16(len);
187 * Copy the payload _after_ the header field.
190 memcpy(((char *) ap) + sizeof(struct if_ath_alq_hdr),
195 alq_post(alq->sc_alq_alq, ale);
197 #endif /* ATH_DEBUG */