• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2010 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 
17 #ifndef BRCMFMAC_BUS_H
18 #define BRCMFMAC_BUS_H
19 
20 #include "debug.h"
21 
22 /* IDs of the 6 default common rings of msgbuf protocol */
23 #define BRCMF_H2D_MSGRING_CONTROL_SUBMIT	0
24 #define BRCMF_H2D_MSGRING_RXPOST_SUBMIT		1
25 #define BRCMF_D2H_MSGRING_CONTROL_COMPLETE	2
26 #define BRCMF_D2H_MSGRING_TX_COMPLETE		3
27 #define BRCMF_D2H_MSGRING_RX_COMPLETE		4
28 
29 #define BRCMF_NROF_H2D_COMMON_MSGRINGS		2
30 #define BRCMF_NROF_D2H_COMMON_MSGRINGS		3
31 #define BRCMF_NROF_COMMON_MSGRINGS	(BRCMF_NROF_H2D_COMMON_MSGRINGS + \
32 					 BRCMF_NROF_D2H_COMMON_MSGRINGS)
33 
34 /* The level of bus communication with the dongle */
35 enum brcmf_bus_state {
36 	BRCMF_BUS_DOWN,		/* Not ready for frame transfers */
37 	BRCMF_BUS_UP		/* Ready for frame transfers */
38 };
39 
40 /* The level of bus communication with the dongle */
41 enum brcmf_bus_protocol_type {
42 	BRCMF_PROTO_BCDC,
43 	BRCMF_PROTO_MSGBUF
44 };
45 
46 struct brcmf_bus_dcmd {
47 	char *name;
48 	char *param;
49 	int param_len;
50 	struct list_head list;
51 };
52 
53 /**
54  * struct brcmf_bus_ops - bus callback operations.
55  *
56  * @preinit: execute bus/device specific dongle init commands (optional).
57  * @init: prepare for communication with dongle.
58  * @stop: clear pending frames, disable data flow.
59  * @txdata: send a data frame to the dongle. When the data
60  *	has been transferred, the common driver must be
61  *	notified using brcmf_txcomplete(). The common
62  *	driver calls this function with interrupts
63  *	disabled.
64  * @txctl: transmit a control request message to dongle.
65  * @rxctl: receive a control response message from dongle.
66  * @gettxq: obtain a reference of bus transmit queue (optional).
67  * @wowl_config: specify if dongle is configured for wowl when going to suspend
68  * @get_ramsize: obtain size of device memory.
69  * @get_memdump: obtain device memory dump in provided buffer.
70  *
71  * This structure provides an abstract interface towards the
72  * bus specific driver. For control messages to common driver
73  * will assure there is only one active transaction. Unless
74  * indicated otherwise these callbacks are mandatory.
75  */
76 struct brcmf_bus_ops {
77 	int (*preinit)(struct device *dev);
78 	void (*stop)(struct device *dev);
79 	int (*txdata)(struct device *dev, struct sk_buff *skb);
80 	int (*txctl)(struct device *dev, unsigned char *msg, uint len);
81 	int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
82 	struct pktq * (*gettxq)(struct device *dev);
83 	void (*wowl_config)(struct device *dev, bool enabled);
84 	size_t (*get_ramsize)(struct device *dev);
85 	int (*get_memdump)(struct device *dev, void *data, size_t len);
86 };
87 
88 
89 /**
90  * struct brcmf_bus_msgbuf - bus ringbuf if in case of msgbuf.
91  *
92  * @commonrings: commonrings which are always there.
93  * @flowrings: commonrings which are dynamically created and destroyed for data.
94  * @rx_dataoffset: if set then all rx data has this this offset.
95  * @max_rxbufpost: maximum number of buffers to post for rx.
96  * @nrof_flowrings: number of flowrings.
97  */
98 struct brcmf_bus_msgbuf {
99 	struct brcmf_commonring *commonrings[BRCMF_NROF_COMMON_MSGRINGS];
100 	struct brcmf_commonring **flowrings;
101 	u32 rx_dataoffset;
102 	u32 max_rxbufpost;
103 	u32 nrof_flowrings;
104 };
105 
106 
107 /**
108  * struct brcmf_bus - interface structure between common and bus layer
109  *
110  * @bus_priv: pointer to private bus device.
111  * @proto_type: protocol type, bcdc or msgbuf
112  * @dev: device pointer of bus device.
113  * @drvr: public driver information.
114  * @state: operational state of the bus interface.
115  * @maxctl: maximum size for rxctl request message.
116  * @tx_realloc: number of tx packets realloced for headroom.
117  * @dstats: dongle-based statistical data.
118  * @dcmd_list: bus/device specific dongle initialization commands.
119  * @chip: device identifier of the dongle chip.
120  * @wowl_supported: is wowl supported by bus driver.
121  * @chiprev: revision of the dongle chip.
122  */
123 struct brcmf_bus {
124 	union {
125 		struct brcmf_sdio_dev *sdio;
126 		struct brcmf_usbdev *usb;
127 		struct brcmf_pciedev *pcie;
128 	} bus_priv;
129 	enum brcmf_bus_protocol_type proto_type;
130 	struct device *dev;
131 	struct brcmf_pub *drvr;
132 	enum brcmf_bus_state state;
133 	uint maxctl;
134 	unsigned long tx_realloc;
135 	u32 chip;
136 	u32 chiprev;
137 	bool always_use_fws_queue;
138 	bool wowl_supported;
139 
140 	struct brcmf_bus_ops *ops;
141 	struct brcmf_bus_msgbuf *msgbuf;
142 };
143 
144 /*
145  * callback wrappers
146  */
brcmf_bus_preinit(struct brcmf_bus * bus)147 static inline int brcmf_bus_preinit(struct brcmf_bus *bus)
148 {
149 	if (!bus->ops->preinit)
150 		return 0;
151 	return bus->ops->preinit(bus->dev);
152 }
153 
brcmf_bus_stop(struct brcmf_bus * bus)154 static inline void brcmf_bus_stop(struct brcmf_bus *bus)
155 {
156 	bus->ops->stop(bus->dev);
157 }
158 
brcmf_bus_txdata(struct brcmf_bus * bus,struct sk_buff * skb)159 static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
160 {
161 	return bus->ops->txdata(bus->dev, skb);
162 }
163 
164 static inline
brcmf_bus_txctl(struct brcmf_bus * bus,unsigned char * msg,uint len)165 int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
166 {
167 	return bus->ops->txctl(bus->dev, msg, len);
168 }
169 
170 static inline
brcmf_bus_rxctl(struct brcmf_bus * bus,unsigned char * msg,uint len)171 int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
172 {
173 	return bus->ops->rxctl(bus->dev, msg, len);
174 }
175 
176 static inline
brcmf_bus_gettxq(struct brcmf_bus * bus)177 struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus)
178 {
179 	if (!bus->ops->gettxq)
180 		return ERR_PTR(-ENOENT);
181 
182 	return bus->ops->gettxq(bus->dev);
183 }
184 
185 static inline
brcmf_bus_wowl_config(struct brcmf_bus * bus,bool enabled)186 void brcmf_bus_wowl_config(struct brcmf_bus *bus, bool enabled)
187 {
188 	if (bus->ops->wowl_config)
189 		bus->ops->wowl_config(bus->dev, enabled);
190 }
191 
brcmf_bus_get_ramsize(struct brcmf_bus * bus)192 static inline size_t brcmf_bus_get_ramsize(struct brcmf_bus *bus)
193 {
194 	if (!bus->ops->get_ramsize)
195 		return 0;
196 
197 	return bus->ops->get_ramsize(bus->dev);
198 }
199 
200 static inline
brcmf_bus_get_memdump(struct brcmf_bus * bus,void * data,size_t len)201 int brcmf_bus_get_memdump(struct brcmf_bus *bus, void *data, size_t len)
202 {
203 	if (!bus->ops->get_memdump)
204 		return -EOPNOTSUPP;
205 
206 	return bus->ops->get_memdump(bus->dev, data, len);
207 }
208 
209 /*
210  * interface functions from common layer
211  */
212 
213 bool brcmf_c_prec_enq(struct device *dev, struct pktq *q, struct sk_buff *pkt,
214 		      int prec);
215 
216 /* Receive frame for delivery to OS.  Callee disposes of rxp. */
217 void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp, bool handle_event);
218 /* Receive async event packet from firmware. Callee disposes of rxp. */
219 void brcmf_rx_event(struct device *dev, struct sk_buff *rxp);
220 
221 /* Indication from bus module regarding presence/insertion of dongle. */
222 int brcmf_attach(struct device *dev);
223 /* Indication from bus module regarding removal/absence of dongle */
224 void brcmf_detach(struct device *dev);
225 /* Indication from bus module that dongle should be reset */
226 void brcmf_dev_reset(struct device *dev);
227 /* Indication from bus module to change flow-control state */
228 void brcmf_txflowblock(struct device *dev, bool state);
229 
230 /* Notify the bus has transferred the tx packet to firmware */
231 void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success);
232 
233 /* Configure the "global" bus state used by upper layers */
234 void brcmf_bus_change_state(struct brcmf_bus *bus, enum brcmf_bus_state state);
235 
236 int brcmf_bus_start(struct device *dev);
237 s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len);
238 void brcmf_bus_add_txhdrlen(struct device *dev, uint len);
239 
240 #ifdef CONFIG_BRCMFMAC_SDIO
241 void brcmf_sdio_exit(void);
242 void brcmf_sdio_init(void);
243 void brcmf_sdio_register(void);
244 #endif
245 #ifdef CONFIG_BRCMFMAC_USB
246 void brcmf_usb_exit(void);
247 void brcmf_usb_register(void);
248 #endif
249 
250 #endif /* BRCMFMAC_BUS_H */
251