blob: f13685e9b845fd9fddecb70e516f7ed1e4d844ee [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"
Sachin Shashidhar1f8ccf82018-08-08 14:32:13 -070019#include "nss_sjack_log.h"
Ankit Dhanuka14999992014-11-12 15:35:11 +053020
21/*
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053022 * nss_sjack_handler()
23 * Handle NSS -> HLOS messages for sjack
24 */
25static void nss_sjack_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm,
26 __attribute__((unused))void *app_data)
27{
28 void *ctx;
29 nss_sjack_msg_callback_t cb;
Ankit Dhanuka14999992014-11-12 15:35:11 +053030 struct nss_sjack_msg *nsm = (struct nss_sjack_msg *)ncm;
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053031
32 BUG_ON(ncm->interface != NSS_SJACK_INTERFACE);
33
34 /*
Sachin Shashidhar1f8ccf82018-08-08 14:32:13 -070035 * Trace Messages
36 */
37 nss_sjack_log_rx_msg(nsm);
38
39 /*
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053040 * Is this a valid request/response packet?
41 */
42 if (ncm->type >= NSS_SJACK_MAX_MSG_TYPE) {
43 nss_warning("%p: received invalid message %d for sjack interface", nss_ctx, ncm->type);
44 return;
45 }
46
Suruchi Agarwalef8a8702016-01-08 12:40:08 -080047 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_sjack_msg)) {
48 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 +053049 return;
50 }
51
52 /*
53 * Update the callback and app_data for NOTIFY messages, sjack sends all notify messages
54 * to the same callback/app_data.
55 */
Suruchi Agarwale4ad24a2018-06-11 12:03:46 +053056 if (ncm->response == NSS_CMN_RESPONSE_NOTIFY) {
Stephen Wangaed46332016-12-12 17:29:03 -080057 ncm->cb = (nss_ptr_t)nss_ctx->nss_top->if_rx_msg_callback[ncm->interface];
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053058 }
59
60 /*
61 * Log failures
62 */
63 nss_core_log_msg_failures(nss_ctx, ncm);
64
Ankit Dhanuka14999992014-11-12 15:35:11 +053065 switch (ncm->type) {
66 case NSS_SJACK_STATS_SYNC_MSG:
67 /*
68 * Update sjack statistics on node sync.
69 */
Yu Huang8c107082017-07-24 14:58:26 -070070 nss_sjack_stats_node_sync(nss_ctx, &nsm->msg.stats_sync);
Ankit Dhanuka14999992014-11-12 15:35:11 +053071 break;
72 }
73
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053074 /*
75 * Do we have a call back
76 */
77 if (!ncm->cb) {
78 return;
79 }
80
81 /*
82 * callback
83 */
84 cb = (nss_sjack_msg_callback_t)ncm->cb;
Stephen Wang84e0e992016-09-07 12:31:40 -070085 ctx = nss_ctx->subsys_dp_register[ncm->interface].ndev;
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053086
87 cb(ctx, ncm);
88}
89
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053090/*
91 * nss_sjack_tx_msg()
92 * Transmit a sjack message to NSSFW
93 */
94nss_tx_status_t nss_sjack_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_sjack_msg *msg)
95{
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053096 struct nss_cmn_msg *ncm = &msg->cm;
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +053097
98 /*
Sachin Shashidhar1f8ccf82018-08-08 14:32:13 -070099 * Trace Messages
100 */
101 nss_sjack_log_tx_msg(msg);
102
103 /*
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +0530104 * Sanity check the message
105 */
106 if (ncm->interface != NSS_SJACK_INTERFACE) {
107 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
108 return NSS_TX_FAILURE;
109 }
110
111 if (ncm->type > NSS_SJACK_MAX_MSG_TYPE) {
112 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
113 return NSS_TX_FAILURE;
114 }
115
Stephen Wang3e2dbd12018-03-14 17:28:17 -0700116 return nss_core_send_cmd(nss_ctx, msg, sizeof(*msg), NSS_NBUF_PAYLOAD_SIZE);
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +0530117}
118
119/*
120 * nss_sjack_register_if()
121 */
122struct nss_ctx_instance *nss_sjack_register_if(uint32_t if_num, struct net_device *netdev,
123 nss_sjack_msg_callback_t event_callback)
124{
Stephen Wang84e0e992016-09-07 12:31:40 -0700125 struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.sjack_handler_id];
126
127 nss_assert(nss_ctx);
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +0530128 nss_assert(if_num == NSS_SJACK_INTERFACE);
129
Jackson Bockus7ca70ec2017-07-17 13:47:29 -0700130 nss_core_register_subsys_dp(nss_ctx, if_num, NULL, NULL, NULL, netdev, 0);
Sundarajan Srinivasan70374842014-11-19 15:22:52 -0800131
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +0530132 nss_top_main.if_rx_msg_callback[if_num] = event_callback;
133
Stephen Wang84e0e992016-09-07 12:31:40 -0700134 return nss_ctx;
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +0530135}
136
137/*
138 * nss_sjack_unregister_if()
139 */
140void nss_sjack_unregister_if(uint32_t if_num)
141{
Stephen Wang84e0e992016-09-07 12:31:40 -0700142 struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.sjack_handler_id];
143
144 nss_assert(nss_ctx);
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +0530145 nss_assert(if_num == NSS_SJACK_INTERFACE);
146
Jackson Bockus7ca70ec2017-07-17 13:47:29 -0700147 nss_core_unregister_subsys_dp(nss_ctx, if_num);
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +0530148 nss_top_main.if_rx_msg_callback[if_num] = NULL;
149
150 return;
151}
152
153/*
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700154 * nss_sjack_get_context()
155 * get NSS context instance for sjack
156 */
157struct nss_ctx_instance *nss_sjack_get_context(void)
158{
159 return &nss_top_main.nss[nss_top_main.sjack_handler_id];
160}
161EXPORT_SYMBOL(nss_sjack_get_context);
162
163/*
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +0530164 * nss_sjack_register_handler()
165 * Registering handler for sending msg to sjack node on NSS.
166 */
167void nss_sjack_register_handler(void)
168{
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700169 struct nss_ctx_instance *nss_ctx = nss_sjack_get_context();
170
171 nss_core_register_handler(nss_ctx, NSS_SJACK_INTERFACE, nss_sjack_handler, NULL);
Yu Huang8c107082017-07-24 14:58:26 -0700172
173 nss_sjack_stats_dentry_create();
Ankit Dhanuka2ae20a82014-08-25 18:04:00 +0530174}
175
176EXPORT_SYMBOL(nss_sjack_register_if);
177EXPORT_SYMBOL(nss_sjack_unregister_if);
178EXPORT_SYMBOL(nss_sjack_tx_msg);