1 // SPDX-License-Identifier: ISC
2 /*
3  * Copyright (c) 2013 Broadcom Corporation
4  */
5 #ifndef BRCMFMAC_PROTO_H
6 #define BRCMFMAC_PROTO_H
7 
8 
9 enum proto_addr_mode {
10 	ADDR_INDIRECT	= 0,
11 	ADDR_DIRECT
12 };
13 
14 struct brcmf_skb_reorder_data {
15 	u8 *reorder;
16 };
17 
18 struct brcmf_proto {
19 	int (*hdrpull)(struct brcmf_pub *drvr, bool do_fws,
20 		       struct sk_buff *skb, struct brcmf_if **ifp);
21 	int (*query_dcmd)(struct brcmf_pub *drvr, int ifidx, uint cmd,
22 			  void *buf, uint len, int *fwerr);
23 	int (*set_dcmd)(struct brcmf_pub *drvr, int ifidx, uint cmd, void *buf,
24 			uint len, int *fwerr);
25 	int (*tx_queue_data)(struct brcmf_pub *drvr, int ifidx,
26 			     struct sk_buff *skb);
27 	int (*txdata)(struct brcmf_pub *drvr, int ifidx, u8 offset,
28 		      struct sk_buff *skb);
29 	void (*configure_addr_mode)(struct brcmf_pub *drvr, int ifidx,
30 				    enum proto_addr_mode addr_mode);
31 	void (*delete_peer)(struct brcmf_pub *drvr, int ifidx,
32 			    u8 peer[ETH_ALEN]);
33 	void (*add_tdls_peer)(struct brcmf_pub *drvr, int ifidx,
34 			      u8 peer[ETH_ALEN]);
35 	void (*rxreorder)(struct brcmf_if *ifp, struct sk_buff *skb, bool inirq);
36 	void (*add_if)(struct brcmf_if *ifp);
37 	void (*del_if)(struct brcmf_if *ifp);
38 	void (*reset_if)(struct brcmf_if *ifp);
39 	int (*init_done)(struct brcmf_pub *drvr);
40 	void (*debugfs_create)(struct brcmf_pub *drvr);
41 	void *pd;
42 };
43 
44 
45 int brcmf_proto_attach(struct brcmf_pub *drvr);
46 void brcmf_proto_detach(struct brcmf_pub *drvr);
47 
48 static inline int brcmf_proto_hdrpull(struct brcmf_pub *drvr, bool do_fws,
49 				      struct sk_buff *skb,
50 				      struct brcmf_if **ifp)
51 {
52 	struct brcmf_if *tmp = NULL;
53 
54 	/* assure protocol is always called with
55 	 * non-null initialized pointer.
56 	 */
57 	if (ifp)
58 		*ifp = NULL;
59 	else
60 		ifp = &tmp;
61 	return drvr->proto->hdrpull(drvr, do_fws, skb, ifp);
62 }
63 static inline int brcmf_proto_query_dcmd(struct brcmf_pub *drvr, int ifidx,
64 					 uint cmd, void *buf, uint len,
65 					 int *fwerr)
66 {
67 	return drvr->proto->query_dcmd(drvr, ifidx, cmd, buf, len,fwerr);
68 }
69 static inline int brcmf_proto_set_dcmd(struct brcmf_pub *drvr, int ifidx,
70 				       uint cmd, void *buf, uint len,
71 				       int *fwerr)
72 {
73 	return drvr->proto->set_dcmd(drvr, ifidx, cmd, buf, len, fwerr);
74 }
75 
76 static inline int brcmf_proto_tx_queue_data(struct brcmf_pub *drvr, int ifidx,
77 					    struct sk_buff *skb)
78 {
79 	return drvr->proto->tx_queue_data(drvr, ifidx, skb);
80 }
81 
82 static inline int brcmf_proto_txdata(struct brcmf_pub *drvr, int ifidx,
83 				     u8 offset, struct sk_buff *skb)
84 {
85 	return drvr->proto->txdata(drvr, ifidx, offset, skb);
86 }
87 static inline void
88 brcmf_proto_configure_addr_mode(struct brcmf_pub *drvr, int ifidx,
89 				enum proto_addr_mode addr_mode)
90 {
91 	drvr->proto->configure_addr_mode(drvr, ifidx, addr_mode);
92 }
93 static inline void
94 brcmf_proto_delete_peer(struct brcmf_pub *drvr, int ifidx, u8 peer[ETH_ALEN])
95 {
96 	drvr->proto->delete_peer(drvr, ifidx, peer);
97 }
98 static inline void
99 brcmf_proto_add_tdls_peer(struct brcmf_pub *drvr, int ifidx, u8 peer[ETH_ALEN])
100 {
101 	drvr->proto->add_tdls_peer(drvr, ifidx, peer);
102 }
103 static inline bool brcmf_proto_is_reorder_skb(struct sk_buff *skb)
104 {
105 	struct brcmf_skb_reorder_data *rd;
106 
107 	rd = (struct brcmf_skb_reorder_data *)skb->cb;
108 	return !!rd->reorder;
109 }
110 
111 static inline void
112 brcmf_proto_rxreorder(struct brcmf_if *ifp, struct sk_buff *skb, bool inirq)
113 {
114 	ifp->drvr->proto->rxreorder(ifp, skb, inirq);
115 }
116 
117 static inline void
118 brcmf_proto_add_if(struct brcmf_pub *drvr, struct brcmf_if *ifp)
119 {
120 	if (!drvr->proto->add_if)
121 		return;
122 	drvr->proto->add_if(ifp);
123 }
124 
125 static inline void
126 brcmf_proto_del_if(struct brcmf_pub *drvr, struct brcmf_if *ifp)
127 {
128 	if (!drvr->proto->del_if)
129 		return;
130 	drvr->proto->del_if(ifp);
131 }
132 
133 static inline void
134 brcmf_proto_reset_if(struct brcmf_pub *drvr, struct brcmf_if *ifp)
135 {
136 	if (!drvr->proto->reset_if)
137 		return;
138 	drvr->proto->reset_if(ifp);
139 }
140 
141 static inline int
142 brcmf_proto_init_done(struct brcmf_pub *drvr)
143 {
144 	if (!drvr->proto->init_done)
145 		return 0;
146 	return drvr->proto->init_done(drvr);
147 }
148 
149 static inline void
150 brcmf_proto_debugfs_create(struct brcmf_pub *drvr)
151 {
152 	drvr->proto->debugfs_create(drvr);
153 }
154 
155 #endif /* BRCMFMAC_PROTO_H */
156