blob: 77c1d105713f2597993df56506df517107ccf9e2 [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
50#define DEFAULT_OUTSTANDING_HIGH_CTL 96
51#define DEFAULT_OUTSTANDING_HIGH 64
52#define DEFAULT_OUTSTANDING_LOW 32
53
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;
140 struct mutex ipa_to_apps_pipe_handle_guard;
141};
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;
661 param->ep = IPA_CLIENT_APPS_LAN_WAN_PROD;
662 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 =
700 ipa3_get_ep_mapping(IPA_CLIENT_APPS_LAN_WAN_PROD);
701 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;
834 rx_ipv4_property->src_pipe = IPA_CLIENT_APPS_LAN_WAN_PROD;
835 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;
841 rx_ipv6_property->src_pipe = IPA_CLIENT_APPS_LAN_WAN_PROD;
842 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;
1119 ret = ipa3_tx_dp(IPA_CLIENT_Q6_LAN_CONS, skb, &meta);
1120 } else {
1121 ret = ipa3_tx_dp(IPA_CLIENT_APPS_LAN_WAN_PROD, skb, NULL);
1122 }
1123
1124 if (ret) {
1125 ret = NETDEV_TX_BUSY;
1126 dev->stats.tx_dropped++;
1127 goto out;
1128 }
1129
1130 atomic_inc(&wwan_ptr->outstanding_pkts);
1131 dev->stats.tx_packets++;
1132 dev->stats.tx_bytes += skb->len;
1133 ret = NETDEV_TX_OK;
1134out:
Skylar Changf3a7dac2017-01-25 09:16:55 -08001135 if (atomic_read(&wwan_ptr->outstanding_pkts) == 0)
1136 ipa_rm_inactivity_timer_release_resource(
1137 IPA_RM_RESOURCE_WWAN_0_PROD);
Amir Levy9659e592016-10-27 18:08:27 +03001138 return ret;
1139}
1140
1141static void ipa3_wwan_tx_timeout(struct net_device *dev)
1142{
1143 IPAWANERR("[%s] ipa3_wwan_tx_timeout(), data stall in UL\n", dev->name);
1144}
1145
1146/**
1147 * apps_ipa_tx_complete_notify() - Rx notify
1148 *
1149 * @priv: driver context
1150 * @evt: event type
1151 * @data: data provided with event
1152 *
1153 * Check that the packet is the one we sent and release it
1154 * This function will be called in defered context in IPA wq.
1155 */
1156static void apps_ipa_tx_complete_notify(void *priv,
1157 enum ipa_dp_evt_type evt,
1158 unsigned long data)
1159{
1160 struct sk_buff *skb = (struct sk_buff *)data;
1161 struct net_device *dev = (struct net_device *)priv;
1162 struct ipa3_wwan_private *wwan_ptr;
1163
1164 if (dev != IPA_NETDEV()) {
1165 IPAWANDBG("Received pre-SSR packet completion\n");
1166 dev_kfree_skb_any(skb);
1167 return;
1168 }
1169
1170 if (evt != IPA_WRITE_DONE) {
1171 IPAWANERR("unsupported evt on Tx callback, Drop the packet\n");
1172 dev_kfree_skb_any(skb);
1173 dev->stats.tx_dropped++;
1174 return;
1175 }
1176
1177 wwan_ptr = netdev_priv(dev);
1178 atomic_dec(&wwan_ptr->outstanding_pkts);
1179 __netif_tx_lock_bh(netdev_get_tx_queue(dev, 0));
1180 if (!atomic_read(&rmnet_ipa3_ctx->is_ssr) &&
1181 netif_queue_stopped(wwan_ptr->net) &&
1182 atomic_read(&wwan_ptr->outstanding_pkts) <
1183 (wwan_ptr->outstanding_low)) {
1184 IPAWANDBG_LOW("Outstanding low (%d) - waking up queue\n",
1185 wwan_ptr->outstanding_low);
1186 netif_wake_queue(wwan_ptr->net);
1187 }
Skylar Changf3a7dac2017-01-25 09:16:55 -08001188
1189 if (atomic_read(&wwan_ptr->outstanding_pkts) == 0)
1190 ipa_rm_inactivity_timer_release_resource(
1191 IPA_RM_RESOURCE_WWAN_0_PROD);
Amir Levy9659e592016-10-27 18:08:27 +03001192 __netif_tx_unlock_bh(netdev_get_tx_queue(dev, 0));
1193 dev_kfree_skb_any(skb);
Amir Levy9659e592016-10-27 18:08:27 +03001194}
1195
1196/**
1197 * apps_ipa_packet_receive_notify() - Rx notify
1198 *
1199 * @priv: driver context
1200 * @evt: event type
1201 * @data: data provided with event
1202 *
1203 * IPA will pass a packet to the Linux network stack with skb->data
1204 */
1205static void apps_ipa_packet_receive_notify(void *priv,
1206 enum ipa_dp_evt_type evt,
1207 unsigned long data)
1208{
1209 struct net_device *dev = (struct net_device *)priv;
1210
1211 if (evt == IPA_RECEIVE) {
1212 struct sk_buff *skb = (struct sk_buff *)data;
1213 int result;
1214 unsigned int packet_len = skb->len;
1215
1216 IPAWANDBG_LOW("Rx packet was received");
1217 skb->dev = IPA_NETDEV();
1218 skb->protocol = htons(ETH_P_MAP);
1219
1220 if (ipa3_rmnet_res.ipa_napi_enable) {
1221 trace_rmnet_ipa_netif_rcv_skb3(dev->stats.rx_packets);
1222 result = netif_receive_skb(skb);
1223 } else {
1224 if (dev->stats.rx_packets % IPA_WWAN_RX_SOFTIRQ_THRESH
1225 == 0) {
1226 trace_rmnet_ipa_netifni3(dev->stats.rx_packets);
1227 result = netif_rx_ni(skb);
1228 } else {
1229 trace_rmnet_ipa_netifrx3(dev->stats.rx_packets);
1230 result = netif_rx(skb);
1231 }
1232 }
1233
1234 if (result) {
1235 pr_err_ratelimited(DEV_NAME " %s:%d fail on netif_receive_skb\n",
1236 __func__, __LINE__);
1237 dev->stats.rx_dropped++;
1238 }
1239 dev->stats.rx_packets++;
1240 dev->stats.rx_bytes += packet_len;
1241 } else if (evt == IPA_CLIENT_START_POLL)
1242 ipa3_rmnet_rx_cb(priv);
1243 else if (evt == IPA_CLIENT_COMP_NAPI) {
1244 if (ipa3_rmnet_res.ipa_napi_enable)
1245 napi_complete(&(rmnet_ipa3_ctx->wwan_priv->napi));
1246 } else
1247 IPAWANERR("Invalid evt %d received in wan_ipa_receive\n", evt);
1248}
1249
Gidon Studinski3021a6f2016-11-10 12:48:48 +02001250static int handle3_ingress_format(struct net_device *dev,
1251 struct rmnet_ioctl_extended_s *in)
1252{
1253 int ret = 0;
1254 struct ipa_sys_connect_params *ipa_wan_ep_cfg;
1255 struct rmnet_phys_ep_conf_s *ep_cfg;
1256
1257 IPAWANDBG("Get RMNET_IOCTL_SET_INGRESS_DATA_FORMAT\n");
1258 ipa_wan_ep_cfg = &rmnet_ipa3_ctx->ipa_to_apps_ep_cfg;
1259 if ((in->u.data) & RMNET_IOCTL_INGRESS_FORMAT_CHECKSUM)
1260 ipa_wan_ep_cfg->ipa_ep_cfg.cfg.cs_offload_en =
1261 IPA_ENABLE_CS_OFFLOAD_DL;
1262
1263 if ((in->u.data) & RMNET_IOCTL_INGRESS_FORMAT_AGG_DATA) {
1264 IPAWANERR("get AGG size %d count %d\n",
1265 in->u.ingress_format.agg_size,
1266 in->u.ingress_format.agg_count);
1267
1268 ret = ipa_disable_apps_wan_cons_deaggr(
1269 in->u.ingress_format.agg_size,
1270 in->u.ingress_format.agg_count);
1271
1272 if (!ret) {
1273 ipa_wan_ep_cfg->ipa_ep_cfg.aggr.aggr_byte_limit =
1274 in->u.ingress_format.agg_size;
1275 ipa_wan_ep_cfg->ipa_ep_cfg.aggr.aggr_pkt_limit =
1276 in->u.ingress_format.agg_count;
1277
1278 if (ipa_wan_ep_cfg->napi_enabled) {
1279 ipa_wan_ep_cfg->recycle_enabled = true;
1280 ep_cfg = (struct rmnet_phys_ep_conf_s *)
1281 rcu_dereference(dev->rx_handler_data);
1282 ep_cfg->recycle = ipa_recycle_wan_skb;
1283 pr_info("Wan Recycle Enabled\n");
1284 }
1285 }
1286 }
1287
1288 ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_len = 4;
1289 ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
1290 ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_metadata = 1;
1291 ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
1292 ipa_wan_ep_cfg->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 2;
1293
1294 ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad_valid = true;
1295 ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad = 0;
1296 ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_payload_len_inc_padding = true;
1297 ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad_offset = 0;
1298 ipa_wan_ep_cfg->ipa_ep_cfg.hdr_ext.hdr_little_endian = 0;
1299 ipa_wan_ep_cfg->ipa_ep_cfg.metadata_mask.metadata_mask = 0xFF000000;
1300
1301 ipa_wan_ep_cfg->client = IPA_CLIENT_APPS_WAN_CONS;
1302 ipa_wan_ep_cfg->notify = apps_ipa_packet_receive_notify;
1303 ipa_wan_ep_cfg->priv = dev;
1304
1305 ipa_wan_ep_cfg->napi_enabled = ipa3_rmnet_res.ipa_napi_enable;
1306 if (ipa_wan_ep_cfg->napi_enabled)
1307 ipa_wan_ep_cfg->desc_fifo_sz = IPA_WAN_CONS_DESC_FIFO_SZ;
1308 else
1309 ipa_wan_ep_cfg->desc_fifo_sz = IPA_SYS_DESC_FIFO_SZ;
1310
1311 mutex_lock(&rmnet_ipa3_ctx->ipa_to_apps_pipe_handle_guard);
1312
1313 if (atomic_read(&rmnet_ipa3_ctx->is_ssr)) {
1314 IPAWANDBG("In SSR sequence/recovery\n");
1315 mutex_unlock(&rmnet_ipa3_ctx->ipa_to_apps_pipe_handle_guard);
1316 return -EFAULT;
1317 }
1318 ret = ipa3_setup_sys_pipe(&rmnet_ipa3_ctx->ipa_to_apps_ep_cfg,
1319 &rmnet_ipa3_ctx->ipa3_to_apps_hdl);
1320
1321 mutex_unlock(&rmnet_ipa3_ctx->ipa_to_apps_pipe_handle_guard);
1322
1323 if (ret)
1324 IPAWANERR("failed to configure ingress\n");
1325
1326 return ret;
1327}
1328
Amir Levy9659e592016-10-27 18:08:27 +03001329/**
1330 * ipa3_wwan_ioctl() - I/O control for wwan network driver.
1331 *
1332 * @dev: network device
1333 * @ifr: ignored
1334 * @cmd: cmd to be excecuded. can be one of the following:
1335 * IPA_WWAN_IOCTL_OPEN - Open the network interface
1336 * IPA_WWAN_IOCTL_CLOSE - Close the network interface
1337 *
1338 * Return codes:
1339 * 0: success
1340 * NETDEV_TX_BUSY: Error while transmitting the skb. Try again
1341 * later
1342 * -EFAULT: Error while transmitting the skb
1343 */
1344static int ipa3_wwan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1345{
1346 int rc = 0;
1347 int mru = 1000, epid = 1, mux_index, len;
1348 struct ipa_msg_meta msg_meta;
1349 struct ipa_wan_msg *wan_msg = NULL;
1350 struct rmnet_ioctl_extended_s extend_ioctl_data;
1351 struct rmnet_ioctl_data_s ioctl_data;
1352 struct ipa3_rmnet_mux_val *mux_channel;
1353 int rmnet_index;
1354
1355 IPAWANDBG("rmnet_ipa got ioctl number 0x%08x", cmd);
1356 switch (cmd) {
1357 /* Set Ethernet protocol */
1358 case RMNET_IOCTL_SET_LLP_ETHERNET:
1359 break;
1360 /* Set RAWIP protocol */
1361 case RMNET_IOCTL_SET_LLP_IP:
1362 break;
1363 /* Get link protocol */
1364 case RMNET_IOCTL_GET_LLP:
1365 ioctl_data.u.operation_mode = RMNET_MODE_LLP_IP;
1366 if (copy_to_user(ifr->ifr_ifru.ifru_data, &ioctl_data,
1367 sizeof(struct rmnet_ioctl_data_s)))
1368 rc = -EFAULT;
1369 break;
1370 /* Set QoS header enabled */
1371 case RMNET_IOCTL_SET_QOS_ENABLE:
1372 return -EINVAL;
1373 /* Set QoS header disabled */
1374 case RMNET_IOCTL_SET_QOS_DISABLE:
1375 break;
1376 /* Get QoS header state */
1377 case RMNET_IOCTL_GET_QOS:
1378 ioctl_data.u.operation_mode = RMNET_MODE_NONE;
1379 if (copy_to_user(ifr->ifr_ifru.ifru_data, &ioctl_data,
1380 sizeof(struct rmnet_ioctl_data_s)))
1381 rc = -EFAULT;
1382 break;
1383 /* Get operation mode */
1384 case RMNET_IOCTL_GET_OPMODE:
1385 ioctl_data.u.operation_mode = RMNET_MODE_LLP_IP;
1386 if (copy_to_user(ifr->ifr_ifru.ifru_data, &ioctl_data,
1387 sizeof(struct rmnet_ioctl_data_s)))
1388 rc = -EFAULT;
1389 break;
1390 /* Open transport port */
1391 case RMNET_IOCTL_OPEN:
1392 break;
1393 /* Close transport port */
1394 case RMNET_IOCTL_CLOSE:
1395 break;
1396 /* Flow enable */
1397 case RMNET_IOCTL_FLOW_ENABLE:
1398 IPAWANDBG("Received flow enable\n");
1399 if (copy_from_user(&ioctl_data, ifr->ifr_ifru.ifru_data,
1400 sizeof(struct rmnet_ioctl_data_s))) {
1401 rc = -EFAULT;
1402 break;
1403 }
1404 ipa3_flow_control(IPA_CLIENT_USB_PROD, true,
1405 ioctl_data.u.tcm_handle);
1406 break;
1407 /* Flow disable */
1408 case RMNET_IOCTL_FLOW_DISABLE:
1409 IPAWANDBG("Received flow disable\n");
1410 if (copy_from_user(&ioctl_data, ifr->ifr_ifru.ifru_data,
1411 sizeof(struct rmnet_ioctl_data_s))) {
1412 rc = -EFAULT;
1413 break;
1414 }
1415 ipa3_flow_control(IPA_CLIENT_USB_PROD, false,
1416 ioctl_data.u.tcm_handle);
1417 break;
1418 /* Set flow handle */
1419 case RMNET_IOCTL_FLOW_SET_HNDL:
1420 break;
1421
1422 /* Extended IOCTLs */
1423 case RMNET_IOCTL_EXTENDED:
1424 IPAWANDBG("get ioctl: RMNET_IOCTL_EXTENDED\n");
1425 if (copy_from_user(&extend_ioctl_data,
1426 (u8 *)ifr->ifr_ifru.ifru_data,
1427 sizeof(struct rmnet_ioctl_extended_s))) {
1428 IPAWANERR("failed to copy extended ioctl data\n");
1429 rc = -EFAULT;
1430 break;
1431 }
1432 switch (extend_ioctl_data.extended_ioctl) {
1433 /* Get features */
1434 case RMNET_IOCTL_GET_SUPPORTED_FEATURES:
1435 IPAWANDBG("get RMNET_IOCTL_GET_SUPPORTED_FEATURES\n");
1436 extend_ioctl_data.u.data =
1437 (RMNET_IOCTL_FEAT_NOTIFY_MUX_CHANNEL |
1438 RMNET_IOCTL_FEAT_SET_EGRESS_DATA_FORMAT |
1439 RMNET_IOCTL_FEAT_SET_INGRESS_DATA_FORMAT);
1440 if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data,
1441 &extend_ioctl_data,
1442 sizeof(struct rmnet_ioctl_extended_s)))
1443 rc = -EFAULT;
1444 break;
1445 /* Set MRU */
1446 case RMNET_IOCTL_SET_MRU:
1447 mru = extend_ioctl_data.u.data;
1448 IPAWANDBG("get MRU size %d\n",
1449 extend_ioctl_data.u.data);
1450 break;
1451 /* Get MRU */
1452 case RMNET_IOCTL_GET_MRU:
1453 extend_ioctl_data.u.data = mru;
1454 if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data,
1455 &extend_ioctl_data,
1456 sizeof(struct rmnet_ioctl_extended_s)))
1457 rc = -EFAULT;
1458 break;
1459 /* GET SG support */
1460 case RMNET_IOCTL_GET_SG_SUPPORT:
1461 extend_ioctl_data.u.data =
1462 ipa3_rmnet_res.ipa_advertise_sg_support;
1463 if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data,
1464 &extend_ioctl_data,
1465 sizeof(struct rmnet_ioctl_extended_s)))
1466 rc = -EFAULT;
1467 break;
1468 /* Get endpoint ID */
1469 case RMNET_IOCTL_GET_EPID:
1470 IPAWANDBG("get ioctl: RMNET_IOCTL_GET_EPID\n");
1471 extend_ioctl_data.u.data = epid;
1472 if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data,
1473 &extend_ioctl_data,
1474 sizeof(struct rmnet_ioctl_extended_s)))
1475 rc = -EFAULT;
1476 if (copy_from_user(&extend_ioctl_data,
1477 (u8 *)ifr->ifr_ifru.ifru_data,
1478 sizeof(struct rmnet_ioctl_extended_s))) {
1479 IPAWANERR("copy extended ioctl data failed\n");
1480 rc = -EFAULT;
1481 break;
1482 }
1483 IPAWANDBG("RMNET_IOCTL_GET_EPID return %d\n",
1484 extend_ioctl_data.u.data);
1485 break;
1486 /* Endpoint pair */
1487 case RMNET_IOCTL_GET_EP_PAIR:
1488 IPAWANDBG("get ioctl: RMNET_IOCTL_GET_EP_PAIR\n");
1489 extend_ioctl_data.u.ipa_ep_pair.consumer_pipe_num =
1490 ipa3_get_ep_mapping(IPA_CLIENT_APPS_LAN_WAN_PROD);
1491 extend_ioctl_data.u.ipa_ep_pair.producer_pipe_num =
1492 ipa3_get_ep_mapping(IPA_CLIENT_APPS_WAN_CONS);
1493 if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data,
1494 &extend_ioctl_data,
1495 sizeof(struct rmnet_ioctl_extended_s)))
1496 rc = -EFAULT;
1497 if (copy_from_user(&extend_ioctl_data,
1498 (u8 *)ifr->ifr_ifru.ifru_data,
1499 sizeof(struct rmnet_ioctl_extended_s))) {
1500 IPAWANERR("copy extended ioctl data failed\n");
1501 rc = -EFAULT;
1502 break;
1503 }
1504 IPAWANDBG("RMNET_IOCTL_GET_EP_PAIR c: %d p: %d\n",
1505 extend_ioctl_data.u.ipa_ep_pair.consumer_pipe_num,
1506 extend_ioctl_data.u.ipa_ep_pair.producer_pipe_num);
1507 break;
1508 /* Get driver name */
1509 case RMNET_IOCTL_GET_DRIVER_NAME:
1510 memcpy(&extend_ioctl_data.u.if_name,
1511 IPA_NETDEV()->name,
1512 sizeof(IFNAMSIZ));
1513 if (copy_to_user((u8 *)ifr->ifr_ifru.ifru_data,
1514 &extend_ioctl_data,
1515 sizeof(struct rmnet_ioctl_extended_s)))
1516 rc = -EFAULT;
1517 break;
1518 /* Add MUX ID */
1519 case RMNET_IOCTL_ADD_MUX_CHANNEL:
1520 mux_index = ipa3_find_mux_channel_index(
1521 extend_ioctl_data.u.rmnet_mux_val.mux_id);
1522 if (mux_index < MAX_NUM_OF_MUX_CHANNEL) {
1523 IPAWANDBG("already setup mux(%d)\n",
1524 extend_ioctl_data.u.
1525 rmnet_mux_val.mux_id);
1526 return rc;
1527 }
1528 if (rmnet_ipa3_ctx->rmnet_index
1529 >= MAX_NUM_OF_MUX_CHANNEL) {
1530 IPAWANERR("Exceed mux_channel limit(%d)\n",
1531 rmnet_ipa3_ctx->rmnet_index);
1532 return -EFAULT;
1533 }
1534 IPAWANDBG("ADD_MUX_CHANNEL(%d, name: %s)\n",
1535 extend_ioctl_data.u.rmnet_mux_val.mux_id,
1536 extend_ioctl_data.u.rmnet_mux_val.vchannel_name);
1537 /* cache the mux name and id */
1538 mux_channel = rmnet_ipa3_ctx->mux_channel;
1539 rmnet_index = rmnet_ipa3_ctx->rmnet_index;
1540
1541 mux_channel[rmnet_index].mux_id =
1542 extend_ioctl_data.u.rmnet_mux_val.mux_id;
1543 memcpy(mux_channel[rmnet_index].vchannel_name,
1544 extend_ioctl_data.u.rmnet_mux_val.vchannel_name,
1545 sizeof(mux_channel[rmnet_index]
1546 .vchannel_name));
1547 IPAWANDBG("cashe device[%s:%d] in IPA_wan[%d]\n",
1548 mux_channel[rmnet_index].vchannel_name,
1549 mux_channel[rmnet_index].mux_id,
1550 rmnet_index);
1551 /* check if UL filter rules coming*/
1552 if (rmnet_ipa3_ctx->num_q6_rules != 0) {
1553 IPAWANERR("dev(%s) register to IPA\n",
1554 extend_ioctl_data.u.rmnet_mux_val.
1555 vchannel_name);
1556 rc = ipa3_wwan_register_to_ipa(
1557 rmnet_ipa3_ctx->rmnet_index);
1558 if (rc < 0) {
1559 IPAWANERR("device %s reg IPA failed\n",
1560 extend_ioctl_data.u.
1561 rmnet_mux_val.vchannel_name);
1562 return -ENODEV;
1563 }
1564 mux_channel[rmnet_index].mux_channel_set = true;
1565 mux_channel[rmnet_index].ul_flt_reg = true;
1566 } else {
1567 IPAWANDBG("dev(%s) haven't registered to IPA\n",
1568 extend_ioctl_data.u.
1569 rmnet_mux_val.vchannel_name);
1570 mux_channel[rmnet_index].mux_channel_set = true;
1571 mux_channel[rmnet_index].ul_flt_reg = false;
1572 }
1573 rmnet_ipa3_ctx->rmnet_index++;
1574 break;
1575 case RMNET_IOCTL_SET_EGRESS_DATA_FORMAT:
1576 IPAWANDBG("get RMNET_IOCTL_SET_EGRESS_DATA_FORMAT\n");
1577 if ((extend_ioctl_data.u.data) &
1578 RMNET_IOCTL_EGRESS_FORMAT_CHECKSUM) {
1579 rmnet_ipa3_ctx->apps_to_ipa_ep_cfg.
1580 ipa_ep_cfg.hdr.hdr_len = 8;
1581 rmnet_ipa3_ctx->apps_to_ipa_ep_cfg.
1582 ipa_ep_cfg.cfg.cs_offload_en =
1583 IPA_ENABLE_CS_OFFLOAD_UL;
1584 rmnet_ipa3_ctx->apps_to_ipa_ep_cfg.
1585 ipa_ep_cfg.cfg.cs_metadata_hdr_offset
1586 = 1;
1587 } else {
1588 rmnet_ipa3_ctx->apps_to_ipa_ep_cfg.
1589 ipa_ep_cfg.hdr.hdr_len = 4;
1590 }
1591 if ((extend_ioctl_data.u.data) &
1592 RMNET_IOCTL_EGRESS_FORMAT_AGGREGATION)
1593 rmnet_ipa3_ctx->apps_to_ipa_ep_cfg.
1594 ipa_ep_cfg.aggr.aggr_en =
1595 IPA_ENABLE_AGGR;
1596 else
1597 rmnet_ipa3_ctx->apps_to_ipa_ep_cfg.
1598 ipa_ep_cfg.aggr.aggr_en =
1599 IPA_BYPASS_AGGR;
1600 rmnet_ipa3_ctx->apps_to_ipa_ep_cfg.ipa_ep_cfg.hdr.
1601 hdr_ofst_metadata_valid = 1;
1602 /* modem want offset at 0! */
1603 rmnet_ipa3_ctx->apps_to_ipa_ep_cfg.ipa_ep_cfg.hdr.
1604 hdr_ofst_metadata = 0;
1605 rmnet_ipa3_ctx->apps_to_ipa_ep_cfg.ipa_ep_cfg.mode.
1606 dst = IPA_CLIENT_APPS_LAN_WAN_PROD;
1607 rmnet_ipa3_ctx->apps_to_ipa_ep_cfg.ipa_ep_cfg.mode.
1608 mode = IPA_BASIC;
1609
1610 rmnet_ipa3_ctx->apps_to_ipa_ep_cfg.client =
1611 IPA_CLIENT_APPS_LAN_WAN_PROD;
1612 rmnet_ipa3_ctx->apps_to_ipa_ep_cfg.notify =
1613 apps_ipa_tx_complete_notify;
1614 rmnet_ipa3_ctx->apps_to_ipa_ep_cfg.desc_fifo_sz =
1615 IPA_SYS_TX_DATA_DESC_FIFO_SZ;
1616 rmnet_ipa3_ctx->apps_to_ipa_ep_cfg.priv = dev;
1617
1618 rc = ipa3_setup_sys_pipe(
1619 &rmnet_ipa3_ctx->apps_to_ipa_ep_cfg,
1620 &rmnet_ipa3_ctx->apps_to_ipa3_hdl);
1621 if (rc)
1622 IPAWANERR("failed to config egress endpoint\n");
1623
1624 if (rmnet_ipa3_ctx->num_q6_rules != 0) {
1625 /* already got Q6 UL filter rules*/
1626 if (ipa3_qmi_ctx->modem_cfg_emb_pipe_flt
1627 == false)
1628 rc = ipa3_wwan_add_ul_flt_rule_to_ipa();
1629 else
1630 rc = 0;
1631 rmnet_ipa3_ctx->egress_set = true;
1632 if (rc)
1633 IPAWANERR("install UL rules failed\n");
1634 else
1635 rmnet_ipa3_ctx->a7_ul_flt_set = true;
1636 } else {
1637 /* wait Q6 UL filter rules*/
1638 rmnet_ipa3_ctx->egress_set = true;
1639 IPAWANDBG("no UL-rules, egress_set(%d)\n",
1640 rmnet_ipa3_ctx->egress_set);
1641 }
1642 break;
1643 case RMNET_IOCTL_SET_INGRESS_DATA_FORMAT:/* Set IDF */
Gidon Studinski3021a6f2016-11-10 12:48:48 +02001644 rc = handle3_ingress_format(dev, &extend_ioctl_data);
Amir Levy9659e592016-10-27 18:08:27 +03001645 break;
1646 case RMNET_IOCTL_SET_XLAT_DEV_INFO:
1647 wan_msg = kzalloc(sizeof(struct ipa_wan_msg),
1648 GFP_KERNEL);
1649 if (!wan_msg) {
1650 IPAWANERR("Failed to allocate memory.\n");
1651 return -ENOMEM;
1652 }
1653 len = sizeof(wan_msg->upstream_ifname) >
1654 sizeof(extend_ioctl_data.u.if_name) ?
1655 sizeof(extend_ioctl_data.u.if_name) :
1656 sizeof(wan_msg->upstream_ifname);
1657 strlcpy(wan_msg->upstream_ifname,
1658 extend_ioctl_data.u.if_name, len);
1659 memset(&msg_meta, 0, sizeof(struct ipa_msg_meta));
1660 msg_meta.msg_type = WAN_XLAT_CONNECT;
1661 msg_meta.msg_len = sizeof(struct ipa_wan_msg);
1662 rc = ipa3_send_msg(&msg_meta, wan_msg,
1663 ipa3_wwan_msg_free_cb);
1664 if (rc) {
1665 IPAWANERR("Failed to send XLAT_CONNECT msg\n");
1666 kfree(wan_msg);
1667 }
1668 break;
1669 /* Get agg count */
1670 case RMNET_IOCTL_GET_AGGREGATION_COUNT:
1671 break;
1672 /* Set agg count */
1673 case RMNET_IOCTL_SET_AGGREGATION_COUNT:
1674 break;
1675 /* Get agg size */
1676 case RMNET_IOCTL_GET_AGGREGATION_SIZE:
1677 break;
1678 /* Set agg size */
1679 case RMNET_IOCTL_SET_AGGREGATION_SIZE:
1680 break;
1681 /* Do flow control */
1682 case RMNET_IOCTL_FLOW_CONTROL:
1683 break;
1684 /* For legacy use */
1685 case RMNET_IOCTL_GET_DFLT_CONTROL_CHANNEL:
1686 break;
1687 /* Get HW/SW map */
1688 case RMNET_IOCTL_GET_HWSW_MAP:
1689 break;
1690 /* Set RX Headroom */
1691 case RMNET_IOCTL_SET_RX_HEADROOM:
1692 break;
1693 default:
1694 IPAWANERR("[%s] unsupported extended cmd[%d]",
1695 dev->name,
1696 extend_ioctl_data.extended_ioctl);
1697 rc = -EINVAL;
1698 }
1699 break;
1700 default:
1701 IPAWANERR("[%s] unsupported cmd[%d]",
1702 dev->name, cmd);
1703 rc = -EINVAL;
1704 }
1705 return rc;
1706}
1707
1708static const struct net_device_ops ipa3_wwan_ops_ip = {
1709 .ndo_open = ipa3_wwan_open,
1710 .ndo_stop = ipa3_wwan_stop,
1711 .ndo_start_xmit = ipa3_wwan_xmit,
1712 .ndo_tx_timeout = ipa3_wwan_tx_timeout,
1713 .ndo_do_ioctl = ipa3_wwan_ioctl,
1714 .ndo_change_mtu = ipa3_wwan_change_mtu,
1715 .ndo_set_mac_address = 0,
1716 .ndo_validate_addr = 0,
1717};
1718
1719/**
1720 * wwan_setup() - Setups the wwan network driver.
1721 *
1722 * @dev: network device
1723 *
1724 * Return codes:
1725 * None
1726 */
1727
1728static void ipa3_wwan_setup(struct net_device *dev)
1729{
1730 dev->netdev_ops = &ipa3_wwan_ops_ip;
1731 ether_setup(dev);
1732 /* set this after calling ether_setup */
1733 dev->header_ops = 0; /* No header */
1734 dev->type = ARPHRD_RAWIP;
1735 dev->hard_header_len = 0;
1736 dev->mtu = WWAN_DATA_LEN;
1737 dev->addr_len = 0;
1738 dev->flags &= ~(IFF_BROADCAST | IFF_MULTICAST);
1739 dev->needed_headroom = HEADROOM_FOR_QMAP;
1740 dev->needed_tailroom = TAILROOM;
1741 dev->watchdog_timeo = 1000;
1742}
1743
1744/* IPA_RM related functions start*/
1745static void ipa3_q6_prod_rm_request_resource(struct work_struct *work);
1746static DECLARE_DELAYED_WORK(ipa3_q6_con_rm_request,
1747 ipa3_q6_prod_rm_request_resource);
1748static void ipa3_q6_prod_rm_release_resource(struct work_struct *work);
1749static DECLARE_DELAYED_WORK(ipa3_q6_con_rm_release,
1750 ipa3_q6_prod_rm_release_resource);
1751
1752static void ipa3_q6_prod_rm_request_resource(struct work_struct *work)
1753{
1754 int ret = 0;
1755
1756 ret = ipa_rm_request_resource(IPA_RM_RESOURCE_Q6_PROD);
1757 if (ret < 0 && ret != -EINPROGRESS) {
1758 IPAWANERR("%s: ipa_rm_request_resource failed %d\n", __func__,
1759 ret);
1760 return;
1761 }
1762}
1763
1764static int ipa3_q6_rm_request_resource(void)
1765{
1766 queue_delayed_work(rmnet_ipa3_ctx->rm_q6_wq,
1767 &ipa3_q6_con_rm_request, 0);
1768 return 0;
1769}
1770
1771static void ipa3_q6_prod_rm_release_resource(struct work_struct *work)
1772{
1773 int ret = 0;
1774
1775 ret = ipa_rm_release_resource(IPA_RM_RESOURCE_Q6_PROD);
1776 if (ret < 0 && ret != -EINPROGRESS) {
1777 IPAWANERR("%s: ipa_rm_release_resource failed %d\n", __func__,
1778 ret);
1779 return;
1780 }
1781}
1782
1783
1784static int ipa3_q6_rm_release_resource(void)
1785{
1786 queue_delayed_work(rmnet_ipa3_ctx->rm_q6_wq,
1787 &ipa3_q6_con_rm_release, 0);
1788 return 0;
1789}
1790
1791
1792static void ipa3_q6_rm_notify_cb(void *user_data,
1793 enum ipa_rm_event event,
1794 unsigned long data)
1795{
1796 switch (event) {
1797 case IPA_RM_RESOURCE_GRANTED:
1798 IPAWANDBG_LOW("%s: Q6_PROD GRANTED CB\n", __func__);
1799 break;
1800 case IPA_RM_RESOURCE_RELEASED:
1801 IPAWANDBG_LOW("%s: Q6_PROD RELEASED CB\n", __func__);
1802 break;
1803 default:
1804 return;
1805 }
1806}
1807static int ipa3_q6_initialize_rm(void)
1808{
1809 struct ipa_rm_create_params create_params;
1810 struct ipa_rm_perf_profile profile;
1811 int result;
1812
1813 /* Initialize IPA_RM workqueue */
1814 rmnet_ipa3_ctx->rm_q6_wq = create_singlethread_workqueue("clnt_req");
1815 if (!rmnet_ipa3_ctx->rm_q6_wq)
1816 return -ENOMEM;
1817
1818 memset(&create_params, 0, sizeof(create_params));
1819 create_params.name = IPA_RM_RESOURCE_Q6_PROD;
1820 create_params.reg_params.notify_cb = &ipa3_q6_rm_notify_cb;
1821 result = ipa_rm_create_resource(&create_params);
1822 if (result)
1823 goto create_rsrc_err1;
1824 memset(&create_params, 0, sizeof(create_params));
1825 create_params.name = IPA_RM_RESOURCE_Q6_CONS;
1826 create_params.release_resource = &ipa3_q6_rm_release_resource;
1827 create_params.request_resource = &ipa3_q6_rm_request_resource;
1828 result = ipa_rm_create_resource(&create_params);
1829 if (result)
1830 goto create_rsrc_err2;
1831 /* add dependency*/
1832 result = ipa_rm_add_dependency(IPA_RM_RESOURCE_Q6_PROD,
1833 IPA_RM_RESOURCE_APPS_CONS);
1834 if (result)
1835 goto add_dpnd_err;
1836 /* setup Performance profile */
1837 memset(&profile, 0, sizeof(profile));
1838 profile.max_supported_bandwidth_mbps = 100;
1839 result = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_Q6_PROD,
1840 &profile);
1841 if (result)
1842 goto set_perf_err;
1843 result = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_Q6_CONS,
1844 &profile);
1845 if (result)
1846 goto set_perf_err;
1847 return result;
1848
1849set_perf_err:
1850 ipa_rm_delete_dependency(IPA_RM_RESOURCE_Q6_PROD,
1851 IPA_RM_RESOURCE_APPS_CONS);
1852add_dpnd_err:
1853 result = ipa_rm_delete_resource(IPA_RM_RESOURCE_Q6_CONS);
1854 if (result < 0)
1855 IPAWANERR("Error deleting resource %d, ret=%d\n",
1856 IPA_RM_RESOURCE_Q6_CONS, result);
1857create_rsrc_err2:
1858 result = ipa_rm_delete_resource(IPA_RM_RESOURCE_Q6_PROD);
1859 if (result < 0)
1860 IPAWANERR("Error deleting resource %d, ret=%d\n",
1861 IPA_RM_RESOURCE_Q6_PROD, result);
1862create_rsrc_err1:
1863 destroy_workqueue(rmnet_ipa3_ctx->rm_q6_wq);
1864 return result;
1865}
1866
1867void ipa3_q6_deinitialize_rm(void)
1868{
1869 int ret;
1870
1871 ret = ipa_rm_delete_dependency(IPA_RM_RESOURCE_Q6_PROD,
1872 IPA_RM_RESOURCE_APPS_CONS);
1873 if (ret < 0)
1874 IPAWANERR("Error deleting dependency %d->%d, ret=%d\n",
1875 IPA_RM_RESOURCE_Q6_PROD, IPA_RM_RESOURCE_APPS_CONS,
1876 ret);
1877 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_Q6_CONS);
1878 if (ret < 0)
1879 IPAWANERR("Error deleting resource %d, ret=%d\n",
1880 IPA_RM_RESOURCE_Q6_CONS, ret);
1881 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_Q6_PROD);
1882 if (ret < 0)
1883 IPAWANERR("Error deleting resource %d, ret=%d\n",
1884 IPA_RM_RESOURCE_Q6_PROD, ret);
1885 destroy_workqueue(rmnet_ipa3_ctx->rm_q6_wq);
1886}
1887
1888static void ipa3_wake_tx_queue(struct work_struct *work)
1889{
1890 if (IPA_NETDEV()) {
1891 __netif_tx_lock_bh(netdev_get_tx_queue(IPA_NETDEV(), 0));
1892 netif_wake_queue(IPA_NETDEV());
1893 __netif_tx_unlock_bh(netdev_get_tx_queue(IPA_NETDEV(), 0));
1894 }
1895}
1896
1897/**
1898 * ipa3_rm_resource_granted() - Called upon
1899 * IPA_RM_RESOURCE_GRANTED event. Wakes up queue is was stopped.
1900 *
1901 * @work: work object supplied ny workqueue
1902 *
1903 * Return codes:
1904 * None
1905 */
1906static void ipa3_rm_resource_granted(void *dev)
1907{
1908 IPAWANDBG_LOW("Resource Granted - starting queue\n");
1909 schedule_work(&ipa3_tx_wakequeue_work);
1910}
1911
1912/**
1913 * ipa3_rm_notify() - Callback function for RM events. Handles
1914 * IPA_RM_RESOURCE_GRANTED and IPA_RM_RESOURCE_RELEASED events.
1915 * IPA_RM_RESOURCE_GRANTED is handled in the context of shared
1916 * workqueue.
1917 *
1918 * @dev: network device
1919 * @event: IPA RM event
1920 * @data: Additional data provided by IPA RM
1921 *
1922 * Return codes:
1923 * None
1924 */
1925static void ipa3_rm_notify(void *dev, enum ipa_rm_event event,
1926 unsigned long data)
1927{
1928 struct ipa3_wwan_private *wwan_ptr = netdev_priv(dev);
1929
1930 pr_debug("%s: event %d\n", __func__, event);
1931 switch (event) {
1932 case IPA_RM_RESOURCE_GRANTED:
1933 if (wwan_ptr->device_status == WWAN_DEVICE_INACTIVE) {
1934 complete_all(&wwan_ptr->resource_granted_completion);
1935 break;
1936 }
1937 ipa3_rm_resource_granted(dev);
1938 break;
1939 case IPA_RM_RESOURCE_RELEASED:
1940 break;
1941 default:
1942 pr_err("%s: unknown event %d\n", __func__, event);
1943 break;
1944 }
1945}
1946
1947/* IPA_RM related functions end*/
1948
1949static int ipa3_ssr_notifier_cb(struct notifier_block *this,
1950 unsigned long code,
1951 void *data);
1952
1953static struct notifier_block ipa3_ssr_notifier = {
1954 .notifier_call = ipa3_ssr_notifier_cb,
1955};
1956
1957static int get_ipa_rmnet_dts_configuration(struct platform_device *pdev,
1958 struct ipa3_rmnet_plat_drv_res *ipa_rmnet_drv_res)
1959{
1960 ipa_rmnet_drv_res->ipa_rmnet_ssr =
1961 of_property_read_bool(pdev->dev.of_node,
1962 "qcom,rmnet-ipa-ssr");
1963 pr_info("IPA SSR support = %s\n",
1964 ipa_rmnet_drv_res->ipa_rmnet_ssr ? "True" : "False");
1965 ipa_rmnet_drv_res->ipa_loaduC =
1966 of_property_read_bool(pdev->dev.of_node,
1967 "qcom,ipa-loaduC");
1968 pr_info("IPA ipa-loaduC = %s\n",
1969 ipa_rmnet_drv_res->ipa_loaduC ? "True" : "False");
1970
1971 ipa_rmnet_drv_res->ipa_advertise_sg_support =
1972 of_property_read_bool(pdev->dev.of_node,
1973 "qcom,ipa-advertise-sg-support");
1974 pr_info("IPA SG support = %s\n",
1975 ipa_rmnet_drv_res->ipa_advertise_sg_support ? "True" : "False");
Gidon Studinski3021a6f2016-11-10 12:48:48 +02001976
1977 ipa_rmnet_drv_res->ipa_napi_enable =
1978 of_property_read_bool(pdev->dev.of_node,
1979 "qcom,ipa-napi-enable");
1980 pr_info("IPA Napi Enable = %s\n",
1981 ipa_rmnet_drv_res->ipa_napi_enable ? "True" : "False");
Amir Levy9659e592016-10-27 18:08:27 +03001982 return 0;
1983}
1984
1985struct ipa3_rmnet_context ipa3_rmnet_ctx;
1986static int ipa3_wwan_probe(struct platform_device *pdev);
1987struct platform_device *m_pdev;
1988
1989static void ipa3_delayed_probe(struct work_struct *work)
1990{
1991 (void)ipa3_wwan_probe(m_pdev);
1992}
1993
1994static DECLARE_WORK(ipa3_scheduled_probe, ipa3_delayed_probe);
1995
1996static void ipa3_ready_cb(void *user_data)
1997{
1998 struct platform_device *pdev = (struct platform_device *)(user_data);
1999
2000 m_pdev = pdev;
2001
2002 IPAWANDBG("IPA ready callback has been triggered!\n");
2003
2004 schedule_work(&ipa3_scheduled_probe);
2005}
2006
2007/**
2008 * ipa3_wwan_probe() - Initialized the module and registers as a
2009 * network interface to the network stack
2010 *
2011 * Note: In case IPA driver hasn't initialized already, the probe function
2012 * will return immediately after registering a callback to be invoked when
2013 * IPA driver initialization is complete.
2014 *
2015 * Return codes:
2016 * 0: success
2017 * -ENOMEM: No memory available
2018 * -EFAULT: Internal error
2019 */
2020static int ipa3_wwan_probe(struct platform_device *pdev)
2021{
2022 int ret, i;
2023 struct net_device *dev;
2024 struct ipa_rm_create_params ipa_rm_params; /* IPA_RM */
2025 struct ipa_rm_perf_profile profile; /* IPA_RM */
2026
2027 pr_info("rmnet_ipa3 started initialization\n");
2028
2029 if (!ipa3_is_ready()) {
2030 IPAWANDBG("IPA driver not ready, registering callback\n");
2031 ret = ipa_register_ipa_ready_cb(ipa3_ready_cb, (void *)pdev);
2032
2033 /*
2034 * If we received -EEXIST, IPA has initialized. So we need
2035 * to continue the probing process.
2036 */
2037 if (ret != -EEXIST) {
2038 if (ret)
2039 IPAWANERR("IPA CB reg failed - %d\n", ret);
2040 return ret;
2041 }
2042 }
2043
2044 ret = get_ipa_rmnet_dts_configuration(pdev, &ipa3_rmnet_res);
2045 ipa3_rmnet_ctx.ipa_rmnet_ssr = ipa3_rmnet_res.ipa_rmnet_ssr;
2046
2047 ret = ipa3_init_q6_smem();
2048 if (ret) {
2049 IPAWANERR("ipa3_init_q6_smem failed!\n");
2050 return ret;
2051 }
2052
2053 /* initialize tx/rx endpoint setup */
2054 memset(&rmnet_ipa3_ctx->apps_to_ipa_ep_cfg, 0,
2055 sizeof(struct ipa_sys_connect_params));
2056 memset(&rmnet_ipa3_ctx->ipa_to_apps_ep_cfg, 0,
2057 sizeof(struct ipa_sys_connect_params));
2058
2059 /* initialize ex property setup */
2060 rmnet_ipa3_ctx->num_q6_rules = 0;
2061 rmnet_ipa3_ctx->old_num_q6_rules = 0;
2062 rmnet_ipa3_ctx->rmnet_index = 0;
2063 rmnet_ipa3_ctx->egress_set = false;
2064 rmnet_ipa3_ctx->a7_ul_flt_set = false;
2065 for (i = 0; i < MAX_NUM_OF_MUX_CHANNEL; i++)
2066 memset(&rmnet_ipa3_ctx->mux_channel[i], 0,
2067 sizeof(struct ipa3_rmnet_mux_val));
2068
2069 /* start A7 QMI service/client */
2070 if (ipa3_rmnet_res.ipa_loaduC)
2071 /* Android platform loads uC */
2072 ipa3_qmi_service_init(QMI_IPA_PLATFORM_TYPE_MSM_ANDROID_V01);
2073 else
2074 /* LE platform not loads uC */
2075 ipa3_qmi_service_init(QMI_IPA_PLATFORM_TYPE_LE_V01);
2076
2077 /* construct default WAN RT tbl for IPACM */
2078 ret = ipa3_setup_a7_qmap_hdr();
2079 if (ret)
2080 goto setup_a7_qmap_hdr_err;
2081 ret = ipa3_setup_dflt_wan_rt_tables();
2082 if (ret)
2083 goto setup_dflt_wan_rt_tables_err;
2084
2085 if (!atomic_read(&rmnet_ipa3_ctx->is_ssr)) {
2086 /* Start transport-driver fd ioctl for ipacm for first init */
2087 ret = ipa3_wan_ioctl_init();
2088 if (ret)
2089 goto wan_ioctl_init_err;
2090 } else {
2091 /* Enable sending QMI messages after SSR */
2092 ipa3_wan_ioctl_enable_qmi_messages();
2093 }
2094
2095 /* initialize wan-driver netdev */
2096 dev = alloc_netdev(sizeof(struct ipa3_wwan_private),
2097 IPA_WWAN_DEV_NAME,
2098 NET_NAME_UNKNOWN,
2099 ipa3_wwan_setup);
2100 if (!dev) {
2101 IPAWANERR("no memory for netdev\n");
2102 ret = -ENOMEM;
2103 goto alloc_netdev_err;
2104 }
2105 rmnet_ipa3_ctx->wwan_priv = netdev_priv(dev);
2106 memset(rmnet_ipa3_ctx->wwan_priv, 0,
2107 sizeof(*(rmnet_ipa3_ctx->wwan_priv)));
2108 IPAWANDBG("wwan_ptr (private) = %p", rmnet_ipa3_ctx->wwan_priv);
2109 rmnet_ipa3_ctx->wwan_priv->net = dev;
2110 rmnet_ipa3_ctx->wwan_priv->outstanding_high = DEFAULT_OUTSTANDING_HIGH;
2111 rmnet_ipa3_ctx->wwan_priv->outstanding_low = DEFAULT_OUTSTANDING_LOW;
2112 atomic_set(&rmnet_ipa3_ctx->wwan_priv->outstanding_pkts, 0);
2113 spin_lock_init(&rmnet_ipa3_ctx->wwan_priv->lock);
2114 init_completion(
2115 &rmnet_ipa3_ctx->wwan_priv->resource_granted_completion);
2116
2117 if (!atomic_read(&rmnet_ipa3_ctx->is_ssr)) {
2118 /* IPA_RM configuration starts */
2119 ret = ipa3_q6_initialize_rm();
2120 if (ret) {
2121 IPAWANERR("%s: ipa3_q6_initialize_rm failed, ret: %d\n",
2122 __func__, ret);
2123 goto q6_init_err;
2124 }
2125 }
2126
2127 memset(&ipa_rm_params, 0, sizeof(struct ipa_rm_create_params));
2128 ipa_rm_params.name = IPA_RM_RESOURCE_WWAN_0_PROD;
2129 ipa_rm_params.reg_params.user_data = dev;
2130 ipa_rm_params.reg_params.notify_cb = ipa3_rm_notify;
2131 ret = ipa_rm_create_resource(&ipa_rm_params);
2132 if (ret) {
2133 pr_err("%s: unable to create resourse %d in IPA RM\n",
2134 __func__, IPA_RM_RESOURCE_WWAN_0_PROD);
2135 goto create_rsrc_err;
2136 }
2137 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WWAN_0_PROD,
2138 IPA_RM_INACTIVITY_TIMER);
2139 if (ret) {
2140 pr_err("%s: ipa rm timer init failed %d on resourse %d\n",
2141 __func__, ret, IPA_RM_RESOURCE_WWAN_0_PROD);
2142 goto timer_init_err;
2143 }
2144 /* add dependency */
2145 ret = ipa_rm_add_dependency(IPA_RM_RESOURCE_WWAN_0_PROD,
2146 IPA_RM_RESOURCE_Q6_CONS);
2147 if (ret)
2148 goto add_dpnd_err;
2149 /* setup Performance profile */
2150 memset(&profile, 0, sizeof(profile));
2151 profile.max_supported_bandwidth_mbps = IPA_APPS_MAX_BW_IN_MBPS;
2152 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WWAN_0_PROD,
2153 &profile);
2154 if (ret)
2155 goto set_perf_err;
2156 /* IPA_RM configuration ends */
2157
2158 /* Enable SG support in netdevice. */
2159 if (ipa3_rmnet_res.ipa_advertise_sg_support)
2160 dev->hw_features |= NETIF_F_SG;
2161
2162 if (ipa3_rmnet_res.ipa_napi_enable)
2163 netif_napi_add(dev, &(rmnet_ipa3_ctx->wwan_priv->napi),
2164 ipa3_rmnet_poll, NAPI_WEIGHT);
2165 ret = register_netdev(dev);
2166 if (ret) {
2167 IPAWANERR("unable to register ipa_netdev %d rc=%d\n",
2168 0, ret);
2169 goto set_perf_err;
2170 }
2171
2172 IPAWANDBG("IPA-WWAN devices (%s) initialization ok :>>>>\n", dev->name);
2173 if (ret) {
2174 IPAWANERR("default configuration failed rc=%d\n",
2175 ret);
2176 goto config_err;
2177 }
2178 atomic_set(&rmnet_ipa3_ctx->is_initialized, 1);
2179 if (!atomic_read(&rmnet_ipa3_ctx->is_ssr)) {
2180 /* offline charging mode */
2181 ipa3_proxy_clk_unvote();
2182 }
2183 atomic_set(&rmnet_ipa3_ctx->is_ssr, 0);
2184
2185 pr_info("rmnet_ipa completed initialization\n");
2186 return 0;
2187config_err:
2188 if (ipa3_rmnet_res.ipa_napi_enable)
2189 netif_napi_del(&(rmnet_ipa3_ctx->wwan_priv->napi));
2190 unregister_netdev(dev);
2191set_perf_err:
2192 ret = ipa_rm_delete_dependency(IPA_RM_RESOURCE_WWAN_0_PROD,
2193 IPA_RM_RESOURCE_Q6_CONS);
2194 if (ret)
2195 IPAWANERR("Error deleting dependency %d->%d, ret=%d\n",
2196 IPA_RM_RESOURCE_WWAN_0_PROD, IPA_RM_RESOURCE_Q6_CONS,
2197 ret);
2198add_dpnd_err:
2199 ret = ipa_rm_inactivity_timer_destroy(
2200 IPA_RM_RESOURCE_WWAN_0_PROD); /* IPA_RM */
2201 if (ret)
2202 IPAWANERR("Error ipa_rm_inactivity_timer_destroy %d, ret=%d\n",
2203 IPA_RM_RESOURCE_WWAN_0_PROD, ret);
2204timer_init_err:
2205 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WWAN_0_PROD);
2206 if (ret)
2207 IPAWANERR("Error deleting resource %d, ret=%d\n",
2208 IPA_RM_RESOURCE_WWAN_0_PROD, ret);
2209create_rsrc_err:
2210 ipa3_q6_deinitialize_rm();
2211q6_init_err:
2212 free_netdev(dev);
2213 rmnet_ipa3_ctx->wwan_priv = NULL;
2214alloc_netdev_err:
2215 ipa3_wan_ioctl_deinit();
2216wan_ioctl_init_err:
2217 ipa3_del_dflt_wan_rt_tables();
2218setup_dflt_wan_rt_tables_err:
2219 ipa3_del_a7_qmap_hdr();
2220setup_a7_qmap_hdr_err:
2221 ipa3_qmi_service_exit();
2222 atomic_set(&rmnet_ipa3_ctx->is_ssr, 0);
2223 return ret;
2224}
2225
2226static int ipa3_wwan_remove(struct platform_device *pdev)
2227{
2228 int ret;
2229
2230 pr_info("rmnet_ipa started deinitialization\n");
2231 mutex_lock(&rmnet_ipa3_ctx->ipa_to_apps_pipe_handle_guard);
2232 ret = ipa3_teardown_sys_pipe(rmnet_ipa3_ctx->ipa3_to_apps_hdl);
2233 if (ret < 0)
2234 IPAWANERR("Failed to teardown IPA->APPS pipe\n");
2235 else
2236 rmnet_ipa3_ctx->ipa3_to_apps_hdl = -1;
2237 if (ipa3_rmnet_res.ipa_napi_enable)
2238 netif_napi_del(&(rmnet_ipa3_ctx->wwan_priv->napi));
2239 mutex_unlock(&rmnet_ipa3_ctx->ipa_to_apps_pipe_handle_guard);
2240 unregister_netdev(IPA_NETDEV());
2241 ret = ipa_rm_delete_dependency(IPA_RM_RESOURCE_WWAN_0_PROD,
2242 IPA_RM_RESOURCE_Q6_CONS);
2243 if (ret < 0)
2244 IPAWANERR("Error deleting dependency %d->%d, ret=%d\n",
2245 IPA_RM_RESOURCE_WWAN_0_PROD, IPA_RM_RESOURCE_Q6_CONS,
2246 ret);
2247 ret = ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WWAN_0_PROD);
2248 if (ret < 0)
2249 IPAWANERR(
2250 "Error ipa_rm_inactivity_timer_destroy resource %d, ret=%d\n",
2251 IPA_RM_RESOURCE_WWAN_0_PROD, ret);
2252 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WWAN_0_PROD);
2253 if (ret < 0)
2254 IPAWANERR("Error deleting resource %d, ret=%d\n",
2255 IPA_RM_RESOURCE_WWAN_0_PROD, ret);
2256 cancel_work_sync(&ipa3_tx_wakequeue_work);
2257 cancel_delayed_work(&ipa_tether_stats_poll_wakequeue_work);
2258 if (IPA_NETDEV())
2259 free_netdev(IPA_NETDEV());
2260 rmnet_ipa3_ctx->wwan_priv = NULL;
2261 /* No need to remove wwan_ioctl during SSR */
2262 if (!atomic_read(&rmnet_ipa3_ctx->is_ssr))
2263 ipa3_wan_ioctl_deinit();
2264 ipa3_del_dflt_wan_rt_tables();
2265 ipa3_del_a7_qmap_hdr();
2266 ipa3_del_mux_qmap_hdrs();
2267 if (ipa3_qmi_ctx->modem_cfg_emb_pipe_flt == false)
2268 ipa3_wwan_del_ul_flt_rule_to_ipa();
2269 ipa3_cleanup_deregister_intf();
2270 atomic_set(&rmnet_ipa3_ctx->is_initialized, 0);
2271 pr_info("rmnet_ipa completed deinitialization\n");
2272 return 0;
2273}
2274
2275/**
2276* rmnet_ipa_ap_suspend() - suspend callback for runtime_pm
2277* @dev: pointer to device
2278*
2279* This callback will be invoked by the runtime_pm framework when an AP suspend
2280* operation is invoked, usually by pressing a suspend button.
2281*
2282* Returns -EAGAIN to runtime_pm framework in case there are pending packets
2283* in the Tx queue. This will postpone the suspend operation until all the
2284* pending packets will be transmitted.
2285*
2286* In case there are no packets to send, releases the WWAN0_PROD entity.
2287* As an outcome, the number of IPA active clients should be decremented
2288* until IPA clocks can be gated.
2289*/
2290static int rmnet_ipa_ap_suspend(struct device *dev)
2291{
2292 struct net_device *netdev = IPA_NETDEV();
2293 struct ipa3_wwan_private *wwan_ptr;
2294
2295 IPAWANDBG_LOW("Enter...\n");
2296 if (netdev == NULL) {
2297 IPAWANERR("netdev is NULL.\n");
2298 return 0;
2299 }
2300
2301 wwan_ptr = netdev_priv(netdev);
2302 if (wwan_ptr == NULL) {
2303 IPAWANERR("wwan_ptr is NULL.\n");
2304 return 0;
2305 }
2306
2307 /* Do not allow A7 to suspend in case there are oustanding packets */
2308 if (atomic_read(&wwan_ptr->outstanding_pkts) != 0) {
2309 IPAWANDBG("Outstanding packets, postponing AP suspend.\n");
2310 return -EAGAIN;
2311 }
2312
2313 /* Make sure that there is no Tx operation ongoing */
2314 netif_tx_lock_bh(netdev);
2315 ipa_rm_release_resource(IPA_RM_RESOURCE_WWAN_0_PROD);
2316 netif_tx_unlock_bh(netdev);
2317 IPAWANDBG_LOW("Exit\n");
2318
2319 return 0;
2320}
2321
2322/**
2323* rmnet_ipa_ap_resume() - resume callback for runtime_pm
2324* @dev: pointer to device
2325*
2326* This callback will be invoked by the runtime_pm framework when an AP resume
2327* operation is invoked.
2328*
2329* Enables the network interface queue and returns success to the
2330* runtime_pm framework.
2331*/
2332static int rmnet_ipa_ap_resume(struct device *dev)
2333{
2334 struct net_device *netdev = IPA_NETDEV();
2335
2336 IPAWANDBG_LOW("Enter...\n");
2337 if (netdev)
2338 netif_wake_queue(netdev);
2339 IPAWANDBG_LOW("Exit\n");
2340
2341 return 0;
2342}
2343
2344static void ipa_stop_polling_stats(void)
2345{
2346 cancel_delayed_work(&ipa_tether_stats_poll_wakequeue_work);
2347 ipa3_rmnet_ctx.polling_interval = 0;
2348}
2349
2350static const struct of_device_id rmnet_ipa_dt_match[] = {
2351 {.compatible = "qcom,rmnet-ipa3"},
2352 {},
2353};
2354MODULE_DEVICE_TABLE(of, rmnet_ipa_dt_match);
2355
2356static const struct dev_pm_ops rmnet_ipa_pm_ops = {
2357 .suspend_noirq = rmnet_ipa_ap_suspend,
2358 .resume_noirq = rmnet_ipa_ap_resume,
2359};
2360
2361static struct platform_driver rmnet_ipa_driver = {
2362 .driver = {
2363 .name = "rmnet_ipa3",
2364 .owner = THIS_MODULE,
2365 .pm = &rmnet_ipa_pm_ops,
2366 .of_match_table = rmnet_ipa_dt_match,
2367 },
2368 .probe = ipa3_wwan_probe,
2369 .remove = ipa3_wwan_remove,
2370};
2371
2372static int ipa3_ssr_notifier_cb(struct notifier_block *this,
2373 unsigned long code,
2374 void *data)
2375{
2376 if (!ipa3_rmnet_ctx.ipa_rmnet_ssr)
2377 return NOTIFY_DONE;
2378
2379 switch (code) {
2380 case SUBSYS_BEFORE_SHUTDOWN:
2381 IPAWANINFO("IPA received MPSS BEFORE_SHUTDOWN\n");
2382 atomic_set(&rmnet_ipa3_ctx->is_ssr, 1);
2383 ipa3_q6_pre_shutdown_cleanup();
2384 if (IPA_NETDEV())
2385 netif_stop_queue(IPA_NETDEV());
2386 ipa3_qmi_stop_workqueues();
2387 ipa3_wan_ioctl_stop_qmi_messages();
2388 ipa_stop_polling_stats();
2389 if (atomic_read(&rmnet_ipa3_ctx->is_initialized))
2390 platform_driver_unregister(&rmnet_ipa_driver);
2391 IPAWANINFO("IPA BEFORE_SHUTDOWN handling is complete\n");
2392 break;
2393 case SUBSYS_AFTER_SHUTDOWN:
2394 IPAWANINFO("IPA Received MPSS AFTER_SHUTDOWN\n");
2395 if (atomic_read(&rmnet_ipa3_ctx->is_ssr))
2396 ipa3_q6_post_shutdown_cleanup();
2397 IPAWANINFO("IPA AFTER_SHUTDOWN handling is complete\n");
2398 break;
2399 case SUBSYS_BEFORE_POWERUP:
2400 IPAWANINFO("IPA received MPSS BEFORE_POWERUP\n");
2401 if (atomic_read(&rmnet_ipa3_ctx->is_ssr))
2402 /* clean up cached QMI msg/handlers */
2403 ipa3_qmi_service_exit();
2404 /*hold a proxy vote for the modem*/
2405 ipa3_proxy_clk_vote();
2406 IPAWANINFO("IPA BEFORE_POWERUP handling is complete\n");
2407 break;
2408 case SUBSYS_AFTER_POWERUP:
2409 IPAWANINFO("%s:%d IPA received MPSS AFTER_POWERUP\n",
2410 __func__, __LINE__);
2411 if (!atomic_read(&rmnet_ipa3_ctx->is_initialized) &&
2412 atomic_read(&rmnet_ipa3_ctx->is_ssr))
2413 platform_driver_register(&rmnet_ipa_driver);
2414
2415 IPAWANINFO("IPA AFTER_POWERUP handling is complete\n");
2416 break;
2417 default:
2418 IPAWANDBG("Unsupported subsys notification, IPA received: %lu",
2419 code);
2420 break;
2421 }
2422
2423 IPAWANDBG_LOW("Exit\n");
2424 return NOTIFY_DONE;
2425}
2426
2427/**
2428 * rmnet_ipa_free_msg() - Free the msg sent to user space via ipa_send_msg
2429 * @buff: pointer to buffer containing the message
2430 * @len: message len
2431 * @type: message type
2432 *
2433 * This function is invoked when ipa_send_msg is complete (Provided as a
2434 * free function pointer along with the message).
2435 */
2436static void rmnet_ipa_free_msg(void *buff, u32 len, u32 type)
2437{
2438 if (!buff) {
2439 IPAWANERR("Null buffer\n");
2440 return;
2441 }
2442
2443 if (type != IPA_TETHERING_STATS_UPDATE_STATS &&
2444 type != IPA_TETHERING_STATS_UPDATE_NETWORK_STATS) {
2445 IPAWANERR("Wrong type given. buff %p type %d\n",
2446 buff, type);
2447 }
2448 kfree(buff);
2449}
2450
2451/**
2452 * rmnet_ipa_get_stats_and_update() - Gets pipe stats from Modem
2453 *
2454 * This function queries the IPA Modem driver for the pipe stats
2455 * via QMI, and updates the user space IPA entity.
2456 */
2457static void rmnet_ipa_get_stats_and_update(void)
2458{
2459 struct ipa_get_data_stats_req_msg_v01 req;
2460 struct ipa_get_data_stats_resp_msg_v01 *resp;
2461 struct ipa_msg_meta msg_meta;
2462 int rc;
2463
2464 resp = kzalloc(sizeof(struct ipa_get_data_stats_resp_msg_v01),
2465 GFP_KERNEL);
2466 if (!resp) {
2467 IPAWANERR("Can't allocate memory for stats message\n");
2468 return;
2469 }
2470
2471 memset(&req, 0, sizeof(struct ipa_get_data_stats_req_msg_v01));
2472 memset(resp, 0, sizeof(struct ipa_get_data_stats_resp_msg_v01));
2473
2474 req.ipa_stats_type = QMI_IPA_STATS_TYPE_PIPE_V01;
2475
2476 rc = ipa3_qmi_get_data_stats(&req, resp);
Gidon Studinski3021a6f2016-11-10 12:48:48 +02002477 if (rc) {
2478 IPAWANERR("ipa3_qmi_get_data_stats failed: %d\n", rc);
2479 kfree(resp);
2480 return;
2481 }
Amir Levy9659e592016-10-27 18:08:27 +03002482
Gidon Studinski3021a6f2016-11-10 12:48:48 +02002483 memset(&msg_meta, 0, sizeof(struct ipa_msg_meta));
2484 msg_meta.msg_type = IPA_TETHERING_STATS_UPDATE_STATS;
2485 msg_meta.msg_len = sizeof(struct ipa_get_data_stats_resp_msg_v01);
2486 rc = ipa_send_msg(&msg_meta, resp, rmnet_ipa_free_msg);
2487 if (rc) {
2488 IPAWANERR("ipa_send_msg failed: %d\n", rc);
2489 kfree(resp);
2490 return;
Amir Levy9659e592016-10-27 18:08:27 +03002491 }
2492}
2493
2494/**
2495 * tethering_stats_poll_queue() - Stats polling function
2496 * @work - Work entry
2497 *
2498 * This function is scheduled periodically (per the interval) in
2499 * order to poll the IPA Modem driver for the pipe stats.
2500 */
2501static void tethering_stats_poll_queue(struct work_struct *work)
2502{
2503 rmnet_ipa_get_stats_and_update();
2504
2505 /* Schedule again only if there's an active polling interval */
2506 if (ipa3_rmnet_ctx.polling_interval != 0)
2507 schedule_delayed_work(&ipa_tether_stats_poll_wakequeue_work,
2508 msecs_to_jiffies(ipa3_rmnet_ctx.polling_interval*1000));
2509}
2510
2511/**
2512 * rmnet_ipa_get_network_stats_and_update() - Get network stats from IPA Modem
2513 *
2514 * This function retrieves the data usage (used quota) from the IPA Modem driver
2515 * via QMI, and updates IPA user space entity.
2516 */
2517static void rmnet_ipa_get_network_stats_and_update(void)
2518{
2519 struct ipa_get_apn_data_stats_req_msg_v01 req;
2520 struct ipa_get_apn_data_stats_resp_msg_v01 *resp;
2521 struct ipa_msg_meta msg_meta;
2522 int rc;
2523
2524 resp = kzalloc(sizeof(struct ipa_get_apn_data_stats_resp_msg_v01),
2525 GFP_KERNEL);
2526 if (!resp) {
2527 IPAWANERR("Can't allocate memory for network stats message\n");
2528 return;
2529 }
2530
2531 memset(&req, 0, sizeof(struct ipa_get_apn_data_stats_req_msg_v01));
2532 memset(resp, 0, sizeof(struct ipa_get_apn_data_stats_resp_msg_v01));
2533
2534 req.mux_id_list_valid = true;
2535 req.mux_id_list_len = 1;
2536 req.mux_id_list[0] = ipa3_rmnet_ctx.metered_mux_id;
2537
2538 rc = ipa3_qmi_get_network_stats(&req, resp);
Gidon Studinski3021a6f2016-11-10 12:48:48 +02002539 if (rc) {
2540 IPAWANERR("ipa3_qmi_get_network_stats failed: %d\n", rc);
2541 kfree(resp);
2542 return;
2543 }
Amir Levy9659e592016-10-27 18:08:27 +03002544
Gidon Studinski3021a6f2016-11-10 12:48:48 +02002545 memset(&msg_meta, 0, sizeof(struct ipa_msg_meta));
2546 msg_meta.msg_type = IPA_TETHERING_STATS_UPDATE_NETWORK_STATS;
2547 msg_meta.msg_len = sizeof(struct ipa_get_apn_data_stats_resp_msg_v01);
2548 rc = ipa_send_msg(&msg_meta, resp, rmnet_ipa_free_msg);
2549 if (rc) {
2550 IPAWANERR("ipa_send_msg failed: %d\n", rc);
2551 kfree(resp);
2552 return;
Amir Levy9659e592016-10-27 18:08:27 +03002553 }
2554}
2555
2556/**
2557 * rmnet_ipa3_poll_tethering_stats() - Tethering stats polling IOCTL handler
2558 * @data - IOCTL data
2559 *
2560 * This function handles WAN_IOC_POLL_TETHERING_STATS.
2561 * In case polling interval received is 0, polling will stop
2562 * (If there's a polling in progress, it will allow it to finish), and then will
2563 * fetch network stats, and update the IPA user space.
2564 *
2565 * Return codes:
2566 * 0: Success
2567 */
2568int rmnet_ipa3_poll_tethering_stats(struct wan_ioctl_poll_tethering_stats *data)
2569{
2570 ipa3_rmnet_ctx.polling_interval = data->polling_interval_secs;
2571
2572 cancel_delayed_work_sync(&ipa_tether_stats_poll_wakequeue_work);
2573
2574 if (ipa3_rmnet_ctx.polling_interval == 0) {
2575 ipa3_qmi_stop_data_qouta();
2576 rmnet_ipa_get_network_stats_and_update();
2577 rmnet_ipa_get_stats_and_update();
2578 return 0;
2579 }
2580
2581 schedule_delayed_work(&ipa_tether_stats_poll_wakequeue_work, 0);
2582 return 0;
2583}
2584
2585/**
2586 * rmnet_ipa_set_data_quota() - Data quota setting IOCTL handler
2587 * @data - IOCTL data
2588 *
2589 * This function handles WAN_IOC_SET_DATA_QUOTA.
2590 * It translates the given interface name to the Modem MUX ID and
2591 * sends the request of the quota to the IPA Modem driver via QMI.
2592 *
2593 * Return codes:
2594 * 0: Success
2595 * -EFAULT: Invalid interface name provided
2596 * other: See ipa_qmi_set_data_quota
2597 */
2598int rmnet_ipa3_set_data_quota(struct wan_ioctl_set_data_quota *data)
2599{
2600 u32 mux_id;
2601 int index;
2602 struct ipa_set_data_usage_quota_req_msg_v01 req;
2603
2604 index = find_vchannel_name_index(data->interface_name);
2605 IPAWANERR("iface name %s, quota %lu\n",
2606 data->interface_name,
2607 (unsigned long int) data->quota_mbytes);
2608
2609 if (index == MAX_NUM_OF_MUX_CHANNEL) {
2610 IPAWANERR("%s is an invalid iface name\n",
2611 data->interface_name);
2612 return -EFAULT;
2613 }
2614
2615 mux_id = rmnet_ipa3_ctx->mux_channel[index].mux_id;
2616 ipa3_rmnet_ctx.metered_mux_id = mux_id;
2617
2618 memset(&req, 0, sizeof(struct ipa_set_data_usage_quota_req_msg_v01));
2619 req.apn_quota_list_valid = true;
2620 req.apn_quota_list_len = 1;
2621 req.apn_quota_list[0].mux_id = mux_id;
2622 req.apn_quota_list[0].num_Mbytes = data->quota_mbytes;
2623
2624 return ipa3_qmi_set_data_quota(&req);
2625}
2626
2627 /* rmnet_ipa_set_tether_client_pipe() -
2628 * @data - IOCTL data
2629 *
2630 * This function handles WAN_IOC_SET_DATA_QUOTA.
2631 * It translates the given interface name to the Modem MUX ID and
2632 * sends the request of the quota to the IPA Modem driver via QMI.
2633 *
2634 * Return codes:
2635 * 0: Success
2636 * -EFAULT: Invalid interface name provided
2637 * other: See ipa_qmi_set_data_quota
2638 */
2639int rmnet_ipa3_set_tether_client_pipe(
2640 struct wan_ioctl_set_tether_client_pipe *data)
2641{
2642 int number, i;
2643
2644 IPAWANDBG("client %d, UL %d, DL %d, reset %d\n",
2645 data->ipa_client,
2646 data->ul_src_pipe_len,
2647 data->dl_dst_pipe_len,
2648 data->reset_client);
2649 number = data->ul_src_pipe_len;
2650 for (i = 0; i < number; i++) {
2651 IPAWANDBG("UL index-%d pipe %d\n", i,
2652 data->ul_src_pipe_list[i]);
2653 if (data->reset_client)
2654 ipa3_set_client(data->ul_src_pipe_list[i],
2655 0, false);
2656 else
2657 ipa3_set_client(data->ul_src_pipe_list[i],
2658 data->ipa_client, true);
2659 }
2660 number = data->dl_dst_pipe_len;
2661 for (i = 0; i < number; i++) {
2662 IPAWANDBG("DL index-%d pipe %d\n", i,
2663 data->dl_dst_pipe_list[i]);
2664 if (data->reset_client)
2665 ipa3_set_client(data->dl_dst_pipe_list[i],
2666 0, false);
2667 else
2668 ipa3_set_client(data->dl_dst_pipe_list[i],
2669 data->ipa_client, false);
2670 }
2671 return 0;
2672}
2673
2674int rmnet_ipa3_query_tethering_stats(struct wan_ioctl_query_tether_stats *data,
2675 bool reset)
2676{
2677 struct ipa_get_data_stats_req_msg_v01 *req;
2678 struct ipa_get_data_stats_resp_msg_v01 *resp;
2679 int pipe_len, rc;
2680
2681 req = kzalloc(sizeof(struct ipa_get_data_stats_req_msg_v01),
2682 GFP_KERNEL);
2683 if (!req) {
2684 IPAWANERR("Can't allocate memory for stats message\n");
2685 return -ENOMEM;
2686 }
2687 resp = kzalloc(sizeof(struct ipa_get_data_stats_resp_msg_v01),
2688 GFP_KERNEL);
2689 if (!resp) {
2690 IPAWANERR("Can't allocate memory for stats message\n");
2691 kfree(req);
2692 return -ENOMEM;
2693 }
2694 memset(req, 0, sizeof(struct ipa_get_data_stats_req_msg_v01));
2695 memset(resp, 0, sizeof(struct ipa_get_data_stats_resp_msg_v01));
2696
2697 req->ipa_stats_type = QMI_IPA_STATS_TYPE_PIPE_V01;
2698 if (reset) {
2699 req->reset_stats_valid = true;
2700 req->reset_stats = true;
2701 IPAWANERR("reset the pipe stats\n");
2702 } else {
2703 /* print tethered-client enum */
2704 IPAWANDBG_LOW("Tethered-client enum(%d)\n", data->ipa_client);
2705 }
2706
2707 rc = ipa3_qmi_get_data_stats(req, resp);
2708 if (rc) {
2709 IPAWANERR("can't get ipa_qmi_get_data_stats\n");
2710 kfree(req);
2711 kfree(resp);
2712 return rc;
2713 } else if (reset) {
2714 kfree(req);
2715 kfree(resp);
2716 return 0;
2717 }
2718
2719 if (resp->dl_dst_pipe_stats_list_valid) {
2720 for (pipe_len = 0; pipe_len < resp->dl_dst_pipe_stats_list_len;
2721 pipe_len++) {
2722 IPAWANDBG_LOW("Check entry(%d) dl_dst_pipe(%d)\n",
2723 pipe_len, resp->dl_dst_pipe_stats_list
2724 [pipe_len].pipe_index);
2725 IPAWANDBG_LOW("dl_p_v4(%lu)v6(%lu)\n",
2726 (unsigned long int) resp->
2727 dl_dst_pipe_stats_list[pipe_len].
2728 num_ipv4_packets,
2729 (unsigned long int) resp->
2730 dl_dst_pipe_stats_list[pipe_len].
2731 num_ipv6_packets);
2732 IPAWANDBG_LOW("dl_b_v4(%lu)v6(%lu)\n",
2733 (unsigned long int) resp->
2734 dl_dst_pipe_stats_list[pipe_len].
2735 num_ipv4_bytes,
2736 (unsigned long int) resp->
2737 dl_dst_pipe_stats_list[pipe_len].
2738 num_ipv6_bytes);
2739 if (ipa_get_client_uplink(resp->
2740 dl_dst_pipe_stats_list[pipe_len].
2741 pipe_index) == false) {
2742 if (data->ipa_client == ipa_get_client(resp->
2743 dl_dst_pipe_stats_list[pipe_len].
2744 pipe_index)) {
2745 /* update the DL stats */
2746 data->ipv4_rx_packets += resp->
2747 dl_dst_pipe_stats_list[pipe_len].
2748 num_ipv4_packets;
2749 data->ipv6_rx_packets += resp->
2750 dl_dst_pipe_stats_list[pipe_len].
2751 num_ipv6_packets;
2752 data->ipv4_rx_bytes += resp->
2753 dl_dst_pipe_stats_list[pipe_len].
2754 num_ipv4_bytes;
2755 data->ipv6_rx_bytes += resp->
2756 dl_dst_pipe_stats_list[pipe_len].
2757 num_ipv6_bytes;
2758 }
2759 }
2760 }
2761 }
2762 IPAWANDBG_LOW("v4_rx_p(%lu) v6_rx_p(%lu) v4_rx_b(%lu) v6_rx_b(%lu)\n",
2763 (unsigned long int) data->ipv4_rx_packets,
2764 (unsigned long int) data->ipv6_rx_packets,
2765 (unsigned long int) data->ipv4_rx_bytes,
2766 (unsigned long int) data->ipv6_rx_bytes);
2767
2768 if (resp->ul_src_pipe_stats_list_valid) {
2769 for (pipe_len = 0; pipe_len < resp->ul_src_pipe_stats_list_len;
2770 pipe_len++) {
2771 IPAWANDBG_LOW("Check entry(%d) ul_dst_pipe(%d)\n",
2772 pipe_len,
2773 resp->ul_src_pipe_stats_list[pipe_len].
2774 pipe_index);
2775 IPAWANDBG_LOW("ul_p_v4(%lu)v6(%lu)\n",
2776 (unsigned long int) resp->
2777 ul_src_pipe_stats_list[pipe_len].
2778 num_ipv4_packets,
2779 (unsigned long int) resp->
2780 ul_src_pipe_stats_list[pipe_len].
2781 num_ipv6_packets);
2782 IPAWANDBG_LOW("ul_b_v4(%lu)v6(%lu)\n",
2783 (unsigned long int) resp->
2784 ul_src_pipe_stats_list[pipe_len].
2785 num_ipv4_bytes,
2786 (unsigned long int) resp->
2787 ul_src_pipe_stats_list[pipe_len].
2788 num_ipv6_bytes);
2789 if (ipa_get_client_uplink(resp->
2790 ul_src_pipe_stats_list[pipe_len].
2791 pipe_index) == true) {
2792 if (data->ipa_client == ipa_get_client(resp->
2793 ul_src_pipe_stats_list[pipe_len].
2794 pipe_index)) {
2795 /* update the DL stats */
2796 data->ipv4_tx_packets += resp->
2797 ul_src_pipe_stats_list[pipe_len].
2798 num_ipv4_packets;
2799 data->ipv6_tx_packets += resp->
2800 ul_src_pipe_stats_list[pipe_len].
2801 num_ipv6_packets;
2802 data->ipv4_tx_bytes += resp->
2803 ul_src_pipe_stats_list[pipe_len].
2804 num_ipv4_bytes;
2805 data->ipv6_tx_bytes += resp->
2806 ul_src_pipe_stats_list[pipe_len].
2807 num_ipv6_bytes;
2808 }
2809 }
2810 }
2811 }
2812 IPAWANDBG_LOW("tx_p_v4(%lu)v6(%lu)tx_b_v4(%lu) v6(%lu)\n",
2813 (unsigned long int) data->ipv4_tx_packets,
2814 (unsigned long int) data->ipv6_tx_packets,
2815 (unsigned long int) data->ipv4_tx_bytes,
2816 (unsigned long int) data->ipv6_tx_bytes);
2817 kfree(req);
2818 kfree(resp);
2819 return 0;
2820}
2821
2822/**
2823 * ipa3_broadcast_quota_reach_ind() - Send Netlink broadcast on Quota
2824 * @mux_id - The MUX ID on which the quota has been reached
2825 *
2826 * This function broadcasts a Netlink event using the kobject of the
2827 * rmnet_ipa interface in order to alert the user space that the quota
2828 * on the specific interface which matches the mux_id has been reached.
2829 *
2830 */
2831void ipa3_broadcast_quota_reach_ind(u32 mux_id)
2832{
2833 char alert_msg[IPA_QUOTA_REACH_ALERT_MAX_SIZE];
2834 char iface_name_m[IPA_QUOTA_REACH_IF_NAME_MAX_SIZE];
2835 char iface_name_l[IPA_QUOTA_REACH_IF_NAME_MAX_SIZE];
2836 char *envp[IPA_UEVENT_NUM_EVNP] = {
2837 alert_msg, iface_name_l, iface_name_m, NULL };
2838 int res;
2839 int index;
2840
2841 index = ipa3_find_mux_channel_index(mux_id);
2842
2843 if (index == MAX_NUM_OF_MUX_CHANNEL) {
2844 IPAWANERR("%u is an mux ID\n", mux_id);
2845 return;
2846 }
2847
2848 res = snprintf(alert_msg, IPA_QUOTA_REACH_ALERT_MAX_SIZE,
2849 "ALERT_NAME=%s", "quotaReachedAlert");
2850 if (res >= IPA_QUOTA_REACH_ALERT_MAX_SIZE) {
2851 IPAWANERR("message too long (%d)", res);
2852 return;
2853 }
2854 /* posting msg for L-release for CNE */
2855 res = snprintf(iface_name_l, IPA_QUOTA_REACH_IF_NAME_MAX_SIZE,
2856 "UPSTREAM=%s", rmnet_ipa3_ctx->mux_channel[index].vchannel_name);
2857 if (res >= IPA_QUOTA_REACH_IF_NAME_MAX_SIZE) {
2858 IPAWANERR("message too long (%d)", res);
2859 return;
2860 }
2861 /* posting msg for M-release for CNE */
2862 res = snprintf(iface_name_m, IPA_QUOTA_REACH_IF_NAME_MAX_SIZE,
2863 "INTERFACE=%s", rmnet_ipa3_ctx->mux_channel[index].vchannel_name);
2864 if (res >= IPA_QUOTA_REACH_IF_NAME_MAX_SIZE) {
2865 IPAWANERR("message too long (%d)", res);
2866 return;
2867 }
2868
2869 IPAWANERR("putting nlmsg: <%s> <%s> <%s>\n",
2870 alert_msg, iface_name_l, iface_name_m);
2871 kobject_uevent_env(&(IPA_NETDEV()->dev.kobj),
2872 KOBJ_CHANGE, envp);
2873}
2874
2875/**
2876 * ipa3_q6_handshake_complete() - Perform operations once Q6 is up
2877 * @ssr_bootup - Indicates whether this is a cold boot-up or post-SSR.
2878 *
2879 * This function is invoked once the handshake between the IPA AP driver
2880 * and IPA Q6 driver is complete. At this point, it is possible to perform
2881 * operations which can't be performed until IPA Q6 driver is up.
2882 *
2883 */
2884void ipa3_q6_handshake_complete(bool ssr_bootup)
2885{
2886 /* It is required to recover the network stats after SSR recovery */
2887 if (ssr_bootup) {
2888 /*
2889 * In case the uC is required to be loaded by the Modem,
2890 * the proxy vote will be removed only when uC loading is
2891 * complete and indication is received by the AP. After SSR,
2892 * uC is already loaded. Therefore, proxy vote can be removed
2893 * once Modem init is complete.
2894 */
2895 ipa3_proxy_clk_unvote();
2896
2897 /*
2898 * It is required to recover the network stats after
2899 * SSR recovery
2900 */
2901 rmnet_ipa_get_network_stats_and_update();
2902 }
2903}
2904
2905static int __init ipa3_wwan_init(void)
2906{
2907 rmnet_ipa3_ctx = kzalloc(sizeof(*rmnet_ipa3_ctx), GFP_KERNEL);
2908 if (!rmnet_ipa3_ctx) {
2909 IPAWANERR("no memory\n");
2910 return -ENOMEM;
2911 }
2912
2913 atomic_set(&rmnet_ipa3_ctx->is_initialized, 0);
2914 atomic_set(&rmnet_ipa3_ctx->is_ssr, 0);
2915
2916 mutex_init(&rmnet_ipa3_ctx->ipa_to_apps_pipe_handle_guard);
2917 rmnet_ipa3_ctx->ipa3_to_apps_hdl = -1;
2918 /* Register for Modem SSR */
2919 rmnet_ipa3_ctx->subsys_notify_handle = subsys_notif_register_notifier(
2920 SUBSYS_MODEM,
2921 &ipa3_ssr_notifier);
2922 if (!IS_ERR(rmnet_ipa3_ctx->subsys_notify_handle))
2923 return platform_driver_register(&rmnet_ipa_driver);
2924 else
2925 return (int)PTR_ERR(rmnet_ipa3_ctx->subsys_notify_handle);
2926}
2927
2928static void __exit ipa3_wwan_cleanup(void)
2929{
2930 int ret;
2931
2932 mutex_destroy(&rmnet_ipa3_ctx->ipa_to_apps_pipe_handle_guard);
2933 ret = subsys_notif_unregister_notifier(
2934 rmnet_ipa3_ctx->subsys_notify_handle, &ipa3_ssr_notifier);
2935 if (ret)
2936 IPAWANERR(
2937 "Error subsys_notif_unregister_notifier system %s, ret=%d\n",
2938 SUBSYS_MODEM, ret);
2939 platform_driver_unregister(&rmnet_ipa_driver);
2940 kfree(rmnet_ipa3_ctx);
2941 rmnet_ipa3_ctx = NULL;
2942}
2943
2944static void ipa3_wwan_msg_free_cb(void *buff, u32 len, u32 type)
2945{
2946 if (!buff)
2947 IPAWANERR("Null buffer.\n");
2948 kfree(buff);
2949}
2950
2951static void ipa3_rmnet_rx_cb(void *priv)
2952{
2953 IPAWANDBG_LOW("\n");
2954 napi_schedule(&(rmnet_ipa3_ctx->wwan_priv->napi));
2955}
2956
2957static int ipa3_rmnet_poll(struct napi_struct *napi, int budget)
2958{
2959 int rcvd_pkts = 0;
2960
2961 rcvd_pkts = ipa_rx_poll(rmnet_ipa3_ctx->ipa3_to_apps_hdl,
2962 NAPI_WEIGHT);
2963 IPAWANDBG_LOW("rcvd packets: %d\n", rcvd_pkts);
2964 return rcvd_pkts;
2965}
2966
2967late_initcall(ipa3_wwan_init);
2968module_exit(ipa3_wwan_cleanup);
2969MODULE_DESCRIPTION("WWAN Network Interface");
2970MODULE_LICENSE("GPL v2");