* [PATCH 7/8] staging: r8822be: Add Makefiles and Kconfig for new driver
From: Larry Finger @ 2017-08-17 17:46 UTC (permalink / raw)
To: gregkh
Cc: devel, Ping-Ke Shih, Yan-Hsuan Chuang, netdev, Birming Chiu,
Shaofu, Steven Ting, Larry Finger
In-Reply-To: <20170817174652.17656-1-Larry.Finger@lwfinger.net>
The RTL8822BE, an 802.11ac wireless network card, is now appearing in
new computers. Its driver is being placed in staging to reduce the time
that users of this new card will have access to in-kernel drivers.
This commit enables building of the new driver. For this version, all
routines are built into a single module r8822be. When this driver is
moved to the wireless tree, halmac, phydm, and rtl8822be will become
new modules.
Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Cc: Ping-Ke Shih <pkshih@realtek.com>
Cc: Yan-Hsuan Chuang <yhchuang@realtek.com>
Cc: Birming Chiu <birming@realtek.com>
Cc: Shaofu <shaofu@realtek.com>
Cc: Steven Ting <steventing@realtek.com>
---
drivers/staging/Kconfig | 2 +
drivers/staging/Makefile | 1 +
drivers/staging/rtlwifi/Kconfig | 22 ++
drivers/staging/rtlwifi/Makefile | 70 ++++++
drivers/staging/rtlwifi/TODO | 11 +
drivers/staging/rtlwifi/btcoexist/Makefile | 8 +
drivers/staging/rtlwifi/btcoexist/halbt_precomp.h | 5 -
drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c | 257 ++--------------------
drivers/staging/rtlwifi/rtl8822be/Makefile | 7 +
9 files changed, 137 insertions(+), 246 deletions(-)
create mode 100644 drivers/staging/rtlwifi/Kconfig
create mode 100644 drivers/staging/rtlwifi/Makefile
create mode 100644 drivers/staging/rtlwifi/TODO
create mode 100644 drivers/staging/rtlwifi/btcoexist/Makefile
create mode 100644 drivers/staging/rtlwifi/rtl8822be/Makefile
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index e97d72e3bc40..1b0a1bed8e11 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -40,6 +40,8 @@ source "drivers/staging/rtl8712/Kconfig"
source "drivers/staging/rtl8188eu/Kconfig"
+source "drivers/staging/rtlwifi/Kconfig"
+
source "drivers/staging/rts5208/Kconfig"
source "drivers/staging/octeon/Kconfig"
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 993ed0c1556c..2b61cbd44d13 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -10,6 +10,7 @@ obj-$(CONFIG_RTL8192E) += rtl8192e/
obj-$(CONFIG_RTL8723BS) += rtl8723bs/
obj-$(CONFIG_R8712U) += rtl8712/
obj-$(CONFIG_R8188EU) += rtl8188eu/
+obj-$(CONFIG_R8822BE) += rtlwifi/
obj-$(CONFIG_RTS5208) += rts5208/
obj-$(CONFIG_NETLOGIC_XLR_NET) += netlogic/
obj-$(CONFIG_OCTEON_ETHERNET) += octeon/
diff --git a/drivers/staging/rtlwifi/Kconfig b/drivers/staging/rtlwifi/Kconfig
new file mode 100644
index 000000000000..fc482b49f9aa
--- /dev/null
+++ b/drivers/staging/rtlwifi/Kconfig
@@ -0,0 +1,22 @@
+config R8822BE
+ tristate "Realtek RTL8822BE Wireless Network Adapter"
+ depends on PCI && m
+ select FW_LOADER
+ ---help---
+ This is the staging driver for Realtek RTL8822BE 802.11ac PCIe
+ wireless network adapters.
+
+config RTLHALMAC_ST
+ tristate
+ depends on R8822BE
+ default m
+
+config RTLPHYDM_ST
+ tristate
+ depends on R8822BE
+ default m
+
+config RTLWIFI_DEBUG_ST
+ boolean
+ depends on R8822BE
+ default y
diff --git a/drivers/staging/rtlwifi/Makefile b/drivers/staging/rtlwifi/Makefile
new file mode 100644
index 000000000000..0d738c18b29c
--- /dev/null
+++ b/drivers/staging/rtlwifi/Makefile
@@ -0,0 +1,70 @@
+obj-$(CONFIG_R8822BE) += r8822be.o
+
+r8822be-objs := \
+ base.o \
+ cam.o \
+ core.o \
+ debug.o \
+ efuse.o \
+ ps.o \
+ rc.o \
+ regd.o \
+ stats.o \
+ pci.o \
+ rtl8822be/fw.o \
+ rtl8822be/hw.o \
+ rtl8822be/led.o \
+ rtl8822be/phy.o \
+ rtl8822be/sw.o \
+ rtl8822be/trx.o \
+ btcoexist/halbtc8822b2ant.o \
+ btcoexist/halbtc8822b1ant.o \
+ btcoexist/halbtc8822bwifionly.o \
+ btcoexist/halbtcoutsrc.o \
+ btcoexist/rtl_btc.o \
+ halmac/halmac_api.o \
+ halmac/halmac_88xx/halmac_api_88xx_usb.o \
+ halmac/halmac_88xx/halmac_api_88xx_sdio.o \
+ halmac/halmac_88xx/halmac_api_88xx.o \
+ halmac/halmac_88xx/halmac_api_88xx_pcie.o \
+ halmac/halmac_88xx/halmac_func_88xx.o \
+ halmac/halmac_88xx/halmac_8822b/halmac_api_8822b_pcie.o \
+ halmac/halmac_88xx/halmac_8822b/halmac_func_8822b.o \
+ halmac/halmac_88xx/halmac_8822b/halmac_api_8822b_sdio.o \
+ halmac/halmac_88xx/halmac_8822b/halmac_api_8822b.o \
+ halmac/halmac_88xx/halmac_8822b/halmac_8822b_phy.o \
+ halmac/halmac_88xx/halmac_8822b/halmac_8822b_pwr_seq.o \
+ halmac/halmac_88xx/halmac_8822b/halmac_api_8822b_usb.o \
+ halmac/rtl_halmac.o \
+ phydm/phydm_debug.o \
+ phydm/phydm_antdiv.o\
+ phydm/phydm_interface.o\
+ phydm/phydm_hwconfig.o\
+ phydm/phydm.o\
+ phydm/halphyrf_ce.o\
+ phydm/phydm_edcaturbocheck.o\
+ phydm/phydm_dig.o\
+ phydm/phydm_rainfo.o\
+ phydm/phydm_dynamicbbpowersaving.o\
+ phydm/phydm_powertracking_ce.o\
+ phydm/phydm_dynamictxpower.o\
+ phydm/phydm_adaptivity.o\
+ phydm/phydm_cfotracking.o\
+ phydm/phydm_noisemonitor.o\
+ phydm/phydm_acs.o\
+ phydm/phydm_psd.o\
+ phydm/phydm_adc_sampling.o\
+ phydm/phydm_kfree.o\
+ phydm/phydm_ccx.o \
+ phydm/rtl8822b/halhwimg8822b_bb.o\
+ phydm/rtl8822b/halhwimg8822b_mac.o\
+ phydm/rtl8822b/halhwimg8822b_rf.o\
+ phydm/rtl8822b/halphyrf_8822b.o\
+ phydm/rtl8822b/phydm_hal_api8822b.o\
+ phydm/rtl8822b/phydm_iqk_8822b.o\
+ phydm/rtl8822b/phydm_regconfig8822b.o\
+ phydm/rtl8822b/phydm_rtl8822b.o \
+ phydm/rtl_phydm.o
+
+
+obj-$(CONFIG_R8822BE) += rtl8822be/
diff --git a/drivers/staging/rtlwifi/TODO b/drivers/staging/rtlwifi/TODO
new file mode 100644
index 000000000000..52a85cdf453c
--- /dev/null
+++ b/drivers/staging/rtlwifi/TODO
@@ -0,0 +1,11 @@
+TODO:
+- checkpatch.pl fixes - most of the remaining ones are lines too long. Many
+ of them will require refactoring
+- merge Realtek's bugfixes and new features into the driver
+- find and remove code blocks guarded by never set CONFIG_FOO defines
+- convert any remaining unusual variable types
+- find codes that can use %pM and %Nph formatting
+- fix any reviewer's comments regarding movin the driver to drivers/net/wireless
+
+Please send any patches to Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
+and Larry Finger <Larry.Finger@lwfinger.net>.
diff --git a/drivers/staging/rtlwifi/btcoexist/Makefile b/drivers/staging/rtlwifi/btcoexist/Makefile
new file mode 100644
index 000000000000..f600bcc38a15
--- /dev/null
+++ b/drivers/staging/rtlwifi/btcoexist/Makefile
@@ -0,0 +1,8 @@
+btcoexist-objs := \
+ halbtc8822b1ant.o \
+ halbtc8822b2ant.o \
+ halbtc8822bwifionly.o \
+ halbtcoutsrc.o \
+ rtl_btc.o
+
+obj-$(CONFIG_RTLBTCOEXIST) += btcoexist.o
diff --git a/drivers/staging/rtlwifi/btcoexist/halbt_precomp.h b/drivers/staging/rtlwifi/btcoexist/halbt_precomp.h
index 1cd3ce54b6a2..d78cd9394373 100644
--- a/drivers/staging/rtlwifi/btcoexist/halbt_precomp.h
+++ b/drivers/staging/rtlwifi/btcoexist/halbt_precomp.h
@@ -43,11 +43,6 @@
#define RT_SDIO_INTERFACE 3
#define DEV_BUS_TYPE RT_PCI_INTERFACE
-#include "halbtc8192e2ant.h"
-#include "halbtc8723b1ant.h"
-#include "halbtc8723b2ant.h"
-#include "halbtc8821a2ant.h"
-#include "halbtc8821a1ant.h"
#include "halbtc8822b1ant.h"
#include "halbtc8822b2ant.h"
#include "halbtc8822bwifionly.h"
diff --git a/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c b/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c
index e5c25c0babfb..39229cdb8045 100644
--- a/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c
+++ b/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c
@@ -1075,24 +1075,6 @@ static u32 halbtc_get_bt_reg(void *btc_context, u8 reg_type, u32 offset)
return 0;
}
-static bool halbtc_under_ips(struct btc_coexist *btcoexist)
-{
- struct rtl_priv *rtlpriv = btcoexist->adapter;
- struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
- enum rf_pwrstate rtstate;
-
- if (ppsc->inactiveps) {
- rtstate = ppsc->rfpwr_state;
-
- if (rtstate != ERFON &&
- ppsc->rfoff_reason == RF_CHANGE_BY_IPS) {
- return true;
- }
- }
-
- return false;
-}
-
static
u32 halbtc_get_phydm_version(void *btc_context)
{
@@ -1389,12 +1371,7 @@ void exhalbtc_power_on_setting(struct btc_coexist *btcoexist)
btcoexist->statistics.cnt_power_on++;
- if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8723b2ant_power_on_setting(btcoexist);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8723b1ant_power_on_setting(btcoexist);
- } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8822b1ant_power_on_setting(btcoexist);
else if (btcoexist->board_info.btdm_ant_num == 2)
@@ -1409,10 +1386,7 @@ void exhalbtc_pre_load_firmware(struct btc_coexist *btcoexist)
btcoexist->statistics.cnt_pre_load_firmware++;
- if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8723b2ant_pre_load_firmware(btcoexist);
- } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8822b1ant_pre_load_firmware(btcoexist);
else if (btcoexist->board_info.btdm_ant_num == 2)
@@ -1427,22 +1401,7 @@ void exhalbtc_init_hw_config(struct btc_coexist *btcoexist, bool wifi_only)
btcoexist->statistics.cnt_init_hw_config++;
- if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8821a2ant_init_hwconfig(btcoexist);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8821a1ant_init_hwconfig(btcoexist, wifi_only);
- } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8723b2ant_init_hwconfig(btcoexist);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8723b1ant_init_hwconfig(btcoexist, wifi_only);
- } else if (IS_HARDWARE_TYPE_8723A(btcoexist->adapter)) {
- /* 8723A has no this function */
- } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8192e2ant_init_hwconfig(btcoexist);
- } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8822b1ant_init_hw_config(btcoexist, wifi_only);
else if (btcoexist->board_info.btdm_ant_num == 2)
@@ -1466,20 +1425,7 @@ void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
btcoexist->statistics.cnt_init_coex_dm++;
- if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8821a2ant_init_coex_dm(btcoexist);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8821a1ant_init_coex_dm(btcoexist);
- } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8723b2ant_init_coex_dm(btcoexist);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8723b1ant_init_coex_dm(btcoexist);
- } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8192e2ant_init_coex_dm(btcoexist);
- } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8822b1ant_init_coex_dm(btcoexist);
else if (btcoexist->board_info.btdm_ant_num == 2)
@@ -1506,20 +1452,7 @@ void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
halbtc_leave_low_power(btcoexist);
- if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8821a2ant_ips_notify(btcoexist, ips_type);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8821a1ant_ips_notify(btcoexist, ips_type);
- } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8723b2ant_ips_notify(btcoexist, ips_type);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8723b1ant_ips_notify(btcoexist, ips_type);
- } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8192e2ant_ips_notify(btcoexist, ips_type);
- } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8822b1ant_ips_notify(btcoexist, ips_type);
else if (btcoexist->board_info.btdm_ant_num == 2)
@@ -1544,20 +1477,7 @@ void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
else
lps_type = BTC_LPS_ENABLE;
- if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8821a2ant_lps_notify(btcoexist, lps_type);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8821a1ant_lps_notify(btcoexist, lps_type);
- } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8723b2ant_lps_notify(btcoexist, lps_type);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8723b1ant_lps_notify(btcoexist, lps_type);
- } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8192e2ant_lps_notify(btcoexist, lps_type);
- } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8822b1ant_lps_notify(btcoexist, lps_type);
else if (btcoexist->board_info.btdm_ant_num == 2)
@@ -1582,20 +1502,7 @@ void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
halbtc_leave_low_power(btcoexist);
- if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8821a2ant_scan_notify(btcoexist, scan_type);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8821a1ant_scan_notify(btcoexist, scan_type);
- } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8723b2ant_scan_notify(btcoexist, scan_type);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8723b1ant_scan_notify(btcoexist, scan_type);
- } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8192e2ant_scan_notify(btcoexist, scan_type);
- } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8822b1ant_scan_notify(btcoexist, scan_type);
else if (btcoexist->board_info.btdm_ant_num == 2)
@@ -1629,20 +1536,7 @@ void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
halbtc_leave_low_power(btcoexist);
- if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8821a2ant_connect_notify(btcoexist, asso_type);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8821a1ant_connect_notify(btcoexist, asso_type);
- } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8723b2ant_connect_notify(btcoexist, asso_type);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8723b1ant_connect_notify(btcoexist, asso_type);
- } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8192e2ant_connect_notify(btcoexist, asso_type);
- } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8822b1ant_connect_notify(btcoexist, asso_type);
else if (btcoexist->board_info.btdm_ant_num == 2)
@@ -1670,20 +1564,7 @@ void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
halbtc_leave_low_power(btcoexist);
- if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8821a2ant_media_status_notify(btcoexist, status);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8821a1ant_media_status_notify(btcoexist, status);
- } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8723b2ant_media_status_notify(btcoexist, status);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8723b1ant_media_status_notify(btcoexist, status);
- } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8192e2ant_media_status_notify(btcoexist, status);
- } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8822b1ant_media_status_notify(btcoexist, status);
else if (btcoexist->board_info.btdm_ant_num == 2)
@@ -1716,25 +1597,7 @@ void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
halbtc_leave_low_power(btcoexist);
- if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8821a2ant_special_packet_notify(btcoexist,
- packet_type);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8821a1ant_special_packet_notify(btcoexist,
- packet_type);
- } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8723b2ant_special_packet_notify(btcoexist,
- packet_type);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8723b1ant_special_packet_notify(btcoexist,
- packet_type);
- } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8192e2ant_special_packet_notify(btcoexist,
- packet_type);
- } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8822b1ant_specific_packet_notify(btcoexist,
packet_type);
@@ -1755,25 +1618,7 @@ void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
halbtc_leave_low_power(btcoexist);
- if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8821a2ant_bt_info_notify(btcoexist, tmp_buf,
- length);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8821a1ant_bt_info_notify(btcoexist, tmp_buf,
- length);
- } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8723b2ant_bt_info_notify(btcoexist, tmp_buf,
- length);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8723b1ant_bt_info_notify(btcoexist, tmp_buf,
- length);
- } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8192e2ant_bt_info_notify(btcoexist, tmp_buf,
- length);
- } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8822b1ant_bt_info_notify(btcoexist, tmp_buf,
length);
@@ -1790,12 +1635,7 @@ void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
if (!halbtc_is_bt_coexist_available(btcoexist))
return;
- if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
- } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8723b1ant_rf_status_notify(btcoexist, type);
- } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
- } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8822b1ant_rf_status_notify(btcoexist, type);
else if (btcoexist->board_info.btdm_ant_num == 2)
@@ -1832,20 +1672,7 @@ void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
if (!halbtc_is_bt_coexist_available(btcoexist))
return;
- if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8821a2ant_halt_notify(btcoexist);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8821a1ant_halt_notify(btcoexist);
- } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8723b2ant_halt_notify(btcoexist);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8723b1ant_halt_notify(btcoexist);
- } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8192e2ant_halt_notify(btcoexist);
- } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8822b1ant_halt_notify(btcoexist);
else if (btcoexist->board_info.btdm_ant_num == 2)
@@ -1865,18 +1692,7 @@ void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
* we can sleep normally.
*/
- if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8723b1ant_pnp_notify(btcoexist, pnp_state);
- else if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8723b2ant_pnp_notify(btcoexist, pnp_state);
- } else if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8821a1ant_pnp_notify(btcoexist, pnp_state);
- else if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8821a2ant_pnp_notify(btcoexist, pnp_state);
- } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
- } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8822b1ant_pnp_notify(btcoexist, pnp_state);
else if (btcoexist->board_info.btdm_ant_num == 2)
@@ -1886,26 +1702,12 @@ void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
void exhalbtc_coex_dm_switch(struct btc_coexist *btcoexist)
{
- struct rtl_priv *rtlpriv = btcoexist->adapter;
-
if (!halbtc_is_bt_coexist_available(btcoexist))
return;
btcoexist->statistics.cnt_coex_dm_switch++;
halbtc_leave_low_power(btcoexist);
- if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 1) {
- btcoexist->stop_coex_dm = true;
- ex_btc8723b1ant_coex_dm_reset(btcoexist);
- exhalbtc_set_ant_num(rtlpriv,
- BT_COEX_ANT_TYPE_DETECTED, 2);
- ex_btc8723b2ant_init_hwconfig(btcoexist);
- ex_btc8723b2ant_init_coex_dm(btcoexist);
- btcoexist->stop_coex_dm = false;
- }
- }
-
halbtc_normal_low_power(btcoexist);
}
@@ -1917,21 +1719,7 @@ void exhalbtc_periodical(struct btc_coexist *btcoexist)
halbtc_leave_low_power(btcoexist);
- if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8821a2ant_periodical(btcoexist);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- if (!halbtc_under_ips(btcoexist))
- ex_btc8821a1ant_periodical(btcoexist);
- } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8723b2ant_periodical(btcoexist);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8723b1ant_periodical(btcoexist);
- } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8192e2ant_periodical(btcoexist);
- } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8822b1ant_periodical(btcoexist);
else if (btcoexist->board_info.btdm_ant_num == 2)
@@ -2056,20 +1844,7 @@ void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist,
halbtc_leave_low_power(btcoexist);
- if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8821a2ant_display_coex_info(btcoexist, m);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8821a1ant_display_coex_info(btcoexist, m);
- } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8723b2ant_display_coex_info(btcoexist, m);
- else if (btcoexist->board_info.btdm_ant_num == 1)
- ex_btc8723b1ant_display_coex_info(btcoexist, m);
- } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
- if (btcoexist->board_info.btdm_ant_num == 2)
- ex_btc8192e2ant_display_coex_info(btcoexist, m);
- } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8822b1ant_display_coex_info(btcoexist, m);
else if (btcoexist->board_info.btdm_ant_num == 2)
diff --git a/drivers/staging/rtlwifi/rtl8822be/Makefile b/drivers/staging/rtlwifi/rtl8822be/Makefile
new file mode 100644
index 000000000000..d535ff8febf1
--- /dev/null
+++ b/drivers/staging/rtlwifi/rtl8822be/Makefile
@@ -0,0 +1,7 @@
+rtl8822be-objs := \
+ fw.o \
+ hw.o \
+ led.o \
+ phy.o \
+ sw.o \
+ trx.o
--
2.12.3
^ permalink raw reply related
* [PATCH 2/8] staging: r8822be: Copy existing btcoexist code into staging
From: Larry Finger @ 2017-08-17 17:46 UTC (permalink / raw)
To: gregkh
Cc: devel, Ping-Ke Shih, Yan-Hsuan Chuang, netdev, Birming Chiu,
Shaofu, Steven Ting, Larry Finger
In-Reply-To: <20170817174652.17656-1-Larry.Finger@lwfinger.net>
The RTL8822BE, an 802.11ac wireless network card, is now appearing in
new computers. Its driver is being placed in staging to reduce the time
that users of this new card will have access to in-kernel drivers.
This commit copies the existing routines from .../rtlwifi/btcoexist/
into staging. There are no changes other than removing all EXPORT
statements, and the fixing of checkpatch messages. The latter will
be backported to the wireless tree.
Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Cc: Ping-Ke Shih <pkshih@realtek.com>
Cc: Yan-Hsuan Chuang <yhchuang@realtek.com>
Cc: Birming Chiu <birming@realtek.com>
Cc: Shaofu <shaofu@realtek.com>
Cc: Steven Ting <steventing@realtek.com>
---
drivers/staging/rtlwifi/btcoexist/halbt_precomp.h | 90 +
drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c | 2107 +++++++++++++++++++++
drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.h | 802 ++++++++
drivers/staging/rtlwifi/btcoexist/rtl_btc.c | 528 ++++++
drivers/staging/rtlwifi/btcoexist/rtl_btc.h | 75 +
5 files changed, 3602 insertions(+)
create mode 100644 drivers/staging/rtlwifi/btcoexist/halbt_precomp.h
create mode 100644 drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c
create mode 100644 drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.h
create mode 100644 drivers/staging/rtlwifi/btcoexist/rtl_btc.c
create mode 100644 drivers/staging/rtlwifi/btcoexist/rtl_btc.h
diff --git a/drivers/staging/rtlwifi/btcoexist/halbt_precomp.h b/drivers/staging/rtlwifi/btcoexist/halbt_precomp.h
new file mode 100644
index 000000000000..1cd3ce54b6a2
--- /dev/null
+++ b/drivers/staging/rtlwifi/btcoexist/halbt_precomp.h
@@ -0,0 +1,90 @@
+/******************************************************************************
+ *
+ * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * The full GNU General Public License is included in this distribution in the
+ * file called LICENSE.
+ *
+ * Contact Information:
+ * wlanfae <wlanfae@realtek.com>
+ * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
+ * Hsinchu 300, Taiwan.
+ * Larry Finger <Larry.Finger@lwfinger.net>
+ *
+ ******************************************************************************/
+
+#ifndef __HALBT_PRECOMP_H__
+#define __HALBT_PRECOMP_H__
+/*************************************************************
+ * include files
+ *************************************************************/
+#include "../wifi.h"
+#include "../efuse.h"
+#include "../base.h"
+#include "../regd.h"
+#include "../cam.h"
+#include "../ps.h"
+#include "../pci.h"
+
+#include "halbtcoutsrc.h"
+
+/* Interface type */
+#define RT_PCI_INTERFACE 1
+#define RT_USB_INTERFACE 2
+#define RT_SDIO_INTERFACE 3
+#define DEV_BUS_TYPE RT_PCI_INTERFACE
+
+#include "halbtc8192e2ant.h"
+#include "halbtc8723b1ant.h"
+#include "halbtc8723b2ant.h"
+#include "halbtc8821a2ant.h"
+#include "halbtc8821a1ant.h"
+#include "halbtc8822b1ant.h"
+#include "halbtc8822b2ant.h"
+#include "halbtc8822bwifionly.h"
+
+#define GETDEFAULTADAPTER(padapter) padapter
+
+#define BIT0 0x00000001
+#define BIT1 0x00000002
+#define BIT2 0x00000004
+#define BIT3 0x00000008
+#define BIT4 0x00000010
+#define BIT5 0x00000020
+#define BIT6 0x00000040
+#define BIT7 0x00000080
+#define BIT8 0x00000100
+#define BIT9 0x00000200
+#define BIT10 0x00000400
+#define BIT11 0x00000800
+#define BIT12 0x00001000
+#define BIT13 0x00002000
+#define BIT14 0x00004000
+#define BIT15 0x00008000
+#define BIT16 0x00010000
+#define BIT17 0x00020000
+#define BIT18 0x00040000
+#define BIT19 0x00080000
+#define BIT20 0x00100000
+#define BIT21 0x00200000
+#define BIT22 0x00400000
+#define BIT23 0x00800000
+#define BIT24 0x01000000
+#define BIT25 0x02000000
+#define BIT26 0x04000000
+#define BIT27 0x08000000
+#define BIT28 0x10000000
+#define BIT29 0x20000000
+#define BIT30 0x40000000
+#define BIT31 0x80000000
+
+#endif /* __HALBT_PRECOMP_H__ */
diff --git a/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c b/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c
new file mode 100644
index 000000000000..e5c25c0babfb
--- /dev/null
+++ b/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c
@@ -0,0 +1,2107 @@
+/******************************************************************************
+ *
+ * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * The full GNU General Public License is included in this distribution in the
+ * file called LICENSE.
+ *
+ * Contact Information:
+ * wlanfae <wlanfae@realtek.com>
+ * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
+ * Hsinchu 300, Taiwan.
+ *
+ * Larry Finger <Larry.Finger@lwfinger.net>
+ *
+ ******************************************************************************/
+
+#include "halbt_precomp.h"
+
+/***************************************************
+ * Debug related function
+ ***************************************************/
+
+static const char *const gl_btc_wifi_bw_string[] = {
+ "11bg",
+ "HT20",
+ "HT40",
+ "HT80",
+ "HT160"
+};
+
+static const char *const gl_btc_wifi_freq_string[] = {
+ "2.4G",
+ "5G"
+};
+
+static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist)
+{
+ if (!btcoexist->binded || NULL == btcoexist->adapter)
+ return false;
+
+ return true;
+}
+
+static bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv)
+{
+ if (rtlpriv->link_info.busytraffic)
+ return true;
+ else
+ return false;
+}
+
+static void halbtc_dbg_init(void)
+{
+}
+
+/***************************************************
+ * helper function
+ ***************************************************/
+static bool is_any_client_connect_to_ap(struct btc_coexist *btcoexist)
+{
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+ struct rtl_mac *mac = rtl_mac(rtlpriv);
+ struct rtl_sta_info *drv_priv;
+ u8 cnt = 0;
+
+ if (mac->opmode == NL80211_IFTYPE_ADHOC ||
+ mac->opmode == NL80211_IFTYPE_MESH_POINT ||
+ mac->opmode == NL80211_IFTYPE_AP) {
+ if (in_interrupt() > 0) {
+ list_for_each_entry(drv_priv, &rtlpriv->entry_list,
+ list) {
+ cnt++;
+ }
+ } else {
+ spin_lock_bh(&rtlpriv->locks.entry_list_lock);
+ list_for_each_entry(drv_priv, &rtlpriv->entry_list,
+ list) {
+ cnt++;
+ }
+ spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
+ }
+ }
+ if (cnt > 0)
+ return true;
+ else
+ return false;
+}
+
+static bool halbtc_legacy(struct rtl_priv *adapter)
+{
+ struct rtl_priv *rtlpriv = adapter;
+ struct rtl_mac *mac = rtl_mac(rtlpriv);
+
+ bool is_legacy = false;
+
+ if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_G))
+ is_legacy = true;
+
+ return is_legacy;
+}
+
+bool halbtc_is_wifi_uplink(struct rtl_priv *adapter)
+{
+ struct rtl_priv *rtlpriv = adapter;
+
+ if (rtlpriv->link_info.tx_busy_traffic)
+ return true;
+ else
+ return false;
+}
+
+static u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist)
+{
+ struct rtl_priv *rtlpriv =
+ (struct rtl_priv *)btcoexist->adapter;
+ struct rtl_phy *rtlphy = &rtlpriv->phy;
+ u32 wifi_bw = BTC_WIFI_BW_HT20;
+
+ if (halbtc_legacy(rtlpriv)) {
+ wifi_bw = BTC_WIFI_BW_LEGACY;
+ } else {
+ switch (rtlphy->current_chan_bw) {
+ case HT_CHANNEL_WIDTH_20:
+ wifi_bw = BTC_WIFI_BW_HT20;
+ break;
+ case HT_CHANNEL_WIDTH_20_40:
+ wifi_bw = BTC_WIFI_BW_HT40;
+ break;
+ case HT_CHANNEL_WIDTH_80:
+ wifi_bw = BTC_WIFI_BW_HT80;
+ break;
+ }
+ }
+
+ return wifi_bw;
+}
+
+static u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist)
+{
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+ struct rtl_phy *rtlphy = &rtlpriv->phy;
+ u8 chnl = 1;
+
+ if (rtlphy->current_channel != 0)
+ chnl = rtlphy->current_channel;
+ RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
+ "%s:%d\n", __func__, chnl);
+ return chnl;
+}
+
+static u8 rtl_get_hwpg_single_ant_path(struct rtl_priv *rtlpriv)
+{
+ return rtlpriv->btcoexist.btc_info.single_ant_path;
+}
+
+static u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv)
+{
+ return rtlpriv->btcoexist.btc_info.bt_type;
+}
+
+static u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv)
+{
+ u8 num;
+
+ if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2)
+ num = 2;
+ else
+ num = 1;
+
+ return num;
+}
+
+static u8 rtl_get_hwpg_package_type(struct rtl_priv *rtlpriv)
+{
+ struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
+
+ return rtlhal->package_type;
+}
+
+static
+u8 rtl_get_hwpg_rfe_type(struct rtl_priv *rtlpriv)
+{
+ struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
+
+ return rtlhal->rfe_type;
+}
+
+/* ************************************
+ * Hal helper function
+ * ************************************
+ */
+static
+bool halbtc_is_hw_mailbox_exist(struct btc_coexist *btcoexist)
+{
+ if (IS_HARDWARE_TYPE_8812(btcoexist->adapter))
+ return false;
+ else
+ return true;
+}
+
+static
+bool halbtc_send_bt_mp_operation(struct btc_coexist *btcoexist, u8 op_code,
+ u8 *cmd, u32 len, unsigned long wait_ms)
+{
+ struct rtl_priv *rtlpriv;
+ const u8 oper_ver = 0;
+ u8 req_num;
+
+ if (!halbtc_is_hw_mailbox_exist(btcoexist))
+ return false;
+
+ if (wait_ms) /* before h2c to avoid race condition */
+ reinit_completion(&btcoexist->bt_mp_comp);
+
+ rtlpriv = btcoexist->adapter;
+
+ /*
+ * fill req_num by op_code, and rtl_btc_btmpinfo_notify() use it
+ * to know message type
+ */
+ switch (op_code) {
+ case BT_OP_GET_BT_VERSION:
+ req_num = BT_SEQ_GET_BT_VERSION;
+ break;
+ case BT_OP_GET_AFH_MAP_L:
+ req_num = BT_SEQ_GET_AFH_MAP_L;
+ break;
+ case BT_OP_GET_AFH_MAP_M:
+ req_num = BT_SEQ_GET_AFH_MAP_M;
+ break;
+ case BT_OP_GET_AFH_MAP_H:
+ req_num = BT_SEQ_GET_AFH_MAP_H;
+ break;
+ case BT_OP_GET_BT_COEX_SUPPORTED_FEATURE:
+ req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_FEATURE;
+ break;
+ case BT_OP_GET_BT_COEX_SUPPORTED_VERSION:
+ req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_VERSION;
+ break;
+ case BT_OP_GET_BT_ANT_DET_VAL:
+ req_num = BT_SEQ_GET_BT_ANT_DET_VAL;
+ break;
+ case BT_OP_GET_BT_BLE_SCAN_PARA:
+ req_num = BT_SEQ_GET_BT_BLE_SCAN_PARA;
+ break;
+ case BT_OP_GET_BT_BLE_SCAN_TYPE:
+ req_num = BT_SEQ_GET_BT_BLE_SCAN_TYPE;
+ break;
+ case BT_OP_WRITE_REG_ADDR:
+ case BT_OP_WRITE_REG_VALUE:
+ case BT_OP_READ_REG:
+ default:
+ req_num = BT_SEQ_DONT_CARE;
+ break;
+ }
+
+ cmd[0] |= (oper_ver & 0x0f); /* Set OperVer */
+ cmd[0] |= ((req_num << 4) & 0xf0); /* Set ReqNum */
+ cmd[1] = op_code;
+ rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, len, cmd);
+
+ /* wait? */
+ if (!wait_ms)
+ return true;
+
+ RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
+ "btmpinfo wait req_num=%d wait=%ld\n", req_num, wait_ms);
+
+ if (in_interrupt())
+ return false;
+
+ if (wait_for_completion_timeout(&btcoexist->bt_mp_comp,
+ msecs_to_jiffies(wait_ms)) == 0) {
+ RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
+ "btmpinfo wait (req_num=%d) timeout\n", req_num);
+
+ return false; /* timeout */
+ }
+
+ return true;
+}
+
+static void halbtc_leave_lps(struct btc_coexist *btcoexist)
+{
+ struct rtl_priv *rtlpriv;
+ struct rtl_ps_ctl *ppsc;
+ bool ap_enable = false;
+
+ rtlpriv = btcoexist->adapter;
+ ppsc = rtl_psc(rtlpriv);
+
+ btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
+ &ap_enable);
+
+ if (ap_enable) {
+ RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
+ "%s()<--dont leave lps under AP mode\n", __func__);
+ return;
+ }
+
+ btcoexist->bt_info.bt_ctrl_lps = true;
+ btcoexist->bt_info.bt_lps_on = false;
+ rtl_lps_leave(rtlpriv->mac80211.hw);
+}
+
+static void halbtc_enter_lps(struct btc_coexist *btcoexist)
+{
+ struct rtl_priv *rtlpriv;
+ struct rtl_ps_ctl *ppsc;
+ bool ap_enable = false;
+
+ rtlpriv = btcoexist->adapter;
+ ppsc = rtl_psc(rtlpriv);
+
+ btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
+ &ap_enable);
+
+ if (ap_enable) {
+ RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
+ "%s()<--dont enter lps under AP mode\n", __func__);
+ return;
+ }
+
+ btcoexist->bt_info.bt_ctrl_lps = true;
+ btcoexist->bt_info.bt_lps_on = true;
+ rtl_lps_enter(rtlpriv->mac80211.hw);
+}
+
+static void halbtc_normal_lps(struct btc_coexist *btcoexist)
+{
+ struct rtl_priv *rtlpriv;
+
+ rtlpriv = btcoexist->adapter;
+
+ if (btcoexist->bt_info.bt_ctrl_lps) {
+ btcoexist->bt_info.bt_lps_on = false;
+ rtl_lps_leave(rtlpriv->mac80211.hw);
+ btcoexist->bt_info.bt_ctrl_lps = false;
+ }
+}
+
+static void halbtc_leave_low_power(struct btc_coexist *btcoexist)
+{
+}
+
+static void halbtc_normal_low_power(struct btc_coexist *btcoexist)
+{
+}
+
+static void halbtc_disable_low_power(struct btc_coexist *btcoexist,
+ bool low_pwr_disable)
+{
+ /* TODO: original/leave 32k low power */
+ btcoexist->bt_info.bt_disable_low_pwr = low_pwr_disable;
+}
+
+static void halbtc_aggregation_check(struct btc_coexist *btcoexist)
+{
+ bool need_to_act = false;
+ static unsigned long pre_time;
+ unsigned long cur_time = 0;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+
+ /* To void continuous deleteBA=>addBA=>deleteBA=>addBA
+ * This function is not allowed to continuous called
+ * It can only be called after 8 seconds
+ */
+
+ cur_time = jiffies;
+ if (jiffies_to_msecs(cur_time - pre_time) <= 8000) {
+ /* over 8 seconds you can execute this function again. */
+ return;
+ }
+ pre_time = cur_time;
+
+ if (btcoexist->bt_info.reject_agg_pkt) {
+ need_to_act = true;
+ btcoexist->bt_info.pre_reject_agg_pkt =
+ btcoexist->bt_info.reject_agg_pkt;
+ } else {
+ if (btcoexist->bt_info.pre_reject_agg_pkt) {
+ need_to_act = true;
+ btcoexist->bt_info.pre_reject_agg_pkt =
+ btcoexist->bt_info.reject_agg_pkt;
+ }
+
+ if (btcoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
+ btcoexist->bt_info.bt_ctrl_agg_buf_size) {
+ need_to_act = true;
+ btcoexist->bt_info.pre_bt_ctrl_agg_buf_size =
+ btcoexist->bt_info.bt_ctrl_agg_buf_size;
+ }
+
+ if (btcoexist->bt_info.bt_ctrl_agg_buf_size) {
+ if (btcoexist->bt_info.pre_agg_buf_size !=
+ btcoexist->bt_info.agg_buf_size) {
+ need_to_act = true;
+ }
+ btcoexist->bt_info.pre_agg_buf_size =
+ btcoexist->bt_info.agg_buf_size;
+ }
+
+ if (need_to_act)
+ rtl_rx_ampdu_apply(rtlpriv);
+ }
+}
+
+static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
+{
+ u8 cmd_buffer[4] = {0};
+
+ if (btcoexist->bt_info.bt_real_fw_ver)
+ goto label_done;
+
+ /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
+ halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_VERSION,
+ cmd_buffer, 4, 200);
+
+label_done:
+ return btcoexist->bt_info.bt_real_fw_ver;
+}
+
+static u32 halbtc_get_bt_coex_supported_feature(void *btc_context)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
+ u8 cmd_buffer[4] = {0};
+
+ if (btcoexist->bt_info.bt_supported_feature)
+ goto label_done;
+
+ /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
+ halbtc_send_bt_mp_operation(btcoexist,
+ BT_OP_GET_BT_COEX_SUPPORTED_FEATURE,
+ cmd_buffer, 4, 200);
+
+label_done:
+ return btcoexist->bt_info.bt_supported_feature;
+}
+
+static u32 halbtc_get_bt_coex_supported_version(void *btc_context)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
+ u8 cmd_buffer[4] = {0};
+
+ if (btcoexist->bt_info.bt_supported_version)
+ goto label_done;
+
+ /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
+ halbtc_send_bt_mp_operation(btcoexist,
+ BT_OP_GET_BT_COEX_SUPPORTED_VERSION,
+ cmd_buffer, 4, 200);
+
+label_done:
+ return btcoexist->bt_info.bt_supported_version;
+}
+
+static u32 halbtc_get_wifi_link_status(struct btc_coexist *btcoexist)
+{
+ /* return value:
+ * [31:16] => connected port number
+ * [15:0] => port connected bit define
+ */
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+ struct rtl_mac *mac = rtl_mac(rtlpriv);
+ u32 ret_val = 0;
+ u32 port_connected_status = 0, num_of_connected_port = 0;
+
+ if (mac->opmode == NL80211_IFTYPE_STATION &&
+ mac->link_state >= MAC80211_LINKED) {
+ port_connected_status |= WIFI_STA_CONNECTED;
+ num_of_connected_port++;
+ }
+ /* AP & ADHOC & MESH */
+ if (is_any_client_connect_to_ap(btcoexist)) {
+ port_connected_status |= WIFI_AP_CONNECTED;
+ num_of_connected_port++;
+ }
+ /* TODO: P2P Connected Status */
+
+ ret_val = (num_of_connected_port << 16) | port_connected_status;
+
+ return ret_val;
+}
+
+static s32 halbtc_get_wifi_rssi(struct rtl_priv *rtlpriv)
+{
+ int undec_sm_pwdb = 0;
+
+ if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
+ undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
+ else /* associated entry pwdb */
+ undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
+ return undec_sm_pwdb;
+}
+
+static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+ struct rtl_phy *rtlphy = &rtlpriv->phy;
+ struct rtl_mac *mac = rtl_mac(rtlpriv);
+ struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
+ bool *bool_tmp = (bool *)out_buf;
+ int *s32_tmp = (int *)out_buf;
+ u32 *u32_tmp = (u32 *)out_buf;
+ u8 *u8_tmp = (u8 *)out_buf;
+ bool tmp = false;
+ bool ret = true;
+
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return false;
+
+ switch (get_type) {
+ case BTC_GET_BL_HS_OPERATION:
+ *bool_tmp = false;
+ ret = false;
+ break;
+ case BTC_GET_BL_HS_CONNECTING:
+ *bool_tmp = false;
+ ret = false;
+ break;
+ case BTC_GET_BL_WIFI_CONNECTED:
+ if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_STATION &&
+ rtlpriv->mac80211.link_state >= MAC80211_LINKED)
+ tmp = true;
+ if (is_any_client_connect_to_ap(btcoexist))
+ tmp = true;
+ *bool_tmp = tmp;
+ break;
+ case BTC_GET_BL_WIFI_BUSY:
+ if (halbtc_is_wifi_busy(rtlpriv))
+ *bool_tmp = true;
+ else
+ *bool_tmp = false;
+ break;
+ case BTC_GET_BL_WIFI_SCAN:
+ if (mac->act_scanning)
+ *bool_tmp = true;
+ else
+ *bool_tmp = false;
+ break;
+ case BTC_GET_BL_WIFI_LINK:
+ if (mac->link_state == MAC80211_LINKING)
+ *bool_tmp = true;
+ else
+ *bool_tmp = false;
+ break;
+ case BTC_GET_BL_WIFI_ROAM:
+ if (mac->link_state == MAC80211_LINKING)
+ *bool_tmp = true;
+ else
+ *bool_tmp = false;
+ break;
+ case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
+ *bool_tmp = rtlpriv->btcoexist.btc_info.in_4way;
+ break;
+ case BTC_GET_BL_WIFI_UNDER_5G:
+ if (rtlhal->current_bandtype == BAND_ON_5G)
+ *bool_tmp = true;
+ else
+ *bool_tmp = false;
+ break;
+ case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
+ if (mac->opmode == NL80211_IFTYPE_AP)
+ *bool_tmp = true;
+ else
+ *bool_tmp = false;
+ break;
+ case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
+ if (rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION)
+ *bool_tmp = false;
+ else
+ *bool_tmp = true;
+ break;
+ case BTC_GET_BL_WIFI_UNDER_B_MODE:
+ if (rtlpriv->mac80211.mode == WIRELESS_MODE_B)
+ *bool_tmp = true;
+ else
+ *bool_tmp = false;
+ break;
+ case BTC_GET_BL_EXT_SWITCH:
+ *bool_tmp = false;
+ break;
+ case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
+ *bool_tmp = false;
+ break;
+ case BTC_GET_BL_IS_ASUS_8723B:
+ *bool_tmp = false;
+ break;
+ case BTC_GET_BL_RF4CE_CONNECTED:
+ *bool_tmp = false;
+ break;
+ case BTC_GET_S4_WIFI_RSSI:
+ *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
+ break;
+ case BTC_GET_S4_HS_RSSI:
+ *s32_tmp = 0;
+ ret = false;
+ break;
+ case BTC_GET_U4_WIFI_BW:
+ *u32_tmp = halbtc_get_wifi_bw(btcoexist);
+ break;
+ case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
+ if (halbtc_is_wifi_uplink(rtlpriv))
+ *u32_tmp = BTC_WIFI_TRAFFIC_TX;
+ else
+ *u32_tmp = BTC_WIFI_TRAFFIC_RX;
+ break;
+ case BTC_GET_U4_WIFI_FW_VER:
+ *u32_tmp = (rtlhal->fw_version << 16) | rtlhal->fw_subversion;
+ break;
+ case BTC_GET_U4_WIFI_LINK_STATUS:
+ *u32_tmp = halbtc_get_wifi_link_status(btcoexist);
+ break;
+ case BTC_GET_U4_BT_PATCH_VER:
+ *u32_tmp = halbtc_get_bt_patch_version(btcoexist);
+ break;
+ case BTC_GET_U4_VENDOR:
+ *u32_tmp = BTC_VENDOR_OTHER;
+ break;
+ case BTC_GET_U4_SUPPORTED_VERSION:
+ *u32_tmp = halbtc_get_bt_coex_supported_version(btcoexist);
+ break;
+ case BTC_GET_U4_SUPPORTED_FEATURE:
+ *u32_tmp = halbtc_get_bt_coex_supported_feature(btcoexist);
+ break;
+ case BTC_GET_U4_WIFI_IQK_TOTAL:
+ *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
+ "IQK_TOTAL");
+ break;
+ case BTC_GET_U4_WIFI_IQK_OK:
+ *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
+ "IQK_OK");
+ break;
+ case BTC_GET_U4_WIFI_IQK_FAIL:
+ *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
+ "IQK_FAIL");
+ break;
+ case BTC_GET_U1_WIFI_DOT11_CHNL:
+ *u8_tmp = rtlphy->current_channel;
+ break;
+ case BTC_GET_U1_WIFI_CENTRAL_CHNL:
+ *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
+ break;
+ case BTC_GET_U1_WIFI_HS_CHNL:
+ *u8_tmp = 0;
+ ret = false;
+ break;
+ case BTC_GET_U1_AP_NUM:
+ *u8_tmp = rtlpriv->btcoexist.btc_info.ap_num;
+ break;
+ case BTC_GET_U1_ANT_TYPE:
+ *u8_tmp = (u8)BTC_ANT_TYPE_0;
+ break;
+ case BTC_GET_U1_IOT_PEER:
+ *u8_tmp = 0;
+ break;
+
+ /************* 1Ant **************/
+ case BTC_GET_U1_LPS_MODE:
+ *u8_tmp = btcoexist->pwr_mode_val[0];
+ break;
+
+ default:
+ ret = false;
+ break;
+ }
+
+ return ret;
+}
+
+static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
+ bool *bool_tmp = (bool *)in_buf;
+ u8 *u8_tmp = (u8 *)in_buf;
+ u32 *u32_tmp = (u32 *)in_buf;
+ bool ret = true;
+
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return false;
+
+ switch (set_type) {
+ /* set some bool type variables. */
+ case BTC_SET_BL_BT_DISABLE:
+ btcoexist->bt_info.bt_disabled = *bool_tmp;
+ break;
+ case BTC_SET_BL_BT_TRAFFIC_BUSY:
+ btcoexist->bt_info.bt_busy = *bool_tmp;
+ break;
+ case BTC_SET_BL_BT_LIMITED_DIG:
+ btcoexist->bt_info.limited_dig = *bool_tmp;
+ break;
+ case BTC_SET_BL_FORCE_TO_ROAM:
+ btcoexist->bt_info.force_to_roam = *bool_tmp;
+ break;
+ case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
+ btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
+ break;
+ case BTC_SET_BL_BT_CTRL_AGG_SIZE:
+ btcoexist->bt_info.bt_ctrl_agg_buf_size = *bool_tmp;
+ break;
+ case BTC_SET_BL_INC_SCAN_DEV_NUM:
+ btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
+ break;
+ case BTC_SET_BL_BT_TX_RX_MASK:
+ btcoexist->bt_info.bt_tx_rx_mask = *bool_tmp;
+ break;
+ case BTC_SET_BL_MIRACAST_PLUS_BT:
+ btcoexist->bt_info.miracast_plus_bt = *bool_tmp;
+ break;
+ /* set some u1Byte type variables. */
+ case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
+ btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp;
+ break;
+ case BTC_SET_U1_AGG_BUF_SIZE:
+ btcoexist->bt_info.agg_buf_size = *u8_tmp;
+ break;
+
+ /* the following are some action which will be triggered */
+ case BTC_SET_ACT_GET_BT_RSSI:
+ ret = false;
+ break;
+ case BTC_SET_ACT_AGGREGATE_CTRL:
+ halbtc_aggregation_check(btcoexist);
+ break;
+
+ /* 1Ant */
+ case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
+ btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
+ break;
+ case BTC_SET_UI_SCAN_SIG_COMPENSATION:
+ break;
+ case BTC_SET_U1_LPS_VAL:
+ btcoexist->bt_info.lps_val = *u8_tmp;
+ break;
+ case BTC_SET_U1_RPWM_VAL:
+ btcoexist->bt_info.rpwm_val = *u8_tmp;
+ break;
+ /* the following are some action which will be triggered */
+ case BTC_SET_ACT_LEAVE_LPS:
+ halbtc_leave_lps(btcoexist);
+ break;
+ case BTC_SET_ACT_ENTER_LPS:
+ halbtc_enter_lps(btcoexist);
+ break;
+ case BTC_SET_ACT_NORMAL_LPS:
+ halbtc_normal_lps(btcoexist);
+ break;
+ case BTC_SET_ACT_DISABLE_LOW_POWER:
+ halbtc_disable_low_power(btcoexist, *bool_tmp);
+ break;
+ case BTC_SET_ACT_UPDATE_RAMASK:
+ btcoexist->bt_info.ra_mask = *u32_tmp;
+ break;
+ case BTC_SET_ACT_SEND_MIMO_PS:
+ break;
+ case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
+ break;
+ case BTC_SET_ACT_CTRL_BT_COEX:
+ break;
+ case BTC_SET_ACT_CTRL_8723B_ANT:
+ break;
+ default:
+ break;
+ }
+
+ return ret;
+}
+
+static void halbtc_display_coex_statistics(struct btc_coexist *btcoexist,
+ struct seq_file *m)
+{
+}
+
+static void halbtc_display_bt_link_info(struct btc_coexist *btcoexist,
+ struct seq_file *m)
+{
+}
+
+static void halbtc_display_wifi_status(struct btc_coexist *btcoexist,
+ struct seq_file *m)
+{
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+ s32 wifi_rssi = 0, bt_hs_rssi = 0;
+ bool scan = false, link = false, roam = false, wifi_busy = false,
+ wifi_under_b_mode = false,
+ wifi_under_5g = false;
+ u32 wifi_bw = BTC_WIFI_BW_HT20,
+ wifi_traffic_dir = BTC_WIFI_TRAFFIC_TX,
+ wifi_freq = BTC_FREQ_2_4G;
+ u32 wifi_link_status = 0x0;
+ bool bt_hs_on = false, under_ips = false, under_lps = false,
+ low_power = false, dc_mode = false;
+ u8 wifi_chnl = 0, wifi_hs_chnl = 0, fw_ps_state;
+ u8 ap_num = 0;
+
+ wifi_link_status = halbtc_get_wifi_link_status(btcoexist);
+ seq_printf(m, "\n %-35s = %d/ %d/ %d/ %d/ %d",
+ "STA/vWifi/HS/p2pGo/p2pGc",
+ ((wifi_link_status & WIFI_STA_CONNECTED) ? 1 : 0),
+ ((wifi_link_status & WIFI_AP_CONNECTED) ? 1 : 0),
+ ((wifi_link_status & WIFI_HS_CONNECTED) ? 1 : 0),
+ ((wifi_link_status & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
+ ((wifi_link_status & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
+
+ btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
+ btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifi_chnl);
+ btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
+ seq_printf(m, "\n %-35s = %d / %d(%d)",
+ "Dot11 channel / HsChnl(High Speed)",
+ wifi_chnl, wifi_hs_chnl, bt_hs_on);
+
+ btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
+ btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
+ seq_printf(m, "\n %-35s = %d/ %d",
+ "Wifi rssi/ HS rssi",
+ wifi_rssi - 100, bt_hs_rssi - 100);
+
+ btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
+ btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
+ btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
+ seq_printf(m, "\n %-35s = %d/ %d/ %d ",
+ "Wifi link/ roam/ scan",
+ link, roam, scan);
+
+ btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
+ btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
+ btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
+ btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
+ &wifi_traffic_dir);
+ btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
+ wifi_freq = (wifi_under_5g ? BTC_FREQ_5G : BTC_FREQ_2_4G);
+ btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
+ &wifi_under_b_mode);
+
+ seq_printf(m, "\n %-35s = %s / %s/ %s/ AP=%d ",
+ "Wifi freq/ bw/ traffic",
+ gl_btc_wifi_freq_string[wifi_freq],
+ ((wifi_under_b_mode) ? "11b" :
+ gl_btc_wifi_bw_string[wifi_bw]),
+ ((!wifi_busy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX ==
+ wifi_traffic_dir) ? "uplink" :
+ "downlink")),
+ ap_num);
+
+ /* power status */
+ dc_mode = true; /*TODO*/
+ under_ips = rtlpriv->psc.inactive_pwrstate == ERFOFF ? 1 : 0;
+ under_lps = rtlpriv->psc.dot11_psmode == EACTIVE ? 0 : 1;
+ fw_ps_state = 0;
+ low_power = 0; /*TODO*/
+ seq_printf(m, "\n %-35s = %s%s%s%s",
+ "Power Status",
+ (dc_mode ? "DC mode" : "AC mode"),
+ (under_ips ? ", IPS ON" : ""),
+ (under_lps ? ", LPS ON" : ""),
+ (low_power ? ", 32k" : ""));
+
+ seq_printf(m,
+ "\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)",
+ "Power mode cmd(lps/rpwm)",
+ btcoexist->pwr_mode_val[0], btcoexist->pwr_mode_val[1],
+ btcoexist->pwr_mode_val[2], btcoexist->pwr_mode_val[3],
+ btcoexist->pwr_mode_val[4], btcoexist->pwr_mode_val[5],
+ btcoexist->bt_info.lps_val,
+ btcoexist->bt_info.rpwm_val);
+}
+
+/************************************************************
+ * IO related function
+ ************************************************************/
+static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+
+ return rtl_read_byte(rtlpriv, reg_addr);
+}
+
+static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+
+ return rtl_read_word(rtlpriv, reg_addr);
+}
+
+static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+
+ return rtl_read_dword(rtlpriv, reg_addr);
+}
+
+static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u32 data)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+
+ rtl_write_byte(rtlpriv, reg_addr, data);
+}
+
+static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr,
+ u32 bit_mask, u8 data)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+ u8 original_value, bit_shift = 0;
+ u8 i;
+
+ if (bit_mask != MASKDWORD) {/*if not "double word" write*/
+ original_value = rtl_read_byte(rtlpriv, reg_addr);
+ for (i = 0; i <= 7; i++) {
+ if ((bit_mask >> i) & 0x1)
+ break;
+ }
+ bit_shift = i;
+ data = (original_value & (~bit_mask)) |
+ ((data << bit_shift) & bit_mask);
+ }
+ rtl_write_byte(rtlpriv, reg_addr, data);
+}
+
+static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+
+ rtl_write_word(rtlpriv, reg_addr, data);
+}
+
+static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
+{
+ struct btc_coexist *btcoexist =
+ (struct btc_coexist *)bt_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+
+ rtl_write_dword(rtlpriv, reg_addr, data);
+}
+
+static void halbtc_write_local_reg_1byte(void *btc_context, u32 reg_addr,
+ u8 data)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+
+ if (btcoexist->chip_interface == BTC_INTF_SDIO)
+ ;
+ else if (btcoexist->chip_interface == BTC_INTF_PCI)
+ rtl_write_byte(rtlpriv, reg_addr, data);
+ else if (btcoexist->chip_interface == BTC_INTF_USB)
+ rtl_write_byte(rtlpriv, reg_addr, data);
+}
+
+static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask,
+ u32 data)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+
+ rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
+}
+
+static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+
+ return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
+}
+
+static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
+ u32 bit_mask, u32 data)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+
+ rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
+}
+
+static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
+ u32 bit_mask)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+
+ return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
+}
+
+static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id,
+ u32 cmd_len, u8 *cmd_buf)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+
+ rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id,
+ cmd_len, cmd_buf);
+}
+
+static void halbtc_send_wifi_port_id_cmd(void *bt_context)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+ u8 cmd_buf[1] = {0}; /* port id [2:0] = 0 */
+
+ rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x71, 1,
+ cmd_buf);
+}
+
+static void halbtc_set_default_port_id_cmd(void *bt_context)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+ struct ieee80211_hw *hw = rtlpriv->mac80211.hw;
+
+ if (!rtlpriv->cfg->ops->set_default_port_id_cmd)
+ return;
+
+ rtlpriv->cfg->ops->set_default_port_id_cmd(hw);
+}
+
+static
+void halbtc_set_bt_reg(void *btc_context, u8 reg_type, u32 offset, u32 set_val)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
+ u8 cmd_buffer1[4] = {0};
+ u8 cmd_buffer2[4] = {0};
+
+ /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
+ *((__le16 *)&cmd_buffer1[2]) = cpu_to_le16((u16)set_val);
+ if (!halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_VALUE,
+ cmd_buffer1, 4, 200))
+ return;
+
+ /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
+ cmd_buffer2[2] = reg_type;
+ *((u8 *)&cmd_buffer2[3]) = (u8)offset;
+ halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_ADDR,
+ cmd_buffer2, 4, 200);
+}
+
+static void halbtc_display_dbg_msg(void *bt_context, u8 disp_type,
+ struct seq_file *m)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
+
+ switch (disp_type) {
+ case BTC_DBG_DISP_COEX_STATISTICS:
+ halbtc_display_coex_statistics(btcoexist, m);
+ break;
+ case BTC_DBG_DISP_BT_LINK_INFO:
+ halbtc_display_bt_link_info(btcoexist, m);
+ break;
+ case BTC_DBG_DISP_WIFI_STATUS:
+ halbtc_display_wifi_status(btcoexist, m);
+ break;
+ default:
+ break;
+ }
+}
+
+static u32 halbtc_get_bt_reg(void *btc_context, u8 reg_type, u32 offset)
+{
+ return 0;
+}
+
+static bool halbtc_under_ips(struct btc_coexist *btcoexist)
+{
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+ struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
+ enum rf_pwrstate rtstate;
+
+ if (ppsc->inactiveps) {
+ rtstate = ppsc->rfpwr_state;
+
+ if (rtstate != ERFON &&
+ ppsc->rfoff_reason == RF_CHANGE_BY_IPS) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static
+u32 halbtc_get_phydm_version(void *btc_context)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+
+ if (rtlpriv->phydm.ops)
+ return rtlpriv->phydm.ops->phydm_get_version(rtlpriv);
+
+ return 0;
+}
+
+static
+void halbtc_phydm_modify_ra_pcr_threshold(void *btc_context,
+ u8 ra_offset_direction,
+ u8 ra_threshold_offset)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+ struct rtl_phydm_ops *phydm_ops = rtlpriv->phydm.ops;
+
+ if (phydm_ops)
+ phydm_ops->phydm_modify_ra_pcr_threshold(rtlpriv,
+ ra_offset_direction,
+ ra_threshold_offset);
+}
+
+static
+u32 halbtc_phydm_query_phy_counter(void *btc_context, const char *info_type)
+{
+ /* info_type may be strings below:
+ * PHYDM_INFO_FA_OFDM, PHYDM_INFO_FA_CCK, PHYDM_INFO_CCA_OFDM,
+ * PHYDM_INFO_CCA_CCK
+ * IQK_TOTAL, IQK_OK, IQK_FAIL
+ */
+
+ struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+ struct rtl_phydm_ops *phydm_ops = rtlpriv->phydm.ops;
+
+ if (phydm_ops)
+ return phydm_ops->phydm_query_counter(rtlpriv, info_type);
+
+ return 0;
+}
+
+static u8 halbtc_get_ant_det_val_from_bt(void *btc_context)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
+ u8 cmd_buffer[4] = {0};
+
+ /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
+ halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_ANT_DET_VAL,
+ cmd_buffer, 4, 200);
+
+ /* need wait completion to return correct value */
+
+ return btcoexist->bt_info.bt_ant_det_val;
+}
+
+static u8 halbtc_get_ble_scan_type_from_bt(void *btc_context)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
+ u8 cmd_buffer[4] = {0};
+
+ /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
+ halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_TYPE,
+ cmd_buffer, 4, 200);
+
+ /* need wait completion to return correct value */
+
+ return btcoexist->bt_info.bt_ble_scan_type;
+}
+
+static u32 halbtc_get_ble_scan_para_from_bt(void *btc_context, u8 scan_type)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
+ u8 cmd_buffer[4] = {0};
+
+ /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
+ halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_PARA,
+ cmd_buffer, 4, 200);
+
+ /* need wait completion to return correct value */
+
+ return btcoexist->bt_info.bt_ble_scan_para;
+}
+
+static bool halbtc_get_bt_afh_map_from_bt(void *btc_context, u8 map_type,
+ u8 *afh_map)
+{
+ struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
+ u8 cmd_buffer[2] = {0};
+ bool ret;
+ u32 *afh_map_l = (u32 *)afh_map;
+ u32 *afh_map_m = (u32 *)(afh_map + 4);
+ u16 *afh_map_h = (u16 *)(afh_map + 8);
+
+ /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
+ ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_L,
+ cmd_buffer, 2, 200);
+ if (!ret)
+ goto exit;
+
+ *afh_map_l = btcoexist->bt_info.afh_map_l;
+
+ /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
+ ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_M,
+ cmd_buffer, 2, 200);
+ if (!ret)
+ goto exit;
+
+ *afh_map_m = btcoexist->bt_info.afh_map_m;
+
+ /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
+ ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_H,
+ cmd_buffer, 2, 200);
+ if (!ret)
+ goto exit;
+
+ *afh_map_h = btcoexist->bt_info.afh_map_h;
+
+exit:
+ return ret;
+}
+
+/*****************************************************************
+ * Extern functions called by other module
+ *****************************************************************/
+bool exhalbtc_initlize_variables(struct rtl_priv *rtlpriv)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return false;
+
+ halbtc_dbg_init();
+
+ btcoexist->btc_read_1byte = halbtc_read_1byte;
+ btcoexist->btc_write_1byte = halbtc_write_1byte;
+ btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte;
+ btcoexist->btc_read_2byte = halbtc_read_2byte;
+ btcoexist->btc_write_2byte = halbtc_write_2byte;
+ btcoexist->btc_read_4byte = halbtc_read_4byte;
+ btcoexist->btc_write_4byte = halbtc_write_4byte;
+ btcoexist->btc_write_local_reg_1byte = halbtc_write_local_reg_1byte;
+
+ btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
+ btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
+
+ btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
+ btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
+
+ btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
+ btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg;
+
+ btcoexist->btc_get = halbtc_get;
+ btcoexist->btc_set = halbtc_set;
+ btcoexist->btc_set_bt_reg = halbtc_set_bt_reg;
+ btcoexist->btc_get_bt_reg = halbtc_get_bt_reg;
+
+ btcoexist->bt_info.bt_ctrl_buf_size = false;
+ btcoexist->bt_info.agg_buf_size = 5;
+
+ btcoexist->bt_info.increase_scan_dev_num = false;
+
+ btcoexist->btc_get_bt_coex_supported_feature =
+ halbtc_get_bt_coex_supported_feature;
+ btcoexist->btc_get_bt_coex_supported_version =
+ halbtc_get_bt_coex_supported_version;
+ btcoexist->btc_get_bt_phydm_version = halbtc_get_phydm_version;
+ btcoexist->btc_phydm_modify_ra_pcr_threshold =
+ halbtc_phydm_modify_ra_pcr_threshold;
+ btcoexist->btc_phydm_query_phy_counter = halbtc_phydm_query_phy_counter;
+ btcoexist->btc_get_ant_det_val_from_bt = halbtc_get_ant_det_val_from_bt;
+ btcoexist->btc_get_ble_scan_type_from_bt =
+ halbtc_get_ble_scan_type_from_bt;
+ btcoexist->btc_get_ble_scan_para_from_bt =
+ halbtc_get_ble_scan_para_from_bt;
+ btcoexist->btc_get_bt_afh_map_from_bt =
+ halbtc_get_bt_afh_map_from_bt;
+
+ init_completion(&btcoexist->bt_mp_comp);
+
+ return true;
+}
+
+bool exhalbtc_initlize_variables_wifi_only(struct rtl_priv *rtlpriv)
+{
+ struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv);
+ struct wifi_only_haldata *wifionly_haldata;
+
+ if (!wifionly_cfg)
+ return false;
+
+ wifionly_cfg->adapter = rtlpriv;
+
+ switch (rtlpriv->rtlhal.interface) {
+ case INTF_PCI:
+ wifionly_cfg->chip_interface = BTC_INTF_PCI;
+ break;
+ case INTF_USB:
+ wifionly_cfg->chip_interface = BTC_INTF_USB;
+ break;
+ default:
+ wifionly_cfg->chip_interface = BTC_INTF_UNKNOWN;
+ break;
+ }
+
+ wifionly_haldata = &wifionly_cfg->haldata_info;
+
+ wifionly_haldata->customer_id = CUSTOMER_NORMAL;
+ wifionly_haldata->efuse_pg_antnum = rtl_get_hwpg_ant_num(rtlpriv);
+ wifionly_haldata->efuse_pg_antpath =
+ rtl_get_hwpg_single_ant_path(rtlpriv);
+ wifionly_haldata->rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
+ wifionly_haldata->ant_div_cfg = 0;
+
+ return true;
+}
+
+bool exhalbtc_bind_bt_coex_withadapter(void *adapter)
+{
+ struct rtl_priv *rtlpriv = adapter;
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+ u8 ant_num = 2, chip_type, single_ant_path = 0;
+
+ if (!btcoexist)
+ return false;
+
+ if (btcoexist->binded)
+ return false;
+
+ switch (rtlpriv->rtlhal.interface) {
+ case INTF_PCI:
+ btcoexist->chip_interface = BTC_INTF_PCI;
+ break;
+ case INTF_USB:
+ btcoexist->chip_interface = BTC_INTF_USB;
+ break;
+ default:
+ btcoexist->chip_interface = BTC_INTF_UNKNOWN;
+ break;
+ }
+
+ btcoexist->binded = true;
+ btcoexist->statistics.cnt_bind++;
+
+ btcoexist->adapter = adapter;
+
+ btcoexist->stack_info.profile_notified = false;
+
+ btcoexist->bt_info.bt_ctrl_agg_buf_size = false;
+ btcoexist->bt_info.agg_buf_size = 5;
+
+ btcoexist->bt_info.increase_scan_dev_num = false;
+ btcoexist->bt_info.miracast_plus_bt = false;
+
+ chip_type = rtl_get_hwpg_bt_type(rtlpriv);
+ exhalbtc_set_chip_type(btcoexist, chip_type);
+ ant_num = rtl_get_hwpg_ant_num(rtlpriv);
+ exhalbtc_set_ant_num(rtlpriv, BT_COEX_ANT_TYPE_PG, ant_num);
+
+ /* set default antenna position to main port */
+ btcoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
+
+ single_ant_path = rtl_get_hwpg_single_ant_path(rtlpriv);
+ exhalbtc_set_single_ant_path(btcoexist, single_ant_path);
+
+ if (rtl_get_hwpg_package_type(rtlpriv) == 0)
+ btcoexist->board_info.tfbga_package = false;
+ else if (rtl_get_hwpg_package_type(rtlpriv) == 1)
+ btcoexist->board_info.tfbga_package = false;
+ else
+ btcoexist->board_info.tfbga_package = true;
+
+ if (btcoexist->board_info.tfbga_package)
+ RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
+ "[BTCoex], Package Type = TFBGA\n");
+ else
+ RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
+ "[BTCoex], Package Type = Non-TFBGA\n");
+
+ btcoexist->board_info.rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
+ btcoexist->board_info.ant_div_cfg = 0;
+
+ return true;
+}
+
+void exhalbtc_power_on_setting(struct btc_coexist *btcoexist)
+{
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+
+ btcoexist->statistics.cnt_power_on++;
+
+ if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8723b2ant_power_on_setting(btcoexist);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8723b1ant_power_on_setting(btcoexist);
+ } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8822b1ant_power_on_setting(btcoexist);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8822b2ant_power_on_setting(btcoexist);
+ }
+}
+
+void exhalbtc_pre_load_firmware(struct btc_coexist *btcoexist)
+{
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+
+ btcoexist->statistics.cnt_pre_load_firmware++;
+
+ if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8723b2ant_pre_load_firmware(btcoexist);
+ } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8822b1ant_pre_load_firmware(btcoexist);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8822b2ant_pre_load_firmware(btcoexist);
+ }
+}
+
+void exhalbtc_init_hw_config(struct btc_coexist *btcoexist, bool wifi_only)
+{
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+
+ btcoexist->statistics.cnt_init_hw_config++;
+
+ if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8821a2ant_init_hwconfig(btcoexist);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8821a1ant_init_hwconfig(btcoexist, wifi_only);
+ } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8723b2ant_init_hwconfig(btcoexist);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8723b1ant_init_hwconfig(btcoexist, wifi_only);
+ } else if (IS_HARDWARE_TYPE_8723A(btcoexist->adapter)) {
+ /* 8723A has no this function */
+ } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8192e2ant_init_hwconfig(btcoexist);
+ } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8822b1ant_init_hw_config(btcoexist, wifi_only);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8822b2ant_init_hw_config(btcoexist, wifi_only);
+
+ halbtc_set_default_port_id_cmd(btcoexist);
+ halbtc_send_wifi_port_id_cmd(btcoexist);
+ }
+}
+
+void exhalbtc_init_hw_config_wifi_only(struct wifi_only_cfg *wifionly_cfg)
+{
+ if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
+ ex_hal8822b_wifi_only_hw_config(wifionly_cfg);
+}
+
+void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
+{
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+
+ btcoexist->statistics.cnt_init_coex_dm++;
+
+ if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8821a2ant_init_coex_dm(btcoexist);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8821a1ant_init_coex_dm(btcoexist);
+ } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8723b2ant_init_coex_dm(btcoexist);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8723b1ant_init_coex_dm(btcoexist);
+ } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8192e2ant_init_coex_dm(btcoexist);
+ } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8822b1ant_init_coex_dm(btcoexist);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8822b2ant_init_coex_dm(btcoexist);
+ }
+
+ btcoexist->initilized = true;
+}
+
+void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
+{
+ u8 ips_type;
+
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+ btcoexist->statistics.cnt_ips_notify++;
+ if (btcoexist->manual_control)
+ return;
+
+ if (type == ERFOFF)
+ ips_type = BTC_IPS_ENTER;
+ else
+ ips_type = BTC_IPS_LEAVE;
+
+ halbtc_leave_low_power(btcoexist);
+
+ if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8821a2ant_ips_notify(btcoexist, ips_type);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8821a1ant_ips_notify(btcoexist, ips_type);
+ } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8723b2ant_ips_notify(btcoexist, ips_type);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8723b1ant_ips_notify(btcoexist, ips_type);
+ } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8192e2ant_ips_notify(btcoexist, ips_type);
+ } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8822b1ant_ips_notify(btcoexist, ips_type);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8822b2ant_ips_notify(btcoexist, ips_type);
+ }
+
+ halbtc_normal_low_power(btcoexist);
+}
+
+void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
+{
+ u8 lps_type;
+
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+ btcoexist->statistics.cnt_lps_notify++;
+ if (btcoexist->manual_control)
+ return;
+
+ if (type == EACTIVE)
+ lps_type = BTC_LPS_DISABLE;
+ else
+ lps_type = BTC_LPS_ENABLE;
+
+ if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8821a2ant_lps_notify(btcoexist, lps_type);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8821a1ant_lps_notify(btcoexist, lps_type);
+ } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8723b2ant_lps_notify(btcoexist, lps_type);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8723b1ant_lps_notify(btcoexist, lps_type);
+ } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8192e2ant_lps_notify(btcoexist, lps_type);
+ } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8822b1ant_lps_notify(btcoexist, lps_type);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8822b2ant_lps_notify(btcoexist, lps_type);
+ }
+}
+
+void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
+{
+ u8 scan_type;
+
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+ btcoexist->statistics.cnt_scan_notify++;
+ if (btcoexist->manual_control)
+ return;
+
+ if (type)
+ scan_type = BTC_SCAN_START;
+ else
+ scan_type = BTC_SCAN_FINISH;
+
+ halbtc_leave_low_power(btcoexist);
+
+ if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8821a2ant_scan_notify(btcoexist, scan_type);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8821a1ant_scan_notify(btcoexist, scan_type);
+ } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8723b2ant_scan_notify(btcoexist, scan_type);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8723b1ant_scan_notify(btcoexist, scan_type);
+ } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8192e2ant_scan_notify(btcoexist, scan_type);
+ } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8822b1ant_scan_notify(btcoexist, scan_type);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8822b2ant_scan_notify(btcoexist, scan_type);
+ }
+
+ halbtc_normal_low_power(btcoexist);
+}
+
+void exhalbtc_scan_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
+ u8 is_5g)
+{
+ if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
+ ex_hal8822b_wifi_only_scannotify(wifionly_cfg, is_5g);
+}
+
+void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
+{
+ u8 asso_type;
+
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+ btcoexist->statistics.cnt_connect_notify++;
+ if (btcoexist->manual_control)
+ return;
+
+ if (action)
+ asso_type = BTC_ASSOCIATE_START;
+ else
+ asso_type = BTC_ASSOCIATE_FINISH;
+
+ halbtc_leave_low_power(btcoexist);
+
+ if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8821a2ant_connect_notify(btcoexist, asso_type);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8821a1ant_connect_notify(btcoexist, asso_type);
+ } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8723b2ant_connect_notify(btcoexist, asso_type);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8723b1ant_connect_notify(btcoexist, asso_type);
+ } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8192e2ant_connect_notify(btcoexist, asso_type);
+ } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8822b1ant_connect_notify(btcoexist, asso_type);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8822b2ant_connect_notify(btcoexist, asso_type);
+ }
+
+ halbtc_normal_low_power(btcoexist);
+}
+
+void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
+ enum rt_media_status media_status)
+{
+ u8 status;
+
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+ btcoexist->statistics.cnt_media_status_notify++;
+ if (btcoexist->manual_control)
+ return;
+
+ if (media_status == RT_MEDIA_CONNECT)
+ status = BTC_MEDIA_CONNECT;
+ else
+ status = BTC_MEDIA_DISCONNECT;
+
+ halbtc_leave_low_power(btcoexist);
+
+ if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8821a2ant_media_status_notify(btcoexist, status);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8821a1ant_media_status_notify(btcoexist, status);
+ } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8723b2ant_media_status_notify(btcoexist, status);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8723b1ant_media_status_notify(btcoexist, status);
+ } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8192e2ant_media_status_notify(btcoexist, status);
+ } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8822b1ant_media_status_notify(btcoexist, status);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8822b2ant_media_status_notify(btcoexist, status);
+ }
+
+ halbtc_normal_low_power(btcoexist);
+}
+
+void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
+{
+ u8 packet_type;
+
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+ btcoexist->statistics.cnt_special_packet_notify++;
+ if (btcoexist->manual_control)
+ return;
+
+ if (pkt_type == PACKET_DHCP) {
+ packet_type = BTC_PACKET_DHCP;
+ } else if (pkt_type == PACKET_EAPOL) {
+ packet_type = BTC_PACKET_EAPOL;
+ } else if (pkt_type == PACKET_ARP) {
+ packet_type = BTC_PACKET_ARP;
+ } else {
+ packet_type = BTC_PACKET_UNKNOWN;
+ return;
+ }
+
+ halbtc_leave_low_power(btcoexist);
+
+ if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8821a2ant_special_packet_notify(btcoexist,
+ packet_type);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8821a1ant_special_packet_notify(btcoexist,
+ packet_type);
+ } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8723b2ant_special_packet_notify(btcoexist,
+ packet_type);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8723b1ant_special_packet_notify(btcoexist,
+ packet_type);
+ } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8192e2ant_special_packet_notify(btcoexist,
+ packet_type);
+ } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8822b1ant_specific_packet_notify(btcoexist,
+ packet_type);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8822b2ant_specific_packet_notify(btcoexist,
+ packet_type);
+ }
+
+ halbtc_normal_low_power(btcoexist);
+}
+
+void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
+ u8 *tmp_buf, u8 length)
+{
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+ btcoexist->statistics.cnt_bt_info_notify++;
+
+ halbtc_leave_low_power(btcoexist);
+
+ if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8821a2ant_bt_info_notify(btcoexist, tmp_buf,
+ length);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8821a1ant_bt_info_notify(btcoexist, tmp_buf,
+ length);
+ } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8723b2ant_bt_info_notify(btcoexist, tmp_buf,
+ length);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8723b1ant_bt_info_notify(btcoexist, tmp_buf,
+ length);
+ } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8192e2ant_bt_info_notify(btcoexist, tmp_buf,
+ length);
+ } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8822b1ant_bt_info_notify(btcoexist, tmp_buf,
+ length);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8822b2ant_bt_info_notify(btcoexist, tmp_buf,
+ length);
+ }
+
+ halbtc_normal_low_power(btcoexist);
+}
+
+void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
+{
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+
+ if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
+ } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8723b1ant_rf_status_notify(btcoexist, type);
+ } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
+ } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8822b1ant_rf_status_notify(btcoexist, type);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8822b2ant_rf_status_notify(btcoexist, type);
+ }
+}
+
+void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type)
+{
+ u8 stack_op_type;
+
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+ btcoexist->statistics.cnt_stack_operation_notify++;
+ if (btcoexist->manual_control)
+ return;
+
+ if ((type == HCI_BT_OP_INQUIRY_START) ||
+ (type == HCI_BT_OP_PAGING_START) ||
+ (type == HCI_BT_OP_PAIRING_START)) {
+ stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_START;
+ } else if ((type == HCI_BT_OP_INQUIRY_FINISH) ||
+ (type == HCI_BT_OP_PAGING_SUCCESS) ||
+ (type == HCI_BT_OP_PAGING_UNSUCCESS) ||
+ (type == HCI_BT_OP_PAIRING_FINISH)) {
+ stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH;
+ } else {
+ stack_op_type = BTC_STACK_OP_NONE;
+ }
+}
+
+void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
+{
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+
+ if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8821a2ant_halt_notify(btcoexist);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8821a1ant_halt_notify(btcoexist);
+ } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8723b2ant_halt_notify(btcoexist);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8723b1ant_halt_notify(btcoexist);
+ } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8192e2ant_halt_notify(btcoexist);
+ } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8822b1ant_halt_notify(btcoexist);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8822b2ant_halt_notify(btcoexist);
+ }
+
+ btcoexist->binded = false;
+}
+
+void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
+{
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+
+ /* currently only 1ant we have to do the notification,
+ * once pnp is notified to sleep state, we have to leave LPS that
+ * we can sleep normally.
+ */
+
+ if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8723b1ant_pnp_notify(btcoexist, pnp_state);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8723b2ant_pnp_notify(btcoexist, pnp_state);
+ } else if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8821a1ant_pnp_notify(btcoexist, pnp_state);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8821a2ant_pnp_notify(btcoexist, pnp_state);
+ } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
+ } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8822b1ant_pnp_notify(btcoexist, pnp_state);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8822b2ant_pnp_notify(btcoexist, pnp_state);
+ }
+}
+
+void exhalbtc_coex_dm_switch(struct btc_coexist *btcoexist)
+{
+ struct rtl_priv *rtlpriv = btcoexist->adapter;
+
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+ btcoexist->statistics.cnt_coex_dm_switch++;
+
+ halbtc_leave_low_power(btcoexist);
+
+ if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1) {
+ btcoexist->stop_coex_dm = true;
+ ex_btc8723b1ant_coex_dm_reset(btcoexist);
+ exhalbtc_set_ant_num(rtlpriv,
+ BT_COEX_ANT_TYPE_DETECTED, 2);
+ ex_btc8723b2ant_init_hwconfig(btcoexist);
+ ex_btc8723b2ant_init_coex_dm(btcoexist);
+ btcoexist->stop_coex_dm = false;
+ }
+ }
+
+ halbtc_normal_low_power(btcoexist);
+}
+
+void exhalbtc_periodical(struct btc_coexist *btcoexist)
+{
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+ btcoexist->statistics.cnt_periodical++;
+
+ halbtc_leave_low_power(btcoexist);
+
+ if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8821a2ant_periodical(btcoexist);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ if (!halbtc_under_ips(btcoexist))
+ ex_btc8821a1ant_periodical(btcoexist);
+ } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8723b2ant_periodical(btcoexist);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8723b1ant_periodical(btcoexist);
+ } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8192e2ant_periodical(btcoexist);
+ } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8822b1ant_periodical(btcoexist);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8822b2ant_periodical(btcoexist);
+ }
+
+ halbtc_normal_low_power(btcoexist);
+}
+
+void exhalbtc_dbg_control(struct btc_coexist *btcoexist,
+ u8 code, u8 len, u8 *data)
+{
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+ btcoexist->statistics.cnt_dbg_ctrl++;
+
+ halbtc_leave_low_power(btcoexist);
+
+ halbtc_normal_low_power(btcoexist);
+}
+
+void exhalbtc_antenna_detection(struct btc_coexist *btcoexist, u32 cent_freq,
+ u32 offset, u32 span, u32 seconds)
+{
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+}
+
+void exhalbtc_stack_update_profile_info(void)
+{
+}
+
+void exhalbtc_update_min_bt_rssi(struct btc_coexist *btcoexist, s8 bt_rssi)
+{
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+
+ btcoexist->stack_info.min_bt_rssi = bt_rssi;
+}
+
+void exhalbtc_set_hci_version(struct btc_coexist *btcoexist, u16 hci_version)
+{
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+
+ btcoexist->stack_info.hci_version = hci_version;
+}
+
+void exhalbtc_set_bt_patch_version(struct btc_coexist *btcoexist,
+ u16 bt_hci_version, u16 bt_patch_version)
+{
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+
+ btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
+ btcoexist->bt_info.bt_hci_ver = bt_hci_version;
+}
+
+void exhalbtc_set_chip_type(struct btc_coexist *btcoexist, u8 chip_type)
+{
+ switch (chip_type) {
+ default:
+ case BT_2WIRE:
+ case BT_ISSC_3WIRE:
+ case BT_ACCEL:
+ case BT_RTL8756:
+ btcoexist->board_info.bt_chip_type = BTC_CHIP_UNDEF;
+ break;
+ case BT_CSR_BC4:
+ btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
+ break;
+ case BT_CSR_BC8:
+ btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
+ break;
+ case BT_RTL8723A:
+ btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723A;
+ break;
+ case BT_RTL8821A:
+ btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8821;
+ break;
+ case BT_RTL8723B:
+ btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723B;
+ break;
+ }
+}
+
+void exhalbtc_set_ant_num(struct rtl_priv *rtlpriv, u8 type, u8 ant_num)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return;
+
+ if (type == BT_COEX_ANT_TYPE_PG) {
+ btcoexist->board_info.pg_ant_num = ant_num;
+ btcoexist->board_info.btdm_ant_num = ant_num;
+ } else if (type == BT_COEX_ANT_TYPE_ANTDIV) {
+ btcoexist->board_info.btdm_ant_num = ant_num;
+ } else if (type == BT_COEX_ANT_TYPE_DETECTED) {
+ btcoexist->board_info.btdm_ant_num = ant_num;
+ if (rtlpriv->cfg->mod_params->ant_sel == 1)
+ btcoexist->board_info.btdm_ant_pos =
+ BTC_ANTENNA_AT_AUX_PORT;
+ else
+ btcoexist->board_info.btdm_ant_pos =
+ BTC_ANTENNA_AT_MAIN_PORT;
+ }
+}
+
+/* Currently used by 8723b only, S0 or S1 */
+void exhalbtc_set_single_ant_path(struct btc_coexist *btcoexist,
+ u8 single_ant_path)
+{
+ btcoexist->board_info.single_ant_path = single_ant_path;
+}
+
+void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist,
+ struct seq_file *m)
+{
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+
+ halbtc_leave_low_power(btcoexist);
+
+ if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8821a2ant_display_coex_info(btcoexist, m);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8821a1ant_display_coex_info(btcoexist, m);
+ } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8723b2ant_display_coex_info(btcoexist, m);
+ else if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8723b1ant_display_coex_info(btcoexist, m);
+ } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8192e2ant_display_coex_info(btcoexist, m);
+ } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8822b1ant_display_coex_info(btcoexist, m);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8822b2ant_display_coex_info(btcoexist, m);
+ }
+
+ halbtc_normal_low_power(btcoexist);
+}
+
+void exhalbtc_switch_band_notify(struct btc_coexist *btcoexist, u8 type)
+{
+ if (!halbtc_is_bt_coexist_available(btcoexist))
+ return;
+
+ if (btcoexist->manual_control)
+ return;
+
+ halbtc_leave_low_power(btcoexist);
+
+ if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+ if (btcoexist->board_info.btdm_ant_num == 1)
+ ex_btc8822b1ant_switchband_notify(btcoexist, type);
+ else if (btcoexist->board_info.btdm_ant_num == 2)
+ ex_btc8822b2ant_switchband_notify(btcoexist, type);
+ }
+
+ halbtc_normal_low_power(btcoexist);
+}
+
+void exhalbtc_switch_band_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
+ u8 is_5g)
+{
+ if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
+ ex_hal8822b_wifi_only_switchbandnotify(wifionly_cfg, is_5g);
+}
diff --git a/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.h b/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.h
new file mode 100644
index 000000000000..8913983b8ad8
--- /dev/null
+++ b/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.h
@@ -0,0 +1,802 @@
+/******************************************************************************
+ *
+ * Copyright(c) 2009-2012 Realtek Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * The full GNU General Public License is included in this distribution in the
+ * file called LICENSE.
+ *
+ * Contact Information:
+ * wlanfae <wlanfae@realtek.com>
+ * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
+ * Hsinchu 300, Taiwan.
+ *
+ * Larry Finger <Larry.Finger@lwfinger.net>
+ *
+ *****************************************************************************/
+#ifndef __HALBTC_OUT_SRC_H__
+#define __HALBTC_OUT_SRC_H__
+
+#include "../wifi.h"
+
+#define BTC_COEX_OFFLOAD 0
+
+#define NORMAL_EXEC false
+#define FORCE_EXEC true
+
+#define BTC_RF_OFF 0x0
+#define BTC_RF_ON 0x1
+
+#define BTC_RF_A RF90_PATH_A
+#define BTC_RF_B RF90_PATH_B
+#define BTC_RF_C RF90_PATH_C
+#define BTC_RF_D RF90_PATH_D
+
+#define BTC_SMSP SINGLEMAC_SINGLEPHY
+#define BTC_DMDP DUALMAC_DUALPHY
+#define BTC_DMSP DUALMAC_SINGLEPHY
+#define BTC_MP_UNKNOWN 0xff
+
+#define IN
+#define OUT
+
+#define BT_TMP_BUF_SIZE 100
+
+#define BT_COEX_ANT_TYPE_PG 0
+#define BT_COEX_ANT_TYPE_ANTDIV 1
+#define BT_COEX_ANT_TYPE_DETECTED 2
+
+#define BTC_MIMO_PS_STATIC 0
+#define BTC_MIMO_PS_DYNAMIC 1
+
+#define BTC_RATE_DISABLE 0
+#define BTC_RATE_ENABLE 1
+
+/* single Antenna definition */
+#define BTC_ANT_PATH_WIFI 0
+#define BTC_ANT_PATH_BT 1
+#define BTC_ANT_PATH_PTA 2
+#define BTC_ANT_PATH_WIFI5G 3
+#define BTC_ANT_PATH_AUTO 4
+/* dual Antenna definition */
+#define BTC_ANT_WIFI_AT_MAIN 0
+#define BTC_ANT_WIFI_AT_AUX 1
+#define BTC_ANT_WIFI_AT_DIVERSITY 2
+/* coupler Antenna definition */
+#define BTC_ANT_WIFI_AT_CPL_MAIN 0
+#define BTC_ANT_WIFI_AT_CPL_AUX 1
+
+enum btc_bt_reg_type {
+ BTC_BT_REG_RF = 0,
+ BTC_BT_REG_MODEM = 1,
+ BTC_BT_REG_BLUEWIZE = 2,
+ BTC_BT_REG_VENDOR = 3,
+ BTC_BT_REG_LE = 4,
+ BTC_BT_REG_MAX
+};
+
+enum btc_chip_interface {
+ BTC_INTF_UNKNOWN = 0,
+ BTC_INTF_PCI = 1,
+ BTC_INTF_USB = 2,
+ BTC_INTF_SDIO = 3,
+ BTC_INTF_GSPI = 4,
+ BTC_INTF_MAX
+};
+
+enum btc_chip_type {
+ BTC_CHIP_UNDEF = 0,
+ BTC_CHIP_CSR_BC4 = 1,
+ BTC_CHIP_CSR_BC8 = 2,
+ BTC_CHIP_RTL8723A = 3,
+ BTC_CHIP_RTL8821 = 4,
+ BTC_CHIP_RTL8723B = 5,
+ BTC_CHIP_MAX
+};
+
+enum btc_msg_type {
+ BTC_MSG_INTERFACE = 0x0,
+ BTC_MSG_ALGORITHM = 0x1,
+ BTC_MSG_MAX
+};
+
+/* following is for BTC_MSG_INTERFACE */
+#define INTF_INIT BIT0
+#define INTF_NOTIFY BIT2
+
+/* following is for BTC_ALGORITHM */
+#define ALGO_BT_RSSI_STATE BIT0
+#define ALGO_WIFI_RSSI_STATE BIT1
+#define ALGO_BT_MONITOR BIT2
+#define ALGO_TRACE BIT3
+#define ALGO_TRACE_FW BIT4
+#define ALGO_TRACE_FW_DETAIL BIT5
+#define ALGO_TRACE_FW_EXEC BIT6
+#define ALGO_TRACE_SW BIT7
+#define ALGO_TRACE_SW_DETAIL BIT8
+#define ALGO_TRACE_SW_EXEC BIT9
+
+/* following is for wifi link status */
+#define WIFI_STA_CONNECTED BIT0
+#define WIFI_AP_CONNECTED BIT1
+#define WIFI_HS_CONNECTED BIT2
+#define WIFI_P2P_GO_CONNECTED BIT3
+#define WIFI_P2P_GC_CONNECTED BIT4
+
+#define BTC_RSSI_HIGH(_rssi_) \
+ ((_rssi_ == BTC_RSSI_STATE_HIGH || \
+ _rssi_ == BTC_RSSI_STATE_STAY_HIGH) ? true : false)
+#define BTC_RSSI_MEDIUM(_rssi_) \
+ ((_rssi_ == BTC_RSSI_STATE_MEDIUM || \
+ _rssi_ == BTC_RSSI_STATE_STAY_MEDIUM) ? true : false)
+#define BTC_RSSI_LOW(_rssi_) \
+ ((_rssi_ == BTC_RSSI_STATE_LOW || \
+ _rssi_ == BTC_RSSI_STATE_STAY_LOW) ? true : false)
+
+enum btc_power_save_type {
+ BTC_PS_WIFI_NATIVE = 0,
+ BTC_PS_LPS_ON = 1,
+ BTC_PS_LPS_OFF = 2,
+ BTC_PS_LPS_MAX
+};
+
+struct btc_board_info {
+ /* The following is some board information */
+ u8 bt_chip_type;
+ u8 pg_ant_num; /* pg ant number */
+ u8 btdm_ant_num; /* ant number for btdm */
+ u8 btdm_ant_num_by_ant_det;
+ u8 btdm_ant_pos;
+ u8 single_ant_path; /* current used for 8723b only, 1=>s0, 0=>s1 */
+ bool tfbga_package;
+ bool btdm_ant_det_finish;
+
+ u8 rfe_type;
+ u8 ant_div_cfg;
+};
+
+enum btc_dbg_opcode {
+ BTC_DBG_SET_COEX_NORMAL = 0x0,
+ BTC_DBG_SET_COEX_WIFI_ONLY = 0x1,
+ BTC_DBG_SET_COEX_BT_ONLY = 0x2,
+ BTC_DBG_MAX
+};
+
+enum btc_rssi_state {
+ BTC_RSSI_STATE_HIGH = 0x0,
+ BTC_RSSI_STATE_MEDIUM = 0x1,
+ BTC_RSSI_STATE_LOW = 0x2,
+ BTC_RSSI_STATE_STAY_HIGH = 0x3,
+ BTC_RSSI_STATE_STAY_MEDIUM = 0x4,
+ BTC_RSSI_STATE_STAY_LOW = 0x5,
+ BTC_RSSI_MAX
+};
+
+enum btc_wifi_role {
+ BTC_ROLE_STATION = 0x0,
+ BTC_ROLE_AP = 0x1,
+ BTC_ROLE_IBSS = 0x2,
+ BTC_ROLE_HS_MODE = 0x3,
+ BTC_ROLE_MAX
+};
+
+enum btc_wireless_freq {
+ BTC_FREQ_2_4G = 0x0,
+ BTC_FREQ_5G = 0x1,
+ BTC_FREQ_MAX
+};
+
+enum btc_wifi_bw_mode {
+ BTC_WIFI_BW_LEGACY = 0x0,
+ BTC_WIFI_BW_HT20 = 0x1,
+ BTC_WIFI_BW_HT40 = 0x2,
+ BTC_WIFI_BW_HT80 = 0x3,
+ BTC_WIFI_BW_MAX
+};
+
+enum btc_wifi_traffic_dir {
+ BTC_WIFI_TRAFFIC_TX = 0x0,
+ BTC_WIFI_TRAFFIC_RX = 0x1,
+ BTC_WIFI_TRAFFIC_MAX
+};
+
+enum btc_wifi_pnp {
+ BTC_WIFI_PNP_WAKE_UP = 0x0,
+ BTC_WIFI_PNP_SLEEP = 0x1,
+ BTC_WIFI_PNP_SLEEP_KEEP_ANT = 0x2,
+ BTC_WIFI_PNP_MAX
+};
+
+enum btc_iot_peer {
+ BTC_IOT_PEER_UNKNOWN = 0,
+ BTC_IOT_PEER_REALTEK = 1,
+ BTC_IOT_PEER_REALTEK_92SE = 2,
+ BTC_IOT_PEER_BROADCOM = 3,
+ BTC_IOT_PEER_RALINK = 4,
+ BTC_IOT_PEER_ATHEROS = 5,
+ BTC_IOT_PEER_CISCO = 6,
+ BTC_IOT_PEER_MERU = 7,
+ BTC_IOT_PEER_MARVELL = 8,
+ BTC_IOT_PEER_REALTEK_SOFTAP = 9,
+ BTC_IOT_PEER_SELF_SOFTAP = 10, /* Self is SoftAP */
+ BTC_IOT_PEER_AIRGO = 11,
+ BTC_IOT_PEER_REALTEK_JAGUAR_BCUTAP = 12,
+ BTC_IOT_PEER_REALTEK_JAGUAR_CCUTAP = 13,
+ BTC_IOT_PEER_MAX,
+};
+
+/* for 8723b-d cut large current issue */
+enum bt_wifi_coex_state {
+ BTC_WIFI_STAT_INIT,
+ BTC_WIFI_STAT_IQK,
+ BTC_WIFI_STAT_NORMAL_OFF,
+ BTC_WIFI_STAT_MP_OFF,
+ BTC_WIFI_STAT_NORMAL,
+ BTC_WIFI_STAT_ANT_DIV,
+ BTC_WIFI_STAT_MAX
+};
+
+enum bt_ant_type {
+ BTC_ANT_TYPE_0,
+ BTC_ANT_TYPE_1,
+ BTC_ANT_TYPE_2,
+ BTC_ANT_TYPE_3,
+ BTC_ANT_TYPE_4,
+ BTC_ANT_TYPE_MAX
+};
+
+enum btc_get_type {
+ /* type bool */
+ BTC_GET_BL_HS_OPERATION,
+ BTC_GET_BL_HS_CONNECTING,
+ BTC_GET_BL_WIFI_CONNECTED,
+ BTC_GET_BL_WIFI_BUSY,
+ BTC_GET_BL_WIFI_SCAN,
+ BTC_GET_BL_WIFI_LINK,
+ BTC_GET_BL_WIFI_DHCP,
+ BTC_GET_BL_WIFI_SOFTAP_IDLE,
+ BTC_GET_BL_WIFI_SOFTAP_LINKING,
+ BTC_GET_BL_WIFI_IN_EARLY_SUSPEND,
+ BTC_GET_BL_WIFI_ROAM,
+ BTC_GET_BL_WIFI_4_WAY_PROGRESS,
+ BTC_GET_BL_WIFI_UNDER_5G,
+ BTC_GET_BL_WIFI_AP_MODE_ENABLE,
+ BTC_GET_BL_WIFI_ENABLE_ENCRYPTION,
+ BTC_GET_BL_WIFI_UNDER_B_MODE,
+ BTC_GET_BL_EXT_SWITCH,
+ BTC_GET_BL_WIFI_IS_IN_MP_MODE,
+ BTC_GET_BL_IS_ASUS_8723B,
+ BTC_GET_BL_FW_READY,
+ BTC_GET_BL_RF4CE_CONNECTED,
+
+ /* type s4Byte */
+ BTC_GET_S4_WIFI_RSSI,
+ BTC_GET_S4_HS_RSSI,
+
+ /* type u32 */
+ BTC_GET_U4_WIFI_BW,
+ BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
+ BTC_GET_U4_WIFI_FW_VER,
+ BTC_GET_U4_WIFI_LINK_STATUS,
+ BTC_GET_U4_BT_PATCH_VER,
+ BTC_GET_U4_VENDOR,
+ BTC_GET_U4_SUPPORTED_VERSION,
+ BTC_GET_U4_SUPPORTED_FEATURE,
+ BTC_GET_U4_WIFI_IQK_TOTAL,
+ BTC_GET_U4_WIFI_IQK_OK,
+ BTC_GET_U4_WIFI_IQK_FAIL,
+
+ /* type u1Byte */
+ BTC_GET_U1_WIFI_DOT11_CHNL,
+ BTC_GET_U1_WIFI_CENTRAL_CHNL,
+ BTC_GET_U1_WIFI_HS_CHNL,
+ BTC_GET_U1_MAC_PHY_MODE,
+ BTC_GET_U1_AP_NUM,
+ BTC_GET_U1_ANT_TYPE,
+ BTC_GET_U1_IOT_PEER,
+
+ /* for 1Ant */
+ BTC_GET_U1_LPS_MODE,
+ BTC_GET_BL_BT_SCO_BUSY,
+
+ /* for test mode */
+ BTC_GET_DRIVER_TEST_CFG,
+ BTC_GET_MAX
+};
+
+enum btc_vendor {
+ BTC_VENDOR_LENOVO,
+ BTC_VENDOR_ASUS,
+ BTC_VENDOR_OTHER
+};
+
+enum btc_set_type {
+ /* type bool */
+ BTC_SET_BL_BT_DISABLE,
+ BTC_SET_BL_BT_ENABLE_DISABLE_CHANGE,
+ BTC_SET_BL_BT_TRAFFIC_BUSY,
+ BTC_SET_BL_BT_LIMITED_DIG,
+ BTC_SET_BL_FORCE_TO_ROAM,
+ BTC_SET_BL_TO_REJ_AP_AGG_PKT,
+ BTC_SET_BL_BT_CTRL_AGG_SIZE,
+ BTC_SET_BL_INC_SCAN_DEV_NUM,
+ BTC_SET_BL_BT_TX_RX_MASK,
+ BTC_SET_BL_MIRACAST_PLUS_BT,
+
+ /* type u1Byte */
+ BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON,
+ BTC_SET_UI_SCAN_SIG_COMPENSATION,
+ BTC_SET_U1_AGG_BUF_SIZE,
+
+ /* type trigger some action */
+ BTC_SET_ACT_GET_BT_RSSI,
+ BTC_SET_ACT_AGGREGATE_CTRL,
+ BTC_SET_ACT_ANTPOSREGRISTRY_CTRL,
+
+ /********* for 1Ant **********/
+ /* type bool */
+ BTC_SET_BL_BT_SCO_BUSY,
+ /* type u1Byte */
+ BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE,
+ BTC_SET_U1_LPS_VAL,
+ BTC_SET_U1_RPWM_VAL,
+ BTC_SET_U1_1ANT_LPS,
+ BTC_SET_U1_1ANT_RPWM,
+ /* type trigger some action */
+ BTC_SET_ACT_LEAVE_LPS,
+ BTC_SET_ACT_ENTER_LPS,
+ BTC_SET_ACT_NORMAL_LPS,
+ BTC_SET_ACT_INC_FORCE_EXEC_PWR_CMD_CNT,
+ BTC_SET_ACT_DISABLE_LOW_POWER,
+ BTC_SET_ACT_UPDATE_RAMASK,
+ BTC_SET_ACT_SEND_MIMO_PS,
+ /* BT Coex related */
+ BTC_SET_ACT_CTRL_BT_INFO,
+ BTC_SET_ACT_CTRL_BT_COEX,
+ BTC_SET_ACT_CTRL_8723B_ANT,
+ /***************************/
+ BTC_SET_MAX
+};
+
+enum btc_dbg_disp_type {
+ BTC_DBG_DISP_COEX_STATISTICS = 0x0,
+ BTC_DBG_DISP_BT_LINK_INFO = 0x1,
+ BTC_DBG_DISP_BT_FW_VER = 0x2,
+ BTC_DBG_DISP_FW_PWR_MODE_CMD = 0x3,
+ BTC_DBG_DISP_WIFI_STATUS = 0x04,
+ BTC_DBG_DISP_MAX
+};
+
+enum btc_notify_type_ips {
+ BTC_IPS_LEAVE = 0x0,
+ BTC_IPS_ENTER = 0x1,
+ BTC_IPS_MAX
+};
+
+enum btc_notify_type_lps {
+ BTC_LPS_DISABLE = 0x0,
+ BTC_LPS_ENABLE = 0x1,
+ BTC_LPS_MAX
+};
+
+enum btc_notify_type_scan {
+ BTC_SCAN_FINISH = 0x0,
+ BTC_SCAN_START = 0x1,
+ BTC_SCAN_START_2G = 0x2,
+ BTC_SCAN_MAX
+};
+
+enum btc_notify_type_switchband {
+ BTC_NOT_SWITCH = 0x0,
+ BTC_SWITCH_TO_24G = 0x1,
+ BTC_SWITCH_TO_5G = 0x2,
+ BTC_SWITCH_TO_24G_NOFORSCAN = 0x3,
+ BTC_SWITCH_MAX
+};
+
+enum btc_notify_type_associate {
+ BTC_ASSOCIATE_FINISH = 0x0,
+ BTC_ASSOCIATE_START = 0x1,
+ BTC_ASSOCIATE_5G_FINISH = 0x2,
+ BTC_ASSOCIATE_5G_START = 0x3,
+ BTC_ASSOCIATE_MAX
+};
+
+enum btc_notify_type_media_status {
+ BTC_MEDIA_DISCONNECT = 0x0,
+ BTC_MEDIA_CONNECT = 0x1,
+ BTC_MEDIA_MAX
+};
+
+enum btc_notify_type_special_packet {
+ BTC_PACKET_UNKNOWN = 0x0,
+ BTC_PACKET_DHCP = 0x1,
+ BTC_PACKET_ARP = 0x2,
+ BTC_PACKET_EAPOL = 0x3,
+ BTC_PACKET_MAX
+};
+
+enum hci_ext_bt_operation {
+ HCI_BT_OP_NONE = 0x0,
+ HCI_BT_OP_INQUIRY_START = 0x1,
+ HCI_BT_OP_INQUIRY_FINISH = 0x2,
+ HCI_BT_OP_PAGING_START = 0x3,
+ HCI_BT_OP_PAGING_SUCCESS = 0x4,
+ HCI_BT_OP_PAGING_UNSUCCESS = 0x5,
+ HCI_BT_OP_PAIRING_START = 0x6,
+ HCI_BT_OP_PAIRING_FINISH = 0x7,
+ HCI_BT_OP_BT_DEV_ENABLE = 0x8,
+ HCI_BT_OP_BT_DEV_DISABLE = 0x9,
+ HCI_BT_OP_MAX
+};
+
+enum btc_notify_type_stack_operation {
+ BTC_STACK_OP_NONE = 0x0,
+ BTC_STACK_OP_INQ_PAGE_PAIR_START = 0x1,
+ BTC_STACK_OP_INQ_PAGE_PAIR_FINISH = 0x2,
+ BTC_STACK_OP_MAX
+};
+
+typedef u8 (*bfp_btc_r1)(void *btc_context, u32 reg_addr);
+
+typedef u16 (*bfp_btc_r2)(void *btc_context, u32 reg_addr);
+
+typedef u32 (*bfp_btc_r4)(void *btc_context, u32 reg_addr);
+
+typedef void (*bfp_btc_w1)(void *btc_context, u32 reg_addr, u32 data);
+
+typedef void (*bfp_btc_w1_bit_mak)(void *btc_context, u32 reg_addr,
+ u32 bit_mask, u8 data1b);
+
+typedef void (*bfp_btc_w2)(void *btc_context, u32 reg_addr, u16 data);
+
+typedef void (*bfp_btc_w4)(void *btc_context, u32 reg_addr, u32 data);
+
+typedef void (*bfp_btc_local_reg_w1)(void *btc_context, u32 reg_addr, u8 data);
+typedef void (*bfp_btc_wr_1byte_bit_mask)(void *btc_context, u32 reg_addr,
+ u8 bit_mask, u8 data);
+
+typedef void (*bfp_btc_set_bb_reg)(void *btc_context, u32 reg_addr,
+ u32 bit_mask, u32 data);
+
+typedef u32 (*bfp_btc_get_bb_reg)(void *btc_context, u32 reg_addr,
+ u32 bit_mask);
+
+typedef void (*bfp_btc_set_rf_reg)(void *btc_context, u8 rf_path, u32 reg_addr,
+ u32 bit_mask, u32 data);
+
+typedef u32 (*bfp_btc_get_rf_reg)(void *btc_context, u8 rf_path,
+ u32 reg_addr, u32 bit_mask);
+
+typedef void (*bfp_btc_fill_h2c)(void *btc_context, u8 element_id,
+ u32 cmd_len, u8 *cmd_buffer);
+
+typedef bool (*bfp_btc_get)(void *btcoexist, u8 get_type, void *out_buf);
+
+typedef bool (*bfp_btc_set)(void *btcoexist, u8 set_type, void *in_buf);
+
+typedef u32 (*bfp_btc_get_bt_coex_supported_feature)(void *btcoexist);
+
+typedef u32 (*bfp_btc_get_bt_coex_supported_version)(void *btcoexist);
+
+typedef u32 (*bfp_btc_get_bt_phydm_version)(void *btcoexist);
+
+typedef void (*bfp_btc_phydm_modify_ra_pcr_threshold)(void *btcoexist,
+ u8 ra_offset_direction,
+ u8 ra_threshold_offset);
+
+typedef u32 (*bfp_btc_phydm_query_phy_counter)(void *btcoexist,
+ const char *info_type);
+
+typedef u8 (*bfp_btc_get_ant_det_val_from_bt)(void *btcoexist);
+
+typedef u8 (*bfp_btc_get_ble_scan_type_from_bt)(void *btcoexist);
+
+typedef u32 (*bfp_btc_get_ble_scan_para_from_bt)(void *btcoexist, u8 scan_type);
+
+typedef bool (*bfp_btc_get_bt_afh_map_from_bt)(void *btcoexist, u8 map_type,
+ u8 *afh_map);
+
+typedef void (*bfp_btc_set_bt_reg)(void *btc_context, u8 reg_type, u32 offset,
+ u32 value);
+typedef u32 (*bfp_btc_get_bt_reg)(void *btc_context, u8 reg_type, u32 offset);
+
+typedef void (*bfp_btc_disp_dbg_msg)(void *btcoexist, u8 disp_type,
+ struct seq_file *m);
+
+struct btc_bt_info {
+ bool bt_disabled;
+ u8 rssi_adjust_for_agc_table_on;
+ u8 rssi_adjust_for_1ant_coex_type;
+ bool pre_bt_ctrl_agg_buf_size;
+ bool bt_busy;
+ u8 pre_agg_buf_size;
+ u8 agg_buf_size;
+ bool limited_dig;
+ bool pre_reject_agg_pkt;
+ bool reject_agg_pkt;
+ bool bt_ctrl_buf_size;
+ bool increase_scan_dev_num;
+ bool miracast_plus_bt;
+ bool bt_ctrl_agg_buf_size;
+ bool bt_tx_rx_mask;
+ u16 bt_hci_ver;
+ u16 bt_real_fw_ver;
+ u8 bt_fw_ver;
+ u32 bt_get_fw_ver;
+
+ bool bt_disable_low_pwr;
+
+ /* the following is for 1Ant solution */
+ bool bt_ctrl_lps;
+ bool bt_pwr_save_mode;
+ bool bt_lps_on;
+ bool force_to_roam;
+ u8 force_exec_pwr_cmd_cnt;
+ u8 lps_val;
+ u8 rpwm_val;
+ u32 ra_mask;
+
+ u32 afh_map_l;
+ u32 afh_map_m;
+ u16 afh_map_h;
+ u32 bt_supported_feature;
+ u32 bt_supported_version;
+ u8 bt_ant_det_val;
+ u8 bt_ble_scan_type;
+ u32 bt_ble_scan_para;
+};
+
+struct btc_stack_info {
+ bool profile_notified;
+ u16 hci_version; /* stack hci version */
+ u8 num_of_link;
+ bool bt_link_exist;
+ bool sco_exist;
+ bool acl_exist;
+ bool a2dp_exist;
+ bool hid_exist;
+ u8 num_of_hid;
+ bool pan_exist;
+ bool unknown_acl_exist;
+ s8 min_bt_rssi;
+};
+
+struct btc_statistics {
+ u32 cnt_bind;
+ u32 cnt_init_hw_config;
+ u32 cnt_init_coex_dm;
+ u32 cnt_ips_notify;
+ u32 cnt_lps_notify;
+ u32 cnt_scan_notify;
+ u32 cnt_connect_notify;
+ u32 cnt_media_status_notify;
+ u32 cnt_special_packet_notify;
+ u32 cnt_bt_info_notify;
+ u32 cnt_periodical;
+ u32 cnt_coex_dm_switch;
+ u32 cnt_stack_operation_notify;
+ u32 cnt_dbg_ctrl;
+ u32 cnt_pre_load_firmware;
+ u32 cnt_power_on;
+};
+
+struct btc_bt_link_info {
+ bool bt_link_exist;
+ bool bt_hi_pri_link_exist;
+ bool sco_exist;
+ bool sco_only;
+ bool a2dp_exist;
+ bool a2dp_only;
+ bool hid_exist;
+ bool hid_only;
+ bool pan_exist;
+ bool pan_only;
+ bool slave_role;
+ bool acl_busy;
+};
+
+enum btc_antenna_pos {
+ BTC_ANTENNA_AT_MAIN_PORT = 0x1,
+ BTC_ANTENNA_AT_AUX_PORT = 0x2,
+};
+
+enum btc_mp_h2c_op_code {
+ BT_OP_GET_BT_VERSION = 0,
+ BT_OP_WRITE_REG_ADDR = 12,
+ BT_OP_WRITE_REG_VALUE = 13,
+ BT_OP_READ_REG = 17,
+ BT_OP_GET_AFH_MAP_L = 30,
+ BT_OP_GET_AFH_MAP_M = 31,
+ BT_OP_GET_AFH_MAP_H = 32,
+ BT_OP_GET_BT_COEX_SUPPORTED_FEATURE = 42,
+ BT_OP_GET_BT_COEX_SUPPORTED_VERSION = 43,
+ BT_OP_GET_BT_ANT_DET_VAL = 44,
+ BT_OP_GET_BT_BLE_SCAN_PARA = 45,
+ BT_OP_GET_BT_BLE_SCAN_TYPE = 46,
+ BT_OP_MAX
+};
+
+enum btc_mp_h2c_req_num {
+ /* 4 bits only */
+ BT_SEQ_DONT_CARE = 0,
+ BT_SEQ_GET_BT_VERSION = 0xE,
+ BT_SEQ_GET_AFH_MAP_L = 0x5,
+ BT_SEQ_GET_AFH_MAP_M = 0x6,
+ BT_SEQ_GET_AFH_MAP_H = 0x9,
+ BT_SEQ_GET_BT_COEX_SUPPORTED_FEATURE = 0x7,
+ BT_SEQ_GET_BT_COEX_SUPPORTED_VERSION = 0x8,
+ BT_SEQ_GET_BT_ANT_DET_VAL = 0x2,
+ BT_SEQ_GET_BT_BLE_SCAN_PARA = 0x3,
+ BT_SEQ_GET_BT_BLE_SCAN_TYPE = 0x4,
+};
+
+struct btc_coexist {
+ /* make sure only one adapter can bind the data context */
+ bool binded;
+ /* default adapter */
+ void *adapter;
+ struct btc_board_info board_info;
+ /* some bt info referenced by non-bt module */
+ struct btc_bt_info bt_info;
+ struct btc_stack_info stack_info;
+ enum btc_chip_interface chip_interface;
+ struct btc_bt_link_info bt_link_info;
+
+ /* boolean variables to replace BT_AUTO_REPORT_ONLY_XXXXY_ZANT
+ * configuration parameters
+ */
+ bool auto_report_1ant;
+ bool auto_report_2ant;
+ bool dbg_mode_1ant;
+ bool dbg_mode_2ant;
+ bool initilized;
+ bool stop_coex_dm;
+ bool manual_control;
+ struct btc_statistics statistics;
+ u8 pwr_mode_val[10];
+
+ struct completion bt_mp_comp;
+
+ /* function pointers - io related */
+ bfp_btc_r1 btc_read_1byte;
+ bfp_btc_w1 btc_write_1byte;
+ bfp_btc_w1_bit_mak btc_write_1byte_bitmask;
+ bfp_btc_r2 btc_read_2byte;
+ bfp_btc_w2 btc_write_2byte;
+ bfp_btc_r4 btc_read_4byte;
+ bfp_btc_w4 btc_write_4byte;
+ bfp_btc_local_reg_w1 btc_write_local_reg_1byte;
+
+ bfp_btc_set_bb_reg btc_set_bb_reg;
+ bfp_btc_get_bb_reg btc_get_bb_reg;
+
+ bfp_btc_set_rf_reg btc_set_rf_reg;
+ bfp_btc_get_rf_reg btc_get_rf_reg;
+
+ bfp_btc_fill_h2c btc_fill_h2c;
+
+ bfp_btc_disp_dbg_msg btc_disp_dbg_msg;
+
+ bfp_btc_get btc_get;
+ bfp_btc_set btc_set;
+
+ bfp_btc_set_bt_reg btc_set_bt_reg;
+ bfp_btc_get_bt_reg btc_get_bt_reg;
+
+ bfp_btc_get_bt_coex_supported_feature btc_get_bt_coex_supported_feature;
+ bfp_btc_get_bt_coex_supported_version btc_get_bt_coex_supported_version;
+ bfp_btc_get_bt_phydm_version btc_get_bt_phydm_version;
+ bfp_btc_phydm_modify_ra_pcr_threshold btc_phydm_modify_ra_pcr_threshold;
+ bfp_btc_phydm_query_phy_counter btc_phydm_query_phy_counter;
+ bfp_btc_get_ant_det_val_from_bt btc_get_ant_det_val_from_bt;
+ bfp_btc_get_ble_scan_type_from_bt btc_get_ble_scan_type_from_bt;
+ bfp_btc_get_ble_scan_para_from_bt btc_get_ble_scan_para_from_bt;
+ bfp_btc_get_bt_afh_map_from_bt btc_get_bt_afh_map_from_bt;
+
+};
+
+bool halbtc_is_wifi_uplink(struct rtl_priv *adapter);
+
+#define rtl_btc_coexist(rtlpriv) \
+ ((struct btc_coexist *)((rtlpriv)->btcoexist.btc_context))
+#define rtl_btc_wifi_only(rtlpriv) \
+ ((struct wifi_only_cfg *)((rtlpriv)->btcoexist.wifi_only_context))
+
+struct wifi_only_cfg;
+
+bool exhalbtc_initlize_variables(struct rtl_priv *rtlpriv);
+bool exhalbtc_initlize_variables_wifi_only(struct rtl_priv *rtlpriv);
+bool exhalbtc_bind_bt_coex_withadapter(void *adapter);
+void exhalbtc_power_on_setting(struct btc_coexist *btcoexist);
+void exhalbtc_pre_load_firmware(struct btc_coexist *btcoexist);
+void exhalbtc_init_hw_config(struct btc_coexist *btcoexist, bool wifi_only);
+void exhalbtc_init_hw_config_wifi_only(struct wifi_only_cfg *wifionly_cfg);
+void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist);
+void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type);
+void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type);
+void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type);
+void exhalbtc_scan_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
+ u8 is_5g);
+void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action);
+void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
+ enum rt_media_status media_status);
+void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type);
+void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist, u8 *tmp_buf,
+ u8 length);
+void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type);
+void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type);
+void exhalbtc_halt_notify(struct btc_coexist *btcoexist);
+void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state);
+void exhalbtc_coex_dm_switch(struct btc_coexist *btcoexist);
+void exhalbtc_periodical(struct btc_coexist *btcoexist);
+void exhalbtc_dbg_control(struct btc_coexist *btcoexist, u8 code, u8 len,
+ u8 *data);
+void exhalbtc_antenna_detection(struct btc_coexist *btcoexist, u32 cent_freq,
+ u32 offset, u32 span, u32 seconds);
+void exhalbtc_stack_update_profile_info(void);
+void exhalbtc_set_hci_version(struct btc_coexist *btcoexist, u16 hci_version);
+void exhalbtc_set_bt_patch_version(struct btc_coexist *btcoexist,
+ u16 bt_hci_version, u16 bt_patch_version);
+void exhalbtc_update_min_bt_rssi(struct btc_coexist *btcoexist, s8 bt_rssi);
+void exhalbtc_set_bt_exist(struct btc_coexist *btcoexist, bool bt_exist);
+void exhalbtc_set_chip_type(struct btc_coexist *btcoexist, u8 chip_type);
+void exhalbtc_set_ant_num(struct rtl_priv *rtlpriv, u8 type, u8 ant_num);
+void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist,
+ struct seq_file *m);
+void exhalbtc_switch_band_notify(struct btc_coexist *btcoexist, u8 type);
+void exhalbtc_switch_band_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
+ u8 is_5g);
+void exhalbtc_signal_compensation(struct btc_coexist *btcoexist,
+ u8 *rssi_wifi, u8 *rssi_bt);
+void exhalbtc_lps_leave(struct btc_coexist *btcoexist);
+void exhalbtc_low_wifi_traffic_notify(struct btc_coexist *btcoexist);
+void exhalbtc_set_single_ant_path(struct btc_coexist *btcoexist,
+ u8 single_ant_path);
+
+/* The following are used by wifi_only case */
+enum wifionly_chip_interface {
+ WIFIONLY_INTF_UNKNOWN = 0,
+ WIFIONLY_INTF_PCI = 1,
+ WIFIONLY_INTF_USB = 2,
+ WIFIONLY_INTF_SDIO = 3,
+ WIFIONLY_INTF_MAX
+};
+
+enum wifionly_customer_id {
+ CUSTOMER_NORMAL = 0,
+ CUSTOMER_HP_1 = 1,
+};
+
+struct wifi_only_haldata {
+ u16 customer_id;
+ u8 efuse_pg_antnum;
+ u8 efuse_pg_antpath;
+ u8 rfe_type;
+ u8 ant_div_cfg;
+};
+
+struct wifi_only_cfg {
+ void *adapter;
+ struct wifi_only_haldata haldata_info;
+ enum wifionly_chip_interface chip_interface;
+};
+
+static inline
+void halwifionly_phy_set_bb_reg(struct wifi_only_cfg *wifi_conly_cfg,
+ u32 regaddr, u32 bitmask, u32 data)
+{
+ struct rtl_priv *rtlpriv = (struct rtl_priv *)wifi_conly_cfg->adapter;
+
+ rtl_set_bbreg(rtlpriv->hw, regaddr, bitmask, data);
+}
+
+#endif
diff --git a/drivers/staging/rtlwifi/btcoexist/rtl_btc.c b/drivers/staging/rtlwifi/btcoexist/rtl_btc.c
new file mode 100644
index 000000000000..18a4f5b43b5a
--- /dev/null
+++ b/drivers/staging/rtlwifi/btcoexist/rtl_btc.c
@@ -0,0 +1,528 @@
+/******************************************************************************
+ *
+ * Copyright(c) 2009-2013 Realtek Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * The full GNU General Public License is included in this distribution in the
+ * file called LICENSE.
+ *
+ * Contact Information:
+ * wlanfae <wlanfae@realtek.com>
+ * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
+ * Hsinchu 300, Taiwan.
+ *
+ * Larry Finger <Larry.Finger@lwfinger.net>
+ *
+ *****************************************************************************/
+#include "../wifi.h"
+#include <linux/vmalloc.h>
+#include <linux/module.h>
+
+#include "rtl_btc.h"
+#include "halbt_precomp.h"
+
+static struct rtl_btc_ops rtl_btc_operation = {
+ .btc_init_variables = rtl_btc_init_variables,
+ .btc_init_variables_wifi_only = rtl_btc_init_variables_wifi_only,
+ .btc_deinit_variables = rtl_btc_deinit_variables,
+ .btc_init_hal_vars = rtl_btc_init_hal_vars,
+ .btc_power_on_setting = rtl_btc_power_on_setting,
+ .btc_init_hw_config = rtl_btc_init_hw_config,
+ .btc_init_hw_config_wifi_only = rtl_btc_init_hw_config_wifi_only,
+ .btc_ips_notify = rtl_btc_ips_notify,
+ .btc_lps_notify = rtl_btc_lps_notify,
+ .btc_scan_notify = rtl_btc_scan_notify,
+ .btc_scan_notify_wifi_only = rtl_btc_scan_notify_wifi_only,
+ .btc_connect_notify = rtl_btc_connect_notify,
+ .btc_mediastatus_notify = rtl_btc_mediastatus_notify,
+ .btc_periodical = rtl_btc_periodical,
+ .btc_halt_notify = rtl_btc_halt_notify,
+ .btc_btinfo_notify = rtl_btc_btinfo_notify,
+ .btc_btmpinfo_notify = rtl_btc_btmpinfo_notify,
+ .btc_is_limited_dig = rtl_btc_is_limited_dig,
+ .btc_is_disable_edca_turbo = rtl_btc_is_disable_edca_turbo,
+ .btc_is_bt_disabled = rtl_btc_is_bt_disabled,
+ .btc_special_packet_notify = rtl_btc_special_packet_notify,
+ .btc_switch_band_notify = rtl_btc_switch_band_notify,
+ .btc_switch_band_notify_wifi_only = rtl_btc_switch_band_notify_wifionly,
+ .btc_record_pwr_mode = rtl_btc_record_pwr_mode,
+ .btc_get_lps_val = rtl_btc_get_lps_val,
+ .btc_get_rpwm_val = rtl_btc_get_rpwm_val,
+ .btc_is_bt_ctrl_lps = rtl_btc_is_bt_ctrl_lps,
+ .btc_is_bt_lps_on = rtl_btc_is_bt_lps_on,
+ .btc_get_ampdu_cfg = rtl_btc_get_ampdu_cfg,
+ .btc_display_bt_coex_info = rtl_btc_display_bt_coex_info,
+};
+
+void rtl_btc_display_bt_coex_info(struct rtl_priv *rtlpriv, struct seq_file *m)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist) {
+ seq_puts(m, "btc_coexist context is NULL!\n");
+ return;
+ }
+
+ exhalbtc_display_bt_coex_info(btcoexist, m);
+}
+
+void rtl_btc_record_pwr_mode(struct rtl_priv *rtlpriv, u8 *buf, u8 len)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+ u8 safe_len;
+
+ if (!btcoexist)
+ return;
+
+ safe_len = sizeof(btcoexist->pwr_mode_val);
+
+ if (safe_len > len)
+ safe_len = len;
+
+ memcpy(btcoexist->pwr_mode_val, buf, safe_len);
+}
+
+u8 rtl_btc_get_lps_val(struct rtl_priv *rtlpriv)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return 0;
+
+ return btcoexist->bt_info.lps_val;
+}
+
+u8 rtl_btc_get_rpwm_val(struct rtl_priv *rtlpriv)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return 0;
+
+ return btcoexist->bt_info.rpwm_val;
+}
+
+bool rtl_btc_is_bt_ctrl_lps(struct rtl_priv *rtlpriv)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return false;
+
+ return btcoexist->bt_info.bt_ctrl_lps;
+}
+
+bool rtl_btc_is_bt_lps_on(struct rtl_priv *rtlpriv)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return false;
+
+ return btcoexist->bt_info.bt_lps_on;
+}
+
+void rtl_btc_get_ampdu_cfg(struct rtl_priv *rtlpriv, u8 *reject_agg,
+ u8 *ctrl_agg_size, u8 *agg_size)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist) {
+ *reject_agg = false;
+ *ctrl_agg_size = false;
+ return;
+ }
+
+ if (reject_agg)
+ *reject_agg = btcoexist->bt_info.reject_agg_pkt;
+ if (ctrl_agg_size)
+ *ctrl_agg_size = btcoexist->bt_info.bt_ctrl_agg_buf_size;
+ if (agg_size)
+ *agg_size = btcoexist->bt_info.agg_buf_size;
+}
+
+static void rtl_btc_alloc_variable(struct rtl_priv *rtlpriv, bool wifi_only)
+{
+ if (wifi_only)
+ rtlpriv->btcoexist.wifi_only_context =
+ kzalloc(sizeof(struct wifi_only_cfg), GFP_KERNEL);
+ else
+ rtlpriv->btcoexist.btc_context =
+ kzalloc(sizeof(struct btc_coexist), GFP_KERNEL);
+}
+
+static void rtl_btc_free_variable(struct rtl_priv *rtlpriv)
+{
+ kfree(rtlpriv->btcoexist.btc_context);
+ rtlpriv->btcoexist.btc_context = NULL;
+
+ kfree(rtlpriv->btcoexist.wifi_only_context);
+ rtlpriv->btcoexist.wifi_only_context = NULL;
+}
+
+void rtl_btc_init_variables(struct rtl_priv *rtlpriv)
+{
+ rtl_btc_alloc_variable(rtlpriv, false);
+
+ exhalbtc_initlize_variables(rtlpriv);
+ exhalbtc_bind_bt_coex_withadapter(rtlpriv);
+}
+
+void rtl_btc_init_variables_wifi_only(struct rtl_priv *rtlpriv)
+{
+ rtl_btc_alloc_variable(rtlpriv, true);
+
+ exhalbtc_initlize_variables_wifi_only(rtlpriv);
+}
+
+void rtl_btc_deinit_variables(struct rtl_priv *rtlpriv)
+{
+ rtl_btc_free_variable(rtlpriv);
+}
+
+void rtl_btc_init_hal_vars(struct rtl_priv *rtlpriv)
+{
+ /* move ant_num, bt_type and single_ant_path to
+ * exhalbtc_bind_bt_coex_withadapter()
+ */
+}
+
+void rtl_btc_power_on_setting(struct rtl_priv *rtlpriv)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return;
+
+ exhalbtc_power_on_setting(btcoexist);
+}
+
+void rtl_btc_init_hw_config(struct rtl_priv *rtlpriv)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ u8 bt_exist;
+
+ bt_exist = rtl_get_hwpg_bt_exist(rtlpriv);
+ RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
+ "%s, bt_exist is %d\n", __func__, bt_exist);
+
+ if (!btcoexist)
+ return;
+
+ exhalbtc_init_hw_config(btcoexist, !bt_exist);
+ exhalbtc_init_coex_dm(btcoexist);
+}
+
+void rtl_btc_init_hw_config_wifi_only(struct rtl_priv *rtlpriv)
+{
+ struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv);
+
+ if (!wifionly_cfg)
+ return;
+
+ exhalbtc_init_hw_config_wifi_only(wifionly_cfg);
+}
+
+void rtl_btc_ips_notify(struct rtl_priv *rtlpriv, u8 type)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return;
+
+ exhalbtc_ips_notify(btcoexist, type);
+
+ if (type == ERFON) {
+ /*
+ * In some situation, it doesn't scan after leaving IPS, and
+ * this will cause btcoex in wrong state.
+ */
+ exhalbtc_scan_notify(btcoexist, 1);
+ exhalbtc_scan_notify(btcoexist, 0);
+ }
+}
+
+void rtl_btc_lps_notify(struct rtl_priv *rtlpriv, u8 type)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return;
+
+ exhalbtc_lps_notify(btcoexist, type);
+}
+
+void rtl_btc_scan_notify(struct rtl_priv *rtlpriv, u8 scantype)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return;
+
+ exhalbtc_scan_notify(btcoexist, scantype);
+}
+
+void rtl_btc_scan_notify_wifi_only(struct rtl_priv *rtlpriv, u8 scantype)
+{
+ struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
+ struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv);
+ u8 is_5g = (rtlhal->current_bandtype == BAND_ON_5G);
+
+ if (!wifionly_cfg)
+ return;
+
+ exhalbtc_scan_notify_wifi_only(wifionly_cfg, is_5g);
+}
+
+void rtl_btc_connect_notify(struct rtl_priv *rtlpriv, u8 action)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return;
+
+ exhalbtc_connect_notify(btcoexist, action);
+}
+
+void rtl_btc_mediastatus_notify(struct rtl_priv *rtlpriv,
+ enum rt_media_status mstatus)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return;
+
+ exhalbtc_mediastatus_notify(btcoexist, mstatus);
+}
+
+void rtl_btc_periodical(struct rtl_priv *rtlpriv)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return;
+
+ /*rtl_bt_dm_monitor();*/
+ exhalbtc_periodical(btcoexist);
+}
+
+void rtl_btc_halt_notify(struct rtl_priv *rtlpriv)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return;
+
+ exhalbtc_halt_notify(btcoexist);
+}
+
+void rtl_btc_btinfo_notify(struct rtl_priv *rtlpriv, u8 *tmp_buf, u8 length)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return;
+
+ exhalbtc_bt_info_notify(btcoexist, tmp_buf, length);
+}
+
+void rtl_btc_btmpinfo_notify(struct rtl_priv *rtlpriv, u8 *tmp_buf, u8 length)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+ u8 extid, seq, len;
+ u16 bt_real_fw_ver;
+ u8 bt_fw_ver;
+ u8 *data;
+
+ if (!btcoexist)
+ return;
+
+ if ((length < 4) || (!tmp_buf))
+ return;
+
+ extid = tmp_buf[0];
+ /* not response from BT FW then exit*/
+ if (extid != 1) /* C2H_TRIG_BY_BT_FW = 1 */
+ return;
+
+ len = tmp_buf[1] >> 4;
+ seq = tmp_buf[2] >> 4;
+ data = &tmp_buf[3];
+
+ /* BT Firmware version response */
+ switch (seq) {
+ case BT_SEQ_GET_BT_VERSION:
+ bt_real_fw_ver = tmp_buf[3] | (tmp_buf[4] << 8);
+ bt_fw_ver = tmp_buf[5];
+
+ btcoexist->bt_info.bt_real_fw_ver = bt_real_fw_ver;
+ btcoexist->bt_info.bt_fw_ver = bt_fw_ver;
+ break;
+ case BT_SEQ_GET_AFH_MAP_L:
+ btcoexist->bt_info.afh_map_l = le32_to_cpu(*(__le32 *)data);
+ break;
+ case BT_SEQ_GET_AFH_MAP_M:
+ btcoexist->bt_info.afh_map_m = le32_to_cpu(*(__le32 *)data);
+ break;
+ case BT_SEQ_GET_AFH_MAP_H:
+ btcoexist->bt_info.afh_map_h = le16_to_cpu(*(__le16 *)data);
+ break;
+ case BT_SEQ_GET_BT_COEX_SUPPORTED_FEATURE:
+ btcoexist->bt_info.bt_supported_feature = tmp_buf[3] |
+ (tmp_buf[4] << 8);
+ break;
+ case BT_SEQ_GET_BT_COEX_SUPPORTED_VERSION:
+ btcoexist->bt_info.bt_supported_version = tmp_buf[3] |
+ (tmp_buf[4] << 8);
+ break;
+ case BT_SEQ_GET_BT_ANT_DET_VAL:
+ btcoexist->bt_info.bt_ant_det_val = tmp_buf[3];
+ break;
+ case BT_SEQ_GET_BT_BLE_SCAN_PARA:
+ btcoexist->bt_info.bt_ble_scan_para = tmp_buf[3] |
+ (tmp_buf[4] << 8) |
+ (tmp_buf[5] << 16) |
+ (tmp_buf[6] << 24);
+ break;
+ case BT_SEQ_GET_BT_BLE_SCAN_TYPE:
+ btcoexist->bt_info.bt_ble_scan_type = tmp_buf[3];
+ break;
+ }
+
+ RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
+ "btmpinfo complete req_num=%d\n", seq);
+
+ complete(&btcoexist->bt_mp_comp);
+}
+
+bool rtl_btc_is_limited_dig(struct rtl_priv *rtlpriv)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return false;
+
+ return btcoexist->bt_info.limited_dig;
+}
+
+bool rtl_btc_is_disable_edca_turbo(struct rtl_priv *rtlpriv)
+{
+ bool bt_change_edca = false;
+ u32 cur_edca_val;
+ u32 edca_bt_hs_uplink = 0x5ea42b, edca_bt_hs_downlink = 0x5ea42b;
+ u32 edca_hs;
+ u32 edca_addr = 0x504;
+
+ cur_edca_val = rtl_read_dword(rtlpriv, edca_addr);
+ if (halbtc_is_wifi_uplink(rtlpriv)) {
+ if (cur_edca_val != edca_bt_hs_uplink) {
+ edca_hs = edca_bt_hs_uplink;
+ bt_change_edca = true;
+ }
+ } else {
+ if (cur_edca_val != edca_bt_hs_downlink) {
+ edca_hs = edca_bt_hs_downlink;
+ bt_change_edca = true;
+ }
+ }
+
+ if (bt_change_edca)
+ rtl_write_dword(rtlpriv, edca_addr, edca_hs);
+
+ return true;
+}
+
+bool rtl_btc_is_bt_disabled(struct rtl_priv *rtlpriv)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return true;
+
+ /* It seems 'bt_disabled' is never be initialized or set. */
+ if (btcoexist->bt_info.bt_disabled)
+ return true;
+ else
+ return false;
+}
+
+void rtl_btc_special_packet_notify(struct rtl_priv *rtlpriv, u8 pkt_type)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+
+ if (!btcoexist)
+ return;
+
+ return exhalbtc_special_packet_notify(btcoexist, pkt_type);
+}
+
+void rtl_btc_switch_band_notify(struct rtl_priv *rtlpriv, u8 band_type,
+ bool scanning)
+{
+ struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
+ u8 type = BTC_NOT_SWITCH;
+
+ if (!btcoexist)
+ return;
+
+ switch (band_type) {
+ case BAND_ON_2_4G:
+ if (scanning)
+ type = BTC_SWITCH_TO_24G;
+ else
+ type = BTC_SWITCH_TO_24G_NOFORSCAN;
+ break;
+
+ case BAND_ON_5G:
+ type = BTC_SWITCH_TO_5G;
+ break;
+ }
+
+ if (type != BTC_NOT_SWITCH)
+ exhalbtc_switch_band_notify(btcoexist, type);
+}
+
+void rtl_btc_switch_band_notify_wifionly(struct rtl_priv *rtlpriv, u8 band_type,
+ bool scanning)
+{
+ struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv);
+ u8 is_5g = (band_type == BAND_ON_5G);
+
+ if (!wifionly_cfg)
+ return;
+
+ exhalbtc_switch_band_notify_wifi_only(wifionly_cfg, is_5g);
+}
+
+struct rtl_btc_ops *rtl_btc_get_ops_pointer(void)
+{
+ return &rtl_btc_operation;
+}
+
+enum rt_media_status mgnt_link_status_query(struct ieee80211_hw *hw)
+{
+ struct rtl_priv *rtlpriv = rtl_priv(hw);
+ struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
+ enum rt_media_status m_status = RT_MEDIA_DISCONNECT;
+
+ u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0;
+
+ if (bibss || rtlpriv->mac80211.link_state >= MAC80211_LINKED)
+ m_status = RT_MEDIA_CONNECT;
+
+ return m_status;
+}
+
+u8 rtl_get_hwpg_bt_exist(struct rtl_priv *rtlpriv)
+{
+ return rtlpriv->btcoexist.btc_info.btcoexist;
+}
diff --git a/drivers/staging/rtlwifi/btcoexist/rtl_btc.h b/drivers/staging/rtlwifi/btcoexist/rtl_btc.h
new file mode 100644
index 000000000000..8c996055de71
--- /dev/null
+++ b/drivers/staging/rtlwifi/btcoexist/rtl_btc.h
@@ -0,0 +1,75 @@
+/******************************************************************************
+ *
+ * Copyright(c) 2009-2010 Realtek Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * The full GNU General Public License is included in this distribution in the
+ * file called LICENSE.
+ *
+ * Contact Information:
+ * wlanfae <wlanfae@realtek.com>
+ * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
+ * Hsinchu 300, Taiwan.
+ * Larry Finger <Larry.Finger@lwfinger.net>
+ *
+ *****************************************************************************/
+
+#ifndef __RTL_BTC_H__
+#define __RTL_BTC_H__
+
+#include "halbt_precomp.h"
+
+void rtl_btc_init_variables(struct rtl_priv *rtlpriv);
+void rtl_btc_init_variables_wifi_only(struct rtl_priv *rtlpriv);
+void rtl_btc_deinit_variables(struct rtl_priv *rtlpriv);
+void rtl_btc_init_hal_vars(struct rtl_priv *rtlpriv);
+void rtl_btc_power_on_setting(struct rtl_priv *rtlpriv);
+void rtl_btc_init_hw_config(struct rtl_priv *rtlpriv);
+void rtl_btc_init_hw_config_wifi_only(struct rtl_priv *rtlpriv);
+void rtl_btc_ips_notify(struct rtl_priv *rtlpriv, u8 type);
+void rtl_btc_lps_notify(struct rtl_priv *rtlpriv, u8 type);
+void rtl_btc_scan_notify(struct rtl_priv *rtlpriv, u8 scantype);
+void rtl_btc_scan_notify_wifi_only(struct rtl_priv *rtlpriv, u8 scantype);
+void rtl_btc_connect_notify(struct rtl_priv *rtlpriv, u8 action);
+void rtl_btc_mediastatus_notify(struct rtl_priv *rtlpriv,
+ enum rt_media_status mstatus);
+void rtl_btc_periodical(struct rtl_priv *rtlpriv);
+void rtl_btc_halt_notify(struct rtl_priv *rtlpriv);
+void rtl_btc_btinfo_notify(struct rtl_priv *rtlpriv, u8 *tmpbuf, u8 length);
+void rtl_btc_btmpinfo_notify(struct rtl_priv *rtlpriv, u8 *tmp_buf, u8 length);
+bool rtl_btc_is_limited_dig(struct rtl_priv *rtlpriv);
+bool rtl_btc_is_disable_edca_turbo(struct rtl_priv *rtlpriv);
+bool rtl_btc_is_bt_disabled(struct rtl_priv *rtlpriv);
+void rtl_btc_special_packet_notify(struct rtl_priv *rtlpriv, u8 pkt_type);
+void rtl_btc_switch_band_notify(struct rtl_priv *rtlpriv, u8 band_type,
+ bool scanning);
+void rtl_btc_switch_band_notify_wifionly(struct rtl_priv *rtlpriv, u8 band_type,
+ bool scanning);
+void rtl_btc_display_bt_coex_info(struct rtl_priv *rtlpriv, struct seq_file *m);
+void rtl_btc_record_pwr_mode(struct rtl_priv *rtlpriv, u8 *buf, u8 len);
+u8 rtl_btc_get_lps_val(struct rtl_priv *rtlpriv);
+u8 rtl_btc_get_rpwm_val(struct rtl_priv *rtlpriv);
+bool rtl_btc_is_bt_ctrl_lps(struct rtl_priv *rtlpriv);
+bool rtl_btc_is_bt_lps_on(struct rtl_priv *rtlpriv);
+void rtl_btc_get_ampdu_cfg(struct rtl_priv *rtlpriv, u8 *reject_agg,
+ u8 *ctrl_agg_size, u8 *agg_size);
+
+struct rtl_btc_ops *rtl_btc_get_ops_pointer(void);
+
+u8 rtl_get_hwpg_bt_exist(struct rtl_priv *rtlpriv);
+u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv);
+u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv);
+u8 rtl_get_hwpg_single_ant_path(struct rtl_priv *rtlpriv);
+u8 rtl_get_hwpg_package_type(struct rtl_priv *rtlpriv);
+
+enum rt_media_status mgnt_link_status_query(struct ieee80211_hw *hw);
+
+#endif
--
2.12.3
^ permalink raw reply related
* [PATCH 0/8] staging: Add new driver for RTL8822BE
From: Larry Finger @ 2017-08-17 17:46 UTC (permalink / raw)
To: gregkh
Cc: devel, Ping-Ke Shih, Yan-Hsuan Chuang, netdev, Birming Chiu,
Shaofu, Steven Ting, Larry Finger
The RTL8822BE, an 802.11ac wireless network card, is now appearing in
new computers. Its driver is being placed in staging to reduce the time
that users of this new card will have access to in-kernel drivers.
Residence in staging should be relatively short as we soon plan to start
introducing the code into the main wireless tree in small pieces.
To minimize interference between the rtlwifi drivers in the wireless tree
and this new driver, the new one can only be built as a module. In
addition, all code is built into a single module.
Larry Finger
Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Cc: Ping-Ke Shih <pkshih@realtek.com>
Cc: Yan-Hsuan Chuang <yhchuang@realtek.com>
Cc: Birming Chiu <birming@realtek.com>
Cc: Shaofu <shaofu@realtek.com>
Cc: Steven Ting <steventing@realtek.com>
Larry Finger (8):
staging: r8822be: Add existing rtlwifi and rtl_pci parts for new
driver
staging: r8822be: Copy existing btcoexist code into staging
staging: r8822be: Add r8822be btcoexist routines to staging
staging: r8822be: Add code for halmac sub-driver
staging: r8822be: Add phydm mini driver
staging: r8822be: Add the driver code
staging: r8822be: Add Makefiles and Kconfig for new driver
staging: rtlwifi: Reviewers fixes
drivers/staging/Kconfig | 2 +
drivers/staging/Makefile | 1 +
drivers/staging/rtlwifi/Kconfig | 22 +
drivers/staging/rtlwifi/Makefile | 70 +
drivers/staging/rtlwifi/TODO | 11 +
drivers/staging/rtlwifi/base.c | 2826 ++++
drivers/staging/rtlwifi/base.h | 186 +
drivers/staging/rtlwifi/btcoexist/Makefile | 8 +
drivers/staging/rtlwifi/btcoexist/halbt_precomp.h | 85 +
.../staging/rtlwifi/btcoexist/halbtc8822b1ant.c | 5246 ++++++++
.../staging/rtlwifi/btcoexist/halbtc8822b1ant.h | 444 +
.../staging/rtlwifi/btcoexist/halbtc8822b2ant.c | 5225 ++++++++
.../staging/rtlwifi/btcoexist/halbtc8822b2ant.h | 498 +
.../rtlwifi/btcoexist/halbtc8822bwifionly.c | 65 +
.../rtlwifi/btcoexist/halbtc8822bwifionly.h | 35 +
drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c | 1881 +++
drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.h | 802 ++
drivers/staging/rtlwifi/btcoexist/rtl_btc.c | 528 +
drivers/staging/rtlwifi/btcoexist/rtl_btc.h | 75 +
drivers/staging/rtlwifi/cam.c | 326 +
drivers/staging/rtlwifi/cam.h | 50 +
drivers/staging/rtlwifi/core.c | 2046 +++
drivers/staging/rtlwifi/core.h | 86 +
drivers/staging/rtlwifi/debug.c | 592 +
drivers/staging/rtlwifi/debug.h | 234 +
drivers/staging/rtlwifi/efuse.c | 1342 ++
drivers/staging/rtlwifi/efuse.h | 120 +
drivers/staging/rtlwifi/halmac/halmac_2_platform.h | 52 +
.../halmac_88xx/halmac_8822b/halmac_8822b_cfg.h | 132 +
.../halmac_88xx/halmac_8822b/halmac_8822b_phy.c | 106 +
.../halmac_8822b/halmac_8822b_pwr_seq.c | 563 +
.../halmac_8822b/halmac_8822b_pwr_seq.h | 40 +
.../halmac_88xx/halmac_8822b/halmac_api_8822b.c | 343 +
.../halmac_88xx/halmac_8822b/halmac_api_8822b.h | 44 +
.../halmac_8822b/halmac_api_8822b_pcie.c | 323 +
.../halmac_8822b/halmac_api_8822b_pcie.h | 53 +
.../halmac_8822b/halmac_api_8822b_sdio.c | 184 +
.../halmac_8822b/halmac_api_8822b_sdio.h | 42 +
.../halmac_8822b/halmac_api_8822b_usb.c | 185 +
.../halmac_8822b/halmac_api_8822b_usb.h | 45 +
.../halmac_88xx/halmac_8822b/halmac_func_8822b.c | 414 +
.../halmac_88xx/halmac_8822b/halmac_func_8822b.h | 38 +
.../rtlwifi/halmac/halmac_88xx/halmac_88xx_cfg.h | 171 +
.../rtlwifi/halmac/halmac_88xx/halmac_api_88xx.c | 5980 +++++++++
.../rtlwifi/halmac/halmac_88xx/halmac_api_88xx.h | 396 +
.../halmac/halmac_88xx/halmac_api_88xx_pcie.c | 329 +
.../halmac/halmac_88xx/halmac_api_88xx_pcie.h | 71 +
.../halmac/halmac_88xx/halmac_api_88xx_sdio.c | 974 ++
.../halmac/halmac_88xx/halmac_api_88xx_sdio.h | 84 +
.../halmac/halmac_88xx/halmac_api_88xx_usb.c | 554 +
.../halmac/halmac_88xx/halmac_api_88xx_usb.h | 73 +
.../rtlwifi/halmac/halmac_88xx/halmac_func_88xx.c | 4499 +++++++
.../rtlwifi/halmac/halmac_88xx/halmac_func_88xx.h | 321 +
drivers/staging/rtlwifi/halmac/halmac_api.c | 426 +
drivers/staging/rtlwifi/halmac/halmac_api.h | 82 +
drivers/staging/rtlwifi/halmac/halmac_bit2.h | 13407 +++++++++++++++++++
drivers/staging/rtlwifi/halmac/halmac_bit_8822b.h | 12103 +++++++++++++++++
drivers/staging/rtlwifi/halmac/halmac_fw_info.h | 122 +
.../rtlwifi/halmac/halmac_fw_offload_c2h_nic.h | 184 +
.../rtlwifi/halmac/halmac_fw_offload_h2c_nic.h | 515 +
.../rtlwifi/halmac/halmac_h2c_extra_info_nic.h | 115 +
.../staging/rtlwifi/halmac/halmac_intf_phy_cmd.h | 54 +
.../rtlwifi/halmac/halmac_original_c2h_nic.h | 403 +
.../rtlwifi/halmac/halmac_original_h2c_nic.h | 1011 ++
drivers/staging/rtlwifi/halmac/halmac_pcie_reg.h | 28 +
.../staging/rtlwifi/halmac/halmac_pwr_seq_cmd.h | 116 +
drivers/staging/rtlwifi/halmac/halmac_reg2.h | 1132 ++
drivers/staging/rtlwifi/halmac/halmac_reg_8822b.h | 728 +
drivers/staging/rtlwifi/halmac/halmac_rx_bd_chip.h | 48 +
drivers/staging/rtlwifi/halmac/halmac_rx_bd_nic.h | 48 +
.../staging/rtlwifi/halmac/halmac_rx_desc_chip.h | 118 +
.../staging/rtlwifi/halmac/halmac_rx_desc_nic.h | 133 +
drivers/staging/rtlwifi/halmac/halmac_sdio_reg.h | 62 +
drivers/staging/rtlwifi/halmac/halmac_tx_bd_chip.h | 118 +
drivers/staging/rtlwifi/halmac/halmac_tx_bd_nic.h | 123 +
.../staging/rtlwifi/halmac/halmac_tx_desc_chip.h | 444 +
.../staging/rtlwifi/halmac/halmac_tx_desc_nic.h | 506 +
drivers/staging/rtlwifi/halmac/halmac_type.h | 1934 +++
drivers/staging/rtlwifi/halmac/halmac_usb_reg.h | 28 +
drivers/staging/rtlwifi/halmac/rtl_halmac.c | 1410 ++
drivers/staging/rtlwifi/halmac/rtl_halmac.h | 94 +
drivers/staging/rtlwifi/pci.c | 2508 ++++
drivers/staging/rtlwifi/pci.h | 329 +
drivers/staging/rtlwifi/phydm/halphyrf_ce.c | 965 ++
drivers/staging/rtlwifi/phydm/halphyrf_ce.h | 85 +
drivers/staging/rtlwifi/phydm/mp_precomp.h | 24 +
drivers/staging/rtlwifi/phydm/phydm.c | 1986 +++
drivers/staging/rtlwifi/phydm/phydm.h | 946 ++
drivers/staging/rtlwifi/phydm/phydm_acs.c | 200 +
drivers/staging/rtlwifi/phydm/phydm_acs.h | 57 +
drivers/staging/rtlwifi/phydm/phydm_adaptivity.c | 941 ++
drivers/staging/rtlwifi/phydm/phydm_adaptivity.h | 119 +
drivers/staging/rtlwifi/phydm/phydm_adc_sampling.c | 628 +
drivers/staging/rtlwifi/phydm/phydm_adc_sampling.h | 96 +
drivers/staging/rtlwifi/phydm/phydm_antdiv.c | 83 +
drivers/staging/rtlwifi/phydm/phydm_antdiv.h | 301 +
drivers/staging/rtlwifi/phydm/phydm_beamforming.h | 48 +
drivers/staging/rtlwifi/phydm/phydm_ccx.c | 457 +
drivers/staging/rtlwifi/phydm/phydm_ccx.h | 83 +
drivers/staging/rtlwifi/phydm/phydm_cfotracking.c | 343 +
drivers/staging/rtlwifi/phydm/phydm_cfotracking.h | 60 +
drivers/staging/rtlwifi/phydm/phydm_debug.c | 2910 ++++
drivers/staging/rtlwifi/phydm/phydm_debug.h | 175 +
drivers/staging/rtlwifi/phydm/phydm_dfs.h | 59 +
drivers/staging/rtlwifi/phydm/phydm_dig.c | 1535 +++
drivers/staging/rtlwifi/phydm/phydm_dig.h | 241 +
.../staging/rtlwifi/phydm/phydm_dynamic_rx_path.h | 37 +
.../rtlwifi/phydm/phydm_dynamicbbpowersaving.c | 129 +
.../rtlwifi/phydm/phydm_dynamicbbpowersaving.h | 50 +
.../staging/rtlwifi/phydm/phydm_dynamictxpower.c | 102 +
.../staging/rtlwifi/phydm/phydm_dynamictxpower.h | 64 +
.../staging/rtlwifi/phydm/phydm_edcaturbocheck.c | 139 +
.../staging/rtlwifi/phydm/phydm_edcaturbocheck.h | 44 +
drivers/staging/rtlwifi/phydm/phydm_features.h | 33 +
drivers/staging/rtlwifi/phydm/phydm_hwconfig.c | 1928 +++
drivers/staging/rtlwifi/phydm/phydm_hwconfig.h | 510 +
drivers/staging/rtlwifi/phydm/phydm_interface.c | 341 +
drivers/staging/rtlwifi/phydm/phydm_interface.h | 205 +
drivers/staging/rtlwifi/phydm/phydm_iqk.h | 76 +
drivers/staging/rtlwifi/phydm/phydm_kfree.c | 228 +
drivers/staging/rtlwifi/phydm/phydm_kfree.h | 42 +
drivers/staging/rtlwifi/phydm/phydm_noisemonitor.c | 330 +
drivers/staging/rtlwifi/phydm/phydm_noisemonitor.h | 46 +
.../staging/rtlwifi/phydm/phydm_powertracking_ce.c | 644 +
.../staging/rtlwifi/phydm/phydm_powertracking_ce.h | 293 +
drivers/staging/rtlwifi/phydm/phydm_pre_define.h | 613 +
drivers/staging/rtlwifi/phydm/phydm_precomp.h | 85 +
drivers/staging/rtlwifi/phydm/phydm_psd.c | 422 +
drivers/staging/rtlwifi/phydm/phydm_psd.h | 67 +
drivers/staging/rtlwifi/phydm/phydm_rainfo.c | 1208 ++
drivers/staging/rtlwifi/phydm/phydm_rainfo.h | 269 +
drivers/staging/rtlwifi/phydm/phydm_reg.h | 151 +
.../staging/rtlwifi/phydm/phydm_regdefine11ac.h | 94 +
drivers/staging/rtlwifi/phydm/phydm_regdefine11n.h | 213 +
drivers/staging/rtlwifi/phydm/phydm_types.h | 130 +
.../rtlwifi/phydm/rtl8822b/halhwimg8822b_bb.c | 1969 +++
.../rtlwifi/phydm/rtl8822b/halhwimg8822b_bb.h | 54 +
.../rtlwifi/phydm/rtl8822b/halhwimg8822b_mac.c | 222 +
.../rtlwifi/phydm/rtl8822b/halhwimg8822b_mac.h | 38 +
.../rtlwifi/phydm/rtl8822b/halhwimg8822b_rf.c | 4744 +++++++
.../rtlwifi/phydm/rtl8822b/halhwimg8822b_rf.h | 129 +
.../rtlwifi/phydm/rtl8822b/halphyrf_8822b.c | 351 +
.../rtlwifi/phydm/rtl8822b/halphyrf_8822b.h | 45 +
.../rtlwifi/phydm/rtl8822b/phydm_hal_api8822b.c | 1815 +++
.../rtlwifi/phydm/rtl8822b/phydm_hal_api8822b.h | 84 +
.../rtlwifi/phydm/rtl8822b/phydm_iqk_8822b.c | 1410 ++
.../rtlwifi/phydm/rtl8822b/phydm_iqk_8822b.h | 48 +
.../rtlwifi/phydm/rtl8822b/phydm_regconfig8822b.c | 168 +
.../rtlwifi/phydm/rtl8822b/phydm_regconfig8822b.h | 54 +
.../rtlwifi/phydm/rtl8822b/phydm_rtl8822b.c | 225 +
.../rtlwifi/phydm/rtl8822b/phydm_rtl8822b.h | 30 +
.../rtlwifi/phydm/rtl8822b/version_rtl8822b.h | 34 +
drivers/staging/rtlwifi/phydm/rtl_phydm.c | 874 ++
drivers/staging/rtlwifi/phydm/rtl_phydm.h | 45 +
drivers/staging/rtlwifi/phydm/txbf/halcomtxbf.h | 67 +
drivers/staging/rtlwifi/phydm/txbf/haltxbf8822b.h | 39 +
.../staging/rtlwifi/phydm/txbf/haltxbfinterface.h | 38 +
drivers/staging/rtlwifi/phydm/txbf/haltxbfjaguar.h | 36 +
.../rtlwifi/phydm/txbf/phydm_hal_txbf_api.h | 41 +
drivers/staging/rtlwifi/ps.c | 1007 ++
drivers/staging/rtlwifi/ps.h | 50 +
drivers/staging/rtlwifi/pwrseqcmd.h | 94 +
drivers/staging/rtlwifi/rc.c | 322 +
drivers/staging/rtlwifi/rc.h | 49 +
drivers/staging/rtlwifi/regd.c | 469 +
drivers/staging/rtlwifi/regd.h | 63 +
drivers/staging/rtlwifi/rtl8822be/Makefile | 7 +
drivers/staging/rtlwifi/rtl8822be/def.h | 82 +
drivers/staging/rtlwifi/rtl8822be/fw.c | 968 ++
drivers/staging/rtlwifi/rtl8822be/fw.h | 198 +
drivers/staging/rtlwifi/rtl8822be/hw.c | 2441 ++++
drivers/staging/rtlwifi/rtl8822be/hw.h | 66 +
drivers/staging/rtlwifi/rtl8822be/led.c | 127 +
drivers/staging/rtlwifi/rtl8822be/led.h | 34 +
drivers/staging/rtlwifi/rtl8822be/phy.c | 2233 +++
drivers/staging/rtlwifi/rtl8822be/phy.h | 145 +
drivers/staging/rtlwifi/rtl8822be/reg.h | 1653 +++
drivers/staging/rtlwifi/rtl8822be/sw.c | 481 +
drivers/staging/rtlwifi/rtl8822be/sw.h | 32 +
drivers/staging/rtlwifi/rtl8822be/trx.c | 1022 ++
drivers/staging/rtlwifi/rtl8822be/trx.h | 165 +
drivers/staging/rtlwifi/stats.c | 260 +
drivers/staging/rtlwifi/stats.h | 42 +
drivers/staging/rtlwifi/wifi.h | 3375 +++++
184 files changed, 125931 insertions(+)
create mode 100644 drivers/staging/rtlwifi/Kconfig
create mode 100644 drivers/staging/rtlwifi/Makefile
create mode 100644 drivers/staging/rtlwifi/TODO
create mode 100644 drivers/staging/rtlwifi/base.c
create mode 100644 drivers/staging/rtlwifi/base.h
create mode 100644 drivers/staging/rtlwifi/btcoexist/Makefile
create mode 100644 drivers/staging/rtlwifi/btcoexist/halbt_precomp.h
create mode 100644 drivers/staging/rtlwifi/btcoexist/halbtc8822b1ant.c
create mode 100644 drivers/staging/rtlwifi/btcoexist/halbtc8822b1ant.h
create mode 100644 drivers/staging/rtlwifi/btcoexist/halbtc8822b2ant.c
create mode 100644 drivers/staging/rtlwifi/btcoexist/halbtc8822b2ant.h
create mode 100644 drivers/staging/rtlwifi/btcoexist/halbtc8822bwifionly.c
create mode 100644 drivers/staging/rtlwifi/btcoexist/halbtc8822bwifionly.h
create mode 100644 drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c
create mode 100644 drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.h
create mode 100644 drivers/staging/rtlwifi/btcoexist/rtl_btc.c
create mode 100644 drivers/staging/rtlwifi/btcoexist/rtl_btc.h
create mode 100644 drivers/staging/rtlwifi/cam.c
create mode 100644 drivers/staging/rtlwifi/cam.h
create mode 100644 drivers/staging/rtlwifi/core.c
create mode 100644 drivers/staging/rtlwifi/core.h
create mode 100644 drivers/staging/rtlwifi/debug.c
create mode 100644 drivers/staging/rtlwifi/debug.h
create mode 100644 drivers/staging/rtlwifi/efuse.c
create mode 100644 drivers/staging/rtlwifi/efuse.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_2_platform.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_8822b_cfg.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_8822b_phy.c
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_8822b_pwr_seq.c
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_8822b_pwr_seq.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_api_8822b.c
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_api_8822b.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_api_8822b_pcie.c
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_api_8822b_pcie.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_api_8822b_sdio.c
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_api_8822b_sdio.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_api_8822b_usb.c
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_api_8822b_usb.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_func_8822b.c
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_func_8822b.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_88xx_cfg.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx.c
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx_pcie.c
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx_pcie.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx_sdio.c
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx_sdio.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx_usb.c
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx_usb.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_func_88xx.c
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_func_88xx.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_api.c
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_api.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_bit2.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_bit_8822b.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_fw_info.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_fw_offload_c2h_nic.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_fw_offload_h2c_nic.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_h2c_extra_info_nic.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_intf_phy_cmd.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_original_c2h_nic.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_original_h2c_nic.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_pcie_reg.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_pwr_seq_cmd.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_reg2.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_reg_8822b.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_rx_bd_chip.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_rx_bd_nic.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_rx_desc_chip.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_rx_desc_nic.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_sdio_reg.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_tx_bd_chip.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_tx_bd_nic.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_tx_desc_chip.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_tx_desc_nic.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_type.h
create mode 100644 drivers/staging/rtlwifi/halmac/halmac_usb_reg.h
create mode 100644 drivers/staging/rtlwifi/halmac/rtl_halmac.c
create mode 100644 drivers/staging/rtlwifi/halmac/rtl_halmac.h
create mode 100644 drivers/staging/rtlwifi/pci.c
create mode 100644 drivers/staging/rtlwifi/pci.h
create mode 100644 drivers/staging/rtlwifi/phydm/halphyrf_ce.c
create mode 100644 drivers/staging/rtlwifi/phydm/halphyrf_ce.h
create mode 100644 drivers/staging/rtlwifi/phydm/mp_precomp.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_acs.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_acs.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_adaptivity.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_adaptivity.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_adc_sampling.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_adc_sampling.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_antdiv.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_antdiv.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_beamforming.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_ccx.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_ccx.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_cfotracking.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_cfotracking.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_debug.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_debug.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_dfs.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_dig.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_dig.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_dynamic_rx_path.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_dynamicbbpowersaving.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_dynamicbbpowersaving.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_dynamictxpower.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_dynamictxpower.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_edcaturbocheck.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_edcaturbocheck.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_features.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_hwconfig.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_hwconfig.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_interface.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_interface.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_iqk.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_kfree.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_kfree.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_noisemonitor.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_noisemonitor.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_powertracking_ce.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_powertracking_ce.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_pre_define.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_precomp.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_psd.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_psd.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_rainfo.c
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_rainfo.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_reg.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_regdefine11ac.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_regdefine11n.h
create mode 100644 drivers/staging/rtlwifi/phydm/phydm_types.h
create mode 100644 drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_bb.c
create mode 100644 drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_bb.h
create mode 100644 drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_mac.c
create mode 100644 drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_mac.h
create mode 100644 drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_rf.c
create mode 100644 drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_rf.h
create mode 100644 drivers/staging/rtlwifi/phydm/rtl8822b/halphyrf_8822b.c
create mode 100644 drivers/staging/rtlwifi/phydm/rtl8822b/halphyrf_8822b.h
create mode 100644 drivers/staging/rtlwifi/phydm/rtl8822b/phydm_hal_api8822b.c
create mode 100644 drivers/staging/rtlwifi/phydm/rtl8822b/phydm_hal_api8822b.h
create mode 100644 drivers/staging/rtlwifi/phydm/rtl8822b/phydm_iqk_8822b.c
create mode 100644 drivers/staging/rtlwifi/phydm/rtl8822b/phydm_iqk_8822b.h
create mode 100644 drivers/staging/rtlwifi/phydm/rtl8822b/phydm_regconfig8822b.c
create mode 100644 drivers/staging/rtlwifi/phydm/rtl8822b/phydm_regconfig8822b.h
create mode 100644 drivers/staging/rtlwifi/phydm/rtl8822b/phydm_rtl8822b.c
create mode 100644 drivers/staging/rtlwifi/phydm/rtl8822b/phydm_rtl8822b.h
create mode 100644 drivers/staging/rtlwifi/phydm/rtl8822b/version_rtl8822b.h
create mode 100644 drivers/staging/rtlwifi/phydm/rtl_phydm.c
create mode 100644 drivers/staging/rtlwifi/phydm/rtl_phydm.h
create mode 100644 drivers/staging/rtlwifi/phydm/txbf/halcomtxbf.h
create mode 100644 drivers/staging/rtlwifi/phydm/txbf/haltxbf8822b.h
create mode 100644 drivers/staging/rtlwifi/phydm/txbf/haltxbfinterface.h
create mode 100644 drivers/staging/rtlwifi/phydm/txbf/haltxbfjaguar.h
create mode 100644 drivers/staging/rtlwifi/phydm/txbf/phydm_hal_txbf_api.h
create mode 100644 drivers/staging/rtlwifi/ps.c
create mode 100644 drivers/staging/rtlwifi/ps.h
create mode 100644 drivers/staging/rtlwifi/pwrseqcmd.h
create mode 100644 drivers/staging/rtlwifi/rc.c
create mode 100644 drivers/staging/rtlwifi/rc.h
create mode 100644 drivers/staging/rtlwifi/regd.c
create mode 100644 drivers/staging/rtlwifi/regd.h
create mode 100644 drivers/staging/rtlwifi/rtl8822be/Makefile
create mode 100644 drivers/staging/rtlwifi/rtl8822be/def.h
create mode 100644 drivers/staging/rtlwifi/rtl8822be/fw.c
create mode 100644 drivers/staging/rtlwifi/rtl8822be/fw.h
create mode 100644 drivers/staging/rtlwifi/rtl8822be/hw.c
create mode 100644 drivers/staging/rtlwifi/rtl8822be/hw.h
create mode 100644 drivers/staging/rtlwifi/rtl8822be/led.c
create mode 100644 drivers/staging/rtlwifi/rtl8822be/led.h
create mode 100644 drivers/staging/rtlwifi/rtl8822be/phy.c
create mode 100644 drivers/staging/rtlwifi/rtl8822be/phy.h
create mode 100644 drivers/staging/rtlwifi/rtl8822be/reg.h
create mode 100644 drivers/staging/rtlwifi/rtl8822be/sw.c
create mode 100644 drivers/staging/rtlwifi/rtl8822be/sw.h
create mode 100644 drivers/staging/rtlwifi/rtl8822be/trx.c
create mode 100644 drivers/staging/rtlwifi/rtl8822be/trx.h
create mode 100644 drivers/staging/rtlwifi/stats.c
create mode 100644 drivers/staging/rtlwifi/stats.h
create mode 100644 drivers/staging/rtlwifi/wifi.h
--
2.12.3
^ permalink raw reply
* [PATCH iproute2 json v2 27/27] ip: iplink_vlan.c: add json output support
From: Julien Fortin @ 2017-08-17 17:36 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema:
{
"protocol": {
"type": "string",
"attr": "IFLA_VLAN_PROTOCOL"
},
"id": {
"type": "uint",
"attr": "IFLA_VLAN_ID"
},
"flags": {
"type": "array",
"attr": "IFLA_VLAN_FLAGS",
"array": [
{
"type": "string"
}
]
},
"ingress_qos": {
"type": "array",
"attr": "IFLA_VLAN_INGRESS_QOS",
"array": [
{
"type": "dict",
"dict": {
"from": {
"type": "uint"
},
"to": {
"type": "uint"
}
}
}
]
},
"egress_qos": {
"type": "array",
"attr": "IFLA_VLAN_EGRESS_QOS",
"array": [
{
"type": "dict",
"dict": {
"from": {
"type": "uint"
},
"to": {
"type": "uint"
}
}
}
]
}
}
$ ip link add name eth0.42 link eth0 type vlan id 42
$ ip -details -json link show
[{
"ifindex": 30,
"ifname": "eth0.42",
"link": "eth0",
"flags": ["BROADCAST","MULTICAST"],
"mtu": 1500,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "ether",
"address": "08:00:27:db:31:88",
"broadcast": "ff:ff:ff:ff:ff:ff",
"promiscuity": 0,
"linkinfo": {
"info_kind": "vlan",
"info_data": {
"protocol": "802.1Q",
"id": 42,
"flags": ["REORDER_HDR"]
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
}
]
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/iplink_vlan.c | 62 ++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 44 insertions(+), 18 deletions(-)
diff --git a/ip/iplink_vlan.c b/ip/iplink_vlan.c
index b47236d8..4d78cf9e 100644
--- a/ip/iplink_vlan.c
+++ b/ip/iplink_vlan.c
@@ -164,37 +164,51 @@ static int vlan_parse_opt(struct link_util *lu, int argc, char **argv,
return 0;
}
-static void vlan_print_map(FILE *f, char *name, struct rtattr *attr)
+static void vlan_print_map(FILE *f,
+ const char *name_json,
+ const char *name_fp,
+ struct rtattr *attr)
{
struct ifla_vlan_qos_mapping *m;
struct rtattr *i;
int rem;
- fprintf(f, "\n %s { ", name);
+ open_json_array(PRINT_JSON, name_json);
+ print_string(PRINT_FP, NULL, "\n %s { ", name_fp);
rem = RTA_PAYLOAD(attr);
for (i = RTA_DATA(attr); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
m = RTA_DATA(i);
- fprintf(f, "%u:%u ", m->from, m->to);
+
+ if (is_json_context()) {
+ open_json_object(NULL);
+ print_uint(PRINT_JSON, "from", NULL, m->from);
+ print_uint(PRINT_JSON, "to", NULL, m->to);
+ close_json_object();
+ } else {
+ fprintf(f, "%u:%u ", m->from, m->to);
+ }
}
- fprintf(f, "} ");
+
+ close_json_array(PRINT_JSON, NULL);
+ print_string(PRINT_FP, NULL, "%s ", "}");
}
static void vlan_print_flags(FILE *fp, __u32 flags)
{
- fprintf(fp, "<");
-#define _PF(f) if (flags & VLAN_FLAG_##f) { \
- flags &= ~VLAN_FLAG_##f; \
- fprintf(fp, #f "%s", flags ? "," : ""); \
- }
+ open_json_array(PRINT_ANY, is_json_context() ? "flags" : "<");
+#define _PF(f) if (flags & VLAN_FLAG_##f) { \
+ flags &= ~VLAN_FLAG_##f; \
+ print_string(PRINT_ANY, NULL, flags ? "%s," : "%s", #f); \
+ }
_PF(REORDER_HDR);
_PF(GVRP);
_PF(MVRP);
_PF(LOOSE_BINDING);
#undef _PF
if (flags)
- fprintf(fp, "%x", flags);
- fprintf(fp, "> ");
+ print_hex(PRINT_ANY, NULL, "%x", flags);
+ close_json_array(PRINT_ANY, "> ");
}
static void vlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
@@ -214,13 +228,19 @@ static void vlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
return;
if (tb[IFLA_VLAN_PROTOCOL])
- fprintf(f, "protocol %s ",
- ll_proto_n2a(rta_getattr_u16(tb[IFLA_VLAN_PROTOCOL]),
+ print_string(PRINT_ANY,
+ "protocol",
+ "protocol %s ",
+ ll_proto_n2a(
+ rta_getattr_u16(tb[IFLA_VLAN_PROTOCOL]),
b1, sizeof(b1)));
else
- fprintf(f, "protocol 802.1q ");
+ print_string(PRINT_ANY, "protocol", "protocol %s ", "802.1q");
- fprintf(f, "id %u ", rta_getattr_u16(tb[IFLA_VLAN_ID]));
+ print_uint(PRINT_ANY,
+ "id",
+ "id %u ",
+ rta_getattr_u16(tb[IFLA_VLAN_ID]));
if (tb[IFLA_VLAN_FLAGS]) {
if (RTA_PAYLOAD(tb[IFLA_VLAN_FLAGS]) < sizeof(*flags))
@@ -229,13 +249,19 @@ static void vlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
vlan_print_flags(f, flags->flags);
}
if (tb[IFLA_VLAN_INGRESS_QOS])
- vlan_print_map(f, "ingress-qos-map", tb[IFLA_VLAN_INGRESS_QOS]);
+ vlan_print_map(f,
+ "ingress_qos",
+ "ingress-qos-map",
+ tb[IFLA_VLAN_INGRESS_QOS]);
if (tb[IFLA_VLAN_EGRESS_QOS])
- vlan_print_map(f, "egress-qos-map", tb[IFLA_VLAN_EGRESS_QOS]);
+ vlan_print_map(f,
+ "egress_qos",
+ "egress-qos-map",
+ tb[IFLA_VLAN_EGRESS_QOS]);
}
static void vlan_print_help(struct link_util *lu, int argc, char **argv,
- FILE *f)
+ FILE *f)
{
print_explain(f);
}
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 26/27] ip: link_macvlan.c: add json output support
From: Julien Fortin @ 2017-08-17 17:36 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema:
{
"mode": {
"type": "string",
"attr": "IFLA_MACVLAN_MODE"
},
"nopromisc": {
"type": "bool",
"attr": "MACVLAN_FLAG_NOPROMISC"
},
"macaddr_count": {
"type": "int",
"attr": "IFLA_MACVLAN_MACADDR_COUNT"
},
"macaddr_data": {
"type": "array",
"attr": "IFLA_MACVLAN_MACADDR_DATA",
"array": [
{
"type": "string"
}
]
},
}
$ ip link add name peth0 link eth0 type macvlan
$ ip -details -json link show peth0
[{
"ifindex": 26,
"ifname": "peth0",
"link": "eth0",
"flags": ["BROADCAST","MULTICAST"],
"mtu": 1500,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "ether",
"address": "7a:84:48:3e:7b:1c",
"broadcast": "ff:ff:ff:ff:ff:ff",
"promiscuity": 0,
"linkinfo": {
"info_kind": "macvlan",
"info_data": {
"mode": "vepa"
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
}
]
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/iplink_macvlan.c | 37 +++++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 12 deletions(-)
diff --git a/ip/iplink_macvlan.c b/ip/iplink_macvlan.c
index 662eb6ff..b966a615 100644
--- a/ip/iplink_macvlan.c
+++ b/ip/iplink_macvlan.c
@@ -193,13 +193,15 @@ static void macvlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]
return;
mode = rta_getattr_u32(tb[IFLA_MACVLAN_MODE]);
- fprintf(f, "mode %s ",
- mode == MACVLAN_MODE_PRIVATE ? "private"
- : mode == MACVLAN_MODE_VEPA ? "vepa"
- : mode == MACVLAN_MODE_BRIDGE ? "bridge"
- : mode == MACVLAN_MODE_PASSTHRU ? "passthru"
- : mode == MACVLAN_MODE_SOURCE ? "source"
- : "unknown");
+ print_string(PRINT_ANY,
+ "mode",
+ "mode %s ",
+ mode == MACVLAN_MODE_PRIVATE ? "private"
+ : mode == MACVLAN_MODE_VEPA ? "vepa"
+ : mode == MACVLAN_MODE_BRIDGE ? "bridge"
+ : mode == MACVLAN_MODE_PASSTHRU ? "passthru"
+ : mode == MACVLAN_MODE_SOURCE ? "source"
+ : "unknown");
if (!tb[IFLA_MACVLAN_FLAGS] ||
RTA_PAYLOAD(tb[IFLA_MACVLAN_FLAGS]) < sizeof(__u16))
@@ -208,7 +210,7 @@ static void macvlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]
flags = rta_getattr_u16(tb[IFLA_MACVLAN_FLAGS]);
if (flags & MACVLAN_FLAG_NOPROMISC)
- fprintf(f, "nopromisc ");
+ print_bool(PRINT_ANY, "nopromisc", "nopromisc ", true);
/* in source mode, there are more options to print */
@@ -220,7 +222,7 @@ static void macvlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]
return;
count = rta_getattr_u32(tb[IFLA_MACVLAN_MACADDR_COUNT]);
- fprintf(f, "remotes (%d) ", count);
+ print_int(PRINT_ANY, "macaddr_count", "remotes (%d) ", count);
if (!tb[IFLA_MACVLAN_MACADDR_DATA])
return;
@@ -228,18 +230,29 @@ static void macvlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]
rta = RTA_DATA(tb[IFLA_MACVLAN_MACADDR_DATA]);
len = RTA_PAYLOAD(tb[IFLA_MACVLAN_MACADDR_DATA]);
+ open_json_array(PRINT_JSON, "macaddr_data");
for (; RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) {
if (rta->rta_type != IFLA_MACVLAN_MACADDR ||
RTA_PAYLOAD(rta) < 6)
continue;
addr = RTA_DATA(rta);
- fprintf(f, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x ", addr[0],
- addr[1], addr[2], addr[3], addr[4], addr[5]);
+ if (is_json_context()) {
+ SPRINT_BUF(b1);
+
+ snprintf(b1, sizeof(b1),
+ "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", addr[0],
+ addr[1], addr[2], addr[3], addr[4], addr[5]);
+ print_string(PRINT_JSON, NULL, NULL, b1);
+ } else {
+ fprintf(f, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x ", addr[0],
+ addr[1], addr[2], addr[3], addr[4], addr[5]);
+ }
}
+ close_json_array(PRINT_JSON, NULL);
}
static void macvlan_print_help(struct link_util *lu, int argc, char **argv,
- FILE *f)
+ FILE *f)
{
print_explain(lu, f);
}
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 25/27] ip: link_vti6.c: add json output support
From: Julien Fortin @ 2017-08-17 17:36 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema:
{
"remote": {
"type": "string",
"attr": "IFLA_VTI_REMOTE"
},
"local": {
"type": "string",
"attr": "IFLA_VTI_LOCAL"
},
"link": {
"type": "string",
"attr": "IFLA_VTI_LINK",
"mutually_exclusive": {
"link_index": {
"type": "uint",
}
}
},
"ikey": {
"type": "string",
"attr": "IFLA_VTI_IKEY"
},
"okey": {
"type": "string",
"attr": "IFLA_VTI_OKEY"
}
}
➜ ~ ip -6 tunnel add name vti6 mode vti6 local 2001:db8:1::1/64 remote
2001:0db8:85a3:0000:0000:8a2e:0370:7334
➜ ~ ip link show
10: ip6tnl0@NONE: <NOARP> mtu 1452 qdisc noop state DOWN mode DEFAULT
group default
link/tunnel6 :: brd ::
11: ip6_vti0@NONE: <NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT
group default
link/tunnel6 :: brd ::
12: vti6@NONE: <POINTOPOINT,NOARP> mtu 1500 qdisc noop state DOWN mode
DEFAULT group default
link/tunnel6 2001:db8:1::1 peer 2001:db8:85a3::8a2e:370:7334
➜ ~ ./ip -details -json link show
[{
"ifindex": 10,
"ifname": "ip6tnl0",
"link": null,
"flags": ["NOARP"],
"mtu": 1452,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "tunnel6",
"address": "::",
"broadcast": "::",
"promiscuity": 0,
"linkinfo": {
"info_kind": "ip6tnl",
"info_data": {
"proto": "ip6ip6",
"remote": "::",
"local": "::",
"encap_limit": 0,
"ttl": 0,
"flowinfo_tclass": "0x00",
"flowlabel": "0x00000",
"flowinfo": "0x00000000"
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
},{
"ifindex": 11,
"ifname": "ip6_vti0",
"link": null,
"flags": ["NOARP"],
"mtu": 1500,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "tunnel6",
"address": "::",
"broadcast": "::",
"promiscuity": 0,
"linkinfo": {
"info_kind": "vti6",
"info_data": {
"remote": "::",
"local": "::",
"ikey": "0.0.0.0",
"okey": "0.0.0.0"
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
},{
"ifindex": 12,
"ifname": "vti6",
"link": null,
"flags": ["POINTOPOINT","NOARP"],
"mtu": 1500,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "tunnel6",
"address": "2001:db8:1::1",
"link_pointtopoint": true,
"broadcast": "2001:db8:85a3::8a2e:370:7334",
"promiscuity": 0,
"linkinfo": {
"info_kind": "vti6",
"info_data": {
"remote": "2001:db8:85a3::8a2e:370:7334",
"local": "2001:db8:1::1",
"ikey": "0.0.0.0",
"okey": "0.0.0.0"
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
}
]
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/link_vti6.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/ip/link_vti6.c b/ip/link_vti6.c
index 6ea1fc23..8198d468 100644
--- a/ip/link_vti6.c
+++ b/ip/link_vti6.c
@@ -225,7 +225,7 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
remote = format_host(AF_INET6, 16, &daddr);
}
- fprintf(f, "remote %s ", remote);
+ print_string(PRINT_ANY, "remote", "remote %s ", remote);
if (tb[IFLA_VTI_LOCAL]) {
memcpy(&saddr, RTA_DATA(tb[IFLA_VTI_LOCAL]), sizeof(saddr));
@@ -233,29 +233,35 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
local = format_host(AF_INET6, 16, &saddr);
}
- fprintf(f, "local %s ", local);
+ print_string(PRINT_ANY, "local", "local %s ", local);
if (tb[IFLA_VTI_LINK] && (link = rta_getattr_u32(tb[IFLA_VTI_LINK]))) {
const char *n = if_indextoname(link, s2);
if (n)
- fprintf(f, "dev %s ", n);
+ print_string(PRINT_ANY, "link", "dev %s ", n);
else
- fprintf(f, "dev %u ", link);
+ print_uint(PRINT_ANY, "link_index", "dev %u ", link);
}
if (tb[IFLA_VTI_IKEY]) {
inet_ntop(AF_INET, RTA_DATA(tb[IFLA_VTI_IKEY]), s2, sizeof(s2));
- fprintf(f, "ikey %s ", s2);
+ print_string(PRINT_ANY, "ikey", "ikey %s ", s2);
}
if (tb[IFLA_VTI_OKEY]) {
inet_ntop(AF_INET, RTA_DATA(tb[IFLA_VTI_OKEY]), s2, sizeof(s2));
- fprintf(f, "okey %s ", s2);
+ print_string(PRINT_ANY, "okey", "okey %s ", s2);
}
- if (tb[IFLA_VTI_FWMARK] && rta_getattr_u32(tb[IFLA_VTI_FWMARK])) {
- fprintf(f, "fwmark 0x%x ", rta_getattr_u32(tb[IFLA_VTI_FWMARK]));
+ if (tb[IFLA_VTI_FWMARK]) {
+ __u32 fwmark = rta_getattr_u32(tb[IFLA_VTI_FWMARK]);
+
+ if (fwmark) {
+ snprintf(s2, sizeof(s2), "0x%x", fwmark);
+
+ print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
+ }
}
}
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 24/27] ip: link_vti.c: add json output support
From: Julien Fortin @ 2017-08-17 17:36 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema:
{
"remote": {
"type": "string",
"attr": "IFLA_VTI_REMOTE"
},
"local": {
"type": "string",
"attr": "IFLA_VTI_LOCAL"
},
"link": {
"type": "string",
"attr": "IFLA_VTI_LINK",
"mutually_exclusive": {
"link_index": {
"type": "uint",
}
}
},
"ikey": {
"type": "string",
"attr": "IFLA_VTI_IKEY"
},
"okey": {
"type": "string",
"attr": "IFLA_VTI_OKEY"
}
}
$ ip tunnel add vti0 mode vti local 192.0.2.1 remote 198.51.100.3
$ ip link show
10: ip_vti0@NONE: <NOARP> mtu 1428 qdisc noop state DOWN mode DEFAULT group
default
link/ipip 0.0.0.0 brd 0.0.0.0
11: vti0@NONE: <POINTOPOINT,NOARP> mtu 1428 qdisc noop state DOWN mode
DEFAULT group default
link/ipip 192.0.2.1 peer 198.51.100.3
$ ./ip -details -json link show
[{
"ifindex": 10,
"ifname": "ip_vti0",
"link": null,
"flags": ["NOARP"],
"mtu": 1428,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "ipip",
"address": "0.0.0.0",
"broadcast": "0.0.0.0",
"promiscuity": 0,
"linkinfo": {
"info_kind": "vti",
"info_data": {
"remote": "any",
"local": "any",
"ikey": "0.0.0.0",
"okey": "0.0.0.0"
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
},{
"ifindex": 11,
"ifname": "vti0",
"link": null,
"flags": ["POINTOPOINT","NOARP"],
"mtu": 1428,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "ipip",
"address": "192.0.2.1",
"link_pointtopoint": true,
"broadcast": "198.51.100.3",
"promiscuity": 0,
"linkinfo": {
"info_kind": "vti",
"info_data": {
"remote": "198.51.100.3",
"local": "192.0.2.1",
"ikey": "0.0.0.0",
"okey": "0.0.0.0"
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
}
]
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/link_vti.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/ip/link_vti.c b/ip/link_vti.c
index 3ffecfac..8bd4d900 100644
--- a/ip/link_vti.c
+++ b/ip/link_vti.c
@@ -224,7 +224,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
remote = format_host(AF_INET, 4, &addr);
}
- fprintf(f, "remote %s ", remote);
+ print_string(PRINT_ANY, "remote", "remote %s ", remote);
if (tb[IFLA_VTI_LOCAL]) {
unsigned int addr = rta_getattr_u32(tb[IFLA_VTI_LOCAL]);
@@ -233,30 +233,36 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
local = format_host(AF_INET, 4, &addr);
}
- fprintf(f, "local %s ", local);
+ print_string(PRINT_ANY, "local", "local %s ", local);
if (tb[IFLA_VTI_LINK] &&
(link = rta_getattr_u32(tb[IFLA_VTI_LINK]))) {
const char *n = if_indextoname(link, s2);
if (n)
- fprintf(f, "dev %s ", n);
+ print_string(PRINT_ANY, "link", "dev %s ", n);
else
- fprintf(f, "dev %u ", link);
+ print_uint(PRINT_ANY, "link_index", "dev %u ", link);
}
if (tb[IFLA_VTI_IKEY] &&
(key = rta_getattr_u32(tb[IFLA_VTI_IKEY])))
- fprintf(f, "ikey %#x ", ntohl(key));
+ print_0xhex(PRINT_ANY, "ikey", "ikey %#x ", ntohl(key));
if (tb[IFLA_VTI_OKEY] &&
(key = rta_getattr_u32(tb[IFLA_VTI_OKEY])))
- fprintf(f, "okey %#x ", ntohl(key));
+ print_0xhex(PRINT_ANY, "okey", "okey %#x ", ntohl(key));
- if (tb[IFLA_VTI_FWMARK] && rta_getattr_u32(tb[IFLA_VTI_FWMARK])) {
- fprintf(f, "fwmark 0x%x ",
- rta_getattr_u32(tb[IFLA_VTI_FWMARK]));
+ if (tb[IFLA_VTI_FWMARK]) {
+ __u32 fwmark = rta_getattr_u32(tb[IFLA_VTI_FWMARK]);
+
+ if (fwmark) {
+ SPRINT_BUF(b1);
+
+ snprintf(b1, sizeof(b1), "0x%x", fwmark);
+ print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
+ }
}
}
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 23/27] ip: link_iptnl.c: add json output support
From: Julien Fortin @ 2017-08-17 17:36 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema
{
"remote": {
"type": "string",
"attr": "IFLA_IPTUN_REMOTE"
},
"local": {
"type": "string",
"attr": "IFLA_IPTUN_LOCAL"
},
"link": {
"type": "string",
"attr": "IFLA_IPTUN_LINK",
"mutually_exclusive": {
"link_index": {
"type": "uint",
}
}
},
"ttl": {
"type": "int",
"attr": "IFLA_IPTUN_TTL"
},
"tos": {
"type": "string",
"attr": "IFLA_IPTUN_TOS"
},
"pmtudisc": {
"type": "bool",
"attr": "IFLA_IPTUN_PMTUDISC"
},
"isatap": {
"type": "bool",
"attr": "SIT_ISATAP & IFLA_IPTUN_FLAGS"
},
"6rd": {
"type": "dict",
"attr": "IFLA_IPTUN_6RD_PREFIXLEN",
"dict": {
"prefix": {
"type": "string"
},
"prefixlen": {
"type": "uint",
"attr": "IFLA_IPTUN_6RD_PREFIXLEN"
},
"relay_prefix": {
"type": "string"
},
"relay_prefixlen": {
"type": "uint",
"attr": "IFLA_IPTUN_6RD_PREFIXLEN"
}
}
},
"encap": {
"type": "dict",
"attr": "IFLA_IPTUN_ENCAP_TYPE",
"dict": {
"type": {
"type": "string",
"attr": "IFLA_IPTUN_ENCAP_TYPE"
},
"sport": {
"type": "uint",
"attr": "IFLA_IPTUN_ENCAP_SPORT"
},
"dport": {
"type": "uint",
"attr": "IFLA_IPTUN_ENCAP_DPORT"
},
"csum": {
"type": "bool",
"attr": "TUNNEL_ENCAP_FLAG_CSUM"
},
"csum6": {
"type": "bool",
"attr": "TUNNEL_ENCAP_FLAG_CSUM6"
},
"remcsum": {
"type": "bool",
"attr": "TUNNEL_ENCAP_FLAG_REMCSUM"
}
}
}
}
$ ip tunnel add tun0 mode ipip local 192.0.2.1 remote 198.51.100.3
$ ip link show
10: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN mode DEFAULT group
default
link/ipip 0.0.0.0 brd 0.0.0.0
11: tun0@NONE: <POINTOPOINT,NOARP> mtu 1480 qdisc noop state DOWN mode
DEFAULT group default
link/ipip 192.0.2.1 peer 198.51.100.3
$ ip -details -json link show
[{
"ifindex": 10,
"ifname": "tunl0",
"link": null,
"flags": ["NOARP"],
"mtu": 1480,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "ipip",
"address": "0.0.0.0",
"broadcast": "0.0.0.0",
"promiscuity": 0,
"linkinfo": {
"info_kind": "ipip",
"info_data": {
"remote": "any",
"local": "any",
"ttl": 0,
"pmtudisc": false
}
},
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
},{
"ifindex": 11,
"ifname": "tun0",
"link": null,
"flags": ["POINTOPOINT","NOARP"],
"mtu": 1480,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "ipip",
"address": "192.0.2.1",
"link_pointtopoint": true,
"broadcast": "198.51.100.3",
"promiscuity": 0,
"linkinfo": {
"info_kind": "ipip",
"info_data": {
"remote": "198.51.100.3",
"local": "192.0.2.1",
"ttl": 0,
"pmtudisc": true
}
},
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
}
]
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/link_iptnl.c | 155 ++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 106 insertions(+), 49 deletions(-)
diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c
index d24e7376..6a725e91 100644
--- a/ip/link_iptnl.c
+++ b/ip/link_iptnl.c
@@ -398,7 +398,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
remote = format_host(AF_INET, 4, &addr);
}
- fprintf(f, "remote %s ", remote);
+ print_string(PRINT_ANY, "remote", "remote %s ", remote);
if (tb[IFLA_IPTUN_LOCAL]) {
unsigned int addr = rta_getattr_u32(tb[IFLA_IPTUN_LOCAL]);
@@ -407,43 +407,55 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
local = format_host(AF_INET, 4, &addr);
}
- fprintf(f, "local %s ", local);
+ print_string(PRINT_ANY, "local", "local %s ", local);
if (tb[IFLA_IPTUN_LINK] && rta_getattr_u32(tb[IFLA_IPTUN_LINK])) {
unsigned int link = rta_getattr_u32(tb[IFLA_IPTUN_LINK]);
const char *n = if_indextoname(link, s2);
if (n)
- fprintf(f, "dev %s ", n);
+ print_string(PRINT_ANY, "link", "dev %s ", n);
else
- fprintf(f, "dev %u ", link);
+ print_int(PRINT_ANY, "link_index", "dev %u ", link);
}
- if (tb[IFLA_IPTUN_TTL] && rta_getattr_u8(tb[IFLA_IPTUN_TTL]))
- fprintf(f, "ttl %d ", rta_getattr_u8(tb[IFLA_IPTUN_TTL]));
- else
- fprintf(f, "ttl inherit ");
+ if (tb[IFLA_IPTUN_TTL]) {
+ __u8 ttl = rta_getattr_u8(tb[IFLA_IPTUN_TTL]);
+
+ if (ttl)
+ print_int(PRINT_ANY, "ttl", "ttl %d ", ttl);
+ else
+ print_int(PRINT_JSON, "ttl", NULL, ttl);
+ } else {
+ print_string(PRINT_FP, NULL, "ttl %s ", "inherit");
+ }
- if (tb[IFLA_IPTUN_TOS] && rta_getattr_u8(tb[IFLA_IPTUN_TOS])) {
+ if (tb[IFLA_IPTUN_TOS]) {
int tos = rta_getattr_u8(tb[IFLA_IPTUN_TOS]);
- fputs("tos ", f);
- if (tos == 1)
- fputs("inherit ", f);
- else
- fprintf(f, "0x%x ", tos);
+ if (tos) {
+ if (is_json_context()) {
+ print_0xhex(PRINT_JSON, "tos", "%#x", tos);
+ } else {
+ fputs("tos ", f);
+ if (tos == 1)
+ fputs("inherit ", f);
+ else
+ fprintf(f, "0x%x ", tos);
+ }
+ }
}
if (tb[IFLA_IPTUN_PMTUDISC] && rta_getattr_u8(tb[IFLA_IPTUN_PMTUDISC]))
- fprintf(f, "pmtudisc ");
+ print_bool(PRINT_ANY, "pmtudisc", "pmtudisc ", true);
else
- fprintf(f, "nopmtudisc ");
+ print_bool(PRINT_ANY, "pmtudisc", "nopmtudisc ", false);
if (tb[IFLA_IPTUN_FLAGS]) {
__u16 iflags = rta_getattr_u16(tb[IFLA_IPTUN_FLAGS]);
if (iflags & SIT_ISATAP)
- fprintf(f, "isatap ");
+ print_bool(PRINT_ANY, "isatap", "isatap ", true);
}
if (tb[IFLA_IPTUN_6RD_PREFIXLEN] &&
@@ -453,14 +465,32 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
__u32 relayprefix =
rta_getattr_u32(tb[IFLA_IPTUN_6RD_RELAY_PREFIX]);
- printf("6rd-prefix %s/%u ",
- inet_ntop(AF_INET6, RTA_DATA(tb[IFLA_IPTUN_6RD_PREFIX]),
- s1, sizeof(s1)),
- prefixlen);
- if (relayprefix) {
- printf("6rd-relay_prefix %s/%u ",
- format_host(AF_INET, 4, &relayprefix),
- relayprefixlen);
+ const char *prefix = inet_ntop(AF_INET6,
+ RTA_DATA(tb[IFLA_IPTUN_6RD_PREFIX]),
+ s1, sizeof(s1));
+
+ if (is_json_context()) {
+ print_string(PRINT_JSON, "prefix", NULL, prefix);
+ print_int(PRINT_JSON, "prefixlen", NULL, prefixlen);
+ if (relayprefix) {
+ print_string(PRINT_JSON,
+ "relay_prefix",
+ NULL,
+ format_host(AF_INET,
+ 4,
+ &relayprefix));
+ print_int(PRINT_JSON,
+ "relay_prefixlen",
+ NULL,
+ relayprefixlen);
+ }
+ } else {
+ printf("6rd-prefix %s/%u ", prefix, prefixlen);
+ if (relayprefix) {
+ printf("6rd-relay_prefix %s/%u ",
+ format_host(AF_INET, 4, &relayprefix),
+ relayprefixlen);
+ }
}
}
@@ -470,45 +500,72 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
__u16 sport = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_SPORT]);
__u16 dport = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_DPORT]);
- fputs("encap ", f);
+ print_string(PRINT_FP, NULL, "encap ", NULL);
switch (type) {
case TUNNEL_ENCAP_FOU:
- fputs("fou ", f);
+ print_string(PRINT_ANY, "type", "%s ", "fou");
break;
case TUNNEL_ENCAP_GUE:
- fputs("gue ", f);
+ print_string(PRINT_ANY, "type", "%s ", "gue");
break;
default:
- fputs("unknown ", f);
+ print_null(PRINT_ANY, "type", "unknown ", NULL);
break;
}
- if (sport == 0)
- fputs("encap-sport auto ", f);
- else
- fprintf(f, "encap-sport %u", ntohs(sport));
+ if (is_json_context()) {
+ print_uint(PRINT_JSON,
+ "sport",
+ NULL,
+ sport ? ntohs(sport) : 0);
+ print_uint(PRINT_JSON, "dport", NULL, ntohs(dport));
+ print_bool(PRINT_JSON,
+ "csum",
+ NULL,
+ flags & TUNNEL_ENCAP_FLAG_CSUM);
+ print_bool(PRINT_JSON,
+ "csum6",
+ NULL,
+ flags & TUNNEL_ENCAP_FLAG_CSUM6);
+ print_bool(PRINT_JSON,
+ "remcsum",
+ NULL,
+ flags & TUNNEL_ENCAP_FLAG_REMCSUM);
+ close_json_object();
+ } else {
+ if (sport == 0)
+ fputs("encap-sport auto ", f);
+ else
+ fprintf(f, "encap-sport %u", ntohs(sport));
- fprintf(f, "encap-dport %u ", ntohs(dport));
+ fprintf(f, "encap-dport %u ", ntohs(dport));
- if (flags & TUNNEL_ENCAP_FLAG_CSUM)
- fputs("encap-csum ", f);
- else
- fputs("noencap-csum ", f);
+ if (flags & TUNNEL_ENCAP_FLAG_CSUM)
+ fputs("encap-csum ", f);
+ else
+ fputs("noencap-csum ", f);
- if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
- fputs("encap-csum6 ", f);
- else
- fputs("noencap-csum6 ", f);
+ if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
+ fputs("encap-csum6 ", f);
+ else
+ fputs("noencap-csum6 ", f);
- if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
- fputs("encap-remcsum ", f);
- else
- fputs("noencap-remcsum ", f);
+ if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
+ fputs("encap-remcsum ", f);
+ else
+ fputs("noencap-remcsum ", f);
+ }
}
- if (tb[IFLA_IPTUN_FWMARK] && rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]))
- fprintf(f, "fwmark 0x%x ",
- rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]));
+ if (tb[IFLA_IPTUN_FWMARK]) {
+ __u32 fwmark = rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]);
+
+ if (fwmark) {
+ snprintf(s2, sizeof(s2), "0x%x", fwmark);
+
+ print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
+ }
+ }
}
static void iptunnel_print_help(struct link_util *lu, int argc, char **argv,
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 22/27] ip: link_ip6tnl.c: add json output support
From: Julien Fortin @ 2017-08-17 17:36 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema
{
"proto": {
"type": "string",
"attr": "IFLA_IPTUN_PROTO"
},
"remote": {
"type": "string",
"attr": "IFLA_IPTUN_REMOTE"
},
"local": {
"type": "string",
"attr": "IFLA_IPTUN_LOCAL"
},
"link": {
"type": "string",
"attr": "IFLA_IPTUN_LINK",
"mutually_exclusive": {
"link_index": {
"type": "uint",
}
}
},
"ip6_tnl_f_ign_encap_limit": {
"type": "bool",
"attr": "IP6_TNL_F_IGN_ENCAP_LIMIT"
},
"encap_limit": {
"type": "uint",
"attr": "IFLA_IPTUN_ENCAP_LIMIT"
},
"ttl": {
"type": "uint",
"attr": "IFLA_IPTUN_TTL"
},
"ip6_tnl_f_use_orig_tclass": {
"type": "",
"attr": "IP6_TNL_F_USE_ORIG_TCLASS"
},
"flowinfo_tclass": {
"type": "string",
"attr": "IP6_FLOWINFO_TCLASS"
},
"ip6_tnl_f_use_orig_flowlabel": {
"type": "bool",
"attr": "IP6_TNL_F_USE_ORIG_FLOWLABEL"
},
"flowlabel": {
"type": "string",
"attr": "IP6_FLOWINFO_FLOWLABEL"
},
"flowinfo": {
"type": "string"
},
"ip6_tnl_f_rcv_dscp_copy": {
"type": "bool",
"attr": "IP6_TNL_F_RCV_DSCP_COPY"
},
"ip6_tnl_f_mip6_dev": {
"type": "bool",
"attr": "IP6_TNL_F_MIP6_DEV"
},
"ip6_tnl_f_use_orig_fwmark": {
"type": "bool",
"attr": "IP6_TNL_F_USE_ORIG_FWMARK"
},
"encap": {
"type": "dict",
"attr": "IFLA_IPTUN_ENCAP_TYPE",
"dict": {
"type": {
"type": "string",
"attr": "IFLA_IPTUN_ENCAP_TYPE"
},
"sport": {
"type": "uint",
"attr": "IFLA_IPTUN_ENCAP_SPORT"
},
"dport": {
"type": "uint",
"attr": "IFLA_IPTUN_ENCAP_DPORT"
},
"csum": {
"type": "bool",
"attr": "TUNNEL_ENCAP_FLAG_CSUM"
},
"csum6": {
"type": "bool",
"attr": "TUNNEL_ENCAP_FLAG_CSUM6"
},
"remcsum": {
"type": "bool",
"attr": "TUNNEL_ENCAP_FLAG_REMCSUM"
}
}
}
}
$ ip link show
$ ip -6 tunnel add name tun6 mode ip6gre local 2001:db8:1::1/64 remote
2001:0db8:85a3:0000:0000:8a2e:0370:7334
$ ip link show
10: ip6tnl0@NONE: <NOARP> mtu 1452 qdisc noop state DOWN mode DEFAULT group
default
link/tunnel6 :: brd ::
11: ip6gre0@NONE: <NOARP> mtu 1448 qdisc noop state DOWN mode DEFAULT group
default
link/gre6 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00 brd
00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
12: tun6@NONE: <POINTOPOINT,NOARP> mtu 1448 qdisc noop state DOWN mode
DEFAULT group default
link/gre6 20:01:0d:b8:00:01:00:00:00:00:00:00:00:00:00:01 peer
20:01:0d:b8:85:a3:00:00:00:00:8a:2e:03:70:73:34
➜ ~ ./ip -details -json link show
[{
"ifindex": 10,
"ifname": "ip6tnl0",
"link": null,
"flags": ["NOARP"],
"mtu": 1452,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "tunnel6",
"address": "::",
"broadcast": "::",
"promiscuity": 0,
"linkinfo": {
"info_kind": "ip6tnl",
"info_data": {
"proto": "ip6ip6",
"remote": "::",
"local": "::",
"encap_limit": 0,
"ttl": 0,
"flowinfo_tclass": "0x00",
"flowlabel": "0x00000",
"flowinfo": "0x00000000"
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
},{
"ifindex": 11,
"ifname": "ip6gre0",
"link": null,
"flags": ["NOARP"],
"mtu": 1448,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "gre6",
"address": "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
"broadcast": "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
"promiscuity": 0,
"linkinfo": {
"info_kind": "ip6gre",
"info_data": {
"remote": "any",
"local": "any",
"ttl": 0,
"encap_limit": 0,
"flowlabel": "0x00000"
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
},{
"ifindex": 12,
"ifname": "tun6",
"link": null,
"flags": ["POINTOPOINT","NOARP"],
"mtu": 1448,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "gre6",
"address": "20:01:0d:b8:00:01:00:00:00:00:00:00:00:00:00:01",
"link_pointtopoint": true,
"broadcast": "20:01:0d:b8:85:a3:00:00:00:00:8a:2e:03:70:73:34",
"promiscuity": 0,
"linkinfo": {
"info_kind": "ip6gre",
"info_data": {
"remote": "2001:db8:85a3::8a2e:370:7334",
"local": "2001:db8:1::1",
"ttl": 64,
"encap_limit": 4,
"flowlabel": "0x00000"
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
}
]
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/link_ip6tnl.c | 172 +++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 122 insertions(+), 50 deletions(-)
diff --git a/ip/link_ip6tnl.c b/ip/link_ip6tnl.c
index 505fb476..a4199006 100644
--- a/ip/link_ip6tnl.c
+++ b/ip/link_ip6tnl.c
@@ -346,25 +346,29 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
if (tb[IFLA_IPTUN_PROTO]) {
switch (rta_getattr_u8(tb[IFLA_IPTUN_PROTO])) {
case IPPROTO_IPIP:
- fprintf(f, "ipip6 ");
+ print_string(PRINT_ANY, "proto", "%s ", "ipip6");
break;
case IPPROTO_IPV6:
- fprintf(f, "ip6ip6 ");
+ print_string(PRINT_ANY, "proto", "%s ", "ip6ip6");
break;
case 0:
- fprintf(f, "any ");
+ print_string(PRINT_ANY, "proto", "%s ", "any");
break;
}
}
if (tb[IFLA_IPTUN_REMOTE]) {
- fprintf(f, "remote %s ",
- rt_addr_n2a_rta(AF_INET6, tb[IFLA_IPTUN_REMOTE]));
+ print_string(PRINT_ANY,
+ "remote",
+ "remote %s ",
+ rt_addr_n2a_rta(AF_INET6, tb[IFLA_IPTUN_REMOTE]));
}
if (tb[IFLA_IPTUN_LOCAL]) {
- fprintf(f, "local %s ",
- rt_addr_n2a_rta(AF_INET6, tb[IFLA_IPTUN_LOCAL]));
+ print_string(PRINT_ANY,
+ "local",
+ "local %s ",
+ rt_addr_n2a_rta(AF_INET6, tb[IFLA_IPTUN_LOCAL]));
}
if (tb[IFLA_IPTUN_LINK] && rta_getattr_u32(tb[IFLA_IPTUN_LINK])) {
@@ -372,93 +376,161 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
const char *n = if_indextoname(link, s2);
if (n)
- fprintf(f, "dev %s ", n);
+ print_string(PRINT_ANY, "link", "dev %s ", n);
else
- fprintf(f, "dev %u ", link);
+ print_uint(PRINT_ANY, "link_index", "dev %u ", link);
}
if (flags & IP6_TNL_F_IGN_ENCAP_LIMIT)
- printf("encaplimit none ");
+ print_bool(PRINT_ANY,
+ "ip6_tnl_f_ign_encap_limit",
+ "encaplimit none ",
+ true);
else if (tb[IFLA_IPTUN_ENCAP_LIMIT])
- fprintf(f, "encaplimit %u ",
- rta_getattr_u8(tb[IFLA_IPTUN_ENCAP_LIMIT]));
+ print_uint(PRINT_ANY,
+ "encap_limit",
+ "encaplimit %u ",
+ rta_getattr_u8(tb[IFLA_IPTUN_ENCAP_LIMIT]));
if (tb[IFLA_IPTUN_TTL])
- fprintf(f, "hoplimit %u ", rta_getattr_u8(tb[IFLA_IPTUN_TTL]));
+ print_uint(PRINT_ANY,
+ "ttl",
+ "hoplimit %u ",
+ rta_getattr_u8(tb[IFLA_IPTUN_TTL]));
if (flags & IP6_TNL_F_USE_ORIG_TCLASS)
- printf("tclass inherit ");
+ print_bool(PRINT_ANY,
+ "ip6_tnl_f_use_orig_tclass",
+ "tclass inherit ",
+ true);
else if (tb[IFLA_IPTUN_FLOWINFO]) {
__u32 val = ntohl(flowinfo & IP6_FLOWINFO_TCLASS);
- printf("tclass 0x%02x ", (__u8)(val >> 20));
+ if (is_json_context()) {
+ SPRINT_BUF(b1);
+
+ snprintf(b1, sizeof(b1), "0x%02x", (__u8)(val >> 20));
+ print_string(PRINT_JSON, "flowinfo_tclass", NULL, b1);
+ } else {
+ printf("tclass 0x%02x ", (__u8)(val >> 20));
+ }
+ }
+
+ if (flags & IP6_TNL_F_USE_ORIG_FLOWLABEL) {
+ print_bool(PRINT_ANY,
+ "ip6_tnl_f_use_orig_flowlabel",
+ "flowlabel inherit ",
+ true);
+ } else {
+ if (is_json_context()) {
+ SPRINT_BUF(b1);
+
+ snprintf(b1, sizeof(b1), "0x%05x",
+ ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
+ print_string(PRINT_JSON, "flowlabel", NULL, b1);
+ } else {
+ printf("flowlabel 0x%05x ",
+ ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
+ }
}
- if (flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
- printf("flowlabel inherit ");
- else
- printf("flowlabel 0x%05x ", ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
+ if (is_json_context()) {
+ SPRINT_BUF(flwinfo);
- printf("(flowinfo 0x%08x) ", ntohl(flowinfo));
+ snprintf(flwinfo, sizeof(flwinfo), "0x%08x", ntohl(flowinfo));
+ print_string(PRINT_JSON, "flowinfo", NULL, flwinfo);
+ } else {
+ printf("(flowinfo 0x%08x) ", ntohl(flowinfo));
+
+ }
if (flags & IP6_TNL_F_RCV_DSCP_COPY)
- printf("dscp inherit ");
+ print_bool(PRINT_ANY,
+ "ip6_tnl_f_rcv_dscp_copy",
+ "dscp inherit ",
+ true);
if (flags & IP6_TNL_F_MIP6_DEV)
- fprintf(f, "mip6 ");
+ print_bool(PRINT_ANY, "ip6_tnl_f_mip6_dev", "mip6 ", true);
+
+ if (flags & IP6_TNL_F_USE_ORIG_FWMARK) {
+ print_bool(PRINT_ANY,
+ "ip6_tnl_f_use_orig_fwmark",
+ "fwmark inherit ",
+ true);
+ } else if (tb[IFLA_IPTUN_FWMARK]) {
+ __u32 fwmark = rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]);
- if (flags & IP6_TNL_F_USE_ORIG_FWMARK)
- fprintf(f, "fwmark inherit ");
- else if (tb[IFLA_IPTUN_FWMARK] && rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]))
- fprintf(f, "fwmark 0x%x ", rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]));
+ if (fwmark) {
+ SPRINT_BUF(b1);
+
+ snprintf(b1, sizeof(b1), "0x%x", fwmark);
+ print_string(PRINT_ANY, "fwmark", "fwmark %s ", b1);
+ }
+ }
if (tb[IFLA_IPTUN_ENCAP_TYPE] &&
- rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE]) !=
- TUNNEL_ENCAP_NONE) {
+ rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
__u16 type = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE]);
__u16 flags = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_FLAGS]);
__u16 sport = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_SPORT]);
__u16 dport = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_DPORT]);
- fputs("encap ", f);
+ open_json_object("encap");
+ print_string(PRINT_FP, NULL, "encap ", NULL);
switch (type) {
case TUNNEL_ENCAP_FOU:
- fputs("fou ", f);
+ print_string(PRINT_ANY, "type", "%s ", "fou");
break;
case TUNNEL_ENCAP_GUE:
- fputs("gue ", f);
+ print_string(PRINT_ANY, "type", "%s ", "gue");
break;
default:
- fputs("unknown ", f);
+ print_null(PRINT_ANY, "type", "unknown ", NULL);
break;
}
- if (sport == 0)
- fputs("encap-sport auto ", f);
- else
- fprintf(f, "encap-sport %u", ntohs(sport));
+ if (is_json_context()) {
+ print_uint(PRINT_JSON,
+ "sport",
+ NULL,
+ sport ? ntohs(sport) : 0);
+ print_uint(PRINT_JSON, "dport", NULL, ntohs(dport));
+ print_bool(PRINT_JSON, "csum", NULL,
+ flags & TUNNEL_ENCAP_FLAG_CSUM);
+ print_bool(PRINT_JSON, "csum6", NULL,
+ flags & TUNNEL_ENCAP_FLAG_CSUM6);
+ print_bool(PRINT_JSON, "remcsum", NULL,
+ flags & TUNNEL_ENCAP_FLAG_REMCSUM);
+ close_json_object();
+ } else {
+ if (sport == 0)
+ fputs("encap-sport auto ", f);
+ else
+ fprintf(f, "encap-sport %u", ntohs(sport));
- fprintf(f, "encap-dport %u ", ntohs(dport));
+ fprintf(f, "encap-dport %u ", ntohs(dport));
- if (flags & TUNNEL_ENCAP_FLAG_CSUM)
- fputs("encap-csum ", f);
- else
- fputs("noencap-csum ", f);
+ if (flags & TUNNEL_ENCAP_FLAG_CSUM)
+ fputs("encap-csum ", f);
+ else
+ fputs("noencap-csum ", f);
- if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
- fputs("encap-csum6 ", f);
- else
- fputs("noencap-csum6 ", f);
+ if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
+ fputs("encap-csum6 ", f);
+ else
+ fputs("noencap-csum6 ", f);
- if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
- fputs("encap-remcsum ", f);
- else
- fputs("noencap-remcsum ", f);
+ if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
+ fputs("encap-remcsum ", f);
+ else
+ fputs("noencap-remcsum ", f);
+ }
}
}
static void ip6tunnel_print_help(struct link_util *lu, int argc, char **argv,
- FILE *f)
+ FILE *f)
{
print_usage(f);
}
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 21/27] ip: link_gre6.c: add json output support
From: Julien Fortin @ 2017-08-17 17:36 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema
{
"remote": {
"type": "string",
"attr": "IFLA_GRE_REMOTE"
},
"local": {
"type": "string",
"attr": "IFLA_GRE_LOCAL"
},
"link": {
"type": "string",
"attr": "IFLA_GRE_LINK",
"mutually_exclusive": {
"link_index": {
"type": "uint",
}
}
},
"ttl": {
"type": "int",
"attr": "IFLA_GRE_TTL"
},
"ip6_tnl_f_ign_encap_limit": {
"type": "bool",
"attr": "IP6_TNL_F_IGN_ENCAP_LIMIT"
},
"encap_limit": {
"type": "int",
"attr": "IFLA_GRE_ENCAP_LIMIT"
},
"ip6_tnl_f_use_orig_flowlabel": {
"type": "bool",
"attr": "IP6_TNL_F_USE_ORIG_FLOWLABEL"
},
"flowlabel": {
"type": "string",
"attr": "IP6_FLOWINFO_FLOWLABEL"
},
"ip6_tnl_f_rcv_dscp_copy": {
"type": "bool",
"attr": "IP6_TNL_F_RCV_DSCP_COPY"
},
"ikey": {
"type": "string",
"attr": "IFLA_GRE_IKEY"
},
"okey": {
"type": "string",
"attr": "IFLA_GRE_OKEY"
},
"iseq": {
"type": "bool",
"attr": "IFLA_GRE_IFLAGS & GRE_SEQ"
},
"oseq": {
"type": "bool",
"attr": "IFLA_GRE_OFLAGS & GRE_SEQ"
},
"icsum": {
"type": "bool",
"attr": "IFLA_GRE_IFLAGS & GRE_CSUM"
},
"ocsum": {
"type": "bool",
"attr": "IFLA_GRE_OFLAGS & GRE_CSUM"
},
"encap": {
"type": "dict",
"attr": "IFLA_GRE_ENCAP_TYPE != TUNNEL_ENCAP_NONE",
"dict": {
"type": {
"type": "string",
"attr": "IFLA_GRE_ENCAP_TYPE"
},
"sport": {
"type": "uint",
"attr": "IFLA_GRE_ENCAP_SPORT"
},
"dport": {
"type": "uint",
"attr": "IFLA_GRE_ENCAP_DPORT"
},
"csum": {
"type": "bool",
"attr": "TUNNEL_ENCAP_FLAG_CSUM"
},
"csum6": {
"type": "bool",
"attr": "TUNNEL_ENCAP_FLAG_CSUM6"
},
"remcsum": {
"type": "bool",
"attr": "TUNNEL_ENCAP_FLAG_REMCSUM"
}
}
}
}
$ ip link show
$ ip -6 tunnel add name tun6 mode ip6gre local 2001:db8:1::1/64 remote
2001:0db8:85a3:0000:0000:8a2e:0370:7334
$ ip link show
10: ip6tnl0@NONE: <NOARP> mtu 1452 qdisc noop state DOWN mode DEFAULT
group default
link/tunnel6 :: brd ::
11: ip6gre0@NONE: <NOARP> mtu 1448 qdisc noop state DOWN mode DEFAULT
group default
link/gre6 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00 brd
00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
12: tun6@NONE: <POINTOPOINT,NOARP> mtu 1448 qdisc noop state DOWN mode
DEFAULT group default
link/gre6 20:01:0d:b8:00:01:00:00:00:00:00:00:00:00:00:01 peer
20:01:0d:b8:85:a3:00:00:00:00:8a:2e:03:70:73:34
➜ ~ ./ip -details -json link show
[{
"ifindex": 10,
"ifname": "ip6tnl0",
"link": null,
"flags": ["NOARP"],
"mtu": 1452,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "tunnel6",
"address": "::",
"broadcast": "::",
"promiscuity": 0,
"linkinfo": {
"info_kind": "ip6tnl",
"info_data": {
"proto": "ip6ip6",
"remote": "::",
"local": "::",
"encap_limit": 0,
"ttl": 0,
"flowinfo_tclass": "0x00",
"flowlabel": "0x00000",
"flowinfo": "0x00000000"
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
},{
"ifindex": 11,
"ifname": "ip6gre0",
"link": null,
"flags": ["NOARP"],
"mtu": 1448,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "gre6",
"address": "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
"broadcast": "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
"promiscuity": 0,
"linkinfo": {
"info_kind": "ip6gre",
"info_data": {
"remote": "any",
"local": "any",
"ttl": 0,
"encap_limit": 0,
"flowlabel": "0x00000"
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
},{
"ifindex": 12,
"ifname": "tun6",
"link": null,
"flags": ["POINTOPOINT","NOARP"],
"mtu": 1448,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "gre6",
"address": "20:01:0d:b8:00:01:00:00:00:00:00:00:00:00:00:01",
"link_pointtopoint": true,
"broadcast": "20:01:0d:b8:85:a3:00:00:00:00:8a:2e:03:70:73:34",
"promiscuity": 0,
"linkinfo": {
"info_kind": "ip6gre",
"info_data": {
"remote": "2001:db8:85a3::8a2e:370:7334",
"local": "2001:db8:1::1",
"ttl": 64,
"encap_limit": 4,
"flowlabel": "0x00000"
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
}
]
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/link_gre6.c | 142 ++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 99 insertions(+), 43 deletions(-)
diff --git a/ip/link_gre6.c b/ip/link_gre6.c
index 4d3d4b54..957853d6 100644
--- a/ip/link_gre6.c
+++ b/ip/link_gre6.c
@@ -423,7 +423,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
remote = format_host(AF_INET6, sizeof(addr), &addr);
}
- fprintf(f, "remote %s ", remote);
+ print_string(PRINT_ANY, "remote", "remote %s ", remote);
if (tb[IFLA_GRE_LOCAL]) {
struct in6_addr addr;
@@ -434,36 +434,65 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
local = format_host(AF_INET6, sizeof(addr), &addr);
}
- fprintf(f, "local %s ", local);
+ print_string(PRINT_ANY, "local", "local %s ", local);
if (tb[IFLA_GRE_LINK] && rta_getattr_u32(tb[IFLA_GRE_LINK])) {
unsigned int link = rta_getattr_u32(tb[IFLA_GRE_LINK]);
const char *n = if_indextoname(link, s2);
if (n)
- fprintf(f, "dev %s ", n);
+ print_string(PRINT_ANY, "link", "dev %s ", n);
else
- fprintf(f, "dev %u ", link);
+ print_uint(PRINT_ANY, "link_index", "dev %u ", link);
}
- if (tb[IFLA_GRE_TTL] && rta_getattr_u8(tb[IFLA_GRE_TTL]))
- fprintf(f, "hoplimit %d ", rta_getattr_u8(tb[IFLA_GRE_TTL]));
+ if (tb[IFLA_GRE_TTL]) {
+ __u8 ttl = rta_getattr_u8(tb[IFLA_GRE_TTL]);
+
+ if (ttl)
+ print_int(PRINT_ANY, "ttl", "hoplimit %d ", ttl);
+ else
+ print_int(PRINT_JSON, "ttl", NULL, ttl);
+ }
if (flags & IP6_TNL_F_IGN_ENCAP_LIMIT)
- fprintf(f, "encaplimit none ");
+ print_bool(PRINT_ANY,
+ "ip6_tnl_f_ign_encap_limit",
+ "encaplimit none ",
+ true);
else if (tb[IFLA_GRE_ENCAP_LIMIT]) {
int encap_limit = rta_getattr_u8(tb[IFLA_GRE_ENCAP_LIMIT]);
- fprintf(f, "encaplimit %d ", encap_limit);
+ print_int(PRINT_ANY,
+ "encap_limit",
+ "encaplimit %d ",
+ encap_limit);
}
- if (flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
- fprintf(f, "flowlabel inherit ");
- else
- fprintf(f, "flowlabel 0x%05x ", ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
+ if (flags & IP6_TNL_F_USE_ORIG_FLOWLABEL) {
+ print_bool(PRINT_ANY,
+ "ip6_tnl_f_use_orig_flowlabel",
+ "flowlabel inherit ",
+ true);
+ } else {
+ if (is_json_context()) {
+ SPRINT_BUF(b1);
+
+ snprintf(b1, sizeof(b1), "0x%05x",
+ ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
+ print_string(PRINT_JSON, "flowlabel", NULL, b1);
+
+ } else {
+ fprintf(f, "flowlabel 0x%05x ",
+ ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
+ }
+ }
if (flags & IP6_TNL_F_RCV_DSCP_COPY)
- fprintf(f, "dscp inherit ");
+ print_bool(PRINT_ANY,
+ "ip6_tnl_f_rcv_dscp_copy",
+ "dscp inherit ",
+ true);
if (tb[IFLA_GRE_IFLAGS])
iflags = rta_getattr_u16(tb[IFLA_GRE_IFLAGS]);
@@ -473,27 +502,37 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if ((iflags & GRE_KEY) && tb[IFLA_GRE_IKEY]) {
inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_IKEY]), s2, sizeof(s2));
- fprintf(f, "ikey %s ", s2);
+ print_string(PRINT_ANY, "ikey", "ikey %s ", s2);
}
if ((oflags & GRE_KEY) && tb[IFLA_GRE_OKEY]) {
inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_OKEY]), s2, sizeof(s2));
- fprintf(f, "okey %s ", s2);
+ print_string(PRINT_ANY, "okey", "okey %s ", s2);
}
if (iflags & GRE_SEQ)
- fputs("iseq ", f);
+ print_bool(PRINT_ANY, "iseq", "iseq ", true);
if (oflags & GRE_SEQ)
- fputs("oseq ", f);
+ print_bool(PRINT_ANY, "oseq", "oseq ", true);
if (iflags & GRE_CSUM)
- fputs("icsum ", f);
+ print_bool(PRINT_ANY, "icsum", "icsum ", true);
if (oflags & GRE_CSUM)
- fputs("ocsum ", f);
+ print_bool(PRINT_ANY, "ocsum", "ocsum ", true);
if (flags & IP6_TNL_F_USE_ORIG_FWMARK)
- fprintf(f, "fwmark inherit ");
- else if (tb[IFLA_GRE_FWMARK] && rta_getattr_u32(tb[IFLA_GRE_FWMARK]))
- fprintf(f, "fwmark 0x%x ", rta_getattr_u32(tb[IFLA_GRE_FWMARK]));
+ print_bool(PRINT_ANY,
+ "ip6_tnl_f_use_orig_fwmark",
+ "fwmark inherit ",
+ true);
+ else if (tb[IFLA_GRE_FWMARK]) {
+ __u32 fwmark = rta_getattr_u32(tb[IFLA_GRE_FWMARK]);
+
+ if (fwmark) {
+ snprintf(s2, sizeof(s2), "0x%x", fwmark);
+
+ print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
+ }
+ }
if (tb[IFLA_GRE_ENCAP_TYPE] &&
rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
@@ -502,40 +541,57 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
__u16 sport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_SPORT]);
__u16 dport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_DPORT]);
- fputs("encap ", f);
+ open_json_object("encap");
+
+ print_string(PRINT_FP, NULL, "encap ", NULL);
switch (type) {
case TUNNEL_ENCAP_FOU:
- fputs("fou ", f);
+ print_string(PRINT_ANY, "type", "%s ", "fou");
break;
case TUNNEL_ENCAP_GUE:
- fputs("gue ", f);
+ print_string(PRINT_ANY, "type", "%s ", "gue");
break;
default:
- fputs("unknown ", f);
+ print_null(PRINT_ANY, "type", "unknown ", NULL);
break;
}
- if (sport == 0)
- fputs("encap-sport auto ", f);
- else
- fprintf(f, "encap-sport %u", ntohs(sport));
+ if (is_json_context()) {
+ print_uint(PRINT_JSON,
+ "sport",
+ NULL,
+ sport ? ntohs(sport) : 0);
+ print_uint(PRINT_JSON, "dport", NULL, ntohs(dport));
+ print_bool(PRINT_JSON, "csum", NULL,
+ flags & TUNNEL_ENCAP_FLAG_CSUM);
+ print_bool(PRINT_JSON, "csum6", NULL,
+ flags & TUNNEL_ENCAP_FLAG_CSUM6);
+ print_bool(PRINT_JSON, "remcsum", NULL,
+ flags & TUNNEL_ENCAP_FLAG_REMCSUM);
+ close_json_object();
+ } else {
+ if (sport == 0)
+ fputs("encap-sport auto ", f);
+ else
+ fprintf(f, "encap-sport %u", ntohs(sport));
- fprintf(f, "encap-dport %u ", ntohs(dport));
+ fprintf(f, "encap-dport %u ", ntohs(dport));
- if (flags & TUNNEL_ENCAP_FLAG_CSUM)
- fputs("encap-csum ", f);
- else
- fputs("noencap-csum ", f);
+ if (flags & TUNNEL_ENCAP_FLAG_CSUM)
+ fputs("encap-csum ", f);
+ else
+ fputs("noencap-csum ", f);
- if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
- fputs("encap-csum6 ", f);
- else
- fputs("noencap-csum6 ", f);
+ if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
+ fputs("encap-csum6 ", f);
+ else
+ fputs("noencap-csum6 ", f);
- if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
- fputs("encap-remcsum ", f);
- else
- fputs("noencap-remcsum ", f);
+ if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
+ fputs("encap-remcsum ", f);
+ else
+ fputs("noencap-remcsum ", f);
+ }
}
}
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 20/27] ip: link_gre.c: add json output support
From: Julien Fortin @ 2017-08-17 17:36 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema
{
"external": {
"type": "bool",
"comment": "!tb[IFLA_GRE_COLLECT_METADATA]"
},
"remote": {
"type": "string",
"attr": "IFLA_GRE_REMOTE"
},
"local": {
"type": "string",
"attr": "IFLA_GRE_LOCAL"
},
"link": {
"type": "string",
"attr": "IFLA_GRE_LINK",
"mutually_exclusive": {
"link_index": {
"type": "uint",
}
}
},
"ttl": {
"type": "int",
"attr": "IFLA_GRE_TTL"
},
"tos": {
"type": "string",
"attr": "IFLA_GRE_TOS"
},
"pmtudisc": {
"type": "bool",
"attr": "IFLA_GRE_PMTUDISC"
},
"ikey": {
"type": "string",
"attr": "IFLA_GRE_IKEY"
},
"okey": {
"type": "string",
"attr": "IFLA_GRE_OKEY"
},
"iseq": {
"type": "bool",
"attr": "IFLA_GRE_IFLAGS & GRE_SEQ"
},
"oseq": {
"type": "bool",
"attr": "IFLA_GRE_OFLAGS & GRE_SEQ"
},
"icsum": {
"type": "bool",
"attr": "IFLA_GRE_IFLAGS & GRE_CSUM"
},
"ocsum": {
"type": "bool",
"attr": "IFLA_GRE_OFLAGS & GRE_CSUM"
},
"ignore_df": {
"type": "bool",
"attr": "IFLA_GRE_IGNORE_DF"
},
"encap": {
"type": "dict",
"attr": "IFLA_GRE_ENCAP_TYPE != TUNNEL_ENCAP_NONE",
"dict": {
"type": {
"type": "string",
"attr": "IFLA_GRE_ENCAP_TYPE"
},
"sport": {
"type": "uint",
"attr": "IFLA_GRE_ENCAP_SPORT"
},
"dport": {
"type": "uint",
"attr": "IFLA_GRE_ENCAP_DPORT"
},
"csum": {
"type": "bool",
"attr": "TUNNEL_ENCAP_FLAG_CSUM"
},
"csum6": {
"type": "bool",
"attr": "TUNNEL_ENCAP_FLAG_CSUM6"
},
"remcsum": {
"type": "bool",
"attr": "TUNNEL_ENCAP_FLAG_REMCSUM"
}
}
}
}
$ ip link show
$ ip tunnel add tun42 mode gre local 192.0.2.42 remote 203.0.113.42 key 42
$ ip link show
10: gre0@NONE: <NOARP> mtu 1476 qdisc noop state DOWN mode DEFAULT group
default
link/gre 0.0.0.0 brd 0.0.0.0
11: gretap0@NONE: <BROADCAST,MULTICAST> mtu 1462 qdisc noop state DOWN
mode DEFAULT group default qlen 1000
link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
12: tun42@NONE: <POINTOPOINT,NOARP> mtu 1472 qdisc noop state DOWN mode
DEFAULT group default
link/gre 192.0.2.42 peer 203.0.113.42
$ ip -details -json link show
[{
"ifindex": 10,
"ifname": "gre0",
"link": null,
"flags": ["NOARP"],
"mtu": 1476,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "gre",
"address": "0.0.0.0",
"broadcast": "0.0.0.0",
"promiscuity": 0,
"linkinfo": {
"info_kind": "gre",
"info_data": {
"remote": "any",
"local": "any",
"ttl": 0,
"pmtudisc": false
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
},{
"ifindex": 11,
"ifname": "gretap0",
"link": null,
"flags": ["BROADCAST","MULTICAST"],
"mtu": 1462,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"txqlen": 1000,
"link_type": "ether",
"address": "00:00:00:00:00:00",
"broadcast": "ff:ff:ff:ff:ff:ff",
"promiscuity": 0,
"linkinfo": {
"info_kind": "gretap",
"info_data": {
"remote": "any",
"local": "any",
"ttl": 0,
"pmtudisc": false
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
},{
"ifindex": 12,
"ifname": "tun42",
"link": null,
"flags": ["POINTOPOINT","NOARP"],
"mtu": 1472,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "gre",
"address": "192.0.2.42",
"link_pointtopoint": true,
"broadcast": "203.0.113.42",
"promiscuity": 0,
"linkinfo": {
"info_kind": "gre",
"info_data": {
"remote": "203.0.113.42",
"local": "192.0.2.42",
"ttl": 0,
"pmtudisc": true,
"ikey": "0.0.0.42",
"okey": "0.0.0.42"
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
}
]
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/link_gre.c | 147 ++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 98 insertions(+), 49 deletions(-)
diff --git a/ip/link_gre.c b/ip/link_gre.c
index c2ec5f26..3c9f8194 100644
--- a/ip/link_gre.c
+++ b/ip/link_gre.c
@@ -389,7 +389,7 @@ static void gre_print_direct_opt(FILE *f, struct rtattr *tb[])
remote = format_host(AF_INET, 4, &addr);
}
- fprintf(f, "remote %s ", remote);
+ print_string(PRINT_ANY, "remote", "remote %s ", remote);
if (tb[IFLA_GRE_LOCAL]) {
unsigned int addr = rta_getattr_u32(tb[IFLA_GRE_LOCAL]);
@@ -398,36 +398,52 @@ static void gre_print_direct_opt(FILE *f, struct rtattr *tb[])
local = format_host(AF_INET, 4, &addr);
}
- fprintf(f, "local %s ", local);
+ print_string(PRINT_ANY, "local", "local %s ", local);
if (tb[IFLA_GRE_LINK] && rta_getattr_u32(tb[IFLA_GRE_LINK])) {
unsigned int link = rta_getattr_u32(tb[IFLA_GRE_LINK]);
const char *n = if_indextoname(link, s2);
if (n)
- fprintf(f, "dev %s ", n);
+ print_string(PRINT_ANY, "link", "dev %s ", n);
else
- fprintf(f, "dev %u ", link);
+ print_uint(PRINT_ANY, "link_index", "dev %u ", link);
}
- if (tb[IFLA_GRE_TTL] && rta_getattr_u8(tb[IFLA_GRE_TTL]))
- fprintf(f, "ttl %d ", rta_getattr_u8(tb[IFLA_GRE_TTL]));
- else
- fprintf(f, "ttl inherit ");
+ if (tb[IFLA_GRE_TTL]) {
+ __u8 ttl = rta_getattr_u8(tb[IFLA_GRE_TTL]);
+
+ if (ttl)
+ print_int(PRINT_ANY, "ttl", "ttl %d ", ttl);
+ else
+ print_int(PRINT_JSON, "ttl", NULL, ttl);
+ } else {
+ print_string(PRINT_FP, NULL, "ttl %s ", "inherit");
+ }
if (tb[IFLA_GRE_TOS] && rta_getattr_u8(tb[IFLA_GRE_TOS])) {
int tos = rta_getattr_u8(tb[IFLA_GRE_TOS]);
- fputs("tos ", f);
- if (tos == 1)
- fputs("inherit ", f);
- else
- fprintf(f, "0x%x ", tos);
+ if (is_json_context()) {
+ SPRINT_BUF(b1);
+
+ snprintf(b1, sizeof(b1), "0x%x", tos);
+ print_string(PRINT_JSON, "tos", NULL, b1);
+ } else {
+ fputs("tos ", f);
+ if (tos == 1)
+ fputs("inherit ", f);
+ else
+ fprintf(f, "0x%x ", tos);
+ }
}
- if (tb[IFLA_GRE_PMTUDISC] &&
- !rta_getattr_u8(tb[IFLA_GRE_PMTUDISC]))
- fputs("nopmtudisc ", f);
+ if (tb[IFLA_GRE_PMTUDISC]) {
+ if (!rta_getattr_u8(tb[IFLA_GRE_PMTUDISC]))
+ print_bool(PRINT_ANY, "pmtudisc", "nopmtudisc ", false);
+ else
+ print_bool(PRINT_JSON, "pmtudisc", NULL, true);
+ }
if (tb[IFLA_GRE_IFLAGS])
iflags = rta_getattr_u16(tb[IFLA_GRE_IFLAGS]);
@@ -437,26 +453,31 @@ static void gre_print_direct_opt(FILE *f, struct rtattr *tb[])
if ((iflags & GRE_KEY) && tb[IFLA_GRE_IKEY]) {
inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_IKEY]), s2, sizeof(s2));
- fprintf(f, "ikey %s ", s2);
+ print_string(PRINT_ANY, "ikey", "ikey %s ", s2);
}
if ((oflags & GRE_KEY) && tb[IFLA_GRE_OKEY]) {
inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_OKEY]), s2, sizeof(s2));
- fprintf(f, "okey %s ", s2);
+ print_string(PRINT_ANY, "okey", "okey %s ", s2);
}
if (iflags & GRE_SEQ)
- fputs("iseq ", f);
+ print_bool(PRINT_ANY, "iseq", "iseq ", true);
if (oflags & GRE_SEQ)
- fputs("oseq ", f);
+ print_bool(PRINT_ANY, "oseq", "oseq ", true);
if (iflags & GRE_CSUM)
- fputs("icsum ", f);
+ print_bool(PRINT_ANY, "icsum", "icsum ", true);
if (oflags & GRE_CSUM)
- fputs("ocsum ", f);
+ print_bool(PRINT_ANY, "ocsum", "ocsum ", true);
+
+ if (tb[IFLA_GRE_FWMARK]) {
+ __u32 fwmark = rta_getattr_u32(tb[IFLA_GRE_FWMARK]);
+
+ if (fwmark) {
+ snprintf(s2, sizeof(s2), "0x%x", fwmark);
- if (tb[IFLA_GRE_FWMARK] && rta_getattr_u32(tb[IFLA_GRE_FWMARK])) {
- fprintf(f, "fwmark 0x%x ",
- rta_getattr_u32(tb[IFLA_GRE_FWMARK]));
+ print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
+ }
}
}
@@ -468,10 +489,10 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (!tb[IFLA_GRE_COLLECT_METADATA])
gre_print_direct_opt(f, tb);
else
- fputs("external ", f);
+ print_bool(PRINT_ANY, "external", "external ", true);
if (tb[IFLA_GRE_IGNORE_DF] && rta_getattr_u8(tb[IFLA_GRE_IGNORE_DF]))
- fputs("ignore-df ", f);
+ print_bool(PRINT_ANY, "ignore_df", "ignore-df ", true);
if (tb[IFLA_GRE_ENCAP_TYPE] &&
rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
@@ -480,45 +501,73 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
__u16 sport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_SPORT]);
__u16 dport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_DPORT]);
- fputs("encap ", f);
+
+ open_json_object("encap");
+ print_string(PRINT_FP, NULL, "encap ", NULL);
+
switch (type) {
case TUNNEL_ENCAP_FOU:
- fputs("fou ", f);
+ print_string(PRINT_ANY, "type", "%s ", "fou");
break;
case TUNNEL_ENCAP_GUE:
- fputs("gue ", f);
+ print_string(PRINT_ANY, "type", "%s ", "gue");
break;
default:
- fputs("unknown ", f);
+ print_null(PRINT_ANY, "type", "%s ", "unknown");
break;
}
- if (sport == 0)
- fputs("encap-sport auto ", f);
- else
- fprintf(f, "encap-sport %u", ntohs(sport));
+ if (is_json_context()) {
+ print_uint(PRINT_JSON,
+ "sport",
+ NULL,
+ sport ? ntohs(sport) : 0);
+ print_uint(PRINT_JSON, "dport", NULL, ntohs(dport));
+
+ print_bool(PRINT_JSON,
+ "csum",
+ NULL,
+ flags & TUNNEL_ENCAP_FLAG_CSUM);
+
+ print_bool(PRINT_JSON,
+ "csum6",
+ NULL,
+ flags & TUNNEL_ENCAP_FLAG_CSUM6);
+
+ print_bool(PRINT_JSON,
+ "remcsum",
+ NULL,
+ flags & TUNNEL_ENCAP_FLAG_REMCSUM);
+
+ close_json_object();
+ } else {
+ if (sport == 0)
+ fputs("encap-sport auto ", f);
+ else
+ fprintf(f, "encap-sport %u", ntohs(sport));
- fprintf(f, "encap-dport %u ", ntohs(dport));
+ fprintf(f, "encap-dport %u ", ntohs(dport));
- if (flags & TUNNEL_ENCAP_FLAG_CSUM)
- fputs("encap-csum ", f);
- else
- fputs("noencap-csum ", f);
+ if (flags & TUNNEL_ENCAP_FLAG_CSUM)
+ fputs("encap-csum ", f);
+ else
+ fputs("noencap-csum ", f);
- if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
- fputs("encap-csum6 ", f);
- else
- fputs("noencap-csum6 ", f);
+ if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
+ fputs("encap-csum6 ", f);
+ else
+ fputs("noencap-csum6 ", f);
- if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
- fputs("encap-remcsum ", f);
- else
- fputs("noencap-remcsum ", f);
+ if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
+ fputs("encap-remcsum ", f);
+ else
+ fputs("noencap-remcsum ", f);
+ }
}
}
static void gre_print_help(struct link_util *lu, int argc, char **argv,
- FILE *f)
+ FILE *f)
{
print_usage(f);
}
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 19/27] ip: ipmacsec.c: add json output support
From: Julien Fortin @ 2017-08-17 17:36 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema
{
"sci": {
"type": "string",
"attr": "IFLA_MACSEC_SCI"
},
"protect": {
"type": "string",
"attr": "IFLA_MACSEC_PROTECT"
},
"cipher_suite": {
"type": "string",
"attr": "IFLA_MACSEC_CIPHER_SUITE"
},
"icv_len": {
"type": "uint",
"attr": "IFLA_MACSEC_ICV_LEN"
},
"encoding_sa": {
"type": "uint",
"attr": "IFLA_MACSEC_ENCODING_SA"
},
"validation": {
"type": "string",
"attr": "IFLA_MACSEC_VALIDATION"
},
"encrypt": {
"type": "string",
"attr": "IFLA_MACSEC_ENCRYPT"
},
"inc_sci": {
"type": "string",
"attr": "IFLA_MACSEC_INC_SCI"
},
"es": {
"type": "string",
"attr": "IFLA_MACSEC_ES"
},
"scb": {
"type": "string",
"attr": "IFLA_MACSEC_SCB"
},
"replay_protect": {
"type": "string",
"attr": "IFLA_MACSEC_REPLAY_PROTECT"
},
"window": {
"type": "int",
"attr": ""
}
}
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/ipmacsec.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 66 insertions(+), 18 deletions(-)
diff --git a/ip/ipmacsec.c b/ip/ipmacsec.c
index aa89a00f..ecc371a5 100644
--- a/ip/ipmacsec.c
+++ b/ip/ipmacsec.c
@@ -561,9 +561,14 @@ static int validate_secy_dump(struct rtattr **attrs)
static void print_flag(FILE *f, struct rtattr *attrs[], const char *desc,
int field)
{
- if (attrs[field])
- fprintf(f, "%s %s ", desc,
- values_on_off[!!rta_getattr_u8(attrs[field])]);
+ if (attrs[field]) {
+ const char *v = values_on_off[!!rta_getattr_u8(attrs[field])];
+
+ if (is_json_context())
+ print_string(PRINT_JSON, desc, NULL, v);
+ else
+ fprintf(f, "%s %s ", desc, v);
+ }
}
#define DEFAULT_CIPHER_NAME "GCM-AES-128"
@@ -1017,8 +1022,16 @@ static void macsec_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
return;
if (tb[IFLA_MACSEC_SCI]) {
- fprintf(f, "sci %016llx ",
- ntohll(rta_getattr_u64(tb[IFLA_MACSEC_SCI])));
+ if (is_json_context()) {
+ SPRINT_BUF(b1);
+
+ snprintf(b1, sizeof(b1), "%016llx",
+ ntohll(rta_getattr_u64(tb[IFLA_MACSEC_SCI])));
+ print_string(PRINT_JSON, "sci", NULL, b1);
+ } else {
+ fprintf(f, "sci %016llx ",
+ ntohll(rta_getattr_u64(tb[IFLA_MACSEC_SCI])));
+ }
}
print_flag(f, tb, "protect", IFLA_MACSEC_PROTECT);
@@ -1026,35 +1039,70 @@ static void macsec_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_MACSEC_CIPHER_SUITE]) {
__u64 csid = rta_getattr_u64(tb[IFLA_MACSEC_CIPHER_SUITE]);
- fprintf(f, "cipher %s ", cs_id_to_name(csid));
+ print_string(PRINT_ANY,
+ "cipher_suite",
+ "cipher %s ",
+ cs_id_to_name(csid));
}
if (tb[IFLA_MACSEC_ICV_LEN]) {
- fprintf(f, "icvlen %hhu ",
- rta_getattr_u8(tb[IFLA_MACSEC_ICV_LEN]));
+ if (is_json_context()) {
+ char b2[4];
+
+ snprintf(b2, sizeof(b2), "%hhu",
+ rta_getattr_u8(tb[IFLA_MACSEC_ICV_LEN]));
+ print_uint(PRINT_JSON, "icv_len", NULL, atoi(b2));
+ } else {
+ fprintf(f, "icvlen %hhu ",
+ rta_getattr_u8(tb[IFLA_MACSEC_ICV_LEN]));
+ }
}
if (tb[IFLA_MACSEC_ENCODING_SA]) {
- fprintf(f, "encodingsa %hhu ",
- rta_getattr_u8(tb[IFLA_MACSEC_ENCODING_SA]));
+ if (is_json_context()) {
+ char b2[4];
+
+ snprintf(b2, sizeof(b2), "%hhu",
+ rta_getattr_u8(tb[IFLA_MACSEC_ENCODING_SA]));
+ print_uint(PRINT_JSON, "encoding_sa", NULL, atoi(b2));
+ } else {
+ fprintf(f, "encodingsa %hhu ",
+ rta_getattr_u8(tb[IFLA_MACSEC_ENCODING_SA]));
+ }
}
if (tb[IFLA_MACSEC_VALIDATION]) {
__u8 val = rta_getattr_u8(tb[IFLA_MACSEC_VALIDATION]);
- fprintf(f, "validate %s ", VALIDATE_STR[val]);
+ print_string(PRINT_ANY,
+ "validation",
+ "validate %s ",
+ VALIDATE_STR[val]);
+ }
+
+ const char *inc_sci, *es, *replay;
+
+ if (is_json_context()) {
+ inc_sci = "inc_sci";
+ replay = "replay_protect";
+ es = "es";
+ } else {
+ inc_sci = "send_sci";
+ es = "end_station";
+ replay = "replay";
}
print_flag(f, tb, "encrypt", IFLA_MACSEC_ENCRYPT);
- print_flag(f, tb, "send_sci", IFLA_MACSEC_INC_SCI);
- print_flag(f, tb, "end_station", IFLA_MACSEC_ES);
+ print_flag(f, tb, inc_sci, IFLA_MACSEC_INC_SCI);
+ print_flag(f, tb, es, IFLA_MACSEC_ES);
print_flag(f, tb, "scb", IFLA_MACSEC_SCB);
+ print_flag(f, tb, replay, IFLA_MACSEC_REPLAY_PROTECT);
- print_flag(f, tb, "replay", IFLA_MACSEC_REPLAY_PROTECT);
- if (tb[IFLA_MACSEC_WINDOW]) {
- fprintf(f, "window %d ",
- rta_getattr_u32(tb[IFLA_MACSEC_WINDOW]));
- }
+ if (tb[IFLA_MACSEC_WINDOW])
+ print_int(PRINT_ANY,
+ "window",
+ "window %d ",
+ rta_getattr_u32(tb[IFLA_MACSEC_WINDOW]));
}
static bool check_txsc_flags(bool es, bool scb, bool sci)
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 18/27] ip: iplink_xdp.c: add json output support
From: Julien Fortin @ 2017-08-17 17:36 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema
{
"attached": {
"type": "uint",
"attr": "IFLA_XDP_ATTACHED"
},
"prog_id": {
"type": "uint",
"attr": "IFLA_XDP_PROG_ID"
}
}
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/iplink_xdp.c | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/ip/iplink_xdp.c b/ip/iplink_xdp.c
index 9ae9ee5d..3a61076e 100644
--- a/ip/iplink_xdp.c
+++ b/ip/iplink_xdp.c
@@ -16,6 +16,7 @@
#include "xdp.h"
#include "bpf_util.h"
+#include "ip_common.h"
extern int force;
@@ -92,20 +93,24 @@ void xdp_dump(FILE *fp, struct rtattr *xdp)
return;
mode = rta_getattr_u8(tb[IFLA_XDP_ATTACHED]);
- if (mode == XDP_ATTACHED_NONE)
- return;
- else if (mode == XDP_ATTACHED_DRV)
- fprintf(fp, "xdp");
- else if (mode == XDP_ATTACHED_SKB)
- fprintf(fp, "xdpgeneric");
- else if (mode == XDP_ATTACHED_HW)
- fprintf(fp, "xdpoffload");
- else
- fprintf(fp, "xdp[%u]", mode);
+ if (is_json_context()) {
+ print_uint(PRINT_JSON, "attached", NULL, mode);
+ } else {
+ if (mode == XDP_ATTACHED_NONE)
+ return;
+ else if (mode == XDP_ATTACHED_DRV)
+ fprintf(fp, "xdp");
+ else if (mode == XDP_ATTACHED_SKB)
+ fprintf(fp, "xdpgeneric");
+ else if (mode == XDP_ATTACHED_HW)
+ fprintf(fp, "xdpoffload");
+ else
+ fprintf(fp, "xdp[%u]", mode);
+ }
if (tb[IFLA_XDP_PROG_ID])
- fprintf(fp, "/id:%u",
- rta_getattr_u32(tb[IFLA_XDP_PROG_ID]));
+ print_uint(PRINT_ANY, "prog_id", "/id:%u",
+ rta_getattr_u32(tb[IFLA_XDP_PROG_ID]));
- fprintf(fp, " ");
+ print_string(PRINT_FP, NULL, "%c", " ");
}
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 17/27] ip: iplink_vxlan.c: add json output support
From: Julien Fortin @ 2017-08-17 17:36 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema:
{
"id": {
"type": "uint",
"attr": "IFLA_VXLAN_ID"
},
"group": {
"type": "string",
"attr": "IFLA_VXLAN_GROUP"
},
"remote": {
"type": "string",
"attr": "IFLA_VXLAN_GROUP"
},
"group6": {
"type": "string",
"attr": "IFLA_VXLAN_GROUP6"
},
"remote6": {
"type": "string",
"attr": "IFLA_VXLAN_GROUP6"
},
"local": {
"type": "string",
"attr": "IFLA_VXLAN_LOCAL"
},
"local6": {
"type": "string",
"attr": "IFLA_VXLAN_LOCAL6"
},
"link": {
"type": "string",
"attr": "IFLA_VXLAN_LINK",
"mutually_exclusive": {
"link_index": {
"type": "uint",
"comment": "if not ifname for ifindex"
}
}
},
"port_range": {
"type": "dict",
"attr": "IFLA_VXLAN_PORT_RANGE",
"dict": {
"low": {
"type": "uint"
},
"high": {
"type": "uint"
}
}
},
"port": {
"type": "uint",
"attr": "IFLA_VXLAN_PORT"
},
"learning": {
"type": "bool",
"attr": "IFLA_VXLAN_LEARNING"
},
"proxy": {
"type": "bool",
"attr": "IFLA_VXLAN_PROXY"
},
"rsc": {
"type": "bool",
"attr": "IFLA_VXLAN_RSC"
},
"l2miss": {
"type": "bool",
"attr": "IFLA_VXLAN_L2MISS"
},
"l3miss": {
"type": "bool",
"attr": "IFLA_VXLAN_L3MISS"
},
"tos": {
"type": "string",
"attr": "IFLA_VXLAN_TOS"
},
"ttl": {
"type": "int",
"attr": "IFLA_VXLAN_TTL"
},
"label": {
"type": "string",
"attr": "IFLA_VXLAN_LABEL"
},
"ageing": {
"type": "uint",
"attr": "IFLA_VXLAN_AGEING"
},
"limit": {
"type": "uint",
"attr": "IFLA_VXLAN_LIMIT"
},
"udp_csum": {
"type": "bool",
"attr": "IFLA_VXLAN_UDP_CSUM"
},
"udp_zero_csum6_tx": {
"type": "bool",
"attr": "IFLA_VXLAN_UDP_ZERO_CSUM6_TX"
},
"udp_zero_csum6_rx": {
"type": "bool",
"attr": "IFLA_VXLAN_UDP_ZERO_CSUM6_RX"
},
"remcsum_tx": {
"type": "bool",
"attr": "IFLA_VXLAN_REMCSUM_TX"
},
"remcsum_rx": {
"type": "bool",
"attr": "IFLA_VXLAN_REMCSUM_RX"
},
"collect_metadata": {
"type": "bool",
"attr": "IFLA_VXLAN_COLLECT_METADATA"
},
"gbp": {
"type": "bool",
"attr": "IFLA_VXLAN_GBP"
},
"gpe": {
"type": "bool",
"attr": "IFLA_VXLAN_GPE"
}
}
$ ip link add name vxlan42 type vxlan id 42 dev eth0 remote 203.0.113.6
local 192.0.2.1 dstport 4789
$ ip link add name vxlan43 type vxlan id 43 dev eth0 group 239.0.0.1
dstport 4789
$ ip -details -json link show
[{
"ifindex": 17,
"ifname": "vxlan42",
"flags": ["BROADCAST","MULTICAST"],
"mtu": 1450,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "ether",
"address": "b2:92:0e:1a:c6:42",
"broadcast": "ff:ff:ff:ff:ff:ff",
"promiscuity": 0,
"linkinfo": {
"info_kind": "vxlan",
"info_data": {
"id": 42,
"remote": "203.0.113.6",
"local": "192.0.2.1",
"link": "eth0",
"port_range": {
"low": 0,
"high": 0
},
"port": 4789,
"learning": true,
"ttl": 0,
"ageing": 300,
"udp_csum": false,
"udp_zero_csum6_tx": false,
"udp_zero_csum6_rx": false
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
},{
"ifindex": 18,
"ifname": "vxlan43",
"flags": ["BROADCAST","MULTICAST"],
"mtu": 1450,
"qdisc": "noop",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "ether",
"address": "c6:51:4d:7f:f9:2f",
"broadcast": "ff:ff:ff:ff:ff:ff",
"promiscuity": 0,
"linkinfo": {
"info_kind": "vxlan",
"info_data": {
"id": 43,
"group": "239.0.0.1",
"link": "eth0",
"port_range": {
"low": 0,
"high": 0
},
"port": 4789,
"learning": true,
"ttl": 0,
"ageing": 300,
"udp_csum": false,
"udp_zero_csum6_tx": false,
"udp_zero_csum6_rx": false
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
}
]
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/iplink_vxlan.c | 161 +++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 112 insertions(+), 49 deletions(-)
diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c
index 2bd619d4..a0530dda 100644
--- a/ip/iplink_vxlan.c
+++ b/ip/iplink_vxlan.c
@@ -406,18 +406,22 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
return;
vni = rta_getattr_u32(tb[IFLA_VXLAN_ID]);
- fprintf(f, "id %u ", vni);
+ print_uint(PRINT_ANY, "id", "id %u ", vni);
if (tb[IFLA_VXLAN_GROUP]) {
__be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_GROUP]);
if (addr) {
if (IN_MULTICAST(ntohl(addr)))
- fprintf(f, "group %s ",
- format_host(AF_INET, 4, &addr));
+ print_string(PRINT_ANY,
+ "group",
+ "group %s ",
+ format_host(AF_INET, 4, &addr));
else
- fprintf(f, "remote %s ",
- format_host(AF_INET, 4, &addr));
+ print_string(PRINT_ANY,
+ "remote",
+ "remote %s ",
+ format_host(AF_INET, 4, &addr));
}
} else if (tb[IFLA_VXLAN_GROUP6]) {
struct in6_addr addr;
@@ -425,11 +429,19 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_GROUP6]), sizeof(struct in6_addr));
if (!IN6_IS_ADDR_UNSPECIFIED(&addr)) {
if (IN6_IS_ADDR_MULTICAST(&addr))
- fprintf(f, "group %s ",
- format_host(AF_INET6, sizeof(struct in6_addr), &addr));
+ print_string(PRINT_ANY,
+ "group6",
+ "group %s ",
+ format_host(AF_INET6,
+ sizeof(struct in6_addr),
+ &addr));
else
- fprintf(f, "remote %s ",
- format_host(AF_INET6, sizeof(struct in6_addr), &addr));
+ print_string(PRINT_ANY,
+ "remote6",
+ "remote %s ",
+ format_host(AF_INET6,
+ sizeof(struct in6_addr),
+ &addr));
}
}
@@ -437,15 +449,21 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
__be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_LOCAL]);
if (addr)
- fprintf(f, "local %s ",
- format_host(AF_INET, 4, &addr));
+ print_string(PRINT_ANY,
+ "local",
+ "local %s ",
+ format_host(AF_INET, 4, &addr));
} else if (tb[IFLA_VXLAN_LOCAL6]) {
struct in6_addr addr;
memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_LOCAL6]), sizeof(struct in6_addr));
if (!IN6_IS_ADDR_UNSPECIFIED(&addr))
- fprintf(f, "local %s ",
- format_host(AF_INET6, sizeof(struct in6_addr), &addr));
+ print_string(PRINT_ANY,
+ "local6",
+ "local %s ",
+ format_host(AF_INET6,
+ sizeof(struct in6_addr),
+ &addr));
}
if (tb[IFLA_VXLAN_LINK] &&
@@ -453,110 +471,155 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
const char *n = if_indextoname(link, s2);
if (n)
- fprintf(f, "dev %s ", n);
+ print_string(PRINT_ANY, "link", "dev %s ", n);
else
- fprintf(f, "dev %u ", link);
+ print_uint(PRINT_ANY, "link_index", "dev %u ", link);
}
if (tb[IFLA_VXLAN_PORT_RANGE]) {
const struct ifla_vxlan_port_range *r
= RTA_DATA(tb[IFLA_VXLAN_PORT_RANGE]);
- fprintf(f, "srcport %u %u ", ntohs(r->low), ntohs(r->high));
+ if (is_json_context()) {
+ open_json_object("port_range");
+ print_uint(PRINT_JSON, "low", NULL, ntohs(r->low));
+ print_uint(PRINT_JSON, "high", NULL, ntohs(r->high));
+ close_json_object();
+ } else {
+ fprintf(f, "srcport %u %u ",
+ ntohs(r->low), ntohs(r->high));
+ }
}
if (tb[IFLA_VXLAN_PORT])
- fprintf(f, "dstport %u ",
- rta_getattr_be16(tb[IFLA_VXLAN_PORT]));
+ print_uint(PRINT_ANY,
+ "port",
+ "dstport %u ",
+ rta_getattr_be16(tb[IFLA_VXLAN_PORT]));
- if (tb[IFLA_VXLAN_LEARNING] &&
- !rta_getattr_u8(tb[IFLA_VXLAN_LEARNING]))
- fputs("nolearning ", f);
+ if (tb[IFLA_VXLAN_LEARNING]) {
+ __u8 learning = rta_getattr_u8(tb[IFLA_VXLAN_LEARNING]);
+
+ print_bool(PRINT_JSON, "learning", NULL, learning);
+ if (!learning)
+ print_bool(PRINT_FP, NULL, "nolearning ", true);
+ }
if (tb[IFLA_VXLAN_PROXY] && rta_getattr_u8(tb[IFLA_VXLAN_PROXY]))
- fputs("proxy ", f);
+ print_bool(PRINT_ANY, "proxy", "proxy ", true);
if (tb[IFLA_VXLAN_RSC] && rta_getattr_u8(tb[IFLA_VXLAN_RSC]))
- fputs("rsc ", f);
+ print_bool(PRINT_ANY, "rsc", "rsc ", true);
if (tb[IFLA_VXLAN_L2MISS] && rta_getattr_u8(tb[IFLA_VXLAN_L2MISS]))
- fputs("l2miss ", f);
+ print_bool(PRINT_ANY, "l2miss", "l2miss ", true);
if (tb[IFLA_VXLAN_L3MISS] && rta_getattr_u8(tb[IFLA_VXLAN_L3MISS]))
- fputs("l3miss ", f);
+ print_bool(PRINT_ANY, "l3miss", "l3miss ", true);
if (tb[IFLA_VXLAN_TOS] &&
(tos = rta_getattr_u8(tb[IFLA_VXLAN_TOS]))) {
- if (tos == 1)
- fprintf(f, "tos inherit ");
- else
- fprintf(f, "tos %#x ", tos);
+ if (is_json_context()) {
+ print_0xhex(PRINT_JSON, "tos", "%#x", tos);
+ } else {
+ if (tos == 1)
+ fprintf(f, "tos %s ", "inherit");
+ else
+ fprintf(f, "tos %#x ", tos);
+ }
}
if (tb[IFLA_VXLAN_TTL]) {
__u8 ttl = rta_getattr_u8(tb[IFLA_VXLAN_TTL]);
if (ttl)
- fprintf(f, "ttl %d ", ttl);
+ print_int(PRINT_ANY, "ttl", "ttl %d ", ttl);
+ else
+ print_int(PRINT_JSON, "ttl", NULL, ttl);
}
if (tb[IFLA_VXLAN_LABEL]) {
__u32 label = rta_getattr_u32(tb[IFLA_VXLAN_LABEL]);
if (label)
- fprintf(f, "flowlabel %#x ", ntohl(label));
+ print_0xhex(PRINT_ANY,
+ "label",
+ "flowlabel %#x ",
+ ntohl(label));
}
if (tb[IFLA_VXLAN_AGEING]) {
__u32 age = rta_getattr_u32(tb[IFLA_VXLAN_AGEING]);
if (age == 0)
- fprintf(f, "ageing none ");
+ print_uint(PRINT_ANY, "ageing", "ageing none ", 0);
else
- fprintf(f, "ageing %u ", age);
+ print_uint(PRINT_ANY, "ageing", "ageing %u ", age);
}
if (tb[IFLA_VXLAN_LIMIT] &&
((maxaddr = rta_getattr_u32(tb[IFLA_VXLAN_LIMIT])) != 0))
- fprintf(f, "maxaddr %u ", maxaddr);
+ print_uint(PRINT_ANY, "limit", "maxaddr %u ", maxaddr);
if (tb[IFLA_VXLAN_UDP_CSUM]) {
- if (!rta_getattr_u8(tb[IFLA_VXLAN_UDP_CSUM]))
- fputs("no", f);
- fputs("udpcsum ", f);
+ __u8 udp_csum = rta_getattr_u8(tb[IFLA_VXLAN_UDP_CSUM]);
+
+ if (is_json_context()) {
+ print_bool(PRINT_ANY, "udp_csum", NULL, udp_csum);
+ } else {
+ if (!udp_csum)
+ fputs("no", f);
+ fputs("udpcsum ", f);
+ }
}
if (tb[IFLA_VXLAN_UDP_ZERO_CSUM6_TX]) {
- if (!rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_TX]))
- fputs("no", f);
- fputs("udp6zerocsumtx ", f);
+ __u8 csum6 = rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_TX]);
+
+ if (is_json_context()) {
+ print_bool(PRINT_ANY,
+ "udp_zero_csum6_tx", NULL, csum6);
+ } else {
+ if (!csum6)
+ fputs("no", f);
+ fputs("udp6zerocsumtx ", f);
+ }
}
if (tb[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]) {
- if (!rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]))
- fputs("no", f);
- fputs("udp6zerocsumrx ", f);
+ __u8 csum6 = rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]);
+
+ if (is_json_context()) {
+ print_bool(PRINT_ANY,
+ "udp_zero_csum6_rx",
+ NULL,
+ csum6);
+ } else {
+ if (!csum6)
+ fputs("no", f);
+ fputs("udp6zerocsumrx ", f);
+ }
}
if (tb[IFLA_VXLAN_REMCSUM_TX] &&
rta_getattr_u8(tb[IFLA_VXLAN_REMCSUM_TX]))
- fputs("remcsumtx ", f);
+ print_bool(PRINT_ANY, "remcsum_tx", "remcsumtx ", true);
if (tb[IFLA_VXLAN_REMCSUM_RX] &&
rta_getattr_u8(tb[IFLA_VXLAN_REMCSUM_RX]))
- fputs("remcsumrx ", f);
+ print_bool(PRINT_ANY, "remcsum_rx", "remcsumrx ", true);
if (tb[IFLA_VXLAN_COLLECT_METADATA] &&
rta_getattr_u8(tb[IFLA_VXLAN_COLLECT_METADATA]))
- fputs("external ", f);
+ print_bool(PRINT_ANY, "collect_metadata", "external ", true);
if (tb[IFLA_VXLAN_GBP])
- fputs("gbp ", f);
+ print_bool(PRINT_ANY, "gbp", "gbp ", true);
if (tb[IFLA_VXLAN_GPE])
- fputs("gpe ", f);
+ print_bool(PRINT_ANY, "gpe", "gpe ", true);
}
static void vxlan_print_help(struct link_util *lu, int argc, char **argv,
- FILE *f)
+ FILE *f)
{
print_explain(f);
}
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 16/27] ip: iplink_vrf.c: add json output support
From: Julien Fortin @ 2017-08-17 17:36 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema:
{
"table": {
"type": "uint",
"attr": "IFLA_VRF_TABLE"
}
}
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/iplink_vrf.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/ip/iplink_vrf.c b/ip/iplink_vrf.c
index 917630e8..f13b1d24 100644
--- a/ip/iplink_vrf.c
+++ b/ip/iplink_vrf.c
@@ -62,7 +62,10 @@ static void vrf_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
return;
if (tb[IFLA_VRF_TABLE])
- fprintf(f, "table %u ", rta_getattr_u32(tb[IFLA_VRF_TABLE]));
+ print_uint(PRINT_ANY,
+ "table",
+ "table %u ",
+ rta_getattr_u32(tb[IFLA_VRF_TABLE]));
}
static void vrf_slave_print_opt(struct link_util *lu, FILE *f,
@@ -72,13 +75,15 @@ static void vrf_slave_print_opt(struct link_util *lu, FILE *f,
return;
if (tb[IFLA_VRF_PORT_TABLE]) {
- fprintf(f, "table %u ",
- rta_getattr_u32(tb[IFLA_VRF_PORT_TABLE]));
+ print_uint(PRINT_ANY,
+ "table",
+ "table %u ",
+ rta_getattr_u32(tb[IFLA_VRF_PORT_TABLE]));
}
}
static void vrf_print_help(struct link_util *lu, int argc, char **argv,
- FILE *f)
+ FILE *f)
{
vrf_explain(f);
}
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 15/27] ip: iplink_ipvlan.c: add json output support
From: Julien Fortin @ 2017-08-17 17:36 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema:
{
"mode": {
"type": "string",
"attr": "IFLA_IPVLAN_MODE"
}
}
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/iplink_ipvlan.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/ip/iplink_ipvlan.c b/ip/iplink_ipvlan.c
index f7735f3a..9f48309e 100644
--- a/ip/iplink_ipvlan.c
+++ b/ip/iplink_ipvlan.c
@@ -68,11 +68,11 @@ static void ipvlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_IPVLAN_MODE]) {
if (RTA_PAYLOAD(tb[IFLA_IPVLAN_MODE]) == sizeof(__u16)) {
__u16 mode = rta_getattr_u16(tb[IFLA_IPVLAN_MODE]);
-
- fprintf(f, " mode %s ",
- mode == IPVLAN_MODE_L2 ? "l2" :
+ const char *mode_str = mode == IPVLAN_MODE_L2 ? "l2" :
mode == IPVLAN_MODE_L3 ? "l3" :
- mode == IPVLAN_MODE_L3S ? "l3s" : "unknown");
+ mode == IPVLAN_MODE_L3S ? "l3s" : "unknown";
+
+ print_string(PRINT_ANY, "mode", " mode %s ", mode_str);
}
}
}
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 14/27] ip: iplink_ipoib.c: add json output support
From: Julien Fortin @ 2017-08-17 17:36 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema:
{
"key": {
"type": "string",
"attr": "IFLA_IPOIB_PKEY"
},
"mode": {
"type": "string",
"attr": "IFLA_IPOIB_PKEY"
},
"umcast": {
"type": "string",
"attr": "IFLA_IPOIB_UMCAST"
}
}
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/iplink_ipoib.c | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)
diff --git a/ip/iplink_ipoib.c b/ip/iplink_ipoib.c
index 86dc65ca..e69bda0e 100644
--- a/ip/iplink_ipoib.c
+++ b/ip/iplink_ipoib.c
@@ -91,23 +91,43 @@ static void ipoib_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
RTA_PAYLOAD(tb[IFLA_IPOIB_PKEY]) < sizeof(__u16))
return;
- fprintf(f, "pkey %#.4x ", rta_getattr_u16(tb[IFLA_IPOIB_PKEY]));
+ __u16 pkey = rta_getattr_u16(tb[IFLA_IPOIB_PKEY]);
+
+ if (is_json_context()) {
+ SPRINT_BUF(b1);
+
+ snprintf(b1, sizeof(b1), "%#.4x", pkey);
+ print_string(PRINT_JSON, "key", NULL, b1);
+ } else {
+ fprintf(f, "pkey %#.4x ", pkey);
+ }
if (!tb[IFLA_IPOIB_MODE] ||
RTA_PAYLOAD(tb[IFLA_IPOIB_MODE]) < sizeof(__u16))
return;
mode = rta_getattr_u16(tb[IFLA_IPOIB_MODE]);
- fprintf(f, "mode %s ",
+
+ const char *mode_str =
mode == IPOIB_MODE_DATAGRAM ? "datagram" :
- mode == IPOIB_MODE_CONNECTED ? "connected" :
- "unknown");
+ mode == IPOIB_MODE_CONNECTED ? "connected" : "unknown";
+
+ print_string(PRINT_ANY, "mode", "mode %s ", mode_str);
if (!tb[IFLA_IPOIB_UMCAST] ||
RTA_PAYLOAD(tb[IFLA_IPOIB_UMCAST]) < sizeof(__u16))
return;
- fprintf(f, "umcast %.4x ", rta_getattr_u16(tb[IFLA_IPOIB_UMCAST]));
+ __u16 umcast = rta_getattr_u16(tb[IFLA_IPOIB_UMCAST]);
+
+ if (is_json_context()) {
+ SPRINT_BUF(b1);
+
+ snprintf(b1, sizeof(b1), "%.4x", umcast);
+ print_string(PRINT_JSON, "umcast", NULL, b1);
+ } else {
+ fprintf(f, "umcast %.4x ", umcast);
+ }
}
static void ipoib_print_help(struct link_util *lu, int argc, char **argv,
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 13/27] ip: iplink_geneve.c: add json output support
From: Julien Fortin @ 2017-08-17 17:36 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema:
{
"id": {
"type": "uint",
"attr": "IFLA_GENEVE_ID"
},
"remote": {
"type": "string",
"attr": "IFLA_GENEVE_REMOTE"
},
"remote6": {
"type": "string",
"attr": "IFLA_GENEVE_REMOTE6"
},
"ttl": {
"type": "int",
"attr": "IFLA_GENEVE_TTL"
},
"tos": {
"type": "string",
"attr": "IFLA_GENEVE_TOS"
},
"label": {
"type": "string",
"attr": "IFLA_GENEVE_LABEL"
},
"port": {
"type": "uint",
"attr": "IFLA_GENEVE_PORT"
},
"collect_metadata": {
"type": "bool",
"attr": "IFLA_GENEVE_COLLECT_METADATA"
},
"udp_csum": {
"type": "bool",
"attr": "IFLA_GENEVE_UDP_CSUM"
},
"udp_zero_csum6_tx": {
"type": "bool",
"attr": "IFLA_GENEVE_UDP_ZERO_CSUM6_TX"
},
"udp_zero_csum6_rx": {
"type": "bool",
"attr": "IFLA_GENEVE_UDP_ZERO_CSUM6_RX"
}
}
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/iplink_geneve.c | 86 +++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 63 insertions(+), 23 deletions(-)
diff --git a/ip/iplink_geneve.c b/ip/iplink_geneve.c
index 594a3e59..f0f1d1c7 100644
--- a/ip/iplink_geneve.c
+++ b/ip/iplink_geneve.c
@@ -237,22 +237,28 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
return;
vni = rta_getattr_u32(tb[IFLA_GENEVE_ID]);
- fprintf(f, "id %u ", vni);
+ print_uint(PRINT_ANY, "id", "id %u ", vni);
if (tb[IFLA_GENEVE_REMOTE]) {
__be32 addr = rta_getattr_u32(tb[IFLA_GENEVE_REMOTE]);
if (addr)
- fprintf(f, "remote %s ",
- format_host(AF_INET, 4, &addr));
+ print_string(PRINT_ANY,
+ "remote",
+ "remote %s ",
+ format_host(AF_INET, 4, &addr));
} else if (tb[IFLA_GENEVE_REMOTE6]) {
struct in6_addr addr;
memcpy(&addr, RTA_DATA(tb[IFLA_GENEVE_REMOTE6]), sizeof(struct in6_addr));
if (!IN6_IS_ADDR_UNSPECIFIED(&addr)) {
if (!IN6_IS_ADDR_MULTICAST(&addr))
- fprintf(f, "remote %s ",
- format_host(AF_INET6, sizeof(struct in6_addr), &addr));
+ print_string(PRINT_ANY,
+ "remote6",
+ "remote %s ",
+ format_host(AF_INET6,
+ sizeof(struct in6_addr),
+ &addr));
}
}
@@ -260,47 +266,81 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
__u8 ttl = rta_getattr_u8(tb[IFLA_GENEVE_TTL]);
if (ttl)
- fprintf(f, "ttl %d ", ttl);
+ print_int(PRINT_ANY, "ttl", "ttl %d ", ttl);
}
if (tb[IFLA_GENEVE_TOS] &&
(tos = rta_getattr_u8(tb[IFLA_GENEVE_TOS]))) {
- if (tos == 1)
- fprintf(f, "tos inherit ");
- else
- fprintf(f, "tos %#x ", tos);
+ if (is_json_context()) {
+ print_0xhex(PRINT_JSON, "tos", "%#x", tos);
+ } else {
+ if (tos == 1) {
+ print_string(PRINT_FP,
+ "tos",
+ "tos %s ",
+ "inherit");
+ } else {
+ fprintf(f, "tos %#x ", tos);
+ }
+ }
}
if (tb[IFLA_GENEVE_LABEL]) {
__u32 label = rta_getattr_u32(tb[IFLA_GENEVE_LABEL]);
if (label)
- fprintf(f, "flowlabel %#x ", ntohl(label));
+ print_0xhex(PRINT_ANY,
+ "label",
+ "flowlabel %#x ",
+ ntohl(label));
}
if (tb[IFLA_GENEVE_PORT])
- fprintf(f, "dstport %u ",
- rta_getattr_be16(tb[IFLA_GENEVE_PORT]));
+ print_uint(PRINT_ANY,
+ "port",
+ "dstport %u ",
+ rta_getattr_be16(tb[IFLA_GENEVE_PORT]));
if (tb[IFLA_GENEVE_COLLECT_METADATA])
- fputs("external ", f);
+ print_bool(PRINT_ANY, "collect_metadata", "external ", true);
if (tb[IFLA_GENEVE_UDP_CSUM]) {
- if (!rta_getattr_u8(tb[IFLA_GENEVE_UDP_CSUM]))
- fputs("no", f);
- fputs("udpcsum ", f);
+ if (is_json_context()) {
+ print_bool(PRINT_JSON,
+ "udp_csum",
+ NULL,
+ rta_getattr_u8(tb[IFLA_GENEVE_UDP_CSUM]));
+ } else {
+ if (!rta_getattr_u8(tb[IFLA_GENEVE_UDP_CSUM]))
+ fputs("no", f);
+ fputs("udpcsum ", f);
+ }
}
if (tb[IFLA_GENEVE_UDP_ZERO_CSUM6_TX]) {
- if (!rta_getattr_u8(tb[IFLA_GENEVE_UDP_ZERO_CSUM6_TX]))
- fputs("no", f);
- fputs("udp6zerocsumtx ", f);
+ if (is_json_context()) {
+ print_bool(PRINT_JSON,
+ "udp_zero_csum6_tx",
+ NULL,
+ rta_getattr_u8(tb[IFLA_GENEVE_UDP_ZERO_CSUM6_TX]));
+ } else {
+ if (!rta_getattr_u8(tb[IFLA_GENEVE_UDP_ZERO_CSUM6_TX]))
+ fputs("no", f);
+ fputs("udp6zerocsumtx ", f);
+ }
}
if (tb[IFLA_GENEVE_UDP_ZERO_CSUM6_RX]) {
- if (!rta_getattr_u8(tb[IFLA_GENEVE_UDP_ZERO_CSUM6_RX]))
- fputs("no", f);
- fputs("udp6zerocsumrx ", f);
+ if (is_json_context()) {
+ print_bool(PRINT_JSON,
+ "udp_zero_csum6_rx",
+ NULL,
+ rta_getattr_u8(tb[IFLA_GENEVE_UDP_ZERO_CSUM6_RX]));
+ } else {
+ if (!rta_getattr_u8(tb[IFLA_GENEVE_UDP_ZERO_CSUM6_RX]))
+ fputs("no", f);
+ fputs("udp6zerocsumrx ", f);
+ }
}
}
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 12/27] ip: iplink_can.c: add json output support
From: Julien Fortin @ 2017-08-17 17:35 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema: IFLA_INFO_DATA
{
"ctrlmode": {
"type": "array",
"attr": "IFLA_CAN_CTRLMODE",
"array": [
{
"type": "string"
}
]
},
"state": {
"type": "string",
"attr": "IFLA_CAN_STATE"
},
"berr_counter": {
"type": "dict",
"attr": "IFLA_CAN_BERR_COUNTER",
"dict": {
"tx": {
"type": "int"
},
"rx": {
"type": "int"
}
}
},
"restart_ms": {
"type": "int",
"attr": "IFLA_CAN_RESTART_MS"
},
"bittiming": {
"type": "dict",
"attr": "IFLA_CAN_BITTIMING",
"dict": {
"bitrate": {
"type": "int"
},
"sample_point": {
"type": "float"
},
"tq": {
"type": "int"
},
"prop_seg": {
"type": "int"
},
"phase_seg1": {
"type": "int"
},
"phase_seg2": {
"type": "int"
},
"sjw": {
"type": "int"
}
}
},
"bittiming_const": {
"type": "dict",
"attr": "IFLA_CAN_BITTIMING_CONST",
"dict": {
"name": {
"type": "string"
},
"tseg1": {
"type": "dict",
"dict": {
"min": {
"type": "int"
},
"max": {
"type": "int"
}
}
},
"tseg2": {
"type": "dict",
"dict": {
"min": {
"type": "int"
},
"max": {
"type": "int"
}
}
},
"sjw": {
"type": "dict",
"dict": {
"min": {
"type": "int"
},
"max": {
"type": "int"
}
}
},
"brp": {
"type": "dict",
"dict": {
"min": {
"type": "int"
},
"max": {
"type": "int"
}
}
},
"brp_inc": {
"type": "int"
}
}
},
"bittiming_bitrate": {
"type": "uint",
"attr": "IFLA_CAN_BITTIMING"
},
"bitrate_const": {
"type": "array",
"attr": "IFLA_CAN_BITRATE_CONST",
"array": [
{
"type": "uint"
}
]
},
"data_bittiming": {
"type": "dict",
"attr": "IFLA_CAN_DATA_BITTIMING",
"dict": {
"bitrate": {
"type": "int"
},
"sample_point": {
"type": "float"
},
"tq": {
"type": "int"
},
"prop_seg": {
"type": "int"
},
"phase_seg1": {
"type": "int"
},
"phase_seg2": {
"type": "int"
},
"sjw": {
"type": "int"
}
}
},
"data_bittiming_const": {
"type": "dict",
"attr": "IFLA_CAN_DATA_BITTIMING_CONST",
"dict": {
"name": {
"type": "string"
},
"tseg1": {
"type": "dict",
"dict": {
"min": {
"type": "int"
},
"max": {
"type": "int"
}
}
},
"tseg2": {
"type": "dict",
"dict": {
"min": {
"type": "int"
},
"max": {
"type": "int"
}
}
},
"sjw": {
"type": "dict",
"dict": {
"min": {
"type": "int"
},
"max": {
"type": "int"
}
}
},
"brp": {
"type": "dict",
"dict": {
"min": {
"type": "int"
},
"max": {
"type": "int"
}
}
},
"brp_inc": {
"type": "int"
}
}
},
"data_bittiming_bitrate": {
"type": "uint",
"attr": "IFLA_CAN_DATA_BITTIMING"
},
"data_bitrate_const": {
"type": "array",
"attr": "IFLA_CAN_DATA_BITRATE_CONST",
"array": [
{
"type": "uint"
}
]
},
"termination": {
"type": "unsigned short",
"attr": "IFLA_CAN_TERMINATION"
},
"termination_const": {
"type": "array",
"attr": "IFLA_CAN_TERMINATION_CONST",
"array": [
{
"type": "unsigned short"
}
]
},
"clock": {
"type": "int",
"attr": "IFLA_CAN_CLOCK"
}
}
IFLA_INFO_XSTATS
{
"restarts": {
"type": "int"
},
"bus_error": {
"type": "int"
},
"arbitration_lost": {
"type": "int"
},
"error_warning": {
"type": "int"
},
"error_passive": {
"type": "int"
},
"bus_off": {
"type": "int"
}
}
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/iplink_can.c | 282 ++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 211 insertions(+), 71 deletions(-)
diff --git a/ip/iplink_can.c b/ip/iplink_can.c
index 5df56b2b..f415558a 100644
--- a/ip/iplink_can.c
+++ b/ip/iplink_can.c
@@ -89,11 +89,11 @@ static void set_ctrlmode(char *name, char *arg,
static void print_ctrlmode(FILE *f, __u32 cm)
{
- fprintf(f, "<");
-#define _PF(cmflag, cmname) \
- if (cm & cmflag) { \
- cm &= ~cmflag; \
- fprintf(f, "%s%s", cmname, cm ? "," : ""); \
+ open_json_array(PRINT_ANY, is_json_context() ? "ctrlmode" : "<");
+#define _PF(cmflag, cmname) \
+ if (cm & cmflag) { \
+ cm &= ~cmflag; \
+ print_string(PRINT_ANY, NULL, cm ? "%s," : "%s", cmname); \
}
_PF(CAN_CTRLMODE_LOOPBACK, "LOOPBACK");
_PF(CAN_CTRLMODE_LISTENONLY, "LISTEN-ONLY");
@@ -105,8 +105,8 @@ static void print_ctrlmode(FILE *f, __u32 cm)
_PF(CAN_CTRLMODE_PRESUME_ACK, "PRESUME-ACK");
#undef _PF
if (cm)
- fprintf(f, "%x", cm);
- fprintf(f, "> ");
+ print_hex(PRINT_ANY, NULL, "%x", cm);
+ close_json_array(PRINT_ANY, "> ");
}
static int can_parse_opt(struct link_util *lu, int argc, char **argv,
@@ -260,6 +260,14 @@ static const char *can_state_names[] = {
[CAN_STATE_SLEEPING] = "SLEEPING"
};
+static void can_print_json_timing_min_max(const char *attr, int min, int max)
+{
+ open_json_object(attr);
+ print_int(PRINT_JSON, "min", NULL, min);
+ print_int(PRINT_JSON, "max", NULL, max);
+ close_json_object();
+}
+
static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
if (!tb)
@@ -275,32 +283,64 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_CAN_STATE]) {
uint32_t state = rta_getattr_u32(tb[IFLA_CAN_STATE]);
- fprintf(f, "state %s ", state <= CAN_STATE_MAX ?
- can_state_names[state] : "UNKNOWN");
+ if (state <= CAN_STATE_MAX)
+ print_string(PRINT_ANY, "state", "state %s ",
+ can_state_names[state]);
+ else
+ print_null(PRINT_ANY, "state", "state UNKNOWN", NULL);
}
if (tb[IFLA_CAN_BERR_COUNTER]) {
struct can_berr_counter *bc =
RTA_DATA(tb[IFLA_CAN_BERR_COUNTER]);
- fprintf(f, "(berr-counter tx %d rx %d) ", bc->txerr, bc->rxerr);
+ if (is_json_context()) {
+ open_json_object("berr_counter");
+ print_int(PRINT_JSON, "tx", NULL, bc->txerr);
+ print_int(PRINT_JSON, "rx", NULL, bc->rxerr);
+ close_json_object();
+ } else {
+ fprintf(f, "(berr-counter tx %d rx %d) ",
+ bc->txerr, bc->rxerr);
+ }
}
if (tb[IFLA_CAN_RESTART_MS]) {
__u32 *restart_ms = RTA_DATA(tb[IFLA_CAN_RESTART_MS]);
- fprintf(f, "restart-ms %d ", *restart_ms);
+ print_int(PRINT_ANY,
+ "restart_ms",
+ "restart-ms %d ",
+ *restart_ms);
}
/* bittiming is irrelevant if fixed bitrate is defined */
if (tb[IFLA_CAN_BITTIMING] && !tb[IFLA_CAN_BITRATE_CONST]) {
struct can_bittiming *bt = RTA_DATA(tb[IFLA_CAN_BITTIMING]);
- fprintf(f, "\n bitrate %d sample-point %.3f ",
- bt->bitrate, (float)bt->sample_point / 1000.);
- fprintf(f, "\n tq %d prop-seg %d phase-seg1 %d phase-seg2 %d sjw %d",
- bt->tq, bt->prop_seg, bt->phase_seg1, bt->phase_seg2,
- bt->sjw);
+ if (is_json_context()) {
+ open_json_object("bittiming");
+ print_int(PRINT_ANY, "bitrate", NULL, bt->bitrate);
+ jsonw_float_field_fmt(get_json_writer(),
+ "sample_point", "%.3f",
+ (float) bt->sample_point / 1000.);
+ print_int(PRINT_ANY, "tq", NULL, bt->tq);
+ print_int(PRINT_ANY, "prop_seg", NULL, bt->prop_seg);
+ print_int(PRINT_ANY, "phase_seg1",
+ NULL, bt->phase_seg1);
+ print_int(PRINT_ANY, "phase_seg2",
+ NULL, bt->phase_seg2);
+ print_int(PRINT_ANY, "sjw", NULL, bt->sjw);
+ close_json_object();
+ } else {
+ fprintf(f, "\n bitrate %d sample-point %.3f ",
+ bt->bitrate, (float) bt->sample_point / 1000.);
+ fprintf(f,
+ "\n tq %d prop-seg %d phase-seg1 %d phase-seg2 %d sjw %d",
+ bt->tq, bt->prop_seg,
+ bt->phase_seg1, bt->phase_seg2,
+ bt->sjw);
+ }
}
/* bittiming const is irrelevant if fixed bitrate is defined */
@@ -308,40 +348,68 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
struct can_bittiming_const *btc =
RTA_DATA(tb[IFLA_CAN_BITTIMING_CONST]);
- fprintf(f, "\n %s: tseg1 %d..%d tseg2 %d..%d "
- "sjw 1..%d brp %d..%d brp-inc %d",
- btc->name, btc->tseg1_min, btc->tseg1_max,
- btc->tseg2_min, btc->tseg2_max, btc->sjw_max,
- btc->brp_min, btc->brp_max, btc->brp_inc);
+ if (is_json_context()) {
+ open_json_object("bittiming_const");
+ print_string(PRINT_JSON, "name", NULL, btc->name);
+ can_print_json_timing_min_max("tseg1",
+ btc->tseg1_min,
+ btc->tseg1_max);
+ can_print_json_timing_min_max("tseg2",
+ btc->tseg2_min,
+ btc->tseg2_max);
+ can_print_json_timing_min_max("sjw", 1, btc->sjw_max);
+ can_print_json_timing_min_max("brp",
+ btc->brp_min,
+ btc->brp_max);
+ print_int(PRINT_JSON, "brp_inc", NULL, btc->brp_inc);
+ close_json_object();
+ } else {
+ fprintf(f, "\n %s: tseg1 %d..%d tseg2 %d..%d "
+ "sjw 1..%d brp %d..%d brp-inc %d",
+ btc->name, btc->tseg1_min, btc->tseg1_max,
+ btc->tseg2_min, btc->tseg2_max, btc->sjw_max,
+ btc->brp_min, btc->brp_max, btc->brp_inc);
+ }
}
if (tb[IFLA_CAN_BITRATE_CONST]) {
__u32 *bitrate_const = RTA_DATA(tb[IFLA_CAN_BITRATE_CONST]);
int bitrate_cnt = RTA_PAYLOAD(tb[IFLA_CAN_BITRATE_CONST]) /
- sizeof(*bitrate_const);
+ sizeof(*bitrate_const);
int i;
__u32 bitrate = 0;
if (tb[IFLA_CAN_BITTIMING]) {
struct can_bittiming *bt =
- RTA_DATA(tb[IFLA_CAN_BITTIMING]);
+ RTA_DATA(tb[IFLA_CAN_BITTIMING]);
bitrate = bt->bitrate;
}
- fprintf(f, "\n bitrate %u", bitrate);
- fprintf(f, "\n [");
+ if (is_json_context()) {
+ print_uint(PRINT_JSON,
+ "bittiming_bitrate",
+ NULL, bitrate);
+ open_json_array(PRINT_JSON, "bitrate_const");
+ for (i = 0; i < bitrate_cnt; ++i)
+ print_uint(PRINT_JSON, NULL, NULL,
+ bitrate_const[i]);
+ close_json_array(PRINT_JSON, NULL);
+ } else {
+ fprintf(f, "\n bitrate %u", bitrate);
+ fprintf(f, "\n [");
+
+ for (i = 0; i < bitrate_cnt - 1; ++i) {
+ /* This will keep lines below 80 signs */
+ if (!(i % 6) && i)
+ fprintf(f, "\n ");
+
+ fprintf(f, "%8u, ", bitrate_const[i]);
+ }
- for (i = 0; i < bitrate_cnt - 1; ++i) {
- /* This will keep lines below 80 signs */
if (!(i % 6) && i)
fprintf(f, "\n ");
-
- fprintf(f, "%8u, ", bitrate_const[i]);
+ fprintf(f, "%8u ]", bitrate_const[i]);
}
-
- if (!(i % 6) && i)
- fprintf(f, "\n ");
- fprintf(f, "%8u ]", bitrate_const[i]);
}
/* data bittiming is irrelevant if fixed bitrate is defined */
@@ -349,12 +417,30 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
struct can_bittiming *dbt =
RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING]);
- fprintf(f, "\n dbitrate %d dsample-point %.3f ",
- dbt->bitrate, (float)dbt->sample_point / 1000.);
- fprintf(f, "\n dtq %d dprop-seg %d dphase-seg1 %d "
- "dphase-seg2 %d dsjw %d",
- dbt->tq, dbt->prop_seg, dbt->phase_seg1,
- dbt->phase_seg2, dbt->sjw);
+ if (is_json_context()) {
+ open_json_object("data_bittiming");
+ print_int(PRINT_JSON, "bitrate", NULL, dbt->bitrate);
+ jsonw_float_field_fmt(get_json_writer(),
+ "sample_point",
+ "%.3f",
+ (float) dbt->sample_point / 1000.);
+ print_int(PRINT_JSON, "tq", NULL, dbt->tq);
+ print_int(PRINT_JSON, "prop_seg", NULL, dbt->prop_seg);
+ print_int(PRINT_JSON, "phase_seg1",
+ NULL, dbt->phase_seg1);
+ print_int(PRINT_JSON, "phase_seg2",
+ NULL, dbt->phase_seg2);
+ print_int(PRINT_JSON, "sjw", NULL, dbt->sjw);
+ close_json_object();
+ } else {
+ fprintf(f, "\n dbitrate %d dsample-point %.3f ",
+ dbt->bitrate,
+ (float) dbt->sample_point / 1000.);
+ fprintf(f, "\n dtq %d dprop-seg %d dphase-seg1 %d "
+ "dphase-seg2 %d dsjw %d",
+ dbt->tq, dbt->prop_seg, dbt->phase_seg1,
+ dbt->phase_seg2, dbt->sjw);
+ }
}
/* data bittiming const is irrelevant if fixed bitrate is defined */
@@ -363,63 +449,102 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
struct can_bittiming_const *dbtc =
RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING_CONST]);
- fprintf(f, "\n %s: dtseg1 %d..%d dtseg2 %d..%d "
- "dsjw 1..%d dbrp %d..%d dbrp-inc %d",
- dbtc->name, dbtc->tseg1_min, dbtc->tseg1_max,
- dbtc->tseg2_min, dbtc->tseg2_max, dbtc->sjw_max,
- dbtc->brp_min, dbtc->brp_max, dbtc->brp_inc);
+ if (is_json_context()) {
+ open_json_object("data_bittiming_const");
+ print_string(PRINT_JSON, "name", NULL, dbtc->name);
+ can_print_json_timing_min_max("tseg1",
+ dbtc->tseg1_min,
+ dbtc->tseg1_max);
+ can_print_json_timing_min_max("tseg2",
+ dbtc->tseg2_min,
+ dbtc->tseg2_max);
+ can_print_json_timing_min_max("sjw", 1, dbtc->sjw_max);
+ can_print_json_timing_min_max("brp",
+ dbtc->brp_min,
+ dbtc->brp_max);
+
+ print_int(PRINT_JSON, "brp_inc", NULL, dbtc->brp_inc);
+ close_json_object();
+ } else {
+ fprintf(f, "\n %s: dtseg1 %d..%d dtseg2 %d..%d "
+ "dsjw 1..%d dbrp %d..%d dbrp-inc %d",
+ dbtc->name, dbtc->tseg1_min, dbtc->tseg1_max,
+ dbtc->tseg2_min, dbtc->tseg2_max, dbtc->sjw_max,
+ dbtc->brp_min, dbtc->brp_max, dbtc->brp_inc);
+ }
}
if (tb[IFLA_CAN_DATA_BITRATE_CONST]) {
__u32 *dbitrate_const =
- RTA_DATA(tb[IFLA_CAN_DATA_BITRATE_CONST]);
+ RTA_DATA(tb[IFLA_CAN_DATA_BITRATE_CONST]);
int dbitrate_cnt =
- RTA_PAYLOAD(tb[IFLA_CAN_DATA_BITRATE_CONST]) /
- sizeof(*dbitrate_const);
+ RTA_PAYLOAD(tb[IFLA_CAN_DATA_BITRATE_CONST]) /
+ sizeof(*dbitrate_const);
int i;
__u32 dbitrate = 0;
if (tb[IFLA_CAN_DATA_BITTIMING]) {
struct can_bittiming *dbt =
- RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING]);
+ RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING]);
dbitrate = dbt->bitrate;
}
- fprintf(f, "\n dbitrate %u", dbitrate);
- fprintf(f, "\n [");
+ if (is_json_context()) {
+ print_uint(PRINT_JSON, "data_bittiming_bitrate",
+ NULL, dbitrate);
+ open_json_array(PRINT_JSON, "data_bitrate_const");
+ for (i = 0; i < dbitrate_cnt; ++i)
+ print_uint(PRINT_JSON, NULL, NULL,
+ dbitrate_const[i]);
+ close_json_array(PRINT_JSON, NULL);
+ } else {
+ fprintf(f, "\n dbitrate %u", dbitrate);
+ fprintf(f, "\n [");
+
+ for (i = 0; i < dbitrate_cnt - 1; ++i) {
+ /* This will keep lines below 80 signs */
+ if (!(i % 6) && i)
+ fprintf(f, "\n ");
+
+ fprintf(f, "%8u, ", dbitrate_const[i]);
+ }
- for (i = 0; i < dbitrate_cnt - 1; ++i) {
- /* This will keep lines below 80 signs */
if (!(i % 6) && i)
fprintf(f, "\n ");
-
- fprintf(f, "%8u, ", dbitrate_const[i]);
+ fprintf(f, "%8u ]", dbitrate_const[i]);
}
-
- if (!(i % 6) && i)
- fprintf(f, "\n ");
- fprintf(f, "%8u ]", dbitrate_const[i]);
}
if (tb[IFLA_CAN_TERMINATION_CONST] && tb[IFLA_CAN_TERMINATION]) {
__u16 *trm = RTA_DATA(tb[IFLA_CAN_TERMINATION]);
__u16 *trm_const = RTA_DATA(tb[IFLA_CAN_TERMINATION_CONST]);
int trm_cnt = RTA_PAYLOAD(tb[IFLA_CAN_TERMINATION_CONST]) /
- sizeof(*trm_const);
+ sizeof(*trm_const);
int i;
- fprintf(f, "\n termination %hu [ ", *trm);
+ if (is_json_context()) {
+ print_hu(PRINT_JSON, "termination", NULL, *trm);
+ open_json_array(PRINT_JSON, "termination_const");
+ for (i = 0; i < trm_cnt; ++i)
+ print_hu(PRINT_JSON, NULL, NULL, trm_const[i]);
+ close_json_array(PRINT_JSON, NULL);
+ } else {
+ fprintf(f, "\n termination %hu [ ", *trm);
- for (i = 0; i < trm_cnt - 1; ++i)
- fprintf(f, "%hu, ", trm_const[i]);
+ for (i = 0; i < trm_cnt - 1; ++i)
+ fprintf(f, "%hu, ", trm_const[i]);
- fprintf(f, "%hu ]", trm_const[i]);
+ fprintf(f, "%hu ]", trm_const[i]);
+ }
}
if (tb[IFLA_CAN_CLOCK]) {
struct can_clock *clock = RTA_DATA(tb[IFLA_CAN_CLOCK]);
- fprintf(f, "\n clock %d", clock->freq);
+ print_int(PRINT_ANY,
+ "clock",
+ "\n clock %d",
+ clock->freq);
}
}
@@ -431,17 +556,32 @@ static void can_print_xstats(struct link_util *lu,
if (xstats && RTA_PAYLOAD(xstats) == sizeof(*stats)) {
stats = RTA_DATA(xstats);
- fprintf(f, "\n re-started bus-errors arbit-lost "
- "error-warn error-pass bus-off");
- fprintf(f, "\n %-10d %-10d %-10d %-10d %-10d %-10d",
- stats->restarts, stats->bus_error,
- stats->arbitration_lost, stats->error_warning,
- stats->error_passive, stats->bus_off);
+
+ if (is_json_context()) {
+ print_int(PRINT_JSON, "restarts",
+ NULL, stats->restarts);
+ print_int(PRINT_JSON, "bus_error",
+ NULL, stats->bus_error);
+ print_int(PRINT_JSON, "arbitration_lost",
+ NULL, stats->arbitration_lost);
+ print_int(PRINT_JSON, "error_warning",
+ NULL, stats->error_warning);
+ print_int(PRINT_JSON, "error_passive",
+ NULL, stats->error_passive);
+ print_int(PRINT_JSON, "bus_off", NULL, stats->bus_off);
+ } else {
+ fprintf(f, "\n re-started bus-errors arbit-lost "
+ "error-warn error-pass bus-off");
+ fprintf(f, "\n %-10d %-10d %-10d %-10d %-10d %-10d",
+ stats->restarts, stats->bus_error,
+ stats->arbitration_lost, stats->error_warning,
+ stats->error_passive, stats->bus_off);
+ }
}
}
static void can_print_help(struct link_util *lu, int argc, char **argv,
- FILE *f)
+ FILE *f)
{
print_usage(f);
}
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 11/27] ip: iplink_bridge_slave.c: add json output support
From: Julien Fortin @ 2017-08-17 17:35 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema:
bridge_slave: IFLA_INFO_SLAVE_DATA
{
"state": {
"type": "string",
"attr": "IFLA_BRPORT_STATE",
"mutually_exclusive": {
"state_index": {
"type": "uint",
"comment": "if (state > BR_STATE_BLOCKING)"
}
}
},
"priority": {
"type": "int",
"attr": "IFLA_BRPORT_PRIORITY"
},
"cost": {
"type": "int",
"attr": "IFLA_BRPORT_COST"
},
"mode": {
"type": "bool",
"attr": "IFLA_BRPORT_MODE"
},
"guard": {
"type": "bool",
"attr": "IFLA_BRPORT_GUARD"
},
"protect": {
"type": "bool",
"attr": "IFLA_BRPORT_PROTECT"
},
"fast_leave": {
"type": "bool",
"attr": "IFLA_BRPORT_FAST_LEAVE"
},
"learning": {
"type": "bool",
"attr": "IFLA_BRPORT_LEARNING"
},
"unicast_flood": {
"type": "bool",
"attr": "IFLA_BRPORT_UNICAST_FLOOD"
},
"id": {
"type": "string",
"attr": "IFLA_BRPORT_ID"
},
"no": {
"type": "string",
"attr": "IFLA_BRPORT_NO"
},
"designated_port": {
"type": "uint",
"attr": "IFLA_BRPORT_DESIGNATED_PORT"
},
"designated_cost": {
"type": "uint",
"attr": "IFLA_BRPORT_DESIGNATED_COST"
},
"bridge_id": {
"type": "string",
"attr": "IFLA_BRPORT_BRIDGE_ID"
},
"root_id": {
"type": "string",
"attr": "IFLA_BRPORT_ROOT_ID"
},
"hold_timer": {
"type": "float",
"attr": "IFLA_BRPORT_HOLD_TIMER"
},
"message_age_timer": {
"type": "float",
"attr": "IFLA_BRPORT_MESSAGE_AGE_TIMER"
},
"forward_delay_timer": {
"type": "float",
"attr": "IFLA_BRPORT_FORWARD_DELAY_TIMER"
},
"topology_change_ack": {
"type": "uint",
"attr": "IFLA_BRPORT_TOPOLOGY_CHANGE_ACK"
},
"config_pending": {
"type": "uint",
"attr": "IFLA_BRPORT_CONFIG_PENDING"
},
"proxyarp": {
"type": "bool",
"attr": "IFLA_BRPORT_PROXYARP"
},
"proxyarp_wifi": {
"type": "bool",
"attr": "IFLA_BRPORT_PROXYARP_WIFI"
},
"multicast_router": {
"type": "uint",
"attr": "IFLA_BRPORT_MULTICAST_ROUTER"
},
"mcast_flood": {
"type": "bool",
"attr": "IFLA_BRPORT_MCAST_FLOOD"
}
}
$ ip link add dev br42 type bridge
$ ip link add dev bond42 type bond
$ ip link set dev bond42 master br42
$ ip link set dev bond42 up
$ ip link set dev br42 up
$ ip -details link show
$ ip -details link show
15: br42: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state
UP mode DEFAULT group default
link/ether 22:8f:91:bb:9f:09 brd ff:ff:ff:ff:ff:ff promiscuity 0
bridge forward_delay 1500 hello_time 200 max_age 2000 ageing_time
30000 stp_state 0 priority 32768 vlan_filtering 0 vlan_protocol 802.1Q
bridge_id 8000.22:8f:91:bb:9f:9 designated_root 8000.22:8f:91:bb:9f:9
root_port 0 root_path_cost 0 topology_change 0 topology_change_detected 0
hello_timer 0.00 tcn_timer 0.00 topology_change_timer 0.00
gc_timer 199.11 vlan_default_pvid 1 vlan_stats_enabled 0 group_fwd_mask 0
group_address 01:80:c2:00:00:00 mcast_snooping 1 mcast_router 1
mcast_query_use_ifaddr 0 mcast_querier 0 mcast_hash_elasticity 4096
mcast_hash_max 4096 mcast_last_member_count 2 mcast_startup_query_count 2
mcast_last_member_interval 100 mcast_membership_interval 26000
mcast_querier_interval 25500 mcast_query_interval 12500
mcast_query_response_interval 1000 mcast_startup_query_interval 3125
mcast_stats_enabled 0 mcast_igmp_version 2 mcast_mld_version 1
nf_call_iptables 0 nf_call_ip6tables 0 nf_call_arptables 0 addrgenmode
eui64
16: bond42: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc
noqueue master br42 state UNKNOWN mode DEFAULT group default
link/ether 22:8f:91:bb:9f:09 brd ff:ff:ff:ff:ff:ff promiscuity 1
bond mode 802.3ad miimon 100 updelay 0 downdelay 0 use_carrier 1
arp_interval 0 arp_validate none arp_all_targets any primary_reselect
always fail_over_mac none xmit_hash_policy layer3+4 resend_igmp 1
num_grat_arp 1 all_slaves_active 0 min_links 1 lp_interval 1
packets_per_slave 1 lacp_rate fast ad_select stable ad_actor_sys_prio
65535 ad_user_port_key 0 ad_actor_system 00:00:00:00:00:00
bridge_slave state forwarding priority 8 cost 100 hairpin off guard
off root_block off fastleave off learning on flood on port_id 0x8001
port_no 0x1 designated_port 32769 designated_cost 0 designated_bridge
8000.22:8f:91:bb:9f:9 designated_root 8000.22:8f:91:bb:9f:9 hold_timer
0.00 message_age_timer 0.00 forward_delay_timer 0.00
topology_change_ack 0 config_pending 0 proxy_arp off proxy_arp_wifi off
mcast_router 1 mcast_fast_leave off mcast_flood on neigh_suppress off
addrgenmode eui64
$ ip -details -json link show
[{
"ifindex": 15,
"ifname": "br42",
"flags": ["BROADCAST","MULTICAST","UP","LOWER_UP"],
"mtu": 1500,
"qdisc": "noqueue",
"operstate": "UP",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "ether",
"address": "22:8f:91:bb:9f:09",
"broadcast": "ff:ff:ff:ff:ff:ff",
"promiscuity": 0,
"linkinfo": {
"info_kind": "bridge",
"info_data": {
"forward_delay": 1500,
"hello_time": 200,
"max_age": 2000,
"ageing_time": 30000,
"stp_state": 0,
"priority": 32768,
"vlan_filtering": 0,
"vlan_protocol": "802.1Q",
"bridge_id": "8000.22:8f:91:bb:9f:9",
"root_id": "8000.22:8f:91:bb:9f:9",
"root_port": 0,
"root_path_cost": 0,
"topology_change": 0,
"topology_change_detected": 0,
"hello_timer": 0.00,
"tcn_timer": 0.00,
"topology_change_timer": 0.00,
"gc_timer": 298.27,
"vlan_default_pvid": 1,
"vlan_stats_enabled": 0,
"group_fwd_mask": "0",
"group_addr": "01:80:c2:00:00:00",
"mcast_snooping": 1,
"mcast_router": 1,
"mcast_query_use_ifaddr": 0,
"mcast_querier": 0,
"mcast_hash_elasticity": 4096,
"mcast_hash_max": 4096,
"mcast_last_member_cnt": 2,
"mcast_startup_query_cnt": 2,
"mcast_last_member_intvl": 100,
"mcast_membership_intvl": 26000,
"mcast_querier_intvl": 25500,
"mcast_query_intvl": 12500,
"mcast_query_response_intvl": 1000,
"mcast_startup_query_intvl": 3125,
"mcast_stats_enabled": 0,
"mcast_igmp_version": 2,
"mcast_mld_version": 1,
"nf_call_iptables": 0,
"nf_call_ip6tables": 0,
"nf_call_arptables": 0
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
},{
"ifindex": 16,
"ifname": "bond42",
"flags": ["BROADCAST","MULTICAST","MASTER","UP","LOWER_UP"],
"mtu": 1500,
"qdisc": "noqueue",
"master": "br42",
"operstate": "UNKNOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "ether",
"address": "22:8f:91:bb:9f:09",
"broadcast": "ff:ff:ff:ff:ff:ff",
"promiscuity": 1,
"linkinfo": {
"info_kind": "bond",
"info_data": {
"mode": "802.3ad",
"miimon": 100,
"updelay": 0,
"downdelay": 0,
"use_carrier": 1,
"arp_interval": 0,
"arp_validate": null,
"arp_all_targets": "any",
"primary_reselect": "always",
"fail_over_mac": "none",
"xmit_hash_policy": "layer3+4",
"resend_igmp": 1,
"num_peer_notif": 1,
"all_slaves_active": 0,
"min_links": 1,
"lp_interval": 1,
"packets_per_slave": 1,
"ad_lacp_rate": "fast",
"ad_select": "stable",
"ad_actor_sys_prio": 65535,
"ad_user_port_key": 0,
"ad_actor_system": "00:00:00:00:00:00"
},
"info_slave_kind": "bridge",
"info_slave_data": {
"state": "forwarding",
"priority": 8,
"cost": 100,
"hairpin": false,
"guard": false,
"root_block": false,
"fastleave": false,
"learning": true,
"flood": true,
"id": "0x8001",
"no": "0x1",
"designated_port": 32769,
"designated_cost": 0,
"bridge_id": "8000.22:8f:91:bb:9f:9",
"root_id": "8000.22:8f:91:bb:9f:9",
"hold_timer": 0.00,
"message_age_timer": 0.00,
"forward_delay_timer": 11.97,
"topology_change_ack": 0,
"config_pending": 0,
"proxy_arp": false,
"proxy_arp_wifi": false,
"multicast_router": 1,
"mcast_flood": true
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 16,
"num_rx_queues": 16,
"gso_max_size": 65536,
"gso_max_segs": 65535
}
]
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/iplink_bridge_slave.c | 185 +++++++++++++++++++++++++++++------------------
1 file changed, 114 insertions(+), 71 deletions(-)
diff --git a/ip/iplink_bridge_slave.c b/ip/iplink_bridge_slave.c
index 3e883328..80272b09 100644
--- a/ip/iplink_bridge_slave.c
+++ b/ip/iplink_bridge_slave.c
@@ -56,14 +56,52 @@ static const char *port_states[] = {
static void print_portstate(FILE *f, __u8 state)
{
if (state <= BR_STATE_BLOCKING)
- fprintf(f, "state %s ", port_states[state]);
+ print_string(PRINT_ANY,
+ "state",
+ "state %s ",
+ port_states[state]);
else
- fprintf(f, "state (%d) ", state);
+ print_int(PRINT_ANY, "state_index", "state (%d) ", state);
}
-static void print_onoff(FILE *f, char *flag, __u8 val)
+static void _print_onoff(FILE *f, char *json_flag, char *flag, __u8 val)
{
- fprintf(f, "%s %s ", flag, val ? "on" : "off");
+ if (is_json_context())
+ print_bool(PRINT_JSON, flag, NULL, val);
+ else
+ fprintf(f, "%s %s ", flag, val ? "on" : "off");
+}
+
+static void _print_hex(FILE *f,
+ const char *json_attr,
+ const char *attr,
+ __u16 val)
+{
+ if (is_json_context()) {
+ SPRINT_BUF(b1);
+
+ snprintf(b1, sizeof(b1), "0x%x", val);
+ print_string(PRINT_JSON, json_attr, NULL, b1);
+ } else {
+ fprintf(f, "%s 0x%x ", attr, val);
+ }
+}
+
+static void _print_timer(FILE *f, const char *attr, struct rtattr *timer)
+{
+ struct timeval tv;
+
+ __jiffies_to_tv(&tv, rta_getattr_u64(timer));
+ if (is_json_context()) {
+ json_writer_t *jw = get_json_writer();
+
+ jsonw_name(jw, attr);
+ jsonw_printf(jw, "%i.%.2i",
+ (int)tv.tv_sec, (int)tv.tv_usec / 10000);
+ } else {
+ fprintf(f, "%s %4i.%.2i ", attr, (int)tv.tv_sec,
+ (int)tv.tv_usec / 10000);
+ }
}
static void bridge_slave_print_opt(struct link_util *lu, FILE *f,
@@ -76,59 +114,70 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f,
print_portstate(f, rta_getattr_u8(tb[IFLA_BRPORT_STATE]));
if (tb[IFLA_BRPORT_PRIORITY])
- fprintf(f, "priority %d ",
- rta_getattr_u16(tb[IFLA_BRPORT_PRIORITY]));
+ print_int(PRINT_ANY,
+ "priority",
+ "priority %d ",
+ rta_getattr_u16(tb[IFLA_BRPORT_PRIORITY]));
if (tb[IFLA_BRPORT_COST])
- fprintf(f, "cost %d ",
- rta_getattr_u32(tb[IFLA_BRPORT_COST]));
+ print_int(PRINT_ANY,
+ "cost",
+ "cost %d ",
+ rta_getattr_u32(tb[IFLA_BRPORT_COST]));
if (tb[IFLA_BRPORT_MODE])
- print_onoff(f, "hairpin",
- rta_getattr_u8(tb[IFLA_BRPORT_MODE]));
+ _print_onoff(f, "mode", "hairpin",
+ rta_getattr_u8(tb[IFLA_BRPORT_MODE]));
if (tb[IFLA_BRPORT_GUARD])
- print_onoff(f, "guard",
- rta_getattr_u8(tb[IFLA_BRPORT_GUARD]));
+ _print_onoff(f, "guard", "guard",
+ rta_getattr_u8(tb[IFLA_BRPORT_GUARD]));
if (tb[IFLA_BRPORT_PROTECT])
- print_onoff(f, "root_block",
- rta_getattr_u8(tb[IFLA_BRPORT_PROTECT]));
+ _print_onoff(f, "protect", "root_block",
+ rta_getattr_u8(tb[IFLA_BRPORT_PROTECT]));
if (tb[IFLA_BRPORT_FAST_LEAVE])
- print_onoff(f, "fastleave",
- rta_getattr_u8(tb[IFLA_BRPORT_FAST_LEAVE]));
+ _print_onoff(f, "fast_leave", "fastleave",
+ rta_getattr_u8(tb[IFLA_BRPORT_FAST_LEAVE]));
if (tb[IFLA_BRPORT_LEARNING])
- print_onoff(f, "learning",
- rta_getattr_u8(tb[IFLA_BRPORT_LEARNING]));
+ _print_onoff(f, "learning", "learning",
+ rta_getattr_u8(tb[IFLA_BRPORT_LEARNING]));
if (tb[IFLA_BRPORT_UNICAST_FLOOD])
- print_onoff(f, "flood",
- rta_getattr_u8(tb[IFLA_BRPORT_UNICAST_FLOOD]));
+ _print_onoff(f, "unicast_flood", "flood",
+ rta_getattr_u8(tb[IFLA_BRPORT_UNICAST_FLOOD]));
if (tb[IFLA_BRPORT_ID])
- fprintf(f, "port_id 0x%x ",
- rta_getattr_u16(tb[IFLA_BRPORT_ID]));
+ _print_hex(f, "id", "port_id",
+ rta_getattr_u16(tb[IFLA_BRPORT_ID]));
if (tb[IFLA_BRPORT_NO])
- fprintf(f, "port_no 0x%x ",
- rta_getattr_u16(tb[IFLA_BRPORT_NO]));
+ _print_hex(f, "no", "port_no",
+ rta_getattr_u16(tb[IFLA_BRPORT_NO]));
if (tb[IFLA_BRPORT_DESIGNATED_PORT])
- fprintf(f, "designated_port %u ",
- rta_getattr_u16(tb[IFLA_BRPORT_DESIGNATED_PORT]));
+ print_uint(PRINT_ANY,
+ "designated_port",
+ "designated_port %u ",
+ rta_getattr_u16(tb[IFLA_BRPORT_DESIGNATED_PORT]));
if (tb[IFLA_BRPORT_DESIGNATED_COST])
- fprintf(f, "designated_cost %u ",
- rta_getattr_u16(tb[IFLA_BRPORT_DESIGNATED_COST]));
+ print_uint(PRINT_ANY,
+ "designated_cost",
+ "designated_cost %u ",
+ rta_getattr_u16(tb[IFLA_BRPORT_DESIGNATED_COST]));
if (tb[IFLA_BRPORT_BRIDGE_ID]) {
char bridge_id[32];
br_dump_bridge_id(RTA_DATA(tb[IFLA_BRPORT_BRIDGE_ID]),
bridge_id, sizeof(bridge_id));
- fprintf(f, "designated_bridge %s ", bridge_id);
+ print_string(PRINT_ANY,
+ "bridge_id",
+ "designated_bridge %s ",
+ bridge_id);
}
if (tb[IFLA_BRPORT_ROOT_ID]) {
@@ -136,65 +185,59 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f,
br_dump_bridge_id(RTA_DATA(tb[IFLA_BRPORT_ROOT_ID]),
root_id, sizeof(root_id));
- fprintf(f, "designated_root %s ", root_id);
- }
-
- if (tb[IFLA_BRPORT_HOLD_TIMER]) {
- struct timeval tv;
- __u64 htimer;
-
- htimer = rta_getattr_u64(tb[IFLA_BRPORT_HOLD_TIMER]);
- __jiffies_to_tv(&tv, htimer);
- fprintf(f, "hold_timer %4i.%.2i ", (int)tv.tv_sec,
- (int)tv.tv_usec/10000);
+ print_string(PRINT_ANY,
+ "root_id",
+ "designated_root %s ", root_id);
}
- if (tb[IFLA_BRPORT_MESSAGE_AGE_TIMER]) {
- struct timeval tv;
- __u64 agetimer;
+ if (tb[IFLA_BRPORT_HOLD_TIMER])
+ _print_timer(f, "hold_timer", tb[IFLA_BRPORT_HOLD_TIMER]);
- agetimer = rta_getattr_u64(tb[IFLA_BRPORT_MESSAGE_AGE_TIMER]);
- __jiffies_to_tv(&tv, agetimer);
- fprintf(f, "message_age_timer %4i.%.2i ", (int)tv.tv_sec,
- (int)tv.tv_usec/10000);
- }
-
- if (tb[IFLA_BRPORT_FORWARD_DELAY_TIMER]) {
- struct timeval tv;
- __u64 fwdtimer;
+ if (tb[IFLA_BRPORT_MESSAGE_AGE_TIMER])
+ _print_timer(f, "message_age_timer",
+ tb[IFLA_BRPORT_MESSAGE_AGE_TIMER]);
- fwdtimer = rta_getattr_u64(tb[IFLA_BRPORT_FORWARD_DELAY_TIMER]);
- __jiffies_to_tv(&tv, fwdtimer);
- fprintf(f, "forward_delay_timer %4i.%.2i ", (int)tv.tv_sec,
- (int)tv.tv_usec/10000);
- }
+ if (tb[IFLA_BRPORT_FORWARD_DELAY_TIMER])
+ _print_timer(f, "forward_delay_timer",
+ tb[IFLA_BRPORT_FORWARD_DELAY_TIMER]);
if (tb[IFLA_BRPORT_TOPOLOGY_CHANGE_ACK])
- fprintf(f, "topology_change_ack %u ",
- rta_getattr_u8(tb[IFLA_BRPORT_TOPOLOGY_CHANGE_ACK]));
+ print_uint(PRINT_ANY,
+ "topology_change_ack",
+ "topology_change_ack %u ",
+ rta_getattr_u8(tb[IFLA_BRPORT_TOPOLOGY_CHANGE_ACK]));
if (tb[IFLA_BRPORT_CONFIG_PENDING])
- fprintf(f, "config_pending %u ",
- rta_getattr_u8(tb[IFLA_BRPORT_CONFIG_PENDING]));
+ print_uint(PRINT_ANY,
+ "config_pending",
+ "config_pending %u ",
+ rta_getattr_u8(tb[IFLA_BRPORT_CONFIG_PENDING]));
+
if (tb[IFLA_BRPORT_PROXYARP])
- print_onoff(f, "proxy_arp",
- rta_getattr_u8(tb[IFLA_BRPORT_PROXYARP]));
+ _print_onoff(f, "proxyarp", "proxy_arp",
+ rta_getattr_u8(tb[IFLA_BRPORT_PROXYARP]));
if (tb[IFLA_BRPORT_PROXYARP_WIFI])
- print_onoff(f, "proxy_arp_wifi",
- rta_getattr_u8(tb[IFLA_BRPORT_PROXYARP_WIFI]));
+ _print_onoff(f, "proxyarp_wifi", "proxy_arp_wifi",
+ rta_getattr_u8(tb[IFLA_BRPORT_PROXYARP_WIFI]));
if (tb[IFLA_BRPORT_MULTICAST_ROUTER])
- fprintf(f, "mcast_router %u ",
- rta_getattr_u8(tb[IFLA_BRPORT_MULTICAST_ROUTER]));
+ print_uint(PRINT_ANY,
+ "multicast_router",
+ "mcast_router %u ",
+ rta_getattr_u8(tb[IFLA_BRPORT_MULTICAST_ROUTER]));
if (tb[IFLA_BRPORT_FAST_LEAVE])
- print_onoff(f, "mcast_fast_leave",
- rta_getattr_u8(tb[IFLA_BRPORT_FAST_LEAVE]));
+ // not printing any json here because
+ // we already printed fast_leave before
+ print_string(PRINT_FP,
+ NULL,
+ "mcast_fast_leave %s ",
+ rta_getattr_u8(tb[IFLA_BRPORT_FAST_LEAVE]) ? "on" : "off");
if (tb[IFLA_BRPORT_MCAST_FLOOD])
- print_onoff(f, "mcast_flood",
- rta_getattr_u8(tb[IFLA_BRPORT_MCAST_FLOOD]));
+ _print_onoff(f, "mcast_flood", "mcast_flood",
+ rta_getattr_u8(tb[IFLA_BRPORT_MCAST_FLOOD]));
}
static void bridge_slave_parse_on_off(char *arg_name, char *arg_val,
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 10/27] ip: iplink_bridge.c: add json output support
From: Julien Fortin @ 2017-08-17 17:35 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema and live example:
bridge: IFLA_INFO_DATA
{
"forward_delay": {
"type": "uint",
"attr": "IFLA_BR_FORWARD_DELAY"
},
"hello_time": {
"type": "uint",
"attr": "IFLA_BR_HELLO_TIME"
},
"max_age": {
"type": "uint",
"attr": "IFLA_BR_MAX_AGE"
},
"ageing_time": {
"type": "uint",
"attr": "IFLA_BR_AGEING_TIME"
},
"stp_state": {
"type": "uint",
"attr": "IFLA_BR_STP_STATE"
},
"priority": {
"type": "uint",
"attr": "IFLA_BR_PRIORITY"
},
"vlan_filtering": {
"type": "uint",
"attr": "IFLA_BR_VLAN_FILTERING"
},
"vlan_protocol": {
"type": "string",
"attr": "IFLA_BR_VLAN_PROTOCOL"
},
"bridge_id": {
"type": "string",
"attr": "IFLA_BR_BRIDGE_ID"
},
"root_id": {
"type": "string",
"attr": "IFLA_BR_ROOT_ID"
},
"root_port": {
"type": "uint",
"attr": "IFLA_BR_ROOT_PORT"
},
"root_path_cost": {
"type": "uint",
"attr": "IFLA_BR_ROOT_PATH_COST"
},
"topology_change": {
"type": "uint",
"attr": "IFLA_BR_TOPOLOGY_CHANGE"
},
"topology_change_detected": {
"type": "uint",
"attr": "IFLA_BR_TOPOLOGY_CHANGE_DETECTED"
},
"hello_timer": {
"type": "float",
"attr": "IFLA_BR_HELLO_TIMER"
},
"tcn_timer": {
"type": "float",
"attr": "IFLA_BR_TCN_TIMER"
},
"topology_change_timer": {
"type": "float",
"attr": "IFLA_BR_TOPOLOGY_CHANGE_TIMER"
},
"gc_timer": {
"type": "float",
"attr": "IFLA_BR_GC_TIMER"
},
"vlan_default_pvid": {
"type": "uint",
"attr": "IFLA_BR_VLAN_DEFAULT_PVID"
},
"vlan_stats_enabled": {
"type": "uint",
"attr": "IFLA_BR_VLAN_STATS_ENABLED"
},
"group_fwd_mask": {
"type": "string",
"attr": "IFLA_BR_GROUP_FWD_MASK"
},
"group_addr": {
"type": "string",
"attr": "IFLA_BR_GROUP_ADDR"
},
"mcast_snooping": {
"type": "uint",
"attr": "IFLA_BR_MCAST_SNOOPING"
},
"mcast_router": {
"type": "uint",
"attr": "IFLA_BR_MCAST_ROUTER"
},
"mcast_query_use_ifaddr": {
"type": "uint",
"attr": "IFLA_BR_MCAST_QUERY_USE_IFADDR"
},
"mcast_querier": {
"type": "uint",
"attr": "IFLA_BR_MCAST_QUERIER"
},
"mcast_hash_elasticity": {
"type": "uint",
"attr": "IFLA_BR_MCAST_HASH_ELASTICITY"
},
"mcast_hash_max": {
"type": "uint",
"attr": "IFLA_BR_MCAST_HASH_MAX"
},
"mcast_last_member_cnt": {
"type": "uint",
"attr": "IFLA_BR_MCAST_LAST_MEMBER_CNT"
},
"mcast_startup_query_cnt": {
"type": "uint",
"attr": "IFLA_BR_MCAST_STARTUP_QUERY_CNT"
},
"mcast_last_member_intvl": {
"type": "lluint",
"attr": "IFLA_BR_MCAST_LAST_MEMBER_INTVL"
},
"mcast_membership_intvl": {
"type": "lluint",
"attr": "IFLA_BR_MCAST_MEMBERSHIP_INTVL"
},
"mcast_querier_intvl": {
"type": "lluint",
"attr": "IFLA_BR_MCAST_QUERIER_INTVL"
},
"mcast_query_intvl": {
"type": "lluint",
"attr": "IFLA_BR_MCAST_QUERY_INTVL"
},
"mcast_query_response_intvl": {
"type": "lluint",
"attr": "IFLA_BR_MCAST_QUERY_RESPONSE_INTVL"
},
"mcast_startup_query_intvl": {
"type": "lluint",
"attr": "IFLA_BR_MCAST_STARTUP_QUERY_INTVL"
},
"mcast_stats_enabled": {
"type": "uint",
"attr": "IFLA_BR_MCAST_STATS_ENABLED"
},
"mcast_igmp_version": {
"type": "uint",
"attr": "IFLA_BR_MCAST_IGMP_VERSION"
},
"mcast_mld_version": {
"type": "uint",
"attr": "IFLA_BR_MCAST_MLD_VERSION"
},
"nf_call_iptables": {
"type": "uint",
"attr": "IFLA_BR_NF_CALL_IPTABLES"
},
"nf_call_ip6tables": {
"type": "uint",
"attr": "IFLA_BR_NF_CALL_IP6TABLES"
},
"nf_call_arptables": {
"type": "uint",
"attr": "IFLA_BR_NF_CALL_ARPTABLES"
}
}
$ ip link add dev br42 type bridge
$ ip link add dev bond42 type bond
$ ip link set dev bond42 master br42
$ ip link set dev bond42 up
$ ip link set dev br42 up
$ ip -details link show
15: br42: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state
UP mode DEFAULT group default
link/ether 22:8f:91:bb:9f:09 brd ff:ff:ff:ff:ff:ff promiscuity 0
bridge forward_delay 1500 hello_time 200 max_age 2000 ageing_time
30000 stp_state 0 priority 32768 vlan_filtering 0 vlan_protocol 802.1Q
bridge_id 8000.22:8f:91:bb:9f:9 designated_root 8000.22:8f:91:bb:9f:9
root_port 0 root_path_cost 0 topology_change 0 topology_change_detected 0
hello_timer 0.00 tcn_timer 0.00 topology_change_timer 0.00
gc_timer 199.11 vlan_default_pvid 1 vlan_stats_enabled 0 group_fwd_mask 0
group_address 01:80:c2:00:00:00 mcast_snooping 1 mcast_router 1
mcast_query_use_ifaddr 0 mcast_querier 0 mcast_hash_elasticity 4096
mcast_hash_max 4096 mcast_last_member_count 2 mcast_startup_query_count 2
mcast_last_member_interval 100 mcast_membership_interval 26000
mcast_querier_interval 25500 mcast_query_interval 12500
mcast_query_response_interval 1000 mcast_startup_query_interval 3125
mcast_stats_enabled 0 mcast_igmp_version 2 mcast_mld_version 1
nf_call_iptables 0 nf_call_ip6tables 0 nf_call_arptables 0 addrgenmode
eui64
16: bond42: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc
noqueue master br42 state UNKNOWN mode DEFAULT group default
link/ether 22:8f:91:bb:9f:09 brd ff:ff:ff:ff:ff:ff promiscuity 1
bond mode 802.3ad miimon 100 updelay 0 downdelay 0 use_carrier 1
arp_interval 0 arp_validate none arp_all_targets any primary_reselect
always fail_over_mac none xmit_hash_policy layer3+4 resend_igmp 1
num_grat_arp 1 all_slaves_active 0 min_links 1 lp_interval 1
packets_per_slave 1 lacp_rate fast ad_select stable ad_actor_sys_prio
65535 ad_user_port_key 0 ad_actor_system 00:00:00:00:00:00
bridge_slave state forwarding priority 8 cost 100 hairpin off guard
off root_block off fastleave off learning on flood on port_id 0x8001
port_no 0x1 designated_port 32769 designated_cost 0 designated_bridge
8000.22:8f:91:bb:9f:9 designated_root 8000.22:8f:91:bb:9f:9 hold_timer
0.00 message_age_timer 0.00 forward_delay_timer 0.00
topology_change_ack 0 config_pending 0 proxy_arp off proxy_arp_wifi off
mcast_router 1 mcast_fast_leave off mcast_flood on neigh_suppress off
addrgenmode eui64
$ ip -details -json link show
[{
"ifindex": 15,
"ifname": "br42",
"flags": ["BROADCAST","MULTICAST","UP","LOWER_UP"],
"mtu": 1500,
"qdisc": "noqueue",
"operstate": "UP",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "ether",
"address": "22:8f:91:bb:9f:09",
"broadcast": "ff:ff:ff:ff:ff:ff",
"promiscuity": 0,
"linkinfo": {
"info_kind": "bridge",
"info_data": {
"forward_delay": 1500,
"hello_time": 200,
"max_age": 2000,
"ageing_time": 30000,
"stp_state": 0,
"priority": 32768,
"vlan_filtering": 0,
"vlan_protocol": "802.1Q",
"bridge_id": "8000.22:8f:91:bb:9f:9",
"root_id": "8000.22:8f:91:bb:9f:9",
"root_port": 0,
"root_path_cost": 0,
"topology_change": 0,
"topology_change_detected": 0,
"hello_timer": 0.00,
"tcn_timer": 0.00,
"topology_change_timer": 0.00,
"gc_timer": 298.27,
"vlan_default_pvid": 1,
"vlan_stats_enabled": 0,
"group_fwd_mask": "0",
"group_addr": "01:80:c2:00:00:00",
"mcast_snooping": 1,
"mcast_router": 1,
"mcast_query_use_ifaddr": 0,
"mcast_querier": 0,
"mcast_hash_elasticity": 4096,
"mcast_hash_max": 4096,
"mcast_last_member_cnt": 2,
"mcast_startup_query_cnt": 2,
"mcast_last_member_intvl": 100,
"mcast_membership_intvl": 26000,
"mcast_querier_intvl": 25500,
"mcast_query_intvl": 12500,
"mcast_query_response_intvl": 1000,
"mcast_startup_query_intvl": 3125,
"mcast_stats_enabled": 0,
"mcast_igmp_version": 2,
"mcast_mld_version": 1,
"nf_call_iptables": 0,
"nf_call_ip6tables": 0,
"nf_call_arptables": 0
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
},{
"ifindex": 16,
"ifname": "bond42",
"flags": ["BROADCAST","MULTICAST","MASTER","UP","LOWER_UP"],
"mtu": 1500,
"qdisc": "noqueue",
"master": "br42",
"operstate": "UNKNOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "ether",
"address": "22:8f:91:bb:9f:09",
"broadcast": "ff:ff:ff:ff:ff:ff",
"promiscuity": 1,
"linkinfo": {
"info_kind": "bond",
"info_data": {
"mode": "802.3ad",
"miimon": 100,
"updelay": 0,
"downdelay": 0,
"use_carrier": 1,
"arp_interval": 0,
"arp_validate": null,
"arp_all_targets": "any",
"primary_reselect": "always",
"fail_over_mac": "none",
"xmit_hash_policy": "layer3+4",
"resend_igmp": 1,
"num_peer_notif": 1,
"all_slaves_active": 0,
"min_links": 1,
"lp_interval": 1,
"packets_per_slave": 1,
"ad_lacp_rate": "fast",
"ad_select": "stable",
"ad_actor_sys_prio": 65535,
"ad_user_port_key": 0,
"ad_actor_system": "00:00:00:00:00:00"
},
"info_slave_kind": "bridge",
"info_slave_data": {
"state": "forwarding",
"priority": 8,
"cost": 100,
"hairpin": false,
"guard": false,
"root_block": false,
"fastleave": false,
"learning": true,
"flood": true,
"id": "0x8001",
"no": "0x1",
"designated_port": 32769,
"designated_cost": 0,
"bridge_id": "8000.22:8f:91:bb:9f:9",
"root_id": "8000.22:8f:91:bb:9f:9",
"hold_timer": 0.00,
"message_age_timer": 0.00,
"forward_delay_timer": 11.97,
"topology_change_ack": 0,
"config_pending": 0,
"proxy_arp": false,
"proxy_arp_wifi": false,
"multicast_router": 1,
"mcast_flood": true
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 16,
"num_rx_queues": 16,
"gso_max_size": 65536,
"gso_max_segs": 65535
}
]
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/iplink_bridge.c | 293 +++++++++++++++++++++++++++++++++--------------------
1 file changed, 185 insertions(+), 108 deletions(-)
diff --git a/ip/iplink_bridge.c b/ip/iplink_bridge.c
index cccdec1c..d3250980 100644
--- a/ip/iplink_bridge.c
+++ b/ip/iplink_bridge.c
@@ -373,45 +373,81 @@ static int bridge_parse_opt(struct link_util *lu, int argc, char **argv,
return 0;
}
+static void _bridge_print_timer(FILE *f,
+ const char *attr,
+ struct rtattr *timer)
+{
+ struct timeval tv;
+
+ __jiffies_to_tv(&tv, rta_getattr_u64(timer));
+ if (is_json_context()) {
+ json_writer_t *jw = get_json_writer();
+
+ jsonw_name(jw, attr);
+ jsonw_printf(jw, "%i.%.2i",
+ (int)tv.tv_sec,
+ (int)tv.tv_usec / 10000);
+ } else {
+ fprintf(f, "%s %4i.%.2i ", attr, (int)tv.tv_sec,
+ (int)tv.tv_usec / 10000);
+ }
+}
+
static void bridge_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
if (!tb)
return;
if (tb[IFLA_BR_FORWARD_DELAY])
- fprintf(f, "forward_delay %u ",
- rta_getattr_u32(tb[IFLA_BR_FORWARD_DELAY]));
+ print_uint(PRINT_ANY,
+ "forward_delay",
+ "forward_delay %u ",
+ rta_getattr_u32(tb[IFLA_BR_FORWARD_DELAY]));
if (tb[IFLA_BR_HELLO_TIME])
- fprintf(f, "hello_time %u ",
- rta_getattr_u32(tb[IFLA_BR_HELLO_TIME]));
+ print_uint(PRINT_ANY,
+ "hello_time",
+ "hello_time %u ",
+ rta_getattr_u32(tb[IFLA_BR_HELLO_TIME]));
if (tb[IFLA_BR_MAX_AGE])
- fprintf(f, "max_age %u ",
- rta_getattr_u32(tb[IFLA_BR_MAX_AGE]));
+ print_uint(PRINT_ANY,
+ "max_age",
+ "max_age %u ",
+ rta_getattr_u32(tb[IFLA_BR_MAX_AGE]));
if (tb[IFLA_BR_AGEING_TIME])
- fprintf(f, "ageing_time %u ",
- rta_getattr_u32(tb[IFLA_BR_AGEING_TIME]));
+ print_uint(PRINT_ANY,
+ "ageing_time",
+ "ageing_time %u ",
+ rta_getattr_u32(tb[IFLA_BR_AGEING_TIME]));
if (tb[IFLA_BR_STP_STATE])
- fprintf(f, "stp_state %u ",
- rta_getattr_u32(tb[IFLA_BR_STP_STATE]));
+ print_uint(PRINT_ANY,
+ "stp_state",
+ "stp_state %u ",
+ rta_getattr_u32(tb[IFLA_BR_STP_STATE]));
if (tb[IFLA_BR_PRIORITY])
- fprintf(f, "priority %u ",
- rta_getattr_u16(tb[IFLA_BR_PRIORITY]));
+ print_uint(PRINT_ANY,
+ "priority",
+ "priority %u ",
+ rta_getattr_u16(tb[IFLA_BR_PRIORITY]));
if (tb[IFLA_BR_VLAN_FILTERING])
- fprintf(f, "vlan_filtering %u ",
- rta_getattr_u8(tb[IFLA_BR_VLAN_FILTERING]));
+ print_uint(PRINT_ANY,
+ "vlan_filtering",
+ "vlan_filtering %u ",
+ rta_getattr_u8(tb[IFLA_BR_VLAN_FILTERING]));
if (tb[IFLA_BR_VLAN_PROTOCOL]) {
SPRINT_BUF(b1);
- fprintf(f, "vlan_protocol %s ",
- ll_proto_n2a(rta_getattr_u16(tb[IFLA_BR_VLAN_PROTOCOL]),
- b1, sizeof(b1)));
+ print_string(PRINT_ANY,
+ "vlan_protocol",
+ "vlan_protocol %s ",
+ ll_proto_n2a(rta_getattr_u16(tb[IFLA_BR_VLAN_PROTOCOL]),
+ b1, sizeof(b1)));
}
if (tb[IFLA_BR_BRIDGE_ID]) {
@@ -419,7 +455,10 @@ static void bridge_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
br_dump_bridge_id(RTA_DATA(tb[IFLA_BR_BRIDGE_ID]), bridge_id,
sizeof(bridge_id));
- fprintf(f, "bridge_id %s ", bridge_id);
+ print_string(PRINT_ANY,
+ "bridge_id",
+ "bridge_id %s ",
+ bridge_id);
}
if (tb[IFLA_BR_ROOT_ID]) {
@@ -427,163 +466,201 @@ static void bridge_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
br_dump_bridge_id(RTA_DATA(tb[IFLA_BR_BRIDGE_ID]), root_id,
sizeof(root_id));
- fprintf(f, "designated_root %s ", root_id);
+ print_string(PRINT_ANY,
+ "root_id",
+ "designated_root %s ",
+ root_id);
}
if (tb[IFLA_BR_ROOT_PORT])
- fprintf(f, "root_port %u ",
- rta_getattr_u16(tb[IFLA_BR_ROOT_PORT]));
+ print_uint(PRINT_ANY,
+ "root_port",
+ "root_port %u ",
+ rta_getattr_u16(tb[IFLA_BR_ROOT_PORT]));
if (tb[IFLA_BR_ROOT_PATH_COST])
- fprintf(f, "root_path_cost %u ",
- rta_getattr_u32(tb[IFLA_BR_ROOT_PATH_COST]));
+ print_uint(PRINT_ANY,
+ "root_path_cost",
+ "root_path_cost %u ",
+ rta_getattr_u32(tb[IFLA_BR_ROOT_PATH_COST]));
if (tb[IFLA_BR_TOPOLOGY_CHANGE])
- fprintf(f, "topology_change %u ",
- rta_getattr_u8(tb[IFLA_BR_TOPOLOGY_CHANGE]));
+ print_uint(PRINT_ANY,
+ "topology_change",
+ "topology_change %u ",
+ rta_getattr_u8(tb[IFLA_BR_TOPOLOGY_CHANGE]));
if (tb[IFLA_BR_TOPOLOGY_CHANGE_DETECTED])
- fprintf(f, "topology_change_detected %u ",
- rta_getattr_u8(tb[IFLA_BR_TOPOLOGY_CHANGE_DETECTED]));
-
- if (tb[IFLA_BR_HELLO_TIMER]) {
- struct timeval tv;
-
- __jiffies_to_tv(&tv, rta_getattr_u64(tb[IFLA_BR_HELLO_TIMER]));
- fprintf(f, "hello_timer %4i.%.2i ", (int)tv.tv_sec,
- (int)tv.tv_usec/10000);
- }
-
- if (tb[IFLA_BR_TCN_TIMER]) {
- struct timeval tv;
-
- __jiffies_to_tv(&tv, rta_getattr_u64(tb[IFLA_BR_TCN_TIMER]));
- fprintf(f, "tcn_timer %4i.%.2i ", (int)tv.tv_sec,
- (int)tv.tv_usec/10000);
- }
+ print_uint(PRINT_ANY,
+ "topology_change_detected",
+ "topology_change_detected %u ",
+ rta_getattr_u8(tb[IFLA_BR_TOPOLOGY_CHANGE_DETECTED]));
- if (tb[IFLA_BR_TOPOLOGY_CHANGE_TIMER]) {
- unsigned long jiffies;
- struct timeval tv;
+ if (tb[IFLA_BR_HELLO_TIMER])
+ _bridge_print_timer(f, "hello_timer", tb[IFLA_BR_HELLO_TIMER]);
- jiffies = rta_getattr_u64(tb[IFLA_BR_TOPOLOGY_CHANGE_TIMER]);
- __jiffies_to_tv(&tv, jiffies);
- fprintf(f, "topology_change_timer %4i.%.2i ", (int)tv.tv_sec,
- (int)tv.tv_usec/10000);
- }
+ if (tb[IFLA_BR_TCN_TIMER])
+ _bridge_print_timer(f, "tcn_timer", tb[IFLA_BR_TCN_TIMER]);
- if (tb[IFLA_BR_GC_TIMER]) {
- struct timeval tv;
+ if (tb[IFLA_BR_TOPOLOGY_CHANGE_TIMER])
+ _bridge_print_timer(f, "topology_change_timer",
+ tb[IFLA_BR_TOPOLOGY_CHANGE_TIMER]);
- __jiffies_to_tv(&tv, rta_getattr_u64(tb[IFLA_BR_GC_TIMER]));
- fprintf(f, "gc_timer %4i.%.2i ", (int)tv.tv_sec,
- (int)tv.tv_usec/10000);
- }
+ if (tb[IFLA_BR_GC_TIMER])
+ _bridge_print_timer(f, "gc_timer", tb[IFLA_BR_GC_TIMER]);
if (tb[IFLA_BR_VLAN_DEFAULT_PVID])
- fprintf(f, "vlan_default_pvid %u ",
- rta_getattr_u16(tb[IFLA_BR_VLAN_DEFAULT_PVID]));
+ print_uint(PRINT_ANY,
+ "vlan_default_pvid",
+ "vlan_default_pvid %u ",
+ rta_getattr_u16(tb[IFLA_BR_VLAN_DEFAULT_PVID]));
if (tb[IFLA_BR_VLAN_STATS_ENABLED])
- fprintf(f, "vlan_stats_enabled %u ",
- rta_getattr_u8(tb[IFLA_BR_VLAN_STATS_ENABLED]));
+ print_uint(PRINT_ANY,
+ "vlan_stats_enabled",
+ "vlan_stats_enabled %u ",
+ rta_getattr_u8(tb[IFLA_BR_VLAN_STATS_ENABLED]));
if (tb[IFLA_BR_GROUP_FWD_MASK])
- fprintf(f, "group_fwd_mask %#x ",
- rta_getattr_u16(tb[IFLA_BR_GROUP_FWD_MASK]));
+ print_0xhex(PRINT_ANY,
+ "group_fwd_mask",
+ "group_fwd_mask %#x ",
+ rta_getattr_u16(tb[IFLA_BR_GROUP_FWD_MASK]));
if (tb[IFLA_BR_GROUP_ADDR]) {
SPRINT_BUF(mac);
- fprintf(f, "group_address %s ",
- ll_addr_n2a(RTA_DATA(tb[IFLA_BR_GROUP_ADDR]),
- RTA_PAYLOAD(tb[IFLA_BR_GROUP_ADDR]),
- 1 /*ARPHDR_ETHER*/, mac, sizeof(mac)));
+ print_string(PRINT_ANY,
+ "group_addr",
+ "group_address %s ",
+ ll_addr_n2a(RTA_DATA(tb[IFLA_BR_GROUP_ADDR]),
+ RTA_PAYLOAD(tb[IFLA_BR_GROUP_ADDR]),
+ 1 /*ARPHDR_ETHER*/, mac, sizeof(mac)));
}
if (tb[IFLA_BR_MCAST_SNOOPING])
- fprintf(f, "mcast_snooping %u ",
- rta_getattr_u8(tb[IFLA_BR_MCAST_SNOOPING]));
+ print_uint(PRINT_ANY,
+ "mcast_snooping",
+ "mcast_snooping %u ",
+ rta_getattr_u8(tb[IFLA_BR_MCAST_SNOOPING]));
if (tb[IFLA_BR_MCAST_ROUTER])
- fprintf(f, "mcast_router %u ",
- rta_getattr_u8(tb[IFLA_BR_MCAST_ROUTER]));
+ print_uint(PRINT_ANY,
+ "mcast_router",
+ "mcast_router %u ",
+ rta_getattr_u8(tb[IFLA_BR_MCAST_ROUTER]));
if (tb[IFLA_BR_MCAST_QUERY_USE_IFADDR])
- fprintf(f, "mcast_query_use_ifaddr %u ",
- rta_getattr_u8(tb[IFLA_BR_MCAST_QUERY_USE_IFADDR]));
+ print_uint(PRINT_ANY,
+ "mcast_query_use_ifaddr",
+ "mcast_query_use_ifaddr %u ",
+ rta_getattr_u8(tb[IFLA_BR_MCAST_QUERY_USE_IFADDR]));
if (tb[IFLA_BR_MCAST_QUERIER])
- fprintf(f, "mcast_querier %u ",
- rta_getattr_u8(tb[IFLA_BR_MCAST_QUERIER]));
+ print_uint(PRINT_ANY,
+ "mcast_querier",
+ "mcast_querier %u ",
+ rta_getattr_u8(tb[IFLA_BR_MCAST_QUERIER]));
if (tb[IFLA_BR_MCAST_HASH_ELASTICITY])
- fprintf(f, "mcast_hash_elasticity %u ",
- rta_getattr_u32(tb[IFLA_BR_MCAST_HASH_ELASTICITY]));
+ print_uint(PRINT_ANY,
+ "mcast_hash_elasticity",
+ "mcast_hash_elasticity %u ",
+ rta_getattr_u32(tb[IFLA_BR_MCAST_HASH_ELASTICITY]));
if (tb[IFLA_BR_MCAST_HASH_MAX])
- fprintf(f, "mcast_hash_max %u ",
- rta_getattr_u32(tb[IFLA_BR_MCAST_HASH_MAX]));
+ print_uint(PRINT_ANY,
+ "mcast_hash_max",
+ "mcast_hash_max %u ",
+ rta_getattr_u32(tb[IFLA_BR_MCAST_HASH_MAX]));
if (tb[IFLA_BR_MCAST_LAST_MEMBER_CNT])
- fprintf(f, "mcast_last_member_count %u ",
- rta_getattr_u32(tb[IFLA_BR_MCAST_LAST_MEMBER_CNT]));
+ print_uint(PRINT_ANY,
+ "mcast_last_member_cnt",
+ "mcast_last_member_count %u ",
+ rta_getattr_u32(tb[IFLA_BR_MCAST_LAST_MEMBER_CNT]));
if (tb[IFLA_BR_MCAST_STARTUP_QUERY_CNT])
- fprintf(f, "mcast_startup_query_count %u ",
- rta_getattr_u32(tb[IFLA_BR_MCAST_STARTUP_QUERY_CNT]));
+ print_uint(PRINT_ANY,
+ "mcast_startup_query_cnt",
+ "mcast_startup_query_count %u ",
+ rta_getattr_u32(tb[IFLA_BR_MCAST_STARTUP_QUERY_CNT]));
if (tb[IFLA_BR_MCAST_LAST_MEMBER_INTVL])
- fprintf(f, "mcast_last_member_interval %llu ",
- rta_getattr_u64(tb[IFLA_BR_MCAST_LAST_MEMBER_INTVL]));
+ print_lluint(PRINT_ANY,
+ "mcast_last_member_intvl",
+ "mcast_last_member_interval %llu ",
+ rta_getattr_u64(tb[IFLA_BR_MCAST_LAST_MEMBER_INTVL]));
if (tb[IFLA_BR_MCAST_MEMBERSHIP_INTVL])
- fprintf(f, "mcast_membership_interval %llu ",
- rta_getattr_u64(tb[IFLA_BR_MCAST_MEMBERSHIP_INTVL]));
+ print_lluint(PRINT_ANY,
+ "mcast_membership_intvl",
+ "mcast_membership_interval %llu ",
+ rta_getattr_u64(tb[IFLA_BR_MCAST_MEMBERSHIP_INTVL]));
if (tb[IFLA_BR_MCAST_QUERIER_INTVL])
- fprintf(f, "mcast_querier_interval %llu ",
- rta_getattr_u64(tb[IFLA_BR_MCAST_QUERIER_INTVL]));
+ print_lluint(PRINT_ANY,
+ "mcast_querier_intvl",
+ "mcast_querier_interval %llu ",
+ rta_getattr_u64(tb[IFLA_BR_MCAST_QUERIER_INTVL]));
if (tb[IFLA_BR_MCAST_QUERY_INTVL])
- fprintf(f, "mcast_query_interval %llu ",
- rta_getattr_u64(tb[IFLA_BR_MCAST_QUERY_INTVL]));
+ print_lluint(PRINT_ANY,
+ "mcast_query_intvl",
+ "mcast_query_interval %llu ",
+ rta_getattr_u64(tb[IFLA_BR_MCAST_QUERY_INTVL]));
if (tb[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL])
- fprintf(f, "mcast_query_response_interval %llu ",
- rta_getattr_u64(tb[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL]));
+ print_lluint(PRINT_ANY,
+ "mcast_query_response_intvl",
+ "mcast_query_response_interval %llu ",
+ rta_getattr_u64(tb[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL]));
if (tb[IFLA_BR_MCAST_STARTUP_QUERY_INTVL])
- fprintf(f, "mcast_startup_query_interval %llu ",
- rta_getattr_u64(tb[IFLA_BR_MCAST_STARTUP_QUERY_INTVL]));
+ print_lluint(PRINT_ANY,
+ "mcast_startup_query_intvl",
+ "mcast_startup_query_interval %llu ",
+ rta_getattr_u64(tb[IFLA_BR_MCAST_STARTUP_QUERY_INTVL]));
if (tb[IFLA_BR_MCAST_STATS_ENABLED])
- fprintf(f, "mcast_stats_enabled %u ",
- rta_getattr_u8(tb[IFLA_BR_MCAST_STATS_ENABLED]));
+ print_uint(PRINT_ANY,
+ "mcast_stats_enabled",
+ "mcast_stats_enabled %u ",
+ rta_getattr_u8(tb[IFLA_BR_MCAST_STATS_ENABLED]));
if (tb[IFLA_BR_MCAST_IGMP_VERSION])
- fprintf(f, "mcast_igmp_version %u ",
- rta_getattr_u8(tb[IFLA_BR_MCAST_IGMP_VERSION]));
+ print_uint(PRINT_ANY,
+ "mcast_igmp_version",
+ "mcast_igmp_version %u ",
+ rta_getattr_u8(tb[IFLA_BR_MCAST_IGMP_VERSION]));
if (tb[IFLA_BR_MCAST_MLD_VERSION])
- fprintf(f, "mcast_mld_version %u ",
- rta_getattr_u8(tb[IFLA_BR_MCAST_MLD_VERSION]));
+ print_uint(PRINT_ANY,
+ "mcast_mld_version",
+ "mcast_mld_version %u ",
+ rta_getattr_u8(tb[IFLA_BR_MCAST_MLD_VERSION]));
if (tb[IFLA_BR_NF_CALL_IPTABLES])
- fprintf(f, "nf_call_iptables %u ",
- rta_getattr_u8(tb[IFLA_BR_NF_CALL_IPTABLES]));
+ print_uint(PRINT_ANY,
+ "nf_call_iptables",
+ "nf_call_iptables %u ",
+ rta_getattr_u8(tb[IFLA_BR_NF_CALL_IPTABLES]));
if (tb[IFLA_BR_NF_CALL_IP6TABLES])
- fprintf(f, "nf_call_ip6tables %u ",
- rta_getattr_u8(tb[IFLA_BR_NF_CALL_IP6TABLES]));
+ print_uint(PRINT_ANY,
+ "nf_call_ip6tables",
+ "nf_call_ip6tables %u ",
+ rta_getattr_u8(tb[IFLA_BR_NF_CALL_IP6TABLES]));
if (tb[IFLA_BR_NF_CALL_ARPTABLES])
- fprintf(f, "nf_call_arptables %u ",
- rta_getattr_u8(tb[IFLA_BR_NF_CALL_ARPTABLES]));
+ print_uint(PRINT_ANY,
+ "nf_call_arptables",
+ "nf_call_arptables %u ",
+ rta_getattr_u8(tb[IFLA_BR_NF_CALL_ARPTABLES]));
}
static void bridge_print_help(struct link_util *lu, int argc, char **argv,
- FILE *f)
+ FILE *f)
{
print_explain(f);
}
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 09/27] ip: iplink_hsr.c: add json output support
From: Julien Fortin @ 2017-08-17 17:35 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema:
hsr: IFLA_INFO_DATA
{
"slave1": {
"type": "string",
"attr": "IFLA_HSR_SLAVE1"
},
"slave2": {
"type": "string",
"attr": "IFLA_HSR_SLAVE2"
},
"seq_nr": {
"type": "int",
"attr": "IFLA_HSR_SEQ_NR"
},
"supervision_addr": {
"type": "int",
"attr": "IFLA_HSR_SUPERVISION_ADDR"
}
}
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/iplink_hsr.c | 36 +++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/ip/iplink_hsr.c b/ip/iplink_hsr.c
index 696b2c91..c673ccf7 100644
--- a/ip/iplink_hsr.c
+++ b/ip/iplink_hsr.c
@@ -110,30 +110,36 @@ static void hsr_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
RTA_PAYLOAD(tb[IFLA_HSR_SUPERVISION_ADDR]) < ETH_ALEN)
return;
- fprintf(f, "slave1 ");
if (tb[IFLA_HSR_SLAVE1])
- fprintf(f, "%s ",
- ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_SLAVE1])));
+ print_string(PRINT_ANY,
+ "slave1",
+ "slave1 %s ",
+ ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_SLAVE1])));
else
- fprintf(f, "<none> ");
+ print_null(PRINT_ANY, "slave1", "slave1 %s ", "<none>");
- fprintf(f, "slave2 ");
if (tb[IFLA_HSR_SLAVE2])
- fprintf(f, "%s ",
- ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_SLAVE2])));
+ print_string(PRINT_ANY,
+ "slave2",
+ "slave2 %s ",
+ ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_SLAVE2])));
else
- fprintf(f, "<none> ");
+ print_null(PRINT_ANY, "slave2", "slave2 %s ", "<none>");
if (tb[IFLA_HSR_SEQ_NR])
- fprintf(f, "sequence %d ",
- rta_getattr_u16(tb[IFLA_HSR_SEQ_NR]));
+ print_int(PRINT_ANY,
+ "seq_nr",
+ "sequence %d ",
+ rta_getattr_u16(tb[IFLA_HSR_SEQ_NR]));
if (tb[IFLA_HSR_SUPERVISION_ADDR])
- fprintf(f, "supervision %s ",
- ll_addr_n2a(RTA_DATA(tb[IFLA_HSR_SUPERVISION_ADDR]),
- RTA_PAYLOAD(tb[IFLA_HSR_SUPERVISION_ADDR]),
- ARPHRD_VOID,
- b1, sizeof(b1)));
+ print_string(PRINT_ANY,
+ "supervision_addr",
+ "supervision %s ",
+ ll_addr_n2a(RTA_DATA(tb[IFLA_HSR_SUPERVISION_ADDR]),
+ RTA_PAYLOAD(tb[IFLA_HSR_SUPERVISION_ADDR]),
+ ARPHRD_VOID,
+ b1, sizeof(b1)));
}
static void hsr_print_help(struct link_util *lu, int argc, char **argv,
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 08/27] ip: iplink_bond_slave.c: add json output support (info_slave_data)
From: Julien Fortin @ 2017-08-17 17:35 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema and live example:
bond_slave: IFLA_INFO_SLAVE_DATA
{
"state": {
"type": "string",
"attr": "IFLA_BOND_SLAVE_STATE",
"mutually_exclusive": {
"state_index": {
"type": "int",
"comment": "if (state >= ARRAY_SIZE(slave_states))"
}
}
},
"mii_status": {
"type": "string",
"attr": "IFLA_BOND_SLAVE_MII_STATUS",
"mutually_exclusive": {
"mii_status_index": {
"type": "int",
"comment": "if (status >= ARRAY_SIZE(slave_mii_status))"
}
}
},
"link_failure_count": {
"type": "int",
"attr": "IFLA_BOND_SLAVE_LINK_FAILURE_COUNT"
},
"perm_hwaddr": {
"type": "string",
"attr": "IFLA_BOND_SLAVE_PERM_HWADDR"
},
"queue_id": {
"type": "int",
"attr": "IFLA_BOND_SLAVE_QUEUE_ID"
},
"ad_aggregator_id": {
"type": "int",
"attr": "IFLA_BOND_SLAVE_AD_AGGREGATOR_ID"
},
"ad_actor_oper_port_state": {
"type": "int",
"attr": "IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE"
},
"ad_partner_oper_port_state": {
"type": "int",
"attr": "IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE"
}
}
$ ip link add dev bond42 type bond
$ ip link set dev swp5 master bond42
$ ip link set dev bond42 up
$ ip link set dev swp5 up
$ ip -details -json link show
[{
"ifindex": 7,
"ifname": "swp5",
"flags": ["BROADCAST","MULTICAST","SLAVE","UP","LOWER_UP"],
"mtu": 1500,
"qdisc": "pfifo_fast",
"master": "bond42",
"operstate": "UP",
"linkmode": "DEFAULT",
"group": "default",
"txqlen": 1000,
"link_type": "ether",
"address": "08:00:27:5c:03:c6",
"broadcast": "ff:ff:ff:ff:ff:ff",
"promiscuity": 0,
"linkinfo": {
"info_slave_kind": "bond",
"info_slave_data": {
"state": "BACKUP",
"mii_status": "UP",
"link_failure_count": 0,
"perm_hwaddr": "08:00:27:5c:03:c6",
"queue_id": 0,
"ad_aggregator_id": 1,
"ad_actor_oper_port_state": 79,
"ad_partner_oper_port_state": 1
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
},{
"ifindex": 14,
"ifname": "bond42",
"flags": ["NO-CARRIER","BROADCAST","MULTICAST","MASTER","UP"],
"mtu": 1500,
"qdisc": "noqueue",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "ether",
"address": "08:00:27:5c:03:c6",
"broadcast": "ff:ff:ff:ff:ff:ff",
"promiscuity": 0,
"linkinfo": {
"info_kind": "bond",
"info_data": {
"mode": "802.3ad",
"miimon": 100,
"updelay": 0,
"downdelay": 0,
"use_carrier": 1,
"arp_interval": 0,
"arp_validate": null,
"arp_all_targets": "any",
"primary_reselect": "always",
"fail_over_mac": "none",
"xmit_hash_policy": "layer3+4",
"resend_igmp": 1,
"num_peer_notif": 1,
"all_slaves_active": 0,
"min_links": 1,
"lp_interval": 1,
"packets_per_slave": 1,
"ad_lacp_rate": "fast",
"ad_select": "stable",
"ad_info": {
"aggregator": 1,
"num_ports": 1,
"actor_key": 0,
"partner_key": 1,
"partner_mac": "00:00:00:00:00:00"
},
"ad_actor_sys_prio": 65535,
"ad_user_port_key": 0,
"ad_actor_system": "00:00:00:00:00:00"
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 16,
"num_rx_queues": 16,
"gso_max_size": 65536,
"gso_max_segs": 65535
}
]
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/iplink_bond_slave.c | 57 ++++++++++++++++++++++++++++++++++----------------
1 file changed, 39 insertions(+), 18 deletions(-)
diff --git a/ip/iplink_bond_slave.c b/ip/iplink_bond_slave.c
index 877e2d9e..67219c67 100644
--- a/ip/iplink_bond_slave.c
+++ b/ip/iplink_bond_slave.c
@@ -37,9 +37,12 @@ static void print_slave_state(FILE *f, struct rtattr *tb)
unsigned int state = rta_getattr_u8(tb);
if (state >= ARRAY_SIZE(slave_states))
- fprintf(f, "state %d ", state);
+ print_int(PRINT_ANY, "state_index", "state %d ", state);
else
- fprintf(f, "state %s ", slave_states[state]);
+ print_string(PRINT_ANY,
+ "state",
+ "state %s ",
+ slave_states[state]);
}
static const char *slave_mii_status[] = {
@@ -54,9 +57,15 @@ static void print_slave_mii_status(FILE *f, struct rtattr *tb)
unsigned int status = rta_getattr_u8(tb);
if (status >= ARRAY_SIZE(slave_mii_status))
- fprintf(f, "mii_status %d ", status);
+ print_int(PRINT_ANY,
+ "mii_status_index",
+ "mii_status %d ",
+ status);
else
- fprintf(f, "mii_status %s ", slave_mii_status[status]);
+ print_string(PRINT_ANY,
+ "mii_status",
+ "mii_status %s ",
+ slave_mii_status[status]);
}
static void bond_slave_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
@@ -72,30 +81,42 @@ static void bond_slave_print_opt(struct link_util *lu, FILE *f, struct rtattr *t
print_slave_mii_status(f, tb[IFLA_BOND_SLAVE_MII_STATUS]);
if (tb[IFLA_BOND_SLAVE_LINK_FAILURE_COUNT])
- fprintf(f, "link_failure_count %d ",
- rta_getattr_u32(tb[IFLA_BOND_SLAVE_LINK_FAILURE_COUNT]));
+ print_int(PRINT_ANY,
+ "link_failure_count",
+ "link_failure_count %d ",
+ rta_getattr_u32(tb[IFLA_BOND_SLAVE_LINK_FAILURE_COUNT]));
if (tb[IFLA_BOND_SLAVE_PERM_HWADDR])
- fprintf(f, "perm_hwaddr %s ",
- ll_addr_n2a(RTA_DATA(tb[IFLA_BOND_SLAVE_PERM_HWADDR]),
- RTA_PAYLOAD(tb[IFLA_BOND_SLAVE_PERM_HWADDR]),
- 0, b1, sizeof(b1)));
+ print_string(PRINT_ANY,
+ "perm_hwaddr",
+ "perm_hwaddr %s ",
+ ll_addr_n2a(RTA_DATA(tb[IFLA_BOND_SLAVE_PERM_HWADDR]),
+ RTA_PAYLOAD(tb[IFLA_BOND_SLAVE_PERM_HWADDR]),
+ 0, b1, sizeof(b1)));
if (tb[IFLA_BOND_SLAVE_QUEUE_ID])
- fprintf(f, "queue_id %d ",
- rta_getattr_u16(tb[IFLA_BOND_SLAVE_QUEUE_ID]));
+ print_int(PRINT_ANY,
+ "queue_id",
+ "queue_id %d ",
+ rta_getattr_u16(tb[IFLA_BOND_SLAVE_QUEUE_ID]));
if (tb[IFLA_BOND_SLAVE_AD_AGGREGATOR_ID])
- fprintf(f, "ad_aggregator_id %d ",
- rta_getattr_u16(tb[IFLA_BOND_SLAVE_AD_AGGREGATOR_ID]));
+ print_int(PRINT_ANY,
+ "ad_aggregator_id",
+ "ad_aggregator_id %d ",
+ rta_getattr_u16(tb[IFLA_BOND_SLAVE_AD_AGGREGATOR_ID]));
if (tb[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE])
- fprintf(f, "ad_actor_oper_port_state %d ",
- rta_getattr_u8(tb[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE]));
+ print_int(PRINT_ANY,
+ "ad_actor_oper_port_state",
+ "ad_actor_oper_port_state %d ",
+ rta_getattr_u8(tb[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE]));
if (tb[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE])
- fprintf(f, "ad_partner_oper_port_state %d ",
- rta_getattr_u16(tb[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE]));
+ print_int(PRINT_ANY,
+ "ad_partner_oper_port_state",
+ "ad_partner_oper_port_state %d ",
+ rta_getattr_u16(tb[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE]));
}
static int bond_slave_parse_opt(struct link_util *lu, int argc, char **argv,
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 07/27] ip: iplink_bond.c: add json output support
From: Julien Fortin @ 2017-08-17 17:35 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Schema and live example:
bond: IFLA_INFO_DATA
{
"mode": {
"type": "string",
"attr": "IFLA_BOND_MODE"
},
"active_slave": {
"type": "string",
"attr": "IFLA_BOND_ACTIVE_SLAVE",
"mutually_exclusive": {
"active_slave_index": {
"type": "int",
"comment": "if active slave doesn't have a valid ifname"
}
}
},
"miimon": {
"type": "uint",
"attr": "IFLA_BOND_MIIMON"
},
"updelay": {
"type": "uint",
"attr": "IFLA_BOND_UPDELAY"
},
"downdelay": {
"type": "uint",
"attr": "IFLA_BOND_DOWNDELAY"
},
"use_carrier": {
"type": "uint",
"attr": "IFLA_BOND_USE_CARRIER"
},
"arp_interval": {
"type": "uint",
"attr": "IFLA_BOND_ARP_INTERVAL"
},
"arp_ip_target": {
"type": "array",
"attr": "IFLA_BOND_ARP_IP_TARGET",
"array": [
{
"type": "string"
}
]
},
"arp_validate": {
"type": "string",
"attr": "IFLA_BOND_ARP_VALIDATE"
},
"arp_all_targets": {
"type": "string",
"attr": "IFLA_BOND_ARP_ALL_TARGETS"
},
"primary": {
"type": "string",
"attr": "IFLA_BOND_PRIMARY",
"mutually_exclusive": {
"primary_index": {
"type": "int",
"comment": "if primary doesn't have a valid ifname"
}
}
},
"primary_reselect": {
"type": "string",
"attr": "IFLA_BOND_PRIMARY_RESELECT"
},
"fail_over_mac": {
"type": "string",
"attr": "IFLA_BOND_FAIL_OVER_MAC"
},
"xmit_hash_policy": {
"type": "string",
"attr": "IFLA_BOND_XMIT_HASH_POLICY"
},
"resend_igmp": {
"type": "uint",
"attr": "IFLA_BOND_RESEND_IGMP"
},
"num_peer_notif": {
"type": "uint",
"attr": "IFLA_BOND_NUM_PEER_NOTIF"
},
"all_slaves_active": {
"type": "uint",
"attr": "IFLA_BOND_ALL_SLAVES_ACTIVE"
},
"min_links": {
"type": "uint",
"attr": "IFLA_BOND_MIN_LINKS"
},
"lp_interval": {
"type": "uint",
"attr": "IFLA_BOND_LP_INTERVAL"
},
"packets_per_slave": {
"type": "uint",
"attr": "IFLA_BOND_PACKETS_PER_SLAVE"
},
"ad_lacp_rate": {
"type": "string",
"attr": "IFLA_BOND_AD_LACP_RATE"
},
"ad_select": {
"type": "string",
"attr": "IFLA_BOND_AD_SELECT"
},
"ad_info": {
"type": "dict",
"attr": "IFLA_BOND_AD_INFO",
"dict": {
"aggregator": {
"type": "int",
"attr": "IFLA_BOND_AD_INFO_AGGREGATOR"
},
"num_ports": {
"type": "int",
"attr": "IFLA_BOND_AD_INFO_NUM_PORTS"
},
"actor_key": {
"type": "int",
"attr": "IFLA_BOND_AD_INFO_ACTOR_KEY"
},
"partner_key": {
"type": "int",
"attr": "IFLA_BOND_AD_INFO_PARTNER_KEY"
},
"partner_mac": {
"type": "string",
"attr": "IFLA_BOND_AD_INFO_PARTNER_MAC"
}
}
},
"ad_actor_sys_prio": {
"type": "uint",
"attr": "IFLA_BOND_AD_ACTOR_SYS_PRIO"
},
"ad_user_port_key": {
"type": "uint",
"attr": "IFLA_BOND_AD_USER_PORT_KEY"
},
"ad_actor_system": {
"type": "string",
"attr": "IFLA_BOND_AD_ACTOR_SYSTEM"
},
"tlb_dynamic_lb": {
"type": "uint",
"attr": "IFLA_BOND_TLB_DYNAMIC_LB"
}
}
$ ip link add dev bond42 type bond
$ ip link set dev swp5 master bond42
$ ip link set dev bond42 up
$ ip link set dev swp5 up
$ ip -details -json link show
[{
"ifindex": 7,
"ifname": "swp5",
"flags": ["BROADCAST","MULTICAST","SLAVE","UP","LOWER_UP"],
"mtu": 1500,
"qdisc": "pfifo_fast",
"master": "bond42",
"operstate": "UP",
"linkmode": "DEFAULT",
"group": "default",
"txqlen": 1000,
"link_type": "ether",
"address": "08:00:27:5c:03:c6",
"broadcast": "ff:ff:ff:ff:ff:ff",
"promiscuity": 0,
"linkinfo": {
"info_slave_kind": "bond",
"info_slave_data": {
"state": "BACKUP",
"mii_status": "UP",
"link_failure_count": 0,
"perm_hwaddr": "08:00:27:5c:03:c6",
"queue_id": 0,
"ad_aggregator_id": 1,
"ad_actor_oper_port_state": 79,
"ad_partner_oper_port_state": 1
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 1,
"num_rx_queues": 1,
"gso_max_size": 65536,
"gso_max_segs": 65535
},{
"ifindex": 14,
"ifname": "bond42",
"flags": ["NO-CARRIER","BROADCAST","MULTICAST","MASTER","UP"],
"mtu": 1500,
"qdisc": "noqueue",
"operstate": "DOWN",
"linkmode": "DEFAULT",
"group": "default",
"link_type": "ether",
"address": "08:00:27:5c:03:c6",
"broadcast": "ff:ff:ff:ff:ff:ff",
"promiscuity": 0,
"linkinfo": {
"info_kind": "bond",
"info_data": {
"mode": "802.3ad",
"miimon": 100,
"updelay": 0,
"downdelay": 0,
"use_carrier": 1,
"arp_interval": 0,
"arp_validate": null,
"arp_all_targets": "any",
"primary_reselect": "always",
"fail_over_mac": "none",
"xmit_hash_policy": "layer3+4",
"resend_igmp": 1,
"num_peer_notif": 1,
"all_slaves_active": 0,
"min_links": 1,
"lp_interval": 1,
"packets_per_slave": 1,
"ad_lacp_rate": "fast",
"ad_select": "stable",
"ad_info": {
"aggregator": 1,
"num_ports": 1,
"actor_key": 0,
"partner_key": 1,
"partner_mac": "00:00:00:00:00:00"
},
"ad_actor_sys_prio": 65535,
"ad_user_port_key": 0,
"ad_actor_system": "00:00:00:00:00:00"
}
},
"inet6_addr_gen_mode": "eui64",
"num_tx_queues": 16,
"num_rx_queues": 16,
"gso_max_size": 65536,
"gso_max_segs": 65535
}
]
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/iplink_bond.c | 231 ++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 160 insertions(+), 71 deletions(-)
diff --git a/ip/iplink_bond.c b/ip/iplink_bond.c
index 772b05fd..2b5cf4f6 100644
--- a/ip/iplink_bond.c
+++ b/ip/iplink_bond.c
@@ -376,8 +376,8 @@ static void bond_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_BOND_MODE]) {
const char *mode = get_name(mode_tbl,
- rta_getattr_u8(tb[IFLA_BOND_MODE]));
- fprintf(f, "mode %s ", mode);
+ rta_getattr_u8(tb[IFLA_BOND_MODE]));
+ print_string(PRINT_ANY, "mode", "mode %s ", mode);
}
if (tb[IFLA_BOND_ACTIVE_SLAVE] &&
@@ -386,61 +386,97 @@ static void bond_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
const char *n = if_indextoname(ifindex, buf);
if (n)
- fprintf(f, "active_slave %s ", n);
+ print_string(PRINT_ANY,
+ "active_slave",
+ "active_slave %s ",
+ n);
else
- fprintf(f, "active_slave %u ", ifindex);
+ print_uint(PRINT_ANY,
+ "active_slave_index",
+ "active_slave %u ",
+ ifindex);
}
if (tb[IFLA_BOND_MIIMON])
- fprintf(f, "miimon %u ", rta_getattr_u32(tb[IFLA_BOND_MIIMON]));
+ print_uint(PRINT_ANY,
+ "miimon",
+ "miimon %u ",
+ rta_getattr_u32(tb[IFLA_BOND_MIIMON]));
if (tb[IFLA_BOND_UPDELAY])
- fprintf(f, "updelay %u ", rta_getattr_u32(tb[IFLA_BOND_UPDELAY]));
+ print_uint(PRINT_ANY,
+ "updelay",
+ "updelay %u ",
+ rta_getattr_u32(tb[IFLA_BOND_UPDELAY]));
if (tb[IFLA_BOND_DOWNDELAY])
- fprintf(f, "downdelay %u ",
- rta_getattr_u32(tb[IFLA_BOND_DOWNDELAY]));
+ print_uint(PRINT_ANY,
+ "downdelay",
+ "downdelay %u ",
+ rta_getattr_u32(tb[IFLA_BOND_DOWNDELAY]));
if (tb[IFLA_BOND_USE_CARRIER])
- fprintf(f, "use_carrier %u ",
- rta_getattr_u8(tb[IFLA_BOND_USE_CARRIER]));
+ print_uint(PRINT_ANY,
+ "use_carrier",
+ "use_carrier %u ",
+ rta_getattr_u8(tb[IFLA_BOND_USE_CARRIER]));
if (tb[IFLA_BOND_ARP_INTERVAL])
- fprintf(f, "arp_interval %u ",
- rta_getattr_u32(tb[IFLA_BOND_ARP_INTERVAL]));
+ print_uint(PRINT_ANY,
+ "arp_interval",
+ "arp_interval %u ",
+ rta_getattr_u32(tb[IFLA_BOND_ARP_INTERVAL]));
if (tb[IFLA_BOND_ARP_IP_TARGET]) {
struct rtattr *iptb[BOND_MAX_ARP_TARGETS + 1];
int i;
parse_rtattr_nested(iptb, BOND_MAX_ARP_TARGETS,
- tb[IFLA_BOND_ARP_IP_TARGET]);
+ tb[IFLA_BOND_ARP_IP_TARGET]);
- if (iptb[0])
- fprintf(f, "arp_ip_target ");
+ if (iptb[0]) {
+ open_json_array(PRINT_JSON, "arp_ip_target");
+ print_string(PRINT_FP, NULL, "arp_ip_target ", NULL);
+ }
for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
if (iptb[i])
- fprintf(f, "%s",
- rt_addr_n2a_rta(AF_INET, iptb[i]));
- if (i < BOND_MAX_ARP_TARGETS-1 && iptb[i+1])
+ print_string(PRINT_ANY,
+ NULL,
+ "%s",
+ rt_addr_n2a_rta(AF_INET, iptb[i]));
+ if (!is_json_context()
+ && i < BOND_MAX_ARP_TARGETS-1
+ && iptb[i+1])
fprintf(f, ",");
}
- if (iptb[0])
- fprintf(f, " ");
+ if (iptb[0]) {
+ print_string(PRINT_FP, NULL, " ", NULL);
+ close_json_array(PRINT_JSON, NULL);
+ }
}
if (tb[IFLA_BOND_ARP_VALIDATE]) {
- const char *arp_validate = get_name(arp_validate_tbl,
- rta_getattr_u32(tb[IFLA_BOND_ARP_VALIDATE]));
- fprintf(f, "arp_validate %s ", arp_validate);
+ __u32 arp_v = rta_getattr_u32(tb[IFLA_BOND_ARP_VALIDATE]);
+ const char *arp_validate = get_name(arp_validate_tbl, arp_v);
+
+ if (!arp_v && is_json_context())
+ print_null(PRINT_JSON, "arp_validate", NULL, NULL);
+ else
+ print_string(PRINT_ANY,
+ "arp_validate",
+ "arp_validate %s ",
+ arp_validate);
}
if (tb[IFLA_BOND_ARP_ALL_TARGETS]) {
const char *arp_all_targets = get_name(arp_all_targets_tbl,
- rta_getattr_u32(tb[IFLA_BOND_ARP_ALL_TARGETS]));
- fprintf(f, "arp_all_targets %s ", arp_all_targets);
+ rta_getattr_u32(tb[IFLA_BOND_ARP_ALL_TARGETS]));
+ print_string(PRINT_ANY,
+ "arp_all_targets",
+ "arp_all_targets %s ",
+ arp_all_targets);
}
if (tb[IFLA_BOND_PRIMARY] &&
@@ -449,123 +485,176 @@ static void bond_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
const char *n = if_indextoname(ifindex, buf);
if (n)
- fprintf(f, "primary %s ", n);
+ print_string(PRINT_ANY, "primary", "primary %s ", n);
else
- fprintf(f, "primary %u ", ifindex);
+ print_uint(PRINT_ANY,
+ "primary_index",
+ "primary %u ",
+ ifindex);
}
if (tb[IFLA_BOND_PRIMARY_RESELECT]) {
const char *primary_reselect = get_name(primary_reselect_tbl,
- rta_getattr_u8(tb[IFLA_BOND_PRIMARY_RESELECT]));
- fprintf(f, "primary_reselect %s ", primary_reselect);
+ rta_getattr_u8(tb[IFLA_BOND_PRIMARY_RESELECT]));
+ print_string(PRINT_ANY,
+ "primary_reselect",
+ "primary_reselect %s ",
+ primary_reselect);
}
if (tb[IFLA_BOND_FAIL_OVER_MAC]) {
const char *fail_over_mac = get_name(fail_over_mac_tbl,
- rta_getattr_u8(tb[IFLA_BOND_FAIL_OVER_MAC]));
- fprintf(f, "fail_over_mac %s ", fail_over_mac);
+ rta_getattr_u8(tb[IFLA_BOND_FAIL_OVER_MAC]));
+ print_string(PRINT_ANY,
+ "fail_over_mac",
+ "fail_over_mac %s ",
+ fail_over_mac);
}
if (tb[IFLA_BOND_XMIT_HASH_POLICY]) {
const char *xmit_hash_policy = get_name(xmit_hash_policy_tbl,
- rta_getattr_u8(tb[IFLA_BOND_XMIT_HASH_POLICY]));
- fprintf(f, "xmit_hash_policy %s ", xmit_hash_policy);
+ rta_getattr_u8(tb[IFLA_BOND_XMIT_HASH_POLICY]));
+ print_string(PRINT_ANY,
+ "xmit_hash_policy",
+ "xmit_hash_policy %s ",
+ xmit_hash_policy);
}
if (tb[IFLA_BOND_RESEND_IGMP])
- fprintf(f, "resend_igmp %u ",
- rta_getattr_u32(tb[IFLA_BOND_RESEND_IGMP]));
+ print_uint(PRINT_ANY,
+ "resend_igmp",
+ "resend_igmp %u ",
+ rta_getattr_u32(tb[IFLA_BOND_RESEND_IGMP]));
if (tb[IFLA_BOND_NUM_PEER_NOTIF])
- fprintf(f, "num_grat_arp %u ",
- rta_getattr_u8(tb[IFLA_BOND_NUM_PEER_NOTIF]));
+ print_uint(PRINT_ANY,
+ "num_peer_notif",
+ "num_grat_arp %u ",
+ rta_getattr_u8(tb[IFLA_BOND_NUM_PEER_NOTIF]));
if (tb[IFLA_BOND_ALL_SLAVES_ACTIVE])
- fprintf(f, "all_slaves_active %u ",
- rta_getattr_u8(tb[IFLA_BOND_ALL_SLAVES_ACTIVE]));
+ print_uint(PRINT_ANY,
+ "all_slaves_active",
+ "all_slaves_active %u ",
+ rta_getattr_u8(tb[IFLA_BOND_ALL_SLAVES_ACTIVE]));
if (tb[IFLA_BOND_MIN_LINKS])
- fprintf(f, "min_links %u ",
- rta_getattr_u32(tb[IFLA_BOND_MIN_LINKS]));
+ print_uint(PRINT_ANY,
+ "min_links",
+ "min_links %u ",
+ rta_getattr_u32(tb[IFLA_BOND_MIN_LINKS]));
if (tb[IFLA_BOND_LP_INTERVAL])
- fprintf(f, "lp_interval %u ",
- rta_getattr_u32(tb[IFLA_BOND_LP_INTERVAL]));
+ print_uint(PRINT_ANY,
+ "lp_interval",
+ "lp_interval %u ",
+ rta_getattr_u32(tb[IFLA_BOND_LP_INTERVAL]));
if (tb[IFLA_BOND_PACKETS_PER_SLAVE])
- fprintf(f, "packets_per_slave %u ",
- rta_getattr_u32(tb[IFLA_BOND_PACKETS_PER_SLAVE]));
+ print_uint(PRINT_ANY,
+ "packets_per_slave",
+ "packets_per_slave %u ",
+ rta_getattr_u32(tb[IFLA_BOND_PACKETS_PER_SLAVE]));
if (tb[IFLA_BOND_AD_LACP_RATE]) {
const char *lacp_rate = get_name(lacp_rate_tbl,
- rta_getattr_u8(tb[IFLA_BOND_AD_LACP_RATE]));
- fprintf(f, "lacp_rate %s ", lacp_rate);
+ rta_getattr_u8(tb[IFLA_BOND_AD_LACP_RATE]));
+ print_string(PRINT_ANY,
+ "ad_lacp_rate",
+ "lacp_rate %s ",
+ lacp_rate);
}
if (tb[IFLA_BOND_AD_SELECT]) {
const char *ad_select = get_name(ad_select_tbl,
- rta_getattr_u8(tb[IFLA_BOND_AD_SELECT]));
- fprintf(f, "ad_select %s ", ad_select);
+ rta_getattr_u8(tb[IFLA_BOND_AD_SELECT]));
+ print_string(PRINT_ANY,
+ "ad_select",
+ "ad_select %s ",
+ ad_select);
}
if (tb[IFLA_BOND_AD_INFO]) {
struct rtattr *adtb[IFLA_BOND_AD_INFO_MAX + 1];
parse_rtattr_nested(adtb, IFLA_BOND_AD_INFO_MAX,
- tb[IFLA_BOND_AD_INFO]);
+ tb[IFLA_BOND_AD_INFO]);
+
+ open_json_object("ad_info");
if (adtb[IFLA_BOND_AD_INFO_AGGREGATOR])
- fprintf(f, "ad_aggregator %d ",
- rta_getattr_u16(adtb[IFLA_BOND_AD_INFO_AGGREGATOR]));
+ print_int(PRINT_ANY,
+ "aggregator",
+ "ad_aggregator %d ",
+ rta_getattr_u16(adtb[IFLA_BOND_AD_INFO_AGGREGATOR]));
if (adtb[IFLA_BOND_AD_INFO_NUM_PORTS])
- fprintf(f, "ad_num_ports %d ",
- rta_getattr_u16(adtb[IFLA_BOND_AD_INFO_NUM_PORTS]));
+ print_int(PRINT_ANY,
+ "num_ports",
+ "ad_num_ports %d ",
+ rta_getattr_u16(adtb[IFLA_BOND_AD_INFO_NUM_PORTS]));
if (adtb[IFLA_BOND_AD_INFO_ACTOR_KEY])
- fprintf(f, "ad_actor_key %d ",
- rta_getattr_u16(adtb[IFLA_BOND_AD_INFO_ACTOR_KEY]));
+ print_int(PRINT_ANY,
+ "actor_key",
+ "ad_actor_key %d ",
+ rta_getattr_u16(adtb[IFLA_BOND_AD_INFO_ACTOR_KEY]));
if (adtb[IFLA_BOND_AD_INFO_PARTNER_KEY])
- fprintf(f, "ad_partner_key %d ",
- rta_getattr_u16(adtb[IFLA_BOND_AD_INFO_PARTNER_KEY]));
+ print_int(PRINT_ANY,
+ "partner_key",
+ "ad_partner_key %d ",
+ rta_getattr_u16(adtb[IFLA_BOND_AD_INFO_PARTNER_KEY]));
if (adtb[IFLA_BOND_AD_INFO_PARTNER_MAC]) {
unsigned char *p =
RTA_DATA(adtb[IFLA_BOND_AD_INFO_PARTNER_MAC]);
SPRINT_BUF(b);
- fprintf(f, "ad_partner_mac %s ",
- ll_addr_n2a(p, ETH_ALEN, 0, b, sizeof(b)));
+ print_string(PRINT_ANY,
+ "partner_mac",
+ "ad_partner_mac %s ",
+ ll_addr_n2a(p, ETH_ALEN, 0, b, sizeof(b)));
}
+
+ close_json_object();
}
if (tb[IFLA_BOND_AD_ACTOR_SYS_PRIO]) {
- fprintf(f, "ad_actor_sys_prio %u ",
- rta_getattr_u16(tb[IFLA_BOND_AD_ACTOR_SYS_PRIO]));
+ print_uint(PRINT_ANY,
+ "ad_actor_sys_prio",
+ "ad_actor_sys_prio %u ",
+ rta_getattr_u16(tb[IFLA_BOND_AD_ACTOR_SYS_PRIO]));
}
if (tb[IFLA_BOND_AD_USER_PORT_KEY]) {
- fprintf(f, "ad_user_port_key %u ",
- rta_getattr_u16(tb[IFLA_BOND_AD_USER_PORT_KEY]));
+ print_uint(PRINT_ANY,
+ "ad_user_port_key",
+ "ad_user_port_key %u ",
+ rta_getattr_u16(tb[IFLA_BOND_AD_USER_PORT_KEY]));
}
if (tb[IFLA_BOND_AD_ACTOR_SYSTEM]) {
/* We assume the l2 address is an Ethernet MAC address */
SPRINT_BUF(b1);
- fprintf(f, "ad_actor_system %s ",
- ll_addr_n2a(RTA_DATA(tb[IFLA_BOND_AD_ACTOR_SYSTEM]),
- RTA_PAYLOAD(tb[IFLA_BOND_AD_ACTOR_SYSTEM]),
- 1 /*ARPHDR_ETHER*/, b1, sizeof(b1)));
+
+ print_string(PRINT_ANY,
+ "ad_actor_system",
+ "ad_actor_system %s ",
+ ll_addr_n2a(RTA_DATA(tb[IFLA_BOND_AD_ACTOR_SYSTEM]),
+ RTA_PAYLOAD(tb[IFLA_BOND_AD_ACTOR_SYSTEM]),
+ 1 /*ARPHDR_ETHER*/, b1, sizeof(b1)));
}
if (tb[IFLA_BOND_TLB_DYNAMIC_LB]) {
- fprintf(f, "tlb_dynamic_lb %u ",
- rta_getattr_u8(tb[IFLA_BOND_TLB_DYNAMIC_LB]));
+ print_uint(PRINT_ANY,
+ "tlb_dynamic_lb",
+ "tlb_dynamic_lb %u ",
+ rta_getattr_u8(tb[IFLA_BOND_TLB_DYNAMIC_LB]));
}
}
static void bond_print_help(struct link_util *lu, int argc, char **argv,
- FILE *f)
+ FILE *f)
{
print_explain(f);
}
--
2.14.1
^ permalink raw reply related
* [PATCH iproute2 json v2 06/27] ip: iplink.c: open/close json obj for ip -brief -json link show dev DEV
From: Julien Fortin @ 2017-08-17 17:35 UTC (permalink / raw)
To: netdev; +Cc: roopa, nikolay, dsa, Julien Fortin
In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com>
From: Julien Fortin <julien@cumulusnetworks.com>
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
ip/iplink.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/ip/iplink.c b/ip/iplink.c
index 5aff2fde..19bda1b9 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -1041,10 +1041,12 @@ int iplink_get(unsigned int flags, char *name, __u32 filt_mask)
if (rtnl_talk(&rth, &req.n, &answer.n, sizeof(answer)) < 0)
return -2;
+ open_json_object(NULL);
if (brief)
print_linkinfo_brief(NULL, &answer.n, stdout, NULL);
else
print_linkinfo(NULL, &answer.n, stdout);
+ close_json_object();
return 0;
}
--
2.14.1
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox