1/* 2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * All rights reserved. 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * 20 * File: mac.c 21 * 22 * Purpose: MAC routines 23 * 24 * Author: Tevin Chen 25 * 26 * Date: May 21, 1996 27 * 28 * Functions: 29 * 30 * Revision History: 31 */ 32 33#include <linux/etherdevice.h> 34 35#include "desc.h" 36#include "mac.h" 37#include "usbpipe.h" 38 39/* 40 * Description: 41 * Write MAC Multicast Address Mask 42 * 43 * Parameters: 44 * In: 45 * mc_filter (mac filter) 46 * Out: 47 * none 48 * 49 * Return Value: none 50 * 51 */ 52void vnt_mac_set_filter(struct vnt_private *priv, u64 mc_filter) 53{ 54 __le64 le_mc = cpu_to_le64(mc_filter); 55 56 vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_MAR0, 57 MESSAGE_REQUEST_MACREG, sizeof(le_mc), (u8 *)&le_mc); 58} 59 60/* 61 * Description: 62 * Shut Down MAC 63 * 64 * Parameters: 65 * In: 66 * Out: 67 * none 68 * 69 * 70 */ 71void vnt_mac_shutdown(struct vnt_private *priv) 72{ 73 vnt_control_out(priv, MESSAGE_TYPE_MACSHUTDOWN, 0, 0, 0, NULL); 74} 75 76void vnt_mac_set_bb_type(struct vnt_private *priv, u8 type) 77{ 78 u8 data[2]; 79 80 data[0] = type; 81 data[1] = EnCFG_BBType_MASK; 82 83 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0, 84 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 85} 86 87/* 88 * Description: 89 * Disable the Key Entry by MISCFIFO 90 * 91 * Parameters: 92 * In: 93 * dwIoBase - Base Address for MAC 94 * 95 * Out: 96 * none 97 * 98 * Return Value: none 99 * 100 */ 101void vnt_mac_disable_keyentry(struct vnt_private *priv, u8 entry_idx) 102{ 103 vnt_control_out(priv, MESSAGE_TYPE_CLRKEYENTRY, 0, 0, 104 sizeof(entry_idx), &entry_idx); 105} 106 107/* 108 * Description: 109 * Set the Key by MISCFIFO 110 * 111 * Parameters: 112 * In: 113 * dwIoBase - Base Address for MAC 114 * 115 * Out: 116 * none 117 * 118 * Return Value: none 119 * 120 */ 121void vnt_mac_set_keyentry(struct vnt_private *priv, u16 key_ctl, u32 entry_idx, 122 u32 key_idx, u8 *addr, u8 *key) 123{ 124 struct vnt_mac_set_key set_key; 125 u16 offset; 126 127 offset = MISCFIFO_KEYETRY0; 128 offset += (entry_idx * MISCFIFO_KEYENTRYSIZE); 129 130 set_key.u.write.key_ctl = cpu_to_le16(key_ctl); 131 ether_addr_copy(set_key.u.write.addr, addr); 132 133 /* swap over swap[0] and swap[1] to get correct write order */ 134 swap(set_key.u.swap[0], set_key.u.swap[1]); 135 136 memcpy(set_key.key, key, WLAN_KEY_LEN_CCMP); 137 138 dev_dbg(&priv->usb->dev, "offset %d key ctl %d set key %24ph\n", 139 offset, key_ctl, (u8 *)&set_key); 140 141 vnt_control_out(priv, MESSAGE_TYPE_SETKEY, offset, 142 (u16)key_idx, sizeof(struct vnt_mac_set_key), (u8 *)&set_key); 143} 144 145void vnt_mac_reg_bits_off(struct vnt_private *priv, u8 reg_ofs, u8 bits) 146{ 147 u8 data[2]; 148 149 data[0] = 0; 150 data[1] = bits; 151 152 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, 153 reg_ofs, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 154} 155 156void vnt_mac_reg_bits_on(struct vnt_private *priv, u8 reg_ofs, u8 bits) 157{ 158 u8 data[2]; 159 160 data[0] = bits; 161 data[1] = bits; 162 163 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, 164 reg_ofs, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 165} 166 167void vnt_mac_write_word(struct vnt_private *priv, u8 reg_ofs, u16 word) 168{ 169 u8 data[2]; 170 171 data[0] = (u8)(word & 0xff); 172 data[1] = (u8)(word >> 8); 173 174 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 175 reg_ofs, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 176} 177 178void vnt_mac_set_bssid_addr(struct vnt_private *priv, u8 *addr) 179{ 180 vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_BSSID0, 181 MESSAGE_REQUEST_MACREG, ETH_ALEN, addr); 182} 183 184void vnt_mac_enable_protect_mode(struct vnt_private *priv) 185{ 186 u8 data[2]; 187 188 data[0] = EnCFG_ProtectMd; 189 data[1] = EnCFG_ProtectMd; 190 191 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, 192 MAC_REG_ENCFG0, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 193} 194 195void vnt_mac_disable_protect_mode(struct vnt_private *priv) 196{ 197 u8 data[2]; 198 199 data[0] = 0; 200 data[1] = EnCFG_ProtectMd; 201 202 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, 203 MAC_REG_ENCFG0, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 204} 205 206void vnt_mac_enable_barker_preamble_mode(struct vnt_private *priv) 207{ 208 u8 data[2]; 209 210 data[0] = EnCFG_BarkerPream; 211 data[1] = EnCFG_BarkerPream; 212 213 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, 214 MAC_REG_ENCFG2, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 215} 216 217void vnt_mac_disable_barker_preamble_mode(struct vnt_private *priv) 218{ 219 u8 data[2]; 220 221 data[0] = 0; 222 data[1] = EnCFG_BarkerPream; 223 224 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, 225 MAC_REG_ENCFG2, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 226} 227 228void vnt_mac_set_beacon_interval(struct vnt_private *priv, u16 interval) 229{ 230 u8 data[2]; 231 232 data[0] = (u8)(interval & 0xff); 233 data[1] = (u8)(interval >> 8); 234 235 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 236 MAC_REG_BI, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 237} 238 239void vnt_mac_set_led(struct vnt_private *priv, u8 state, u8 led) 240{ 241 u8 data[2]; 242 243 data[0] = led; 244 data[1] = state; 245 246 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_PAPEDELAY, 247 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 248} 249