1
2
3
4
5
6
7
8
9
10#ifndef __NCSI_INTERNAL_H__
11#define __NCSI_INTERNAL_H__
12
13enum {
14 NCSI_CAP_BASE = 0,
15 NCSI_CAP_GENERIC = 0,
16 NCSI_CAP_BC,
17 NCSI_CAP_MC,
18 NCSI_CAP_BUFFER,
19 NCSI_CAP_AEN,
20 NCSI_CAP_VLAN,
21 NCSI_CAP_MAX
22};
23
24enum {
25 NCSI_CAP_GENERIC_HWA = 0x01,
26 NCSI_CAP_GENERIC_HDS = 0x02,
27 NCSI_CAP_GENERIC_FC = 0x04,
28 NCSI_CAP_GENERIC_FC1 = 0x08,
29 NCSI_CAP_GENERIC_MC = 0x10,
30 NCSI_CAP_GENERIC_HWA_UNKNOWN = 0x00,
31 NCSI_CAP_GENERIC_HWA_SUPPORT = 0x20,
32 NCSI_CAP_GENERIC_HWA_NOT_SUPPORT = 0x40,
33 NCSI_CAP_GENERIC_HWA_RESERVED = 0x60,
34 NCSI_CAP_GENERIC_HWA_MASK = 0x60,
35 NCSI_CAP_GENERIC_MASK = 0x7f,
36 NCSI_CAP_BC_ARP = 0x01,
37 NCSI_CAP_BC_DHCPC = 0x02,
38 NCSI_CAP_BC_DHCPS = 0x04,
39 NCSI_CAP_BC_NETBIOS = 0x08,
40 NCSI_CAP_BC_MASK = 0x0f,
41 NCSI_CAP_MC_IPV6_NEIGHBOR = 0x01,
42 NCSI_CAP_MC_IPV6_ROUTER = 0x02,
43 NCSI_CAP_MC_DHCPV6_RELAY = 0x04,
44 NCSI_CAP_MC_DHCPV6_WELL_KNOWN = 0x08,
45 NCSI_CAP_MC_IPV6_MLD = 0x10,
46 NCSI_CAP_MC_IPV6_NEIGHBOR_S = 0x20,
47 NCSI_CAP_MC_MASK = 0x3f,
48 NCSI_CAP_AEN_LSC = 0x01,
49 NCSI_CAP_AEN_CR = 0x02,
50 NCSI_CAP_AEN_HDS = 0x04,
51 NCSI_CAP_AEN_MASK = 0x07,
52 NCSI_CAP_VLAN_ONLY = 0x01,
53 NCSI_CAP_VLAN_NO = 0x02,
54 NCSI_CAP_VLAN_ANY = 0x04,
55 NCSI_CAP_VLAN_MASK = 0x07
56};
57
58enum {
59 NCSI_MODE_BASE = 0,
60 NCSI_MODE_ENABLE = 0,
61 NCSI_MODE_TX_ENABLE,
62 NCSI_MODE_LINK,
63 NCSI_MODE_VLAN,
64 NCSI_MODE_BC,
65 NCSI_MODE_MC,
66 NCSI_MODE_AEN,
67 NCSI_MODE_FC,
68 NCSI_MODE_MAX
69};
70
71enum {
72 NCSI_FILTER_BASE = 0,
73 NCSI_FILTER_VLAN = 0,
74 NCSI_FILTER_UC,
75 NCSI_FILTER_MC,
76 NCSI_FILTER_MIXED,
77 NCSI_FILTER_MAX
78};
79
80struct ncsi_channel_version {
81 u32 version;
82 u32 alpha2;
83 u8 fw_name[12];
84 u32 fw_version;
85 u16 pci_ids[4];
86 u32 mf_id;
87};
88
89struct ncsi_channel_cap {
90 u32 index;
91 u32 cap;
92};
93
94struct ncsi_channel_mode {
95 u32 index;
96 u32 enable;
97 u32 size;
98 u32 data[8];
99};
100
101struct ncsi_channel_filter {
102 u32 index;
103 u32 total;
104 u64 bitmap;
105 u32 data[];
106};
107
108struct ncsi_channel_stats {
109 u32 hnc_cnt_hi;
110 u32 hnc_cnt_lo;
111 u32 hnc_rx_bytes;
112 u32 hnc_tx_bytes;
113 u32 hnc_rx_uc_pkts;
114 u32 hnc_rx_mc_pkts;
115 u32 hnc_rx_bc_pkts;
116 u32 hnc_tx_uc_pkts;
117 u32 hnc_tx_mc_pkts;
118 u32 hnc_tx_bc_pkts;
119 u32 hnc_fcs_err;
120 u32 hnc_align_err;
121 u32 hnc_false_carrier;
122 u32 hnc_runt_pkts;
123 u32 hnc_jabber_pkts;
124 u32 hnc_rx_pause_xon;
125 u32 hnc_rx_pause_xoff;
126 u32 hnc_tx_pause_xon;
127 u32 hnc_tx_pause_xoff;
128 u32 hnc_tx_s_collision;
129 u32 hnc_tx_m_collision;
130 u32 hnc_l_collision;
131 u32 hnc_e_collision;
132 u32 hnc_rx_ctl_frames;
133 u32 hnc_rx_64_frames;
134 u32 hnc_rx_127_frames;
135 u32 hnc_rx_255_frames;
136 u32 hnc_rx_511_frames;
137 u32 hnc_rx_1023_frames;
138 u32 hnc_rx_1522_frames;
139 u32 hnc_rx_9022_frames;
140 u32 hnc_tx_64_frames;
141 u32 hnc_tx_127_frames;
142 u32 hnc_tx_255_frames;
143 u32 hnc_tx_511_frames;
144 u32 hnc_tx_1023_frames;
145 u32 hnc_tx_1522_frames;
146 u32 hnc_tx_9022_frames;
147 u32 hnc_rx_valid_bytes;
148 u32 hnc_rx_runt_pkts;
149 u32 hnc_rx_jabber_pkts;
150 u32 ncsi_rx_cmds;
151 u32 ncsi_dropped_cmds;
152 u32 ncsi_cmd_type_errs;
153 u32 ncsi_cmd_csum_errs;
154 u32 ncsi_rx_pkts;
155 u32 ncsi_tx_pkts;
156 u32 ncsi_tx_aen_pkts;
157 u32 pt_tx_pkts;
158 u32 pt_tx_dropped;
159 u32 pt_tx_channel_err;
160 u32 pt_tx_us_err;
161 u32 pt_rx_pkts;
162 u32 pt_rx_dropped;
163 u32 pt_rx_channel_err;
164 u32 pt_rx_us_err;
165 u32 pt_rx_os_err;
166};
167
168struct ncsi_dev_priv;
169struct ncsi_package;
170
171#define NCSI_PACKAGE_SHIFT 5
172#define NCSI_PACKAGE_INDEX(c) (((c) >> NCSI_PACKAGE_SHIFT) & 0x7)
173#define NCSI_RESERVED_CHANNEL 0x1f
174#define NCSI_CHANNEL_INDEX(c) ((c) & ((1 << NCSI_PACKAGE_SHIFT) - 1))
175#define NCSI_TO_CHANNEL(p, c) (((p) << NCSI_PACKAGE_SHIFT) | (c))
176
177struct ncsi_channel {
178 unsigned char id;
179 int state;
180#define NCSI_CHANNEL_INACTIVE 1
181#define NCSI_CHANNEL_ACTIVE 2
182#define NCSI_CHANNEL_INVISIBLE 3
183 bool reconfigure_needed;
184 spinlock_t lock;
185 struct ncsi_package *package;
186 struct ncsi_channel_version version;
187 struct ncsi_channel_cap caps[NCSI_CAP_MAX];
188 struct ncsi_channel_mode modes[NCSI_MODE_MAX];
189 struct ncsi_channel_filter *filters[NCSI_FILTER_MAX];
190 struct ncsi_channel_stats stats;
191 struct {
192 struct timer_list timer;
193 bool enabled;
194 unsigned int state;
195#define NCSI_CHANNEL_MONITOR_START 0
196#define NCSI_CHANNEL_MONITOR_RETRY 1
197#define NCSI_CHANNEL_MONITOR_WAIT 2
198#define NCSI_CHANNEL_MONITOR_WAIT_MAX 5
199 } monitor;
200 struct list_head node;
201 struct list_head link;
202};
203
204struct ncsi_package {
205 unsigned char id;
206 unsigned char uuid[16];
207 struct ncsi_dev_priv *ndp;
208 spinlock_t lock;
209 unsigned int channel_num;
210 struct list_head channels;
211 struct list_head node;
212};
213
214struct ncsi_request {
215 unsigned char id;
216 bool used;
217 unsigned int flags;
218#define NCSI_REQ_FLAG_EVENT_DRIVEN 1
219 struct ncsi_dev_priv *ndp;
220 struct sk_buff *cmd;
221 struct sk_buff *rsp;
222 struct timer_list timer;
223 bool enabled;
224};
225
226enum {
227 ncsi_dev_state_major = 0xff00,
228 ncsi_dev_state_minor = 0x00ff,
229 ncsi_dev_state_probe_deselect = 0x0201,
230 ncsi_dev_state_probe_package,
231 ncsi_dev_state_probe_channel,
232 ncsi_dev_state_probe_cis,
233 ncsi_dev_state_probe_gvi,
234 ncsi_dev_state_probe_gc,
235 ncsi_dev_state_probe_gls,
236 ncsi_dev_state_probe_dp,
237 ncsi_dev_state_config_sp = 0x0301,
238 ncsi_dev_state_config_cis,
239 ncsi_dev_state_config_clear_vids,
240 ncsi_dev_state_config_svf,
241 ncsi_dev_state_config_ev,
242 ncsi_dev_state_config_sma,
243 ncsi_dev_state_config_ebf,
244#if IS_ENABLED(CONFIG_IPV6)
245 ncsi_dev_state_config_egmf,
246#endif
247 ncsi_dev_state_config_ecnt,
248 ncsi_dev_state_config_ec,
249 ncsi_dev_state_config_ae,
250 ncsi_dev_state_config_gls,
251 ncsi_dev_state_config_done,
252 ncsi_dev_state_suspend_select = 0x0401,
253 ncsi_dev_state_suspend_gls,
254 ncsi_dev_state_suspend_dcnt,
255 ncsi_dev_state_suspend_dc,
256 ncsi_dev_state_suspend_deselect,
257 ncsi_dev_state_suspend_done
258};
259
260struct vlan_vid {
261 struct list_head list;
262 __be16 proto;
263 u16 vid;
264};
265
266struct ncsi_dev_priv {
267 struct ncsi_dev ndev;
268 unsigned int flags;
269#define NCSI_DEV_PROBED 1
270#define NCSI_DEV_HWA 2
271#define NCSI_DEV_RESHUFFLE 4
272 spinlock_t lock;
273#if IS_ENABLED(CONFIG_IPV6)
274 unsigned int inet6_addr_num;
275#endif
276 unsigned int package_num;
277 struct list_head packages;
278 struct ncsi_channel *hot_channel;
279 struct ncsi_request requests[256];
280 unsigned int request_id;
281#define NCSI_REQ_START_IDX 1
282 unsigned int pending_req_num;
283 struct ncsi_package *active_package;
284 struct ncsi_channel *active_channel;
285 struct list_head channel_queue;
286 struct work_struct work;
287 struct packet_type ptype;
288 struct list_head node;
289#define NCSI_MAX_VLAN_VIDS 15
290 struct list_head vlan_vids;
291};
292
293struct ncsi_cmd_arg {
294 struct ncsi_dev_priv *ndp;
295 unsigned char type;
296 unsigned char id;
297 unsigned char package;
298 unsigned char channel;
299 unsigned short payload;
300 unsigned int req_flags;
301 union {
302 unsigned char bytes[16];
303 unsigned short words[8];
304 unsigned int dwords[4];
305 };
306};
307
308extern struct list_head ncsi_dev_list;
309extern spinlock_t ncsi_dev_lock;
310
311#define TO_NCSI_DEV_PRIV(nd) \
312 container_of(nd, struct ncsi_dev_priv, ndev)
313#define NCSI_FOR_EACH_DEV(ndp) \
314 list_for_each_entry_rcu(ndp, &ncsi_dev_list, node)
315#define NCSI_FOR_EACH_PACKAGE(ndp, np) \
316 list_for_each_entry_rcu(np, &ndp->packages, node)
317#define NCSI_FOR_EACH_CHANNEL(np, nc) \
318 list_for_each_entry_rcu(nc, &np->channels, node)
319
320
321int ncsi_find_filter(struct ncsi_channel *nc, int table, void *data);
322int ncsi_add_filter(struct ncsi_channel *nc, int table, void *data);
323int ncsi_remove_filter(struct ncsi_channel *nc, int table, int index);
324void ncsi_start_channel_monitor(struct ncsi_channel *nc);
325void ncsi_stop_channel_monitor(struct ncsi_channel *nc);
326struct ncsi_channel *ncsi_find_channel(struct ncsi_package *np,
327 unsigned char id);
328struct ncsi_channel *ncsi_add_channel(struct ncsi_package *np,
329 unsigned char id);
330struct ncsi_package *ncsi_find_package(struct ncsi_dev_priv *ndp,
331 unsigned char id);
332struct ncsi_package *ncsi_add_package(struct ncsi_dev_priv *ndp,
333 unsigned char id);
334void ncsi_remove_package(struct ncsi_package *np);
335void ncsi_find_package_and_channel(struct ncsi_dev_priv *ndp,
336 unsigned char id,
337 struct ncsi_package **np,
338 struct ncsi_channel **nc);
339struct ncsi_request *ncsi_alloc_request(struct ncsi_dev_priv *ndp,
340 unsigned int req_flags);
341void ncsi_free_request(struct ncsi_request *nr);
342struct ncsi_dev *ncsi_find_dev(struct net_device *dev);
343int ncsi_process_next_channel(struct ncsi_dev_priv *ndp);
344
345
346u32 ncsi_calculate_checksum(unsigned char *data, int len);
347int ncsi_xmit_cmd(struct ncsi_cmd_arg *nca);
348int ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev,
349 struct packet_type *pt, struct net_device *orig_dev);
350int ncsi_aen_handler(struct ncsi_dev_priv *ndp, struct sk_buff *skb);
351
352#endif
353