Merge tag 'v3.16-rc1' into i2c/for-next
[linux-2.6-block.git] / drivers / net / wireless / brcm80211 / brcmfmac / dhd_bus.h
CommitLineData
5b435de0
AS
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 _BRCMF_BUS_H_
18#define _BRCMF_BUS_H_
19
bb350711
AS
20#include "dhd_dbg.h"
21
a8a363ac
FL
22/* The level of bus communication with the dongle */
23enum brcmf_bus_state {
bb350711
AS
24 BRCMF_BUS_UNKNOWN, /* Not determined yet */
25 BRCMF_BUS_NOMEDIUM, /* No medium access to dongle */
a8a363ac
FL
26 BRCMF_BUS_DOWN, /* Not ready for frame transfers */
27 BRCMF_BUS_LOAD, /* Download access only (CPU reset) */
28 BRCMF_BUS_DATA /* Ready for frame transfers */
29};
30
943258b6
HM
31/* The level of bus communication with the dongle */
32enum brcmf_bus_protocol_type {
33 BRCMF_PROTO_BCDC,
34 BRCMF_PROTO_MSGBUF
35};
36
135e4c61
FL
37struct brcmf_bus_dcmd {
38 char *name;
39 char *param;
40 int param_len;
41 struct list_head list;
42};
43
d9cb2596
AS
44/**
45 * struct brcmf_bus_ops - bus callback operations.
46 *
cf458287 47 * @preinit: execute bus/device specific dongle init commands (optional).
d9cb2596
AS
48 * @init: prepare for communication with dongle.
49 * @stop: clear pending frames, disable data flow.
4061f895
AS
50 * @txdata: send a data frame to the dongle. When the data
51 * has been transferred, the common driver must be
52 * notified using brcmf_txcomplete(). The common
53 * driver calls this function with interrupts
54 * disabled.
d9cb2596
AS
55 * @txctl: transmit a control request message to dongle.
56 * @rxctl: receive a control response message from dongle.
e2432b67 57 * @gettxq: obtain a reference of bus transmit queue (optional).
d9cb2596
AS
58 *
59 * This structure provides an abstract interface towards the
60 * bus specific driver. For control messages to common driver
e2432b67
AS
61 * will assure there is only one active transaction. Unless
62 * indicated otherwise these callbacks are mandatory.
d9cb2596
AS
63 */
64struct brcmf_bus_ops {
cf458287 65 int (*preinit)(struct device *dev);
d9cb2596
AS
66 void (*stop)(struct device *dev);
67 int (*txdata)(struct device *dev, struct sk_buff *skb);
68 int (*txctl)(struct device *dev, unsigned char *msg, uint len);
69 int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
e2432b67 70 struct pktq * (*gettxq)(struct device *dev);
d9cb2596
AS
71};
72
73/**
74 * struct brcmf_bus - interface structure between common and bus layer
75 *
76 * @bus_priv: pointer to private bus device.
943258b6 77 * @proto_type: protocol type, bcdc or msgbuf
d9cb2596
AS
78 * @dev: device pointer of bus device.
79 * @drvr: public driver information.
80 * @state: operational state of the bus interface.
81 * @maxctl: maximum size for rxctl request message.
d9cb2596
AS
82 * @tx_realloc: number of tx packets realloced for headroom.
83 * @dstats: dongle-based statistical data.
d9cb2596 84 * @dcmd_list: bus/device specific dongle initialization commands.
75d907d3
AS
85 * @chip: device identifier of the dongle chip.
86 * @chiprev: revision of the dongle chip.
d9cb2596 87 */
a8a363ac 88struct brcmf_bus {
0a332e46 89 union {
0a332e46 90 struct brcmf_sdio_dev *sdio;
71bb244b 91 struct brcmf_usbdev *usb;
0a332e46 92 } bus_priv;
943258b6 93 enum brcmf_bus_protocol_type proto_type;
d9cb2596
AS
94 struct device *dev;
95 struct brcmf_pub *drvr;
a8a363ac 96 enum brcmf_bus_state state;
d9cb2596 97 uint maxctl;
d9cb2596 98 unsigned long tx_realloc;
75d907d3
AS
99 u32 chip;
100 u32 chiprev;
9cd18359 101 bool always_use_fws_queue;
a8a363ac 102
d9cb2596 103 struct brcmf_bus_ops *ops;
a8a363ac
FL
104};
105
d9cb2596
AS
106/*
107 * callback wrappers
108 */
cf458287
AS
109static inline int brcmf_bus_preinit(struct brcmf_bus *bus)
110{
111 if (!bus->ops->preinit)
112 return 0;
113 return bus->ops->preinit(bus->dev);
114}
115
d9cb2596
AS
116static inline void brcmf_bus_stop(struct brcmf_bus *bus)
117{
118 bus->ops->stop(bus->dev);
119}
120
121static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
122{
123 return bus->ops->txdata(bus->dev, skb);
124}
125
126static inline
127int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
128{
129 return bus->ops->txctl(bus->dev, msg, len);
130}
131
132static inline
133int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
134{
135 return bus->ops->rxctl(bus->dev, msg, len);
136}
137
e2432b67
AS
138static inline
139struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus)
140{
141 if (!bus->ops->gettxq)
142 return ERR_PTR(-ENOENT);
143
144 return bus->ops->gettxq(bus->dev);
145}
bb350711
AS
146
147static inline bool brcmf_bus_ready(struct brcmf_bus *bus)
148{
149 return bus->state == BRCMF_BUS_LOAD || bus->state == BRCMF_BUS_DATA;
150}
151
152static inline void brcmf_bus_change_state(struct brcmf_bus *bus,
153 enum brcmf_bus_state new_state)
154{
155 /* NOMEDIUM is permanent */
156 if (bus->state == BRCMF_BUS_NOMEDIUM)
157 return;
158
159 brcmf_dbg(TRACE, "%d -> %d\n", bus->state, new_state);
160 bus->state = new_state;
161}
162
a8a363ac
FL
163/*
164 * interface functions from common layer
165 */
166
9bd91f3c
JP
167bool brcmf_c_prec_enq(struct device *dev, struct pktq *q, struct sk_buff *pkt,
168 int prec);
a8a363ac
FL
169
170/* Receive frame for delivery to OS. Callee disposes of rxp. */
7009deab 171void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp);
a8a363ac
FL
172
173/* Indication from bus module regarding presence/insertion of dongle. */
8dee77ba 174int brcmf_attach(struct device *dev);
a8a363ac 175/* Indication from bus module regarding removal/absence of dongle */
9bd91f3c 176void brcmf_detach(struct device *dev);
81d5f1bb 177/* Indication from bus module that dongle should be reset */
9bd91f3c 178void brcmf_dev_reset(struct device *dev);
a8a363ac 179/* Indication from bus module to change flow-control state */
9bd91f3c 180void brcmf_txflowblock(struct device *dev, bool state);
a8a363ac 181
7f4bceec 182/* Notify the bus has transferred the tx packet to firmware */
9bd91f3c 183void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success);
a8a363ac 184
9bd91f3c 185int brcmf_bus_start(struct device *dev);
cf458287
AS
186s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data,
187 u32 len);
8dee77ba 188void brcmf_bus_add_txhdrlen(struct device *dev, uint len);
a8a363ac 189
f3d7cdc3 190#ifdef CONFIG_BRCMFMAC_SDIO
9bd91f3c
JP
191void brcmf_sdio_exit(void);
192void brcmf_sdio_init(void);
4fbef95a 193void brcmf_sdio_register(void);
f3d7cdc3 194#endif
71bb244b 195#ifdef CONFIG_BRCMFMAC_USB
9bd91f3c 196void brcmf_usb_exit(void);
4fbef95a 197void brcmf_usb_register(void);
71bb244b 198#endif
f3d7cdc3 199
5b435de0 200#endif /* _BRCMF_BUS_H_ */