blob: 150a73798bf76548826210aad761bd81549969e7 [file] [log] [blame]
Jackson Bockusb40398c2017-10-03 11:01:37 -07001/*
2 **************************************************************************
3 * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
4 * 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_unaligned.c
19 * NSS unaligned APIs
20 */
21
22#include "nss_tx_rx_common.h"
23#include "nss_unaligned_stats.h"
24#include "nss_unaligned_log.h"
25
26/*
27 * nss_unaligned_update_stats()
28 * Updates the statistics in the nss_ctx.
29 */
30static void nss_unaligned_update_stats(struct nss_ctx_instance *nss_ctx,
31 struct nss_unaligned_stats *usm)
32{
33 spin_lock_bh(&nss_top_main.stats_lock);
34 nss_ctx->unaligned_stats = *usm;
35 spin_unlock_bh(&nss_top_main.stats_lock);
36}
37
38/*
39 * nss_unaligned_msg_handler()
40 * Handles metadata messages on the unaligned interface.
41 */
42static void nss_unaligned_msg_handler(struct nss_ctx_instance *nss_ctx,
43 struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
44{
45 struct nss_unaligned_msg *um = (struct nss_unaligned_msg *)ncm;
46
47 /*
48 * Sanity checks on message
49 */
50 if (um->cm.type >= NSS_UNALIGNED_MSG_MAX) {
51 nss_warning("%p: message type out of range: %d\n", nss_ctx, um->cm.type);
52 return;
53 }
54
55 if (nss_cmn_get_msg_len(&(um->cm)) > sizeof(struct nss_unaligned_msg)) {
56 nss_warning("%p: message length is invalid: %d\n", nss_ctx, nss_cmn_get_msg_len(&(um->cm)));
57 return;
58 }
59
60 nss_unaligned_log_rx_msg(um);
61
62 switch (um->cm.type) {
63 case NSS_UNALIGNED_MSG_STATS:
64 nss_unaligned_update_stats(nss_ctx, &um->msg.stats_msg);
65 return;
66 }
67
68 nss_core_log_msg_failures(nss_ctx, ncm);
69}
70
71/*
72 * nss_unaligned_register_handler()
73 * Registers message handler on the NSS unaligned interface and stats dentry.
74 */
75void nss_unaligned_register_handler(struct nss_ctx_instance *nss_ctx)
76{
77 nss_core_register_handler(nss_ctx, NSS_UNALIGNED_INTERFACE, nss_unaligned_msg_handler, NULL);
78 nss_unaligned_stats_dentry_create();
79}