blob: 840f40d37241cd105264d3ca12e8c9b4bc0a4a42 [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,
Jackson Bockus95842802019-02-27 10:12:05 -080031 struct nss_unaligned_stats_msg *usm)
Jackson Bockusb40398c2017-10-03 11:01:37 -070032{
Jackson Bockus95842802019-02-27 10:12:05 -080033 uint32_t start_index = NSS_UNALIGNED_OPS_PER_MSG * usm->current_iteration;
34 uint32_t i;
Jackson Bockusb40398c2017-10-03 11:01:37 -070035 spin_lock_bh(&nss_top_main.stats_lock);
Jackson Bockus95842802019-02-27 10:12:05 -080036 nss_ctx->unaligned_stats.trap_count = usm->trap_count;
37 for (i = 0; i < NSS_UNALIGNED_OPS_PER_MSG; i++) {
38 uint32_t index = i + start_index;
39 if (unlikely(index >= NSS_UNALIGNED_EMULATED_OPS)) {
40 break;
41 }
42 nss_ctx->unaligned_stats.ops[index] = usm->ops[i];
43 }
Jackson Bockusb40398c2017-10-03 11:01:37 -070044 spin_unlock_bh(&nss_top_main.stats_lock);
45}
46
47/*
48 * nss_unaligned_msg_handler()
49 * Handles metadata messages on the unaligned interface.
50 */
51static void nss_unaligned_msg_handler(struct nss_ctx_instance *nss_ctx,
52 struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
53{
54 struct nss_unaligned_msg *um = (struct nss_unaligned_msg *)ncm;
55
56 /*
57 * Sanity checks on message
58 */
59 if (um->cm.type >= NSS_UNALIGNED_MSG_MAX) {
60 nss_warning("%p: message type out of range: %d\n", nss_ctx, um->cm.type);
61 return;
62 }
63
64 if (nss_cmn_get_msg_len(&(um->cm)) > sizeof(struct nss_unaligned_msg)) {
65 nss_warning("%p: message length is invalid: %d\n", nss_ctx, nss_cmn_get_msg_len(&(um->cm)));
66 return;
67 }
68
69 nss_unaligned_log_rx_msg(um);
70
71 switch (um->cm.type) {
72 case NSS_UNALIGNED_MSG_STATS:
73 nss_unaligned_update_stats(nss_ctx, &um->msg.stats_msg);
74 return;
75 }
76
77 nss_core_log_msg_failures(nss_ctx, ncm);
78}
79
80/*
81 * nss_unaligned_register_handler()
82 * Registers message handler on the NSS unaligned interface and stats dentry.
83 */
84void nss_unaligned_register_handler(struct nss_ctx_instance *nss_ctx)
85{
86 nss_core_register_handler(nss_ctx, NSS_UNALIGNED_INTERFACE, nss_unaligned_msg_handler, NULL);
87 nss_unaligned_stats_dentry_create();
88}