2 * Copyright (C) 2013-2014 Chelsio Communications. All rights reserved.
4 * Written by Anish Bhatt (anish@chelsio.com)
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * The full GNU General Public License is included in this distribution in
16 * the file called "COPYING".
23 #include <linux/netdevice.h>
24 #include <linux/dcbnl.h>
25 #include <net/dcbnl.h>
27 #ifdef CONFIG_CHELSIO_T4_DCB
29 #define CXGB4_DCBX_FW_SUPPORT \
30 (DCB_CAP_DCBX_VER_CEE | \
31 DCB_CAP_DCBX_VER_IEEE | \
32 DCB_CAP_DCBX_LLD_MANAGED)
33 #define CXGB4_DCBX_HOST_SUPPORT \
34 (DCB_CAP_DCBX_VER_CEE | \
35 DCB_CAP_DCBX_VER_IEEE | \
38 #define CXGB4_MAX_PRIORITY CXGB4_MAX_DCBX_APP_SUPPORTED
39 #define CXGB4_MAX_TCS CXGB4_MAX_DCBX_APP_SUPPORTED
41 #define INIT_PORT_DCB_CMD(__pcmd, __port, __op, __action) \
43 memset(&(__pcmd), 0, sizeof(__pcmd)); \
44 (__pcmd).op_to_portid = \
45 cpu_to_be32(FW_CMD_OP(FW_PORT_CMD) | \
48 FW_PORT_CMD_PORTID(__port)); \
49 (__pcmd).action_to_len16 = \
50 cpu_to_be32(FW_PORT_CMD_ACTION(__action) | \
54 #define INIT_PORT_DCB_READ_PEER_CMD(__pcmd, __port) \
55 INIT_PORT_DCB_CMD(__pcmd, __port, READ, FW_PORT_ACTION_DCB_READ_RECV)
57 #define INIT_PORT_DCB_READ_LOCAL_CMD(__pcmd, __port) \
58 INIT_PORT_DCB_CMD(__pcmd, __port, READ, FW_PORT_ACTION_DCB_READ_TRANS)
60 #define INIT_PORT_DCB_READ_SYNC_CMD(__pcmd, __port) \
61 INIT_PORT_DCB_CMD(__pcmd, __port, READ, FW_PORT_ACTION_DCB_READ_DET)
63 #define INIT_PORT_DCB_WRITE_CMD(__pcmd, __port) \
64 INIT_PORT_DCB_CMD(__pcmd, __port, EXEC, FW_PORT_ACTION_L2_DCB_CFG)
66 /* States we can be in for a port's Data Center Bridging.
68 enum cxgb4_dcb_state {
69 CXGB4_DCB_STATE_START, /* initial unknown state */
70 CXGB4_DCB_STATE_HOST, /* we're using Host DCB (if at all) */
71 CXGB4_DCB_STATE_FW_INCOMPLETE, /* using firmware DCB, incomplete */
72 CXGB4_DCB_STATE_FW_ALLSYNCED, /* using firmware DCB, all sync'ed */
75 /* Data Center Bridging state input for the Finite State Machine.
77 enum cxgb4_dcb_state_input {
78 /* Input from the firmware.
80 CXGB4_DCB_INPUT_FW_DISABLED, /* firmware DCB disabled */
81 CXGB4_DCB_INPUT_FW_ENABLED, /* firmware DCB enabled */
82 CXGB4_DCB_INPUT_FW_INCOMPLETE, /* firmware reports incomplete DCB */
83 CXGB4_DCB_INPUT_FW_ALLSYNCED, /* firmware reports all sync'ed */
87 /* Firmware DCB messages that we've received so far ...
89 enum cxgb4_dcb_fw_msgs {
90 CXGB4_DCB_FW_PGID = 0x01,
91 CXGB4_DCB_FW_PGRATE = 0x02,
92 CXGB4_DCB_FW_PRIORATE = 0x04,
93 CXGB4_DCB_FW_PFC = 0x08,
94 CXGB4_DCB_FW_APP_ID = 0x10,
97 #define CXGB4_MAX_DCBX_APP_SUPPORTED 8
99 /* Data Center Bridging support;
101 struct port_dcb_info {
102 enum cxgb4_dcb_state state; /* DCB State Machine */
103 enum cxgb4_dcb_fw_msgs msgs; /* DCB Firmware messages received */
104 unsigned int supported; /* OS DCB capabilities supported */
105 bool enabled; /* OS Enabled state */
107 /* Cached copies of DCB information sent by the firmware (in Host
108 * Native Endian format).
110 u32 pgid; /* Priority Group[0..7] */
111 u8 pfcen; /* Priority Flow Control[0..7] */
112 u8 pg_num_tcs_supported; /* max PG Traffic Classes */
113 u8 pfc_num_tcs_supported; /* max PFC Traffic Classes */
114 u8 pgrate[8]; /* Priority Group Rate[0..7] */
115 u8 priorate[8]; /* Priority Rate[0..7] */
116 struct app_priority { /* Application Information */
117 u8 user_prio_map; /* Priority Map bitfield */
118 u8 sel_field; /* Protocol ID interpretation */
119 u16 protocolid; /* Protocol ID */
120 } app_priority[CXGB4_MAX_DCBX_APP_SUPPORTED];
123 void cxgb4_dcb_state_init(struct net_device *);
124 void cxgb4_dcb_state_fsm(struct net_device *, enum cxgb4_dcb_state_input);
125 void cxgb4_dcb_handle_fw_update(struct adapter *, const struct fw_port_cmd *);
126 void cxgb4_dcb_set_caps(struct adapter *, const struct fw_port_cmd *);
127 extern const struct dcbnl_rtnl_ops cxgb4_dcb_ops;
129 #define CXGB4_DCB_ENABLED true
131 #else /* !CONFIG_CHELSIO_T4_DCB */
133 static inline void cxgb4_dcb_state_init(struct net_device *dev)
137 #define CXGB4_DCB_ENABLED false
139 #endif /* !CONFIG_CHELSIO_T4_DCB */
141 #endif /* __CXGB4_DCB_H */