xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: ISC
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2010 Broadcom Corporation
4*4882a593Smuzhiyun  */
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun #ifndef BRCMFMAC_BUS_H
7*4882a593Smuzhiyun #define BRCMFMAC_BUS_H
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include "debug.h"
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun /* IDs of the 6 default common rings of msgbuf protocol */
12*4882a593Smuzhiyun #define BRCMF_H2D_MSGRING_CONTROL_SUBMIT	0
13*4882a593Smuzhiyun #define BRCMF_H2D_MSGRING_RXPOST_SUBMIT		1
14*4882a593Smuzhiyun #define BRCMF_H2D_MSGRING_FLOWRING_IDSTART	2
15*4882a593Smuzhiyun #define BRCMF_D2H_MSGRING_CONTROL_COMPLETE	2
16*4882a593Smuzhiyun #define BRCMF_D2H_MSGRING_TX_COMPLETE		3
17*4882a593Smuzhiyun #define BRCMF_D2H_MSGRING_RX_COMPLETE		4
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #define BRCMF_NROF_H2D_COMMON_MSGRINGS		2
21*4882a593Smuzhiyun #define BRCMF_NROF_D2H_COMMON_MSGRINGS		3
22*4882a593Smuzhiyun #define BRCMF_NROF_COMMON_MSGRINGS	(BRCMF_NROF_H2D_COMMON_MSGRINGS + \
23*4882a593Smuzhiyun 					 BRCMF_NROF_D2H_COMMON_MSGRINGS)
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun /* The level of bus communication with the dongle */
26*4882a593Smuzhiyun enum brcmf_bus_state {
27*4882a593Smuzhiyun 	BRCMF_BUS_DOWN,		/* Not ready for frame transfers */
28*4882a593Smuzhiyun 	BRCMF_BUS_UP		/* Ready for frame transfers */
29*4882a593Smuzhiyun };
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun /* The level of bus communication with the dongle */
32*4882a593Smuzhiyun enum brcmf_bus_protocol_type {
33*4882a593Smuzhiyun 	BRCMF_PROTO_BCDC,
34*4882a593Smuzhiyun 	BRCMF_PROTO_MSGBUF
35*4882a593Smuzhiyun };
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun struct brcmf_mp_device;
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun struct brcmf_bus_dcmd {
40*4882a593Smuzhiyun 	char *name;
41*4882a593Smuzhiyun 	char *param;
42*4882a593Smuzhiyun 	int param_len;
43*4882a593Smuzhiyun 	struct list_head list;
44*4882a593Smuzhiyun };
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun /**
47*4882a593Smuzhiyun  * struct brcmf_bus_ops - bus callback operations.
48*4882a593Smuzhiyun  *
49*4882a593Smuzhiyun  * @preinit: execute bus/device specific dongle init commands (optional).
50*4882a593Smuzhiyun  * @init: prepare for communication with dongle.
51*4882a593Smuzhiyun  * @stop: clear pending frames, disable data flow.
52*4882a593Smuzhiyun  * @txdata: send a data frame to the dongle. When the data
53*4882a593Smuzhiyun  *	has been transferred, the common driver must be
54*4882a593Smuzhiyun  *	notified using brcmf_txcomplete(). The common
55*4882a593Smuzhiyun  *	driver calls this function with interrupts
56*4882a593Smuzhiyun  *	disabled.
57*4882a593Smuzhiyun  * @txctl: transmit a control request message to dongle.
58*4882a593Smuzhiyun  * @rxctl: receive a control response message from dongle.
59*4882a593Smuzhiyun  * @gettxq: obtain a reference of bus transmit queue (optional).
60*4882a593Smuzhiyun  * @wowl_config: specify if dongle is configured for wowl when going to suspend
61*4882a593Smuzhiyun  * @get_ramsize: obtain size of device memory.
62*4882a593Smuzhiyun  * @get_memdump: obtain device memory dump in provided buffer.
63*4882a593Smuzhiyun  * @get_fwname: obtain firmware name.
64*4882a593Smuzhiyun  *
65*4882a593Smuzhiyun  * This structure provides an abstract interface towards the
66*4882a593Smuzhiyun  * bus specific driver. For control messages to common driver
67*4882a593Smuzhiyun  * will assure there is only one active transaction. Unless
68*4882a593Smuzhiyun  * indicated otherwise these callbacks are mandatory.
69*4882a593Smuzhiyun  */
70*4882a593Smuzhiyun struct brcmf_bus_ops {
71*4882a593Smuzhiyun 	int (*preinit)(struct device *dev);
72*4882a593Smuzhiyun 	void (*stop)(struct device *dev);
73*4882a593Smuzhiyun 	int (*txdata)(struct device *dev, struct sk_buff *skb);
74*4882a593Smuzhiyun 	int (*txctl)(struct device *dev, unsigned char *msg, uint len);
75*4882a593Smuzhiyun 	int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
76*4882a593Smuzhiyun 	struct pktq * (*gettxq)(struct device *dev);
77*4882a593Smuzhiyun 	void (*wowl_config)(struct device *dev, bool enabled);
78*4882a593Smuzhiyun 	size_t (*get_ramsize)(struct device *dev);
79*4882a593Smuzhiyun 	int (*get_memdump)(struct device *dev, void *data, size_t len);
80*4882a593Smuzhiyun 	int (*get_fwname)(struct device *dev, const char *ext,
81*4882a593Smuzhiyun 			  unsigned char *fw_name);
82*4882a593Smuzhiyun 	void (*debugfs_create)(struct device *dev);
83*4882a593Smuzhiyun 	int (*reset)(struct device *dev);
84*4882a593Smuzhiyun };
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun /**
88*4882a593Smuzhiyun  * struct brcmf_bus_msgbuf - bus ringbuf if in case of msgbuf.
89*4882a593Smuzhiyun  *
90*4882a593Smuzhiyun  * @commonrings: commonrings which are always there.
91*4882a593Smuzhiyun  * @flowrings: commonrings which are dynamically created and destroyed for data.
92*4882a593Smuzhiyun  * @rx_dataoffset: if set then all rx data has this this offset.
93*4882a593Smuzhiyun  * @max_rxbufpost: maximum number of buffers to post for rx.
94*4882a593Smuzhiyun  * @max_flowrings: maximum number of tx flow rings supported.
95*4882a593Smuzhiyun  * @max_submissionrings: maximum number of submission rings(h2d) supported.
96*4882a593Smuzhiyun  * @max_completionrings: maximum number of completion rings(d2h) supported.
97*4882a593Smuzhiyun  */
98*4882a593Smuzhiyun struct brcmf_bus_msgbuf {
99*4882a593Smuzhiyun 	struct brcmf_commonring *commonrings[BRCMF_NROF_COMMON_MSGRINGS];
100*4882a593Smuzhiyun 	struct brcmf_commonring **flowrings;
101*4882a593Smuzhiyun 	u32 rx_dataoffset;
102*4882a593Smuzhiyun 	u32 max_rxbufpost;
103*4882a593Smuzhiyun 	u16 max_flowrings;
104*4882a593Smuzhiyun 	u16 max_submissionrings;
105*4882a593Smuzhiyun 	u16 max_completionrings;
106*4882a593Smuzhiyun };
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun /**
110*4882a593Smuzhiyun  * struct brcmf_bus_stats - bus statistic counters.
111*4882a593Smuzhiyun  *
112*4882a593Smuzhiyun  * @pktcowed: packets cowed for extra headroom/unorphan.
113*4882a593Smuzhiyun  * @pktcow_failed: packets dropped due to failed cow-ing.
114*4882a593Smuzhiyun  */
115*4882a593Smuzhiyun struct brcmf_bus_stats {
116*4882a593Smuzhiyun 	atomic_t pktcowed;
117*4882a593Smuzhiyun 	atomic_t pktcow_failed;
118*4882a593Smuzhiyun };
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun /**
121*4882a593Smuzhiyun  * struct brcmf_bus - interface structure between common and bus layer
122*4882a593Smuzhiyun  *
123*4882a593Smuzhiyun  * @bus_priv: pointer to private bus device.
124*4882a593Smuzhiyun  * @proto_type: protocol type, bcdc or msgbuf
125*4882a593Smuzhiyun  * @dev: device pointer of bus device.
126*4882a593Smuzhiyun  * @drvr: public driver information.
127*4882a593Smuzhiyun  * @state: operational state of the bus interface.
128*4882a593Smuzhiyun  * @stats: statistics shared between common and bus layer.
129*4882a593Smuzhiyun  * @maxctl: maximum size for rxctl request message.
130*4882a593Smuzhiyun  * @chip: device identifier of the dongle chip.
131*4882a593Smuzhiyun  * @always_use_fws_queue: bus wants use queue also when fwsignal is inactive.
132*4882a593Smuzhiyun  * @wowl_supported: is wowl supported by bus driver.
133*4882a593Smuzhiyun  * @chiprev: revision of the dongle chip.
134*4882a593Smuzhiyun  * @msgbuf: msgbuf protocol parameters provided by bus layer.
135*4882a593Smuzhiyun  */
136*4882a593Smuzhiyun struct brcmf_bus {
137*4882a593Smuzhiyun 	union {
138*4882a593Smuzhiyun 		struct brcmf_sdio_dev *sdio;
139*4882a593Smuzhiyun 		struct brcmf_usbdev *usb;
140*4882a593Smuzhiyun 		struct brcmf_pciedev *pcie;
141*4882a593Smuzhiyun 	} bus_priv;
142*4882a593Smuzhiyun 	enum brcmf_bus_protocol_type proto_type;
143*4882a593Smuzhiyun 	struct device *dev;
144*4882a593Smuzhiyun 	struct brcmf_pub *drvr;
145*4882a593Smuzhiyun 	enum brcmf_bus_state state;
146*4882a593Smuzhiyun 	struct brcmf_bus_stats stats;
147*4882a593Smuzhiyun 	uint maxctl;
148*4882a593Smuzhiyun 	u32 chip;
149*4882a593Smuzhiyun 	u32 chiprev;
150*4882a593Smuzhiyun 	bool always_use_fws_queue;
151*4882a593Smuzhiyun 	bool wowl_supported;
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun 	const struct brcmf_bus_ops *ops;
154*4882a593Smuzhiyun 	struct brcmf_bus_msgbuf *msgbuf;
155*4882a593Smuzhiyun };
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun /*
158*4882a593Smuzhiyun  * callback wrappers
159*4882a593Smuzhiyun  */
brcmf_bus_preinit(struct brcmf_bus * bus)160*4882a593Smuzhiyun static inline int brcmf_bus_preinit(struct brcmf_bus *bus)
161*4882a593Smuzhiyun {
162*4882a593Smuzhiyun 	if (!bus->ops->preinit)
163*4882a593Smuzhiyun 		return 0;
164*4882a593Smuzhiyun 	return bus->ops->preinit(bus->dev);
165*4882a593Smuzhiyun }
166*4882a593Smuzhiyun 
brcmf_bus_stop(struct brcmf_bus * bus)167*4882a593Smuzhiyun static inline void brcmf_bus_stop(struct brcmf_bus *bus)
168*4882a593Smuzhiyun {
169*4882a593Smuzhiyun 	bus->ops->stop(bus->dev);
170*4882a593Smuzhiyun }
171*4882a593Smuzhiyun 
brcmf_bus_txdata(struct brcmf_bus * bus,struct sk_buff * skb)172*4882a593Smuzhiyun static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
173*4882a593Smuzhiyun {
174*4882a593Smuzhiyun 	return bus->ops->txdata(bus->dev, skb);
175*4882a593Smuzhiyun }
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun static inline
brcmf_bus_txctl(struct brcmf_bus * bus,unsigned char * msg,uint len)178*4882a593Smuzhiyun int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
179*4882a593Smuzhiyun {
180*4882a593Smuzhiyun 	return bus->ops->txctl(bus->dev, msg, len);
181*4882a593Smuzhiyun }
182*4882a593Smuzhiyun 
183*4882a593Smuzhiyun static inline
brcmf_bus_rxctl(struct brcmf_bus * bus,unsigned char * msg,uint len)184*4882a593Smuzhiyun int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
185*4882a593Smuzhiyun {
186*4882a593Smuzhiyun 	return bus->ops->rxctl(bus->dev, msg, len);
187*4882a593Smuzhiyun }
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun static inline
brcmf_bus_gettxq(struct brcmf_bus * bus)190*4882a593Smuzhiyun struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus)
191*4882a593Smuzhiyun {
192*4882a593Smuzhiyun 	if (!bus->ops->gettxq)
193*4882a593Smuzhiyun 		return ERR_PTR(-ENOENT);
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun 	return bus->ops->gettxq(bus->dev);
196*4882a593Smuzhiyun }
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun static inline
brcmf_bus_wowl_config(struct brcmf_bus * bus,bool enabled)199*4882a593Smuzhiyun void brcmf_bus_wowl_config(struct brcmf_bus *bus, bool enabled)
200*4882a593Smuzhiyun {
201*4882a593Smuzhiyun 	if (bus->ops->wowl_config)
202*4882a593Smuzhiyun 		bus->ops->wowl_config(bus->dev, enabled);
203*4882a593Smuzhiyun }
204*4882a593Smuzhiyun 
brcmf_bus_get_ramsize(struct brcmf_bus * bus)205*4882a593Smuzhiyun static inline size_t brcmf_bus_get_ramsize(struct brcmf_bus *bus)
206*4882a593Smuzhiyun {
207*4882a593Smuzhiyun 	if (!bus->ops->get_ramsize)
208*4882a593Smuzhiyun 		return 0;
209*4882a593Smuzhiyun 
210*4882a593Smuzhiyun 	return bus->ops->get_ramsize(bus->dev);
211*4882a593Smuzhiyun }
212*4882a593Smuzhiyun 
213*4882a593Smuzhiyun static inline
brcmf_bus_get_memdump(struct brcmf_bus * bus,void * data,size_t len)214*4882a593Smuzhiyun int brcmf_bus_get_memdump(struct brcmf_bus *bus, void *data, size_t len)
215*4882a593Smuzhiyun {
216*4882a593Smuzhiyun 	if (!bus->ops->get_memdump)
217*4882a593Smuzhiyun 		return -EOPNOTSUPP;
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun 	return bus->ops->get_memdump(bus->dev, data, len);
220*4882a593Smuzhiyun }
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun static inline
brcmf_bus_get_fwname(struct brcmf_bus * bus,const char * ext,unsigned char * fw_name)223*4882a593Smuzhiyun int brcmf_bus_get_fwname(struct brcmf_bus *bus, const char *ext,
224*4882a593Smuzhiyun 			 unsigned char *fw_name)
225*4882a593Smuzhiyun {
226*4882a593Smuzhiyun 	return bus->ops->get_fwname(bus->dev, ext, fw_name);
227*4882a593Smuzhiyun }
228*4882a593Smuzhiyun 
229*4882a593Smuzhiyun static inline
brcmf_bus_debugfs_create(struct brcmf_bus * bus)230*4882a593Smuzhiyun void brcmf_bus_debugfs_create(struct brcmf_bus *bus)
231*4882a593Smuzhiyun {
232*4882a593Smuzhiyun 	if (!bus->ops->debugfs_create)
233*4882a593Smuzhiyun 		return;
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun 	return bus->ops->debugfs_create(bus->dev);
236*4882a593Smuzhiyun }
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun static inline
brcmf_bus_reset(struct brcmf_bus * bus)239*4882a593Smuzhiyun int brcmf_bus_reset(struct brcmf_bus *bus)
240*4882a593Smuzhiyun {
241*4882a593Smuzhiyun 	if (!bus->ops->reset)
242*4882a593Smuzhiyun 		return -EOPNOTSUPP;
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun 	return bus->ops->reset(bus->dev);
245*4882a593Smuzhiyun }
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun /*
248*4882a593Smuzhiyun  * interface functions from common layer
249*4882a593Smuzhiyun  */
250*4882a593Smuzhiyun 
251*4882a593Smuzhiyun /* Receive frame for delivery to OS.  Callee disposes of rxp. */
252*4882a593Smuzhiyun void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp, bool handle_event,
253*4882a593Smuzhiyun 		    bool inirq);
254*4882a593Smuzhiyun /* Receive async event packet from firmware. Callee disposes of rxp. */
255*4882a593Smuzhiyun void brcmf_rx_event(struct device *dev, struct sk_buff *rxp);
256*4882a593Smuzhiyun 
257*4882a593Smuzhiyun int brcmf_alloc(struct device *dev, struct brcmf_mp_device *settings);
258*4882a593Smuzhiyun /* Indication from bus module regarding presence/insertion of dongle. */
259*4882a593Smuzhiyun int brcmf_attach(struct device *dev);
260*4882a593Smuzhiyun /* Indication from bus module regarding removal/absence of dongle */
261*4882a593Smuzhiyun void brcmf_detach(struct device *dev);
262*4882a593Smuzhiyun void brcmf_free(struct device *dev);
263*4882a593Smuzhiyun /* Indication from bus module that dongle should be reset */
264*4882a593Smuzhiyun void brcmf_dev_reset(struct device *dev);
265*4882a593Smuzhiyun /* Request from bus module to initiate a coredump */
266*4882a593Smuzhiyun void brcmf_dev_coredump(struct device *dev);
267*4882a593Smuzhiyun /* Indication that firmware has halted or crashed */
268*4882a593Smuzhiyun void brcmf_fw_crashed(struct device *dev);
269*4882a593Smuzhiyun 
270*4882a593Smuzhiyun /* Configure the "global" bus state used by upper layers */
271*4882a593Smuzhiyun void brcmf_bus_change_state(struct brcmf_bus *bus, enum brcmf_bus_state state);
272*4882a593Smuzhiyun 
273*4882a593Smuzhiyun s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len);
274*4882a593Smuzhiyun void brcmf_bus_add_txhdrlen(struct device *dev, uint len);
275*4882a593Smuzhiyun 
276*4882a593Smuzhiyun #ifdef CONFIG_BRCMFMAC_SDIO
277*4882a593Smuzhiyun void brcmf_sdio_exit(void);
278*4882a593Smuzhiyun int brcmf_sdio_register(void);
279*4882a593Smuzhiyun #else
brcmf_sdio_exit(void)280*4882a593Smuzhiyun static inline void brcmf_sdio_exit(void) { }
brcmf_sdio_register(void)281*4882a593Smuzhiyun static inline int brcmf_sdio_register(void) { return 0; }
282*4882a593Smuzhiyun #endif
283*4882a593Smuzhiyun 
284*4882a593Smuzhiyun #ifdef CONFIG_BRCMFMAC_USB
285*4882a593Smuzhiyun void brcmf_usb_exit(void);
286*4882a593Smuzhiyun int brcmf_usb_register(void);
287*4882a593Smuzhiyun #else
brcmf_usb_exit(void)288*4882a593Smuzhiyun static inline void brcmf_usb_exit(void) { }
brcmf_usb_register(void)289*4882a593Smuzhiyun static inline int brcmf_usb_register(void) { return 0; }
290*4882a593Smuzhiyun #endif
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun #ifdef CONFIG_BRCMFMAC_PCIE
293*4882a593Smuzhiyun void brcmf_pcie_exit(void);
294*4882a593Smuzhiyun int brcmf_pcie_register(void);
295*4882a593Smuzhiyun #else
brcmf_pcie_exit(void)296*4882a593Smuzhiyun static inline void brcmf_pcie_exit(void) { }
brcmf_pcie_register(void)297*4882a593Smuzhiyun static inline int brcmf_pcie_register(void) { return 0; }
298*4882a593Smuzhiyun #endif
299*4882a593Smuzhiyun 
300*4882a593Smuzhiyun #endif /* BRCMFMAC_BUS_H */
301