Tushar Mathur | 6650654 | 2014-04-03 22:01:40 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
| 3 | * Copyright (c) 2014, 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_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 | |
| 44 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
| 45 | if (unlikely(!nbuf)) { |
| 46 | spin_lock_bh(&nss_ctx->nss_top->stats_lock); |
| 47 | nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++; |
| 48 | spin_unlock_bh(&nss_ctx->nss_top->stats_lock); |
Sol Kavy | cd1bd5c | 2014-04-04 11:09:44 -0700 | [diff] [blame] | 49 | nss_warning("%p: LAG msg dropped as command allocation failed", nss_ctx); |
Tushar Mathur | 6650654 | 2014-04-03 22:01:40 +0530 | [diff] [blame] | 50 | return NSS_TX_FAILURE; |
| 51 | } |
| 52 | |
| 53 | nm = (struct nss_lag_msg *)skb_put(nbuf, sizeof(struct nss_lag_msg)); |
| 54 | memcpy(nm, msg, sizeof(struct nss_lag_msg)); |
| 55 | |
| 56 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 57 | if (status != NSS_CORE_STATUS_SUCCESS) { |
| 58 | dev_kfree_skb_any(nbuf); |
Sol Kavy | cd1bd5c | 2014-04-04 11:09:44 -0700 | [diff] [blame] | 59 | nss_warning("%p: Unable to enqueue LAG msg\n", nss_ctx); |
| 60 | return NSS_TX_FAILURE; |
Tushar Mathur | 6650654 | 2014-04-03 22:01:40 +0530 | [diff] [blame] | 61 | } |
| 62 | nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit, |
| 63 | NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE); |
| 64 | |
| 65 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 66 | return NSS_TX_SUCCESS; |
| 67 | } |
| 68 | EXPORT_SYMBOL(nss_lag_tx); |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * nss_register_lag_if() |
| 72 | */ |
Gareth Williams | b52af51 | 2014-04-25 19:31:15 +0100 | [diff] [blame] | 73 | void *nss_register_lag_if(uint32_t if_num, |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 74 | nss_lag_callback_t lag_cb, |
| 75 | nss_lag_event_callback_t lag_ev_cb, |
| 76 | struct net_device *netdev) |
| 77 | { |
Murat Sezgin | 6bde581 | 2014-04-09 13:58:29 -0700 | [diff] [blame] | 78 | nss_assert((if_num == NSS_LAG0_INTERFACE_NUM) || (if_num == NSS_LAG1_INTERFACE_NUM)); |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 79 | |
| 80 | nss_top_main.if_ctx[if_num] = netdev; |
| 81 | nss_top_main.if_rx_callback[if_num] = lag_cb; |
| 82 | nss_top_main.lag_event_callback = lag_ev_cb; |
Gareth Williams | b52af51 | 2014-04-25 19:31:15 +0100 | [diff] [blame] | 83 | |
| 84 | /* |
| 85 | * Return the NSS driver context for LAG (same as for ipv4 functions) |
| 86 | */ |
| 87 | return (void *)&nss_top_main.nss[nss_top_main.ipv4_handler_id]; |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 88 | } |
| 89 | EXPORT_SYMBOL(nss_register_lag_if); |
| 90 | |
| 91 | |
| 92 | /** |
| 93 | * nss_unregister_lag_if() |
| 94 | */ |
| 95 | void nss_unregister_lag_if(uint32_t if_num) |
| 96 | { |
Sakthi Vignesh Radhakrishnan | d98ae98 | 2014-04-08 17:35:21 -0700 | [diff] [blame] | 97 | nss_assert((if_num == NSS_LAG0_INTERFACE_NUM) || (if_num == NSS_LAG1_INTERFACE_NUM)); |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 98 | |
| 99 | nss_top_main.if_rx_callback[if_num] = NULL; |
| 100 | nss_top_main.if_ctx[if_num] = NULL; |
| 101 | nss_top_main.lag_event_callback = NULL; |
| 102 | } |
| 103 | EXPORT_SYMBOL(nss_unregister_lag_if); |
| 104 | |
| 105 | |
| 106 | /** |
| 107 | * nss_lag_handler() |
| 108 | */ |
| 109 | void nss_lag_handler(struct nss_ctx_instance *nss_ctx, |
| 110 | struct nss_cmn_msg *ncm, |
| 111 | void *app_data) |
| 112 | { |
| 113 | struct nss_lag_msg *lm = (struct nss_lag_msg *)ncm; |
| 114 | void *ctx = NULL; |
| 115 | nss_lag_event_callback_t cb; |
| 116 | |
| 117 | BUG_ON(ncm->interface != NSS_LAG0_INTERFACE_NUM |
| 118 | && ncm->interface != NSS_LAG1_INTERFACE_NUM); |
| 119 | |
| 120 | if (ncm->type >= NSS_TX_METADATA_LAG_MAX) { |
| 121 | nss_warning("%p: received invalid message %d for LAG interface", nss_ctx, ncm->type); |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | if (ncm->len > sizeof(struct nss_lag_msg)) { |
| 126 | nss_warning("%p: invalid length for LAG message: %d", nss_ctx, ncm->len); |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Update the callback and app_data for NOTIFY messages. |
| 132 | * LAG sends all notify messages to the same callback. |
| 133 | */ |
| 134 | if (ncm->response == NSS_CMM_RESPONSE_NOTIFY) { |
| 135 | ncm->cb = (uint32_t)nss_ctx->nss_top->lag_event_callback; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Log failures |
| 140 | */ |
| 141 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 142 | |
| 143 | /** |
| 144 | * Do we have a call back |
| 145 | */ |
| 146 | if (!ncm->cb) { |
| 147 | return; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * callback |
| 152 | */ |
| 153 | cb = (nss_lag_event_callback_t)ncm->cb; |
| 154 | ctx = nss_ctx->nss_top->if_ctx[ncm->interface]; |
| 155 | |
| 156 | cb(ctx, lm); |
| 157 | } |
| 158 | |
| 159 | |
| 160 | /** |
| 161 | * nss_lag_register_handler() |
| 162 | */ |
| 163 | void nss_lag_register_handler(void) |
| 164 | { |
| 165 | nss_core_register_handler(NSS_LAG0_INTERFACE_NUM, nss_lag_handler, NULL); |
| 166 | nss_core_register_handler(NSS_LAG1_INTERFACE_NUM, nss_lag_handler, NULL); |
| 167 | } |
| 168 | |