blob: 3e1a8fbf4d7280cb423f232e4cd52fadd0baaaee [file] [log] [blame]
Skylar Changf3a7dac2017-01-25 09:16:55 -08001/* Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
Amir Levy9659e592016-10-27 18:08:27 +03002 *
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 Studinski3021a6f2016-11-10 12:48:48 +020037#include <uapi/linux/msm_rmnet.h>
38#include <net/rmnet_config.h>
Amir Levy9659e592016-10-27 18:08:27 +030039
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 Fodic6b67492017-03-15 14:19:56 +020050#define DEFAULT_OUTSTANDING_HIGH 128
51#define DEFAULT_OUTSTANDING_HIGH_CTL (DEFAULT_OUTSTANDING_HIGH+32)
52#define DEFAULT_OUTSTANDING_LOW 64
Amir Levy9659e592016-10-27 18:08:27 +030053
54#define IPA_WWAN_DEV_NAME "rmnet_ipa%d"
55
56#define IPA_WWAN_RX_SOFTIRQ_THRESH 16
57
58#define INVALID_MUX_ID 0xFF
59#define IPA_QUOTA_REACH_ALERT_MAX_SIZE 64
60#define IPA_QUOTA_REACH_IF_NAME_MAX_SIZE 64
61#define IPA_UEVENT_NUM_EVNP 4 /* number of event pointers */
62#define NAPI_WEIGHT 60
63
64#define IPA_NETDEV() \
65 ((rmnet_ipa3_ctx && rmnet_ipa3_ctx->wwan_priv) ? \
66 rmnet_ipa3_ctx->wwan_priv->net : NULL)
67
68
69static int ipa3_wwan_add_ul_flt_rule_to_ipa(void);
70static int ipa3_wwan_del_ul_flt_rule_to_ipa(void);
71static void ipa3_wwan_msg_free_cb(void*, u32, u32);
72static void ipa3_rmnet_rx_cb(void *priv);
73static int ipa3_rmnet_poll(struct napi_struct *napi, int budget);
74
75static void ipa3_wake_tx_queue(struct work_struct *work);
76static DECLARE_WORK(ipa3_tx_wakequeue_work, ipa3_wake_tx_queue);
77
78static void tethering_stats_poll_queue(struct work_struct *work);
79static DECLARE_DELAYED_WORK(ipa_tether_stats_poll_wakequeue_work,
80 tethering_stats_poll_queue);
81
82enum ipa3_wwan_device_status {
83 WWAN_DEVICE_INACTIVE = 0,
84 WWAN_DEVICE_ACTIVE = 1
85};
86
87struct ipa3_rmnet_plat_drv_res {
88 bool ipa_rmnet_ssr;
89 bool ipa_loaduC;
90 bool ipa_advertise_sg_support;
91 bool ipa_napi_enable;
92};
93
94/**
95 * struct ipa3_wwan_private - WWAN private data
96 * @net: network interface struct implemented by this driver
97 * @stats: iface statistics
98 * @outstanding_pkts: number of packets sent to IPA without TX complete ACKed
99 * @outstanding_high: number of outstanding packets allowed
100 * @outstanding_low: number of outstanding packets which shall cause
101 * @ch_id: channel id
102 * @lock: spinlock for mutual exclusion
103 * @device_status: holds device status
104 *
105 * WWAN private - holds all relevant info about WWAN driver
106 */
107struct ipa3_wwan_private {
108 struct net_device *net;
109 struct net_device_stats stats;
110 atomic_t outstanding_pkts;
111 int outstanding_high_ctl;
112 int outstanding_high;
113 int outstanding_low;
114 uint32_t ch_id;
115 spinlock_t lock;
116 struct completion resource_granted_completion;
117 enum ipa3_wwan_device_status device_status;
118 struct napi_struct napi;
119};
120
121struct rmnet_ipa3_context {
122 struct ipa3_wwan_private *wwan_priv;
123 struct ipa_sys_connect_params apps_to_ipa_ep_cfg;
124 struct ipa_sys_connect_params ipa_to_apps_ep_cfg;
125 u32 qmap_hdr_hdl;
126 u32 dflt_v4_wan_rt_hdl;
127 u32 dflt_v6_wan_rt_hdl;
128 struct ipa3_rmnet_mux_val mux_channel[MAX_NUM_OF_MUX_CHANNEL];
129 int num_q6_rules;
130 int old_num_q6_rules;
131 int rmnet_index;
132 bool egress_set;
133 bool a7_ul_flt_set;
134 struct workqueue_struct *rm_q6_wq;
135 atomic_t is_initialized;
136 atomic_t is_ssr;
137 void *subsys_notify_handle;
138 u32 apps_to_ipa3_hdl;
139 u32 ipa3_to_apps_hdl;
Ghanim Fodic6b67492017-03-15 14:19:56 +0200140 struct mutex pipe_handle_guard;
Amir Levy9659e592016-10-27 18:08:27 +0300141};
142
143static struct rmnet_ipa3_context *rmnet_ipa3_ctx;
144static struct ipa3_rmnet_plat_drv_res ipa3_rmnet_res;
145
146/**
147* ipa3_setup_a7_qmap_hdr() - Setup default a7 qmap hdr
148*
149* Return codes:
150* 0: success
151* -ENOMEM: failed to allocate memory
152* -EPERM: failed to add the tables
153*/
154static int ipa3_setup_a7_qmap_hdr(void)
155{
156 struct ipa_ioc_add_hdr *hdr;
157 struct ipa_hdr_add *hdr_entry;
158 u32 pyld_sz;
159 int ret;
160
161 /* install the basic exception header */
162 pyld_sz = sizeof(struct ipa_ioc_add_hdr) + 1 *
163 sizeof(struct ipa_hdr_add);
164 hdr = kzalloc(pyld_sz, GFP_KERNEL);
165 if (!hdr) {
166 IPAWANERR("fail to alloc exception hdr\n");
167 return -ENOMEM;
168 }
169 hdr->num_hdrs = 1;
170 hdr->commit = 1;
171 hdr_entry = &hdr->hdr[0];
172
173 strlcpy(hdr_entry->name, IPA_A7_QMAP_HDR_NAME,
174 IPA_RESOURCE_NAME_MAX);
175 hdr_entry->hdr_len = IPA_QMAP_HEADER_LENGTH; /* 4 bytes */
176
177 if (ipa3_add_hdr(hdr)) {
178 IPAWANERR("fail to add IPA_A7_QMAP hdr\n");
179 ret = -EPERM;
180 goto bail;
181 }
182
183 if (hdr_entry->status) {
184 IPAWANERR("fail to add IPA_A7_QMAP hdr\n");
185 ret = -EPERM;
186 goto bail;
187 }
188 rmnet_ipa3_ctx->qmap_hdr_hdl = hdr_entry->hdr_hdl;
189
190 ret = 0;
191bail:
192 kfree(hdr);
193 return ret;
194}
195
196static void ipa3_del_a7_qmap_hdr(void)
197{
198 struct ipa_ioc_del_hdr *del_hdr;
199 struct ipa_hdr_del *hdl_entry;
200 u32 pyld_sz;
201 int ret;
202
203 pyld_sz = sizeof(struct ipa_ioc_del_hdr) + 1 *
204 sizeof(struct ipa_hdr_del);
205 del_hdr = kzalloc(pyld_sz, GFP_KERNEL);
206 if (!del_hdr) {
207 IPAWANERR("fail to alloc exception hdr_del\n");
208 return;
209 }
210
211 del_hdr->commit = 1;
212 del_hdr->num_hdls = 1;
213 hdl_entry = &del_hdr->hdl[0];
214 hdl_entry->hdl = rmnet_ipa3_ctx->qmap_hdr_hdl;
215
216 ret = ipa3_del_hdr(del_hdr);
217 if (ret || hdl_entry->status)
218 IPAWANERR("ipa3_del_hdr failed\n");
219 else
220 IPAWANDBG("hdrs deletion done\n");
221
222 rmnet_ipa3_ctx->qmap_hdr_hdl = 0;
223 kfree(del_hdr);
224}
225
226static void ipa3_del_qmap_hdr(uint32_t hdr_hdl)
227{
228 struct ipa_ioc_del_hdr *del_hdr;
229 struct ipa_hdr_del *hdl_entry;
230 u32 pyld_sz;
231 int ret;
232
233 if (hdr_hdl == 0) {
234 IPAWANERR("Invalid hdr_hdl provided\n");
235 return;
236 }
237
238 pyld_sz = sizeof(struct ipa_ioc_del_hdr) + 1 *
239 sizeof(struct ipa_hdr_del);
240 del_hdr = kzalloc(pyld_sz, GFP_KERNEL);
241 if (!del_hdr) {
242 IPAWANERR("fail to alloc exception hdr_del\n");
243 return;
244 }
245
246 del_hdr->commit = 1;
247 del_hdr->num_hdls = 1;
248 hdl_entry = &del_hdr->hdl[0];
249 hdl_entry->hdl = hdr_hdl;
250
251 ret = ipa3_del_hdr(del_hdr);
252 if (ret || hdl_entry->status)
253 IPAWANERR("ipa3_del_hdr failed\n");
254 else
255 IPAWANDBG("header deletion done\n");
256
257 rmnet_ipa3_ctx->qmap_hdr_hdl = 0;
258 kfree(del_hdr);
259}
260
261static void ipa3_del_mux_qmap_hdrs(void)
262{
263 int index;
264
265 for (index = 0; index < rmnet_ipa3_ctx->rmnet_index; index++) {
266 ipa3_del_qmap_hdr(rmnet_ipa3_ctx->mux_channel[index].hdr_hdl);
267 rmnet_ipa3_ctx->mux_channel[index].hdr_hdl = 0;
268 }
269}
270
271static int ipa3_add_qmap_hdr(uint32_t mux_id, uint32_t *hdr_hdl)
272{
273 struct ipa_ioc_add_hdr *hdr;
274 struct ipa_hdr_add *hdr_entry;
275 char hdr_name[IPA_RESOURCE_NAME_MAX];
276 u32 pyld_sz;
277 int ret;
278
279 pyld_sz = sizeof(struct ipa_ioc_add_hdr) + 1 *
280 sizeof(struct ipa_hdr_add);
281 hdr = kzalloc(pyld_sz, GFP_KERNEL);
282 if (!hdr) {
283 IPAWANERR("fail to alloc exception hdr\n");
284 return -ENOMEM;
285 }
286 hdr->num_hdrs = 1;
287 hdr->commit = 1;
288 hdr_entry = &hdr->hdr[0];
289
290 snprintf(hdr_name, IPA_RESOURCE_NAME_MAX, "%s%d",
291 A2_MUX_HDR_NAME_V4_PREF,
292 mux_id);
293 strlcpy(hdr_entry->name, hdr_name,
294 IPA_RESOURCE_NAME_MAX);
295
296 hdr_entry->hdr_len = IPA_QMAP_HEADER_LENGTH; /* 4 bytes */
297 hdr_entry->hdr[1] = (uint8_t) mux_id;
298 IPAWANDBG("header (%s) with mux-id: (%d)\n",
299 hdr_name,
300 hdr_entry->hdr[1]);
301 if (ipa3_add_hdr(hdr)) {
302 IPAWANERR("fail to add IPA_QMAP hdr\n");
303 ret = -EPERM;
304 goto bail;
305 }
306
307 if (hdr_entry->status) {
308 IPAWANERR("fail to add IPA_QMAP hdr\n");
309 ret = -EPERM;
310 goto bail;
311 }
312
313 ret = 0;
314 *hdr_hdl = hdr_entry->hdr_hdl;
315bail:
316 kfree(hdr);
317 return ret;
318}
319
320/**
321* ipa3_setup_dflt_wan_rt_tables() - Setup default wan routing tables
322*
323* Return codes:
324* 0: success
325* -ENOMEM: failed to allocate memory
326* -EPERM: failed to add the tables
327*/
328static int ipa3_setup_dflt_wan_rt_tables(void)
329{
330 struct ipa_ioc_add_rt_rule *rt_rule;
331 struct ipa_rt_rule_add *rt_rule_entry;
332
333 rt_rule =
334 kzalloc(sizeof(struct ipa_ioc_add_rt_rule) + 1 *
335 sizeof(struct ipa_rt_rule_add), GFP_KERNEL);
336 if (!rt_rule) {
337 IPAWANERR("fail to alloc mem\n");
338 return -ENOMEM;
339 }
340 /* setup a default v4 route to point to Apps */
341 rt_rule->num_rules = 1;
342 rt_rule->commit = 1;
343 rt_rule->ip = IPA_IP_v4;
344 strlcpy(rt_rule->rt_tbl_name, IPA_DFLT_WAN_RT_TBL_NAME,
345 IPA_RESOURCE_NAME_MAX);
346
347 rt_rule_entry = &rt_rule->rules[0];
348 rt_rule_entry->at_rear = 1;
349 rt_rule_entry->rule.dst = IPA_CLIENT_APPS_WAN_CONS;
350 rt_rule_entry->rule.hdr_hdl = rmnet_ipa3_ctx->qmap_hdr_hdl;
351
352 if (ipa3_add_rt_rule(rt_rule)) {
353 IPAWANERR("fail to add dflt_wan v4 rule\n");
354 kfree(rt_rule);
355 return -EPERM;
356 }
357
358 IPAWANDBG("dflt v4 rt rule hdl=%x\n", rt_rule_entry->rt_rule_hdl);
359 rmnet_ipa3_ctx->dflt_v4_wan_rt_hdl = rt_rule_entry->rt_rule_hdl;
360
361 /* setup a default v6 route to point to A5 */
362 rt_rule->ip = IPA_IP_v6;
363 if (ipa3_add_rt_rule(rt_rule)) {
364 IPAWANERR("fail to add dflt_wan v6 rule\n");
365 kfree(rt_rule);
366 return -EPERM;
367 }
368 IPAWANDBG("dflt v6 rt rule hdl=%x\n", rt_rule_entry->rt_rule_hdl);
369 rmnet_ipa3_ctx->dflt_v6_wan_rt_hdl = rt_rule_entry->rt_rule_hdl;
370
371 kfree(rt_rule);
372 return 0;
373}
374
375static void ipa3_del_dflt_wan_rt_tables(void)
376{
377 struct ipa_ioc_del_rt_rule *rt_rule;
378 struct ipa_rt_rule_del *rt_rule_entry;
379 int len;
380
381 len = sizeof(struct ipa_ioc_del_rt_rule) + 1 *
382 sizeof(struct ipa_rt_rule_del);
383 rt_rule = kzalloc(len, GFP_KERNEL);
384 if (!rt_rule) {
385 IPAWANERR("unable to allocate memory for del route rule\n");
386 return;
387 }
388
389 memset(rt_rule, 0, len);
390 rt_rule->commit = 1;
391 rt_rule->num_hdls = 1;
392 rt_rule->ip = IPA_IP_v4;
393
394 rt_rule_entry = &rt_rule->hdl[0];
395 rt_rule_entry->status = -1;
396 rt_rule_entry->hdl = rmnet_ipa3_ctx->dflt_v4_wan_rt_hdl;
397
398 IPAWANERR("Deleting Route hdl:(0x%x) with ip type: %d\n",
399 rt_rule_entry->hdl, IPA_IP_v4);
400 if (ipa3_del_rt_rule(rt_rule) ||
401 (rt_rule_entry->status)) {
402 IPAWANERR("Routing rule deletion failed!\n");
403 }
404
405 rt_rule->ip = IPA_IP_v6;
406 rt_rule_entry->hdl = rmnet_ipa3_ctx->dflt_v6_wan_rt_hdl;
407 IPAWANERR("Deleting Route hdl:(0x%x) with ip type: %d\n",
408 rt_rule_entry->hdl, IPA_IP_v6);
409 if (ipa3_del_rt_rule(rt_rule) ||
410 (rt_rule_entry->status)) {
411 IPAWANERR("Routing rule deletion failed!\n");
412 }
413
414 kfree(rt_rule);
415}
416
417int ipa3_copy_ul_filter_rule_to_ipa(struct ipa_install_fltr_rule_req_msg_v01
418 *rule_req)
419{
420 int i, j;
421
422 if (rule_req->filter_spec_ex_list_valid == true) {
423 rmnet_ipa3_ctx->num_q6_rules =
424 rule_req->filter_spec_ex_list_len;
425 IPAWANDBG("Received (%d) install_flt_req\n",
426 rmnet_ipa3_ctx->num_q6_rules);
427 } else {
428 rmnet_ipa3_ctx->num_q6_rules = 0;
429 IPAWANERR("got no UL rules from modem\n");
430 return -EINVAL;
431 }
432
433 /* copy UL filter rules from Modem*/
434 for (i = 0; i < rmnet_ipa3_ctx->num_q6_rules; i++) {
435 /* check if rules overside the cache*/
436 if (i == MAX_NUM_Q6_RULE) {
437 IPAWANERR("Reaching (%d) max cache ",
438 MAX_NUM_Q6_RULE);
439 IPAWANERR(" however total (%d)\n",
440 rmnet_ipa3_ctx->num_q6_rules);
441 goto failure;
442 }
443 ipa3_qmi_ctx->q6_ul_filter_rule[i].ip =
444 rule_req->filter_spec_ex_list[i].ip_type;
445 ipa3_qmi_ctx->q6_ul_filter_rule[i].action =
446 rule_req->filter_spec_ex_list[i].filter_action;
447 if (rule_req->filter_spec_ex_list[i].
448 is_routing_table_index_valid == true)
449 ipa3_qmi_ctx->q6_ul_filter_rule[i].rt_tbl_idx =
450 rule_req->filter_spec_ex_list[i].route_table_index;
451 if (rule_req->filter_spec_ex_list[i].is_mux_id_valid == true)
452 ipa3_qmi_ctx->q6_ul_filter_rule[i].mux_id =
453 rule_req->filter_spec_ex_list[i].mux_id;
454 ipa3_qmi_ctx->q6_ul_filter_rule[i].rule_id =
455 rule_req->filter_spec_ex_list[i].rule_id;
456 ipa3_qmi_ctx->q6_ul_filter_rule[i].is_rule_hashable =
457 rule_req->filter_spec_ex_list[i].is_rule_hashable;
458 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.rule_eq_bitmap =
459 rule_req->filter_spec_ex_list[i].filter_rule.
460 rule_eq_bitmap;
461 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.tos_eq_present =
462 rule_req->filter_spec_ex_list[i].filter_rule.
463 tos_eq_present;
464 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.tos_eq =
465 rule_req->filter_spec_ex_list[i].filter_rule.tos_eq;
466 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
467 protocol_eq_present = rule_req->filter_spec_ex_list[i].
468 filter_rule.protocol_eq_present;
469 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.protocol_eq =
470 rule_req->filter_spec_ex_list[i].filter_rule.
471 protocol_eq;
472
473 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
474 num_ihl_offset_range_16 =
475 rule_req->filter_spec_ex_list[i].
476 filter_rule.num_ihl_offset_range_16;
477 for (j = 0; j < ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
478 num_ihl_offset_range_16; j++) {
479 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
480 ihl_offset_range_16[j].offset = rule_req->
481 filter_spec_ex_list[i].filter_rule.
482 ihl_offset_range_16[j].offset;
483 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
484 ihl_offset_range_16[j].range_low = rule_req->
485 filter_spec_ex_list[i].filter_rule.
486 ihl_offset_range_16[j].range_low;
487 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
488 ihl_offset_range_16[j].range_high = rule_req->
489 filter_spec_ex_list[i].filter_rule.
490 ihl_offset_range_16[j].range_high;
491 }
492 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.num_offset_meq_32 =
493 rule_req->filter_spec_ex_list[i].filter_rule.
494 num_offset_meq_32;
495 for (j = 0; j < ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
496 num_offset_meq_32; j++) {
497 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
498 offset_meq_32[j].offset =
499 rule_req->filter_spec_ex_list[i].
500 filter_rule.offset_meq_32[j].offset;
501 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
502 offset_meq_32[j].mask =
503 rule_req->filter_spec_ex_list[i].
504 filter_rule.offset_meq_32[j].mask;
505 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
506 offset_meq_32[j].value =
507 rule_req->filter_spec_ex_list[i].
508 filter_rule.offset_meq_32[j].value;
509 }
510
511 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.tc_eq_present =
512 rule_req->filter_spec_ex_list[i].
513 filter_rule.tc_eq_present;
514 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.tc_eq =
515 rule_req->filter_spec_ex_list[i].filter_rule.tc_eq;
516 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.fl_eq_present =
517 rule_req->filter_spec_ex_list[i].filter_rule.
518 flow_eq_present;
519 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.fl_eq =
520 rule_req->filter_spec_ex_list[i].filter_rule.flow_eq;
521 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
522 ihl_offset_eq_16_present = rule_req->filter_spec_ex_list[i].
523 filter_rule.ihl_offset_eq_16_present;
524 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
525 ihl_offset_eq_16.offset = rule_req->filter_spec_ex_list[i].
526 filter_rule.ihl_offset_eq_16.offset;
527 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
528 ihl_offset_eq_16.value = rule_req->filter_spec_ex_list[i].
529 filter_rule.ihl_offset_eq_16.value;
530
531 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
532 ihl_offset_eq_32_present = rule_req->filter_spec_ex_list[i].
533 filter_rule.ihl_offset_eq_32_present;
534 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
535 ihl_offset_eq_32.offset = rule_req->filter_spec_ex_list[i].
536 filter_rule.ihl_offset_eq_32.offset;
537 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
538 ihl_offset_eq_32.value = rule_req->filter_spec_ex_list[i].
539 filter_rule.ihl_offset_eq_32.value;
540
541 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
542 num_ihl_offset_meq_32 = rule_req->filter_spec_ex_list[i].
543 filter_rule.num_ihl_offset_meq_32;
544 for (j = 0; j < ipa3_qmi_ctx->q6_ul_filter_rule[i].
545 eq_attrib.num_ihl_offset_meq_32; j++) {
546 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
547 ihl_offset_meq_32[j].offset = rule_req->
548 filter_spec_ex_list[i].filter_rule.
549 ihl_offset_meq_32[j].offset;
550 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
551 ihl_offset_meq_32[j].mask = rule_req->
552 filter_spec_ex_list[i].filter_rule.
553 ihl_offset_meq_32[j].mask;
554 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
555 ihl_offset_meq_32[j].value = rule_req->
556 filter_spec_ex_list[i].filter_rule.
557 ihl_offset_meq_32[j].value;
558 }
559 ipa3_qmi_ctx->
560 q6_ul_filter_rule[i].eq_attrib.num_offset_meq_128 =
561 rule_req->filter_spec_ex_list[i].filter_rule.
562 num_offset_meq_128;
563 for (j = 0; j < ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
564 num_offset_meq_128; j++) {
565 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
566 offset_meq_128[j].offset = rule_req->
567 filter_spec_ex_list[i].filter_rule.
568 offset_meq_128[j].offset;
569 memcpy(ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
570 offset_meq_128[j].mask,
571 rule_req->filter_spec_ex_list[i].
572 filter_rule.offset_meq_128[j].mask, 16);
573 memcpy(ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
574 offset_meq_128[j].value, rule_req->
575 filter_spec_ex_list[i].filter_rule.
576 offset_meq_128[j].value, 16);
577 }
578
579 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
580 metadata_meq32_present =
581 rule_req->filter_spec_ex_list[i].
582 filter_rule.metadata_meq32_present;
583 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
584 metadata_meq32.offset =
585 rule_req->filter_spec_ex_list[i].
586 filter_rule.metadata_meq32.offset;
587 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
588 metadata_meq32.mask = rule_req->filter_spec_ex_list[i].
589 filter_rule.metadata_meq32.mask;
590 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.metadata_meq32.
591 value = rule_req->filter_spec_ex_list[i].filter_rule.
592 metadata_meq32.value;
593 ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib.
594 ipv4_frag_eq_present = rule_req->filter_spec_ex_list[i].
595 filter_rule.ipv4_frag_eq_present;
596 }
597
598 if (rule_req->xlat_filter_indices_list_valid) {
599 if (rule_req->xlat_filter_indices_list_len >
600 rmnet_ipa3_ctx->num_q6_rules) {
601 IPAWANERR("Number of xlat indices is not valid: %d\n",
602 rule_req->xlat_filter_indices_list_len);
603 goto failure;
604 }
605 IPAWANDBG("Receive %d XLAT indices: ",
606 rule_req->xlat_filter_indices_list_len);
607 for (i = 0; i < rule_req->xlat_filter_indices_list_len; i++)
608 IPAWANDBG("%d ", rule_req->xlat_filter_indices_list[i]);
609 IPAWANDBG("\n");
610
611 for (i = 0; i < rule_req->xlat_filter_indices_list_len; i++) {
612 if (rule_req->xlat_filter_indices_list[i]
613 >= rmnet_ipa3_ctx->num_q6_rules) {
614 IPAWANERR("Xlat rule idx is wrong: %d\n",
615 rule_req->xlat_filter_indices_list[i]);
616 goto failure;
617 } else {
618 ipa3_qmi_ctx->q6_ul_filter_rule
619 [rule_req->xlat_filter_indices_list[i]]
620 .is_xlat_rule = 1;
621 IPAWANDBG("Rule %d is xlat rule\n",
622 rule_req->xlat_filter_indices_list[i]);
623 }
624 }
625 }
626 goto success;
627
628failure:
629 rmnet_ipa3_ctx->num_q6_rules = 0;
630 memset(ipa3_qmi_ctx->q6_ul_filter_rule, 0,
631 sizeof(ipa3_qmi_ctx->q6_ul_filter_rule));
632 return -EINVAL;
633
634success:
635 return 0;
636}
637
638static int ipa3_wwan_add_ul_flt_rule_to_ipa(void)
639{
640 u32 pyld_sz;
641 int i, retval = 0;
642 struct ipa_ioc_add_flt_rule *param;
643 struct ipa_flt_rule_add flt_rule_entry;
644 struct ipa_fltr_installed_notif_req_msg_v01 *req;
645
646 pyld_sz = sizeof(struct ipa_ioc_add_flt_rule) +
647 sizeof(struct ipa_flt_rule_add);
648 param = kzalloc(pyld_sz, GFP_KERNEL);
649 if (!param)
650 return -ENOMEM;
651
652 req = (struct ipa_fltr_installed_notif_req_msg_v01 *)
653 kzalloc(sizeof(struct ipa_fltr_installed_notif_req_msg_v01),
654 GFP_KERNEL);
655 if (!req) {
656 kfree(param);
657 return -ENOMEM;
658 }
659
660 param->commit = 1;
Ghanim Fodic6b67492017-03-15 14:19:56 +0200661 param->ep = IPA_CLIENT_APPS_WAN_PROD;
Amir Levy9659e592016-10-27 18:08:27 +0300662 param->global = false;
663 param->num_rules = (uint8_t)1;
664
665 for (i = 0; i < rmnet_ipa3_ctx->num_q6_rules; i++) {
666 param->ip = ipa3_qmi_ctx->q6_ul_filter_rule[i].ip;
667 memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_add));
668 flt_rule_entry.at_rear = true;
669 flt_rule_entry.rule.action =
670 ipa3_qmi_ctx->q6_ul_filter_rule[i].action;
671 flt_rule_entry.rule.rt_tbl_idx
672 = ipa3_qmi_ctx->q6_ul_filter_rule[i].rt_tbl_idx;
673 flt_rule_entry.rule.retain_hdr = true;
674 flt_rule_entry.rule.hashable =
675 ipa3_qmi_ctx->q6_ul_filter_rule[i].is_rule_hashable;
676 flt_rule_entry.rule.rule_id =
677 ipa3_qmi_ctx->q6_ul_filter_rule[i].rule_id;
678
679 /* debug rt-hdl*/
680 IPAWANDBG("install-IPA index(%d),rt-tbl:(%d)\n",
681 i, flt_rule_entry.rule.rt_tbl_idx);
682 flt_rule_entry.rule.eq_attrib_type = true;
683 memcpy(&(flt_rule_entry.rule.eq_attrib),
684 &ipa3_qmi_ctx->q6_ul_filter_rule[i].eq_attrib,
685 sizeof(struct ipa_ipfltri_rule_eq));
686 memcpy(&(param->rules[0]), &flt_rule_entry,
687 sizeof(struct ipa_flt_rule_add));
688 if (ipa3_add_flt_rule((struct ipa_ioc_add_flt_rule *)param)) {
689 retval = -EFAULT;
690 IPAWANERR("add A7 UL filter rule(%d) failed\n", i);
691 } else {
692 /* store the rule handler */
693 ipa3_qmi_ctx->q6_ul_filter_rule_hdl[i] =
694 param->rules[0].flt_rule_hdl;
695 }
696 }
697
698 /* send ipa_fltr_installed_notif_req_msg_v01 to Q6*/
699 req->source_pipe_index =
Ghanim Fodic6b67492017-03-15 14:19:56 +0200700 ipa3_get_ep_mapping(IPA_CLIENT_APPS_WAN_PROD);
Amir Levy9659e592016-10-27 18:08:27 +0300701 req->install_status = QMI_RESULT_SUCCESS_V01;
702 req->rule_id_valid = 1;
703 req->rule_id_len = rmnet_ipa3_ctx->num_q6_rules;
704 for (i = 0; i < rmnet_ipa3_ctx->num_q6_rules; i++) {
705 req->rule_id[i] =
706 ipa3_qmi_ctx->q6_ul_filter_rule[i].rule_id;
707 }
708 if (ipa3_qmi_filter_notify_send(req)) {
709 IPAWANDBG("add filter rule index on A7-RX failed\n");
710 retval = -EFAULT;
711 }
712 rmnet_ipa3_ctx->old_num_q6_rules = rmnet_ipa3_ctx->num_q6_rules;
713 IPAWANDBG("add (%d) filter rule index on A7-RX\n",
714 rmnet_ipa3_ctx->old_num_q6_rules);
715 kfree(param);
716 kfree(req);
717 return retval;
718}
719
720static int ipa3_wwan_del_ul_flt_rule_to_ipa(void)
721{
722 u32 pyld_sz;
723 int i, retval = 0;
724 struct ipa_ioc_del_flt_rule *param;
725 struct ipa_flt_rule_del flt_rule_entry;
726
727 pyld_sz = sizeof(struct ipa_ioc_del_flt_rule) +
728 sizeof(struct ipa_flt_rule_del);
729 param = kzalloc(pyld_sz, GFP_KERNEL);
730 if (!param) {
731 IPAWANERR("kzalloc failed\n");
732 return -ENOMEM;
733 }
734
735 param->commit = 1;
736 param->num_hdls = (uint8_t) 1;
737
738 for (i = 0; i < rmnet_ipa3_ctx->old_num_q6_rules; i++) {
739 param->ip = ipa3_qmi_ctx->q6_ul_filter_rule[i].ip;
740 memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_del));
741 flt_rule_entry.hdl = ipa3_qmi_ctx->q6_ul_filter_rule_hdl[i];
742 /* debug rt-hdl*/
743 IPAWANDBG("delete-IPA rule index(%d)\n", i);
744 memcpy(&(param->hdl[0]), &flt_rule_entry,
745 sizeof(struct ipa_flt_rule_del));
746 if (ipa3_del_flt_rule((struct ipa_ioc_del_flt_rule *)param)) {
747 IPAWANERR("del A7 UL filter rule(%d) failed\n", i);
748 kfree(param);
749 return -EFAULT;
750 }
751 }
752
753 /* set UL filter-rule add-indication */
754 rmnet_ipa3_ctx->a7_ul_flt_set = false;
755 rmnet_ipa3_ctx->old_num_q6_rules = 0;
756
757 kfree(param);
758 return retval;
759}
760
761static int ipa3_find_mux_channel_index(uint32_t mux_id)
762{
763 int i;
764
765 for (i = 0; i < MAX_NUM_OF_MUX_CHANNEL; i++) {
766 if (mux_id == rmnet_ipa3_ctx->mux_channel[i].mux_id)
767 return i;
768 }
769 return MAX_NUM_OF_MUX_CHANNEL;
770}
771
772static int find_vchannel_name_index(const char *vchannel_name)
773{
774 int i;
775
776 for (i = 0; i < MAX_NUM_OF_MUX_CHANNEL; i++) {
777 if (strcmp(rmnet_ipa3_ctx->mux_channel[i].vchannel_name,
778 vchannel_name) == 0)
779 return i;
780 }
781 return MAX_NUM_OF_MUX_CHANNEL;
782}
783
784static int ipa3_wwan_register_to_ipa(int index)
785{
786 struct ipa_tx_intf tx_properties = {0};
787 struct ipa_ioc_tx_intf_prop tx_ioc_properties[2] = { {0}, {0} };
788 struct ipa_ioc_tx_intf_prop *tx_ipv4_property;
789 struct ipa_ioc_tx_intf_prop *tx_ipv6_property;
790 struct ipa_rx_intf rx_properties = {0};
791 struct ipa_ioc_rx_intf_prop rx_ioc_properties[2] = { {0}, {0} };
792 struct ipa_ioc_rx_intf_prop *rx_ipv4_property;
793 struct ipa_ioc_rx_intf_prop *rx_ipv6_property;
794 struct ipa_ext_intf ext_properties = {0};
795 struct ipa_ioc_ext_intf_prop *ext_ioc_properties;
796 u32 pyld_sz;
797 int ret = 0, i;
798
799 IPAWANDBG("index(%d) device[%s]:\n", index,
800 rmnet_ipa3_ctx->mux_channel[index].vchannel_name);
801 if (!rmnet_ipa3_ctx->mux_channel[index].mux_hdr_set) {
802 ret = ipa3_add_qmap_hdr(
803 rmnet_ipa3_ctx->mux_channel[index].mux_id,
804 &rmnet_ipa3_ctx->mux_channel[index].hdr_hdl);
805 if (ret) {
806 IPAWANERR("ipa_add_mux_hdr failed (%d)\n", index);
807 return ret;
808 }
809 rmnet_ipa3_ctx->mux_channel[index].mux_hdr_set = true;
810 }
811 tx_properties.prop = tx_ioc_properties;
812 tx_ipv4_property = &tx_properties.prop[0];
813 tx_ipv4_property->ip = IPA_IP_v4;
814 tx_ipv4_property->dst_pipe = IPA_CLIENT_APPS_WAN_CONS;
815 snprintf(tx_ipv4_property->hdr_name, IPA_RESOURCE_NAME_MAX, "%s%d",
816 A2_MUX_HDR_NAME_V4_PREF,
817 rmnet_ipa3_ctx->mux_channel[index].mux_id);
818 tx_ipv6_property = &tx_properties.prop[1];
819 tx_ipv6_property->ip = IPA_IP_v6;
820 tx_ipv6_property->dst_pipe = IPA_CLIENT_APPS_WAN_CONS;
821 /* no need use A2_MUX_HDR_NAME_V6_PREF, same header */
822 snprintf(tx_ipv6_property->hdr_name, IPA_RESOURCE_NAME_MAX, "%s%d",
823 A2_MUX_HDR_NAME_V4_PREF,
824 rmnet_ipa3_ctx->mux_channel[index].mux_id);
825 tx_properties.num_props = 2;
826
827 rx_properties.prop = rx_ioc_properties;
828 rx_ipv4_property = &rx_properties.prop[0];
829 rx_ipv4_property->ip = IPA_IP_v4;
830 rx_ipv4_property->attrib.attrib_mask |= IPA_FLT_META_DATA;
831 rx_ipv4_property->attrib.meta_data =
832 rmnet_ipa3_ctx->mux_channel[index].mux_id << WWAN_METADATA_SHFT;
833 rx_ipv4_property->attrib.meta_data_mask = WWAN_METADATA_MASK;
Ghanim Fodic6b67492017-03-15 14:19:56 +0200834 rx_ipv4_property->src_pipe = IPA_CLIENT_APPS_WAN_PROD;
Amir Levy9659e592016-10-27 18:08:27 +0300835 rx_ipv6_property = &rx_properties.prop[1];
836 rx_ipv6_property->ip = IPA_IP_v6;
837 rx_ipv6_property->attrib.attrib_mask |= IPA_FLT_META_DATA;
838 rx_ipv6_property->attrib.meta_data =
839 rmnet_ipa3_ctx->mux_channel[index].mux_id << WWAN_METADATA_SHFT;
840 rx_ipv6_property->attrib.meta_data_mask = WWAN_METADATA_MASK;
Ghanim Fodic6b67492017-03-15 14:19:56 +0200841 rx_ipv6_property->src_pipe = IPA_CLIENT_APPS_WAN_PROD;
Amir Levy9659e592016-10-27 18:08:27 +0300842 rx_properties.num_props = 2;
843
844 pyld_sz = rmnet_ipa3_ctx->num_q6_rules *
845 sizeof(struct ipa_ioc_ext_intf_prop);
846 ext_ioc_properties = kmalloc(pyld_sz, GFP_KERNEL);
847 if (!ext_ioc_properties) {
848 IPAWANERR("Error allocate memory\n");
849 return -ENOMEM;
850 }
851
852 ext_properties.prop = ext_ioc_properties;
853 ext_properties.excp_pipe_valid = true;
854 ext_properties.excp_pipe = IPA_CLIENT_APPS_WAN_CONS;
855 ext_properties.num_props = rmnet_ipa3_ctx->num_q6_rules;
856 for (i = 0; i < rmnet_ipa3_ctx->num_q6_rules; i++) {
857 memcpy(&(ext_properties.prop[i]),
858 &(ipa3_qmi_ctx->q6_ul_filter_rule[i]),
859 sizeof(struct ipa_ioc_ext_intf_prop));
860 ext_properties.prop[i].mux_id =
861 rmnet_ipa3_ctx->mux_channel[index].mux_id;
862 IPAWANDBG("index %d ip: %d rt-tbl:%d\n", i,
863 ext_properties.prop[i].ip,
864 ext_properties.prop[i].rt_tbl_idx);
865 IPAWANDBG("action: %d mux:%d\n",
866 ext_properties.prop[i].action,
867 ext_properties.prop[i].mux_id);
868 }
869 ret = ipa3_register_intf_ext(rmnet_ipa3_ctx->mux_channel[index].
870 vchannel_name, &tx_properties,
871 &rx_properties, &ext_properties);
872 if (ret) {
873 IPAWANERR("[%s]:ipa3_register_intf failed %d\n",
874 rmnet_ipa3_ctx->mux_channel[index].vchannel_name, ret);
875 goto fail;
876 }
877 rmnet_ipa3_ctx->mux_channel[index].ul_flt_reg = true;
878fail:
879 kfree(ext_ioc_properties);
880 return ret;
881}
882
883static void ipa3_cleanup_deregister_intf(void)
884{
885 int i;
886 int ret;
887
888 for (i = 0; i < rmnet_ipa3_ctx->rmnet_index; i++) {
889 if (rmnet_ipa3_ctx->mux_channel[i].ul_flt_reg) {
890 ret = ipa3_deregister_intf(
891 rmnet_ipa3_ctx->mux_channel[i].vchannel_name);
892 if (ret < 0) {
893 IPAWANERR("de-register device %s(%d) failed\n",
894 rmnet_ipa3_ctx->mux_channel[i].
895 vchannel_name,
896 i);
897 return;
898 }
899 IPAWANDBG("de-register device %s(%d) success\n",
900 rmnet_ipa3_ctx->mux_channel[i].vchannel_name,
901 i);
902 }
903 rmnet_ipa3_ctx->mux_channel[i].ul_flt_reg = false;
904 }
905}
906
907int ipa3_wwan_update_mux_channel_prop(void)
908{
909 int ret = 0, i;
910 /* install UL filter rules */
911 if (rmnet_ipa3_ctx->egress_set) {
912 if (ipa3_qmi_ctx->modem_cfg_emb_pipe_flt == false) {
913 IPAWANDBG("setup UL filter rules\n");
914 if (rmnet_ipa3_ctx->a7_ul_flt_set) {
915 IPAWANDBG("del previous UL filter rules\n");
916 /* delete rule hdlers */
917 ret = ipa3_wwan_del_ul_flt_rule_to_ipa();
918 if (ret) {
919 IPAWANERR("failed to del old rules\n");
920 return -EINVAL;
921 }
922 IPAWANDBG("deleted old UL rules\n");
923 }
924 ret = ipa3_wwan_add_ul_flt_rule_to_ipa();
925 }
926 if (ret)
927 IPAWANERR("failed to install UL rules\n");
928 else
929 rmnet_ipa3_ctx->a7_ul_flt_set = true;
930 }
931 /* update Tx/Rx/Ext property */
932 IPAWANDBG("update Tx/Rx/Ext property in IPA\n");
933 if (rmnet_ipa3_ctx->rmnet_index == 0) {
934 IPAWANDBG("no Tx/Rx/Ext property registered in IPA\n");
935 return ret;
936 }
937
938 ipa3_cleanup_deregister_intf();
939
940 for (i = 0; i < rmnet_ipa3_ctx->rmnet_index; i++) {
941 ret = ipa3_wwan_register_to_ipa(i);
942 if (ret < 0) {
943 IPAWANERR("failed to re-regist %s, mux %d, index %d\n",
944 rmnet_ipa3_ctx->mux_channel[i].vchannel_name,
945 rmnet_ipa3_ctx->mux_channel[i].mux_id,
946 i);
947 return -ENODEV;
948 }
949 IPAWANERR("dev(%s) has registered to IPA\n",
950 rmnet_ipa3_ctx->mux_channel[i].vchannel_name);
951 rmnet_ipa3_ctx->mux_channel[i].ul_flt_reg = true;
952 }
953 return ret;
954}
955
956#ifdef INIT_COMPLETION
957#define reinit_completion(x) INIT_COMPLETION(*(x))
958#endif /* INIT_COMPLETION */
959
960static int __ipa_wwan_open(struct net_device *dev)
961{
962 struct ipa3_wwan_private *wwan_ptr = netdev_priv(dev);
963
964 IPAWANDBG("[%s] __wwan_open()\n", dev->name);
965 if (wwan_ptr->device_status != WWAN_DEVICE_ACTIVE)
966 reinit_completion(&wwan_ptr->resource_granted_completion);
967 wwan_ptr->device_status = WWAN_DEVICE_ACTIVE;
968
969 if (ipa3_rmnet_res.ipa_napi_enable)
970 napi_enable(&(wwan_ptr->napi));
971 return 0;
972}
973
974/**
975 * wwan_open() - Opens the wwan network interface. Opens logical
976 * channel on A2 MUX driver and starts the network stack queue
977 *
978 * @dev: network device
979 *
980 * Return codes:
981 * 0: success
982 * -ENODEV: Error while opening logical channel on A2 MUX driver
983 */
984static int ipa3_wwan_open(struct net_device *dev)
985{
986 int rc = 0;
987
988 IPAWANDBG("[%s] wwan_open()\n", dev->name);
989 rc = __ipa_wwan_open(dev);
990 if (rc == 0)
991 netif_start_queue(dev);
992 return rc;
993}
994
995static int __ipa_wwan_close(struct net_device *dev)
996{
997 struct ipa3_wwan_private *wwan_ptr = netdev_priv(dev);
998 int rc = 0;
999
1000 if (wwan_ptr->device_status == WWAN_DEVICE_ACTIVE) {
1001 wwan_ptr->device_status = WWAN_DEVICE_INACTIVE;
1002 /* do not close wwan port once up, this causes
1003 * remote side to hang if tried to open again
1004 */
1005 reinit_completion(&wwan_ptr->resource_granted_completion);
1006 rc = ipa3_deregister_intf(dev->name);
1007 if (rc) {
1008 IPAWANERR("[%s]: ipa3_deregister_intf failed %d\n",
1009 dev->name, rc);
1010 return rc;
1011 }
1012 return rc;
1013 } else {
1014 return -EBADF;
1015 }
1016}
1017
1018/**
1019 * ipa3_wwan_stop() - Stops the wwan network interface. Closes
1020 * logical channel on A2 MUX driver and stops the network stack
1021 * 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 */
1029static int ipa3_wwan_stop(struct net_device *dev)
1030{
1031 IPAWANDBG("[%s] ipa3_wwan_stop()\n", dev->name);
1032 __ipa_wwan_close(dev);
1033 netif_stop_queue(dev);
1034 return 0;
1035}
1036
1037static int ipa3_wwan_change_mtu(struct net_device *dev, int new_mtu)
1038{
1039 if (0 > new_mtu || WWAN_DATA_LEN < new_mtu)
1040 return -EINVAL;
1041 IPAWANDBG("[%s] MTU change: old=%d new=%d\n",
1042 dev->name, dev->mtu, new_mtu);
1043 dev->mtu = new_mtu;
1044 return 0;
1045}
1046
1047/**
1048 * ipa3_wwan_xmit() - Transmits an skb.
1049 *
1050 * @skb: skb to be transmitted
1051 * @dev: network device
1052 *
1053 * Return codes:
1054 * 0: success
1055 * NETDEV_TX_BUSY: Error while transmitting the skb. Try again
1056 * later
1057 * -EFAULT: Error while transmitting the skb
1058 */
1059static int ipa3_wwan_xmit(struct sk_buff *skb, struct net_device *dev)
1060{
1061 int ret = 0;
1062 bool qmap_check;
1063 struct ipa3_wwan_private *wwan_ptr = netdev_priv(dev);
1064 struct ipa_tx_meta meta;
1065
1066 if (skb->protocol != htons(ETH_P_MAP)) {
1067 IPAWANDBG_LOW
1068 ("SW filtering out none QMAP packet received from %s",
1069 current->comm);
1070 return NETDEV_TX_OK;
1071 }
1072
1073 qmap_check = RMNET_MAP_GET_CD_BIT(skb);
1074 if (netif_queue_stopped(dev)) {
1075 if (qmap_check &&
1076 atomic_read(&wwan_ptr->outstanding_pkts) <
1077 wwan_ptr->outstanding_high_ctl) {
1078 pr_err("[%s]Queue stop, send ctrl pkts\n", dev->name);
1079 goto send;
1080 } else {
1081 pr_err("[%s]fatal: ipa_wwan_xmit stopped\n", dev->name);
1082 return NETDEV_TX_BUSY;
1083 }
1084 }
1085
1086 /* checking High WM hit */
1087 if (atomic_read(&wwan_ptr->outstanding_pkts) >=
1088 wwan_ptr->outstanding_high) {
1089 if (!qmap_check) {
1090 IPAWANDBG_LOW("pending(%d)/(%d)- stop(%d)\n",
1091 atomic_read(&wwan_ptr->outstanding_pkts),
1092 wwan_ptr->outstanding_high,
1093 netif_queue_stopped(dev));
1094 IPAWANDBG_LOW("qmap_chk(%d)\n", qmap_check);
1095 netif_stop_queue(dev);
1096 return NETDEV_TX_BUSY;
1097 }
1098 }
1099
1100send:
1101 /* IPA_RM checking start */
1102 ret = ipa_rm_inactivity_timer_request_resource(
1103 IPA_RM_RESOURCE_WWAN_0_PROD);
1104 if (ret == -EINPROGRESS) {
1105 netif_stop_queue(dev);
1106 return NETDEV_TX_BUSY;
1107 }
1108 if (ret) {
1109 pr_err("[%s] fatal: ipa rm timer request resource failed %d\n",
1110 dev->name, ret);
1111 return -EFAULT;
1112 }
1113 /* IPA_RM checking end */
1114
1115 if (RMNET_MAP_GET_CD_BIT(skb)) {
1116 memset(&meta, 0, sizeof(meta));
1117 meta.pkt_init_dst_ep_valid = true;
1118 meta.pkt_init_dst_ep_remote = true;
Ghanim Fodic6b67492017-03-15 14:19:56 +02001119 meta.pkt_init_dst_ep = IPA_CLIENT_Q6_LAN_CONS;
1120 ret = ipa3_tx_dp(IPA_CLIENT_APPS_WAN_PROD, skb, &meta);
Amir Levy9659e592016-10-27 18:08:27 +03001121 } else {
Ghanim Fodic6b67492017-03-15 14:19:56 +02001122 ret = ipa3_tx_dp(IPA_CLIENT_APPS_WAN_PROD, skb, NULL);
Amir Levy9659e592016-10-27 18:08:27 +03001123 }
1124
1125 if (ret) {
1126 ret = NETDEV_TX_BUSY;
1127 dev->stats.tx_dropped++;
1128 goto out;
1129 }
1130
1131 atomic_inc(&wwan_ptr->outstanding_pkts);
1132 dev->stats.tx_packets++;
1133 dev->stats.tx_bytes += skb->len;
1134 ret = NETDEV_TX_OK;
1135out:
Skylar Changf3a7dac2017-01-25 09:16:55 -08001136 if (atomic_read(&wwan_ptr->outstanding_pkts) == 0)
1137 ipa_rm_inactivity_timer_release_resource(
1138 IPA_RM_RESOURCE_WWAN_0_PROD);
Amir Levy9659e592016-10-27 18:08:27 +03001139 return ret;
1140}
1141
1142static void ipa3_wwan_tx_timeout(struct net_device *dev)
1143{
1144 IPAWANERR("[%s] ipa3_wwan_tx_timeout(), data stall in UL\n", dev->name);
1145}
1146
1147/**
1148 * apps_ipa_tx_complete_notify() - Rx notify
1149 *
1150 * @priv: driver context
1151 * @evt: event type
1152 * @data: data provided with event
1153 *
1154 * Check that the packet is the one we sent and release it
1155 * This function will be called in defered context in IPA wq.
1156 */
1157static void apps_ipa_tx_complete_notify(void *priv,
1158 enum ipa_dp_evt_type evt,
1159 unsigned long data)
1160{
1161 struct sk_buff *skb = (struct sk_buff *)data;
1162 struct net_device *dev = (struct net_device *)priv;
1163 struct ipa3_wwan_private *wwan_ptr;
1164
1165 if (dev != IPA_NETDEV()) {
1166 IPAWANDBG("Received pre-SSR packet completion\n");
1167 dev_kfree_skb_any(skb);
1168 return;
1169 }
1170
1171 if (evt != IPA_WRITE_DONE) {
1172 IPAWANERR("unsupported evt on Tx callback, Drop the packet\n");
1173 dev_kfree_skb_any(skb);
1174 dev->stats.tx_dropped++;
1175 return;
1176 }
1177
1178 wwan_ptr = netdev_priv(dev);
1179 atomic_dec(&wwan_ptr->outstanding_pkts);
1180 __netif_tx_lock_bh(netdev_get_tx_queue(dev, 0));
1181 if (!atomic_read(&rmnet_ipa3_ctx->is_ssr) &&
1182 netif_queue_stopped(wwan_ptr->net) &&
1183 atomic_read(&wwan_ptr->outstanding_pkts) <
1184 (wwan_ptr->outstanding_low)) {
1185 IPAWANDBG_LOW("Outstanding low (%d) - waking up queue\n",
1186 wwan_ptr->outstanding_low);
1187 netif_wake_queue(wwan_ptr->net);
1188 }
Skylar Changf3a7dac2017-01-25 09:16:55 -08001189
1190 if (atomic_read(&wwan_ptr->outstanding_pkts) == 0)
1191 ipa_rm_inactivity_timer_release_resource(
1192 IPA_RM_RESOURCE_WWAN_0_PROD);
Amir Levy9659e592016-10-27 18:08:27 +03001193 __netif_tx_unlock_bh(netdev_get_tx_queue(dev, 0));
1194 dev_kfree_skb_any(skb);
Amir Levy9659e592016-10-27 18:08:27 +03001195}
1196
1197/**
1198 * apps_ipa_packet_receive_notify() - Rx notify
1199 *
1200 * @priv: driver context
1201 * @evt: event type
1202 * @data: data provided with event
1203 *
1204 * IPA will pass a packet to the Linux network stack with skb->data
1205 */
1206static void apps_ipa_packet_receive_notify(void *priv,
1207 enum ipa_dp_evt_type evt,
1208 unsigned long data)
1209{
1210 struct net_device *dev = (struct net_device *)priv;
1211
1212 if (evt == IPA_RECEIVE) {
1213 struct sk_buff *skb = (struct sk_buff *)data;
1214 int result;
1215 unsigned int packet_len = skb->len;
1216
1217 IPAWANDBG_LOW("Rx packet was received");
1218 skb->dev = IPA_NETDEV();
1219 skb->protocol = htons(ETH_P_MAP);
1220
1221 if (ipa3_rmnet_res.ipa_napi_enable) {
1222 trace_rmnet_ipa_netif_rcv_skb3(dev->stats.rx_packets);
1223 result = netif_receive_skb(skb);
1224 } else {
1225 if (dev->stats.rx_packets % IPA_WWAN_RX_SOFTIRQ_THRESH
1226 == 0) {
1227 trace_rmnet_ipa_netifni3(dev->stats.rx_packets);
1228 result = netif_rx_ni(skb);
1229 } else {
1230 trace_rmnet_ipa_netifrx3(dev->stats.rx_packets);
1231 result = netif_rx(skb);
1232 }
1233 }
1234
1235 if (result) {
1236 pr_err_ratelimited(DEV_NAME " %s:%d fail on netif_receive_skb\n",
1237 __func__, __LINE__);
1238 dev->stats.rx_dropped++;
1239 }
1240 dev->stats.rx_packets++;
1241 dev->stats.rx_bytes += packet_len;
1242 } else if (evt == IPA_CLIENT_START_POLL)
1243 ipa3_rmnet_rx_cb(priv);
1244 else if (evt == IPA_CLIENT_COMP_NAPI) {
1245 if (ipa3_rmnet_res.ipa_napi_enable)
1246 napi_complete(&(rmnet_ipa3_ctx->wwan_priv->napi));
1247 } else
1248 IPAWANERR("Invalid evt %d received in wan_ipa_receive\n", evt);
1249}
1250
Gidon Studinski3021a6f2016-11-10 12:48:48 +02001251static int handle3_ingress_format(struct net_device *dev,
1252 struct rmnet_ioctl_extended_s *in)
1253{
1254 int ret = 0;
1255 struct ipa_sys_connect_params *ipa_wan_ep_cfg;
1256 struct rmnet_phys_ep_conf_s *ep_cfg;
1257
1258 IPAWANDBG("Get RMNET_IOCTL_SET_INGRESS_DATA_FORMAT\n");
1259 ipa_wan_ep_cfg = &rmnet_ipa3_ctx->ipa_to_apps_ep_cfg;
1260 if ((in->u.data) & RMNET_IOCTL_INGRESS_FORMAT_CHECKSUM)
1261 ipa_wan_ep_cfg->ipa_ep_cfg.cfg.cs_offload_en =
1262 IPA_ENABLE_CS_OFFLOAD_DL;
1263
1264 if ((in->u.data) & RMNET_IOCTL_INGRESS_FORMAT_AGG_DATA) {
Ghanim Fodic6b67492017-03-15 14:19:56 +02001265 IPAWANDBG("get AGG size %d count %d\n",
Gidon Studinski3021a6f2016-11-10 12:48:48 +02001266 in->u.ingress_format.agg_size,
1267 in->u.ingress_format.agg_count);
1268
1269 ret = ipa_disable_apps_wan_cons_deaggr(
1270 in->u.ingress_format.agg_size,
1271 in->u.ingress_format.agg_count);
1272
1273 if (!ret) {
1274 ipa_wan_ep_cfg->ipa_ep_cfg.aggr.aggr_byte_limit =
1275 in->u.ingress_format.agg_size;
1276 ipa_wan_ep_cfg->ipa_ep_cfg.aggr.aggr_pkt_limit =
1277 in->u.ingress_format.agg_count;
1278
1279 if (ipa_wan_ep_cfg->napi_enabled) {
1280 ipa_wan_ep_cfg->recycle_enabled = true;
1281 ep_cfg = (struct rmnet_phys_ep_conf_s *)
1282 rcu_dereference(dev->rx_handler_data);
1283 ep_cfg->recycle = ipa_recycle_wan_skb;
1284 pr_info("Wan Recycle Enabled\n");
1285 }
1286 }
1287 }
1288
1289 ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_len = 4;
1290 ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
1291 ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_metadata = 1;
1292 ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
1293 ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 2;
1294
1295 ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad_valid = true;
1296 ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad = 0;
1297 ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_payload_len_inc_padding = true;
1298 ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad_offset = 0;
1299 ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_little_endian = 0;
1300 ipa_wan_ep_cfg->ipa_ep_cfg.metadata_mask.metadata_mask = 0xFF000000;
1301
1302 ipa_wan_ep_cfg->client = IPA_CLIENT_APPS_WAN_CONS;
1303 ipa_wan_ep_cfg->notify = apps_ipa_packet_receive_notify;
1304 ipa_wan_ep_cfg->priv = dev;
1305
1306 ipa_wan_ep_cfg->napi_enabled = ipa3_rmnet_res.ipa_napi_enable;
1307 if (ipa_wan_ep_cfg->napi_enabled)
1308 ipa_wan_ep_cfg->desc_fifo_sz = IPA_WAN_CONS_DESC_FIFO_SZ;
1309 else
1310 ipa_wan_ep_cfg->desc_fifo_sz = IPA_SYS_DESC_FIFO_SZ;
1311
Ghanim Fodic6b67492017-03-15 14:19:56 +02001312 mutex_lock(&rmnet_ipa3_ctx->pipe_handle_guard);
Gidon Studinski3021a6f2016-11-10 12:48:48 +02001313
1314 if (atomic_read(&rmnet_ipa3_ctx->is_ssr)) {
1315 IPAWANDBG("In SSR sequence/recovery\n");
Ghanim Fodic6b67492017-03-15 14:19:56 +02001316 mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard);
Gidon Studinski3021a6f2016-11-10 12:48:48 +02001317 return -EFAULT;
1318 }
1319 ret = ipa3_setup_sys_pipe(&rmnet_ipa3_ctx->ipa_to_apps_ep_cfg,
1320 &rmnet_ipa3_ctx->ipa3_to_apps_hdl);
1321
Ghanim Fodic6b67492017-03-15 14:19:56 +02001322 mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard);
Gidon Studinski3021a6f2016-11-10 12:48:48 +02001323
1324 if (ret)
1325 IPAWANERR("failed to configure ingress\n");
1326
1327 return ret;
1328}
1329
Amir Levy9659e592016-10-27 18:08:27 +03001330/**
Ghanim Fodic6b67492017-03-15 14:19:56 +02001331 * handle3_egress_format() - Egress data format configuration
1332 *
1333 * Setup IPA egress system pipe and Configure:
1334 * header handling, checksum, de-aggregation and fifo size
1335 *
1336 * @dev: network device
1337 * @e: egress configuration
1338 */
1339static int handle3_egress_format(struct net_device *dev,
1340 struct rmnet_ioctl_extended_s *e)
1341{
1342 int rc;
1343 struct ipa_sys_connect_params *ipa_wan_ep_cfg;
1344
1345 IPAWANDBG("get RMNET_IOCTL_SET_EGRESS_DATA_FORMAT\n");
1346 ipa_wan_ep_cfg = &rmnet_ipa3_ctx->apps_to_ipa_ep_cfg;
1347 if ((e->u.data) & RMNET_IOCTL_EGRESS_FORMAT_CHECKSUM) {
1348 ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_len = 8;
1349 ipa_wan_ep_cfg->ipa_ep_cfg.cfg.cs_offload_en =
1350 IPA_ENABLE_CS_OFFLOAD_UL;
1351 ipa_wan_ep_cfg->ipa_ep_cfg.cfg.cs_metadata_hdr_offset = 1;
1352 } else {
1353 ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_len = 4;
1354 }
1355
1356 if ((e->u.data) & RMNET_IOCTL_EGRESS_FORMAT_AGGREGATION) {
1357 IPAWANERR("WAN UL Aggregation not supported!!\n");
1358 WARN_ON(1);
1359 return -EINVAL;
1360 ipa_wan_ep_cfg->ipa_ep_cfg.aggr.aggr_en = IPA_ENABLE_DEAGGR;
1361 ipa_wan_ep_cfg->ipa_ep_cfg.aggr.aggr = IPA_QCMAP;
1362
1363 ipa_wan_ep_cfg->ipa_ep_cfg.deaggr.packet_offset_valid = false;
1364
1365 ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 2;
1366
1367 ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad_valid =
1368 true;
1369 ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad =
1370 IPA_HDR_PAD;
1371 ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_pad_to_alignment =
1372 2;
1373 ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_payload_len_inc_padding =
1374 true;
1375 ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad_offset =
1376 0;
1377 ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_little_endian =
1378 false;
1379 } else {
1380 IPAWANDBG("WAN UL Aggregation disabled\n");
1381 ipa_wan_ep_cfg->ipa_ep_cfg.aggr.aggr_en = IPA_BYPASS_AGGR;
1382 }
1383
1384 ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
1385 /* modem want offset at 0! */
1386 ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_metadata = 0;
1387
1388 ipa_wan_ep_cfg->ipa_ep_cfg.mode.dst = IPA_CLIENT_APPS_WAN_PROD;
1389 ipa_wan_ep_cfg->ipa_ep_cfg.mode.mode = IPA_BASIC;
1390
1391 ipa_wan_ep_cfg->client = IPA_CLIENT_APPS_WAN_PROD;
1392 ipa_wan_ep_cfg->notify = apps_ipa_tx_complete_notify;
1393 ipa_wan_ep_cfg->desc_fifo_sz = IPA_SYS_TX_DATA_DESC_FIFO_SZ;
1394 ipa_wan_ep_cfg->priv = dev;
1395
1396 mutex_lock(&rmnet_ipa3_ctx->pipe_handle_guard);
1397 if (atomic_read(&rmnet_ipa3_ctx->is_ssr)) {
1398 IPAWANDBG("In SSR sequence/recovery\n");
1399 mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard);
1400 return -EFAULT;
1401 }
1402 rc = ipa3_setup_sys_pipe(
1403 ipa_wan_ep_cfg, &rmnet_ipa3_ctx->apps_to_ipa3_hdl);
1404 if (rc) {
1405 IPAWANERR("failed to config egress endpoint\n");
1406 mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard);
1407 return rc;
1408 }
1409 mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard);
1410
1411 if (rmnet_ipa3_ctx->num_q6_rules != 0) {
1412 /* already got Q6 UL filter rules*/
1413 if (ipa3_qmi_ctx->modem_cfg_emb_pipe_flt == false)
1414 rc = ipa3_wwan_add_ul_flt_rule_to_ipa();
1415 if (rc)
1416 IPAWANERR("install UL rules failed\n");
1417 else
1418 rmnet_ipa3_ctx->a7_ul_flt_set = true;
1419 } else {
1420 /* wait Q6 UL filter rules*/
1421 IPAWANDBG("no UL-rules\n");
1422 }
1423 rmnet_ipa3_ctx->egress_set = true;
1424
1425 return rc;
1426}
1427
1428/**
Amir Levy9659e592016-10-27 18:08:27 +03001429 * ipa3_wwan_ioctl() - I/O control for wwan network driver.
1430 *
1431 * @dev: network device
1432 * @ifr: ignored
1433 * @cmd: cmd to be excecuded. can be one of the following:
1434 * IPA_WWAN_IOCTL_OPEN - Open the network interface
1435 * IPA_WWAN_IOCTL_CLOSE - Close the network interface
1436 *
1437 * Return codes:
1438 * 0: success
1439 * NETDEV_TX_BUSY: Error while transmitting the skb. Try again
1440 * later
1441 * -EFAULT: Error while transmitting the skb
1442 */
1443static int ipa3_wwan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1444{
1445 int rc = 0;
1446 int mru = 1000, epid = 1, mux_index, len;
1447 struct ipa_msg_meta msg_meta;
1448 struct ipa_wan_msg *wan_msg = NULL;
1449 struct rmnet_ioctl_extended_s extend_ioctl_data;
1450 struct rmnet_ioctl_data_s ioctl_data;
1451 struct ipa3_rmnet_mux_val *mux_channel;
1452 int rmnet_index;
1453
1454 IPAWANDBG("rmnet_ipa got ioctl number 0x%08x", cmd);
1455 switch (cmd) {
1456 /* Set Ethernet protocol */
1457 case RMNET_IOCTL_SET_LLP_ETHERNET:
1458 break;
1459 /* Set RAWIP protocol */
1460 case RMNET_IOCTL_SET_LLP_IP:
1461 break;
1462 /* Get link protocol */
1463 case RMNET_IOCTL_GET_LLP:
1464 ioctl_data.u.operation_mode = RMNET_MODE_LLP_IP;
1465 if (copy_to_user(ifr->ifr_ifru.ifru_data, &ioctl_data,
1466 sizeof(struct rmnet_ioctl_data_s)))
1467 rc = -EFAULT;
1468 break;
1469 /* Set QoS header enabled */
1470 case RMNET_IOCTL_SET_QOS_ENABLE:
1471 return -EINVAL;
1472 /* Set QoS header disabled */
1473 case RMNET_IOCTL_SET_QOS_DISABLE:
1474 break;
1475 /* Get QoS header state */
1476 case RMNET_IOCTL_GET_QOS:
1477 ioctl_data.u.operation_mode = RMNET_MODE_NONE;
1478 if (copy_to_user(ifr->ifr_ifru.ifru_data, &ioctl_data,
1479 sizeof(struct rmnet_ioctl_data_s)))
1480 rc = -EFAULT;
1481 break;
1482 /* Get operation mode */
1483 case RMNET_IOCTL_GET_OPMODE:
1484 ioctl_data.u.operation_mode = RMNET_MODE_LLP_IP;
1485 if (copy_to_user(ifr->ifr_ifru.ifru_data, &ioctl_data,
1486 sizeof(struct rmnet_ioctl_data_s)))
1487 rc = -EFAULT;
1488 break;
1489 /* Open transport port */
1490 case RMNET_IOCTL_OPEN:
1491 break;
1492 /* Close transport port */
1493 case RMNET_IOCTL_CLOSE:
1494 break;
1495 /* Flow enable */
1496 case RMNET_IOCTL_FLOW_ENABLE:
1497 IPAWANDBG("Received flow enable\n");
1498 if (copy_from_user(&ioctl_data, ifr->ifr_ifru.ifru_data,
1499 sizeof(struct rmnet_ioctl_data_s))) {
1500 rc = -EFAULT;
1501 break;
1502 }
1503 ipa3_flow_control(IPA_CLIENT_USB_PROD, true,
1504 ioctl_data.u.tcm_handle);
1505 break;
1506 /* Flow disable */
1507 case RMNET_IOCTL_FLOW_DISABLE:
1508 IPAWANDBG("Received flow disable\n");
1509 if (copy_from_user(&ioctl_data, ifr->ifr_ifru.ifru_data,
1510 sizeof(struct rmnet_ioctl_data_s))) {
1511 rc = -EFAULT;
1512 break;
1513 }
1514 ipa3_flow_control(IPA_CLIENT_USB_PROD, false,
1515 ioctl_data.u.tcm_handle);
1516 break;
1517 /* Set flow handle */
1518 case RMNET_IOCTL_FLOW_SET_HNDL:
1519 break;
1520
1521 /* Extended IOCTLs */
1522 case RMNET_IOCTL_EXTENDED:
1523 IPAWANDBG("get ioctl: RMNET_IOCTL_EXTENDED\n");
1524 if (copy_from_user(&extend_ioctl_data,
1525 (u8 *)ifr->ifr_ifru.ifru_data,
1526 sizeof(struct rmnet_ioctl_extended_s))) {
1527 IPAWANERR("failed to copy extended ioctl data\n");
1528 rc = -EFAULT;
1529 break;
1530 }
1531 switch (extend_ioctl_data.extended_ioctl) {
1532 /* Get features */
1533 case RMNET_IOCTL_GET_SUPPORTED_FEATURES:
1534 IPAWANDBG("get RMNET_IOCTL_GET_SUPPORTED_FEATURES\n");
1535 extend_ioctl_data.u.data =
1536 (RMNET_IOCTL_FEAT_NOTIFY_MUX_CHANNEL |
1537 RMNET_IOCTL_FEAT_SET_EGRESS_DATA_FORMAT |
1538 RMNET_IOCTL_FEAT_SET_INGRESS_DATA_FORMAT);
1539 if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data,
1540 &extend_ioctl_data,
1541 sizeof(struct rmnet_ioctl_extended_s)))
1542 rc = -EFAULT;
1543 break;
1544 /* Set MRU */
1545 case RMNET_IOCTL_SET_MRU:
1546 mru = extend_ioctl_data.u.data;
1547 IPAWANDBG("get MRU size %d\n",
1548 extend_ioctl_data.u.data);
1549 break;
1550 /* Get MRU */
1551 case RMNET_IOCTL_GET_MRU:
1552 extend_ioctl_data.u.data = mru;
1553 if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data,
1554 &extend_ioctl_data,
1555 sizeof(struct rmnet_ioctl_extended_s)))
1556 rc = -EFAULT;
1557 break;
1558 /* GET SG support */
1559 case RMNET_IOCTL_GET_SG_SUPPORT:
1560 extend_ioctl_data.u.data =
1561 ipa3_rmnet_res.ipa_advertise_sg_support;
1562 if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data,
1563 &extend_ioctl_data,
1564 sizeof(struct rmnet_ioctl_extended_s)))
1565 rc = -EFAULT;
1566 break;
1567 /* Get endpoint ID */
1568 case RMNET_IOCTL_GET_EPID:
1569 IPAWANDBG("get ioctl: RMNET_IOCTL_GET_EPID\n");
1570 extend_ioctl_data.u.data = epid;
1571 if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data,
1572 &extend_ioctl_data,
1573 sizeof(struct rmnet_ioctl_extended_s)))
1574 rc = -EFAULT;
1575 if (copy_from_user(&extend_ioctl_data,
1576 (u8 *)ifr->ifr_ifru.ifru_data,
1577 sizeof(struct rmnet_ioctl_extended_s))) {
1578 IPAWANERR("copy extended ioctl data failed\n");
1579 rc = -EFAULT;
1580 break;
1581 }
1582 IPAWANDBG("RMNET_IOCTL_GET_EPID return %d\n",
1583 extend_ioctl_data.u.data);
1584 break;
1585 /* Endpoint pair */
1586 case RMNET_IOCTL_GET_EP_PAIR:
1587 IPAWANDBG("get ioctl: RMNET_IOCTL_GET_EP_PAIR\n");
1588 extend_ioctl_data.u.ipa_ep_pair.consumer_pipe_num =
Ghanim Fodic6b67492017-03-15 14:19:56 +02001589 ipa3_get_ep_mapping(IPA_CLIENT_APPS_WAN_PROD);
Amir Levy9659e592016-10-27 18:08:27 +03001590 extend_ioctl_data.u.ipa_ep_pair.producer_pipe_num =
1591 ipa3_get_ep_mapping(IPA_CLIENT_APPS_WAN_CONS);
1592 if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data,
1593 &extend_ioctl_data,
1594 sizeof(struct rmnet_ioctl_extended_s)))
1595 rc = -EFAULT;
1596 if (copy_from_user(&extend_ioctl_data,
1597 (u8 *)ifr->ifr_ifru.ifru_data,
1598 sizeof(struct rmnet_ioctl_extended_s))) {
1599 IPAWANERR("copy extended ioctl data failed\n");
1600 rc = -EFAULT;
1601 break;
1602 }
1603 IPAWANDBG("RMNET_IOCTL_GET_EP_PAIR c: %d p: %d\n",
1604 extend_ioctl_data.u.ipa_ep_pair.consumer_pipe_num,
1605 extend_ioctl_data.u.ipa_ep_pair.producer_pipe_num);
1606 break;
1607 /* Get driver name */
1608 case RMNET_IOCTL_GET_DRIVER_NAME:
1609 memcpy(&extend_ioctl_data.u.if_name,
1610 IPA_NETDEV()->name,
1611 sizeof(IFNAMSIZ));
1612 if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data,
1613 &extend_ioctl_data,
1614 sizeof(struct rmnet_ioctl_extended_s)))
1615 rc = -EFAULT;
1616 break;
1617 /* Add MUX ID */
1618 case RMNET_IOCTL_ADD_MUX_CHANNEL:
1619 mux_index = ipa3_find_mux_channel_index(
1620 extend_ioctl_data.u.rmnet_mux_val.mux_id);
1621 if (mux_index < MAX_NUM_OF_MUX_CHANNEL) {
1622 IPAWANDBG("already setup mux(%d)\n",
1623 extend_ioctl_data.u.
1624 rmnet_mux_val.mux_id);
1625 return rc;
1626 }
1627 if (rmnet_ipa3_ctx->rmnet_index
1628 >= MAX_NUM_OF_MUX_CHANNEL) {
1629 IPAWANERR("Exceed mux_channel limit(%d)\n",
1630 rmnet_ipa3_ctx->rmnet_index);
1631 return -EFAULT;
1632 }
1633 IPAWANDBG("ADD_MUX_CHANNEL(%d, name: %s)\n",
1634 extend_ioctl_data.u.rmnet_mux_val.mux_id,
1635 extend_ioctl_data.u.rmnet_mux_val.vchannel_name);
1636 /* cache the mux name and id */
1637 mux_channel = rmnet_ipa3_ctx->mux_channel;
1638 rmnet_index = rmnet_ipa3_ctx->rmnet_index;
1639
1640 mux_channel[rmnet_index].mux_id =
1641 extend_ioctl_data.u.rmnet_mux_val.mux_id;
1642 memcpy(mux_channel[rmnet_index].vchannel_name,
1643 extend_ioctl_data.u.rmnet_mux_val.vchannel_name,
1644 sizeof(mux_channel[rmnet_index]
1645 .vchannel_name));
1646 IPAWANDBG("cashe device[%s:%d] in IPA_wan[%d]\n",
1647 mux_channel[rmnet_index].vchannel_name,
1648 mux_channel[rmnet_index].mux_id,
1649 rmnet_index);
1650 /* check if UL filter rules coming*/
1651 if (rmnet_ipa3_ctx->num_q6_rules != 0) {
1652 IPAWANERR("dev(%s) register to IPA\n",
1653 extend_ioctl_data.u.rmnet_mux_val.
1654 vchannel_name);
1655 rc = ipa3_wwan_register_to_ipa(
1656 rmnet_ipa3_ctx->rmnet_index);
1657 if (rc < 0) {
1658 IPAWANERR("device %s reg IPA failed\n",
1659 extend_ioctl_data.u.
1660 rmnet_mux_val.vchannel_name);
1661 return -ENODEV;
1662 }
1663 mux_channel[rmnet_index].mux_channel_set = true;
1664 mux_channel[rmnet_index].ul_flt_reg = true;
1665 } else {
1666 IPAWANDBG("dev(%s) haven't registered to IPA\n",
1667 extend_ioctl_data.u.
1668 rmnet_mux_val.vchannel_name);
1669 mux_channel[rmnet_index].mux_channel_set = true;
1670 mux_channel[rmnet_index].ul_flt_reg = false;
1671 }
1672 rmnet_ipa3_ctx->rmnet_index++;
1673 break;
1674 case RMNET_IOCTL_SET_EGRESS_DATA_FORMAT:
Ghanim Fodic6b67492017-03-15 14:19:56 +02001675 rc = handle3_egress_format(dev, &extend_ioctl_data);
Amir Levy9659e592016-10-27 18:08:27 +03001676 break;
1677 case RMNET_IOCTL_SET_INGRESS_DATA_FORMAT:/* Set IDF */
Gidon Studinski3021a6f2016-11-10 12:48:48 +02001678 rc = handle3_ingress_format(dev, &extend_ioctl_data);
Amir Levy9659e592016-10-27 18:08:27 +03001679 break;
1680 case RMNET_IOCTL_SET_XLAT_DEV_INFO:
1681 wan_msg = kzalloc(sizeof(struct ipa_wan_msg),
1682 GFP_KERNEL);
1683 if (!wan_msg) {
1684 IPAWANERR("Failed to allocate memory.\n");
1685 return -ENOMEM;
1686 }
1687 len = sizeof(wan_msg->upstream_ifname) >
1688 sizeof(extend_ioctl_data.u.if_name) ?
1689 sizeof(extend_ioctl_data.u.if_name) :
1690 sizeof(wan_msg->upstream_ifname);
1691 strlcpy(wan_msg->upstream_ifname,
1692 extend_ioctl_data.u.if_name, len);
1693 memset(&msg_meta, 0, sizeof(struct ipa_msg_meta));
1694 msg_meta.msg_type = WAN_XLAT_CONNECT;
1695 msg_meta.msg_len = sizeof(struct ipa_wan_msg);
1696 rc = ipa3_send_msg(&msg_meta, wan_msg,
1697 ipa3_wwan_msg_free_cb);
1698 if (rc) {
1699 IPAWANERR("Failed to send XLAT_CONNECT msg\n");
1700 kfree(wan_msg);
1701 }
1702 break;
1703 /* Get agg count */
1704 case RMNET_IOCTL_GET_AGGREGATION_COUNT:
1705 break;
1706 /* Set agg count */
1707 case RMNET_IOCTL_SET_AGGREGATION_COUNT:
1708 break;
1709 /* Get agg size */
1710 case RMNET_IOCTL_GET_AGGREGATION_SIZE:
1711 break;
1712 /* Set agg size */
1713 case RMNET_IOCTL_SET_AGGREGATION_SIZE:
1714 break;
1715 /* Do flow control */
1716 case RMNET_IOCTL_FLOW_CONTROL:
1717 break;
1718 /* For legacy use */
1719 case RMNET_IOCTL_GET_DFLT_CONTROL_CHANNEL:
1720 break;
1721 /* Get HW/SW map */
1722 case RMNET_IOCTL_GET_HWSW_MAP:
1723 break;
1724 /* Set RX Headroom */
1725 case RMNET_IOCTL_SET_RX_HEADROOM:
1726 break;
1727 default:
1728 IPAWANERR("[%s] unsupported extended cmd[%d]",
1729 dev->name,
1730 extend_ioctl_data.extended_ioctl);
1731 rc = -EINVAL;
1732 }
1733 break;
1734 default:
1735 IPAWANERR("[%s] unsupported cmd[%d]",
1736 dev->name, cmd);
1737 rc = -EINVAL;
1738 }
1739 return rc;
1740}
1741
1742static const struct net_device_ops ipa3_wwan_ops_ip = {
1743 .ndo_open = ipa3_wwan_open,
1744 .ndo_stop = ipa3_wwan_stop,
1745 .ndo_start_xmit = ipa3_wwan_xmit,
1746 .ndo_tx_timeout = ipa3_wwan_tx_timeout,
1747 .ndo_do_ioctl = ipa3_wwan_ioctl,
1748 .ndo_change_mtu = ipa3_wwan_change_mtu,
1749 .ndo_set_mac_address = 0,
1750 .ndo_validate_addr = 0,
1751};
1752
1753/**
1754 * wwan_setup() - Setups the wwan network driver.
1755 *
1756 * @dev: network device
1757 *
1758 * Return codes:
1759 * None
1760 */
1761
1762static void ipa3_wwan_setup(struct net_device *dev)
1763{
1764 dev->netdev_ops = &ipa3_wwan_ops_ip;
1765 ether_setup(dev);
1766 /* set this after calling ether_setup */
1767 dev->header_ops = 0; /* No header */
1768 dev->type = ARPHRD_RAWIP;
1769 dev->hard_header_len = 0;
1770 dev->mtu = WWAN_DATA_LEN;
1771 dev->addr_len = 0;
1772 dev->flags &= ~(IFF_BROADCAST | IFF_MULTICAST);
1773 dev->needed_headroom = HEADROOM_FOR_QMAP;
1774 dev->needed_tailroom = TAILROOM;
1775 dev->watchdog_timeo = 1000;
1776}
1777
1778/* IPA_RM related functions start*/
1779static void ipa3_q6_prod_rm_request_resource(struct work_struct *work);
1780static DECLARE_DELAYED_WORK(ipa3_q6_con_rm_request,
1781 ipa3_q6_prod_rm_request_resource);
1782static void ipa3_q6_prod_rm_release_resource(struct work_struct *work);
1783static DECLARE_DELAYED_WORK(ipa3_q6_con_rm_release,
1784 ipa3_q6_prod_rm_release_resource);
1785
1786static void ipa3_q6_prod_rm_request_resource(struct work_struct *work)
1787{
1788 int ret = 0;
1789
1790 ret = ipa_rm_request_resource(IPA_RM_RESOURCE_Q6_PROD);
1791 if (ret < 0 && ret != -EINPROGRESS) {
1792 IPAWANERR("%s: ipa_rm_request_resource failed %d\n", __func__,
1793 ret);
1794 return;
1795 }
1796}
1797
1798static int ipa3_q6_rm_request_resource(void)
1799{
1800 queue_delayed_work(rmnet_ipa3_ctx->rm_q6_wq,
1801 &ipa3_q6_con_rm_request, 0);
1802 return 0;
1803}
1804
1805static void ipa3_q6_prod_rm_release_resource(struct work_struct *work)
1806{
1807 int ret = 0;
1808
1809 ret = ipa_rm_release_resource(IPA_RM_RESOURCE_Q6_PROD);
1810 if (ret < 0 && ret != -EINPROGRESS) {
1811 IPAWANERR("%s: ipa_rm_release_resource failed %d\n", __func__,
1812 ret);
1813 return;
1814 }
1815}
1816
1817
1818static int ipa3_q6_rm_release_resource(void)
1819{
1820 queue_delayed_work(rmnet_ipa3_ctx->rm_q6_wq,
1821 &ipa3_q6_con_rm_release, 0);
1822 return 0;
1823}
1824
1825
1826static void ipa3_q6_rm_notify_cb(void *user_data,
1827 enum ipa_rm_event event,
1828 unsigned long data)
1829{
1830 switch (event) {
1831 case IPA_RM_RESOURCE_GRANTED:
1832 IPAWANDBG_LOW("%s: Q6_PROD GRANTED CB\n", __func__);
1833 break;
1834 case IPA_RM_RESOURCE_RELEASED:
1835 IPAWANDBG_LOW("%s: Q6_PROD RELEASED CB\n", __func__);
1836 break;
1837 default:
1838 return;
1839 }
1840}
1841static int ipa3_q6_initialize_rm(void)
1842{
1843 struct ipa_rm_create_params create_params;
1844 struct ipa_rm_perf_profile profile;
1845 int result;
1846
1847 /* Initialize IPA_RM workqueue */
1848 rmnet_ipa3_ctx->rm_q6_wq = create_singlethread_workqueue("clnt_req");
1849 if (!rmnet_ipa3_ctx->rm_q6_wq)
1850 return -ENOMEM;
1851
1852 memset(&create_params, 0, sizeof(create_params));
1853 create_params.name = IPA_RM_RESOURCE_Q6_PROD;
1854 create_params.reg_params.notify_cb = &ipa3_q6_rm_notify_cb;
1855 result = ipa_rm_create_resource(&create_params);
1856 if (result)
1857 goto create_rsrc_err1;
1858 memset(&create_params, 0, sizeof(create_params));
1859 create_params.name = IPA_RM_RESOURCE_Q6_CONS;
1860 create_params.release_resource = &ipa3_q6_rm_release_resource;
1861 create_params.request_resource = &ipa3_q6_rm_request_resource;
1862 result = ipa_rm_create_resource(&create_params);
1863 if (result)
1864 goto create_rsrc_err2;
1865 /* add dependency*/
1866 result = ipa_rm_add_dependency(IPA_RM_RESOURCE_Q6_PROD,
1867 IPA_RM_RESOURCE_APPS_CONS);
1868 if (result)
1869 goto add_dpnd_err;
1870 /* setup Performance profile */
1871 memset(&profile, 0, sizeof(profile));
1872 profile.max_supported_bandwidth_mbps = 100;
1873 result = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_Q6_PROD,
1874 &profile);
1875 if (result)
1876 goto set_perf_err;
1877 result = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_Q6_CONS,
1878 &profile);
1879 if (result)
1880 goto set_perf_err;
1881 return result;
1882
1883set_perf_err:
1884 ipa_rm_delete_dependency(IPA_RM_RESOURCE_Q6_PROD,
1885 IPA_RM_RESOURCE_APPS_CONS);
1886add_dpnd_err:
1887 result = ipa_rm_delete_resource(IPA_RM_RESOURCE_Q6_CONS);
1888 if (result < 0)
1889 IPAWANERR("Error deleting resource %d, ret=%d\n",
1890 IPA_RM_RESOURCE_Q6_CONS, result);
1891create_rsrc_err2:
1892 result = ipa_rm_delete_resource(IPA_RM_RESOURCE_Q6_PROD);
1893 if (result < 0)
1894 IPAWANERR("Error deleting resource %d, ret=%d\n",
1895 IPA_RM_RESOURCE_Q6_PROD, result);
1896create_rsrc_err1:
1897 destroy_workqueue(rmnet_ipa3_ctx->rm_q6_wq);
1898 return result;
1899}
1900
1901void ipa3_q6_deinitialize_rm(void)
1902{
1903 int ret;
1904
1905 ret = ipa_rm_delete_dependency(IPA_RM_RESOURCE_Q6_PROD,
1906 IPA_RM_RESOURCE_APPS_CONS);
1907 if (ret < 0)
1908 IPAWANERR("Error deleting dependency %d->%d, ret=%d\n",
1909 IPA_RM_RESOURCE_Q6_PROD, IPA_RM_RESOURCE_APPS_CONS,
1910 ret);
1911 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_Q6_CONS);
1912 if (ret < 0)
1913 IPAWANERR("Error deleting resource %d, ret=%d\n",
1914 IPA_RM_RESOURCE_Q6_CONS, ret);
1915 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_Q6_PROD);
1916 if (ret < 0)
1917 IPAWANERR("Error deleting resource %d, ret=%d\n",
1918 IPA_RM_RESOURCE_Q6_PROD, ret);
1919 destroy_workqueue(rmnet_ipa3_ctx->rm_q6_wq);
1920}
1921
1922static void ipa3_wake_tx_queue(struct work_struct *work)
1923{
1924 if (IPA_NETDEV()) {
1925 __netif_tx_lock_bh(netdev_get_tx_queue(IPA_NETDEV(), 0));
1926 netif_wake_queue(IPA_NETDEV());
1927 __netif_tx_unlock_bh(netdev_get_tx_queue(IPA_NETDEV(), 0));
1928 }
1929}
1930
1931/**
1932 * ipa3_rm_resource_granted() - Called upon
1933 * IPA_RM_RESOURCE_GRANTED event. Wakes up queue is was stopped.
1934 *
1935 * @work: work object supplied ny workqueue
1936 *
1937 * Return codes:
1938 * None
1939 */
1940static void ipa3_rm_resource_granted(void *dev)
1941{
1942 IPAWANDBG_LOW("Resource Granted - starting queue\n");
1943 schedule_work(&ipa3_tx_wakequeue_work);
1944}
1945
1946/**
1947 * ipa3_rm_notify() - Callback function for RM events. Handles
1948 * IPA_RM_RESOURCE_GRANTED and IPA_RM_RESOURCE_RELEASED events.
1949 * IPA_RM_RESOURCE_GRANTED is handled in the context of shared
1950 * workqueue.
1951 *
1952 * @dev: network device
1953 * @event: IPA RM event
1954 * @data: Additional data provided by IPA RM
1955 *
1956 * Return codes:
1957 * None
1958 */
1959static void ipa3_rm_notify(void *dev, enum ipa_rm_event event,
1960 unsigned long data)
1961{
1962 struct ipa3_wwan_private *wwan_ptr = netdev_priv(dev);
1963
1964 pr_debug("%s: event %d\n", __func__, event);
1965 switch (event) {
1966 case IPA_RM_RESOURCE_GRANTED:
1967 if (wwan_ptr->device_status == WWAN_DEVICE_INACTIVE) {
1968 complete_all(&wwan_ptr->resource_granted_completion);
1969 break;
1970 }
1971 ipa3_rm_resource_granted(dev);
1972 break;
1973 case IPA_RM_RESOURCE_RELEASED:
1974 break;
1975 default:
1976 pr_err("%s: unknown event %d\n", __func__, event);
1977 break;
1978 }
1979}
1980
1981/* IPA_RM related functions end*/
1982
1983static int ipa3_ssr_notifier_cb(struct notifier_block *this,
1984 unsigned long code,
1985 void *data);
1986
1987static struct notifier_block ipa3_ssr_notifier = {
1988 .notifier_call = ipa3_ssr_notifier_cb,
1989};
1990
1991static int get_ipa_rmnet_dts_configuration(struct platform_device *pdev,
1992 struct ipa3_rmnet_plat_drv_res *ipa_rmnet_drv_res)
1993{
1994 ipa_rmnet_drv_res->ipa_rmnet_ssr =
1995 of_property_read_bool(pdev->dev.of_node,
1996 "qcom,rmnet-ipa-ssr");
1997 pr_info("IPA SSR support = %s\n",
1998 ipa_rmnet_drv_res->ipa_rmnet_ssr ? "True" : "False");
1999 ipa_rmnet_drv_res->ipa_loaduC =
2000 of_property_read_bool(pdev->dev.of_node,
2001 "qcom,ipa-loaduC");
2002 pr_info("IPA ipa-loaduC = %s\n",
2003 ipa_rmnet_drv_res->ipa_loaduC ? "True" : "False");
2004
2005 ipa_rmnet_drv_res->ipa_advertise_sg_support =
2006 of_property_read_bool(pdev->dev.of_node,
2007 "qcom,ipa-advertise-sg-support");
2008 pr_info("IPA SG support = %s\n",
2009 ipa_rmnet_drv_res->ipa_advertise_sg_support ? "True" : "False");
Gidon Studinski3021a6f2016-11-10 12:48:48 +02002010
2011 ipa_rmnet_drv_res->ipa_napi_enable =
2012 of_property_read_bool(pdev->dev.of_node,
2013 "qcom,ipa-napi-enable");
2014 pr_info("IPA Napi Enable = %s\n",
2015 ipa_rmnet_drv_res->ipa_napi_enable ? "True" : "False");
Amir Levy9659e592016-10-27 18:08:27 +03002016 return 0;
2017}
2018
2019struct ipa3_rmnet_context ipa3_rmnet_ctx;
2020static int ipa3_wwan_probe(struct platform_device *pdev);
2021struct platform_device *m_pdev;
2022
2023static void ipa3_delayed_probe(struct work_struct *work)
2024{
2025 (void)ipa3_wwan_probe(m_pdev);
2026}
2027
2028static DECLARE_WORK(ipa3_scheduled_probe, ipa3_delayed_probe);
2029
2030static void ipa3_ready_cb(void *user_data)
2031{
2032 struct platform_device *pdev = (struct platform_device *)(user_data);
2033
2034 m_pdev = pdev;
2035
2036 IPAWANDBG("IPA ready callback has been triggered!\n");
2037
2038 schedule_work(&ipa3_scheduled_probe);
2039}
2040
2041/**
2042 * ipa3_wwan_probe() - Initialized the module and registers as a
2043 * network interface to the network stack
2044 *
2045 * Note: In case IPA driver hasn't initialized already, the probe function
2046 * will return immediately after registering a callback to be invoked when
2047 * IPA driver initialization is complete.
2048 *
2049 * Return codes:
2050 * 0: success
2051 * -ENOMEM: No memory available
2052 * -EFAULT: Internal error
2053 */
2054static int ipa3_wwan_probe(struct platform_device *pdev)
2055{
2056 int ret, i;
2057 struct net_device *dev;
2058 struct ipa_rm_create_params ipa_rm_params; /* IPA_RM */
2059 struct ipa_rm_perf_profile profile; /* IPA_RM */
2060
2061 pr_info("rmnet_ipa3 started initialization\n");
2062
2063 if (!ipa3_is_ready()) {
2064 IPAWANDBG("IPA driver not ready, registering callback\n");
2065 ret = ipa_register_ipa_ready_cb(ipa3_ready_cb, (void *)pdev);
2066
2067 /*
2068 * If we received -EEXIST, IPA has initialized. So we need
2069 * to continue the probing process.
2070 */
2071 if (ret != -EEXIST) {
2072 if (ret)
2073 IPAWANERR("IPA CB reg failed - %d\n", ret);
2074 return ret;
2075 }
2076 }
2077
2078 ret = get_ipa_rmnet_dts_configuration(pdev, &ipa3_rmnet_res);
2079 ipa3_rmnet_ctx.ipa_rmnet_ssr = ipa3_rmnet_res.ipa_rmnet_ssr;
2080
2081 ret = ipa3_init_q6_smem();
2082 if (ret) {
2083 IPAWANERR("ipa3_init_q6_smem failed!\n");
2084 return ret;
2085 }
2086
2087 /* initialize tx/rx endpoint setup */
2088 memset(&rmnet_ipa3_ctx->apps_to_ipa_ep_cfg, 0,
2089 sizeof(struct ipa_sys_connect_params));
2090 memset(&rmnet_ipa3_ctx->ipa_to_apps_ep_cfg, 0,
2091 sizeof(struct ipa_sys_connect_params));
2092
2093 /* initialize ex property setup */
2094 rmnet_ipa3_ctx->num_q6_rules = 0;
2095 rmnet_ipa3_ctx->old_num_q6_rules = 0;
2096 rmnet_ipa3_ctx->rmnet_index = 0;
2097 rmnet_ipa3_ctx->egress_set = false;
2098 rmnet_ipa3_ctx->a7_ul_flt_set = false;
2099 for (i = 0; i < MAX_NUM_OF_MUX_CHANNEL; i++)
2100 memset(&rmnet_ipa3_ctx->mux_channel[i], 0,
2101 sizeof(struct ipa3_rmnet_mux_val));
2102
2103 /* start A7 QMI service/client */
2104 if (ipa3_rmnet_res.ipa_loaduC)
2105 /* Android platform loads uC */
2106 ipa3_qmi_service_init(QMI_IPA_PLATFORM_TYPE_MSM_ANDROID_V01);
2107 else
2108 /* LE platform not loads uC */
2109 ipa3_qmi_service_init(QMI_IPA_PLATFORM_TYPE_LE_V01);
2110
2111 /* construct default WAN RT tbl for IPACM */
2112 ret = ipa3_setup_a7_qmap_hdr();
2113 if (ret)
2114 goto setup_a7_qmap_hdr_err;
2115 ret = ipa3_setup_dflt_wan_rt_tables();
2116 if (ret)
2117 goto setup_dflt_wan_rt_tables_err;
2118
2119 if (!atomic_read(&rmnet_ipa3_ctx->is_ssr)) {
2120 /* Start transport-driver fd ioctl for ipacm for first init */
2121 ret = ipa3_wan_ioctl_init();
2122 if (ret)
2123 goto wan_ioctl_init_err;
2124 } else {
2125 /* Enable sending QMI messages after SSR */
2126 ipa3_wan_ioctl_enable_qmi_messages();
2127 }
2128
2129 /* initialize wan-driver netdev */
2130 dev = alloc_netdev(sizeof(struct ipa3_wwan_private),
2131 IPA_WWAN_DEV_NAME,
2132 NET_NAME_UNKNOWN,
2133 ipa3_wwan_setup);
2134 if (!dev) {
2135 IPAWANERR("no memory for netdev\n");
2136 ret = -ENOMEM;
2137 goto alloc_netdev_err;
2138 }
2139 rmnet_ipa3_ctx->wwan_priv = netdev_priv(dev);
2140 memset(rmnet_ipa3_ctx->wwan_priv, 0,
2141 sizeof(*(rmnet_ipa3_ctx->wwan_priv)));
2142 IPAWANDBG("wwan_ptr (private) = %p", rmnet_ipa3_ctx->wwan_priv);
2143 rmnet_ipa3_ctx->wwan_priv->net = dev;
2144 rmnet_ipa3_ctx->wwan_priv->outstanding_high = DEFAULT_OUTSTANDING_HIGH;
2145 rmnet_ipa3_ctx->wwan_priv->outstanding_low = DEFAULT_OUTSTANDING_LOW;
2146 atomic_set(&rmnet_ipa3_ctx->wwan_priv->outstanding_pkts, 0);
2147 spin_lock_init(&rmnet_ipa3_ctx->wwan_priv->lock);
2148 init_completion(
2149 &rmnet_ipa3_ctx->wwan_priv->resource_granted_completion);
2150
2151 if (!atomic_read(&rmnet_ipa3_ctx->is_ssr)) {
2152 /* IPA_RM configuration starts */
2153 ret = ipa3_q6_initialize_rm();
2154 if (ret) {
2155 IPAWANERR("%s: ipa3_q6_initialize_rm failed, ret: %d\n",
2156 __func__, ret);
2157 goto q6_init_err;
2158 }
2159 }
2160
2161 memset(&ipa_rm_params, 0, sizeof(struct ipa_rm_create_params));
2162 ipa_rm_params.name = IPA_RM_RESOURCE_WWAN_0_PROD;
2163 ipa_rm_params.reg_params.user_data = dev;
2164 ipa_rm_params.reg_params.notify_cb = ipa3_rm_notify;
2165 ret = ipa_rm_create_resource(&ipa_rm_params);
2166 if (ret) {
2167 pr_err("%s: unable to create resourse %d in IPA RM\n",
2168 __func__, IPA_RM_RESOURCE_WWAN_0_PROD);
2169 goto create_rsrc_err;
2170 }
2171 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WWAN_0_PROD,
2172 IPA_RM_INACTIVITY_TIMER);
2173 if (ret) {
2174 pr_err("%s: ipa rm timer init failed %d on resourse %d\n",
2175 __func__, ret, IPA_RM_RESOURCE_WWAN_0_PROD);
2176 goto timer_init_err;
2177 }
2178 /* add dependency */
2179 ret = ipa_rm_add_dependency(IPA_RM_RESOURCE_WWAN_0_PROD,
2180 IPA_RM_RESOURCE_Q6_CONS);
2181 if (ret)
2182 goto add_dpnd_err;
2183 /* setup Performance profile */
2184 memset(&profile, 0, sizeof(profile));
2185 profile.max_supported_bandwidth_mbps = IPA_APPS_MAX_BW_IN_MBPS;
2186 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WWAN_0_PROD,
2187 &profile);
2188 if (ret)
2189 goto set_perf_err;
2190 /* IPA_RM configuration ends */
2191
2192 /* Enable SG support in netdevice. */
2193 if (ipa3_rmnet_res.ipa_advertise_sg_support)
2194 dev->hw_features |= NETIF_F_SG;
2195
2196 if (ipa3_rmnet_res.ipa_napi_enable)
2197 netif_napi_add(dev, &(rmnet_ipa3_ctx->wwan_priv->napi),
2198 ipa3_rmnet_poll, NAPI_WEIGHT);
2199 ret = register_netdev(dev);
2200 if (ret) {
2201 IPAWANERR("unable to register ipa_netdev %d rc=%d\n",
2202 0, ret);
2203 goto set_perf_err;
2204 }
2205
2206 IPAWANDBG("IPA-WWAN devices (%s) initialization ok :>>>>\n", dev->name);
2207 if (ret) {
2208 IPAWANERR("default configuration failed rc=%d\n",
2209 ret);
2210 goto config_err;
2211 }
2212 atomic_set(&rmnet_ipa3_ctx->is_initialized, 1);
2213 if (!atomic_read(&rmnet_ipa3_ctx->is_ssr)) {
2214 /* offline charging mode */
2215 ipa3_proxy_clk_unvote();
2216 }
2217 atomic_set(&rmnet_ipa3_ctx->is_ssr, 0);
2218
2219 pr_info("rmnet_ipa completed initialization\n");
2220 return 0;
2221config_err:
2222 if (ipa3_rmnet_res.ipa_napi_enable)
2223 netif_napi_del(&(rmnet_ipa3_ctx->wwan_priv->napi));
2224 unregister_netdev(dev);
2225set_perf_err:
2226 ret = ipa_rm_delete_dependency(IPA_RM_RESOURCE_WWAN_0_PROD,
2227 IPA_RM_RESOURCE_Q6_CONS);
2228 if (ret)
2229 IPAWANERR("Error deleting dependency %d->%d, ret=%d\n",
2230 IPA_RM_RESOURCE_WWAN_0_PROD, IPA_RM_RESOURCE_Q6_CONS,
2231 ret);
2232add_dpnd_err:
2233 ret = ipa_rm_inactivity_timer_destroy(
2234 IPA_RM_RESOURCE_WWAN_0_PROD); /* IPA_RM */
2235 if (ret)
2236 IPAWANERR("Error ipa_rm_inactivity_timer_destroy %d, ret=%d\n",
2237 IPA_RM_RESOURCE_WWAN_0_PROD, ret);
2238timer_init_err:
2239 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WWAN_0_PROD);
2240 if (ret)
2241 IPAWANERR("Error deleting resource %d, ret=%d\n",
2242 IPA_RM_RESOURCE_WWAN_0_PROD, ret);
2243create_rsrc_err:
2244 ipa3_q6_deinitialize_rm();
2245q6_init_err:
2246 free_netdev(dev);
2247 rmnet_ipa3_ctx->wwan_priv = NULL;
2248alloc_netdev_err:
2249 ipa3_wan_ioctl_deinit();
2250wan_ioctl_init_err:
2251 ipa3_del_dflt_wan_rt_tables();
2252setup_dflt_wan_rt_tables_err:
2253 ipa3_del_a7_qmap_hdr();
2254setup_a7_qmap_hdr_err:
2255 ipa3_qmi_service_exit();
2256 atomic_set(&rmnet_ipa3_ctx->is_ssr, 0);
2257 return ret;
2258}
2259
2260static int ipa3_wwan_remove(struct platform_device *pdev)
2261{
2262 int ret;
2263
2264 pr_info("rmnet_ipa started deinitialization\n");
Ghanim Fodic6b67492017-03-15 14:19:56 +02002265 mutex_lock(&rmnet_ipa3_ctx->pipe_handle_guard);
Amir Levy9659e592016-10-27 18:08:27 +03002266 ret = ipa3_teardown_sys_pipe(rmnet_ipa3_ctx->ipa3_to_apps_hdl);
2267 if (ret < 0)
2268 IPAWANERR("Failed to teardown IPA->APPS pipe\n");
2269 else
2270 rmnet_ipa3_ctx->ipa3_to_apps_hdl = -1;
Ghanim Fodic6b67492017-03-15 14:19:56 +02002271 ret = ipa3_teardown_sys_pipe(rmnet_ipa3_ctx->apps_to_ipa3_hdl);
2272 if (ret < 0)
2273 IPAWANERR("Failed to teardown APPS->IPA pipe\n");
2274 else
2275 rmnet_ipa3_ctx->apps_to_ipa3_hdl = -1;
Amir Levy9659e592016-10-27 18:08:27 +03002276 if (ipa3_rmnet_res.ipa_napi_enable)
2277 netif_napi_del(&(rmnet_ipa3_ctx->wwan_priv->napi));
Ghanim Fodic6b67492017-03-15 14:19:56 +02002278 mutex_unlock(&rmnet_ipa3_ctx->pipe_handle_guard);
Amir Levy9659e592016-10-27 18:08:27 +03002279 unregister_netdev(IPA_NETDEV());
2280 ret = ipa_rm_delete_dependency(IPA_RM_RESOURCE_WWAN_0_PROD,
2281 IPA_RM_RESOURCE_Q6_CONS);
2282 if (ret < 0)
2283 IPAWANERR("Error deleting dependency %d->%d, ret=%d\n",
2284 IPA_RM_RESOURCE_WWAN_0_PROD, IPA_RM_RESOURCE_Q6_CONS,
2285 ret);
2286 ret = ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WWAN_0_PROD);
2287 if (ret < 0)
2288 IPAWANERR(
2289 "Error ipa_rm_inactivity_timer_destroy resource %d, ret=%d\n",
2290 IPA_RM_RESOURCE_WWAN_0_PROD, ret);
2291 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WWAN_0_PROD);
2292 if (ret < 0)
2293 IPAWANERR("Error deleting resource %d, ret=%d\n",
2294 IPA_RM_RESOURCE_WWAN_0_PROD, ret);
2295 cancel_work_sync(&ipa3_tx_wakequeue_work);
2296 cancel_delayed_work(&ipa_tether_stats_poll_wakequeue_work);
2297 if (IPA_NETDEV())
2298 free_netdev(IPA_NETDEV());
2299 rmnet_ipa3_ctx->wwan_priv = NULL;
2300 /* No need to remove wwan_ioctl during SSR */
2301 if (!atomic_read(&rmnet_ipa3_ctx->is_ssr))
2302 ipa3_wan_ioctl_deinit();
2303 ipa3_del_dflt_wan_rt_tables();
2304 ipa3_del_a7_qmap_hdr();
2305 ipa3_del_mux_qmap_hdrs();
2306 if (ipa3_qmi_ctx->modem_cfg_emb_pipe_flt == false)
2307 ipa3_wwan_del_ul_flt_rule_to_ipa();
2308 ipa3_cleanup_deregister_intf();
2309 atomic_set(&rmnet_ipa3_ctx->is_initialized, 0);
2310 pr_info("rmnet_ipa completed deinitialization\n");
2311 return 0;
2312}
2313
2314/**
2315* rmnet_ipa_ap_suspend() - suspend callback for runtime_pm
2316* @dev: pointer to device
2317*
2318* This callback will be invoked by the runtime_pm framework when an AP suspend
2319* operation is invoked, usually by pressing a suspend button.
2320*
2321* Returns -EAGAIN to runtime_pm framework in case there are pending packets
2322* in the Tx queue. This will postpone the suspend operation until all the
2323* pending packets will be transmitted.
2324*
2325* In case there are no packets to send, releases the WWAN0_PROD entity.
2326* As an outcome, the number of IPA active clients should be decremented
2327* until IPA clocks can be gated.
2328*/
2329static int rmnet_ipa_ap_suspend(struct device *dev)
2330{
2331 struct net_device *netdev = IPA_NETDEV();
2332 struct ipa3_wwan_private *wwan_ptr;
2333
2334 IPAWANDBG_LOW("Enter...\n");
2335 if (netdev == NULL) {
2336 IPAWANERR("netdev is NULL.\n");
2337 return 0;
2338 }
2339
2340 wwan_ptr = netdev_priv(netdev);
2341 if (wwan_ptr == NULL) {
2342 IPAWANERR("wwan_ptr is NULL.\n");
2343 return 0;
2344 }
2345
2346 /* Do not allow A7 to suspend in case there are oustanding packets */
2347 if (atomic_read(&wwan_ptr->outstanding_pkts) != 0) {
2348 IPAWANDBG("Outstanding packets, postponing AP suspend.\n");
2349 return -EAGAIN;
2350 }
2351
2352 /* Make sure that there is no Tx operation ongoing */
2353 netif_tx_lock_bh(netdev);
2354 ipa_rm_release_resource(IPA_RM_RESOURCE_WWAN_0_PROD);
2355 netif_tx_unlock_bh(netdev);
2356 IPAWANDBG_LOW("Exit\n");
2357
2358 return 0;
2359}
2360
2361/**
2362* rmnet_ipa_ap_resume() - resume callback for runtime_pm
2363* @dev: pointer to device
2364*
2365* This callback will be invoked by the runtime_pm framework when an AP resume
2366* operation is invoked.
2367*
2368* Enables the network interface queue and returns success to the
2369* runtime_pm framework.
2370*/
2371static int rmnet_ipa_ap_resume(struct device *dev)
2372{
2373 struct net_device *netdev = IPA_NETDEV();
2374
2375 IPAWANDBG_LOW("Enter...\n");
2376 if (netdev)
2377 netif_wake_queue(netdev);
2378 IPAWANDBG_LOW("Exit\n");
2379
2380 return 0;
2381}
2382
2383static void ipa_stop_polling_stats(void)
2384{
2385 cancel_delayed_work(&ipa_tether_stats_poll_wakequeue_work);
2386 ipa3_rmnet_ctx.polling_interval = 0;
2387}
2388
2389static const struct of_device_id rmnet_ipa_dt_match[] = {
2390 {.compatible = "qcom,rmnet-ipa3"},
2391 {},
2392};
2393MODULE_DEVICE_TABLE(of, rmnet_ipa_dt_match);
2394
2395static const struct dev_pm_ops rmnet_ipa_pm_ops = {
2396 .suspend_noirq = rmnet_ipa_ap_suspend,
2397 .resume_noirq = rmnet_ipa_ap_resume,
2398};
2399
2400static struct platform_driver rmnet_ipa_driver = {
2401 .driver = {
2402 .name = "rmnet_ipa3",
2403 .owner = THIS_MODULE,
2404 .pm = &rmnet_ipa_pm_ops,
2405 .of_match_table = rmnet_ipa_dt_match,
2406 },
2407 .probe = ipa3_wwan_probe,
2408 .remove = ipa3_wwan_remove,
2409};
2410
2411static int ipa3_ssr_notifier_cb(struct notifier_block *this,
2412 unsigned long code,
2413 void *data)
2414{
2415 if (!ipa3_rmnet_ctx.ipa_rmnet_ssr)
2416 return NOTIFY_DONE;
2417
2418 switch (code) {
2419 case SUBSYS_BEFORE_SHUTDOWN:
2420 IPAWANINFO("IPA received MPSS BEFORE_SHUTDOWN\n");
2421 atomic_set(&rmnet_ipa3_ctx->is_ssr, 1);
2422 ipa3_q6_pre_shutdown_cleanup();
2423 if (IPA_NETDEV())
2424 netif_stop_queue(IPA_NETDEV());
2425 ipa3_qmi_stop_workqueues();
2426 ipa3_wan_ioctl_stop_qmi_messages();
2427 ipa_stop_polling_stats();
2428 if (atomic_read(&rmnet_ipa3_ctx->is_initialized))
2429 platform_driver_unregister(&rmnet_ipa_driver);
2430 IPAWANINFO("IPA BEFORE_SHUTDOWN handling is complete\n");
2431 break;
2432 case SUBSYS_AFTER_SHUTDOWN:
2433 IPAWANINFO("IPA Received MPSS AFTER_SHUTDOWN\n");
2434 if (atomic_read(&rmnet_ipa3_ctx->is_ssr))
2435 ipa3_q6_post_shutdown_cleanup();
2436 IPAWANINFO("IPA AFTER_SHUTDOWN handling is complete\n");
2437 break;
2438 case SUBSYS_BEFORE_POWERUP:
2439 IPAWANINFO("IPA received MPSS BEFORE_POWERUP\n");
2440 if (atomic_read(&rmnet_ipa3_ctx->is_ssr))
2441 /* clean up cached QMI msg/handlers */
2442 ipa3_qmi_service_exit();
2443 /*hold a proxy vote for the modem*/
2444 ipa3_proxy_clk_vote();
Skylar Change1209942017-02-02 14:26:38 -08002445 ipa3_reset_freeze_vote();
Amir Levy9659e592016-10-27 18:08:27 +03002446 IPAWANINFO("IPA BEFORE_POWERUP handling is complete\n");
2447 break;
2448 case SUBSYS_AFTER_POWERUP:
2449 IPAWANINFO("%s:%d IPA received MPSS AFTER_POWERUP\n",
2450 __func__, __LINE__);
2451 if (!atomic_read(&rmnet_ipa3_ctx->is_initialized) &&
2452 atomic_read(&rmnet_ipa3_ctx->is_ssr))
2453 platform_driver_register(&rmnet_ipa_driver);
2454
2455 IPAWANINFO("IPA AFTER_POWERUP handling is complete\n");
2456 break;
2457 default:
2458 IPAWANDBG("Unsupported subsys notification, IPA received: %lu",
2459 code);
2460 break;
2461 }
2462
2463 IPAWANDBG_LOW("Exit\n");
2464 return NOTIFY_DONE;
2465}
2466
2467/**
2468 * rmnet_ipa_free_msg() - Free the msg sent to user space via ipa_send_msg
2469 * @buff: pointer to buffer containing the message
2470 * @len: message len
2471 * @type: message type
2472 *
2473 * This function is invoked when ipa_send_msg is complete (Provided as a
2474 * free function pointer along with the message).
2475 */
2476static void rmnet_ipa_free_msg(void *buff, u32 len, u32 type)
2477{
2478 if (!buff) {
2479 IPAWANERR("Null buffer\n");
2480 return;
2481 }
2482
2483 if (type != IPA_TETHERING_STATS_UPDATE_STATS &&
2484 type != IPA_TETHERING_STATS_UPDATE_NETWORK_STATS) {
2485 IPAWANERR("Wrong type given. buff %p type %d\n",
2486 buff, type);
2487 }
2488 kfree(buff);
2489}
2490
2491/**
2492 * rmnet_ipa_get_stats_and_update() - Gets pipe stats from Modem
2493 *
2494 * This function queries the IPA Modem driver for the pipe stats
2495 * via QMI, and updates the user space IPA entity.
2496 */
2497static void rmnet_ipa_get_stats_and_update(void)
2498{
2499 struct ipa_get_data_stats_req_msg_v01 req;
2500 struct ipa_get_data_stats_resp_msg_v01 *resp;
2501 struct ipa_msg_meta msg_meta;
2502 int rc;
2503
2504 resp = kzalloc(sizeof(struct ipa_get_data_stats_resp_msg_v01),
2505 GFP_KERNEL);
2506 if (!resp) {
2507 IPAWANERR("Can't allocate memory for stats message\n");
2508 return;
2509 }
2510
2511 memset(&req, 0, sizeof(struct ipa_get_data_stats_req_msg_v01));
2512 memset(resp, 0, sizeof(struct ipa_get_data_stats_resp_msg_v01));
2513
2514 req.ipa_stats_type = QMI_IPA_STATS_TYPE_PIPE_V01;
2515
2516 rc = ipa3_qmi_get_data_stats(&req, resp);
Gidon Studinski3021a6f2016-11-10 12:48:48 +02002517 if (rc) {
2518 IPAWANERR("ipa3_qmi_get_data_stats failed: %d\n", rc);
2519 kfree(resp);
2520 return;
2521 }
Amir Levy9659e592016-10-27 18:08:27 +03002522
Gidon Studinski3021a6f2016-11-10 12:48:48 +02002523 memset(&msg_meta, 0, sizeof(struct ipa_msg_meta));
2524 msg_meta.msg_type = IPA_TETHERING_STATS_UPDATE_STATS;
2525 msg_meta.msg_len = sizeof(struct ipa_get_data_stats_resp_msg_v01);
2526 rc = ipa_send_msg(&msg_meta, resp, rmnet_ipa_free_msg);
2527 if (rc) {
2528 IPAWANERR("ipa_send_msg failed: %d\n", rc);
2529 kfree(resp);
2530 return;
Amir Levy9659e592016-10-27 18:08:27 +03002531 }
2532}
2533
2534/**
2535 * tethering_stats_poll_queue() - Stats polling function
2536 * @work - Work entry
2537 *
2538 * This function is scheduled periodically (per the interval) in
2539 * order to poll the IPA Modem driver for the pipe stats.
2540 */
2541static void tethering_stats_poll_queue(struct work_struct *work)
2542{
2543 rmnet_ipa_get_stats_and_update();
2544
2545 /* Schedule again only if there's an active polling interval */
2546 if (ipa3_rmnet_ctx.polling_interval != 0)
2547 schedule_delayed_work(&ipa_tether_stats_poll_wakequeue_work,
2548 msecs_to_jiffies(ipa3_rmnet_ctx.polling_interval*1000));
2549}
2550
2551/**
2552 * rmnet_ipa_get_network_stats_and_update() - Get network stats from IPA Modem
2553 *
2554 * This function retrieves the data usage (used quota) from the IPA Modem driver
2555 * via QMI, and updates IPA user space entity.
2556 */
2557static void rmnet_ipa_get_network_stats_and_update(void)
2558{
2559 struct ipa_get_apn_data_stats_req_msg_v01 req;
2560 struct ipa_get_apn_data_stats_resp_msg_v01 *resp;
2561 struct ipa_msg_meta msg_meta;
2562 int rc;
2563
2564 resp = kzalloc(sizeof(struct ipa_get_apn_data_stats_resp_msg_v01),
2565 GFP_KERNEL);
2566 if (!resp) {
2567 IPAWANERR("Can't allocate memory for network stats message\n");
2568 return;
2569 }
2570
2571 memset(&req, 0, sizeof(struct ipa_get_apn_data_stats_req_msg_v01));
2572 memset(resp, 0, sizeof(struct ipa_get_apn_data_stats_resp_msg_v01));
2573
2574 req.mux_id_list_valid = true;
2575 req.mux_id_list_len = 1;
2576 req.mux_id_list[0] = ipa3_rmnet_ctx.metered_mux_id;
2577
2578 rc = ipa3_qmi_get_network_stats(&req, resp);
Gidon Studinski3021a6f2016-11-10 12:48:48 +02002579 if (rc) {
2580 IPAWANERR("ipa3_qmi_get_network_stats failed: %d\n", rc);
2581 kfree(resp);
2582 return;
2583 }
Amir Levy9659e592016-10-27 18:08:27 +03002584
Gidon Studinski3021a6f2016-11-10 12:48:48 +02002585 memset(&msg_meta, 0, sizeof(struct ipa_msg_meta));
2586 msg_meta.msg_type = IPA_TETHERING_STATS_UPDATE_NETWORK_STATS;
2587 msg_meta.msg_len = sizeof(struct ipa_get_apn_data_stats_resp_msg_v01);
2588 rc = ipa_send_msg(&msg_meta, resp, rmnet_ipa_free_msg);
2589 if (rc) {
2590 IPAWANERR("ipa_send_msg failed: %d\n", rc);
2591 kfree(resp);
2592 return;
Amir Levy9659e592016-10-27 18:08:27 +03002593 }
2594}
2595
2596/**
2597 * rmnet_ipa3_poll_tethering_stats() - Tethering stats polling IOCTL handler
2598 * @data - IOCTL data
2599 *
2600 * This function handles WAN_IOC_POLL_TETHERING_STATS.
2601 * In case polling interval received is 0, polling will stop
2602 * (If there's a polling in progress, it will allow it to finish), and then will
2603 * fetch network stats, and update the IPA user space.
2604 *
2605 * Return codes:
2606 * 0: Success
2607 */
2608int rmnet_ipa3_poll_tethering_stats(struct wan_ioctl_poll_tethering_stats *data)
2609{
2610 ipa3_rmnet_ctx.polling_interval = data->polling_interval_secs;
2611
2612 cancel_delayed_work_sync(&ipa_tether_stats_poll_wakequeue_work);
2613
2614 if (ipa3_rmnet_ctx.polling_interval == 0) {
2615 ipa3_qmi_stop_data_qouta();
2616 rmnet_ipa_get_network_stats_and_update();
2617 rmnet_ipa_get_stats_and_update();
2618 return 0;
2619 }
2620
2621 schedule_delayed_work(&ipa_tether_stats_poll_wakequeue_work, 0);
2622 return 0;
2623}
2624
2625/**
2626 * rmnet_ipa_set_data_quota() - Data quota setting IOCTL handler
2627 * @data - IOCTL data
2628 *
2629 * This function handles WAN_IOC_SET_DATA_QUOTA.
2630 * It translates the given interface name to the Modem MUX ID and
2631 * sends the request of the quota to the IPA Modem driver via QMI.
2632 *
2633 * Return codes:
2634 * 0: Success
2635 * -EFAULT: Invalid interface name provided
2636 * other: See ipa_qmi_set_data_quota
2637 */
2638int rmnet_ipa3_set_data_quota(struct wan_ioctl_set_data_quota *data)
2639{
2640 u32 mux_id;
2641 int index;
2642 struct ipa_set_data_usage_quota_req_msg_v01 req;
2643
2644 index = find_vchannel_name_index(data->interface_name);
2645 IPAWANERR("iface name %s, quota %lu\n",
2646 data->interface_name,
2647 (unsigned long int) data->quota_mbytes);
2648
2649 if (index == MAX_NUM_OF_MUX_CHANNEL) {
2650 IPAWANERR("%s is an invalid iface name\n",
2651 data->interface_name);
2652 return -EFAULT;
2653 }
2654
2655 mux_id = rmnet_ipa3_ctx->mux_channel[index].mux_id;
2656 ipa3_rmnet_ctx.metered_mux_id = mux_id;
2657
2658 memset(&req, 0, sizeof(struct ipa_set_data_usage_quota_req_msg_v01));
2659 req.apn_quota_list_valid = true;
2660 req.apn_quota_list_len = 1;
2661 req.apn_quota_list[0].mux_id = mux_id;
2662 req.apn_quota_list[0].num_Mbytes = data->quota_mbytes;
2663
2664 return ipa3_qmi_set_data_quota(&req);
2665}
2666
2667 /* rmnet_ipa_set_tether_client_pipe() -
2668 * @data - IOCTL data
2669 *
2670 * This function handles WAN_IOC_SET_DATA_QUOTA.
2671 * It translates the given interface name to the Modem MUX ID and
2672 * sends the request of the quota to the IPA Modem driver via QMI.
2673 *
2674 * Return codes:
2675 * 0: Success
2676 * -EFAULT: Invalid interface name provided
2677 * other: See ipa_qmi_set_data_quota
2678 */
2679int rmnet_ipa3_set_tether_client_pipe(
2680 struct wan_ioctl_set_tether_client_pipe *data)
2681{
2682 int number, i;
2683
2684 IPAWANDBG("client %d, UL %d, DL %d, reset %d\n",
2685 data->ipa_client,
2686 data->ul_src_pipe_len,
2687 data->dl_dst_pipe_len,
2688 data->reset_client);
2689 number = data->ul_src_pipe_len;
2690 for (i = 0; i < number; i++) {
2691 IPAWANDBG("UL index-%d pipe %d\n", i,
2692 data->ul_src_pipe_list[i]);
2693 if (data->reset_client)
2694 ipa3_set_client(data->ul_src_pipe_list[i],
2695 0, false);
2696 else
2697 ipa3_set_client(data->ul_src_pipe_list[i],
2698 data->ipa_client, true);
2699 }
2700 number = data->dl_dst_pipe_len;
2701 for (i = 0; i < number; i++) {
2702 IPAWANDBG("DL index-%d pipe %d\n", i,
2703 data->dl_dst_pipe_list[i]);
2704 if (data->reset_client)
2705 ipa3_set_client(data->dl_dst_pipe_list[i],
2706 0, false);
2707 else
2708 ipa3_set_client(data->dl_dst_pipe_list[i],
2709 data->ipa_client, false);
2710 }
2711 return 0;
2712}
2713
2714int rmnet_ipa3_query_tethering_stats(struct wan_ioctl_query_tether_stats *data,
2715 bool reset)
2716{
2717 struct ipa_get_data_stats_req_msg_v01 *req;
2718 struct ipa_get_data_stats_resp_msg_v01 *resp;
2719 int pipe_len, rc;
2720
2721 req = kzalloc(sizeof(struct ipa_get_data_stats_req_msg_v01),
2722 GFP_KERNEL);
2723 if (!req) {
2724 IPAWANERR("Can't allocate memory for stats message\n");
2725 return -ENOMEM;
2726 }
2727 resp = kzalloc(sizeof(struct ipa_get_data_stats_resp_msg_v01),
2728 GFP_KERNEL);
2729 if (!resp) {
2730 IPAWANERR("Can't allocate memory for stats message\n");
2731 kfree(req);
2732 return -ENOMEM;
2733 }
2734 memset(req, 0, sizeof(struct ipa_get_data_stats_req_msg_v01));
2735 memset(resp, 0, sizeof(struct ipa_get_data_stats_resp_msg_v01));
2736
2737 req->ipa_stats_type = QMI_IPA_STATS_TYPE_PIPE_V01;
2738 if (reset) {
2739 req->reset_stats_valid = true;
2740 req->reset_stats = true;
2741 IPAWANERR("reset the pipe stats\n");
2742 } else {
2743 /* print tethered-client enum */
2744 IPAWANDBG_LOW("Tethered-client enum(%d)\n", data->ipa_client);
2745 }
2746
2747 rc = ipa3_qmi_get_data_stats(req, resp);
2748 if (rc) {
2749 IPAWANERR("can't get ipa_qmi_get_data_stats\n");
2750 kfree(req);
2751 kfree(resp);
2752 return rc;
2753 } else if (reset) {
2754 kfree(req);
2755 kfree(resp);
2756 return 0;
2757 }
2758
2759 if (resp->dl_dst_pipe_stats_list_valid) {
2760 for (pipe_len = 0; pipe_len < resp->dl_dst_pipe_stats_list_len;
2761 pipe_len++) {
2762 IPAWANDBG_LOW("Check entry(%d) dl_dst_pipe(%d)\n",
2763 pipe_len, resp->dl_dst_pipe_stats_list
2764 [pipe_len].pipe_index);
2765 IPAWANDBG_LOW("dl_p_v4(%lu)v6(%lu)\n",
2766 (unsigned long int) resp->
2767 dl_dst_pipe_stats_list[pipe_len].
2768 num_ipv4_packets,
2769 (unsigned long int) resp->
2770 dl_dst_pipe_stats_list[pipe_len].
2771 num_ipv6_packets);
2772 IPAWANDBG_LOW("dl_b_v4(%lu)v6(%lu)\n",
2773 (unsigned long int) resp->
2774 dl_dst_pipe_stats_list[pipe_len].
2775 num_ipv4_bytes,
2776 (unsigned long int) resp->
2777 dl_dst_pipe_stats_list[pipe_len].
2778 num_ipv6_bytes);
2779 if (ipa_get_client_uplink(resp->
2780 dl_dst_pipe_stats_list[pipe_len].
2781 pipe_index) == false) {
2782 if (data->ipa_client == ipa_get_client(resp->
2783 dl_dst_pipe_stats_list[pipe_len].
2784 pipe_index)) {
2785 /* update the DL stats */
2786 data->ipv4_rx_packets += resp->
2787 dl_dst_pipe_stats_list[pipe_len].
2788 num_ipv4_packets;
2789 data->ipv6_rx_packets += resp->
2790 dl_dst_pipe_stats_list[pipe_len].
2791 num_ipv6_packets;
2792 data->ipv4_rx_bytes += resp->
2793 dl_dst_pipe_stats_list[pipe_len].
2794 num_ipv4_bytes;
2795 data->ipv6_rx_bytes += resp->
2796 dl_dst_pipe_stats_list[pipe_len].
2797 num_ipv6_bytes;
2798 }
2799 }
2800 }
2801 }
2802 IPAWANDBG_LOW("v4_rx_p(%lu) v6_rx_p(%lu) v4_rx_b(%lu) v6_rx_b(%lu)\n",
2803 (unsigned long int) data->ipv4_rx_packets,
2804 (unsigned long int) data->ipv6_rx_packets,
2805 (unsigned long int) data->ipv4_rx_bytes,
2806 (unsigned long int) data->ipv6_rx_bytes);
2807
2808 if (resp->ul_src_pipe_stats_list_valid) {
2809 for (pipe_len = 0; pipe_len < resp->ul_src_pipe_stats_list_len;
2810 pipe_len++) {
2811 IPAWANDBG_LOW("Check entry(%d) ul_dst_pipe(%d)\n",
2812 pipe_len,
2813 resp->ul_src_pipe_stats_list[pipe_len].
2814 pipe_index);
2815 IPAWANDBG_LOW("ul_p_v4(%lu)v6(%lu)\n",
2816 (unsigned long int) resp->
2817 ul_src_pipe_stats_list[pipe_len].
2818 num_ipv4_packets,
2819 (unsigned long int) resp->
2820 ul_src_pipe_stats_list[pipe_len].
2821 num_ipv6_packets);
2822 IPAWANDBG_LOW("ul_b_v4(%lu)v6(%lu)\n",
2823 (unsigned long int) resp->
2824 ul_src_pipe_stats_list[pipe_len].
2825 num_ipv4_bytes,
2826 (unsigned long int) resp->
2827 ul_src_pipe_stats_list[pipe_len].
2828 num_ipv6_bytes);
2829 if (ipa_get_client_uplink(resp->
2830 ul_src_pipe_stats_list[pipe_len].
2831 pipe_index) == true) {
2832 if (data->ipa_client == ipa_get_client(resp->
2833 ul_src_pipe_stats_list[pipe_len].
2834 pipe_index)) {
2835 /* update the DL stats */
2836 data->ipv4_tx_packets += resp->
2837 ul_src_pipe_stats_list[pipe_len].
2838 num_ipv4_packets;
2839 data->ipv6_tx_packets += resp->
2840 ul_src_pipe_stats_list[pipe_len].
2841 num_ipv6_packets;
2842 data->ipv4_tx_bytes += resp->
2843 ul_src_pipe_stats_list[pipe_len].
2844 num_ipv4_bytes;
2845 data->ipv6_tx_bytes += resp->
2846 ul_src_pipe_stats_list[pipe_len].
2847 num_ipv6_bytes;
2848 }
2849 }
2850 }
2851 }
2852 IPAWANDBG_LOW("tx_p_v4(%lu)v6(%lu)tx_b_v4(%lu) v6(%lu)\n",
2853 (unsigned long int) data->ipv4_tx_packets,
2854 (unsigned long int) data->ipv6_tx_packets,
2855 (unsigned long int) data->ipv4_tx_bytes,
2856 (unsigned long int) data->ipv6_tx_bytes);
2857 kfree(req);
2858 kfree(resp);
2859 return 0;
2860}
2861
2862/**
2863 * ipa3_broadcast_quota_reach_ind() - Send Netlink broadcast on Quota
2864 * @mux_id - The MUX ID on which the quota has been reached
2865 *
2866 * This function broadcasts a Netlink event using the kobject of the
2867 * rmnet_ipa interface in order to alert the user space that the quota
2868 * on the specific interface which matches the mux_id has been reached.
2869 *
2870 */
2871void ipa3_broadcast_quota_reach_ind(u32 mux_id)
2872{
2873 char alert_msg[IPA_QUOTA_REACH_ALERT_MAX_SIZE];
2874 char iface_name_m[IPA_QUOTA_REACH_IF_NAME_MAX_SIZE];
2875 char iface_name_l[IPA_QUOTA_REACH_IF_NAME_MAX_SIZE];
2876 char *envp[IPA_UEVENT_NUM_EVNP] = {
2877 alert_msg, iface_name_l, iface_name_m, NULL };
2878 int res;
2879 int index;
2880
2881 index = ipa3_find_mux_channel_index(mux_id);
2882
2883 if (index == MAX_NUM_OF_MUX_CHANNEL) {
2884 IPAWANERR("%u is an mux ID\n", mux_id);
2885 return;
2886 }
2887
2888 res = snprintf(alert_msg, IPA_QUOTA_REACH_ALERT_MAX_SIZE,
2889 "ALERT_NAME=%s", "quotaReachedAlert");
2890 if (res >= IPA_QUOTA_REACH_ALERT_MAX_SIZE) {
2891 IPAWANERR("message too long (%d)", res);
2892 return;
2893 }
2894 /* posting msg for L-release for CNE */
2895 res = snprintf(iface_name_l, IPA_QUOTA_REACH_IF_NAME_MAX_SIZE,
2896 "UPSTREAM=%s", rmnet_ipa3_ctx->mux_channel[index].vchannel_name);
2897 if (res >= IPA_QUOTA_REACH_IF_NAME_MAX_SIZE) {
2898 IPAWANERR("message too long (%d)", res);
2899 return;
2900 }
2901 /* posting msg for M-release for CNE */
2902 res = snprintf(iface_name_m, IPA_QUOTA_REACH_IF_NAME_MAX_SIZE,
2903 "INTERFACE=%s", rmnet_ipa3_ctx->mux_channel[index].vchannel_name);
2904 if (res >= IPA_QUOTA_REACH_IF_NAME_MAX_SIZE) {
2905 IPAWANERR("message too long (%d)", res);
2906 return;
2907 }
2908
2909 IPAWANERR("putting nlmsg: <%s> <%s> <%s>\n",
2910 alert_msg, iface_name_l, iface_name_m);
2911 kobject_uevent_env(&(IPA_NETDEV()->dev.kobj),
2912 KOBJ_CHANGE, envp);
2913}
2914
2915/**
2916 * ipa3_q6_handshake_complete() - Perform operations once Q6 is up
2917 * @ssr_bootup - Indicates whether this is a cold boot-up or post-SSR.
2918 *
2919 * This function is invoked once the handshake between the IPA AP driver
2920 * and IPA Q6 driver is complete. At this point, it is possible to perform
2921 * operations which can't be performed until IPA Q6 driver is up.
2922 *
2923 */
2924void ipa3_q6_handshake_complete(bool ssr_bootup)
2925{
2926 /* It is required to recover the network stats after SSR recovery */
2927 if (ssr_bootup) {
2928 /*
2929 * In case the uC is required to be loaded by the Modem,
2930 * the proxy vote will be removed only when uC loading is
2931 * complete and indication is received by the AP. After SSR,
2932 * uC is already loaded. Therefore, proxy vote can be removed
2933 * once Modem init is complete.
2934 */
2935 ipa3_proxy_clk_unvote();
2936
2937 /*
2938 * It is required to recover the network stats after
2939 * SSR recovery
2940 */
2941 rmnet_ipa_get_network_stats_and_update();
2942 }
2943}
2944
2945static int __init ipa3_wwan_init(void)
2946{
2947 rmnet_ipa3_ctx = kzalloc(sizeof(*rmnet_ipa3_ctx), GFP_KERNEL);
2948 if (!rmnet_ipa3_ctx) {
2949 IPAWANERR("no memory\n");
2950 return -ENOMEM;
2951 }
2952
2953 atomic_set(&rmnet_ipa3_ctx->is_initialized, 0);
2954 atomic_set(&rmnet_ipa3_ctx->is_ssr, 0);
2955
Ghanim Fodic6b67492017-03-15 14:19:56 +02002956 mutex_init(&rmnet_ipa3_ctx->pipe_handle_guard);
Amir Levy9659e592016-10-27 18:08:27 +03002957 rmnet_ipa3_ctx->ipa3_to_apps_hdl = -1;
Ghanim Fodic6b67492017-03-15 14:19:56 +02002958 rmnet_ipa3_ctx->apps_to_ipa3_hdl = -1;
Amir Levy9659e592016-10-27 18:08:27 +03002959 /* Register for Modem SSR */
2960 rmnet_ipa3_ctx->subsys_notify_handle = subsys_notif_register_notifier(
2961 SUBSYS_MODEM,
2962 &ipa3_ssr_notifier);
2963 if (!IS_ERR(rmnet_ipa3_ctx->subsys_notify_handle))
2964 return platform_driver_register(&rmnet_ipa_driver);
2965 else
2966 return (int)PTR_ERR(rmnet_ipa3_ctx->subsys_notify_handle);
2967}
2968
2969static void __exit ipa3_wwan_cleanup(void)
2970{
2971 int ret;
2972
Ghanim Fodic6b67492017-03-15 14:19:56 +02002973 mutex_destroy(&rmnet_ipa3_ctx->pipe_handle_guard);
Amir Levy9659e592016-10-27 18:08:27 +03002974 ret = subsys_notif_unregister_notifier(
2975 rmnet_ipa3_ctx->subsys_notify_handle, &ipa3_ssr_notifier);
2976 if (ret)
2977 IPAWANERR(
2978 "Error subsys_notif_unregister_notifier system %s, ret=%d\n",
2979 SUBSYS_MODEM, ret);
2980 platform_driver_unregister(&rmnet_ipa_driver);
2981 kfree(rmnet_ipa3_ctx);
2982 rmnet_ipa3_ctx = NULL;
2983}
2984
2985static void ipa3_wwan_msg_free_cb(void *buff, u32 len, u32 type)
2986{
2987 if (!buff)
2988 IPAWANERR("Null buffer.\n");
2989 kfree(buff);
2990}
2991
2992static void ipa3_rmnet_rx_cb(void *priv)
2993{
2994 IPAWANDBG_LOW("\n");
2995 napi_schedule(&(rmnet_ipa3_ctx->wwan_priv->napi));
2996}
2997
2998static int ipa3_rmnet_poll(struct napi_struct *napi, int budget)
2999{
3000 int rcvd_pkts = 0;
3001
3002 rcvd_pkts = ipa_rx_poll(rmnet_ipa3_ctx->ipa3_to_apps_hdl,
3003 NAPI_WEIGHT);
3004 IPAWANDBG_LOW("rcvd packets: %d\n", rcvd_pkts);
3005 return rcvd_pkts;
3006}
3007
3008late_initcall(ipa3_wwan_init);
3009module_exit(ipa3_wwan_cleanup);
3010MODULE_DESCRIPTION("WWAN Network Interface");
3011MODULE_LICENSE("GPL v2");