Merge branch 'mscc-fixes'
[linux-block.git] / net / ncsi / internal.h
CommitLineData
2d283bdd
GS
1/*
2 * Copyright Gavin Shan, IBM Corporation 2016.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
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, /* HW arbitration */
26 NCSI_CAP_GENERIC_HDS = 0x02, /* HNC driver status change */
27 NCSI_CAP_GENERIC_FC = 0x04, /* HNC to MC flow control */
28 NCSI_CAP_GENERIC_FC1 = 0x08, /* MC to HNC flow control */
29 NCSI_CAP_GENERIC_MC = 0x10, /* Global MC filtering */
30 NCSI_CAP_GENERIC_HWA_UNKNOWN = 0x00, /* Unknown HW arbitration */
31 NCSI_CAP_GENERIC_HWA_SUPPORT = 0x20, /* Supported HW arbitration */
32 NCSI_CAP_GENERIC_HWA_NOT_SUPPORT = 0x40, /* No HW arbitration */
33 NCSI_CAP_GENERIC_HWA_RESERVED = 0x60, /* Reserved HW arbitration */
34 NCSI_CAP_GENERIC_HWA_MASK = 0x60, /* Mask for HW arbitration */
35 NCSI_CAP_GENERIC_MASK = 0x7f,
36 NCSI_CAP_BC_ARP = 0x01, /* ARP packet filtering */
37 NCSI_CAP_BC_DHCPC = 0x02, /* DHCP client filtering */
38 NCSI_CAP_BC_DHCPS = 0x04, /* DHCP server filtering */
39 NCSI_CAP_BC_NETBIOS = 0x08, /* NetBIOS packet filtering */
40 NCSI_CAP_BC_MASK = 0x0f,
41 NCSI_CAP_MC_IPV6_NEIGHBOR = 0x01, /* IPv6 neighbor filtering */
42 NCSI_CAP_MC_IPV6_ROUTER = 0x02, /* IPv6 router filering */
43 NCSI_CAP_MC_DHCPV6_RELAY = 0x04, /* DHCPv6 relay / server MC */
44 NCSI_CAP_MC_DHCPV6_WELL_KNOWN = 0x08, /* DHCPv6 well-known MC */
45 NCSI_CAP_MC_IPV6_MLD = 0x10, /* IPv6 MLD filtering */
46 NCSI_CAP_MC_IPV6_NEIGHBOR_S = 0x20, /* IPv6 neighbour filtering */
47 NCSI_CAP_MC_MASK = 0x3f,
48 NCSI_CAP_AEN_LSC = 0x01, /* Link status change */
49 NCSI_CAP_AEN_CR = 0x02, /* Configuration required */
50 NCSI_CAP_AEN_HDS = 0x04, /* HNC driver status */
51 NCSI_CAP_AEN_MASK = 0x07,
52 NCSI_CAP_VLAN_ONLY = 0x01, /* Filter VLAN packet only */
53 NCSI_CAP_VLAN_NO = 0x02, /* Filter VLAN and non-VLAN */
54 NCSI_CAP_VLAN_ANY = 0x04, /* Filter Any-and-non-VLAN */
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
fb4ee675
VK
71/* OEM Vendor Manufacture ID */
72#define NCSI_OEM_MFR_MLX_ID 0x8119
73#define NCSI_OEM_MFR_BCM_ID 0x113d
74
2d283bdd
GS
75struct ncsi_channel_version {
76 u32 version; /* Supported BCD encoded NCSI version */
77 u32 alpha2; /* Supported BCD encoded NCSI version */
78 u8 fw_name[12]; /* Firware name string */
79 u32 fw_version; /* Firmware version */
80 u16 pci_ids[4]; /* PCI identification */
81 u32 mf_id; /* Manufacture ID */
82};
83
84struct ncsi_channel_cap {
85 u32 index; /* Index of channel capabilities */
86 u32 cap; /* NCSI channel capability */
87};
88
89struct ncsi_channel_mode {
90 u32 index; /* Index of channel modes */
91 u32 enable; /* Enabled or disabled */
92 u32 size; /* Valid entries in ncm_data[] */
93 u32 data[8]; /* Data entries */
94};
95
062b3e1b
SMJ
96struct ncsi_channel_mac_filter {
97 u8 n_uc;
98 u8 n_mc;
99 u8 n_mixed;
100 u64 bitmap;
101 unsigned char *addrs;
102};
103
104struct ncsi_channel_vlan_filter {
105 u8 n_vids;
106 u64 bitmap;
107 u16 *vids;
2d283bdd
GS
108};
109
110struct ncsi_channel_stats {
111 u32 hnc_cnt_hi; /* Counter cleared */
112 u32 hnc_cnt_lo; /* Counter cleared */
113 u32 hnc_rx_bytes; /* Rx bytes */
114 u32 hnc_tx_bytes; /* Tx bytes */
115 u32 hnc_rx_uc_pkts; /* Rx UC packets */
116 u32 hnc_rx_mc_pkts; /* Rx MC packets */
117 u32 hnc_rx_bc_pkts; /* Rx BC packets */
118 u32 hnc_tx_uc_pkts; /* Tx UC packets */
119 u32 hnc_tx_mc_pkts; /* Tx MC packets */
120 u32 hnc_tx_bc_pkts; /* Tx BC packets */
121 u32 hnc_fcs_err; /* FCS errors */
122 u32 hnc_align_err; /* Alignment errors */
123 u32 hnc_false_carrier; /* False carrier detection */
124 u32 hnc_runt_pkts; /* Rx runt packets */
125 u32 hnc_jabber_pkts; /* Rx jabber packets */
126 u32 hnc_rx_pause_xon; /* Rx pause XON frames */
127 u32 hnc_rx_pause_xoff; /* Rx XOFF frames */
128 u32 hnc_tx_pause_xon; /* Tx XON frames */
129 u32 hnc_tx_pause_xoff; /* Tx XOFF frames */
130 u32 hnc_tx_s_collision; /* Single collision frames */
131 u32 hnc_tx_m_collision; /* Multiple collision frames */
132 u32 hnc_l_collision; /* Late collision frames */
133 u32 hnc_e_collision; /* Excessive collision frames */
134 u32 hnc_rx_ctl_frames; /* Rx control frames */
135 u32 hnc_rx_64_frames; /* Rx 64-bytes frames */
136 u32 hnc_rx_127_frames; /* Rx 65-127 bytes frames */
137 u32 hnc_rx_255_frames; /* Rx 128-255 bytes frames */
138 u32 hnc_rx_511_frames; /* Rx 256-511 bytes frames */
139 u32 hnc_rx_1023_frames; /* Rx 512-1023 bytes frames */
140 u32 hnc_rx_1522_frames; /* Rx 1024-1522 bytes frames */
141 u32 hnc_rx_9022_frames; /* Rx 1523-9022 bytes frames */
142 u32 hnc_tx_64_frames; /* Tx 64-bytes frames */
143 u32 hnc_tx_127_frames; /* Tx 65-127 bytes frames */
144 u32 hnc_tx_255_frames; /* Tx 128-255 bytes frames */
145 u32 hnc_tx_511_frames; /* Tx 256-511 bytes frames */
146 u32 hnc_tx_1023_frames; /* Tx 512-1023 bytes frames */
147 u32 hnc_tx_1522_frames; /* Tx 1024-1522 bytes frames */
148 u32 hnc_tx_9022_frames; /* Tx 1523-9022 bytes frames */
149 u32 hnc_rx_valid_bytes; /* Rx valid bytes */
150 u32 hnc_rx_runt_pkts; /* Rx error runt packets */
151 u32 hnc_rx_jabber_pkts; /* Rx error jabber packets */
152 u32 ncsi_rx_cmds; /* Rx NCSI commands */
153 u32 ncsi_dropped_cmds; /* Dropped commands */
154 u32 ncsi_cmd_type_errs; /* Command type errors */
155 u32 ncsi_cmd_csum_errs; /* Command checksum errors */
156 u32 ncsi_rx_pkts; /* Rx NCSI packets */
157 u32 ncsi_tx_pkts; /* Tx NCSI packets */
158 u32 ncsi_tx_aen_pkts; /* Tx AEN packets */
159 u32 pt_tx_pkts; /* Tx packets */
160 u32 pt_tx_dropped; /* Tx dropped packets */
161 u32 pt_tx_channel_err; /* Tx channel errors */
162 u32 pt_tx_us_err; /* Tx undersize errors */
163 u32 pt_rx_pkts; /* Rx packets */
164 u32 pt_rx_dropped; /* Rx dropped packets */
165 u32 pt_rx_channel_err; /* Rx channel errors */
166 u32 pt_rx_us_err; /* Rx undersize errors */
167 u32 pt_rx_os_err; /* Rx oversize errors */
168};
169
170struct ncsi_dev_priv;
171struct ncsi_package;
172
173#define NCSI_PACKAGE_SHIFT 5
174#define NCSI_PACKAGE_INDEX(c) (((c) >> NCSI_PACKAGE_SHIFT) & 0x7)
bc7e0f50 175#define NCSI_RESERVED_CHANNEL 0x1f
2d283bdd
GS
176#define NCSI_CHANNEL_INDEX(c) ((c) & ((1 << NCSI_PACKAGE_SHIFT) - 1))
177#define NCSI_TO_CHANNEL(p, c) (((p) << NCSI_PACKAGE_SHIFT) | (c))
9771b8cc
JLD
178#define NCSI_MAX_PACKAGE 8
179#define NCSI_MAX_CHANNEL 32
2d283bdd
GS
180
181struct ncsi_channel {
182 unsigned char id;
183 int state;
184#define NCSI_CHANNEL_INACTIVE 1
185#define NCSI_CHANNEL_ACTIVE 2
e6f44ed6 186#define NCSI_CHANNEL_INVISIBLE 3
21acf630 187 bool reconfigure_needed;
2d283bdd
GS
188 spinlock_t lock; /* Protect filters etc */
189 struct ncsi_package *package;
190 struct ncsi_channel_version version;
191 struct ncsi_channel_cap caps[NCSI_CAP_MAX];
192 struct ncsi_channel_mode modes[NCSI_MODE_MAX];
062b3e1b
SMJ
193 /* Filtering Settings */
194 struct ncsi_channel_mac_filter mac_filter;
195 struct ncsi_channel_vlan_filter vlan_filter;
2d283bdd 196 struct ncsi_channel_stats stats;
83afdc6a
GS
197 struct {
198 struct timer_list timer;
199 bool enabled;
200 unsigned int state;
201#define NCSI_CHANNEL_MONITOR_START 0
202#define NCSI_CHANNEL_MONITOR_RETRY 1
203#define NCSI_CHANNEL_MONITOR_WAIT 2
204#define NCSI_CHANNEL_MONITOR_WAIT_MAX 5
205 } monitor;
2d283bdd 206 struct list_head node;
e6f44ed6 207 struct list_head link;
2d283bdd
GS
208};
209
210struct ncsi_package {
211 unsigned char id; /* NCSI 3-bits package ID */
212 unsigned char uuid[16]; /* UUID */
213 struct ncsi_dev_priv *ndp; /* NCSI device */
214 spinlock_t lock; /* Protect the package */
215 unsigned int channel_num; /* Number of channels */
216 struct list_head channels; /* List of chanels */
217 struct list_head node; /* Form list of packages */
218};
219
220struct ncsi_request {
221 unsigned char id; /* Request ID - 0 to 255 */
222 bool used; /* Request that has been assigned */
a0509cbe
GS
223 unsigned int flags; /* NCSI request property */
224#define NCSI_REQ_FLAG_EVENT_DRIVEN 1
9771b8cc 225#define NCSI_REQ_FLAG_NETLINK_DRIVEN 2
2d283bdd
GS
226 struct ncsi_dev_priv *ndp; /* Associated NCSI device */
227 struct sk_buff *cmd; /* Associated NCSI command packet */
228 struct sk_buff *rsp; /* Associated NCSI response packet */
229 struct timer_list timer; /* Timer on waiting for response */
230 bool enabled; /* Time has been enabled or not */
9771b8cc
JLD
231 u32 snd_seq; /* netlink sending sequence number */
232 u32 snd_portid; /* netlink portid of sender */
233 struct nlmsghdr nlhdr; /* netlink message header */
2d283bdd
GS
234};
235
e6f44ed6
GS
236enum {
237 ncsi_dev_state_major = 0xff00,
238 ncsi_dev_state_minor = 0x00ff,
239 ncsi_dev_state_probe_deselect = 0x0201,
240 ncsi_dev_state_probe_package,
241 ncsi_dev_state_probe_channel,
242 ncsi_dev_state_probe_cis,
243 ncsi_dev_state_probe_gvi,
244 ncsi_dev_state_probe_gc,
245 ncsi_dev_state_probe_gls,
246 ncsi_dev_state_probe_dp,
247 ncsi_dev_state_config_sp = 0x0301,
248 ncsi_dev_state_config_cis,
21acf630
SMJ
249 ncsi_dev_state_config_clear_vids,
250 ncsi_dev_state_config_svf,
251 ncsi_dev_state_config_ev,
e6f44ed6
GS
252 ncsi_dev_state_config_sma,
253 ncsi_dev_state_config_ebf,
254#if IS_ENABLED(CONFIG_IPV6)
255 ncsi_dev_state_config_egmf,
256#endif
257 ncsi_dev_state_config_ecnt,
258 ncsi_dev_state_config_ec,
259 ncsi_dev_state_config_ae,
260 ncsi_dev_state_config_gls,
261 ncsi_dev_state_config_done,
262 ncsi_dev_state_suspend_select = 0x0401,
008a424a 263 ncsi_dev_state_suspend_gls,
e6f44ed6
GS
264 ncsi_dev_state_suspend_dcnt,
265 ncsi_dev_state_suspend_dc,
266 ncsi_dev_state_suspend_deselect,
267 ncsi_dev_state_suspend_done
268};
269
21acf630
SMJ
270struct vlan_vid {
271 struct list_head list;
272 __be16 proto;
273 u16 vid;
274};
275
2d283bdd
GS
276struct ncsi_dev_priv {
277 struct ncsi_dev ndev; /* Associated NCSI device */
278 unsigned int flags; /* NCSI device flags */
e6f44ed6
GS
279#define NCSI_DEV_PROBED 1 /* Finalized NCSI topology */
280#define NCSI_DEV_HWA 2 /* Enabled HW arbitration */
281#define NCSI_DEV_RESHUFFLE 4
2d283bdd 282 spinlock_t lock; /* Protect the NCSI device */
e6f44ed6
GS
283#if IS_ENABLED(CONFIG_IPV6)
284 unsigned int inet6_addr_num; /* Number of IPv6 addresses */
285#endif
2d283bdd
GS
286 unsigned int package_num; /* Number of packages */
287 struct list_head packages; /* List of packages */
bbc7c01e 288 struct ncsi_channel *hot_channel; /* Channel was ever active */
955dc68c
SMJ
289 struct ncsi_package *force_package; /* Force a specific package */
290 struct ncsi_channel *force_channel; /* Force a specific channel */
2d283bdd
GS
291 struct ncsi_request requests[256]; /* Request table */
292 unsigned int request_id; /* Last used request ID */
a15af54f 293#define NCSI_REQ_START_IDX 1
e6f44ed6
GS
294 unsigned int pending_req_num; /* Number of pending requests */
295 struct ncsi_package *active_package; /* Currently handled package */
296 struct ncsi_channel *active_channel; /* Currently handled channel */
297 struct list_head channel_queue; /* Config queue of channels */
298 struct work_struct work; /* For channel management */
299 struct packet_type ptype; /* NCSI packet Rx handler */
2d283bdd 300 struct list_head node; /* Form NCSI device list */
6e9c0075 301#define NCSI_MAX_VLAN_VIDS 15
21acf630 302 struct list_head vlan_vids; /* List of active VLAN IDs */
2d283bdd
GS
303};
304
6389eaa7
GS
305struct ncsi_cmd_arg {
306 struct ncsi_dev_priv *ndp; /* Associated NCSI device */
307 unsigned char type; /* Command in the NCSI packet */
308 unsigned char id; /* Request ID (sequence number) */
309 unsigned char package; /* Destination package ID */
310 unsigned char channel; /* Detination channel ID or 0x1f */
311 unsigned short payload; /* Command packet payload length */
a0509cbe 312 unsigned int req_flags; /* NCSI request properties */
6389eaa7
GS
313 union {
314 unsigned char bytes[16]; /* Command packet specific data */
315 unsigned short words[8];
316 unsigned int dwords[4];
317 };
fb4ee675 318 unsigned char *data; /* NCSI OEM data */
9771b8cc 319 struct genl_info *info; /* Netlink information */
6389eaa7
GS
320};
321
2d283bdd
GS
322extern struct list_head ncsi_dev_list;
323extern spinlock_t ncsi_dev_lock;
324
325#define TO_NCSI_DEV_PRIV(nd) \
326 container_of(nd, struct ncsi_dev_priv, ndev)
327#define NCSI_FOR_EACH_DEV(ndp) \
328 list_for_each_entry_rcu(ndp, &ncsi_dev_list, node)
329#define NCSI_FOR_EACH_PACKAGE(ndp, np) \
330 list_for_each_entry_rcu(np, &ndp->packages, node)
331#define NCSI_FOR_EACH_CHANNEL(np, nc) \
332 list_for_each_entry_rcu(nc, &np->channels, node)
333
334/* Resources */
e6f44ed6
GS
335void ncsi_start_channel_monitor(struct ncsi_channel *nc);
336void ncsi_stop_channel_monitor(struct ncsi_channel *nc);
2d283bdd
GS
337struct ncsi_channel *ncsi_find_channel(struct ncsi_package *np,
338 unsigned char id);
339struct ncsi_channel *ncsi_add_channel(struct ncsi_package *np,
340 unsigned char id);
341struct ncsi_package *ncsi_find_package(struct ncsi_dev_priv *ndp,
342 unsigned char id);
343struct ncsi_package *ncsi_add_package(struct ncsi_dev_priv *ndp,
344 unsigned char id);
345void ncsi_remove_package(struct ncsi_package *np);
346void ncsi_find_package_and_channel(struct ncsi_dev_priv *ndp,
347 unsigned char id,
348 struct ncsi_package **np,
349 struct ncsi_channel **nc);
a0509cbe
GS
350struct ncsi_request *ncsi_alloc_request(struct ncsi_dev_priv *ndp,
351 unsigned int req_flags);
2d283bdd
GS
352void ncsi_free_request(struct ncsi_request *nr);
353struct ncsi_dev *ncsi_find_dev(struct net_device *dev);
e6f44ed6 354int ncsi_process_next_channel(struct ncsi_dev_priv *ndp);
2d283bdd 355
6389eaa7
GS
356/* Packet handlers */
357u32 ncsi_calculate_checksum(unsigned char *data, int len);
358int ncsi_xmit_cmd(struct ncsi_cmd_arg *nca);
138635cc
GS
359int ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev,
360 struct packet_type *pt, struct net_device *orig_dev);
7a82ecf4 361int ncsi_aen_handler(struct ncsi_dev_priv *ndp, struct sk_buff *skb);
6389eaa7 362
2d283bdd 363#endif /* __NCSI_INTERNAL_H__ */