162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * This file is part of the Chelsio T4 Ethernet driver for Linux. 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright (c) 2016 Chelsio Communications, Inc. All rights reserved. 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * This software is available to you under a choice of one of two 762306a36Sopenharmony_ci * licenses. You may choose to be licensed under the terms of the GNU 862306a36Sopenharmony_ci * General Public License (GPL) Version 2, available from the file 962306a36Sopenharmony_ci * COPYING in the main directory of this source tree, or the 1062306a36Sopenharmony_ci * OpenIB.org BSD license below: 1162306a36Sopenharmony_ci * 1262306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or 1362306a36Sopenharmony_ci * without modification, are permitted provided that the following 1462306a36Sopenharmony_ci * conditions are met: 1562306a36Sopenharmony_ci * 1662306a36Sopenharmony_ci * - Redistributions of source code must retain the above 1762306a36Sopenharmony_ci * copyright notice, this list of conditions and the following 1862306a36Sopenharmony_ci * disclaimer. 1962306a36Sopenharmony_ci * 2062306a36Sopenharmony_ci * - Redistributions in binary form must reproduce the above 2162306a36Sopenharmony_ci * copyright notice, this list of conditions and the following 2262306a36Sopenharmony_ci * disclaimer in the documentation and/or other materials 2362306a36Sopenharmony_ci * provided with the distribution. 2462306a36Sopenharmony_ci * 2562306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 2662306a36Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 2762306a36Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 2862306a36Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 2962306a36Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 3062306a36Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 3162306a36Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 3262306a36Sopenharmony_ci * SOFTWARE. 3362306a36Sopenharmony_ci */ 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#ifndef __CXGB4_SCHED_H 3662306a36Sopenharmony_ci#define __CXGB4_SCHED_H 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#include <linux/spinlock.h> 3962306a36Sopenharmony_ci#include <linux/atomic.h> 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci#define SCHED_CLS_NONE 0xff 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#define FW_SCHED_CLS_NONE 0xffffffff 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci/* Max rate that can be set to a scheduling class is 100 Gbps */ 4662306a36Sopenharmony_ci#define SCHED_MAX_RATE_KBPS 100000000U 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_cienum { 4962306a36Sopenharmony_ci SCHED_STATE_ACTIVE, 5062306a36Sopenharmony_ci SCHED_STATE_UNUSED, 5162306a36Sopenharmony_ci}; 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_cienum sched_fw_ops { 5462306a36Sopenharmony_ci SCHED_FW_OP_ADD, 5562306a36Sopenharmony_ci SCHED_FW_OP_DEL, 5662306a36Sopenharmony_ci}; 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_cienum sched_bind_type { 5962306a36Sopenharmony_ci SCHED_QUEUE, 6062306a36Sopenharmony_ci SCHED_FLOWC, 6162306a36Sopenharmony_ci}; 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_cistruct sched_queue_entry { 6462306a36Sopenharmony_ci struct list_head list; 6562306a36Sopenharmony_ci unsigned int cntxt_id; 6662306a36Sopenharmony_ci struct ch_sched_queue param; 6762306a36Sopenharmony_ci}; 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_cistruct sched_flowc_entry { 7062306a36Sopenharmony_ci struct list_head list; 7162306a36Sopenharmony_ci struct ch_sched_flowc param; 7262306a36Sopenharmony_ci}; 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_cistruct sched_class { 7562306a36Sopenharmony_ci u8 state; 7662306a36Sopenharmony_ci u8 idx; 7762306a36Sopenharmony_ci struct ch_sched_params info; 7862306a36Sopenharmony_ci enum sched_bind_type bind_type; 7962306a36Sopenharmony_ci struct list_head entry_list; 8062306a36Sopenharmony_ci atomic_t refcnt; 8162306a36Sopenharmony_ci}; 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_cistruct sched_table { /* per port scheduling table */ 8462306a36Sopenharmony_ci u8 sched_size; 8562306a36Sopenharmony_ci struct sched_class tab[]; 8662306a36Sopenharmony_ci}; 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_cistatic inline bool can_sched(struct net_device *dev) 8962306a36Sopenharmony_ci{ 9062306a36Sopenharmony_ci struct port_info *pi = netdev2pinfo(dev); 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci return !pi->sched_tbl ? false : true; 9362306a36Sopenharmony_ci} 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_cistatic inline bool valid_class_id(struct net_device *dev, u8 class_id) 9662306a36Sopenharmony_ci{ 9762306a36Sopenharmony_ci struct port_info *pi = netdev2pinfo(dev); 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci if ((class_id > pi->sched_tbl->sched_size - 1) && 10062306a36Sopenharmony_ci (class_id != SCHED_CLS_NONE)) 10162306a36Sopenharmony_ci return false; 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci return true; 10462306a36Sopenharmony_ci} 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_cistruct sched_class *cxgb4_sched_queue_lookup(struct net_device *dev, 10762306a36Sopenharmony_ci struct ch_sched_queue *p); 10862306a36Sopenharmony_ciint cxgb4_sched_class_bind(struct net_device *dev, void *arg, 10962306a36Sopenharmony_ci enum sched_bind_type type); 11062306a36Sopenharmony_ciint cxgb4_sched_class_unbind(struct net_device *dev, void *arg, 11162306a36Sopenharmony_ci enum sched_bind_type type); 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_cistruct sched_class *cxgb4_sched_class_alloc(struct net_device *dev, 11462306a36Sopenharmony_ci struct ch_sched_params *p); 11562306a36Sopenharmony_civoid cxgb4_sched_class_free(struct net_device *dev, u8 classid); 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_cistruct sched_table *t4_init_sched(unsigned int size); 11862306a36Sopenharmony_civoid t4_cleanup_sched(struct adapter *adap); 11962306a36Sopenharmony_ci#endif /* __CXGB4_SCHED_H */ 120