dma.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
  3. * Copyright (C) 2015 Jakub Kicinski <kubakici@wp.pl>
  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 version 2
  7. * as published by the Free Software Foundation
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef __MT7601U_DMA_H
  15. #define __MT7601U_DMA_H
  16. #include <asm/unaligned.h>
  17. #include <linux/skbuff.h>
  18. #include "util.h"
  19. #define MT_DMA_HDR_LEN 4
  20. #define MT_RX_INFO_LEN 4
  21. #define MT_FCE_INFO_LEN 4
  22. #define MT_DMA_HDRS (MT_DMA_HDR_LEN + MT_RX_INFO_LEN)
  23. /* Common Tx DMA descriptor fields */
  24. #define MT_TXD_INFO_LEN GENMASK(15, 0)
  25. #define MT_TXD_INFO_D_PORT GENMASK(29, 27)
  26. #define MT_TXD_INFO_TYPE GENMASK(31, 30)
  27. enum mt76_msg_port {
  28. WLAN_PORT,
  29. CPU_RX_PORT,
  30. CPU_TX_PORT,
  31. HOST_PORT,
  32. VIRTUAL_CPU_RX_PORT,
  33. VIRTUAL_CPU_TX_PORT,
  34. DISCARD,
  35. };
  36. enum mt76_info_type {
  37. DMA_PACKET,
  38. DMA_COMMAND,
  39. };
  40. /* Tx DMA packet specific flags */
  41. #define MT_TXD_PKT_INFO_NEXT_VLD BIT(16)
  42. #define MT_TXD_PKT_INFO_TX_BURST BIT(17)
  43. #define MT_TXD_PKT_INFO_80211 BIT(19)
  44. #define MT_TXD_PKT_INFO_TSO BIT(20)
  45. #define MT_TXD_PKT_INFO_CSO BIT(21)
  46. #define MT_TXD_PKT_INFO_WIV BIT(24)
  47. #define MT_TXD_PKT_INFO_QSEL GENMASK(26, 25)
  48. enum mt76_qsel {
  49. MT_QSEL_MGMT,
  50. MT_QSEL_HCCA,
  51. MT_QSEL_EDCA,
  52. MT_QSEL_EDCA_2,
  53. };
  54. /* Tx DMA MCU command specific flags */
  55. #define MT_TXD_CMD_INFO_SEQ GENMASK(19, 16)
  56. #define MT_TXD_CMD_INFO_TYPE GENMASK(26, 20)
  57. static inline int mt7601u_dma_skb_wrap(struct sk_buff *skb,
  58. enum mt76_msg_port d_port,
  59. enum mt76_info_type type, u32 flags)
  60. {
  61. u32 info;
  62. /* Buffer layout:
  63. * | 4B | xfer len | pad | 4B |
  64. * | TXINFO | pkt/cmd | zero pad to 4B | zero |
  65. *
  66. * length field of TXINFO should be set to 'xfer len'.
  67. */
  68. info = flags |
  69. MT76_SET(MT_TXD_INFO_LEN, round_up(skb->len, 4)) |
  70. MT76_SET(MT_TXD_INFO_D_PORT, d_port) |
  71. MT76_SET(MT_TXD_INFO_TYPE, type);
  72. put_unaligned_le32(info, skb_push(skb, sizeof(info)));
  73. return skb_put_padto(skb, round_up(skb->len, 4) + 4);
  74. }
  75. static inline int
  76. mt7601u_dma_skb_wrap_pkt(struct sk_buff *skb, enum mt76_qsel qsel, u32 flags)
  77. {
  78. flags |= MT76_SET(MT_TXD_PKT_INFO_QSEL, qsel);
  79. return mt7601u_dma_skb_wrap(skb, WLAN_PORT, DMA_PACKET, flags);
  80. }
  81. /* Common Rx DMA descriptor fields */
  82. #define MT_RXD_INFO_LEN GENMASK(13, 0)
  83. #define MT_RXD_INFO_PCIE_INTR BIT(24)
  84. #define MT_RXD_INFO_QSEL GENMASK(26, 25)
  85. #define MT_RXD_INFO_PORT GENMASK(29, 27)
  86. #define MT_RXD_INFO_TYPE GENMASK(31, 30)
  87. /* Rx DMA packet specific flags */
  88. #define MT_RXD_PKT_INFO_UDP_ERR BIT(16)
  89. #define MT_RXD_PKT_INFO_TCP_ERR BIT(17)
  90. #define MT_RXD_PKT_INFO_IP_ERR BIT(18)
  91. #define MT_RXD_PKT_INFO_PKT_80211 BIT(19)
  92. #define MT_RXD_PKT_INFO_L3L4_DONE BIT(20)
  93. #define MT_RXD_PKT_INFO_MAC_LEN GENMASK(23, 21)
  94. /* Rx DMA MCU command specific flags */
  95. #define MT_RXD_CMD_INFO_SELF_GEN BIT(15)
  96. #define MT_RXD_CMD_INFO_CMD_SEQ GENMASK(19, 16)
  97. #define MT_RXD_CMD_INFO_EVT_TYPE GENMASK(23, 20)
  98. enum mt76_evt_type {
  99. CMD_DONE,
  100. CMD_ERROR,
  101. CMD_RETRY,
  102. EVENT_PWR_RSP,
  103. EVENT_WOW_RSP,
  104. EVENT_CARRIER_DETECT_RSP,
  105. EVENT_DFS_DETECT_RSP,
  106. };
  107. #endif