1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2019-2021, Intel Corporation. */
3 
4 #ifndef _ICE_ESWITCH_H_
5 #define _ICE_ESWITCH_H_
6 
7 #include <net/devlink.h>
8 #include "devlink/devlink_port.h"
9 
10 #ifdef CONFIG_ICE_SWITCHDEV
11 void ice_eswitch_detach_vf(struct ice_pf *pf, struct ice_vf *vf);
12 void ice_eswitch_detach_sf(struct ice_pf *pf, struct ice_dynamic_port *sf);
13 int ice_eswitch_attach_vf(struct ice_pf *pf, struct ice_vf *vf);
14 int ice_eswitch_attach_sf(struct ice_pf *pf, struct ice_dynamic_port *sf);
15 
16 int ice_eswitch_mode_get(struct devlink *devlink, u16 *mode);
17 int
18 ice_eswitch_mode_set(struct devlink *devlink, u16 mode,
19 		     struct netlink_ext_ack *extack);
20 bool ice_is_eswitch_mode_switchdev(struct ice_pf *pf);
21 
22 void ice_eswitch_update_repr(unsigned long *repr_id, struct ice_vsi *vsi);
23 
24 void ice_eswitch_stop_all_tx_queues(struct ice_pf *pf);
25 
26 void ice_eswitch_set_target_vsi(struct sk_buff *skb,
27 				struct ice_tx_offload_params *off);
28 netdev_tx_t
29 ice_eswitch_port_start_xmit(struct sk_buff *skb, struct net_device *netdev);
30 struct net_device *ice_eswitch_get_target(struct ice_rx_ring *rx_ring,
31 					  union ice_32b_rx_flex_desc *rx_desc);
32 
33 int ice_eswitch_cfg_vsi(struct ice_vsi *vsi, const u8 *mac);
34 void ice_eswitch_decfg_vsi(struct ice_vsi *vsi, const u8 *mac);
35 #else /* CONFIG_ICE_SWITCHDEV */
36 static inline void
ice_eswitch_detach_vf(struct ice_pf * pf,struct ice_vf * vf)37 ice_eswitch_detach_vf(struct ice_pf *pf, struct ice_vf *vf) { }
38 
39 static inline void
ice_eswitch_detach_sf(struct ice_pf * pf,struct ice_dynamic_port * sf)40 ice_eswitch_detach_sf(struct ice_pf *pf, struct ice_dynamic_port *sf) { }
41 
42 static inline int
ice_eswitch_attach_vf(struct ice_pf * pf,struct ice_vf * vf)43 ice_eswitch_attach_vf(struct ice_pf *pf, struct ice_vf *vf)
44 {
45 	return -EOPNOTSUPP;
46 }
47 
48 static inline int
ice_eswitch_attach_sf(struct ice_pf * pf,struct ice_dynamic_port * sf)49 ice_eswitch_attach_sf(struct ice_pf *pf, struct ice_dynamic_port *sf)
50 {
51 	return -EOPNOTSUPP;
52 }
53 
ice_eswitch_stop_all_tx_queues(struct ice_pf * pf)54 static inline void ice_eswitch_stop_all_tx_queues(struct ice_pf *pf) { }
55 
56 static inline void
ice_eswitch_set_target_vsi(struct sk_buff * skb,struct ice_tx_offload_params * off)57 ice_eswitch_set_target_vsi(struct sk_buff *skb,
58 			   struct ice_tx_offload_params *off) { }
59 
60 static inline void
ice_eswitch_update_repr(unsigned long * repr_id,struct ice_vsi * vsi)61 ice_eswitch_update_repr(unsigned long *repr_id, struct ice_vsi *vsi) { }
62 
ice_eswitch_configure(struct ice_pf * pf)63 static inline int ice_eswitch_configure(struct ice_pf *pf)
64 {
65 	return 0;
66 }
67 
ice_eswitch_mode_get(struct devlink * devlink,u16 * mode)68 static inline int ice_eswitch_mode_get(struct devlink *devlink, u16 *mode)
69 {
70 	return DEVLINK_ESWITCH_MODE_LEGACY;
71 }
72 
73 static inline int
ice_eswitch_mode_set(struct devlink * devlink,u16 mode,struct netlink_ext_ack * extack)74 ice_eswitch_mode_set(struct devlink *devlink, u16 mode,
75 		     struct netlink_ext_ack *extack)
76 {
77 	return -EOPNOTSUPP;
78 }
79 
ice_is_eswitch_mode_switchdev(struct ice_pf * pf)80 static inline bool ice_is_eswitch_mode_switchdev(struct ice_pf *pf)
81 {
82 	return false;
83 }
84 
85 static inline netdev_tx_t
ice_eswitch_port_start_xmit(struct sk_buff * skb,struct net_device * netdev)86 ice_eswitch_port_start_xmit(struct sk_buff *skb, struct net_device *netdev)
87 {
88 	return NETDEV_TX_BUSY;
89 }
90 
91 static inline struct net_device *
ice_eswitch_get_target(struct ice_rx_ring * rx_ring,union ice_32b_rx_flex_desc * rx_desc)92 ice_eswitch_get_target(struct ice_rx_ring *rx_ring,
93 		       union ice_32b_rx_flex_desc *rx_desc)
94 {
95 	return rx_ring->netdev;
96 }
97 
ice_eswitch_cfg_vsi(struct ice_vsi * vsi,const u8 * mac)98 static inline int ice_eswitch_cfg_vsi(struct ice_vsi *vsi, const u8 *mac)
99 {
100 	return -EOPNOTSUPP;
101 }
102 
ice_eswitch_decfg_vsi(struct ice_vsi * vsi,const u8 * mac)103 static inline void ice_eswitch_decfg_vsi(struct ice_vsi *vsi, const u8 *mac) { }
104 #endif /* CONFIG_ICE_SWITCHDEV */
105 #endif /* _ICE_ESWITCH_H_ */
106