blob: dd38b78a9726f75861bcb1f92ef3d511a81b92db [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
27struct dngl_stats {
28 unsigned long rx_packets; /* total packets received */
29 unsigned long tx_packets; /* total packets transmitted */
30 unsigned long rx_bytes; /* total bytes received */
31 unsigned long tx_bytes; /* total bytes transmitted */
32 unsigned long rx_errors; /* bad packets received */
33 unsigned long tx_errors; /* packet transmit problems */
34 unsigned long rx_dropped; /* packets dropped by dongle */
35 unsigned long tx_dropped; /* packets dropped by dongle */
36 unsigned long multicast; /* multicast packets received */
37};
38
Franky Lin135e4c62012-06-26 21:26:34 +020039struct brcmf_bus_dcmd {
40 char *name;
41 char *param;
42 int param_len;
43 struct list_head list;
44};
45
Arend van Sprield9cb2592012-12-05 15:25:54 +010046/**
47 * struct brcmf_bus_ops - bus callback operations.
48 *
49 * @init: prepare for communication with dongle.
50 * @stop: clear pending frames, disable data flow.
51 * @txdata: send a data frame to the dongle (callee disposes skb).
52 * @txctl: transmit a control request message to dongle.
53 * @rxctl: receive a control response message from dongle.
54 *
55 * This structure provides an abstract interface towards the
56 * bus specific driver. For control messages to common driver
57 * will assure there is only one active transaction.
58 */
59struct brcmf_bus_ops {
60 int (*init)(struct device *dev);
61 void (*stop)(struct device *dev);
62 int (*txdata)(struct device *dev, struct sk_buff *skb);
63 int (*txctl)(struct device *dev, unsigned char *msg, uint len);
64 int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
65};
66
67/**
68 * struct brcmf_bus - interface structure between common and bus layer
69 *
70 * @bus_priv: pointer to private bus device.
71 * @dev: device pointer of bus device.
72 * @drvr: public driver information.
73 * @state: operational state of the bus interface.
74 * @maxctl: maximum size for rxctl request message.
75 * @drvr_up: indicates driver up/down status.
76 * @tx_realloc: number of tx packets realloced for headroom.
77 * @dstats: dongle-based statistical data.
78 * @align: alignment requirement for the bus.
79 * @dcmd_list: bus/device specific dongle initialization commands.
80 */
Franky Lina8a363a2011-12-16 18:37:13 -080081struct brcmf_bus {
Arend van Spriel0a332e42012-02-09 21:09:02 +010082 union {
Arend van Spriel0a332e42012-02-09 21:09:02 +010083 struct brcmf_sdio_dev *sdio;
Arend van Spriel71bb2442012-02-09 21:09:08 +010084 struct brcmf_usbdev *usb;
Arend van Spriel0a332e42012-02-09 21:09:02 +010085 } bus_priv;
Arend van Sprield9cb2592012-12-05 15:25:54 +010086 struct device *dev;
87 struct brcmf_pub *drvr;
Franky Lina8a363a2011-12-16 18:37:13 -080088 enum brcmf_bus_state state;
Arend van Sprield9cb2592012-12-05 15:25:54 +010089 uint maxctl;
90 bool drvr_up;
91 unsigned long tx_realloc;
92 struct dngl_stats dstats;
93 u8 align;
Franky Lin135e4c62012-06-26 21:26:34 +020094 struct list_head dcmd_list;
Franky Lina8a363a2011-12-16 18:37:13 -080095
Arend van Sprield9cb2592012-12-05 15:25:54 +010096 struct brcmf_bus_ops *ops;
Franky Lina8a363a2011-12-16 18:37:13 -080097};
98
99/*
Arend van Sprield9cb2592012-12-05 15:25:54 +0100100 * callback wrappers
101 */
102static inline int brcmf_bus_init(struct brcmf_bus *bus)
103{
104 return bus->ops->init(bus->dev);
105}
106
107static inline void brcmf_bus_stop(struct brcmf_bus *bus)
108{
109 bus->ops->stop(bus->dev);
110}
111
112static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
113{
114 return bus->ops->txdata(bus->dev, skb);
115}
116
117static inline
118int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
119{
120 return bus->ops->txctl(bus->dev, msg, len);
121}
122
123static inline
124int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
125{
126 return bus->ops->rxctl(bus->dev, msg, len);
127}
128
129/*
Franky Lina8a363a2011-12-16 18:37:13 -0800130 * interface functions from common layer
131 */
132
133/* Remove any protocol-specific data header. */
134extern int brcmf_proto_hdrpull(struct device *dev, int *ifidx,
135 struct sk_buff *rxp);
136
137extern 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 Spriel5c36b992012-11-14 18:46:05 -0800141extern void brcmf_rx_frame(struct device *dev, u8 ifidx,
Franky Lina8a363a2011-12-16 18:37:13 -0800142 struct sk_buff_head *rxlist);
143static inline void brcmf_rx_packet(struct device *dev, int ifidx,
144 struct sk_buff *pkt)
145{
146 struct sk_buff_head q;
147
148 skb_queue_head_init(&q);
149 skb_queue_tail(&q, pkt);
150 brcmf_rx_frame(dev, ifidx, &q);
151}
152
153/* Indication from bus module regarding presence/insertion of dongle. */
154extern int brcmf_attach(uint bus_hdrlen, struct device *dev);
155/* Indication from bus module regarding removal/absence of dongle */
156extern void brcmf_detach(struct device *dev);
157
158/* Indication from bus module to change flow-control state */
Hante Meuleman90d03ff2012-09-11 21:18:46 +0200159extern void brcmf_txflowblock(struct device *dev, bool state);
Franky Lina8a363a2011-12-16 18:37:13 -0800160
161/* Notify tx completion */
162extern void brcmf_txcomplete(struct device *dev, struct sk_buff *txp,
163 bool success);
164
165extern int brcmf_bus_start(struct device *dev);
166
Arend van Sprielf3d7cdc2012-02-09 21:09:03 +0100167#ifdef CONFIG_BRCMFMAC_SDIO
168extern void brcmf_sdio_exit(void);
Arend van Spriel549040a2012-03-02 22:55:48 +0100169extern void brcmf_sdio_init(void);
Arend van Sprielf3d7cdc2012-02-09 21:09:03 +0100170#endif
Arend van Spriel71bb2442012-02-09 21:09:08 +0100171#ifdef CONFIG_BRCMFMAC_USB
172extern void brcmf_usb_exit(void);
Arend van Spriel549040a2012-03-02 22:55:48 +0100173extern void brcmf_usb_init(void);
Arend van Spriel71bb2442012-02-09 21:09:08 +0100174#endif
Arend van Sprielf3d7cdc2012-02-09 21:09:03 +0100175
Arend van Spriel5b435de2011-10-05 13:19:03 +0200176#endif /* _BRCMF_BUS_H_ */