blob: 0607ba9063b72622830204c752c14bd052911dcf [file] [log] [blame]
Sol Kavya55c9a52014-04-08 14:33:16 -07001/*
2 **************************************************************************
Stephen Wang3e2dbd12018-03-14 17:28:17 -07003 * Copyright (c) 2014-2016, 2018, The Linux Foundation. All rights reserved.
Sol Kavya55c9a52014-04-08 14:33:16 -07004 * 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/*
18 * nss_if.c
19 * NSS base interfaces
20 */
21
22#include "nss_tx_rx_common.h"
Sol Kavya55c9a52014-04-08 14:33:16 -070023
24/*
25 * nss_if_msg_handler()
26 * Handle NSS -> HLOS messages for base class interfaces
27 */
28void nss_if_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm,
29 __attribute__((unused))void *app_data)
30{
31 struct nss_if_msg *nim = (struct nss_if_msg *)ncm;
32 nss_if_msg_callback_t cb;
33
34 /*
35 * We only support base class messages with this interface
36 */
37 if (ncm->type > NSS_IF_MAX_MSG_TYPES) {
38 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
39 return;
40 }
41
Sundarajan Srinivasancd1631b2015-06-18 01:23:30 -070042 if (!nss_is_dynamic_interface(ncm->interface) &&
43 !((ncm->interface >= NSS_PHYSICAL_IF_START) && (ncm->interface < NSS_VIRTUAL_IF_START))) {
44 nss_warning("%p: interface %d not in physical or dynamic if range\n", nss_ctx, ncm->interface);
Sol Kavya55c9a52014-04-08 14:33:16 -070045 return;
46 }
47
Suruchi Agarwalef8a8702016-01-08 12:40:08 -080048 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_if_msg)) {
49 nss_warning("%p: message length too big: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Sol Kavya55c9a52014-04-08 14:33:16 -070050 return;
51 }
52
53 /*
54 * Log failures
55 */
56 nss_core_log_msg_failures(nss_ctx, ncm);
57
58 /*
59 * Do we have a callback?
60 */
61 if (!ncm->cb) {
62 return;
63 }
64
65 /*
66 * Callback
67 */
68 cb = (nss_if_msg_callback_t)ncm->cb;
69 cb((void *)ncm->app_data, nim);
70}
71
72/*
73 * nss_if_tx_buf()
74 * Send packet to interface owned by NSS
75 */
76nss_tx_status_t nss_if_tx_buf(struct nss_ctx_instance *nss_ctx, struct sk_buff *os_buf, uint32_t if_num)
77{
Sol Kavya55c9a52014-04-08 14:33:16 -070078 nss_trace("%p: If Tx packet, id:%d, data=%p", nss_ctx, if_num, os_buf->data);
79
Sundarajan Srinivasancd1631b2015-06-18 01:23:30 -070080 if (!nss_is_dynamic_interface(if_num) &&
81 !((if_num >= NSS_PHYSICAL_IF_START) && (if_num < NSS_VIRTUAL_IF_START))) {
82 nss_warning("%p: interface %d not in physical or dynamic if range\n", nss_ctx, if_num);
83 return NSS_TX_FAILURE_BAD_PARAM;
84 }
85
Stephen Wang3e2dbd12018-03-14 17:28:17 -070086 return nss_core_send_packet(nss_ctx, os_buf, if_num, 0);
Sol Kavya55c9a52014-04-08 14:33:16 -070087}
88
89/*
90 * nss_if_tx_msg()
91 * Transmit a message to the specific interface on this core.
92 */
93nss_tx_status_t nss_if_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_if_msg *nim)
94{
95 struct nss_cmn_msg *ncm = &nim->cm;
Sol Kavya55c9a52014-04-08 14:33:16 -070096 struct net_device *dev;
Sol Kavya55c9a52014-04-08 14:33:16 -070097
Stephen Wang3e2dbd12018-03-14 17:28:17 -070098 NSS_VERIFY_CTX_MAGIC(nss_ctx);
Sol Kavya55c9a52014-04-08 14:33:16 -070099
100 /*
101 * Sanity check the message
102 */
Sol Kavya55c9a52014-04-08 14:33:16 -0700103 if (ncm->type > NSS_IF_MAX_MSG_TYPES) {
104 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
105 return NSS_TX_FAILURE;
106 }
107
Stephen Wang3e2dbd12018-03-14 17:28:17 -0700108 dev = nss_ctx->subsys_dp_register[ncm->interface].ndev;
Sol Kavya55c9a52014-04-08 14:33:16 -0700109 if (!dev) {
Stephen Wang3e2dbd12018-03-14 17:28:17 -0700110 nss_warning("%p: Unregister interface %d: no context", nss_ctx, ncm->interface);
Sol Kavya55c9a52014-04-08 14:33:16 -0700111 return NSS_TX_FAILURE_BAD_PARAM;
112 }
113
Stephen Wang3e2dbd12018-03-14 17:28:17 -0700114 return nss_core_send_cmd(nss_ctx, nim, sizeof(*nim), NSS_NBUF_PAYLOAD_SIZE);
Sol Kavya55c9a52014-04-08 14:33:16 -0700115}
116
117/*
118 * nss_if_register()
119 * Primary registration for receiving data and msgs from an interface.
120 */
121struct nss_ctx_instance *nss_if_register(uint32_t if_num,
Sakthi Vignesh Radhakrishnanef918492014-04-07 14:24:19 -0700122 nss_if_rx_callback_t rx_callback,
123 nss_if_msg_callback_t msg_callback,
Sol Kavya55c9a52014-04-08 14:33:16 -0700124 struct net_device *if_ctx)
125{
126 return NULL;
127}
128
129/*
130 * nss_if_unregister()
131 * Unregisteer the callback for this interface
132 */
133void nss_if_unregister(uint32_t if_num)
134{
135}
136
137EXPORT_SYMBOL(nss_if_tx_msg);
138EXPORT_SYMBOL(nss_if_register);
139EXPORT_SYMBOL(nss_if_unregister);