1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 /* 3 * Copyright (C) 2018 Netronome Systems, Inc. 4 * 5 * This software is dual licensed under the GNU General License Version 2, 6 * June 1991 as shown in the file COPYING in the top-level directory of this 7 * source tree or the BSD 2-Clause License provided below. You have the 8 * option to license this software under the complete terms of either license. 9 * 10 * The BSD 2-Clause License: 11 * 12 * Redistribution and use in source and binary forms, with or 13 * without modification, are permitted provided that the following 14 * conditions are met: 15 * 16 * 1. Redistributions of source code must retain the above 17 * copyright notice, this list of conditions and the following 18 * disclaimer. 19 * 20 * 2. Redistributions in binary form must reproduce the above 21 * copyright notice, this list of conditions and the following 22 * disclaimer in the documentation and/or other materials 23 * provided with the distribution. 24 * 25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 * SOFTWARE. 33 */ 34 35 #include "../nfpcore/nfp_cpp.h" 36 #include "../nfpcore/nfp_nsp.h" 37 #include "../nfp_app.h" 38 #include "../nfp_main.h" 39 #include "main.h" 40 41 static int nfp_abm_init(struct nfp_app *app) 42 { 43 struct nfp_pf *pf = app->pf; 44 struct nfp_abm *abm; 45 46 if (!pf->eth_tbl) { 47 nfp_err(pf->cpp, "ABM NIC requires ETH table\n"); 48 return -EINVAL; 49 } 50 if (pf->max_data_vnics != pf->eth_tbl->count) { 51 nfp_err(pf->cpp, "ETH entries don't match vNICs (%d vs %d)\n", 52 pf->max_data_vnics, pf->eth_tbl->count); 53 return -EINVAL; 54 } 55 if (!pf->mac_stats_bar) { 56 nfp_warn(app->cpp, "ABM NIC requires mac_stats symbol\n"); 57 return -EINVAL; 58 } 59 60 abm = kzalloc(sizeof(*abm), GFP_KERNEL); 61 if (!abm) 62 return -ENOMEM; 63 app->priv = abm; 64 abm->app = app; 65 66 return 0; 67 } 68 69 static void nfp_abm_clean(struct nfp_app *app) 70 { 71 struct nfp_abm *abm = app->priv; 72 73 kfree(abm); 74 app->priv = NULL; 75 } 76 77 const struct nfp_app_type app_abm = { 78 .id = NFP_APP_ACTIVE_BUFFER_MGMT_NIC, 79 .name = "abm", 80 81 .init = nfp_abm_init, 82 .clean = nfp_abm_clean, 83 84 .vnic_alloc = nfp_app_nic_vnic_alloc, 85 }; 86