• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /* Copyright (c) 2015 Quantenna Communications. All rights reserved. */
3 
4 #ifndef QTNFMAC_BUS_H
5 #define QTNFMAC_BUS_H
6 
7 #include <linux/netdevice.h>
8 #include <linux/workqueue.h>
9 
10 #include "trans.h"
11 #include "core.h"
12 
13 #define QTNF_MAX_MAC		3
14 
15 enum qtnf_fw_state {
16 	QTNF_FW_STATE_DETACHED,
17 	QTNF_FW_STATE_BOOT_DONE,
18 	QTNF_FW_STATE_ACTIVE,
19 	QTNF_FW_STATE_RUNNING,
20 	QTNF_FW_STATE_DEAD,
21 };
22 
23 struct qtnf_bus;
24 
25 struct qtnf_bus_ops {
26 	/* mgmt methods */
27 	int (*preinit)(struct qtnf_bus *);
28 	void (*stop)(struct qtnf_bus *);
29 
30 	/* control path methods */
31 	int (*control_tx)(struct qtnf_bus *, struct sk_buff *);
32 
33 	/* data xfer methods */
34 	int (*data_tx)(struct qtnf_bus *, struct sk_buff *);
35 	void (*data_tx_timeout)(struct qtnf_bus *, struct net_device *);
36 	void (*data_rx_start)(struct qtnf_bus *);
37 	void (*data_rx_stop)(struct qtnf_bus *);
38 };
39 
40 struct qtnf_bus {
41 	struct device *dev;
42 	enum qtnf_fw_state fw_state;
43 	u32 chip;
44 	u32 chiprev;
45 	const struct qtnf_bus_ops *bus_ops;
46 	struct qtnf_wmac *mac[QTNF_MAX_MAC];
47 	struct qtnf_qlink_transport trans;
48 	struct qtnf_hw_info hw_info;
49 	struct napi_struct mux_napi;
50 	struct net_device mux_dev;
51 	struct workqueue_struct *workqueue;
52 	struct workqueue_struct *hprio_workqueue;
53 	struct work_struct fw_work;
54 	struct work_struct event_work;
55 	struct mutex bus_lock; /* lock during command/event processing */
56 	struct dentry *dbg_dir;
57 	/* bus private data */
58 	char bus_priv[0] __aligned(sizeof(void *));
59 };
60 
qtnf_fw_is_up(struct qtnf_bus * bus)61 static inline bool qtnf_fw_is_up(struct qtnf_bus *bus)
62 {
63 	enum qtnf_fw_state state = bus->fw_state;
64 
65 	return ((state == QTNF_FW_STATE_ACTIVE) ||
66 		(state == QTNF_FW_STATE_RUNNING));
67 }
68 
qtnf_fw_is_attached(struct qtnf_bus * bus)69 static inline bool qtnf_fw_is_attached(struct qtnf_bus *bus)
70 {
71 	enum qtnf_fw_state state = bus->fw_state;
72 
73 	return ((state == QTNF_FW_STATE_ACTIVE) ||
74 		(state == QTNF_FW_STATE_RUNNING) ||
75 		(state == QTNF_FW_STATE_DEAD));
76 }
77 
get_bus_priv(struct qtnf_bus * bus)78 static inline void *get_bus_priv(struct qtnf_bus *bus)
79 {
80 	if (WARN(!bus, "qtnfmac: invalid bus pointer"))
81 		return NULL;
82 
83 	return &bus->bus_priv;
84 }
85 
86 /* callback wrappers */
87 
qtnf_bus_preinit(struct qtnf_bus * bus)88 static inline int qtnf_bus_preinit(struct qtnf_bus *bus)
89 {
90 	if (!bus->bus_ops->preinit)
91 		return 0;
92 	return bus->bus_ops->preinit(bus);
93 }
94 
qtnf_bus_stop(struct qtnf_bus * bus)95 static inline void qtnf_bus_stop(struct qtnf_bus *bus)
96 {
97 	if (!bus->bus_ops->stop)
98 		return;
99 	bus->bus_ops->stop(bus);
100 }
101 
qtnf_bus_data_tx(struct qtnf_bus * bus,struct sk_buff * skb)102 static inline int qtnf_bus_data_tx(struct qtnf_bus *bus, struct sk_buff *skb)
103 {
104 	return bus->bus_ops->data_tx(bus, skb);
105 }
106 
107 static inline void
qtnf_bus_data_tx_timeout(struct qtnf_bus * bus,struct net_device * ndev)108 qtnf_bus_data_tx_timeout(struct qtnf_bus *bus, struct net_device *ndev)
109 {
110 	return bus->bus_ops->data_tx_timeout(bus, ndev);
111 }
112 
qtnf_bus_control_tx(struct qtnf_bus * bus,struct sk_buff * skb)113 static inline int qtnf_bus_control_tx(struct qtnf_bus *bus, struct sk_buff *skb)
114 {
115 	return bus->bus_ops->control_tx(bus, skb);
116 }
117 
qtnf_bus_data_rx_start(struct qtnf_bus * bus)118 static inline void qtnf_bus_data_rx_start(struct qtnf_bus *bus)
119 {
120 	return bus->bus_ops->data_rx_start(bus);
121 }
122 
qtnf_bus_data_rx_stop(struct qtnf_bus * bus)123 static inline void qtnf_bus_data_rx_stop(struct qtnf_bus *bus)
124 {
125 	return bus->bus_ops->data_rx_stop(bus);
126 }
127 
qtnf_bus_lock(struct qtnf_bus * bus)128 static __always_inline void qtnf_bus_lock(struct qtnf_bus *bus)
129 {
130 	mutex_lock(&bus->bus_lock);
131 }
132 
qtnf_bus_unlock(struct qtnf_bus * bus)133 static __always_inline void qtnf_bus_unlock(struct qtnf_bus *bus)
134 {
135 	mutex_unlock(&bus->bus_lock);
136 }
137 
138 /* interface functions from common layer */
139 
140 int qtnf_core_attach(struct qtnf_bus *bus);
141 void qtnf_core_detach(struct qtnf_bus *bus);
142 
143 #endif /* QTNFMAC_BUS_H */
144