util.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * NXP Wireless LAN device driver: utility functions
  4. *
  5. * Copyright 2011-2020 NXP
  6. */
  7. #ifndef _MWIFIEX_UTIL_H_
  8. #define _MWIFIEX_UTIL_H_
  9. struct mwifiex_private;
  10. struct mwifiex_dma_mapping {
  11. dma_addr_t addr;
  12. size_t len;
  13. };
  14. struct mwifiex_cb {
  15. struct mwifiex_dma_mapping dma_mapping;
  16. union {
  17. struct mwifiex_rxinfo rx_info;
  18. struct mwifiex_txinfo tx_info;
  19. };
  20. };
  21. /* size/addr for mwifiex_debug_info */
  22. #define item_size(n) (sizeof_field(struct mwifiex_debug_info, n))
  23. #define item_addr(n) (offsetof(struct mwifiex_debug_info, n))
  24. /* size/addr for struct mwifiex_adapter */
  25. #define adapter_item_size(n) (sizeof_field(struct mwifiex_adapter, n))
  26. #define adapter_item_addr(n) (offsetof(struct mwifiex_adapter, n))
  27. struct mwifiex_debug_data {
  28. char name[32]; /* variable/array name */
  29. u32 size; /* size of the variable/array */
  30. size_t addr; /* address of the variable/array */
  31. int num; /* number of variables in an array */
  32. };
  33. static inline struct mwifiex_rxinfo *MWIFIEX_SKB_RXCB(struct sk_buff *skb)
  34. {
  35. struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb;
  36. BUILD_BUG_ON(sizeof(struct mwifiex_cb) > sizeof(skb->cb));
  37. return &cb->rx_info;
  38. }
  39. static inline struct mwifiex_txinfo *MWIFIEX_SKB_TXCB(struct sk_buff *skb)
  40. {
  41. struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb;
  42. return &cb->tx_info;
  43. }
  44. static inline void mwifiex_store_mapping(struct sk_buff *skb,
  45. struct mwifiex_dma_mapping *mapping)
  46. {
  47. struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb;
  48. memcpy(&cb->dma_mapping, mapping, sizeof(*mapping));
  49. }
  50. static inline void mwifiex_get_mapping(struct sk_buff *skb,
  51. struct mwifiex_dma_mapping *mapping)
  52. {
  53. struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb;
  54. memcpy(mapping, &cb->dma_mapping, sizeof(*mapping));
  55. }
  56. static inline dma_addr_t MWIFIEX_SKB_DMA_ADDR(struct sk_buff *skb)
  57. {
  58. struct mwifiex_dma_mapping mapping;
  59. mwifiex_get_mapping(skb, &mapping);
  60. return mapping.addr;
  61. }
  62. int mwifiex_debug_info_to_buffer(struct mwifiex_private *priv, char *buf,
  63. struct mwifiex_debug_info *info);
  64. static inline void le16_unaligned_add_cpu(__le16 *var, u16 val)
  65. {
  66. put_unaligned_le16(get_unaligned_le16(var) + val, var);
  67. }
  68. #endif /* !_MWIFIEX_UTIL_H_ */