18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * This file is part of the Chelsio T4 Ethernet driver for Linux. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (c) 2016 Chelsio Communications, Inc. All rights reserved. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two 78c2ecf20Sopenharmony_ci * licenses. You may choose to be licensed under the terms of the GNU 88c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file 98c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the 108c2ecf20Sopenharmony_ci * OpenIB.org BSD license below: 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or 138c2ecf20Sopenharmony_ci * without modification, are permitted provided that the following 148c2ecf20Sopenharmony_ci * conditions are met: 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * - Redistributions of source code must retain the above 178c2ecf20Sopenharmony_ci * copyright notice, this list of conditions and the following 188c2ecf20Sopenharmony_ci * disclaimer. 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * - Redistributions in binary form must reproduce the above 218c2ecf20Sopenharmony_ci * copyright notice, this list of conditions and the following 228c2ecf20Sopenharmony_ci * disclaimer in the documentation and/or other materials 238c2ecf20Sopenharmony_ci * provided with the distribution. 248c2ecf20Sopenharmony_ci * 258c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 268c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 278c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 288c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 298c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 308c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 318c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 328c2ecf20Sopenharmony_ci * SOFTWARE. 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#ifndef __CXGB4_SCHED_H 368c2ecf20Sopenharmony_ci#define __CXGB4_SCHED_H 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 398c2ecf20Sopenharmony_ci#include <linux/atomic.h> 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define SCHED_CLS_NONE 0xff 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define FW_SCHED_CLS_NONE 0xffffffff 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci/* Max rate that can be set to a scheduling class is 100 Gbps */ 468c2ecf20Sopenharmony_ci#define SCHED_MAX_RATE_KBPS 100000000U 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_cienum { 498c2ecf20Sopenharmony_ci SCHED_STATE_ACTIVE, 508c2ecf20Sopenharmony_ci SCHED_STATE_UNUSED, 518c2ecf20Sopenharmony_ci}; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_cienum sched_fw_ops { 548c2ecf20Sopenharmony_ci SCHED_FW_OP_ADD, 558c2ecf20Sopenharmony_ci SCHED_FW_OP_DEL, 568c2ecf20Sopenharmony_ci}; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cienum sched_bind_type { 598c2ecf20Sopenharmony_ci SCHED_QUEUE, 608c2ecf20Sopenharmony_ci SCHED_FLOWC, 618c2ecf20Sopenharmony_ci}; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cistruct sched_queue_entry { 648c2ecf20Sopenharmony_ci struct list_head list; 658c2ecf20Sopenharmony_ci unsigned int cntxt_id; 668c2ecf20Sopenharmony_ci struct ch_sched_queue param; 678c2ecf20Sopenharmony_ci}; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistruct sched_flowc_entry { 708c2ecf20Sopenharmony_ci struct list_head list; 718c2ecf20Sopenharmony_ci struct ch_sched_flowc param; 728c2ecf20Sopenharmony_ci}; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistruct sched_class { 758c2ecf20Sopenharmony_ci u8 state; 768c2ecf20Sopenharmony_ci u8 idx; 778c2ecf20Sopenharmony_ci struct ch_sched_params info; 788c2ecf20Sopenharmony_ci enum sched_bind_type bind_type; 798c2ecf20Sopenharmony_ci struct list_head entry_list; 808c2ecf20Sopenharmony_ci atomic_t refcnt; 818c2ecf20Sopenharmony_ci}; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistruct sched_table { /* per port scheduling table */ 848c2ecf20Sopenharmony_ci u8 sched_size; 858c2ecf20Sopenharmony_ci struct sched_class tab[]; 868c2ecf20Sopenharmony_ci}; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_cistatic inline bool can_sched(struct net_device *dev) 898c2ecf20Sopenharmony_ci{ 908c2ecf20Sopenharmony_ci struct port_info *pi = netdev2pinfo(dev); 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci return !pi->sched_tbl ? false : true; 938c2ecf20Sopenharmony_ci} 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_cistatic inline bool valid_class_id(struct net_device *dev, u8 class_id) 968c2ecf20Sopenharmony_ci{ 978c2ecf20Sopenharmony_ci struct port_info *pi = netdev2pinfo(dev); 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci if ((class_id > pi->sched_tbl->sched_size - 1) && 1008c2ecf20Sopenharmony_ci (class_id != SCHED_CLS_NONE)) 1018c2ecf20Sopenharmony_ci return false; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci return true; 1048c2ecf20Sopenharmony_ci} 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_cistruct sched_class *cxgb4_sched_queue_lookup(struct net_device *dev, 1078c2ecf20Sopenharmony_ci struct ch_sched_queue *p); 1088c2ecf20Sopenharmony_ciint cxgb4_sched_class_bind(struct net_device *dev, void *arg, 1098c2ecf20Sopenharmony_ci enum sched_bind_type type); 1108c2ecf20Sopenharmony_ciint cxgb4_sched_class_unbind(struct net_device *dev, void *arg, 1118c2ecf20Sopenharmony_ci enum sched_bind_type type); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistruct sched_class *cxgb4_sched_class_alloc(struct net_device *dev, 1148c2ecf20Sopenharmony_ci struct ch_sched_params *p); 1158c2ecf20Sopenharmony_civoid cxgb4_sched_class_free(struct net_device *dev, u8 classid); 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_cistruct sched_table *t4_init_sched(unsigned int size); 1188c2ecf20Sopenharmony_civoid t4_cleanup_sched(struct adapter *adap); 1198c2ecf20Sopenharmony_ci#endif /* __CXGB4_SCHED_H */ 120