msm: ipa: AP+STA statistics support for IPAv2 driver

Add IPA stats support on AP+STA mode for V2 driver
when CNE queries. Also add metering funtionality
on WIFI interface to stop the data transfer
when quota reached on WIFI-case.

Change-Id: I51a771423e6a35ea0453b978be484d0464bddf14
Acked-by: Chaitanya Pratapa <cpratapa@qti.qualcomm.com>
Signed-off-by: Utkarsh Saxena <usaxena@codeaurora.org>
This commit is contained in:
Utkarsh Saxena 2017-01-04 23:00:48 +05:30
parent 053b0dcf11
commit e1131a815f
7 changed files with 326 additions and 24 deletions

View file

@ -1,4 +1,4 @@
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
@ -941,6 +941,10 @@ struct ipa_uc_wdi_ctx {
struct IpaHwStatsWDIInfoData_t *wdi_uc_stats_mmio;
void *priv;
ipa_uc_ready_cb uc_ready_cb;
/* for AP+STA stats update */
#ifdef IPA_WAN_MSG_IPv6_ADDR_GW_LEN
ipa_wdi_meter_notifier_cb stats_notify;
#endif
};
/**
@ -1524,6 +1528,7 @@ int ipa2_resume_wdi_pipe(u32 clnt_hdl);
int ipa2_suspend_wdi_pipe(u32 clnt_hdl);
int ipa2_get_wdi_stats(struct IpaHwStatsWDIInfoData_t *stats);
u16 ipa2_get_smem_restr_bytes(void);
int ipa2_broadcast_wdi_quota_reach_ind(uint32_t fid, uint64_t num_bytes);
int ipa2_setup_uc_ntn_pipes(struct ipa_ntn_conn_in_params *inp,
ipa_notify_cb notify, void *priv, u8 hdr_len,
struct ipa_ntn_conn_out_params *outp);
@ -1564,6 +1569,10 @@ enum ipacm_client_enum ipa2_get_client(int pipe_idx);
bool ipa2_get_client_uplink(int pipe_idx);
int ipa2_get_wlan_stats(struct ipa_get_wdi_sap_stats *wdi_sap_stats);
int ipa2_set_wlan_quota(struct ipa_set_wifi_quota *wdi_quota);
/*
* IPADMA
*/

View file

