18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * NXP Wireless LAN device driver: utility functions
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright 2011-2020 NXP
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This software file (the "File") is distributed by NXP
78c2ecf20Sopenharmony_ci * under the terms of the GNU General Public License Version 2, June 1991
88c2ecf20Sopenharmony_ci * (the "License").  You may use, redistribute and/or modify this File in
98c2ecf20Sopenharmony_ci * accordance with the terms and conditions of the License, a copy of which
108c2ecf20Sopenharmony_ci * is available by writing to the Free Software Foundation, Inc.,
118c2ecf20Sopenharmony_ci * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
128c2ecf20Sopenharmony_ci * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
158c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
168c2ecf20Sopenharmony_ci * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
178c2ecf20Sopenharmony_ci * this warranty disclaimer.
188c2ecf20Sopenharmony_ci */
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#ifndef _MWIFIEX_UTIL_H_
218c2ecf20Sopenharmony_ci#define _MWIFIEX_UTIL_H_
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistruct mwifiex_private;
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cistruct mwifiex_dma_mapping {
268c2ecf20Sopenharmony_ci	dma_addr_t addr;
278c2ecf20Sopenharmony_ci	size_t len;
288c2ecf20Sopenharmony_ci};
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistruct mwifiex_cb {
318c2ecf20Sopenharmony_ci	struct mwifiex_dma_mapping dma_mapping;
328c2ecf20Sopenharmony_ci	union {
338c2ecf20Sopenharmony_ci		struct mwifiex_rxinfo rx_info;
348c2ecf20Sopenharmony_ci		struct mwifiex_txinfo tx_info;
358c2ecf20Sopenharmony_ci	};
368c2ecf20Sopenharmony_ci};
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/* size/addr for mwifiex_debug_info */
398c2ecf20Sopenharmony_ci#define item_size(n)		(sizeof_field(struct mwifiex_debug_info, n))
408c2ecf20Sopenharmony_ci#define item_addr(n)		(offsetof(struct mwifiex_debug_info, n))
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci/* size/addr for struct mwifiex_adapter */
438c2ecf20Sopenharmony_ci#define adapter_item_size(n)	(sizeof_field(struct mwifiex_adapter, n))
448c2ecf20Sopenharmony_ci#define adapter_item_addr(n)	(offsetof(struct mwifiex_adapter, n))
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistruct mwifiex_debug_data {
478c2ecf20Sopenharmony_ci	char name[32];		/* variable/array name */
488c2ecf20Sopenharmony_ci	u32 size;		/* size of the variable/array */
498c2ecf20Sopenharmony_ci	size_t addr;		/* address of the variable/array */
508c2ecf20Sopenharmony_ci	int num;		/* number of variables in an array */
518c2ecf20Sopenharmony_ci};
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistatic inline struct mwifiex_rxinfo *MWIFIEX_SKB_RXCB(struct sk_buff *skb)
548c2ecf20Sopenharmony_ci{
558c2ecf20Sopenharmony_ci	struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb;
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	BUILD_BUG_ON(sizeof(struct mwifiex_cb) > sizeof(skb->cb));
588c2ecf20Sopenharmony_ci	return &cb->rx_info;
598c2ecf20Sopenharmony_ci}
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cistatic inline struct mwifiex_txinfo *MWIFIEX_SKB_TXCB(struct sk_buff *skb)
628c2ecf20Sopenharmony_ci{
638c2ecf20Sopenharmony_ci	struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb;
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	return &cb->tx_info;
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistatic inline void mwifiex_store_mapping(struct sk_buff *skb,
698c2ecf20Sopenharmony_ci					 struct mwifiex_dma_mapping *mapping)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb;
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	memcpy(&cb->dma_mapping, mapping, sizeof(*mapping));
748c2ecf20Sopenharmony_ci}
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistatic inline void mwifiex_get_mapping(struct sk_buff *skb,
778c2ecf20Sopenharmony_ci				       struct mwifiex_dma_mapping *mapping)
788c2ecf20Sopenharmony_ci{
798c2ecf20Sopenharmony_ci	struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb;
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	memcpy(mapping, &cb->dma_mapping, sizeof(*mapping));
828c2ecf20Sopenharmony_ci}
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_cistatic inline dma_addr_t MWIFIEX_SKB_DMA_ADDR(struct sk_buff *skb)
858c2ecf20Sopenharmony_ci{
868c2ecf20Sopenharmony_ci	struct mwifiex_dma_mapping mapping;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	mwifiex_get_mapping(skb, &mapping);
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	return mapping.addr;
918c2ecf20Sopenharmony_ci}
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ciint mwifiex_debug_info_to_buffer(struct mwifiex_private *priv, char *buf,
948c2ecf20Sopenharmony_ci				 struct mwifiex_debug_info *info);
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_cistatic inline void le16_unaligned_add_cpu(__le16 *var, u16 val)
978c2ecf20Sopenharmony_ci{
988c2ecf20Sopenharmony_ci	put_unaligned_le16(get_unaligned_le16(var) + val, var);
998c2ecf20Sopenharmony_ci}
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci#endif /* !_MWIFIEX_UTIL_H_ */
102