blob: 54799fe6a700cfba1813b31279d0ab44c28cbd4f [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>
Frank Blaschkab3332932011-08-08 01:33:59 +000035#include <net/iucv/af_iucv.h>
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020036#include <linux/hashtable.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010037
Frank Blaschka4a71df52008-02-15 09:19:42 +010038#include "qeth_l3.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010039
Einar Lueckd0ddf30f2010-12-08 02:57:58 +000040
Frank Blaschka4a71df52008-02-15 09:19:42 +010041static int qeth_l3_set_offline(struct ccwgroup_device *);
Julian Wiedmann00c163f2017-12-20 20:11:02 +010042static void qeth_l3_set_rx_mode(struct net_device *dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +010043static int qeth_l3_register_addr_entry(struct qeth_card *,
44 struct qeth_ipaddr *);
45static int qeth_l3_deregister_addr_entry(struct qeth_card *,
46 struct qeth_ipaddr *);
Frank Blaschka4a71df52008-02-15 09:19:42 +010047
Thomas Richter56530d62014-10-22 12:18:04 +020048static void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010049{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020050 sprintf(buf, "%pI4", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010051}
52
Thomas Richter56530d62014-10-22 12:18:04 +020053static void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010054{
Joe Perches963a9fd2010-09-07 21:14:40 +000055 sprintf(buf, "%pI6", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010056}
57
Frank Blaschka4a71df52008-02-15 09:19:42 +010058void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
59 char *buf)
60{
61 if (proto == QETH_PROT_IPV4)
62 qeth_l3_ipaddr4_to_string(addr, buf);
63 else if (proto == QETH_PROT_IPV6)
64 qeth_l3_ipaddr6_to_string(addr, buf);
65}
66
Julian Wiedmann1617dae2018-03-09 18:13:02 +010067static struct qeth_ipaddr *qeth_l3_get_addr_buffer(enum qeth_prot_versions prot)
Julian Wiedmannd66b1c02018-03-09 18:13:00 +010068{
69 struct qeth_ipaddr *addr = kmalloc(sizeof(*addr), GFP_ATOMIC);
70
71 if (addr)
72 qeth_l3_init_ipaddr(addr, QETH_IP_TYPE_NORMAL, prot);
73 return addr;
74}
75
Julian Wiedmannc5c48c52018-02-27 18:58:16 +010076static struct qeth_ipaddr *qeth_l3_find_addr_by_ip(struct qeth_card *card,
77 struct qeth_ipaddr *query)
78{
79 u64 key = qeth_l3_ipaddr_hash(query);
80 struct qeth_ipaddr *addr;
81
82 if (query->is_multicast) {
83 hash_for_each_possible(card->ip_mc_htable, addr, hnode, key)
84 if (qeth_l3_addr_match_ip(addr, query))
85 return addr;
86 } else {
87 hash_for_each_possible(card->ip_htable, addr, hnode, key)
88 if (qeth_l3_addr_match_ip(addr, query))
89 return addr;
90 }
91 return NULL;
92}
93
Frank Blaschka4a71df52008-02-15 09:19:42 +010094static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
95{
96 int i, j;
97 u8 octet;
98
99 for (i = 0; i < len; ++i) {
100 octet = addr[i];
101 for (j = 7; j >= 0; --j) {
102 bits[i*8 + j] = octet & 1;
103 octet >>= 1;
104 }
105 }
106}
107
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100108static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
109 struct qeth_ipaddr *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100110{
111 struct qeth_ipato_entry *ipatoe;
112 u8 addr_bits[128] = {0, };
113 u8 ipatoe_bits[128] = {0, };
114 int rc = 0;
115
116 if (!card->ipato.enabled)
Gustavo A. R. Silva1a363b02018-08-09 14:48:04 +0200117 return false;
Julian Wiedmannb22d73d62017-12-13 18:56:30 +0100118 if (addr->type != QETH_IP_TYPE_NORMAL)
Gustavo A. R. Silva1a363b02018-08-09 14:48:04 +0200119 return false;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100120
121 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
122 (addr->proto == QETH_PROT_IPV4)? 4:16);
123 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
124 if (addr->proto != ipatoe->proto)
125 continue;
126 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
127 (ipatoe->proto == QETH_PROT_IPV4) ?
128 4 : 16);
129 if (addr->proto == QETH_PROT_IPV4)
130 rc = !memcmp(addr_bits, ipatoe_bits,
131 min(32, ipatoe->mask_bits));
132 else
133 rc = !memcmp(addr_bits, ipatoe_bits,
134 min(128, ipatoe->mask_bits));
135 if (rc)
136 break;
137 }
138 /* invert? */
139 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
140 rc = !rc;
141 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
142 rc = !rc;
143
144 return rc;
145}
146
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100147static int qeth_l3_delete_ip(struct qeth_card *card,
148 struct qeth_ipaddr *tmp_addr)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200149{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100150 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200151 struct qeth_ipaddr *addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100152
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100153 if (tmp_addr->type == QETH_IP_TYPE_RXIP)
154 QETH_CARD_TEXT(card, 2, "delrxip");
155 else if (tmp_addr->type == QETH_IP_TYPE_VIPA)
156 QETH_CARD_TEXT(card, 2, "delvipa");
157 else
158 QETH_CARD_TEXT(card, 2, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100159
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200160 if (tmp_addr->proto == QETH_PROT_IPV4)
161 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100162 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200163 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
164 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100165 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200166
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100167 addr = qeth_l3_find_addr_by_ip(card, tmp_addr);
168 if (!addr || !qeth_l3_addr_match_all(addr, tmp_addr))
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200169 return -ENOENT;
170
171 addr->ref_counter--;
Julian Wiedmann4964c662018-02-27 18:58:15 +0100172 if (addr->type == QETH_IP_TYPE_NORMAL && addr->ref_counter > 0)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200173 return rc;
174 if (addr->in_progress)
175 return -EINPROGRESS;
176
Julian Wiedmann98d823a2018-02-27 18:58:13 +0100177 if (qeth_card_hw_is_reachable(card))
178 rc = qeth_l3_deregister_addr_entry(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200179
180 hash_del(&addr->hnode);
181 kfree(addr);
182
Frank Blaschka4a71df52008-02-15 09:19:42 +0100183 return rc;
184}
185
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100186static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100187{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100188 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200189 struct qeth_ipaddr *addr;
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100190 char buf[40];
Frank Blaschka4a71df52008-02-15 09:19:42 +0100191
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100192 if (tmp_addr->type == QETH_IP_TYPE_RXIP)
193 QETH_CARD_TEXT(card, 2, "addrxip");
194 else if (tmp_addr->type == QETH_IP_TYPE_VIPA)
195 QETH_CARD_TEXT(card, 2, "addvipa");
196 else
197 QETH_CARD_TEXT(card, 2, "addip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200198
199 if (tmp_addr->proto == QETH_PROT_IPV4)
200 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100201 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200202 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
203 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100204 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200205
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100206 addr = qeth_l3_find_addr_by_ip(card, tmp_addr);
207 if (addr) {
208 if (tmp_addr->type != QETH_IP_TYPE_NORMAL)
209 return -EADDRINUSE;
210 if (qeth_l3_addr_match_all(addr, tmp_addr)) {
211 addr->ref_counter++;
212 return 0;
213 }
214 qeth_l3_ipaddr_to_string(tmp_addr->proto, (u8 *)&tmp_addr->u,
215 buf);
216 dev_warn(&card->gdev->dev,
217 "Registering IP address %s failed\n", buf);
218 return -EADDRINUSE;
219 } else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200220 addr = qeth_l3_get_addr_buffer(tmp_addr->proto);
221 if (!addr)
222 return -ENOMEM;
223
224 memcpy(addr, tmp_addr, sizeof(struct qeth_ipaddr));
225 addr->ref_counter = 1;
226
Julian Wiedmannb22d73d62017-12-13 18:56:30 +0100227 if (qeth_l3_is_addr_covered_by_ipato(card, addr)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200228 QETH_CARD_TEXT(card, 2, "tkovaddr");
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100229 addr->ipato = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200230 }
231 hash_add(card->ip_htable, &addr->hnode,
232 qeth_l3_ipaddr_hash(addr));
233
Ursula Brauna7531c12016-09-15 14:39:23 +0200234 if (!qeth_card_hw_is_reachable(card)) {
235 addr->disp_flag = QETH_DISP_ADDR_ADD;
236 return 0;
237 }
238
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200239 /* qeth_l3_register_addr_entry can go to sleep
240 * if we add a IPV4 addr. It is caused by the reason
241 * that SETIP ipa cmd starts ARP staff for IPV4 addr.
242 * Thus we should unlock spinlock, and make a protection
243 * using in_progress variable to indicate that there is
244 * an hardware operation with this IPV4 address
245 */
246 if (addr->proto == QETH_PROT_IPV4) {
247 addr->in_progress = 1;
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100248 mutex_unlock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200249 rc = qeth_l3_register_addr_entry(card, addr);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100250 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200251 addr->in_progress = 0;
252 } else
253 rc = qeth_l3_register_addr_entry(card, addr);
254
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100255 if (!rc || rc == -EADDRINUSE || rc == -ENETDOWN) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200256 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
257 if (addr->ref_counter < 1) {
Julian Wiedmann14d066c2018-02-27 18:58:14 +0100258 qeth_l3_deregister_addr_entry(card, addr);
259 hash_del(&addr->hnode);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200260 kfree(addr);
261 }
262 } else {
263 hash_del(&addr->hnode);
264 kfree(addr);
265 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200266 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100267 return rc;
268}
269
Julian Wiedmann05a17852019-03-28 16:39:21 +0100270static int qeth_l3_modify_ip(struct qeth_card *card, struct qeth_ipaddr *addr,
271 bool add)
272{
273 int rc;
274
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100275 mutex_lock(&card->ip_lock);
Julian Wiedmann05a17852019-03-28 16:39:21 +0100276 rc = add ? qeth_l3_add_ip(card, addr) : qeth_l3_delete_ip(card, addr);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100277 mutex_unlock(&card->ip_lock);
Julian Wiedmann05a17852019-03-28 16:39:21 +0100278
279 return rc;
280}
281
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100282static void qeth_l3_drain_rx_mode_cache(struct qeth_card *card)
283{
284 struct qeth_ipaddr *addr;
285 struct hlist_node *tmp;
286 int i;
287
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100288 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
289 hash_del(&addr->hnode);
290 kfree(addr);
291 }
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100292}
293
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200294static void qeth_l3_clear_ip_htable(struct qeth_card *card, int recover)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100295{
296 struct qeth_ipaddr *addr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200297 struct hlist_node *tmp;
298 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100299
Carsten Otte847a50f2010-06-21 22:57:05 +0000300 QETH_CARD_TEXT(card, 4, "clearip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200301
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100302 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200303
304 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
305 if (!recover) {
306 hash_del(&addr->hnode);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100307 kfree(addr);
308 continue;
309 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200310 addr->disp_flag = QETH_DISP_ADDR_ADD;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100311 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200312
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100313 mutex_unlock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100314}
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100315
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200316static void qeth_l3_recover_ip(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100317{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200318 struct qeth_ipaddr *addr;
319 struct hlist_node *tmp;
320 int i;
321 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100322
Ursula Brauna7531c12016-09-15 14:39:23 +0200323 QETH_CARD_TEXT(card, 4, "recovrip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100324
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100325 mutex_lock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100326
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200327 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
Julian Wiedmann98d823a2018-02-27 18:58:13 +0100328 if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200329 if (addr->proto == QETH_PROT_IPV4) {
330 addr->in_progress = 1;
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100331 mutex_unlock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200332 rc = qeth_l3_register_addr_entry(card, addr);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100333 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200334 addr->in_progress = 0;
335 } else
336 rc = qeth_l3_register_addr_entry(card, addr);
337
338 if (!rc) {
339 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Ursula Brauna7531c12016-09-15 14:39:23 +0200340 if (addr->ref_counter < 1)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200341 qeth_l3_delete_ip(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200342 } else {
343 hash_del(&addr->hnode);
344 kfree(addr);
345 }
346 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100347 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200348
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100349 mutex_unlock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100350}
351
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100352static int qeth_l3_setdelip_cb(struct qeth_card *card, struct qeth_reply *reply,
353 unsigned long data)
354{
355 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
356
357 switch (cmd->hdr.return_code) {
358 case IPA_RC_SUCCESS:
359 return 0;
360 case IPA_RC_DUPLICATE_IP_ADDRESS:
361 return -EADDRINUSE;
362 case IPA_RC_MC_ADDR_NOT_FOUND:
363 return -ENOENT;
364 case IPA_RC_LAN_OFFLINE:
365 return -ENETDOWN;
366 default:
367 return -EIO;
368 }
369}
370
Frank Blaschka4a71df52008-02-15 09:19:42 +0100371static int qeth_l3_send_setdelmc(struct qeth_card *card,
372 struct qeth_ipaddr *addr, int ipacmd)
373{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100374 struct qeth_cmd_buffer *iob;
375 struct qeth_ipa_cmd *cmd;
376
Carsten Otte847a50f2010-06-21 22:57:05 +0000377 QETH_CARD_TEXT(card, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100378
Julian Wiedmanna59d1212019-06-27 17:01:22 +0200379 iob = qeth_ipa_alloc_cmd(card, ipacmd, addr->proto,
380 IPA_DATA_SIZEOF(setdelipm));
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
Julian Wiedmanna59d1212019-06-27 17:01:22 +0200432 iob = qeth_ipa_alloc_cmd(card, ipacmd, addr->proto,
433 IPA_DATA_SIZEOF(setdelip6));
Thomas Richter1aec42b2015-01-21 13:39:10 +0100434 if (!iob)
435 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100436 cmd = __ipa_cmd(iob);
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100437
438 flags = qeth_l3_get_setdelip_flags(addr, ipacmd == IPA_CMD_SETIP);
439 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
440
Frank Blaschka4a71df52008-02-15 09:19:42 +0100441 if (addr->proto == QETH_PROT_IPV6) {
442 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
443 sizeof(struct in6_addr));
444 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
445 memcpy(cmd->data.setdelip6.mask, netmask,
446 sizeof(struct in6_addr));
447 cmd->data.setdelip6.flags = flags;
448 } else {
449 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
450 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
451 cmd->data.setdelip4.flags = flags;
452 }
453
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100454 return qeth_send_ipa_cmd(card, iob, qeth_l3_setdelip_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100455}
456
457static int qeth_l3_send_setrouting(struct qeth_card *card,
458 enum qeth_routing_types type, enum qeth_prot_versions prot)
459{
460 int rc;
461 struct qeth_ipa_cmd *cmd;
462 struct qeth_cmd_buffer *iob;
463
Carsten Otte847a50f2010-06-21 22:57:05 +0000464 QETH_CARD_TEXT(card, 4, "setroutg");
Julian Wiedmanna59d1212019-06-27 17:01:22 +0200465 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_SETRTG, prot,
466 IPA_DATA_SIZEOF(setrtg));
Thomas Richter1aec42b2015-01-21 13:39:10 +0100467 if (!iob)
468 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100469 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100470 cmd->data.setrtg.type = (type);
471 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
472
473 return rc;
474}
475
Stefan Raspl82e2e782013-03-18 20:04:43 +0000476static int qeth_l3_correct_routing_type(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100477 enum qeth_routing_types *type, enum qeth_prot_versions prot)
478{
Julian Wiedmann379ac992019-04-25 18:25:57 +0200479 if (IS_IQD(card)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100480 switch (*type) {
481 case NO_ROUTER:
482 case PRIMARY_CONNECTOR:
483 case SECONDARY_CONNECTOR:
484 case MULTICAST_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000485 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100486 default:
487 goto out_inval;
488 }
489 } else {
490 switch (*type) {
491 case NO_ROUTER:
492 case PRIMARY_ROUTER:
493 case SECONDARY_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000494 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100495 case MULTICAST_ROUTER:
496 if (qeth_is_ipafunc_supported(card, prot,
497 IPA_OSA_MC_ROUTER))
Stefan Raspl82e2e782013-03-18 20:04:43 +0000498 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100499 default:
500 goto out_inval;
501 }
502 }
503out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100504 *type = NO_ROUTER;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000505 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100506}
507
508int qeth_l3_setrouting_v4(struct qeth_card *card)
509{
510 int rc;
511
Carsten Otte847a50f2010-06-21 22:57:05 +0000512 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100513
Stefan Raspl82e2e782013-03-18 20:04:43 +0000514 rc = qeth_l3_correct_routing_type(card, &card->options.route4.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100515 QETH_PROT_IPV4);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000516 if (rc)
517 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100518
519 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
520 QETH_PROT_IPV4);
521 if (rc) {
522 card->options.route4.type = NO_ROUTER;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100523 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n",
524 rc, CARD_DEVID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100525 }
526 return rc;
527}
528
529int qeth_l3_setrouting_v6(struct qeth_card *card)
530{
531 int rc = 0;
532
Carsten Otte847a50f2010-06-21 22:57:05 +0000533 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100534
535 if (!qeth_is_supported(card, IPA_IPV6))
536 return 0;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000537 rc = qeth_l3_correct_routing_type(card, &card->options.route6.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100538 QETH_PROT_IPV6);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000539 if (rc)
540 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100541
542 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
543 QETH_PROT_IPV6);
544 if (rc) {
545 card->options.route6.type = NO_ROUTER;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100546 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n",
547 rc, CARD_DEVID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100548 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100549 return rc;
550}
551
552/*
553 * IP address takeover related functions
554 */
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100555
556/**
557 * qeth_l3_update_ipato() - Update 'takeover' property, for all NORMAL IPs.
558 *
559 * Caller must hold ip_lock.
560 */
561void qeth_l3_update_ipato(struct qeth_card *card)
562{
563 struct qeth_ipaddr *addr;
564 unsigned int i;
565
566 hash_for_each(card->ip_htable, i, addr, hnode) {
567 if (addr->type != QETH_IP_TYPE_NORMAL)
568 continue;
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100569 addr->ipato = qeth_l3_is_addr_covered_by_ipato(card, addr);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100570 }
571}
572
Frank Blaschka4a71df52008-02-15 09:19:42 +0100573static void qeth_l3_clear_ipato_list(struct qeth_card *card)
574{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100575 struct qeth_ipato_entry *ipatoe, *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100576
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100577 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200578
Frank Blaschka4a71df52008-02-15 09:19:42 +0100579 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
580 list_del(&ipatoe->entry);
581 kfree(ipatoe);
582 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200583
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100584 qeth_l3_update_ipato(card);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100585 mutex_unlock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100586}
587
588int qeth_l3_add_ipato_entry(struct qeth_card *card,
589 struct qeth_ipato_entry *new)
590{
591 struct qeth_ipato_entry *ipatoe;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100592 int rc = 0;
593
Carsten Otte847a50f2010-06-21 22:57:05 +0000594 QETH_CARD_TEXT(card, 2, "addipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200595
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100596 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200597
Frank Blaschka4a71df52008-02-15 09:19:42 +0100598 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
599 if (ipatoe->proto != new->proto)
600 continue;
601 if (!memcmp(ipatoe->addr, new->addr,
602 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
603 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100604 rc = -EEXIST;
605 break;
606 }
607 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200608
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100609 if (!rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100610 list_add_tail(&new->entry, &card->ipato.entries);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100611 qeth_l3_update_ipato(card);
612 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100613
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100614 mutex_unlock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200615
Frank Blaschka4a71df52008-02-15 09:19:42 +0100616 return rc;
617}
618
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100619int qeth_l3_del_ipato_entry(struct qeth_card *card,
620 enum qeth_prot_versions proto, u8 *addr,
621 int mask_bits)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100622{
623 struct qeth_ipato_entry *ipatoe, *tmp;
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100624 int rc = -ENOENT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100625
Carsten Otte847a50f2010-06-21 22:57:05 +0000626 QETH_CARD_TEXT(card, 2, "delipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200627
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100628 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200629
Frank Blaschka4a71df52008-02-15 09:19:42 +0100630 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
631 if (ipatoe->proto != proto)
632 continue;
633 if (!memcmp(ipatoe->addr, addr,
634 (proto == QETH_PROT_IPV4)? 4:16) &&
635 (ipatoe->mask_bits == mask_bits)) {
636 list_del(&ipatoe->entry);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100637 qeth_l3_update_ipato(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100638 kfree(ipatoe);
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100639 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100640 }
641 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200642
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100643 mutex_unlock(&card->ip_lock);
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100644 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100645}
646
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100647int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip,
648 enum qeth_ip_types type,
649 enum qeth_prot_versions proto)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100650{
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100651 struct qeth_ipaddr addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100652
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100653 qeth_l3_init_ipaddr(&addr, type, proto);
654 if (proto == QETH_PROT_IPV4)
655 memcpy(&addr.u.a4.addr, ip, 4);
656 else
657 memcpy(&addr.u.a6.addr, ip, 16);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200658
Julian Wiedmann05a17852019-03-28 16:39:21 +0100659 return qeth_l3_modify_ip(card, &addr, add);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100660}
661
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100662int qeth_l3_modify_hsuid(struct qeth_card *card, bool add)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100663{
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100664 struct qeth_ipaddr addr;
Julian Wiedmann05a17852019-03-28 16:39:21 +0100665 unsigned int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100666
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100667 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV6);
668 addr.u.a6.addr.s6_addr[0] = 0xfe;
669 addr.u.a6.addr.s6_addr[1] = 0x80;
670 for (i = 0; i < 8; i++)
671 addr.u.a6.addr.s6_addr[8+i] = card->options.hsuid[i];
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200672
Julian Wiedmann05a17852019-03-28 16:39:21 +0100673 return qeth_l3_modify_ip(card, &addr, add);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100674}
675
676static int qeth_l3_register_addr_entry(struct qeth_card *card,
677 struct qeth_ipaddr *addr)
678{
679 char buf[50];
680 int rc = 0;
681 int cnt = 3;
682
Julian Wiedmannbd74a7f2018-11-02 19:04:09 +0100683 if (card->options.sniffer)
684 return 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200685
Frank Blaschka4a71df52008-02-15 09:19:42 +0100686 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000687 QETH_CARD_TEXT(card, 2, "setaddr4");
688 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100689 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000690 QETH_CARD_TEXT(card, 2, "setaddr6");
691 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
692 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100693 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000694 QETH_CARD_TEXT(card, 2, "setaddr?");
695 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100696 }
697 do {
698 if (addr->is_multicast)
699 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
700 else
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100701 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100702 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000703 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100704 } while ((--cnt > 0) && rc);
705 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000706 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100707 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100708 dev_warn(&card->gdev->dev,
709 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100710 }
711 return rc;
712}
713
714static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
715 struct qeth_ipaddr *addr)
716{
717 int rc = 0;
718
Julian Wiedmannbd74a7f2018-11-02 19:04:09 +0100719 if (card->options.sniffer)
720 return 0;
721
Frank Blaschka4a71df52008-02-15 09:19:42 +0100722 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000723 QETH_CARD_TEXT(card, 2, "deladdr4");
724 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100725 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000726 QETH_CARD_TEXT(card, 2, "deladdr6");
727 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
728 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100729 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000730 QETH_CARD_TEXT(card, 2, "deladdr?");
731 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100732 }
733 if (addr->is_multicast)
734 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
735 else
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100736 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200737 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000738 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100739
740 return rc;
741}
742
Frank Blaschka4a71df52008-02-15 09:19:42 +0100743static int qeth_l3_setadapter_parms(struct qeth_card *card)
744{
Julian Wiedmann699d3fe2017-08-15 17:02:41 +0200745 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100746
Julian Wiedmann57a688aa2019-06-11 18:37:55 +0200747 QETH_CARD_TEXT(card, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100748
Frank Blaschka4a71df52008-02-15 09:19:42 +0100749 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
750 rc = qeth_setadpparms_change_macaddr(card);
751 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100752 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -0800753 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100754 }
755
Frank Blaschka4a71df52008-02-15 09:19:42 +0100756 return rc;
757}
758
Frank Blaschka4a71df52008-02-15 09:19:42 +0100759static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
760{
761 int rc;
762
Carsten Otte847a50f2010-06-21 22:57:05 +0000763 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100764
765 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100766 dev_info(&card->gdev->dev,
767 "ARP processing not supported on %s!\n",
768 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100769 return 0;
770 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200771 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200772 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100773 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100774 dev_warn(&card->gdev->dev,
775 "Starting ARP processing support for %s failed\n",
776 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100777 }
778 return rc;
779}
780
Frank Blaschka4a71df52008-02-15 09:19:42 +0100781static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
782{
783 int rc;
784
Carsten Otte847a50f2010-06-21 22:57:05 +0000785 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100786
Frank Blaschka4a71df52008-02-15 09:19:42 +0100787 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100788 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800789 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100790 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100791 return -EOPNOTSUPP;
792 }
793
Thomas Richter4d7def22015-09-18 16:06:51 +0200794 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200795 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100796 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100797 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800798 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100799 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100800 return rc;
801}
802
803static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
804{
805 int rc = 0;
806
Carsten Otte847a50f2010-06-21 22:57:05 +0000807 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100808
809 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100810 dev_info(&card->gdev->dev,
811 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100812 return -EOPNOTSUPP;
813 }
814
Thomas Richter4d7def22015-09-18 16:06:51 +0200815 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200816 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100817 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100818 dev_warn(&card->gdev->dev,
819 "Starting VLAN support for %s failed\n",
820 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100821 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100822 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100823 }
824 return rc;
825}
826
827static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
828{
829 int rc;
830
Carsten Otte847a50f2010-06-21 22:57:05 +0000831 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100832
833 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100834 dev_info(&card->gdev->dev,
835 "Multicast not supported on %s\n",
836 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100837 return -EOPNOTSUPP;
838 }
839
Thomas Richter4d7def22015-09-18 16:06:51 +0200840 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200841 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100842 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100843 dev_warn(&card->gdev->dev,
844 "Starting multicast support for %s failed\n",
845 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100846 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100847 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100848 card->dev->flags |= IFF_MULTICAST;
849 }
850 return rc;
851}
852
Frank Blaschka4a71df52008-02-15 09:19:42 +0100853static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
854{
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200855 u32 ipv6_data = 3;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100856 int rc;
857
Carsten Otte847a50f2010-06-21 22:57:05 +0000858 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100859
Julian Wiedmann379ac992019-04-25 18:25:57 +0200860 if (IS_IQD(card))
Julian Wiedmann23274592017-06-06 14:33:44 +0200861 goto out;
862
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200863 rc = qeth_send_simple_setassparms(card, IPA_IPV6, IPA_CMD_ASS_START,
864 &ipv6_data);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100865 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100866 dev_err(&card->gdev->dev,
867 "Activating IPv6 support for %s failed\n",
868 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100869 return rc;
870 }
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200871 rc = qeth_send_simple_setassparms_v6(card, IPA_IPV6, IPA_CMD_ASS_START,
872 NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100873 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100874 dev_err(&card->gdev->dev,
875 "Activating IPv6 support for %s failed\n",
876 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100877 return rc;
878 }
Kittipon Meesompopa8155b02018-04-26 09:42:21 +0200879 rc = qeth_send_simple_setassparms_v6(card, IPA_PASSTHRU,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200880 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100881 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100882 dev_warn(&card->gdev->dev,
883 "Enabling the passthrough mode for %s failed\n",
884 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100885 return rc;
886 }
887out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100888 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100889 return 0;
890}
Frank Blaschka4a71df52008-02-15 09:19:42 +0100891
892static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
893{
Carsten Otte847a50f2010-06-21 22:57:05 +0000894 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100895
896 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100897 dev_info(&card->gdev->dev,
898 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100899 return 0;
900 }
Julian Wiedmannc0622042017-12-20 20:10:58 +0100901 return qeth_l3_softsetup_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100902}
903
904static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
905{
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200906 u32 filter_data = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100907 int rc;
908
Carsten Otte847a50f2010-06-21 22:57:05 +0000909 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100910 card->info.broadcast_capable = 0;
911 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100912 dev_info(&card->gdev->dev,
913 "Broadcast not supported on %s\n",
914 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100915 rc = -EOPNOTSUPP;
916 goto out;
917 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200918 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200919 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100920 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100921 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
922 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100923 goto out;
924 }
925
Thomas Richter4d7def22015-09-18 16:06:51 +0200926 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200927 IPA_CMD_ASS_CONFIGURE, &filter_data);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100928 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100929 dev_warn(&card->gdev->dev,
930 "Setting up broadcast filtering for %s failed\n",
931 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100932 goto out;
933 }
934 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100935 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Thomas Richter4d7def22015-09-18 16:06:51 +0200936 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200937 IPA_CMD_ASS_ENABLE, &filter_data);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100938 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100939 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
940 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100941 goto out;
942 }
943 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
944out:
945 if (card->info.broadcast_capable)
946 card->dev->flags |= IFF_BROADCAST;
947 else
948 card->dev->flags &= ~IFF_BROADCAST;
949 return rc;
950}
951
Frank Blaschka4a71df52008-02-15 09:19:42 +0100952static int qeth_l3_start_ipassists(struct qeth_card *card)
953{
Carsten Otte847a50f2010-06-21 22:57:05 +0000954 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +0000955
Stefan Raspl0f547612013-01-21 02:30:20 +0000956 if (qeth_set_access_ctrl_online(card, 0))
957 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100958 qeth_l3_start_ipa_arp_processing(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +0100959 qeth_l3_start_ipa_source_mac(card); /* go on*/
960 qeth_l3_start_ipa_vlan(card); /* go on*/
961 qeth_l3_start_ipa_multicast(card); /* go on*/
962 qeth_l3_start_ipa_ipv6(card); /* go on*/
963 qeth_l3_start_ipa_broadcast(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +0100964 return 0;
965}
966
Frank Blaschka4a71df52008-02-15 09:19:42 +0100967static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
968 struct qeth_reply *reply, unsigned long data)
969{
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100970 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100971
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100972 if (cmd->hdr.return_code)
973 return -EIO;
974
975 ether_addr_copy(card->dev->dev_addr,
976 cmd->data.create_destroy_addr.unique_id);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100977 return 0;
978}
979
980static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
981{
982 int rc = 0;
983 struct qeth_cmd_buffer *iob;
984 struct qeth_ipa_cmd *cmd;
985
Julian Wiedmann57a688aa2019-06-11 18:37:55 +0200986 QETH_CARD_TEXT(card, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100987
Julian Wiedmanna59d1212019-06-27 17:01:22 +0200988 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_CREATE_ADDR, QETH_PROT_IPV6,
989 IPA_DATA_SIZEOF(create_destroy_addr));
Thomas Richter1aec42b2015-01-21 13:39:10 +0100990 if (!iob)
991 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100992 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100993 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
994 card->info.unique_id;
995
996 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
997 NULL);
998 return rc;
999}
1000
1001static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1002 struct qeth_reply *reply, unsigned long data)
1003{
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001004 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001005
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001006 if (cmd->hdr.return_code == 0) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001007 card->info.unique_id = *((__u16 *)
1008 &cmd->data.create_destroy_addr.unique_id[6]);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001009 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001010 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001011
1012 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1013 UNIQUE_ID_NOT_BY_CARD;
1014 dev_warn(&card->gdev->dev, "The network adapter failed to generate a unique ID\n");
1015 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001016}
1017
1018static int qeth_l3_get_unique_id(struct qeth_card *card)
1019{
1020 int rc = 0;
1021 struct qeth_cmd_buffer *iob;
1022 struct qeth_ipa_cmd *cmd;
1023
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02001024 QETH_CARD_TEXT(card, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001025
1026 if (!qeth_is_supported(card, IPA_IPV6)) {
1027 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1028 UNIQUE_ID_NOT_BY_CARD;
1029 return 0;
1030 }
1031
Julian Wiedmanna59d1212019-06-27 17:01:22 +02001032 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_CREATE_ADDR, QETH_PROT_IPV6,
1033 IPA_DATA_SIZEOF(create_destroy_addr));
Thomas Richter1aec42b2015-01-21 13:39:10 +01001034 if (!iob)
1035 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001036 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001037 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1038 card->info.unique_id;
1039
1040 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1041 return rc;
1042}
1043
Ursula Braun76b11f82010-01-11 02:50:50 +00001044static int
1045qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1046 unsigned long data)
1047{
1048 struct qeth_ipa_cmd *cmd;
1049 __u16 rc;
1050
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02001051 QETH_CARD_TEXT(card, 2, "diastrcb");
Ursula Braun76b11f82010-01-11 02:50:50 +00001052
1053 cmd = (struct qeth_ipa_cmd *)data;
1054 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001055 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001056 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001057 switch (cmd->data.diagass.action) {
1058 case QETH_DIAGS_CMD_TRACE_QUERY:
1059 break;
1060 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001061 switch (rc) {
1062 case 0:
1063 case IPA_RC_INVALID_SUBCMD:
1064 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1065 dev_info(&card->gdev->dev, "The HiperSockets network "
1066 "traffic analyzer is deactivated\n");
1067 break;
1068 default:
1069 break;
1070 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001071 break;
1072 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001073 switch (rc) {
1074 case 0:
1075 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1076 dev_info(&card->gdev->dev, "The HiperSockets network "
1077 "traffic analyzer is activated\n");
1078 break;
1079 case IPA_RC_HARDWARE_AUTH_ERROR:
1080 dev_warn(&card->gdev->dev, "The device is not "
1081 "authorized to run as a HiperSockets network "
1082 "traffic analyzer\n");
1083 break;
1084 case IPA_RC_TRACE_ALREADY_ACTIVE:
1085 dev_warn(&card->gdev->dev, "A HiperSockets "
1086 "network traffic analyzer is already "
1087 "active in the HiperSockets LAN\n");
1088 break;
1089 default:
1090 break;
1091 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001092 break;
1093 default:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001094 QETH_DBF_MESSAGE(2, "Unknown sniffer action (%#06x) on device %x\n",
1095 cmd->data.diagass.action, CARD_DEVID(card));
Ursula Braun76b11f82010-01-11 02:50:50 +00001096 }
1097
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001098 return rc ? -EIO : 0;
Ursula Braun76b11f82010-01-11 02:50:50 +00001099}
1100
1101static int
1102qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1103{
1104 struct qeth_cmd_buffer *iob;
1105 struct qeth_ipa_cmd *cmd;
1106
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02001107 QETH_CARD_TEXT(card, 2, "diagtrac");
Ursula Braun76b11f82010-01-11 02:50:50 +00001108
Julian Wiedmann5cfbe102019-06-27 17:01:25 +02001109 iob = qeth_get_diag_cmd(card, QETH_DIAGS_CMD_TRACE, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001110 if (!iob)
1111 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001112 cmd = __ipa_cmd(iob);
Ursula Braun76b11f82010-01-11 02:50:50 +00001113 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1114 cmd->data.diagass.action = diags_cmd;
1115 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1116}
1117
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001118static void
1119qeth_l3_add_mc_to_hash(struct qeth_card *card, struct in_device *in4_dev)
1120{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001121 struct ip_mc_list *im4;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001122 struct qeth_ipaddr *tmp, *ipm;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001123
Carsten Otte847a50f2010-06-21 22:57:05 +00001124 QETH_CARD_TEXT(card, 4, "addmc");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001125
1126 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001127 if (!tmp)
1128 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001129
Sachin Santf3aa3132010-11-26 02:41:17 +00001130 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1131 im4 = rcu_dereference(im4->next_rcu)) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001132 ip_eth_mc_map(im4->multiaddr, tmp->mac);
Hans Wippel6bee4e22017-04-07 09:15:36 +02001133 tmp->u.a4.addr = be32_to_cpu(im4->multiaddr);
Julian Wiedmannbc3ab7052017-12-01 10:14:49 +01001134 tmp->is_multicast = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001135
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001136 ipm = qeth_l3_find_addr_by_ip(card, tmp);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001137 if (ipm) {
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001138 /* for mcast, by-IP match means full match */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001139 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1140 } else {
1141 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1142 if (!ipm)
1143 continue;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001144 ether_addr_copy(ipm->mac, tmp->mac);
Hans Wippel6bee4e22017-04-07 09:15:36 +02001145 ipm->u.a4.addr = be32_to_cpu(im4->multiaddr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001146 ipm->is_multicast = 1;
1147 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1148 hash_add(card->ip_mc_htable,
1149 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1150 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001151 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001152
1153 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001154}
1155
Jiri Pirko0347af52013-01-03 22:48:58 +00001156/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001157static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1158{
1159 struct in_device *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001160 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001161
Carsten Otte847a50f2010-06-21 22:57:05 +00001162 QETH_CARD_TEXT(card, 4, "addmcvl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001163
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001164 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001165 return;
1166
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001167 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1168 struct net_device *netdev;
1169
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001170 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001171 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001172 if (netdev == NULL ||
1173 !(netdev->flags & IFF_UP))
1174 continue;
Jiri Pirko0347af52013-01-03 22:48:58 +00001175 in_dev = __in_dev_get_rcu(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001176 if (!in_dev)
1177 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001178 qeth_l3_add_mc_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001179 }
1180}
1181
1182static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1183{
1184 struct in_device *in4_dev;
1185
Carsten Otte847a50f2010-06-21 22:57:05 +00001186 QETH_CARD_TEXT(card, 4, "chkmcv4");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001187
Sachin Santf3aa3132010-11-26 02:41:17 +00001188 rcu_read_lock();
Jiri Pirko0347af52013-01-03 22:48:58 +00001189 in4_dev = __in_dev_get_rcu(card->dev);
1190 if (in4_dev == NULL)
1191 goto unlock;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001192 qeth_l3_add_mc_to_hash(card, in4_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001193 qeth_l3_add_vlan_mc(card);
Jiri Pirko0347af52013-01-03 22:48:58 +00001194unlock:
Sachin Santf3aa3132010-11-26 02:41:17 +00001195 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001196}
1197
Julian Wiedmannc0622042017-12-20 20:10:58 +01001198static void qeth_l3_add_mc6_to_hash(struct qeth_card *card,
1199 struct inet6_dev *in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001200{
1201 struct qeth_ipaddr *ipm;
1202 struct ifmcaddr6 *im6;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001203 struct qeth_ipaddr *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001204
Carsten Otte847a50f2010-06-21 22:57:05 +00001205 QETH_CARD_TEXT(card, 4, "addmc6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001206
1207 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001208 if (!tmp)
1209 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001210
Frank Blaschka4a71df52008-02-15 09:19:42 +01001211 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001212 ipv6_eth_mc_map(&im6->mca_addr, tmp->mac);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001213 memcpy(&tmp->u.a6.addr, &im6->mca_addr.s6_addr,
1214 sizeof(struct in6_addr));
1215 tmp->is_multicast = 1;
1216
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001217 ipm = qeth_l3_find_addr_by_ip(card, tmp);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001218 if (ipm) {
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001219 /* for mcast, by-IP match means full match */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001220 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1221 continue;
1222 }
1223
Frank Blaschka4a71df52008-02-15 09:19:42 +01001224 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1225 if (!ipm)
1226 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001227
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001228 ether_addr_copy(ipm->mac, tmp->mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001229 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1230 sizeof(struct in6_addr));
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001231 ipm->is_multicast = 1;
1232 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1233 hash_add(card->ip_mc_htable,
1234 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1235
Frank Blaschka4a71df52008-02-15 09:19:42 +01001236 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001237 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001238}
1239
Jiri Pirko0347af52013-01-03 22:48:58 +00001240/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001241static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1242{
1243 struct inet6_dev *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001244 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001245
Carsten Otte847a50f2010-06-21 22:57:05 +00001246 QETH_CARD_TEXT(card, 4, "admc6vl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001247
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001248 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001249 return;
1250
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001251 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1252 struct net_device *netdev;
1253
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001254 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001255 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001256 if (netdev == NULL ||
1257 !(netdev->flags & IFF_UP))
1258 continue;
1259 in_dev = in6_dev_get(netdev);
1260 if (!in_dev)
1261 continue;
1262 read_lock_bh(&in_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001263 qeth_l3_add_mc6_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001264 read_unlock_bh(&in_dev->lock);
1265 in6_dev_put(in_dev);
1266 }
1267}
1268
1269static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1270{
1271 struct inet6_dev *in6_dev;
1272
Carsten Otte847a50f2010-06-21 22:57:05 +00001273 QETH_CARD_TEXT(card, 4, "chkmcv6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001274
Frank Blaschka4a71df52008-02-15 09:19:42 +01001275 if (!qeth_is_supported(card, IPA_IPV6))
1276 return ;
1277 in6_dev = in6_dev_get(card->dev);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001278 if (!in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001279 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001280
Jiri Pirko0347af52013-01-03 22:48:58 +00001281 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001282 read_lock_bh(&in6_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001283 qeth_l3_add_mc6_to_hash(card, in6_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001284 qeth_l3_add_vlan_mc6(card);
1285 read_unlock_bh(&in6_dev->lock);
Jiri Pirko0347af52013-01-03 22:48:58 +00001286 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001287 in6_dev_put(in6_dev);
1288}
Frank Blaschka4a71df52008-02-15 09:19:42 +01001289
Patrick McHardy80d5c362013-04-19 02:04:28 +00001290static int qeth_l3_vlan_rx_add_vid(struct net_device *dev,
1291 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001292{
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001293 struct qeth_card *card = dev->ml_priv;
1294
1295 set_bit(vid, card->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001296 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001297}
1298
Patrick McHardy80d5c362013-04-19 02:04:28 +00001299static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev,
1300 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001301{
Heiko Carstens509e2562008-07-26 02:24:10 -07001302 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001303
Carsten Otte847a50f2010-06-21 22:57:05 +00001304 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001305
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001306 clear_bit(vid, card->active_vlans);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001307 qeth_l3_set_rx_mode(dev);
Jiri Pirko8e586132011-12-08 19:52:37 -05001308 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001309}
1310
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001311static void qeth_l3_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
1312 struct qeth_hdr *hdr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001313{
Julian Wiedmannc097cc92019-06-27 17:01:31 +02001314 struct af_iucv_trans_hdr *iucv = (struct af_iucv_trans_hdr *) skb->data;
1315 struct net_device *dev = skb->dev;
1316
1317 if (IS_IQD(card) && iucv->magic == ETH_P_AF_IUCV) {
1318 dev_hard_header(skb, dev, ETH_P_AF_IUCV, dev->dev_addr,
1319 "FAKELL", skb->len);
1320 return;
1321 }
1322
Frank Blaschka4a71df52008-02-15 09:19:42 +01001323 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001324 u16 prot = (hdr->hdr.l3.flags & QETH_HDR_IPV6) ? ETH_P_IPV6 :
1325 ETH_P_IP;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001326 unsigned char tg_addr[ETH_ALEN];
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001327
1328 skb_reset_network_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001329 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1330 case QETH_CAST_MULTICAST:
Julian Wiedmannc0622042017-12-20 20:10:58 +01001331 if (prot == ETH_P_IP)
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001332 ip_eth_mc_map(ip_hdr(skb)->daddr, tg_addr);
Julian Wiedmannc0622042017-12-20 20:10:58 +01001333 else
1334 ipv6_eth_mc_map(&ipv6_hdr(skb)->daddr, tg_addr);
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001335 QETH_CARD_STAT_INC(card, rx_multicast);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001336 break;
1337 case QETH_CAST_BROADCAST:
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001338 ether_addr_copy(tg_addr, card->dev->broadcast);
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001339 QETH_CARD_STAT_INC(card, rx_multicast);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001340 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001341 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00001342 if (card->options.sniffer)
1343 skb->pkt_type = PACKET_OTHERHOST;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001344 ether_addr_copy(tg_addr, card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001345 }
Julian Wiedmann04f67392018-03-09 18:12:58 +01001346
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001347 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1348 card->dev->header_ops->create(skb, card->dev, prot,
Julian Wiedmanna8433832017-12-20 20:11:06 +01001349 tg_addr, &hdr->hdr.l3.next_hop.rx.src_mac,
Julian Wiedmannf0ea8bf2018-03-09 18:12:56 +01001350 skb->len);
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001351 else
1352 card->dev->header_ops->create(skb, card->dev, prot,
Julian Wiedmannf0ea8bf2018-03-09 18:12:56 +01001353 tg_addr, "FAKELL", skb->len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001354 }
1355
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001356 /* copy VLAN tag from hdr into skb */
1357 if (!card->options.sniffer &&
1358 (hdr->hdr.l3.ext_flags & (QETH_HDR_EXT_VLAN_FRAME |
1359 QETH_HDR_EXT_INCLUDE_VLAN_TAG))) {
1360 u16 tag = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
1361 hdr->hdr.l3.vlan_id :
Julian Wiedmanna8433832017-12-20 20:11:06 +01001362 hdr->hdr.l3.next_hop.rx.vlan_id;
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001363 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001364 }
1365
Julian Wiedmann6195b932018-04-26 09:42:17 +02001366 qeth_rx_csum(card, skb, hdr->hdr.l3.ext_flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001367}
1368
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001369static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1370 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001371{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001372 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001373 struct sk_buff *skb;
1374 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001375 unsigned int len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001376
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001377 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +00001378 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001379 while (budget) {
1380 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +00001381 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001382 &card->rx.b_element, &card->rx.e_offset, &hdr);
1383 if (!skb) {
1384 *done = 1;
1385 break;
1386 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001387 switch (hdr->hdr.l3.id) {
1388 case QETH_HEADER_TYPE_LAYER3:
Julian Wiedmannc097cc92019-06-27 17:01:31 +02001389 qeth_l3_rebuild_skb(card, skb, hdr);
1390 /* fall through */
Ursula Braun76b11f82010-01-11 02:50:50 +00001391 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
Ursula Braun76b11f82010-01-11 02:50:50 +00001392 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00001393 len = skb->len;
Julian Wiedmannc097cc92019-06-27 17:01:31 +02001394 napi_gro_receive(&card->napi, skb);
Ursula Braun76b11f82010-01-11 02:50:50 +00001395 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001396 default:
1397 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00001398 QETH_CARD_TEXT(card, 3, "inbunkno");
Julian Wiedmann0ac14872018-09-12 15:31:35 +02001399 QETH_DBF_HEX(CTRL, 3, hdr, sizeof(*hdr));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001400 continue;
1401 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001402 work_done++;
1403 budget--;
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001404 QETH_CARD_STAT_INC(card, rx_packets);
1405 QETH_CARD_STAT_ADD(card, rx_bytes, len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001406 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001407 return work_done;
1408}
1409
Julian Wiedmannd4560152019-02-28 18:59:39 +01001410static void qeth_l3_stop_card(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001411{
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02001412 QETH_CARD_TEXT(card, 2, "stopcard");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001413
1414 qeth_set_allowed_threads(card, 0, 1);
Julian Wiedmann0f7aedbd2019-02-28 18:59:44 +01001415
Julian Wiedmannd0c74822019-03-28 16:39:19 +01001416 cancel_work_sync(&card->rx_mode_work);
1417 qeth_l3_drain_rx_mode_cache(card);
1418
Ursula Braun76b11f82010-01-11 02:50:50 +00001419 if (card->options.sniffer &&
1420 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
1421 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Julian Wiedmann0f7aedbd2019-02-28 18:59:44 +01001422
Frank Blaschka4a71df52008-02-15 09:19:42 +01001423 if (card->state == CARD_STATE_SOFTSETUP) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001424 qeth_l3_clear_ip_htable(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001425 qeth_clear_ipacmd_list(card);
1426 card->state = CARD_STATE_HARDSETUP;
1427 }
1428 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001429 qeth_qdio_clear_card(card, 0);
Julian Wiedmann41c47da2019-04-17 18:17:28 +02001430 qeth_drain_output_queues(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001431 qeth_clear_working_pool_list(card);
1432 card->state = CARD_STATE_DOWN;
1433 }
Julian Wiedmannc0a2e4d2019-02-04 17:40:09 +01001434
1435 flush_workqueue(card->event_wq);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001436}
1437
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001438static void qeth_l3_set_promisc_mode(struct qeth_card *card)
Ursula Braun76b11f82010-01-11 02:50:50 +00001439{
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001440 bool enable = card->dev->flags & IFF_PROMISC;
Ursula Braun76b11f82010-01-11 02:50:50 +00001441
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001442 if (card->info.promisc_mode == enable)
Ursula Braun76b11f82010-01-11 02:50:50 +00001443 return;
1444
Julian Wiedmann379ac992019-04-25 18:25:57 +02001445 if (IS_VM_NIC(card)) { /* Guestlan trace */
Ursula Braun76b11f82010-01-11 02:50:50 +00001446 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001447 qeth_setadp_promisc_mode(card, enable);
Ursula Braun76b11f82010-01-11 02:50:50 +00001448 } else if (card->options.sniffer && /* HiperSockets trace */
1449 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001450 if (enable) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001451 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001452 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
1453 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00001454 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001455 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
1456 }
1457 }
1458}
1459
Julian Wiedmannd0c74822019-03-28 16:39:19 +01001460static void qeth_l3_rx_mode_work(struct work_struct *work)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001461{
Julian Wiedmannd0c74822019-03-28 16:39:19 +01001462 struct qeth_card *card = container_of(work, struct qeth_card,
1463 rx_mode_work);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001464 struct qeth_ipaddr *addr;
1465 struct hlist_node *tmp;
1466 int i, rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001467
Carsten Otte847a50f2010-06-21 22:57:05 +00001468 QETH_CARD_TEXT(card, 3, "setmulti");
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01001469
Ursula Braun76b11f82010-01-11 02:50:50 +00001470 if (!card->options.sniffer) {
Ursula Braun76b11f82010-01-11 02:50:50 +00001471 qeth_l3_add_multicast_ipv4(card);
Ursula Braun76b11f82010-01-11 02:50:50 +00001472 qeth_l3_add_multicast_ipv6(card);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001473
1474 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1475 switch (addr->disp_flag) {
1476 case QETH_DISP_ADDR_DELETE:
1477 rc = qeth_l3_deregister_addr_entry(card, addr);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001478 if (!rc || rc == -ENOENT) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001479 hash_del(&addr->hnode);
1480 kfree(addr);
1481 }
1482 break;
1483 case QETH_DISP_ADDR_ADD:
1484 rc = qeth_l3_register_addr_entry(card, addr);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001485 if (rc && rc != -ENETDOWN) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001486 hash_del(&addr->hnode);
1487 kfree(addr);
1488 break;
1489 }
1490 addr->ref_counter = 1;
1491 /* fall through */
1492 default:
1493 /* for next call to set_rx_mode(): */
1494 addr->disp_flag = QETH_DISP_ADDR_DELETE;
1495 }
1496 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001497 }
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001498
1499 qeth_l3_set_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001500}
1501
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001502static int qeth_l3_arp_makerc(u16 rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001503{
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001504 switch (rc) {
1505 case IPA_RC_SUCCESS:
1506 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001507 case QETH_IPA_ARP_RC_NOTSUPP:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001508 case QETH_IPA_ARP_RC_Q_NOTSUPP:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001509 return -EOPNOTSUPP;
1510 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
1511 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001512 case QETH_IPA_ARP_RC_Q_NO_DATA:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001513 return -ENOENT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001514 default:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001515 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001516 }
1517}
1518
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001519static int qeth_l3_arp_cmd_cb(struct qeth_card *card, struct qeth_reply *reply,
1520 unsigned long data)
1521{
1522 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1523
1524 qeth_setassparms_cb(card, reply, data);
1525 return qeth_l3_arp_makerc(cmd->hdr.return_code);
1526}
1527
Frank Blaschka4a71df52008-02-15 09:19:42 +01001528static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
1529{
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001530 struct qeth_cmd_buffer *iob;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001531 int rc;
1532
Carsten Otte847a50f2010-06-21 22:57:05 +00001533 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001534
1535 /*
1536 * currently GuestLAN only supports the ARP assist function
1537 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
1538 * thus we say EOPNOTSUPP for this ARP function
1539 */
Julian Wiedmann379ac992019-04-25 18:25:57 +02001540 if (IS_VM_NIC(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001541 return -EOPNOTSUPP;
1542 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001543 return -EOPNOTSUPP;
1544 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001545
1546 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
Julian Wiedmannb9150462019-06-27 17:01:24 +02001547 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
1548 SETASS_DATA_SIZEOF(flags_32bit),
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001549 QETH_PROT_IPV4);
1550 if (!iob)
1551 return -ENOMEM;
1552
1553 __ipa_cmd(iob)->data.setassparms.data.flags_32bit = (u32) no_entries;
1554 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001555 if (rc)
1556 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on device %x: %#x\n",
1557 CARD_DEVID(card), rc);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001558 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001559}
1560
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001561static __u32 get_arp_entry_size(struct qeth_card *card,
1562 struct qeth_arp_query_data *qdata,
1563 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001564{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001565 __u32 rc;
1566 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001567
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001568 is_hsi = qdata->reply_bits == 5;
1569 if (type->ip == QETHARP_IP_ADDR_V4) {
1570 QETH_CARD_TEXT(card, 4, "arpev4");
1571 if (strip_entries) {
1572 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
1573 sizeof(struct qeth_arp_qi_entry7_short);
1574 } else {
1575 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
1576 sizeof(struct qeth_arp_qi_entry7);
1577 }
1578 } else if (type->ip == QETHARP_IP_ADDR_V6) {
1579 QETH_CARD_TEXT(card, 4, "arpev6");
1580 if (strip_entries) {
1581 rc = is_hsi ?
1582 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
1583 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
1584 } else {
1585 rc = is_hsi ?
1586 sizeof(struct qeth_arp_qi_entry5_ipv6) :
1587 sizeof(struct qeth_arp_qi_entry7_ipv6);
1588 }
1589 } else {
1590 QETH_CARD_TEXT(card, 4, "arpinv");
1591 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001592 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001593
1594 return rc;
1595}
1596
1597static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
1598{
1599 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
1600 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001601}
1602
1603static int qeth_l3_arp_query_cb(struct qeth_card *card,
1604 struct qeth_reply *reply, unsigned long data)
1605{
1606 struct qeth_ipa_cmd *cmd;
1607 struct qeth_arp_query_data *qdata;
1608 struct qeth_arp_query_info *qinfo;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001609 int e;
1610 int entrybytes_done;
1611 int stripped_bytes;
1612 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001613
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001614 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001615
1616 qinfo = (struct qeth_arp_query_info *) reply->param;
1617 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001618 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001619 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001620 QETH_CARD_TEXT(card, 4, "arpcberr");
1621 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001622 return qeth_l3_arp_makerc(cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001623 }
1624 if (cmd->data.setassparms.hdr.return_code) {
1625 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001626 QETH_CARD_TEXT(card, 4, "setaperr");
1627 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001628 return qeth_l3_arp_makerc(cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001629 }
1630 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00001631 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001632
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001633 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
1634 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
1635 entrybytes_done = 0;
1636 for (e = 0; e < qdata->no_entries; ++e) {
1637 char *cur_entry;
1638 __u32 esize;
1639 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001640
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001641 cur_entry = &qdata->data + entrybytes_done;
1642 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
1643 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
1644 QETH_CARD_TEXT(card, 4, "pmis");
1645 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
1646 break;
1647 }
1648 esize = get_arp_entry_size(card, qdata, etype,
1649 do_strip_entries);
1650 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
1651 if (!esize)
1652 break;
1653
1654 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001655 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOSPC);
1656 memset(qinfo->udata, 0, 4);
1657 return -ENOSPC;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001658 }
1659
1660 memcpy(qinfo->udata + qinfo->udata_offset,
1661 &qdata->data + entrybytes_done + stripped_bytes,
1662 esize);
1663 entrybytes_done += esize + stripped_bytes;
1664 qinfo->udata_offset += esize;
1665 ++qinfo->no_entries;
1666 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001667 /* check if all replies received ... */
1668 if (cmd->data.setassparms.hdr.seq_no <
1669 cmd->data.setassparms.hdr.number_of_replies)
1670 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001671 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001672 memcpy(qinfo->udata, &qinfo->no_entries, 4);
1673 /* keep STRIP_ENTRIES flag so the user program can distinguish
1674 * stripped entries from normal ones */
1675 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
1676 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
1677 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001678 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001679 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001680}
1681
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001682static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
1683 enum qeth_prot_versions prot,
1684 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001685{
1686 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001687 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001688 int rc;
1689
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001690 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
1691
Thomas Richterb475e312015-12-11 12:27:54 +01001692 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
1693 IPA_CMD_ASS_ARP_QUERY_INFO,
Julian Wiedmannb9150462019-06-27 17:01:24 +02001694 SETASS_DATA_SIZEOF(query_arp), prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001695 if (!iob)
1696 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001697 cmd = __ipa_cmd(iob);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001698 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
Julian Wiedmann84dbea42019-02-12 18:33:16 +01001699 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_query_cb, qinfo);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001700 if (rc)
1701 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on device %x: %#x\n",
1702 CARD_DEVID(card), rc);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001703 return rc;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001704}
1705
1706static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
1707{
1708 struct qeth_arp_query_info qinfo = {0, };
1709 int rc;
1710
Carsten Otte847a50f2010-06-21 22:57:05 +00001711 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001712
1713 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
1714 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001715 QETH_CARD_TEXT(card, 3, "arpqnsup");
1716 rc = -EOPNOTSUPP;
1717 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001718 }
1719 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001720 if (copy_from_user(&qinfo, udata, 6)) {
1721 rc = -EFAULT;
1722 goto out;
1723 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001724 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001725 if (!qinfo.udata) {
1726 rc = -ENOMEM;
1727 goto out;
1728 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001729 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001730 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001731 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001732 if (copy_to_user(udata, qinfo.udata, 4))
1733 rc = -EFAULT;
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001734 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001735 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001736 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
1737 /* fails in case of GuestLAN QDIO mode */
1738 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6, &qinfo);
1739 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001740 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
1741 QETH_CARD_TEXT(card, 4, "qactf");
1742 rc = -EFAULT;
1743 goto free_and_out;
1744 }
1745 QETH_CARD_TEXT(card, 4, "qacts");
1746
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001747free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001748 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001749out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001750 return rc;
1751}
1752
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001753static int qeth_l3_arp_modify_entry(struct qeth_card *card,
1754 struct qeth_arp_cache_entry *entry,
1755 enum qeth_arp_process_subcmds arp_cmd)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001756{
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001757 struct qeth_arp_cache_entry *cmd_entry;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001758 struct qeth_cmd_buffer *iob;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001759 int rc;
1760
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001761 if (arp_cmd == IPA_CMD_ASS_ARP_ADD_ENTRY)
1762 QETH_CARD_TEXT(card, 3, "arpadd");
1763 else
1764 QETH_CARD_TEXT(card, 3, "arpdel");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001765
1766 /*
1767 * currently GuestLAN only supports the ARP assist function
1768 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
1769 * thus we say EOPNOTSUPP for this ARP function
1770 */
Julian Wiedmann379ac992019-04-25 18:25:57 +02001771 if (IS_VM_NIC(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001772 return -EOPNOTSUPP;
1773 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001774 return -EOPNOTSUPP;
1775 }
1776
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001777 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, arp_cmd,
Julian Wiedmannb9150462019-06-27 17:01:24 +02001778 SETASS_DATA_SIZEOF(arp_entry),
1779 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001780 if (!iob)
1781 return -ENOMEM;
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001782
1783 cmd_entry = &__ipa_cmd(iob)->data.setassparms.data.arp_entry;
1784 ether_addr_copy(cmd_entry->macaddr, entry->macaddr);
1785 memcpy(cmd_entry->ipaddr, entry->ipaddr, 4);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001786 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001787 if (rc)
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001788 QETH_DBF_MESSAGE(2, "Could not modify (cmd: %#x) ARP entry on device %x: %#x\n",
1789 arp_cmd, CARD_DEVID(card), rc);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001790 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001791}
1792
1793static int qeth_l3_arp_flush_cache(struct qeth_card *card)
1794{
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001795 struct qeth_cmd_buffer *iob;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001796 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001797
Carsten Otte847a50f2010-06-21 22:57:05 +00001798 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001799
1800 /*
1801 * currently GuestLAN only supports the ARP assist function
1802 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
1803 * thus we say EOPNOTSUPP for this ARP function
1804 */
Julian Wiedmann379ac992019-04-25 18:25:57 +02001805 if (IS_VM_NIC(card) || IS_IQD(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001806 return -EOPNOTSUPP;
1807 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001808 return -EOPNOTSUPP;
1809 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001810
1811 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
1812 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0,
1813 QETH_PROT_IPV4);
1814 if (!iob)
1815 return -ENOMEM;
1816
1817 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001818 if (rc)
1819 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on device %x: %#x\n",
1820 CARD_DEVID(card), rc);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001821 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001822}
1823
1824static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1825{
Heiko Carstens509e2562008-07-26 02:24:10 -07001826 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001827 struct qeth_arp_cache_entry arp_entry;
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001828 enum qeth_arp_process_subcmds arp_cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001829 int rc = 0;
1830
Frank Blaschka4a71df52008-02-15 09:19:42 +01001831 switch (cmd) {
1832 case SIOC_QETH_ARP_SET_NO_ENTRIES:
1833 if (!capable(CAP_NET_ADMIN)) {
1834 rc = -EPERM;
1835 break;
1836 }
1837 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
1838 break;
1839 case SIOC_QETH_ARP_QUERY_INFO:
1840 if (!capable(CAP_NET_ADMIN)) {
1841 rc = -EPERM;
1842 break;
1843 }
1844 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
1845 break;
1846 case SIOC_QETH_ARP_ADD_ENTRY:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001847 case SIOC_QETH_ARP_REMOVE_ENTRY:
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001848 if (!capable(CAP_NET_ADMIN))
1849 return -EPERM;
1850 if (copy_from_user(&arp_entry, rq->ifr_data, sizeof(arp_entry)))
1851 return -EFAULT;
1852
1853 arp_cmd = (cmd == SIOC_QETH_ARP_ADD_ENTRY) ?
1854 IPA_CMD_ASS_ARP_ADD_ENTRY :
1855 IPA_CMD_ASS_ARP_REMOVE_ENTRY;
1856 return qeth_l3_arp_modify_entry(card, &arp_entry, arp_cmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001857 case SIOC_QETH_ARP_FLUSH_CACHE:
1858 if (!capable(CAP_NET_ADMIN)) {
1859 rc = -EPERM;
1860 break;
1861 }
1862 rc = qeth_l3_arp_flush_cache(card);
1863 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001864 default:
1865 rc = -EOPNOTSUPP;
1866 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001867 return rc;
1868}
1869
Julian Wiedmann980f4562019-06-27 17:01:32 +02001870static int qeth_l3_get_cast_type_rcu(struct sk_buff *skb, struct dst_entry *dst,
1871 int ipv)
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001872{
David S. Miller69cce1d2011-07-17 23:09:49 -07001873 struct neighbour *n = NULL;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001874
Julian Wiedmann980f4562019-06-27 17:01:32 +02001875 if (dst)
1876 n = dst_neigh_lookup_skb(dst, skb);
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02001877
David S. Miller69cce1d2011-07-17 23:09:49 -07001878 if (n) {
Julian Wiedmann1f979122017-12-20 20:11:04 +01001879 int cast_type = n->type;
1880
David S. Miller24db1ba2012-07-02 22:02:33 -07001881 neigh_release(n);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001882 if ((cast_type == RTN_BROADCAST) ||
1883 (cast_type == RTN_MULTICAST) ||
1884 (cast_type == RTN_ANYCAST))
1885 return cast_type;
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +02001886 return RTN_UNICAST;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001887 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001888
Julian Wiedmann1f979122017-12-20 20:11:04 +01001889 /* no neighbour (eg AF_PACKET), fall back to target's IP address ... */
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02001890 switch (ipv) {
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001891 case 4:
Julian Wiedmann72c87972019-06-05 13:48:48 +02001892 if (ipv4_is_lbcast(ip_hdr(skb)->daddr))
1893 return RTN_BROADCAST;
Julian Wiedmann1f979122017-12-20 20:11:04 +01001894 return ipv4_is_multicast(ip_hdr(skb)->daddr) ?
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +02001895 RTN_MULTICAST : RTN_UNICAST;
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001896 case 6:
1897 return ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr) ?
1898 RTN_MULTICAST : RTN_UNICAST;
1899 default:
1900 /* ... and MAC address */
Julian Wiedmann58aa2492019-04-25 18:26:00 +02001901 return qeth_get_ether_cast_type(skb);
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001902 }
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001903}
1904
Julian Wiedmann980f4562019-06-27 17:01:32 +02001905static int qeth_l3_get_cast_type(struct sk_buff *skb)
1906{
1907 int ipv = qeth_get_ip_version(skb);
1908 struct dst_entry *dst;
1909 int cast_type;
1910
1911 rcu_read_lock();
1912 dst = qeth_dst_check_rcu(skb, ipv);
1913 cast_type = qeth_l3_get_cast_type_rcu(skb, dst, ipv);
1914 rcu_read_unlock();
1915
1916 return cast_type;
1917}
1918
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001919static u8 qeth_l3_cast_type_to_flag(int cast_type)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001920{
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001921 if (cast_type == RTN_MULTICAST)
1922 return QETH_CAST_MULTICAST;
1923 if (cast_type == RTN_ANYCAST)
1924 return QETH_CAST_ANYCAST;
1925 if (cast_type == RTN_BROADCAST)
1926 return QETH_CAST_BROADCAST;
1927 return QETH_CAST_UNICAST;
1928}
David S. Miller69cce1d2011-07-17 23:09:49 -07001929
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001930static void qeth_l3_fill_header(struct qeth_qdio_out_q *queue,
1931 struct qeth_hdr *hdr, struct sk_buff *skb,
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001932 int ipv, unsigned int data_len)
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001933{
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001934 struct qeth_hdr_layer3 *l3_hdr = &hdr->hdr.l3;
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001935 struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001936 struct qeth_card *card = queue->card;
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02001937 struct dst_entry *dst;
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001938 int cast_type;
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001939
Julian Wiedmannf6c13142017-12-20 20:11:08 +01001940 hdr->hdr.l3.length = data_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001941
Julian Wiedmanne517b642018-09-17 17:36:02 +02001942 if (skb_is_gso(skb)) {
Julian Wiedmann0aef8392018-10-12 17:27:15 +02001943 hdr->hdr.l3.id = QETH_HEADER_TYPE_L3_TSO;
Julian Wiedmanne517b642018-09-17 17:36:02 +02001944 } else {
1945 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001946
1947 if (skb->protocol == htons(ETH_P_AF_IUCV)) {
1948 l3_hdr->flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
1949 l3_hdr->next_hop.ipv6_addr.s6_addr16[0] = htons(0xfe80);
1950 memcpy(&l3_hdr->next_hop.ipv6_addr.s6_addr32[2],
1951 iucv_trans_hdr(skb)->destUserID, 8);
1952 return;
1953 }
1954
Julian Wiedmanne517b642018-09-17 17:36:02 +02001955 if (skb->ip_summed == CHECKSUM_PARTIAL) {
1956 qeth_tx_csum(skb, &hdr->hdr.l3.ext_flags, ipv);
1957 /* some HW requires combined L3+L4 csum offload: */
1958 if (ipv == 4)
1959 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_HDR_REQ;
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001960 QETH_TXQ_STAT_INC(queue, skbs_csum);
Julian Wiedmanne517b642018-09-17 17:36:02 +02001961 }
1962 }
1963
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001964 if (ipv == 4 || IS_IQD(card)) {
1965 /* NETIF_F_HW_VLAN_CTAG_TX */
1966 if (skb_vlan_tag_present(skb)) {
1967 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_VLAN_FRAME;
1968 hdr->hdr.l3.vlan_id = skb_vlan_tag_get(skb);
1969 }
1970 } else if (veth->h_vlan_proto == htons(ETH_P_8021Q)) {
1971 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_INCLUDE_VLAN_TAG;
1972 hdr->hdr.l3.vlan_id = ntohs(veth->h_vlan_TCI);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001973 }
1974
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001975 rcu_read_lock();
Julian Wiedmann980f4562019-06-27 17:01:32 +02001976 dst = qeth_dst_check_rcu(skb, ipv);
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02001977
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001978 if (IS_IQD(card) && skb_get_queue_mapping(skb) != QETH_IQD_MCAST_TXQ)
1979 cast_type = RTN_UNICAST;
1980 else
1981 cast_type = qeth_l3_get_cast_type_rcu(skb, dst, ipv);
1982 l3_hdr->flags |= qeth_l3_cast_type_to_flag(cast_type);
1983
Frank Blaschka4a71df52008-02-15 09:19:42 +01001984 if (ipv == 4) {
Julian Wiedmann980f4562019-06-27 17:01:32 +02001985 struct rtable *rt = (struct rtable *) dst;
David Miller87e75972012-02-01 10:49:17 +00001986
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001987 *((__be32 *) &hdr->hdr.l3.next_hop.ipv4.addr) = (rt) ?
1988 rt_nexthop(rt, ip_hdr(skb)->daddr) :
1989 ip_hdr(skb)->daddr;
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001990 } else if (ipv == 6) {
Julian Wiedmann980f4562019-06-27 17:01:32 +02001991 struct rt6_info *rt = (struct rt6_info *) dst;
David Miller87e75972012-02-01 10:49:17 +00001992
Julian Wiedmannec2c6722017-08-07 13:28:39 +02001993 if (rt && !ipv6_addr_any(&rt->rt6i_gateway))
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001994 l3_hdr->next_hop.ipv6_addr = rt->rt6i_gateway;
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001995 else
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001996 l3_hdr->next_hop.ipv6_addr = ipv6_hdr(skb)->daddr;
David Miller87e75972012-02-01 10:49:17 +00001997
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001998 hdr->hdr.l3.flags |= QETH_HDR_IPV6;
Julian Wiedmann379ac992019-04-25 18:25:57 +02001999 if (!IS_IQD(card))
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002000 hdr->hdr.l3.flags |= QETH_HDR_PASSTHRU;
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02002001 } else {
2002 /* OSA only: */
2003 l3_hdr->flags |= QETH_HDR_PASSTHRU;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002004 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002005 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002006}
2007
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02002008static void qeth_l3_fixup_headers(struct sk_buff *skb)
2009{
2010 struct iphdr *iph = ip_hdr(skb);
2011
2012 /* this is safe, IPv6 traffic takes a different path */
2013 if (skb->ip_summed == CHECKSUM_PARTIAL)
2014 iph->check = 0;
Julian Wiedmanne517b642018-09-17 17:36:02 +02002015 if (skb_is_gso(skb)) {
2016 iph->tot_len = 0;
2017 tcp_hdr(skb)->check = ~tcp_v4_check(0, iph->saddr,
2018 iph->daddr, 0);
2019 }
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02002020}
2021
Julian Wiedmann356156b2018-09-17 17:36:03 +02002022static int qeth_l3_xmit(struct qeth_card *card, struct sk_buff *skb,
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02002023 struct qeth_qdio_out_q *queue, int ipv)
Julian Wiedmanna647a022018-07-11 17:42:46 +02002024{
Julian Wiedmann81ec5432018-11-08 15:06:17 +01002025 unsigned int hw_hdr_len;
2026 int rc;
Julian Wiedmanne517b642018-09-17 17:36:02 +02002027
Julian Wiedmanna647a022018-07-11 17:42:46 +02002028 /* re-use the L2 header area for the HW header: */
Julian Wiedmann81ec5432018-11-08 15:06:17 +01002029 hw_hdr_len = skb_is_gso(skb) ? sizeof(struct qeth_hdr_tso) :
2030 sizeof(struct qeth_hdr);
Julian Wiedmanna647a022018-07-11 17:42:46 +02002031 rc = skb_cow_head(skb, hw_hdr_len - ETH_HLEN);
2032 if (rc)
2033 return rc;
Julian Wiedmanna647a022018-07-11 17:42:46 +02002034 skb_pull(skb, ETH_HLEN);
Julian Wiedmanna647a022018-07-11 17:42:46 +02002035
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02002036 qeth_l3_fixup_headers(skb);
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02002037 return qeth_xmit(card, skb, queue, ipv, qeth_l3_fill_header);
Julian Wiedmanna647a022018-07-11 17:42:46 +02002038}
2039
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002040static netdev_tx_t qeth_l3_hard_start_xmit(struct sk_buff *skb,
2041 struct net_device *dev)
2042{
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002043 struct qeth_card *card = dev->ml_priv;
Julian Wiedmann3a18d752019-04-17 18:17:32 +02002044 u16 txq = skb_get_queue_mapping(skb);
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002045 int ipv = qeth_get_ip_version(skb);
2046 struct qeth_qdio_out_q *queue;
2047 int tx_bytes = skb->len;
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02002048 int rc;
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002049
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002050 if (IS_IQD(card)) {
Julian Wiedmann3a18d752019-04-17 18:17:32 +02002051 queue = card->qdio.out_qs[qeth_iqd_translate_txq(dev, txq)];
2052
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002053 if (card->options.sniffer)
2054 goto tx_drop;
2055 if ((card->options.cq != QETH_CQ_ENABLED && !ipv) ||
2056 (card->options.cq == QETH_CQ_ENABLED &&
2057 skb->protocol != htons(ETH_P_AF_IUCV)))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002058 goto tx_drop;
Julian Wiedmann3a18d752019-04-17 18:17:32 +02002059 } else {
Julian Wiedmann73dc2da2019-04-17 18:17:33 +02002060 queue = card->qdio.out_qs[txq];
Frank Blaschka4a71df52008-02-15 09:19:42 +01002061 }
2062
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02002063 if (!(dev->flags & IFF_BROADCAST) &&
2064 qeth_l3_get_cast_type(skb) == RTN_BROADCAST)
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002065 goto tx_drop;
2066
Julian Wiedmann356156b2018-09-17 17:36:03 +02002067 if (ipv == 4 || IS_IQD(card))
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02002068 rc = qeth_l3_xmit(card, skb, queue, ipv);
Julian Wiedmannf13ade12018-09-17 17:35:56 +02002069 else
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02002070 rc = qeth_xmit(card, skb, queue, ipv, qeth_l3_fill_header);
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002071
2072 if (!rc) {
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002073 QETH_TXQ_STAT_INC(queue, tx_packets);
2074 QETH_TXQ_STAT_ADD(queue, tx_bytes, tx_bytes);
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002075 return NETDEV_TX_OK;
Julian Wiedmann54a50942019-04-17 18:17:35 +02002076 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002077
2078tx_drop:
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002079 QETH_TXQ_STAT_INC(queue, tx_dropped);
Julian Wiedmann104b4852019-03-18 16:40:56 +01002080 kfree_skb(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002081 return NETDEV_TX_OK;
2082}
2083
Julian Wiedmannd0c74822019-03-28 16:39:19 +01002084static void qeth_l3_set_rx_mode(struct net_device *dev)
2085{
2086 struct qeth_card *card = dev->ml_priv;
2087
2088 schedule_work(&card->rx_mode_work);
2089}
2090
Frank Blaschka4a71df52008-02-15 09:19:42 +01002091/*
2092 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
2093 * NOARP on the netdevice is no option because it also turns off neighbor
2094 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
2095 * arp resolution but we want the hard header (packet socket will work
2096 * e.g. tcpdump)
2097 */
2098static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
2099{
2100 n->nud_state = NUD_NOARP;
2101 memcpy(n->ha, "FAKELL", 6);
2102 n->output = n->ops->connected_output;
2103 return 0;
2104}
2105
2106static int
2107qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
2108{
2109 if (np->tbl->family == AF_INET)
2110 np->neigh_setup = qeth_l3_neigh_setup_noarp;
2111
2112 return 0;
2113}
2114
Julian Wiedmannf13ade12018-09-17 17:35:56 +02002115static netdev_features_t qeth_l3_osa_features_check(struct sk_buff *skb,
2116 struct net_device *dev,
2117 netdev_features_t features)
2118{
2119 if (qeth_get_ip_version(skb) != 4)
2120 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
2121 return qeth_features_check(skb, dev, features);
2122}
2123
Julian Wiedmann3a18d752019-04-17 18:17:32 +02002124static u16 qeth_l3_iqd_select_queue(struct net_device *dev, struct sk_buff *skb,
2125 struct net_device *sb_dev)
2126{
2127 return qeth_iqd_select_queue(dev, skb, qeth_l3_get_cast_type(skb),
2128 sb_dev);
2129}
2130
Julian Wiedmann73dc2da2019-04-17 18:17:33 +02002131static u16 qeth_l3_osa_select_queue(struct net_device *dev, struct sk_buff *skb,
2132 struct net_device *sb_dev)
2133{
2134 struct qeth_card *card = dev->ml_priv;
2135
2136 return qeth_get_priority_queue(card, skb);
2137}
2138
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002139static const struct net_device_ops qeth_l3_netdev_ops = {
Julian Wiedmanne22355e2019-01-25 15:44:18 +01002140 .ndo_open = qeth_open,
2141 .ndo_stop = qeth_stop,
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002142 .ndo_get_stats64 = qeth_get_stats64,
Frank Blaschka8403b132009-01-08 10:50:55 -08002143 .ndo_start_xmit = qeth_l3_hard_start_xmit,
Julian Wiedmann3a18d752019-04-17 18:17:32 +02002144 .ndo_select_queue = qeth_l3_iqd_select_queue,
Frank Blaschka8403b132009-01-08 10:50:55 -08002145 .ndo_validate_addr = eth_validate_addr,
Julian Wiedmann00c163f2017-12-20 20:11:02 +01002146 .ndo_set_rx_mode = qeth_l3_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002147 .ndo_do_ioctl = qeth_do_ioctl,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002148 .ndo_fix_features = qeth_fix_features,
2149 .ndo_set_features = qeth_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08002150 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2151 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002152 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka8403b132009-01-08 10:50:55 -08002153};
2154
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002155static const struct net_device_ops qeth_l3_osa_netdev_ops = {
Julian Wiedmanne22355e2019-01-25 15:44:18 +01002156 .ndo_open = qeth_open,
2157 .ndo_stop = qeth_stop,
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002158 .ndo_get_stats64 = qeth_get_stats64,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002159 .ndo_start_xmit = qeth_l3_hard_start_xmit,
Julian Wiedmannf13ade12018-09-17 17:35:56 +02002160 .ndo_features_check = qeth_l3_osa_features_check,
Julian Wiedmann73dc2da2019-04-17 18:17:33 +02002161 .ndo_select_queue = qeth_l3_osa_select_queue,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002162 .ndo_validate_addr = eth_validate_addr,
Julian Wiedmann00c163f2017-12-20 20:11:02 +01002163 .ndo_set_rx_mode = qeth_l3_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002164 .ndo_do_ioctl = qeth_do_ioctl,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002165 .ndo_fix_features = qeth_fix_features,
2166 .ndo_set_features = qeth_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002167 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2168 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002169 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002170 .ndo_neigh_setup = qeth_l3_neigh_setup,
2171};
2172
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002173static int qeth_l3_setup_netdev(struct qeth_card *card, bool carrier_ok)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002174{
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002175 unsigned int headroom;
Thomas Richter1aec42b2015-01-21 13:39:10 +01002176 int rc;
2177
Julian Wiedmann379ac992019-04-25 18:25:57 +02002178 if (IS_OSD(card) || IS_OSX(card)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002179 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
2180 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002181 pr_info("qeth_l3: ignoring TR device\n");
2182 return -ENODEV;
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002183 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002184
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002185 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Julian Wiedmann0f342942018-03-09 18:12:54 +01002186
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002187 /*IPv6 address autoconfiguration stuff*/
2188 qeth_l3_get_unique_id(card);
2189 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
2190 card->dev->dev_id = card->info.unique_id & 0xffff;
Julian Wiedmann0f342942018-03-09 18:12:54 +01002191
Julian Wiedmann379ac992019-04-25 18:25:57 +02002192 if (!IS_VM_NIC(card)) {
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002193 card->dev->features |= NETIF_F_SG;
2194 card->dev->hw_features |= NETIF_F_TSO |
2195 NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
2196 card->dev->vlan_features |= NETIF_F_TSO |
2197 NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002198 }
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +02002199
2200 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) {
2201 card->dev->hw_features |= NETIF_F_IPV6_CSUM;
2202 card->dev->vlan_features |= NETIF_F_IPV6_CSUM;
2203 }
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002204 if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) {
2205 card->dev->hw_features |= NETIF_F_TSO6;
2206 card->dev->vlan_features |= NETIF_F_TSO6;
2207 }
2208
2209 /* allow for de-acceleration of NETIF_F_HW_VLAN_CTAG_TX: */
2210 if (card->dev->hw_features & NETIF_F_TSO6)
2211 headroom = sizeof(struct qeth_hdr_tso) + VLAN_HLEN;
2212 else if (card->dev->hw_features & NETIF_F_TSO)
2213 headroom = sizeof(struct qeth_hdr_tso);
2214 else
2215 headroom = sizeof(struct qeth_hdr) + VLAN_HLEN;
Julian Wiedmann379ac992019-04-25 18:25:57 +02002216 } else if (IS_IQD(card)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002217 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002218 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002219 headroom = sizeof(struct qeth_hdr) - ETH_HLEN;
Julian Wiedmanna647a022018-07-11 17:42:46 +02002220
Thomas Richter1aec42b2015-01-21 13:39:10 +01002221 rc = qeth_l3_iqd_read_initial_mac(card);
2222 if (rc)
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002223 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002224 } else
2225 return -ENODEV;
2226
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002227 card->dev->needed_headroom = headroom;
Patrick McHardyf6469682013-04-19 02:04:27 +00002228 card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2229 NETIF_F_HW_VLAN_CTAG_RX |
2230 NETIF_F_HW_VLAN_CTAG_FILTER;
Julian Wiedmanna647a022018-07-11 17:42:46 +02002231
Eric Dumazet02875872014-10-05 18:38:35 -07002232 netif_keep_dst(card->dev);
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002233 if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6))
Julian Wiedmann371a1e72018-07-11 17:42:44 +02002234 netif_set_gso_max_size(card->dev,
2235 PAGE_SIZE * (QETH_MAX_BUFFER_ELEMENTS(card) - 1));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002236
Julian Wiedmannd73ef322017-04-11 16:11:11 +02002237 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002238 rc = register_netdev(card->dev);
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002239 if (!rc && carrier_ok)
2240 netif_carrier_on(card->dev);
2241
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002242out:
2243 if (rc)
2244 card->dev->netdev_ops = NULL;
2245 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002246}
2247
Ursula Braun79a04e42017-06-06 14:33:49 +02002248static const struct device_type qeth_l3_devtype = {
2249 .name = "qeth_layer3",
2250 .groups = qeth_l3_attr_groups,
2251};
2252
Frank Blaschka4a71df52008-02-15 09:19:42 +01002253static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
2254{
2255 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +02002256 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002257
Julian Wiedmann7221b722019-03-18 16:40:55 +01002258 hash_init(card->ip_htable);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +01002259 mutex_init(&card->ip_lock);
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002260 card->cmd_wq = alloc_ordered_workqueue("%s_cmd", 0,
2261 dev_name(&gdev->dev));
2262 if (!card->cmd_wq)
2263 return -ENOMEM;
Julian Wiedmann7221b722019-03-18 16:40:55 +01002264
Ursula Braun79a04e42017-06-06 14:33:49 +02002265 if (gdev->dev.type == &qeth_generic_devtype) {
2266 rc = qeth_l3_create_device_attributes(&gdev->dev);
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002267 if (rc) {
2268 destroy_workqueue(card->cmd_wq);
Ursula Braun79a04e42017-06-06 14:33:49 +02002269 return rc;
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002270 }
Ursula Braun79a04e42017-06-06 14:33:49 +02002271 }
Julian Wiedmann7221b722019-03-18 16:40:55 +01002272
Ursula Braunebccc7392017-05-10 19:07:54 +02002273 hash_init(card->ip_mc_htable);
Julian Wiedmannd0c74822019-03-28 16:39:19 +01002274 INIT_WORK(&card->rx_mode_work, qeth_l3_rx_mode_work);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002275 return 0;
2276}
2277
2278static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
2279{
2280 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
2281
Ursula Braun79a04e42017-06-06 14:33:49 +02002282 if (cgdev->dev.type == &qeth_generic_devtype)
2283 qeth_l3_remove_device_attributes(&cgdev->dev);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002284
Ursula Braunf2148562009-05-19 21:38:37 +00002285 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002286 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
2287
Ursula Braun70919e22011-02-26 22:41:36 -08002288 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002289 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002290
Julian Wiedmannc2780c12019-02-04 17:40:08 +01002291 cancel_work_sync(&card->close_dev_work);
Julian Wiedmann30356d02018-11-02 19:04:10 +01002292 if (qeth_netdev_is_registered(card->dev))
2293 unregister_netdev(card->dev);
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002294
2295 flush_workqueue(card->cmd_wq);
2296 destroy_workqueue(card->cmd_wq);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002297 qeth_l3_clear_ip_htable(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002298 qeth_l3_clear_ipato_list(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002299}
2300
Julian Wiedmannd4560152019-02-28 18:59:39 +01002301static int qeth_l3_set_online(struct ccwgroup_device *gdev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002302{
2303 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002304 struct net_device *dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002305 int rc = 0;
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002306 bool carrier_ok;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002307
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002308 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002309 mutex_lock(&card->conf_mutex);
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002310 QETH_CARD_TEXT(card, 2, "setonlin");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002311
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002312 rc = qeth_core_hardsetup_card(card, &carrier_ok);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002313 if (rc) {
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002314 QETH_CARD_TEXT_(card, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00002315 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002316 goto out_remove;
2317 }
2318
Frank Blaschka1da74b12011-05-12 18:45:02 +00002319 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
2320 if (card->info.hwtrap &&
2321 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
2322 card->info.hwtrap = 0;
2323 } else
2324 card->info.hwtrap = 0;
2325
Frank Blaschka4a71df52008-02-15 09:19:42 +01002326 card->state = CARD_STATE_HARDSETUP;
2327 qeth_print_status_message(card);
2328
2329 /* softsetup */
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002330 QETH_CARD_TEXT(card, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002331
Frank Blaschka4a71df52008-02-15 09:19:42 +01002332 rc = qeth_l3_setadapter_parms(card);
2333 if (rc)
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002334 QETH_CARD_TEXT_(card, 2, "2err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002335 if (!card->options.sniffer) {
2336 rc = qeth_l3_start_ipassists(card);
Stefan Raspl0f547612013-01-21 02:30:20 +00002337 if (rc) {
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002338 QETH_CARD_TEXT_(card, 2, "3err%d", rc);
Stefan Raspl0f547612013-01-21 02:30:20 +00002339 goto out_remove;
2340 }
Ursula Braun76b11f82010-01-11 02:50:50 +00002341 rc = qeth_l3_setrouting_v4(card);
2342 if (rc)
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002343 QETH_CARD_TEXT_(card, 2, "4err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002344 rc = qeth_l3_setrouting_v6(card);
2345 if (rc)
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002346 QETH_CARD_TEXT_(card, 2, "5err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002347 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002348
2349 rc = qeth_init_qdio_queues(card);
2350 if (rc) {
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002351 QETH_CARD_TEXT_(card, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00002352 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002353 goto out_remove;
2354 }
2355 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002356
2357 qeth_set_allowed_threads(card, 0xffffffff, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002358 qeth_l3_recover_ip(card);
Julian Wiedmannd025da92018-06-29 19:45:54 +02002359
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002360 if (!qeth_netdev_is_registered(dev)) {
2361 rc = qeth_l3_setup_netdev(card, carrier_ok);
2362 if (rc)
2363 goto out_remove;
2364 } else {
Ursula Braun4763b0a2011-12-19 22:56:32 +00002365 rtnl_lock();
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002366 if (carrier_ok)
2367 netif_carrier_on(dev);
2368 else
2369 netif_carrier_off(dev);
2370
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01002371 netif_device_attach(dev);
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002372 qeth_enable_hw_features(dev);
2373
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01002374 if (card->info.open_when_online) {
2375 card->info.open_when_online = 0;
Julian Wiedmannd4560152019-02-28 18:59:39 +01002376 dev_open(dev, NULL);
Julian Wiedmann9aa17df2018-07-11 17:42:40 +02002377 }
Ursula Braun4763b0a2011-12-19 22:56:32 +00002378 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002379 }
Stefan Raspl82f77cf2013-03-18 20:04:42 +00002380 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002381 /* let user_space know that device is online */
2382 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002383 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002384 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002385 return 0;
2386out_remove:
Julian Wiedmannd4560152019-02-28 18:59:39 +01002387 qeth_l3_stop_card(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002388 ccw_device_set_offline(CARD_DDEV(card));
2389 ccw_device_set_offline(CARD_WDEV(card));
2390 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01002391 qdio_free(CARD_DDEV(card));
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01002392
Frank Blaschkac4949f02010-05-11 19:34:47 +00002393 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002394 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00002395 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002396}
2397
Frank Blaschka4a71df52008-02-15 09:19:42 +01002398static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
2399 int recovery_mode)
2400{
2401 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
2402 int rc = 0, rc2 = 0, rc3 = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002403
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002404 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002405 mutex_lock(&card->conf_mutex);
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002406 QETH_CARD_TEXT(card, 3, "setoffl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002407
Julian Wiedmannd7ef489f2019-02-28 18:59:37 +01002408 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
2409 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
2410 card->info.hwtrap = 1;
2411 }
2412
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01002413 rtnl_lock();
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01002414 card->info.open_when_online = card->dev->flags & IFF_UP;
Julian Wiedmannd4560152019-02-28 18:59:39 +01002415 dev_close(card->dev);
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01002416 netif_device_detach(card->dev);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002417 netif_carrier_off(card->dev);
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01002418 rtnl_unlock();
2419
Julian Wiedmannd4560152019-02-28 18:59:39 +01002420 qeth_l3_stop_card(card);
Julian Wiedmann464e86d2019-02-28 18:59:40 +01002421 if (card->options.cq == QETH_CQ_ENABLED) {
Einar Lueck72861ae2011-12-19 22:56:36 +00002422 rtnl_lock();
2423 call_netdevice_notifiers(NETDEV_REBOOT, card->dev);
2424 rtnl_unlock();
2425 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002426 rc = ccw_device_set_offline(CARD_DDEV(card));
2427 rc2 = ccw_device_set_offline(CARD_WDEV(card));
2428 rc3 = ccw_device_set_offline(CARD_RDEV(card));
2429 if (!rc)
2430 rc = (rc2) ? rc2 : rc3;
2431 if (rc)
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002432 QETH_CARD_TEXT_(card, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01002433 qdio_free(CARD_DDEV(card));
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01002434
Frank Blaschka4a71df52008-02-15 09:19:42 +01002435 /* let user_space know that device is offline */
2436 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002437 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002438 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002439 return 0;
2440}
2441
2442static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
2443{
2444 return __qeth_l3_set_offline(cgdev, 0);
2445}
2446
2447static int qeth_l3_recover(void *ptr)
2448{
2449 struct qeth_card *card;
2450 int rc = 0;
2451
2452 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00002453 QETH_CARD_TEXT(card, 2, "recover1");
2454 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002455 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
2456 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00002457 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002458 dev_warn(&card->gdev->dev,
2459 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002460 __qeth_l3_set_offline(card->gdev, 1);
Julian Wiedmannd4560152019-02-28 18:59:39 +01002461 rc = qeth_l3_set_online(card->gdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002462 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002463 dev_info(&card->gdev->dev,
2464 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02002465 else {
Julian Wiedmannbf42d402019-02-28 18:59:41 +01002466 ccwgroup_set_offline(card->gdev);
Stefan Raspl0f547612013-01-21 02:30:20 +00002467 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00002468 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02002469 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002470 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
2471 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002472 return 0;
2473}
2474
Eugene Crosserc044dc22014-01-29 09:23:48 +01002475/* Returns zero if the command is successfully "consumed" */
2476static int qeth_l3_control_event(struct qeth_card *card,
2477 struct qeth_ipa_cmd *cmd)
2478{
2479 return 1;
2480}
2481
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002482struct qeth_discipline qeth_l3_discipline = {
Ursula Braun79a04e42017-06-06 14:33:49 +02002483 .devtype = &qeth_l3_devtype,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02002484 .process_rx_buffer = qeth_l3_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002485 .recover = qeth_l3_recover,
2486 .setup = qeth_l3_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002487 .remove = qeth_l3_remove_device,
2488 .set_online = qeth_l3_set_online,
2489 .set_offline = qeth_l3_set_offline,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002490 .do_ioctl = qeth_l3_do_ioctl,
Eugene Crosserc044dc22014-01-29 09:23:48 +01002491 .control_event_handler = qeth_l3_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002492};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002493EXPORT_SYMBOL_GPL(qeth_l3_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002494
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002495static int qeth_l3_handle_ip_event(struct qeth_card *card,
2496 struct qeth_ipaddr *addr,
2497 unsigned long event)
2498{
2499 switch (event) {
2500 case NETDEV_UP:
Julian Wiedmann05a17852019-03-28 16:39:21 +01002501 qeth_l3_modify_ip(card, addr, true);
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002502 return NOTIFY_OK;
2503 case NETDEV_DOWN:
Julian Wiedmann05a17852019-03-28 16:39:21 +01002504 qeth_l3_modify_ip(card, addr, false);
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002505 return NOTIFY_OK;
2506 default:
2507 return NOTIFY_DONE;
2508 }
2509}
2510
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002511struct qeth_l3_ip_event_work {
2512 struct work_struct work;
2513 struct qeth_card *card;
2514 struct qeth_ipaddr addr;
2515};
2516
2517#define to_ip_work(w) container_of((w), struct qeth_l3_ip_event_work, work)
2518
2519static void qeth_l3_add_ip_worker(struct work_struct *work)
2520{
2521 struct qeth_l3_ip_event_work *ip_work = to_ip_work(work);
2522
2523 qeth_l3_modify_ip(ip_work->card, &ip_work->addr, true);
2524 kfree(work);
2525}
2526
2527static void qeth_l3_delete_ip_worker(struct work_struct *work)
2528{
2529 struct qeth_l3_ip_event_work *ip_work = to_ip_work(work);
2530
2531 qeth_l3_modify_ip(ip_work->card, &ip_work->addr, false);
2532 kfree(work);
2533}
2534
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002535static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2536{
2537 if (is_vlan_dev(dev))
2538 dev = vlan_dev_real_dev(dev);
2539 if (dev->netdev_ops == &qeth_l3_osa_netdev_ops ||
2540 dev->netdev_ops == &qeth_l3_netdev_ops)
2541 return (struct qeth_card *) dev->ml_priv;
2542 return NULL;
2543}
2544
Frank Blaschka4a71df52008-02-15 09:19:42 +01002545static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07002546 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002547{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002548
Frank Blaschka4a71df52008-02-15 09:19:42 +01002549 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002550 struct net_device *dev = ifa->ifa_dev->dev;
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002551 struct qeth_ipaddr addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002552 struct qeth_card *card;
2553
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09002554 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07002555 return NOTIFY_DONE;
2556
Frank Blaschka4a71df52008-02-15 09:19:42 +01002557 card = qeth_l3_get_card_from_dev(dev);
2558 if (!card)
2559 return NOTIFY_DONE;
frank.blaschka@de.ibm.com6d8823d2012-05-16 01:28:26 +00002560 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002561
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002562 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV4);
2563 addr.u.a4.addr = be32_to_cpu(ifa->ifa_address);
2564 addr.u.a4.mask = be32_to_cpu(ifa->ifa_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002565
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002566 return qeth_l3_handle_ip_event(card, &addr, event);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002567}
2568
2569static struct notifier_block qeth_l3_ip_notifier = {
2570 qeth_l3_ip_event,
2571 NULL,
2572};
2573
Frank Blaschka4a71df52008-02-15 09:19:42 +01002574static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07002575 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002576{
2577 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002578 struct net_device *dev = ifa->idev->dev;
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002579 struct qeth_l3_ip_event_work *ip_work;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002580 struct qeth_card *card;
2581
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002582 if (event != NETDEV_UP && event != NETDEV_DOWN)
2583 return NOTIFY_DONE;
2584
Frank Blaschka4a71df52008-02-15 09:19:42 +01002585 card = qeth_l3_get_card_from_dev(dev);
2586 if (!card)
2587 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00002588 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002589 if (!qeth_is_supported(card, IPA_IPV6))
2590 return NOTIFY_DONE;
2591
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002592 ip_work = kmalloc(sizeof(*ip_work), GFP_ATOMIC);
2593 if (!ip_work)
2594 return NOTIFY_DONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002595
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002596 if (event == NETDEV_UP)
2597 INIT_WORK(&ip_work->work, qeth_l3_add_ip_worker);
2598 else
2599 INIT_WORK(&ip_work->work, qeth_l3_delete_ip_worker);
2600
2601 ip_work->card = card;
2602 qeth_l3_init_ipaddr(&ip_work->addr, QETH_IP_TYPE_NORMAL,
2603 QETH_PROT_IPV6);
2604 ip_work->addr.u.a6.addr = ifa->addr;
2605 ip_work->addr.u.a6.pfxlen = ifa->prefix_len;
2606
2607 queue_work(card->cmd_wq, &ip_work->work);
2608 return NOTIFY_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002609}
2610
2611static struct notifier_block qeth_l3_ip6_notifier = {
2612 qeth_l3_ip6_event,
2613 NULL,
2614};
Frank Blaschka4a71df52008-02-15 09:19:42 +01002615
2616static int qeth_l3_register_notifiers(void)
2617{
2618 int rc;
2619
Carsten Otte847a50f2010-06-21 22:57:05 +00002620 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002621 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
2622 if (rc)
2623 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002624 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
2625 if (rc) {
2626 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
2627 return rc;
2628 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002629 return 0;
2630}
2631
2632static void qeth_l3_unregister_notifiers(void)
2633{
Carsten Otte847a50f2010-06-21 22:57:05 +00002634 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Stefan Raspl18af5c12012-11-19 02:46:50 +00002635 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
Stefan Raspl18af5c12012-11-19 02:46:50 +00002636 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002637}
2638
2639static int __init qeth_l3_init(void)
2640{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002641 pr_info("register layer 3 discipline\n");
Julian Wiedmannc0622042017-12-20 20:10:58 +01002642 return qeth_l3_register_notifiers();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002643}
2644
2645static void __exit qeth_l3_exit(void)
2646{
2647 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002648 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002649}
2650
2651module_init(qeth_l3_init);
2652module_exit(qeth_l3_exit);
2653MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2654MODULE_DESCRIPTION("qeth layer 3 discipline");
2655MODULE_LICENSE("GPL");