162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef B43legacy_PIO_H_
362306a36Sopenharmony_ci#define B43legacy_PIO_H_
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include "b43legacy.h"
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#include <linux/interrupt.h>
862306a36Sopenharmony_ci#include <linux/list.h>
962306a36Sopenharmony_ci#include <linux/skbuff.h>
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#define B43legacy_PIO_TXCTL		0x00
1362306a36Sopenharmony_ci#define B43legacy_PIO_TXDATA		0x02
1462306a36Sopenharmony_ci#define B43legacy_PIO_TXQBUFSIZE	0x04
1562306a36Sopenharmony_ci#define B43legacy_PIO_RXCTL		0x08
1662306a36Sopenharmony_ci#define B43legacy_PIO_RXDATA		0x0A
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#define B43legacy_PIO_TXCTL_WRITELO	(1 << 0)
1962306a36Sopenharmony_ci#define B43legacy_PIO_TXCTL_WRITEHI	(1 << 1)
2062306a36Sopenharmony_ci#define B43legacy_PIO_TXCTL_COMPLETE	(1 << 2)
2162306a36Sopenharmony_ci#define B43legacy_PIO_TXCTL_INIT	(1 << 3)
2262306a36Sopenharmony_ci#define B43legacy_PIO_TXCTL_SUSPEND	(1 << 7)
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#define B43legacy_PIO_RXCTL_DATAAVAILABLE	(1 << 0)
2562306a36Sopenharmony_ci#define B43legacy_PIO_RXCTL_READY		(1 << 1)
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci/* PIO constants */
2862306a36Sopenharmony_ci#define B43legacy_PIO_MAXTXDEVQPACKETS	31
2962306a36Sopenharmony_ci#define B43legacy_PIO_TXQADJUST		80
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci/* PIO tuning knobs */
3262306a36Sopenharmony_ci#define B43legacy_PIO_MAXTXPACKETS	256
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci#ifdef CONFIG_B43LEGACY_PIO
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_cistruct b43legacy_pioqueue;
4062306a36Sopenharmony_cistruct b43legacy_xmitstatus;
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_cistruct b43legacy_pio_txpacket {
4362306a36Sopenharmony_ci	struct b43legacy_pioqueue *queue;
4462306a36Sopenharmony_ci	struct sk_buff *skb;
4562306a36Sopenharmony_ci	struct list_head list;
4662306a36Sopenharmony_ci};
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci#define pio_txpacket_getindex(packet) ((int)((packet) - \
4962306a36Sopenharmony_ci			      (packet)->queue->tx_packets_cache))
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_cistruct b43legacy_pioqueue {
5262306a36Sopenharmony_ci	struct b43legacy_wldev *dev;
5362306a36Sopenharmony_ci	u16 mmio_base;
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci	bool tx_suspended;
5662306a36Sopenharmony_ci	bool tx_frozen;
5762306a36Sopenharmony_ci	bool need_workarounds; /* Workarounds needed for core.rev < 3 */
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci	/* Adjusted size of the device internal TX buffer. */
6062306a36Sopenharmony_ci	u16 tx_devq_size;
6162306a36Sopenharmony_ci	/* Used octets of the device internal TX buffer. */
6262306a36Sopenharmony_ci	u16 tx_devq_used;
6362306a36Sopenharmony_ci	/* Used packet slots in the device internal TX buffer. */
6462306a36Sopenharmony_ci	u8 tx_devq_packets;
6562306a36Sopenharmony_ci	/* Packets from the txfree list can
6662306a36Sopenharmony_ci	 * be taken on incoming TX requests.
6762306a36Sopenharmony_ci	 */
6862306a36Sopenharmony_ci	struct list_head txfree;
6962306a36Sopenharmony_ci	unsigned int nr_txfree;
7062306a36Sopenharmony_ci	/* Packets on the txqueue are queued,
7162306a36Sopenharmony_ci	 * but not completely written to the chip, yet.
7262306a36Sopenharmony_ci	 */
7362306a36Sopenharmony_ci	struct list_head txqueue;
7462306a36Sopenharmony_ci	/* Packets on the txrunning queue are completely
7562306a36Sopenharmony_ci	 * posted to the device. We are waiting for the txstatus.
7662306a36Sopenharmony_ci	 */
7762306a36Sopenharmony_ci	struct list_head txrunning;
7862306a36Sopenharmony_ci	struct tasklet_struct txtask;
7962306a36Sopenharmony_ci	struct b43legacy_pio_txpacket
8062306a36Sopenharmony_ci			 tx_packets_cache[B43legacy_PIO_MAXTXPACKETS];
8162306a36Sopenharmony_ci};
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_cistatic inline
8462306a36Sopenharmony_ciu16 b43legacy_pio_read(struct b43legacy_pioqueue *queue,
8562306a36Sopenharmony_ci		     u16 offset)
8662306a36Sopenharmony_ci{
8762306a36Sopenharmony_ci	return b43legacy_read16(queue->dev, queue->mmio_base + offset);
8862306a36Sopenharmony_ci}
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_cistatic inline
9162306a36Sopenharmony_civoid b43legacy_pio_write(struct b43legacy_pioqueue *queue,
9262306a36Sopenharmony_ci		       u16 offset, u16 value)
9362306a36Sopenharmony_ci{
9462306a36Sopenharmony_ci	b43legacy_write16(queue->dev, queue->mmio_base + offset, value);
9562306a36Sopenharmony_ci}
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ciint b43legacy_pio_init(struct b43legacy_wldev *dev);
9962306a36Sopenharmony_civoid b43legacy_pio_free(struct b43legacy_wldev *dev);
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ciint b43legacy_pio_tx(struct b43legacy_wldev *dev,
10262306a36Sopenharmony_ci		   struct sk_buff *skb);
10362306a36Sopenharmony_civoid b43legacy_pio_handle_txstatus(struct b43legacy_wldev *dev,
10462306a36Sopenharmony_ci				 const struct b43legacy_txstatus *status);
10562306a36Sopenharmony_civoid b43legacy_pio_rx(struct b43legacy_pioqueue *queue);
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci/* Suspend TX queue in hardware. */
10862306a36Sopenharmony_civoid b43legacy_pio_tx_suspend(struct b43legacy_pioqueue *queue);
10962306a36Sopenharmony_civoid b43legacy_pio_tx_resume(struct b43legacy_pioqueue *queue);
11062306a36Sopenharmony_ci/* Suspend (freeze) the TX tasklet (software level). */
11162306a36Sopenharmony_civoid b43legacy_pio_freeze_txqueues(struct b43legacy_wldev *dev);
11262306a36Sopenharmony_civoid b43legacy_pio_thaw_txqueues(struct b43legacy_wldev *dev);
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci#else /* CONFIG_B43LEGACY_PIO */
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_cistatic inline
11762306a36Sopenharmony_ciint b43legacy_pio_init(struct b43legacy_wldev *dev)
11862306a36Sopenharmony_ci{
11962306a36Sopenharmony_ci	return 0;
12062306a36Sopenharmony_ci}
12162306a36Sopenharmony_cistatic inline
12262306a36Sopenharmony_civoid b43legacy_pio_free(struct b43legacy_wldev *dev)
12362306a36Sopenharmony_ci{
12462306a36Sopenharmony_ci}
12562306a36Sopenharmony_cistatic inline
12662306a36Sopenharmony_ciint b43legacy_pio_tx(struct b43legacy_wldev *dev,
12762306a36Sopenharmony_ci		   struct sk_buff *skb)
12862306a36Sopenharmony_ci{
12962306a36Sopenharmony_ci	return 0;
13062306a36Sopenharmony_ci}
13162306a36Sopenharmony_cistatic inline
13262306a36Sopenharmony_civoid b43legacy_pio_handle_txstatus(struct b43legacy_wldev *dev,
13362306a36Sopenharmony_ci				 const struct b43legacy_txstatus *status)
13462306a36Sopenharmony_ci{
13562306a36Sopenharmony_ci}
13662306a36Sopenharmony_cistatic inline
13762306a36Sopenharmony_civoid b43legacy_pio_rx(struct b43legacy_pioqueue *queue)
13862306a36Sopenharmony_ci{
13962306a36Sopenharmony_ci}
14062306a36Sopenharmony_cistatic inline
14162306a36Sopenharmony_civoid b43legacy_pio_tx_suspend(struct b43legacy_pioqueue *queue)
14262306a36Sopenharmony_ci{
14362306a36Sopenharmony_ci}
14462306a36Sopenharmony_cistatic inline
14562306a36Sopenharmony_civoid b43legacy_pio_tx_resume(struct b43legacy_pioqueue *queue)
14662306a36Sopenharmony_ci{
14762306a36Sopenharmony_ci}
14862306a36Sopenharmony_cistatic inline
14962306a36Sopenharmony_civoid b43legacy_pio_freeze_txqueues(struct b43legacy_wldev *dev)
15062306a36Sopenharmony_ci{
15162306a36Sopenharmony_ci}
15262306a36Sopenharmony_cistatic inline
15362306a36Sopenharmony_civoid b43legacy_pio_thaw_txqueues(struct b43legacy_wldev *dev)
15462306a36Sopenharmony_ci{
15562306a36Sopenharmony_ci}
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci#endif /* CONFIG_B43LEGACY_PIO */
15862306a36Sopenharmony_ci#endif /* B43legacy_PIO_H_ */
159