xref: /linux/drivers/net/wireless/marvell/mwifiex/util.h (revision ae22a94997b8a03dcb3c922857c203246711f9d4)
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 
8 #ifndef _MWIFIEX_UTIL_H_
9 #define _MWIFIEX_UTIL_H_
10 
11 struct mwifiex_private;
12 
13 struct mwifiex_dma_mapping {
14 	dma_addr_t addr;
15 	size_t len;
16 };
17 
18 struct mwifiex_cb {
19 	struct mwifiex_dma_mapping dma_mapping;
20 	union {
21 		struct mwifiex_rxinfo rx_info;
22 		struct mwifiex_txinfo tx_info;
23 	};
24 };
25 
26 /* size/addr for mwifiex_debug_info */
27 #define item_size(n)		(sizeof_field(struct mwifiex_debug_info, n))
28 #define item_addr(n)		(offsetof(struct mwifiex_debug_info, n))
29 
30 /* size/addr for struct mwifiex_adapter */
31 #define adapter_item_size(n)	(sizeof_field(struct mwifiex_adapter, n))
32 #define adapter_item_addr(n)	(offsetof(struct mwifiex_adapter, n))
33 
34 struct mwifiex_debug_data {
35 	char name[32];		/* variable/array name */
36 	u32 size;		/* size of the variable/array */
37 	size_t addr;		/* address of the variable/array */
38 	int num;		/* number of variables in an array */
39 };
40 
41 static inline struct mwifiex_rxinfo *MWIFIEX_SKB_RXCB(struct sk_buff *skb)
42 {
43 	struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb;
44 
45 	BUILD_BUG_ON(sizeof(struct mwifiex_cb) > sizeof(skb->cb));
46 	return &cb->rx_info;
47 }
48 
49 static inline struct mwifiex_txinfo *MWIFIEX_SKB_TXCB(struct sk_buff *skb)
50 {
51 	struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb;
52 
53 	return &cb->tx_info;
54 }
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 
61 	memcpy(&cb->dma_mapping, mapping, sizeof(*mapping));
62 }
63 
64 static inline void mwifiex_get_mapping(struct sk_buff *skb,
65 				       struct mwifiex_dma_mapping *mapping)
66 {
67 	struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb;
68 
69 	memcpy(mapping, &cb->dma_mapping, sizeof(*mapping));
70 }
71 
72 static inline dma_addr_t MWIFIEX_SKB_DMA_ADDR(struct sk_buff *skb)
73 {
74 	struct mwifiex_dma_mapping mapping;
75 
76 	mwifiex_get_mapping(skb, &mapping);
77 
78 	return mapping.addr;
79 }
80 
81 int mwifiex_debug_info_to_buffer(struct mwifiex_private *priv, char *buf,
82 				 struct mwifiex_debug_info *info);
83 
84 static inline void le16_unaligned_add_cpu(__le16 *var, u16 val)
85 {
86 	put_unaligned_le16(get_unaligned_le16(var) + val, var);
87 }
88 
89 #endif /* !_MWIFIEX_UTIL_H_ */
90