Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [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 | /* |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 18 | * nss_n2h.c |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 19 | * NSS N2H node APIs |
| 20 | */ |
| 21 | |
| 22 | #include "nss_tx_rx_common.h" |
| 23 | |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 24 | #define NSS_N2H_TIMEOUT 5*HZ |
| 25 | |
| 26 | wait_queue_head_t nss_n2h_wq; |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 27 | |
| 28 | /* |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 29 | * nss_n2h_tx() |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 30 | * Send Message to NSS to enable RPS. |
| 31 | * |
| 32 | * This API could be used for any additional RPS related |
| 33 | * configuration in future. |
| 34 | */ |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 35 | nss_tx_status_t nss_n2h_tx(struct nss_ctx_instance *nss_ctx, uint32_t enable_rps) |
| 36 | { |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 37 | struct sk_buff *nbuf; |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 38 | nss_tx_status_t status; |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 39 | struct nss_n2h_msg *nnhm; |
| 40 | struct nss_n2h_rps *rps_cfg; |
| 41 | |
| 42 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 43 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 44 | return NSS_TX_FAILURE_NOT_READY; |
| 45 | } |
| 46 | |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 47 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 48 | if (unlikely(!nbuf)) { |
| 49 | spin_lock_bh(&nss_ctx->nss_top->stats_lock); |
| 50 | nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++; |
| 51 | spin_unlock_bh(&nss_ctx->nss_top->stats_lock); |
| 52 | return NSS_TX_FAILURE; |
| 53 | } |
| 54 | |
| 55 | nnhm = (struct nss_n2h_msg *)skb_put(nbuf, sizeof(struct nss_n2h_msg)); |
| 56 | |
| 57 | nnhm->cm.type = NSS_TX_METADATA_TYPE_N2H_RPS_CFG; |
| 58 | nnhm->cm.version = NSS_HLOS_MESSAGE_VERSION; |
| 59 | nnhm->cm.interface = NSS_N2H_INTERFACE; |
| 60 | nnhm->cm.len = nbuf->len; |
| 61 | |
| 62 | rps_cfg = &nnhm->msg.rps_cfg; |
| 63 | |
| 64 | rps_cfg->enable = enable_rps; |
| 65 | |
| 66 | nss_info("n22_n2h_rps_configure %d \n", enable_rps); |
| 67 | |
| 68 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 69 | if (status != NSS_CORE_STATUS_SUCCESS) { |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 70 | dev_kfree_skb_any(nbuf); |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 71 | nss_info("%p: unable to enqueue 'nss frequency change' - marked as stopped\n", nss_ctx); |
| 72 | return NSS_TX_FAILURE; |
| 73 | } |
| 74 | |
| 75 | nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit, NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE); |
| 76 | |
| 77 | return NSS_TX_SUCCESS; |
| 78 | } |
| 79 | |
| 80 | /* |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 81 | * nss_n2h_stats_sync() |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 82 | * Handle the syncing of NSS statistics. |
| 83 | */ |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 84 | static void nss_n2h_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_n2h_stats_sync *nnss) |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 85 | { |
| 86 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
| 87 | |
| 88 | spin_lock_bh(&nss_top->stats_lock); |
| 89 | |
| 90 | /* |
| 91 | * common node stats |
| 92 | */ |
| 93 | nss_ctx->stats_n2h[NSS_STATS_NODE_RX_PKTS] += nnss->node_stats.rx_packets; |
| 94 | nss_ctx->stats_n2h[NSS_STATS_NODE_RX_BYTES] += nnss->node_stats.rx_bytes; |
| 95 | nss_ctx->stats_n2h[NSS_STATS_NODE_RX_DROPPED] += nnss->node_stats.rx_dropped; |
| 96 | nss_ctx->stats_n2h[NSS_STATS_NODE_TX_PKTS] += nnss->node_stats.tx_packets; |
| 97 | nss_ctx->stats_n2h[NSS_STATS_NODE_TX_BYTES] += nnss->node_stats.tx_bytes; |
| 98 | |
| 99 | /* |
| 100 | * General N2H stats |
| 101 | */ |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 102 | nss_ctx->stats_n2h[NSS_STATS_N2H_QUEUE_DROPPED] += nnss->queue_dropped; |
| 103 | nss_ctx->stats_n2h[NSS_STATS_N2H_TOTAL_TICKS] += nnss->total_ticks; |
| 104 | nss_ctx->stats_n2h[NSS_STATS_N2H_WORST_CASE_TICKS] += nnss->worst_case_ticks; |
| 105 | nss_ctx->stats_n2h[NSS_STATS_N2H_ITERATIONS] += nnss->iterations; |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 106 | |
| 107 | /* |
Thomas Wu | 3fd8dd7 | 2014-06-11 15:57:05 -0700 | [diff] [blame] | 108 | * pbuf manager ocm and default pool stats |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 109 | */ |
Thomas Wu | 3fd8dd7 | 2014-06-11 15:57:05 -0700 | [diff] [blame] | 110 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_ALLOC_FAILS] += nnss->pbuf_ocm_stats.pbuf_alloc_fails; |
| 111 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_FREE_COUNT] = nnss->pbuf_ocm_stats.pbuf_free_count; |
| 112 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_TOTAL_COUNT] = nnss->pbuf_ocm_stats.pbuf_total_count; |
| 113 | |
| 114 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_ALLOC_FAILS] += nnss->pbuf_default_stats.pbuf_alloc_fails; |
| 115 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_FREE_COUNT] = nnss->pbuf_default_stats.pbuf_free_count; |
| 116 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_TOTAL_COUNT] = nnss->pbuf_default_stats.pbuf_total_count; |
| 117 | |
| 118 | /* |
| 119 | * payload mgr stats |
| 120 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 121 | nss_ctx->stats_n2h[NSS_STATS_N2H_PAYLOAD_ALLOC_FAILS] += nnss->payload_alloc_fails; |
| 122 | |
| 123 | spin_unlock_bh(&nss_top->stats_lock); |
| 124 | } |
| 125 | |
| 126 | /* |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 127 | * nss_n2h_interface_handler() |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 128 | * Handle NSS -> HLOS messages for N2H node |
| 129 | */ |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 130 | static void nss_n2h_interface_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 131 | { |
| 132 | struct nss_n2h_msg *nnm = (struct nss_n2h_msg *)ncm; |
| 133 | |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 134 | BUG_ON(ncm->interface != NSS_N2H_INTERFACE); |
| 135 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 136 | /* |
| 137 | * Is this a valid request/response packet? |
| 138 | */ |
| 139 | if (nnm->cm.type >= NSS_METADATA_TYPE_N2H_MAX) { |
| 140 | nss_warning("%p: received invalid message %d for Offload stats interface", nss_ctx, nnm->cm.type); |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | switch (nnm->cm.type) { |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 145 | case NSS_TX_METADATA_TYPE_N2H_RPS_CFG: |
| 146 | nss_ctx->n2h_rps_en = nnm->msg.rps_cfg.enable; |
| 147 | nss_info("NSS N2H rps_en %d \n",nnm->msg.rps_cfg.enable); |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 148 | wake_up(&nss_n2h_wq); |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 149 | break; |
| 150 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 151 | case NSS_RX_METADATA_TYPE_N2H_STATS_SYNC: |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 152 | nss_n2h_stats_sync(nss_ctx, &nnm->msg.stats_sync); |
| 153 | wake_up(&nss_n2h_wq); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 154 | break; |
| 155 | |
| 156 | default: |
| 157 | if (ncm->response != NSS_CMN_RESPONSE_ACK) { |
| 158 | /* |
| 159 | * Check response |
| 160 | */ |
| 161 | nss_info("%p: Received response %d for type %d, interface %d", |
| 162 | nss_ctx, ncm->response, ncm->type, ncm->interface); |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | /* |
| 168 | * nss_n2h_register_handler() |
| 169 | */ |
| 170 | void nss_n2h_register_handler() |
| 171 | { |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 172 | nss_core_register_handler(NSS_N2H_INTERFACE, nss_n2h_interface_handler, NULL); |
| 173 | |
| 174 | /* |
| 175 | * Initialize wait queue |
| 176 | */ |
| 177 | init_waitqueue_head(&nss_n2h_wq); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 178 | } |