mac.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. #include <linux/etherdevice.h>
  19. #include "desc.h"
  20. #include "mac.h"
  21. #include "usbpipe.h"
  22. /*
  23. * Description:
  24. * Write MAC Multicast Address Mask
  25. *
  26. * Parameters:
  27. * In:
  28. * mc_filter (mac filter)
  29. * Out:
  30. * none
  31. *
  32. * Return Value: none
  33. *
  34. */
  35. void vnt_mac_set_filter(struct vnt_private *priv, u64 mc_filter)
  36. {
  37. __le64 le_mc = cpu_to_le64(mc_filter);
  38. vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_MAR0,
  39. MESSAGE_REQUEST_MACREG, sizeof(le_mc), (u8 *)&le_mc);
  40. }
  41. /*
  42. * Description:
  43. * Shut Down MAC
  44. *
  45. * Parameters:
  46. * In:
  47. * Out:
  48. * none
  49. *
  50. *
  51. */
  52. void vnt_mac_shutdown(struct vnt_private *priv)
  53. {
  54. vnt_control_out(priv, MESSAGE_TYPE_MACSHUTDOWN, 0, 0, 0, NULL);
  55. }
  56. void vnt_mac_set_bb_type(struct vnt_private *priv, u8 type)
  57. {
  58. u8 data[2];
  59. data[0] = type;
  60. data[1] = EnCFG_BBType_MASK;
  61. vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0,
  62. MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  63. }
  64. /*
  65. * Description:
  66. * Disable the Key Entry by MISCFIFO
  67. *
  68. * Parameters:
  69. * In:
  70. * dwIoBase - Base Address for MAC
  71. *
  72. * Out:
  73. * none
  74. *
  75. * Return Value: none
  76. *
  77. */
  78. void vnt_mac_disable_keyentry(struct vnt_private *priv, u8 entry_idx)
  79. {
  80. vnt_control_out(priv, MESSAGE_TYPE_CLRKEYENTRY, 0, 0,
  81. sizeof(entry_idx), &entry_idx);
  82. }
  83. /*
  84. * Description:
  85. * Set the Key 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_set_keyentry(struct vnt_private *priv, u16 key_ctl, u32 entry_idx,
  98. u32 key_idx, u8 *addr, u8 *key)
  99. {
  100. struct vnt_mac_set_key set_key;
  101. u16 offset;
  102. offset = MISCFIFO_KEYETRY0;
  103. offset += entry_idx * MISCFIFO_KEYENTRYSIZE;
  104. set_key.u.write.key_ctl = cpu_to_le16(key_ctl);
  105. ether_addr_copy(set_key.u.write.addr, addr);
  106. /* swap over swap[0] and swap[1] to get correct write order */
  107. swap(set_key.u.swap[0], set_key.u.swap[1]);
  108. memcpy(set_key.key, key, WLAN_KEY_LEN_CCMP);
  109. dev_dbg(&priv->usb->dev, "offset %d key ctl %d set key %24ph\n",
  110. offset, key_ctl, (u8 *)&set_key);
  111. vnt_control_out(priv, MESSAGE_TYPE_SETKEY, offset,
  112. (u16)key_idx, sizeof(struct vnt_mac_set_key),
  113. (u8 *)&set_key);
  114. }
  115. void vnt_mac_reg_bits_off(struct vnt_private *priv, u8 reg_ofs, u8 bits)
  116. {
  117. u8 data[2];
  118. data[0] = 0;
  119. data[1] = bits;
  120. vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK,
  121. reg_ofs, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data),
  122. data);
  123. }
  124. void vnt_mac_reg_bits_on(struct vnt_private *priv, u8 reg_ofs, u8 bits)
  125. {
  126. u8 data[2];
  127. data[0] = bits;
  128. data[1] = bits;
  129. vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, reg_ofs,
  130. MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  131. }
  132. void vnt_mac_write_word(struct vnt_private *priv, u8 reg_ofs, u16 word)
  133. {
  134. u8 data[2];
  135. data[0] = (u8)(word & 0xff);
  136. data[1] = (u8)(word >> 8);
  137. vnt_control_out(priv, MESSAGE_TYPE_WRITE, reg_ofs,
  138. MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  139. }
  140. void vnt_mac_set_bssid_addr(struct vnt_private *priv, u8 *addr)
  141. {
  142. vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_BSSID0,
  143. MESSAGE_REQUEST_MACREG, ETH_ALEN, addr);
  144. }
  145. void vnt_mac_enable_protect_mode(struct vnt_private *priv)
  146. {
  147. u8 data[2];
  148. data[0] = EnCFG_ProtectMd;
  149. data[1] = EnCFG_ProtectMd;
  150. vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0,
  151. MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  152. }
  153. void vnt_mac_disable_protect_mode(struct vnt_private *priv)
  154. {
  155. u8 data[2];
  156. data[0] = 0;
  157. data[1] = EnCFG_ProtectMd;
  158. vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0,
  159. MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  160. }
  161. void vnt_mac_enable_barker_preamble_mode(struct vnt_private *priv)
  162. {
  163. u8 data[2];
  164. data[0] = EnCFG_BarkerPream;
  165. data[1] = EnCFG_BarkerPream;
  166. vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG2,
  167. MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  168. }
  169. void vnt_mac_disable_barker_preamble_mode(struct vnt_private *priv)
  170. {
  171. u8 data[2];
  172. data[0] = 0;
  173. data[1] = EnCFG_BarkerPream;
  174. vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG2,
  175. MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  176. }
  177. void vnt_mac_set_beacon_interval(struct vnt_private *priv, u16 interval)
  178. {
  179. u8 data[2];
  180. data[0] = (u8)(interval & 0xff);
  181. data[1] = (u8)(interval >> 8);
  182. vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_BI,
  183. MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  184. }
  185. void vnt_mac_set_led(struct vnt_private *priv, u8 state, u8 led)
  186. {
  187. u8 data[2];
  188. data[0] = led;
  189. data[1] = state;
  190. vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_PAPEDELAY,
  191. MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  192. }