util.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Marvell Wireless LAN device driver: utility functions
  3. *
  4. * Copyright (C) 2011-2014, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #ifndef _MWIFIEX_UTIL_H_
  20. #define _MWIFIEX_UTIL_H_
  21. struct mwifiex_private;
  22. struct mwifiex_dma_mapping {
  23. dma_addr_t addr;
  24. size_t len;
  25. };
  26. struct mwifiex_cb {
  27. struct mwifiex_dma_mapping dma_mapping;
  28. union {
  29. struct mwifiex_rxinfo rx_info;
  30. struct mwifiex_txinfo tx_info;
  31. };
  32. };
  33. /* size/addr for mwifiex_debug_info */
  34. #define item_size(n) (FIELD_SIZEOF(struct mwifiex_debug_info, n))
  35. #define item_addr(n) (offsetof(struct mwifiex_debug_info, n))
  36. /* size/addr for struct mwifiex_adapter */
  37. #define adapter_item_size(n) (FIELD_SIZEOF(struct mwifiex_adapter, n))
  38. #define adapter_item_addr(n) (offsetof(struct mwifiex_adapter, n))
  39. struct mwifiex_debug_data {
  40. char name[32]; /* variable/array name */
  41. u32 size; /* size of the variable/array */
  42. size_t addr; /* address of the variable/array */
  43. int num; /* number of variables in an array */
  44. };
  45. static inline struct mwifiex_rxinfo *MWIFIEX_SKB_RXCB(struct sk_buff *skb)
  46. {
  47. struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb;
  48. BUILD_BUG_ON(sizeof(struct mwifiex_cb) > sizeof(skb->cb));
  49. return &cb->rx_info;
  50. }
  51. static inline struct mwifiex_txinfo *MWIFIEX_SKB_TXCB(struct sk_buff *skb)
  52. {
  53. struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb;
  54. return &cb->tx_info;
  55. }
  56. static inline void mwifiex_store_mapping(struct sk_buff *skb,
  57. struct mwifiex_dma_mapping *mapping)
  58. {
  59. struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb;
  60. memcpy(&cb->dma_mapping, mapping, sizeof(*mapping));
  61. }
  62. static inline void mwifiex_get_mapping(struct sk_buff *skb,
  63. struct mwifiex_dma_mapping *mapping)
  64. {
  65. struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb;
  66. memcpy(mapping, &cb->dma_mapping, sizeof(*mapping));
  67. }
  68. static inline dma_addr_t MWIFIEX_SKB_DMA_ADDR(struct sk_buff *skb)
  69. {
  70. struct mwifiex_dma_mapping mapping;
  71. mwifiex_get_mapping(skb, &mapping);
  72. return mapping.addr;
  73. }
  74. int mwifiex_debug_info_to_buffer(struct mwifiex_private *priv, char *buf,
  75. struct mwifiex_debug_info *info);
  76. #endif /* !_MWIFIEX_UTIL_H_ */