blob: 13bf3e2e9cea6b6cdd899573249bf71a8c90d704 [file] [log] [blame]
Greg Kroah-Hartmanab9953f2017-11-14 18:38:04 +01001// SPDX-License-Identifier: GPL-2.0
Frank Blaschka4a71df52008-02-15 09:19:42 +01002/*
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003 * Copyright IBM Corp. 2007, 2009
Frank Blaschka4a71df52008-02-15 09:19:42 +01004 * 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
Frank Blaschka74eacdb2008-12-25 13:39:49 +010010#define KMSG_COMPONENT "qeth"
11#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
Frank Blaschka4a71df52008-02-15 09:19:42 +010013#include <linux/module.h>
14#include <linux/moduleparam.h>
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +000015#include <linux/bitops.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010016#include <linux/string.h>
17#include <linux/errno.h>
18#include <linux/kernel.h>
19#include <linux/etherdevice.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010020#include <linux/ip.h>
Julian Wiedmann1f979122017-12-20 20:11:04 +010021#include <linux/in.h>
Frank Blaschka64ef8952009-03-24 20:57:16 +000022#include <linux/ipv6.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010023#include <linux/inetdevice.h>
24#include <linux/igmp.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Julian Wiedmann910a0a82017-12-20 20:11:07 +010026#include <linux/if_ether.h>
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +000027#include <linux/if_vlan.h>
Julian Wiedmann910a0a82017-12-20 20:11:07 +010028#include <linux/skbuff.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010029
30#include <net/ip.h>
31#include <net/arp.h>
David Miller87e75972012-02-01 10:49:17 +000032#include <net/route.h>
Julian Wiedmann1f979122017-12-20 20:11:04 +010033#include <net/ipv6.h>
Julian Wiedmann910a0a82017-12-20 20:11:07 +010034#include <net/ip6_route.h>
David Miller87e75972012-02-01 10:49:17 +000035#include <net/ip6_fib.h>
Frank Blaschkab3332932011-08-08 01:33:59 +000036#include <net/iucv/af_iucv.h>
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020037#include <linux/hashtable.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010038
Frank Blaschka4a71df52008-02-15 09:19:42 +010039#include "qeth_l3.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010040
Einar Lueckd0ddf30f2010-12-08 02:57:58 +000041
Frank Blaschka4a71df52008-02-15 09:19:42 +010042static int qeth_l3_set_offline(struct ccwgroup_device *);
Julian Wiedmann00c163f2017-12-20 20:11:02 +010043static void qeth_l3_set_rx_mode(struct net_device *dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +010044static int qeth_l3_register_addr_entry(struct qeth_card *,
45 struct qeth_ipaddr *);
46static int qeth_l3_deregister_addr_entry(struct qeth_card *,
47 struct qeth_ipaddr *);
Frank Blaschka4a71df52008-02-15 09:19:42 +010048
Thomas Richter56530d62014-10-22 12:18:04 +020049static void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010050{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020051 sprintf(buf, "%pI4", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010052}
53
Thomas Richter56530d62014-10-22 12:18:04 +020054static void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010055{
Joe Perches963a9fd2010-09-07 21:14:40 +000056 sprintf(buf, "%pI6", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010057}
58
Frank Blaschka4a71df52008-02-15 09:19:42 +010059void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
60 char *buf)
61{
62 if (proto == QETH_PROT_IPV4)
63 qeth_l3_ipaddr4_to_string(addr, buf);
64 else if (proto == QETH_PROT_IPV6)
65 qeth_l3_ipaddr6_to_string(addr, buf);
66}
67
Julian Wiedmann1617dae2018-03-09 18:13:02 +010068static struct qeth_ipaddr *qeth_l3_get_addr_buffer(enum qeth_prot_versions prot)
Julian Wiedmannd66b1c02018-03-09 18:13:00 +010069{
70 struct qeth_ipaddr *addr = kmalloc(sizeof(*addr), GFP_ATOMIC);
71
72 if (addr)
73 qeth_l3_init_ipaddr(addr, QETH_IP_TYPE_NORMAL, prot);
74 return addr;
75}
76
Julian Wiedmannc5c48c52018-02-27 18:58:16 +010077static struct qeth_ipaddr *qeth_l3_find_addr_by_ip(struct qeth_card *card,
78 struct qeth_ipaddr *query)
79{
80 u64 key = qeth_l3_ipaddr_hash(query);
81 struct qeth_ipaddr *addr;
82
83 if (query->is_multicast) {
84 hash_for_each_possible(card->ip_mc_htable, addr, hnode, key)
85 if (qeth_l3_addr_match_ip(addr, query))
86 return addr;
87 } else {
88 hash_for_each_possible(card->ip_htable, addr, hnode, key)
89 if (qeth_l3_addr_match_ip(addr, query))
90 return addr;
91 }
92 return NULL;
93}
94
Frank Blaschka4a71df52008-02-15 09:19:42 +010095static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
96{
97 int i, j;
98 u8 octet;
99
100 for (i = 0; i < len; ++i) {
101 octet = addr[i];
102 for (j = 7; j >= 0; --j) {
103 bits[i*8 + j] = octet & 1;
104 octet >>= 1;
105 }
106 }
107}
108
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100109static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
110 struct qeth_ipaddr *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100111{
112 struct qeth_ipato_entry *ipatoe;
113 u8 addr_bits[128] = {0, };
114 u8 ipatoe_bits[128] = {0, };
115 int rc = 0;
116
117 if (!card->ipato.enabled)
Gustavo A. R. Silva1a363b02018-08-09 14:48:04 +0200118 return false;
Julian Wiedmannb22d73d62017-12-13 18:56:30 +0100119 if (addr->type != QETH_IP_TYPE_NORMAL)
Gustavo A. R. Silva1a363b02018-08-09 14:48:04 +0200120 return false;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100121
122 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
123 (addr->proto == QETH_PROT_IPV4)? 4:16);
124 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
125 if (addr->proto != ipatoe->proto)
126 continue;
127 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
128 (ipatoe->proto == QETH_PROT_IPV4) ?
129 4 : 16);
130 if (addr->proto == QETH_PROT_IPV4)
131 rc = !memcmp(addr_bits, ipatoe_bits,
132 min(32, ipatoe->mask_bits));
133 else
134 rc = !memcmp(addr_bits, ipatoe_bits,
135 min(128, ipatoe->mask_bits));
136 if (rc)
137 break;
138 }
139 /* invert? */
140 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
141 rc = !rc;
142 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
143 rc = !rc;
144
145 return rc;
146}
147
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100148static int qeth_l3_delete_ip(struct qeth_card *card,
149 struct qeth_ipaddr *tmp_addr)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200150{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100151 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200152 struct qeth_ipaddr *addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100153
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100154 if (tmp_addr->type == QETH_IP_TYPE_RXIP)
155 QETH_CARD_TEXT(card, 2, "delrxip");
156 else if (tmp_addr->type == QETH_IP_TYPE_VIPA)
157 QETH_CARD_TEXT(card, 2, "delvipa");
158 else
159 QETH_CARD_TEXT(card, 2, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100160
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200161 if (tmp_addr->proto == QETH_PROT_IPV4)
162 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100163 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200164 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
165 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100166 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200167
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100168 addr = qeth_l3_find_addr_by_ip(card, tmp_addr);
169 if (!addr || !qeth_l3_addr_match_all(addr, tmp_addr))
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200170 return -ENOENT;
171
172 addr->ref_counter--;
Julian Wiedmann4964c662018-02-27 18:58:15 +0100173 if (addr->type == QETH_IP_TYPE_NORMAL && addr->ref_counter > 0)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200174 return rc;
175 if (addr->in_progress)
176 return -EINPROGRESS;
177
Julian Wiedmann98d823a2018-02-27 18:58:13 +0100178 if (qeth_card_hw_is_reachable(card))
179 rc = qeth_l3_deregister_addr_entry(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200180
181 hash_del(&addr->hnode);
182 kfree(addr);
183
Frank Blaschka4a71df52008-02-15 09:19:42 +0100184 return rc;
185}
186
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100187static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100188{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100189 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200190 struct qeth_ipaddr *addr;
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100191 char buf[40];
Frank Blaschka4a71df52008-02-15 09:19:42 +0100192
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100193 if (tmp_addr->type == QETH_IP_TYPE_RXIP)
194 QETH_CARD_TEXT(card, 2, "addrxip");
195 else if (tmp_addr->type == QETH_IP_TYPE_VIPA)
196 QETH_CARD_TEXT(card, 2, "addvipa");
197 else
198 QETH_CARD_TEXT(card, 2, "addip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200199
200 if (tmp_addr->proto == QETH_PROT_IPV4)
201 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100202 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200203 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
204 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100205 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200206
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100207 addr = qeth_l3_find_addr_by_ip(card, tmp_addr);
208 if (addr) {
209 if (tmp_addr->type != QETH_IP_TYPE_NORMAL)
210 return -EADDRINUSE;
211 if (qeth_l3_addr_match_all(addr, tmp_addr)) {
212 addr->ref_counter++;
213 return 0;
214 }
215 qeth_l3_ipaddr_to_string(tmp_addr->proto, (u8 *)&tmp_addr->u,
216 buf);
217 dev_warn(&card->gdev->dev,
218 "Registering IP address %s failed\n", buf);
219 return -EADDRINUSE;
220 } else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200221 addr = qeth_l3_get_addr_buffer(tmp_addr->proto);
222 if (!addr)
223 return -ENOMEM;
224
225 memcpy(addr, tmp_addr, sizeof(struct qeth_ipaddr));
226 addr->ref_counter = 1;
227
Julian Wiedmannb22d73d62017-12-13 18:56:30 +0100228 if (qeth_l3_is_addr_covered_by_ipato(card, addr)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200229 QETH_CARD_TEXT(card, 2, "tkovaddr");
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100230 addr->ipato = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200231 }
232 hash_add(card->ip_htable, &addr->hnode,
233 qeth_l3_ipaddr_hash(addr));
234
Ursula Brauna7531c12016-09-15 14:39:23 +0200235 if (!qeth_card_hw_is_reachable(card)) {
236 addr->disp_flag = QETH_DISP_ADDR_ADD;
237 return 0;
238 }
239
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200240 /* qeth_l3_register_addr_entry can go to sleep
241 * if we add a IPV4 addr. It is caused by the reason
242 * that SETIP ipa cmd starts ARP staff for IPV4 addr.
243 * Thus we should unlock spinlock, and make a protection
244 * using in_progress variable to indicate that there is
245 * an hardware operation with this IPV4 address
246 */
247 if (addr->proto == QETH_PROT_IPV4) {
248 addr->in_progress = 1;
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100249 mutex_unlock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200250 rc = qeth_l3_register_addr_entry(card, addr);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100251 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200252 addr->in_progress = 0;
253 } else
254 rc = qeth_l3_register_addr_entry(card, addr);
255
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100256 if (!rc || rc == -EADDRINUSE || rc == -ENETDOWN) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200257 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
258 if (addr->ref_counter < 1) {
Julian Wiedmann14d066c2018-02-27 18:58:14 +0100259 qeth_l3_deregister_addr_entry(card, addr);
260 hash_del(&addr->hnode);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200261 kfree(addr);
262 }
263 } else {
264 hash_del(&addr->hnode);
265 kfree(addr);
266 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200267 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100268 return rc;
269}
270
Julian Wiedmann05a17852019-03-28 16:39:21 +0100271static int qeth_l3_modify_ip(struct qeth_card *card, struct qeth_ipaddr *addr,
272 bool add)
273{
274 int rc;
275
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100276 mutex_lock(&card->ip_lock);
Julian Wiedmann05a17852019-03-28 16:39:21 +0100277 rc = add ? qeth_l3_add_ip(card, addr) : qeth_l3_delete_ip(card, addr);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100278 mutex_unlock(&card->ip_lock);
Julian Wiedmann05a17852019-03-28 16:39:21 +0100279
280 return rc;
281}
282
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100283static void qeth_l3_drain_rx_mode_cache(struct qeth_card *card)
284{
285 struct qeth_ipaddr *addr;
286 struct hlist_node *tmp;
287 int i;
288
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100289 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
290 hash_del(&addr->hnode);
291 kfree(addr);
292 }
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100293}
294
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200295static void qeth_l3_clear_ip_htable(struct qeth_card *card, int recover)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100296{
297 struct qeth_ipaddr *addr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200298 struct hlist_node *tmp;
299 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100300
Carsten Otte847a50f2010-06-21 22:57:05 +0000301 QETH_CARD_TEXT(card, 4, "clearip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200302
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100303 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200304
305 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
306 if (!recover) {
307 hash_del(&addr->hnode);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100308 kfree(addr);
309 continue;
310 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200311 addr->disp_flag = QETH_DISP_ADDR_ADD;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100312 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200313
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100314 mutex_unlock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100315}
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100316
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200317static void qeth_l3_recover_ip(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100318{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200319 struct qeth_ipaddr *addr;
320 struct hlist_node *tmp;
321 int i;
322 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100323
Ursula Brauna7531c12016-09-15 14:39:23 +0200324 QETH_CARD_TEXT(card, 4, "recovrip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100325
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100326 mutex_lock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100327
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200328 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
Julian Wiedmann98d823a2018-02-27 18:58:13 +0100329 if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200330 if (addr->proto == QETH_PROT_IPV4) {
331 addr->in_progress = 1;
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100332 mutex_unlock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200333 rc = qeth_l3_register_addr_entry(card, addr);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100334 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200335 addr->in_progress = 0;
336 } else
337 rc = qeth_l3_register_addr_entry(card, addr);
338
339 if (!rc) {
340 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Ursula Brauna7531c12016-09-15 14:39:23 +0200341 if (addr->ref_counter < 1)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200342 qeth_l3_delete_ip(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200343 } else {
344 hash_del(&addr->hnode);
345 kfree(addr);
346 }
347 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100348 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200349
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100350 mutex_unlock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100351}
352
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100353static int qeth_l3_setdelip_cb(struct qeth_card *card, struct qeth_reply *reply,
354 unsigned long data)
355{
356 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
357
358 switch (cmd->hdr.return_code) {
359 case IPA_RC_SUCCESS:
360 return 0;
361 case IPA_RC_DUPLICATE_IP_ADDRESS:
362 return -EADDRINUSE;
363 case IPA_RC_MC_ADDR_NOT_FOUND:
364 return -ENOENT;
365 case IPA_RC_LAN_OFFLINE:
366 return -ENETDOWN;
367 default:
368 return -EIO;
369 }
370}
371
Frank Blaschka4a71df52008-02-15 09:19:42 +0100372static int qeth_l3_send_setdelmc(struct qeth_card *card,
373 struct qeth_ipaddr *addr, int ipacmd)
374{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100375 struct qeth_cmd_buffer *iob;
376 struct qeth_ipa_cmd *cmd;
377
Carsten Otte847a50f2010-06-21 22:57:05 +0000378 QETH_CARD_TEXT(card, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100379
380 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100381 if (!iob)
382 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100383 cmd = __ipa_cmd(iob);
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100384 ether_addr_copy(cmd->data.setdelipm.mac, addr->mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100385 if (addr->proto == QETH_PROT_IPV6)
386 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
387 sizeof(struct in6_addr));
388 else
389 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
390
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100391 return qeth_send_ipa_cmd(card, iob, qeth_l3_setdelip_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100392}
393
394static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
395{
396 int i, j;
397 for (i = 0; i < 16; i++) {
398 j = (len) - (i * 8);
399 if (j >= 8)
400 netmask[i] = 0xff;
401 else if (j > 0)
402 netmask[i] = (u8)(0xFF00 >> j);
403 else
404 netmask[i] = 0;
405 }
406}
407
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100408static u32 qeth_l3_get_setdelip_flags(struct qeth_ipaddr *addr, bool set)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100409{
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100410 switch (addr->type) {
411 case QETH_IP_TYPE_RXIP:
412 return (set) ? QETH_IPA_SETIP_TAKEOVER_FLAG : 0;
413 case QETH_IP_TYPE_VIPA:
414 return (set) ? QETH_IPA_SETIP_VIPA_FLAG :
415 QETH_IPA_DELIP_VIPA_FLAG;
416 default:
417 return (set && addr->ipato) ? QETH_IPA_SETIP_TAKEOVER_FLAG : 0;
418 }
419}
420
421static int qeth_l3_send_setdelip(struct qeth_card *card,
422 struct qeth_ipaddr *addr,
423 enum qeth_ipa_cmds ipacmd)
424{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100425 struct qeth_cmd_buffer *iob;
426 struct qeth_ipa_cmd *cmd;
427 __u8 netmask[16];
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100428 u32 flags;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100429
Carsten Otte847a50f2010-06-21 22:57:05 +0000430 QETH_CARD_TEXT(card, 4, "setdelip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100431
432 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100433 if (!iob)
434 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100435 cmd = __ipa_cmd(iob);
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100436
437 flags = qeth_l3_get_setdelip_flags(addr, ipacmd == IPA_CMD_SETIP);
438 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
439
Frank Blaschka4a71df52008-02-15 09:19:42 +0100440 if (addr->proto == QETH_PROT_IPV6) {
441 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
442 sizeof(struct in6_addr));
443 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
444 memcpy(cmd->data.setdelip6.mask, netmask,
445 sizeof(struct in6_addr));
446 cmd->data.setdelip6.flags = flags;
447 } else {
448 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
449 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
450 cmd->data.setdelip4.flags = flags;
451 }
452
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100453 return qeth_send_ipa_cmd(card, iob, qeth_l3_setdelip_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100454}
455
456static int qeth_l3_send_setrouting(struct qeth_card *card,
457 enum qeth_routing_types type, enum qeth_prot_versions prot)
458{
459 int rc;
460 struct qeth_ipa_cmd *cmd;
461 struct qeth_cmd_buffer *iob;
462
Carsten Otte847a50f2010-06-21 22:57:05 +0000463 QETH_CARD_TEXT(card, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100464 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100465 if (!iob)
466 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100467 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100468 cmd->data.setrtg.type = (type);
469 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
470
471 return rc;
472}
473
Stefan Raspl82e2e782013-03-18 20:04:43 +0000474static int qeth_l3_correct_routing_type(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100475 enum qeth_routing_types *type, enum qeth_prot_versions prot)
476{
Julian Wiedmann379ac992019-04-25 18:25:57 +0200477 if (IS_IQD(card)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100478 switch (*type) {
479 case NO_ROUTER:
480 case PRIMARY_CONNECTOR:
481 case SECONDARY_CONNECTOR:
482 case MULTICAST_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000483 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100484 default:
485 goto out_inval;
486 }
487 } else {
488 switch (*type) {
489 case NO_ROUTER:
490 case PRIMARY_ROUTER:
491 case SECONDARY_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000492 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100493 case MULTICAST_ROUTER:
494 if (qeth_is_ipafunc_supported(card, prot,
495 IPA_OSA_MC_ROUTER))
Stefan Raspl82e2e782013-03-18 20:04:43 +0000496 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100497 default:
498 goto out_inval;
499 }
500 }
501out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100502 *type = NO_ROUTER;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000503 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100504}
505
506int qeth_l3_setrouting_v4(struct qeth_card *card)
507{
508 int rc;
509
Carsten Otte847a50f2010-06-21 22:57:05 +0000510 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100511
Stefan Raspl82e2e782013-03-18 20:04:43 +0000512 rc = qeth_l3_correct_routing_type(card, &card->options.route4.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100513 QETH_PROT_IPV4);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000514 if (rc)
515 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100516
517 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
518 QETH_PROT_IPV4);
519 if (rc) {
520 card->options.route4.type = NO_ROUTER;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100521 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n",
522 rc, CARD_DEVID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100523 }
524 return rc;
525}
526
527int qeth_l3_setrouting_v6(struct qeth_card *card)
528{
529 int rc = 0;
530
Carsten Otte847a50f2010-06-21 22:57:05 +0000531 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100532
533 if (!qeth_is_supported(card, IPA_IPV6))
534 return 0;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000535 rc = qeth_l3_correct_routing_type(card, &card->options.route6.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100536 QETH_PROT_IPV6);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000537 if (rc)
538 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100539
540 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
541 QETH_PROT_IPV6);
542 if (rc) {
543 card->options.route6.type = NO_ROUTER;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100544 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n",
545 rc, CARD_DEVID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100546 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100547 return rc;
548}
549
550/*
551 * IP address takeover related functions
552 */
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100553
554/**
555 * qeth_l3_update_ipato() - Update 'takeover' property, for all NORMAL IPs.
556 *
557 * Caller must hold ip_lock.
558 */
559void qeth_l3_update_ipato(struct qeth_card *card)
560{
561 struct qeth_ipaddr *addr;
562 unsigned int i;
563
564 hash_for_each(card->ip_htable, i, addr, hnode) {
565 if (addr->type != QETH_IP_TYPE_NORMAL)
566 continue;
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100567 addr->ipato = qeth_l3_is_addr_covered_by_ipato(card, addr);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100568 }
569}
570
Frank Blaschka4a71df52008-02-15 09:19:42 +0100571static void qeth_l3_clear_ipato_list(struct qeth_card *card)
572{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100573 struct qeth_ipato_entry *ipatoe, *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100574
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100575 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200576
Frank Blaschka4a71df52008-02-15 09:19:42 +0100577 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
578 list_del(&ipatoe->entry);
579 kfree(ipatoe);
580 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200581
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100582 qeth_l3_update_ipato(card);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100583 mutex_unlock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100584}
585
586int qeth_l3_add_ipato_entry(struct qeth_card *card,
587 struct qeth_ipato_entry *new)
588{
589 struct qeth_ipato_entry *ipatoe;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100590 int rc = 0;
591
Carsten Otte847a50f2010-06-21 22:57:05 +0000592 QETH_CARD_TEXT(card, 2, "addipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200593
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100594 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200595
Frank Blaschka4a71df52008-02-15 09:19:42 +0100596 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
597 if (ipatoe->proto != new->proto)
598 continue;
599 if (!memcmp(ipatoe->addr, new->addr,
600 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
601 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100602 rc = -EEXIST;
603 break;
604 }
605 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200606
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100607 if (!rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100608 list_add_tail(&new->entry, &card->ipato.entries);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100609 qeth_l3_update_ipato(card);
610 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100611
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100612 mutex_unlock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200613
Frank Blaschka4a71df52008-02-15 09:19:42 +0100614 return rc;
615}
616
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100617int qeth_l3_del_ipato_entry(struct qeth_card *card,
618 enum qeth_prot_versions proto, u8 *addr,
619 int mask_bits)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100620{
621 struct qeth_ipato_entry *ipatoe, *tmp;
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100622 int rc = -ENOENT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100623
Carsten Otte847a50f2010-06-21 22:57:05 +0000624 QETH_CARD_TEXT(card, 2, "delipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200625
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100626 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200627
Frank Blaschka4a71df52008-02-15 09:19:42 +0100628 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
629 if (ipatoe->proto != proto)
630 continue;
631 if (!memcmp(ipatoe->addr, addr,
632 (proto == QETH_PROT_IPV4)? 4:16) &&
633 (ipatoe->mask_bits == mask_bits)) {
634 list_del(&ipatoe->entry);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100635 qeth_l3_update_ipato(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100636 kfree(ipatoe);
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100637 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100638 }
639 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200640
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100641 mutex_unlock(&card->ip_lock);
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100642 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100643}
644
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100645int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip,
646 enum qeth_ip_types type,
647 enum qeth_prot_versions proto)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100648{
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100649 struct qeth_ipaddr addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100650
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100651 qeth_l3_init_ipaddr(&addr, type, proto);
652 if (proto == QETH_PROT_IPV4)
653 memcpy(&addr.u.a4.addr, ip, 4);
654 else
655 memcpy(&addr.u.a6.addr, ip, 16);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200656
Julian Wiedmann05a17852019-03-28 16:39:21 +0100657 return qeth_l3_modify_ip(card, &addr, add);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100658}
659
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100660int qeth_l3_modify_hsuid(struct qeth_card *card, bool add)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100661{
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100662 struct qeth_ipaddr addr;
Julian Wiedmann05a17852019-03-28 16:39:21 +0100663 unsigned int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100664
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100665 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV6);
666 addr.u.a6.addr.s6_addr[0] = 0xfe;
667 addr.u.a6.addr.s6_addr[1] = 0x80;
668 for (i = 0; i < 8; i++)
669 addr.u.a6.addr.s6_addr[8+i] = card->options.hsuid[i];
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200670
Julian Wiedmann05a17852019-03-28 16:39:21 +0100671 return qeth_l3_modify_ip(card, &addr, add);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100672}
673
674static int qeth_l3_register_addr_entry(struct qeth_card *card,
675 struct qeth_ipaddr *addr)
676{
677 char buf[50];
678 int rc = 0;
679 int cnt = 3;
680
Julian Wiedmannbd74a7f2018-11-02 19:04:09 +0100681 if (card->options.sniffer)
682 return 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200683
Frank Blaschka4a71df52008-02-15 09:19:42 +0100684 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000685 QETH_CARD_TEXT(card, 2, "setaddr4");
686 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100687 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000688 QETH_CARD_TEXT(card, 2, "setaddr6");
689 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
690 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100691 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000692 QETH_CARD_TEXT(card, 2, "setaddr?");
693 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100694 }
695 do {
696 if (addr->is_multicast)
697 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
698 else
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100699 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100700 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000701 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100702 } while ((--cnt > 0) && rc);
703 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000704 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100705 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100706 dev_warn(&card->gdev->dev,
707 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100708 }
709 return rc;
710}
711
712static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
713 struct qeth_ipaddr *addr)
714{
715 int rc = 0;
716
Julian Wiedmannbd74a7f2018-11-02 19:04:09 +0100717 if (card->options.sniffer)
718 return 0;
719
Frank Blaschka4a71df52008-02-15 09:19:42 +0100720 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000721 QETH_CARD_TEXT(card, 2, "deladdr4");
722 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100723 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000724 QETH_CARD_TEXT(card, 2, "deladdr6");
725 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
726 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100727 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000728 QETH_CARD_TEXT(card, 2, "deladdr?");
729 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100730 }
731 if (addr->is_multicast)
732 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
733 else
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100734 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200735 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000736 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100737
738 return rc;
739}
740
Frank Blaschka4a71df52008-02-15 09:19:42 +0100741static int qeth_l3_setadapter_parms(struct qeth_card *card)
742{
Julian Wiedmann699d3fe2017-08-15 17:02:41 +0200743 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100744
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200745 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100746
Frank Blaschka4a71df52008-02-15 09:19:42 +0100747 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
748 rc = qeth_setadpparms_change_macaddr(card);
749 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100750 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -0800751 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100752 }
753
Frank Blaschka4a71df52008-02-15 09:19:42 +0100754 return rc;
755}
756
Frank Blaschka4a71df52008-02-15 09:19:42 +0100757static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
758{
759 int rc;
760
Carsten Otte847a50f2010-06-21 22:57:05 +0000761 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100762
763 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100764 dev_info(&card->gdev->dev,
765 "ARP processing not supported on %s!\n",
766 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100767 return 0;
768 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200769 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
770 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100771 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100772 dev_warn(&card->gdev->dev,
773 "Starting ARP processing support for %s failed\n",
774 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100775 }
776 return rc;
777}
778
Frank Blaschka4a71df52008-02-15 09:19:42 +0100779static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
780{
781 int rc;
782
Carsten Otte847a50f2010-06-21 22:57:05 +0000783 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100784
Frank Blaschka4a71df52008-02-15 09:19:42 +0100785 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100786 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800787 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100788 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100789 return -EOPNOTSUPP;
790 }
791
Thomas Richter4d7def22015-09-18 16:06:51 +0200792 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100793 IPA_CMD_ASS_START, 0);
794 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100795 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800796 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100797 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100798 return rc;
799}
800
801static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
802{
803 int rc = 0;
804
Carsten Otte847a50f2010-06-21 22:57:05 +0000805 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100806
807 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100808 dev_info(&card->gdev->dev,
809 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100810 return -EOPNOTSUPP;
811 }
812
Thomas Richter4d7def22015-09-18 16:06:51 +0200813 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100814 IPA_CMD_ASS_START, 0);
815 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100816 dev_warn(&card->gdev->dev,
817 "Starting VLAN support for %s failed\n",
818 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100819 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100820 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100821 }
822 return rc;
823}
824
825static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
826{
827 int rc;
828
Carsten Otte847a50f2010-06-21 22:57:05 +0000829 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100830
831 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100832 dev_info(&card->gdev->dev,
833 "Multicast not supported on %s\n",
834 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100835 return -EOPNOTSUPP;
836 }
837
Thomas Richter4d7def22015-09-18 16:06:51 +0200838 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100839 IPA_CMD_ASS_START, 0);
840 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100841 dev_warn(&card->gdev->dev,
842 "Starting multicast support for %s failed\n",
843 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100844 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100845 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100846 card->dev->flags |= IFF_MULTICAST;
847 }
848 return rc;
849}
850
Frank Blaschka4a71df52008-02-15 09:19:42 +0100851static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
852{
853 int rc;
854
Carsten Otte847a50f2010-06-21 22:57:05 +0000855 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100856
Julian Wiedmann379ac992019-04-25 18:25:57 +0200857 if (IS_IQD(card))
Julian Wiedmann23274592017-06-06 14:33:44 +0200858 goto out;
859
Thomas Richter4d7def22015-09-18 16:06:51 +0200860 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100861 IPA_CMD_ASS_START, 3);
862 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100863 dev_err(&card->gdev->dev,
864 "Activating IPv6 support for %s failed\n",
865 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100866 return rc;
867 }
Kittipon Meesompopa8155b02018-04-26 09:42:21 +0200868 rc = qeth_send_simple_setassparms_v6(card, IPA_IPV6,
869 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100870 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100871 dev_err(&card->gdev->dev,
872 "Activating IPv6 support for %s failed\n",
873 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100874 return rc;
875 }
Kittipon Meesompopa8155b02018-04-26 09:42:21 +0200876 rc = qeth_send_simple_setassparms_v6(card, IPA_PASSTHRU,
877 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100878 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100879 dev_warn(&card->gdev->dev,
880 "Enabling the passthrough mode for %s failed\n",
881 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100882 return rc;
883 }
884out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100885 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100886 return 0;
887}
Frank Blaschka4a71df52008-02-15 09:19:42 +0100888
889static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
890{
Carsten Otte847a50f2010-06-21 22:57:05 +0000891 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100892
893 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100894 dev_info(&card->gdev->dev,
895 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100896 return 0;
897 }
Julian Wiedmannc0622042017-12-20 20:10:58 +0100898 return qeth_l3_softsetup_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100899}
900
901static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
902{
903 int rc;
904
Carsten Otte847a50f2010-06-21 22:57:05 +0000905 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100906 card->info.broadcast_capable = 0;
907 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100908 dev_info(&card->gdev->dev,
909 "Broadcast not supported on %s\n",
910 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100911 rc = -EOPNOTSUPP;
912 goto out;
913 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200914 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100915 IPA_CMD_ASS_START, 0);
916 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100917 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
918 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100919 goto out;
920 }
921
Thomas Richter4d7def22015-09-18 16:06:51 +0200922 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100923 IPA_CMD_ASS_CONFIGURE, 1);
924 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100925 dev_warn(&card->gdev->dev,
926 "Setting up broadcast filtering for %s failed\n",
927 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100928 goto out;
929 }
930 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100931 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Thomas Richter4d7def22015-09-18 16:06:51 +0200932 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100933 IPA_CMD_ASS_ENABLE, 1);
934 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100935 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
936 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100937 goto out;
938 }
939 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
940out:
941 if (card->info.broadcast_capable)
942 card->dev->flags |= IFF_BROADCAST;
943 else
944 card->dev->flags &= ~IFF_BROADCAST;
945 return rc;
946}
947
Frank Blaschka4a71df52008-02-15 09:19:42 +0100948static int qeth_l3_start_ipassists(struct qeth_card *card)
949{
Carsten Otte847a50f2010-06-21 22:57:05 +0000950 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +0000951
Stefan Raspl0f547612013-01-21 02:30:20 +0000952 if (qeth_set_access_ctrl_online(card, 0))
953 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100954 qeth_l3_start_ipa_arp_processing(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +0100955 qeth_l3_start_ipa_source_mac(card); /* go on*/
956 qeth_l3_start_ipa_vlan(card); /* go on*/
957 qeth_l3_start_ipa_multicast(card); /* go on*/
958 qeth_l3_start_ipa_ipv6(card); /* go on*/
959 qeth_l3_start_ipa_broadcast(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +0100960 return 0;
961}
962
Frank Blaschka4a71df52008-02-15 09:19:42 +0100963static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
964 struct qeth_reply *reply, unsigned long data)
965{
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100966 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100967
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100968 if (cmd->hdr.return_code)
969 return -EIO;
970
971 ether_addr_copy(card->dev->dev_addr,
972 cmd->data.create_destroy_addr.unique_id);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100973 return 0;
974}
975
976static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
977{
978 int rc = 0;
979 struct qeth_cmd_buffer *iob;
980 struct qeth_ipa_cmd *cmd;
981
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200982 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100983
984 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
985 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100986 if (!iob)
987 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100988 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100989 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
990 card->info.unique_id;
991
992 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
993 NULL);
994 return rc;
995}
996
997static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
998 struct qeth_reply *reply, unsigned long data)
999{
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001000 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001001
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001002 if (cmd->hdr.return_code == 0) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001003 card->info.unique_id = *((__u16 *)
1004 &cmd->data.create_destroy_addr.unique_id[6]);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001005 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001006 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001007
1008 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1009 UNIQUE_ID_NOT_BY_CARD;
1010 dev_warn(&card->gdev->dev, "The network adapter failed to generate a unique ID\n");
1011 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001012}
1013
1014static int qeth_l3_get_unique_id(struct qeth_card *card)
1015{
1016 int rc = 0;
1017 struct qeth_cmd_buffer *iob;
1018 struct qeth_ipa_cmd *cmd;
1019
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001020 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001021
1022 if (!qeth_is_supported(card, IPA_IPV6)) {
1023 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1024 UNIQUE_ID_NOT_BY_CARD;
1025 return 0;
1026 }
1027
1028 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1029 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001030 if (!iob)
1031 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001032 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001033 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1034 card->info.unique_id;
1035
1036 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1037 return rc;
1038}
1039
Ursula Braun76b11f82010-01-11 02:50:50 +00001040static int
1041qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1042 unsigned long data)
1043{
1044 struct qeth_ipa_cmd *cmd;
1045 __u16 rc;
1046
1047 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1048
1049 cmd = (struct qeth_ipa_cmd *)data;
1050 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001051 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001052 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001053 switch (cmd->data.diagass.action) {
1054 case QETH_DIAGS_CMD_TRACE_QUERY:
1055 break;
1056 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001057 switch (rc) {
1058 case 0:
1059 case IPA_RC_INVALID_SUBCMD:
1060 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1061 dev_info(&card->gdev->dev, "The HiperSockets network "
1062 "traffic analyzer is deactivated\n");
1063 break;
1064 default:
1065 break;
1066 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001067 break;
1068 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001069 switch (rc) {
1070 case 0:
1071 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1072 dev_info(&card->gdev->dev, "The HiperSockets network "
1073 "traffic analyzer is activated\n");
1074 break;
1075 case IPA_RC_HARDWARE_AUTH_ERROR:
1076 dev_warn(&card->gdev->dev, "The device is not "
1077 "authorized to run as a HiperSockets network "
1078 "traffic analyzer\n");
1079 break;
1080 case IPA_RC_TRACE_ALREADY_ACTIVE:
1081 dev_warn(&card->gdev->dev, "A HiperSockets "
1082 "network traffic analyzer is already "
1083 "active in the HiperSockets LAN\n");
1084 break;
1085 default:
1086 break;
1087 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001088 break;
1089 default:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001090 QETH_DBF_MESSAGE(2, "Unknown sniffer action (%#06x) on device %x\n",
1091 cmd->data.diagass.action, CARD_DEVID(card));
Ursula Braun76b11f82010-01-11 02:50:50 +00001092 }
1093
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001094 return rc ? -EIO : 0;
Ursula Braun76b11f82010-01-11 02:50:50 +00001095}
1096
1097static int
1098qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1099{
1100 struct qeth_cmd_buffer *iob;
1101 struct qeth_ipa_cmd *cmd;
1102
1103 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1104
1105 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001106 if (!iob)
1107 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001108 cmd = __ipa_cmd(iob);
Ursula Braun76b11f82010-01-11 02:50:50 +00001109 cmd->data.diagass.subcmd_len = 16;
1110 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1111 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1112 cmd->data.diagass.action = diags_cmd;
1113 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1114}
1115
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001116static void
1117qeth_l3_add_mc_to_hash(struct qeth_card *card, struct in_device *in4_dev)
1118{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001119 struct ip_mc_list *im4;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001120 struct qeth_ipaddr *tmp, *ipm;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001121
Carsten Otte847a50f2010-06-21 22:57:05 +00001122 QETH_CARD_TEXT(card, 4, "addmc");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001123
1124 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001125 if (!tmp)
1126 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001127
Sachin Santf3aa3132010-11-26 02:41:17 +00001128 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1129 im4 = rcu_dereference(im4->next_rcu)) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001130 ip_eth_mc_map(im4->multiaddr, tmp->mac);
Hans Wippel6bee4e22017-04-07 09:15:36 +02001131 tmp->u.a4.addr = be32_to_cpu(im4->multiaddr);
Julian Wiedmannbc3ab7052017-12-01 10:14:49 +01001132 tmp->is_multicast = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001133
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001134 ipm = qeth_l3_find_addr_by_ip(card, tmp);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001135 if (ipm) {
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001136 /* for mcast, by-IP match means full match */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001137 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1138 } else {
1139 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1140 if (!ipm)
1141 continue;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001142 ether_addr_copy(ipm->mac, tmp->mac);
Hans Wippel6bee4e22017-04-07 09:15:36 +02001143 ipm->u.a4.addr = be32_to_cpu(im4->multiaddr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001144 ipm->is_multicast = 1;
1145 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1146 hash_add(card->ip_mc_htable,
1147 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1148 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001149 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001150
1151 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001152}
1153
Jiri Pirko0347af52013-01-03 22:48:58 +00001154/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001155static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1156{
1157 struct in_device *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001158 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001159
Carsten Otte847a50f2010-06-21 22:57:05 +00001160 QETH_CARD_TEXT(card, 4, "addmcvl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001161
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001162 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001163 return;
1164
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001165 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1166 struct net_device *netdev;
1167
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001168 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001169 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001170 if (netdev == NULL ||
1171 !(netdev->flags & IFF_UP))
1172 continue;
Jiri Pirko0347af52013-01-03 22:48:58 +00001173 in_dev = __in_dev_get_rcu(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001174 if (!in_dev)
1175 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001176 qeth_l3_add_mc_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001177 }
1178}
1179
1180static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1181{
1182 struct in_device *in4_dev;
1183
Carsten Otte847a50f2010-06-21 22:57:05 +00001184 QETH_CARD_TEXT(card, 4, "chkmcv4");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001185
Sachin Santf3aa3132010-11-26 02:41:17 +00001186 rcu_read_lock();
Jiri Pirko0347af52013-01-03 22:48:58 +00001187 in4_dev = __in_dev_get_rcu(card->dev);
1188 if (in4_dev == NULL)
1189 goto unlock;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001190 qeth_l3_add_mc_to_hash(card, in4_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001191 qeth_l3_add_vlan_mc(card);
Jiri Pirko0347af52013-01-03 22:48:58 +00001192unlock:
Sachin Santf3aa3132010-11-26 02:41:17 +00001193 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001194}
1195
Julian Wiedmannc0622042017-12-20 20:10:58 +01001196static void qeth_l3_add_mc6_to_hash(struct qeth_card *card,
1197 struct inet6_dev *in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001198{
1199 struct qeth_ipaddr *ipm;
1200 struct ifmcaddr6 *im6;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001201 struct qeth_ipaddr *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001202
Carsten Otte847a50f2010-06-21 22:57:05 +00001203 QETH_CARD_TEXT(card, 4, "addmc6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001204
1205 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001206 if (!tmp)
1207 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001208
Frank Blaschka4a71df52008-02-15 09:19:42 +01001209 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001210 ipv6_eth_mc_map(&im6->mca_addr, tmp->mac);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001211 memcpy(&tmp->u.a6.addr, &im6->mca_addr.s6_addr,
1212 sizeof(struct in6_addr));
1213 tmp->is_multicast = 1;
1214
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001215 ipm = qeth_l3_find_addr_by_ip(card, tmp);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001216 if (ipm) {
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001217 /* for mcast, by-IP match means full match */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001218 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1219 continue;
1220 }
1221
Frank Blaschka4a71df52008-02-15 09:19:42 +01001222 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1223 if (!ipm)
1224 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001225
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001226 ether_addr_copy(ipm->mac, tmp->mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001227 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1228 sizeof(struct in6_addr));
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001229 ipm->is_multicast = 1;
1230 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1231 hash_add(card->ip_mc_htable,
1232 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1233
Frank Blaschka4a71df52008-02-15 09:19:42 +01001234 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001235 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001236}
1237
Jiri Pirko0347af52013-01-03 22:48:58 +00001238/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001239static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1240{
1241 struct inet6_dev *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001242 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001243
Carsten Otte847a50f2010-06-21 22:57:05 +00001244 QETH_CARD_TEXT(card, 4, "admc6vl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001245
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001246 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001247 return;
1248
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001249 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1250 struct net_device *netdev;
1251
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001252 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001253 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001254 if (netdev == NULL ||
1255 !(netdev->flags & IFF_UP))
1256 continue;
1257 in_dev = in6_dev_get(netdev);
1258 if (!in_dev)
1259 continue;
1260 read_lock_bh(&in_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001261 qeth_l3_add_mc6_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001262 read_unlock_bh(&in_dev->lock);
1263 in6_dev_put(in_dev);
1264 }
1265}
1266
1267static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1268{
1269 struct inet6_dev *in6_dev;
1270
Carsten Otte847a50f2010-06-21 22:57:05 +00001271 QETH_CARD_TEXT(card, 4, "chkmcv6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001272
Frank Blaschka4a71df52008-02-15 09:19:42 +01001273 if (!qeth_is_supported(card, IPA_IPV6))
1274 return ;
1275 in6_dev = in6_dev_get(card->dev);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001276 if (!in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001277 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001278
Jiri Pirko0347af52013-01-03 22:48:58 +00001279 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001280 read_lock_bh(&in6_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001281 qeth_l3_add_mc6_to_hash(card, in6_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001282 qeth_l3_add_vlan_mc6(card);
1283 read_unlock_bh(&in6_dev->lock);
Jiri Pirko0347af52013-01-03 22:48:58 +00001284 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001285 in6_dev_put(in6_dev);
1286}
Frank Blaschka4a71df52008-02-15 09:19:42 +01001287
Patrick McHardy80d5c362013-04-19 02:04:28 +00001288static int qeth_l3_vlan_rx_add_vid(struct net_device *dev,
1289 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001290{
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001291 struct qeth_card *card = dev->ml_priv;
1292
1293 set_bit(vid, card->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001294 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001295}
1296
Patrick McHardy80d5c362013-04-19 02:04:28 +00001297static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev,
1298 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001299{
Heiko Carstens509e2562008-07-26 02:24:10 -07001300 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001301
Carsten Otte847a50f2010-06-21 22:57:05 +00001302 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001303
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001304 clear_bit(vid, card->active_vlans);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001305 qeth_l3_set_rx_mode(dev);
Jiri Pirko8e586132011-12-08 19:52:37 -05001306 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001307}
1308
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001309static void qeth_l3_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
1310 struct qeth_hdr *hdr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001311{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001312 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001313 u16 prot = (hdr->hdr.l3.flags & QETH_HDR_IPV6) ? ETH_P_IPV6 :
1314 ETH_P_IP;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001315 unsigned char tg_addr[ETH_ALEN];
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001316
1317 skb_reset_network_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001318 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1319 case QETH_CAST_MULTICAST:
Julian Wiedmannc0622042017-12-20 20:10:58 +01001320 if (prot == ETH_P_IP)
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001321 ip_eth_mc_map(ip_hdr(skb)->daddr, tg_addr);
Julian Wiedmannc0622042017-12-20 20:10:58 +01001322 else
1323 ipv6_eth_mc_map(&ipv6_hdr(skb)->daddr, tg_addr);
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001324 QETH_CARD_STAT_INC(card, rx_multicast);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001325 break;
1326 case QETH_CAST_BROADCAST:
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001327 ether_addr_copy(tg_addr, card->dev->broadcast);
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001328 QETH_CARD_STAT_INC(card, rx_multicast);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001329 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001330 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00001331 if (card->options.sniffer)
1332 skb->pkt_type = PACKET_OTHERHOST;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001333 ether_addr_copy(tg_addr, card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001334 }
Julian Wiedmann04f67392018-03-09 18:12:58 +01001335
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001336 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1337 card->dev->header_ops->create(skb, card->dev, prot,
Julian Wiedmanna8433832017-12-20 20:11:06 +01001338 tg_addr, &hdr->hdr.l3.next_hop.rx.src_mac,
Julian Wiedmannf0ea8bf2018-03-09 18:12:56 +01001339 skb->len);
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001340 else
1341 card->dev->header_ops->create(skb, card->dev, prot,
Julian Wiedmannf0ea8bf2018-03-09 18:12:56 +01001342 tg_addr, "FAKELL", skb->len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001343 }
1344
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001345 skb->protocol = eth_type_trans(skb, card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001346
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001347 /* copy VLAN tag from hdr into skb */
1348 if (!card->options.sniffer &&
1349 (hdr->hdr.l3.ext_flags & (QETH_HDR_EXT_VLAN_FRAME |
1350 QETH_HDR_EXT_INCLUDE_VLAN_TAG))) {
1351 u16 tag = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
1352 hdr->hdr.l3.vlan_id :
Julian Wiedmanna8433832017-12-20 20:11:06 +01001353 hdr->hdr.l3.next_hop.rx.vlan_id;
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001354 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001355 }
1356
Julian Wiedmann6195b932018-04-26 09:42:17 +02001357 qeth_rx_csum(card, skb, hdr->hdr.l3.ext_flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001358}
1359
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001360static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1361 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001362{
Julian Wiedmanncd11d112018-09-26 18:29:06 +02001363 struct net_device *dev = card->dev;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001364 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001365 struct sk_buff *skb;
1366 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001367 unsigned int len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001368 __u16 magic;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001369
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001370 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +00001371 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001372 while (budget) {
1373 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +00001374 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001375 &card->rx.b_element, &card->rx.e_offset, &hdr);
1376 if (!skb) {
1377 *done = 1;
1378 break;
1379 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001380 switch (hdr->hdr.l3.id) {
1381 case QETH_HEADER_TYPE_LAYER3:
Frank Blaschkab3332932011-08-08 01:33:59 +00001382 magic = *(__u16 *)skb->data;
Julian Wiedmann379ac992019-04-25 18:25:57 +02001383 if (IS_IQD(card) && magic == ETH_P_AF_IUCV) {
Frank Blaschkab3332932011-08-08 01:33:59 +00001384 len = skb->len;
Julian Wiedmanncd11d112018-09-26 18:29:06 +02001385 dev_hard_header(skb, dev, ETH_P_AF_IUCV,
1386 dev->dev_addr, "FAKELL", len);
1387 skb->protocol = eth_type_trans(skb, dev);
Frank Blaschkab3332932011-08-08 01:33:59 +00001388 netif_receive_skb(skb);
1389 } else {
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001390 qeth_l3_rebuild_skb(card, skb, hdr);
Frank Blaschkab3332932011-08-08 01:33:59 +00001391 len = skb->len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001392 napi_gro_receive(&card->napi, skb);
1393 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001394 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00001395 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
Ursula Braun76b11f82010-01-11 02:50:50 +00001396 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00001397 len = skb->len;
1398 netif_receive_skb(skb);
1399 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001400 default:
1401 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00001402 QETH_CARD_TEXT(card, 3, "inbunkno");
Julian Wiedmann0ac14872018-09-12 15:31:35 +02001403 QETH_DBF_HEX(CTRL, 3, hdr, sizeof(*hdr));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001404 continue;
1405 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001406 work_done++;
1407 budget--;
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001408 QETH_CARD_STAT_INC(card, rx_packets);
1409 QETH_CARD_STAT_ADD(card, rx_bytes, len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001410 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001411 return work_done;
1412}
1413
Julian Wiedmannd4560152019-02-28 18:59:39 +01001414static void qeth_l3_stop_card(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001415{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001416 QETH_DBF_TEXT(SETUP, 2, "stopcard");
1417 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001418
1419 qeth_set_allowed_threads(card, 0, 1);
Julian Wiedmann0f7aedbd2019-02-28 18:59:44 +01001420
Julian Wiedmannd0c74822019-03-28 16:39:19 +01001421 cancel_work_sync(&card->rx_mode_work);
1422 qeth_l3_drain_rx_mode_cache(card);
1423
Ursula Braun76b11f82010-01-11 02:50:50 +00001424 if (card->options.sniffer &&
1425 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
1426 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Julian Wiedmann0f7aedbd2019-02-28 18:59:44 +01001427
Frank Blaschka4a71df52008-02-15 09:19:42 +01001428 if (card->state == CARD_STATE_SOFTSETUP) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001429 qeth_l3_clear_ip_htable(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001430 qeth_clear_ipacmd_list(card);
1431 card->state = CARD_STATE_HARDSETUP;
1432 }
1433 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001434 qeth_qdio_clear_card(card, 0);
Julian Wiedmann41c47da2019-04-17 18:17:28 +02001435 qeth_drain_output_queues(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001436 qeth_clear_working_pool_list(card);
1437 card->state = CARD_STATE_DOWN;
1438 }
1439 if (card->state == CARD_STATE_DOWN) {
1440 qeth_clear_cmd_buffers(&card->read);
1441 qeth_clear_cmd_buffers(&card->write);
1442 }
Julian Wiedmannc0a2e4d2019-02-04 17:40:09 +01001443
1444 flush_workqueue(card->event_wq);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001445}
1446
Ursula Braun76b11f82010-01-11 02:50:50 +00001447/*
1448 * test for and Switch promiscuous mode (on or off)
1449 * either for guestlan or HiperSocket Sniffer
1450 */
1451static void
1452qeth_l3_handle_promisc_mode(struct qeth_card *card)
1453{
1454 struct net_device *dev = card->dev;
1455
1456 if (((dev->flags & IFF_PROMISC) &&
1457 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
1458 (!(dev->flags & IFF_PROMISC) &&
1459 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
1460 return;
1461
Julian Wiedmann379ac992019-04-25 18:25:57 +02001462 if (IS_VM_NIC(card)) { /* Guestlan trace */
Ursula Braun76b11f82010-01-11 02:50:50 +00001463 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
1464 qeth_setadp_promisc_mode(card);
1465 } else if (card->options.sniffer && /* HiperSockets trace */
1466 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
1467 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001468 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001469 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
1470 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00001471 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001472 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
1473 }
1474 }
1475}
1476
Julian Wiedmannd0c74822019-03-28 16:39:19 +01001477static void qeth_l3_rx_mode_work(struct work_struct *work)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001478{
Julian Wiedmannd0c74822019-03-28 16:39:19 +01001479 struct qeth_card *card = container_of(work, struct qeth_card,
1480 rx_mode_work);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001481 struct qeth_ipaddr *addr;
1482 struct hlist_node *tmp;
1483 int i, rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001484
Carsten Otte847a50f2010-06-21 22:57:05 +00001485 QETH_CARD_TEXT(card, 3, "setmulti");
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01001486
Ursula Braun76b11f82010-01-11 02:50:50 +00001487 if (!card->options.sniffer) {
Ursula Braun76b11f82010-01-11 02:50:50 +00001488 qeth_l3_add_multicast_ipv4(card);
Ursula Braun76b11f82010-01-11 02:50:50 +00001489 qeth_l3_add_multicast_ipv6(card);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001490
1491 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1492 switch (addr->disp_flag) {
1493 case QETH_DISP_ADDR_DELETE:
1494 rc = qeth_l3_deregister_addr_entry(card, addr);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001495 if (!rc || rc == -ENOENT) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001496 hash_del(&addr->hnode);
1497 kfree(addr);
1498 }
1499 break;
1500 case QETH_DISP_ADDR_ADD:
1501 rc = qeth_l3_register_addr_entry(card, addr);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001502 if (rc && rc != -ENETDOWN) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001503 hash_del(&addr->hnode);
1504 kfree(addr);
1505 break;
1506 }
1507 addr->ref_counter = 1;
1508 /* fall through */
1509 default:
1510 /* for next call to set_rx_mode(): */
1511 addr->disp_flag = QETH_DISP_ADDR_DELETE;
1512 }
1513 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001514
Ursula Braun76b11f82010-01-11 02:50:50 +00001515 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
1516 return;
1517 }
1518 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001519}
1520
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001521static int qeth_l3_arp_makerc(u16 rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001522{
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001523 switch (rc) {
1524 case IPA_RC_SUCCESS:
1525 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001526 case QETH_IPA_ARP_RC_NOTSUPP:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001527 case QETH_IPA_ARP_RC_Q_NOTSUPP:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001528 return -EOPNOTSUPP;
1529 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
1530 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001531 case QETH_IPA_ARP_RC_Q_NO_DATA:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001532 return -ENOENT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001533 default:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001534 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001535 }
1536}
1537
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001538static int qeth_l3_arp_cmd_cb(struct qeth_card *card, struct qeth_reply *reply,
1539 unsigned long data)
1540{
1541 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1542
1543 qeth_setassparms_cb(card, reply, data);
1544 return qeth_l3_arp_makerc(cmd->hdr.return_code);
1545}
1546
Frank Blaschka4a71df52008-02-15 09:19:42 +01001547static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
1548{
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001549 struct qeth_cmd_buffer *iob;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001550 int rc;
1551
Carsten Otte847a50f2010-06-21 22:57:05 +00001552 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001553
1554 /*
1555 * currently GuestLAN only supports the ARP assist function
1556 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
1557 * thus we say EOPNOTSUPP for this ARP function
1558 */
Julian Wiedmann379ac992019-04-25 18:25:57 +02001559 if (IS_VM_NIC(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001560 return -EOPNOTSUPP;
1561 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001562 return -EOPNOTSUPP;
1563 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001564
1565 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
1566 IPA_CMD_ASS_ARP_SET_NO_ENTRIES, 4,
1567 QETH_PROT_IPV4);
1568 if (!iob)
1569 return -ENOMEM;
1570
1571 __ipa_cmd(iob)->data.setassparms.data.flags_32bit = (u32) no_entries;
1572 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001573 if (rc)
1574 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on device %x: %#x\n",
1575 CARD_DEVID(card), rc);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001576 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001577}
1578
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001579static __u32 get_arp_entry_size(struct qeth_card *card,
1580 struct qeth_arp_query_data *qdata,
1581 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001582{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001583 __u32 rc;
1584 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001585
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001586 is_hsi = qdata->reply_bits == 5;
1587 if (type->ip == QETHARP_IP_ADDR_V4) {
1588 QETH_CARD_TEXT(card, 4, "arpev4");
1589 if (strip_entries) {
1590 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
1591 sizeof(struct qeth_arp_qi_entry7_short);
1592 } else {
1593 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
1594 sizeof(struct qeth_arp_qi_entry7);
1595 }
1596 } else if (type->ip == QETHARP_IP_ADDR_V6) {
1597 QETH_CARD_TEXT(card, 4, "arpev6");
1598 if (strip_entries) {
1599 rc = is_hsi ?
1600 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
1601 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
1602 } else {
1603 rc = is_hsi ?
1604 sizeof(struct qeth_arp_qi_entry5_ipv6) :
1605 sizeof(struct qeth_arp_qi_entry7_ipv6);
1606 }
1607 } else {
1608 QETH_CARD_TEXT(card, 4, "arpinv");
1609 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001610 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001611
1612 return rc;
1613}
1614
1615static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
1616{
1617 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
1618 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001619}
1620
1621static int qeth_l3_arp_query_cb(struct qeth_card *card,
1622 struct qeth_reply *reply, unsigned long data)
1623{
1624 struct qeth_ipa_cmd *cmd;
1625 struct qeth_arp_query_data *qdata;
1626 struct qeth_arp_query_info *qinfo;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001627 int e;
1628 int entrybytes_done;
1629 int stripped_bytes;
1630 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001631
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001632 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001633
1634 qinfo = (struct qeth_arp_query_info *) reply->param;
1635 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001636 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001637 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001638 QETH_CARD_TEXT(card, 4, "arpcberr");
1639 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001640 return qeth_l3_arp_makerc(cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001641 }
1642 if (cmd->data.setassparms.hdr.return_code) {
1643 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001644 QETH_CARD_TEXT(card, 4, "setaperr");
1645 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001646 return qeth_l3_arp_makerc(cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001647 }
1648 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00001649 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001650
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001651 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
1652 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
1653 entrybytes_done = 0;
1654 for (e = 0; e < qdata->no_entries; ++e) {
1655 char *cur_entry;
1656 __u32 esize;
1657 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001658
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001659 cur_entry = &qdata->data + entrybytes_done;
1660 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
1661 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
1662 QETH_CARD_TEXT(card, 4, "pmis");
1663 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
1664 break;
1665 }
1666 esize = get_arp_entry_size(card, qdata, etype,
1667 do_strip_entries);
1668 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
1669 if (!esize)
1670 break;
1671
1672 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001673 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOSPC);
1674 memset(qinfo->udata, 0, 4);
1675 return -ENOSPC;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001676 }
1677
1678 memcpy(qinfo->udata + qinfo->udata_offset,
1679 &qdata->data + entrybytes_done + stripped_bytes,
1680 esize);
1681 entrybytes_done += esize + stripped_bytes;
1682 qinfo->udata_offset += esize;
1683 ++qinfo->no_entries;
1684 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001685 /* check if all replies received ... */
1686 if (cmd->data.setassparms.hdr.seq_no <
1687 cmd->data.setassparms.hdr.number_of_replies)
1688 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001689 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001690 memcpy(qinfo->udata, &qinfo->no_entries, 4);
1691 /* keep STRIP_ENTRIES flag so the user program can distinguish
1692 * stripped entries from normal ones */
1693 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
1694 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
1695 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001696 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001697 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001698}
1699
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001700static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
1701 enum qeth_prot_versions prot,
1702 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001703{
1704 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001705 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001706 int rc;
1707
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001708 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
1709
Thomas Richterb475e312015-12-11 12:27:54 +01001710 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
1711 IPA_CMD_ASS_ARP_QUERY_INFO,
1712 sizeof(struct qeth_arp_query_data)
1713 - sizeof(char),
1714 prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001715 if (!iob)
1716 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001717 cmd = __ipa_cmd(iob);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001718 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
Julian Wiedmann84dbea42019-02-12 18:33:16 +01001719 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_query_cb, qinfo);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001720 if (rc)
1721 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on device %x: %#x\n",
1722 CARD_DEVID(card), rc);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001723 return rc;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001724}
1725
1726static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
1727{
1728 struct qeth_arp_query_info qinfo = {0, };
1729 int rc;
1730
Carsten Otte847a50f2010-06-21 22:57:05 +00001731 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001732
1733 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
1734 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001735 QETH_CARD_TEXT(card, 3, "arpqnsup");
1736 rc = -EOPNOTSUPP;
1737 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001738 }
1739 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001740 if (copy_from_user(&qinfo, udata, 6)) {
1741 rc = -EFAULT;
1742 goto out;
1743 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001744 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001745 if (!qinfo.udata) {
1746 rc = -ENOMEM;
1747 goto out;
1748 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001749 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001750 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001751 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001752 if (copy_to_user(udata, qinfo.udata, 4))
1753 rc = -EFAULT;
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001754 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001755 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001756 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
1757 /* fails in case of GuestLAN QDIO mode */
1758 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6, &qinfo);
1759 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001760 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
1761 QETH_CARD_TEXT(card, 4, "qactf");
1762 rc = -EFAULT;
1763 goto free_and_out;
1764 }
1765 QETH_CARD_TEXT(card, 4, "qacts");
1766
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001767free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001768 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001769out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001770 return rc;
1771}
1772
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001773static int qeth_l3_arp_modify_entry(struct qeth_card *card,
1774 struct qeth_arp_cache_entry *entry,
1775 enum qeth_arp_process_subcmds arp_cmd)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001776{
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001777 struct qeth_arp_cache_entry *cmd_entry;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001778 struct qeth_cmd_buffer *iob;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001779 int rc;
1780
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001781 if (arp_cmd == IPA_CMD_ASS_ARP_ADD_ENTRY)
1782 QETH_CARD_TEXT(card, 3, "arpadd");
1783 else
1784 QETH_CARD_TEXT(card, 3, "arpdel");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001785
1786 /*
1787 * currently GuestLAN only supports the ARP assist function
1788 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
1789 * thus we say EOPNOTSUPP for this ARP function
1790 */
Julian Wiedmann379ac992019-04-25 18:25:57 +02001791 if (IS_VM_NIC(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001792 return -EOPNOTSUPP;
1793 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001794 return -EOPNOTSUPP;
1795 }
1796
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001797 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, arp_cmd,
1798 sizeof(*cmd_entry), QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001799 if (!iob)
1800 return -ENOMEM;
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001801
1802 cmd_entry = &__ipa_cmd(iob)->data.setassparms.data.arp_entry;
1803 ether_addr_copy(cmd_entry->macaddr, entry->macaddr);
1804 memcpy(cmd_entry->ipaddr, entry->ipaddr, 4);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001805 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001806 if (rc)
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001807 QETH_DBF_MESSAGE(2, "Could not modify (cmd: %#x) ARP entry on device %x: %#x\n",
1808 arp_cmd, CARD_DEVID(card), rc);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001809 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001810}
1811
1812static int qeth_l3_arp_flush_cache(struct qeth_card *card)
1813{
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001814 struct qeth_cmd_buffer *iob;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001815 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001816
Carsten Otte847a50f2010-06-21 22:57:05 +00001817 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001818
1819 /*
1820 * currently GuestLAN only supports the ARP assist function
1821 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
1822 * thus we say EOPNOTSUPP for this ARP function
1823 */
Julian Wiedmann379ac992019-04-25 18:25:57 +02001824 if (IS_VM_NIC(card) || IS_IQD(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001825 return -EOPNOTSUPP;
1826 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001827 return -EOPNOTSUPP;
1828 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001829
1830 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
1831 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0,
1832 QETH_PROT_IPV4);
1833 if (!iob)
1834 return -ENOMEM;
1835
1836 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001837 if (rc)
1838 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on device %x: %#x\n",
1839 CARD_DEVID(card), rc);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001840 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001841}
1842
1843static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1844{
Heiko Carstens509e2562008-07-26 02:24:10 -07001845 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001846 struct qeth_arp_cache_entry arp_entry;
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001847 enum qeth_arp_process_subcmds arp_cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001848 int rc = 0;
1849
Frank Blaschka4a71df52008-02-15 09:19:42 +01001850 switch (cmd) {
1851 case SIOC_QETH_ARP_SET_NO_ENTRIES:
1852 if (!capable(CAP_NET_ADMIN)) {
1853 rc = -EPERM;
1854 break;
1855 }
1856 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
1857 break;
1858 case SIOC_QETH_ARP_QUERY_INFO:
1859 if (!capable(CAP_NET_ADMIN)) {
1860 rc = -EPERM;
1861 break;
1862 }
1863 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
1864 break;
1865 case SIOC_QETH_ARP_ADD_ENTRY:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001866 case SIOC_QETH_ARP_REMOVE_ENTRY:
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001867 if (!capable(CAP_NET_ADMIN))
1868 return -EPERM;
1869 if (copy_from_user(&arp_entry, rq->ifr_data, sizeof(arp_entry)))
1870 return -EFAULT;
1871
1872 arp_cmd = (cmd == SIOC_QETH_ARP_ADD_ENTRY) ?
1873 IPA_CMD_ASS_ARP_ADD_ENTRY :
1874 IPA_CMD_ASS_ARP_REMOVE_ENTRY;
1875 return qeth_l3_arp_modify_entry(card, &arp_entry, arp_cmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001876 case SIOC_QETH_ARP_FLUSH_CACHE:
1877 if (!capable(CAP_NET_ADMIN)) {
1878 rc = -EPERM;
1879 break;
1880 }
1881 rc = qeth_l3_arp_flush_cache(card);
1882 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001883 default:
1884 rc = -EOPNOTSUPP;
1885 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001886 return rc;
1887}
1888
Julian Wiedmann1f979122017-12-20 20:11:04 +01001889static int qeth_l3_get_cast_type(struct sk_buff *skb)
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001890{
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02001891 int ipv = qeth_get_ip_version(skb);
David S. Miller69cce1d2011-07-17 23:09:49 -07001892 struct neighbour *n = NULL;
1893 struct dst_entry *dst;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001894
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001895 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07001896 dst = skb_dst(skb);
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02001897 if (dst) {
1898 struct rt6_info *rt = (struct rt6_info *) dst;
1899
1900 dst = dst_check(dst, (ipv == 6) ? rt6_get_cookie(rt) : 0);
1901 if (dst)
1902 n = dst_neigh_lookup_skb(dst, skb);
1903 }
1904
David S. Miller69cce1d2011-07-17 23:09:49 -07001905 if (n) {
Julian Wiedmann1f979122017-12-20 20:11:04 +01001906 int cast_type = n->type;
1907
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001908 rcu_read_unlock();
David S. Miller24db1ba2012-07-02 22:02:33 -07001909 neigh_release(n);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001910 if ((cast_type == RTN_BROADCAST) ||
1911 (cast_type == RTN_MULTICAST) ||
1912 (cast_type == RTN_ANYCAST))
1913 return cast_type;
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +02001914 return RTN_UNICAST;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001915 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001916 rcu_read_unlock();
1917
Julian Wiedmann1f979122017-12-20 20:11:04 +01001918 /* no neighbour (eg AF_PACKET), fall back to target's IP address ... */
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02001919 switch (ipv) {
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001920 case 4:
Julian Wiedmann72c87972019-06-05 13:48:48 +02001921 if (ipv4_is_lbcast(ip_hdr(skb)->daddr))
1922 return RTN_BROADCAST;
Julian Wiedmann1f979122017-12-20 20:11:04 +01001923 return ipv4_is_multicast(ip_hdr(skb)->daddr) ?
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +02001924 RTN_MULTICAST : RTN_UNICAST;
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001925 case 6:
1926 return ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr) ?
1927 RTN_MULTICAST : RTN_UNICAST;
1928 default:
1929 /* ... and MAC address */
Julian Wiedmann58aa2492019-04-25 18:26:00 +02001930 return qeth_get_ether_cast_type(skb);
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001931 }
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001932}
1933
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001934static u8 qeth_l3_cast_type_to_flag(int cast_type)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001935{
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001936 if (cast_type == RTN_MULTICAST)
1937 return QETH_CAST_MULTICAST;
1938 if (cast_type == RTN_ANYCAST)
1939 return QETH_CAST_ANYCAST;
1940 if (cast_type == RTN_BROADCAST)
1941 return QETH_CAST_BROADCAST;
1942 return QETH_CAST_UNICAST;
1943}
David S. Miller69cce1d2011-07-17 23:09:49 -07001944
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001945static void qeth_l3_fill_header(struct qeth_qdio_out_q *queue,
1946 struct qeth_hdr *hdr, struct sk_buff *skb,
1947 int ipv, int cast_type, unsigned int data_len)
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001948{
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001949 struct qeth_hdr_layer3 *l3_hdr = &hdr->hdr.l3;
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001950 struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001951 struct qeth_card *card = queue->card;
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02001952 struct dst_entry *dst;
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001953
Julian Wiedmannf6c13142017-12-20 20:11:08 +01001954 hdr->hdr.l3.length = data_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001955
Julian Wiedmanne517b642018-09-17 17:36:02 +02001956 if (skb_is_gso(skb)) {
Julian Wiedmann0aef8392018-10-12 17:27:15 +02001957 hdr->hdr.l3.id = QETH_HEADER_TYPE_L3_TSO;
Julian Wiedmanne517b642018-09-17 17:36:02 +02001958 } else {
1959 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001960
1961 if (skb->protocol == htons(ETH_P_AF_IUCV)) {
1962 l3_hdr->flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
1963 l3_hdr->next_hop.ipv6_addr.s6_addr16[0] = htons(0xfe80);
1964 memcpy(&l3_hdr->next_hop.ipv6_addr.s6_addr32[2],
1965 iucv_trans_hdr(skb)->destUserID, 8);
1966 return;
1967 }
1968
Julian Wiedmanne517b642018-09-17 17:36:02 +02001969 if (skb->ip_summed == CHECKSUM_PARTIAL) {
1970 qeth_tx_csum(skb, &hdr->hdr.l3.ext_flags, ipv);
1971 /* some HW requires combined L3+L4 csum offload: */
1972 if (ipv == 4)
1973 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_HDR_REQ;
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001974 QETH_TXQ_STAT_INC(queue, skbs_csum);
Julian Wiedmanne517b642018-09-17 17:36:02 +02001975 }
1976 }
1977
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001978 if (ipv == 4 || IS_IQD(card)) {
1979 /* NETIF_F_HW_VLAN_CTAG_TX */
1980 if (skb_vlan_tag_present(skb)) {
1981 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_VLAN_FRAME;
1982 hdr->hdr.l3.vlan_id = skb_vlan_tag_get(skb);
1983 }
1984 } else if (veth->h_vlan_proto == htons(ETH_P_8021Q)) {
1985 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_INCLUDE_VLAN_TAG;
1986 hdr->hdr.l3.vlan_id = ntohs(veth->h_vlan_TCI);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001987 }
1988
Julian Wiedmann14a1b042019-04-25 18:26:01 +02001989 l3_hdr->flags = qeth_l3_cast_type_to_flag(cast_type);
1990
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001991 /* OSA only: */
1992 if (!ipv) {
Julian Wiedmann14a1b042019-04-25 18:26:01 +02001993 l3_hdr->flags |= QETH_HDR_PASSTHRU;
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001994 return;
1995 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001996
1997 rcu_read_lock();
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02001998 dst = skb_dst(skb);
1999
Frank Blaschka4a71df52008-02-15 09:19:42 +01002000 if (ipv == 4) {
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02002001 struct rtable *rt;
2002
2003 if (dst)
2004 dst = dst_check(dst, 0);
2005 rt = (struct rtable *) dst;
David Miller87e75972012-02-01 10:49:17 +00002006
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002007 *((__be32 *) &hdr->hdr.l3.next_hop.ipv4.addr) = (rt) ?
2008 rt_nexthop(rt, ip_hdr(skb)->daddr) :
2009 ip_hdr(skb)->daddr;
2010 } else {
2011 /* IPv6 */
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02002012 struct rt6_info *rt;
2013
2014 if (dst) {
2015 rt = (struct rt6_info *) dst;
2016 dst = dst_check(dst, rt6_get_cookie(rt));
2017 }
2018 rt = (struct rt6_info *) dst;
David Miller87e75972012-02-01 10:49:17 +00002019
Julian Wiedmannec2c6722017-08-07 13:28:39 +02002020 if (rt && !ipv6_addr_any(&rt->rt6i_gateway))
Julian Wiedmann5a541f62018-11-08 15:06:16 +01002021 l3_hdr->next_hop.ipv6_addr = rt->rt6i_gateway;
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002022 else
Julian Wiedmann5a541f62018-11-08 15:06:16 +01002023 l3_hdr->next_hop.ipv6_addr = ipv6_hdr(skb)->daddr;
David Miller87e75972012-02-01 10:49:17 +00002024
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002025 hdr->hdr.l3.flags |= QETH_HDR_IPV6;
Julian Wiedmann379ac992019-04-25 18:25:57 +02002026 if (!IS_IQD(card))
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002027 hdr->hdr.l3.flags |= QETH_HDR_PASSTHRU;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002028 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002029 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002030}
2031
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02002032static void qeth_l3_fixup_headers(struct sk_buff *skb)
2033{
2034 struct iphdr *iph = ip_hdr(skb);
2035
2036 /* this is safe, IPv6 traffic takes a different path */
2037 if (skb->ip_summed == CHECKSUM_PARTIAL)
2038 iph->check = 0;
Julian Wiedmanne517b642018-09-17 17:36:02 +02002039 if (skb_is_gso(skb)) {
2040 iph->tot_len = 0;
2041 tcp_hdr(skb)->check = ~tcp_v4_check(0, iph->saddr,
2042 iph->daddr, 0);
2043 }
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02002044}
2045
Julian Wiedmann356156b2018-09-17 17:36:03 +02002046static int qeth_l3_xmit(struct qeth_card *card, struct sk_buff *skb,
2047 struct qeth_qdio_out_q *queue, int ipv, int cast_type)
Julian Wiedmanna647a022018-07-11 17:42:46 +02002048{
Julian Wiedmann81ec5432018-11-08 15:06:17 +01002049 unsigned int hw_hdr_len;
2050 int rc;
Julian Wiedmanne517b642018-09-17 17:36:02 +02002051
Julian Wiedmanna647a022018-07-11 17:42:46 +02002052 /* re-use the L2 header area for the HW header: */
Julian Wiedmann81ec5432018-11-08 15:06:17 +01002053 hw_hdr_len = skb_is_gso(skb) ? sizeof(struct qeth_hdr_tso) :
2054 sizeof(struct qeth_hdr);
Julian Wiedmanna647a022018-07-11 17:42:46 +02002055 rc = skb_cow_head(skb, hw_hdr_len - ETH_HLEN);
2056 if (rc)
2057 return rc;
Julian Wiedmanna647a022018-07-11 17:42:46 +02002058 skb_pull(skb, ETH_HLEN);
Julian Wiedmanna647a022018-07-11 17:42:46 +02002059
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02002060 qeth_l3_fixup_headers(skb);
Julian Wiedmann54a50942019-04-17 18:17:35 +02002061 return qeth_xmit(card, skb, queue, ipv, cast_type, qeth_l3_fill_header);
Julian Wiedmanna647a022018-07-11 17:42:46 +02002062}
2063
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002064static netdev_tx_t qeth_l3_hard_start_xmit(struct sk_buff *skb,
2065 struct net_device *dev)
2066{
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002067 struct qeth_card *card = dev->ml_priv;
Julian Wiedmann3a18d752019-04-17 18:17:32 +02002068 u16 txq = skb_get_queue_mapping(skb);
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002069 int ipv = qeth_get_ip_version(skb);
2070 struct qeth_qdio_out_q *queue;
2071 int tx_bytes = skb->len;
Julian Wiedmann3a18d752019-04-17 18:17:32 +02002072 int cast_type, rc;
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002073
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002074 if (IS_IQD(card)) {
Julian Wiedmann3a18d752019-04-17 18:17:32 +02002075 queue = card->qdio.out_qs[qeth_iqd_translate_txq(dev, txq)];
2076
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002077 if (card->options.sniffer)
2078 goto tx_drop;
2079 if ((card->options.cq != QETH_CQ_ENABLED && !ipv) ||
2080 (card->options.cq == QETH_CQ_ENABLED &&
2081 skb->protocol != htons(ETH_P_AF_IUCV)))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002082 goto tx_drop;
Julian Wiedmann3a18d752019-04-17 18:17:32 +02002083
2084 if (txq == QETH_IQD_MCAST_TXQ)
2085 cast_type = qeth_l3_get_cast_type(skb);
2086 else
2087 cast_type = RTN_UNICAST;
2088 } else {
Julian Wiedmann73dc2da2019-04-17 18:17:33 +02002089 queue = card->qdio.out_qs[txq];
Julian Wiedmann3a18d752019-04-17 18:17:32 +02002090 cast_type = qeth_l3_get_cast_type(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002091 }
2092
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002093 if (cast_type == RTN_BROADCAST && !card->info.broadcast_capable)
2094 goto tx_drop;
2095
Julian Wiedmann356156b2018-09-17 17:36:03 +02002096 if (ipv == 4 || IS_IQD(card))
Julian Wiedmanna647a022018-07-11 17:42:46 +02002097 rc = qeth_l3_xmit(card, skb, queue, ipv, cast_type);
Julian Wiedmannf13ade12018-09-17 17:35:56 +02002098 else
2099 rc = qeth_xmit(card, skb, queue, ipv, cast_type,
2100 qeth_l3_fill_header);
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002101
2102 if (!rc) {
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002103 QETH_TXQ_STAT_INC(queue, tx_packets);
2104 QETH_TXQ_STAT_ADD(queue, tx_bytes, tx_bytes);
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002105 return NETDEV_TX_OK;
Julian Wiedmann54a50942019-04-17 18:17:35 +02002106 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002107
2108tx_drop:
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002109 QETH_TXQ_STAT_INC(queue, tx_dropped);
Julian Wiedmann104b4852019-03-18 16:40:56 +01002110 kfree_skb(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002111 return NETDEV_TX_OK;
2112}
2113
Julian Wiedmannd0c74822019-03-28 16:39:19 +01002114static void qeth_l3_set_rx_mode(struct net_device *dev)
2115{
2116 struct qeth_card *card = dev->ml_priv;
2117
2118 schedule_work(&card->rx_mode_work);
2119}
2120
Frank Blaschka4a71df52008-02-15 09:19:42 +01002121/*
2122 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
2123 * NOARP on the netdevice is no option because it also turns off neighbor
2124 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
2125 * arp resolution but we want the hard header (packet socket will work
2126 * e.g. tcpdump)
2127 */
2128static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
2129{
2130 n->nud_state = NUD_NOARP;
2131 memcpy(n->ha, "FAKELL", 6);
2132 n->output = n->ops->connected_output;
2133 return 0;
2134}
2135
2136static int
2137qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
2138{
2139 if (np->tbl->family == AF_INET)
2140 np->neigh_setup = qeth_l3_neigh_setup_noarp;
2141
2142 return 0;
2143}
2144
Julian Wiedmannf13ade12018-09-17 17:35:56 +02002145static netdev_features_t qeth_l3_osa_features_check(struct sk_buff *skb,
2146 struct net_device *dev,
2147 netdev_features_t features)
2148{
2149 if (qeth_get_ip_version(skb) != 4)
2150 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
2151 return qeth_features_check(skb, dev, features);
2152}
2153
Julian Wiedmann3a18d752019-04-17 18:17:32 +02002154static u16 qeth_l3_iqd_select_queue(struct net_device *dev, struct sk_buff *skb,
2155 struct net_device *sb_dev)
2156{
2157 return qeth_iqd_select_queue(dev, skb, qeth_l3_get_cast_type(skb),
2158 sb_dev);
2159}
2160
Julian Wiedmann73dc2da2019-04-17 18:17:33 +02002161static u16 qeth_l3_osa_select_queue(struct net_device *dev, struct sk_buff *skb,
2162 struct net_device *sb_dev)
2163{
2164 struct qeth_card *card = dev->ml_priv;
2165
2166 return qeth_get_priority_queue(card, skb);
2167}
2168
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002169static const struct net_device_ops qeth_l3_netdev_ops = {
Julian Wiedmanne22355e2019-01-25 15:44:18 +01002170 .ndo_open = qeth_open,
2171 .ndo_stop = qeth_stop,
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002172 .ndo_get_stats64 = qeth_get_stats64,
Frank Blaschka8403b132009-01-08 10:50:55 -08002173 .ndo_start_xmit = qeth_l3_hard_start_xmit,
Julian Wiedmann3a18d752019-04-17 18:17:32 +02002174 .ndo_select_queue = qeth_l3_iqd_select_queue,
Frank Blaschka8403b132009-01-08 10:50:55 -08002175 .ndo_validate_addr = eth_validate_addr,
Julian Wiedmann00c163f2017-12-20 20:11:02 +01002176 .ndo_set_rx_mode = qeth_l3_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002177 .ndo_do_ioctl = qeth_do_ioctl,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002178 .ndo_fix_features = qeth_fix_features,
2179 .ndo_set_features = qeth_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08002180 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2181 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002182 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka8403b132009-01-08 10:50:55 -08002183};
2184
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002185static const struct net_device_ops qeth_l3_osa_netdev_ops = {
Julian Wiedmanne22355e2019-01-25 15:44:18 +01002186 .ndo_open = qeth_open,
2187 .ndo_stop = qeth_stop,
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002188 .ndo_get_stats64 = qeth_get_stats64,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002189 .ndo_start_xmit = qeth_l3_hard_start_xmit,
Julian Wiedmannf13ade12018-09-17 17:35:56 +02002190 .ndo_features_check = qeth_l3_osa_features_check,
Julian Wiedmann73dc2da2019-04-17 18:17:33 +02002191 .ndo_select_queue = qeth_l3_osa_select_queue,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002192 .ndo_validate_addr = eth_validate_addr,
Julian Wiedmann00c163f2017-12-20 20:11:02 +01002193 .ndo_set_rx_mode = qeth_l3_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002194 .ndo_do_ioctl = qeth_do_ioctl,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002195 .ndo_fix_features = qeth_fix_features,
2196 .ndo_set_features = qeth_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002197 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2198 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002199 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002200 .ndo_neigh_setup = qeth_l3_neigh_setup,
2201};
2202
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002203static int qeth_l3_setup_netdev(struct qeth_card *card, bool carrier_ok)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002204{
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002205 unsigned int headroom;
Thomas Richter1aec42b2015-01-21 13:39:10 +01002206 int rc;
2207
Julian Wiedmann379ac992019-04-25 18:25:57 +02002208 if (IS_OSD(card) || IS_OSX(card)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002209 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
2210 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002211 pr_info("qeth_l3: ignoring TR device\n");
2212 return -ENODEV;
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002213 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002214
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002215 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Julian Wiedmann0f342942018-03-09 18:12:54 +01002216
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002217 /*IPv6 address autoconfiguration stuff*/
2218 qeth_l3_get_unique_id(card);
2219 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
2220 card->dev->dev_id = card->info.unique_id & 0xffff;
Julian Wiedmann0f342942018-03-09 18:12:54 +01002221
Julian Wiedmann379ac992019-04-25 18:25:57 +02002222 if (!IS_VM_NIC(card)) {
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002223 card->dev->features |= NETIF_F_SG;
2224 card->dev->hw_features |= NETIF_F_TSO |
2225 NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
2226 card->dev->vlan_features |= NETIF_F_TSO |
2227 NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002228 }
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +02002229
2230 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) {
2231 card->dev->hw_features |= NETIF_F_IPV6_CSUM;
2232 card->dev->vlan_features |= NETIF_F_IPV6_CSUM;
2233 }
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002234 if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) {
2235 card->dev->hw_features |= NETIF_F_TSO6;
2236 card->dev->vlan_features |= NETIF_F_TSO6;
2237 }
2238
2239 /* allow for de-acceleration of NETIF_F_HW_VLAN_CTAG_TX: */
2240 if (card->dev->hw_features & NETIF_F_TSO6)
2241 headroom = sizeof(struct qeth_hdr_tso) + VLAN_HLEN;
2242 else if (card->dev->hw_features & NETIF_F_TSO)
2243 headroom = sizeof(struct qeth_hdr_tso);
2244 else
2245 headroom = sizeof(struct qeth_hdr) + VLAN_HLEN;
Julian Wiedmann379ac992019-04-25 18:25:57 +02002246 } else if (IS_IQD(card)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002247 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002248 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002249 headroom = sizeof(struct qeth_hdr) - ETH_HLEN;
Julian Wiedmanna647a022018-07-11 17:42:46 +02002250
Thomas Richter1aec42b2015-01-21 13:39:10 +01002251 rc = qeth_l3_iqd_read_initial_mac(card);
2252 if (rc)
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002253 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002254 } else
2255 return -ENODEV;
2256
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002257 card->dev->needed_headroom = headroom;
Patrick McHardyf6469682013-04-19 02:04:27 +00002258 card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2259 NETIF_F_HW_VLAN_CTAG_RX |
2260 NETIF_F_HW_VLAN_CTAG_FILTER;
Julian Wiedmanna647a022018-07-11 17:42:46 +02002261
Eric Dumazet02875872014-10-05 18:38:35 -07002262 netif_keep_dst(card->dev);
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002263 if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6))
Julian Wiedmann371a1e72018-07-11 17:42:44 +02002264 netif_set_gso_max_size(card->dev,
2265 PAGE_SIZE * (QETH_MAX_BUFFER_ELEMENTS(card) - 1));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002266
Julian Wiedmannd73ef322017-04-11 16:11:11 +02002267 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002268 rc = register_netdev(card->dev);
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002269 if (!rc && carrier_ok)
2270 netif_carrier_on(card->dev);
2271
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002272out:
2273 if (rc)
2274 card->dev->netdev_ops = NULL;
2275 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002276}
2277
Ursula Braun79a04e42017-06-06 14:33:49 +02002278static const struct device_type qeth_l3_devtype = {
2279 .name = "qeth_layer3",
2280 .groups = qeth_l3_attr_groups,
2281};
2282
Frank Blaschka4a71df52008-02-15 09:19:42 +01002283static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
2284{
2285 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +02002286 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002287
Julian Wiedmann7221b722019-03-18 16:40:55 +01002288 hash_init(card->ip_htable);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +01002289 mutex_init(&card->ip_lock);
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002290 card->cmd_wq = alloc_ordered_workqueue("%s_cmd", 0,
2291 dev_name(&gdev->dev));
2292 if (!card->cmd_wq)
2293 return -ENOMEM;
Julian Wiedmann7221b722019-03-18 16:40:55 +01002294
Ursula Braun79a04e42017-06-06 14:33:49 +02002295 if (gdev->dev.type == &qeth_generic_devtype) {
2296 rc = qeth_l3_create_device_attributes(&gdev->dev);
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002297 if (rc) {
2298 destroy_workqueue(card->cmd_wq);
Ursula Braun79a04e42017-06-06 14:33:49 +02002299 return rc;
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002300 }
Ursula Braun79a04e42017-06-06 14:33:49 +02002301 }
Julian Wiedmann7221b722019-03-18 16:40:55 +01002302
Ursula Braunebccc7392017-05-10 19:07:54 +02002303 hash_init(card->ip_mc_htable);
Julian Wiedmannd0c74822019-03-28 16:39:19 +01002304 INIT_WORK(&card->rx_mode_work, qeth_l3_rx_mode_work);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002305 return 0;
2306}
2307
2308static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
2309{
2310 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
2311
Ursula Braun79a04e42017-06-06 14:33:49 +02002312 if (cgdev->dev.type == &qeth_generic_devtype)
2313 qeth_l3_remove_device_attributes(&cgdev->dev);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002314
Ursula Braunf2148562009-05-19 21:38:37 +00002315 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002316 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
2317
Ursula Braun70919e22011-02-26 22:41:36 -08002318 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002319 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002320
Julian Wiedmannc2780c12019-02-04 17:40:08 +01002321 cancel_work_sync(&card->close_dev_work);
Julian Wiedmann30356d02018-11-02 19:04:10 +01002322 if (qeth_netdev_is_registered(card->dev))
2323 unregister_netdev(card->dev);
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002324
2325 flush_workqueue(card->cmd_wq);
2326 destroy_workqueue(card->cmd_wq);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002327 qeth_l3_clear_ip_htable(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002328 qeth_l3_clear_ipato_list(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002329}
2330
Julian Wiedmannd4560152019-02-28 18:59:39 +01002331static int qeth_l3_set_online(struct ccwgroup_device *gdev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002332{
2333 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002334 struct net_device *dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002335 int rc = 0;
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002336 bool carrier_ok;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002337
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002338 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002339 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002340 QETH_DBF_TEXT(SETUP, 2, "setonlin");
2341 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002342
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002343 rc = qeth_core_hardsetup_card(card, &carrier_ok);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002344 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01002345 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00002346 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002347 goto out_remove;
2348 }
2349
Frank Blaschka1da74b12011-05-12 18:45:02 +00002350 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
2351 if (card->info.hwtrap &&
2352 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
2353 card->info.hwtrap = 0;
2354 } else
2355 card->info.hwtrap = 0;
2356
Frank Blaschka4a71df52008-02-15 09:19:42 +01002357 card->state = CARD_STATE_HARDSETUP;
2358 qeth_print_status_message(card);
2359
2360 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002361 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002362
Frank Blaschka4a71df52008-02-15 09:19:42 +01002363 rc = qeth_l3_setadapter_parms(card);
2364 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01002365 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002366 if (!card->options.sniffer) {
2367 rc = qeth_l3_start_ipassists(card);
Stefan Raspl0f547612013-01-21 02:30:20 +00002368 if (rc) {
Ursula Braun76b11f82010-01-11 02:50:50 +00002369 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Stefan Raspl0f547612013-01-21 02:30:20 +00002370 goto out_remove;
2371 }
Ursula Braun76b11f82010-01-11 02:50:50 +00002372 rc = qeth_l3_setrouting_v4(card);
2373 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01002374 QETH_DBF_TEXT_(SETUP, 2, "4err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002375 rc = qeth_l3_setrouting_v6(card);
2376 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01002377 QETH_DBF_TEXT_(SETUP, 2, "5err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002378 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002379
2380 rc = qeth_init_qdio_queues(card);
2381 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002382 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00002383 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002384 goto out_remove;
2385 }
2386 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002387
2388 qeth_set_allowed_threads(card, 0xffffffff, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002389 qeth_l3_recover_ip(card);
Julian Wiedmannd025da92018-06-29 19:45:54 +02002390
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002391 if (!qeth_netdev_is_registered(dev)) {
2392 rc = qeth_l3_setup_netdev(card, carrier_ok);
2393 if (rc)
2394 goto out_remove;
2395 } else {
Ursula Braun4763b0a2011-12-19 22:56:32 +00002396 rtnl_lock();
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002397 if (carrier_ok)
2398 netif_carrier_on(dev);
2399 else
2400 netif_carrier_off(dev);
2401
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01002402 netif_device_attach(dev);
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002403 qeth_enable_hw_features(dev);
2404
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01002405 if (card->info.open_when_online) {
2406 card->info.open_when_online = 0;
Julian Wiedmannd4560152019-02-28 18:59:39 +01002407 dev_open(dev, NULL);
Julian Wiedmann9aa17df2018-07-11 17:42:40 +02002408 }
Ursula Braun4763b0a2011-12-19 22:56:32 +00002409 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002410 }
Stefan Raspl82f77cf2013-03-18 20:04:42 +00002411 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002412 /* let user_space know that device is online */
2413 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002414 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002415 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002416 return 0;
2417out_remove:
Julian Wiedmannd4560152019-02-28 18:59:39 +01002418 qeth_l3_stop_card(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002419 ccw_device_set_offline(CARD_DDEV(card));
2420 ccw_device_set_offline(CARD_WDEV(card));
2421 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01002422 qdio_free(CARD_DDEV(card));
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01002423 card->state = CARD_STATE_DOWN;
2424
Frank Blaschkac4949f02010-05-11 19:34:47 +00002425 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002426 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00002427 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002428}
2429
Frank Blaschka4a71df52008-02-15 09:19:42 +01002430static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
2431 int recovery_mode)
2432{
2433 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
2434 int rc = 0, rc2 = 0, rc3 = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002435
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002436 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002437 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002438 QETH_DBF_TEXT(SETUP, 3, "setoffl");
2439 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002440
Julian Wiedmannd7ef489f2019-02-28 18:59:37 +01002441 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
2442 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
2443 card->info.hwtrap = 1;
2444 }
2445
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01002446 rtnl_lock();
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01002447 card->info.open_when_online = card->dev->flags & IFF_UP;
Julian Wiedmannd4560152019-02-28 18:59:39 +01002448 dev_close(card->dev);
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01002449 netif_device_detach(card->dev);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002450 netif_carrier_off(card->dev);
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01002451 rtnl_unlock();
2452
Julian Wiedmannd4560152019-02-28 18:59:39 +01002453 qeth_l3_stop_card(card);
Julian Wiedmann464e86d2019-02-28 18:59:40 +01002454 if (card->options.cq == QETH_CQ_ENABLED) {
Einar Lueck72861ae2011-12-19 22:56:36 +00002455 rtnl_lock();
2456 call_netdevice_notifiers(NETDEV_REBOOT, card->dev);
2457 rtnl_unlock();
2458 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002459 rc = ccw_device_set_offline(CARD_DDEV(card));
2460 rc2 = ccw_device_set_offline(CARD_WDEV(card));
2461 rc3 = ccw_device_set_offline(CARD_RDEV(card));
2462 if (!rc)
2463 rc = (rc2) ? rc2 : rc3;
2464 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002465 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01002466 qdio_free(CARD_DDEV(card));
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01002467
Frank Blaschka4a71df52008-02-15 09:19:42 +01002468 /* let user_space know that device is offline */
2469 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002470 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002471 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002472 return 0;
2473}
2474
2475static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
2476{
2477 return __qeth_l3_set_offline(cgdev, 0);
2478}
2479
2480static int qeth_l3_recover(void *ptr)
2481{
2482 struct qeth_card *card;
2483 int rc = 0;
2484
2485 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00002486 QETH_CARD_TEXT(card, 2, "recover1");
2487 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002488 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
2489 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00002490 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002491 dev_warn(&card->gdev->dev,
2492 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002493 __qeth_l3_set_offline(card->gdev, 1);
Julian Wiedmannd4560152019-02-28 18:59:39 +01002494 rc = qeth_l3_set_online(card->gdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002495 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002496 dev_info(&card->gdev->dev,
2497 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02002498 else {
Julian Wiedmannbf42d402019-02-28 18:59:41 +01002499 ccwgroup_set_offline(card->gdev);
Stefan Raspl0f547612013-01-21 02:30:20 +00002500 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00002501 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02002502 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002503 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
2504 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002505 return 0;
2506}
2507
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002508static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
2509{
2510 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
2511
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002512 qeth_set_allowed_threads(card, 0, 1);
2513 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
2514 if (gdev->state == CCWGROUP_OFFLINE)
2515 return 0;
Julian Wiedmann62ca98d2019-02-28 18:59:43 +01002516
2517 qeth_l3_set_offline(gdev);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002518 return 0;
2519}
2520
2521static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
2522{
2523 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Julian Wiedmannd4560152019-02-28 18:59:39 +01002524 int rc;
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002525
Julian Wiedmannd4560152019-02-28 18:59:39 +01002526 rc = qeth_l3_set_online(gdev);
Julian Wiedmann6585ac42018-09-26 18:29:12 +02002527
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002528 qeth_set_allowed_threads(card, 0xffffffff, 0);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002529 if (rc)
2530 dev_warn(&card->gdev->dev, "The qeth device driver "
2531 "failed to recover an error on the device\n");
2532 return rc;
2533}
2534
Eugene Crosserc044dc22014-01-29 09:23:48 +01002535/* Returns zero if the command is successfully "consumed" */
2536static int qeth_l3_control_event(struct qeth_card *card,
2537 struct qeth_ipa_cmd *cmd)
2538{
2539 return 1;
2540}
2541
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002542struct qeth_discipline qeth_l3_discipline = {
Ursula Braun79a04e42017-06-06 14:33:49 +02002543 .devtype = &qeth_l3_devtype,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02002544 .process_rx_buffer = qeth_l3_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002545 .recover = qeth_l3_recover,
2546 .setup = qeth_l3_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002547 .remove = qeth_l3_remove_device,
2548 .set_online = qeth_l3_set_online,
2549 .set_offline = qeth_l3_set_offline,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002550 .freeze = qeth_l3_pm_suspend,
2551 .thaw = qeth_l3_pm_resume,
2552 .restore = qeth_l3_pm_resume,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002553 .do_ioctl = qeth_l3_do_ioctl,
Eugene Crosserc044dc22014-01-29 09:23:48 +01002554 .control_event_handler = qeth_l3_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002555};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002556EXPORT_SYMBOL_GPL(qeth_l3_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002557
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002558static int qeth_l3_handle_ip_event(struct qeth_card *card,
2559 struct qeth_ipaddr *addr,
2560 unsigned long event)
2561{
2562 switch (event) {
2563 case NETDEV_UP:
Julian Wiedmann05a17852019-03-28 16:39:21 +01002564 qeth_l3_modify_ip(card, addr, true);
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002565 return NOTIFY_OK;
2566 case NETDEV_DOWN:
Julian Wiedmann05a17852019-03-28 16:39:21 +01002567 qeth_l3_modify_ip(card, addr, false);
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002568 return NOTIFY_OK;
2569 default:
2570 return NOTIFY_DONE;
2571 }
2572}
2573
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002574struct qeth_l3_ip_event_work {
2575 struct work_struct work;
2576 struct qeth_card *card;
2577 struct qeth_ipaddr addr;
2578};
2579
2580#define to_ip_work(w) container_of((w), struct qeth_l3_ip_event_work, work)
2581
2582static void qeth_l3_add_ip_worker(struct work_struct *work)
2583{
2584 struct qeth_l3_ip_event_work *ip_work = to_ip_work(work);
2585
2586 qeth_l3_modify_ip(ip_work->card, &ip_work->addr, true);
2587 kfree(work);
2588}
2589
2590static void qeth_l3_delete_ip_worker(struct work_struct *work)
2591{
2592 struct qeth_l3_ip_event_work *ip_work = to_ip_work(work);
2593
2594 qeth_l3_modify_ip(ip_work->card, &ip_work->addr, false);
2595 kfree(work);
2596}
2597
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002598static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2599{
2600 if (is_vlan_dev(dev))
2601 dev = vlan_dev_real_dev(dev);
2602 if (dev->netdev_ops == &qeth_l3_osa_netdev_ops ||
2603 dev->netdev_ops == &qeth_l3_netdev_ops)
2604 return (struct qeth_card *) dev->ml_priv;
2605 return NULL;
2606}
2607
Frank Blaschka4a71df52008-02-15 09:19:42 +01002608static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07002609 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002610{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002611
Frank Blaschka4a71df52008-02-15 09:19:42 +01002612 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002613 struct net_device *dev = ifa->ifa_dev->dev;
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002614 struct qeth_ipaddr addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002615 struct qeth_card *card;
2616
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09002617 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07002618 return NOTIFY_DONE;
2619
Frank Blaschka4a71df52008-02-15 09:19:42 +01002620 card = qeth_l3_get_card_from_dev(dev);
2621 if (!card)
2622 return NOTIFY_DONE;
frank.blaschka@de.ibm.com6d8823d2012-05-16 01:28:26 +00002623 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002624
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002625 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV4);
2626 addr.u.a4.addr = be32_to_cpu(ifa->ifa_address);
2627 addr.u.a4.mask = be32_to_cpu(ifa->ifa_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002628
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002629 return qeth_l3_handle_ip_event(card, &addr, event);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002630}
2631
2632static struct notifier_block qeth_l3_ip_notifier = {
2633 qeth_l3_ip_event,
2634 NULL,
2635};
2636
Frank Blaschka4a71df52008-02-15 09:19:42 +01002637static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07002638 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002639{
2640 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002641 struct net_device *dev = ifa->idev->dev;
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002642 struct qeth_l3_ip_event_work *ip_work;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002643 struct qeth_card *card;
2644
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002645 if (event != NETDEV_UP && event != NETDEV_DOWN)
2646 return NOTIFY_DONE;
2647
Frank Blaschka4a71df52008-02-15 09:19:42 +01002648 card = qeth_l3_get_card_from_dev(dev);
2649 if (!card)
2650 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00002651 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002652 if (!qeth_is_supported(card, IPA_IPV6))
2653 return NOTIFY_DONE;
2654
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002655 ip_work = kmalloc(sizeof(*ip_work), GFP_ATOMIC);
2656 if (!ip_work)
2657 return NOTIFY_DONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002658
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002659 if (event == NETDEV_UP)
2660 INIT_WORK(&ip_work->work, qeth_l3_add_ip_worker);
2661 else
2662 INIT_WORK(&ip_work->work, qeth_l3_delete_ip_worker);
2663
2664 ip_work->card = card;
2665 qeth_l3_init_ipaddr(&ip_work->addr, QETH_IP_TYPE_NORMAL,
2666 QETH_PROT_IPV6);
2667 ip_work->addr.u.a6.addr = ifa->addr;
2668 ip_work->addr.u.a6.pfxlen = ifa->prefix_len;
2669
2670 queue_work(card->cmd_wq, &ip_work->work);
2671 return NOTIFY_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002672}
2673
2674static struct notifier_block qeth_l3_ip6_notifier = {
2675 qeth_l3_ip6_event,
2676 NULL,
2677};
Frank Blaschka4a71df52008-02-15 09:19:42 +01002678
2679static int qeth_l3_register_notifiers(void)
2680{
2681 int rc;
2682
Carsten Otte847a50f2010-06-21 22:57:05 +00002683 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002684 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
2685 if (rc)
2686 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002687 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
2688 if (rc) {
2689 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
2690 return rc;
2691 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002692 return 0;
2693}
2694
2695static void qeth_l3_unregister_notifiers(void)
2696{
Carsten Otte847a50f2010-06-21 22:57:05 +00002697 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Stefan Raspl18af5c12012-11-19 02:46:50 +00002698 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
Stefan Raspl18af5c12012-11-19 02:46:50 +00002699 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002700}
2701
2702static int __init qeth_l3_init(void)
2703{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002704 pr_info("register layer 3 discipline\n");
Julian Wiedmannc0622042017-12-20 20:10:58 +01002705 return qeth_l3_register_notifiers();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002706}
2707
2708static void __exit qeth_l3_exit(void)
2709{
2710 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002711 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002712}
2713
2714module_init(qeth_l3_init);
2715module_exit(qeth_l3_exit);
2716MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2717MODULE_DESCRIPTION("qeth layer 3 discipline");
2718MODULE_LICENSE("GPL");