1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * drivers/net/ethernet/rocker/rocker.h - Rocker switch device driver
4  * Copyright (c) 2014-2016 Jiri Pirko <jiri@mellanox.com>
5  * Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
6  */
7 
8 #ifndef _ROCKER_H
9 #define _ROCKER_H
10 
11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/netdevice.h>
14 #include <linux/notifier.h>
15 #include <net/neighbour.h>
16 #include <net/switchdev.h>
17 
18 #include "rocker_hw.h"
19 
20 struct rocker_desc_info {
21 	char *data; /* mapped */
22 	size_t data_size;
23 	size_t tlv_size;
24 	struct rocker_desc *desc;
25 	dma_addr_t mapaddr;
26 };
27 
28 struct rocker_dma_ring_info {
29 	size_t size;
30 	u32 head;
31 	u32 tail;
32 	struct rocker_desc *desc; /* mapped */
33 	dma_addr_t mapaddr;
34 	struct rocker_desc_info *desc_info;
35 	unsigned int type;
36 };
37 
38 struct rocker;
39 
40 struct rocker_port {
41 	struct net_device *dev;
42 	struct rocker *rocker;
43 	void *wpriv;
44 	unsigned int port_number;
45 	u32 pport;
46 	struct napi_struct napi_tx;
47 	struct napi_struct napi_rx;
48 	struct rocker_dma_ring_info tx_ring;
49 	struct rocker_dma_ring_info rx_ring;
50 };
51 
52 struct rocker_port *rocker_port_dev_lower_find(struct net_device *dev,
53 					       struct rocker *rocker);
54 
55 struct rocker_world_ops;
56 
57 struct rocker {
58 	struct pci_dev *pdev;
59 	u8 __iomem *hw_addr;
60 	struct msix_entry *msix_entries;
61 	unsigned int port_count;
62 	struct rocker_port **ports;
63 	struct {
64 		u64 id;
65 	} hw;
66 	spinlock_t cmd_ring_lock;		/* for cmd ring accesses */
67 	struct rocker_dma_ring_info cmd_ring;
68 	struct rocker_dma_ring_info event_ring;
69 	struct notifier_block fib_nb;
70 	struct rocker_world_ops *wops;
71 	struct workqueue_struct *rocker_owq;
72 	void *wpriv;
73 };
74 
75 typedef int (*rocker_cmd_prep_cb_t)(const struct rocker_port *rocker_port,
76 				    struct rocker_desc_info *desc_info,
77 				    void *priv);
78 
79 typedef int (*rocker_cmd_proc_cb_t)(const struct rocker_port *rocker_port,
80 				    const struct rocker_desc_info *desc_info,
81 				    void *priv);
82 
83 int rocker_cmd_exec(struct rocker_port *rocker_port, bool nowait,
84 		    rocker_cmd_prep_cb_t prepare, void *prepare_priv,
85 		    rocker_cmd_proc_cb_t process, void *process_priv);
86 
87 int rocker_port_set_learning(struct rocker_port *rocker_port,
88 			     bool learning);
89 
90 struct rocker_world_ops {
91 	const char *kind;
92 	size_t priv_size;
93 	size_t port_priv_size;
94 	u8 mode;
95 	int (*init)(struct rocker *rocker);
96 	void (*fini)(struct rocker *rocker);
97 	int (*port_pre_init)(struct rocker_port *rocker_port);
98 	int (*port_init)(struct rocker_port *rocker_port);
99 	void (*port_fini)(struct rocker_port *rocker_port);
100 	void (*port_post_fini)(struct rocker_port *rocker_port);
101 	int (*port_open)(struct rocker_port *rocker_port);
102 	void (*port_stop)(struct rocker_port *rocker_port);
103 	int (*port_attr_stp_state_set)(struct rocker_port *rocker_port,
104 				       u8 state);
105 	int (*port_attr_bridge_flags_set)(struct rocker_port *rocker_port,
106 					  unsigned long brport_flags,
107 					  struct switchdev_trans *trans);
108 	int (*port_attr_bridge_flags_support_get)(const struct rocker_port *
109 						  rocker_port,
110 						  unsigned long *
111 						  p_brport_flags);
112 	int (*port_attr_bridge_ageing_time_set)(struct rocker_port *rocker_port,
113 						u32 ageing_time,
114 						struct switchdev_trans *trans);
115 	int (*port_obj_vlan_add)(struct rocker_port *rocker_port,
116 				 const struct switchdev_obj_port_vlan *vlan);
117 	int (*port_obj_vlan_del)(struct rocker_port *rocker_port,
118 				 const struct switchdev_obj_port_vlan *vlan);
119 	int (*port_obj_fdb_add)(struct rocker_port *rocker_port,
120 				u16 vid, const unsigned char *addr);
121 	int (*port_obj_fdb_del)(struct rocker_port *rocker_port,
122 				u16 vid, const unsigned char *addr);
123 	int (*port_master_linked)(struct rocker_port *rocker_port,
124 				  struct net_device *master);
125 	int (*port_master_unlinked)(struct rocker_port *rocker_port,
126 				    struct net_device *master);
127 	int (*port_neigh_update)(struct rocker_port *rocker_port,
128 				 struct neighbour *n);
129 	int (*port_neigh_destroy)(struct rocker_port *rocker_port,
130 				  struct neighbour *n);
131 	int (*port_ev_mac_vlan_seen)(struct rocker_port *rocker_port,
132 				     const unsigned char *addr,
133 				     __be16 vlan_id);
134 	int (*fib4_add)(struct rocker *rocker,
135 			const struct fib_entry_notifier_info *fen_info);
136 	int (*fib4_del)(struct rocker *rocker,
137 			const struct fib_entry_notifier_info *fen_info);
138 	void (*fib4_abort)(struct rocker *rocker);
139 };
140 
141 extern struct rocker_world_ops rocker_ofdpa_ops;
142 
143 #endif
144