Amit Gupta | 316729b | 2016-08-12 12:21:15 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Thomas Wu | fc4d9fd | 2017-03-22 10:15:30 -0700 | [diff] [blame] | 3 | * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. |
Amit Gupta | 316729b | 2016-08-12 12:21:15 +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 | #include "nss_ppe.h" |
| 18 | |
Amit Gupta | 79c1c20 | 2017-06-30 15:28:13 +0530 | [diff] [blame^] | 19 | static uint8_t ppe_cc_nonexception[NSS_STATS_PPE_CPU_CODE_NONEXCEPTION_MAX] = { |
| 20 | NSS_STATS_PPE_CPU_CODE_EXP_FAKE_L2_PROT_ERR, |
| 21 | NSS_STATS_PPE_CPU_CODE_EXP_FAKE_MAC_HEADER_ERR, |
| 22 | NSS_STATS_PPE_CPU_CODE_EXP_BITMAP_MAX, |
| 23 | NSS_STATS_PPE_CPU_CODE_L2_EXP_MRU_FAIL, |
| 24 | NSS_STATS_PPE_CPU_CODE_L2_EXP_MTU_FAIL, |
| 25 | NSS_STATS_PPE_CPU_CODE_L3_EXP_IP_PREFIX_BC, |
| 26 | NSS_STATS_PPE_CPU_CODE_L3_EXP_MTU_FAIL, |
| 27 | NSS_STATS_PPE_CPU_CODE_L3_EXP_MRU_FAIL, |
| 28 | NSS_STATS_PPE_CPU_CODE_L3_EXP_ICMP_RDT, |
| 29 | NSS_STATS_PPE_CPU_CODE_L3_EXP_IP_RT_TTL1_TO_ME, |
| 30 | NSS_STATS_PPE_CPU_CODE_L3_EXP_IP_RT_TTL_ZERO, |
| 31 | NSS_STATS_PPE_CPU_CODE_L3_FLOW_SERVICE_CODE_LOOP, |
| 32 | NSS_STATS_PPE_CPU_CODE_L3_FLOW_DE_ACCELERATE, |
| 33 | NSS_STATS_PPE_CPU_CODE_L3_EXP_FLOW_SRC_IF_CHK_FAIL, |
| 34 | NSS_STATS_PPE_CPU_CODE_L3_FLOW_SYNC_TOGGLE_MISMATCH, |
| 35 | NSS_STATS_PPE_CPU_CODE_L3_EXP_MTU_DF_FAIL, |
| 36 | NSS_STATS_PPE_CPU_CODE_L3_EXP_PPPOE_MULTICAST, |
| 37 | NSS_STATS_PPE_CPU_CODE_MGMT_OFFSET, |
| 38 | NSS_STATS_PPE_CPU_CODE_MGMT_EAPOL, |
| 39 | NSS_STATS_PPE_CPU_CODE_MGMT_PPPOE_DIS, |
| 40 | NSS_STATS_PPE_CPU_CODE_MGMT_IGMP, |
| 41 | NSS_STATS_PPE_CPU_CODE_MGMT_ARP_REQ, |
| 42 | NSS_STATS_PPE_CPU_CODE_MGMT_ARP_REP, |
| 43 | NSS_STATS_PPE_CPU_CODE_MGMT_DHCPv4, |
| 44 | NSS_STATS_PPE_CPU_CODE_MGMT_MLD, |
| 45 | NSS_STATS_PPE_CPU_CODE_MGMT_NS, |
| 46 | NSS_STATS_PPE_CPU_CODE_MGMT_NA, |
| 47 | NSS_STATS_PPE_CPU_CODE_MGMT_DHCPv6, |
| 48 | NSS_STATS_PPE_CPU_CODE_PTP_OFFSET, |
| 49 | NSS_STATS_PPE_CPU_CODE_PTP_SYNC, |
| 50 | NSS_STATS_PPE_CPU_CODE_PTP_FOLLOW_UP, |
| 51 | NSS_STATS_PPE_CPU_CODE_PTP_DELAY_REQ, |
| 52 | NSS_STATS_PPE_CPU_CODE_PTP_DELAY_RESP, |
| 53 | NSS_STATS_PPE_CPU_CODE_PTP_PDELAY_REQ, |
| 54 | NSS_STATS_PPE_CPU_CODE_PTP_PDELAY_RESP, |
| 55 | NSS_STATS_PPE_CPU_CODE_PTP_PDELAY_RESP_FOLLOW_UP, |
| 56 | NSS_STATS_PPE_CPU_CODE_PTP_ANNOUNCE, |
| 57 | NSS_STATS_PPE_CPU_CODE_PTP_MANAGEMENT, |
| 58 | NSS_STATS_PPE_CPU_CODE_PTP_SIGNALING, |
| 59 | NSS_STATS_PPE_CPU_CODE_PTP_PKT_RSV_MSG, |
| 60 | NSS_STATS_PPE_CPU_CODE_IPV4_SG_UNKNOWN, |
| 61 | NSS_STATS_PPE_CPU_CODE_IPV6_SG_UNKNOWN, |
| 62 | NSS_STATS_PPE_CPU_CODE_ARP_SG_UNKNOWN, |
| 63 | NSS_STATS_PPE_CPU_CODE_ND_SG_UNKNOWN, |
| 64 | NSS_STATS_PPE_CPU_CODE_IPV4_SG_VIO, |
| 65 | NSS_STATS_PPE_CPU_CODE_IPV6_SG_VIO, |
| 66 | NSS_STATS_PPE_CPU_CODE_ARP_SG_VIO, |
| 67 | NSS_STATS_PPE_CPU_CODE_ND_SG_VIO, |
| 68 | NSS_STATS_PPE_CPU_CODE_L3_ROUTING_IP_TO_ME, |
| 69 | NSS_STATS_PPE_CPU_CODE_L3_FLOW_SNAT_ACTION, |
| 70 | NSS_STATS_PPE_CPU_CODE_L3_FLOW_DNAT_ACTION, |
| 71 | NSS_STATS_PPE_CPU_CODE_L3_FLOW_RT_ACTION, |
| 72 | NSS_STATS_PPE_CPU_CODE_L3_FLOW_BR_ACTION, |
| 73 | NSS_STATS_PPE_CPU_CODE_L3_MC_BRIDGE_ACTION, |
| 74 | NSS_STATS_PPE_CPU_CODE_L3_ROUTE_PREHEAD_RT_ACTION, |
| 75 | NSS_STATS_PPE_CPU_CODE_L3_ROUTE_PREHEAD_SNAPT_ACTION, |
| 76 | NSS_STATS_PPE_CPU_CODE_L3_ROUTE_PREHEAD_DNAPT_ACTION, |
| 77 | NSS_STATS_PPE_CPU_CODE_L3_ROUTE_PREHEAD_SNAT_ACTION, |
| 78 | NSS_STATS_PPE_CPU_CODE_L3_ROUTE_PREHEAD_DNAT_ACTION, |
| 79 | NSS_STATS_PPE_CPU_CODE_L3_NO_ROUTE_PREHEAD_NAT_ACTION, |
| 80 | NSS_STATS_PPE_CPU_CODE_L3_NO_ROUTE_PREHEAD_NAT_ERROR, |
| 81 | NSS_STATS_PPE_CPU_CODE_L3_ROUTE_ACTION, |
| 82 | NSS_STATS_PPE_CPU_CODE_L3_NO_ROUTE_ACTION, |
| 83 | NSS_STATS_PPE_CPU_CODE_L3_NO_ROUTE_NH_INVALID_ACTION, |
| 84 | NSS_STATS_PPE_CPU_CODE_L3_NO_ROUTE_PREHEAD_ACTION, |
| 85 | NSS_STATS_PPE_CPU_CODE_L3_BRIDGE_ACTION, |
| 86 | NSS_STATS_PPE_CPU_CODE_L3_FLOW_ACTION, |
| 87 | NSS_STATS_PPE_CPU_CODE_L3_FLOW_MISS_ACTION, |
| 88 | NSS_STATS_PPE_CPU_CODE_L2_NEW_MAC_ADDRESS, |
| 89 | NSS_STATS_PPE_CPU_CODE_L2_HASH_COLLISION, |
| 90 | NSS_STATS_PPE_CPU_CODE_L2_STATION_MOVE, |
| 91 | NSS_STATS_PPE_CPU_CODE_L2_LEARN_LIMIT, |
| 92 | NSS_STATS_PPE_CPU_CODE_L2_SA_LOOKUP_ACTION, |
| 93 | NSS_STATS_PPE_CPU_CODE_L2_DA_LOOKUP_ACTION, |
| 94 | NSS_STATS_PPE_CPU_CODE_APP_CTRL_ACTION, |
| 95 | NSS_STATS_PPE_CPU_CODE_IN_VLAN_FILTER_ACTION, |
| 96 | NSS_STATS_PPE_CPU_CODE_IN_VLAN_XLT_MISS, |
| 97 | NSS_STATS_PPE_CPU_CODE_EG_VLAN_FILTER_DROP, |
| 98 | NSS_STATS_PPE_CPU_CODE_ACL_PRE_ACTION, |
| 99 | NSS_STATS_PPE_CPU_CODE_ACL_POST_ACTION, |
| 100 | NSS_STATS_PPE_CPU_CODE_SERVICE_CODE_ACTION, |
| 101 | }; |
| 102 | |
Amit Gupta | 316729b | 2016-08-12 12:21:15 +0530 | [diff] [blame] | 103 | /* |
| 104 | * nss_ppe_verify_ifnum() |
| 105 | * Verify PPE interface number. |
| 106 | */ |
| 107 | static inline bool nss_ppe_verify_ifnum(int if_num) |
| 108 | { |
| 109 | return nss_is_dynamic_interface(if_num) || (if_num == NSS_PPE_INTERFACE); |
| 110 | } |
| 111 | |
| 112 | /* |
| 113 | * nss_ppe_stats_sync |
| 114 | * PPE connection sync stats from NSS |
| 115 | */ |
| 116 | static void nss_ppe_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_ppe_sync_stats_msg *stats_msg, uint16_t if_num) |
| 117 | { |
| 118 | spin_lock_bh(&nss_ppe_stats_lock); |
| 119 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_L3_FLOWS] += stats_msg->nss_ppe_v4_l3_flows; |
| 120 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_L2_FLOWS] += stats_msg->nss_ppe_v4_l2_flows; |
| 121 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_CREATE_REQ] += stats_msg->nss_ppe_v4_create_req; |
| 122 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_CREATE_FAIL] += stats_msg->nss_ppe_v4_create_fail; |
| 123 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_DESTROY_REQ] += stats_msg->nss_ppe_v4_destroy_req; |
| 124 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_DESTROY_FAIL] += stats_msg->nss_ppe_v4_destroy_fail; |
Amit Gupta | 263df9c | 2017-05-16 20:43:07 +0530 | [diff] [blame] | 125 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_MC_CREATE_REQ] += stats_msg->nss_ppe_v4_mc_create_req; |
| 126 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_MC_CREATE_FAIL] += stats_msg->nss_ppe_v4_mc_create_fail; |
| 127 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_MC_UPDATE_REQ] += stats_msg->nss_ppe_v4_mc_update_req; |
| 128 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_MC_UPDATE_FAIL] += stats_msg->nss_ppe_v4_mc_update_fail; |
| 129 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_MC_DESTROY_REQ] += stats_msg->nss_ppe_v4_mc_destroy_req; |
| 130 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_MC_DESTROY_FAIL] += stats_msg->nss_ppe_v4_mc_destroy_fail; |
Amit Gupta | 316729b | 2016-08-12 12:21:15 +0530 | [diff] [blame] | 131 | |
| 132 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_L3_FLOWS] += stats_msg->nss_ppe_v6_l3_flows; |
| 133 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_L2_FLOWS] += stats_msg->nss_ppe_v6_l2_flows; |
| 134 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_CREATE_REQ] += stats_msg->nss_ppe_v6_create_req; |
| 135 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_CREATE_FAIL] += stats_msg->nss_ppe_v6_create_fail; |
| 136 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_DESTROY_REQ] += stats_msg->nss_ppe_v6_destroy_req; |
| 137 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_DESTROY_FAIL] += stats_msg->nss_ppe_v6_destroy_fail; |
Amit Gupta | 263df9c | 2017-05-16 20:43:07 +0530 | [diff] [blame] | 138 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_MC_CREATE_REQ] += stats_msg->nss_ppe_v6_mc_create_req; |
| 139 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_MC_CREATE_FAIL] += stats_msg->nss_ppe_v6_mc_create_fail; |
| 140 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_MC_UPDATE_REQ] += stats_msg->nss_ppe_v6_mc_update_req; |
| 141 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_MC_UPDATE_FAIL] += stats_msg->nss_ppe_v6_mc_update_fail; |
| 142 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_MC_DESTROY_REQ] += stats_msg->nss_ppe_v6_mc_destroy_req; |
| 143 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_MC_DESTROY_FAIL] += stats_msg->nss_ppe_v6_mc_destroy_fail; |
Amit Gupta | 316729b | 2016-08-12 12:21:15 +0530 | [diff] [blame] | 144 | |
Amit Gupta | 263df9c | 2017-05-16 20:43:07 +0530 | [diff] [blame] | 145 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_VP_FULL] += stats_msg->nss_ppe_fail_vp_full; |
Amit Gupta | 316729b | 2016-08-12 12:21:15 +0530 | [diff] [blame] | 146 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_NH_FULL] += stats_msg->nss_ppe_fail_nh_full; |
| 147 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_FLOW_FULL] += stats_msg->nss_ppe_fail_flow_full; |
| 148 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_HOST_FULL] += stats_msg->nss_ppe_fail_host_full; |
| 149 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_PUBIP_FULL] += stats_msg->nss_ppe_fail_pubip_full; |
| 150 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_PORT_SETUP] += stats_msg->nss_ppe_fail_port_setup; |
| 151 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_RW_FIFO_FULL] += stats_msg->nss_ppe_fail_rw_fifo_full; |
| 152 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_FLOW_COMMAND] += stats_msg->nss_ppe_fail_flow_command; |
| 153 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_UNKNOWN_PROTO] += stats_msg->nss_ppe_fail_unknown_proto; |
| 154 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_PPE_UNRESPONSIVE] += stats_msg->nss_ppe_fail_ppe_unresponsive; |
Amit Gupta | 263df9c | 2017-05-16 20:43:07 +0530 | [diff] [blame] | 155 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_CE_OPAQUE_INVALID] += stats_msg->nss_ppe_ce_opaque_invalid; |
Thomas Wu | fc4d9fd | 2017-03-22 10:15:30 -0700 | [diff] [blame] | 156 | nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_FQG_FULL] += stats_msg->nss_ppe_fail_fqg_full; |
Amit Gupta | 316729b | 2016-08-12 12:21:15 +0530 | [diff] [blame] | 157 | spin_unlock_bh(&nss_ppe_stats_lock); |
| 158 | } |
| 159 | |
| 160 | /* |
| 161 | * nss_ppe_stats_conn_get() |
| 162 | * Get ppe connection stats. |
| 163 | */ |
| 164 | void nss_ppe_stats_conn_get(uint32_t *stats) |
| 165 | { |
| 166 | if (!stats) { |
| 167 | nss_warning("No memory to copy ppe connection stats"); |
| 168 | return; |
| 169 | } |
| 170 | |
| 171 | spin_lock_bh(&nss_ppe_stats_lock); |
| 172 | |
| 173 | if (!nss_ppe_debug_stats.valid) { |
| 174 | spin_unlock_bh(&nss_ppe_stats_lock); |
| 175 | nss_warning("PPE base address not initialized!\n"); |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * Get flow stats |
| 181 | */ |
| 182 | memcpy(stats, nss_ppe_debug_stats.conn_stats, (sizeof(uint32_t) * NSS_STATS_PPE_CONN_MAX)); |
| 183 | |
| 184 | spin_unlock_bh(&nss_ppe_stats_lock); |
| 185 | } |
| 186 | |
| 187 | /* |
| 188 | * nss_ppe_stats_l3_get() |
| 189 | * Get ppe L3 debug stats. |
| 190 | */ |
| 191 | void nss_ppe_stats_l3_get(uint32_t *stats) |
| 192 | { |
| 193 | if (!stats) { |
| 194 | nss_warning("No memory to copy ppe l3 dbg stats\n"); |
| 195 | return; |
| 196 | } |
| 197 | |
| 198 | spin_lock_bh(&nss_ppe_stats_lock); |
| 199 | |
| 200 | if (!nss_ppe_debug_stats.valid) { |
| 201 | spin_unlock_bh(&nss_ppe_stats_lock); |
| 202 | nss_warning("PPE base address not initialized!\n"); |
| 203 | return; |
| 204 | } |
| 205 | |
| 206 | nss_ppe_reg_write(PPE_L3_DBG_WR_OFFSET, PPE_L3_DBG0_OFFSET); |
| 207 | nss_ppe_reg_read(PPE_L3_DBG_RD_OFFSET, &stats[NSS_STATS_PPE_L3_DBG_0]); |
| 208 | |
| 209 | nss_ppe_reg_write(PPE_L3_DBG_WR_OFFSET, PPE_L3_DBG1_OFFSET); |
| 210 | nss_ppe_reg_read(PPE_L3_DBG_RD_OFFSET, &stats[NSS_STATS_PPE_L3_DBG_1]); |
| 211 | |
| 212 | nss_ppe_reg_write(PPE_L3_DBG_WR_OFFSET, PPE_L3_DBG2_OFFSET); |
| 213 | nss_ppe_reg_read(PPE_L3_DBG_RD_OFFSET, &stats[NSS_STATS_PPE_L3_DBG_2]); |
| 214 | |
| 215 | nss_ppe_reg_write(PPE_L3_DBG_WR_OFFSET, PPE_L3_DBG3_OFFSET); |
| 216 | nss_ppe_reg_read(PPE_L3_DBG_RD_OFFSET, &stats[NSS_STATS_PPE_L3_DBG_3]); |
| 217 | |
| 218 | nss_ppe_reg_write(PPE_L3_DBG_WR_OFFSET, PPE_L3_DBG4_OFFSET); |
| 219 | nss_ppe_reg_read(PPE_L3_DBG_RD_OFFSET, &stats[NSS_STATS_PPE_L3_DBG_4]); |
| 220 | |
| 221 | nss_ppe_reg_write(PPE_L3_DBG_WR_OFFSET, PPE_L3_DBG_PORT_OFFSET); |
| 222 | nss_ppe_reg_read(PPE_L3_DBG_RD_OFFSET, &stats[NSS_STATS_PPE_L3_DBG_PORT]); |
| 223 | |
| 224 | spin_unlock_bh(&nss_ppe_stats_lock); |
| 225 | } |
| 226 | |
| 227 | /* |
| 228 | * nss_ppe_stats_code_get() |
| 229 | * Get ppe CPU and DROP code for last packet processed. |
| 230 | */ |
| 231 | void nss_ppe_stats_code_get(uint32_t *stats) |
| 232 | { |
| 233 | uint32_t drop_0, drop_1, cpu_code; |
| 234 | |
| 235 | nss_trace("%s(%d) Start\n", __func__, __LINE__); |
| 236 | if (!stats) { |
| 237 | nss_warning("No memory to copy ppe code\n"); |
| 238 | return; |
| 239 | } |
| 240 | |
| 241 | if (!nss_ppe_debug_stats.valid) { |
| 242 | nss_warning("PPE base address not initialized!\n"); |
| 243 | return; |
| 244 | } |
| 245 | |
| 246 | spin_lock_bh(&nss_ppe_stats_lock); |
| 247 | nss_ppe_reg_write(PPE_PKT_CODE_WR_OFFSET, PPE_PKT_CODE_DROP0_OFFSET); |
| 248 | nss_ppe_reg_read(PPE_PKT_CODE_RD_OFFSET, &drop_0); |
| 249 | |
| 250 | nss_ppe_reg_write(PPE_PKT_CODE_WR_OFFSET, PPE_PKT_CODE_DROP1_OFFSET); |
| 251 | nss_ppe_reg_read(PPE_PKT_CODE_RD_OFFSET, &drop_1); |
| 252 | |
| 253 | stats[NSS_STATS_PPE_CODE_DROP] = PPE_PKT_CODE_DROP_GET(drop_0, drop_1); |
| 254 | |
| 255 | nss_ppe_reg_write(PPE_PKT_CODE_WR_OFFSET, PPE_PKT_CODE_CPU_OFFSET); |
| 256 | nss_ppe_reg_read(PPE_PKT_CODE_RD_OFFSET, &cpu_code); |
| 257 | |
| 258 | stats[NSS_STATS_PPE_CODE_CPU] = PPE_PKT_CODE_CPU_GET(cpu_code); |
| 259 | |
| 260 | spin_unlock_bh(&nss_ppe_stats_lock); |
| 261 | } |
| 262 | |
| 263 | /* |
Amit Gupta | 79c1c20 | 2017-06-30 15:28:13 +0530 | [diff] [blame^] | 264 | * nss_ppe_port_drop_code_get() |
| 265 | * Get ppe per port drop code. |
| 266 | */ |
| 267 | void nss_ppe_port_drop_code_get(uint32_t *stats, uint8_t port_id) |
| 268 | { |
| 269 | uint8_t i; |
| 270 | nss_trace("%s(%d) Start\n", __func__, __LINE__); |
| 271 | if (!stats) { |
| 272 | nss_warning("No memory to copy ppe code\n"); |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | if (port_id > NSS_PPE_NUM_PHY_PORTS_MAX) { |
| 277 | nss_warning("Port id is out of range\n"); |
| 278 | return; |
| 279 | } |
| 280 | |
| 281 | if (!nss_ppe_debug_stats.valid) { |
| 282 | nss_warning("PPE base address not initialized!\n"); |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | spin_lock_bh(&nss_ppe_stats_lock); |
| 287 | |
| 288 | for (i = 0; i < NSS_STATS_PPE_DROP_CODE_MAX; i++) { |
| 289 | nss_ppe_reg_read(PPE_DROP_CODE_OFFSET(i, port_id), &stats[i]); |
| 290 | } |
| 291 | |
| 292 | spin_unlock_bh(&nss_ppe_stats_lock); |
| 293 | } |
| 294 | |
| 295 | /* |
| 296 | * nss_ppe_cpu_code_exception_get() |
| 297 | * Get ppe cpu code specific for flow exceptions. |
| 298 | */ |
| 299 | void nss_ppe_cpu_code_exception_get(uint32_t *stats) |
| 300 | { |
| 301 | uint8_t i; |
| 302 | nss_trace("%s(%d) Start\n", __func__, __LINE__); |
| 303 | if (!stats) { |
| 304 | nss_warning("No memory to copy ppe code\n"); |
| 305 | return; |
| 306 | } |
| 307 | |
| 308 | if (!nss_ppe_debug_stats.valid) { |
| 309 | nss_warning("PPE base address not initialized!\n"); |
| 310 | return; |
| 311 | } |
| 312 | |
| 313 | spin_lock_bh(&nss_ppe_stats_lock); |
| 314 | |
| 315 | for (i = 0; i < NSS_STATS_PPE_CPU_CODE_EXCEPTION_MAX ; i++) { |
| 316 | nss_ppe_reg_read(PPE_CPU_CODE_OFFSET(i), &stats[i]); |
| 317 | } |
| 318 | |
| 319 | spin_unlock_bh(&nss_ppe_stats_lock); |
| 320 | } |
| 321 | |
| 322 | /* |
| 323 | * nss_ppe_cpu_code_nonexception_get() |
| 324 | * Get ppe cpu code specific for flow exceptions. |
| 325 | */ |
| 326 | void nss_ppe_cpu_code_nonexception_get(uint32_t *stats) |
| 327 | { |
| 328 | uint8_t i; |
| 329 | nss_trace("%s(%d) Start\n", __func__, __LINE__); |
| 330 | if (!stats) { |
| 331 | nss_warning("No memory to copy ppe code\n"); |
| 332 | return; |
| 333 | } |
| 334 | |
| 335 | if (!nss_ppe_debug_stats.valid) { |
| 336 | nss_warning("PPE base address not initialized!\n"); |
| 337 | return; |
| 338 | } |
| 339 | |
| 340 | spin_lock_bh(&nss_ppe_stats_lock); |
| 341 | |
| 342 | for (i = 0; i < NSS_STATS_PPE_CPU_CODE_NONEXCEPTION_MAX; i++) { |
| 343 | nss_ppe_reg_read(PPE_CPU_CODE_OFFSET(ppe_cc_nonexception[i]), &stats[i]); |
| 344 | } |
| 345 | |
| 346 | spin_unlock_bh(&nss_ppe_stats_lock); |
| 347 | } |
| 348 | |
| 349 | /* |
Amit Gupta | 316729b | 2016-08-12 12:21:15 +0530 | [diff] [blame] | 350 | * nss_ppe_handler() |
| 351 | * Handle NSS -> HLOS messages for ppe tunnel |
| 352 | */ |
| 353 | static void nss_ppe_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
| 354 | { |
| 355 | struct nss_ppe_msg *msg = (struct nss_ppe_msg *)ncm; |
| 356 | |
| 357 | nss_trace("nss_ctx: %p ppe msg: %p", nss_ctx, msg); |
| 358 | BUG_ON(!nss_ppe_verify_ifnum(ncm->interface)); |
| 359 | |
| 360 | /* |
| 361 | * Is this a valid request/response packet? |
| 362 | */ |
| 363 | if (ncm->type >= NSS_PPE_MSG_MAX) { |
| 364 | nss_warning("%p: received invalid message %d for PPE interface", nss_ctx, ncm->type); |
| 365 | return; |
| 366 | } |
| 367 | |
| 368 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ppe_msg)) { |
| 369 | nss_warning("%p: Length of message is greater than required: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
| 370 | return; |
| 371 | } |
| 372 | |
| 373 | switch (msg->cm.type) { |
| 374 | case NSS_PPE_MSG_SYNC_STATS: |
| 375 | /* |
| 376 | * session debug stats embeded in session stats msg |
| 377 | */ |
| 378 | nss_ppe_stats_sync(nss_ctx, &msg->msg.stats, ncm->interface); |
| 379 | break; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | /* |
| 384 | * nss_ppe_register_handler() |
| 385 | * debugfs stats msg handler received on static ppe interface |
| 386 | * |
| 387 | * TODO: Export API so that others can also read PPE stats. |
| 388 | */ |
| 389 | void nss_ppe_register_handler(void) |
| 390 | { |
| 391 | nss_core_register_handler(NSS_PPE_INTERFACE, nss_ppe_handler, NULL); |
| 392 | } |
| 393 | |
| 394 | /* |
| 395 | * nss_ppe_free() |
| 396 | * Uninitialize PPE base |
| 397 | */ |
| 398 | void nss_ppe_free(void) |
| 399 | { |
| 400 | /* |
| 401 | * Check if PPE base is already uninitialized. |
| 402 | */ |
| 403 | if (!ppe_pvt.ppe_base) { |
| 404 | return; |
| 405 | } |
| 406 | |
| 407 | /* |
| 408 | * Unmap PPE base address |
| 409 | */ |
| 410 | iounmap(ppe_pvt.ppe_base); |
| 411 | ppe_pvt.ppe_base = NULL; |
| 412 | |
| 413 | spin_lock_bh(&nss_ppe_stats_lock); |
| 414 | nss_ppe_debug_stats.valid = false; |
| 415 | nss_ppe_debug_stats.if_num = 0; |
| 416 | nss_ppe_debug_stats.if_index = 0; |
| 417 | spin_unlock_bh(&nss_ppe_stats_lock); |
| 418 | } |
| 419 | |
| 420 | /* |
| 421 | * nss_ppe_init() |
| 422 | * Initialize PPE base |
| 423 | */ |
| 424 | void nss_ppe_init(void) |
| 425 | { |
| 426 | /* |
| 427 | * Check if PPE base is already initialized. |
| 428 | */ |
| 429 | if (ppe_pvt.ppe_base) { |
| 430 | return; |
| 431 | } |
| 432 | |
| 433 | /* |
| 434 | * Get the PPE base address |
| 435 | */ |
| 436 | ppe_pvt.ppe_base = ioremap_nocache(PPE_BASE_ADDR, PPE_REG_SIZE); |
| 437 | if (!ppe_pvt.ppe_base) { |
| 438 | nss_warning("DRV can't get PPE base address\n"); |
| 439 | return; |
| 440 | } |
| 441 | |
| 442 | spin_lock_bh(&nss_ppe_stats_lock); |
| 443 | nss_ppe_debug_stats.valid = true; |
| 444 | nss_ppe_debug_stats.if_num = 0; |
| 445 | nss_ppe_debug_stats.if_index = 0; |
| 446 | spin_unlock_bh(&nss_ppe_stats_lock); |
| 447 | } |