mac.c 5.4 KB

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