1 /*
2  * Copyright (c) 2013 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 #ifndef BRCMFMAC_PROTO_H
17 #define BRCMFMAC_PROTO_H
18 
19 
20 enum proto_addr_mode {
21 	ADDR_INDIRECT	= 0,
22 	ADDR_DIRECT
23 };
24 
25 struct brcmf_skb_reorder_data {
26 	u8 *reorder;
27 };
28 
29 struct brcmf_proto {
30 	int (*hdrpull)(struct brcmf_pub *drvr, bool do_fws,
31 		       struct sk_buff *skb, struct brcmf_if **ifp);
32 	int (*query_dcmd)(struct brcmf_pub *drvr, int ifidx, uint cmd,
33 			  void *buf, uint len);
34 	int (*set_dcmd)(struct brcmf_pub *drvr, int ifidx, uint cmd, void *buf,
35 			uint len);
36 	int (*txdata)(struct brcmf_pub *drvr, int ifidx, u8 offset,
37 		      struct sk_buff *skb);
38 	void (*configure_addr_mode)(struct brcmf_pub *drvr, int ifidx,
39 				    enum proto_addr_mode addr_mode);
40 	void (*delete_peer)(struct brcmf_pub *drvr, int ifidx,
41 			    u8 peer[ETH_ALEN]);
42 	void (*add_tdls_peer)(struct brcmf_pub *drvr, int ifidx,
43 			      u8 peer[ETH_ALEN]);
44 	void (*rxreorder)(struct brcmf_if *ifp, struct sk_buff *skb);
45 	void *pd;
46 };
47 
48 
49 int brcmf_proto_attach(struct brcmf_pub *drvr);
50 void brcmf_proto_detach(struct brcmf_pub *drvr);
51 
52 static inline int brcmf_proto_hdrpull(struct brcmf_pub *drvr, bool do_fws,
53 				      struct sk_buff *skb,
54 				      struct brcmf_if **ifp)
55 {
56 	struct brcmf_if *tmp = NULL;
57 
58 	/* assure protocol is always called with
59 	 * non-null initialized pointer.
60 	 */
61 	if (ifp)
62 		*ifp = NULL;
63 	else
64 		ifp = &tmp;
65 	return drvr->proto->hdrpull(drvr, do_fws, skb, ifp);
66 }
67 static inline int brcmf_proto_query_dcmd(struct brcmf_pub *drvr, int ifidx,
68 					 uint cmd, void *buf, uint len)
69 {
70 	return drvr->proto->query_dcmd(drvr, ifidx, cmd, buf, len);
71 }
72 static inline int brcmf_proto_set_dcmd(struct brcmf_pub *drvr, int ifidx,
73 				       uint cmd, void *buf, uint len)
74 {
75 	return drvr->proto->set_dcmd(drvr, ifidx, cmd, buf, len);
76 }
77 static inline int brcmf_proto_txdata(struct brcmf_pub *drvr, int ifidx,
78 				     u8 offset, struct sk_buff *skb)
79 {
80 	return drvr->proto->txdata(drvr, ifidx, offset, skb);
81 }
82 static inline void
83 brcmf_proto_configure_addr_mode(struct brcmf_pub *drvr, int ifidx,
84 				enum proto_addr_mode addr_mode)
85 {
86 	drvr->proto->configure_addr_mode(drvr, ifidx, addr_mode);
87 }
88 static inline void
89 brcmf_proto_delete_peer(struct brcmf_pub *drvr, int ifidx, u8 peer[ETH_ALEN])
90 {
91 	drvr->proto->delete_peer(drvr, ifidx, peer);
92 }
93 static inline void
94 brcmf_proto_add_tdls_peer(struct brcmf_pub *drvr, int ifidx, u8 peer[ETH_ALEN])
95 {
96 	drvr->proto->add_tdls_peer(drvr, ifidx, peer);
97 }
98 static inline bool brcmf_proto_is_reorder_skb(struct sk_buff *skb)
99 {
100 	struct brcmf_skb_reorder_data *rd;
101 
102 	rd = (struct brcmf_skb_reorder_data *)skb->cb;
103 	return !!rd->reorder;
104 }
105 
106 static inline void
107 brcmf_proto_rxreorder(struct brcmf_if *ifp, struct sk_buff *skb)
108 {
109 	ifp->drvr->proto->rxreorder(ifp, skb);
110 }
111 
112 #endif /* BRCMFMAC_PROTO_H */
113