1 /*- 2 * Copyright (c) 2016 Adrian Chadd <adrian@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 15 * 16 * NO WARRANTY 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. 28 */ 29 30 #include <sys/cdefs.h> 31 __FBSDID("$FreeBSD$"); 32 33 /* 34 * This is the top-level N-PHY support for the Broadcom softmac driver. 35 */ 36 37 #include "opt_bwn.h" 38 #include "opt_wlan.h" 39 40 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/kernel.h> 43 #include <sys/malloc.h> 44 #include <sys/module.h> 45 #include <sys/endian.h> 46 #include <sys/errno.h> 47 #include <sys/firmware.h> 48 #include <sys/lock.h> 49 #include <sys/mutex.h> 50 #include <machine/bus.h> 51 #include <machine/resource.h> 52 #include <sys/bus.h> 53 #include <sys/rman.h> 54 #include <sys/socket.h> 55 #include <sys/sockio.h> 56 57 #include <net/ethernet.h> 58 #include <net/if.h> 59 #include <net/if_var.h> 60 #include <net/if_arp.h> 61 #include <net/if_dl.h> 62 #include <net/if_llc.h> 63 #include <net/if_media.h> 64 #include <net/if_types.h> 65 66 #include <dev/pci/pcivar.h> 67 #include <dev/pci/pcireg.h> 68 #include <dev/siba/siba_ids.h> 69 #include <dev/siba/sibareg.h> 70 #include <dev/siba/sibavar.h> 71 72 #include <net80211/ieee80211_var.h> 73 #include <net80211/ieee80211_radiotap.h> 74 #include <net80211/ieee80211_regdomain.h> 75 #include <net80211/ieee80211_phy.h> 76 #include <net80211/ieee80211_ratectl.h> 77 78 #include <dev/bwn/if_bwnreg.h> 79 #include <dev/bwn/if_bwnvar.h> 80 81 #include <dev/bwn/if_bwn_debug.h> 82 #include <dev/bwn/if_bwn_misc.h> 83 #include <dev/bwn/if_bwn_phy_n.h> 84 85 #ifdef BWN_GPL_PHY 86 #include <gnu/dev/bwn/phy_n/if_bwn_phy_n_tables.h> 87 #include <gnu/dev/bwn/phy_n/if_bwn_phy_n_ppr.h> 88 #include <gnu/dev/bwn/phy_n/if_bwn_phy_n_core.h> 89 #endif 90 91 /* 92 * This module is always compiled into the kernel, regardless of 93 * whether the GPL PHY is enabled. If the GPL PHY isn't enabled 94 * then it'll just be stubs that will fail to attach. 95 */ 96 97 int 98 bwn_phy_n_attach(struct bwn_mac *mac) 99 { 100 101 #ifdef BWN_GPL_PHY 102 return bwn_nphy_op_allocate(mac); 103 #else 104 device_printf(mac->mac_sc->sc_dev, 105 "%s: BWN_GPL_PHY not in kernel config; " 106 "no PHY-N support\n", __func__); 107 return (ENXIO); 108 #endif 109 } 110 111 void 112 bwn_phy_n_detach(struct bwn_mac *mac) 113 { 114 115 #ifdef BWN_GPL_PHY 116 return bwn_nphy_op_free(mac); 117 #endif 118 } 119 120 int 121 bwn_phy_n_prepare_hw(struct bwn_mac *mac) 122 { 123 124 #ifdef BWN_GPL_PHY 125 bwn_nphy_op_prepare_structs(mac); 126 return (0); 127 #else 128 return (ENXIO); 129 #endif 130 } 131 132 void 133 bwn_phy_n_init_pre(struct bwn_mac *mac) 134 { 135 136 /* XXX TODO */ 137 } 138 139 int 140 bwn_phy_n_init(struct bwn_mac *mac) 141 { 142 #ifdef BWN_GPL_PHY 143 return bwn_nphy_op_init(mac); 144 #else 145 return (ENXIO); 146 #endif 147 } 148 149 void 150 bwn_phy_n_exit(struct bwn_mac *mac) 151 { 152 153 /* XXX TODO */ 154 } 155 156 uint16_t 157 bwn_phy_n_read(struct bwn_mac *mac, uint16_t reg) 158 { 159 160 BWN_WRITE_2(mac, BWN_PHYCTL, reg); 161 return BWN_READ_2(mac, BWN_PHYDATA); 162 } 163 164 void 165 bwn_phy_n_write(struct bwn_mac *mac, uint16_t reg, uint16_t value) 166 { 167 168 BWN_WRITE_2(mac, BWN_PHYCTL, reg); 169 BWN_WRITE_2(mac, BWN_PHYDATA, value); 170 } 171 172 uint16_t 173 bwn_phy_n_rf_read(struct bwn_mac *mac, uint16_t reg) 174 { 175 176 /* Register 1 is a 32-bit register. */ 177 if (mac->mac_phy.rev < 7 && reg == 1) { 178 BWN_ERRPRINTF(mac->mac_sc, "%s: bad reg access\n", __func__); 179 } 180 181 if (mac->mac_phy.rev >= 7) 182 reg |= 0x200; /* radio 0x2057 */ 183 else 184 reg |= 0x100; 185 186 BWN_WRITE_2(mac, BWN_RFCTL, reg); 187 return BWN_READ_2(mac, BWN_RFDATALO); 188 } 189 190 void 191 bwn_phy_n_rf_write(struct bwn_mac *mac, uint16_t reg, uint16_t value) 192 { 193 194 /* Register 1 is a 32-bit register. */ 195 if (mac->mac_phy.rev < 7 && reg == 1) { 196 BWN_ERRPRINTF(mac->mac_sc, "%s: bad reg access\n", __func__); 197 } 198 199 BWN_WRITE_2(mac, BWN_RFCTL, reg); 200 BWN_WRITE_2(mac, BWN_RFDATALO, value); 201 } 202 203 int 204 bwn_phy_n_hwpctl(struct bwn_mac *mac) 205 { 206 207 return (0); 208 } 209 210 void 211 bwn_phy_n_rf_onoff(struct bwn_mac *mac, int on) 212 { 213 #ifdef BWN_GPL_PHY 214 bwn_nphy_op_software_rfkill(mac, on); 215 #endif 216 } 217 218 void 219 bwn_phy_n_switch_analog(struct bwn_mac *mac, int on) 220 { 221 #ifdef BWN_GPL_PHY 222 bwn_nphy_op_switch_analog(mac, on); 223 #endif 224 } 225 226 int 227 bwn_phy_n_switch_channel(struct bwn_mac *mac, uint32_t newchan) 228 { 229 #ifdef BWN_GPL_PHY 230 return bwn_nphy_op_switch_channel(mac, newchan); 231 #else 232 return (ENXIO); 233 #endif 234 } 235 236 uint32_t 237 bwn_phy_n_get_default_chan(struct bwn_mac *mac) 238 { 239 240 if (bwn_current_band(mac) == BWN_BAND_2G) 241 return (1); 242 return (36); 243 } 244 245 void 246 bwn_phy_n_set_antenna(struct bwn_mac *mac, int antenna) 247 { 248 /* XXX TODO */ 249 } 250 251 int 252 bwn_phy_n_im(struct bwn_mac *mac, int mode) 253 { 254 /* XXX TODO */ 255 return (0); 256 } 257 258 bwn_txpwr_result_t 259 bwn_phy_n_recalc_txpwr(struct bwn_mac *mac, int ignore_tssi) 260 { 261 #ifdef BWN_GPL_PHY 262 return bwn_nphy_op_recalc_txpower(mac, ignore_tssi); 263 #else 264 return (BWN_TXPWR_RES_DONE); 265 #endif 266 } 267 268 void 269 bwn_phy_n_set_txpwr(struct bwn_mac *mac) 270 { 271 272 } 273 274 void 275 bwn_phy_n_task_15s(struct bwn_mac *mac) 276 { 277 278 } 279 280 void 281 bwn_phy_n_task_60s(struct bwn_mac *mac) 282 { 283 284 } 285