Jackson Bockus | b40398c | 2017-10-03 11:01:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Kyle Swenson | dd7b296 | 2021-03-16 13:46:32 -0600 | [diff] [blame^] | 3 | * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. |
Jackson Bockus | b40398c | 2017-10-03 11:01:37 -0700 | [diff] [blame] | 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 | */ |
| 30 | static void nss_unaligned_update_stats(struct nss_ctx_instance *nss_ctx, |
Jackson Bockus | 9584280 | 2019-02-27 10:12:05 -0800 | [diff] [blame] | 31 | struct nss_unaligned_stats_msg *usm) |
Jackson Bockus | b40398c | 2017-10-03 11:01:37 -0700 | [diff] [blame] | 32 | { |
Jackson Bockus | 9584280 | 2019-02-27 10:12:05 -0800 | [diff] [blame] | 33 | uint32_t start_index = NSS_UNALIGNED_OPS_PER_MSG * usm->current_iteration; |
| 34 | uint32_t i; |
Jackson Bockus | b40398c | 2017-10-03 11:01:37 -0700 | [diff] [blame] | 35 | spin_lock_bh(&nss_top_main.stats_lock); |
Jackson Bockus | 9584280 | 2019-02-27 10:12:05 -0800 | [diff] [blame] | 36 | 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 Bockus | b40398c | 2017-10-03 11:01:37 -0700 | [diff] [blame] | 44 | 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 | */ |
| 51 | static 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) { |
Kyle Swenson | dd7b296 | 2021-03-16 13:46:32 -0600 | [diff] [blame^] | 60 | nss_warning("%px: message type out of range: %d\n", nss_ctx, um->cm.type); |
Jackson Bockus | b40398c | 2017-10-03 11:01:37 -0700 | [diff] [blame] | 61 | return; |
| 62 | } |
| 63 | |
| 64 | if (nss_cmn_get_msg_len(&(um->cm)) > sizeof(struct nss_unaligned_msg)) { |
Kyle Swenson | dd7b296 | 2021-03-16 13:46:32 -0600 | [diff] [blame^] | 65 | nss_warning("%px: message length is invalid: %d\n", nss_ctx, nss_cmn_get_msg_len(&(um->cm))); |
Jackson Bockus | b40398c | 2017-10-03 11:01:37 -0700 | [diff] [blame] | 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 | */ |
| 84 | void 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); |
Cemil Coskun | 26be616 | 2019-06-28 15:44:48 -0700 | [diff] [blame] | 87 | |
| 88 | if (nss_ctx->id == NSS_CORE_0) { |
| 89 | nss_unaligned_stats_dentry_create(); |
| 90 | } |
Jackson Bockus | b40398c | 2017-10-03 11:01:37 -0700 | [diff] [blame] | 91 | } |