blob: 9249b6d4206613e35be75e4b68fafce628e61aa5 [file] [log] [blame]
Arend van Spriel5b435de2011-10-05 13:19:03 +02001/*
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
Franky Lina8a363a2011-12-16 18:37:13 -080020/* The level of bus communication with the dongle */
21enum brcmf_bus_state {
22 BRCMF_BUS_DOWN, /* Not ready for frame transfers */
23 BRCMF_BUS_LOAD, /* Download access only (CPU reset) */
24 BRCMF_BUS_DATA /* Ready for frame transfers */
25};
26
Franky Lin135e4c62012-06-26 21:26:34 +020027struct brcmf_bus_dcmd {
28 char *name;
29 char *param;
30 int param_len;
31 struct list_head list;
32};
33
Arend van Sprield9cb2592012-12-05 15:25:54 +010034/**
35 * struct brcmf_bus_ops - bus callback operations.
36 *
37 * @init: prepare for communication with dongle.
38 * @stop: clear pending frames, disable data flow.
Arend van Spriel4061f892013-08-10 12:27:19 +020039 * @txdata: send a data frame to the dongle. When the data
40 * has been transferred, the common driver must be
41 * notified using brcmf_txcomplete(). The common
42 * driver calls this function with interrupts
43 * disabled.
Arend van Sprield9cb2592012-12-05 15:25:54 +010044 * @txctl: transmit a control request message to dongle.
45 * @rxctl: receive a control response message from dongle.
Arend van Spriele2432b62013-04-03 12:40:38 +020046 * @gettxq: obtain a reference of bus transmit queue (optional).
Arend van Sprield9cb2592012-12-05 15:25:54 +010047 *
48 * This structure provides an abstract interface towards the
49 * bus specific driver. For control messages to common driver
Arend van Spriele2432b62013-04-03 12:40:38 +020050 * will assure there is only one active transaction. Unless
51 * indicated otherwise these callbacks are mandatory.
Arend van Sprield9cb2592012-12-05 15:25:54 +010052 */
53struct brcmf_bus_ops {
54 int (*init)(struct device *dev);
55 void (*stop)(struct device *dev);
56 int (*txdata)(struct device *dev, struct sk_buff *skb);
57 int (*txctl)(struct device *dev, unsigned char *msg, uint len);
58 int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
Arend van Spriele2432b62013-04-03 12:40:38 +020059 struct pktq * (*gettxq)(struct device *dev);
Arend van Sprield9cb2592012-12-05 15:25:54 +010060};
61
62/**
63 * struct brcmf_bus - interface structure between common and bus layer
64 *
65 * @bus_priv: pointer to private bus device.
66 * @dev: device pointer of bus device.
67 * @drvr: public driver information.
68 * @state: operational state of the bus interface.
69 * @maxctl: maximum size for rxctl request message.
Arend van Sprield9cb2592012-12-05 15:25:54 +010070 * @tx_realloc: number of tx packets realloced for headroom.
71 * @dstats: dongle-based statistical data.
72 * @align: alignment requirement for the bus.
73 * @dcmd_list: bus/device specific dongle initialization commands.
Arend van Spriel75d907d2013-02-06 18:40:45 +010074 * @chip: device identifier of the dongle chip.
75 * @chiprev: revision of the dongle chip.
Arend van Sprield9cb2592012-12-05 15:25:54 +010076 */
Franky Lina8a363a2011-12-16 18:37:13 -080077struct brcmf_bus {
Arend van Spriel0a332e42012-02-09 21:09:02 +010078 union {
Arend van Spriel0a332e42012-02-09 21:09:02 +010079 struct brcmf_sdio_dev *sdio;
Arend van Spriel71bb2442012-02-09 21:09:08 +010080 struct brcmf_usbdev *usb;
Arend van Spriel0a332e42012-02-09 21:09:02 +010081 } bus_priv;
Arend van Sprield9cb2592012-12-05 15:25:54 +010082 struct device *dev;
83 struct brcmf_pub *drvr;
Franky Lina8a363a2011-12-16 18:37:13 -080084 enum brcmf_bus_state state;
Arend van Sprield9cb2592012-12-05 15:25:54 +010085 uint maxctl;
Arend van Sprield9cb2592012-12-05 15:25:54 +010086 unsigned long tx_realloc;
Arend van Sprield9cb2592012-12-05 15:25:54 +010087 u8 align;
Arend van Spriel75d907d2013-02-06 18:40:45 +010088 u32 chip;
89 u32 chiprev;
Franky Lin135e4c62012-06-26 21:26:34 +020090 struct list_head dcmd_list;
Franky Lina8a363a2011-12-16 18:37:13 -080091
Arend van Sprield9cb2592012-12-05 15:25:54 +010092 struct brcmf_bus_ops *ops;
Franky Lina8a363a2011-12-16 18:37:13 -080093};
94
95/*
Arend van Sprield9cb2592012-12-05 15:25:54 +010096 * callback wrappers
97 */
98static inline int brcmf_bus_init(struct brcmf_bus *bus)
99{
100 return bus->ops->init(bus->dev);
101}
102
103static inline void brcmf_bus_stop(struct brcmf_bus *bus)
104{
105 bus->ops->stop(bus->dev);
106}
107
108static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
109{
110 return bus->ops->txdata(bus->dev, skb);
111}
112
113static inline
114int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
115{
116 return bus->ops->txctl(bus->dev, msg, len);
117}
118
119static inline
120int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
121{
122 return bus->ops->rxctl(bus->dev, msg, len);
123}
124
Arend van Spriele2432b62013-04-03 12:40:38 +0200125static inline
126struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus)
127{
128 if (!bus->ops->gettxq)
129 return ERR_PTR(-ENOENT);
130
131 return bus->ops->gettxq(bus->dev);
132}
Arend van Sprield9cb2592012-12-05 15:25:54 +0100133/*
Franky Lina8a363a2011-12-16 18:37:13 -0800134 * interface functions from common layer
135 */
136
Franky Lina8a363a2011-12-16 18:37:13 -0800137extern bool brcmf_c_prec_enq(struct device *dev, struct pktq *q,
138 struct sk_buff *pkt, int prec);
139
140/* Receive frame for delivery to OS. Callee disposes of rxp. */
Arend van Spriela43af512013-01-02 15:22:43 +0100141extern void brcmf_rx_frames(struct device *dev, struct sk_buff_head *rxlist);
Franky Lina8a363a2011-12-16 18:37:13 -0800142
143/* Indication from bus module regarding presence/insertion of dongle. */
144extern int brcmf_attach(uint bus_hdrlen, struct device *dev);
145/* Indication from bus module regarding removal/absence of dongle */
146extern void brcmf_detach(struct device *dev);
Arend van Spriel81d5f1b2013-01-02 15:22:40 +0100147/* Indication from bus module that dongle should be reset */
148extern void brcmf_dev_reset(struct device *dev);
Franky Lina8a363a2011-12-16 18:37:13 -0800149/* Indication from bus module to change flow-control state */
Hante Meuleman90d03ff2012-09-11 21:18:46 +0200150extern void brcmf_txflowblock(struct device *dev, bool state);
Franky Lina8a363a2011-12-16 18:37:13 -0800151
Arend van Spriel7f4bcee2013-03-03 12:45:29 +0100152/* Notify the bus has transferred the tx packet to firmware */
Franky Lina8a363a2011-12-16 18:37:13 -0800153extern void brcmf_txcomplete(struct device *dev, struct sk_buff *txp,
154 bool success);
155
156extern int brcmf_bus_start(struct device *dev);
157
Arend van Sprielf3d7cdc2012-02-09 21:09:03 +0100158#ifdef CONFIG_BRCMFMAC_SDIO
159extern void brcmf_sdio_exit(void);
Arend van Spriel549040a2012-03-02 22:55:48 +0100160extern void brcmf_sdio_init(void);
Arend van Sprielf3d7cdc2012-02-09 21:09:03 +0100161#endif
Arend van Spriel71bb2442012-02-09 21:09:08 +0100162#ifdef CONFIG_BRCMFMAC_USB
163extern void brcmf_usb_exit(void);
Arend van Spriel549040a2012-03-02 22:55:48 +0100164extern void brcmf_usb_init(void);
Arend van Spriel71bb2442012-02-09 21:09:08 +0100165#endif
Arend van Sprielf3d7cdc2012-02-09 21:09:03 +0100166
Arend van Spriel5b435de2011-10-05 13:19:03 +0200167#endif /* _BRCMF_BUS_H_ */