xref: /openbmc/linux/drivers/s390/net/qeth_l3.h (revision 715f23b6)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *    Copyright IBM Corp. 2007
4  *    Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
5  *		 Frank Pavlic <fpavlic@de.ibm.com>,
6  *		 Thomas Spatzier <tspat@de.ibm.com>,
7  *		 Frank Blaschka <frank.blaschka@de.ibm.com>
8  */
9 
10 #ifndef __QETH_L3_H__
11 #define __QETH_L3_H__
12 
13 #include "qeth_core.h"
14 #include <linux/hashtable.h>
15 
16 enum qeth_ip_types {
17 	QETH_IP_TYPE_NORMAL,
18 	QETH_IP_TYPE_VIPA,
19 	QETH_IP_TYPE_RXIP,
20 };
21 
22 struct qeth_ipaddr {
23 	struct hlist_node hnode;
24 	enum qeth_ip_types type;
25 	u8 is_multicast:1;
26 	u8 in_progress:1;
27 	u8 disp_flag:2;
28 	u8 ipato:1;			/* ucast only */
29 
30 	/* is changed only for normal ip addresses
31 	 * for non-normal addresses it always is  1
32 	 */
33 	int  ref_counter;
34 	enum qeth_prot_versions proto;
35 	union {
36 		struct {
37 			__be32 addr;
38 			unsigned int mask;
39 		} a4;
40 		struct {
41 			struct in6_addr addr;
42 			unsigned int pfxlen;
43 		} a6;
44 	} u;
45 };
46 
47 static inline void qeth_l3_init_ipaddr(struct qeth_ipaddr *addr,
48 				       enum qeth_ip_types type,
49 				       enum qeth_prot_versions proto)
50 {
51 	memset(addr, 0, sizeof(*addr));
52 	addr->type = type;
53 	addr->proto = proto;
54 	addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
55 	addr->ref_counter = 1;
56 }
57 
58 static inline bool qeth_l3_addr_match_ip(struct qeth_ipaddr *a1,
59 					 struct qeth_ipaddr *a2)
60 {
61 	if (a1->proto != a2->proto)
62 		return false;
63 	if (a1->proto == QETH_PROT_IPV6)
64 		return ipv6_addr_equal(&a1->u.a6.addr, &a2->u.a6.addr);
65 	return a1->u.a4.addr == a2->u.a4.addr;
66 }
67 
68 static inline bool qeth_l3_addr_match_all(struct qeth_ipaddr *a1,
69 					  struct qeth_ipaddr *a2)
70 {
71 	/* Assumes that the pair was obtained via qeth_l3_addr_find_by_ip(),
72 	 * so 'proto' and 'addr' match for sure.
73 	 *
74 	 * For ucast:
75 	 * -	'mask'/'pfxlen' for RXIP/VIPA is always 0. For NORMAL, matching
76 	 *	values are required to avoid mixups in takeover eligibility.
77 	 *
78 	 * For mcast,
79 	 * -	'mask'/'pfxlen' is always 0.
80 	 */
81 	if (a1->type != a2->type)
82 		return false;
83 	if (a1->proto == QETH_PROT_IPV6)
84 		return a1->u.a6.pfxlen == a2->u.a6.pfxlen;
85 	return a1->u.a4.mask == a2->u.a4.mask;
86 }
87 
88 static inline u32 qeth_l3_ipaddr_hash(struct qeth_ipaddr *addr)
89 {
90 	if (addr->proto == QETH_PROT_IPV6)
91 		return ipv6_addr_hash(&addr->u.a6.addr);
92 	else
93 		return ipv4_addr_hash(addr->u.a4.addr);
94 }
95 
96 struct qeth_ipato_entry {
97 	struct list_head entry;
98 	enum qeth_prot_versions proto;
99 	char addr[16];
100 	int mask_bits;
101 };
102 
103 extern const struct attribute_group *qeth_l3_attr_groups[];
104 
105 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions, const __u8 *, char *);
106 int qeth_l3_create_device_attributes(struct device *);
107 void qeth_l3_remove_device_attributes(struct device *);
108 int qeth_l3_setrouting_v4(struct qeth_card *);
109 int qeth_l3_setrouting_v6(struct qeth_card *);
110 int qeth_l3_add_ipato_entry(struct qeth_card *, struct qeth_ipato_entry *);
111 int qeth_l3_del_ipato_entry(struct qeth_card *card,
112 			    enum qeth_prot_versions proto, u8 *addr,
113 			    int mask_bits);
114 void qeth_l3_update_ipato(struct qeth_card *card);
115 int qeth_l3_modify_hsuid(struct qeth_card *card, bool add);
116 int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip,
117 			     enum qeth_ip_types type,
118 			     enum qeth_prot_versions proto);
119 
120 #endif /* __QETH_L3_H__ */
121