@ -1,4 +1,4 @@
/* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
/* Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
@ -763,7 +763,8 @@ static void ipa_q6_clnt_ind_cb(struct qmi_handle *handle, unsigned int msg_id,
IPAWANDBG("Quota reached indication on qmux(%d) Mbytes(%lu)\n",
qmi_ind.apn.mux_id,
(unsigned long int) qmi_ind.apn.num_Mbytes);
ipa_broadcast_quota_reach_ind(qmi_ind.apn.mux_id);
ipa_broadcast_quota_reach_ind(qmi_ind.apn.mux_id,
IPA_UPSTEAM_MODEM);
}
}

View file

@ -1,4 +1,4 @@
/* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
/* Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
@ -168,7 +168,8 @@ int rmnet_ipa_poll_tethering_stats(struct wan_ioctl_poll_tethering_stats *data);
int rmnet_ipa_set_data_quota(struct wan_ioctl_set_data_quota *data);
void ipa_broadcast_quota_reach_ind(uint32_t mux_id);
void ipa_broadcast_quota_reach_ind(uint32_t mux_id,
enum ipa_upstream_type upstream_type);
int rmnet_ipa_set_tether_client_pipe(struct wan_ioctl_set_tether_client_pipe
*data);
@ -176,6 +177,8 @@ int rmnet_ipa_set_tether_client_pipe(struct wan_ioctl_set_tether_client_pipe
int rmnet_ipa_query_tethering_stats(struct wan_ioctl_query_tether_stats *data,
bool reset);
int rmnet_ipa_reset_tethering_stats(struct wan_ioctl_reset_tether_stats *data);
int ipa_qmi_get_data_stats(struct ipa_get_data_stats_req_msg_v01 *req,
struct ipa_get_data_stats_resp_msg_v01 *resp);
@ -268,7 +271,21 @@ static inline int rmnet_ipa_set_data_quota(
return -EPERM;
}
static inline void ipa_broadcast_quota_reach_ind(uint32_t mux_id) { }
static inline void ipa_broadcast_quota_reach_ind
(
uint32_t mux_id,
enum ipa_upstream_type upstream_type)
{
}
static int rmnet_ipa_reset_tethering_stats
(
struct wan_ioctl_reset_tether_stats *data
)
{
return -EPERM;
}
static inline int ipa_qmi_get_data_stats(
struct ipa_get_data_stats_req_msg_v01 *req,

View file

@ -1,4 +1,4 @@
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
@ -12,6 +12,7 @@
#include "ipa_i.h"
#include <linux/dmapool.h>
#include <linux/delay.h>
#include "ipa_qmi_service.h"
#define IPA_HOLB_TMR_DIS 0x0
@ -1205,6 +1206,12 @@ int ipa2_connect_wdi_pipe(struct ipa_wdi_in_params *in,
ep->client_notify = in->sys.notify;
ep->priv = in->sys.priv;
/* for AP+STA stats update */
if (in->wdi_notify)
ipa_ctx->uc_wdi_ctx.stats_notify = in->wdi_notify;
else
IPADBG("in->wdi_notify is null\n");
if (!ep->skip_ep_cfg) {
if (ipa2_cfg_ep(ipa_ep_idx, &in->sys.ipa_ep_cfg)) {
IPAERR("fail to configure EP.\n");
@ -1302,6 +1309,12 @@ int ipa2_disconnect_wdi_pipe(u32 clnt_hdl)
IPADBG("client (ep: %d) disconnected\n", clnt_hdl);
/* for AP+STA stats update */
if (ipa_ctx->uc_wdi_ctx.stats_notify)
ipa_ctx->uc_wdi_ctx.stats_notify = NULL;
else
IPADBG("uc_wdi_ctx.stats_notify already null\n");
uc_timeout:
return result;
}
@ -1660,6 +1673,23 @@ uc_timeout:
return result;
}
/**
* ipa_broadcast_wdi_quota_reach_ind() - quota reach
* @uint32_t fid: [in] input netdev ID
* @uint64_t num_bytes: [in] used bytes
*
* Returns: 0 on success, negative on failure
*/
int ipa2_broadcast_wdi_quota_reach_ind(uint32_t fid,
uint64_t num_bytes)
{
IPAERR("Quota reached indication on fis(%d) Mbytes(%lu)\n",
fid,
(unsigned long int) num_bytes);
ipa_broadcast_quota_reach_ind(0, IPA_UPSTEAM_WLAN);
return 0;
}
int ipa_write_qmapid_wdi_pipe(u32 clnt_hdl, u8 qmap_id)
{
int result = 0;

View file

@ -1,4 +1,4 @@
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
@ -953,11 +953,39 @@ void ipa2_set_client(int index, enum ipacm_client_enum client, bool uplink)
}
}
/* ipa2_get_wlan_stats() - get ipa wifi stats
*
* Return value: success or failure
*/
int ipa2_get_wlan_stats(struct ipa_get_wdi_sap_stats *wdi_sap_stats)
{
if (ipa_ctx->uc_wdi_ctx.stats_notify) {
ipa_ctx->uc_wdi_ctx.stats_notify(IPA_GET_WDI_SAP_STATS,
wdi_sap_stats);
} else {
IPAERR("uc_wdi_ctx.stats_notify not registered\n");
return -EFAULT;
}
return 0;
}
int ipa2_set_wlan_quota(struct ipa_set_wifi_quota *wdi_quota)
{
if (ipa_ctx->uc_wdi_ctx.stats_notify) {
ipa_ctx->uc_wdi_ctx.stats_notify(IPA_SET_WIFI_QUOTA,
wdi_quota);
} else {
IPAERR("uc_wdi_ctx.stats_notify not registered\n");
return -EFAULT;
}
return 0;
}
/**
* ipa2_get_client() - provide client mapping
* @client: client type
*
* Return value: none
* Return value: client mapping enum
*/
enum ipacm_client_enum ipa2_get_client(int pipe_idx)
{
@ -5030,6 +5058,8 @@ int ipa2_bind_api_controller(enum ipa_hw_type ipa_hw_type,
api_ctrl->ipa_suspend_wdi_pipe = ipa2_suspend_wdi_pipe;
api_ctrl->ipa_get_wdi_stats = ipa2_get_wdi_stats;
api_ctrl->ipa_get_smem_restr_bytes = ipa2_get_smem_restr_bytes;
api_ctrl->ipa_broadcast_wdi_quota_reach_ind =
ipa2_broadcast_wdi_quota_reach_ind;
api_ctrl->ipa_uc_wdi_get_dbpa = ipa2_uc_wdi_get_dbpa;
api_ctrl->ipa_uc_reg_rdyCB = ipa2_uc_reg_rdyCB;
api_ctrl->ipa_uc_dereg_rdyCB = ipa2_uc_dereg_rdyCB;

View file

@ -1,4 +1,4 @@
/* Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
/* Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
@ -52,6 +52,8 @@
#define DEFAULT_OUTSTANDING_LOW 32
#define IPA_WWAN_DEV_NAME "rmnet_ipa%d"
#define IPA_UPSTEAM_WLAN_IFACE_NAME "wlan0"
#define IPA_WWAN_DEVICE_COUNT (1)
#define IPA_WWAN_RX_SOFTIRQ_THRESH 16
@ -770,6 +772,22 @@ static int find_vchannel_name_index(const char *vchannel_name)
return MAX_NUM_OF_MUX_CHANNEL;
}
static enum ipa_upstream_type find_upstream_type(const char *upstreamIface)
{
int i;
for (i = 0; i < MAX_NUM_OF_MUX_CHANNEL; i++) {
if (strcmp(mux_channel[i].vchannel_name,
upstreamIface) == 0)
return IPA_UPSTEAM_MODEM;
}
if (strcmp(IPA_UPSTEAM_WLAN_IFACE_NAME, upstreamIface) == 0)
return IPA_UPSTEAM_WLAN;
else
return IPA_UPSTEAM_MAX;
}
static int wwan_register_to_ipa(int index)
{
struct ipa_tx_intf tx_properties = {0};
@ -2525,10 +2543,10 @@ int rmnet_ipa_poll_tethering_stats(struct wan_ioctl_poll_tethering_stats *data)
}
/**
* rmnet_ipa_set_data_quota() - Data quota setting IOCTL handler
* rmnet_ipa_set_data_quota_modem() - Data quota setting IOCTL handler
* @data - IOCTL data
*
* This function handles WAN_IOC_SET_DATA_QUOTA.
* This function handles WAN_IOC_SET_DATA_QUOTA on modem interface.
* It translates the given interface name to the Modem MUX ID and
* sends the request of the quota to the IPA Modem driver via QMI.
*
@ -2537,12 +2555,16 @@ int rmnet_ipa_poll_tethering_stats(struct wan_ioctl_poll_tethering_stats *data)
* -EFAULT: Invalid interface name provided
* other: See ipa_qmi_set_data_quota
*/
int rmnet_ipa_set_data_quota(struct wan_ioctl_set_data_quota *data)
static int rmnet_ipa_set_data_quota_modem(struct wan_ioctl_set_data_quota *data)
{
u32 mux_id;
int index;
struct ipa_set_data_usage_quota_req_msg_v01 req;
/* stop quota */
if (!data->set_quota)
ipa_qmi_stop_data_qouta();
index = find_vchannel_name_index(data->interface_name);
IPAWANERR("iface name %s, quota %lu\n",
data->interface_name,
@ -2567,6 +2589,65 @@ int rmnet_ipa_set_data_quota(struct wan_ioctl_set_data_quota *data)
return ipa_qmi_set_data_quota(&req);
}
static int rmnet_ipa_set_data_quota_wifi(struct wan_ioctl_set_data_quota *data)
{
struct ipa_set_wifi_quota wifi_quota;
int rc = 0;
memset(&wifi_quota, 0, sizeof(struct ipa_set_wifi_quota));
wifi_quota.set_quota = data->set_quota;
wifi_quota.quota_bytes = data->quota_mbytes;
IPAWANDBG("iface name %s, quota %lu\n",
data->interface_name,
(unsigned long int) data->quota_mbytes);
rc = ipa2_set_wlan_quota(&wifi_quota);
/* check if wlan-fw takes this quota-set */
if (!wifi_quota.set_valid)
rc = -EFAULT;
return rc;
}
/**
* rmnet_ipa_set_data_quota() - Data quota setting IOCTL handler
* @data - IOCTL data
*
* This function handles WAN_IOC_SET_DATA_QUOTA.
* It translates the given interface name to the Modem MUX ID and
* sends the request of the quota to the IPA Modem driver via QMI.
*
* Return codes:
* 0: Success
* -EFAULT: Invalid interface name provided
* other: See ipa_qmi_set_data_quota
*/
int rmnet_ipa_set_data_quota(struct wan_ioctl_set_data_quota *data)
{
enum ipa_upstream_type upstream_type;
int rc = 0;
/* get IPA backhaul type */
upstream_type = find_upstream_type(data->interface_name);
if (upstream_type == IPA_UPSTEAM_MAX) {
IPAWANERR("upstream iface %s not supported\n",
data->interface_name);
} else if (upstream_type == IPA_UPSTEAM_WLAN) {
rc = rmnet_ipa_set_data_quota_wifi(data);
if (rc) {
IPAWANERR("set quota on wifi failed\n");
return rc;
}
} else {
rc = rmnet_ipa_set_data_quota_modem(data);
if (rc) {
IPAWANERR("set quota on modem failed\n");
return rc;
}
}
return rc;
}
/* rmnet_ipa_set_tether_client_pipe() -
* @data - IOCTL data
*
@ -2631,8 +2712,59 @@ int rmnet_ipa_set_tether_client_pipe(
return 0;
}
int rmnet_ipa_query_tethering_stats(struct wan_ioctl_query_tether_stats *data,
bool reset)
static int rmnet_ipa_query_tethering_stats_wifi(
struct wan_ioctl_query_tether_stats *data, bool reset)
{
struct ipa_get_wdi_sap_stats *sap_stats;
int rc;
sap_stats = kzalloc(sizeof(struct ipa_get_wdi_sap_stats),
GFP_KERNEL);
if (!sap_stats)
return -ENOMEM;
sap_stats->reset_stats = reset;
IPAWANDBG("reset the pipe stats %d\n", sap_stats->reset_stats);
rc = ipa2_get_wlan_stats(sap_stats);
if (rc) {
kfree(sap_stats);
return rc;
} else if (reset) {
kfree(sap_stats);
return 0;
}
if (sap_stats->stats_valid) {
data->ipv4_tx_packets = sap_stats->ipv4_tx_packets;
data->ipv4_tx_bytes = sap_stats->ipv4_tx_bytes;
data->ipv4_rx_packets = sap_stats->ipv4_rx_packets;
data->ipv4_rx_bytes = sap_stats->ipv4_rx_bytes;
data->ipv6_tx_packets = sap_stats->ipv6_tx_packets;
data->ipv6_tx_bytes = sap_stats->ipv6_tx_bytes;
data->ipv6_rx_packets = sap_stats->ipv6_rx_packets;
data->ipv6_rx_bytes = sap_stats->ipv6_rx_bytes;
}
IPAWANDBG("v4_rx_p(%lu) v6_rx_p(%lu) v4_rx_b(%lu) v6_rx_b(%lu)\n",
(unsigned long int) data->ipv4_rx_packets,
(unsigned long int) data->ipv6_rx_packets,
(unsigned long int) data->ipv4_rx_bytes,
(unsigned long int) data->ipv6_rx_bytes);
IPAWANDBG("tx_p_v4(%lu)v6(%lu)tx_b_v4(%lu) v6(%lu)\n",
(unsigned long int) data->ipv4_tx_packets,
(unsigned long int) data->ipv6_tx_packets,
(unsigned long int) data->ipv4_tx_bytes,
(unsigned long int) data->ipv6_tx_bytes);
kfree(sap_stats);
return rc;
}
int rmnet_ipa_query_tethering_stats_modem(
struct wan_ioctl_query_tether_stats *data,
bool reset
)
{
struct ipa_get_data_stats_req_msg_v01 *req;
struct ipa_get_data_stats_resp_msg_v01 *resp;
@ -2779,6 +2911,70 @@ int rmnet_ipa_query_tethering_stats(struct wan_ioctl_query_tether_stats *data,
return 0;
}
int rmnet_ipa_query_tethering_stats(struct wan_ioctl_query_tether_stats *data,
bool reset)
{
enum ipa_upstream_type upstream_type;
int rc = 0;
/* get IPA backhaul type */
upstream_type = find_upstream_type(data->upstreamIface);
if (upstream_type == IPA_UPSTEAM_MAX) {
IPAWANERR("upstreamIface %s not supported\n",
data->upstreamIface);
} else if (upstream_type == IPA_UPSTEAM_WLAN) {
IPAWANDBG_LOW(" query wifi-backhaul stats\n");
rc = rmnet_ipa_query_tethering_stats_wifi(
data, false);
if (rc) {
IPAWANERR("wlan WAN_IOC_QUERY_TETHER_STATS failed\n");
return rc;
}
} else {
IPAWANDBG_LOW(" query modem-backhaul stats\n");
rc = rmnet_ipa_query_tethering_stats_modem(
data, false);
if (rc) {
IPAWANERR("modem WAN_IOC_QUERY_TETHER_STATS failed\n");
return rc;
}
}
return rc;
}
int rmnet_ipa_reset_tethering_stats(struct wan_ioctl_reset_tether_stats *data)
{
enum ipa_upstream_type upstream_type;
int rc = 0;
/* get IPA backhaul type */
upstream_type = find_upstream_type(data->upstreamIface);
if (upstream_type == IPA_UPSTEAM_MAX) {
IPAWANERR("upstream iface %s not supported\n",
data->upstreamIface);
} else if (upstream_type == IPA_UPSTEAM_WLAN) {
IPAWANDBG(" reset wifi-backhaul stats\n");
rc = rmnet_ipa_query_tethering_stats_wifi(
NULL, true);
if (rc) {
IPAWANERR("reset WLAN stats failed\n");
return rc;
}
} else {
IPAWANDBG(" reset modem-backhaul stats\n");
rc = rmnet_ipa_query_tethering_stats_modem(
NULL, true);
if (rc) {
IPAWANERR("reset MODEM stats failed\n");
return rc;
}
}
return rc;
}
/**
* ipa_broadcast_quota_reach_ind() - Send Netlink broadcast on Quota
* @mux_id - The MUX ID on which the quota has been reached
@ -2788,7 +2984,8 @@ int rmnet_ipa_query_tethering_stats(struct wan_ioctl_query_tether_stats *data,
* on the specific interface which matches the mux_id has been reached.
*
*/
void ipa_broadcast_quota_reach_ind(u32 mux_id)
void ipa_broadcast_quota_reach_ind(u32 mux_id,
enum ipa_upstream_type upstream_type)
{
char alert_msg[IPA_QUOTA_REACH_ALERT_MAX_SIZE];
char iface_name_l[IPA_QUOTA_REACH_IF_NAME_MAX_SIZE];
@ -2798,12 +2995,18 @@ void ipa_broadcast_quota_reach_ind(u32 mux_id)
int res;
int index;
/* check upstream_type*/
if (upstream_type == IPA_UPSTEAM_MAX) {
IPAWANERR("upstreamIface type %d not supported\n",
upstream_type);
return;
} else if (upstream_type == IPA_UPSTEAM_MODEM) {
index = find_mux_channel_index(mux_id);
if (index == MAX_NUM_OF_MUX_CHANNEL) {
IPAWANERR("%u is an mux ID\n", mux_id);
return;
}
}
res = snprintf(alert_msg, IPA_QUOTA_REACH_ALERT_MAX_SIZE,
"ALERT_NAME=%s", "quotaReachedAlert");
@ -2811,16 +3014,28 @@ void ipa_broadcast_quota_reach_ind(u32 mux_id)
IPAWANERR("message too long (%d)", res);
return;
}
/* posting msg for L-release for CNE */
if (upstream_type == IPA_UPSTEAM_MODEM) {
res = snprintf(iface_name_l, IPA_QUOTA_REACH_IF_NAME_MAX_SIZE,
"UPSTREAM=%s", mux_channel[index].vchannel_name);
} else {
res = snprintf(iface_name_l, IPA_QUOTA_REACH_IF_NAME_MAX_SIZE,
"UPSTREAM=%s", IPA_UPSTEAM_WLAN_IFACE_NAME);
}
if (IPA_QUOTA_REACH_IF_NAME_MAX_SIZE <= res) {
IPAWANERR("message too long (%d)", res);
return;
}
/* posting msg for M-release for CNE */
if (upstream_type == IPA_UPSTEAM_MODEM) {
res = snprintf(iface_name_m, IPA_QUOTA_REACH_IF_NAME_MAX_SIZE,
"INTERFACE=%s", mux_channel[index].vchannel_name);
} else {
res = snprintf(iface_name_m, IPA_QUOTA_REACH_IF_NAME_MAX_SIZE,
"INTERFACE=%s", IPA_UPSTEAM_WLAN_IFACE_NAME);
}
if (IPA_QUOTA_REACH_IF_NAME_MAX_SIZE <= res) {
IPAWANERR("message too long (%d)", res);
return;

View file

@ -1,4 +1,4 @@
/* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
/* Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
@ -251,7 +251,7 @@ static long wan_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
break;
}
if (rmnet_ipa_query_tethering_stats(NULL, true)) {
if (rmnet_ipa_reset_tethering_stats(NULL)) {
IPAWANERR("WAN_IOC_QUERY_TETHER_STATS failed\n");
retval = -EFAULT;
break;