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 #ifndef __NFP_ABM_H__ 36 #define __NFP_ABM_H__ 1 37 38 #include <net/devlink.h> 39 40 struct nfp_app; 41 struct nfp_net; 42 43 #define NFP_ABM_PORTID_TYPE GENMASK(23, 16) 44 #define NFP_ABM_PORTID_ID GENMASK(7, 0) 45 46 /** 47 * struct nfp_abm - ABM NIC app structure 48 * @app: back pointer to nfp_app 49 * @pf_id: ID of our PF link 50 * @eswitch_mode: devlink eswitch mode, advanced functions only visible 51 * in switchdev mode 52 * @q_lvls: queue level control area 53 * @qm_stats: queue statistics symbol 54 */ 55 struct nfp_abm { 56 struct nfp_app *app; 57 unsigned int pf_id; 58 enum devlink_eswitch_mode eswitch_mode; 59 const struct nfp_rtsym *q_lvls; 60 const struct nfp_rtsym *qm_stats; 61 }; 62 63 /** 64 * struct nfp_alink_stats - ABM NIC statistics 65 * @tx_pkts: number of TXed packets 66 * @tx_bytes: number of TXed bytes 67 * @backlog_pkts: momentary backlog length (packets) 68 * @backlog_bytes: momentary backlog length (bytes) 69 * @overlimits: number of ECN marked TXed packets (accumulative) 70 * @drops: number of tail-dropped packets (accumulative) 71 */ 72 struct nfp_alink_stats { 73 u64 tx_pkts; 74 u64 tx_bytes; 75 u64 backlog_pkts; 76 u64 backlog_bytes; 77 u64 overlimits; 78 u64 drops; 79 }; 80 81 /** 82 * struct nfp_alink_xstats - extended ABM NIC statistics 83 * @ecn_marked: number of ECN marked TXed packets 84 * @pdrop: number of hard drops due to queue limit 85 */ 86 struct nfp_alink_xstats { 87 u64 ecn_marked; 88 u64 pdrop; 89 }; 90 91 /** 92 * struct nfp_red_qdisc - representation of single RED Qdisc 93 * @handle: handle of currently offloaded RED Qdisc 94 * @stats: statistics from last refresh 95 * @xstats: base of extended statistics 96 */ 97 struct nfp_red_qdisc { 98 u32 handle; 99 struct nfp_alink_stats stats; 100 struct nfp_alink_xstats xstats; 101 }; 102 103 /** 104 * struct nfp_abm_link - port tuple of a ABM NIC 105 * @abm: back pointer to nfp_abm 106 * @vnic: data vNIC 107 * @id: id of the data vNIC 108 * @queue_base: id of base to host queue within PCIe (not QC idx) 109 * @total_queues: number of PF queues 110 * @parent: handle of expected parent, i.e. handle of MQ, or TC_H_ROOT 111 * @num_qdiscs: number of currently used qdiscs 112 * @qdiscs: array of qdiscs 113 */ 114 struct nfp_abm_link { 115 struct nfp_abm *abm; 116 struct nfp_net *vnic; 117 unsigned int id; 118 unsigned int queue_base; 119 unsigned int total_queues; 120 u32 parent; 121 unsigned int num_qdiscs; 122 struct nfp_red_qdisc *qdiscs; 123 }; 124 125 void nfp_abm_ctrl_read_params(struct nfp_abm_link *alink); 126 int nfp_abm_ctrl_find_addrs(struct nfp_abm *abm); 127 int nfp_abm_ctrl_set_all_q_lvls(struct nfp_abm_link *alink, u32 val); 128 int nfp_abm_ctrl_set_q_lvl(struct nfp_abm_link *alink, unsigned int i, 129 u32 val); 130 int nfp_abm_ctrl_read_stats(struct nfp_abm_link *alink, 131 struct nfp_alink_stats *stats); 132 int nfp_abm_ctrl_read_q_stats(struct nfp_abm_link *alink, unsigned int i, 133 struct nfp_alink_stats *stats); 134 int nfp_abm_ctrl_read_xstats(struct nfp_abm_link *alink, 135 struct nfp_alink_xstats *xstats); 136 int nfp_abm_ctrl_read_q_xstats(struct nfp_abm_link *alink, unsigned int i, 137 struct nfp_alink_xstats *xstats); 138 u64 nfp_abm_ctrl_stat_non_sto(struct nfp_abm_link *alink, unsigned int i); 139 u64 nfp_abm_ctrl_stat_sto(struct nfp_abm_link *alink, unsigned int i); 140 int nfp_abm_ctrl_qm_enable(struct nfp_abm *abm); 141 int nfp_abm_ctrl_qm_disable(struct nfp_abm *abm); 142 #endif 143