Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: utility functions |
| 3 | * |
Xinming Hu | 65da33f | 2014-06-19 21:38:57 -0700 | [diff] [blame] | 4 | * Copyright (C) 2011-2014, Marvell International Ltd. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 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 | |
| 20 | #ifndef _MWIFIEX_UTIL_H_ |
| 21 | #define _MWIFIEX_UTIL_H_ |
| 22 | |
Xinming Hu | bb5097f | 2014-12-23 19:14:09 +0530 | [diff] [blame] | 23 | struct mwifiex_private; |
| 24 | |
Aaron Durbin | dbccc92b | 2014-02-07 16:25:50 -0800 | [diff] [blame] | 25 | struct mwifiex_dma_mapping { |
| 26 | dma_addr_t addr; |
| 27 | size_t len; |
| 28 | }; |
| 29 | |
Chin-Ran Lo | bca463e | 2014-06-06 19:37:10 -0700 | [diff] [blame] | 30 | struct mwifiex_cb { |
| 31 | struct mwifiex_dma_mapping dma_mapping; |
| 32 | union { |
| 33 | struct mwifiex_rxinfo rx_info; |
| 34 | struct mwifiex_txinfo tx_info; |
| 35 | }; |
| 36 | }; |
| 37 | |
Xinming Hu | bb5097f | 2014-12-23 19:14:09 +0530 | [diff] [blame] | 38 | /* size/addr for mwifiex_debug_info */ |
| 39 | #define item_size(n) (FIELD_SIZEOF(struct mwifiex_debug_info, n)) |
| 40 | #define item_addr(n) (offsetof(struct mwifiex_debug_info, n)) |
| 41 | |
| 42 | /* size/addr for struct mwifiex_adapter */ |
| 43 | #define adapter_item_size(n) (FIELD_SIZEOF(struct mwifiex_adapter, n)) |
| 44 | #define adapter_item_addr(n) (offsetof(struct mwifiex_adapter, n)) |
| 45 | |
| 46 | struct mwifiex_debug_data { |
| 47 | char name[32]; /* variable/array name */ |
| 48 | u32 size; /* size of the variable/array */ |
| 49 | size_t addr; /* address of the variable/array */ |
| 50 | int num; /* number of variables in an array */ |
| 51 | }; |
| 52 | |
Chin-Ran Lo | bca463e | 2014-06-06 19:37:10 -0700 | [diff] [blame] | 53 | static inline struct mwifiex_rxinfo *MWIFIEX_SKB_RXCB(struct sk_buff *skb) |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 54 | { |
Chin-Ran Lo | bca463e | 2014-06-06 19:37:10 -0700 | [diff] [blame] | 55 | struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb; |
| 56 | |
| 57 | BUILD_BUG_ON(sizeof(struct mwifiex_cb) > sizeof(skb->cb)); |
| 58 | return &cb->rx_info; |
| 59 | } |
| 60 | |
| 61 | static inline struct mwifiex_txinfo *MWIFIEX_SKB_TXCB(struct sk_buff *skb) |
| 62 | { |
| 63 | struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb; |
| 64 | |
| 65 | return &cb->tx_info; |
| 66 | } |
| 67 | |
| 68 | static inline void mwifiex_store_mapping(struct sk_buff *skb, |
| 69 | struct mwifiex_dma_mapping *mapping) |
| 70 | { |
| 71 | struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb; |
| 72 | |
| 73 | memcpy(&cb->dma_mapping, mapping, sizeof(*mapping)); |
| 74 | } |
| 75 | |
| 76 | static inline void mwifiex_get_mapping(struct sk_buff *skb, |
| 77 | struct mwifiex_dma_mapping *mapping) |
| 78 | { |
| 79 | struct mwifiex_cb *cb = (struct mwifiex_cb *)skb->cb; |
| 80 | |
| 81 | memcpy(mapping, &cb->dma_mapping, sizeof(*mapping)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 82 | } |
Aaron Durbin | dbccc92b | 2014-02-07 16:25:50 -0800 | [diff] [blame] | 83 | |
| 84 | static inline dma_addr_t MWIFIEX_SKB_DMA_ADDR(struct sk_buff *skb) |
| 85 | { |
| 86 | struct mwifiex_dma_mapping mapping; |
| 87 | |
Chin-Ran Lo | bca463e | 2014-06-06 19:37:10 -0700 | [diff] [blame] | 88 | mwifiex_get_mapping(skb, &mapping); |
Aaron Durbin | dbccc92b | 2014-02-07 16:25:50 -0800 | [diff] [blame] | 89 | |
| 90 | return mapping.addr; |
| 91 | } |
| 92 | |
Xinming Hu | bb5097f | 2014-12-23 19:14:09 +0530 | [diff] [blame] | 93 | int mwifiex_debug_info_to_buffer(struct mwifiex_private *priv, char *buf, |
| 94 | struct mwifiex_debug_info *info); |
| 95 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 96 | #endif /* !_MWIFIEX_UTIL_H_ */ |