Linux Audio

Check our new training course

Loading...
v6.8
  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#define HBM_FRAME_META_MAGIC_PATTERN_S	0xAB
 16#define HBM_FRAME_META_MAGIC_PATTERN_E	0xBA
 17
 18struct qtnf_frame_meta_info {
 19	u8 magic_s;
 20	u8 ifidx;
 21	u8 macid;
 22	u8 magic_e;
 23} __packed;
 24
 25enum qtnf_fw_state {
 26	QTNF_FW_STATE_DETACHED,
 
 27	QTNF_FW_STATE_BOOT_DONE,
 28	QTNF_FW_STATE_ACTIVE,
 29	QTNF_FW_STATE_RUNNING,
 30	QTNF_FW_STATE_DEAD,
 31};
 32
 33struct qtnf_bus;
 34
 35struct qtnf_bus_ops {
 36	/* mgmt methods */
 37	int (*preinit)(struct qtnf_bus *);
 38	void (*stop)(struct qtnf_bus *);
 39
 40	/* control path methods */
 41	int (*control_tx)(struct qtnf_bus *, struct sk_buff *);
 42
 43	/* data xfer methods */
 44	int (*data_tx)(struct qtnf_bus *bus, struct sk_buff *skb,
 45		       unsigned int macid, unsigned int vifid);
 46	void (*data_tx_timeout)(struct qtnf_bus *, struct net_device *);
 47	void (*data_tx_use_meta_set)(struct qtnf_bus *bus, bool use_meta);
 48	void (*data_rx_start)(struct qtnf_bus *);
 49	void (*data_rx_stop)(struct qtnf_bus *);
 50};
 51
 52struct qtnf_bus {
 53	struct device *dev;
 54	enum qtnf_fw_state fw_state;
 55	u32 chip;
 56	u32 chiprev;
 57	struct qtnf_bus_ops *bus_ops;
 58	struct qtnf_wmac *mac[QTNF_MAX_MAC];
 59	struct qtnf_qlink_transport trans;
 60	struct qtnf_hw_info hw_info;
 
 61	struct napi_struct mux_napi;
 62	struct net_device mux_dev;
 
 63	struct workqueue_struct *workqueue;
 64	struct workqueue_struct *hprio_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	struct notifier_block netdev_nb;
 70	u8 hw_id[ETH_ALEN];
 71	/* bus private data */
 72	char bus_priv[] __aligned(sizeof(void *));
 73};
 74
 75static inline bool qtnf_fw_is_up(struct qtnf_bus *bus)
 76{
 77	enum qtnf_fw_state state = bus->fw_state;
 78
 79	return ((state == QTNF_FW_STATE_ACTIVE) ||
 80		(state == QTNF_FW_STATE_RUNNING));
 81}
 82
 83static inline bool qtnf_fw_is_attached(struct qtnf_bus *bus)
 84{
 85	enum qtnf_fw_state state = bus->fw_state;
 86
 87	return ((state == QTNF_FW_STATE_ACTIVE) ||
 88		(state == QTNF_FW_STATE_RUNNING) ||
 89		(state == QTNF_FW_STATE_DEAD));
 90}
 91
 92static inline void *get_bus_priv(struct qtnf_bus *bus)
 93{
 94	if (WARN(!bus, "qtnfmac: invalid bus pointer"))
 95		return NULL;
 96
 97	return &bus->bus_priv;
 98}
 99
