Skylar Chang | f3a7dac | 2017-01-25 09:16:55 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2014-2017, The Linux Foundation. All rights reserved. |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * WWAN Transport Network Driver. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/completion.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/if_arp.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/netdevice.h> |
| 25 | #include <linux/of_device.h> |
| 26 | #include <linux/string.h> |
| 27 | #include <linux/skbuff.h> |
| 28 | #include <linux/version.h> |
| 29 | #include <linux/workqueue.h> |
| 30 | #include <net/pkt_sched.h> |
| 31 | #include <soc/qcom/subsystem_restart.h> |
| 32 | #include <soc/qcom/subsystem_notif.h> |
| 33 | #include "ipa_qmi_service.h" |
| 34 | #include <linux/rmnet_ipa_fd_ioctl.h> |
| 35 | #include <linux/ipa.h> |
| 36 | #include <uapi/linux/net_map.h> |
Gidon Studinski | 3021a6f | 2016-11-10 12:48:48 +0200 | [diff] [blame] | 37 | #include <uapi/linux/msm_rmnet.h> |
| 38 | #include <net/rmnet_config.h> |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 39 | |
| 40 | #include "ipa_trace.h" |
| 41 | |
| 42 | #define WWAN_METADATA_SHFT 24 |
| 43 | #define WWAN_METADATA_MASK 0xFF000000 |
| 44 | #define WWAN_DATA_LEN 2000 |
| 45 | #define IPA_RM_INACTIVITY_TIMER 100 /* IPA_RM */ |
| 46 | #define HEADROOM_FOR_QMAP 8 /* for mux header */ |
| 47 | #define TAILROOM 0 /* for padding by mux layer */ |
| 48 | #define MAX_NUM_OF_MUX_CHANNEL 10 /* max mux channels */ |
| 49 | #define UL_FILTER_RULE_HANDLE_START 69 |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 50 | #define DEFAULT_OUTSTANDING_HIGH 128 |
| 51 | #define DEFAULT_OUTSTANDING_HIGH_CTL (DEFAULT_OUTSTANDING_HIGH+32) |
| 52 | #define DEFAULT_OUTSTANDING_LOW 64 |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 53 | |
| 54 | #define IPA_WWAN_DEV_NAME "rmnet_ipa%d" |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 55 | #define IPA_UPSTEAM_WLAN_IFACE_NAME "wlan0" |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 56 | |
| 57 | #define IPA_WWAN_RX_SOFTIRQ_THRESH 16 |
| 58 | |
| 59 | #define INVALID_MUX_ID 0xFF |
| 60 | #define IPA_QUOTA_REACH_ALERT_MAX_SIZE 64 |
| 61 | #define IPA_QUOTA_REACH_IF_NAME_MAX_SIZE 64 |
| 62 | #define IPA_UEVENT_NUM_EVNP 4 /* number of event pointers */ |
| 63 | #define NAPI_WEIGHT 60 |
| 64 | |
| 65 | #define IPA_NETDEV() \ |
| 66 | ((rmnet_ipa3_ctx && rmnet_ipa3_ctx->wwan_priv) ? \ |
| 67 | rmnet_ipa3_ctx->wwan_priv->net : NULL) |
| 68 | |
Sunil Paidimarri | 226cf03 | 2016-10-14 13:33:08 -0700 | [diff] [blame] | 69 | #define IPA_WWAN_CONS_DESC_FIFO_SZ 256 |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 70 | |
Mohammed Javid | d0c2a1e | 2017-10-30 15:34:22 +0530 | [diff] [blame] | 71 | static void rmnet_ipa_free_msg(void *buff, u32 len, u32 type); |
| 72 | static void rmnet_ipa_get_stats_and_update(void); |
| 73 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 74 | static int ipa3_wwan_add_ul_flt_rule_to_ipa(void); |
| 75 | static int ipa3_wwan_del_ul_flt_rule_to_ipa(void); |
| 76 | static void ipa3_wwan_msg_free_cb(void*, u32, u32); |
| 77 | static void ipa3_rmnet_rx_cb(void *priv); |
| 78 | static int ipa3_rmnet_poll(struct napi_struct *napi, int budget); |
| 79 | |
| 80 | static void ipa3_wake_tx_queue(struct work_struct *work); |
| 81 | static DECLARE_WORK(ipa3_tx_wakequeue_work, ipa3_wake_tx_queue); |
| 82 | |
| 83 | static void tethering_stats_poll_queue(struct work_struct *work); |
| 84 | static DECLARE_DELAYED_WORK(ipa_tether_stats_poll_wakequeue_work, |
| 85 | tethering_stats_poll_queue); |
| 86 | |
| 87 | enum ipa3_wwan_device_status { |
| 88 | WWAN_DEVICE_INACTIVE = 0, |
| 89 | WWAN_DEVICE_ACTIVE = 1 |
| 90 | }; |
| 91 | |
| 92 | struct ipa3_rmnet_plat_drv_res { |
| 93 | bool ipa_rmnet_ssr; |
| 94 | bool ipa_loaduC; |
| 95 | bool ipa_advertise_sg_support; |
| 96 | bool ipa_napi_enable; |
Sunil Paidimarri | 226cf03 | 2016-10-14 13:33:08 -0700 | [diff] [blame] | 97 | u32 wan_rx_desc_size; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | /** |
| 101 | * struct ipa3_wwan_private - WWAN private data |
| 102 | * @net: network interface struct implemented by this driver |
| 103 | * @stats: iface statistics |
| 104 | * @outstanding_pkts: number of packets sent to IPA without TX complete ACKed |
| 105 | * @outstanding_high: number of outstanding packets allowed |
| 106 | * @outstanding_low: number of outstanding packets which shall cause |
| 107 | * @ch_id: channel id |
| 108 | * @lock: spinlock for mutual exclusion |
| 109 | * @device_status: holds device status |
| 110 | * |
| 111 | * WWAN private - holds all relevant info about WWAN driver |
| 112 | */ |
| 113 | struct ipa3_wwan_private { |
| 114 | struct net_device *net; |
| 115 | struct net_device_stats stats; |
| 116 | atomic_t outstanding_pkts; |
| 117 | int outstanding_high_ctl; |
| 118 | int outstanding_high; |
| 119 | int outstanding_low; |
| 120 | uint32_t ch_id; |
| 121 | spinlock_t lock; |
| 122 | struct completion resource_granted_completion; |
| 123 | enum ipa3_wwan_device_status device_status; |
| 124 | struct napi_struct napi; |
| 125 | }; |
| 126 | |
| 127 | struct rmnet_ipa3_context { |
| 128 | struct ipa3_wwan_private *wwan_priv; |
| 129 | struct ipa_sys_connect_params apps_to_ipa_ep_cfg; |
| 130 | struct ipa_sys_connect_params ipa_to_apps_ep_cfg; |
| 131 | u32 qmap_hdr_hdl; |
| 132 | u32 dflt_v4_wan_rt_hdl; |
| 133 | u32 dflt_v6_wan_rt_hdl; |
| 134 | struct ipa3_rmnet_mux_val mux_channel[MAX_NUM_OF_MUX_CHANNEL]; |
| 135 | int num_q6_rules; |
| 136 | int old_num_q6_rules; |
| 137 | int rmnet_index; |
| 138 | bool egress_set; |
| 139 | bool a7_ul_flt_set; |
| 140 | struct workqueue_struct *rm_q6_wq; |
| 141 | atomic_t is_initialized; |
| 142 | atomic_t is_ssr; |
| 143 | void *subsys_notify_handle; |
| 144 | u32 apps_to_ipa3_hdl; |
| 145 | u32 ipa3_to_apps_hdl; |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 146 | struct mutex pipe_handle_guard; |
Skylar Chang | 8438ba5 | 2017-03-15 21:27:35 -0700 | [diff] [blame] | 147 | struct mutex add_mux_channel_lock; |
Michael Adisumarta | 3e35081 | 2017-09-18 14:54:36 -0700 | [diff] [blame] | 148 | u32 pm_hdl; |
| 149 | u32 q6_pm_hdl; |
| 150 | u32 q6_teth_pm_hdl; |
Mohammed Javid | d0c2a1e | 2017-10-30 15:34:22 +0530 | [diff] [blame] | 151 | struct mutex per_client_stats_guard; |
| 152 | struct ipa_tether_device_info |
| 153 | tether_device |
| 154 | [IPACM_MAX_CLIENT_DEVICE_TYPES]; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | static struct rmnet_ipa3_context *rmnet_ipa3_ctx; |
| 158 | static struct ipa3_rmnet_plat_drv_res ipa3_rmnet_res; |
| 159 | |
| 160 | /** |
| 161 | * ipa3_setup_a7_qmap_hdr() - Setup default a7 qmap hdr |
| 162 | * |
| 163 | * Return codes: |
| 164 | * 0: success |
| 165 | * -ENOMEM: failed to allocate memory |
| 166 | * -EPERM: failed to add the tables |
| 167 | */ |
| 168 | static int ipa3_setup_a7_qmap_hdr(void) |
| 169 | { |
| 170 | struct ipa_ioc_add_hdr *hdr; |
| 171 | struct ipa_hdr_add *hdr_entry; |
| 172 | u32 pyld_sz; |
| 173 | int ret; |
| 174 | |
| 175 | /* install the basic exception header */ |
| 176 | pyld_sz = sizeof(struct ipa_ioc_add_hdr) + 1 * |
| 177 | sizeof(struct ipa_hdr_add); |
| 178 | hdr = kzalloc(pyld_sz, GFP_KERNEL); |
| 179 | if (!hdr) { |
| 180 | IPAWANERR("fail to alloc exception hdr\n"); |
| 181 | return -ENOMEM; |
| 182 | } |
| 183 | hdr->num_hdrs = 1; |
| 184 | hdr->commit = 1; |
| 185 | hdr_entry = &hdr->hdr[0]; |
| 186 | |
| 187 | strlcpy(hdr_entry->name, IPA_A7_QMAP_HDR_NAME, |
| 188 | IPA_RESOURCE_NAME_MAX); |
| 189 | hdr_entry->hdr_len = IPA_QMAP_HEADER_LENGTH; /* 4 bytes */ |
| 190 | |
| 191 | if (ipa3_add_hdr(hdr)) { |
| 192 | IPAWANERR("fail to add IPA_A7_QMAP hdr\n"); |
| 193 | ret = -EPERM; |
| 194 | goto bail; |
| 195 | } |
| 196 | |
| 197 | if (hdr_entry->status) { |
| 198 | IPAWANERR("fail to add IPA_A7_QMAP hdr\n"); |
| 199 | ret = -EPERM; |
| 200 | goto bail; |
| 201 | } |
| 202 | rmnet_ipa3_ctx->qmap_hdr_hdl = hdr_entry->hdr_hdl; |
| 203 | |
| 204 | ret = 0; |
| 205 | bail: |
| 206 | kfree(hdr); |
| 207 | return ret; |
| 208 | } |
| 209 | |
| 210 | static void ipa3_del_a7_qmap_hdr(void) |
| 211 | { |
| 212 | struct ipa_ioc_del_hdr *del_hdr; |
| 213 | struct ipa_hdr_del *hdl_entry; |
| 214 | u32 pyld_sz; |
| 215 | int ret; |
| 216 | |
| 217 | pyld_sz = sizeof(struct ipa_ioc_del_hdr) + 1 * |
| 218 | sizeof(struct ipa_hdr_del); |
| 219 | del_hdr = kzalloc(pyld_sz, GFP_KERNEL); |
| 220 | if (!del_hdr) { |
| 221 | IPAWANERR("fail to alloc exception hdr_del\n"); |
| 222 | return; |
| 223 | } |
| 224 | |
| 225 | del_hdr->commit = 1; |
| 226 | del_hdr->num_hdls = 1; |
| 227 | hdl_entry = &del_hdr->hdl[0]; |
| 228 | hdl_entry->hdl = rmnet_ipa3_ctx->qmap_hdr_hdl; |
| 229 | |
| 230 | ret = ipa3_del_hdr(del_hdr); |
| 231 | if (ret || hdl_entry->status) |
| 232 | IPAWANERR("ipa3_del_hdr failed\n"); |
| 233 | else |
| 234 | IPAWANDBG("hdrs deletion done\n"); |
| 235 | |
| 236 | rmnet_ipa3_ctx->qmap_hdr_hdl = 0; |
| 237 | kfree(del_hdr); |
| 238 | } |
| 239 | |
| 240 | static void ipa3_del_qmap_hdr(uint32_t hdr_hdl) |
| 241 | { |
| 242 | struct ipa_ioc_del_hdr *del_hdr; |
| 243 | struct ipa_hdr_del *hdl_entry; |
| 244 | u32 pyld_sz; |
| 245 | int ret; |
| 246 | |
| 247 | if (hdr_hdl == 0) { |
| 248 | IPAWANERR("Invalid hdr_hdl provided\n"); |
| 249 | return; |
| 250 | } |
| 251 | |
| 252 | pyld_sz = sizeof(struct ipa_ioc_del_hdr) + 1 * |
| 253 | sizeof(struct ipa_hdr_del); |
| 254 | del_hdr = kzalloc(pyld_sz, GFP_KERNEL); |
| 255 | if (!del_hdr) { |
| 256 | IPAWANERR("fail to alloc exception hdr_del\n"); |
| 257 | return; |
| 258 | } |
| 259 | |
| 260 | del_hdr->commit = 1; |
| 261 | del_hdr->num_hdls = 1; |
| 262 | hdl_entry = &del_hdr->hdl[0]; |
| 263 | hdl_entry->hdl = hdr_hdl; |
| 264 | |
| 265 | ret = ipa3_del_hdr(del_hdr); |
| 266 | if (ret || hdl_entry->status) |
| 267 | IPAWANERR("ipa3_del_hdr failed\n"); |
| 268 | else |
| 269 | IPAWANDBG("header deletion done\n"); |
| 270 | |
| 271 | rmnet_ipa3_ctx->qmap_hdr_hdl = 0; |
| 272 | kfree(del_hdr); |
| 273 | } |
| 274 | |
| 275 | static void ipa3_del_mux_qmap_hdrs(void) |
| 276 | { |
| 277 | int index; |
| 278 | |
| 279 | for (index = 0; index < rmnet_ipa3_ctx->rmnet_index; index++) { |
| 280 | ipa3_del_qmap_hdr(rmnet_ipa3_ctx->mux_channel[index].hdr_hdl); |
| 281 | rmnet_ipa3_ctx->mux_channel[index].hdr_hdl = 0; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | static int ipa3_add_qmap_hdr(uint32_t mux_id, uint32_t *hdr_hdl) |
| 286 | { |
| 287 | struct ipa_ioc_add_hdr *hdr; |
| 288 | struct ipa_hdr_add *hdr_entry; |
| 289 | char hdr_name[IPA_RESOURCE_NAME_MAX]; |
| 290 | u32 pyld_sz; |
| 291 | int ret; |
| 292 | |
| 293 | pyld_sz = sizeof(struct ipa_ioc_add_hdr) + 1 * |
| 294 | sizeof(struct ipa_hdr_add); |
| 295 | hdr = kzalloc(pyld_sz, GFP_KERNEL); |
| 296 | if (!hdr) { |
| 297 | IPAWANERR("fail to alloc exception hdr\n"); |
| 298 | return -ENOMEM; |
| 299 | } |
| 300 | hdr->num_hdrs = 1; |
| 301 | hdr->commit = 1; |
| 302 | hdr_entry = &hdr->hdr[0]; |
| 303 | |
| 304 | snprintf(hdr_name, IPA_RESOURCE_NAME_MAX, "%s%d", |
| 305 | A2_MUX_HDR_NAME_V4_PREF, |
| 306 | mux_id); |
| 307 | strlcpy(hdr_entry->name, hdr_name, |
| 308 | IPA_RESOURCE_NAME_MAX); |
| 309 | |
| 310 | hdr_entry->hdr_len = IPA_QMAP_HEADER_LENGTH; /* 4 bytes */ |
| 311 | hdr_entry->hdr[1] = (uint8_t) mux_id; |
| 312 | IPAWANDBG("header (%s) with mux-id: (%d)\n", |
| 313 | hdr_name, |
| 314 | hdr_entry->hdr[1]); |
| 315 | if (ipa3_add_hdr(hdr)) { |
| 316 | IPAWANERR("fail to add IPA_QMAP hdr\n"); |
| 317 | ret = -EPERM; |
| 318 | goto bail; |
| 319 | } |
| 320 | |
| 321 | if (hdr_entry->status) { |
| 322 | IPAWANERR("fail to add IPA_QMAP hdr\n"); |
| 323 | ret = -EPERM; |
| 324 | goto bail; |
| 325 | } |
| 326 | |
| 327 | ret = 0; |
| 328 | *hdr_hdl = hdr_entry->hdr_hdl; |
| 329 | bail: |
| 330 | kfree(hdr); |
| 331 | return ret; |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * ipa3_setup_dflt_wan_rt_tables() - Setup default wan routing tables |
| 336 | * |
| 337 | * Return codes: |
| 338 | * 0: success |
| 339 | * -ENOMEM: failed to allocate memory |
| 340 | * -EPERM: failed to add the tables |
| 341 | */ |
| 342 | static int ipa3_setup_dflt_wan_rt_tables(void) |
| 343 | { |
| 344 | struct ipa_ioc_add_rt_rule *rt_rule; |
| 345 | struct ipa_rt_rule_add *rt_rule_entry; |
| 346 | |
| 347 | rt_rule = |
| 348 | kzalloc(sizeof(struct ipa_ioc_add_rt_rule) + 1 * |
| 349 | sizeof(struct ipa_rt_rule_add), GFP_KERNEL); |
| 350 | if (!rt_rule) { |
| 351 | IPAWANERR("fail to alloc mem\n"); |
| 352 | return -ENOMEM; |
| 353 | } |
| 354 | /* setup a default v4 route to point to Apps */ |
| 355 | rt_rule->num_rules = 1; |
| 356 | rt_rule->commit = 1; |
| 357 | rt_rule->ip = IPA_IP_v4; |
| 358 | strlcpy(rt_rule->rt_tbl_name, IPA_DFLT_WAN_RT_TBL_NAME, |
| 359 | IPA_RESOURCE_NAME_MAX); |
| 360 | |
| 361 | rt_rule_entry = &rt_rule->rules[0]; |
| 362 | rt_rule_entry->at_rear = 1; |
| 363 | rt_rule_entry->rule.dst = IPA_CLIENT_APPS_WAN_CONS; |
| 364 | rt_rule_entry->rule.hdr_hdl = rmnet_ipa3_ctx->qmap_hdr_hdl; |
| 365 | |
| 366 | if (ipa3_add_rt_rule(rt_rule)) { |
| 367 | IPAWANERR("fail to add dflt_wan v4 rule\n"); |
| 368 | kfree(rt_rule); |
| 369 | return -EPERM; |
| 370 | } |
| 371 | |
| 372 | IPAWANDBG("dflt v4 rt rule hdl=%x\n", rt_rule_entry->rt_rule_hdl); |
| 373 | rmnet_ipa3_ctx->dflt_v4_wan_rt_hdl = rt_rule_entry->rt_rule_hdl; |
| 374 | |
| 375 | /* setup a default v6 route to point to A5 */ |
| 376 | rt_rule->ip = IPA_IP_v6; |
| 377 | if (ipa3_add_rt_rule(rt_rule)) { |
| 378 | IPAWANERR("fail to add dflt_wan v6 rule\n"); |
| 379 | kfree(rt_rule); |
| 380 | return -EPERM; |
| 381 | } |
| 382 | IPAWANDBG("dflt v6 rt rule hdl=%x\n", rt_rule_entry->rt_rule_hdl); |
| 383 | rmnet_ipa3_ctx->dflt_v6_wan_rt_hdl = rt_rule_entry->rt_rule_hdl; |
| 384 | |
| 385 | kfree(rt_rule); |
| 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | static void ipa3_del_dflt_wan_rt_tables(void) |
| 390 | { |
| 391 | struct ipa_ioc_del_rt_rule *rt_rule; |
| 392 | struct ipa_rt_rule_del *rt_rule_entry; |
| 393 | int len; |
| 394 | |
| 395 | len = sizeof(struct ipa_ioc_del_rt_rule) + 1 * |
| 396 | sizeof(struct ipa_rt_rule_del); |
| 397 | rt_rule = kzalloc(len, GFP_KERNEL); |
| 398 | if (!rt_rule) { |
| 399 | IPAWANERR("unable to allocate memory for del route rule\n"); |
| 400 | return; |
| 401 | } |
| 402 | |
| 403 | memset(rt_rule, 0, len); |
| 404 | rt_rule->commit = 1; |
| 405 | rt_rule->num_hdls = 1; |
| 406 | rt_rule->ip = IPA_IP_v4; |
| 407 | |
| 408 | rt_rule_entry = &rt_rule->hdl[0]; |
| 409 | rt_rule_entry->status = -1; |
| 410 | rt_rule_entry->hdl = rmnet_ipa3_ctx->dflt_v4_wan_rt_hdl; |
| 411 | |
| 412 | IPAWANERR("Deleting Route hdl:(0x%x) with ip type: %d\n", |
| 413 | rt_rule_entry->hdl, IPA_IP_v4); |
| 414 | if (ipa3_del_rt_rule(rt_rule) || |
| 415 | (rt_rule_entry->status)) { |
| 416 | IPAWANERR("Routing rule deletion failed!\n"); |
| 417 | } |
| 418 | |
| 419 | rt_rule->ip = IPA_IP_v6; |
| 420 | rt_rule_entry->hdl = rmnet_ipa3_ctx->dflt_v6_wan_rt_hdl; |
| 421 | IPAWANERR("Deleting Route hdl:(0x%x) with ip type: %d\n", |
| 422 | rt_rule_entry->hdl, IPA_IP_v6); |
| 423 | if (ipa3_del_rt_rule(rt_rule) || |
| 424 | (rt_rule_entry->status)) { |
| 425 | IPAWANERR("Routing rule deletion failed!\n"); |
| 426 | } |
| 427 | |
| 428 | kfree(rt_rule); |
| 429 | } |
| 430 | |
| 431 | int ipa3_copy_ul_filter_rule_to_ipa(struct ipa_install_fltr_rule_req_msg_v01 |
| 432 | *rule_req) |
| 433 | { |
| 434 | int i, j; |
| 435 | |
Skylar Chang | 441cc5e | 2017-08-11 15:49:21 -0700 | [diff] [blame] | 436 | /* prevent multi-threads accessing rmnet_ipa3_ctx->num_q6_rules */ |
| 437 | mutex_lock(&rmnet_ipa3_ctx->add_mux_channel_lock); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 438 | if (rule_req->filter_spec_ex_list_valid == true) { |
| 439 | rmnet_ipa3_ctx->num_q6_rules = |
| 440 | rule_req->filter_spec_ex_list_len; |
| 441 | IPAWANDBG("Received (%d) install_flt_req\n", |
| 442 | rmnet_ipa3_ctx->num_q6_rules); |
| 443 | } else { |
| 444 | rmnet_ipa3_ctx->num_q6_rules = 0; |
| 445 | IPAWANERR("got no UL rules from modem\n"); |
Skylar Chang | 441cc5e | 2017-08-11 15:49:21 -0700 | [diff] [blame] | 446 | mutex_unlock(&rmnet_ipa3_ctx-> |
| 447 | add_mux_channel_lock); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 448 | return -EINVAL; |
| 449 | } |
| 450 | |
| 451 | /* copy UL filter rules from Modem*/ |
| 452 | for (i = 0; i < rmnet_ipa3_ctx->num_q6_rules; i++) { |
| 453 | /* check if rules overside the cache*/ |
| 454 | if (i == MAX_NUM_Q6_RULE) { |
| 455 | IPAWANERR("Reaching (%d) max cache ", |
| 456 | MAX_NUM_Q6_RULE); |
| 457 | IPAWANERR(" however total (%d)\n", |
| 458 | rmnet_ipa3_ctx->num_q6_rules); |
| 459 | goto failure; |
| 460 | } |
| 461 | ipa3_qmi_ctx->q6_ul_filter_rule[i].ip = |
| 462 | rule_req->filter_spec_ex_list[i].ip_type; |
| 463 | ipa3_qmi_ctx->q6_ul_filter_rule[i].action = |
| 464 | rule_req->filter_spec_ex_list[i].filter_action; |
| 465 | if (rule_req->filter_spec_ex_list[i]. |
| 466 | is_routing_table_index_valid == true) |
| 467 | ipa3_qmi_ctx->q6_ul_filter_rule[i].rt_tbl_idx = |
| 468 | rule_req->filter_spec_ex_list[i].route_table_index; |
| 469 | if (rule_req->filter_spec_ex_list[i].is_mux_id_valid == true) |
| 470 | ipa3_qmi_ctx->q6_ul_filter_rule[i].mux_id = |
| 471 | rule_req->filter_spec_ex_list[i].mux_id; |
| 472 | ipa3_qmi_ctx->q6_ul_filter_rule[i].rule_id = |
| 473 | rule_req->filter_spec_ex_list[i].rule_id; |
| 474 | ipa3_qmi_ctx->q6_ul_filter_rule[i].is_rule_hashable = |
| 475 | rule_req->filter_spec_ex_list[i].is_rule_hashable; |
| 476 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.rule_eq_bitmap = |
| 477 | rule_req->filter_spec_ex_list[i].filter_rule. |
| 478 | rule_eq_bitmap; |
| 479 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.tos_eq_present = |
| 480 | rule_req->filter_spec_ex_list[i].filter_rule. |
| 481 | tos_eq_present; |
| 482 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.tos_eq = |
| 483 | rule_req->filter_spec_ex_list[i].filter_rule.tos_eq; |
| 484 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 485 | protocol_eq_present = rule_req->filter_spec_ex_list[i]. |
| 486 | filter_rule.protocol_eq_present; |
| 487 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.protocol_eq = |
| 488 | rule_req->filter_spec_ex_list[i].filter_rule. |
| 489 | protocol_eq; |
| 490 | |
| 491 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 492 | num_ihl_offset_range_16 = |
| 493 | rule_req->filter_spec_ex_list[i]. |
| 494 | filter_rule.num_ihl_offset_range_16; |
| 495 | for (j = 0; j < ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 496 | num_ihl_offset_range_16; j++) { |
| 497 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 498 | ihl_offset_range_16[j].offset = rule_req-> |
| 499 | filter_spec_ex_list[i].filter_rule. |
| 500 | ihl_offset_range_16[j].offset; |
| 501 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 502 | ihl_offset_range_16[j].range_low = rule_req-> |
| 503 | filter_spec_ex_list[i].filter_rule. |
| 504 | ihl_offset_range_16[j].range_low; |
| 505 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 506 | ihl_offset_range_16[j].range_high = rule_req-> |
| 507 | filter_spec_ex_list[i].filter_rule. |
| 508 | ihl_offset_range_16[j].range_high; |
| 509 | } |
| 510 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.num_offset_meq_32 = |
| 511 | rule_req->filter_spec_ex_list[i].filter_rule. |
| 512 | num_offset_meq_32; |
| 513 | for (j = 0; j < ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 514 | num_offset_meq_32; j++) { |
| 515 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 516 | offset_meq_32[j].offset = |
| 517 | rule_req->filter_spec_ex_list[i]. |
| 518 | filter_rule.offset_meq_32[j].offset; |
| 519 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 520 | offset_meq_32[j].mask = |
| 521 | rule_req->filter_spec_ex_list[i]. |
| 522 | filter_rule.offset_meq_32[j].mask; |
| 523 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 524 | offset_meq_32[j].value = |
| 525 | rule_req->filter_spec_ex_list[i]. |
| 526 | filter_rule.offset_meq_32[j].value; |
| 527 | } |
| 528 | |
| 529 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.tc_eq_present = |
| 530 | rule_req->filter_spec_ex_list[i]. |
| 531 | filter_rule.tc_eq_present; |
| 532 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.tc_eq = |
| 533 | rule_req->filter_spec_ex_list[i].filter_rule.tc_eq; |
| 534 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.fl_eq_present = |
| 535 | rule_req->filter_spec_ex_list[i].filter_rule. |
| 536 | flow_eq_present; |
| 537 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.fl_eq = |
| 538 | rule_req->filter_spec_ex_list[i].filter_rule.flow_eq; |
| 539 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 540 | ihl_offset_eq_16_present = rule_req->filter_spec_ex_list[i]. |
| 541 | filter_rule.ihl_offset_eq_16_present; |
| 542 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 543 | ihl_offset_eq_16.offset = rule_req->filter_spec_ex_list[i]. |
| 544 | filter_rule.ihl_offset_eq_16.offset; |
| 545 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 546 | ihl_offset_eq_16.value = rule_req->filter_spec_ex_list[i]. |
| 547 | filter_rule.ihl_offset_eq_16.value; |
| 548 | |
| 549 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 550 | ihl_offset_eq_32_present = rule_req->filter_spec_ex_list[i]. |
| 551 | filter_rule.ihl_offset_eq_32_present; |
| 552 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 553 | ihl_offset_eq_32.offset = rule_req->filter_spec_ex_list[i]. |
| 554 | filter_rule.ihl_offset_eq_32.offset; |
| 555 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 556 | ihl_offset_eq_32.value = rule_req->filter_spec_ex_list[i]. |
| 557 | filter_rule.ihl_offset_eq_32.value; |
| 558 | |
| 559 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 560 | num_ihl_offset_meq_32 = rule_req->filter_spec_ex_list[i]. |
| 561 | filter_rule.num_ihl_offset_meq_32; |
| 562 | for (j = 0; j < ipa3_qmi_ctx->q6_ul_filter_rule[i]. |
| 563 | eq_attrib.num_ihl_offset_meq_32; j++) { |
| 564 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 565 | ihl_offset_meq_32[j].offset = rule_req-> |
| 566 | filter_spec_ex_list[i].filter_rule. |
| 567 | ihl_offset_meq_32[j].offset; |
| 568 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 569 | ihl_offset_meq_32[j].mask = rule_req-> |
| 570 | filter_spec_ex_list[i].filter_rule. |
| 571 | ihl_offset_meq_32[j].mask; |
| 572 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 573 | ihl_offset_meq_32[j].value = rule_req-> |
| 574 | filter_spec_ex_list[i].filter_rule. |
| 575 | ihl_offset_meq_32[j].value; |
| 576 | } |
| 577 | ipa3_qmi_ctx-> |
| 578 | q6_ul_filter_rule[i].eq_attrib.num_offset_meq_128 = |
| 579 | rule_req->filter_spec_ex_list[i].filter_rule. |
| 580 | num_offset_meq_128; |
| 581 | for (j = 0; j < ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 582 | num_offset_meq_128; j++) { |
| 583 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 584 | offset_meq_128[j].offset = rule_req-> |
| 585 | filter_spec_ex_list[i].filter_rule. |
| 586 | offset_meq_128[j].offset; |
| 587 | memcpy(ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 588 | offset_meq_128[j].mask, |
| 589 | rule_req->filter_spec_ex_list[i]. |
| 590 | filter_rule.offset_meq_128[j].mask, 16); |
| 591 | memcpy(ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 592 | offset_meq_128[j].value, rule_req-> |
| 593 | filter_spec_ex_list[i].filter_rule. |
| 594 | offset_meq_128[j].value, 16); |
| 595 | } |
| 596 | |
| 597 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 598 | metadata_meq32_present = |
| 599 | rule_req->filter_spec_ex_list[i]. |
| 600 | filter_rule.metadata_meq32_present; |
| 601 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 602 | metadata_meq32.offset = |
| 603 | rule_req->filter_spec_ex_list[i]. |
| 604 | filter_rule.metadata_meq32.offset; |
| 605 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 606 | metadata_meq32.mask = rule_req->filter_spec_ex_list[i]. |
| 607 | filter_rule.metadata_meq32.mask; |
| 608 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.metadata_meq32. |
| 609 | value = rule_req->filter_spec_ex_list[i].filter_rule. |
| 610 | metadata_meq32.value; |
| 611 | ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib. |
| 612 | ipv4_frag_eq_present = rule_req->filter_spec_ex_list[i]. |
| 613 | filter_rule.ipv4_frag_eq_present; |
| 614 | } |
| 615 | |
| 616 | if (rule_req->xlat_filter_indices_list_valid) { |
| 617 | if (rule_req->xlat_filter_indices_list_len > |
| 618 | rmnet_ipa3_ctx->num_q6_rules) { |
| 619 | IPAWANERR("Number of xlat indices is not valid: %d\n", |
| 620 | rule_req->xlat_filter_indices_list_len); |
| 621 | goto failure; |
| 622 | } |
| 623 | IPAWANDBG("Receive %d XLAT indices: ", |
| 624 | rule_req->xlat_filter_indices_list_len); |
| 625 | for (i = 0; i < rule_req->xlat_filter_indices_list_len; i++) |
| 626 | IPAWANDBG("%d ", rule_req->xlat_filter_indices_list[i]); |
| 627 | IPAWANDBG("\n"); |
| 628 | |
| 629 | for (i = 0; i < rule_req->xlat_filter_indices_list_len; i++) { |
| 630 | if (rule_req->xlat_filter_indices_list[i] |
| 631 | >= rmnet_ipa3_ctx->num_q6_rules) { |
| 632 | IPAWANERR("Xlat rule idx is wrong: %d\n", |
| 633 | rule_req->xlat_filter_indices_list[i]); |
| 634 | goto failure; |
| 635 | } else { |
| 636 | ipa3_qmi_ctx->q6_ul_filter_rule |
| 637 | [rule_req->xlat_filter_indices_list[i]] |
| 638 | .is_xlat_rule = 1; |
| 639 | IPAWANDBG("Rule %d is xlat rule\n", |
| 640 | rule_req->xlat_filter_indices_list[i]); |
| 641 | } |
| 642 | } |
| 643 | } |
| 644 | goto success; |
| 645 | |
| 646 | failure: |
| 647 | rmnet_ipa3_ctx->num_q6_rules = 0; |
| 648 | memset(ipa3_qmi_ctx->q6_ul_filter_rule, 0, |
| 649 | sizeof(ipa3_qmi_ctx->q6_ul_filter_rule)); |
Skylar Chang | 441cc5e | 2017-08-11 15:49:21 -0700 | [diff] [blame] | 650 | mutex_unlock(&rmnet_ipa3_ctx-> |
| 651 | add_mux_channel_lock); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 652 | return -EINVAL; |
| 653 | |
| 654 | success: |
Skylar Chang | 441cc5e | 2017-08-11 15:49:21 -0700 | [diff] [blame] | 655 | mutex_unlock(&rmnet_ipa3_ctx-> |
| 656 | add_mux_channel_lock); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 657 | return 0; |
| 658 | } |
| 659 | |
| 660 | static int ipa3_wwan_add_ul_flt_rule_to_ipa(void) |
| 661 | { |
| 662 | u32 pyld_sz; |
| 663 | int i, retval = 0; |
| 664 | struct ipa_ioc_add_flt_rule *param; |
| 665 | struct ipa_flt_rule_add flt_rule_entry; |
| 666 | struct ipa_fltr_installed_notif_req_msg_v01 *req; |
| 667 | |
| 668 | pyld_sz = sizeof(struct ipa_ioc_add_flt_rule) + |
| 669 | sizeof(struct ipa_flt_rule_add); |
| 670 | param = kzalloc(pyld_sz, GFP_KERNEL); |
| 671 | if (!param) |
| 672 | return -ENOMEM; |
| 673 | |
| 674 | req = (struct ipa_fltr_installed_notif_req_msg_v01 *) |
| 675 | kzalloc(sizeof(struct ipa_fltr_installed_notif_req_msg_v01), |
| 676 | GFP_KERNEL); |
| 677 | if (!req) { |
| 678 | kfree(param); |
| 679 | return -ENOMEM; |
| 680 | } |
| 681 | |
| 682 | param->commit = 1; |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 683 | param->ep = IPA_CLIENT_APPS_WAN_PROD; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 684 | param->global = false; |
| 685 | param->num_rules = (uint8_t)1; |
| 686 | |
Mohammed Javid | bf4c802 | 2017-08-07 23:15:48 +0530 | [diff] [blame] | 687 | memset(req, 0, sizeof(struct ipa_fltr_installed_notif_req_msg_v01)); |
| 688 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 689 | for (i = 0; i < rmnet_ipa3_ctx->num_q6_rules; i++) { |
| 690 | param->ip = ipa3_qmi_ctx->q6_ul_filter_rule[i].ip; |
| 691 | memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_add)); |
| 692 | flt_rule_entry.at_rear = true; |
| 693 | flt_rule_entry.rule.action = |
| 694 | ipa3_qmi_ctx->q6_ul_filter_rule[i].action; |
| 695 | flt_rule_entry.rule.rt_tbl_idx |
| 696 | = ipa3_qmi_ctx->q6_ul_filter_rule[i].rt_tbl_idx; |
| 697 | flt_rule_entry.rule.retain_hdr = true; |
| 698 | flt_rule_entry.rule.hashable = |
| 699 | ipa3_qmi_ctx->q6_ul_filter_rule[i].is_rule_hashable; |
| 700 | flt_rule_entry.rule.rule_id = |
| 701 | ipa3_qmi_ctx->q6_ul_filter_rule[i].rule_id; |
| 702 | |
| 703 | /* debug rt-hdl*/ |
| 704 | IPAWANDBG("install-IPA index(%d),rt-tbl:(%d)\n", |
| 705 | i, flt_rule_entry.rule.rt_tbl_idx); |
| 706 | flt_rule_entry.rule.eq_attrib_type = true; |
| 707 | memcpy(&(flt_rule_entry.rule.eq_attrib), |
| 708 | &ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib, |
| 709 | sizeof(struct ipa_ipfltri_rule_eq)); |
| 710 | memcpy(&(param->rules[0]), &flt_rule_entry, |
| 711 | sizeof(struct ipa_flt_rule_add)); |
| 712 | if (ipa3_add_flt_rule((struct ipa_ioc_add_flt_rule *)param)) { |
| 713 | retval = -EFAULT; |
| 714 | IPAWANERR("add A7 UL filter rule(%d) failed\n", i); |
| 715 | } else { |
| 716 | /* store the rule handler */ |
| 717 | ipa3_qmi_ctx->q6_ul_filter_rule_hdl[i] = |
| 718 | param->rules[0].flt_rule_hdl; |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | /* send ipa_fltr_installed_notif_req_msg_v01 to Q6*/ |
| 723 | req->source_pipe_index = |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 724 | ipa3_get_ep_mapping(IPA_CLIENT_APPS_WAN_PROD); |
Mohammed Javid | e53b546 | 2017-07-27 17:23:05 +0530 | [diff] [blame] | 725 | if (req->source_pipe_index == IPA_EP_NOT_ALLOCATED) { |
| 726 | IPAWANERR("ep mapping failed\n"); |
| 727 | retval = -EFAULT; |
| 728 | } |
| 729 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 730 | req->install_status = QMI_RESULT_SUCCESS_V01; |
| 731 | req->rule_id_valid = 1; |
| 732 | req->rule_id_len = rmnet_ipa3_ctx->num_q6_rules; |
| 733 | for (i = 0; i < rmnet_ipa3_ctx->num_q6_rules; i++) { |
| 734 | req->rule_id[i] = |
| 735 | ipa3_qmi_ctx->q6_ul_filter_rule[i].rule_id; |
| 736 | } |
| 737 | if (ipa3_qmi_filter_notify_send(req)) { |
| 738 | IPAWANDBG("add filter rule index on A7-RX failed\n"); |
| 739 | retval = -EFAULT; |
| 740 | } |
| 741 | rmnet_ipa3_ctx->old_num_q6_rules = rmnet_ipa3_ctx->num_q6_rules; |
| 742 | IPAWANDBG("add (%d) filter rule index on A7-RX\n", |
| 743 | rmnet_ipa3_ctx->old_num_q6_rules); |
| 744 | kfree(param); |
| 745 | kfree(req); |
| 746 | return retval; |
| 747 | } |
| 748 | |
| 749 | static int ipa3_wwan_del_ul_flt_rule_to_ipa(void) |
| 750 | { |
| 751 | u32 pyld_sz; |
| 752 | int i, retval = 0; |
| 753 | struct ipa_ioc_del_flt_rule *param; |
| 754 | struct ipa_flt_rule_del flt_rule_entry; |
| 755 | |
| 756 | pyld_sz = sizeof(struct ipa_ioc_del_flt_rule) + |
| 757 | sizeof(struct ipa_flt_rule_del); |
| 758 | param = kzalloc(pyld_sz, GFP_KERNEL); |
| 759 | if (!param) { |
| 760 | IPAWANERR("kzalloc failed\n"); |
| 761 | return -ENOMEM; |
| 762 | } |
| 763 | |
| 764 | param->commit = 1; |
| 765 | param->num_hdls = (uint8_t) 1; |
| 766 | |
| 767 | for (i = 0; i < rmnet_ipa3_ctx->old_num_q6_rules; i++) { |
| 768 | param->ip = ipa3_qmi_ctx->q6_ul_filter_rule[i].ip; |
| 769 | memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_del)); |
| 770 | flt_rule_entry.hdl = ipa3_qmi_ctx->q6_ul_filter_rule_hdl[i]; |
| 771 | /* debug rt-hdl*/ |
| 772 | IPAWANDBG("delete-IPA rule index(%d)\n", i); |
| 773 | memcpy(&(param->hdl[0]), &flt_rule_entry, |
| 774 | sizeof(struct ipa_flt_rule_del)); |
| 775 | if (ipa3_del_flt_rule((struct ipa_ioc_del_flt_rule *)param)) { |
| 776 | IPAWANERR("del A7 UL filter rule(%d) failed\n", i); |
| 777 | kfree(param); |
| 778 | return -EFAULT; |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | /* set UL filter-rule add-indication */ |
| 783 | rmnet_ipa3_ctx->a7_ul_flt_set = false; |
| 784 | rmnet_ipa3_ctx->old_num_q6_rules = 0; |
| 785 | |
| 786 | kfree(param); |
| 787 | return retval; |
| 788 | } |
| 789 | |
| 790 | static int ipa3_find_mux_channel_index(uint32_t mux_id) |
| 791 | { |
| 792 | int i; |
| 793 | |
| 794 | for (i = 0; i < MAX_NUM_OF_MUX_CHANNEL; i++) { |
| 795 | if (mux_id == rmnet_ipa3_ctx->mux_channel[i].mux_id) |
| 796 | return i; |
| 797 | } |
| 798 | return MAX_NUM_OF_MUX_CHANNEL; |
| 799 | } |
| 800 | |
| 801 | static int find_vchannel_name_index(const char *vchannel_name) |
| 802 | { |
| 803 | int i; |
| 804 | |
| 805 | for (i = 0; i < MAX_NUM_OF_MUX_CHANNEL; i++) { |
| 806 | if (strcmp(rmnet_ipa3_ctx->mux_channel[i].vchannel_name, |
| 807 | vchannel_name) == 0) |
| 808 | return i; |
| 809 | } |
| 810 | return MAX_NUM_OF_MUX_CHANNEL; |
| 811 | } |
| 812 | |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 813 | static enum ipa_upstream_type find_upstream_type(const char *upstreamIface) |
| 814 | { |
| 815 | int i; |
| 816 | |
| 817 | for (i = 0; i < MAX_NUM_OF_MUX_CHANNEL; i++) { |
| 818 | if (strcmp(rmnet_ipa3_ctx->mux_channel[i].vchannel_name, |
| 819 | upstreamIface) == 0) |
| 820 | return IPA_UPSTEAM_MODEM; |
| 821 | } |
| 822 | |
| 823 | if (strcmp(IPA_UPSTEAM_WLAN_IFACE_NAME, upstreamIface) == 0) |
| 824 | return IPA_UPSTEAM_WLAN; |
| 825 | else |
| 826 | return MAX_NUM_OF_MUX_CHANNEL; |
| 827 | } |
| 828 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 829 | static int ipa3_wwan_register_to_ipa(int index) |
| 830 | { |
| 831 | struct ipa_tx_intf tx_properties = {0}; |
| 832 | struct ipa_ioc_tx_intf_prop tx_ioc_properties[2] = { {0}, {0} }; |
| 833 | struct ipa_ioc_tx_intf_prop *tx_ipv4_property; |
| 834 | struct ipa_ioc_tx_intf_prop *tx_ipv6_property; |
| 835 | struct ipa_rx_intf rx_properties = {0}; |
| 836 | struct ipa_ioc_rx_intf_prop rx_ioc_properties[2] = { {0}, {0} }; |
| 837 | struct ipa_ioc_rx_intf_prop *rx_ipv4_property; |
| 838 | struct ipa_ioc_rx_intf_prop *rx_ipv6_property; |
| 839 | struct ipa_ext_intf ext_properties = {0}; |
| 840 | struct ipa_ioc_ext_intf_prop *ext_ioc_properties; |
| 841 | u32 pyld_sz; |
| 842 | int ret = 0, i; |
| 843 | |
| 844 | IPAWANDBG("index(%d) device[%s]:\n", index, |
| 845 | rmnet_ipa3_ctx->mux_channel[index].vchannel_name); |
| 846 | if (!rmnet_ipa3_ctx->mux_channel[index].mux_hdr_set) { |
| 847 | ret = ipa3_add_qmap_hdr( |
| 848 | rmnet_ipa3_ctx->mux_channel[index].mux_id, |
| 849 | &rmnet_ipa3_ctx->mux_channel[index].hdr_hdl); |
| 850 | if (ret) { |
| 851 | IPAWANERR("ipa_add_mux_hdr failed (%d)\n", index); |
| 852 | return ret; |
| 853 | } |
| 854 | rmnet_ipa3_ctx->mux_channel[index].mux_hdr_set = true; |
| 855 | } |
| 856 | tx_properties.prop = tx_ioc_properties; |
| 857 | tx_ipv4_property = &tx_properties.prop[0]; |
| 858 | tx_ipv4_property->ip = IPA_IP_v4; |
| 859 | tx_ipv4_property->dst_pipe = IPA_CLIENT_APPS_WAN_CONS; |
| 860 | snprintf(tx_ipv4_property->hdr_name, IPA_RESOURCE_NAME_MAX, "%s%d", |
| 861 | A2_MUX_HDR_NAME_V4_PREF, |
| 862 | rmnet_ipa3_ctx->mux_channel[index].mux_id); |
| 863 | tx_ipv6_property = &tx_properties.prop[1]; |
| 864 | tx_ipv6_property->ip = IPA_IP_v6; |
| 865 | tx_ipv6_property->dst_pipe = IPA_CLIENT_APPS_WAN_CONS; |
| 866 | /* no need use A2_MUX_HDR_NAME_V6_PREF, same header */ |
| 867 | snprintf(tx_ipv6_property->hdr_name, IPA_RESOURCE_NAME_MAX, "%s%d", |
| 868 | A2_MUX_HDR_NAME_V4_PREF, |
| 869 | rmnet_ipa3_ctx->mux_channel[index].mux_id); |
| 870 | tx_properties.num_props = 2; |
| 871 | |
| 872 | rx_properties.prop = rx_ioc_properties; |
| 873 | rx_ipv4_property = &rx_properties.prop[0]; |
| 874 | rx_ipv4_property->ip = IPA_IP_v4; |
| 875 | rx_ipv4_property->attrib.attrib_mask |= IPA_FLT_META_DATA; |
| 876 | rx_ipv4_property->attrib.meta_data = |
| 877 | rmnet_ipa3_ctx->mux_channel[index].mux_id << WWAN_METADATA_SHFT; |
| 878 | rx_ipv4_property->attrib.meta_data_mask = WWAN_METADATA_MASK; |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 879 | rx_ipv4_property->src_pipe = IPA_CLIENT_APPS_WAN_PROD; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 880 | rx_ipv6_property = &rx_properties.prop[1]; |
| 881 | rx_ipv6_property->ip = IPA_IP_v6; |
| 882 | rx_ipv6_property->attrib.attrib_mask |= IPA_FLT_META_DATA; |
| 883 | rx_ipv6_property->attrib.meta_data = |
| 884 | rmnet_ipa3_ctx->mux_channel[index].mux_id << WWAN_METADATA_SHFT; |
| 885 | rx_ipv6_property->attrib.meta_data_mask = WWAN_METADATA_MASK; |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 886 | rx_ipv6_property->src_pipe = IPA_CLIENT_APPS_WAN_PROD; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 887 | rx_properties.num_props = 2; |
| 888 | |
| 889 | pyld_sz = rmnet_ipa3_ctx->num_q6_rules * |
| 890 | sizeof(struct ipa_ioc_ext_intf_prop); |
| 891 | ext_ioc_properties = kmalloc(pyld_sz, GFP_KERNEL); |
| 892 | if (!ext_ioc_properties) { |
| 893 | IPAWANERR("Error allocate memory\n"); |
| 894 | return -ENOMEM; |
| 895 | } |
| 896 | |
| 897 | ext_properties.prop = ext_ioc_properties; |
| 898 | ext_properties.excp_pipe_valid = true; |
| 899 | ext_properties.excp_pipe = IPA_CLIENT_APPS_WAN_CONS; |
| 900 | ext_properties.num_props = rmnet_ipa3_ctx->num_q6_rules; |
| 901 | for (i = 0; i < rmnet_ipa3_ctx->num_q6_rules; i++) { |
| 902 | memcpy(&(ext_properties.prop[i]), |
| 903 | &(ipa3_qmi_ctx->q6_ul_filter_rule[i]), |
| 904 | sizeof(struct ipa_ioc_ext_intf_prop)); |
| 905 | ext_properties.prop[i].mux_id = |
| 906 | rmnet_ipa3_ctx->mux_channel[index].mux_id; |
| 907 | IPAWANDBG("index %d ip: %d rt-tbl:%d\n", i, |
| 908 | ext_properties.prop[i].ip, |
| 909 | ext_properties.prop[i].rt_tbl_idx); |
| 910 | IPAWANDBG("action: %d mux:%d\n", |
| 911 | ext_properties.prop[i].action, |
| 912 | ext_properties.prop[i].mux_id); |
| 913 | } |
| 914 | ret = ipa3_register_intf_ext(rmnet_ipa3_ctx->mux_channel[index]. |
| 915 | vchannel_name, &tx_properties, |
| 916 | &rx_properties, &ext_properties); |
| 917 | if (ret) { |
| 918 | IPAWANERR("[%s]:ipa3_register_intf failed %d\n", |
| 919 | rmnet_ipa3_ctx->mux_channel[index].vchannel_name, ret); |
| 920 | goto fail; |
| 921 | } |
| 922 | rmnet_ipa3_ctx->mux_channel[index].ul_flt_reg = true; |
| 923 | fail: |
| 924 | kfree(ext_ioc_properties); |
| 925 | return ret; |
| 926 | } |
| 927 | |
| 928 | static void ipa3_cleanup_deregister_intf(void) |
| 929 | { |
| 930 | int i; |
| 931 | int ret; |
| 932 | |
| 933 | for (i = 0; i < rmnet_ipa3_ctx->rmnet_index; i++) { |
| 934 | if (rmnet_ipa3_ctx->mux_channel[i].ul_flt_reg) { |
| 935 | ret = ipa3_deregister_intf( |
| 936 | rmnet_ipa3_ctx->mux_channel[i].vchannel_name); |
| 937 | if (ret < 0) { |
| 938 | IPAWANERR("de-register device %s(%d) failed\n", |
| 939 | rmnet_ipa3_ctx->mux_channel[i]. |
| 940 | vchannel_name, |
| 941 | i); |
| 942 | return; |
| 943 | } |
| 944 | IPAWANDBG("de-register device %s(%d) success\n", |
| 945 | rmnet_ipa3_ctx->mux_channel[i].vchannel_name, |
| 946 | i); |
| 947 | } |
| 948 | rmnet_ipa3_ctx->mux_channel[i].ul_flt_reg = false; |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | int ipa3_wwan_update_mux_channel_prop(void) |
| 953 | { |
| 954 | int ret = 0, i; |
| 955 | /* install UL filter rules */ |
| 956 | if (rmnet_ipa3_ctx->egress_set) { |
| 957 | if (ipa3_qmi_ctx->modem_cfg_emb_pipe_flt == false) { |
| 958 | IPAWANDBG("setup UL filter rules\n"); |
| 959 | if (rmnet_ipa3_ctx->a7_ul_flt_set) { |
| 960 | IPAWANDBG("del previous UL filter rules\n"); |
| 961 | /* delete rule hdlers */ |
| 962 | ret = ipa3_wwan_del_ul_flt_rule_to_ipa(); |
| 963 | if (ret) { |
| 964 | IPAWANERR("failed to del old rules\n"); |
| 965 | return -EINVAL; |
| 966 | } |
| 967 | IPAWANDBG("deleted old UL rules\n"); |
| 968 | } |
| 969 | ret = ipa3_wwan_add_ul_flt_rule_to_ipa(); |
| 970 | } |
| 971 | if (ret) |
| 972 | IPAWANERR("failed to install UL rules\n"); |
| 973 | else |
| 974 | rmnet_ipa3_ctx->a7_ul_flt_set = true; |
| 975 | } |
| 976 | /* update Tx/Rx/Ext property */ |
| 977 | IPAWANDBG("update Tx/Rx/Ext property in IPA\n"); |
| 978 | if (rmnet_ipa3_ctx->rmnet_index == 0) { |
| 979 | IPAWANDBG("no Tx/Rx/Ext property registered in IPA\n"); |
| 980 | return ret; |
| 981 | } |
| 982 | |
| 983 | ipa3_cleanup_deregister_intf(); |
| 984 | |
| 985 | for (i = 0; i < rmnet_ipa3_ctx->rmnet_index; i++) { |
| 986 | ret = ipa3_wwan_register_to_ipa(i); |
| 987 | if (ret < 0) { |
| 988 | IPAWANERR("failed to re-regist %s, mux %d, index %d\n", |
| 989 | rmnet_ipa3_ctx->mux_channel[i].vchannel_name, |
| 990 | rmnet_ipa3_ctx->mux_channel[i].mux_id, |
| 991 | i); |
| 992 | return -ENODEV; |
| 993 | } |
| 994 | IPAWANERR("dev(%s) has registered to IPA\n", |
| 995 | rmnet_ipa3_ctx->mux_channel[i].vchannel_name); |
| 996 | rmnet_ipa3_ctx->mux_channel[i].ul_flt_reg = true; |
| 997 | } |
| 998 | return ret; |
| 999 | } |
| 1000 | |
| 1001 | #ifdef INIT_COMPLETION |
| 1002 | #define reinit_completion(x) INIT_COMPLETION(*(x)) |
| 1003 | #endif /* INIT_COMPLETION */ |
| 1004 | |
| 1005 | static int __ipa_wwan_open(struct net_device *dev) |
| 1006 | { |
| 1007 | struct ipa3_wwan_private *wwan_ptr = netdev_priv(dev); |
| 1008 | |
| 1009 | IPAWANDBG("[%s] __wwan_open()\n", dev->name); |
| 1010 | if (wwan_ptr->device_status != WWAN_DEVICE_ACTIVE) |
| 1011 | reinit_completion(&wwan_ptr->resource_granted_completion); |
| 1012 | wwan_ptr->device_status = WWAN_DEVICE_ACTIVE; |
| 1013 | |
| 1014 | if (ipa3_rmnet_res.ipa_napi_enable) |
| 1015 | napi_enable(&(wwan_ptr->napi)); |
| 1016 | return 0; |
| 1017 | } |
| 1018 | |
| 1019 | /** |
| 1020 | * wwan_open() - Opens the wwan network interface. Opens logical |
| 1021 | * channel on A2 MUX driver and starts the network stack queue |
| 1022 | * |
| 1023 | * @dev: network device |
| 1024 | * |
| 1025 | * Return codes: |
| 1026 | * 0: success |
| 1027 | * -ENODEV: Error while opening logical channel on A2 MUX driver |
| 1028 | */ |
| 1029 | static int ipa3_wwan_open(struct net_device *dev) |
| 1030 | { |
| 1031 | int rc = 0; |
| 1032 | |
| 1033 | IPAWANDBG("[%s] wwan_open()\n", dev->name); |
| 1034 | rc = __ipa_wwan_open(dev); |
| 1035 | if (rc == 0) |
| 1036 | netif_start_queue(dev); |
| 1037 | return rc; |
| 1038 | } |
| 1039 | |
| 1040 | static int __ipa_wwan_close(struct net_device *dev) |
| 1041 | { |
| 1042 | struct ipa3_wwan_private *wwan_ptr = netdev_priv(dev); |
| 1043 | int rc = 0; |
| 1044 | |
| 1045 | if (wwan_ptr->device_status == WWAN_DEVICE_ACTIVE) { |
| 1046 | wwan_ptr->device_status = WWAN_DEVICE_INACTIVE; |
| 1047 | /* do not close wwan port once up, this causes |
| 1048 | * remote side to hang if tried to open again |
| 1049 | */ |
| 1050 | reinit_completion(&wwan_ptr->resource_granted_completion); |
| 1051 | rc = ipa3_deregister_intf(dev->name); |
| 1052 | if (rc) { |
| 1053 | IPAWANERR("[%s]: ipa3_deregister_intf failed %d\n", |
| 1054 | dev->name, rc); |
| 1055 | return rc; |
| 1056 | } |
| 1057 | return rc; |
| 1058 | } else { |
| 1059 | return -EBADF; |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | /** |
| 1064 | * ipa3_wwan_stop() - Stops the wwan network interface. Closes |
| 1065 | * logical channel on A2 MUX driver and stops the network stack |
| 1066 | * queue |
| 1067 | * |
| 1068 | * @dev: network device |
| 1069 | * |
| 1070 | * Return codes: |
| 1071 | * 0: success |
| 1072 | * -ENODEV: Error while opening logical channel on A2 MUX driver |
| 1073 | */ |
| 1074 | static int ipa3_wwan_stop(struct net_device *dev) |
| 1075 | { |
| 1076 | IPAWANDBG("[%s] ipa3_wwan_stop()\n", dev->name); |
| 1077 | __ipa_wwan_close(dev); |
| 1078 | netif_stop_queue(dev); |
| 1079 | return 0; |
| 1080 | } |
| 1081 | |
| 1082 | static int ipa3_wwan_change_mtu(struct net_device *dev, int new_mtu) |
| 1083 | { |
| 1084 | if (0 > new_mtu || WWAN_DATA_LEN < new_mtu) |
| 1085 | return -EINVAL; |
| 1086 | IPAWANDBG("[%s] MTU change: old=%d new=%d\n", |
| 1087 | dev->name, dev->mtu, new_mtu); |
| 1088 | dev->mtu = new_mtu; |
| 1089 | return 0; |
| 1090 | } |
| 1091 | |
| 1092 | /** |
| 1093 | * ipa3_wwan_xmit() - Transmits an skb. |
| 1094 | * |
| 1095 | * @skb: skb to be transmitted |
| 1096 | * @dev: network device |
| 1097 | * |
| 1098 | * Return codes: |
| 1099 | * 0: success |
| 1100 | * NETDEV_TX_BUSY: Error while transmitting the skb. Try again |
| 1101 | * later |
| 1102 | * -EFAULT: Error while transmitting the skb |
| 1103 | */ |
| 1104 | static int ipa3_wwan_xmit(struct sk_buff *skb, struct net_device *dev) |
| 1105 | { |
| 1106 | int ret = 0; |
| 1107 | bool qmap_check; |
| 1108 | struct ipa3_wwan_private *wwan_ptr = netdev_priv(dev); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1109 | |
| 1110 | if (skb->protocol != htons(ETH_P_MAP)) { |
| 1111 | IPAWANDBG_LOW |
| 1112 | ("SW filtering out none QMAP packet received from %s", |
| 1113 | current->comm); |
Sunil Paidimarri | 6c818e8 | 2016-10-17 18:33:13 -0700 | [diff] [blame] | 1114 | dev_kfree_skb_any(skb); |
| 1115 | dev->stats.tx_dropped++; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1116 | return NETDEV_TX_OK; |
| 1117 | } |
| 1118 | |
| 1119 | qmap_check = RMNET_MAP_GET_CD_BIT(skb); |
| 1120 | if (netif_queue_stopped(dev)) { |
| 1121 | if (qmap_check && |
| 1122 | atomic_read(&wwan_ptr->outstanding_pkts) < |
| 1123 | wwan_ptr->outstanding_high_ctl) { |
| 1124 | pr_err("[%s]Queue stop, send ctrl pkts\n", dev->name); |
| 1125 | goto send; |
| 1126 | } else { |
Sunil Paidimarri | 6c818e8 | 2016-10-17 18:33:13 -0700 | [diff] [blame] | 1127 | pr_err("[%s]fatal: ipa3_wwan_xmit stopped\n", |
| 1128 | dev->name); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1129 | return NETDEV_TX_BUSY; |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | /* checking High WM hit */ |
| 1134 | if (atomic_read(&wwan_ptr->outstanding_pkts) >= |
| 1135 | wwan_ptr->outstanding_high) { |
| 1136 | if (!qmap_check) { |
| 1137 | IPAWANDBG_LOW("pending(%d)/(%d)- stop(%d)\n", |
| 1138 | atomic_read(&wwan_ptr->outstanding_pkts), |
| 1139 | wwan_ptr->outstanding_high, |
| 1140 | netif_queue_stopped(dev)); |
| 1141 | IPAWANDBG_LOW("qmap_chk(%d)\n", qmap_check); |
| 1142 | netif_stop_queue(dev); |
| 1143 | return NETDEV_TX_BUSY; |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | send: |
| 1148 | /* IPA_RM checking start */ |
Michael Adisumarta | 3e35081 | 2017-09-18 14:54:36 -0700 | [diff] [blame] | 1149 | if (ipa3_ctx->use_ipa_pm) { |
| 1150 | /* activate the modem pm for clock scaling */ |
| 1151 | ipa_pm_activate(rmnet_ipa3_ctx->q6_pm_hdl); |
| 1152 | ret = ipa_pm_activate(rmnet_ipa3_ctx->pm_hdl); |
| 1153 | } else { |
| 1154 | ret = ipa_rm_inactivity_timer_request_resource( |
| 1155 | IPA_RM_RESOURCE_WWAN_0_PROD); |
| 1156 | } |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1157 | if (ret == -EINPROGRESS) { |
| 1158 | netif_stop_queue(dev); |
| 1159 | return NETDEV_TX_BUSY; |
| 1160 | } |
| 1161 | if (ret) { |
| 1162 | pr_err("[%s] fatal: ipa rm timer request resource failed %d\n", |
| 1163 | dev->name, ret); |
Sunil Paidimarri | 6c818e8 | 2016-10-17 18:33:13 -0700 | [diff] [blame] | 1164 | dev_kfree_skb_any(skb); |
| 1165 | dev->stats.tx_dropped++; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1166 | return -EFAULT; |
| 1167 | } |
| 1168 | /* IPA_RM checking end */ |
| 1169 | |
Skylar Chang | eaebfca | 2017-08-16 17:36:21 -0700 | [diff] [blame] | 1170 | /* |
| 1171 | * both data packets and command will be routed to |
| 1172 | * IPA_CLIENT_Q6_WAN_CONS based on status configuration |
| 1173 | */ |
| 1174 | ret = ipa3_tx_dp(IPA_CLIENT_APPS_WAN_PROD, skb, NULL); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1175 | if (ret) { |
| 1176 | ret = NETDEV_TX_BUSY; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1177 | goto out; |
| 1178 | } |
| 1179 | |
| 1180 | atomic_inc(&wwan_ptr->outstanding_pkts); |
| 1181 | dev->stats.tx_packets++; |
| 1182 | dev->stats.tx_bytes += skb->len; |
| 1183 | ret = NETDEV_TX_OK; |
| 1184 | out: |
Michael Adisumarta | 3e35081 | 2017-09-18 14:54:36 -0700 | [diff] [blame] | 1185 | if (atomic_read(&wwan_ptr->outstanding_pkts) == 0) { |
| 1186 | if (ipa3_ctx->use_ipa_pm) { |
| 1187 | ipa_pm_deferred_deactivate(rmnet_ipa3_ctx->pm_hdl); |
| 1188 | ipa_pm_deferred_deactivate(rmnet_ipa3_ctx->q6_pm_hdl); |
| 1189 | } else { |
| 1190 | ipa_rm_inactivity_timer_release_resource( |
| 1191 | IPA_RM_RESOURCE_WWAN_0_PROD); |
| 1192 | } |
| 1193 | } |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1194 | return ret; |
| 1195 | } |
| 1196 | |
| 1197 | static void ipa3_wwan_tx_timeout(struct net_device *dev) |
| 1198 | { |
Skylar Chang | 686267c | 2017-10-27 15:38:27 -0700 | [diff] [blame] | 1199 | struct ipa3_wwan_private *wwan_ptr = netdev_priv(dev); |
| 1200 | |
| 1201 | if (atomic_read(&wwan_ptr->outstanding_pkts) != 0) |
| 1202 | IPAWANERR("[%s] data stall in UL, %d outstanding\n", |
| 1203 | dev->name, atomic_read(&wwan_ptr->outstanding_pkts)); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | /** |
| 1207 | * apps_ipa_tx_complete_notify() - Rx notify |
| 1208 | * |
| 1209 | * @priv: driver context |
| 1210 | * @evt: event type |
| 1211 | * @data: data provided with event |
| 1212 | * |
| 1213 | * Check that the packet is the one we sent and release it |
| 1214 | * This function will be called in defered context in IPA wq. |
| 1215 | */ |
| 1216 | static void apps_ipa_tx_complete_notify(void *priv, |
| 1217 | enum ipa_dp_evt_type evt, |
| 1218 | unsigned long data) |
| 1219 | { |
| 1220 | struct sk_buff *skb = (struct sk_buff *)data; |
| 1221 | struct net_device *dev = (struct net_device *)priv; |
| 1222 | struct ipa3_wwan_private *wwan_ptr; |
| 1223 | |
| 1224 | if (dev != IPA_NETDEV()) { |
| 1225 | IPAWANDBG("Received pre-SSR packet completion\n"); |
| 1226 | dev_kfree_skb_any(skb); |
| 1227 | return; |
| 1228 | } |
| 1229 | |
| 1230 | if (evt != IPA_WRITE_DONE) { |
| 1231 | IPAWANERR("unsupported evt on Tx callback, Drop the packet\n"); |
| 1232 | dev_kfree_skb_any(skb); |
| 1233 | dev->stats.tx_dropped++; |
| 1234 | return; |
| 1235 | } |
| 1236 | |
| 1237 | wwan_ptr = netdev_priv(dev); |
| 1238 | atomic_dec(&wwan_ptr->outstanding_pkts); |
| 1239 | __netif_tx_lock_bh(netdev_get_tx_queue(dev, 0)); |
| 1240 | if (!atomic_read(&rmnet_ipa3_ctx->is_ssr) && |
| 1241 | netif_queue_stopped(wwan_ptr->net) && |
| 1242 | atomic_read(&wwan_ptr->outstanding_pkts) < |
| 1243 | (wwan_ptr->outstanding_low)) { |
| 1244 | IPAWANDBG_LOW("Outstanding low (%d) - waking up queue\n", |
| 1245 | wwan_ptr->outstanding_low); |
| 1246 | netif_wake_queue(wwan_ptr->net); |
| 1247 | } |
Skylar Chang | f3a7dac | 2017-01-25 09:16:55 -0800 | [diff] [blame] | 1248 | |
Michael Adisumarta | 3e35081 | 2017-09-18 14:54:36 -0700 | [diff] [blame] | 1249 | if (atomic_read(&wwan_ptr->outstanding_pkts) == 0) { |
| 1250 | if (ipa3_ctx->use_ipa_pm) { |
| 1251 | ipa_pm_deferred_deactivate(rmnet_ipa3_ctx->pm_hdl); |
| 1252 | ipa_pm_deferred_deactivate(rmnet_ipa3_ctx->q6_pm_hdl); |
| 1253 | } else { |
| 1254 | ipa_rm_inactivity_timer_release_resource( |
Skylar Chang | f3a7dac | 2017-01-25 09:16:55 -0800 | [diff] [blame] | 1255 | IPA_RM_RESOURCE_WWAN_0_PROD); |
Michael Adisumarta | 3e35081 | 2017-09-18 14:54:36 -0700 | [diff] [blame] | 1256 | } |
| 1257 | } |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1258 | __netif_tx_unlock_bh(netdev_get_tx_queue(dev, 0)); |
| 1259 | dev_kfree_skb_any(skb); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | /** |
| 1263 | * apps_ipa_packet_receive_notify() - Rx notify |
| 1264 | * |
| 1265 | * @priv: driver context |
| 1266 | * @evt: event type |
| 1267 | * @data: data provided with event |
| 1268 | * |
| 1269 | * IPA will pass a packet to the Linux network stack with skb->data |
| 1270 | */ |
| 1271 | static void apps_ipa_packet_receive_notify(void *priv, |
| 1272 | enum ipa_dp_evt_type evt, |
| 1273 | unsigned long data) |
| 1274 | { |
| 1275 | struct net_device *dev = (struct net_device *)priv; |
| 1276 | |
| 1277 | if (evt == IPA_RECEIVE) { |
| 1278 | struct sk_buff *skb = (struct sk_buff *)data; |
| 1279 | int result; |
| 1280 | unsigned int packet_len = skb->len; |
| 1281 | |
| 1282 | IPAWANDBG_LOW("Rx packet was received"); |
| 1283 | skb->dev = IPA_NETDEV(); |
| 1284 | skb->protocol = htons(ETH_P_MAP); |
| 1285 | |
| 1286 | if (ipa3_rmnet_res.ipa_napi_enable) { |
| 1287 | trace_rmnet_ipa_netif_rcv_skb3(dev->stats.rx_packets); |
| 1288 | result = netif_receive_skb(skb); |
| 1289 | } else { |
| 1290 | if (dev->stats.rx_packets % IPA_WWAN_RX_SOFTIRQ_THRESH |
| 1291 | == 0) { |
| 1292 | trace_rmnet_ipa_netifni3(dev->stats.rx_packets); |
| 1293 | result = netif_rx_ni(skb); |
| 1294 | } else { |
| 1295 | trace_rmnet_ipa_netifrx3(dev->stats.rx_packets); |
| 1296 | result = netif_rx(skb); |
| 1297 | } |
| 1298 | } |
| 1299 | |
| 1300 | if (result) { |
| 1301 | pr_err_ratelimited(DEV_NAME " %s:%d fail on netif_receive_skb\n", |
| 1302 | __func__, __LINE__); |
| 1303 | dev->stats.rx_dropped++; |
| 1304 | } |
| 1305 | dev->stats.rx_packets++; |
| 1306 | dev->stats.rx_bytes += packet_len; |
| 1307 | } else if (evt == IPA_CLIENT_START_POLL) |
| 1308 | ipa3_rmnet_rx_cb(priv); |
| 1309 | else if (evt == IPA_CLIENT_COMP_NAPI) { |
| 1310 | if (ipa3_rmnet_res.ipa_napi_enable) |
| 1311 | napi_complete(&(rmnet_ipa3_ctx->wwan_priv->napi)); |
| 1312 | } else |
| 1313 | IPAWANERR("Invalid evt %d received in wan_ipa_receive\n", evt); |
| 1314 | } |
| 1315 | |
Gidon Studinski | 3021a6f | 2016-11-10 12:48:48 +0200 | [diff] [blame] | 1316 | static int handle3_ingress_format(struct net_device *dev, |
| 1317 | struct rmnet_ioctl_extended_s *in) |
| 1318 | { |
| 1319 | int ret = 0; |
| 1320 | struct ipa_sys_connect_params *ipa_wan_ep_cfg; |
Gidon Studinski | 3021a6f | 2016-11-10 12:48:48 +0200 | [diff] [blame] | 1321 | |
| 1322 | IPAWANDBG("Get RMNET_IOCTL_SET_INGRESS_DATA_FORMAT\n"); |
| 1323 | ipa_wan_ep_cfg = &rmnet_ipa3_ctx->ipa_to_apps_ep_cfg; |
| 1324 | if ((in->u.data) & RMNET_IOCTL_INGRESS_FORMAT_CHECKSUM) |
| 1325 | ipa_wan_ep_cfg->ipa_ep_cfg.cfg.cs_offload_en = |
| 1326 | IPA_ENABLE_CS_OFFLOAD_DL; |
| 1327 | |
| 1328 | if ((in->u.data) & RMNET_IOCTL_INGRESS_FORMAT_AGG_DATA) { |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 1329 | IPAWANDBG("get AGG size %d count %d\n", |
Gidon Studinski | 3021a6f | 2016-11-10 12:48:48 +0200 | [diff] [blame] | 1330 | in->u.ingress_format.agg_size, |
| 1331 | in->u.ingress_format.agg_count); |
| 1332 | |
| 1333 | ret = ipa_disable_apps_wan_cons_deaggr( |
| 1334 | in->u.ingress_format.agg_size, |
| 1335 | in->u.ingress_format.agg_count); |
| 1336 | |
| 1337 | if (!ret) { |
| 1338 | ipa_wan_ep_cfg->ipa_ep_cfg.aggr.aggr_byte_limit = |
| 1339 | in->u.ingress_format.agg_size; |
| 1340 | ipa_wan_ep_cfg->ipa_ep_cfg.aggr.aggr_pkt_limit = |
| 1341 | in->u.ingress_format.agg_count; |
Gidon Studinski | 3021a6f | 2016-11-10 12:48:48 +0200 | [diff] [blame] | 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_len = 4; |
| 1346 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1; |
| 1347 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_metadata = 1; |
| 1348 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1; |
| 1349 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 2; |
| 1350 | |
| 1351 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad_valid = true; |
| 1352 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad = 0; |
| 1353 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_payload_len_inc_padding = true; |
| 1354 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad_offset = 0; |
| 1355 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_little_endian = 0; |
| 1356 | ipa_wan_ep_cfg->ipa_ep_cfg.metadata_mask.metadata_mask = 0xFF000000; |
| 1357 | |
| 1358 | ipa_wan_ep_cfg->client = IPA_CLIENT_APPS_WAN_CONS; |
| 1359 | ipa_wan_ep_cfg->notify = apps_ipa_packet_receive_notify; |
| 1360 | ipa_wan_ep_cfg->priv = dev; |
| 1361 | |
| 1362 | ipa_wan_ep_cfg->napi_enabled = ipa3_rmnet_res.ipa_napi_enable; |
Sunil Paidimarri | 226cf03 | 2016-10-14 13:33:08 -0700 | [diff] [blame] | 1363 | ipa_wan_ep_cfg->desc_fifo_sz = |
| 1364 | ipa3_rmnet_res.wan_rx_desc_size * IPA_FIFO_ELEMENT_SIZE; |
Gidon Studinski | 3021a6f | 2016-11-10 12:48:48 +0200 | [diff] [blame] | 1365 | |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 1366 | mutex_lock(&rmnet_ipa3_ctx->pipe_handle_guard); |
Gidon Studinski | 3021a6f | 2016-11-10 12:48:48 +0200 | [diff] [blame] | 1367 | |
| 1368 | if (atomic_read(&rmnet_ipa3_ctx->is_ssr)) { |
| 1369 | IPAWANDBG("In SSR sequence/recovery\n"); |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 1370 | mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard); |
Gidon Studinski | 3021a6f | 2016-11-10 12:48:48 +0200 | [diff] [blame] | 1371 | return -EFAULT; |
| 1372 | } |
| 1373 | ret = ipa3_setup_sys_pipe(&rmnet_ipa3_ctx->ipa_to_apps_ep_cfg, |
| 1374 | &rmnet_ipa3_ctx->ipa3_to_apps_hdl); |
| 1375 | |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 1376 | mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard); |
Gidon Studinski | 3021a6f | 2016-11-10 12:48:48 +0200 | [diff] [blame] | 1377 | |
| 1378 | if (ret) |
| 1379 | IPAWANERR("failed to configure ingress\n"); |
| 1380 | |
| 1381 | return ret; |
| 1382 | } |
| 1383 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1384 | /** |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 1385 | * handle3_egress_format() - Egress data format configuration |
| 1386 | * |
| 1387 | * Setup IPA egress system pipe and Configure: |
| 1388 | * header handling, checksum, de-aggregation and fifo size |
| 1389 | * |
| 1390 | * @dev: network device |
| 1391 | * @e: egress configuration |
| 1392 | */ |
| 1393 | static int handle3_egress_format(struct net_device *dev, |
| 1394 | struct rmnet_ioctl_extended_s *e) |
| 1395 | { |
| 1396 | int rc; |
| 1397 | struct ipa_sys_connect_params *ipa_wan_ep_cfg; |
| 1398 | |
| 1399 | IPAWANDBG("get RMNET_IOCTL_SET_EGRESS_DATA_FORMAT\n"); |
| 1400 | ipa_wan_ep_cfg = &rmnet_ipa3_ctx->apps_to_ipa_ep_cfg; |
| 1401 | if ((e->u.data) & RMNET_IOCTL_EGRESS_FORMAT_CHECKSUM) { |
| 1402 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_len = 8; |
| 1403 | ipa_wan_ep_cfg->ipa_ep_cfg.cfg.cs_offload_en = |
| 1404 | IPA_ENABLE_CS_OFFLOAD_UL; |
| 1405 | ipa_wan_ep_cfg->ipa_ep_cfg.cfg.cs_metadata_hdr_offset = 1; |
| 1406 | } else { |
| 1407 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_len = 4; |
| 1408 | } |
| 1409 | |
| 1410 | if ((e->u.data) & RMNET_IOCTL_EGRESS_FORMAT_AGGREGATION) { |
Skylar Chang | eaebfca | 2017-08-16 17:36:21 -0700 | [diff] [blame] | 1411 | IPAWANDBG("WAN UL Aggregation enabled\n"); |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 1412 | ipa_wan_ep_cfg->ipa_ep_cfg.aggr.aggr_en = IPA_ENABLE_DEAGGR; |
| 1413 | ipa_wan_ep_cfg->ipa_ep_cfg.aggr.aggr = IPA_QCMAP; |
| 1414 | |
| 1415 | ipa_wan_ep_cfg->ipa_ep_cfg.deaggr.packet_offset_valid = false; |
| 1416 | |
| 1417 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 2; |
| 1418 | |
| 1419 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad_valid = |
| 1420 | true; |
| 1421 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad = |
| 1422 | IPA_HDR_PAD; |
| 1423 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_pad_to_alignment = |
| 1424 | 2; |
| 1425 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_payload_len_inc_padding = |
| 1426 | true; |
| 1427 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad_offset = |
| 1428 | 0; |
| 1429 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_little_endian = |
| 1430 | false; |
| 1431 | } else { |
| 1432 | IPAWANDBG("WAN UL Aggregation disabled\n"); |
| 1433 | ipa_wan_ep_cfg->ipa_ep_cfg.aggr.aggr_en = IPA_BYPASS_AGGR; |
| 1434 | } |
| 1435 | |
| 1436 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1; |
| 1437 | /* modem want offset at 0! */ |
| 1438 | ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_metadata = 0; |
| 1439 | |
| 1440 | ipa_wan_ep_cfg->ipa_ep_cfg.mode.dst = IPA_CLIENT_APPS_WAN_PROD; |
| 1441 | ipa_wan_ep_cfg->ipa_ep_cfg.mode.mode = IPA_BASIC; |
| 1442 | |
| 1443 | ipa_wan_ep_cfg->client = IPA_CLIENT_APPS_WAN_PROD; |
| 1444 | ipa_wan_ep_cfg->notify = apps_ipa_tx_complete_notify; |
| 1445 | ipa_wan_ep_cfg->desc_fifo_sz = IPA_SYS_TX_DATA_DESC_FIFO_SZ; |
| 1446 | ipa_wan_ep_cfg->priv = dev; |
| 1447 | |
| 1448 | mutex_lock(&rmnet_ipa3_ctx->pipe_handle_guard); |
| 1449 | if (atomic_read(&rmnet_ipa3_ctx->is_ssr)) { |
| 1450 | IPAWANDBG("In SSR sequence/recovery\n"); |
| 1451 | mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard); |
| 1452 | return -EFAULT; |
| 1453 | } |
| 1454 | rc = ipa3_setup_sys_pipe( |
| 1455 | ipa_wan_ep_cfg, &rmnet_ipa3_ctx->apps_to_ipa3_hdl); |
| 1456 | if (rc) { |
| 1457 | IPAWANERR("failed to config egress endpoint\n"); |
| 1458 | mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard); |
| 1459 | return rc; |
| 1460 | } |
| 1461 | mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard); |
| 1462 | |
| 1463 | if (rmnet_ipa3_ctx->num_q6_rules != 0) { |
| 1464 | /* already got Q6 UL filter rules*/ |
Skylar Chang | 441cc5e | 2017-08-11 15:49:21 -0700 | [diff] [blame] | 1465 | if (ipa3_qmi_ctx->modem_cfg_emb_pipe_flt == false) { |
| 1466 | /* prevent multi-threads accessing num_q6_rules */ |
| 1467 | mutex_lock(&rmnet_ipa3_ctx->add_mux_channel_lock); |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 1468 | rc = ipa3_wwan_add_ul_flt_rule_to_ipa(); |
Skylar Chang | 441cc5e | 2017-08-11 15:49:21 -0700 | [diff] [blame] | 1469 | mutex_unlock(&rmnet_ipa3_ctx-> |
| 1470 | add_mux_channel_lock); |
| 1471 | } |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 1472 | if (rc) |
| 1473 | IPAWANERR("install UL rules failed\n"); |
| 1474 | else |
| 1475 | rmnet_ipa3_ctx->a7_ul_flt_set = true; |
| 1476 | } else { |
| 1477 | /* wait Q6 UL filter rules*/ |
| 1478 | IPAWANDBG("no UL-rules\n"); |
| 1479 | } |
| 1480 | rmnet_ipa3_ctx->egress_set = true; |
| 1481 | |
| 1482 | return rc; |
| 1483 | } |
| 1484 | |
| 1485 | /** |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1486 | * ipa3_wwan_ioctl() - I/O control for wwan network driver. |
| 1487 | * |
| 1488 | * @dev: network device |
| 1489 | * @ifr: ignored |
| 1490 | * @cmd: cmd to be excecuded. can be one of the following: |
| 1491 | * IPA_WWAN_IOCTL_OPEN - Open the network interface |
| 1492 | * IPA_WWAN_IOCTL_CLOSE - Close the network interface |
| 1493 | * |
| 1494 | * Return codes: |
| 1495 | * 0: success |
| 1496 | * NETDEV_TX_BUSY: Error while transmitting the skb. Try again |
| 1497 | * later |
| 1498 | * -EFAULT: Error while transmitting the skb |
| 1499 | */ |
| 1500 | static int ipa3_wwan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 1501 | { |
| 1502 | int rc = 0; |
| 1503 | int mru = 1000, epid = 1, mux_index, len; |
| 1504 | struct ipa_msg_meta msg_meta; |
| 1505 | struct ipa_wan_msg *wan_msg = NULL; |
| 1506 | struct rmnet_ioctl_extended_s extend_ioctl_data; |
| 1507 | struct rmnet_ioctl_data_s ioctl_data; |
| 1508 | struct ipa3_rmnet_mux_val *mux_channel; |
| 1509 | int rmnet_index; |
| 1510 | |
| 1511 | IPAWANDBG("rmnet_ipa got ioctl number 0x%08x", cmd); |
| 1512 | switch (cmd) { |
| 1513 | /* Set Ethernet protocol */ |
| 1514 | case RMNET_IOCTL_SET_LLP_ETHERNET: |
| 1515 | break; |
| 1516 | /* Set RAWIP protocol */ |
| 1517 | case RMNET_IOCTL_SET_LLP_IP: |
| 1518 | break; |
| 1519 | /* Get link protocol */ |
| 1520 | case RMNET_IOCTL_GET_LLP: |
| 1521 | ioctl_data.u.operation_mode = RMNET_MODE_LLP_IP; |
| 1522 | if (copy_to_user(ifr->ifr_ifru.ifru_data, &ioctl_data, |
| 1523 | sizeof(struct rmnet_ioctl_data_s))) |
| 1524 | rc = -EFAULT; |
| 1525 | break; |
| 1526 | /* Set QoS header enabled */ |
| 1527 | case RMNET_IOCTL_SET_QOS_ENABLE: |
| 1528 | return -EINVAL; |
| 1529 | /* Set QoS header disabled */ |
| 1530 | case RMNET_IOCTL_SET_QOS_DISABLE: |
| 1531 | break; |
| 1532 | /* Get QoS header state */ |
| 1533 | case RMNET_IOCTL_GET_QOS: |
| 1534 | ioctl_data.u.operation_mode = RMNET_MODE_NONE; |
| 1535 | if (copy_to_user(ifr->ifr_ifru.ifru_data, &ioctl_data, |
| 1536 | sizeof(struct rmnet_ioctl_data_s))) |
| 1537 | rc = -EFAULT; |
| 1538 | break; |
| 1539 | /* Get operation mode */ |
| 1540 | case RMNET_IOCTL_GET_OPMODE: |
| 1541 | ioctl_data.u.operation_mode = RMNET_MODE_LLP_IP; |
| 1542 | if (copy_to_user(ifr->ifr_ifru.ifru_data, &ioctl_data, |
| 1543 | sizeof(struct rmnet_ioctl_data_s))) |
| 1544 | rc = -EFAULT; |
| 1545 | break; |
| 1546 | /* Open transport port */ |
| 1547 | case RMNET_IOCTL_OPEN: |
| 1548 | break; |
| 1549 | /* Close transport port */ |
| 1550 | case RMNET_IOCTL_CLOSE: |
| 1551 | break; |
| 1552 | /* Flow enable */ |
| 1553 | case RMNET_IOCTL_FLOW_ENABLE: |
Skylar Chang | a699afd | 2017-06-06 10:06:21 -0700 | [diff] [blame] | 1554 | IPAWANERR("RMNET_IOCTL_FLOW_ENABLE not supported\n"); |
| 1555 | rc = -EFAULT; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1556 | break; |
| 1557 | /* Flow disable */ |
| 1558 | case RMNET_IOCTL_FLOW_DISABLE: |
Skylar Chang | a699afd | 2017-06-06 10:06:21 -0700 | [diff] [blame] | 1559 | IPAWANERR("RMNET_IOCTL_FLOW_DISABLE not supported\n"); |
| 1560 | rc = -EFAULT; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1561 | break; |
| 1562 | /* Set flow handle */ |
| 1563 | case RMNET_IOCTL_FLOW_SET_HNDL: |
| 1564 | break; |
| 1565 | |
| 1566 | /* Extended IOCTLs */ |
| 1567 | case RMNET_IOCTL_EXTENDED: |
| 1568 | IPAWANDBG("get ioctl: RMNET_IOCTL_EXTENDED\n"); |
| 1569 | if (copy_from_user(&extend_ioctl_data, |
| 1570 | (u8 *)ifr->ifr_ifru.ifru_data, |
| 1571 | sizeof(struct rmnet_ioctl_extended_s))) { |
| 1572 | IPAWANERR("failed to copy extended ioctl data\n"); |
| 1573 | rc = -EFAULT; |
| 1574 | break; |
| 1575 | } |
| 1576 | switch (extend_ioctl_data.extended_ioctl) { |
| 1577 | /* Get features */ |
| 1578 | case RMNET_IOCTL_GET_SUPPORTED_FEATURES: |
| 1579 | IPAWANDBG("get RMNET_IOCTL_GET_SUPPORTED_FEATURES\n"); |
| 1580 | extend_ioctl_data.u.data = |
| 1581 | (RMNET_IOCTL_FEAT_NOTIFY_MUX_CHANNEL | |
| 1582 | RMNET_IOCTL_FEAT_SET_EGRESS_DATA_FORMAT | |
| 1583 | RMNET_IOCTL_FEAT_SET_INGRESS_DATA_FORMAT); |
| 1584 | if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data, |
| 1585 | &extend_ioctl_data, |
| 1586 | sizeof(struct rmnet_ioctl_extended_s))) |
| 1587 | rc = -EFAULT; |
| 1588 | break; |
| 1589 | /* Set MRU */ |
| 1590 | case RMNET_IOCTL_SET_MRU: |
| 1591 | mru = extend_ioctl_data.u.data; |
| 1592 | IPAWANDBG("get MRU size %d\n", |
| 1593 | extend_ioctl_data.u.data); |
| 1594 | break; |
| 1595 | /* Get MRU */ |
| 1596 | case RMNET_IOCTL_GET_MRU: |
| 1597 | extend_ioctl_data.u.data = mru; |
| 1598 | if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data, |
| 1599 | &extend_ioctl_data, |
| 1600 | sizeof(struct rmnet_ioctl_extended_s))) |
| 1601 | rc = -EFAULT; |
| 1602 | break; |
| 1603 | /* GET SG support */ |
| 1604 | case RMNET_IOCTL_GET_SG_SUPPORT: |
| 1605 | extend_ioctl_data.u.data = |
| 1606 | ipa3_rmnet_res.ipa_advertise_sg_support; |
| 1607 | if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data, |
| 1608 | &extend_ioctl_data, |
| 1609 | sizeof(struct rmnet_ioctl_extended_s))) |
| 1610 | rc = -EFAULT; |
| 1611 | break; |
| 1612 | /* Get endpoint ID */ |
| 1613 | case RMNET_IOCTL_GET_EPID: |
| 1614 | IPAWANDBG("get ioctl: RMNET_IOCTL_GET_EPID\n"); |
| 1615 | extend_ioctl_data.u.data = epid; |
| 1616 | if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data, |
| 1617 | &extend_ioctl_data, |
| 1618 | sizeof(struct rmnet_ioctl_extended_s))) |
| 1619 | rc = -EFAULT; |
| 1620 | if (copy_from_user(&extend_ioctl_data, |
| 1621 | (u8 *)ifr->ifr_ifru.ifru_data, |
| 1622 | sizeof(struct rmnet_ioctl_extended_s))) { |
| 1623 | IPAWANERR("copy extended ioctl data failed\n"); |
| 1624 | rc = -EFAULT; |
| 1625 | break; |
| 1626 | } |
| 1627 | IPAWANDBG("RMNET_IOCTL_GET_EPID return %d\n", |
| 1628 | extend_ioctl_data.u.data); |
| 1629 | break; |
| 1630 | /* Endpoint pair */ |
| 1631 | case RMNET_IOCTL_GET_EP_PAIR: |
| 1632 | IPAWANDBG("get ioctl: RMNET_IOCTL_GET_EP_PAIR\n"); |
| 1633 | extend_ioctl_data.u.ipa_ep_pair.consumer_pipe_num = |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 1634 | ipa3_get_ep_mapping(IPA_CLIENT_APPS_WAN_PROD); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1635 | extend_ioctl_data.u.ipa_ep_pair.producer_pipe_num = |
| 1636 | ipa3_get_ep_mapping(IPA_CLIENT_APPS_WAN_CONS); |
| 1637 | if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data, |
| 1638 | &extend_ioctl_data, |
| 1639 | sizeof(struct rmnet_ioctl_extended_s))) |
| 1640 | rc = -EFAULT; |
| 1641 | if (copy_from_user(&extend_ioctl_data, |
| 1642 | (u8 *)ifr->ifr_ifru.ifru_data, |
| 1643 | sizeof(struct rmnet_ioctl_extended_s))) { |
| 1644 | IPAWANERR("copy extended ioctl data failed\n"); |
| 1645 | rc = -EFAULT; |
| 1646 | break; |
| 1647 | } |
| 1648 | IPAWANDBG("RMNET_IOCTL_GET_EP_PAIR c: %d p: %d\n", |
| 1649 | extend_ioctl_data.u.ipa_ep_pair.consumer_pipe_num, |
| 1650 | extend_ioctl_data.u.ipa_ep_pair.producer_pipe_num); |
| 1651 | break; |
| 1652 | /* Get driver name */ |
| 1653 | case RMNET_IOCTL_GET_DRIVER_NAME: |
| 1654 | memcpy(&extend_ioctl_data.u.if_name, |
Mohammed Javid | bf4c802 | 2017-08-07 23:15:48 +0530 | [diff] [blame] | 1655 | IPA_NETDEV()->name, IFNAMSIZ); |
| 1656 | extend_ioctl_data.u.if_name[IFNAMSIZ - 1] = '\0'; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1657 | if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data, |
| 1658 | &extend_ioctl_data, |
| 1659 | sizeof(struct rmnet_ioctl_extended_s))) |
| 1660 | rc = -EFAULT; |
| 1661 | break; |
| 1662 | /* Add MUX ID */ |
| 1663 | case RMNET_IOCTL_ADD_MUX_CHANNEL: |
| 1664 | mux_index = ipa3_find_mux_channel_index( |
| 1665 | extend_ioctl_data.u.rmnet_mux_val.mux_id); |
| 1666 | if (mux_index < MAX_NUM_OF_MUX_CHANNEL) { |
| 1667 | IPAWANDBG("already setup mux(%d)\n", |
| 1668 | extend_ioctl_data.u. |
| 1669 | rmnet_mux_val.mux_id); |
| 1670 | return rc; |
| 1671 | } |
Skylar Chang | 8438ba5 | 2017-03-15 21:27:35 -0700 | [diff] [blame] | 1672 | mutex_lock(&rmnet_ipa3_ctx->add_mux_channel_lock); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1673 | if (rmnet_ipa3_ctx->rmnet_index |
| 1674 | >= MAX_NUM_OF_MUX_CHANNEL) { |
| 1675 | IPAWANERR("Exceed mux_channel limit(%d)\n", |
| 1676 | rmnet_ipa3_ctx->rmnet_index); |
Skylar Chang | 8438ba5 | 2017-03-15 21:27:35 -0700 | [diff] [blame] | 1677 | mutex_unlock(&rmnet_ipa3_ctx-> |
| 1678 | add_mux_channel_lock); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1679 | return -EFAULT; |
| 1680 | } |
Shihuan Liu | 7b89d4e | 2017-10-06 20:38:02 -0700 | [diff] [blame] | 1681 | extend_ioctl_data.u.rmnet_mux_val.vchannel_name |
| 1682 | [IFNAMSIZ-1] = '\0'; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1683 | IPAWANDBG("ADD_MUX_CHANNEL(%d, name: %s)\n", |
| 1684 | extend_ioctl_data.u.rmnet_mux_val.mux_id, |
| 1685 | extend_ioctl_data.u.rmnet_mux_val.vchannel_name); |
| 1686 | /* cache the mux name and id */ |
| 1687 | mux_channel = rmnet_ipa3_ctx->mux_channel; |
| 1688 | rmnet_index = rmnet_ipa3_ctx->rmnet_index; |
| 1689 | |
| 1690 | mux_channel[rmnet_index].mux_id = |
| 1691 | extend_ioctl_data.u.rmnet_mux_val.mux_id; |
| 1692 | memcpy(mux_channel[rmnet_index].vchannel_name, |
| 1693 | extend_ioctl_data.u.rmnet_mux_val.vchannel_name, |
| 1694 | sizeof(mux_channel[rmnet_index] |
| 1695 | .vchannel_name)); |
Skylar Chang | ba7c511 | 2017-04-14 19:23:05 -0700 | [diff] [blame] | 1696 | mux_channel[rmnet_index].vchannel_name[ |
| 1697 | IFNAMSIZ - 1] = '\0'; |
| 1698 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1699 | IPAWANDBG("cashe device[%s:%d] in IPA_wan[%d]\n", |
| 1700 | mux_channel[rmnet_index].vchannel_name, |
| 1701 | mux_channel[rmnet_index].mux_id, |
| 1702 | rmnet_index); |
| 1703 | /* check if UL filter rules coming*/ |
| 1704 | if (rmnet_ipa3_ctx->num_q6_rules != 0) { |
| 1705 | IPAWANERR("dev(%s) register to IPA\n", |
| 1706 | extend_ioctl_data.u.rmnet_mux_val. |
| 1707 | vchannel_name); |
| 1708 | rc = ipa3_wwan_register_to_ipa( |
| 1709 | rmnet_ipa3_ctx->rmnet_index); |
| 1710 | if (rc < 0) { |
| 1711 | IPAWANERR("device %s reg IPA failed\n", |
| 1712 | extend_ioctl_data.u. |
| 1713 | rmnet_mux_val.vchannel_name); |
Skylar Chang | 8438ba5 | 2017-03-15 21:27:35 -0700 | [diff] [blame] | 1714 | mutex_unlock(&rmnet_ipa3_ctx-> |
| 1715 | add_mux_channel_lock); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1716 | return -ENODEV; |
| 1717 | } |
| 1718 | mux_channel[rmnet_index].mux_channel_set = true; |
| 1719 | mux_channel[rmnet_index].ul_flt_reg = true; |
| 1720 | } else { |
| 1721 | IPAWANDBG("dev(%s) haven't registered to IPA\n", |
| 1722 | extend_ioctl_data.u. |
| 1723 | rmnet_mux_val.vchannel_name); |
| 1724 | mux_channel[rmnet_index].mux_channel_set = true; |
| 1725 | mux_channel[rmnet_index].ul_flt_reg = false; |
| 1726 | } |
| 1727 | rmnet_ipa3_ctx->rmnet_index++; |
Skylar Chang | 8438ba5 | 2017-03-15 21:27:35 -0700 | [diff] [blame] | 1728 | mutex_unlock(&rmnet_ipa3_ctx->add_mux_channel_lock); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1729 | break; |
| 1730 | case RMNET_IOCTL_SET_EGRESS_DATA_FORMAT: |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 1731 | rc = handle3_egress_format(dev, &extend_ioctl_data); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1732 | break; |
| 1733 | case RMNET_IOCTL_SET_INGRESS_DATA_FORMAT:/* Set IDF */ |
Gidon Studinski | 3021a6f | 2016-11-10 12:48:48 +0200 | [diff] [blame] | 1734 | rc = handle3_ingress_format(dev, &extend_ioctl_data); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1735 | break; |
| 1736 | case RMNET_IOCTL_SET_XLAT_DEV_INFO: |
| 1737 | wan_msg = kzalloc(sizeof(struct ipa_wan_msg), |
| 1738 | GFP_KERNEL); |
| 1739 | if (!wan_msg) { |
| 1740 | IPAWANERR("Failed to allocate memory.\n"); |
| 1741 | return -ENOMEM; |
| 1742 | } |
| 1743 | len = sizeof(wan_msg->upstream_ifname) > |
| 1744 | sizeof(extend_ioctl_data.u.if_name) ? |
| 1745 | sizeof(extend_ioctl_data.u.if_name) : |
| 1746 | sizeof(wan_msg->upstream_ifname); |
| 1747 | strlcpy(wan_msg->upstream_ifname, |
| 1748 | extend_ioctl_data.u.if_name, len); |
Mohammed Javid | bf4c802 | 2017-08-07 23:15:48 +0530 | [diff] [blame] | 1749 | wan_msg->upstream_ifname[len-1] = '\0'; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1750 | memset(&msg_meta, 0, sizeof(struct ipa_msg_meta)); |
| 1751 | msg_meta.msg_type = WAN_XLAT_CONNECT; |
| 1752 | msg_meta.msg_len = sizeof(struct ipa_wan_msg); |
| 1753 | rc = ipa3_send_msg(&msg_meta, wan_msg, |
| 1754 | ipa3_wwan_msg_free_cb); |
| 1755 | if (rc) { |
| 1756 | IPAWANERR("Failed to send XLAT_CONNECT msg\n"); |
| 1757 | kfree(wan_msg); |
| 1758 | } |
| 1759 | break; |
| 1760 | /* Get agg count */ |
| 1761 | case RMNET_IOCTL_GET_AGGREGATION_COUNT: |
| 1762 | break; |
| 1763 | /* Set agg count */ |
| 1764 | case RMNET_IOCTL_SET_AGGREGATION_COUNT: |
| 1765 | break; |
| 1766 | /* Get agg size */ |
| 1767 | case RMNET_IOCTL_GET_AGGREGATION_SIZE: |
| 1768 | break; |
| 1769 | /* Set agg size */ |
| 1770 | case RMNET_IOCTL_SET_AGGREGATION_SIZE: |
| 1771 | break; |
| 1772 | /* Do flow control */ |
| 1773 | case RMNET_IOCTL_FLOW_CONTROL: |
| 1774 | break; |
| 1775 | /* For legacy use */ |
| 1776 | case RMNET_IOCTL_GET_DFLT_CONTROL_CHANNEL: |
| 1777 | break; |
| 1778 | /* Get HW/SW map */ |
| 1779 | case RMNET_IOCTL_GET_HWSW_MAP: |
| 1780 | break; |
| 1781 | /* Set RX Headroom */ |
| 1782 | case RMNET_IOCTL_SET_RX_HEADROOM: |
| 1783 | break; |
| 1784 | default: |
| 1785 | IPAWANERR("[%s] unsupported extended cmd[%d]", |
| 1786 | dev->name, |
| 1787 | extend_ioctl_data.extended_ioctl); |
| 1788 | rc = -EINVAL; |
| 1789 | } |
| 1790 | break; |
| 1791 | default: |
| 1792 | IPAWANERR("[%s] unsupported cmd[%d]", |
| 1793 | dev->name, cmd); |
| 1794 | rc = -EINVAL; |
| 1795 | } |
| 1796 | return rc; |
| 1797 | } |
| 1798 | |
| 1799 | static const struct net_device_ops ipa3_wwan_ops_ip = { |
| 1800 | .ndo_open = ipa3_wwan_open, |
| 1801 | .ndo_stop = ipa3_wwan_stop, |
| 1802 | .ndo_start_xmit = ipa3_wwan_xmit, |
| 1803 | .ndo_tx_timeout = ipa3_wwan_tx_timeout, |
| 1804 | .ndo_do_ioctl = ipa3_wwan_ioctl, |
| 1805 | .ndo_change_mtu = ipa3_wwan_change_mtu, |
| 1806 | .ndo_set_mac_address = 0, |
| 1807 | .ndo_validate_addr = 0, |
| 1808 | }; |
| 1809 | |
| 1810 | /** |
| 1811 | * wwan_setup() - Setups the wwan network driver. |
| 1812 | * |
| 1813 | * @dev: network device |
| 1814 | * |
| 1815 | * Return codes: |
| 1816 | * None |
| 1817 | */ |
| 1818 | |
| 1819 | static void ipa3_wwan_setup(struct net_device *dev) |
| 1820 | { |
| 1821 | dev->netdev_ops = &ipa3_wwan_ops_ip; |
| 1822 | ether_setup(dev); |
| 1823 | /* set this after calling ether_setup */ |
| 1824 | dev->header_ops = 0; /* No header */ |
| 1825 | dev->type = ARPHRD_RAWIP; |
| 1826 | dev->hard_header_len = 0; |
| 1827 | dev->mtu = WWAN_DATA_LEN; |
| 1828 | dev->addr_len = 0; |
| 1829 | dev->flags &= ~(IFF_BROADCAST | IFF_MULTICAST); |
| 1830 | dev->needed_headroom = HEADROOM_FOR_QMAP; |
| 1831 | dev->needed_tailroom = TAILROOM; |
| 1832 | dev->watchdog_timeo = 1000; |
| 1833 | } |
| 1834 | |
| 1835 | /* IPA_RM related functions start*/ |
| 1836 | static void ipa3_q6_prod_rm_request_resource(struct work_struct *work); |
| 1837 | static DECLARE_DELAYED_WORK(ipa3_q6_con_rm_request, |
| 1838 | ipa3_q6_prod_rm_request_resource); |
| 1839 | static void ipa3_q6_prod_rm_release_resource(struct work_struct *work); |
| 1840 | static DECLARE_DELAYED_WORK(ipa3_q6_con_rm_release, |
| 1841 | ipa3_q6_prod_rm_release_resource); |
| 1842 | |
| 1843 | static void ipa3_q6_prod_rm_request_resource(struct work_struct *work) |
| 1844 | { |
| 1845 | int ret = 0; |
| 1846 | |
| 1847 | ret = ipa_rm_request_resource(IPA_RM_RESOURCE_Q6_PROD); |
| 1848 | if (ret < 0 && ret != -EINPROGRESS) { |
| 1849 | IPAWANERR("%s: ipa_rm_request_resource failed %d\n", __func__, |
| 1850 | ret); |
| 1851 | return; |
| 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | static int ipa3_q6_rm_request_resource(void) |
| 1856 | { |
| 1857 | queue_delayed_work(rmnet_ipa3_ctx->rm_q6_wq, |
| 1858 | &ipa3_q6_con_rm_request, 0); |
| 1859 | return 0; |
| 1860 | } |
| 1861 | |
| 1862 | static void ipa3_q6_prod_rm_release_resource(struct work_struct *work) |
| 1863 | { |
| 1864 | int ret = 0; |
| 1865 | |
| 1866 | ret = ipa_rm_release_resource(IPA_RM_RESOURCE_Q6_PROD); |
| 1867 | if (ret < 0 && ret != -EINPROGRESS) { |
| 1868 | IPAWANERR("%s: ipa_rm_release_resource failed %d\n", __func__, |
| 1869 | ret); |
| 1870 | return; |
| 1871 | } |
| 1872 | } |
| 1873 | |
| 1874 | |
| 1875 | static int ipa3_q6_rm_release_resource(void) |
| 1876 | { |
| 1877 | queue_delayed_work(rmnet_ipa3_ctx->rm_q6_wq, |
| 1878 | &ipa3_q6_con_rm_release, 0); |
| 1879 | return 0; |
| 1880 | } |
| 1881 | |
| 1882 | |
| 1883 | static void ipa3_q6_rm_notify_cb(void *user_data, |
| 1884 | enum ipa_rm_event event, |
| 1885 | unsigned long data) |
| 1886 | { |
| 1887 | switch (event) { |
| 1888 | case IPA_RM_RESOURCE_GRANTED: |
| 1889 | IPAWANDBG_LOW("%s: Q6_PROD GRANTED CB\n", __func__); |
| 1890 | break; |
| 1891 | case IPA_RM_RESOURCE_RELEASED: |
| 1892 | IPAWANDBG_LOW("%s: Q6_PROD RELEASED CB\n", __func__); |
| 1893 | break; |
| 1894 | default: |
| 1895 | return; |
| 1896 | } |
| 1897 | } |
Michael Adisumarta | 3e35081 | 2017-09-18 14:54:36 -0700 | [diff] [blame] | 1898 | |
| 1899 | int ipa3_wwan_set_modem_state(struct wan_ioctl_notify_wan_state *state) |
| 1900 | { |
| 1901 | if (!state) |
| 1902 | return -EINVAL; |
| 1903 | |
| 1904 | if (!ipa_pm_is_used()) |
| 1905 | return 0; |
| 1906 | |
| 1907 | if (state->up) |
| 1908 | return ipa_pm_activate_sync(rmnet_ipa3_ctx->q6_teth_pm_hdl); |
| 1909 | else |
| 1910 | return ipa_pm_deactivate_sync(rmnet_ipa3_ctx->q6_teth_pm_hdl); |
| 1911 | } |
| 1912 | |
| 1913 | /** |
| 1914 | * ipa3_q6_register_pm - Register modem clients for PM |
| 1915 | * |
| 1916 | * This function will register 2 client with IPA PM to represent modem |
| 1917 | * in clock scaling calculation: |
| 1918 | * - "EMB MODEM" - this client will be activated with embedded traffic |
| 1919 | - "TETH MODEM" - this client we be activated by IPACM on offload to |
| 1920 | modem. |
| 1921 | */ |
| 1922 | static int ipa3_q6_register_pm(void) |
| 1923 | { |
| 1924 | int result; |
| 1925 | struct ipa_pm_register_params pm_reg; |
| 1926 | |
| 1927 | memset(&pm_reg, 0, sizeof(pm_reg)); |
| 1928 | pm_reg.name = "EMB MODEM"; |
| 1929 | pm_reg.group = IPA_PM_GROUP_MODEM; |
| 1930 | pm_reg.skip_clk_vote = true; |
| 1931 | result = ipa_pm_register(&pm_reg, &rmnet_ipa3_ctx->q6_pm_hdl); |
| 1932 | if (result) { |
| 1933 | IPAERR("failed to create IPA PM client %d\n", result); |
| 1934 | return result; |
| 1935 | } |
| 1936 | |
| 1937 | pm_reg.name = "TETH MODEM"; |
| 1938 | pm_reg.group = IPA_PM_GROUP_MODEM; |
| 1939 | pm_reg.skip_clk_vote = true; |
| 1940 | result = ipa_pm_register(&pm_reg, &rmnet_ipa3_ctx->q6_teth_pm_hdl); |
| 1941 | if (result) { |
| 1942 | IPAERR("failed to create IPA PM client %d\n", result); |
| 1943 | return result; |
| 1944 | } |
| 1945 | |
| 1946 | return 0; |
| 1947 | } |
| 1948 | |
| 1949 | static void ipa3_q6_deregister_pm(void) |
| 1950 | { |
| 1951 | ipa_pm_deactivate_sync(rmnet_ipa3_ctx->q6_pm_hdl); |
| 1952 | ipa_pm_deregister(rmnet_ipa3_ctx->q6_pm_hdl); |
| 1953 | } |
| 1954 | |
| 1955 | int ipa3_wwan_set_modem_perf_profile(int throughput) |
| 1956 | { |
| 1957 | struct ipa_rm_perf_profile profile; |
| 1958 | int ret; |
| 1959 | |
Michael Adisumarta | 3e35081 | 2017-09-18 14:54:36 -0700 | [diff] [blame] | 1960 | if (ipa3_ctx->use_ipa_pm) { |
| 1961 | ret = ipa_pm_set_perf_profile(rmnet_ipa3_ctx->q6_pm_hdl, |
| 1962 | throughput); |
| 1963 | if (ret) |
| 1964 | return ret; |
| 1965 | ret = ipa_pm_set_perf_profile(rmnet_ipa3_ctx->q6_teth_pm_hdl, |
| 1966 | throughput); |
| 1967 | } else { |
| 1968 | memset(&profile, 0, sizeof(profile)); |
| 1969 | profile.max_supported_bandwidth_mbps = throughput; |
| 1970 | ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_Q6_PROD, |
| 1971 | &profile); |
| 1972 | } |
| 1973 | |
| 1974 | return ret; |
| 1975 | } |
| 1976 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 1977 | static int ipa3_q6_initialize_rm(void) |
| 1978 | { |
| 1979 | struct ipa_rm_create_params create_params; |
| 1980 | struct ipa_rm_perf_profile profile; |
| 1981 | int result; |
| 1982 | |
| 1983 | /* Initialize IPA_RM workqueue */ |
| 1984 | rmnet_ipa3_ctx->rm_q6_wq = create_singlethread_workqueue("clnt_req"); |
| 1985 | if (!rmnet_ipa3_ctx->rm_q6_wq) |
| 1986 | return -ENOMEM; |
| 1987 | |
| 1988 | memset(&create_params, 0, sizeof(create_params)); |
| 1989 | create_params.name = IPA_RM_RESOURCE_Q6_PROD; |
| 1990 | create_params.reg_params.notify_cb = &ipa3_q6_rm_notify_cb; |
| 1991 | result = ipa_rm_create_resource(&create_params); |
| 1992 | if (result) |
| 1993 | goto create_rsrc_err1; |
| 1994 | memset(&create_params, 0, sizeof(create_params)); |
| 1995 | create_params.name = IPA_RM_RESOURCE_Q6_CONS; |
| 1996 | create_params.release_resource = &ipa3_q6_rm_release_resource; |
| 1997 | create_params.request_resource = &ipa3_q6_rm_request_resource; |
| 1998 | result = ipa_rm_create_resource(&create_params); |
| 1999 | if (result) |
| 2000 | goto create_rsrc_err2; |
| 2001 | /* add dependency*/ |
| 2002 | result = ipa_rm_add_dependency(IPA_RM_RESOURCE_Q6_PROD, |
| 2003 | IPA_RM_RESOURCE_APPS_CONS); |
| 2004 | if (result) |
| 2005 | goto add_dpnd_err; |
| 2006 | /* setup Performance profile */ |
| 2007 | memset(&profile, 0, sizeof(profile)); |
| 2008 | profile.max_supported_bandwidth_mbps = 100; |
| 2009 | result = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_Q6_PROD, |
| 2010 | &profile); |
| 2011 | if (result) |
| 2012 | goto set_perf_err; |
| 2013 | result = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_Q6_CONS, |
| 2014 | &profile); |
| 2015 | if (result) |
| 2016 | goto set_perf_err; |
| 2017 | return result; |
| 2018 | |
| 2019 | set_perf_err: |
| 2020 | ipa_rm_delete_dependency(IPA_RM_RESOURCE_Q6_PROD, |
| 2021 | IPA_RM_RESOURCE_APPS_CONS); |
| 2022 | add_dpnd_err: |
| 2023 | result = ipa_rm_delete_resource(IPA_RM_RESOURCE_Q6_CONS); |
| 2024 | if (result < 0) |
| 2025 | IPAWANERR("Error deleting resource %d, ret=%d\n", |
| 2026 | IPA_RM_RESOURCE_Q6_CONS, result); |
| 2027 | create_rsrc_err2: |
| 2028 | result = ipa_rm_delete_resource(IPA_RM_RESOURCE_Q6_PROD); |
| 2029 | if (result < 0) |
| 2030 | IPAWANERR("Error deleting resource %d, ret=%d\n", |
| 2031 | IPA_RM_RESOURCE_Q6_PROD, result); |
| 2032 | create_rsrc_err1: |
| 2033 | destroy_workqueue(rmnet_ipa3_ctx->rm_q6_wq); |
| 2034 | return result; |
| 2035 | } |
| 2036 | |
| 2037 | void ipa3_q6_deinitialize_rm(void) |
| 2038 | { |
| 2039 | int ret; |
| 2040 | |
| 2041 | ret = ipa_rm_delete_dependency(IPA_RM_RESOURCE_Q6_PROD, |
| 2042 | IPA_RM_RESOURCE_APPS_CONS); |
| 2043 | if (ret < 0) |
| 2044 | IPAWANERR("Error deleting dependency %d->%d, ret=%d\n", |
| 2045 | IPA_RM_RESOURCE_Q6_PROD, IPA_RM_RESOURCE_APPS_CONS, |
| 2046 | ret); |
| 2047 | ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_Q6_CONS); |
| 2048 | if (ret < 0) |
| 2049 | IPAWANERR("Error deleting resource %d, ret=%d\n", |
| 2050 | IPA_RM_RESOURCE_Q6_CONS, ret); |
| 2051 | ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_Q6_PROD); |
| 2052 | if (ret < 0) |
| 2053 | IPAWANERR("Error deleting resource %d, ret=%d\n", |
| 2054 | IPA_RM_RESOURCE_Q6_PROD, ret); |
Mohammed Javid | 4e3015d | 2017-07-31 13:27:18 +0530 | [diff] [blame] | 2055 | |
| 2056 | if (rmnet_ipa3_ctx->rm_q6_wq) |
| 2057 | destroy_workqueue(rmnet_ipa3_ctx->rm_q6_wq); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | static void ipa3_wake_tx_queue(struct work_struct *work) |
| 2061 | { |
| 2062 | if (IPA_NETDEV()) { |
| 2063 | __netif_tx_lock_bh(netdev_get_tx_queue(IPA_NETDEV(), 0)); |
| 2064 | netif_wake_queue(IPA_NETDEV()); |
| 2065 | __netif_tx_unlock_bh(netdev_get_tx_queue(IPA_NETDEV(), 0)); |
| 2066 | } |
| 2067 | } |
| 2068 | |
| 2069 | /** |
| 2070 | * ipa3_rm_resource_granted() - Called upon |
| 2071 | * IPA_RM_RESOURCE_GRANTED event. Wakes up queue is was stopped. |
| 2072 | * |
| 2073 | * @work: work object supplied ny workqueue |
| 2074 | * |
| 2075 | * Return codes: |
| 2076 | * None |
| 2077 | */ |
| 2078 | static void ipa3_rm_resource_granted(void *dev) |
| 2079 | { |
| 2080 | IPAWANDBG_LOW("Resource Granted - starting queue\n"); |
| 2081 | schedule_work(&ipa3_tx_wakequeue_work); |
| 2082 | } |
| 2083 | |
| 2084 | /** |
| 2085 | * ipa3_rm_notify() - Callback function for RM events. Handles |
| 2086 | * IPA_RM_RESOURCE_GRANTED and IPA_RM_RESOURCE_RELEASED events. |
| 2087 | * IPA_RM_RESOURCE_GRANTED is handled in the context of shared |
| 2088 | * workqueue. |
| 2089 | * |
| 2090 | * @dev: network device |
| 2091 | * @event: IPA RM event |
| 2092 | * @data: Additional data provided by IPA RM |
| 2093 | * |
| 2094 | * Return codes: |
| 2095 | * None |
| 2096 | */ |
| 2097 | static void ipa3_rm_notify(void *dev, enum ipa_rm_event event, |
| 2098 | unsigned long data) |
| 2099 | { |
| 2100 | struct ipa3_wwan_private *wwan_ptr = netdev_priv(dev); |
| 2101 | |
| 2102 | pr_debug("%s: event %d\n", __func__, event); |
| 2103 | switch (event) { |
| 2104 | case IPA_RM_RESOURCE_GRANTED: |
| 2105 | if (wwan_ptr->device_status == WWAN_DEVICE_INACTIVE) { |
| 2106 | complete_all(&wwan_ptr->resource_granted_completion); |
| 2107 | break; |
| 2108 | } |
| 2109 | ipa3_rm_resource_granted(dev); |
| 2110 | break; |
| 2111 | case IPA_RM_RESOURCE_RELEASED: |
| 2112 | break; |
| 2113 | default: |
| 2114 | pr_err("%s: unknown event %d\n", __func__, event); |
| 2115 | break; |
| 2116 | } |
| 2117 | } |
| 2118 | |
| 2119 | /* IPA_RM related functions end*/ |
| 2120 | |
| 2121 | static int ipa3_ssr_notifier_cb(struct notifier_block *this, |
| 2122 | unsigned long code, |
| 2123 | void *data); |
| 2124 | |
| 2125 | static struct notifier_block ipa3_ssr_notifier = { |
| 2126 | .notifier_call = ipa3_ssr_notifier_cb, |
| 2127 | }; |
| 2128 | |
| 2129 | static int get_ipa_rmnet_dts_configuration(struct platform_device *pdev, |
| 2130 | struct ipa3_rmnet_plat_drv_res *ipa_rmnet_drv_res) |
| 2131 | { |
Sunil Paidimarri | 226cf03 | 2016-10-14 13:33:08 -0700 | [diff] [blame] | 2132 | int result; |
| 2133 | |
| 2134 | ipa_rmnet_drv_res->wan_rx_desc_size = IPA_WWAN_CONS_DESC_FIFO_SZ; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2135 | ipa_rmnet_drv_res->ipa_rmnet_ssr = |
| 2136 | of_property_read_bool(pdev->dev.of_node, |
| 2137 | "qcom,rmnet-ipa-ssr"); |
| 2138 | pr_info("IPA SSR support = %s\n", |
| 2139 | ipa_rmnet_drv_res->ipa_rmnet_ssr ? "True" : "False"); |
| 2140 | ipa_rmnet_drv_res->ipa_loaduC = |
| 2141 | of_property_read_bool(pdev->dev.of_node, |
| 2142 | "qcom,ipa-loaduC"); |
| 2143 | pr_info("IPA ipa-loaduC = %s\n", |
| 2144 | ipa_rmnet_drv_res->ipa_loaduC ? "True" : "False"); |
| 2145 | |
| 2146 | ipa_rmnet_drv_res->ipa_advertise_sg_support = |
| 2147 | of_property_read_bool(pdev->dev.of_node, |
| 2148 | "qcom,ipa-advertise-sg-support"); |
| 2149 | pr_info("IPA SG support = %s\n", |
| 2150 | ipa_rmnet_drv_res->ipa_advertise_sg_support ? "True" : "False"); |
Gidon Studinski | 3021a6f | 2016-11-10 12:48:48 +0200 | [diff] [blame] | 2151 | |
| 2152 | ipa_rmnet_drv_res->ipa_napi_enable = |
| 2153 | of_property_read_bool(pdev->dev.of_node, |
| 2154 | "qcom,ipa-napi-enable"); |
| 2155 | pr_info("IPA Napi Enable = %s\n", |
| 2156 | ipa_rmnet_drv_res->ipa_napi_enable ? "True" : "False"); |
Sunil Paidimarri | 226cf03 | 2016-10-14 13:33:08 -0700 | [diff] [blame] | 2157 | |
| 2158 | /* Get IPA WAN RX desc fifo size */ |
| 2159 | result = of_property_read_u32(pdev->dev.of_node, |
| 2160 | "qcom,wan-rx-desc-size", |
| 2161 | &ipa_rmnet_drv_res->wan_rx_desc_size); |
| 2162 | if (result) |
| 2163 | pr_info("using default for wan-rx-desc-size = %u\n", |
| 2164 | ipa_rmnet_drv_res->wan_rx_desc_size); |
| 2165 | else |
| 2166 | IPAWANDBG(": found ipa_drv_res->wan-rx-desc-size = %u\n", |
| 2167 | ipa_rmnet_drv_res->wan_rx_desc_size); |
| 2168 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2169 | return 0; |
| 2170 | } |
| 2171 | |
| 2172 | struct ipa3_rmnet_context ipa3_rmnet_ctx; |
| 2173 | static int ipa3_wwan_probe(struct platform_device *pdev); |
| 2174 | struct platform_device *m_pdev; |
| 2175 | |
| 2176 | static void ipa3_delayed_probe(struct work_struct *work) |
| 2177 | { |
| 2178 | (void)ipa3_wwan_probe(m_pdev); |
| 2179 | } |
| 2180 | |
| 2181 | static DECLARE_WORK(ipa3_scheduled_probe, ipa3_delayed_probe); |
| 2182 | |
| 2183 | static void ipa3_ready_cb(void *user_data) |
| 2184 | { |
| 2185 | struct platform_device *pdev = (struct platform_device *)(user_data); |
| 2186 | |
| 2187 | m_pdev = pdev; |
| 2188 | |
| 2189 | IPAWANDBG("IPA ready callback has been triggered!\n"); |
| 2190 | |
| 2191 | schedule_work(&ipa3_scheduled_probe); |
| 2192 | } |
| 2193 | |
Michael Adisumarta | 3e35081 | 2017-09-18 14:54:36 -0700 | [diff] [blame] | 2194 | static void ipa_pm_wwan_pm_cb(void *p, enum ipa_pm_cb_event event) |
| 2195 | { |
| 2196 | struct net_device *dev = (struct net_device *)p; |
| 2197 | struct ipa3_wwan_private *wwan_ptr = netdev_priv(dev); |
| 2198 | |
| 2199 | IPAWANDBG_LOW("event %d\n", event); |
| 2200 | switch (event) { |
| 2201 | case IPA_PM_CLIENT_ACTIVATED: |
| 2202 | if (wwan_ptr->device_status == WWAN_DEVICE_INACTIVE) { |
| 2203 | complete_all(&wwan_ptr->resource_granted_completion); |
| 2204 | break; |
| 2205 | } |
| 2206 | ipa3_rm_resource_granted(dev); |
| 2207 | break; |
| 2208 | default: |
| 2209 | pr_err("%s: unknown event %d\n", __func__, event); |
| 2210 | break; |
| 2211 | } |
| 2212 | } |
| 2213 | |
| 2214 | static int ipa3_wwan_register_netdev_pm_client(struct net_device *dev) |
| 2215 | { |
| 2216 | int result; |
| 2217 | struct ipa_pm_register_params pm_reg; |
| 2218 | |
| 2219 | memset(&pm_reg, 0, sizeof(pm_reg)); |
| 2220 | pm_reg.name = IPA_NETDEV()->name; |
| 2221 | pm_reg.user_data = dev; |
| 2222 | pm_reg.callback = ipa_pm_wwan_pm_cb; |
| 2223 | pm_reg.group = IPA_PM_GROUP_APPS; |
| 2224 | result = ipa_pm_register(&pm_reg, &rmnet_ipa3_ctx->pm_hdl); |
| 2225 | if (result) { |
| 2226 | IPAERR("failed to create IPA PM client %d\n", result); |
| 2227 | return result; |
| 2228 | } |
| 2229 | return 0; |
| 2230 | } |
| 2231 | |
| 2232 | static void ipa3_wwan_deregister_netdev_pm_client(void) |
| 2233 | { |
| 2234 | ipa_pm_deactivate_sync(rmnet_ipa3_ctx->pm_hdl); |
| 2235 | ipa_pm_deregister(rmnet_ipa3_ctx->pm_hdl); |
| 2236 | } |
| 2237 | |
| 2238 | static int ipa3_wwan_create_wwan_rm_resource(struct net_device *dev) |
| 2239 | { |
| 2240 | struct ipa_rm_create_params ipa_rm_params; |
| 2241 | struct ipa_rm_perf_profile profile; |
| 2242 | int ret; |
| 2243 | |
| 2244 | memset(&ipa_rm_params, 0, sizeof(struct ipa_rm_create_params)); |
| 2245 | ipa_rm_params.name = IPA_RM_RESOURCE_WWAN_0_PROD; |
| 2246 | ipa_rm_params.reg_params.user_data = dev; |
| 2247 | ipa_rm_params.reg_params.notify_cb = ipa3_rm_notify; |
| 2248 | ret = ipa_rm_create_resource(&ipa_rm_params); |
| 2249 | if (ret) { |
| 2250 | pr_err("%s: unable to create resourse %d in IPA RM\n", |
| 2251 | __func__, IPA_RM_RESOURCE_WWAN_0_PROD); |
| 2252 | return ret; |
| 2253 | } |
| 2254 | ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WWAN_0_PROD, |
| 2255 | IPA_RM_INACTIVITY_TIMER); |
| 2256 | if (ret) { |
| 2257 | pr_err("%s: ipa rm timer init failed %d on resourse %d\n", |
| 2258 | __func__, ret, IPA_RM_RESOURCE_WWAN_0_PROD); |
| 2259 | goto timer_init_err; |
| 2260 | } |
| 2261 | /* add dependency */ |
| 2262 | ret = ipa_rm_add_dependency(IPA_RM_RESOURCE_WWAN_0_PROD, |
| 2263 | IPA_RM_RESOURCE_Q6_CONS); |
| 2264 | if (ret) |
| 2265 | goto add_dpnd_err; |
| 2266 | /* setup Performance profile */ |
| 2267 | memset(&profile, 0, sizeof(profile)); |
| 2268 | profile.max_supported_bandwidth_mbps = IPA_APPS_MAX_BW_IN_MBPS; |
| 2269 | ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WWAN_0_PROD, |
| 2270 | &profile); |
| 2271 | if (ret) |
| 2272 | goto set_perf_err; |
| 2273 | |
| 2274 | return 0; |
| 2275 | |
| 2276 | set_perf_err: |
| 2277 | ipa_rm_delete_dependency(IPA_RM_RESOURCE_WWAN_0_PROD, |
| 2278 | IPA_RM_RESOURCE_Q6_CONS); |
| 2279 | add_dpnd_err: |
| 2280 | ipa_rm_inactivity_timer_destroy( |
| 2281 | IPA_RM_RESOURCE_WWAN_0_PROD); /* IPA_RM */ |
| 2282 | timer_init_err: |
| 2283 | ipa_rm_delete_resource(IPA_RM_RESOURCE_WWAN_0_PROD); |
| 2284 | return ret; |
| 2285 | } |
| 2286 | |
| 2287 | static void ipa3_wwan_delete_wwan_rm_resource(void) |
| 2288 | { |
| 2289 | int ret; |
| 2290 | |
| 2291 | ret = ipa_rm_delete_dependency(IPA_RM_RESOURCE_WWAN_0_PROD, |
| 2292 | IPA_RM_RESOURCE_Q6_CONS); |
| 2293 | if (ret < 0) |
| 2294 | IPAWANERR("Error deleting dependency %d->%d, ret=%d\n", |
| 2295 | IPA_RM_RESOURCE_WWAN_0_PROD, IPA_RM_RESOURCE_Q6_CONS, |
| 2296 | ret); |
| 2297 | ret = ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WWAN_0_PROD); |
| 2298 | if (ret < 0) |
| 2299 | IPAWANERR( |
| 2300 | "Error ipa_rm_inactivity_timer_destroy resource %d, ret=%d\n", |
| 2301 | IPA_RM_RESOURCE_WWAN_0_PROD, ret); |
| 2302 | ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WWAN_0_PROD); |
| 2303 | if (ret < 0) |
| 2304 | IPAWANERR("Error deleting resource %d, ret=%d\n", |
| 2305 | IPA_RM_RESOURCE_WWAN_0_PROD, ret); |
| 2306 | } |
| 2307 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2308 | /** |
| 2309 | * ipa3_wwan_probe() - Initialized the module and registers as a |
| 2310 | * network interface to the network stack |
| 2311 | * |
| 2312 | * Note: In case IPA driver hasn't initialized already, the probe function |
| 2313 | * will return immediately after registering a callback to be invoked when |
| 2314 | * IPA driver initialization is complete. |
| 2315 | * |
| 2316 | * Return codes: |
| 2317 | * 0: success |
| 2318 | * -ENOMEM: No memory available |
| 2319 | * -EFAULT: Internal error |
| 2320 | */ |
| 2321 | static int ipa3_wwan_probe(struct platform_device *pdev) |
| 2322 | { |
| 2323 | int ret, i; |
| 2324 | struct net_device *dev; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2325 | |
| 2326 | pr_info("rmnet_ipa3 started initialization\n"); |
| 2327 | |
| 2328 | if (!ipa3_is_ready()) { |
| 2329 | IPAWANDBG("IPA driver not ready, registering callback\n"); |
| 2330 | ret = ipa_register_ipa_ready_cb(ipa3_ready_cb, (void *)pdev); |
| 2331 | |
| 2332 | /* |
| 2333 | * If we received -EEXIST, IPA has initialized. So we need |
| 2334 | * to continue the probing process. |
| 2335 | */ |
| 2336 | if (ret != -EEXIST) { |
| 2337 | if (ret) |
| 2338 | IPAWANERR("IPA CB reg failed - %d\n", ret); |
| 2339 | return ret; |
| 2340 | } |
| 2341 | } |
| 2342 | |
| 2343 | ret = get_ipa_rmnet_dts_configuration(pdev, &ipa3_rmnet_res); |
| 2344 | ipa3_rmnet_ctx.ipa_rmnet_ssr = ipa3_rmnet_res.ipa_rmnet_ssr; |
| 2345 | |
| 2346 | ret = ipa3_init_q6_smem(); |
| 2347 | if (ret) { |
| 2348 | IPAWANERR("ipa3_init_q6_smem failed!\n"); |
| 2349 | return ret; |
| 2350 | } |
| 2351 | |
| 2352 | /* initialize tx/rx endpoint setup */ |
| 2353 | memset(&rmnet_ipa3_ctx->apps_to_ipa_ep_cfg, 0, |
| 2354 | sizeof(struct ipa_sys_connect_params)); |
| 2355 | memset(&rmnet_ipa3_ctx->ipa_to_apps_ep_cfg, 0, |
| 2356 | sizeof(struct ipa_sys_connect_params)); |
| 2357 | |
| 2358 | /* initialize ex property setup */ |
| 2359 | rmnet_ipa3_ctx->num_q6_rules = 0; |
| 2360 | rmnet_ipa3_ctx->old_num_q6_rules = 0; |
| 2361 | rmnet_ipa3_ctx->rmnet_index = 0; |
| 2362 | rmnet_ipa3_ctx->egress_set = false; |
| 2363 | rmnet_ipa3_ctx->a7_ul_flt_set = false; |
| 2364 | for (i = 0; i < MAX_NUM_OF_MUX_CHANNEL; i++) |
| 2365 | memset(&rmnet_ipa3_ctx->mux_channel[i], 0, |
| 2366 | sizeof(struct ipa3_rmnet_mux_val)); |
| 2367 | |
| 2368 | /* start A7 QMI service/client */ |
| 2369 | if (ipa3_rmnet_res.ipa_loaduC) |
| 2370 | /* Android platform loads uC */ |
| 2371 | ipa3_qmi_service_init(QMI_IPA_PLATFORM_TYPE_MSM_ANDROID_V01); |
| 2372 | else |
| 2373 | /* LE platform not loads uC */ |
| 2374 | ipa3_qmi_service_init(QMI_IPA_PLATFORM_TYPE_LE_V01); |
| 2375 | |
| 2376 | /* construct default WAN RT tbl for IPACM */ |
| 2377 | ret = ipa3_setup_a7_qmap_hdr(); |
| 2378 | if (ret) |
| 2379 | goto setup_a7_qmap_hdr_err; |
| 2380 | ret = ipa3_setup_dflt_wan_rt_tables(); |
| 2381 | if (ret) |
| 2382 | goto setup_dflt_wan_rt_tables_err; |
| 2383 | |
| 2384 | if (!atomic_read(&rmnet_ipa3_ctx->is_ssr)) { |
| 2385 | /* Start transport-driver fd ioctl for ipacm for first init */ |
| 2386 | ret = ipa3_wan_ioctl_init(); |
| 2387 | if (ret) |
| 2388 | goto wan_ioctl_init_err; |
| 2389 | } else { |
| 2390 | /* Enable sending QMI messages after SSR */ |
| 2391 | ipa3_wan_ioctl_enable_qmi_messages(); |
| 2392 | } |
| 2393 | |
| 2394 | /* initialize wan-driver netdev */ |
| 2395 | dev = alloc_netdev(sizeof(struct ipa3_wwan_private), |
| 2396 | IPA_WWAN_DEV_NAME, |
| 2397 | NET_NAME_UNKNOWN, |
| 2398 | ipa3_wwan_setup); |
| 2399 | if (!dev) { |
| 2400 | IPAWANERR("no memory for netdev\n"); |
| 2401 | ret = -ENOMEM; |
| 2402 | goto alloc_netdev_err; |
| 2403 | } |
| 2404 | rmnet_ipa3_ctx->wwan_priv = netdev_priv(dev); |
| 2405 | memset(rmnet_ipa3_ctx->wwan_priv, 0, |
| 2406 | sizeof(*(rmnet_ipa3_ctx->wwan_priv))); |
| 2407 | IPAWANDBG("wwan_ptr (private) = %p", rmnet_ipa3_ctx->wwan_priv); |
| 2408 | rmnet_ipa3_ctx->wwan_priv->net = dev; |
| 2409 | rmnet_ipa3_ctx->wwan_priv->outstanding_high = DEFAULT_OUTSTANDING_HIGH; |
| 2410 | rmnet_ipa3_ctx->wwan_priv->outstanding_low = DEFAULT_OUTSTANDING_LOW; |
| 2411 | atomic_set(&rmnet_ipa3_ctx->wwan_priv->outstanding_pkts, 0); |
| 2412 | spin_lock_init(&rmnet_ipa3_ctx->wwan_priv->lock); |
| 2413 | init_completion( |
| 2414 | &rmnet_ipa3_ctx->wwan_priv->resource_granted_completion); |
| 2415 | |
| 2416 | if (!atomic_read(&rmnet_ipa3_ctx->is_ssr)) { |
| 2417 | /* IPA_RM configuration starts */ |
Michael Adisumarta | 3e35081 | 2017-09-18 14:54:36 -0700 | [diff] [blame] | 2418 | if (ipa3_ctx->use_ipa_pm) |
| 2419 | ret = ipa3_q6_register_pm(); |
| 2420 | else |
| 2421 | ret = ipa3_q6_initialize_rm(); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2422 | if (ret) { |
| 2423 | IPAWANERR("%s: ipa3_q6_initialize_rm failed, ret: %d\n", |
| 2424 | __func__, ret); |
| 2425 | goto q6_init_err; |
| 2426 | } |
| 2427 | } |
| 2428 | |
Michael Adisumarta | 3e35081 | 2017-09-18 14:54:36 -0700 | [diff] [blame] | 2429 | if (ipa3_ctx->use_ipa_pm) |
| 2430 | ret = ipa3_wwan_register_netdev_pm_client(dev); |
| 2431 | else |
| 2432 | ret = ipa3_wwan_create_wwan_rm_resource(dev); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2433 | if (ret) { |
Michael Adisumarta | 3e35081 | 2017-09-18 14:54:36 -0700 | [diff] [blame] | 2434 | IPAWANERR("fail to create/register pm resources\n"); |
| 2435 | goto fail_pm; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2436 | } |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2437 | |
| 2438 | /* Enable SG support in netdevice. */ |
| 2439 | if (ipa3_rmnet_res.ipa_advertise_sg_support) |
| 2440 | dev->hw_features |= NETIF_F_SG; |
| 2441 | |
| 2442 | if (ipa3_rmnet_res.ipa_napi_enable) |
| 2443 | netif_napi_add(dev, &(rmnet_ipa3_ctx->wwan_priv->napi), |
| 2444 | ipa3_rmnet_poll, NAPI_WEIGHT); |
| 2445 | ret = register_netdev(dev); |
| 2446 | if (ret) { |
| 2447 | IPAWANERR("unable to register ipa_netdev %d rc=%d\n", |
| 2448 | 0, ret); |
| 2449 | goto set_perf_err; |
| 2450 | } |
| 2451 | |
| 2452 | IPAWANDBG("IPA-WWAN devices (%s) initialization ok :>>>>\n", dev->name); |
| 2453 | if (ret) { |
| 2454 | IPAWANERR("default configuration failed rc=%d\n", |
| 2455 | ret); |
| 2456 | goto config_err; |
| 2457 | } |
| 2458 | atomic_set(&rmnet_ipa3_ctx->is_initialized, 1); |
| 2459 | if (!atomic_read(&rmnet_ipa3_ctx->is_ssr)) { |
| 2460 | /* offline charging mode */ |
| 2461 | ipa3_proxy_clk_unvote(); |
| 2462 | } |
| 2463 | atomic_set(&rmnet_ipa3_ctx->is_ssr, 0); |
| 2464 | |
| 2465 | pr_info("rmnet_ipa completed initialization\n"); |
| 2466 | return 0; |
| 2467 | config_err: |
| 2468 | if (ipa3_rmnet_res.ipa_napi_enable) |
| 2469 | netif_napi_del(&(rmnet_ipa3_ctx->wwan_priv->napi)); |
| 2470 | unregister_netdev(dev); |
| 2471 | set_perf_err: |
Michael Adisumarta | 3e35081 | 2017-09-18 14:54:36 -0700 | [diff] [blame] | 2472 | if (ipa3_ctx->use_ipa_pm) |
| 2473 | ipa3_wwan_deregister_netdev_pm_client(); |
| 2474 | else |
| 2475 | ipa3_wwan_delete_wwan_rm_resource(); |
| 2476 | fail_pm: |
| 2477 | if (ipa3_ctx->use_ipa_pm) { |
| 2478 | if (!atomic_read(&rmnet_ipa3_ctx->is_ssr)) |
| 2479 | ipa3_q6_deregister_pm(); |
| 2480 | } else { |
| 2481 | if (!atomic_read(&rmnet_ipa3_ctx->is_ssr)) |
| 2482 | ipa3_q6_deinitialize_rm(); |
| 2483 | } |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2484 | q6_init_err: |
| 2485 | free_netdev(dev); |
| 2486 | rmnet_ipa3_ctx->wwan_priv = NULL; |
| 2487 | alloc_netdev_err: |
| 2488 | ipa3_wan_ioctl_deinit(); |
| 2489 | wan_ioctl_init_err: |
| 2490 | ipa3_del_dflt_wan_rt_tables(); |
| 2491 | setup_dflt_wan_rt_tables_err: |
| 2492 | ipa3_del_a7_qmap_hdr(); |
| 2493 | setup_a7_qmap_hdr_err: |
| 2494 | ipa3_qmi_service_exit(); |
| 2495 | atomic_set(&rmnet_ipa3_ctx->is_ssr, 0); |
| 2496 | return ret; |
| 2497 | } |
| 2498 | |
| 2499 | static int ipa3_wwan_remove(struct platform_device *pdev) |
| 2500 | { |
| 2501 | int ret; |
| 2502 | |
| 2503 | pr_info("rmnet_ipa started deinitialization\n"); |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 2504 | mutex_lock(&rmnet_ipa3_ctx->pipe_handle_guard); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2505 | ret = ipa3_teardown_sys_pipe(rmnet_ipa3_ctx->ipa3_to_apps_hdl); |
| 2506 | if (ret < 0) |
| 2507 | IPAWANERR("Failed to teardown IPA->APPS pipe\n"); |
| 2508 | else |
| 2509 | rmnet_ipa3_ctx->ipa3_to_apps_hdl = -1; |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 2510 | ret = ipa3_teardown_sys_pipe(rmnet_ipa3_ctx->apps_to_ipa3_hdl); |
| 2511 | if (ret < 0) |
| 2512 | IPAWANERR("Failed to teardown APPS->IPA pipe\n"); |
| 2513 | else |
| 2514 | rmnet_ipa3_ctx->apps_to_ipa3_hdl = -1; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2515 | if (ipa3_rmnet_res.ipa_napi_enable) |
| 2516 | netif_napi_del(&(rmnet_ipa3_ctx->wwan_priv->napi)); |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 2517 | mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2518 | unregister_netdev(IPA_NETDEV()); |
Michael Adisumarta | 3e35081 | 2017-09-18 14:54:36 -0700 | [diff] [blame] | 2519 | if (ipa3_ctx->use_ipa_pm) |
| 2520 | ipa3_wwan_deregister_netdev_pm_client(); |
| 2521 | else |
| 2522 | ipa3_wwan_delete_wwan_rm_resource(); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2523 | cancel_work_sync(&ipa3_tx_wakequeue_work); |
| 2524 | cancel_delayed_work(&ipa_tether_stats_poll_wakequeue_work); |
| 2525 | if (IPA_NETDEV()) |
| 2526 | free_netdev(IPA_NETDEV()); |
| 2527 | rmnet_ipa3_ctx->wwan_priv = NULL; |
| 2528 | /* No need to remove wwan_ioctl during SSR */ |
| 2529 | if (!atomic_read(&rmnet_ipa3_ctx->is_ssr)) |
| 2530 | ipa3_wan_ioctl_deinit(); |
| 2531 | ipa3_del_dflt_wan_rt_tables(); |
| 2532 | ipa3_del_a7_qmap_hdr(); |
| 2533 | ipa3_del_mux_qmap_hdrs(); |
| 2534 | if (ipa3_qmi_ctx->modem_cfg_emb_pipe_flt == false) |
| 2535 | ipa3_wwan_del_ul_flt_rule_to_ipa(); |
| 2536 | ipa3_cleanup_deregister_intf(); |
| 2537 | atomic_set(&rmnet_ipa3_ctx->is_initialized, 0); |
| 2538 | pr_info("rmnet_ipa completed deinitialization\n"); |
| 2539 | return 0; |
| 2540 | } |
| 2541 | |
| 2542 | /** |
| 2543 | * rmnet_ipa_ap_suspend() - suspend callback for runtime_pm |
| 2544 | * @dev: pointer to device |
| 2545 | * |
| 2546 | * This callback will be invoked by the runtime_pm framework when an AP suspend |
| 2547 | * operation is invoked, usually by pressing a suspend button. |
| 2548 | * |
| 2549 | * Returns -EAGAIN to runtime_pm framework in case there are pending packets |
| 2550 | * in the Tx queue. This will postpone the suspend operation until all the |
| 2551 | * pending packets will be transmitted. |
| 2552 | * |
| 2553 | * In case there are no packets to send, releases the WWAN0_PROD entity. |
| 2554 | * As an outcome, the number of IPA active clients should be decremented |
| 2555 | * until IPA clocks can be gated. |
| 2556 | */ |
| 2557 | static int rmnet_ipa_ap_suspend(struct device *dev) |
| 2558 | { |
| 2559 | struct net_device *netdev = IPA_NETDEV(); |
| 2560 | struct ipa3_wwan_private *wwan_ptr; |
Skylar Chang | 24a6cc1 | 2017-04-10 14:59:40 -0700 | [diff] [blame] | 2561 | int ret; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2562 | |
Skylar Chang | 24a6cc1 | 2017-04-10 14:59:40 -0700 | [diff] [blame] | 2563 | IPAWANDBG("Enter...\n"); |
| 2564 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2565 | if (netdev == NULL) { |
| 2566 | IPAWANERR("netdev is NULL.\n"); |
Skylar Chang | 24a6cc1 | 2017-04-10 14:59:40 -0700 | [diff] [blame] | 2567 | ret = 0; |
| 2568 | goto bail; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2569 | } |
| 2570 | |
Skylar Chang | 24a6cc1 | 2017-04-10 14:59:40 -0700 | [diff] [blame] | 2571 | netif_tx_lock_bh(netdev); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2572 | wwan_ptr = netdev_priv(netdev); |
| 2573 | if (wwan_ptr == NULL) { |
| 2574 | IPAWANERR("wwan_ptr is NULL.\n"); |
Skylar Chang | 24a6cc1 | 2017-04-10 14:59:40 -0700 | [diff] [blame] | 2575 | ret = 0; |
Michael Adisumarta | 3e35081 | 2017-09-18 14:54:36 -0700 | [diff] [blame] | 2576 | netif_tx_unlock_bh(netdev); |
| 2577 | goto bail; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | /* Do not allow A7 to suspend in case there are oustanding packets */ |
| 2581 | if (atomic_read(&wwan_ptr->outstanding_pkts) != 0) { |
| 2582 | IPAWANDBG("Outstanding packets, postponing AP suspend.\n"); |
Skylar Chang | 24a6cc1 | 2017-04-10 14:59:40 -0700 | [diff] [blame] | 2583 | ret = -EAGAIN; |
Michael Adisumarta | 3e35081 | 2017-09-18 14:54:36 -0700 | [diff] [blame] | 2584 | netif_tx_unlock_bh(netdev); |
| 2585 | goto bail; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2586 | } |
| 2587 | |
| 2588 | /* Make sure that there is no Tx operation ongoing */ |
Skylar Chang | 24a6cc1 | 2017-04-10 14:59:40 -0700 | [diff] [blame] | 2589 | netif_stop_queue(netdev); |
Skylar Chang | 24a6cc1 | 2017-04-10 14:59:40 -0700 | [diff] [blame] | 2590 | netif_tx_unlock_bh(netdev); |
Michael Adisumarta | 3e35081 | 2017-09-18 14:54:36 -0700 | [diff] [blame] | 2591 | if (ipa3_ctx->use_ipa_pm) |
| 2592 | ipa_pm_deactivate_sync(rmnet_ipa3_ctx->pm_hdl); |
| 2593 | else |
| 2594 | ipa_rm_release_resource(IPA_RM_RESOURCE_WWAN_0_PROD); |
| 2595 | ret = 0; |
Skylar Chang | 24a6cc1 | 2017-04-10 14:59:40 -0700 | [diff] [blame] | 2596 | bail: |
| 2597 | IPAWANDBG("Exit with %d\n", ret); |
| 2598 | return ret; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | /** |
| 2602 | * rmnet_ipa_ap_resume() - resume callback for runtime_pm |
| 2603 | * @dev: pointer to device |
| 2604 | * |
| 2605 | * This callback will be invoked by the runtime_pm framework when an AP resume |
| 2606 | * operation is invoked. |
| 2607 | * |
| 2608 | * Enables the network interface queue and returns success to the |
| 2609 | * runtime_pm framework. |
| 2610 | */ |
| 2611 | static int rmnet_ipa_ap_resume(struct device *dev) |
| 2612 | { |
| 2613 | struct net_device *netdev = IPA_NETDEV(); |
| 2614 | |
Skylar Chang | 24a6cc1 | 2017-04-10 14:59:40 -0700 | [diff] [blame] | 2615 | IPAWANDBG("Enter...\n"); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2616 | if (netdev) |
| 2617 | netif_wake_queue(netdev); |
Skylar Chang | 24a6cc1 | 2017-04-10 14:59:40 -0700 | [diff] [blame] | 2618 | IPAWANDBG("Exit\n"); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2619 | |
| 2620 | return 0; |
| 2621 | } |
| 2622 | |
| 2623 | static void ipa_stop_polling_stats(void) |
| 2624 | { |
| 2625 | cancel_delayed_work(&ipa_tether_stats_poll_wakequeue_work); |
| 2626 | ipa3_rmnet_ctx.polling_interval = 0; |
| 2627 | } |
| 2628 | |
| 2629 | static const struct of_device_id rmnet_ipa_dt_match[] = { |
| 2630 | {.compatible = "qcom,rmnet-ipa3"}, |
| 2631 | {}, |
| 2632 | }; |
| 2633 | MODULE_DEVICE_TABLE(of, rmnet_ipa_dt_match); |
| 2634 | |
| 2635 | static const struct dev_pm_ops rmnet_ipa_pm_ops = { |
| 2636 | .suspend_noirq = rmnet_ipa_ap_suspend, |
| 2637 | .resume_noirq = rmnet_ipa_ap_resume, |
| 2638 | }; |
| 2639 | |
| 2640 | static struct platform_driver rmnet_ipa_driver = { |
| 2641 | .driver = { |
| 2642 | .name = "rmnet_ipa3", |
| 2643 | .owner = THIS_MODULE, |
| 2644 | .pm = &rmnet_ipa_pm_ops, |
| 2645 | .of_match_table = rmnet_ipa_dt_match, |
| 2646 | }, |
| 2647 | .probe = ipa3_wwan_probe, |
| 2648 | .remove = ipa3_wwan_remove, |
| 2649 | }; |
| 2650 | |
Skylar Chang | 09e0e25 | 2017-03-20 14:51:29 -0700 | [diff] [blame] | 2651 | /** |
| 2652 | * rmnet_ipa_send_ssr_notification(bool ssr_done) - send SSR notification |
| 2653 | * |
| 2654 | * This function sends the SSR notification before modem shutdown and |
| 2655 | * after_powerup from SSR framework, to user-space module |
| 2656 | */ |
| 2657 | static void rmnet_ipa_send_ssr_notification(bool ssr_done) |
| 2658 | { |
| 2659 | struct ipa_msg_meta msg_meta; |
| 2660 | int rc; |
| 2661 | |
| 2662 | memset(&msg_meta, 0, sizeof(struct ipa_msg_meta)); |
| 2663 | if (ssr_done) |
| 2664 | msg_meta.msg_type = IPA_SSR_AFTER_POWERUP; |
| 2665 | else |
| 2666 | msg_meta.msg_type = IPA_SSR_BEFORE_SHUTDOWN; |
| 2667 | rc = ipa_send_msg(&msg_meta, NULL, NULL); |
| 2668 | if (rc) { |
| 2669 | IPAWANERR("ipa_send_msg failed: %d\n", rc); |
| 2670 | return; |
| 2671 | } |
| 2672 | } |
| 2673 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2674 | static int ipa3_ssr_notifier_cb(struct notifier_block *this, |
| 2675 | unsigned long code, |
| 2676 | void *data) |
| 2677 | { |
| 2678 | if (!ipa3_rmnet_ctx.ipa_rmnet_ssr) |
| 2679 | return NOTIFY_DONE; |
| 2680 | |
| 2681 | switch (code) { |
| 2682 | case SUBSYS_BEFORE_SHUTDOWN: |
| 2683 | IPAWANINFO("IPA received MPSS BEFORE_SHUTDOWN\n"); |
Skylar Chang | 09e0e25 | 2017-03-20 14:51:29 -0700 | [diff] [blame] | 2684 | /* send SSR before-shutdown notification to IPACM */ |
| 2685 | rmnet_ipa_send_ssr_notification(false); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2686 | atomic_set(&rmnet_ipa3_ctx->is_ssr, 1); |
| 2687 | ipa3_q6_pre_shutdown_cleanup(); |
| 2688 | if (IPA_NETDEV()) |
| 2689 | netif_stop_queue(IPA_NETDEV()); |
| 2690 | ipa3_qmi_stop_workqueues(); |
| 2691 | ipa3_wan_ioctl_stop_qmi_messages(); |
| 2692 | ipa_stop_polling_stats(); |
| 2693 | if (atomic_read(&rmnet_ipa3_ctx->is_initialized)) |
| 2694 | platform_driver_unregister(&rmnet_ipa_driver); |
| 2695 | IPAWANINFO("IPA BEFORE_SHUTDOWN handling is complete\n"); |
| 2696 | break; |
| 2697 | case SUBSYS_AFTER_SHUTDOWN: |
| 2698 | IPAWANINFO("IPA Received MPSS AFTER_SHUTDOWN\n"); |
| 2699 | if (atomic_read(&rmnet_ipa3_ctx->is_ssr)) |
| 2700 | ipa3_q6_post_shutdown_cleanup(); |
| 2701 | IPAWANINFO("IPA AFTER_SHUTDOWN handling is complete\n"); |
| 2702 | break; |
| 2703 | case SUBSYS_BEFORE_POWERUP: |
| 2704 | IPAWANINFO("IPA received MPSS BEFORE_POWERUP\n"); |
| 2705 | if (atomic_read(&rmnet_ipa3_ctx->is_ssr)) |
| 2706 | /* clean up cached QMI msg/handlers */ |
| 2707 | ipa3_qmi_service_exit(); |
| 2708 | /*hold a proxy vote for the modem*/ |
| 2709 | ipa3_proxy_clk_vote(); |
Skylar Chang | e120994 | 2017-02-02 14:26:38 -0800 | [diff] [blame] | 2710 | ipa3_reset_freeze_vote(); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2711 | IPAWANINFO("IPA BEFORE_POWERUP handling is complete\n"); |
| 2712 | break; |
| 2713 | case SUBSYS_AFTER_POWERUP: |
| 2714 | IPAWANINFO("%s:%d IPA received MPSS AFTER_POWERUP\n", |
| 2715 | __func__, __LINE__); |
| 2716 | if (!atomic_read(&rmnet_ipa3_ctx->is_initialized) && |
| 2717 | atomic_read(&rmnet_ipa3_ctx->is_ssr)) |
| 2718 | platform_driver_register(&rmnet_ipa_driver); |
| 2719 | |
| 2720 | IPAWANINFO("IPA AFTER_POWERUP handling is complete\n"); |
| 2721 | break; |
| 2722 | default: |
| 2723 | IPAWANDBG("Unsupported subsys notification, IPA received: %lu", |
| 2724 | code); |
| 2725 | break; |
| 2726 | } |
| 2727 | |
| 2728 | IPAWANDBG_LOW("Exit\n"); |
| 2729 | return NOTIFY_DONE; |
| 2730 | } |
| 2731 | |
| 2732 | /** |
| 2733 | * rmnet_ipa_free_msg() - Free the msg sent to user space via ipa_send_msg |
| 2734 | * @buff: pointer to buffer containing the message |
| 2735 | * @len: message len |
| 2736 | * @type: message type |
| 2737 | * |
| 2738 | * This function is invoked when ipa_send_msg is complete (Provided as a |
| 2739 | * free function pointer along with the message). |
| 2740 | */ |
| 2741 | static void rmnet_ipa_free_msg(void *buff, u32 len, u32 type) |
| 2742 | { |
| 2743 | if (!buff) { |
| 2744 | IPAWANERR("Null buffer\n"); |
| 2745 | return; |
| 2746 | } |
| 2747 | |
| 2748 | if (type != IPA_TETHERING_STATS_UPDATE_STATS && |
Mohammed Javid | d0c2a1e | 2017-10-30 15:34:22 +0530 | [diff] [blame] | 2749 | type != IPA_TETHERING_STATS_UPDATE_NETWORK_STATS && |
| 2750 | type != IPA_PER_CLIENT_STATS_CONNECT_EVENT && |
| 2751 | type != IPA_PER_CLIENT_STATS_DISCONNECT_EVENT) { |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2752 | IPAWANERR("Wrong type given. buff %p type %d\n", |
Mohammed Javid | d0c2a1e | 2017-10-30 15:34:22 +0530 | [diff] [blame] | 2753 | buff, type); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2754 | } |
| 2755 | kfree(buff); |
| 2756 | } |
| 2757 | |
| 2758 | /** |
| 2759 | * rmnet_ipa_get_stats_and_update() - Gets pipe stats from Modem |
| 2760 | * |
| 2761 | * This function queries the IPA Modem driver for the pipe stats |
| 2762 | * via QMI, and updates the user space IPA entity. |
| 2763 | */ |
| 2764 | static void rmnet_ipa_get_stats_and_update(void) |
| 2765 | { |
| 2766 | struct ipa_get_data_stats_req_msg_v01 req; |
| 2767 | struct ipa_get_data_stats_resp_msg_v01 *resp; |
| 2768 | struct ipa_msg_meta msg_meta; |
| 2769 | int rc; |
| 2770 | |
| 2771 | resp = kzalloc(sizeof(struct ipa_get_data_stats_resp_msg_v01), |
| 2772 | GFP_KERNEL); |
| 2773 | if (!resp) { |
| 2774 | IPAWANERR("Can't allocate memory for stats message\n"); |
| 2775 | return; |
| 2776 | } |
| 2777 | |
| 2778 | memset(&req, 0, sizeof(struct ipa_get_data_stats_req_msg_v01)); |
| 2779 | memset(resp, 0, sizeof(struct ipa_get_data_stats_resp_msg_v01)); |
| 2780 | |
| 2781 | req.ipa_stats_type = QMI_IPA_STATS_TYPE_PIPE_V01; |
| 2782 | |
| 2783 | rc = ipa3_qmi_get_data_stats(&req, resp); |
Gidon Studinski | 3021a6f | 2016-11-10 12:48:48 +0200 | [diff] [blame] | 2784 | if (rc) { |
| 2785 | IPAWANERR("ipa3_qmi_get_data_stats failed: %d\n", rc); |
| 2786 | kfree(resp); |
| 2787 | return; |
| 2788 | } |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2789 | |
Gidon Studinski | 3021a6f | 2016-11-10 12:48:48 +0200 | [diff] [blame] | 2790 | memset(&msg_meta, 0, sizeof(struct ipa_msg_meta)); |
| 2791 | msg_meta.msg_type = IPA_TETHERING_STATS_UPDATE_STATS; |
| 2792 | msg_meta.msg_len = sizeof(struct ipa_get_data_stats_resp_msg_v01); |
| 2793 | rc = ipa_send_msg(&msg_meta, resp, rmnet_ipa_free_msg); |
| 2794 | if (rc) { |
| 2795 | IPAWANERR("ipa_send_msg failed: %d\n", rc); |
| 2796 | kfree(resp); |
| 2797 | return; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2798 | } |
| 2799 | } |
| 2800 | |
| 2801 | /** |
| 2802 | * tethering_stats_poll_queue() - Stats polling function |
| 2803 | * @work - Work entry |
| 2804 | * |
| 2805 | * This function is scheduled periodically (per the interval) in |
| 2806 | * order to poll the IPA Modem driver for the pipe stats. |
| 2807 | */ |
| 2808 | static void tethering_stats_poll_queue(struct work_struct *work) |
| 2809 | { |
| 2810 | rmnet_ipa_get_stats_and_update(); |
| 2811 | |
| 2812 | /* Schedule again only if there's an active polling interval */ |
| 2813 | if (ipa3_rmnet_ctx.polling_interval != 0) |
| 2814 | schedule_delayed_work(&ipa_tether_stats_poll_wakequeue_work, |
| 2815 | msecs_to_jiffies(ipa3_rmnet_ctx.polling_interval*1000)); |
| 2816 | } |
| 2817 | |
| 2818 | /** |
| 2819 | * rmnet_ipa_get_network_stats_and_update() - Get network stats from IPA Modem |
| 2820 | * |
| 2821 | * This function retrieves the data usage (used quota) from the IPA Modem driver |
| 2822 | * via QMI, and updates IPA user space entity. |
| 2823 | */ |
| 2824 | static void rmnet_ipa_get_network_stats_and_update(void) |
| 2825 | { |
| 2826 | struct ipa_get_apn_data_stats_req_msg_v01 req; |
| 2827 | struct ipa_get_apn_data_stats_resp_msg_v01 *resp; |
| 2828 | struct ipa_msg_meta msg_meta; |
| 2829 | int rc; |
| 2830 | |
| 2831 | resp = kzalloc(sizeof(struct ipa_get_apn_data_stats_resp_msg_v01), |
| 2832 | GFP_KERNEL); |
| 2833 | if (!resp) { |
| 2834 | IPAWANERR("Can't allocate memory for network stats message\n"); |
| 2835 | return; |
| 2836 | } |
| 2837 | |
| 2838 | memset(&req, 0, sizeof(struct ipa_get_apn_data_stats_req_msg_v01)); |
| 2839 | memset(resp, 0, sizeof(struct ipa_get_apn_data_stats_resp_msg_v01)); |
| 2840 | |
| 2841 | req.mux_id_list_valid = true; |
| 2842 | req.mux_id_list_len = 1; |
| 2843 | req.mux_id_list[0] = ipa3_rmnet_ctx.metered_mux_id; |
| 2844 | |
| 2845 | rc = ipa3_qmi_get_network_stats(&req, resp); |
Gidon Studinski | 3021a6f | 2016-11-10 12:48:48 +0200 | [diff] [blame] | 2846 | if (rc) { |
| 2847 | IPAWANERR("ipa3_qmi_get_network_stats failed: %d\n", rc); |
| 2848 | kfree(resp); |
| 2849 | return; |
| 2850 | } |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2851 | |
Gidon Studinski | 3021a6f | 2016-11-10 12:48:48 +0200 | [diff] [blame] | 2852 | memset(&msg_meta, 0, sizeof(struct ipa_msg_meta)); |
| 2853 | msg_meta.msg_type = IPA_TETHERING_STATS_UPDATE_NETWORK_STATS; |
| 2854 | msg_meta.msg_len = sizeof(struct ipa_get_apn_data_stats_resp_msg_v01); |
| 2855 | rc = ipa_send_msg(&msg_meta, resp, rmnet_ipa_free_msg); |
| 2856 | if (rc) { |
| 2857 | IPAWANERR("ipa_send_msg failed: %d\n", rc); |
| 2858 | kfree(resp); |
| 2859 | return; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | /** |
Skylar Chang | 09e0e25 | 2017-03-20 14:51:29 -0700 | [diff] [blame] | 2864 | * rmnet_ipa_send_quota_reach_ind() - send quota_reach notification from |
| 2865 | * IPA Modem |
| 2866 | * This function sends the quota_reach indication from the IPA Modem driver |
| 2867 | * via QMI, to user-space module |
| 2868 | */ |
| 2869 | static void rmnet_ipa_send_quota_reach_ind(void) |
| 2870 | { |
| 2871 | struct ipa_msg_meta msg_meta; |
| 2872 | int rc; |
| 2873 | |
| 2874 | memset(&msg_meta, 0, sizeof(struct ipa_msg_meta)); |
| 2875 | msg_meta.msg_type = IPA_QUOTA_REACH; |
| 2876 | rc = ipa_send_msg(&msg_meta, NULL, NULL); |
| 2877 | if (rc) { |
| 2878 | IPAWANERR("ipa_send_msg failed: %d\n", rc); |
| 2879 | return; |
| 2880 | } |
| 2881 | } |
| 2882 | |
| 2883 | /** |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2884 | * rmnet_ipa3_poll_tethering_stats() - Tethering stats polling IOCTL handler |
| 2885 | * @data - IOCTL data |
| 2886 | * |
| 2887 | * This function handles WAN_IOC_POLL_TETHERING_STATS. |
| 2888 | * In case polling interval received is 0, polling will stop |
| 2889 | * (If there's a polling in progress, it will allow it to finish), and then will |
| 2890 | * fetch network stats, and update the IPA user space. |
| 2891 | * |
| 2892 | * Return codes: |
| 2893 | * 0: Success |
| 2894 | */ |
| 2895 | int rmnet_ipa3_poll_tethering_stats(struct wan_ioctl_poll_tethering_stats *data) |
| 2896 | { |
| 2897 | ipa3_rmnet_ctx.polling_interval = data->polling_interval_secs; |
| 2898 | |
| 2899 | cancel_delayed_work_sync(&ipa_tether_stats_poll_wakequeue_work); |
| 2900 | |
| 2901 | if (ipa3_rmnet_ctx.polling_interval == 0) { |
| 2902 | ipa3_qmi_stop_data_qouta(); |
| 2903 | rmnet_ipa_get_network_stats_and_update(); |
| 2904 | rmnet_ipa_get_stats_and_update(); |
| 2905 | return 0; |
| 2906 | } |
| 2907 | |
| 2908 | schedule_delayed_work(&ipa_tether_stats_poll_wakequeue_work, 0); |
| 2909 | return 0; |
| 2910 | } |
| 2911 | |
| 2912 | /** |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 2913 | * rmnet_ipa_set_data_quota_modem() - Data quota setting IOCTL handler |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2914 | * @data - IOCTL data |
| 2915 | * |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 2916 | * This function handles WAN_IOC_SET_DATA_QUOTA on modem interface. |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2917 | * It translates the given interface name to the Modem MUX ID and |
| 2918 | * sends the request of the quota to the IPA Modem driver via QMI. |
| 2919 | * |
| 2920 | * Return codes: |
| 2921 | * 0: Success |
| 2922 | * -EFAULT: Invalid interface name provided |
| 2923 | * other: See ipa_qmi_set_data_quota |
| 2924 | */ |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 2925 | static int rmnet_ipa3_set_data_quota_modem( |
| 2926 | struct wan_ioctl_set_data_quota *data) |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2927 | { |
| 2928 | u32 mux_id; |
| 2929 | int index; |
| 2930 | struct ipa_set_data_usage_quota_req_msg_v01 req; |
| 2931 | |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 2932 | /* stop quota */ |
| 2933 | if (!data->set_quota) |
| 2934 | ipa3_qmi_stop_data_qouta(); |
| 2935 | |
Skylar Chang | cde17ed | 2017-06-21 16:51:26 -0700 | [diff] [blame] | 2936 | /* prevent string buffer overflows */ |
| 2937 | data->interface_name[IFNAMSIZ-1] = '\0'; |
| 2938 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 2939 | index = find_vchannel_name_index(data->interface_name); |
| 2940 | IPAWANERR("iface name %s, quota %lu\n", |
| 2941 | data->interface_name, |
| 2942 | (unsigned long int) data->quota_mbytes); |
| 2943 | |
| 2944 | if (index == MAX_NUM_OF_MUX_CHANNEL) { |
| 2945 | IPAWANERR("%s is an invalid iface name\n", |
| 2946 | data->interface_name); |
| 2947 | return -EFAULT; |
| 2948 | } |
| 2949 | |
| 2950 | mux_id = rmnet_ipa3_ctx->mux_channel[index].mux_id; |
| 2951 | ipa3_rmnet_ctx.metered_mux_id = mux_id; |
| 2952 | |
| 2953 | memset(&req, 0, sizeof(struct ipa_set_data_usage_quota_req_msg_v01)); |
| 2954 | req.apn_quota_list_valid = true; |
| 2955 | req.apn_quota_list_len = 1; |
| 2956 | req.apn_quota_list[0].mux_id = mux_id; |
| 2957 | req.apn_quota_list[0].num_Mbytes = data->quota_mbytes; |
| 2958 | |
| 2959 | return ipa3_qmi_set_data_quota(&req); |
| 2960 | } |
| 2961 | |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 2962 | static int rmnet_ipa3_set_data_quota_wifi(struct wan_ioctl_set_data_quota *data) |
| 2963 | { |
| 2964 | struct ipa_set_wifi_quota wifi_quota; |
| 2965 | int rc = 0; |
| 2966 | |
| 2967 | memset(&wifi_quota, 0, sizeof(struct ipa_set_wifi_quota)); |
| 2968 | wifi_quota.set_quota = data->set_quota; |
| 2969 | wifi_quota.quota_bytes = data->quota_mbytes; |
| 2970 | IPAWANERR("iface name %s, quota %lu\n", |
| 2971 | data->interface_name, |
| 2972 | (unsigned long int) data->quota_mbytes); |
| 2973 | |
| 2974 | rc = ipa3_set_wlan_quota(&wifi_quota); |
| 2975 | /* check if wlan-fw takes this quota-set */ |
| 2976 | if (!wifi_quota.set_valid) |
| 2977 | rc = -EFAULT; |
| 2978 | return rc; |
| 2979 | } |
| 2980 | |
| 2981 | /** |
| 2982 | * rmnet_ipa_set_data_quota() - Data quota setting IOCTL handler |
| 2983 | * @data - IOCTL data |
| 2984 | * |
| 2985 | * This function handles WAN_IOC_SET_DATA_QUOTA. |
| 2986 | * It translates the given interface name to the Modem MUX ID and |
| 2987 | * sends the request of the quota to the IPA Modem driver via QMI. |
| 2988 | * |
| 2989 | * Return codes: |
| 2990 | * 0: Success |
| 2991 | * -EFAULT: Invalid interface name provided |
| 2992 | * other: See ipa_qmi_set_data_quota |
| 2993 | */ |
| 2994 | int rmnet_ipa3_set_data_quota(struct wan_ioctl_set_data_quota *data) |
| 2995 | { |
| 2996 | enum ipa_upstream_type upstream_type; |
| 2997 | int rc = 0; |
| 2998 | |
Mohammed Javid | bba17b3 | 2017-09-26 12:51:14 +0530 | [diff] [blame] | 2999 | /* prevent string buffer overflows */ |
| 3000 | data->interface_name[IFNAMSIZ-1] = '\0'; |
| 3001 | |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3002 | /* get IPA backhaul type */ |
| 3003 | upstream_type = find_upstream_type(data->interface_name); |
| 3004 | |
| 3005 | if (upstream_type == IPA_UPSTEAM_MAX) { |
| 3006 | IPAWANERR("Wrong interface_name name %s\n", |
| 3007 | data->interface_name); |
| 3008 | } else if (upstream_type == IPA_UPSTEAM_WLAN) { |
| 3009 | rc = rmnet_ipa3_set_data_quota_wifi(data); |
| 3010 | if (rc) { |
| 3011 | IPAWANERR("set quota on wifi failed\n"); |
| 3012 | return rc; |
| 3013 | } |
| 3014 | } else { |
| 3015 | rc = rmnet_ipa3_set_data_quota_modem(data); |
| 3016 | if (rc) { |
| 3017 | IPAWANERR("set quota on modem failed\n"); |
| 3018 | return rc; |
| 3019 | } |
| 3020 | } |
| 3021 | return rc; |
| 3022 | } |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3023 | /* rmnet_ipa_set_tether_client_pipe() - |
| 3024 | * @data - IOCTL data |
| 3025 | * |
| 3026 | * This function handles WAN_IOC_SET_DATA_QUOTA. |
| 3027 | * It translates the given interface name to the Modem MUX ID and |
| 3028 | * sends the request of the quota to the IPA Modem driver via QMI. |
| 3029 | * |
| 3030 | * Return codes: |
| 3031 | * 0: Success |
| 3032 | * -EFAULT: Invalid interface name provided |
| 3033 | * other: See ipa_qmi_set_data_quota |
| 3034 | */ |
| 3035 | int rmnet_ipa3_set_tether_client_pipe( |
| 3036 | struct wan_ioctl_set_tether_client_pipe *data) |
| 3037 | { |
| 3038 | int number, i; |
| 3039 | |
Skylar Chang | 345c814 | 2016-11-30 14:41:24 -0800 | [diff] [blame] | 3040 | /* error checking if ul_src_pipe_len valid or not*/ |
| 3041 | if (data->ul_src_pipe_len > QMI_IPA_MAX_PIPES_V01 || |
| 3042 | data->ul_src_pipe_len < 0) { |
| 3043 | IPAWANERR("UL src pipes %d exceeding max %d\n", |
| 3044 | data->ul_src_pipe_len, |
| 3045 | QMI_IPA_MAX_PIPES_V01); |
| 3046 | return -EFAULT; |
| 3047 | } |
| 3048 | /* error checking if dl_dst_pipe_len valid or not*/ |
| 3049 | if (data->dl_dst_pipe_len > QMI_IPA_MAX_PIPES_V01 || |
| 3050 | data->dl_dst_pipe_len < 0) { |
| 3051 | IPAWANERR("DL dst pipes %d exceeding max %d\n", |
| 3052 | data->dl_dst_pipe_len, |
| 3053 | QMI_IPA_MAX_PIPES_V01); |
| 3054 | return -EFAULT; |
| 3055 | } |
| 3056 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3057 | IPAWANDBG("client %d, UL %d, DL %d, reset %d\n", |
| 3058 | data->ipa_client, |
| 3059 | data->ul_src_pipe_len, |
| 3060 | data->dl_dst_pipe_len, |
| 3061 | data->reset_client); |
| 3062 | number = data->ul_src_pipe_len; |
| 3063 | for (i = 0; i < number; i++) { |
| 3064 | IPAWANDBG("UL index-%d pipe %d\n", i, |
| 3065 | data->ul_src_pipe_list[i]); |
| 3066 | if (data->reset_client) |
| 3067 | ipa3_set_client(data->ul_src_pipe_list[i], |
| 3068 | 0, false); |
| 3069 | else |
| 3070 | ipa3_set_client(data->ul_src_pipe_list[i], |
| 3071 | data->ipa_client, true); |
| 3072 | } |
| 3073 | number = data->dl_dst_pipe_len; |
| 3074 | for (i = 0; i < number; i++) { |
| 3075 | IPAWANDBG("DL index-%d pipe %d\n", i, |
| 3076 | data->dl_dst_pipe_list[i]); |
| 3077 | if (data->reset_client) |
| 3078 | ipa3_set_client(data->dl_dst_pipe_list[i], |
| 3079 | 0, false); |
| 3080 | else |
| 3081 | ipa3_set_client(data->dl_dst_pipe_list[i], |
| 3082 | data->ipa_client, false); |
| 3083 | } |
| 3084 | return 0; |
| 3085 | } |
| 3086 | |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3087 | static int rmnet_ipa3_query_tethering_stats_wifi( |
| 3088 | struct wan_ioctl_query_tether_stats *data, bool reset) |
| 3089 | { |
| 3090 | struct ipa_get_wdi_sap_stats *sap_stats; |
| 3091 | int rc; |
| 3092 | |
| 3093 | sap_stats = kzalloc(sizeof(struct ipa_get_wdi_sap_stats), |
| 3094 | GFP_KERNEL); |
| 3095 | if (!sap_stats) { |
| 3096 | IPAWANERR("Can't allocate memory for stats message\n"); |
| 3097 | return -ENOMEM; |
| 3098 | } |
| 3099 | memset(sap_stats, 0, sizeof(struct ipa_get_wdi_sap_stats)); |
| 3100 | |
| 3101 | sap_stats->reset_stats = reset; |
| 3102 | IPAWANDBG("reset the pipe stats %d\n", sap_stats->reset_stats); |
| 3103 | |
| 3104 | rc = ipa3_get_wlan_stats(sap_stats); |
| 3105 | if (rc) { |
| 3106 | IPAWANERR("can't get ipa3_get_wlan_stats\n"); |
| 3107 | kfree(sap_stats); |
| 3108 | return rc; |
| 3109 | } else if (reset) { |
| 3110 | kfree(sap_stats); |
| 3111 | return 0; |
| 3112 | } |
| 3113 | |
| 3114 | if (sap_stats->stats_valid) { |
| 3115 | data->ipv4_tx_packets = sap_stats->ipv4_tx_packets; |
| 3116 | data->ipv4_tx_bytes = sap_stats->ipv4_tx_bytes; |
| 3117 | data->ipv4_rx_packets = sap_stats->ipv4_rx_packets; |
| 3118 | data->ipv4_rx_bytes = sap_stats->ipv4_rx_bytes; |
| 3119 | data->ipv6_tx_packets = sap_stats->ipv6_tx_packets; |
| 3120 | data->ipv6_tx_bytes = sap_stats->ipv6_tx_bytes; |
| 3121 | data->ipv6_rx_packets = sap_stats->ipv6_rx_packets; |
| 3122 | data->ipv6_rx_bytes = sap_stats->ipv6_rx_bytes; |
| 3123 | } |
| 3124 | |
| 3125 | IPAWANDBG("v4_rx_p(%lu) v6_rx_p(%lu) v4_rx_b(%lu) v6_rx_b(%lu)\n", |
| 3126 | (unsigned long int) data->ipv4_rx_packets, |
| 3127 | (unsigned long int) data->ipv6_rx_packets, |
| 3128 | (unsigned long int) data->ipv4_rx_bytes, |
| 3129 | (unsigned long int) data->ipv6_rx_bytes); |
| 3130 | IPAWANDBG("tx_p_v4(%lu)v6(%lu)tx_b_v4(%lu) v6(%lu)\n", |
| 3131 | (unsigned long int) data->ipv4_tx_packets, |
| 3132 | (unsigned long int) data->ipv6_tx_packets, |
| 3133 | (unsigned long int) data->ipv4_tx_bytes, |
| 3134 | (unsigned long int) data->ipv6_tx_bytes); |
| 3135 | |
| 3136 | kfree(sap_stats); |
| 3137 | return rc; |
| 3138 | } |
| 3139 | |
| 3140 | static int rmnet_ipa3_query_tethering_stats_modem( |
| 3141 | struct wan_ioctl_query_tether_stats *data, bool reset) |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3142 | { |
| 3143 | struct ipa_get_data_stats_req_msg_v01 *req; |
| 3144 | struct ipa_get_data_stats_resp_msg_v01 *resp; |
| 3145 | int pipe_len, rc; |
| 3146 | |
| 3147 | req = kzalloc(sizeof(struct ipa_get_data_stats_req_msg_v01), |
| 3148 | GFP_KERNEL); |
| 3149 | if (!req) { |
| 3150 | IPAWANERR("Can't allocate memory for stats message\n"); |
| 3151 | return -ENOMEM; |
| 3152 | } |
| 3153 | resp = kzalloc(sizeof(struct ipa_get_data_stats_resp_msg_v01), |
| 3154 | GFP_KERNEL); |
| 3155 | if (!resp) { |
| 3156 | IPAWANERR("Can't allocate memory for stats message\n"); |
| 3157 | kfree(req); |
| 3158 | return -ENOMEM; |
| 3159 | } |
| 3160 | memset(req, 0, sizeof(struct ipa_get_data_stats_req_msg_v01)); |
| 3161 | memset(resp, 0, sizeof(struct ipa_get_data_stats_resp_msg_v01)); |
| 3162 | |
| 3163 | req->ipa_stats_type = QMI_IPA_STATS_TYPE_PIPE_V01; |
| 3164 | if (reset) { |
| 3165 | req->reset_stats_valid = true; |
| 3166 | req->reset_stats = true; |
| 3167 | IPAWANERR("reset the pipe stats\n"); |
| 3168 | } else { |
| 3169 | /* print tethered-client enum */ |
Skylar Chang | 09e0e25 | 2017-03-20 14:51:29 -0700 | [diff] [blame] | 3170 | IPAWANDBG("Tethered-client enum(%d)\n", data->ipa_client); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3171 | } |
| 3172 | |
| 3173 | rc = ipa3_qmi_get_data_stats(req, resp); |
| 3174 | if (rc) { |
| 3175 | IPAWANERR("can't get ipa_qmi_get_data_stats\n"); |
| 3176 | kfree(req); |
| 3177 | kfree(resp); |
| 3178 | return rc; |
Mohammed Javid | 2cee34a | 2017-06-14 12:40:34 +0530 | [diff] [blame] | 3179 | } else if (data == NULL) { |
| 3180 | kfree(req); |
| 3181 | kfree(resp); |
| 3182 | return 0; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3183 | } |
| 3184 | |
| 3185 | if (resp->dl_dst_pipe_stats_list_valid) { |
| 3186 | for (pipe_len = 0; pipe_len < resp->dl_dst_pipe_stats_list_len; |
| 3187 | pipe_len++) { |
| 3188 | IPAWANDBG_LOW("Check entry(%d) dl_dst_pipe(%d)\n", |
| 3189 | pipe_len, resp->dl_dst_pipe_stats_list |
| 3190 | [pipe_len].pipe_index); |
| 3191 | IPAWANDBG_LOW("dl_p_v4(%lu)v6(%lu)\n", |
| 3192 | (unsigned long int) resp-> |
| 3193 | dl_dst_pipe_stats_list[pipe_len]. |
| 3194 | num_ipv4_packets, |
| 3195 | (unsigned long int) resp-> |
| 3196 | dl_dst_pipe_stats_list[pipe_len]. |
| 3197 | num_ipv6_packets); |
| 3198 | IPAWANDBG_LOW("dl_b_v4(%lu)v6(%lu)\n", |
| 3199 | (unsigned long int) resp-> |
| 3200 | dl_dst_pipe_stats_list[pipe_len]. |
| 3201 | num_ipv4_bytes, |
| 3202 | (unsigned long int) resp-> |
| 3203 | dl_dst_pipe_stats_list[pipe_len]. |
| 3204 | num_ipv6_bytes); |
| 3205 | if (ipa_get_client_uplink(resp-> |
| 3206 | dl_dst_pipe_stats_list[pipe_len]. |
| 3207 | pipe_index) == false) { |
| 3208 | if (data->ipa_client == ipa_get_client(resp-> |
| 3209 | dl_dst_pipe_stats_list[pipe_len]. |
| 3210 | pipe_index)) { |
| 3211 | /* update the DL stats */ |
| 3212 | data->ipv4_rx_packets += resp-> |
| 3213 | dl_dst_pipe_stats_list[pipe_len]. |
| 3214 | num_ipv4_packets; |
| 3215 | data->ipv6_rx_packets += resp-> |
| 3216 | dl_dst_pipe_stats_list[pipe_len]. |
| 3217 | num_ipv6_packets; |
| 3218 | data->ipv4_rx_bytes += resp-> |
| 3219 | dl_dst_pipe_stats_list[pipe_len]. |
| 3220 | num_ipv4_bytes; |
| 3221 | data->ipv6_rx_bytes += resp-> |
| 3222 | dl_dst_pipe_stats_list[pipe_len]. |
| 3223 | num_ipv6_bytes; |
| 3224 | } |
| 3225 | } |
| 3226 | } |
| 3227 | } |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3228 | IPAWANDBG("v4_rx_p(%lu) v6_rx_p(%lu) v4_rx_b(%lu) v6_rx_b(%lu)\n", |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3229 | (unsigned long int) data->ipv4_rx_packets, |
| 3230 | (unsigned long int) data->ipv6_rx_packets, |
| 3231 | (unsigned long int) data->ipv4_rx_bytes, |
| 3232 | (unsigned long int) data->ipv6_rx_bytes); |
| 3233 | |
| 3234 | if (resp->ul_src_pipe_stats_list_valid) { |
| 3235 | for (pipe_len = 0; pipe_len < resp->ul_src_pipe_stats_list_len; |
| 3236 | pipe_len++) { |
| 3237 | IPAWANDBG_LOW("Check entry(%d) ul_dst_pipe(%d)\n", |
| 3238 | pipe_len, |
| 3239 | resp->ul_src_pipe_stats_list[pipe_len]. |
| 3240 | pipe_index); |
| 3241 | IPAWANDBG_LOW("ul_p_v4(%lu)v6(%lu)\n", |
| 3242 | (unsigned long int) resp-> |
| 3243 | ul_src_pipe_stats_list[pipe_len]. |
| 3244 | num_ipv4_packets, |
| 3245 | (unsigned long int) resp-> |
| 3246 | ul_src_pipe_stats_list[pipe_len]. |
| 3247 | num_ipv6_packets); |
| 3248 | IPAWANDBG_LOW("ul_b_v4(%lu)v6(%lu)\n", |
| 3249 | (unsigned long int) resp-> |
| 3250 | ul_src_pipe_stats_list[pipe_len]. |
| 3251 | num_ipv4_bytes, |
| 3252 | (unsigned long int) resp-> |
| 3253 | ul_src_pipe_stats_list[pipe_len]. |
| 3254 | num_ipv6_bytes); |
| 3255 | if (ipa_get_client_uplink(resp-> |
| 3256 | ul_src_pipe_stats_list[pipe_len]. |
| 3257 | pipe_index) == true) { |
| 3258 | if (data->ipa_client == ipa_get_client(resp-> |
| 3259 | ul_src_pipe_stats_list[pipe_len]. |
| 3260 | pipe_index)) { |
| 3261 | /* update the DL stats */ |
| 3262 | data->ipv4_tx_packets += resp-> |
| 3263 | ul_src_pipe_stats_list[pipe_len]. |
| 3264 | num_ipv4_packets; |
| 3265 | data->ipv6_tx_packets += resp-> |
| 3266 | ul_src_pipe_stats_list[pipe_len]. |
| 3267 | num_ipv6_packets; |
| 3268 | data->ipv4_tx_bytes += resp-> |
| 3269 | ul_src_pipe_stats_list[pipe_len]. |
| 3270 | num_ipv4_bytes; |
| 3271 | data->ipv6_tx_bytes += resp-> |
| 3272 | ul_src_pipe_stats_list[pipe_len]. |
| 3273 | num_ipv6_bytes; |
| 3274 | } |
| 3275 | } |
| 3276 | } |
| 3277 | } |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3278 | IPAWANDBG("tx_p_v4(%lu)v6(%lu)tx_b_v4(%lu) v6(%lu)\n", |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3279 | (unsigned long int) data->ipv4_tx_packets, |
| 3280 | (unsigned long int) data->ipv6_tx_packets, |
| 3281 | (unsigned long int) data->ipv4_tx_bytes, |
| 3282 | (unsigned long int) data->ipv6_tx_bytes); |
| 3283 | kfree(req); |
| 3284 | kfree(resp); |
| 3285 | return 0; |
| 3286 | } |
| 3287 | |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3288 | int rmnet_ipa3_query_tethering_stats(struct wan_ioctl_query_tether_stats *data, |
| 3289 | bool reset) |
| 3290 | { |
| 3291 | enum ipa_upstream_type upstream_type; |
| 3292 | int rc = 0; |
| 3293 | |
Mohammed Javid | bba17b3 | 2017-09-26 12:51:14 +0530 | [diff] [blame] | 3294 | /* prevent string buffer overflows */ |
| 3295 | data->upstreamIface[IFNAMSIZ-1] = '\0'; |
| 3296 | data->tetherIface[IFNAMSIZ-1] = '\0'; |
| 3297 | |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3298 | /* get IPA backhaul type */ |
| 3299 | upstream_type = find_upstream_type(data->upstreamIface); |
| 3300 | |
| 3301 | if (upstream_type == IPA_UPSTEAM_MAX) { |
| 3302 | IPAWANERR(" Wrong upstreamIface name %s\n", |
| 3303 | data->upstreamIface); |
| 3304 | } else if (upstream_type == IPA_UPSTEAM_WLAN) { |
| 3305 | IPAWANDBG_LOW(" query wifi-backhaul stats\n"); |
| 3306 | rc = rmnet_ipa3_query_tethering_stats_wifi( |
| 3307 | data, false); |
| 3308 | if (rc) { |
| 3309 | IPAWANERR("wlan WAN_IOC_QUERY_TETHER_STATS failed\n"); |
| 3310 | return rc; |
| 3311 | } |
| 3312 | } else { |
| 3313 | IPAWANDBG_LOW(" query modem-backhaul stats\n"); |
| 3314 | rc = rmnet_ipa3_query_tethering_stats_modem( |
| 3315 | data, false); |
| 3316 | if (rc) { |
| 3317 | IPAWANERR("modem WAN_IOC_QUERY_TETHER_STATS failed\n"); |
| 3318 | return rc; |
| 3319 | } |
| 3320 | } |
| 3321 | return rc; |
| 3322 | } |
| 3323 | |
Skylar Chang | 09e0e25 | 2017-03-20 14:51:29 -0700 | [diff] [blame] | 3324 | int rmnet_ipa3_query_tethering_stats_all( |
| 3325 | struct wan_ioctl_query_tether_stats_all *data) |
| 3326 | { |
| 3327 | struct wan_ioctl_query_tether_stats tether_stats; |
| 3328 | enum ipa_upstream_type upstream_type; |
| 3329 | int rc = 0; |
| 3330 | |
| 3331 | memset(&tether_stats, 0, sizeof(struct wan_ioctl_query_tether_stats)); |
Mohammed Javid | bba17b3 | 2017-09-26 12:51:14 +0530 | [diff] [blame] | 3332 | |
| 3333 | /* prevent string buffer overflows */ |
| 3334 | data->upstreamIface[IFNAMSIZ-1] = '\0'; |
| 3335 | |
Skylar Chang | 09e0e25 | 2017-03-20 14:51:29 -0700 | [diff] [blame] | 3336 | /* get IPA backhaul type */ |
| 3337 | upstream_type = find_upstream_type(data->upstreamIface); |
| 3338 | |
| 3339 | if (upstream_type == IPA_UPSTEAM_MAX) { |
| 3340 | IPAWANERR(" Wrong upstreamIface name %s\n", |
| 3341 | data->upstreamIface); |
| 3342 | } else if (upstream_type == IPA_UPSTEAM_WLAN) { |
| 3343 | IPAWANDBG_LOW(" query wifi-backhaul stats\n"); |
| 3344 | rc = rmnet_ipa3_query_tethering_stats_wifi( |
| 3345 | &tether_stats, data->reset_stats); |
| 3346 | if (rc) { |
| 3347 | IPAWANERR("wlan WAN_IOC_QUERY_TETHER_STATS failed\n"); |
| 3348 | return rc; |
| 3349 | } |
| 3350 | data->tx_bytes = tether_stats.ipv4_tx_bytes |
| 3351 | + tether_stats.ipv6_tx_bytes; |
| 3352 | data->rx_bytes = tether_stats.ipv4_rx_bytes |
| 3353 | + tether_stats.ipv6_rx_bytes; |
| 3354 | } else { |
| 3355 | IPAWANDBG_LOW(" query modem-backhaul stats\n"); |
| 3356 | tether_stats.ipa_client = data->ipa_client; |
| 3357 | rc = rmnet_ipa3_query_tethering_stats_modem( |
| 3358 | &tether_stats, data->reset_stats); |
| 3359 | if (rc) { |
| 3360 | IPAWANERR("modem WAN_IOC_QUERY_TETHER_STATS failed\n"); |
| 3361 | return rc; |
| 3362 | } |
| 3363 | data->tx_bytes = tether_stats.ipv4_tx_bytes |
| 3364 | + tether_stats.ipv6_tx_bytes; |
| 3365 | data->rx_bytes = tether_stats.ipv4_rx_bytes |
| 3366 | + tether_stats.ipv6_rx_bytes; |
| 3367 | } |
| 3368 | return rc; |
| 3369 | } |
| 3370 | |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3371 | int rmnet_ipa3_reset_tethering_stats(struct wan_ioctl_reset_tether_stats *data) |
| 3372 | { |
| 3373 | enum ipa_upstream_type upstream_type; |
Mohammed Javid | 2cee34a | 2017-06-14 12:40:34 +0530 | [diff] [blame] | 3374 | struct wan_ioctl_query_tether_stats tether_stats; |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3375 | int rc = 0; |
| 3376 | |
Mohammed Javid | 2cee34a | 2017-06-14 12:40:34 +0530 | [diff] [blame] | 3377 | memset(&tether_stats, 0, sizeof(struct wan_ioctl_query_tether_stats)); |
| 3378 | |
Mohammed Javid | bba17b3 | 2017-09-26 12:51:14 +0530 | [diff] [blame] | 3379 | /* prevent string buffer overflows */ |
| 3380 | data->upstreamIface[IFNAMSIZ-1] = '\0'; |
| 3381 | |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3382 | /* get IPA backhaul type */ |
| 3383 | upstream_type = find_upstream_type(data->upstreamIface); |
| 3384 | |
| 3385 | if (upstream_type == IPA_UPSTEAM_MAX) { |
| 3386 | IPAWANERR(" Wrong upstreamIface name %s\n", |
| 3387 | data->upstreamIface); |
| 3388 | } else if (upstream_type == IPA_UPSTEAM_WLAN) { |
| 3389 | IPAWANERR(" reset wifi-backhaul stats\n"); |
| 3390 | rc = rmnet_ipa3_query_tethering_stats_wifi( |
| 3391 | NULL, true); |
| 3392 | if (rc) { |
| 3393 | IPAWANERR("reset WLAN stats failed\n"); |
| 3394 | return rc; |
| 3395 | } |
| 3396 | } else { |
| 3397 | IPAWANERR(" reset modem-backhaul stats\n"); |
| 3398 | rc = rmnet_ipa3_query_tethering_stats_modem( |
Mohammed Javid | 2cee34a | 2017-06-14 12:40:34 +0530 | [diff] [blame] | 3399 | &tether_stats, true); |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3400 | if (rc) { |
| 3401 | IPAWANERR("reset MODEM stats failed\n"); |
| 3402 | return rc; |
| 3403 | } |
| 3404 | } |
| 3405 | return rc; |
| 3406 | } |
| 3407 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3408 | /** |
| 3409 | * ipa3_broadcast_quota_reach_ind() - Send Netlink broadcast on Quota |
| 3410 | * @mux_id - The MUX ID on which the quota has been reached |
| 3411 | * |
| 3412 | * This function broadcasts a Netlink event using the kobject of the |
| 3413 | * rmnet_ipa interface in order to alert the user space that the quota |
| 3414 | * on the specific interface which matches the mux_id has been reached. |
| 3415 | * |
| 3416 | */ |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3417 | void ipa3_broadcast_quota_reach_ind(u32 mux_id, |
| 3418 | enum ipa_upstream_type upstream_type) |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3419 | { |
| 3420 | char alert_msg[IPA_QUOTA_REACH_ALERT_MAX_SIZE]; |
| 3421 | char iface_name_m[IPA_QUOTA_REACH_IF_NAME_MAX_SIZE]; |
| 3422 | char iface_name_l[IPA_QUOTA_REACH_IF_NAME_MAX_SIZE]; |
| 3423 | char *envp[IPA_UEVENT_NUM_EVNP] = { |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3424 | alert_msg, iface_name_l, iface_name_m, NULL}; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3425 | int res; |
| 3426 | int index; |
| 3427 | |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3428 | /* check upstream_type*/ |
| 3429 | if (upstream_type == IPA_UPSTEAM_MAX) { |
| 3430 | IPAWANERR(" Wrong upstreamIface type %d\n", upstream_type); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3431 | return; |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3432 | } else if (upstream_type == IPA_UPSTEAM_MODEM) { |
| 3433 | index = ipa3_find_mux_channel_index(mux_id); |
| 3434 | if (index == MAX_NUM_OF_MUX_CHANNEL) { |
| 3435 | IPAWANERR("%u is an mux ID\n", mux_id); |
| 3436 | return; |
| 3437 | } |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3438 | } |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3439 | res = snprintf(alert_msg, IPA_QUOTA_REACH_ALERT_MAX_SIZE, |
| 3440 | "ALERT_NAME=%s", "quotaReachedAlert"); |
| 3441 | if (res >= IPA_QUOTA_REACH_ALERT_MAX_SIZE) { |
| 3442 | IPAWANERR("message too long (%d)", res); |
| 3443 | return; |
| 3444 | } |
| 3445 | /* posting msg for L-release for CNE */ |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3446 | if (upstream_type == IPA_UPSTEAM_MODEM) { |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3447 | res = snprintf(iface_name_l, IPA_QUOTA_REACH_IF_NAME_MAX_SIZE, |
| 3448 | "UPSTREAM=%s", rmnet_ipa3_ctx->mux_channel[index].vchannel_name); |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3449 | } else { |
| 3450 | res = snprintf(iface_name_l, IPA_QUOTA_REACH_IF_NAME_MAX_SIZE, |
| 3451 | "UPSTREAM=%s", IPA_UPSTEAM_WLAN_IFACE_NAME); |
| 3452 | } |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3453 | if (res >= IPA_QUOTA_REACH_IF_NAME_MAX_SIZE) { |
| 3454 | IPAWANERR("message too long (%d)", res); |
| 3455 | return; |
| 3456 | } |
| 3457 | /* posting msg for M-release for CNE */ |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3458 | if (upstream_type == IPA_UPSTEAM_MODEM) { |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3459 | res = snprintf(iface_name_m, IPA_QUOTA_REACH_IF_NAME_MAX_SIZE, |
| 3460 | "INTERFACE=%s", rmnet_ipa3_ctx->mux_channel[index].vchannel_name); |
Skylar Chang | 6b41f8d | 2016-11-01 12:50:11 -0700 | [diff] [blame] | 3461 | } else { |
| 3462 | res = snprintf(iface_name_m, IPA_QUOTA_REACH_IF_NAME_MAX_SIZE, |
| 3463 | "INTERFACE=%s", IPA_UPSTEAM_WLAN_IFACE_NAME); |
| 3464 | } |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3465 | if (res >= IPA_QUOTA_REACH_IF_NAME_MAX_SIZE) { |
| 3466 | IPAWANERR("message too long (%d)", res); |
| 3467 | return; |
| 3468 | } |
| 3469 | |
| 3470 | IPAWANERR("putting nlmsg: <%s> <%s> <%s>\n", |
| 3471 | alert_msg, iface_name_l, iface_name_m); |
| 3472 | kobject_uevent_env(&(IPA_NETDEV()->dev.kobj), |
| 3473 | KOBJ_CHANGE, envp); |
Skylar Chang | 09e0e25 | 2017-03-20 14:51:29 -0700 | [diff] [blame] | 3474 | |
| 3475 | rmnet_ipa_send_quota_reach_ind(); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | /** |
| 3479 | * ipa3_q6_handshake_complete() - Perform operations once Q6 is up |
| 3480 | * @ssr_bootup - Indicates whether this is a cold boot-up or post-SSR. |
| 3481 | * |
| 3482 | * This function is invoked once the handshake between the IPA AP driver |
| 3483 | * and IPA Q6 driver is complete. At this point, it is possible to perform |
| 3484 | * operations which can't be performed until IPA Q6 driver is up. |
| 3485 | * |
| 3486 | */ |
| 3487 | void ipa3_q6_handshake_complete(bool ssr_bootup) |
| 3488 | { |
| 3489 | /* It is required to recover the network stats after SSR recovery */ |
| 3490 | if (ssr_bootup) { |
| 3491 | /* |
| 3492 | * In case the uC is required to be loaded by the Modem, |
| 3493 | * the proxy vote will be removed only when uC loading is |
| 3494 | * complete and indication is received by the AP. After SSR, |
| 3495 | * uC is already loaded. Therefore, proxy vote can be removed |
| 3496 | * once Modem init is complete. |
| 3497 | */ |
| 3498 | ipa3_proxy_clk_unvote(); |
| 3499 | |
Skylar Chang | 09e0e25 | 2017-03-20 14:51:29 -0700 | [diff] [blame] | 3500 | /* send SSR power-up notification to IPACM */ |
| 3501 | rmnet_ipa_send_ssr_notification(true); |
| 3502 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3503 | /* |
| 3504 | * It is required to recover the network stats after |
| 3505 | * SSR recovery |
| 3506 | */ |
| 3507 | rmnet_ipa_get_network_stats_and_update(); |
| 3508 | } |
| 3509 | } |
| 3510 | |
Mohammed Javid | d0c2a1e | 2017-10-30 15:34:22 +0530 | [diff] [blame] | 3511 | static inline bool rmnet_ipa3_check_any_client_inited |
| 3512 | ( |
| 3513 | enum ipacm_per_client_device_type device_type |
| 3514 | ) |
| 3515 | { |
| 3516 | int i = 0; |
| 3517 | |
| 3518 | for (; i < IPA_MAX_NUM_HW_PATH_CLIENTS; i++) { |
| 3519 | if (rmnet_ipa3_ctx->tether_device[device_type]. |
| 3520 | lan_client[i].client_idx != -1 && |
| 3521 | rmnet_ipa3_ctx->tether_device[device_type]. |
| 3522 | lan_client[i].inited) { |
| 3523 | IPAWANERR("Found client index: %d which is inited\n", |
| 3524 | i); |
| 3525 | return true; |
| 3526 | } |
| 3527 | } |
| 3528 | |
| 3529 | return false; |
| 3530 | } |
| 3531 | |
| 3532 | static inline int rmnet_ipa3_get_lan_client_info |
| 3533 | ( |
| 3534 | enum ipacm_per_client_device_type device_type, |
| 3535 | uint8_t mac[] |
| 3536 | ) |
| 3537 | { |
| 3538 | int i = 0; |
| 3539 | |
| 3540 | IPAWANDBG("Client MAC %02x:%02x:%02x:%02x:%02x:%02x\n", |
| 3541 | mac[0], mac[1], mac[2], |
| 3542 | mac[3], mac[4], mac[5]); |
| 3543 | |
| 3544 | for (; i < IPA_MAX_NUM_HW_PATH_CLIENTS; i++) { |
| 3545 | if (memcmp( |
| 3546 | rmnet_ipa3_ctx->tether_device[device_type]. |
| 3547 | lan_client[i].mac, |
| 3548 | mac, |
| 3549 | IPA_MAC_ADDR_SIZE) == 0) { |
| 3550 | IPAWANDBG("Matched client index: %d\n", i); |
| 3551 | return i; |
| 3552 | } |
| 3553 | } |
| 3554 | |
| 3555 | return -EINVAL; |
| 3556 | } |
| 3557 | |
| 3558 | static inline int rmnet_ipa3_delete_lan_client_info |
| 3559 | ( |
| 3560 | enum ipacm_per_client_device_type device_type, |
| 3561 | int lan_clnt_idx |
| 3562 | ) |
| 3563 | { |
| 3564 | struct ipa_lan_client *lan_client = NULL; |
| 3565 | int i; |
| 3566 | |
| 3567 | /* Check if the request is to clean up all clients. */ |
| 3568 | if (lan_clnt_idx == 0xffffffff) { |
| 3569 | /* Reset the complete device info. */ |
| 3570 | memset(&rmnet_ipa3_ctx->tether_device[device_type], 0, |
| 3571 | sizeof(struct ipa_tether_device_info)); |
| 3572 | rmnet_ipa3_ctx->tether_device[device_type].ul_src_pipe = -1; |
| 3573 | for (i = 0; i < IPA_MAX_NUM_HW_PATH_CLIENTS; i++) |
| 3574 | rmnet_ipa3_ctx->tether_device[device_type]. |
| 3575 | lan_client[i].client_idx = -1; |
| 3576 | } else { |
| 3577 | lan_client = |
| 3578 | &rmnet_ipa3_ctx->tether_device[device_type]. |
| 3579 | lan_client[lan_clnt_idx]; |
| 3580 | /* Reset the client info before sending the message. */ |
| 3581 | memset(lan_client, 0, sizeof(struct ipa_lan_client)); |
| 3582 | lan_client->client_idx = -1; |
| 3583 | |
| 3584 | } |
| 3585 | return 0; |
| 3586 | } |
| 3587 | |
| 3588 | /* rmnet_ipa3_set_lan_client_info() - |
| 3589 | * @data - IOCTL data |
| 3590 | * |
| 3591 | * This function handles WAN_IOC_SET_LAN_CLIENT_INFO. |
| 3592 | * It is used to store LAN client information which |
| 3593 | * is used to fetch the packet stats for a client. |
| 3594 | * |
| 3595 | * Return codes: |
| 3596 | * 0: Success |
| 3597 | * -EINVAL: Invalid args provided |
| 3598 | */ |
| 3599 | int rmnet_ipa3_set_lan_client_info( |
| 3600 | struct wan_ioctl_lan_client_info *data) |
| 3601 | { |
| 3602 | |
| 3603 | struct ipa_lan_client *lan_client = NULL; |
| 3604 | |
| 3605 | |
| 3606 | IPAWANDBG("Client MAC %02x:%02x:%02x:%02x:%02x:%02x\n", |
| 3607 | data->mac[0], data->mac[1], data->mac[2], |
| 3608 | data->mac[3], data->mac[4], data->mac[5]); |
| 3609 | |
| 3610 | /* Check if Device type is valid. */ |
| 3611 | if (data->device_type >= IPACM_MAX_CLIENT_DEVICE_TYPES || |
| 3612 | data->device_type < 0) { |
| 3613 | IPAWANERR("Invalid Device type: %d\n", data->device_type); |
| 3614 | return -EINVAL; |
| 3615 | } |
| 3616 | |
| 3617 | /* Check if Client index is valid. */ |
| 3618 | if (data->client_idx >= IPA_MAX_NUM_HW_PATH_CLIENTS || |
| 3619 | data->client_idx < 0) { |
| 3620 | IPAWANERR("Invalid Client Index: %d\n", data->client_idx); |
| 3621 | return -EINVAL; |
| 3622 | } |
| 3623 | |
| 3624 | mutex_lock(&rmnet_ipa3_ctx->per_client_stats_guard); |
| 3625 | if (data->client_init) { |
| 3626 | /* check if the client is already inited. */ |
| 3627 | if (rmnet_ipa3_ctx->tether_device[data->device_type] |
| 3628 | .lan_client[data->client_idx].inited) { |
| 3629 | IPAWANERR("Client already inited: %d:%d\n", |
| 3630 | data->device_type, data->client_idx); |
| 3631 | mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard); |
| 3632 | return -EINVAL; |
| 3633 | } |
| 3634 | } |
| 3635 | |
| 3636 | lan_client = |
| 3637 | &rmnet_ipa3_ctx->tether_device[data->device_type]. |
| 3638 | lan_client[data->client_idx]; |
| 3639 | |
| 3640 | memcpy(lan_client->mac, data->mac, IPA_MAC_ADDR_SIZE); |
| 3641 | |
| 3642 | lan_client->client_idx = data->client_idx; |
| 3643 | |
| 3644 | /* Update the Source pipe. */ |
| 3645 | rmnet_ipa3_ctx->tether_device[data->device_type].ul_src_pipe = |
| 3646 | ipa3_get_ep_mapping(data->ul_src_pipe); |
| 3647 | |
| 3648 | /* Update the header length if not set. */ |
| 3649 | if (!rmnet_ipa3_ctx->tether_device[data->device_type].hdr_len) |
| 3650 | rmnet_ipa3_ctx->tether_device[data->device_type].hdr_len = |
| 3651 | data->hdr_len; |
| 3652 | |
| 3653 | lan_client->inited = true; |
| 3654 | |
| 3655 | rmnet_ipa3_ctx->tether_device[data->device_type].num_clients++; |
| 3656 | |
| 3657 | IPAWANDBG("Set the lan client info: %d, %d, %d\n", |
| 3658 | lan_client->client_idx, |
| 3659 | rmnet_ipa3_ctx->tether_device[data->device_type].ul_src_pipe, |
| 3660 | rmnet_ipa3_ctx->tether_device[data->device_type].num_clients); |
| 3661 | |
| 3662 | mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard); |
| 3663 | |
| 3664 | return 0; |
| 3665 | } |
| 3666 | |
| 3667 | /* rmnet_ipa3_delete_lan_client_info() - |
| 3668 | * @data - IOCTL data |
| 3669 | * |
| 3670 | * This function handles WAN_IOC_DELETE_LAN_CLIENT_INFO. |
| 3671 | * It is used to delete LAN client information which |
| 3672 | * is used to fetch the packet stats for a client. |
| 3673 | * |
| 3674 | * Return codes: |
| 3675 | * 0: Success |
| 3676 | * -EINVAL: Invalid args provided |
| 3677 | */ |
| 3678 | int rmnet_ipa3_clear_lan_client_info( |
| 3679 | struct wan_ioctl_lan_client_info *data) |
| 3680 | { |
| 3681 | |
| 3682 | struct ipa_lan_client *lan_client = NULL; |
| 3683 | |
| 3684 | |
| 3685 | IPAWANDBG("Client MAC %02x:%02x:%02x:%02x:%02x:%02x\n", |
| 3686 | data->mac[0], data->mac[1], data->mac[2], |
| 3687 | data->mac[3], data->mac[4], data->mac[5]); |
| 3688 | |
| 3689 | /* Check if Device type is valid. */ |
| 3690 | if (data->device_type >= IPACM_MAX_CLIENT_DEVICE_TYPES || |
| 3691 | data->device_type < 0) { |
| 3692 | IPAWANERR("Invalid Device type: %d\n", data->device_type); |
| 3693 | return -EINVAL; |
| 3694 | } |
| 3695 | |
| 3696 | /* Check if Client index is valid. */ |
| 3697 | if (data->client_idx >= IPA_MAX_NUM_HW_PATH_CLIENTS || |
| 3698 | data->client_idx < 0) { |
| 3699 | IPAWANERR("Invalid Client Index: %d\n", data->client_idx); |
| 3700 | return -EINVAL; |
| 3701 | } |
| 3702 | |
| 3703 | mutex_lock(&rmnet_ipa3_ctx->per_client_stats_guard); |
| 3704 | lan_client = |
| 3705 | &rmnet_ipa3_ctx->tether_device[data->device_type]. |
| 3706 | lan_client[data->client_idx]; |
| 3707 | |
| 3708 | if (!data->client_init) { |
| 3709 | /* check if the client is already de-inited. */ |
| 3710 | if (!lan_client->inited) { |
| 3711 | IPAWANERR("Client already de-inited: %d:%d\n", |
| 3712 | data->device_type, data->client_idx); |
| 3713 | mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard); |
| 3714 | return -EINVAL; |
| 3715 | } |
| 3716 | } |
| 3717 | |
| 3718 | lan_client->inited = false; |
| 3719 | mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard); |
| 3720 | |
| 3721 | return 0; |
| 3722 | } |
| 3723 | |
| 3724 | |
| 3725 | /* rmnet_ipa3_send_lan_client_msg() - |
| 3726 | * @data - IOCTL data |
| 3727 | * |
| 3728 | * This function handles WAN_IOC_SEND_LAN_CLIENT_MSG. |
| 3729 | * It is used to send LAN client information to IPACM. |
| 3730 | * |
| 3731 | * Return codes: |
| 3732 | * 0: Success |
| 3733 | * -EINVAL: Invalid args provided |
| 3734 | */ |
| 3735 | int rmnet_ipa3_send_lan_client_msg( |
| 3736 | struct wan_ioctl_send_lan_client_msg *data) |
| 3737 | { |
| 3738 | struct ipa_msg_meta msg_meta; |
| 3739 | int rc; |
| 3740 | struct ipa_lan_client_msg *lan_client; |
| 3741 | |
| 3742 | /* Notify IPACM to reset the client index. */ |
| 3743 | lan_client = kzalloc(sizeof(struct ipa_lan_client_msg), |
| 3744 | GFP_KERNEL); |
| 3745 | if (!lan_client) { |
| 3746 | IPAWANERR("Can't allocate memory for tether_info\n"); |
| 3747 | return -ENOMEM; |
| 3748 | } |
| 3749 | memset(&msg_meta, 0, sizeof(struct ipa_msg_meta)); |
| 3750 | memcpy(lan_client, &data->lan_client, |
| 3751 | sizeof(struct ipa_lan_client_msg)); |
| 3752 | msg_meta.msg_type = data->client_event; |
| 3753 | msg_meta.msg_len = sizeof(struct ipa_lan_client_msg); |
| 3754 | |
| 3755 | rc = ipa_send_msg(&msg_meta, lan_client, rmnet_ipa_free_msg); |
| 3756 | if (rc) { |
| 3757 | IPAWANERR("ipa_send_msg failed: %d\n", rc); |
| 3758 | kfree(lan_client); |
| 3759 | return rc; |
| 3760 | } |
| 3761 | return 0; |
| 3762 | } |
| 3763 | |
| 3764 | /* rmnet_ipa3_enable_per_client_stats() - |
| 3765 | * @data - IOCTL data |
| 3766 | * |
| 3767 | * This function handles WAN_IOC_ENABLE_PER_CLIENT_STATS. |
| 3768 | * It is used to indicate Q6 to start capturing per client stats. |
| 3769 | * |
| 3770 | * Return codes: |
| 3771 | * 0: Success |
| 3772 | * -EINVAL: Invalid args provided |
| 3773 | */ |
| 3774 | int rmnet_ipa3_enable_per_client_stats( |
| 3775 | bool *data) |
| 3776 | { |
| 3777 | struct ipa_enable_per_client_stats_req_msg_v01 *req; |
| 3778 | struct ipa_enable_per_client_stats_resp_msg_v01 *resp; |
| 3779 | int rc; |
| 3780 | |
| 3781 | req = |
| 3782 | kzalloc(sizeof(struct ipa_enable_per_client_stats_req_msg_v01), |
| 3783 | GFP_KERNEL); |
| 3784 | if (!req) { |
| 3785 | IPAWANERR("Can't allocate memory for stats message\n"); |
| 3786 | return -ENOMEM; |
| 3787 | } |
| 3788 | resp = |
| 3789 | kzalloc(sizeof(struct ipa_enable_per_client_stats_resp_msg_v01), |
| 3790 | GFP_KERNEL); |
| 3791 | if (!resp) { |
| 3792 | IPAWANERR("Can't allocate memory for stats message\n"); |
| 3793 | kfree(req); |
| 3794 | return -ENOMEM; |
| 3795 | } |
| 3796 | memset(req, 0, |
| 3797 | sizeof(struct ipa_enable_per_client_stats_req_msg_v01)); |
| 3798 | memset(resp, 0, |
| 3799 | sizeof(struct ipa_enable_per_client_stats_resp_msg_v01)); |
| 3800 | |
| 3801 | if (*data) |
| 3802 | req->enable_per_client_stats = 1; |
| 3803 | else |
| 3804 | req->enable_per_client_stats = 0; |
| 3805 | |
| 3806 | rc = ipa3_qmi_enable_per_client_stats(req, resp); |
| 3807 | if (rc) { |
| 3808 | IPAWANERR("can't enable per client stats\n"); |
| 3809 | kfree(req); |
| 3810 | kfree(resp); |
| 3811 | return rc; |
| 3812 | } |
| 3813 | |
| 3814 | kfree(req); |
| 3815 | kfree(resp); |
| 3816 | return 0; |
| 3817 | } |
| 3818 | |
| 3819 | int rmnet_ipa3_query_per_client_stats( |
| 3820 | struct wan_ioctl_query_per_client_stats *data) |
| 3821 | { |
| 3822 | struct ipa_get_stats_per_client_req_msg_v01 *req; |
| 3823 | struct ipa_get_stats_per_client_resp_msg_v01 *resp; |
| 3824 | int rc, lan_clnt_idx, lan_clnt_idx1, i; |
| 3825 | struct ipa_lan_client *lan_client = NULL; |
| 3826 | |
| 3827 | |
| 3828 | IPAWANDBG("Client MAC %02x:%02x:%02x:%02x:%02x:%02x\n", |
| 3829 | data->client_info[0].mac[0], |
| 3830 | data->client_info[0].mac[1], |
| 3831 | data->client_info[0].mac[2], |
| 3832 | data->client_info[0].mac[3], |
| 3833 | data->client_info[0].mac[4], |
| 3834 | data->client_info[0].mac[5]); |
| 3835 | |
| 3836 | /* Check if Device type is valid. */ |
| 3837 | if (data->device_type >= IPACM_MAX_CLIENT_DEVICE_TYPES || |
| 3838 | data->device_type < 0) { |
| 3839 | IPAWANERR("Invalid Device type: %d\n", data->device_type); |
| 3840 | return -EINVAL; |
| 3841 | } |
| 3842 | |
| 3843 | /* Check if num_clients is valid. */ |
| 3844 | if (data->num_clients != IPA_MAX_NUM_HW_PATH_CLIENTS && |
| 3845 | data->num_clients != 1) { |
| 3846 | IPAWANERR("Invalid number of clients: %d\n", data->num_clients); |
| 3847 | return -EINVAL; |
| 3848 | } |
| 3849 | |
| 3850 | mutex_lock(&rmnet_ipa3_ctx->per_client_stats_guard); |
| 3851 | |
| 3852 | if (data->num_clients == 1) { |
| 3853 | /* Check if the client info is valid.*/ |
| 3854 | lan_clnt_idx1 = rmnet_ipa3_get_lan_client_info( |
| 3855 | data->device_type, |
| 3856 | data->client_info[0].mac); |
| 3857 | if (lan_clnt_idx1 < 0) { |
| 3858 | IPAWANERR("Client info not available return.\n"); |
| 3859 | mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard); |
| 3860 | return -EINVAL; |
| 3861 | } |
| 3862 | lan_client = |
| 3863 | &rmnet_ipa3_ctx->tether_device[data->device_type]. |
| 3864 | lan_client[lan_clnt_idx1]; |
| 3865 | /* |
| 3866 | * Check if disconnect flag is set and |
| 3867 | * see if all the clients info are cleared. |
| 3868 | */ |
| 3869 | if (data->disconnect_clnt && |
| 3870 | lan_client->inited) { |
| 3871 | IPAWANERR("Client not inited. Try again.\n"); |
| 3872 | mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard); |
| 3873 | return -EAGAIN; |
| 3874 | } |
| 3875 | |
| 3876 | } else { |
| 3877 | /* Max number of clients. */ |
| 3878 | /* Check if disconnect flag is set and |
| 3879 | * see if all the clients info are cleared. |
| 3880 | */ |
| 3881 | if (data->disconnect_clnt && |
| 3882 | rmnet_ipa3_check_any_client_inited(data->device_type)) { |
| 3883 | IPAWANERR("CLient not inited. Try again.\n"); |
| 3884 | mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard); |
| 3885 | return -EAGAIN; |
| 3886 | } |
| 3887 | lan_clnt_idx1 = 0xffffffff; |
| 3888 | } |
| 3889 | |
| 3890 | req = kzalloc(sizeof(struct ipa_get_stats_per_client_req_msg_v01), |
| 3891 | GFP_KERNEL); |
| 3892 | if (!req) { |
| 3893 | IPAWANERR("Can't allocate memory for stats message\n"); |
| 3894 | mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard); |
| 3895 | return -ENOMEM; |
| 3896 | } |
| 3897 | resp = kzalloc(sizeof(struct ipa_get_stats_per_client_resp_msg_v01), |
| 3898 | GFP_KERNEL); |
| 3899 | if (!resp) { |
| 3900 | IPAWANERR("Can't allocate memory for stats message\n"); |
| 3901 | mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard); |
| 3902 | kfree(req); |
| 3903 | return -ENOMEM; |
| 3904 | } |
| 3905 | memset(req, 0, sizeof(struct ipa_get_stats_per_client_req_msg_v01)); |
| 3906 | memset(resp, 0, sizeof(struct ipa_get_stats_per_client_resp_msg_v01)); |
| 3907 | |
| 3908 | if (data->reset_stats) { |
| 3909 | req->reset_stats_valid = true; |
| 3910 | req->reset_stats = true; |
| 3911 | IPAWANDBG("fetch and reset the client stats\n"); |
| 3912 | } |
| 3913 | |
| 3914 | req->client_id = lan_clnt_idx1; |
| 3915 | req->src_pipe_id = |
| 3916 | rmnet_ipa3_ctx->tether_device[data->device_type].ul_src_pipe; |
| 3917 | |
| 3918 | IPAWANDBG("fetch the client stats for %d, %d\n", req->client_id, |
| 3919 | req->src_pipe_id); |
| 3920 | |
| 3921 | rc = ipa3_qmi_get_per_client_packet_stats(req, resp); |
| 3922 | if (rc) { |
| 3923 | IPAWANERR("can't get per client stats\n"); |
| 3924 | mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard); |
| 3925 | kfree(req); |
| 3926 | kfree(resp); |
| 3927 | return rc; |
| 3928 | } |
| 3929 | |
| 3930 | if (resp->per_client_stats_list_valid) { |
| 3931 | for (i = 0; i < resp->per_client_stats_list_len |
| 3932 | && i < IPA_MAX_NUM_HW_PATH_CLIENTS; i++) { |
| 3933 | /* Subtract the header bytes from the DL bytes. */ |
| 3934 | data->client_info[i].ipv4_rx_bytes = |
| 3935 | (resp->per_client_stats_list[i].num_dl_ipv4_bytes) - |
| 3936 | (rmnet_ipa3_ctx-> |
| 3937 | tether_device[data->device_type].hdr_len * |
| 3938 | resp->per_client_stats_list[i].num_dl_ipv4_pkts); |
| 3939 | /* UL header bytes are subtracted by Q6. */ |
| 3940 | data->client_info[i].ipv4_tx_bytes = |
| 3941 | resp->per_client_stats_list[i].num_ul_ipv4_bytes; |
| 3942 | /* Subtract the header bytes from the DL bytes. */ |
| 3943 | data->client_info[i].ipv6_rx_bytes = |
| 3944 | (resp->per_client_stats_list[i].num_dl_ipv6_bytes) - |
| 3945 | (rmnet_ipa3_ctx-> |
| 3946 | tether_device[data->device_type].hdr_len * |
| 3947 | resp->per_client_stats_list[i].num_dl_ipv6_pkts); |
| 3948 | /* UL header bytes are subtracted by Q6. */ |
| 3949 | data->client_info[i].ipv6_tx_bytes = |
| 3950 | resp->per_client_stats_list[i].num_ul_ipv6_bytes; |
| 3951 | |
| 3952 | IPAWANDBG("tx_b_v4(%lu)v6(%lu)rx_b_v4(%lu) v6(%lu)\n", |
| 3953 | (unsigned long int) data->client_info[i].ipv4_tx_bytes, |
| 3954 | (unsigned long int) data->client_info[i].ipv6_tx_bytes, |
| 3955 | (unsigned long int) data->client_info[i].ipv4_rx_bytes, |
| 3956 | (unsigned long int) data->client_info[i].ipv6_rx_bytes); |
| 3957 | |
| 3958 | /* Get the lan client index. */ |
| 3959 | lan_clnt_idx = resp->per_client_stats_list[i].client_id; |
| 3960 | /* Check if lan_clnt_idx is valid. */ |
| 3961 | if (lan_clnt_idx < 0 || |
| 3962 | lan_clnt_idx >= IPA_MAX_NUM_HW_PATH_CLIENTS) { |
| 3963 | IPAWANERR("Lan client index not valid.\n"); |
| 3964 | mutex_unlock( |
| 3965 | &rmnet_ipa3_ctx->per_client_stats_guard); |
| 3966 | kfree(req); |
| 3967 | kfree(resp); |
| 3968 | ipa_assert(); |
| 3969 | return -EINVAL; |
| 3970 | } |
| 3971 | memcpy(data->client_info[i].mac, |
| 3972 | rmnet_ipa3_ctx-> |
| 3973 | tether_device[data->device_type]. |
| 3974 | lan_client[lan_clnt_idx].mac, |
| 3975 | IPA_MAC_ADDR_SIZE); |
| 3976 | } |
| 3977 | } |
| 3978 | |
| 3979 | if (data->disconnect_clnt) { |
| 3980 | rmnet_ipa3_delete_lan_client_info(data->device_type, |
| 3981 | lan_clnt_idx1); |
| 3982 | } |
| 3983 | |
| 3984 | mutex_unlock(&rmnet_ipa3_ctx->per_client_stats_guard); |
| 3985 | kfree(req); |
| 3986 | kfree(resp); |
| 3987 | return 0; |
| 3988 | } |
| 3989 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3990 | static int __init ipa3_wwan_init(void) |
| 3991 | { |
Mohammed Javid | d0c2a1e | 2017-10-30 15:34:22 +0530 | [diff] [blame] | 3992 | int i, j; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 3993 | rmnet_ipa3_ctx = kzalloc(sizeof(*rmnet_ipa3_ctx), GFP_KERNEL); |
| 3994 | if (!rmnet_ipa3_ctx) { |
| 3995 | IPAWANERR("no memory\n"); |
| 3996 | return -ENOMEM; |
| 3997 | } |
| 3998 | |
| 3999 | atomic_set(&rmnet_ipa3_ctx->is_initialized, 0); |
| 4000 | atomic_set(&rmnet_ipa3_ctx->is_ssr, 0); |
| 4001 | |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 4002 | mutex_init(&rmnet_ipa3_ctx->pipe_handle_guard); |
Skylar Chang | 8438ba5 | 2017-03-15 21:27:35 -0700 | [diff] [blame] | 4003 | mutex_init(&rmnet_ipa3_ctx->add_mux_channel_lock); |
Mohammed Javid | d0c2a1e | 2017-10-30 15:34:22 +0530 | [diff] [blame] | 4004 | mutex_init(&rmnet_ipa3_ctx->per_client_stats_guard); |
| 4005 | /* Reset the Lan Stats. */ |
| 4006 | for (i = 0; i < IPACM_MAX_CLIENT_DEVICE_TYPES; i++) { |
| 4007 | rmnet_ipa3_ctx->tether_device[i].ul_src_pipe = -1; |
| 4008 | for (j = 0; j < IPA_MAX_NUM_HW_PATH_CLIENTS; j++) |
| 4009 | rmnet_ipa3_ctx->tether_device[i]. |
| 4010 | lan_client[j].client_idx = -1; |
| 4011 | } |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 4012 | rmnet_ipa3_ctx->ipa3_to_apps_hdl = -1; |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 4013 | rmnet_ipa3_ctx->apps_to_ipa3_hdl = -1; |
Utkarsh Saxena | bcb324e | 2017-04-24 22:56:31 +0530 | [diff] [blame] | 4014 | |
| 4015 | ipa3_qmi_init(); |
| 4016 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 4017 | /* Register for Modem SSR */ |
| 4018 | rmnet_ipa3_ctx->subsys_notify_handle = subsys_notif_register_notifier( |
| 4019 | SUBSYS_MODEM, |
| 4020 | &ipa3_ssr_notifier); |
| 4021 | if (!IS_ERR(rmnet_ipa3_ctx->subsys_notify_handle)) |
| 4022 | return platform_driver_register(&rmnet_ipa_driver); |
| 4023 | else |
| 4024 | return (int)PTR_ERR(rmnet_ipa3_ctx->subsys_notify_handle); |
| 4025 | } |
| 4026 | |
| 4027 | static void __exit ipa3_wwan_cleanup(void) |
| 4028 | { |
| 4029 | int ret; |
Skylar Chang | 8438ba5 | 2017-03-15 21:27:35 -0700 | [diff] [blame] | 4030 | |
Utkarsh Saxena | bcb324e | 2017-04-24 22:56:31 +0530 | [diff] [blame] | 4031 | ipa3_qmi_cleanup(); |
Ghanim Fodi | c6b6749 | 2017-03-15 14:19:56 +0200 | [diff] [blame] | 4032 | mutex_destroy(&rmnet_ipa3_ctx->pipe_handle_guard); |
Skylar Chang | 8438ba5 | 2017-03-15 21:27:35 -0700 | [diff] [blame] | 4033 | mutex_destroy(&rmnet_ipa3_ctx->add_mux_channel_lock); |
Mohammed Javid | d0c2a1e | 2017-10-30 15:34:22 +0530 | [diff] [blame] | 4034 | mutex_destroy(&rmnet_ipa3_ctx->per_client_stats_guard); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 4035 | ret = subsys_notif_unregister_notifier( |
| 4036 | rmnet_ipa3_ctx->subsys_notify_handle, &ipa3_ssr_notifier); |
| 4037 | if (ret) |
| 4038 | IPAWANERR( |
| 4039 | "Error subsys_notif_unregister_notifier system %s, ret=%d\n", |
| 4040 | SUBSYS_MODEM, ret); |
| 4041 | platform_driver_unregister(&rmnet_ipa_driver); |
| 4042 | kfree(rmnet_ipa3_ctx); |
| 4043 | rmnet_ipa3_ctx = NULL; |
| 4044 | } |
| 4045 | |
| 4046 | static void ipa3_wwan_msg_free_cb(void *buff, u32 len, u32 type) |
| 4047 | { |
| 4048 | if (!buff) |
| 4049 | IPAWANERR("Null buffer.\n"); |
| 4050 | kfree(buff); |
| 4051 | } |
| 4052 | |
| 4053 | static void ipa3_rmnet_rx_cb(void *priv) |
| 4054 | { |
| 4055 | IPAWANDBG_LOW("\n"); |
| 4056 | napi_schedule(&(rmnet_ipa3_ctx->wwan_priv->napi)); |
| 4057 | } |
| 4058 | |
| 4059 | static int ipa3_rmnet_poll(struct napi_struct *napi, int budget) |
| 4060 | { |
| 4061 | int rcvd_pkts = 0; |
| 4062 | |
| 4063 | rcvd_pkts = ipa_rx_poll(rmnet_ipa3_ctx->ipa3_to_apps_hdl, |
| 4064 | NAPI_WEIGHT); |
| 4065 | IPAWANDBG_LOW("rcvd packets: %d\n", rcvd_pkts); |
| 4066 | return rcvd_pkts; |
| 4067 | } |
| 4068 | |
| 4069 | late_initcall(ipa3_wwan_init); |
| 4070 | module_exit(ipa3_wwan_cleanup); |
| 4071 | MODULE_DESCRIPTION("WWAN Network Interface"); |
| 4072 | MODULE_LICENSE("GPL v2"); |