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
9enum proto_addr_mode {
10	ADDR_INDIRECT	= 0,
11	ADDR_DIRECT
12};
13
14struct brcmf_skb_reorder_data {
15	u8 *reorder;
16};
17
18struct 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);
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
45int brcmf_proto_attach(struct brcmf_pub *drvr);
46void brcmf_proto_detach(struct brcmf_pub *drvr);
47
48static 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}
63static 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}
69static 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
76static 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
82static 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}
87static inline void
88brcmf_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}
93static inline void
94brcmf_proto_delete_peer(struct brcmf_pub *drvr, int ifidx, u8 peer[ETH_ALEN])
95{
96	drvr->proto->delete_peer(drvr, ifidx, peer);
97}
98static inline void
99brcmf_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}
103static 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
111static inline void
112brcmf_proto_rxreorder(struct brcmf_if *ifp, struct sk_buff *skb)
113{
114	ifp->drvr->proto->rxreorder(ifp, skb);
115}
116
117static inline void
118brcmf_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
125static inline void
126brcmf_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
133static inline void
134brcmf_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
141static inline int
142brcmf_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
149static inline void
150brcmf_proto_debugfs_create(struct brcmf_pub *drvr)
151{
152	drvr->proto->debugfs_create(drvr);
153}
154
155#endif /* BRCMFMAC_PROTO_H */
156