Merge tag 'nfc-next-3.16-2' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo...
[pandora-kernel.git] / drivers / net / wireless / brcm80211 / brcmfmac / dhd_bus.h
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
20 #include "dhd_dbg.h"
21
22 /* The level of bus communication with the dongle */
23 enum brcmf_bus_state {
24         BRCMF_BUS_UNKNOWN,      /* Not determined yet */
25         BRCMF_BUS_NOMEDIUM,     /* No medium access to dongle */
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
31 /* The level of bus communication with the dongle */
32 enum brcmf_bus_protocol_type {
33         BRCMF_PROTO_BCDC,
34         BRCMF_PROTO_MSGBUF
35 };
36
37 struct brcmf_bus_dcmd {
38         char *name;
39         char *param;
40         int param_len;
41         struct list_head list;
42 };
43
44 /**
45  * struct brcmf_bus_ops - bus callback operations.
46  *
47  * @preinit: execute bus/device specific dongle init commands (optional).
48  * @init: prepare for communication with dongle.
49  * @stop: clear pending frames, disable data flow.
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.
55  * @txctl: transmit a control request message to dongle.
56  * @rxctl: receive a control response message from dongle.
57  * @gettxq: obtain a reference of bus transmit queue (optional).
58  *
59  * This structure provides an abstract interface towards the
60  * bus specific driver. For control messages to common driver
61  * will assure there is only one active transaction. Unless
62  * indicated otherwise these callbacks are mandatory.
63  */
64 struct brcmf_bus_ops {
65         int (*preinit)(struct device *dev);
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);
70         struct pktq * (*gettxq)(struct device *dev);
71 };
72
73 /**
74  * struct brcmf_bus - interface structure between common and bus layer
75  *
76  * @bus_priv: pointer to private bus device.
77  * @proto_type: protocol type, bcdc or msgbuf
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.
82  * @tx_realloc: number of tx packets realloced for headroom.
83  * @dstats: dongle-based statistical data.
84  * @dcmd_list: bus/device specific dongle initialization commands.
85  * @chip: device identifier of the dongle chip.
86  * @chiprev: revision of the dongle chip.
87  */
88 struct brcmf_bus {
89         union {
90                 struct brcmf_sdio_dev *sdio;
91                 struct brcmf_usbdev *usb;
92         } bus_priv;
93         enum brcmf_bus_protocol_type proto_type;
94         struct device *dev;
95         struct brcmf_pub *drvr;
96         enum brcmf_bus_state state;
97         uint maxctl;
98         unsigned long tx_realloc;
99         u32 chip;
100         u32 chiprev;
101         bool always_use_fws_queue;
102
103         struct brcmf_bus_ops *ops;
104 };
105
106 /*
107  * callback wrappers
108  */
109 static 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
116 static inline void brcmf_bus_stop(struct brcmf_bus *bus)
117 {
118         bus->ops->stop(bus->dev);
119 }
120
121 static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
122 {
123         return bus->ops->txdata(bus->dev, skb);
124 }
125
126 static inline
127 int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
128 {
129         return bus->ops->txctl(bus->dev, msg, len);
130 }
131
132 static inline
133 int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
134 {
135         return bus->ops->rxctl(bus->dev, msg, len);
136 }
137
138 static inline
139 struct 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 }
146
147 static inline bool brcmf_bus_ready(struct brcmf_bus *bus)
148 {
149         return bus->state == BRCMF_BUS_LOAD || bus->state == BRCMF_BUS_DATA;
150 }
151
152 static 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
163 /*
164  * interface functions from common layer
165  */
166
167 bool brcmf_c_prec_enq(struct device *dev, struct pktq *q, struct sk_buff *pkt,
168                       int prec);
169
170 /* Receive frame for delivery to OS.  Callee disposes of rxp. */
171 void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp);
172
173 /* Indication from bus module regarding presence/insertion of dongle. */
174 int brcmf_attach(struct device *dev);
175 /* Indication from bus module regarding removal/absence of dongle */
176 void brcmf_detach(struct device *dev);
177 /* Indication from bus module that dongle should be reset */
178 void brcmf_dev_reset(struct device *dev);
179 /* Indication from bus module to change flow-control state */
180 void brcmf_txflowblock(struct device *dev, bool state);
181
182 /* Notify the bus has transferred the tx packet to firmware */
183 void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success);
184
185 int brcmf_bus_start(struct device *dev);
186 s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data,
187                                 u32 len);
188 void brcmf_bus_add_txhdrlen(struct device *dev, uint len);
189
190 #ifdef CONFIG_BRCMFMAC_SDIO
191 void brcmf_sdio_exit(void);
192 void brcmf_sdio_init(void);
193 void brcmf_sdio_register(void);
194 #endif
195 #ifdef CONFIG_BRCMFMAC_USB
196 void brcmf_usb_exit(void);
197 void brcmf_usb_register(void);
198 #endif
199
200 #endif                          /* _BRCMF_BUS_H_ */