spectrum.h 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493
  1. /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
  2. /* Copyright (c) 2015-2018 Mellanox Technologies. All rights reserved */
  3. #ifndef _MLXSW_SPECTRUM_H
  4. #define _MLXSW_SPECTRUM_H
  5. #include <linux/ethtool.h>
  6. #include <linux/types.h>
  7. #include <linux/netdevice.h>
  8. #include <linux/rhashtable.h>
  9. #include <linux/bitops.h>
  10. #include <linux/if_bridge.h>
  11. #include <linux/if_vlan.h>
  12. #include <linux/list.h>
  13. #include <linux/dcbnl.h>
  14. #include <linux/in6.h>
  15. #include <linux/notifier.h>
  16. #include <linux/net_namespace.h>
  17. #include <linux/spinlock.h>
  18. #include <net/psample.h>
  19. #include <net/pkt_cls.h>
  20. #include <net/red.h>
  21. #include <net/vxlan.h>
  22. #include <net/flow_offload.h>
  23. #include <net/inet_ecn.h>
  24. #include "port.h"
  25. #include "core.h"
  26. #include "core_acl_flex_keys.h"
  27. #include "core_acl_flex_actions.h"
  28. #include "reg.h"
  29. #define MLXSW_SP_DEFAULT_VID (VLAN_N_VID - 1)
  30. #define MLXSW_SP_FID_8021D_MAX 1024
  31. #define MLXSW_SP_MID_MAX 7000
  32. #define MLXSW_SP_KVD_LINEAR_SIZE 98304 /* entries */
  33. #define MLXSW_SP_KVD_GRANULARITY 128
  34. #define MLXSW_SP_RESOURCE_NAME_KVD "kvd"
  35. #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR "linear"
  36. #define MLXSW_SP_RESOURCE_NAME_KVD_HASH_SINGLE "hash_single"
  37. #define MLXSW_SP_RESOURCE_NAME_KVD_HASH_DOUBLE "hash_double"
  38. #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_SINGLES "singles"
  39. #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_CHUNKS "chunks"
  40. #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_LARGE_CHUNKS "large_chunks"
  41. #define MLXSW_SP_RESOURCE_NAME_SPAN "span_agents"
  42. #define MLXSW_SP_RESOURCE_NAME_COUNTERS "counters"
  43. #define MLXSW_SP_RESOURCE_NAME_COUNTERS_FLOW "flow"
  44. #define MLXSW_SP_RESOURCE_NAME_COUNTERS_RIF "rif"
  45. enum mlxsw_sp_resource_id {
  46. MLXSW_SP_RESOURCE_KVD = MLXSW_CORE_RESOURCE_MAX,
  47. MLXSW_SP_RESOURCE_KVD_LINEAR,
  48. MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
  49. MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
  50. MLXSW_SP_RESOURCE_KVD_LINEAR_SINGLE,
  51. MLXSW_SP_RESOURCE_KVD_LINEAR_CHUNKS,
  52. MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS,
  53. MLXSW_SP_RESOURCE_SPAN,
  54. MLXSW_SP_RESOURCE_COUNTERS,
  55. MLXSW_SP_RESOURCE_COUNTERS_FLOW,
  56. MLXSW_SP_RESOURCE_COUNTERS_RIF,
  57. MLXSW_SP_RESOURCE_GLOBAL_POLICERS,
  58. MLXSW_SP_RESOURCE_SINGLE_RATE_POLICERS,
  59. MLXSW_SP_RESOURCE_RIF_MAC_PROFILES,
  60. MLXSW_SP_RESOURCE_RIFS,
  61. };
  62. struct mlxsw_sp_port;
  63. struct mlxsw_sp_rif;
  64. struct mlxsw_sp_span_entry;
  65. enum mlxsw_sp_l3proto;
  66. union mlxsw_sp_l3addr;
  67. struct mlxsw_sp_upper {
  68. struct net_device *dev;
  69. unsigned int ref_count;
  70. };
  71. enum mlxsw_sp_rif_type {
  72. MLXSW_SP_RIF_TYPE_SUBPORT,
  73. MLXSW_SP_RIF_TYPE_VLAN,
  74. MLXSW_SP_RIF_TYPE_FID,
  75. MLXSW_SP_RIF_TYPE_IPIP_LB, /* IP-in-IP loopback. */
  76. MLXSW_SP_RIF_TYPE_MAX,
  77. };
  78. struct mlxsw_sp_router_ops;
  79. extern const struct mlxsw_sp_router_ops mlxsw_sp1_router_ops;
  80. extern const struct mlxsw_sp_router_ops mlxsw_sp2_router_ops;
  81. struct mlxsw_sp_switchdev_ops;
  82. extern const struct mlxsw_sp_switchdev_ops mlxsw_sp1_switchdev_ops;
  83. extern const struct mlxsw_sp_switchdev_ops mlxsw_sp2_switchdev_ops;
  84. enum mlxsw_sp_fid_type {
  85. MLXSW_SP_FID_TYPE_8021Q,
  86. MLXSW_SP_FID_TYPE_8021D,
  87. MLXSW_SP_FID_TYPE_RFID,
  88. MLXSW_SP_FID_TYPE_DUMMY,
  89. MLXSW_SP_FID_TYPE_MAX,
  90. };
  91. enum mlxsw_sp_nve_type {
  92. MLXSW_SP_NVE_TYPE_VXLAN,
  93. };
  94. struct mlxsw_sp_sb;
  95. struct mlxsw_sp_bridge;
  96. struct mlxsw_sp_router;
  97. struct mlxsw_sp_mr;
  98. struct mlxsw_sp_acl;
  99. struct mlxsw_sp_counter_pool;
  100. struct mlxsw_sp_fid_core;
  101. struct mlxsw_sp_kvdl;
  102. struct mlxsw_sp_nve;
  103. struct mlxsw_sp_kvdl_ops;
  104. struct mlxsw_sp_mr_tcam_ops;
  105. struct mlxsw_sp_acl_rulei_ops;
  106. struct mlxsw_sp_acl_tcam_ops;
  107. struct mlxsw_sp_nve_ops;
  108. struct mlxsw_sp_sb_ops;
  109. struct mlxsw_sp_sb_vals;
  110. struct mlxsw_sp_port_type_speed_ops;
  111. struct mlxsw_sp_ptp_state;
  112. struct mlxsw_sp_ptp_ops;
  113. struct mlxsw_sp_span_ops;
  114. struct mlxsw_sp_qdisc_state;
  115. struct mlxsw_sp_mall_entry;
  116. struct mlxsw_sp_pgt;
  117. struct mlxsw_sp_port_mapping {
  118. u8 module;
  119. u8 slot_index;
  120. u8 width; /* Number of lanes used by the port */
  121. u8 module_width; /* Number of lanes in the module (static) */
  122. u8 lane;
  123. };
  124. struct mlxsw_sp_port_mapping_events {
  125. struct list_head queue;
  126. spinlock_t queue_lock; /* protects queue */
  127. struct work_struct work;
  128. };
  129. struct mlxsw_sp_parsing {
  130. refcount_t parsing_depth_ref;
  131. u16 parsing_depth;
  132. u16 vxlan_udp_dport;
  133. struct mutex lock; /* Protects parsing configuration */
  134. };
  135. struct mlxsw_sp {
  136. struct mlxsw_sp_port **ports;
  137. struct mlxsw_core *core;
  138. const struct mlxsw_bus_info *bus_info;
  139. unsigned char base_mac[ETH_ALEN];
  140. const unsigned char *mac_mask;
  141. struct mlxsw_sp_upper *lags;
  142. struct mlxsw_sp_port_mapping *port_mapping;
  143. struct mlxsw_sp_port_mapping_events port_mapping_events;
  144. struct rhashtable sample_trigger_ht;
  145. struct mlxsw_sp_sb *sb;
  146. struct mlxsw_sp_bridge *bridge;
  147. struct mlxsw_sp_router *router;
  148. struct mlxsw_sp_mr *mr;
  149. struct mlxsw_afa *afa;
  150. struct mlxsw_sp_acl *acl;
  151. struct mlxsw_sp_fid_core *fid_core;
  152. struct mlxsw_sp_policer_core *policer_core;
  153. struct mlxsw_sp_kvdl *kvdl;
  154. struct mlxsw_sp_nve *nve;
  155. struct notifier_block netdevice_nb;
  156. struct mlxsw_sp_ptp_clock *clock;
  157. struct mlxsw_sp_ptp_state *ptp_state;
  158. struct mlxsw_sp_counter_pool *counter_pool;
  159. struct mlxsw_sp_span *span;
  160. struct mlxsw_sp_trap *trap;
  161. struct mlxsw_sp_parsing parsing;
  162. const struct mlxsw_sp_switchdev_ops *switchdev_ops;
  163. const struct mlxsw_sp_kvdl_ops *kvdl_ops;
  164. const struct mlxsw_afa_ops *afa_ops;
  165. const struct mlxsw_afk_ops *afk_ops;
  166. const struct mlxsw_sp_mr_tcam_ops *mr_tcam_ops;
  167. const struct mlxsw_sp_acl_rulei_ops *acl_rulei_ops;
  168. const struct mlxsw_sp_acl_tcam_ops *acl_tcam_ops;
  169. const struct mlxsw_sp_acl_bf_ops *acl_bf_ops;
  170. const struct mlxsw_sp_nve_ops **nve_ops_arr;
  171. const struct mlxsw_sp_sb_vals *sb_vals;
  172. const struct mlxsw_sp_sb_ops *sb_ops;
  173. const struct mlxsw_sp_port_type_speed_ops *port_type_speed_ops;
  174. const struct mlxsw_sp_ptp_ops *ptp_ops;
  175. const struct mlxsw_sp_span_ops *span_ops;
  176. const struct mlxsw_sp_policer_core_ops *policer_core_ops;
  177. const struct mlxsw_sp_trap_ops *trap_ops;
  178. const struct mlxsw_sp_mall_ops *mall_ops;
  179. const struct mlxsw_sp_router_ops *router_ops;
  180. const struct mlxsw_listener *listeners;
  181. const struct mlxsw_sp_fid_family **fid_family_arr;
  182. size_t listeners_count;
  183. u32 lowest_shaper_bs;
  184. struct rhashtable ipv6_addr_ht;
  185. struct mutex ipv6_addr_ht_lock; /* Protects ipv6_addr_ht */
  186. struct mlxsw_sp_pgt *pgt;
  187. bool pgt_smpe_index_valid;
  188. };
  189. struct mlxsw_sp_ptp_ops {
  190. struct mlxsw_sp_ptp_clock *
  191. (*clock_init)(struct mlxsw_sp *mlxsw_sp, struct device *dev);
  192. void (*clock_fini)(struct mlxsw_sp_ptp_clock *clock);
  193. struct mlxsw_sp_ptp_state *(*init)(struct mlxsw_sp *mlxsw_sp);
  194. void (*fini)(struct mlxsw_sp_ptp_state *ptp_state);
  195. /* Notify a driver that a packet that might be PTP was received. Driver
  196. * is responsible for freeing the passed-in SKB.
  197. */
  198. void (*receive)(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
  199. u16 local_port);
  200. /* Notify a driver that a timestamped packet was transmitted. Driver
  201. * is responsible for freeing the passed-in SKB.
  202. */
  203. void (*transmitted)(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
  204. u16 local_port);
  205. int (*hwtstamp_get)(struct mlxsw_sp_port *mlxsw_sp_port,
  206. struct hwtstamp_config *config);
  207. int (*hwtstamp_set)(struct mlxsw_sp_port *mlxsw_sp_port,
  208. struct hwtstamp_config *config);
  209. void (*shaper_work)(struct work_struct *work);
  210. int (*get_ts_info)(struct mlxsw_sp *mlxsw_sp,
  211. struct ethtool_ts_info *info);
  212. int (*get_stats_count)(void);
  213. void (*get_stats_strings)(u8 **p);
  214. void (*get_stats)(struct mlxsw_sp_port *mlxsw_sp_port,
  215. u64 *data, int data_index);
  216. int (*txhdr_construct)(struct mlxsw_core *mlxsw_core,
  217. struct mlxsw_sp_port *mlxsw_sp_port,
  218. struct sk_buff *skb,
  219. const struct mlxsw_tx_info *tx_info);
  220. };
  221. static inline struct mlxsw_sp_upper *
  222. mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id)
  223. {
  224. return &mlxsw_sp->lags[lag_id];
  225. }
  226. struct mlxsw_sp_port_pcpu_stats {
  227. u64 rx_packets;
  228. u64 rx_bytes;
  229. u64 tx_packets;
  230. u64 tx_bytes;
  231. struct u64_stats_sync syncp;
  232. u32 tx_dropped;
  233. };
  234. enum mlxsw_sp_sample_trigger_type {
  235. MLXSW_SP_SAMPLE_TRIGGER_TYPE_INGRESS,
  236. MLXSW_SP_SAMPLE_TRIGGER_TYPE_EGRESS,
  237. MLXSW_SP_SAMPLE_TRIGGER_TYPE_POLICY_ENGINE,
  238. };
  239. struct mlxsw_sp_sample_trigger {
  240. enum mlxsw_sp_sample_trigger_type type;
  241. u16 local_port; /* Reserved when trigger type is not ingress / egress. */
  242. };
  243. struct mlxsw_sp_sample_params {
  244. struct psample_group *psample_group;
  245. u32 trunc_size;
  246. u32 rate;
  247. bool truncate;
  248. };
  249. struct mlxsw_sp_bridge_port;
  250. struct mlxsw_sp_fid;
  251. struct mlxsw_sp_port_vlan {
  252. struct list_head list;
  253. struct mlxsw_sp_port *mlxsw_sp_port;
  254. struct mlxsw_sp_fid *fid;
  255. u16 vid;
  256. struct mlxsw_sp_bridge_port *bridge_port;
  257. struct list_head bridge_vlan_node;
  258. };
  259. /* No need an internal lock; At worse - miss a single periodic iteration */
  260. struct mlxsw_sp_port_xstats {
  261. u64 ecn;
  262. u64 tc_ecn[TC_MAX_QUEUE];
  263. u64 wred_drop[TC_MAX_QUEUE];
  264. u64 tail_drop[TC_MAX_QUEUE];
  265. u64 backlog[TC_MAX_QUEUE];
  266. u64 tx_bytes[IEEE_8021QAZ_MAX_TCS];
  267. u64 tx_packets[IEEE_8021QAZ_MAX_TCS];
  268. };
  269. struct mlxsw_sp_ptp_port_dir_stats {
  270. u64 packets;
  271. u64 timestamps;
  272. };
  273. struct mlxsw_sp_ptp_port_stats {
  274. struct mlxsw_sp_ptp_port_dir_stats rx_gcd;
  275. struct mlxsw_sp_ptp_port_dir_stats tx_gcd;
  276. };
  277. struct mlxsw_sp_port {
  278. struct net_device *dev;
  279. struct mlxsw_sp_port_pcpu_stats __percpu *pcpu_stats;
  280. struct mlxsw_sp *mlxsw_sp;
  281. u16 local_port;
  282. u8 lagged:1,
  283. split:1;
  284. u16 pvid;
  285. u16 lag_id;
  286. struct {
  287. u8 tx_pause:1,
  288. rx_pause:1,
  289. autoneg:1;
  290. } link;
  291. struct {
  292. struct ieee_ets *ets;
  293. struct ieee_maxrate *maxrate;
  294. struct ieee_pfc *pfc;
  295. enum mlxsw_reg_qpts_trust_state trust_state;
  296. } dcb;
  297. struct mlxsw_sp_port_mapping mapping; /* mapping is constant during the
  298. * mlxsw_sp_port lifetime, however
  299. * the same localport can have
  300. * different mapping.
  301. */
  302. struct {
  303. #define MLXSW_HW_STATS_UPDATE_TIME HZ
  304. struct rtnl_link_stats64 stats;
  305. struct mlxsw_sp_port_xstats xstats;
  306. struct delayed_work update_dw;
  307. } periodic_hw_stats;
  308. struct list_head vlans_list;
  309. struct mlxsw_sp_port_vlan *default_vlan;
  310. struct mlxsw_sp_qdisc_state *qdisc;
  311. unsigned acl_rule_count;
  312. struct mlxsw_sp_flow_block *ing_flow_block;
  313. struct mlxsw_sp_flow_block *eg_flow_block;
  314. struct {
  315. struct delayed_work shaper_dw;
  316. struct hwtstamp_config hwtstamp_config;
  317. u16 ing_types;
  318. u16 egr_types;
  319. struct mlxsw_sp_ptp_port_stats stats;
  320. } ptp;
  321. int max_mtu;
  322. u32 max_speed;
  323. struct mlxsw_sp_hdroom *hdroom;
  324. u64 module_overheat_initial_val;
  325. };
  326. struct mlxsw_sp_port_type_speed_ops {
  327. void (*from_ptys_supported_port)(struct mlxsw_sp *mlxsw_sp,
  328. u32 ptys_eth_proto,
  329. struct ethtool_link_ksettings *cmd);
  330. void (*from_ptys_link)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto,
  331. unsigned long *mode);
  332. u32 (*from_ptys_speed)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto);
  333. void (*from_ptys_link_mode)(struct mlxsw_sp *mlxsw_sp,
  334. bool carrier_ok, u32 ptys_eth_proto,
  335. struct ethtool_link_ksettings *cmd);
  336. int (*ptys_max_speed)(struct mlxsw_sp_port *mlxsw_sp_port, u32 *p_max_speed);
  337. u32 (*to_ptys_advert_link)(struct mlxsw_sp *mlxsw_sp,
  338. const struct ethtool_link_ksettings *cmd);
  339. u32 (*to_ptys_speed_lanes)(struct mlxsw_sp *mlxsw_sp, u8 width,
  340. const struct ethtool_link_ksettings *cmd);
  341. void (*reg_ptys_eth_pack)(struct mlxsw_sp *mlxsw_sp, char *payload,
  342. u16 local_port, u32 proto_admin, bool autoneg);
  343. void (*reg_ptys_eth_unpack)(struct mlxsw_sp *mlxsw_sp, char *payload,
  344. u32 *p_eth_proto_cap,
  345. u32 *p_eth_proto_admin,
  346. u32 *p_eth_proto_oper);
  347. u32 (*ptys_proto_cap_masked_get)(u32 eth_proto_cap);
  348. };
  349. struct mlxsw_sp_ports_bitmap {
  350. unsigned long *bitmap;
  351. unsigned int nbits;
  352. };
  353. static inline int
  354. mlxsw_sp_port_bitmap_init(struct mlxsw_sp *mlxsw_sp,
  355. struct mlxsw_sp_ports_bitmap *ports_bm)
  356. {
  357. unsigned int nbits = mlxsw_core_max_ports(mlxsw_sp->core);
  358. ports_bm->nbits = nbits;
  359. ports_bm->bitmap = bitmap_zalloc(nbits, GFP_KERNEL);
  360. if (!ports_bm->bitmap)
  361. return -ENOMEM;
  362. return 0;
  363. }
  364. static inline void
  365. mlxsw_sp_port_bitmap_fini(struct mlxsw_sp_ports_bitmap *ports_bm)
  366. {
  367. bitmap_free(ports_bm->bitmap);
  368. }
  369. static inline u8 mlxsw_sp_tunnel_ecn_decap(u8 outer_ecn, u8 inner_ecn,
  370. bool *trap_en)
  371. {
  372. bool set_ce = false;
  373. *trap_en = !!__INET_ECN_decapsulate(outer_ecn, inner_ecn, &set_ce);
  374. if (set_ce)
  375. return INET_ECN_CE;
  376. else if (outer_ecn == INET_ECN_ECT_1 && inner_ecn == INET_ECN_ECT_0)
  377. return INET_ECN_ECT_1;
  378. else
  379. return inner_ecn;
  380. }
  381. static inline struct net_device *
  382. mlxsw_sp_bridge_vxlan_dev_find(struct net_device *br_dev)
  383. {
  384. struct net_device *dev;
  385. struct list_head *iter;
  386. netdev_for_each_lower_dev(br_dev, dev, iter) {
  387. if (netif_is_vxlan(dev))
  388. return dev;
  389. }
  390. return NULL;
  391. }
  392. static inline bool mlxsw_sp_bridge_has_vxlan(struct net_device *br_dev)
  393. {
  394. return !!mlxsw_sp_bridge_vxlan_dev_find(br_dev);
  395. }
  396. static inline int
  397. mlxsw_sp_vxlan_mapped_vid(const struct net_device *vxlan_dev, u16 *p_vid)
  398. {
  399. struct bridge_vlan_info vinfo;
  400. u16 vid = 0;
  401. int err;
  402. err = br_vlan_get_pvid(vxlan_dev, &vid);
  403. if (err || !vid)
  404. goto out;
  405. err = br_vlan_get_info(vxlan_dev, vid, &vinfo);
  406. if (err || !(vinfo.flags & BRIDGE_VLAN_INFO_UNTAGGED))
  407. vid = 0;
  408. out:
  409. *p_vid = vid;
  410. return err;
  411. }
  412. static inline bool
  413. mlxsw_sp_port_is_pause_en(const struct mlxsw_sp_port *mlxsw_sp_port)
  414. {
  415. return mlxsw_sp_port->link.tx_pause || mlxsw_sp_port->link.rx_pause;
  416. }
  417. static inline struct mlxsw_sp_port *
  418. mlxsw_sp_port_lagged_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id, u8 port_index)
  419. {
  420. struct mlxsw_sp_port *mlxsw_sp_port;
  421. u16 local_port;
  422. local_port = mlxsw_core_lag_mapping_get(mlxsw_sp->core,
  423. lag_id, port_index);
  424. mlxsw_sp_port = mlxsw_sp->ports[local_port];
  425. return mlxsw_sp_port && mlxsw_sp_port->lagged ? mlxsw_sp_port : NULL;
  426. }
  427. static inline struct mlxsw_sp_port_vlan *
  428. mlxsw_sp_port_vlan_find_by_vid(const struct mlxsw_sp_port *mlxsw_sp_port,
  429. u16 vid)
  430. {
  431. struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
  432. list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
  433. list) {
  434. if (mlxsw_sp_port_vlan->vid == vid)
  435. return mlxsw_sp_port_vlan;
  436. }
  437. return NULL;
  438. }
  439. enum mlxsw_sp_flood_type {
  440. MLXSW_SP_FLOOD_TYPE_UC,
  441. MLXSW_SP_FLOOD_TYPE_BC,
  442. MLXSW_SP_FLOOD_TYPE_MC,
  443. };
  444. int mlxsw_sp_port_get_stats_raw(struct net_device *dev, int grp,
  445. int prio, char *ppcnt_pl);
  446. int mlxsw_sp_port_admin_status_set(struct mlxsw_sp_port *mlxsw_sp_port,
  447. bool is_up);
  448. int
  449. mlxsw_sp_port_vlan_classification_set(struct mlxsw_sp_port *mlxsw_sp_port,
  450. bool is_8021ad_tagged,
  451. bool is_8021q_tagged);
  452. static inline bool
  453. mlxsw_sp_local_port_is_valid(struct mlxsw_sp *mlxsw_sp, u16 local_port)
  454. {
  455. unsigned int max_ports = mlxsw_core_max_ports(mlxsw_sp->core);
  456. return local_port < max_ports && local_port;
  457. }
  458. /* spectrum_buffers.c */
  459. struct mlxsw_sp_hdroom_prio {
  460. /* Number of port buffer associated with this priority. This is the
  461. * actually configured value.
  462. */
  463. u8 buf_idx;
  464. /* Value of buf_idx deduced from the DCB ETS configuration. */
  465. u8 ets_buf_idx;
  466. /* Value of buf_idx taken from the dcbnl_setbuffer configuration. */
  467. u8 set_buf_idx;
  468. bool lossy;
  469. };
  470. struct mlxsw_sp_hdroom_buf {
  471. u32 thres_cells;
  472. u32 size_cells;
  473. /* Size requirement form dcbnl_setbuffer. */
  474. u32 set_size_cells;
  475. bool lossy;
  476. };
  477. enum mlxsw_sp_hdroom_mode {
  478. MLXSW_SP_HDROOM_MODE_DCB,
  479. MLXSW_SP_HDROOM_MODE_TC,
  480. };
  481. #define MLXSW_SP_PB_COUNT 10
  482. struct mlxsw_sp_hdroom {
  483. enum mlxsw_sp_hdroom_mode mode;
  484. struct {
  485. struct mlxsw_sp_hdroom_prio prio[IEEE_8021Q_MAX_PRIORITIES];
  486. } prios;
  487. struct {
  488. struct mlxsw_sp_hdroom_buf buf[MLXSW_SP_PB_COUNT];
  489. } bufs;
  490. struct {
  491. /* Size actually configured for the internal buffer. Equal to
  492. * reserve when internal buffer is enabled.
  493. */
  494. u32 size_cells;
  495. /* Space reserved in the headroom for the internal buffer. Port
  496. * buffers are not allowed to grow into this space.
  497. */
  498. u32 reserve_cells;
  499. bool enable;
  500. } int_buf;
  501. int delay_bytes;
  502. int mtu;
  503. };
  504. int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp);
  505. void mlxsw_sp_buffers_fini(struct mlxsw_sp *mlxsw_sp);
  506. int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port);
  507. void mlxsw_sp_port_buffers_fini(struct mlxsw_sp_port *mlxsw_sp_port);
  508. int mlxsw_sp_sb_pool_get(struct mlxsw_core *mlxsw_core,
  509. unsigned int sb_index, u16 pool_index,
  510. struct devlink_sb_pool_info *pool_info);
  511. int mlxsw_sp_sb_pool_set(struct mlxsw_core *mlxsw_core,
  512. unsigned int sb_index, u16 pool_index, u32 size,
  513. enum devlink_sb_threshold_type threshold_type,
  514. struct netlink_ext_ack *extack);
  515. int mlxsw_sp_sb_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
  516. unsigned int sb_index, u16 pool_index,
  517. u32 *p_threshold);
  518. int mlxsw_sp_sb_port_pool_set(struct mlxsw_core_port *mlxsw_core_port,
  519. unsigned int sb_index, u16 pool_index,
  520. u32 threshold, struct netlink_ext_ack *extack);
  521. int mlxsw_sp_sb_tc_pool_bind_get(struct mlxsw_core_port *mlxsw_core_port,
  522. unsigned int sb_index, u16 tc_index,
  523. enum devlink_sb_pool_type pool_type,
  524. u16 *p_pool_index, u32 *p_threshold);
  525. int mlxsw_sp_sb_tc_pool_bind_set(struct mlxsw_core_port *mlxsw_core_port,
  526. unsigned int sb_index, u16 tc_index,
  527. enum devlink_sb_pool_type pool_type,
  528. u16 pool_index, u32 threshold,
  529. struct netlink_ext_ack *extack);
  530. int mlxsw_sp_sb_occ_snapshot(struct mlxsw_core *mlxsw_core,
  531. unsigned int sb_index);
  532. int mlxsw_sp_sb_occ_max_clear(struct mlxsw_core *mlxsw_core,
  533. unsigned int sb_index);
  534. int mlxsw_sp_sb_occ_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
  535. unsigned int sb_index, u16 pool_index,
  536. u32 *p_cur, u32 *p_max);
  537. int mlxsw_sp_sb_occ_tc_port_bind_get(struct mlxsw_core_port *mlxsw_core_port,
  538. unsigned int sb_index, u16 tc_index,
  539. enum devlink_sb_pool_type pool_type,
  540. u32 *p_cur, u32 *p_max);
  541. u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells);
  542. u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes);
  543. void mlxsw_sp_hdroom_prios_reset_buf_idx(struct mlxsw_sp_hdroom *hdroom);
  544. void mlxsw_sp_hdroom_bufs_reset_lossiness(struct mlxsw_sp_hdroom *hdroom);
  545. void mlxsw_sp_hdroom_bufs_reset_sizes(struct mlxsw_sp_port *mlxsw_sp_port,
  546. struct mlxsw_sp_hdroom *hdroom);
  547. int mlxsw_sp_hdroom_configure(struct mlxsw_sp_port *mlxsw_sp_port,
  548. const struct mlxsw_sp_hdroom *hdroom);
  549. struct mlxsw_sp_sample_params *
  550. mlxsw_sp_sample_trigger_params_lookup(struct mlxsw_sp *mlxsw_sp,
  551. const struct mlxsw_sp_sample_trigger *trigger);
  552. int
  553. mlxsw_sp_sample_trigger_params_set(struct mlxsw_sp *mlxsw_sp,
  554. const struct mlxsw_sp_sample_trigger *trigger,
  555. const struct mlxsw_sp_sample_params *params,
  556. struct netlink_ext_ack *extack);
  557. void
  558. mlxsw_sp_sample_trigger_params_unset(struct mlxsw_sp *mlxsw_sp,
  559. const struct mlxsw_sp_sample_trigger *trigger);
  560. int mlxsw_sp_ipv6_addr_kvdl_index_get(struct mlxsw_sp *mlxsw_sp,
  561. const struct in6_addr *addr6,
  562. u32 *p_kvdl_index);
  563. void
  564. mlxsw_sp_ipv6_addr_put(struct mlxsw_sp *mlxsw_sp, const struct in6_addr *addr6);
  565. extern const struct mlxsw_sp_sb_vals mlxsw_sp1_sb_vals;
  566. extern const struct mlxsw_sp_sb_vals mlxsw_sp2_sb_vals;
  567. extern const struct mlxsw_sp_sb_ops mlxsw_sp1_sb_ops;
  568. extern const struct mlxsw_sp_sb_ops mlxsw_sp2_sb_ops;
  569. extern const struct mlxsw_sp_sb_ops mlxsw_sp3_sb_ops;
  570. /* spectrum_switchdev.c */
  571. int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp);
  572. void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp);
  573. int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
  574. bool adding);
  575. void
  576. mlxsw_sp_port_vlan_bridge_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
  577. int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port,
  578. struct net_device *brport_dev,
  579. struct net_device *br_dev,
  580. struct netlink_ext_ack *extack);
  581. void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port,
  582. struct net_device *brport_dev,
  583. struct net_device *br_dev);
  584. bool mlxsw_sp_bridge_device_is_offloaded(const struct mlxsw_sp *mlxsw_sp,
  585. const struct net_device *br_dev);
  586. int mlxsw_sp_bridge_vxlan_join(struct mlxsw_sp *mlxsw_sp,
  587. const struct net_device *br_dev,
  588. const struct net_device *vxlan_dev, u16 vid,
  589. struct netlink_ext_ack *extack);
  590. void mlxsw_sp_bridge_vxlan_leave(struct mlxsw_sp *mlxsw_sp,
  591. const struct net_device *vxlan_dev);
  592. extern struct notifier_block mlxsw_sp_switchdev_notifier;
  593. /* spectrum.c */
  594. void mlxsw_sp_rx_listener_no_mark_func(struct sk_buff *skb,
  595. u16 local_port, void *priv);
  596. void mlxsw_sp_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
  597. u16 local_port);
  598. int mlxsw_sp_port_speed_get(struct mlxsw_sp_port *mlxsw_sp_port, u32 *speed);
  599. int mlxsw_sp_port_ets_set(struct mlxsw_sp_port *mlxsw_sp_port,
  600. enum mlxsw_reg_qeec_hr hr, u8 index, u8 next_index,
  601. bool dwrr, u8 dwrr_weight);
  602. int mlxsw_sp_port_prio_tc_set(struct mlxsw_sp_port *mlxsw_sp_port,
  603. u8 switch_prio, u8 tclass);
  604. int mlxsw_sp_port_ets_maxrate_set(struct mlxsw_sp_port *mlxsw_sp_port,
  605. enum mlxsw_reg_qeec_hr hr, u8 index,
  606. u8 next_index, u32 maxrate, u8 burst_size);
  607. enum mlxsw_reg_spms_state mlxsw_sp_stp_spms_state(u8 stp_state);
  608. int mlxsw_sp_port_vid_stp_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
  609. u8 state);
  610. int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, bool enable);
  611. int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
  612. bool learn_enable);
  613. int mlxsw_sp_ethtype_to_sver_type(u16 ethtype, u8 *p_sver_type);
  614. int mlxsw_sp_port_egress_ethtype_set(struct mlxsw_sp_port *mlxsw_sp_port,
  615. u16 ethtype);
  616. int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
  617. u16 ethtype);
  618. struct mlxsw_sp_port_vlan *
  619. mlxsw_sp_port_vlan_create(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
  620. void mlxsw_sp_port_vlan_destroy(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
  621. int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
  622. u16 vid_end, bool is_member, bool untagged);
  623. int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
  624. unsigned int counter_index, u64 *packets,
  625. u64 *bytes);
  626. int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp,
  627. unsigned int *p_counter_index);
  628. void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp,
  629. unsigned int counter_index);
  630. void mlxsw_sp_txhdr_construct(struct sk_buff *skb,
  631. const struct mlxsw_tx_info *tx_info);
  632. int mlxsw_sp_txhdr_ptp_data_construct(struct mlxsw_core *mlxsw_core,
  633. struct mlxsw_sp_port *mlxsw_sp_port,
  634. struct sk_buff *skb,
  635. const struct mlxsw_tx_info *tx_info);
  636. bool mlxsw_sp_port_dev_check(const struct net_device *dev);
  637. struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev);
  638. struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev);
  639. struct mlxsw_sp_port *mlxsw_sp_port_lower_dev_hold(struct net_device *dev);
  640. void mlxsw_sp_port_dev_put(struct mlxsw_sp_port *mlxsw_sp_port);
  641. struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find_rcu(struct net_device *dev);
  642. int mlxsw_sp_parsing_depth_inc(struct mlxsw_sp *mlxsw_sp);
  643. void mlxsw_sp_parsing_depth_dec(struct mlxsw_sp *mlxsw_sp);
  644. int mlxsw_sp_parsing_vxlan_udp_dport_set(struct mlxsw_sp *mlxsw_sp,
  645. __be16 udp_dport);
  646. /* spectrum_dcb.c */
  647. #ifdef CONFIG_MLXSW_SPECTRUM_DCB
  648. int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port);
  649. void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port);
  650. #else
  651. static inline int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port)
  652. {
  653. return 0;
  654. }
  655. static inline void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port)
  656. {}
  657. #endif
  658. /* spectrum_router.c */
  659. enum mlxsw_sp_l3proto {
  660. MLXSW_SP_L3_PROTO_IPV4,
  661. MLXSW_SP_L3_PROTO_IPV6,
  662. #define MLXSW_SP_L3_PROTO_MAX (MLXSW_SP_L3_PROTO_IPV6 + 1)
  663. };
  664. union mlxsw_sp_l3addr {
  665. __be32 addr4;
  666. struct in6_addr addr6;
  667. };
  668. u16 mlxsw_sp_rif_index(const struct mlxsw_sp_rif *rif);
  669. int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp,
  670. struct netlink_ext_ack *extack);
  671. void mlxsw_sp_router_fini(struct mlxsw_sp *mlxsw_sp);
  672. void mlxsw_sp_rif_macvlan_del(struct mlxsw_sp *mlxsw_sp,
  673. const struct net_device *macvlan_dev);
  674. int mlxsw_sp_inetaddr_valid_event(struct notifier_block *unused,
  675. unsigned long event, void *ptr);
  676. int mlxsw_sp_inet6addr_valid_event(struct notifier_block *unused,
  677. unsigned long event, void *ptr);
  678. int
  679. mlxsw_sp_port_vlan_router_join(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan,
  680. struct net_device *l3_dev,
  681. struct netlink_ext_ack *extack);
  682. void
  683. mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
  684. void mlxsw_sp_rif_destroy_by_dev(struct mlxsw_sp *mlxsw_sp,
  685. struct net_device *dev);
  686. bool mlxsw_sp_rif_exists(struct mlxsw_sp *mlxsw_sp,
  687. const struct net_device *dev);
  688. u16 mlxsw_sp_rif_vid(struct mlxsw_sp *mlxsw_sp, const struct net_device *dev);
  689. u16 mlxsw_sp_router_port(const struct mlxsw_sp *mlxsw_sp);
  690. int mlxsw_sp_router_nve_promote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
  691. enum mlxsw_sp_l3proto ul_proto,
  692. const union mlxsw_sp_l3addr *ul_sip,
  693. u32 tunnel_index);
  694. void mlxsw_sp_router_nve_demote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
  695. enum mlxsw_sp_l3proto ul_proto,
  696. const union mlxsw_sp_l3addr *ul_sip);
  697. int mlxsw_sp_router_tb_id_vr_id(struct mlxsw_sp *mlxsw_sp, u32 tb_id,
  698. u16 *vr_id);
  699. int mlxsw_sp_router_ul_rif_get(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
  700. u16 *ul_rif_index);
  701. void mlxsw_sp_router_ul_rif_put(struct mlxsw_sp *mlxsw_sp, u16 ul_rif_index);
  702. /* spectrum_kvdl.c */
  703. enum mlxsw_sp_kvdl_entry_type {
  704. MLXSW_SP_KVDL_ENTRY_TYPE_ADJ,
  705. MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET,
  706. MLXSW_SP_KVDL_ENTRY_TYPE_PBS,
  707. MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR,
  708. MLXSW_SP_KVDL_ENTRY_TYPE_IPV6_ADDRESS,
  709. MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT,
  710. };
  711. static inline unsigned int
  712. mlxsw_sp_kvdl_entry_size(enum mlxsw_sp_kvdl_entry_type type)
  713. {
  714. switch (type) {
  715. case MLXSW_SP_KVDL_ENTRY_TYPE_ADJ:
  716. case MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET:
  717. case MLXSW_SP_KVDL_ENTRY_TYPE_PBS:
  718. case MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR:
  719. case MLXSW_SP_KVDL_ENTRY_TYPE_IPV6_ADDRESS:
  720. case MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT:
  721. default:
  722. return 1;
  723. }
  724. }
  725. struct mlxsw_sp_kvdl_ops {
  726. size_t priv_size;
  727. int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
  728. void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
  729. int (*alloc)(struct mlxsw_sp *mlxsw_sp, void *priv,
  730. enum mlxsw_sp_kvdl_entry_type type,
  731. unsigned int entry_count, u32 *p_entry_index);
  732. void (*free)(struct mlxsw_sp *mlxsw_sp, void *priv,
  733. enum mlxsw_sp_kvdl_entry_type type,
  734. unsigned int entry_count, int entry_index);
  735. int (*alloc_size_query)(struct mlxsw_sp *mlxsw_sp, void *priv,
  736. enum mlxsw_sp_kvdl_entry_type type,
  737. unsigned int entry_count,
  738. unsigned int *p_alloc_count);
  739. int (*resources_register)(struct mlxsw_sp *mlxsw_sp, void *priv);
  740. };
  741. int mlxsw_sp_kvdl_init(struct mlxsw_sp *mlxsw_sp);
  742. void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp);
  743. int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp,
  744. enum mlxsw_sp_kvdl_entry_type type,
  745. unsigned int entry_count, u32 *p_entry_index);
  746. void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp,
  747. enum mlxsw_sp_kvdl_entry_type type,
  748. unsigned int entry_count, int entry_index);
  749. int mlxsw_sp_kvdl_alloc_count_query(struct mlxsw_sp *mlxsw_sp,
  750. enum mlxsw_sp_kvdl_entry_type type,
  751. unsigned int entry_count,
  752. unsigned int *p_alloc_count);
  753. /* spectrum1_kvdl.c */
  754. extern const struct mlxsw_sp_kvdl_ops mlxsw_sp1_kvdl_ops;
  755. int mlxsw_sp1_kvdl_resources_register(struct mlxsw_core *mlxsw_core);
  756. /* spectrum2_kvdl.c */
  757. extern const struct mlxsw_sp_kvdl_ops mlxsw_sp2_kvdl_ops;
  758. enum mlxsw_sp_acl_mangle_field {
  759. MLXSW_SP_ACL_MANGLE_FIELD_IP_DSFIELD,
  760. MLXSW_SP_ACL_MANGLE_FIELD_IP_DSCP,
  761. MLXSW_SP_ACL_MANGLE_FIELD_IP_ECN,
  762. MLXSW_SP_ACL_MANGLE_FIELD_IP_SPORT,
  763. MLXSW_SP_ACL_MANGLE_FIELD_IP_DPORT,
  764. MLXSW_SP_ACL_MANGLE_FIELD_IP4_SIP,
  765. MLXSW_SP_ACL_MANGLE_FIELD_IP4_DIP,
  766. MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_1,
  767. MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_2,
  768. MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_3,
  769. MLXSW_SP_ACL_MANGLE_FIELD_IP6_SIP_4,
  770. MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_1,
  771. MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_2,
  772. MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_3,
  773. MLXSW_SP_ACL_MANGLE_FIELD_IP6_DIP_4,
  774. };
  775. struct mlxsw_sp_acl_rule_info {
  776. unsigned int priority;
  777. struct mlxsw_afk_element_values values;
  778. struct mlxsw_afa_block *act_block;
  779. u8 action_created:1,
  780. ingress_bind_blocker:1,
  781. egress_bind_blocker:1,
  782. counter_valid:1,
  783. policer_index_valid:1,
  784. ipv6_valid:1;
  785. unsigned int counter_index;
  786. u16 policer_index;
  787. struct {
  788. u32 prev_val;
  789. enum mlxsw_sp_acl_mangle_field prev_field;
  790. } ipv6;
  791. };
  792. /* spectrum_flow.c */
  793. struct mlxsw_sp_flow_block {
  794. struct list_head binding_list;
  795. struct {
  796. struct list_head list;
  797. unsigned int min_prio;
  798. unsigned int max_prio;
  799. } mall;
  800. struct mlxsw_sp_acl_ruleset *ruleset_zero;
  801. struct mlxsw_sp *mlxsw_sp;
  802. unsigned int rule_count;
  803. unsigned int disable_count;
  804. unsigned int ingress_blocker_rule_count;
  805. unsigned int egress_blocker_rule_count;
  806. unsigned int ingress_binding_count;
  807. unsigned int egress_binding_count;
  808. struct net *net;
  809. };
  810. struct mlxsw_sp_flow_block_binding {
  811. struct list_head list;
  812. struct mlxsw_sp_port *mlxsw_sp_port;
  813. bool ingress;
  814. };
  815. static inline struct mlxsw_sp *
  816. mlxsw_sp_flow_block_mlxsw_sp(struct mlxsw_sp_flow_block *block)
  817. {
  818. return block->mlxsw_sp;
  819. }
  820. static inline unsigned int
  821. mlxsw_sp_flow_block_rule_count(const struct mlxsw_sp_flow_block *block)
  822. {
  823. return block ? block->rule_count : 0;
  824. }
  825. static inline void
  826. mlxsw_sp_flow_block_disable_inc(struct mlxsw_sp_flow_block *block)
  827. {
  828. if (block)
  829. block->disable_count++;
  830. }
  831. static inline void
  832. mlxsw_sp_flow_block_disable_dec(struct mlxsw_sp_flow_block *block)
  833. {
  834. if (block)
  835. block->disable_count--;
  836. }
  837. static inline bool
  838. mlxsw_sp_flow_block_disabled(const struct mlxsw_sp_flow_block *block)
  839. {
  840. return block->disable_count;
  841. }
  842. static inline bool
  843. mlxsw_sp_flow_block_is_egress_bound(const struct mlxsw_sp_flow_block *block)
  844. {
  845. return block->egress_binding_count;
  846. }
  847. static inline bool
  848. mlxsw_sp_flow_block_is_ingress_bound(const struct mlxsw_sp_flow_block *block)
  849. {
  850. return block->ingress_binding_count;
  851. }
  852. static inline bool
  853. mlxsw_sp_flow_block_is_mixed_bound(const struct mlxsw_sp_flow_block *block)
  854. {
  855. return block->ingress_binding_count && block->egress_binding_count;
  856. }
  857. struct mlxsw_sp_flow_block *mlxsw_sp_flow_block_create(struct mlxsw_sp *mlxsw_sp,
  858. struct net *net);
  859. void mlxsw_sp_flow_block_destroy(struct mlxsw_sp_flow_block *block);
  860. int mlxsw_sp_setup_tc_block_clsact(struct mlxsw_sp_port *mlxsw_sp_port,
  861. struct flow_block_offload *f,
  862. bool ingress);
  863. /* spectrum_acl.c */
  864. struct mlxsw_sp_acl_ruleset;
  865. enum mlxsw_sp_acl_profile {
  866. MLXSW_SP_ACL_PROFILE_FLOWER,
  867. MLXSW_SP_ACL_PROFILE_MR,
  868. };
  869. struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl);
  870. int mlxsw_sp_acl_ruleset_bind(struct mlxsw_sp *mlxsw_sp,
  871. struct mlxsw_sp_flow_block *block,
  872. struct mlxsw_sp_flow_block_binding *binding);
  873. void mlxsw_sp_acl_ruleset_unbind(struct mlxsw_sp *mlxsw_sp,
  874. struct mlxsw_sp_flow_block *block,
  875. struct mlxsw_sp_flow_block_binding *binding);
  876. struct mlxsw_sp_acl_ruleset *
  877. mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp,
  878. struct mlxsw_sp_flow_block *block, u32 chain_index,
  879. enum mlxsw_sp_acl_profile profile);
  880. struct mlxsw_sp_acl_ruleset *
  881. mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
  882. struct mlxsw_sp_flow_block *block, u32 chain_index,
  883. enum mlxsw_sp_acl_profile profile,
  884. struct mlxsw_afk_element_usage *tmplt_elusage);
  885. void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
  886. struct mlxsw_sp_acl_ruleset *ruleset);
  887. u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset);
  888. void mlxsw_sp_acl_ruleset_prio_get(struct mlxsw_sp_acl_ruleset *ruleset,
  889. unsigned int *p_min_prio,
  890. unsigned int *p_max_prio);
  891. struct mlxsw_sp_acl_rule_info *
  892. mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl,
  893. struct mlxsw_afa_block *afa_block);
  894. void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei);
  895. int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei);
  896. void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei,
  897. unsigned int priority);
  898. void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei,
  899. enum mlxsw_afk_element element,
  900. u32 key_value, u32 mask_value);
  901. void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei,
  902. enum mlxsw_afk_element element,
  903. const char *key_value,
  904. const char *mask_value, unsigned int len);
  905. int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei);
  906. int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
  907. u16 group_id);
  908. int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei);
  909. int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei,
  910. bool ingress,
  911. const struct flow_action_cookie *fa_cookie,
  912. struct netlink_ext_ack *extack);
  913. int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei);
  914. int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp,
  915. struct mlxsw_sp_acl_rule_info *rulei,
  916. struct mlxsw_sp_flow_block *block,
  917. struct net_device *out_dev,
  918. struct netlink_ext_ack *extack);
  919. int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp,
  920. struct mlxsw_sp_acl_rule_info *rulei,
  921. struct net_device *out_dev,
  922. struct netlink_ext_ack *extack);
  923. int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp,
  924. struct mlxsw_sp_acl_rule_info *rulei,
  925. u32 action, u16 vid, u16 proto, u8 prio,
  926. struct netlink_ext_ack *extack);
  927. int mlxsw_sp_acl_rulei_act_priority(struct mlxsw_sp *mlxsw_sp,
  928. struct mlxsw_sp_acl_rule_info *rulei,
  929. u32 prio, struct netlink_ext_ack *extack);
  930. int mlxsw_sp_acl_rulei_act_mangle(struct mlxsw_sp *mlxsw_sp,
  931. struct mlxsw_sp_acl_rule_info *rulei,
  932. enum flow_action_mangle_base htype,
  933. u32 offset, u32 mask, u32 val,
  934. struct netlink_ext_ack *extack);
  935. int mlxsw_sp_acl_rulei_act_police(struct mlxsw_sp *mlxsw_sp,
  936. struct mlxsw_sp_acl_rule_info *rulei,
  937. u32 index, u64 rate_bytes_ps,
  938. u32 burst, struct netlink_ext_ack *extack);
  939. int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
  940. struct mlxsw_sp_acl_rule_info *rulei,
  941. struct netlink_ext_ack *extack);
  942. int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
  943. struct mlxsw_sp_acl_rule_info *rulei,
  944. u16 fid, struct netlink_ext_ack *extack);
  945. int mlxsw_sp_acl_rulei_act_sample(struct mlxsw_sp *mlxsw_sp,
  946. struct mlxsw_sp_acl_rule_info *rulei,
  947. struct mlxsw_sp_flow_block *block,
  948. struct psample_group *psample_group, u32 rate,
  949. u32 trunc_size, bool truncate,
  950. struct netlink_ext_ack *extack);
  951. struct mlxsw_sp_acl_rule;
  952. struct mlxsw_sp_acl_rule *
  953. mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,
  954. struct mlxsw_sp_acl_ruleset *ruleset,
  955. unsigned long cookie,
  956. struct mlxsw_afa_block *afa_block,
  957. struct netlink_ext_ack *extack);
  958. void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp,
  959. struct mlxsw_sp_acl_rule *rule);
  960. int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp,
  961. struct mlxsw_sp_acl_rule *rule);
  962. void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp,
  963. struct mlxsw_sp_acl_rule *rule);
  964. int mlxsw_sp_acl_rule_action_replace(struct mlxsw_sp *mlxsw_sp,
  965. struct mlxsw_sp_acl_rule *rule,
  966. struct mlxsw_afa_block *afa_block);
  967. struct mlxsw_sp_acl_rule *
  968. mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp,
  969. struct mlxsw_sp_acl_ruleset *ruleset,
  970. unsigned long cookie);
  971. struct mlxsw_sp_acl_rule_info *
  972. mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule);
  973. int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
  974. struct mlxsw_sp_acl_rule *rule,
  975. u64 *packets, u64 *bytes, u64 *drops,
  976. u64 *last_use,
  977. enum flow_action_hw_stats *used_hw_stats);
  978. struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp);
  979. static inline const struct flow_action_cookie *
  980. mlxsw_sp_acl_act_cookie_lookup(struct mlxsw_sp *mlxsw_sp, u32 cookie_index)
  981. {
  982. return mlxsw_afa_cookie_lookup(mlxsw_sp->afa, cookie_index);
  983. }
  984. int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp);
  985. void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);
  986. u32 mlxsw_sp_acl_region_rehash_intrvl_get(struct mlxsw_sp *mlxsw_sp);
  987. int mlxsw_sp_acl_region_rehash_intrvl_set(struct mlxsw_sp *mlxsw_sp, u32 val);
  988. struct mlxsw_sp_acl_mangle_action;
  989. struct mlxsw_sp_acl_rulei_ops {
  990. int (*act_mangle_field)(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_rule_info *rulei,
  991. struct mlxsw_sp_acl_mangle_action *mact, u32 val,
  992. struct netlink_ext_ack *extack);
  993. };
  994. extern struct mlxsw_sp_acl_rulei_ops mlxsw_sp1_acl_rulei_ops;
  995. extern struct mlxsw_sp_acl_rulei_ops mlxsw_sp2_acl_rulei_ops;
  996. /* spectrum_acl_tcam.c */
  997. struct mlxsw_sp_acl_tcam;
  998. struct mlxsw_sp_acl_tcam_region;
  999. struct mlxsw_sp_acl_tcam_ops {
  1000. enum mlxsw_reg_ptar_key_type key_type;
  1001. size_t priv_size;
  1002. int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv,
  1003. struct mlxsw_sp_acl_tcam *tcam);
  1004. void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
  1005. size_t region_priv_size;
  1006. int (*region_init)(struct mlxsw_sp *mlxsw_sp, void *region_priv,
  1007. void *tcam_priv,
  1008. struct mlxsw_sp_acl_tcam_region *region,
  1009. void *hints_priv);
  1010. void (*region_fini)(struct mlxsw_sp *mlxsw_sp, void *region_priv);
  1011. int (*region_associate)(struct mlxsw_sp *mlxsw_sp,
  1012. struct mlxsw_sp_acl_tcam_region *region);
  1013. void * (*region_rehash_hints_get)(void *region_priv);
  1014. void (*region_rehash_hints_put)(void *hints_priv);
  1015. size_t chunk_priv_size;
  1016. void (*chunk_init)(void *region_priv, void *chunk_priv,
  1017. unsigned int priority);
  1018. void (*chunk_fini)(void *chunk_priv);
  1019. size_t entry_priv_size;
  1020. int (*entry_add)(struct mlxsw_sp *mlxsw_sp,
  1021. void *region_priv, void *chunk_priv,
  1022. void *entry_priv,
  1023. struct mlxsw_sp_acl_rule_info *rulei);
  1024. void (*entry_del)(struct mlxsw_sp *mlxsw_sp,
  1025. void *region_priv, void *chunk_priv,
  1026. void *entry_priv);
  1027. int (*entry_action_replace)(struct mlxsw_sp *mlxsw_sp,
  1028. void *region_priv, void *entry_priv,
  1029. struct mlxsw_sp_acl_rule_info *rulei);
  1030. int (*entry_activity_get)(struct mlxsw_sp *mlxsw_sp,
  1031. void *region_priv, void *entry_priv,
  1032. bool *activity);
  1033. };
  1034. /* spectrum1_acl_tcam.c */
  1035. extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp1_acl_tcam_ops;
  1036. /* spectrum2_acl_tcam.c */
  1037. extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp2_acl_tcam_ops;
  1038. /* spectrum_acl_flex_actions.c */
  1039. extern const struct mlxsw_afa_ops mlxsw_sp1_act_afa_ops;
  1040. extern const struct mlxsw_afa_ops mlxsw_sp2_act_afa_ops;
  1041. /* spectrum_acl_flex_keys.c */
  1042. extern const struct mlxsw_afk_ops mlxsw_sp1_afk_ops;
  1043. extern const struct mlxsw_afk_ops mlxsw_sp2_afk_ops;
  1044. extern const struct mlxsw_afk_ops mlxsw_sp4_afk_ops;
  1045. /* spectrum_acl_bloom_filter.c */
  1046. extern const struct mlxsw_sp_acl_bf_ops mlxsw_sp2_acl_bf_ops;
  1047. extern const struct mlxsw_sp_acl_bf_ops mlxsw_sp4_acl_bf_ops;
  1048. /* spectrum_matchall.c */
  1049. struct mlxsw_sp_mall_ops {
  1050. int (*sample_add)(struct mlxsw_sp *mlxsw_sp,
  1051. struct mlxsw_sp_port *mlxsw_sp_port,
  1052. struct mlxsw_sp_mall_entry *mall_entry,
  1053. struct netlink_ext_ack *extack);
  1054. void (*sample_del)(struct mlxsw_sp *mlxsw_sp,
  1055. struct mlxsw_sp_port *mlxsw_sp_port,
  1056. struct mlxsw_sp_mall_entry *mall_entry);
  1057. };
  1058. extern const struct mlxsw_sp_mall_ops mlxsw_sp1_mall_ops;
  1059. extern const struct mlxsw_sp_mall_ops mlxsw_sp2_mall_ops;
  1060. enum mlxsw_sp_mall_action_type {
  1061. MLXSW_SP_MALL_ACTION_TYPE_MIRROR,
  1062. MLXSW_SP_MALL_ACTION_TYPE_SAMPLE,
  1063. MLXSW_SP_MALL_ACTION_TYPE_TRAP,
  1064. };
  1065. struct mlxsw_sp_mall_mirror_entry {
  1066. const struct net_device *to_dev;
  1067. int span_id;
  1068. };
  1069. struct mlxsw_sp_mall_trap_entry {
  1070. int span_id;
  1071. };
  1072. struct mlxsw_sp_mall_sample_entry {
  1073. struct mlxsw_sp_sample_params params;
  1074. int span_id; /* Relevant for Spectrum-2 onwards. */
  1075. };
  1076. struct mlxsw_sp_mall_entry {
  1077. struct list_head list;
  1078. unsigned long cookie;
  1079. unsigned int priority;
  1080. enum mlxsw_sp_mall_action_type type;
  1081. bool ingress;
  1082. union {
  1083. struct mlxsw_sp_mall_mirror_entry mirror;
  1084. struct mlxsw_sp_mall_trap_entry trap;
  1085. struct mlxsw_sp_mall_sample_entry sample;
  1086. };
  1087. struct rcu_head rcu;
  1088. };
  1089. int mlxsw_sp_mall_replace(struct mlxsw_sp *mlxsw_sp,
  1090. struct mlxsw_sp_flow_block *block,
  1091. struct tc_cls_matchall_offload *f);
  1092. void mlxsw_sp_mall_destroy(struct mlxsw_sp_flow_block *block,
  1093. struct tc_cls_matchall_offload *f);
  1094. int mlxsw_sp_mall_port_bind(struct mlxsw_sp_flow_block *block,
  1095. struct mlxsw_sp_port *mlxsw_sp_port,
  1096. struct netlink_ext_ack *extack);
  1097. void mlxsw_sp_mall_port_unbind(struct mlxsw_sp_flow_block *block,
  1098. struct mlxsw_sp_port *mlxsw_sp_port);
  1099. int mlxsw_sp_mall_prio_get(struct mlxsw_sp_flow_block *block, u32 chain_index,
  1100. unsigned int *p_min_prio, unsigned int *p_max_prio);
  1101. /* spectrum_flower.c */
  1102. int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
  1103. struct mlxsw_sp_flow_block *block,
  1104. struct flow_cls_offload *f);
  1105. void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
  1106. struct mlxsw_sp_flow_block *block,
  1107. struct flow_cls_offload *f);
  1108. int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
  1109. struct mlxsw_sp_flow_block *block,
  1110. struct flow_cls_offload *f);
  1111. int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp,
  1112. struct mlxsw_sp_flow_block *block,
  1113. struct flow_cls_offload *f);
  1114. void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp,
  1115. struct mlxsw_sp_flow_block *block,
  1116. struct flow_cls_offload *f);
  1117. int mlxsw_sp_flower_prio_get(struct mlxsw_sp *mlxsw_sp,
  1118. struct mlxsw_sp_flow_block *block,
  1119. u32 chain_index, unsigned int *p_min_prio,
  1120. unsigned int *p_max_prio);
  1121. /* spectrum_qdisc.c */
  1122. int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port);
  1123. void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port);
  1124. int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
  1125. struct tc_red_qopt_offload *p);
  1126. int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port,
  1127. struct tc_prio_qopt_offload *p);
  1128. int mlxsw_sp_setup_tc_ets(struct mlxsw_sp_port *mlxsw_sp_port,
  1129. struct tc_ets_qopt_offload *p);
  1130. int mlxsw_sp_setup_tc_tbf(struct mlxsw_sp_port *mlxsw_sp_port,
  1131. struct tc_tbf_qopt_offload *p);
  1132. int mlxsw_sp_setup_tc_fifo(struct mlxsw_sp_port *mlxsw_sp_port,
  1133. struct tc_fifo_qopt_offload *p);
  1134. int mlxsw_sp_setup_tc_block_qevent_early_drop(struct mlxsw_sp_port *mlxsw_sp_port,
  1135. struct flow_block_offload *f);
  1136. int mlxsw_sp_setup_tc_block_qevent_mark(struct mlxsw_sp_port *mlxsw_sp_port,
  1137. struct flow_block_offload *f);
  1138. /* spectrum_fid.c */
  1139. bool mlxsw_sp_fid_is_dummy(struct mlxsw_sp *mlxsw_sp, u16 fid_index);
  1140. struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_index(struct mlxsw_sp *mlxsw_sp,
  1141. u16 fid_index);
  1142. int mlxsw_sp_fid_nve_ifindex(const struct mlxsw_sp_fid *fid, int *nve_ifindex);
  1143. int mlxsw_sp_fid_nve_type(const struct mlxsw_sp_fid *fid,
  1144. enum mlxsw_sp_nve_type *p_type);
  1145. struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_vni(struct mlxsw_sp *mlxsw_sp,
  1146. __be32 vni);
  1147. int mlxsw_sp_fid_vni(const struct mlxsw_sp_fid *fid, __be32 *vni);
  1148. int mlxsw_sp_fid_nve_flood_index_set(struct mlxsw_sp_fid *fid,
  1149. u32 nve_flood_index);
  1150. void mlxsw_sp_fid_nve_flood_index_clear(struct mlxsw_sp_fid *fid);
  1151. bool mlxsw_sp_fid_nve_flood_index_is_set(const struct mlxsw_sp_fid *fid);
  1152. int mlxsw_sp_fid_vni_set(struct mlxsw_sp_fid *fid, enum mlxsw_sp_nve_type type,
  1153. __be32 vni, int nve_ifindex);
  1154. void mlxsw_sp_fid_vni_clear(struct mlxsw_sp_fid *fid);
  1155. bool mlxsw_sp_fid_vni_is_set(const struct mlxsw_sp_fid *fid);
  1156. void mlxsw_sp_fid_fdb_clear_offload(const struct mlxsw_sp_fid *fid,
  1157. const struct net_device *nve_dev);
  1158. int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid,
  1159. enum mlxsw_sp_flood_type packet_type, u16 local_port,
  1160. bool member);
  1161. int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid,
  1162. struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
  1163. void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid,
  1164. struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
  1165. u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid);
  1166. enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid);
  1167. int mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif);
  1168. void mlxsw_sp_fid_rif_unset(struct mlxsw_sp_fid *fid);
  1169. struct mlxsw_sp_rif *mlxsw_sp_fid_rif(const struct mlxsw_sp_fid *fid);
  1170. enum mlxsw_sp_rif_type
  1171. mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp,
  1172. enum mlxsw_sp_fid_type type);
  1173. u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid);
  1174. struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid);
  1175. struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp,
  1176. int br_ifindex);
  1177. struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_lookup(struct mlxsw_sp *mlxsw_sp,
  1178. u16 vid);
  1179. struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_lookup(struct mlxsw_sp *mlxsw_sp,
  1180. int br_ifindex);
  1181. struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp,
  1182. u16 rif_index);
  1183. struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp);
  1184. void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid);
  1185. int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port);
  1186. void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port);
  1187. int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp);
  1188. void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp);
  1189. extern const struct mlxsw_sp_fid_family *mlxsw_sp1_fid_family_arr[];
  1190. extern const struct mlxsw_sp_fid_family *mlxsw_sp2_fid_family_arr[];
  1191. /* spectrum_mr.c */
  1192. enum mlxsw_sp_mr_route_prio {
  1193. MLXSW_SP_MR_ROUTE_PRIO_SG,
  1194. MLXSW_SP_MR_ROUTE_PRIO_STARG,
  1195. MLXSW_SP_MR_ROUTE_PRIO_CATCHALL,
  1196. __MLXSW_SP_MR_ROUTE_PRIO_MAX
  1197. };
  1198. #define MLXSW_SP_MR_ROUTE_PRIO_MAX (__MLXSW_SP_MR_ROUTE_PRIO_MAX - 1)
  1199. struct mlxsw_sp_mr_route_key;
  1200. struct mlxsw_sp_mr_tcam_ops {
  1201. size_t priv_size;
  1202. int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
  1203. void (*fini)(void *priv);
  1204. size_t route_priv_size;
  1205. int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv,
  1206. void *route_priv,
  1207. struct mlxsw_sp_mr_route_key *key,
  1208. struct mlxsw_afa_block *afa_block,
  1209. enum mlxsw_sp_mr_route_prio prio);
  1210. void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv,
  1211. void *route_priv,
  1212. struct mlxsw_sp_mr_route_key *key);
  1213. int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
  1214. struct mlxsw_sp_mr_route_key *key,
  1215. struct mlxsw_afa_block *afa_block);
  1216. };
  1217. /* spectrum1_mr_tcam.c */
  1218. extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp1_mr_tcam_ops;
  1219. /* spectrum2_mr_tcam.c */
  1220. extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp2_mr_tcam_ops;
  1221. /* spectrum_nve.c */
  1222. struct mlxsw_sp_nve_params {
  1223. enum mlxsw_sp_nve_type type;
  1224. __be32 vni;
  1225. const struct net_device *dev;
  1226. u16 ethertype;
  1227. };
  1228. extern const struct mlxsw_sp_nve_ops *mlxsw_sp1_nve_ops_arr[];
  1229. extern const struct mlxsw_sp_nve_ops *mlxsw_sp2_nve_ops_arr[];
  1230. int mlxsw_sp_nve_learned_ip_resolve(struct mlxsw_sp *mlxsw_sp, u32 uip,
  1231. enum mlxsw_sp_l3proto proto,
  1232. union mlxsw_sp_l3addr *addr);
  1233. int mlxsw_sp_nve_flood_ip_add(struct mlxsw_sp *mlxsw_sp,
  1234. struct mlxsw_sp_fid *fid,
  1235. enum mlxsw_sp_l3proto proto,
  1236. union mlxsw_sp_l3addr *addr);
  1237. void mlxsw_sp_nve_flood_ip_del(struct mlxsw_sp *mlxsw_sp,
  1238. struct mlxsw_sp_fid *fid,
  1239. enum mlxsw_sp_l3proto proto,
  1240. union mlxsw_sp_l3addr *addr);
  1241. int mlxsw_sp_nve_ipv6_addr_kvdl_set(struct mlxsw_sp *mlxsw_sp,
  1242. const struct in6_addr *addr6,
  1243. u32 *p_kvdl_index);
  1244. void mlxsw_sp_nve_ipv6_addr_kvdl_unset(struct mlxsw_sp *mlxsw_sp,
  1245. const struct in6_addr *addr6);
  1246. int
  1247. mlxsw_sp_nve_ipv6_addr_map_replace(struct mlxsw_sp *mlxsw_sp, const char *mac,
  1248. u16 fid_index,
  1249. const struct in6_addr *new_addr6);
  1250. void mlxsw_sp_nve_ipv6_addr_map_del(struct mlxsw_sp *mlxsw_sp, const char *mac,
  1251. u16 fid_index);
  1252. int mlxsw_sp_nve_fid_enable(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_fid *fid,
  1253. struct mlxsw_sp_nve_params *params,
  1254. struct netlink_ext_ack *extack);
  1255. void mlxsw_sp_nve_fid_disable(struct mlxsw_sp *mlxsw_sp,
  1256. struct mlxsw_sp_fid *fid);
  1257. int mlxsw_sp_port_nve_init(struct mlxsw_sp_port *mlxsw_sp_port);
  1258. void mlxsw_sp_port_nve_fini(struct mlxsw_sp_port *mlxsw_sp_port);
  1259. int mlxsw_sp_nve_init(struct mlxsw_sp *mlxsw_sp);
  1260. void mlxsw_sp_nve_fini(struct mlxsw_sp *mlxsw_sp);
  1261. /* spectrum_nve_vxlan.c */
  1262. int mlxsw_sp_nve_inc_parsing_depth_get(struct mlxsw_sp *mlxsw_sp);
  1263. void mlxsw_sp_nve_inc_parsing_depth_put(struct mlxsw_sp *mlxsw_sp);
  1264. /* spectrum_trap.c */
  1265. int mlxsw_sp_devlink_traps_init(struct mlxsw_sp *mlxsw_sp);
  1266. void mlxsw_sp_devlink_traps_fini(struct mlxsw_sp *mlxsw_sp);
  1267. int mlxsw_sp_trap_init(struct mlxsw_core *mlxsw_core,
  1268. const struct devlink_trap *trap, void *trap_ctx);
  1269. void mlxsw_sp_trap_fini(struct mlxsw_core *mlxsw_core,
  1270. const struct devlink_trap *trap, void *trap_ctx);
  1271. int mlxsw_sp_trap_action_set(struct mlxsw_core *mlxsw_core,
  1272. const struct devlink_trap *trap,
  1273. enum devlink_trap_action action,
  1274. struct netlink_ext_ack *extack);
  1275. int mlxsw_sp_trap_group_init(struct mlxsw_core *mlxsw_core,
  1276. const struct devlink_trap_group *group);
  1277. int mlxsw_sp_trap_group_set(struct mlxsw_core *mlxsw_core,
  1278. const struct devlink_trap_group *group,
  1279. const struct devlink_trap_policer *policer,
  1280. struct netlink_ext_ack *extack);
  1281. int
  1282. mlxsw_sp_trap_policer_init(struct mlxsw_core *mlxsw_core,
  1283. const struct devlink_trap_policer *policer);
  1284. void mlxsw_sp_trap_policer_fini(struct mlxsw_core *mlxsw_core,
  1285. const struct devlink_trap_policer *policer);
  1286. int
  1287. mlxsw_sp_trap_policer_set(struct mlxsw_core *mlxsw_core,
  1288. const struct devlink_trap_policer *policer,
  1289. u64 rate, u64 burst, struct netlink_ext_ack *extack);
  1290. int
  1291. mlxsw_sp_trap_policer_counter_get(struct mlxsw_core *mlxsw_core,
  1292. const struct devlink_trap_policer *policer,
  1293. u64 *p_drops);
  1294. int mlxsw_sp_trap_group_policer_hw_id_get(struct mlxsw_sp *mlxsw_sp, u16 id,
  1295. bool *p_enabled, u16 *p_hw_id);
  1296. static inline struct net *mlxsw_sp_net(struct mlxsw_sp *mlxsw_sp)
  1297. {
  1298. return mlxsw_core_net(mlxsw_sp->core);
  1299. }
  1300. /* spectrum_ethtool.c */
  1301. extern const struct ethtool_ops mlxsw_sp_port_ethtool_ops;
  1302. extern const struct mlxsw_sp_port_type_speed_ops mlxsw_sp1_port_type_speed_ops;
  1303. extern const struct mlxsw_sp_port_type_speed_ops mlxsw_sp2_port_type_speed_ops;
  1304. /* spectrum_policer.c */
  1305. extern const struct mlxsw_sp_policer_core_ops mlxsw_sp1_policer_core_ops;
  1306. extern const struct mlxsw_sp_policer_core_ops mlxsw_sp2_policer_core_ops;
  1307. enum mlxsw_sp_policer_type {
  1308. MLXSW_SP_POLICER_TYPE_SINGLE_RATE,
  1309. __MLXSW_SP_POLICER_TYPE_MAX,
  1310. MLXSW_SP_POLICER_TYPE_MAX = __MLXSW_SP_POLICER_TYPE_MAX - 1,
  1311. };
  1312. struct mlxsw_sp_policer_params {
  1313. u64 rate;
  1314. u64 burst;
  1315. bool bytes;
  1316. };
  1317. int mlxsw_sp_policer_add(struct mlxsw_sp *mlxsw_sp,
  1318. enum mlxsw_sp_policer_type type,
  1319. const struct mlxsw_sp_policer_params *params,
  1320. struct netlink_ext_ack *extack, u16 *p_policer_index);
  1321. void mlxsw_sp_policer_del(struct mlxsw_sp *mlxsw_sp,
  1322. enum mlxsw_sp_policer_type type,
  1323. u16 policer_index);
  1324. int mlxsw_sp_policer_drops_counter_get(struct mlxsw_sp *mlxsw_sp,
  1325. enum mlxsw_sp_policer_type type,
  1326. u16 policer_index, u64 *p_drops);
  1327. int mlxsw_sp_policers_init(struct mlxsw_sp *mlxsw_sp);
  1328. void mlxsw_sp_policers_fini(struct mlxsw_sp *mlxsw_sp);
  1329. int mlxsw_sp_policer_resources_register(struct mlxsw_core *mlxsw_core);
  1330. /* spectrum_pgt.c */
  1331. int mlxsw_sp_pgt_mid_alloc(struct mlxsw_sp *mlxsw_sp, u16 *p_mid);
  1332. void mlxsw_sp_pgt_mid_free(struct mlxsw_sp *mlxsw_sp, u16 mid_base);
  1333. int mlxsw_sp_pgt_mid_alloc_range(struct mlxsw_sp *mlxsw_sp, u16 mid_base,
  1334. u16 count);
  1335. void mlxsw_sp_pgt_mid_free_range(struct mlxsw_sp *mlxsw_sp, u16 mid_base,
  1336. u16 count);
  1337. int mlxsw_sp_pgt_entry_port_set(struct mlxsw_sp *mlxsw_sp, u16 mid,
  1338. u16 smpe, u16 local_port, bool member);
  1339. int mlxsw_sp_pgt_init(struct mlxsw_sp *mlxsw_sp);
  1340. void mlxsw_sp_pgt_fini(struct mlxsw_sp *mlxsw_sp);
  1341. #endif