162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/* Copyright(c) 1999 - 2018 Intel Corporation. */
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci#ifndef _DCB_CONFIG_H_
562306a36Sopenharmony_ci#define _DCB_CONFIG_H_
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#include <linux/dcbnl.h>
862306a36Sopenharmony_ci#include "ixgbe_type.h"
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci/* DCB data structures */
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#define IXGBE_MAX_PACKET_BUFFERS 8
1362306a36Sopenharmony_ci#define MAX_USER_PRIORITY        8
1462306a36Sopenharmony_ci#define MAX_BW_GROUP             8
1562306a36Sopenharmony_ci#define BW_PERCENT               100
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#define DCB_TX_CONFIG            0
1862306a36Sopenharmony_ci#define DCB_RX_CONFIG            1
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/* DCB error Codes */
2162306a36Sopenharmony_ci#define DCB_SUCCESS              0
2262306a36Sopenharmony_ci#define DCB_ERR_CONFIG           -1
2362306a36Sopenharmony_ci#define DCB_ERR_PARAM            -2
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci/* Transmit and receive Errors */
2662306a36Sopenharmony_ci/* Error in bandwidth group allocation */
2762306a36Sopenharmony_ci#define DCB_ERR_BW_GROUP        -3
2862306a36Sopenharmony_ci/* Error in traffic class bandwidth allocation */
2962306a36Sopenharmony_ci#define DCB_ERR_TC_BW           -4
3062306a36Sopenharmony_ci/* Traffic class has both link strict and group strict enabled */
3162306a36Sopenharmony_ci#define DCB_ERR_LS_GS           -5
3262306a36Sopenharmony_ci/* Link strict traffic class has non zero bandwidth */
3362306a36Sopenharmony_ci#define DCB_ERR_LS_BW_NONZERO   -6
3462306a36Sopenharmony_ci/* Link strict bandwidth group has non zero bandwidth */
3562306a36Sopenharmony_ci#define DCB_ERR_LS_BWG_NONZERO  -7
3662306a36Sopenharmony_ci/*  Traffic class has zero bandwidth */
3762306a36Sopenharmony_ci#define DCB_ERR_TC_BW_ZERO      -8
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci#define DCB_NOT_IMPLEMENTED      0x7FFFFFFF
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_cistruct dcb_pfc_tc_debug {
4262306a36Sopenharmony_ci	u8  tc;
4362306a36Sopenharmony_ci	u8  pause_status;
4462306a36Sopenharmony_ci	u64 pause_quanta;
4562306a36Sopenharmony_ci};
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_cienum strict_prio_type {
4862306a36Sopenharmony_ci	prio_none = 0,
4962306a36Sopenharmony_ci	prio_group,
5062306a36Sopenharmony_ci	prio_link
5162306a36Sopenharmony_ci};
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci/* DCB capability definitions */
5462306a36Sopenharmony_ci#define IXGBE_DCB_PG_SUPPORT        0x00000001
5562306a36Sopenharmony_ci#define IXGBE_DCB_PFC_SUPPORT       0x00000002
5662306a36Sopenharmony_ci#define IXGBE_DCB_BCN_SUPPORT       0x00000004
5762306a36Sopenharmony_ci#define IXGBE_DCB_UP2TC_SUPPORT     0x00000008
5862306a36Sopenharmony_ci#define IXGBE_DCB_GSP_SUPPORT       0x00000010
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci#define IXGBE_DCB_8_TC_SUPPORT      0x80
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_cistruct dcb_support {
6362306a36Sopenharmony_ci	/* DCB capabilities */
6462306a36Sopenharmony_ci	u32 capabilities;
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci	/* Each bit represents a number of TCs configurable in the hw.
6762306a36Sopenharmony_ci	 * If 8 traffic classes can be configured, the value is 0x80.
6862306a36Sopenharmony_ci	 */
6962306a36Sopenharmony_ci	u8  traffic_classes;
7062306a36Sopenharmony_ci	u8  pfc_traffic_classes;
7162306a36Sopenharmony_ci};
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci/* Traffic class bandwidth allocation per direction */
7462306a36Sopenharmony_cistruct tc_bw_alloc {
7562306a36Sopenharmony_ci	u8 bwg_id;		  /* Bandwidth Group (BWG) ID */
7662306a36Sopenharmony_ci	u8 bwg_percent;		  /* % of BWG's bandwidth */
7762306a36Sopenharmony_ci	u8 link_percent;	  /* % of link bandwidth */
7862306a36Sopenharmony_ci	u8 up_to_tc_bitmap;	  /* User Priority to Traffic Class mapping */
7962306a36Sopenharmony_ci	u16 data_credits_refill;  /* Credit refill amount in 64B granularity */
8062306a36Sopenharmony_ci	u16 data_credits_max;	  /* Max credits for a configured packet buffer
8162306a36Sopenharmony_ci				   * in 64B granularity.*/
8262306a36Sopenharmony_ci	enum strict_prio_type prio_type; /* Link or Group Strict Priority */
8362306a36Sopenharmony_ci};
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_cienum dcb_pfc_type {
8662306a36Sopenharmony_ci	pfc_disabled = 0,
8762306a36Sopenharmony_ci	pfc_enabled_full,
8862306a36Sopenharmony_ci	pfc_enabled_tx,
8962306a36Sopenharmony_ci	pfc_enabled_rx
9062306a36Sopenharmony_ci};
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci/* Traffic class configuration */
9362306a36Sopenharmony_cistruct tc_configuration {
9462306a36Sopenharmony_ci	struct tc_bw_alloc path[2]; /* One each for Tx/Rx */
9562306a36Sopenharmony_ci	enum dcb_pfc_type  dcb_pfc; /* Class based flow control setting */
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci	u16 desc_credits_max; /* For Tx Descriptor arbitration */
9862306a36Sopenharmony_ci	u8 tc; /* Traffic class (TC) */
9962306a36Sopenharmony_ci};
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_cistruct dcb_num_tcs {
10262306a36Sopenharmony_ci	u8 pg_tcs;
10362306a36Sopenharmony_ci	u8 pfc_tcs;
10462306a36Sopenharmony_ci};
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_cistruct ixgbe_dcb_config {
10762306a36Sopenharmony_ci	struct dcb_support support;
10862306a36Sopenharmony_ci	struct dcb_num_tcs num_tcs;
10962306a36Sopenharmony_ci	struct tc_configuration tc_config[MAX_TRAFFIC_CLASS];
11062306a36Sopenharmony_ci	u8     bw_percentage[2][MAX_BW_GROUP]; /* One each for Tx/Rx */
11162306a36Sopenharmony_ci	bool   pfc_mode_enable;
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci	u32  dcb_cfg_version; /* Not used...OS-specific? */
11462306a36Sopenharmony_ci	u32  link_speed; /* For bandwidth allocation validation purpose */
11562306a36Sopenharmony_ci};
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci/* DCB driver APIs */
11862306a36Sopenharmony_civoid ixgbe_dcb_unpack_pfc(struct ixgbe_dcb_config *cfg, u8 *pfc_en);
11962306a36Sopenharmony_civoid ixgbe_dcb_unpack_refill(struct ixgbe_dcb_config *, int, u16 *);
12062306a36Sopenharmony_civoid ixgbe_dcb_unpack_max(struct ixgbe_dcb_config *, u16 *);
12162306a36Sopenharmony_civoid ixgbe_dcb_unpack_bwgid(struct ixgbe_dcb_config *, int, u8 *);
12262306a36Sopenharmony_civoid ixgbe_dcb_unpack_prio(struct ixgbe_dcb_config *, int, u8 *);
12362306a36Sopenharmony_civoid ixgbe_dcb_unpack_map(struct ixgbe_dcb_config *, int, u8 *);
12462306a36Sopenharmony_ciu8 ixgbe_dcb_get_tc_from_up(struct ixgbe_dcb_config *, int, u8);
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci/* DCB credits calculation */
12762306a36Sopenharmony_cis32 ixgbe_dcb_calculate_tc_credits(struct ixgbe_hw *,
12862306a36Sopenharmony_ci				   struct ixgbe_dcb_config *, int, u8);
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci/* DCB hw initialization */
13162306a36Sopenharmony_cis32 ixgbe_dcb_hw_ets(struct ixgbe_hw *hw, struct ieee_ets *ets, int max);
13262306a36Sopenharmony_cis32 ixgbe_dcb_hw_ets_config(struct ixgbe_hw *hw, u16 *refill, u16 *max,
13362306a36Sopenharmony_ci			    u8 *bwg_id, u8 *prio_type, u8 *tc_prio);
13462306a36Sopenharmony_cis32 ixgbe_dcb_hw_pfc_config(struct ixgbe_hw *hw, u8 pfc_en, u8 *tc_prio);
13562306a36Sopenharmony_cis32 ixgbe_dcb_hw_config(struct ixgbe_hw *, struct ixgbe_dcb_config *);
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_civoid ixgbe_dcb_read_rtrup2tc(struct ixgbe_hw *hw, u8 *map);
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci/* DCB definitions for credit calculation */
14062306a36Sopenharmony_ci#define DCB_CREDIT_QUANTUM	64   /* DCB Quantum */
14162306a36Sopenharmony_ci#define MAX_CREDIT_REFILL       511  /* 0x1FF * 64B = 32704B */
14262306a36Sopenharmony_ci#define DCB_MAX_TSO_SIZE        (32*1024) /* MAX TSO packet size supported in DCB mode */
14362306a36Sopenharmony_ci#define MINIMUM_CREDIT_FOR_TSO  (DCB_MAX_TSO_SIZE/64 + 1) /* 513 for 32KB TSO packet */
14462306a36Sopenharmony_ci#define MAX_CREDIT              4095 /* Maximum credit supported: 256KB * 1204 / 64B */
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci#endif /* _DCB_CONFIG_H */
147