WIP FPC-III support
[linux/fpc-iii.git] / drivers / staging / vt6656 / mac.c
blobda7067c34643cfe8ac747794367865b37374ad08
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
4 * All rights reserved.
6 * File: mac.c
8 * Purpose: MAC routines
10 * Author: Tevin Chen
12 * Date: May 21, 1996
14 * Functions:
16 * Revision History:
19 #include <linux/etherdevice.h>
21 #include "desc.h"
22 #include "mac.h"
23 #include "usbpipe.h"
25 int vnt_mac_set_filter(struct vnt_private *priv, u64 mc_filter)
27 __le64 le_mc = cpu_to_le64(mc_filter);
29 return vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_MAR0,
30 MESSAGE_REQUEST_MACREG, sizeof(le_mc),
31 (u8 *)&le_mc);
34 int vnt_mac_shutdown(struct vnt_private *priv)
36 return vnt_control_out(priv, MESSAGE_TYPE_MACSHUTDOWN, 0, 0, 0, NULL);
39 int vnt_mac_set_bb_type(struct vnt_private *priv, u8 type)
41 u8 data[2];
43 data[0] = type;
44 data[1] = EnCFG_BBType_MASK;
46 return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0,
47 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data),
48 data);
51 int vnt_mac_disable_keyentry(struct vnt_private *priv, u8 entry_idx)
53 return vnt_control_out(priv, MESSAGE_TYPE_CLRKEYENTRY, 0, 0,
54 sizeof(entry_idx), &entry_idx);
57 int vnt_mac_set_keyentry(struct vnt_private *priv, u16 key_ctl, u32 entry_idx,
58 u32 key_idx, u8 *addr, u8 *key)
60 struct vnt_mac_set_key set_key;
61 u16 offset;
63 offset = MISCFIFO_KEYETRY0;
64 offset += entry_idx * MISCFIFO_KEYENTRYSIZE;
66 set_key.u.write.key_ctl = cpu_to_le16(key_ctl);
67 ether_addr_copy(set_key.u.write.addr, addr);
69 /* swap over swap[0] and swap[1] to get correct write order */
70 swap(set_key.u.swap[0], set_key.u.swap[1]);
72 memcpy(set_key.key, key, WLAN_KEY_LEN_CCMP);
74 dev_dbg(&priv->usb->dev, "offset %d key ctl %d set key %24ph\n",
75 offset, key_ctl, (u8 *)&set_key);
77 return vnt_control_out(priv, MESSAGE_TYPE_SETKEY, offset,
78 (u16)key_idx, sizeof(struct vnt_mac_set_key),
79 (u8 *)&set_key);
82 int vnt_mac_reg_bits_off(struct vnt_private *priv, u8 reg_ofs, u8 bits)
84 u8 data[2];
86 data[0] = 0;
87 data[1] = bits;
89 return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, reg_ofs,
90 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
93 int vnt_mac_reg_bits_on(struct vnt_private *priv, u8 reg_ofs, u8 bits)
95 u8 data[2];
97 data[0] = bits;
98 data[1] = bits;
100 return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, reg_ofs,
101 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
104 int vnt_mac_write_word(struct vnt_private *priv, u8 reg_ofs, u16 word)
106 u8 data[2];
108 data[0] = (u8)(word & 0xff);
109 data[1] = (u8)(word >> 8);
111 return vnt_control_out(priv, MESSAGE_TYPE_WRITE, reg_ofs,
112 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
115 int vnt_mac_set_bssid_addr(struct vnt_private *priv, u8 *addr)
117 return vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_BSSID0,
118 MESSAGE_REQUEST_MACREG, ETH_ALEN, addr);
121 int vnt_mac_enable_protect_mode(struct vnt_private *priv)
123 u8 data[2];
125 data[0] = EnCFG_ProtectMd;
126 data[1] = EnCFG_ProtectMd;
128 return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0,
129 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
132 int vnt_mac_disable_protect_mode(struct vnt_private *priv)
134 u8 data[2];
136 data[0] = 0;
137 data[1] = EnCFG_ProtectMd;
139 return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0,
140 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
143 int vnt_mac_enable_barker_preamble_mode(struct vnt_private *priv)
145 u8 data[2];
147 data[0] = EnCFG_BarkerPream;
148 data[1] = EnCFG_BarkerPream;
150 return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG2,
151 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
154 int vnt_mac_disable_barker_preamble_mode(struct vnt_private *priv)
156 u8 data[2];
158 data[0] = 0;
159 data[1] = EnCFG_BarkerPream;
161 return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG2,
162 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
165 int vnt_mac_set_beacon_interval(struct vnt_private *priv, u16 interval)
167 u8 data[2];
169 data[0] = (u8)(interval & 0xff);
170 data[1] = (u8)(interval >> 8);
172 return vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_BI,
173 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
176 int vnt_mac_set_led(struct vnt_private *priv, u8 state, u8 led)
178 u8 data[2];
180 data[0] = led;
181 data[1] = state;
183 return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_PAPEDELAY,
184 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);