18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef B43_PIO_H_
38c2ecf20Sopenharmony_ci#define B43_PIO_H_
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include "b43.h"
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
88c2ecf20Sopenharmony_ci#include <linux/io.h>
98c2ecf20Sopenharmony_ci#include <linux/list.h>
108c2ecf20Sopenharmony_ci#include <linux/skbuff.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/*** Registers for PIO queues up to revision 7. ***/
148c2ecf20Sopenharmony_ci/* TX queue. */
158c2ecf20Sopenharmony_ci#define B43_PIO_TXCTL			0x00
168c2ecf20Sopenharmony_ci#define  B43_PIO_TXCTL_WRITELO		0x0001
178c2ecf20Sopenharmony_ci#define  B43_PIO_TXCTL_WRITEHI		0x0002
188c2ecf20Sopenharmony_ci#define  B43_PIO_TXCTL_EOF		0x0004
198c2ecf20Sopenharmony_ci#define  B43_PIO_TXCTL_FREADY		0x0008
208c2ecf20Sopenharmony_ci#define  B43_PIO_TXCTL_FLUSHREQ		0x0020
218c2ecf20Sopenharmony_ci#define  B43_PIO_TXCTL_FLUSHPEND	0x0040
228c2ecf20Sopenharmony_ci#define  B43_PIO_TXCTL_SUSPREQ		0x0080
238c2ecf20Sopenharmony_ci#define  B43_PIO_TXCTL_QSUSP		0x0100
248c2ecf20Sopenharmony_ci#define  B43_PIO_TXCTL_COMMCNT		0xFC00
258c2ecf20Sopenharmony_ci#define  B43_PIO_TXCTL_COMMCNT_SHIFT	10
268c2ecf20Sopenharmony_ci#define B43_PIO_TXDATA			0x02
278c2ecf20Sopenharmony_ci#define B43_PIO_TXQBUFSIZE		0x04
288c2ecf20Sopenharmony_ci/* RX queue. */
298c2ecf20Sopenharmony_ci#define B43_PIO_RXCTL			0x00
308c2ecf20Sopenharmony_ci#define  B43_PIO_RXCTL_FRAMERDY		0x0001
318c2ecf20Sopenharmony_ci#define  B43_PIO_RXCTL_DATARDY		0x0002
328c2ecf20Sopenharmony_ci#define B43_PIO_RXDATA			0x02
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/*** Registers for PIO queues revision 8 and later. ***/
358c2ecf20Sopenharmony_ci/* TX queue */
368c2ecf20Sopenharmony_ci#define B43_PIO8_TXCTL			0x00
378c2ecf20Sopenharmony_ci#define  B43_PIO8_TXCTL_0_7		0x00000001
388c2ecf20Sopenharmony_ci#define  B43_PIO8_TXCTL_8_15		0x00000002
398c2ecf20Sopenharmony_ci#define  B43_PIO8_TXCTL_16_23		0x00000004
408c2ecf20Sopenharmony_ci#define  B43_PIO8_TXCTL_24_31		0x00000008
418c2ecf20Sopenharmony_ci#define  B43_PIO8_TXCTL_EOF		0x00000010
428c2ecf20Sopenharmony_ci#define  B43_PIO8_TXCTL_FREADY		0x00000080
438c2ecf20Sopenharmony_ci#define  B43_PIO8_TXCTL_SUSPREQ		0x00000100
448c2ecf20Sopenharmony_ci#define  B43_PIO8_TXCTL_QSUSP		0x00000200
458c2ecf20Sopenharmony_ci#define  B43_PIO8_TXCTL_FLUSHREQ	0x00000400
468c2ecf20Sopenharmony_ci#define  B43_PIO8_TXCTL_FLUSHPEND	0x00000800
478c2ecf20Sopenharmony_ci#define B43_PIO8_TXDATA			0x04
488c2ecf20Sopenharmony_ci/* RX queue */
498c2ecf20Sopenharmony_ci#define B43_PIO8_RXCTL			0x00
508c2ecf20Sopenharmony_ci#define  B43_PIO8_RXCTL_FRAMERDY	0x00000001
518c2ecf20Sopenharmony_ci#define  B43_PIO8_RXCTL_DATARDY		0x00000002
528c2ecf20Sopenharmony_ci#define B43_PIO8_RXDATA			0x04
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/* The maximum number of TX-packets the HW can handle. */
568c2ecf20Sopenharmony_ci#define B43_PIO_MAX_NR_TXPACKETS	32
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistruct b43_pio_txpacket {
608c2ecf20Sopenharmony_ci	/* Pointer to the TX queue we belong to. */
618c2ecf20Sopenharmony_ci	struct b43_pio_txqueue *queue;
628c2ecf20Sopenharmony_ci	/* The TX data packet. */
638c2ecf20Sopenharmony_ci	struct sk_buff *skb;
648c2ecf20Sopenharmony_ci	/* Index in the (struct b43_pio_txqueue)->packets array. */
658c2ecf20Sopenharmony_ci	u8 index;
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	struct list_head list;
688c2ecf20Sopenharmony_ci};
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistruct b43_pio_txqueue {
718c2ecf20Sopenharmony_ci	struct b43_wldev *dev;
728c2ecf20Sopenharmony_ci	u16 mmio_base;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	/* The device queue buffer size in bytes. */
758c2ecf20Sopenharmony_ci	u16 buffer_size;
768c2ecf20Sopenharmony_ci	/* The number of used bytes in the device queue buffer. */
778c2ecf20Sopenharmony_ci	u16 buffer_used;
788c2ecf20Sopenharmony_ci	/* The number of packets that can still get queued.
798c2ecf20Sopenharmony_ci	 * This is decremented on queueing a packet and incremented
808c2ecf20Sopenharmony_ci	 * after receiving the transmit status. */
818c2ecf20Sopenharmony_ci	u16 free_packet_slots;
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	/* True, if the mac80211 queue was stopped due to overflow at TX. */
848c2ecf20Sopenharmony_ci	bool stopped;
858c2ecf20Sopenharmony_ci	/* Our b43 queue index number */
868c2ecf20Sopenharmony_ci	u8 index;
878c2ecf20Sopenharmony_ci	/* The mac80211 QoS queue priority. */
888c2ecf20Sopenharmony_ci	u8 queue_prio;
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	/* Buffer for TX packet meta data. */
918c2ecf20Sopenharmony_ci	struct b43_pio_txpacket packets[B43_PIO_MAX_NR_TXPACKETS];
928c2ecf20Sopenharmony_ci	struct list_head packets_list;
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	/* Shortcut to the 802.11 core revision. This is to
958c2ecf20Sopenharmony_ci	 * avoid horrible pointer dereferencing in the fastpaths. */
968c2ecf20Sopenharmony_ci	u8 rev;
978c2ecf20Sopenharmony_ci};
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_cistruct b43_pio_rxqueue {
1008c2ecf20Sopenharmony_ci	struct b43_wldev *dev;
1018c2ecf20Sopenharmony_ci	u16 mmio_base;
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci	/* Shortcut to the 802.11 core revision. This is to
1048c2ecf20Sopenharmony_ci	 * avoid horrible pointer dereferencing in the fastpaths. */
1058c2ecf20Sopenharmony_ci	u8 rev;
1068c2ecf20Sopenharmony_ci};
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_cistatic inline u16 b43_piotx_read16(struct b43_pio_txqueue *q, u16 offset)
1108c2ecf20Sopenharmony_ci{
1118c2ecf20Sopenharmony_ci	return b43_read16(q->dev, q->mmio_base + offset);
1128c2ecf20Sopenharmony_ci}
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_cistatic inline u32 b43_piotx_read32(struct b43_pio_txqueue *q, u16 offset)
1158c2ecf20Sopenharmony_ci{
1168c2ecf20Sopenharmony_ci	return b43_read32(q->dev, q->mmio_base + offset);
1178c2ecf20Sopenharmony_ci}
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_cistatic inline void b43_piotx_write16(struct b43_pio_txqueue *q,
1208c2ecf20Sopenharmony_ci				     u16 offset, u16 value)
1218c2ecf20Sopenharmony_ci{
1228c2ecf20Sopenharmony_ci	b43_write16(q->dev, q->mmio_base + offset, value);
1238c2ecf20Sopenharmony_ci}
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_cistatic inline void b43_piotx_write32(struct b43_pio_txqueue *q,
1268c2ecf20Sopenharmony_ci				     u16 offset, u32 value)
1278c2ecf20Sopenharmony_ci{
1288c2ecf20Sopenharmony_ci	b43_write32(q->dev, q->mmio_base + offset, value);
1298c2ecf20Sopenharmony_ci}
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cistatic inline u16 b43_piorx_read16(struct b43_pio_rxqueue *q, u16 offset)
1338c2ecf20Sopenharmony_ci{
1348c2ecf20Sopenharmony_ci	return b43_read16(q->dev, q->mmio_base + offset);
1358c2ecf20Sopenharmony_ci}
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_cistatic inline u32 b43_piorx_read32(struct b43_pio_rxqueue *q, u16 offset)
1388c2ecf20Sopenharmony_ci{
1398c2ecf20Sopenharmony_ci	return b43_read32(q->dev, q->mmio_base + offset);
1408c2ecf20Sopenharmony_ci}
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_cistatic inline void b43_piorx_write16(struct b43_pio_rxqueue *q,
1438c2ecf20Sopenharmony_ci				     u16 offset, u16 value)
1448c2ecf20Sopenharmony_ci{
1458c2ecf20Sopenharmony_ci	b43_write16(q->dev, q->mmio_base + offset, value);
1468c2ecf20Sopenharmony_ci}
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_cistatic inline void b43_piorx_write32(struct b43_pio_rxqueue *q,
1498c2ecf20Sopenharmony_ci				     u16 offset, u32 value)
1508c2ecf20Sopenharmony_ci{
1518c2ecf20Sopenharmony_ci	b43_write32(q->dev, q->mmio_base + offset, value);
1528c2ecf20Sopenharmony_ci}
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ciint b43_pio_init(struct b43_wldev *dev);
1568c2ecf20Sopenharmony_civoid b43_pio_free(struct b43_wldev *dev);
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ciint b43_pio_tx(struct b43_wldev *dev, struct sk_buff *skb);
1598c2ecf20Sopenharmony_civoid b43_pio_handle_txstatus(struct b43_wldev *dev,
1608c2ecf20Sopenharmony_ci			     const struct b43_txstatus *status);
1618c2ecf20Sopenharmony_civoid b43_pio_rx(struct b43_pio_rxqueue *q);
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_civoid b43_pio_tx_suspend(struct b43_wldev *dev);
1648c2ecf20Sopenharmony_civoid b43_pio_tx_resume(struct b43_wldev *dev);
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci#endif /* B43_PIO_H_ */
167