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