linux/drivers/staging/vt6656/mac.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2/*
   3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
   4 * All rights reserved.
   5 *
   6 * File: mac.c
   7 *
   8 * Purpose:  MAC routines
   9 *
  10 * Author: Tevin Chen
  11 *
  12 * Date: May 21, 1996
  13 *
  14 * Functions:
  15 *
  16 * Revision History:
  17 */
  18
  19#include <linux/etherdevice.h>
  20
  21#include "desc.h"
  22#include "mac.h"
  23#include "usbpipe.h"
  24
  25int vnt_mac_set_filter(struct vnt_private *priv, u64 mc_filter)
  26{
  27        __le64 le_mc = cpu_to_le64(mc_filter);
  28
  29        return vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_MAR0,
  30                               MESSAGE_REQUEST_MACREG, sizeof(le_mc),
  31                               (u8 *)&le_mc);
  32}
  33
  34int vnt_mac_shutdown(struct vnt_private *priv)
  35{
  36        return vnt_control_out(priv, MESSAGE_TYPE_MACSHUTDOWN, 0, 0, 0, NULL);
  37}
  38
  39int vnt_mac_set_bb_type(struct vnt_private *priv, u8 type)
  40{
  41        u8 data[2];
  42
  43        data[0] = type;
  44        data[1] = EnCFG_BBType_MASK;
  45
  46        return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0,
  47                               MESSAGE_REQUEST_MACREG,  ARRAY_SIZE(data),
  48                               data);
  49}
  50
  51int vnt_mac_disable_keyentry(struct vnt_private *priv, u8 entry_idx)
  52{
  53        return vnt_control_out(priv, MESSAGE_TYPE_CLRKEYENTRY, 0, 0,
  54                               sizeof(entry_idx), &entry_idx);
  55}
  56
  57int vnt_mac_set_keyentry(struct vnt_private *priv, u16 key_ctl, u32 entry_idx,
  58                         u32 key_idx, u8 *addr, u8 *key)
  59{
  60        struct vnt_mac_set_key set_key;
  61        u16 offset;
  62
  63        offset = MISCFIFO_KEYETRY0;
  64        offset += entry_idx * MISCFIFO_KEYENTRYSIZE;
  65
  66        set_key.u.write.key_ctl = cpu_to_le16(key_ctl);
  67        ether_addr_copy(set_key.u.write.addr, addr);
  68
  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]);
  71
  72        memcpy(set_key.key, key, WLAN_KEY_LEN_CCMP);
  73
  74        dev_dbg(&priv->usb->dev, "offset %d key ctl %d set key %24ph\n",
  75                offset, key_ctl, (u8 *)&set_key);
  76
  77        return vnt_control_out(priv, MESSAGE_TYPE_SETKEY, offset,
  78                               (u16)key_idx, sizeof(struct vnt_mac_set_key),
  79                               (u8 *)&set_key);
  80}
  81
  82int vnt_mac_reg_bits_off(struct vnt_private *priv, u8 reg_ofs, u8 bits)
  83{
  84        u8 data[2];
  85
  86        data[0] = 0;
  87        data[1] = bits;
  88
  89        return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, reg_ofs,
  90                               MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  91}
  92
  93int vnt_mac_reg_bits_on(struct vnt_private *priv, u8 reg_ofs, u8 bits)
  94{
  95        u8 data[2];
  96
  97        data[0] = bits;
  98        data[1] = bits;
  99
 100        return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, reg_ofs,
 101                               MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
 102}
 103
 104int vnt_mac_write_word(struct vnt_private *priv, u8 reg_ofs, u16 word)
 105{
 106        u8 data[2];
 107
 108        data[0] = (u8)(word & 0xff);
 109        data[1] = (u8)(word >> 8);
 110
 111        return vnt_control_out(priv, MESSAGE_TYPE_WRITE, reg_ofs,
 112                               MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
 113}
 114
 115int vnt_mac_set_bssid_addr(struct vnt_private *priv, u8 *addr)
 116{
 117        return vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_BSSID0,
 118                               MESSAGE_REQUEST_MACREG, ETH_ALEN, addr);
 119}
 120
 121int vnt_mac_enable_protect_mode(struct vnt_private *priv)
 122{
 123        u8 data[2];
 124
 125        data[0] = EnCFG_ProtectMd;
 126        data[1] = EnCFG_ProtectMd;
 127
 128        return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0,
 129                               MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
 130}
 131
 132int vnt_mac_disable_protect_mode(struct vnt_private *priv)
 133{
 134        u8 data[2];
 135
 136        data[0] = 0;
 137        data[1] = EnCFG_ProtectMd;
 138
 139        return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0,
 140                               MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
 141}
 142
 143int vnt_mac_enable_barker_preamble_mode(struct vnt_private *priv)
 144{
 145        u8 data[2];
 146
 147        data[0] = EnCFG_BarkerPream;
 148        data[1] = EnCFG_BarkerPream;
 149
 150        return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG2,
 151                               MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
 152}
 153
 154int vnt_mac_disable_barker_preamble_mode(struct vnt_private *priv)
 155{
 156        u8 data[2];
 157
 158        data[0] = 0;
 159        data[1] = EnCFG_BarkerPream;
 160
 161        return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG2,
 162                               MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
 163}
 164
 165int vnt_mac_set_beacon_interval(struct vnt_private *priv, u16 interval)
 166{
 167        u8 data[2];
 168
 169        data[0] = (u8)(interval & 0xff);
 170        data[1] = (u8)(interval >> 8);
 171
 172        return vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_BI,
 173                               MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
 174}
 175
 176int vnt_mac_set_led(struct vnt_private *priv, u8 state, u8 led)
 177{
 178        u8 data[2];
 179
 180        data[0] = led;
 181        data[1] = state;
 182
 183        return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_PAPEDELAY,
 184                               MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
 185}
 186