18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/* Copyright(c) 1999 - 2018 Intel Corporation. */
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#ifndef _DCB_CONFIG_H_
58c2ecf20Sopenharmony_ci#define _DCB_CONFIG_H_
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/dcbnl.h>
88c2ecf20Sopenharmony_ci#include "ixgbe_type.h"
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/* DCB data structures */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#define IXGBE_MAX_PACKET_BUFFERS 8
138c2ecf20Sopenharmony_ci#define MAX_USER_PRIORITY        8
148c2ecf20Sopenharmony_ci#define MAX_BW_GROUP             8
158c2ecf20Sopenharmony_ci#define BW_PERCENT               100
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define DCB_TX_CONFIG            0
188c2ecf20Sopenharmony_ci#define DCB_RX_CONFIG            1
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci/* DCB error Codes */
218c2ecf20Sopenharmony_ci#define DCB_SUCCESS              0
228c2ecf20Sopenharmony_ci#define DCB_ERR_CONFIG           -1
238c2ecf20Sopenharmony_ci#define DCB_ERR_PARAM            -2
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/* Transmit and receive Errors */
268c2ecf20Sopenharmony_ci/* Error in bandwidth group allocation */
278c2ecf20Sopenharmony_ci#define DCB_ERR_BW_GROUP        -3
288c2ecf20Sopenharmony_ci/* Error in traffic class bandwidth allocation */
298c2ecf20Sopenharmony_ci#define DCB_ERR_TC_BW           -4
308c2ecf20Sopenharmony_ci/* Traffic class has both link strict and group strict enabled */
318c2ecf20Sopenharmony_ci#define DCB_ERR_LS_GS           -5
328c2ecf20Sopenharmony_ci/* Link strict traffic class has non zero bandwidth */
338c2ecf20Sopenharmony_ci#define DCB_ERR_LS_BW_NONZERO   -6
348c2ecf20Sopenharmony_ci/* Link strict bandwidth group has non zero bandwidth */
358c2ecf20Sopenharmony_ci#define DCB_ERR_LS_BWG_NONZERO  -7
368c2ecf20Sopenharmony_ci/*  Traffic class has zero bandwidth */
378c2ecf20Sopenharmony_ci#define DCB_ERR_TC_BW_ZERO      -8
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define DCB_NOT_IMPLEMENTED      0x7FFFFFFF
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cistruct dcb_pfc_tc_debug {
428c2ecf20Sopenharmony_ci	u8  tc;
438c2ecf20Sopenharmony_ci	u8  pause_status;
448c2ecf20Sopenharmony_ci	u64 pause_quanta;
458c2ecf20Sopenharmony_ci};
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cienum strict_prio_type {
488c2ecf20Sopenharmony_ci	prio_none = 0,
498c2ecf20Sopenharmony_ci	prio_group,
508c2ecf20Sopenharmony_ci	prio_link
518c2ecf20Sopenharmony_ci};
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci/* DCB capability definitions */
548c2ecf20Sopenharmony_ci#define IXGBE_DCB_PG_SUPPORT        0x00000001
558c2ecf20Sopenharmony_ci#define IXGBE_DCB_PFC_SUPPORT       0x00000002
568c2ecf20Sopenharmony_ci#define IXGBE_DCB_BCN_SUPPORT       0x00000004
578c2ecf20Sopenharmony_ci#define IXGBE_DCB_UP2TC_SUPPORT     0x00000008
588c2ecf20Sopenharmony_ci#define IXGBE_DCB_GSP_SUPPORT       0x00000010
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define IXGBE_DCB_8_TC_SUPPORT      0x80
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistruct dcb_support {
638c2ecf20Sopenharmony_ci	/* DCB capabilities */
648c2ecf20Sopenharmony_ci	u32 capabilities;
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci	/* Each bit represents a number of TCs configurable in the hw.
678c2ecf20Sopenharmony_ci	 * If 8 traffic classes can be configured, the value is 0x80.
688c2ecf20Sopenharmony_ci	 */
698c2ecf20Sopenharmony_ci	u8  traffic_classes;
708c2ecf20Sopenharmony_ci	u8  pfc_traffic_classes;
718c2ecf20Sopenharmony_ci};
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/* Traffic class bandwidth allocation per direction */
748c2ecf20Sopenharmony_cistruct tc_bw_alloc {
758c2ecf20Sopenharmony_ci	u8 bwg_id;		  /* Bandwidth Group (BWG) ID */
768c2ecf20Sopenharmony_ci	u8 bwg_percent;		  /* % of BWG's bandwidth */
778c2ecf20Sopenharmony_ci	u8 link_percent;	  /* % of link bandwidth */
788c2ecf20Sopenharmony_ci	u8 up_to_tc_bitmap;	  /* User Priority to Traffic Class mapping */
798c2ecf20Sopenharmony_ci	u16 data_credits_refill;  /* Credit refill amount in 64B granularity */
808c2ecf20Sopenharmony_ci	u16 data_credits_max;	  /* Max credits for a configured packet buffer
818c2ecf20Sopenharmony_ci				   * in 64B granularity.*/
828c2ecf20Sopenharmony_ci	enum strict_prio_type prio_type; /* Link or Group Strict Priority */
838c2ecf20Sopenharmony_ci};
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cienum dcb_pfc_type {
868c2ecf20Sopenharmony_ci	pfc_disabled = 0,
878c2ecf20Sopenharmony_ci	pfc_enabled_full,
888c2ecf20Sopenharmony_ci	pfc_enabled_tx,
898c2ecf20Sopenharmony_ci	pfc_enabled_rx
908c2ecf20Sopenharmony_ci};
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/* Traffic class configuration */
938c2ecf20Sopenharmony_cistruct tc_configuration {
948c2ecf20Sopenharmony_ci	struct tc_bw_alloc path[2]; /* One each for Tx/Rx */
958c2ecf20Sopenharmony_ci	enum dcb_pfc_type  dcb_pfc; /* Class based flow control setting */
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	u16 desc_credits_max; /* For Tx Descriptor arbitration */
988c2ecf20Sopenharmony_ci	u8 tc; /* Traffic class (TC) */
998c2ecf20Sopenharmony_ci};
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_cistruct dcb_num_tcs {
1028c2ecf20Sopenharmony_ci	u8 pg_tcs;
1038c2ecf20Sopenharmony_ci	u8 pfc_tcs;
1048c2ecf20Sopenharmony_ci};
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_cistruct ixgbe_dcb_config {
1078c2ecf20Sopenharmony_ci	struct dcb_support support;
1088c2ecf20Sopenharmony_ci	struct dcb_num_tcs num_tcs;
1098c2ecf20Sopenharmony_ci	struct tc_configuration tc_config[MAX_TRAFFIC_CLASS];
1108c2ecf20Sopenharmony_ci	u8     bw_percentage[2][MAX_BW_GROUP]; /* One each for Tx/Rx */
1118c2ecf20Sopenharmony_ci	bool   pfc_mode_enable;
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	u32  dcb_cfg_version; /* Not used...OS-specific? */
1148c2ecf20Sopenharmony_ci	u32  link_speed; /* For bandwidth allocation validation purpose */
1158c2ecf20Sopenharmony_ci};
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci/* DCB driver APIs */
1188c2ecf20Sopenharmony_civoid ixgbe_dcb_unpack_pfc(struct ixgbe_dcb_config *cfg, u8 *pfc_en);
1198c2ecf20Sopenharmony_civoid ixgbe_dcb_unpack_refill(struct ixgbe_dcb_config *, int, u16 *);
1208c2ecf20Sopenharmony_civoid ixgbe_dcb_unpack_max(struct ixgbe_dcb_config *, u16 *);
1218c2ecf20Sopenharmony_civoid ixgbe_dcb_unpack_bwgid(struct ixgbe_dcb_config *, int, u8 *);
1228c2ecf20Sopenharmony_civoid ixgbe_dcb_unpack_prio(struct ixgbe_dcb_config *, int, u8 *);
1238c2ecf20Sopenharmony_civoid ixgbe_dcb_unpack_map(struct ixgbe_dcb_config *, int, u8 *);
1248c2ecf20Sopenharmony_ciu8 ixgbe_dcb_get_tc_from_up(struct ixgbe_dcb_config *, int, u8);
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci/* DCB credits calculation */
1278c2ecf20Sopenharmony_cis32 ixgbe_dcb_calculate_tc_credits(struct ixgbe_hw *,
1288c2ecf20Sopenharmony_ci				   struct ixgbe_dcb_config *, int, u8);
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci/* DCB hw initialization */
1318c2ecf20Sopenharmony_cis32 ixgbe_dcb_hw_ets(struct ixgbe_hw *hw, struct ieee_ets *ets, int max);
1328c2ecf20Sopenharmony_cis32 ixgbe_dcb_hw_ets_config(struct ixgbe_hw *hw, u16 *refill, u16 *max,
1338c2ecf20Sopenharmony_ci			    u8 *bwg_id, u8 *prio_type, u8 *tc_prio);
1348c2ecf20Sopenharmony_cis32 ixgbe_dcb_hw_pfc_config(struct ixgbe_hw *hw, u8 pfc_en, u8 *tc_prio);
1358c2ecf20Sopenharmony_cis32 ixgbe_dcb_hw_config(struct ixgbe_hw *, struct ixgbe_dcb_config *);
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_civoid ixgbe_dcb_read_rtrup2tc(struct ixgbe_hw *hw, u8 *map);
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci/* DCB definitions for credit calculation */
1408c2ecf20Sopenharmony_ci#define DCB_CREDIT_QUANTUM	64   /* DCB Quantum */
1418c2ecf20Sopenharmony_ci#define MAX_CREDIT_REFILL       511  /* 0x1FF * 64B = 32704B */
1428c2ecf20Sopenharmony_ci#define DCB_MAX_TSO_SIZE        (32*1024) /* MAX TSO packet size supported in DCB mode */
1438c2ecf20Sopenharmony_ci#define MINIMUM_CREDIT_FOR_TSO  (DCB_MAX_TSO_SIZE/64 + 1) /* 513 for 32KB TSO packet */
1448c2ecf20Sopenharmony_ci#define MAX_CREDIT              4095 /* Maximum credit supported: 256KB * 1204 / 64B */
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci#endif /* _DCB_CONFIG_H */
147