1b72a32daSRahul Lakkireddy /* 2b72a32daSRahul Lakkireddy * This file is part of the Chelsio T4 Ethernet driver for Linux. 3b72a32daSRahul Lakkireddy * 4b72a32daSRahul Lakkireddy * Copyright (c) 2016 Chelsio Communications, Inc. All rights reserved. 5b72a32daSRahul Lakkireddy * 6b72a32daSRahul Lakkireddy * This software is available to you under a choice of one of two 7b72a32daSRahul Lakkireddy * licenses. You may choose to be licensed under the terms of the GNU 8b72a32daSRahul Lakkireddy * General Public License (GPL) Version 2, available from the file 9b72a32daSRahul Lakkireddy * COPYING in the main directory of this source tree, or the 10b72a32daSRahul Lakkireddy * OpenIB.org BSD license below: 11b72a32daSRahul Lakkireddy * 12b72a32daSRahul Lakkireddy * Redistribution and use in source and binary forms, with or 13b72a32daSRahul Lakkireddy * without modification, are permitted provided that the following 14b72a32daSRahul Lakkireddy * conditions are met: 15b72a32daSRahul Lakkireddy * 16b72a32daSRahul Lakkireddy * - Redistributions of source code must retain the above 17b72a32daSRahul Lakkireddy * copyright notice, this list of conditions and the following 18b72a32daSRahul Lakkireddy * disclaimer. 19b72a32daSRahul Lakkireddy * 20b72a32daSRahul Lakkireddy * - Redistributions in binary form must reproduce the above 21b72a32daSRahul Lakkireddy * copyright notice, this list of conditions and the following 22b72a32daSRahul Lakkireddy * disclaimer in the documentation and/or other materials 23b72a32daSRahul Lakkireddy * provided with the distribution. 24b72a32daSRahul Lakkireddy * 25b72a32daSRahul Lakkireddy * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26b72a32daSRahul Lakkireddy * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27b72a32daSRahul Lakkireddy * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28b72a32daSRahul Lakkireddy * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29b72a32daSRahul Lakkireddy * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30b72a32daSRahul Lakkireddy * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31b72a32daSRahul Lakkireddy * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32b72a32daSRahul Lakkireddy * SOFTWARE. 33b72a32daSRahul Lakkireddy */ 34b72a32daSRahul Lakkireddy 35b72a32daSRahul Lakkireddy #ifndef __CXGB4_SCHED_H 36b72a32daSRahul Lakkireddy #define __CXGB4_SCHED_H 37b72a32daSRahul Lakkireddy 38b72a32daSRahul Lakkireddy #include <linux/spinlock.h> 39b72a32daSRahul Lakkireddy #include <linux/atomic.h> 40b72a32daSRahul Lakkireddy 41b72a32daSRahul Lakkireddy #define SCHED_CLS_NONE 0xff 42b72a32daSRahul Lakkireddy 436cede1f1SRahul Lakkireddy #define FW_SCHED_CLS_NONE 0xffffffff 446cede1f1SRahul Lakkireddy 45d185efc1SGanesh Goudar /* Max rate that can be set to a scheduling class is 100 Gbps */ 46d185efc1SGanesh Goudar #define SCHED_MAX_RATE_KBPS 100000000U 4710a2604eSRahul Lakkireddy 48b72a32daSRahul Lakkireddy enum { 49b72a32daSRahul Lakkireddy SCHED_STATE_ACTIVE, 50b72a32daSRahul Lakkireddy SCHED_STATE_UNUSED, 51b72a32daSRahul Lakkireddy }; 52b72a32daSRahul Lakkireddy 53b72a32daSRahul Lakkireddy enum sched_fw_ops { 54b72a32daSRahul Lakkireddy SCHED_FW_OP_ADD, 554ec4762dSRahul Lakkireddy SCHED_FW_OP_DEL, 56b72a32daSRahul Lakkireddy }; 57b72a32daSRahul Lakkireddy 586cede1f1SRahul Lakkireddy enum sched_bind_type { 596cede1f1SRahul Lakkireddy SCHED_QUEUE, 600e395b3cSRahul Lakkireddy SCHED_FLOWC, 616cede1f1SRahul Lakkireddy }; 626cede1f1SRahul Lakkireddy 636cede1f1SRahul Lakkireddy struct sched_queue_entry { 646cede1f1SRahul Lakkireddy struct list_head list; 656cede1f1SRahul Lakkireddy unsigned int cntxt_id; 666cede1f1SRahul Lakkireddy struct ch_sched_queue param; 676cede1f1SRahul Lakkireddy }; 686cede1f1SRahul Lakkireddy 690e395b3cSRahul Lakkireddy struct sched_flowc_entry { 700e395b3cSRahul Lakkireddy struct list_head list; 710e395b3cSRahul Lakkireddy struct ch_sched_flowc param; 720e395b3cSRahul Lakkireddy }; 730e395b3cSRahul Lakkireddy 74b72a32daSRahul Lakkireddy struct sched_class { 75b72a32daSRahul Lakkireddy u8 state; 76b72a32daSRahul Lakkireddy u8 idx; 77b72a32daSRahul Lakkireddy struct ch_sched_params info; 780e395b3cSRahul Lakkireddy enum sched_bind_type bind_type; 790e395b3cSRahul Lakkireddy struct list_head entry_list; 80b72a32daSRahul Lakkireddy atomic_t refcnt; 81b72a32daSRahul Lakkireddy }; 82b72a32daSRahul Lakkireddy 83b72a32daSRahul Lakkireddy struct sched_table { /* per port scheduling table */ 84b72a32daSRahul Lakkireddy u8 sched_size; 85*65dc2f1aSGustavo A. R. Silva struct sched_class tab[]; 86b72a32daSRahul Lakkireddy }; 87b72a32daSRahul Lakkireddy 88b72a32daSRahul Lakkireddy static inline bool can_sched(struct net_device *dev) 89b72a32daSRahul Lakkireddy { 90b72a32daSRahul Lakkireddy struct port_info *pi = netdev2pinfo(dev); 91b72a32daSRahul Lakkireddy 92b72a32daSRahul Lakkireddy return !pi->sched_tbl ? false : true; 93b72a32daSRahul Lakkireddy } 94b72a32daSRahul Lakkireddy 95b72a32daSRahul Lakkireddy static inline bool valid_class_id(struct net_device *dev, u8 class_id) 96b72a32daSRahul Lakkireddy { 97b72a32daSRahul Lakkireddy struct port_info *pi = netdev2pinfo(dev); 98b72a32daSRahul Lakkireddy 99b72a32daSRahul Lakkireddy if ((class_id > pi->sched_tbl->sched_size - 1) && 100b72a32daSRahul Lakkireddy (class_id != SCHED_CLS_NONE)) 101b72a32daSRahul Lakkireddy return false; 102b72a32daSRahul Lakkireddy 103b72a32daSRahul Lakkireddy return true; 104b72a32daSRahul Lakkireddy } 105b72a32daSRahul Lakkireddy 106c856e2b6SRahul Lakkireddy struct sched_class *cxgb4_sched_queue_lookup(struct net_device *dev, 107c856e2b6SRahul Lakkireddy struct ch_sched_queue *p); 1086cede1f1SRahul Lakkireddy int cxgb4_sched_class_bind(struct net_device *dev, void *arg, 1096cede1f1SRahul Lakkireddy enum sched_bind_type type); 1106cede1f1SRahul Lakkireddy int cxgb4_sched_class_unbind(struct net_device *dev, void *arg, 1116cede1f1SRahul Lakkireddy enum sched_bind_type type); 1126cede1f1SRahul Lakkireddy 113b72a32daSRahul Lakkireddy struct sched_class *cxgb4_sched_class_alloc(struct net_device *dev, 114b72a32daSRahul Lakkireddy struct ch_sched_params *p); 1150e395b3cSRahul Lakkireddy void cxgb4_sched_class_free(struct net_device *dev, u8 classid); 116b72a32daSRahul Lakkireddy 117b72a32daSRahul Lakkireddy struct sched_table *t4_init_sched(unsigned int size); 118b72a32daSRahul Lakkireddy void t4_cleanup_sched(struct adapter *adap); 119b72a32daSRahul Lakkireddy #endif /* __CXGB4_SCHED_H */ 120