18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef B43legacy_XMIT_H_
38c2ecf20Sopenharmony_ci#define B43legacy_XMIT_H_
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include "main.h"
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#define _b43legacy_declare_plcp_hdr(size)	\
98c2ecf20Sopenharmony_ci	struct b43legacy_plcp_hdr##size {	\
108c2ecf20Sopenharmony_ci		union {				\
118c2ecf20Sopenharmony_ci			__le32 data;		\
128c2ecf20Sopenharmony_ci			__u8 raw[size];		\
138c2ecf20Sopenharmony_ci		} __packed;	\
148c2ecf20Sopenharmony_ci	} __packed
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci/* struct b43legacy_plcp_hdr4 */
178c2ecf20Sopenharmony_ci_b43legacy_declare_plcp_hdr(4);
188c2ecf20Sopenharmony_ci/* struct b43legacy_plcp_hdr6 */
198c2ecf20Sopenharmony_ci_b43legacy_declare_plcp_hdr(6);
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#undef _b43legacy_declare_plcp_hdr
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/* TX header for v3 firmware */
258c2ecf20Sopenharmony_cistruct b43legacy_txhdr_fw3 {
268c2ecf20Sopenharmony_ci	__le32 mac_ctl;				/* MAC TX control */
278c2ecf20Sopenharmony_ci	__le16 mac_frame_ctl;			/* Copy of the FrameControl */
288c2ecf20Sopenharmony_ci	__le16 tx_fes_time_norm;		/* TX FES Time Normal */
298c2ecf20Sopenharmony_ci	__le16 phy_ctl;				/* PHY TX control */
308c2ecf20Sopenharmony_ci	__u8 iv[16];				/* Encryption IV */
318c2ecf20Sopenharmony_ci	__u8 tx_receiver[6];			/* TX Frame Receiver address */
328c2ecf20Sopenharmony_ci	__le16 tx_fes_time_fb;			/* TX FES Time Fallback */
338c2ecf20Sopenharmony_ci	struct b43legacy_plcp_hdr4 rts_plcp_fb;	/* RTS fallback PLCP */
348c2ecf20Sopenharmony_ci	__le16 rts_dur_fb;			/* RTS fallback duration */
358c2ecf20Sopenharmony_ci	struct b43legacy_plcp_hdr4 plcp_fb;	/* Fallback PLCP */
368c2ecf20Sopenharmony_ci	__le16 dur_fb;				/* Fallback duration */
378c2ecf20Sopenharmony_ci	PAD_BYTES(2);
388c2ecf20Sopenharmony_ci	__le16 cookie;
398c2ecf20Sopenharmony_ci	__le16 unknown_scb_stuff;
408c2ecf20Sopenharmony_ci	struct b43legacy_plcp_hdr6 rts_plcp;	/* RTS PLCP */
418c2ecf20Sopenharmony_ci	__u8 rts_frame[18];			/* The RTS frame (if used) */
428c2ecf20Sopenharmony_ci	struct b43legacy_plcp_hdr6 plcp;
438c2ecf20Sopenharmony_ci} __packed;
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/* MAC TX control */
468c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_KEYIDX	0x0FF00000 /* Security key index */
478c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_KEYIDX_SHIFT	20
488c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_KEYALG	0x00070000 /* Security key algorithm */
498c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_KEYALG_SHIFT	16
508c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_LIFETIME	0x00001000
518c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_FRAMEBURST	0x00000800
528c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_SENDCTS	0x00000400
538c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_AMPDU		0x00000300
548c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_AMPDU_SHIFT	8
558c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_CTSFALLBACKOFDM	0x00000200
568c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_FALLBACKOFDM	0x00000100
578c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_5GHZ		0x00000080
588c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_IGNPMQ	0x00000020
598c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_HWSEQ		0x00000010 /* Use Hardware Seq No */
608c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_STMSDU	0x00000008 /* Start MSDU */
618c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_SENDRTS	0x00000004
628c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_LONGFRAME	0x00000002
638c2ecf20Sopenharmony_ci#define B43legacy_TX4_MAC_ACK		0x00000001
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/* Extra Frame Types */
668c2ecf20Sopenharmony_ci#define B43legacy_TX4_EFT_FBOFDM	0x0001 /* Data frame fb rate type */
678c2ecf20Sopenharmony_ci#define B43legacy_TX4_EFT_RTSOFDM	0x0004 /* RTS/CTS rate type */
688c2ecf20Sopenharmony_ci#define B43legacy_TX4_EFT_RTSFBOFDM	0x0010 /* RTS/CTS fallback rate type */
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci/* PHY TX control word */
718c2ecf20Sopenharmony_ci#define B43legacy_TX4_PHY_ENC		0x0003 /* Data frame encoding */
728c2ecf20Sopenharmony_ci#define B43legacy_TX4_PHY_ENC_CCK	0x0000 /* CCK */
738c2ecf20Sopenharmony_ci#define B43legacy_TX4_PHY_ENC_OFDM	0x0001 /* Data frame rate type */
748c2ecf20Sopenharmony_ci#define B43legacy_TX4_PHY_SHORTPRMBL	0x0010 /* Use short preamble */
758c2ecf20Sopenharmony_ci#define B43legacy_TX4_PHY_ANT		0x03C0 /* Antenna selection */
768c2ecf20Sopenharmony_ci#define  B43legacy_TX4_PHY_ANT0		0x0000 /* Use antenna 0 */
778c2ecf20Sopenharmony_ci#define  B43legacy_TX4_PHY_ANT1		0x0100 /* Use antenna 1 */
788c2ecf20Sopenharmony_ci#define  B43legacy_TX4_PHY_ANTLAST	0x0300 /* Use last used antenna */
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ciint b43legacy_generate_txhdr(struct b43legacy_wldev *dev,
838c2ecf20Sopenharmony_ci			      u8 *txhdr,
848c2ecf20Sopenharmony_ci			      const unsigned char *fragment_data,
858c2ecf20Sopenharmony_ci			      unsigned int fragment_len,
868c2ecf20Sopenharmony_ci			      struct ieee80211_tx_info *info,
878c2ecf20Sopenharmony_ci			      u16 cookie);
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci/* Transmit Status */
918c2ecf20Sopenharmony_cistruct b43legacy_txstatus {
928c2ecf20Sopenharmony_ci	u16 cookie;	/* The cookie from the txhdr */
938c2ecf20Sopenharmony_ci	u16 seq;	/* Sequence number */
948c2ecf20Sopenharmony_ci	u8 phy_stat;	/* PHY TX status */
958c2ecf20Sopenharmony_ci	u8 frame_count;	/* Frame transmit count */
968c2ecf20Sopenharmony_ci	u8 rts_count;	/* RTS transmit count */
978c2ecf20Sopenharmony_ci	u8 supp_reason;	/* Suppression reason */
988c2ecf20Sopenharmony_ci	/* flags */
998c2ecf20Sopenharmony_ci	u8 pm_indicated;/* PM mode indicated to AP */
1008c2ecf20Sopenharmony_ci	u8 intermediate;/* Intermediate status notification */
1018c2ecf20Sopenharmony_ci	u8 for_ampdu;	/* Status is for an AMPDU (afterburner) */
1028c2ecf20Sopenharmony_ci	u8 acked;	/* Wireless ACK received */
1038c2ecf20Sopenharmony_ci};
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci/* txstatus supp_reason values */
1068c2ecf20Sopenharmony_cienum {
1078c2ecf20Sopenharmony_ci	B43legacy_TXST_SUPP_NONE,	/* Not suppressed */
1088c2ecf20Sopenharmony_ci	B43legacy_TXST_SUPP_PMQ,	/* Suppressed due to PMQ entry */
1098c2ecf20Sopenharmony_ci	B43legacy_TXST_SUPP_FLUSH,	/* Suppressed due to flush request */
1108c2ecf20Sopenharmony_ci	B43legacy_TXST_SUPP_PREV,	/* Previous fragment failed */
1118c2ecf20Sopenharmony_ci	B43legacy_TXST_SUPP_CHAN,	/* Channel mismatch */
1128c2ecf20Sopenharmony_ci	B43legacy_TXST_SUPP_LIFE,	/* Lifetime expired */
1138c2ecf20Sopenharmony_ci	B43legacy_TXST_SUPP_UNDER,	/* Buffer underflow */
1148c2ecf20Sopenharmony_ci	B43legacy_TXST_SUPP_ABNACK,	/* Afterburner NACK */
1158c2ecf20Sopenharmony_ci};
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci/* Transmit Status as received through DMA/PIO on old chips */
1188c2ecf20Sopenharmony_cistruct b43legacy_hwtxstatus {
1198c2ecf20Sopenharmony_ci	PAD_BYTES(4);
1208c2ecf20Sopenharmony_ci	__le16 cookie;
1218c2ecf20Sopenharmony_ci	u8 flags;
1228c2ecf20Sopenharmony_ci	u8 count;
1238c2ecf20Sopenharmony_ci	PAD_BYTES(2);
1248c2ecf20Sopenharmony_ci	__le16 seq;
1258c2ecf20Sopenharmony_ci	u8 phy_stat;
1268c2ecf20Sopenharmony_ci	PAD_BYTES(1);
1278c2ecf20Sopenharmony_ci} __packed;
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci/* Receive header for v3 firmware. */
1318c2ecf20Sopenharmony_cistruct b43legacy_rxhdr_fw3 {
1328c2ecf20Sopenharmony_ci	__le16 frame_len;	/* Frame length */
1338c2ecf20Sopenharmony_ci	PAD_BYTES(2);
1348c2ecf20Sopenharmony_ci	__le16 phy_status0;	/* PHY RX Status 0 */
1358c2ecf20Sopenharmony_ci	__u8 jssi;		/* PHY RX Status 1: JSSI */
1368c2ecf20Sopenharmony_ci	__u8 sig_qual;		/* PHY RX Status 1: Signal Quality */
1378c2ecf20Sopenharmony_ci	PAD_BYTES(2);		/* PHY RX Status 2 */
1388c2ecf20Sopenharmony_ci	__le16 phy_status3;	/* PHY RX Status 3 */
1398c2ecf20Sopenharmony_ci	__le16 mac_status;	/* MAC RX status */
1408c2ecf20Sopenharmony_ci	__le16 mac_time;
1418c2ecf20Sopenharmony_ci	__le16 channel;
1428c2ecf20Sopenharmony_ci} __packed;
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci/* PHY RX Status 0 */
1468c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST0_GAINCTL	0x4000 /* Gain Control */
1478c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST0_PLCPHCF	0x0200
1488c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST0_PLCPFV	0x0100
1498c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST0_SHORTPRMBL	0x0080 /* Recvd with Short Preamble */
1508c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST0_LCRS	0x0040
1518c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST0_ANT		0x0020 /* Antenna */
1528c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST0_UNSRATE	0x0010
1538c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST0_CLIP	0x000C
1548c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST0_CLIP_SHIFT	2
1558c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST0_FTYPE	0x0003 /* Frame type */
1568c2ecf20Sopenharmony_ci#define  B43legacy_RX_PHYST0_CCK	0x0000 /* Frame type: CCK */
1578c2ecf20Sopenharmony_ci#define  B43legacy_RX_PHYST0_OFDM	0x0001 /* Frame type: OFDM */
1588c2ecf20Sopenharmony_ci#define  B43legacy_RX_PHYST0_PRE_N	0x0002 /* Pre-standard N-PHY frame */
1598c2ecf20Sopenharmony_ci#define  B43legacy_RX_PHYST0_STD_N	0x0003 /* Standard N-PHY frame */
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci/* PHY RX Status 2 */
1628c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST2_LNAG	0xC000 /* LNA Gain */
1638c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST2_LNAG_SHIFT	14
1648c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST2_PNAG	0x3C00 /* PNA Gain */
1658c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST2_PNAG_SHIFT	10
1668c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST2_FOFF	0x03FF /* F offset */
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci/* PHY RX Status 3 */
1698c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST3_DIGG	0x1800 /* DIG Gain */
1708c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST3_DIGG_SHIFT	11
1718c2ecf20Sopenharmony_ci#define B43legacy_RX_PHYST3_TRSTATE	0x0400 /* TR state */
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci/* MAC RX Status */
1748c2ecf20Sopenharmony_ci#define B43legacy_RX_MAC_BEACONSENT	0x00008000 /* Beacon send flag */
1758c2ecf20Sopenharmony_ci#define B43legacy_RX_MAC_KEYIDX		0x000007E0 /* Key index */
1768c2ecf20Sopenharmony_ci#define B43legacy_RX_MAC_KEYIDX_SHIFT	5
1778c2ecf20Sopenharmony_ci#define B43legacy_RX_MAC_DECERR		0x00000010 /* Decrypt error */
1788c2ecf20Sopenharmony_ci#define B43legacy_RX_MAC_DEC		0x00000008 /* Decryption attempted */
1798c2ecf20Sopenharmony_ci#define B43legacy_RX_MAC_PADDING	0x00000004 /* Pad bytes present */
1808c2ecf20Sopenharmony_ci#define B43legacy_RX_MAC_RESP		0x00000002 /* Response frame xmitted */
1818c2ecf20Sopenharmony_ci#define B43legacy_RX_MAC_FCSERR		0x00000001 /* FCS error */
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci/* RX channel */
1848c2ecf20Sopenharmony_ci#define B43legacy_RX_CHAN_GAIN		0xFC00 /* Gain */
1858c2ecf20Sopenharmony_ci#define B43legacy_RX_CHAN_GAIN_SHIFT	10
1868c2ecf20Sopenharmony_ci#define B43legacy_RX_CHAN_ID		0x03FC /* Channel ID */
1878c2ecf20Sopenharmony_ci#define B43legacy_RX_CHAN_ID_SHIFT	2
1888c2ecf20Sopenharmony_ci#define B43legacy_RX_CHAN_PHYTYPE	0x0003 /* PHY type */
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ciu8 b43legacy_plcp_get_ratecode_cck(const u8 bitrate);
1938c2ecf20Sopenharmony_ciu8 b43legacy_plcp_get_ratecode_ofdm(const u8 bitrate);
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_civoid b43legacy_generate_plcp_hdr(struct b43legacy_plcp_hdr4 *plcp,
1968c2ecf20Sopenharmony_ci			       const u16 octets, const u8 bitrate);
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_civoid b43legacy_rx(struct b43legacy_wldev *dev,
1998c2ecf20Sopenharmony_ci		struct sk_buff *skb,
2008c2ecf20Sopenharmony_ci		const void *_rxhdr);
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_civoid b43legacy_handle_txstatus(struct b43legacy_wldev *dev,
2038c2ecf20Sopenharmony_ci			       const struct b43legacy_txstatus *status);
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_civoid b43legacy_handle_hwtxstatus(struct b43legacy_wldev *dev,
2068c2ecf20Sopenharmony_ci				 const struct b43legacy_hwtxstatus *hw);
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_civoid b43legacy_tx_suspend(struct b43legacy_wldev *dev);
2098c2ecf20Sopenharmony_civoid b43legacy_tx_resume(struct b43legacy_wldev *dev);
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci#define B43legacy_NR_QOSPARMS	22
2138c2ecf20Sopenharmony_cienum {
2148c2ecf20Sopenharmony_ci	B43legacy_QOSPARM_TXOP = 0,
2158c2ecf20Sopenharmony_ci	B43legacy_QOSPARM_CWMIN,
2168c2ecf20Sopenharmony_ci	B43legacy_QOSPARM_CWMAX,
2178c2ecf20Sopenharmony_ci	B43legacy_QOSPARM_CWCUR,
2188c2ecf20Sopenharmony_ci	B43legacy_QOSPARM_AIFS,
2198c2ecf20Sopenharmony_ci	B43legacy_QOSPARM_BSLOTS,
2208c2ecf20Sopenharmony_ci	B43legacy_QOSPARM_REGGAP,
2218c2ecf20Sopenharmony_ci	B43legacy_QOSPARM_STATUS,
2228c2ecf20Sopenharmony_ci};
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_civoid b43legacy_qos_init(struct b43legacy_wldev *dev);
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci/* Helper functions for converting the key-table index from "firmware-format"
2288c2ecf20Sopenharmony_ci * to "raw-format" and back. The firmware API changed for this at some revision.
2298c2ecf20Sopenharmony_ci * We need to account for that here. */
2308c2ecf20Sopenharmony_cistatic inline
2318c2ecf20Sopenharmony_ciint b43legacy_new_kidx_api(struct b43legacy_wldev *dev)
2328c2ecf20Sopenharmony_ci{
2338c2ecf20Sopenharmony_ci	/* FIXME: Not sure the change was at rev 351 */
2348c2ecf20Sopenharmony_ci	return (dev->fw.rev >= 351);
2358c2ecf20Sopenharmony_ci}
2368c2ecf20Sopenharmony_cistatic inline
2378c2ecf20Sopenharmony_ciu8 b43legacy_kidx_to_fw(struct b43legacy_wldev *dev, u8 raw_kidx)
2388c2ecf20Sopenharmony_ci{
2398c2ecf20Sopenharmony_ci	u8 firmware_kidx;
2408c2ecf20Sopenharmony_ci	if (b43legacy_new_kidx_api(dev))
2418c2ecf20Sopenharmony_ci		firmware_kidx = raw_kidx;
2428c2ecf20Sopenharmony_ci	else {
2438c2ecf20Sopenharmony_ci		if (raw_kidx >= 4) /* Is per STA key? */
2448c2ecf20Sopenharmony_ci			firmware_kidx = raw_kidx - 4;
2458c2ecf20Sopenharmony_ci		else
2468c2ecf20Sopenharmony_ci			firmware_kidx = raw_kidx; /* TX default key */
2478c2ecf20Sopenharmony_ci	}
2488c2ecf20Sopenharmony_ci	return firmware_kidx;
2498c2ecf20Sopenharmony_ci}
2508c2ecf20Sopenharmony_cistatic inline
2518c2ecf20Sopenharmony_ciu8 b43legacy_kidx_to_raw(struct b43legacy_wldev *dev, u8 firmware_kidx)
2528c2ecf20Sopenharmony_ci{
2538c2ecf20Sopenharmony_ci	u8 raw_kidx;
2548c2ecf20Sopenharmony_ci	if (b43legacy_new_kidx_api(dev))
2558c2ecf20Sopenharmony_ci		raw_kidx = firmware_kidx;
2568c2ecf20Sopenharmony_ci	else
2578c2ecf20Sopenharmony_ci		/* RX default keys or per STA keys */
2588c2ecf20Sopenharmony_ci		raw_kidx = firmware_kidx + 4;
2598c2ecf20Sopenharmony_ci	return raw_kidx;
2608c2ecf20Sopenharmony_ci}
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci#endif /* B43legacy_XMIT_H_ */
263