blob: d9ded9914c9366f63eb56440d43398644f646492 [file] [log] [blame]
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +05301/*
2 **************************************************************************
Stephen Wang3e2dbd12018-03-14 17:28:17 -07003 * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +05304 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all copies.
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
13 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 **************************************************************************
15 */
16
17#include "nss_tx_rx_common.h"
Yu Huang8c107082017-07-24 14:58:26 -070018#include "nss_sjack_stats.h"
Ankit Dhanuka14999992014-11-12 15:35:11 +053019
20/*
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053021 * nss_sjack_handler()
22 * Handle NSS -> HLOS messages for sjack
23 */
24static void nss_sjack_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm,
25 __attribute__((unused))void *app_data)
26{
27 void *ctx;
28 nss_sjack_msg_callback_t cb;
Ankit Dhanuka14999992014-11-12 15:35:11 +053029 struct nss_sjack_msg *nsm = (struct nss_sjack_msg *)ncm;
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053030
31 BUG_ON(ncm->interface != NSS_SJACK_INTERFACE);
32
33 /*
34 * Is this a valid request/response packet?
35 */
36 if (ncm->type >= NSS_SJACK_MAX_MSG_TYPE) {
37 nss_warning("%p: received invalid message %d for sjack interface", nss_ctx, ncm->type);
38 return;
39 }
40
Suruchi Agarwalef8a8702016-01-08 12:40:08 -080041 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_sjack_msg)) {
42 nss_warning("%p: Length of message is greater than required: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053043 return;
44 }
45
46 /*
47 * Update the callback and app_data for NOTIFY messages, sjack sends all notify messages
48 * to the same callback/app_data.
49 */
Suruchi Agarwale4ad24a2018-06-11 12:03:46 +053050 if (ncm->response == NSS_CMN_RESPONSE_NOTIFY) {
Stephen Wangaed46332016-12-12 17:29:03 -080051 ncm->cb = (nss_ptr_t)nss_ctx->nss_top->if_rx_msg_callback[ncm->interface];
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053052 }
53
54 /*
55 * Log failures
56 */
57 nss_core_log_msg_failures(nss_ctx, ncm);
58
Ankit Dhanuka14999992014-11-12 15:35:11 +053059 switch (ncm->type) {
60 case NSS_SJACK_STATS_SYNC_MSG:
61 /*
62 * Update sjack statistics on node sync.
63 */
Yu Huang8c107082017-07-24 14:58:26 -070064 nss_sjack_stats_node_sync(nss_ctx, &nsm->msg.stats_sync);
Ankit Dhanuka14999992014-11-12 15:35:11 +053065 break;
66 }
67
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053068 /*
69 * Do we have a call back
70 */
71 if (!ncm->cb) {
72 return;
73 }
74
75 /*
76 * callback
77 */
78 cb = (nss_sjack_msg_callback_t)ncm->cb;
Stephen Wang84e0e992016-09-07 12:31:40 -070079 ctx = nss_ctx->subsys_dp_register[ncm->interface].ndev;
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053080
81 cb(ctx, ncm);
82}
83
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053084/*
85 * nss_sjack_tx_msg()
86 * Transmit a sjack message to NSSFW
87 */
88nss_tx_status_t nss_sjack_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_sjack_msg *msg)
89{
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053090 struct nss_cmn_msg *ncm = &msg->cm;
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053091
92 /*
93 * Sanity check the message
94 */
95 if (ncm->interface != NSS_SJACK_INTERFACE) {
96 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
97 return NSS_TX_FAILURE;
98 }
99
100 if (ncm->type > NSS_SJACK_MAX_MSG_TYPE) {
101 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
102 return NSS_TX_FAILURE;
103 }
104
Stephen Wang3e2dbd12018-03-14 17:28:17 -0700105 return nss_core_send_cmd(nss_ctx, msg, sizeof(*msg), NSS_NBUF_PAYLOAD_SIZE);
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +0530106}
107
108/*
109 * nss_sjack_register_if()
110 */
111struct nss_ctx_instance *nss_sjack_register_if(uint32_t if_num, struct net_device *netdev,
112 nss_sjack_msg_callback_t event_callback)
113{
Stephen Wang84e0e992016-09-07 12:31:40 -0700114 struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.sjack_handler_id];
115
116 nss_assert(nss_ctx);
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +0530117 nss_assert(if_num == NSS_SJACK_INTERFACE);
118
Jackson Bockus7ca70ec2017-07-17 13:47:29 -0700119 nss_core_register_subsys_dp(nss_ctx, if_num, NULL, NULL, NULL, netdev, 0);
Sundarajan Srinivasan70374842014-11-19 15:22:52 -0800120
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +0530121 nss_top_main.if_rx_msg_callback[if_num] = event_callback;
122
Stephen Wang84e0e992016-09-07 12:31:40 -0700123 return nss_ctx;
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +0530124}
125
126/*
127 * nss_sjack_unregister_if()
128 */
129void nss_sjack_unregister_if(uint32_t if_num)
130{
Stephen Wang84e0e992016-09-07 12:31:40 -0700131 struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.sjack_handler_id];
132
133 nss_assert(nss_ctx);
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +0530134 nss_assert(if_num == NSS_SJACK_INTERFACE);
135
Jackson Bockus7ca70ec2017-07-17 13:47:29 -0700136 nss_core_unregister_subsys_dp(nss_ctx, if_num);
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +0530137 nss_top_main.if_rx_msg_callback[if_num] = NULL;
138
139 return;
140}
141
142/*
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700143 * nss_sjack_get_context()
144 * get NSS context instance for sjack
145 */
146struct nss_ctx_instance *nss_sjack_get_context(void)
147{
148 return &nss_top_main.nss[nss_top_main.sjack_handler_id];
149}
150EXPORT_SYMBOL(nss_sjack_get_context);
151
152/*
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +0530153 * nss_sjack_register_handler()
154 * Registering handler for sending msg to sjack node on NSS.
155 */
156void nss_sjack_register_handler(void)
157{
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700158 struct nss_ctx_instance *nss_ctx = nss_sjack_get_context();
159
160 nss_core_register_handler(nss_ctx, NSS_SJACK_INTERFACE, nss_sjack_handler, NULL);
Yu Huang8c107082017-07-24 14:58:26 -0700161
162 nss_sjack_stats_dentry_create();
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +0530163}
164
165EXPORT_SYMBOL(nss_sjack_register_if);
166EXPORT_SYMBOL(nss_sjack_unregister_if);
167EXPORT_SYMBOL(nss_sjack_tx_msg);