gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / staging / vt6656 / mac.c
blob5cacf6e60e90b4a011f087e60b15cfb19eccf18f
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"
26 * Description:
27 * Write MAC Multicast Address Mask
29 * Parameters:
30 * In:
31 * mc_filter (mac filter)
32 * Out:
33 * none
35 * Return Value: none
38 void vnt_mac_set_filter(struct vnt_private *priv, u64 mc_filter)
40 __le64 le_mc = cpu_to_le64(mc_filter);
42 vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_MAR0,
43 MESSAGE_REQUEST_MACREG, sizeof(le_mc), (u8 *)&le_mc);
47 * Description:
48 * Shut Down MAC
50 * Parameters:
51 * In:
52 * Out:
53 * none
57 void vnt_mac_shutdown(struct vnt_private *priv)
59 vnt_control_out(priv, MESSAGE_TYPE_MACSHUTDOWN, 0, 0, 0, NULL);
62 void vnt_mac_set_bb_type(struct vnt_private *priv, u8 type)
64 u8 data[2];
66 data[0] = type;
67 data[1] = EnCFG_BBType_MASK;
69 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0,
70 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
74 * Description:
75 * Disable the Key Entry by MISCFIFO
77 * Parameters:
78 * In:
79 * dwIoBase - Base Address for MAC
81 * Out:
82 * none
84 * Return Value: none
87 void vnt_mac_disable_keyentry(struct vnt_private *priv, u8 entry_idx)
89 vnt_control_out(priv, MESSAGE_TYPE_CLRKEYENTRY, 0, 0,
90 sizeof(entry_idx), &entry_idx);
94 * Description:
95 * Set the Key by MISCFIFO
97 * Parameters:
98 * In:
99 * dwIoBase - Base Address for MAC
101 * Out:
102 * none
104 * Return Value: none
107 void vnt_mac_set_keyentry(struct vnt_private *priv, u16 key_ctl, u32 entry_idx,
108 u32 key_idx, u8 *addr, u8 *key)
110 struct vnt_mac_set_key set_key;
111 u16 offset;
113 offset = MISCFIFO_KEYETRY0;
114 offset += entry_idx * MISCFIFO_KEYENTRYSIZE;
116 set_key.u.write.key_ctl = cpu_to_le16(key_ctl);
117 ether_addr_copy(set_key.u.write.addr, addr);
119 /* swap over swap[0] and swap[1] to get correct write order */
120 swap(set_key.u.swap[0], set_key.u.swap[1]);
122 memcpy(set_key.key, key, WLAN_KEY_LEN_CCMP);
124 dev_dbg(&priv->usb->dev, "offset %d key ctl %d set key %24ph\n",
125 offset, key_ctl, (u8 *)&set_key);
127 vnt_control_out(priv, MESSAGE_TYPE_SETKEY, offset,
128 (u16)key_idx, sizeof(struct vnt_mac_set_key),
129 (u8 *)&set_key);
132 int vnt_mac_reg_bits_off(struct vnt_private *priv, u8 reg_ofs, u8 bits)
134 u8 data[2];
136 data[0] = 0;
137 data[1] = bits;
139 return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, reg_ofs,
140 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
143 int vnt_mac_reg_bits_on(struct vnt_private *priv, u8 reg_ofs, u8 bits)
145 u8 data[2];
147 data[0] = bits;
148 data[1] = bits;
150 return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, reg_ofs,
151 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
154 void vnt_mac_write_word(struct vnt_private *priv, u8 reg_ofs, u16 word)
156 u8 data[2];
158 data[0] = (u8)(word & 0xff);
159 data[1] = (u8)(word >> 8);
161 vnt_control_out(priv, MESSAGE_TYPE_WRITE, reg_ofs,
162 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
165 void vnt_mac_set_bssid_addr(struct vnt_private *priv, u8 *addr)
167 vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_BSSID0,
168 MESSAGE_REQUEST_MACREG, ETH_ALEN, addr);
171 void vnt_mac_enable_protect_mode(struct vnt_private *priv)
173 u8 data[2];
175 data[0] = EnCFG_ProtectMd;
176 data[1] = EnCFG_ProtectMd;
178 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0,
179 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
182 void vnt_mac_disable_protect_mode(struct vnt_private *priv)
184 u8 data[2];
186 data[0] = 0;
187 data[1] = EnCFG_ProtectMd;
189 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0,
190 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
193 void vnt_mac_enable_barker_preamble_mode(struct vnt_private *priv)
195 u8 data[2];
197 data[0] = EnCFG_BarkerPream;
198 data[1] = EnCFG_BarkerPream;
200 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG2,
201 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
204 void vnt_mac_disable_barker_preamble_mode(struct vnt_private *priv)
206 u8 data[2];
208 data[0] = 0;
209 data[1] = EnCFG_BarkerPream;
211 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG2,
212 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
215 void vnt_mac_set_beacon_interval(struct vnt_private *priv, u16 interval)
217 u8 data[2];
219 data[0] = (u8)(interval & 0xff);
220 data[1] = (u8)(interval >> 8);
222 vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_BI,
223 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
226 int vnt_mac_set_led(struct vnt_private *priv, u8 state, u8 led)
228 u8 data[2];
230 data[0] = led;
231 data[1] = state;
233 return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_PAPEDELAY,
234 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);