]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/bwn/if_bwn_siba_compat.h
MFV r328323,328324:
[FreeBSD/FreeBSD.git] / sys / dev / bwn / if_bwn_siba_compat.h
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2016 Landon J. Fuller <landonf@FreeBSD.org>.
5  * Copyright (c) 2017 The FreeBSD Foundation
6  * All rights reserved.
7  *
8  * Portions of this software were developed by Landon Fuller
9  * under sponsorship from the FreeBSD Foundation.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * $FreeBSD$
33  */
34
35 #ifndef _IF_BWN_SIBA_COMPAT_H_
36 #define _IF_BWN_SIBA_COMPAT_H_
37
38 #define BWN_USE_SIBA    0
39 #include "if_bwn_siba.h"
40
41 #include "if_bwnvar.h"
42
43 #define BWN_BHND_NUM_CORE_PWR   4
44
45 /**
46  * Compatiblity shim state.
47  */
48 struct bwn_bhnd_ctx {
49         device_t        chipc_dev;      /**< ChipCommon device */
50         device_t        gpio_dev;       /**< GPIO device */
51
52         device_t        pmu_dev;        /**< PMU device, or NULL if no PMU */
53         uint32_t        pmu_cctl_addr;  /**< chipctrl_addr target of
54                                              reads/writes to/from the
55                                              chipctrl_data register */
56
57         uint8_t         sromrev;        /**< SROM format revision */
58
59         /* NVRAM variables for which bwn(4) expects the bus to manage storage
60          * for (and in some cases, allow writes). */    
61         uint8_t         mac_80211bg[6]; /**< D11 unit 0 */
62         uint8_t         mac_80211a[6];  /**< D11 unit 1 */
63
64         uint32_t        boardflags;     /**< boardflags (bwn-writable) */
65         uint8_t         pa0maxpwr;      /**< 2GHz max power (bwn-writable) */
66 };
67
68 /**
69  * Return the bwn(4) device's bhnd compatiblity context.
70  */
71 static inline struct bwn_bhnd_ctx *
72 bwn_bhnd_get_ctx(device_t dev)
73 {
74         struct bwn_softc *sc = device_get_softc(dev);
75         return (sc->sc_bus_ctx);
76 }
77
78 /**
79  * Fetch an NVRAM variable via bhnd_nvram_getvar_*().
80  */
81 #define BWN_BHND_NVRAM_FETCH_VAR(_dev, _type, _name, _result)           \
82 do {                                                                    \
83         int error;                                                      \
84                                                                         \
85         error = bhnd_nvram_getvar_ ## _type(_dev, _name, _result);      \
86         if (error) {                                                    \
87                 panic("NVRAM variable %s unreadable: %d", _name,        \
88                     error);                                             \
89         }                                                               \
90 } while(0)
91
92 /**
93  * Fetch and return an NVRAM variable via bhnd_nvram_getvar_*().
94  */
95 #define BWN_BHND_NVRAM_RETURN_VAR(_dev, _type, _name)                   \
96 do {                                                                    \
97         _type ## _t     value;                                          \
98         BWN_BHND_NVRAM_FETCH_VAR(_dev, _type, _name, &value);           \
99         return (value);                                                 \
100 } while(0)
101
102 #endif /* _IF_BWN_SIBA_COMPAT_H_ */