Tushar Mathur | 6650654 | 2014-04-03 22:01:40 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved. |
Tushar Mathur | 6650654 | 2014-04-03 22:01:40 +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 | /* |
| 18 | * nss_tx_rx_lag.c |
| 19 | * NSS LAG Tx APIs |
| 20 | */ |
| 21 | |
| 22 | #include <linux/if_bonding.h> |
| 23 | |
| 24 | #include "nss_tx_rx_common.h" |
| 25 | |
| 26 | /* |
| 27 | * nss_lag_tx() |
Sol Kavy | cd1bd5c | 2014-04-04 11:09:44 -0700 | [diff] [blame] | 28 | * Transmit a LAG msg to the firmware. |
Tushar Mathur | 6650654 | 2014-04-03 22:01:40 +0530 | [diff] [blame] | 29 | */ |
| 30 | nss_tx_status_t nss_lag_tx(struct nss_ctx_instance *nss_ctx, struct nss_lag_msg *msg) |
| 31 | { |
| 32 | struct sk_buff *nbuf; |
| 33 | int32_t status; |
| 34 | struct nss_lag_msg *nm; |
| 35 | |
| 36 | nss_info("%p: NSS LAG Tx\n", nss_ctx); |
| 37 | |
| 38 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 39 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
Sol Kavy | cd1bd5c | 2014-04-04 11:09:44 -0700 | [diff] [blame] | 40 | nss_warning("%p: LAG msg dropped as core not ready", nss_ctx); |
Tushar Mathur | 6650654 | 2014-04-03 22:01:40 +0530 | [diff] [blame] | 41 | return NSS_TX_FAILURE_NOT_READY; |
| 42 | } |
| 43 | |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 44 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
Tushar Mathur | 6650654 | 2014-04-03 22:01:40 +0530 | [diff] [blame] | 45 | if (unlikely(!nbuf)) { |
Sundarajan Srinivasan | 62fee7e | 2015-01-22 11:13:10 -0800 | [diff] [blame] | 46 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]); |
Sol Kavy | cd1bd5c | 2014-04-04 11:09:44 -0700 | [diff] [blame] | 47 | nss_warning("%p: LAG msg dropped as command allocation failed", nss_ctx); |
Tushar Mathur | 6650654 | 2014-04-03 22:01:40 +0530 | [diff] [blame] | 48 | return NSS_TX_FAILURE; |
| 49 | } |
| 50 | |
| 51 | nm = (struct nss_lag_msg *)skb_put(nbuf, sizeof(struct nss_lag_msg)); |
| 52 | memcpy(nm, msg, sizeof(struct nss_lag_msg)); |
| 53 | |
| 54 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 55 | if (status != NSS_CORE_STATUS_SUCCESS) { |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 56 | dev_kfree_skb_any(nbuf); |
Sol Kavy | cd1bd5c | 2014-04-04 11:09:44 -0700 | [diff] [blame] | 57 | nss_warning("%p: Unable to enqueue LAG msg\n", nss_ctx); |
| 58 | return NSS_TX_FAILURE; |
Tushar Mathur | 6650654 | 2014-04-03 22:01:40 +0530 | [diff] [blame] | 59 | } |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 60 | nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE); |
Tushar Mathur | 6650654 | 2014-04-03 22:01:40 +0530 | [diff] [blame] | 61 | |
| 62 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 63 | return NSS_TX_SUCCESS; |
| 64 | } |
| 65 | EXPORT_SYMBOL(nss_lag_tx); |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * nss_register_lag_if() |
| 69 | */ |
Gareth Williams | b52af51 | 2014-04-25 19:31:15 +0100 | [diff] [blame] | 70 | void *nss_register_lag_if(uint32_t if_num, |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 71 | nss_lag_callback_t lag_cb, |
| 72 | nss_lag_event_callback_t lag_ev_cb, |
| 73 | struct net_device *netdev) |
| 74 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 75 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.ipv4_handler_id]; |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 76 | uint32_t features = 0; |
| 77 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 78 | nss_assert(nss_ctx); |
Suman Ghosh | cf8ed1c | 2015-09-07 18:57:04 +0530 | [diff] [blame] | 79 | nss_assert((if_num == NSS_LAG0_INTERFACE_NUM) || (if_num == NSS_LAG1_INTERFACE_NUM) || |
| 80 | (if_num == NSS_LAG2_INTERFACE_NUM) || (if_num == NSS_LAG3_INTERFACE_NUM)); |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 81 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 82 | nss_ctx->subsys_dp_register[if_num].ndev = netdev; |
| 83 | nss_ctx->subsys_dp_register[if_num].cb = lag_cb; |
| 84 | nss_ctx->subsys_dp_register[if_num].app_data = NULL; |
| 85 | nss_ctx->subsys_dp_register[if_num].features = features; |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 86 | |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 87 | nss_top_main.lag_event_callback = lag_ev_cb; |
Gareth Williams | b52af51 | 2014-04-25 19:31:15 +0100 | [diff] [blame] | 88 | |
| 89 | /* |
| 90 | * Return the NSS driver context for LAG (same as for ipv4 functions) |
| 91 | */ |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 92 | return (void *)nss_ctx; |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 93 | } |
| 94 | EXPORT_SYMBOL(nss_register_lag_if); |
| 95 | |
| 96 | |
| 97 | /** |
| 98 | * nss_unregister_lag_if() |
| 99 | */ |
| 100 | void nss_unregister_lag_if(uint32_t if_num) |
| 101 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 102 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.ipv4_handler_id]; |
| 103 | |
| 104 | nss_assert(nss_ctx); |
Suman Ghosh | cf8ed1c | 2015-09-07 18:57:04 +0530 | [diff] [blame] | 105 | nss_assert((if_num == NSS_LAG0_INTERFACE_NUM) || (if_num == NSS_LAG1_INTERFACE_NUM) || |
| 106 | (if_num == NSS_LAG2_INTERFACE_NUM) || (if_num == NSS_LAG3_INTERFACE_NUM)); |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 107 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 108 | nss_ctx->subsys_dp_register[if_num].cb = NULL; |
| 109 | nss_ctx->subsys_dp_register[if_num].ndev = NULL; |
| 110 | nss_ctx->subsys_dp_register[if_num].app_data = NULL; |
| 111 | nss_ctx->subsys_dp_register[if_num].features = 0; |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 112 | |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 113 | nss_top_main.lag_event_callback = NULL; |
| 114 | } |
| 115 | EXPORT_SYMBOL(nss_unregister_lag_if); |
| 116 | |
| 117 | |
| 118 | /** |
| 119 | * nss_lag_handler() |
| 120 | */ |
| 121 | void nss_lag_handler(struct nss_ctx_instance *nss_ctx, |
| 122 | struct nss_cmn_msg *ncm, |
| 123 | void *app_data) |
| 124 | { |
| 125 | struct nss_lag_msg *lm = (struct nss_lag_msg *)ncm; |
| 126 | void *ctx = NULL; |
| 127 | nss_lag_event_callback_t cb; |
| 128 | |
| 129 | BUG_ON(ncm->interface != NSS_LAG0_INTERFACE_NUM |
Suman Ghosh | cf8ed1c | 2015-09-07 18:57:04 +0530 | [diff] [blame] | 130 | && ncm->interface != NSS_LAG1_INTERFACE_NUM |
| 131 | && ncm->interface != NSS_LAG2_INTERFACE_NUM |
| 132 | && ncm->interface != NSS_LAG3_INTERFACE_NUM); |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 133 | |
| 134 | if (ncm->type >= NSS_TX_METADATA_LAG_MAX) { |
| 135 | nss_warning("%p: received invalid message %d for LAG interface", nss_ctx, ncm->type); |
| 136 | return; |
| 137 | } |
| 138 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 139 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_lag_msg)) { |
| 140 | nss_warning("%p: invalid length for LAG message: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 141 | return; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Update the callback and app_data for NOTIFY messages. |
| 146 | * LAG sends all notify messages to the same callback. |
| 147 | */ |
| 148 | if (ncm->response == NSS_CMM_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 149 | ncm->cb = (nss_ptr_t)nss_ctx->nss_top->lag_event_callback; |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Log failures |
| 154 | */ |
| 155 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 156 | |
| 157 | /** |
| 158 | * Do we have a call back |
| 159 | */ |
| 160 | if (!ncm->cb) { |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * callback |
| 166 | */ |
| 167 | cb = (nss_lag_event_callback_t)ncm->cb; |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 168 | ctx = nss_ctx->subsys_dp_register[ncm->interface].ndev; |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 169 | |
| 170 | cb(ctx, lm); |
| 171 | } |
| 172 | |
| 173 | |
| 174 | /** |
| 175 | * nss_lag_register_handler() |
| 176 | */ |
| 177 | void nss_lag_register_handler(void) |
| 178 | { |
| 179 | nss_core_register_handler(NSS_LAG0_INTERFACE_NUM, nss_lag_handler, NULL); |
| 180 | nss_core_register_handler(NSS_LAG1_INTERFACE_NUM, nss_lag_handler, NULL); |
Suman Ghosh | cf8ed1c | 2015-09-07 18:57:04 +0530 | [diff] [blame] | 181 | nss_core_register_handler(NSS_LAG2_INTERFACE_NUM, nss_lag_handler, NULL); |
| 182 | nss_core_register_handler(NSS_LAG3_INTERFACE_NUM, nss_lag_handler, NULL); |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 183 | } |
| 184 | |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 185 | /** |
| 186 | * nss_lag_msg_init() |
| 187 | * Initialize lag message |
| 188 | */ |
| 189 | void nss_lag_msg_init(struct nss_lag_msg *nlm, uint16_t lag_num, uint32_t type, uint32_t len, |
Sundarajan Srinivasan | 30a53d4 | 2015-01-30 10:52:08 -0800 | [diff] [blame] | 190 | nss_lag_callback_t cb, void *app_data) |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 191 | { |
| 192 | nss_cmn_msg_init(&nlm->cm, lag_num, type, len, (void *)cb, app_data); |
| 193 | } |
| 194 | EXPORT_SYMBOL(nss_lag_msg_init); |