1 // SPDX-License-Identifier: ISC
2 /*
3  * Copyright (c) 2010 Broadcom Corporation
4  */
5 
6 /****************
7  * Common types *
8  */
9 
10 #ifndef BRCMFMAC_CORE_H
11 #define BRCMFMAC_CORE_H
12 
13 #include <net/cfg80211.h>
14 #include "fweh.h"
15 
16 #if IS_MODULE(CONFIG_BRCMFMAC)
17 #define BRCMF_EXPORT_SYMBOL_GPL(__sym)	EXPORT_SYMBOL_NS_GPL(__sym, BRCMFMAC)
18 #else
19 #define BRCMF_EXPORT_SYMBOL_GPL(__sym)
20 #endif
21 
22 #define TOE_TX_CSUM_OL		0x00000001
23 #define TOE_RX_CSUM_OL		0x00000002
24 
25 /* For supporting multiple interfaces */
26 #define BRCMF_MAX_IFS	16
27 
28 /* Small, medium and maximum buffer size for dcmd
29  */
30 #define BRCMF_DCMD_SMLEN	256
31 #define BRCMF_DCMD_MEDLEN	1536
32 #define BRCMF_DCMD_MAXLEN	8192
33 
34 /* IOCTL from host to device are limited in length. A device can only handle
35  * ethernet frame size. This limitation is to be applied by protocol layer.
36  */
37 #define BRCMF_TX_IOCTL_MAX_MSG_SIZE	(ETH_FRAME_LEN+ETH_FCS_LEN)
38 
39 #define BRCMF_AMPDU_RX_REORDER_MAXFLOWS		256
40 
41 /* Length of firmware version string stored for
42  * ethtool driver info which uses 32 bytes as well.
43  */
44 #define BRCMF_DRIVER_FIRMWARE_VERSION_LEN	32
45 
46 #define NDOL_MAX_ENTRIES	8
47 
48 /**
49  * struct brcmf_ampdu_rx_reorder - AMPDU receive reorder info
50  *
51  * @pktslots: dynamic allocated array for ordering AMPDU packets.
52  * @flow_id: AMPDU flow identifier.
53  * @cur_idx: last AMPDU index from firmware.
54  * @exp_idx: expected next AMPDU index.
55  * @max_idx: maximum amount of packets per AMPDU.
56  * @pend_pkts: number of packets currently in @pktslots.
57  */
58 struct brcmf_ampdu_rx_reorder {
59 	struct sk_buff **pktslots;
60 	u8 flow_id;
61 	u8 cur_idx;
62 	u8 exp_idx;
63 	u8 max_idx;
64 	u8 pend_pkts;
65 };
66 
67 /* Forward decls for struct brcmf_pub (see below) */
68 struct brcmf_proto;	/* device communication protocol info */
69 struct brcmf_fws_info;	/* firmware signalling info */
70 struct brcmf_mp_device;	/* module paramateres, device specific */
71 
72 /*
73  * struct brcmf_rev_info
74  *
75  * The result field stores the error code of the
76  * revision info request from firmware. For the
77  * other fields see struct brcmf_rev_info_le in
78  * fwil_types.h
79  */
80 struct brcmf_rev_info {
81 	int result;
82 	u32 vendorid;
83 	u32 deviceid;
84 	u32 radiorev;
85 	u32 corerev;
86 	u32 boardid;
87 	u32 boardvendor;
88 	u32 boardrev;
89 	u32 driverrev;
90 	u32 ucoderev;
91 	u32 bus;
92 	char chipname[12];
93 	u32 phytype;
94 	u32 phyrev;
95 	u32 anarev;
96 	u32 chippkg;
97 	u32 nvramrev;
98 };
99 
100 /* Common structure for module and instance linkage */
101 struct brcmf_pub {
102 	/* Linkage ponters */
103 	struct brcmf_bus *bus_if;
104 	struct brcmf_proto *proto;
105 	struct wiphy *wiphy;
106 	struct cfg80211_ops *ops;
107 	struct brcmf_cfg80211_info *config;
108 
109 	/* Internal brcmf items */
110 	uint hdrlen;		/* Total BRCMF header length (proto + bus) */
111 
112 	/* Dongle media info */
113 	char fwver[BRCMF_DRIVER_FIRMWARE_VERSION_LEN];
114 	u8 mac[ETH_ALEN];		/* MAC address obtained from dongle */
115 
116 	struct mac_address addresses[BRCMF_MAX_IFS];
117 
118 	struct brcmf_if *iflist[BRCMF_MAX_IFS];
119 	s32 if2bss[BRCMF_MAX_IFS];
120 	struct brcmf_if *mon_if;
121 
122 	struct mutex proto_block;
123 	unsigned char proto_buf[BRCMF_DCMD_MAXLEN];
124 
125 	struct brcmf_fweh_info fweh;
126 
127 	struct brcmf_ampdu_rx_reorder
128 		*reorder_flows[BRCMF_AMPDU_RX_REORDER_MAXFLOWS];
129 
130 	u32 feat_flags;
131 	u32 chip_quirks;
132 
133 	struct brcmf_rev_info revinfo;
134 #ifdef DEBUG
135 	struct dentry *dbgfs_dir;
136 #endif
137 
138 	struct notifier_block inetaddr_notifier;
139 	struct notifier_block inet6addr_notifier;
140 	struct brcmf_mp_device *settings;
141 
142 	struct work_struct bus_reset;
143 
144 	u8 clmver[BRCMF_DCMD_SMLEN];
145 	u8 sta_mac_idx;
146 	const struct brcmf_fwvid_ops *vops;
147 	void *vdata;
148 };
149 
150 /* forward declarations */
151 struct brcmf_cfg80211_vif;
152 struct brcmf_fws_mac_descriptor;
153 
154 /**
155  * enum brcmf_netif_stop_reason - reason for stopping netif queue.
156  *
157  * @BRCMF_NETIF_STOP_REASON_FWS_FC:
158  *	netif stopped due to firmware signalling flow control.
159  * @BRCMF_NETIF_STOP_REASON_FLOW:
160  *	netif stopped due to flowring full.
161  * @BRCMF_NETIF_STOP_REASON_DISCONNECTED:
162  *	netif stopped due to not being connected (STA mode).
163  */
164 enum brcmf_netif_stop_reason {
165 	BRCMF_NETIF_STOP_REASON_FWS_FC = BIT(0),
166 	BRCMF_NETIF_STOP_REASON_FLOW = BIT(1),
167 	BRCMF_NETIF_STOP_REASON_DISCONNECTED = BIT(2)
168 };
169 
170 /**
171  * struct brcmf_if - interface control information.
172  *
173  * @drvr: points to device related information.
174  * @vif: points to cfg80211 specific interface information.
175  * @ndev: associated network device.
176  * @multicast_work: worker object for multicast provisioning.
177  * @ndoffload_work: worker object for neighbor discovery offload configuration.
178  * @fws_desc: interface specific firmware-signalling descriptor.
179  * @ifidx: interface index in device firmware.
180  * @bsscfgidx: index of bss associated with this interface.
181  * @mac_addr: assigned mac address.
182  * @netif_stop: bitmap indicates reason why netif queues are stopped.
183  * @netif_stop_lock: spinlock for update netif_stop from multiple sources.
184  * @pend_8021x_cnt: tracks outstanding number of 802.1x frames.
185  * @pend_8021x_wait: used for signalling change in count.
186  * @fwil_fwerr: flag indicating fwil layer should return firmware error codes.
187  */
188 struct brcmf_if {
189 	struct brcmf_pub *drvr;
190 	struct brcmf_cfg80211_vif *vif;
191 	struct net_device *ndev;
192 	struct work_struct multicast_work;
193 	struct work_struct ndoffload_work;
194 	struct brcmf_fws_mac_descriptor *fws_desc;
195 	int ifidx;
196 	s32 bsscfgidx;
197 	u8 mac_addr[ETH_ALEN];
198 	u8 netif_stop;
199 	spinlock_t netif_stop_lock;
200 	atomic_t pend_8021x_cnt;
201 	wait_queue_head_t pend_8021x_wait;
202 	struct in6_addr ipv6_addr_tbl[NDOL_MAX_ENTRIES];
203 	u8 ipv6addr_idx;
204 	bool fwil_fwerr;
205 };
206 
207 int brcmf_netdev_wait_pend8021x(struct brcmf_if *ifp);
208 
209 /* Return pointer to interface name */
210 char *brcmf_ifname(struct brcmf_if *ifp);
211 struct brcmf_if *brcmf_get_ifp(struct brcmf_pub *drvr, int ifidx);
212 void brcmf_configure_arp_nd_offload(struct brcmf_if *ifp, bool enable);
213 int brcmf_net_attach(struct brcmf_if *ifp, bool locked);
214 struct brcmf_if *brcmf_add_if(struct brcmf_pub *drvr, s32 bsscfgidx, s32 ifidx,
215 			      bool is_p2pdev, const char *name, u8 *mac_addr);
216 void brcmf_remove_interface(struct brcmf_if *ifp, bool locked);
217 void brcmf_txflowblock_if(struct brcmf_if *ifp,
218 			  enum brcmf_netif_stop_reason reason, bool state);
219 void brcmf_txfinalize(struct brcmf_if *ifp, struct sk_buff *txp, bool success);
220 void brcmf_netif_rx(struct brcmf_if *ifp, struct sk_buff *skb);
221 void brcmf_netif_mon_rx(struct brcmf_if *ifp, struct sk_buff *skb);
222 void brcmf_net_detach(struct net_device *ndev, bool locked);
223 int brcmf_net_mon_attach(struct brcmf_if *ifp);
224 void brcmf_net_setcarrier(struct brcmf_if *ifp, bool on);
225 int __init brcmf_core_init(void);
226 void __exit brcmf_core_exit(void);
227 
228 #endif /* BRCMFMAC_CORE_H */
229