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 "desc.h"
34 #include "mac.h"
35 #include "usbpipe.h"
36
37 /*
38 * Description:
39 * Write MAC Multicast Address Mask
40 *
41 * Parameters:
42 * In:
43 * mc_filter (mac filter)
44 * Out:
45 * none
46 *
47 * Return Value: none
48 *
49 */
vnt_mac_set_filter(struct vnt_private * priv,u64 mc_filter)50 void vnt_mac_set_filter(struct vnt_private *priv, u64 mc_filter)
51 {
52 __le64 le_mc = cpu_to_le64(mc_filter);
53
54 vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_MAR0,
55 MESSAGE_REQUEST_MACREG, sizeof(le_mc), (u8 *)&le_mc);
56 }
57
58 /*
59 * Description:
60 * Shut Down MAC
61 *
62 * Parameters:
63 * In:
64 * Out:
65 * none
66 *
67 *
68 */
vnt_mac_shutdown(struct vnt_private * priv)69 void vnt_mac_shutdown(struct vnt_private *priv)
70 {
71 vnt_control_out(priv, MESSAGE_TYPE_MACSHUTDOWN, 0, 0, 0, NULL);
72 }
73
vnt_mac_set_bb_type(struct vnt_private * priv,u8 type)74 void vnt_mac_set_bb_type(struct vnt_private *priv, u8 type)
75 {
76 u8 data[2];
77
78 data[0] = type;
79 data[1] = EnCFG_BBType_MASK;
80
81 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0,
82 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
83 }
84
85 /*
86 * Description:
87 * Disable the Key Entry by MISCFIFO
88 *
89 * Parameters:
90 * In:
91 * dwIoBase - Base Address for MAC
92 *
93 * Out:
94 * none
95 *
96 * Return Value: none
97 *
98 */
vnt_mac_disable_keyentry(struct vnt_private * priv,u8 entry_idx)99 void vnt_mac_disable_keyentry(struct vnt_private *priv, u8 entry_idx)
100 {
101 vnt_control_out(priv, MESSAGE_TYPE_CLRKEYENTRY, 0, 0,
102 sizeof(entry_idx), &entry_idx);
103 }
104
105 /*
106 * Description:
107 * Set the Key by MISCFIFO
108 *
109 * Parameters:
110 * In:
111 * dwIoBase - Base Address for MAC
112 *
113 * Out:
114 * none
115 *
116 * Return Value: none
117 *
118 */
vnt_mac_set_keyentry(struct vnt_private * priv,u16 key_ctl,u32 entry_idx,u32 key_idx,u8 * addr,u8 * key)119 void vnt_mac_set_keyentry(struct vnt_private *priv, u16 key_ctl, u32 entry_idx,
120 u32 key_idx, u8 *addr, u8 *key)
121 {
122 struct vnt_mac_set_key set_key;
123 u16 offset;
124
125 offset = MISCFIFO_KEYETRY0;
126 offset += (entry_idx * MISCFIFO_KEYENTRYSIZE);
127
128 set_key.u.write.key_ctl = cpu_to_le16(key_ctl);
129 memcpy(set_key.u.write.addr, addr, ETH_ALEN);
130
131 /* swap over swap[0] and swap[1] to get correct write order */
132 swap(set_key.u.swap[0], set_key.u.swap[1]);
133
134 memcpy(set_key.key, key, WLAN_KEY_LEN_CCMP);
135
136 dev_dbg(&priv->usb->dev, "offset %d key ctl %d set key %24ph\n",
137 offset, key_ctl, (u8 *)&set_key);
138
139 vnt_control_out(priv, MESSAGE_TYPE_SETKEY, offset,
140 (u16)key_idx, sizeof(struct vnt_mac_set_key), (u8 *)&set_key);
141 }
142
vnt_mac_reg_bits_off(struct vnt_private * priv,u8 reg_ofs,u8 bits)143 void vnt_mac_reg_bits_off(struct vnt_private *priv, u8 reg_ofs, u8 bits)
144 {
145 u8 data[2];
146
147 data[0] = 0;
148 data[1] = bits;
149
150 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK,
151 reg_ofs, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
152 }
153
vnt_mac_reg_bits_on(struct vnt_private * priv,u8 reg_ofs,u8 bits)154 void vnt_mac_reg_bits_on(struct vnt_private *priv, u8 reg_ofs, u8 bits)
155 {
156 u8 data[2];
157
158 data[0] = bits;
159 data[1] = bits;
160
161 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK,
162 reg_ofs, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
163 }
164
vnt_mac_write_word(struct vnt_private * priv,u8 reg_ofs,u16 word)165 void vnt_mac_write_word(struct vnt_private *priv, u8 reg_ofs, u16 word)
166 {
167 u8 data[2];
168
169 data[0] = (u8)(word & 0xff);
170 data[1] = (u8)(word >> 8);
171
172 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
173 reg_ofs, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
174 }
175
vnt_mac_set_bssid_addr(struct vnt_private * priv,u8 * addr)176 void vnt_mac_set_bssid_addr(struct vnt_private *priv, u8 *addr)
177 {
178 vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_BSSID0,
179 MESSAGE_REQUEST_MACREG, ETH_ALEN, addr);
180 }
181
vnt_mac_enable_protect_mode(struct vnt_private * priv)182 void vnt_mac_enable_protect_mode(struct vnt_private *priv)
183 {
184 u8 data[2];
185
186 data[0] = EnCFG_ProtectMd;
187 data[1] = EnCFG_ProtectMd;
188
189 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK,
190 MAC_REG_ENCFG0, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
191 }
192
vnt_mac_disable_protect_mode(struct vnt_private * priv)193 void vnt_mac_disable_protect_mode(struct vnt_private *priv)
194 {
195 u8 data[2];
196
197 data[0] = 0;
198 data[1] = EnCFG_ProtectMd;
199
200 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK,
201 MAC_REG_ENCFG0, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
202 }
203
vnt_mac_enable_barker_preamble_mode(struct vnt_private * priv)204 void vnt_mac_enable_barker_preamble_mode(struct vnt_private *priv)
205 {
206 u8 data[2];
207
208 data[0] = EnCFG_BarkerPream;
209 data[1] = EnCFG_BarkerPream;
210
211 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK,
212 MAC_REG_ENCFG2, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
213 }
214
vnt_mac_disable_barker_preamble_mode(struct vnt_private * priv)215 void vnt_mac_disable_barker_preamble_mode(struct vnt_private *priv)
216 {
217 u8 data[2];
218
219 data[0] = 0;
220 data[1] = EnCFG_BarkerPream;
221
222 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK,
223 MAC_REG_ENCFG2, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
224 }
225
vnt_mac_set_beacon_interval(struct vnt_private * priv,u16 interval)226 void vnt_mac_set_beacon_interval(struct vnt_private *priv, u16 interval)
227 {
228 u8 data[2];
229
230 data[0] = (u8)(interval & 0xff);
231 data[1] = (u8)(interval >> 8);
232
233 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
234 MAC_REG_BI, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
235 }
236
vnt_mac_set_led(struct vnt_private * priv,u8 state,u8 led)237 void vnt_mac_set_led(struct vnt_private *priv, u8 state, u8 led)
238 {
239 u8 data[2];
240
241 data[0] = led;
242 data[1] = state;
243
244 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_PAPEDELAY,
245 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
246 }
247