i2c: gpio: fault-injector: refactor incomplete transfer
[linux/fpc-iii.git] / drivers / net / wireless / quantenna / qtnfmac / bus.h
blob323e47cea1e2ff579f8f0b392b44536d74b8d5db
1 /*
2 * Copyright (c) 2015 Quantenna Communications
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.
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.
17 #ifndef QTNFMAC_BUS_H
18 #define QTNFMAC_BUS_H
20 #include <linux/netdevice.h>
21 #include <linux/workqueue.h>
23 #define QTNF_MAX_MAC 3
25 enum qtnf_fw_state {
26 QTNF_FW_STATE_RESET,
27 QTNF_FW_STATE_FW_DNLD_DONE,
28 QTNF_FW_STATE_BOOT_DONE,
29 QTNF_FW_STATE_ACTIVE,
30 QTNF_FW_STATE_DETACHED,
31 QTNF_FW_STATE_EP_DEAD,
34 struct qtnf_bus;
36 struct qtnf_bus_ops {
37 /* mgmt methods */
38 int (*preinit)(struct qtnf_bus *);
39 void (*stop)(struct qtnf_bus *);
41 /* control path methods */
42 int (*control_tx)(struct qtnf_bus *, struct sk_buff *);
44 /* data xfer methods */
45 int (*data_tx)(struct qtnf_bus *, struct sk_buff *);
46 void (*data_tx_timeout)(struct qtnf_bus *, struct net_device *);
47 void (*data_rx_start)(struct qtnf_bus *);
48 void (*data_rx_stop)(struct qtnf_bus *);
51 struct qtnf_bus {
52 struct device *dev;
53 enum qtnf_fw_state fw_state;
54 u32 chip;
55 u32 chiprev;
56 const struct qtnf_bus_ops *bus_ops;
57 struct qtnf_wmac *mac[QTNF_MAX_MAC];
58 struct qtnf_qlink_transport trans;
59 struct qtnf_hw_info hw_info;
60 char fwname[32];
61 struct napi_struct mux_napi;
62 struct net_device mux_dev;
63 struct completion firmware_init_complete;
64 struct workqueue_struct *workqueue;
65 struct work_struct fw_work;
66 struct work_struct event_work;
67 struct mutex bus_lock; /* lock during command/event processing */
68 struct dentry *dbg_dir;
69 /* bus private data */
70 char bus_priv[0] __aligned(sizeof(void *));
73 static inline void *get_bus_priv(struct qtnf_bus *bus)
75 if (WARN(!bus, "qtnfmac: invalid bus pointer"))
76 return NULL;
78 return &bus->bus_priv;
81 /* callback wrappers */
83 static inline int qtnf_bus_preinit(struct qtnf_bus *bus)
85 if (!bus->bus_ops->preinit)
86 return 0;
87 return bus->bus_ops->preinit(bus);
90 static inline void qtnf_bus_stop(struct qtnf_bus *bus)
92 if (!bus->bus_ops->stop)
93 return;
94 bus->bus_ops->stop(bus);
97 static inline int qtnf_bus_data_tx(struct qtnf_bus *bus, struct sk_buff *skb)
99 return bus->bus_ops->data_tx(bus, skb);
102 static inline void
103 qtnf_bus_data_tx_timeout(struct qtnf_bus *bus, struct net_device *ndev)
105 return bus->bus_ops->data_tx_timeout(bus, ndev);
108 static inline int qtnf_bus_control_tx(struct qtnf_bus *bus, struct sk_buff *skb)
110 return bus->bus_ops->control_tx(bus, skb);
113 static inline void qtnf_bus_data_rx_start(struct qtnf_bus *bus)
115 return bus->bus_ops->data_rx_start(bus);
118 static inline void qtnf_bus_data_rx_stop(struct qtnf_bus *bus)
120 return bus->bus_ops->data_rx_stop(bus);
123 static __always_inline void qtnf_bus_lock(struct qtnf_bus *bus)
125 mutex_lock(&bus->bus_lock);
128 static __always_inline void qtnf_bus_unlock(struct qtnf_bus *bus)
130 mutex_unlock(&bus->bus_lock);
133 /* interface functions from common layer */
135 int qtnf_core_attach(struct qtnf_bus *bus);
136 void qtnf_core_detach(struct qtnf_bus *bus);
137 void qtnf_txflowblock(struct device *dev, bool state);
138 void qtnf_txcomplete(struct device *dev, struct sk_buff *txp, bool success);
140 #endif /* QTNFMAC_BUS_H */