100/* callback wrappers */
101
102static inline int qtnf_bus_preinit(struct qtnf_bus *bus)
103{
104	if (!bus->bus_ops->preinit)
105		return 0;
106	return bus->bus_ops->preinit(bus);
107}
108
109static inline void qtnf_bus_stop(struct qtnf_bus *bus)
110{
111	if (!bus->bus_ops->stop)
112		return;
113	bus->bus_ops->stop(bus);
114}
115
116static inline int qtnf_bus_data_tx(struct qtnf_bus *bus, struct sk_buff *skb,
117				   unsigned int macid, unsigned int vifid)
118{
119	return bus->bus_ops->data_tx(bus, skb, macid, vifid);
120}
121
122static inline void
123qtnf_bus_data_tx_timeout(struct qtnf_bus *bus, struct net_device *ndev)
124{
125	return bus->bus_ops->data_tx_timeout(bus, ndev);
126}
127
128static inline int qtnf_bus_control_tx(struct qtnf_bus *bus, struct sk_buff *skb)
129{
130	return bus->bus_ops->control_tx(bus, skb);
131}
132
133static inline void qtnf_bus_data_rx_start(struct qtnf_bus *bus)
134{
135	return bus->bus_ops->data_rx_start(bus);
136}
137
138static inline void qtnf_bus_data_rx_stop(struct qtnf_bus *bus)
139{
140	return bus->bus_ops->data_rx_stop(bus);
141}
142
143static __always_inline void qtnf_bus_lock(struct qtnf_bus *bus)
144{
145	mutex_lock(&bus->bus_lock);
146}
147
148static __always_inline void qtnf_bus_unlock(struct qtnf_bus *bus)
149{
150	mutex_unlock(&bus->bus_lock);
151}
152
153/* interface functions from common layer */
154
155int qtnf_core_attach(struct qtnf_bus *bus);
156void qtnf_core_detach(struct qtnf_bus *bus);
 
 
157
158#endif /* QTNFMAC_BUS_H */
v4.17
  1/*
  2 * Copyright (c) 2015 Quantenna Communications
  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 QTNFMAC_BUS_H
 18#define QTNFMAC_BUS_H
 19
 20#include <linux/netdevice.h>
 21#include <linux/workqueue.h>
 22
 
 
 
 23#define QTNF_MAX_MAC		3
 24
 
 
 
 
 
 
 
 
 
 
 25enum 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_DEAD,
 31};
 32
 33struct qtnf_bus;
 34
 35struct qtnf_bus_ops {
 36	/* mgmt methods */
 37	int (*preinit)(struct qtnf_bus *);
 38	void (*stop)(struct qtnf_bus *);
 39
 40	/* control path methods */
 41	int (*control_tx)(struct qtnf_bus *, struct sk_buff *);
 42
 43	/* data xfer methods */
 44	int (*data_tx)(struct qtnf_bus *, struct sk_buff *);
 
 45	void (*data_tx_timeout)(struct qtnf_bus *, struct net_device *);
 
 46	void (*data_rx_start)(struct qtnf_bus *);
 47	void (*data_rx_stop)(struct qtnf_bus *);
 48};
 49
 50struct qtnf_bus {
 51	struct device *dev;
 52	enum qtnf_fw_state fw_state;
 53	u32 chip;
 54	u32 chiprev;
 55	const struct qtnf_bus_ops *bus_ops;
 56	struct qtnf_wmac *mac[QTNF_MAX_MAC];
 57	struct qtnf_qlink_transport trans;
 58	struct qtnf_hw_info hw_info;
 59	char fwname[32];
 60	struct napi_struct mux_napi;
 61	struct net_device mux_dev;
 62	struct completion firmware_init_complete;
 63	struct workqueue_struct *workqueue;
 
 64	struct work_struct fw_work;
 65	struct work_struct event_work;
 66	struct mutex bus_lock; /* lock during command/event processing */
 67	struct dentry *dbg_dir;
 
 
 68	/* bus private data */
 69	char bus_priv[0] __aligned(sizeof(void *));
 70};
 71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 72static inline void *get_bus_priv(struct qtnf_bus *bus)
 73{
 74	if (WARN(!bus, "qtnfmac: invalid bus pointer"))
 75		return NULL;
 76
 77	return &bus->bus_priv;
 78}
 79
 80/* callback wrappers */
 81
 82static inline int qtnf_bus_preinit(struct qtnf_bus *bus)
 83{
 84	if (!bus->bus_ops->preinit)
 85		return 0;
 86	return bus->bus_ops->preinit(bus);
 87}
 88
 89static inline void qtnf_bus_stop(struct qtnf_bus *bus)
 90{
 91	if (!bus->bus_ops->stop)
 92		return;
 93	bus->bus_ops->stop(bus);
 94}
 95
 96static inline int qtnf_bus_data_tx(struct qtnf_bus *bus, struct sk_buff *skb)
 
 97{
 98	return bus->bus_ops->data_tx(bus, skb);
 99}
100
101static inline void
102qtnf_bus_data_tx_timeout(struct qtnf_bus *bus, struct net_device *ndev)
103{
104	return bus->bus_ops->data_tx_timeout(bus, ndev);
105}
106
107static inline int qtnf_bus_control_tx(struct qtnf_bus *bus, struct sk_buff *skb)
108{
109	return bus->bus_ops->control_tx(bus, skb);
110}
111
112static inline void qtnf_bus_data_rx_start(struct qtnf_bus *bus)
113{
114	return bus->bus_ops->data_rx_start(bus);
115}
116
117static inline void qtnf_bus_data_rx_stop(struct qtnf_bus *bus)
118{
119	return bus->bus_ops->data_rx_stop(bus);
120}
121
122static __always_inline void qtnf_bus_lock(struct qtnf_bus *bus)
123{
124	mutex_lock(&bus->bus_lock);
125}
126
127static __always_inline void qtnf_bus_unlock(struct qtnf_bus *bus)
128{
129	mutex_unlock(&bus->bus_lock);
130}
131
132/* interface functions from common layer */
133
134int qtnf_core_attach(struct qtnf_bus *bus);
135void qtnf_core_detach(struct qtnf_bus *bus);
136void qtnf_txflowblock(struct device *dev, bool state);
137void qtnf_txcomplete(struct device *dev, struct sk_buff *txp, bool success);
138
139#endif /* QTNFMAC_BUS_H */