Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 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 | |
Franky Lin | a8a363a | 2011-12-16 18:37:13 -0800 | [diff] [blame] | 20 | /* The level of bus communication with the dongle */ |
| 21 | enum 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 Lin | 135e4c6 | 2012-06-26 21:26:34 +0200 | [diff] [blame] | 27 | struct brcmf_bus_dcmd { |
| 28 | char *name; |
| 29 | char *param; |
| 30 | int param_len; |
| 31 | struct list_head list; |
| 32 | }; |
| 33 | |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 34 | /** |
| 35 | * struct brcmf_bus_ops - bus callback operations. |
| 36 | * |
| 37 | * @init: prepare for communication with dongle. |
| 38 | * @stop: clear pending frames, disable data flow. |
| 39 | * @txdata: send a data frame to the dongle (callee disposes skb). |
| 40 | * @txctl: transmit a control request message to dongle. |
| 41 | * @rxctl: receive a control response message from dongle. |
Arend van Spriel | e2432b6 | 2013-04-03 12:40:38 +0200 | [diff] [blame] | 42 | * @gettxq: obtain a reference of bus transmit queue (optional). |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 43 | * |
| 44 | * This structure provides an abstract interface towards the |
| 45 | * bus specific driver. For control messages to common driver |
Arend van Spriel | e2432b6 | 2013-04-03 12:40:38 +0200 | [diff] [blame] | 46 | * will assure there is only one active transaction. Unless |
| 47 | * indicated otherwise these callbacks are mandatory. |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 48 | */ |
| 49 | struct brcmf_bus_ops { |
| 50 | int (*init)(struct device *dev); |
| 51 | void (*stop)(struct device *dev); |
| 52 | int (*txdata)(struct device *dev, struct sk_buff *skb); |
| 53 | int (*txctl)(struct device *dev, unsigned char *msg, uint len); |
| 54 | int (*rxctl)(struct device *dev, unsigned char *msg, uint len); |
Arend van Spriel | e2432b6 | 2013-04-03 12:40:38 +0200 | [diff] [blame] | 55 | struct pktq * (*gettxq)(struct device *dev); |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | /** |
| 59 | * struct brcmf_bus - interface structure between common and bus layer |
| 60 | * |
| 61 | * @bus_priv: pointer to private bus device. |
| 62 | * @dev: device pointer of bus device. |
| 63 | * @drvr: public driver information. |
| 64 | * @state: operational state of the bus interface. |
| 65 | * @maxctl: maximum size for rxctl request message. |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 66 | * @tx_realloc: number of tx packets realloced for headroom. |
| 67 | * @dstats: dongle-based statistical data. |
| 68 | * @align: alignment requirement for the bus. |
| 69 | * @dcmd_list: bus/device specific dongle initialization commands. |
Arend van Spriel | 75d907d | 2013-02-06 18:40:45 +0100 | [diff] [blame] | 70 | * @chip: device identifier of the dongle chip. |
| 71 | * @chiprev: revision of the dongle chip. |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 72 | */ |
Franky Lin | a8a363a | 2011-12-16 18:37:13 -0800 | [diff] [blame] | 73 | struct brcmf_bus { |
Arend van Spriel | 0a332e4 | 2012-02-09 21:09:02 +0100 | [diff] [blame] | 74 | union { |
Arend van Spriel | 0a332e4 | 2012-02-09 21:09:02 +0100 | [diff] [blame] | 75 | struct brcmf_sdio_dev *sdio; |
Arend van Spriel | 71bb244 | 2012-02-09 21:09:08 +0100 | [diff] [blame] | 76 | struct brcmf_usbdev *usb; |
Arend van Spriel | 0a332e4 | 2012-02-09 21:09:02 +0100 | [diff] [blame] | 77 | } bus_priv; |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 78 | struct device *dev; |
| 79 | struct brcmf_pub *drvr; |
Franky Lin | a8a363a | 2011-12-16 18:37:13 -0800 | [diff] [blame] | 80 | enum brcmf_bus_state state; |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 81 | uint maxctl; |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 82 | unsigned long tx_realloc; |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 83 | u8 align; |
Arend van Spriel | 75d907d | 2013-02-06 18:40:45 +0100 | [diff] [blame] | 84 | u32 chip; |
| 85 | u32 chiprev; |
Franky Lin | 135e4c6 | 2012-06-26 21:26:34 +0200 | [diff] [blame] | 86 | struct list_head dcmd_list; |
Franky Lin | a8a363a | 2011-12-16 18:37:13 -0800 | [diff] [blame] | 87 | |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 88 | struct brcmf_bus_ops *ops; |
Franky Lin | a8a363a | 2011-12-16 18:37:13 -0800 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | /* |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 92 | * callback wrappers |
| 93 | */ |
| 94 | static inline int brcmf_bus_init(struct brcmf_bus *bus) |
| 95 | { |
| 96 | return bus->ops->init(bus->dev); |
| 97 | } |
| 98 | |
| 99 | static inline void brcmf_bus_stop(struct brcmf_bus *bus) |
| 100 | { |
| 101 | bus->ops->stop(bus->dev); |
| 102 | } |
| 103 | |
| 104 | static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb) |
| 105 | { |
| 106 | return bus->ops->txdata(bus->dev, skb); |
| 107 | } |
| 108 | |
| 109 | static inline |
| 110 | int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len) |
| 111 | { |
| 112 | return bus->ops->txctl(bus->dev, msg, len); |
| 113 | } |
| 114 | |
| 115 | static inline |
| 116 | int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len) |
| 117 | { |
| 118 | return bus->ops->rxctl(bus->dev, msg, len); |
| 119 | } |
| 120 | |
Arend van Spriel | e2432b6 | 2013-04-03 12:40:38 +0200 | [diff] [blame] | 121 | static inline |
| 122 | struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus) |
| 123 | { |
| 124 | if (!bus->ops->gettxq) |
| 125 | return ERR_PTR(-ENOENT); |
| 126 | |
| 127 | return bus->ops->gettxq(bus->dev); |
| 128 | } |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 129 | /* |
Franky Lin | a8a363a | 2011-12-16 18:37:13 -0800 | [diff] [blame] | 130 | * interface functions from common layer |
| 131 | */ |
| 132 | |
Franky Lin | a8a363a | 2011-12-16 18:37:13 -0800 | [diff] [blame] | 133 | extern bool brcmf_c_prec_enq(struct device *dev, struct pktq *q, |
| 134 | struct sk_buff *pkt, int prec); |
| 135 | |
| 136 | /* Receive frame for delivery to OS. Callee disposes of rxp. */ |
Arend van Spriel | a43af51 | 2013-01-02 15:22:43 +0100 | [diff] [blame] | 137 | extern void brcmf_rx_frames(struct device *dev, struct sk_buff_head *rxlist); |
Franky Lin | a8a363a | 2011-12-16 18:37:13 -0800 | [diff] [blame] | 138 | |
| 139 | /* Indication from bus module regarding presence/insertion of dongle. */ |
| 140 | extern int brcmf_attach(uint bus_hdrlen, struct device *dev); |
| 141 | /* Indication from bus module regarding removal/absence of dongle */ |
| 142 | extern void brcmf_detach(struct device *dev); |
Arend van Spriel | 81d5f1b | 2013-01-02 15:22:40 +0100 | [diff] [blame] | 143 | /* Indication from bus module that dongle should be reset */ |
| 144 | extern void brcmf_dev_reset(struct device *dev); |
Franky Lin | a8a363a | 2011-12-16 18:37:13 -0800 | [diff] [blame] | 145 | /* Indication from bus module to change flow-control state */ |
Hante Meuleman | 90d03ff | 2012-09-11 21:18:46 +0200 | [diff] [blame] | 146 | extern void brcmf_txflowblock(struct device *dev, bool state); |
Franky Lin | a8a363a | 2011-12-16 18:37:13 -0800 | [diff] [blame] | 147 | |
Arend van Spriel | 7f4bcee | 2013-03-03 12:45:29 +0100 | [diff] [blame] | 148 | /* Notify the bus has transferred the tx packet to firmware */ |
Franky Lin | a8a363a | 2011-12-16 18:37:13 -0800 | [diff] [blame] | 149 | extern void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, |
| 150 | bool success); |
| 151 | |
| 152 | extern int brcmf_bus_start(struct device *dev); |
| 153 | |
Arend van Spriel | f3d7cdc | 2012-02-09 21:09:03 +0100 | [diff] [blame] | 154 | #ifdef CONFIG_BRCMFMAC_SDIO |
| 155 | extern void brcmf_sdio_exit(void); |
Arend van Spriel | 549040a | 2012-03-02 22:55:48 +0100 | [diff] [blame] | 156 | extern void brcmf_sdio_init(void); |
Arend van Spriel | f3d7cdc | 2012-02-09 21:09:03 +0100 | [diff] [blame] | 157 | #endif |
Arend van Spriel | 71bb244 | 2012-02-09 21:09:08 +0100 | [diff] [blame] | 158 | #ifdef CONFIG_BRCMFMAC_USB |
| 159 | extern void brcmf_usb_exit(void); |
Arend van Spriel | 549040a | 2012-03-02 22:55:48 +0100 | [diff] [blame] | 160 | extern void brcmf_usb_init(void); |
Arend van Spriel | 71bb244 | 2012-02-09 21:09:08 +0100 | [diff] [blame] | 161 | #endif |
Arend van Spriel | f3d7cdc | 2012-02-09 21:09:03 +0100 | [diff] [blame] | 162 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 163 | #endif /* _BRCMF_BUS_H_ */ |