ath10k: add 'cryptmode' param to support raw tx injection and sw crypto.
PATCH v2 1/1 ath10k: add 'cryptmode' param to support raw tx injection and sw crypto.
This change supports bypassing HW crypto engine by enabling raw Rx/Tx mode. This will enable use cases such as sw crypto and raw tx injection. This change introduces a new module param 'cryptmode'.
cryptmode:
0 Use HW crypto engine. Use native WiFi mode Tx/Rx encap
1 Use SW crypto engine. Use raw mode Tx/Rx encap
2 Supports both SW & HW crypto engine. Use raw mode Tx/Rx encap.
Testing: used QCA988x hw 2.0 with firmware-4.bin_10.2.4.48 with backports-20150424 (Skipped ATH10K_FW_FEATURE_RAW_MODE_SUPPORT check in core.c within this patch.
Since none of the existing QCA official firmware has the feature bit set yet)
ath10k
cryptmode
param Testing Status
------- ---------------------------------
0 HW CCMP/TKIP tested ok.Note: HW crypto bypass not supported by ath10k hw in native WiFi mode.
1 - mac80211 SW crypto tested ok.
- raw Tx frame injection tested ok.
2 HW CCMP/TKIP tested ok.
SW CCMP/TKIP tested ok.
Tested raw Tx encrypted frame injection ok.
--- drivers/net/wireless/ath/ath10k/core.c | 29 +++++++++++++++++ drivers/net/wireless/ath/ath10k/core.h | 29 +++++++++++++++-- drivers/net/wireless/ath/ath10k/htt_rx.c | 5 ++- drivers/net/wireless/ath/ath10k/htt_tx.c | 9 +++++- drivers/net/wireless/ath/ath10k/mac.c | 53 +++++++++++++++++++++++++++----- drivers/net/wireless/ath/ath10k/wmi.c | 4 ++- 6 files changed, 114 insertions(+), 15 deletions(-)
drivers/net/wireless/ath/ath10k/core.c +29 -0
@@ -31,16 +31,19 @@#include "wmi-ops.h" unsigned int ath10k_debug_mask; +unsigned int ath10k_cryptmode_param;static bool uart_print;static bool skip_otp;module_param_named (debug_mask, ath10k_debug_mask, uint,0644 ); +module_param_named (cryptmode, ath10k_cryptmode_param, uint,0644 );module_param (uart_print, bool,0644 );module_param (skip_otp, bool,0644 );MODULE_PARM_DESC (debug_mask,"Debugging mask" );MODULE_PARM_DESC (uart_print,"Uart target debugging" );MODULE_PARM_DESC (skip_otp,"Skip otp failure for calibration in testmode" ); +MODULE_PARM_DESC (cryptmode,"Crypto mode - 0: HW only, 1: SW only, 2:Both" );static const struct ath10k_hw_params ath10k_hw_params_list[] = { {
@@ -991,6 +994,32 @@ static int ath10k_core_init_firmware_features(struct ath10k *ar)return -EINVAL ; } +switch (ath10k_cryptmode_param) { +case ATH10K_CRYPT_MODE_HW : +clear_bit (ATH10K_FLAG_RAW_MODE , &ar->dev_flags); +clear_bit (ATH10K_FLAG_HW_CRYPTO_DISABLED , &ar->dev_flags); +break ; +case ATH10K_CRYPT_MODE_SW : +case ATH10K_CRYPT_MODE_HW_SW : +if (!test_bit (ATH10K_FW_FEATURE_RAW_MODE_SUPPORT , + ar->fw_features)) { +ath10k_err (ar,"cryptmode > 0 requires raw mode support from firmware" ); +return -EINVAL ; + } + +set_bit (ATH10K_FLAG_RAW_MODE , &ar->dev_flags); + +if (ath10k_cryptmode_param ==ATH10K_CRYPT_MODE_SW ) { +set_bit (ATH10K_FLAG_HW_CRYPTO_DISABLED , &ar->dev_flags); + } +break ; +default : +ath10k_info (ar,"invalid cryptmode: %d\n" , + ath10k_cryptmode_param); +return -EINVAL ; + } +ath10k_info (ar,"cryptmode: %d\n" , ath10k_cryptmode_param); +/* Backwards compatibility for firmwares without * ATH10K_FW_IE_WMI_OP_VERSION. */
drivers/net/wireless/ath/ath10k/core.h +27 -2
@@ -91,6 +91,7 @@ struct ath10k_skb_cb {u8 tid;u16 freq;bool is_offchan; +bool nohwcrypt;struct ath10k_htt_txbuf *txbuf;u32 txbuf_paddr; }__packed htt;
@@ -349,6 +350,7 @@ struct ath10k_vif { } u;bool use_cts_prot; +bool nohwcrypt;int num_legacy_stations;int txpower;struct wmi_wmm_params_all_arg wmm_params;
@@ -461,16 +463,21 @@ enum ath10k_fw_features {ATH10K_FW_FEATURE_WOWLAN_SUPPORT =6 ,/* Don't trust error code from otp.bin */ -ATH10K_FW_FEATURE_IGNORE_OTP_RESULT , +ATH10K_FW_FEATURE_IGNORE_OTP_RESULT =7 ,/* Some firmware revisions pad 4th hw address to 4 byte boundary making * it 8 bytes long in Native Wifi Rx decap. */ -ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING , +ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING =8 ,/* Firmware supports bypassing PLL setting on init. */ ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT =9 , +/* Raw mode support. If supported, FW supports receiving and trasmitting +* frames in raw mode +*/ +ATH10K_FW_FEATURE_RAW_MODE_SUPPORT =10 , +/* keep last */ ATH10K_FW_FEATURE_COUNT, };
@@ -484,6 +491,15 @@ enum ath10k_dev_flags {* waiters should immediately cancel instead of waiting for a time out. */ ATH10K_FLAG_CRASH_FLUSH , + +/* Use Raw mode instead of native WiFi Tx/Rx encap mode. +* Raw mode supports both HW and SW crypto. Native WiFi only +* supports HW crypto. +*/ +ATH10K_FLAG_RAW_MODE , + +/* Disable HW crypto engine */ + ATH10K_FLAG_HW_CRYPTO_DISABLED, }; enum ath10k_cal_mode {
@@ -492,6 +508,15 @@ enum ath10k_cal_mode { ATH10K_CAL_MODE_DT, }; +enum ath10k_crypt_mode { +/* Use HW crypto engine only */ +ATH10K_CRYPT_MODE_HW , +/* HW SW crypto engine only (ie. HW crypto engine disabled) */ +ATH10K_CRYPT_MODE_SW , +/* Both SW & HW crypto engine supported */ +ATH10K_CRYPT_MODE_HW_SW , +}; +static inline const char *ath10k_cal_mode_str (enum ath10k_cal_mode mode) {switch (mode) {
drivers/net/wireless/ath/ath10k/htt_rx.c +2 -3
@@ -1017,9 +1017,8 @@ static void ath10k_htt_rx_h_undecap_raw(struct ath10k *ar,skb_trim (msdu, msdu->len -FCS_LEN );/* In most cases this will be true for sniffed frames. It makes sense -* to deliver them as-is without stripping the crypto param. This would -* also make sense for software based decryption (which is not -* implemented in ath10k). +* to deliver them as-is without stripping the crypto param. This is +* neccessary for software based decryption. * * If there's no error then the frame is decrypted. At least that is * the case for frames that come in via fragmented rx indication.
drivers/net/wireless/ath/ath10k/htt_tx.c +8 -1
@@ -450,8 +450,12 @@ int ath10k_htt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)if ((ieee80211_is_action (hdr->frame_control) ||ieee80211_is_deauth (hdr->frame_control) ||ieee80211_is_disassoc (hdr->frame_control)) && -ieee80211_has_protected (hdr->frame_control)) +ieee80211_has_protected (hdr->frame_control)) {skb_put (msdu,IEEE80211_CCMP_MIC_LEN ); + }else if (!skb_cb->htt.nohwcrypt && + skb_cb->txmode ==ATH10K_HW_TXRX_RAW ) { +skb_put (msdu,IEEE80211_CCMP_MIC_LEN ); + } skb_cb->paddr =dma_map_single (dev, msdu->data, msdu->len,DMA_TO_DEVICE );
@@ -508,6 +512,9 @@ int ath10k_htt_tx(struct ath10k_htt *htt, struct sk_buff *msdu) prefetch_len); skb_cb->htt.txbuf->htc_hdr.flags =0 ; +if (skb_cb->htt.nohwcrypt) + flags0 |=HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT ; +if (!skb_cb->is_protected) flags0 |=HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT ;
drivers/net/wireless/ath/ath10k/mac.c +45 -8
109 lines not on this page · raw message
drivers/net/wireless/ath/ath10k/wmi.c +3 -1
@@ -3894,7 +3894,9 @@ static struct sk_buff *ath10k_wmi_10_2_op_gen_init(struct ath10k *ar) config.rx_timeout_pri_vi =__cpu_to_le32 (TARGET_10X_RX_TIMEOUT_LO_PRI ); config.rx_timeout_pri_be =__cpu_to_le32 (TARGET_10X_RX_TIMEOUT_LO_PRI ); config.rx_timeout_pri_bk =__cpu_to_le32 (TARGET_10X_RX_TIMEOUT_HI_PRI ); - config.rx_decap_mode =__cpu_to_le32 (TARGET_10X_RX_DECAP_MODE ); + config.rx_decap_mode =__cpu_to_le32 (ATH10K_HW_TXRX_NATIVE_WIFI ); +if (test_bit (ATH10K_FLAG_RAW_MODE , &ar->dev_flags)) + config.rx_decap_mode =__cpu_to_le32 (ATH10K_HW_TXRX_RAW ); config.scan_max_pending_reqs =__cpu_to_le32 (TARGET_10X_SCAN_MAX_PENDING_REQS );
Signature · 1 line
2.1.4
On 4 June 2015 at 19:47, Liu CF/TW <[email protected]> wrote:
[...]
Quoted 19 lines
drivers/net/wireless/ath/ath10k/core.c +15
-0@@ -991,6 +994,32 @@ static int ath10k_core_init_firmware_features(struct ath10k *ar)return -EINVAL ; } +switch (ath10k_cryptmode_param) { +case ATH10K_CRYPT_MODE_HW : +clear_bit (ATH10K_FLAG_RAW_MODE , &ar->dev_flags); +clear_bit (ATH10K_FLAG_HW_CRYPTO_DISABLED , &ar->dev_flags); +break ; +case ATH10K_CRYPT_MODE_SW : +case ATH10K_CRYPT_MODE_HW_SW : +if (!test_bit (ATH10K_FW_FEATURE_RAW_MODE_SUPPORT , + ar->fw_features)) { +ath10k_err (ar,"cryptmode > 0 requires raw mode support from firmware" ); +return -EINVAL ; + } + +set_bit (ATH10K_FLAG_RAW_MODE , &ar->dev_flags); +
drivers/net/wireless/ath/ath10k/core.c static int ath10k_core_init_firmware_features(struct ath10k *ar) · line 1021
Quoted 10 lines
drivers/net/wireless/ath/ath10k/core.c +10
-0+if (ath10k_cryptmode_param ==ATH10K_CRYPT_MODE_SW ) { +set_bit (ATH10K_FLAG_HW_CRYPTO_DISABLED , &ar->dev_flags); + } +break ; +default : +ath10k_info (ar,"invalid cryptmode: %d\n" , + ath10k_cryptmode_param); +return -EINVAL ; + } +ath10k_info (ar,"cryptmode: %d\n" , ath10k_cryptmode_param);
This may be a bit too verbose. I was actually thinking of adding this to the ath10k_print_driver_info().
[...]
drivers/net/wireless/ath/ath10k/mac.c ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif, · line 3188
Quoted 7 lines
drivers/net/wireless/ath/ath10k/mac.c +2
-0static int ath10k_install_key(struct ath10k_vif *arvif,@@ -3172,9 +3184,24 @@ ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,if (ieee80211_is_data_present (fc) && sta && sta->tdls)return ATH10K_HW_TXRX_ETHERNET ; +if (test_bit (ATH10K_FLAG_RAW_MODE , &ar->dev_flags)) +return ATH10K_HW_TXRX_RAW ;
This means not all traffic will go RAW. The TDLS case above will use ethernet encap. I'm aware you might not have the hardware to test that though.. Might be worth putting a FIXME at least.
[...]
drivers/net/wireless/ath/ath10k/wmi.c static struct sk_buff *ath10k_wmi_10_2_op_gen_init(struct ath10k *ar) · line 3899
Quoted 12 lines
drivers/net/wireless/ath/ath10k/wmi.c +3
-1@@ -3894,7 +3894,9 @@ static struct sk_buff *ath10k_wmi_10_2_op_gen_init(struct ath10k *ar) config.rx_timeout_pri_vi =__cpu_to_le32 (TARGET_10X_RX_TIMEOUT_LO_PRI ); config.rx_timeout_pri_be =__cpu_to_le32 (TARGET_10X_RX_TIMEOUT_LO_PRI ); config.rx_timeout_pri_bk =__cpu_to_le32 (TARGET_10X_RX_TIMEOUT_HI_PRI ); - config.rx_decap_mode =__cpu_to_le32 (TARGET_10X_RX_DECAP_MODE ); + config.rx_decap_mode =__cpu_to_le32 (ATH10K_HW_TXRX_NATIVE_WIFI ); +if (test_bit (ATH10K_FLAG_RAW_MODE , &ar->dev_flags)) + config.rx_decap_mode =__cpu_to_le32 (ATH10K_HW_TXRX_RAW );
If 636, 10.1 or wmi-tlv firmware revisions were to advertise RAW mode support in the future rx_decap_mode won't be set correctly because you only update the 10.2 op_gen_init code.
All TARGET_*RX_DECAP_MODE should be removed from hw.h and ar->wmi.rx_decap_mode should be introduced which is set somewhere in ath10k_core_init_firmware_features() and used throughout all op_gen_init implementations.
Michał
Quoted 24 lines · Liu CF/TW
This change supports bypassing HW crypto engine by enabling raw Rx/Tx mode. This will enable use cases such as sw crypto and raw tx injection. This change introduces a new module param 'cryptmode'.
cryptmode:
0 Use HW crypto engine. Use native WiFi mode Tx/Rx encap
1 Use SW crypto engine. Use raw mode Tx/Rx encap
2 Supports both SW & HW crypto engine. Use raw mode Tx/Rx encap.
Testing: used QCA988x hw 2.0 with firmware-4.bin_10.2.4.48 with backports-20150424 (Skipped
ATH10K_FW_FEATURE_RAW_MODE_SUPPORTcheck incore.cwithin this patch.
Since none of the existing QCA official firmware has the feature bit set yet)ath10k
cryptmodeparam Testing Status ------- --------------------------------- 0 HW CCMP/TKIP tested ok.Note: HW crypto bypass not supported by ath10k hw in native WiFi mode.
Quoted 8 lines
1 - mac80211 SW crypto tested ok.
- raw Tx frame injection tested ok.2 HW CCMP/TKIP tested ok.
SW CCMP/TKIP tested ok.
Tested raw Tx encrypted frame injection ok.Signed-off-by Liu CF/TW <[email protected]>
Kbuild bot found a sparse warning:
Quoted 1 line
Quoted 1 line
drivers/net/wireless/ath/ath10k/core.c:34:14: sparse: symbol 'ath10k_cryptmode_param' was not declared. Should it be static?
Signature · 1 line
Kalle Valo
Quoted 3 lines · Liu CF/TW
This change supports bypassing HW crypto engine by enabling raw Rx/Tx mode. This will enable use cases such as sw crypto and raw tx injection. This change introduces a new module param 'cryptmode'.
Please use full words, eg. sw -> software, hw -> hardware
Quoted 3 lines
cryptmode:
0 Use HW crypto engine. Use native WiFi mode Tx/Rx encap
"Use hardware crypto engine with native Wi-Fi mode TX/RX encapsulation to the firmware"
Quoted 1 line
1 Use SW crypto engine. Use raw mode Tx/Rx encap
"Use sofware crypto engine from mac80211 with raw mode TX/RX encapsulation to the firmware"
Quoted 1 line
2 Supports both SW & HW crypto engine. Use raw mode Tx/Rx encap.
It's not clear how to use this. How does the user choose between SW or HW crypto modes? Please document that fully in the commit log.
Quoted 7 lines
ath10k
cryptmodeparam Testing Status ------- --------------------------------- 0 HW CCMP/TKIP tested ok.Note: HW crypto bypass not supported by ath10k hw in native WiFi mode.
What's "HW crypto bypass"? Please write the commit log so that everyone can understand it.
Quoted 2 lines
1 - mac80211 SW crypto tested ok.
- raw Tx frame injection tested ok.
What does "mac80211 SW crypto tested ok" exactly mean?
Quoted 2 lines
2 HW CCMP/TKIP tested ok.
SW CCMP/TKIP tested ok.
How were the HW and SW modes chosen?
Quoted 1 line
Tested raw Tx encrypted frame injection ok.
With HW or SW crypto mode?
Signature · 1 line
Kalle Valo