knet.h (9003B)
1 /* 2 * 3 * 4 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 5 * 6 * Copyright 2007-2020 Broadcom Inc. All rights reserved. 7 * 8 */ 9 10 #ifndef __BCM_KNET_H__ 11 #define __BCM_KNET_H__ 12 13 #include <bcm/types.h> 14 #include <bcm/rx.h> 15 16 /* Network interface types */ 17 #define BCM_KNET_NETIF_T_TX_CPU_INGRESS 1 /* Tx packets are sent 18 through CPU port ingress 19 logic. */ 20 #define BCM_KNET_NETIF_T_TX_LOCAL_PORT 2 /* Tx packets are sent to 21 local device port 22 bypassing switch logic. */ 23 #define BCM_KNET_NETIF_T_TX_META_DATA 3 /* Tx packets are sent using 24 raw meta data as DMA 25 descriptors. */ 26 27 /* Network interface flags */ 28 #define BCM_KNET_NETIF_F_ADD_TAG 0x00000001 /* Add VLAN tag to packets 29 sent directly to physical 30 port. */ 31 #define BCM_KNET_NETIF_F_RCPU_ENCAP 0x00000002 /* Use RCPU encapsulation for 32 packets that enter and 33 exit this interface. */ 34 #define BCM_KNET_NETIF_F_KEEP_RX_TAG 0x00000004 /* Do nothing to the tag of 35 packets which will be sent 36 to this interface. */ 37 38 #define BCM_KNET_NETIF_NAME_MAX 16 39 40 /* Kernel network interface structure. */ 41 typedef struct bcm_knet_netif_s { 42 int id; /* Network interface ID. */ 43 int type; /* Network interface type 44 (BCM_KNET_NETIF_T_XXX). */ 45 uint32 flags; /* BCM_KNET_NETIF_F_XXX flags. */ 46 bcm_mac_t mac_addr; /* MAC address associated with this 47 network interface. */ 48 bcm_vlan_t vlan; /* VLAN ID associated with this 49 interface. */ 50 bcm_port_t port; /* Local port associated with this 51 interface. */ 52 bcm_cos_queue_t cosq; /* Cos offset from base queue of port 53 associated with this interface. */ 54 char name[BCM_KNET_NETIF_NAME_MAX]; /* Network interface name (assigned by 55 kernel) */ 56 uint32 cb_user_data; /* Netif user data for knet rx cb. */ 57 } bcm_knet_netif_t; 58 59 /* Filter types */ 60 #define BCM_KNET_FILTER_T_RX_PKT 1 /* Rx packet filter. */ 61 62 /* Filter destinstion types */ 63 #define BCM_KNET_DEST_T_NULL 0 /* Null destination (drop 64 packet). */ 65 #define BCM_KNET_DEST_T_NETIF 1 /* Send packet to virtual network 66 interface. */ 67 #define BCM_KNET_DEST_T_BCM_RX_API 2 /* Send packet to BCM Rx API. */ 68 #define BCM_KNET_DEST_T_CALLBACK 3 /* Send packet to kernel 69 call-back function. */ 70 71 /* Filter flags */ 72 #define BCM_KNET_FILTER_F_STRIP_TAG 0x00000001 /* Strip VLAN tag from packets 73 sent to vitual network 74 interfaces. */ 75 76 #define BCM_KNET_FILTER_DESC_MAX 32 77 78 #define BCM_KNET_FILTER_SIZE_MAX 256 79 80 /* Match criteria selection */ 81 #define BCM_KNET_FILTER_M_RAW 0x00000001 /* Match raw packet data */ 82 #define BCM_KNET_FILTER_M_VLAN 0x00000002 /* Match VLAN ID */ 83 #define BCM_KNET_FILTER_M_INGPORT 0x00000004 /* Match local ingress port */ 84 #define BCM_KNET_FILTER_M_SRC_MODPORT 0x00000008 /* Match source module port */ 85 #define BCM_KNET_FILTER_M_SRC_MODID 0x00000010 /* Match source module ID */ 86 #define BCM_KNET_FILTER_M_REASON 0x00000020 /* Match copy-to-CPU reason 87 code */ 88 #define BCM_KNET_FILTER_M_FP_RULE 0x00000040 /* Match filter processor 89 rule number */ 90 #define BCM_KNET_FILTER_M_ERROR 0x00000080 /* Match error bit */ 91 92 /* Kernel packet filter structure. */ 93 typedef struct bcm_knet_filter_s { 94 int id; /* Filter ID. */ 95 int type; /* Filter type (BCM_KNET_FILTER_T_XXX). */ 96 uint32 flags; /* BCM_KNET_FILTER_F_XXX flags. */ 97 int priority; /* Filter priority, lower value has 98 higher priority, value of RX channels 99 are reserved to bind filter to 100 corresponding RX channel by default. */ 101 int dest_type; /* Filter destination type. */ 102 int dest_id; /* Filter destination ID. */ 103 int dest_proto; /* If non-zero this value overrides the 104 default protocol type when matching 105 packet is passed to network stack. */ 106 int mirror_type; /* Mirror destination type. */ 107 int mirror_id; /* Mirror destination ID. */ 108 int mirror_proto; /* If non-zero this value overrides the 109 default protocol type when matching 110 packet is passed to network stack. */ 111 uint32 match_flags; /* BCM_KNET_FILTER_M_XXX flags. */ 112 char desc[BCM_KNET_FILTER_DESC_MAX]; /* Filter description (optional) */ 113 bcm_vlan_t m_vlan; /* VLAN ID to match. */ 114 bcm_port_t m_ingport; /* Local ingress port to match. */ 115 int m_src_modport; /* Source module port to match. */ 116 int m_src_modid; /* Source module ID to match. */ 117 bcm_rx_reasons_t m_reason; /* Copy-to-CPU reason to match. */ 118 int m_fp_rule; /* Filter processor rule to match. */ 119 int raw_size; /* Size of valid raw data and mask. */ 120 uint8 m_raw_data[BCM_KNET_FILTER_SIZE_MAX]; /* Raw data to match. */ 121 uint8 m_raw_mask[BCM_KNET_FILTER_SIZE_MAX]; /* Raw data mask for match. */ 122 uint32 cb_user_data; /* Filter user data for knet rx cb. */ 123 } bcm_knet_filter_t; 124 125 /* Initialize a bcm_knet_netif_t structure. */ 126 extern void bcm_knet_netif_t_init( 127 bcm_knet_netif_t *netif); 128 129 /* Initialize a bcm_knet_filter_t structure. */ 130 extern void bcm_knet_filter_t_init( 131 bcm_knet_filter_t *filter); 132 133 #ifndef BCM_HIDE_DISPATCHABLE 134 135 /* Initialize the kernel networking subsystem. */ 136 extern int bcm_knet_init( 137 int unit); 138 139 /* Clean up the kernel networking subsystem. */ 140 extern int bcm_knet_cleanup( 141 int unit); 142 143 /* Create a kernel network interface. */ 144 extern int bcm_knet_netif_create( 145 int unit, 146 bcm_knet_netif_t *netif); 147 148 /* Destroy a kernel network interface. */ 149 extern int bcm_knet_netif_destroy( 150 int unit, 151 int netif_id); 152 153 /* Get a kernel network interface configuration. */ 154 extern int bcm_knet_netif_get( 155 int unit, 156 int netif_id, 157 bcm_knet_netif_t *netif); 158 159 #endif /* BCM_HIDE_DISPATCHABLE */ 160 161 /* Kernel network interface traverse callback */ 162 typedef int (*bcm_knet_netif_traverse_cb)( 163 int unit, 164 bcm_knet_netif_t *netif, 165 void *user_data); 166 167 #ifndef BCM_HIDE_DISPATCHABLE 168 169 /* Traverse kernel network interface objects */ 170 extern int bcm_knet_netif_traverse( 171 int unit, 172 bcm_knet_netif_traverse_cb trav_fn, 173 void *user_data); 174 175 /* Create a kernel packet filter. */ 176 extern int bcm_knet_filter_create( 177 int unit, 178 bcm_knet_filter_t *filter); 179 180 /* Destroy a kernel packet filter. */ 181 extern int bcm_knet_filter_destroy( 182 int unit, 183 int filter_id); 184 185 /* Get a kernel packet filter configuration. */ 186 extern int bcm_knet_filter_get( 187 int unit, 188 int filter_id, 189 bcm_knet_filter_t *filter); 190 191 #endif /* BCM_HIDE_DISPATCHABLE */ 192 193 /* Kernel packet filter traverse callback */ 194 typedef int (*bcm_knet_filter_traverse_cb)( 195 int unit, 196 bcm_knet_filter_t *filter, 197 void *user_data); 198 199 #ifndef BCM_HIDE_DISPATCHABLE 200 201 /* Traverse kernel packet filter objects */ 202 extern int bcm_knet_filter_traverse( 203 int unit, 204 bcm_knet_filter_traverse_cb trav_fn, 205 void *user_data); 206 207 #endif /* BCM_HIDE_DISPATCHABLE */ 208 209 #endif /* __BCM_KNET_H__ */