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