blob: 5e810561cb1247884d5d5b455a02c1ed8cae7675 [file] [log] [blame]
Greg Kroah-Hartmanab9953f2017-11-14 18:38:04 +01001// SPDX-License-Identifier: GPL-2.0
Frank Blaschka4a71df52008-02-15 09:19:42 +01002/*
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003 * Copyright IBM Corp. 2007, 2009
Frank Blaschka4a71df52008-02-15 09:19:42 +01004 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
5 * Frank Pavlic <fpavlic@de.ibm.com>,
6 * Thomas Spatzier <tspat@de.ibm.com>,
7 * Frank Blaschka <frank.blaschka@de.ibm.com>
8 */
9
Frank Blaschka74eacdb2008-12-25 13:39:49 +010010#define KMSG_COMPONENT "qeth"
11#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
Frank Blaschka4a71df52008-02-15 09:19:42 +010013#include <linux/module.h>
14#include <linux/moduleparam.h>
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +000015#include <linux/bitops.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010016#include <linux/string.h>
17#include <linux/errno.h>
18#include <linux/kernel.h>
19#include <linux/etherdevice.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010020#include <linux/ip.h>
Julian Wiedmann1f979122017-12-20 20:11:04 +010021#include <linux/in.h>
Frank Blaschka64ef8952009-03-24 20:57:16 +000022#include <linux/ipv6.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010023#include <linux/inetdevice.h>
24#include <linux/igmp.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Julian Wiedmann910a0a82017-12-20 20:11:07 +010026#include <linux/if_ether.h>
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +000027#include <linux/if_vlan.h>
Julian Wiedmann910a0a82017-12-20 20:11:07 +010028#include <linux/skbuff.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010029
30#include <net/ip.h>
31#include <net/arp.h>
David Miller87e75972012-02-01 10:49:17 +000032#include <net/route.h>
Julian Wiedmann1f979122017-12-20 20:11:04 +010033#include <net/ipv6.h>
Julian Wiedmann910a0a82017-12-20 20:11:07 +010034#include <net/ip6_route.h>
David Miller87e75972012-02-01 10:49:17 +000035#include <net/ip6_fib.h>
Frank Blaschkab3332932011-08-08 01:33:59 +000036#include <net/iucv/af_iucv.h>
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020037#include <linux/hashtable.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010038
Frank Blaschka4a71df52008-02-15 09:19:42 +010039#include "qeth_l3.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010040
Einar Lueckd0ddf30f2010-12-08 02:57:58 +000041
Frank Blaschka4a71df52008-02-15 09:19:42 +010042static int qeth_l3_set_offline(struct ccwgroup_device *);
Frank Blaschka4a71df52008-02-15 09:19:42 +010043static int qeth_l3_stop(struct net_device *);
Julian Wiedmann00c163f2017-12-20 20:11:02 +010044static void qeth_l3_set_rx_mode(struct net_device *dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +010045static int qeth_l3_register_addr_entry(struct qeth_card *,
46 struct qeth_ipaddr *);
47static int qeth_l3_deregister_addr_entry(struct qeth_card *,
48 struct qeth_ipaddr *);
Frank Blaschka4a71df52008-02-15 09:19:42 +010049
Thomas Richter56530d62014-10-22 12:18:04 +020050static void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010051{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020052 sprintf(buf, "%pI4", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010053}
54
Thomas Richter56530d62014-10-22 12:18:04 +020055static void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010056{
Joe Perches963a9fd2010-09-07 21:14:40 +000057 sprintf(buf, "%pI6", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010058}
59
Frank Blaschka4a71df52008-02-15 09:19:42 +010060void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
61 char *buf)
62{
63 if (proto == QETH_PROT_IPV4)
64 qeth_l3_ipaddr4_to_string(addr, buf);
65 else if (proto == QETH_PROT_IPV6)
66 qeth_l3_ipaddr6_to_string(addr, buf);
67}
68
Julian Wiedmann1617dae2018-03-09 18:13:02 +010069static struct qeth_ipaddr *qeth_l3_get_addr_buffer(enum qeth_prot_versions prot)
Julian Wiedmannd66b1c02018-03-09 18:13:00 +010070{
71 struct qeth_ipaddr *addr = kmalloc(sizeof(*addr), GFP_ATOMIC);
72
73 if (addr)
74 qeth_l3_init_ipaddr(addr, QETH_IP_TYPE_NORMAL, prot);
75 return addr;
76}
77
Julian Wiedmannc5c48c52018-02-27 18:58:16 +010078static struct qeth_ipaddr *qeth_l3_find_addr_by_ip(struct qeth_card *card,
79 struct qeth_ipaddr *query)
80{
81 u64 key = qeth_l3_ipaddr_hash(query);
82 struct qeth_ipaddr *addr;
83
84 if (query->is_multicast) {
85 hash_for_each_possible(card->ip_mc_htable, addr, hnode, key)
86 if (qeth_l3_addr_match_ip(addr, query))
87 return addr;
88 } else {
89 hash_for_each_possible(card->ip_htable, addr, hnode, key)
90 if (qeth_l3_addr_match_ip(addr, query))
91 return addr;
92 }
93 return NULL;
94}
95
Frank Blaschka4a71df52008-02-15 09:19:42 +010096static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
97{
98 int i, j;
99 u8 octet;
100
101 for (i = 0; i < len; ++i) {
102 octet = addr[i];
103 for (j = 7; j >= 0; --j) {
104 bits[i*8 + j] = octet & 1;
105 octet >>= 1;
106 }
107 }
108}
109
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100110static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
111 struct qeth_ipaddr *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100112{
113 struct qeth_ipato_entry *ipatoe;
114 u8 addr_bits[128] = {0, };
115 u8 ipatoe_bits[128] = {0, };
116 int rc = 0;
117
118 if (!card->ipato.enabled)
Gustavo A. R. Silva1a363b02018-08-09 14:48:04 +0200119 return false;
Julian Wiedmannb22d73d62017-12-13 18:56:30 +0100120 if (addr->type != QETH_IP_TYPE_NORMAL)
Gustavo A. R. Silva1a363b02018-08-09 14:48:04 +0200121 return false;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100122
123 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
124 (addr->proto == QETH_PROT_IPV4)? 4:16);
125 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
126 if (addr->proto != ipatoe->proto)
127 continue;
128 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
129 (ipatoe->proto == QETH_PROT_IPV4) ?
130 4 : 16);
131 if (addr->proto == QETH_PROT_IPV4)
132 rc = !memcmp(addr_bits, ipatoe_bits,
133 min(32, ipatoe->mask_bits));
134 else
135 rc = !memcmp(addr_bits, ipatoe_bits,
136 min(128, ipatoe->mask_bits));
137 if (rc)
138 break;
139 }
140 /* invert? */
141 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
142 rc = !rc;
143 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
144 rc = !rc;
145
146 return rc;
147}
148
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100149static int qeth_l3_delete_ip(struct qeth_card *card,
150 struct qeth_ipaddr *tmp_addr)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200151{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100152 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200153 struct qeth_ipaddr *addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100154
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100155 if (tmp_addr->type == QETH_IP_TYPE_RXIP)
156 QETH_CARD_TEXT(card, 2, "delrxip");
157 else if (tmp_addr->type == QETH_IP_TYPE_VIPA)
158 QETH_CARD_TEXT(card, 2, "delvipa");
159 else
160 QETH_CARD_TEXT(card, 2, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100161
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200162 if (tmp_addr->proto == QETH_PROT_IPV4)
163 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100164 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200165 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
166 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100167 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200168
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100169 addr = qeth_l3_find_addr_by_ip(card, tmp_addr);
170 if (!addr || !qeth_l3_addr_match_all(addr, tmp_addr))
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200171 return -ENOENT;
172
173 addr->ref_counter--;
Julian Wiedmann4964c662018-02-27 18:58:15 +0100174 if (addr->type == QETH_IP_TYPE_NORMAL && addr->ref_counter > 0)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200175 return rc;
176 if (addr->in_progress)
177 return -EINPROGRESS;
178
Julian Wiedmann98d823a2018-02-27 18:58:13 +0100179 if (qeth_card_hw_is_reachable(card))
180 rc = qeth_l3_deregister_addr_entry(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200181
182 hash_del(&addr->hnode);
183 kfree(addr);
184
Frank Blaschka4a71df52008-02-15 09:19:42 +0100185 return rc;
186}
187
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100188static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100189{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100190 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200191 struct qeth_ipaddr *addr;
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100192 char buf[40];
Frank Blaschka4a71df52008-02-15 09:19:42 +0100193
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100194 if (tmp_addr->type == QETH_IP_TYPE_RXIP)
195 QETH_CARD_TEXT(card, 2, "addrxip");
196 else if (tmp_addr->type == QETH_IP_TYPE_VIPA)
197 QETH_CARD_TEXT(card, 2, "addvipa");
198 else
199 QETH_CARD_TEXT(card, 2, "addip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200200
201 if (tmp_addr->proto == QETH_PROT_IPV4)
202 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100203 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200204 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
205 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100206 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200207
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100208 addr = qeth_l3_find_addr_by_ip(card, tmp_addr);
209 if (addr) {
210 if (tmp_addr->type != QETH_IP_TYPE_NORMAL)
211 return -EADDRINUSE;
212 if (qeth_l3_addr_match_all(addr, tmp_addr)) {
213 addr->ref_counter++;
214 return 0;
215 }
216 qeth_l3_ipaddr_to_string(tmp_addr->proto, (u8 *)&tmp_addr->u,
217 buf);
218 dev_warn(&card->gdev->dev,
219 "Registering IP address %s failed\n", buf);
220 return -EADDRINUSE;
221 } else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200222 addr = qeth_l3_get_addr_buffer(tmp_addr->proto);
223 if (!addr)
224 return -ENOMEM;
225
226 memcpy(addr, tmp_addr, sizeof(struct qeth_ipaddr));
227 addr->ref_counter = 1;
228
Julian Wiedmannb22d73d62017-12-13 18:56:30 +0100229 if (qeth_l3_is_addr_covered_by_ipato(card, addr)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200230 QETH_CARD_TEXT(card, 2, "tkovaddr");
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100231 addr->ipato = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200232 }
233 hash_add(card->ip_htable, &addr->hnode,
234 qeth_l3_ipaddr_hash(addr));
235
Ursula Brauna7531c12016-09-15 14:39:23 +0200236 if (!qeth_card_hw_is_reachable(card)) {
237 addr->disp_flag = QETH_DISP_ADDR_ADD;
238 return 0;
239 }
240
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200241 /* qeth_l3_register_addr_entry can go to sleep
242 * if we add a IPV4 addr. It is caused by the reason
243 * that SETIP ipa cmd starts ARP staff for IPV4 addr.
244 * Thus we should unlock spinlock, and make a protection
245 * using in_progress variable to indicate that there is
246 * an hardware operation with this IPV4 address
247 */
248 if (addr->proto == QETH_PROT_IPV4) {
249 addr->in_progress = 1;
250 spin_unlock_bh(&card->ip_lock);
251 rc = qeth_l3_register_addr_entry(card, addr);
252 spin_lock_bh(&card->ip_lock);
253 addr->in_progress = 0;
254 } else
255 rc = qeth_l3_register_addr_entry(card, addr);
256
257 if (!rc || (rc == IPA_RC_DUPLICATE_IP_ADDRESS) ||
258 (rc == IPA_RC_LAN_OFFLINE)) {
259 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
260 if (addr->ref_counter < 1) {
Julian Wiedmann14d066c2018-02-27 18:58:14 +0100261 qeth_l3_deregister_addr_entry(card, addr);
262 hash_del(&addr->hnode);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200263 kfree(addr);
264 }
265 } else {
266 hash_del(&addr->hnode);
267 kfree(addr);
268 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200269 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100270 return rc;
271}
272
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200273static void qeth_l3_clear_ip_htable(struct qeth_card *card, int recover)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100274{
275 struct qeth_ipaddr *addr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200276 struct hlist_node *tmp;
277 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100278
Carsten Otte847a50f2010-06-21 22:57:05 +0000279 QETH_CARD_TEXT(card, 4, "clearip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200280
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200281 spin_lock_bh(&card->ip_lock);
282
283 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
284 if (!recover) {
285 hash_del(&addr->hnode);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100286 kfree(addr);
287 continue;
288 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200289 addr->disp_flag = QETH_DISP_ADDR_ADD;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100290 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200291
292 spin_unlock_bh(&card->ip_lock);
293
294 spin_lock_bh(&card->mclock);
295
296 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
297 hash_del(&addr->hnode);
298 kfree(addr);
299 }
300
301 spin_unlock_bh(&card->mclock);
302
303
Frank Blaschka4a71df52008-02-15 09:19:42 +0100304}
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200305static void qeth_l3_recover_ip(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100306{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200307 struct qeth_ipaddr *addr;
308 struct hlist_node *tmp;
309 int i;
310 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100311
Ursula Brauna7531c12016-09-15 14:39:23 +0200312 QETH_CARD_TEXT(card, 4, "recovrip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100313
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200314 spin_lock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100315
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200316 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
Julian Wiedmann98d823a2018-02-27 18:58:13 +0100317 if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200318 if (addr->proto == QETH_PROT_IPV4) {
319 addr->in_progress = 1;
320 spin_unlock_bh(&card->ip_lock);
321 rc = qeth_l3_register_addr_entry(card, addr);
322 spin_lock_bh(&card->ip_lock);
323 addr->in_progress = 0;
324 } else
325 rc = qeth_l3_register_addr_entry(card, addr);
326
327 if (!rc) {
328 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Ursula Brauna7531c12016-09-15 14:39:23 +0200329 if (addr->ref_counter < 1)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200330 qeth_l3_delete_ip(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200331 } else {
332 hash_del(&addr->hnode);
333 kfree(addr);
334 }
335 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100336 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200337
338 spin_unlock_bh(&card->ip_lock);
339
Frank Blaschka4a71df52008-02-15 09:19:42 +0100340}
341
342static int qeth_l3_send_setdelmc(struct qeth_card *card,
343 struct qeth_ipaddr *addr, int ipacmd)
344{
345 int rc;
346 struct qeth_cmd_buffer *iob;
347 struct qeth_ipa_cmd *cmd;
348
Carsten Otte847a50f2010-06-21 22:57:05 +0000349 QETH_CARD_TEXT(card, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100350
351 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100352 if (!iob)
353 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100354 cmd = __ipa_cmd(iob);
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100355 ether_addr_copy(cmd->data.setdelipm.mac, addr->mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100356 if (addr->proto == QETH_PROT_IPV6)
357 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
358 sizeof(struct in6_addr));
359 else
360 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
361
362 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
363
364 return rc;
365}
366
367static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
368{
369 int i, j;
370 for (i = 0; i < 16; i++) {
371 j = (len) - (i * 8);
372 if (j >= 8)
373 netmask[i] = 0xff;
374 else if (j > 0)
375 netmask[i] = (u8)(0xFF00 >> j);
376 else
377 netmask[i] = 0;
378 }
379}
380
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100381static u32 qeth_l3_get_setdelip_flags(struct qeth_ipaddr *addr, bool set)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100382{
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100383 switch (addr->type) {
384 case QETH_IP_TYPE_RXIP:
385 return (set) ? QETH_IPA_SETIP_TAKEOVER_FLAG : 0;
386 case QETH_IP_TYPE_VIPA:
387 return (set) ? QETH_IPA_SETIP_VIPA_FLAG :
388 QETH_IPA_DELIP_VIPA_FLAG;
389 default:
390 return (set && addr->ipato) ? QETH_IPA_SETIP_TAKEOVER_FLAG : 0;
391 }
392}
393
394static int qeth_l3_send_setdelip(struct qeth_card *card,
395 struct qeth_ipaddr *addr,
396 enum qeth_ipa_cmds ipacmd)
397{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100398 struct qeth_cmd_buffer *iob;
399 struct qeth_ipa_cmd *cmd;
400 __u8 netmask[16];
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100401 u32 flags;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100402
Carsten Otte847a50f2010-06-21 22:57:05 +0000403 QETH_CARD_TEXT(card, 4, "setdelip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100404
405 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100406 if (!iob)
407 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100408 cmd = __ipa_cmd(iob);
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100409
410 flags = qeth_l3_get_setdelip_flags(addr, ipacmd == IPA_CMD_SETIP);
411 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
412
Frank Blaschka4a71df52008-02-15 09:19:42 +0100413 if (addr->proto == QETH_PROT_IPV6) {
414 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
415 sizeof(struct in6_addr));
416 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
417 memcpy(cmd->data.setdelip6.mask, netmask,
418 sizeof(struct in6_addr));
419 cmd->data.setdelip6.flags = flags;
420 } else {
421 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
422 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
423 cmd->data.setdelip4.flags = flags;
424 }
425
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100426 return qeth_send_ipa_cmd(card, iob, NULL, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100427}
428
429static int qeth_l3_send_setrouting(struct qeth_card *card,
430 enum qeth_routing_types type, enum qeth_prot_versions prot)
431{
432 int rc;
433 struct qeth_ipa_cmd *cmd;
434 struct qeth_cmd_buffer *iob;
435
Carsten Otte847a50f2010-06-21 22:57:05 +0000436 QETH_CARD_TEXT(card, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100437 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100438 if (!iob)
439 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100440 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100441 cmd->data.setrtg.type = (type);
442 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
443
444 return rc;
445}
446
Stefan Raspl82e2e782013-03-18 20:04:43 +0000447static int qeth_l3_correct_routing_type(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100448 enum qeth_routing_types *type, enum qeth_prot_versions prot)
449{
450 if (card->info.type == QETH_CARD_TYPE_IQD) {
451 switch (*type) {
452 case NO_ROUTER:
453 case PRIMARY_CONNECTOR:
454 case SECONDARY_CONNECTOR:
455 case MULTICAST_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000456 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100457 default:
458 goto out_inval;
459 }
460 } else {
461 switch (*type) {
462 case NO_ROUTER:
463 case PRIMARY_ROUTER:
464 case SECONDARY_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000465 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100466 case MULTICAST_ROUTER:
467 if (qeth_is_ipafunc_supported(card, prot,
468 IPA_OSA_MC_ROUTER))
Stefan Raspl82e2e782013-03-18 20:04:43 +0000469 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100470 default:
471 goto out_inval;
472 }
473 }
474out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100475 *type = NO_ROUTER;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000476 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100477}
478
479int qeth_l3_setrouting_v4(struct qeth_card *card)
480{
481 int rc;
482
Carsten Otte847a50f2010-06-21 22:57:05 +0000483 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100484
Stefan Raspl82e2e782013-03-18 20:04:43 +0000485 rc = qeth_l3_correct_routing_type(card, &card->options.route4.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100486 QETH_PROT_IPV4);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000487 if (rc)
488 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100489
490 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
491 QETH_PROT_IPV4);
492 if (rc) {
493 card->options.route4.type = NO_ROUTER;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100494 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n",
495 rc, CARD_DEVID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100496 }
497 return rc;
498}
499
500int qeth_l3_setrouting_v6(struct qeth_card *card)
501{
502 int rc = 0;
503
Carsten Otte847a50f2010-06-21 22:57:05 +0000504 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100505
506 if (!qeth_is_supported(card, IPA_IPV6))
507 return 0;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000508 rc = qeth_l3_correct_routing_type(card, &card->options.route6.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100509 QETH_PROT_IPV6);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000510 if (rc)
511 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100512
513 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
514 QETH_PROT_IPV6);
515 if (rc) {
516 card->options.route6.type = NO_ROUTER;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100517 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n",
518 rc, CARD_DEVID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100519 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100520 return rc;
521}
522
523/*
524 * IP address takeover related functions
525 */
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100526
527/**
528 * qeth_l3_update_ipato() - Update 'takeover' property, for all NORMAL IPs.
529 *
530 * Caller must hold ip_lock.
531 */
532void qeth_l3_update_ipato(struct qeth_card *card)
533{
534 struct qeth_ipaddr *addr;
535 unsigned int i;
536
537 hash_for_each(card->ip_htable, i, addr, hnode) {
538 if (addr->type != QETH_IP_TYPE_NORMAL)
539 continue;
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100540 addr->ipato = qeth_l3_is_addr_covered_by_ipato(card, addr);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100541 }
542}
543
Frank Blaschka4a71df52008-02-15 09:19:42 +0100544static void qeth_l3_clear_ipato_list(struct qeth_card *card)
545{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100546 struct qeth_ipato_entry *ipatoe, *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100547
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200548 spin_lock_bh(&card->ip_lock);
549
Frank Blaschka4a71df52008-02-15 09:19:42 +0100550 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
551 list_del(&ipatoe->entry);
552 kfree(ipatoe);
553 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200554
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100555 qeth_l3_update_ipato(card);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200556 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100557}
558
559int qeth_l3_add_ipato_entry(struct qeth_card *card,
560 struct qeth_ipato_entry *new)
561{
562 struct qeth_ipato_entry *ipatoe;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100563 int rc = 0;
564
Carsten Otte847a50f2010-06-21 22:57:05 +0000565 QETH_CARD_TEXT(card, 2, "addipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200566
567 spin_lock_bh(&card->ip_lock);
568
Frank Blaschka4a71df52008-02-15 09:19:42 +0100569 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
570 if (ipatoe->proto != new->proto)
571 continue;
572 if (!memcmp(ipatoe->addr, new->addr,
573 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
574 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100575 rc = -EEXIST;
576 break;
577 }
578 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200579
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100580 if (!rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100581 list_add_tail(&new->entry, &card->ipato.entries);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100582 qeth_l3_update_ipato(card);
583 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100584
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200585 spin_unlock_bh(&card->ip_lock);
586
Frank Blaschka4a71df52008-02-15 09:19:42 +0100587 return rc;
588}
589
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100590int qeth_l3_del_ipato_entry(struct qeth_card *card,
591 enum qeth_prot_versions proto, u8 *addr,
592 int mask_bits)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100593{
594 struct qeth_ipato_entry *ipatoe, *tmp;
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100595 int rc = -ENOENT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100596
Carsten Otte847a50f2010-06-21 22:57:05 +0000597 QETH_CARD_TEXT(card, 2, "delipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200598
599 spin_lock_bh(&card->ip_lock);
600
Frank Blaschka4a71df52008-02-15 09:19:42 +0100601 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
602 if (ipatoe->proto != proto)
603 continue;
604 if (!memcmp(ipatoe->addr, addr,
605 (proto == QETH_PROT_IPV4)? 4:16) &&
606 (ipatoe->mask_bits == mask_bits)) {
607 list_del(&ipatoe->entry);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100608 qeth_l3_update_ipato(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100609 kfree(ipatoe);
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100610 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100611 }
612 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200613
614 spin_unlock_bh(&card->ip_lock);
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100615 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100616}
617
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100618int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip,
619 enum qeth_ip_types type,
620 enum qeth_prot_versions proto)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100621{
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100622 struct qeth_ipaddr addr;
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100623 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100624
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100625 qeth_l3_init_ipaddr(&addr, type, proto);
626 if (proto == QETH_PROT_IPV4)
627 memcpy(&addr.u.a4.addr, ip, 4);
628 else
629 memcpy(&addr.u.a6.addr, ip, 16);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200630
631 spin_lock_bh(&card->ip_lock);
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100632 rc = add ? qeth_l3_add_ip(card, &addr) : qeth_l3_delete_ip(card, &addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200633 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100634 return rc;
635}
636
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100637int qeth_l3_modify_hsuid(struct qeth_card *card, bool add)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100638{
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100639 struct qeth_ipaddr addr;
640 int rc, i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100641
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100642 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV6);
643 addr.u.a6.addr.s6_addr[0] = 0xfe;
644 addr.u.a6.addr.s6_addr[1] = 0x80;
645 for (i = 0; i < 8; i++)
646 addr.u.a6.addr.s6_addr[8+i] = card->options.hsuid[i];
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200647
648 spin_lock_bh(&card->ip_lock);
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100649 rc = add ? qeth_l3_add_ip(card, &addr) : qeth_l3_delete_ip(card, &addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200650 spin_unlock_bh(&card->ip_lock);
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100651 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100652}
653
654static int qeth_l3_register_addr_entry(struct qeth_card *card,
655 struct qeth_ipaddr *addr)
656{
657 char buf[50];
658 int rc = 0;
659 int cnt = 3;
660
Julian Wiedmannbd74a7f2018-11-02 19:04:09 +0100661 if (card->options.sniffer)
662 return 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200663
Frank Blaschka4a71df52008-02-15 09:19:42 +0100664 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000665 QETH_CARD_TEXT(card, 2, "setaddr4");
666 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100667 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000668 QETH_CARD_TEXT(card, 2, "setaddr6");
669 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
670 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100671 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000672 QETH_CARD_TEXT(card, 2, "setaddr?");
673 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100674 }
675 do {
676 if (addr->is_multicast)
677 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
678 else
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100679 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100680 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000681 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100682 } while ((--cnt > 0) && rc);
683 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000684 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100685 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100686 dev_warn(&card->gdev->dev,
687 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100688 }
689 return rc;
690}
691
692static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
693 struct qeth_ipaddr *addr)
694{
695 int rc = 0;
696
Julian Wiedmannbd74a7f2018-11-02 19:04:09 +0100697 if (card->options.sniffer)
698 return 0;
699
Frank Blaschka4a71df52008-02-15 09:19:42 +0100700 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000701 QETH_CARD_TEXT(card, 2, "deladdr4");
702 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100703 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000704 QETH_CARD_TEXT(card, 2, "deladdr6");
705 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
706 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100707 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000708 QETH_CARD_TEXT(card, 2, "deladdr?");
709 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100710 }
711 if (addr->is_multicast)
712 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
713 else
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100714 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200715 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000716 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100717
718 return rc;
719}
720
Frank Blaschka4a71df52008-02-15 09:19:42 +0100721static int qeth_l3_setadapter_parms(struct qeth_card *card)
722{
Julian Wiedmann699d3fe2017-08-15 17:02:41 +0200723 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100724
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200725 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100726
Frank Blaschka4a71df52008-02-15 09:19:42 +0100727 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
728 rc = qeth_setadpparms_change_macaddr(card);
729 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100730 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -0800731 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100732 }
733
Frank Blaschka4a71df52008-02-15 09:19:42 +0100734 return rc;
735}
736
Frank Blaschka4a71df52008-02-15 09:19:42 +0100737static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
738{
739 int rc;
740
Carsten Otte847a50f2010-06-21 22:57:05 +0000741 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100742
743 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100744 dev_info(&card->gdev->dev,
745 "ARP processing not supported on %s!\n",
746 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100747 return 0;
748 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200749 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
750 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100751 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100752 dev_warn(&card->gdev->dev,
753 "Starting ARP processing support for %s failed\n",
754 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100755 }
756 return rc;
757}
758
Frank Blaschka4a71df52008-02-15 09:19:42 +0100759static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
760{
761 int rc;
762
Carsten Otte847a50f2010-06-21 22:57:05 +0000763 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100764
Frank Blaschka4a71df52008-02-15 09:19:42 +0100765 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100766 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800767 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100768 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100769 return -EOPNOTSUPP;
770 }
771
Thomas Richter4d7def22015-09-18 16:06:51 +0200772 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100773 IPA_CMD_ASS_START, 0);
774 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100775 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800776 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100777 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100778 return rc;
779}
780
781static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
782{
783 int rc = 0;
784
Carsten Otte847a50f2010-06-21 22:57:05 +0000785 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100786
787 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100788 dev_info(&card->gdev->dev,
789 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100790 return -EOPNOTSUPP;
791 }
792
Thomas Richter4d7def22015-09-18 16:06:51 +0200793 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100794 IPA_CMD_ASS_START, 0);
795 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100796 dev_warn(&card->gdev->dev,
797 "Starting VLAN support for %s failed\n",
798 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100799 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100800 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100801 }
802 return rc;
803}
804
805static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
806{
807 int rc;
808
Carsten Otte847a50f2010-06-21 22:57:05 +0000809 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100810
811 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100812 dev_info(&card->gdev->dev,
813 "Multicast not supported on %s\n",
814 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100815 return -EOPNOTSUPP;
816 }
817
Thomas Richter4d7def22015-09-18 16:06:51 +0200818 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100819 IPA_CMD_ASS_START, 0);
820 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100821 dev_warn(&card->gdev->dev,
822 "Starting multicast support for %s failed\n",
823 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100824 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100825 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100826 card->dev->flags |= IFF_MULTICAST;
827 }
828 return rc;
829}
830
Frank Blaschka4a71df52008-02-15 09:19:42 +0100831static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
832{
833 int rc;
834
Carsten Otte847a50f2010-06-21 22:57:05 +0000835 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100836
Julian Wiedmann23274592017-06-06 14:33:44 +0200837 if (card->info.type == QETH_CARD_TYPE_IQD)
838 goto out;
839
Thomas Richter4d7def22015-09-18 16:06:51 +0200840 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100841 IPA_CMD_ASS_START, 3);
842 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100843 dev_err(&card->gdev->dev,
844 "Activating IPv6 support for %s failed\n",
845 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100846 return rc;
847 }
Kittipon Meesompopa8155b02018-04-26 09:42:21 +0200848 rc = qeth_send_simple_setassparms_v6(card, IPA_IPV6,
849 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100850 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100851 dev_err(&card->gdev->dev,
852 "Activating IPv6 support for %s failed\n",
853 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100854 return rc;
855 }
Kittipon Meesompopa8155b02018-04-26 09:42:21 +0200856 rc = qeth_send_simple_setassparms_v6(card, IPA_PASSTHRU,
857 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100858 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100859 dev_warn(&card->gdev->dev,
860 "Enabling the passthrough mode for %s failed\n",
861 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100862 return rc;
863 }
864out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100865 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100866 return 0;
867}
Frank Blaschka4a71df52008-02-15 09:19:42 +0100868
869static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
870{
Carsten Otte847a50f2010-06-21 22:57:05 +0000871 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100872
873 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100874 dev_info(&card->gdev->dev,
875 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100876 return 0;
877 }
Julian Wiedmannc0622042017-12-20 20:10:58 +0100878 return qeth_l3_softsetup_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100879}
880
881static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
882{
883 int rc;
884
Carsten Otte847a50f2010-06-21 22:57:05 +0000885 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100886 card->info.broadcast_capable = 0;
887 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100888 dev_info(&card->gdev->dev,
889 "Broadcast not supported on %s\n",
890 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100891 rc = -EOPNOTSUPP;
892 goto out;
893 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200894 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100895 IPA_CMD_ASS_START, 0);
896 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100897 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
898 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100899 goto out;
900 }
901
Thomas Richter4d7def22015-09-18 16:06:51 +0200902 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100903 IPA_CMD_ASS_CONFIGURE, 1);
904 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100905 dev_warn(&card->gdev->dev,
906 "Setting up broadcast filtering for %s failed\n",
907 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100908 goto out;
909 }
910 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100911 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Thomas Richter4d7def22015-09-18 16:06:51 +0200912 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100913 IPA_CMD_ASS_ENABLE, 1);
914 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100915 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
916 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100917 goto out;
918 }
919 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
920out:
921 if (card->info.broadcast_capable)
922 card->dev->flags |= IFF_BROADCAST;
923 else
924 card->dev->flags &= ~IFF_BROADCAST;
925 return rc;
926}
927
Frank Blaschka4a71df52008-02-15 09:19:42 +0100928static int qeth_l3_start_ipassists(struct qeth_card *card)
929{
Carsten Otte847a50f2010-06-21 22:57:05 +0000930 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +0000931
Stefan Raspl0f547612013-01-21 02:30:20 +0000932 if (qeth_set_access_ctrl_online(card, 0))
933 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100934 qeth_l3_start_ipa_arp_processing(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +0100935 qeth_l3_start_ipa_source_mac(card); /* go on*/
936 qeth_l3_start_ipa_vlan(card); /* go on*/
937 qeth_l3_start_ipa_multicast(card); /* go on*/
938 qeth_l3_start_ipa_ipv6(card); /* go on*/
939 qeth_l3_start_ipa_broadcast(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +0100940 return 0;
941}
942
Frank Blaschka4a71df52008-02-15 09:19:42 +0100943static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
944 struct qeth_reply *reply, unsigned long data)
945{
946 struct qeth_ipa_cmd *cmd;
947
948 cmd = (struct qeth_ipa_cmd *) data;
949 if (cmd->hdr.return_code == 0)
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100950 ether_addr_copy(card->dev->dev_addr,
951 cmd->data.create_destroy_addr.unique_id);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100952 return 0;
953}
954
955static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
956{
957 int rc = 0;
958 struct qeth_cmd_buffer *iob;
959 struct qeth_ipa_cmd *cmd;
960
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200961 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100962
963 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
964 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100965 if (!iob)
966 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100967 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100968 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
969 card->info.unique_id;
970
971 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
972 NULL);
973 return rc;
974}
975
976static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
977 struct qeth_reply *reply, unsigned long data)
978{
979 struct qeth_ipa_cmd *cmd;
980
981 cmd = (struct qeth_ipa_cmd *) data;
982 if (cmd->hdr.return_code == 0)
983 card->info.unique_id = *((__u16 *)
984 &cmd->data.create_destroy_addr.unique_id[6]);
985 else {
986 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
987 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100988 dev_warn(&card->gdev->dev, "The network adapter failed to "
989 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100990 }
991 return 0;
992}
993
994static int qeth_l3_get_unique_id(struct qeth_card *card)
995{
996 int rc = 0;
997 struct qeth_cmd_buffer *iob;
998 struct qeth_ipa_cmd *cmd;
999
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001000 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001001
1002 if (!qeth_is_supported(card, IPA_IPV6)) {
1003 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1004 UNIQUE_ID_NOT_BY_CARD;
1005 return 0;
1006 }
1007
1008 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1009 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001010 if (!iob)
1011 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001012 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001013 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1014 card->info.unique_id;
1015
1016 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1017 return rc;
1018}
1019
Ursula Braun76b11f82010-01-11 02:50:50 +00001020static int
1021qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1022 unsigned long data)
1023{
1024 struct qeth_ipa_cmd *cmd;
1025 __u16 rc;
1026
1027 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1028
1029 cmd = (struct qeth_ipa_cmd *)data;
1030 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001031 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001032 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001033 switch (cmd->data.diagass.action) {
1034 case QETH_DIAGS_CMD_TRACE_QUERY:
1035 break;
1036 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001037 switch (rc) {
1038 case 0:
1039 case IPA_RC_INVALID_SUBCMD:
1040 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1041 dev_info(&card->gdev->dev, "The HiperSockets network "
1042 "traffic analyzer is deactivated\n");
1043 break;
1044 default:
1045 break;
1046 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001047 break;
1048 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001049 switch (rc) {
1050 case 0:
1051 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1052 dev_info(&card->gdev->dev, "The HiperSockets network "
1053 "traffic analyzer is activated\n");
1054 break;
1055 case IPA_RC_HARDWARE_AUTH_ERROR:
1056 dev_warn(&card->gdev->dev, "The device is not "
1057 "authorized to run as a HiperSockets network "
1058 "traffic analyzer\n");
1059 break;
1060 case IPA_RC_TRACE_ALREADY_ACTIVE:
1061 dev_warn(&card->gdev->dev, "A HiperSockets "
1062 "network traffic analyzer is already "
1063 "active in the HiperSockets LAN\n");
1064 break;
1065 default:
1066 break;
1067 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001068 break;
1069 default:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001070 QETH_DBF_MESSAGE(2, "Unknown sniffer action (%#06x) on device %x\n",
1071 cmd->data.diagass.action, CARD_DEVID(card));
Ursula Braun76b11f82010-01-11 02:50:50 +00001072 }
1073
1074 return 0;
1075}
1076
1077static int
1078qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1079{
1080 struct qeth_cmd_buffer *iob;
1081 struct qeth_ipa_cmd *cmd;
1082
1083 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1084
1085 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001086 if (!iob)
1087 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001088 cmd = __ipa_cmd(iob);
Ursula Braun76b11f82010-01-11 02:50:50 +00001089 cmd->data.diagass.subcmd_len = 16;
1090 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1091 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1092 cmd->data.diagass.action = diags_cmd;
1093 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1094}
1095
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001096static void
1097qeth_l3_add_mc_to_hash(struct qeth_card *card, struct in_device *in4_dev)
1098{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001099 struct ip_mc_list *im4;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001100 struct qeth_ipaddr *tmp, *ipm;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001101
Carsten Otte847a50f2010-06-21 22:57:05 +00001102 QETH_CARD_TEXT(card, 4, "addmc");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001103
1104 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001105 if (!tmp)
1106 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001107
Sachin Santf3aa3132010-11-26 02:41:17 +00001108 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1109 im4 = rcu_dereference(im4->next_rcu)) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001110 ip_eth_mc_map(im4->multiaddr, tmp->mac);
Hans Wippel6bee4e22017-04-07 09:15:36 +02001111 tmp->u.a4.addr = be32_to_cpu(im4->multiaddr);
Julian Wiedmannbc3ab7052017-12-01 10:14:49 +01001112 tmp->is_multicast = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001113
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001114 ipm = qeth_l3_find_addr_by_ip(card, tmp);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001115 if (ipm) {
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001116 /* for mcast, by-IP match means full match */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001117 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1118 } else {
1119 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1120 if (!ipm)
1121 continue;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001122 ether_addr_copy(ipm->mac, tmp->mac);
Hans Wippel6bee4e22017-04-07 09:15:36 +02001123 ipm->u.a4.addr = be32_to_cpu(im4->multiaddr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001124 ipm->is_multicast = 1;
1125 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1126 hash_add(card->ip_mc_htable,
1127 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1128 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001129 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001130
1131 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001132}
1133
Jiri Pirko0347af52013-01-03 22:48:58 +00001134/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001135static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1136{
1137 struct in_device *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001138 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001139
Carsten Otte847a50f2010-06-21 22:57:05 +00001140 QETH_CARD_TEXT(card, 4, "addmcvl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001141
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001142 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001143 return;
1144
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001145 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1146 struct net_device *netdev;
1147
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001148 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001149 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001150 if (netdev == NULL ||
1151 !(netdev->flags & IFF_UP))
1152 continue;
Jiri Pirko0347af52013-01-03 22:48:58 +00001153 in_dev = __in_dev_get_rcu(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001154 if (!in_dev)
1155 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001156 qeth_l3_add_mc_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001157 }
1158}
1159
1160static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1161{
1162 struct in_device *in4_dev;
1163
Carsten Otte847a50f2010-06-21 22:57:05 +00001164 QETH_CARD_TEXT(card, 4, "chkmcv4");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001165
Sachin Santf3aa3132010-11-26 02:41:17 +00001166 rcu_read_lock();
Jiri Pirko0347af52013-01-03 22:48:58 +00001167 in4_dev = __in_dev_get_rcu(card->dev);
1168 if (in4_dev == NULL)
1169 goto unlock;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001170 qeth_l3_add_mc_to_hash(card, in4_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001171 qeth_l3_add_vlan_mc(card);
Jiri Pirko0347af52013-01-03 22:48:58 +00001172unlock:
Sachin Santf3aa3132010-11-26 02:41:17 +00001173 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001174}
1175
Julian Wiedmannc0622042017-12-20 20:10:58 +01001176static void qeth_l3_add_mc6_to_hash(struct qeth_card *card,
1177 struct inet6_dev *in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001178{
1179 struct qeth_ipaddr *ipm;
1180 struct ifmcaddr6 *im6;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001181 struct qeth_ipaddr *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001182
Carsten Otte847a50f2010-06-21 22:57:05 +00001183 QETH_CARD_TEXT(card, 4, "addmc6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001184
1185 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001186 if (!tmp)
1187 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001188
Frank Blaschka4a71df52008-02-15 09:19:42 +01001189 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001190 ipv6_eth_mc_map(&im6->mca_addr, tmp->mac);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001191 memcpy(&tmp->u.a6.addr, &im6->mca_addr.s6_addr,
1192 sizeof(struct in6_addr));
1193 tmp->is_multicast = 1;
1194
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001195 ipm = qeth_l3_find_addr_by_ip(card, tmp);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001196 if (ipm) {
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001197 /* for mcast, by-IP match means full match */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001198 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1199 continue;
1200 }
1201
Frank Blaschka4a71df52008-02-15 09:19:42 +01001202 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1203 if (!ipm)
1204 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001205
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001206 ether_addr_copy(ipm->mac, tmp->mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001207 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1208 sizeof(struct in6_addr));
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001209 ipm->is_multicast = 1;
1210 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1211 hash_add(card->ip_mc_htable,
1212 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1213
Frank Blaschka4a71df52008-02-15 09:19:42 +01001214 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001215 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001216}
1217
Jiri Pirko0347af52013-01-03 22:48:58 +00001218/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001219static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1220{
1221 struct inet6_dev *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001222 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001223
Carsten Otte847a50f2010-06-21 22:57:05 +00001224 QETH_CARD_TEXT(card, 4, "admc6vl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001225
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001226 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001227 return;
1228
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001229 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1230 struct net_device *netdev;
1231
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001232 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001233 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001234 if (netdev == NULL ||
1235 !(netdev->flags & IFF_UP))
1236 continue;
1237 in_dev = in6_dev_get(netdev);
1238 if (!in_dev)
1239 continue;
1240 read_lock_bh(&in_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001241 qeth_l3_add_mc6_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001242 read_unlock_bh(&in_dev->lock);
1243 in6_dev_put(in_dev);
1244 }
1245}
1246
1247static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1248{
1249 struct inet6_dev *in6_dev;
1250
Carsten Otte847a50f2010-06-21 22:57:05 +00001251 QETH_CARD_TEXT(card, 4, "chkmcv6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001252
Frank Blaschka4a71df52008-02-15 09:19:42 +01001253 if (!qeth_is_supported(card, IPA_IPV6))
1254 return ;
1255 in6_dev = in6_dev_get(card->dev);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001256 if (!in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001257 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001258
Jiri Pirko0347af52013-01-03 22:48:58 +00001259 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001260 read_lock_bh(&in6_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001261 qeth_l3_add_mc6_to_hash(card, in6_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001262 qeth_l3_add_vlan_mc6(card);
1263 read_unlock_bh(&in6_dev->lock);
Jiri Pirko0347af52013-01-03 22:48:58 +00001264 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001265 in6_dev_put(in6_dev);
1266}
Frank Blaschka4a71df52008-02-15 09:19:42 +01001267
Patrick McHardy80d5c362013-04-19 02:04:28 +00001268static int qeth_l3_vlan_rx_add_vid(struct net_device *dev,
1269 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001270{
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001271 struct qeth_card *card = dev->ml_priv;
1272
1273 set_bit(vid, card->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001274 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001275}
1276
Patrick McHardy80d5c362013-04-19 02:04:28 +00001277static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev,
1278 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001279{
Heiko Carstens509e2562008-07-26 02:24:10 -07001280 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001281
Carsten Otte847a50f2010-06-21 22:57:05 +00001282 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001283
Ursula Braun8e98ac42009-03-24 20:57:18 +00001284 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001285 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -05001286 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +00001287 }
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001288 clear_bit(vid, card->active_vlans);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001289 qeth_l3_set_rx_mode(dev);
Jiri Pirko8e586132011-12-08 19:52:37 -05001290 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001291}
1292
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001293static void qeth_l3_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
1294 struct qeth_hdr *hdr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001295{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001296 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001297 u16 prot = (hdr->hdr.l3.flags & QETH_HDR_IPV6) ? ETH_P_IPV6 :
1298 ETH_P_IP;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001299 unsigned char tg_addr[ETH_ALEN];
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001300
1301 skb_reset_network_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001302 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1303 case QETH_CAST_MULTICAST:
Julian Wiedmannc0622042017-12-20 20:10:58 +01001304 if (prot == ETH_P_IP)
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001305 ip_eth_mc_map(ip_hdr(skb)->daddr, tg_addr);
Julian Wiedmannc0622042017-12-20 20:10:58 +01001306 else
1307 ipv6_eth_mc_map(&ipv6_hdr(skb)->daddr, tg_addr);
1308
Frank Blaschka4a71df52008-02-15 09:19:42 +01001309 card->stats.multicast++;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001310 break;
1311 case QETH_CAST_BROADCAST:
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001312 ether_addr_copy(tg_addr, card->dev->broadcast);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001313 card->stats.multicast++;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001314 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001315 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00001316 if (card->options.sniffer)
1317 skb->pkt_type = PACKET_OTHERHOST;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001318 ether_addr_copy(tg_addr, card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001319 }
Julian Wiedmann04f67392018-03-09 18:12:58 +01001320
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001321 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1322 card->dev->header_ops->create(skb, card->dev, prot,
Julian Wiedmanna8433832017-12-20 20:11:06 +01001323 tg_addr, &hdr->hdr.l3.next_hop.rx.src_mac,
Julian Wiedmannf0ea8bf2018-03-09 18:12:56 +01001324 skb->len);
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001325 else
1326 card->dev->header_ops->create(skb, card->dev, prot,
Julian Wiedmannf0ea8bf2018-03-09 18:12:56 +01001327 tg_addr, "FAKELL", skb->len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001328 }
1329
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001330 skb->protocol = eth_type_trans(skb, card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001331
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001332 /* copy VLAN tag from hdr into skb */
1333 if (!card->options.sniffer &&
1334 (hdr->hdr.l3.ext_flags & (QETH_HDR_EXT_VLAN_FRAME |
1335 QETH_HDR_EXT_INCLUDE_VLAN_TAG))) {
1336 u16 tag = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
1337 hdr->hdr.l3.vlan_id :
Julian Wiedmanna8433832017-12-20 20:11:06 +01001338 hdr->hdr.l3.next_hop.rx.vlan_id;
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001339 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001340 }
1341
Julian Wiedmann6195b932018-04-26 09:42:17 +02001342 qeth_rx_csum(card, skb, hdr->hdr.l3.ext_flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001343}
1344
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001345static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1346 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001347{
Julian Wiedmanncd11d112018-09-26 18:29:06 +02001348 struct net_device *dev = card->dev;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001349 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001350 struct sk_buff *skb;
1351 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001352 unsigned int len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001353 __u16 magic;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001354
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001355 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +00001356 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001357 while (budget) {
1358 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +00001359 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001360 &card->rx.b_element, &card->rx.e_offset, &hdr);
1361 if (!skb) {
1362 *done = 1;
1363 break;
1364 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001365 switch (hdr->hdr.l3.id) {
1366 case QETH_HEADER_TYPE_LAYER3:
Frank Blaschkab3332932011-08-08 01:33:59 +00001367 magic = *(__u16 *)skb->data;
1368 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
1369 (magic == ETH_P_AF_IUCV)) {
Frank Blaschkab3332932011-08-08 01:33:59 +00001370 len = skb->len;
Julian Wiedmanncd11d112018-09-26 18:29:06 +02001371 dev_hard_header(skb, dev, ETH_P_AF_IUCV,
1372 dev->dev_addr, "FAKELL", len);
1373 skb->protocol = eth_type_trans(skb, dev);
Frank Blaschkab3332932011-08-08 01:33:59 +00001374 netif_receive_skb(skb);
1375 } else {
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001376 qeth_l3_rebuild_skb(card, skb, hdr);
Frank Blaschkab3332932011-08-08 01:33:59 +00001377 len = skb->len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001378 napi_gro_receive(&card->napi, skb);
1379 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001380 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00001381 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
Ursula Braun76b11f82010-01-11 02:50:50 +00001382 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00001383 len = skb->len;
1384 netif_receive_skb(skb);
1385 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001386 default:
1387 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00001388 QETH_CARD_TEXT(card, 3, "inbunkno");
Julian Wiedmann0ac14872018-09-12 15:31:35 +02001389 QETH_DBF_HEX(CTRL, 3, hdr, sizeof(*hdr));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001390 continue;
1391 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001392 work_done++;
1393 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001394 card->stats.rx_packets++;
1395 card->stats.rx_bytes += len;
1396 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001397 return work_done;
1398}
1399
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +02001400static void qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001401{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001402 QETH_DBF_TEXT(SETUP, 2, "stopcard");
1403 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001404
1405 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00001406 if (card->options.sniffer &&
1407 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
1408 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001409 if (card->read.state == CH_STATE_UP &&
1410 card->write.state == CH_STATE_UP &&
1411 (card->state == CARD_STATE_UP)) {
1412 if (recovery_mode)
1413 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02001414 else {
Ursula Braun869da902010-03-08 20:36:56 +00001415 rtnl_lock();
1416 dev_close(card->dev);
1417 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02001418 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001419 card->state = CARD_STATE_SOFTSETUP;
1420 }
1421 if (card->state == CARD_STATE_SOFTSETUP) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001422 qeth_l3_clear_ip_htable(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001423 qeth_clear_ipacmd_list(card);
1424 card->state = CARD_STATE_HARDSETUP;
1425 }
1426 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001427 qeth_qdio_clear_card(card, 0);
1428 qeth_clear_qdio_buffers(card);
1429 qeth_clear_working_pool_list(card);
1430 card->state = CARD_STATE_DOWN;
1431 }
1432 if (card->state == CARD_STATE_DOWN) {
1433 qeth_clear_cmd_buffers(&card->read);
1434 qeth_clear_cmd_buffers(&card->write);
1435 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001436}
1437
Ursula Braun76b11f82010-01-11 02:50:50 +00001438/*
1439 * test for and Switch promiscuous mode (on or off)
1440 * either for guestlan or HiperSocket Sniffer
1441 */
1442static void
1443qeth_l3_handle_promisc_mode(struct qeth_card *card)
1444{
1445 struct net_device *dev = card->dev;
1446
1447 if (((dev->flags & IFF_PROMISC) &&
1448 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
1449 (!(dev->flags & IFF_PROMISC) &&
1450 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
1451 return;
1452
1453 if (card->info.guestlan) { /* Guestlan trace */
1454 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
1455 qeth_setadp_promisc_mode(card);
1456 } else if (card->options.sniffer && /* HiperSockets trace */
1457 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
1458 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001459 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001460 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
1461 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00001462 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001463 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
1464 }
1465 }
1466}
1467
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001468static void qeth_l3_set_rx_mode(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001469{
Heiko Carstens509e2562008-07-26 02:24:10 -07001470 struct qeth_card *card = dev->ml_priv;
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001471 struct qeth_ipaddr *addr;
1472 struct hlist_node *tmp;
1473 int i, rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001474
Carsten Otte847a50f2010-06-21 22:57:05 +00001475 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00001476 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
1477 (card->state != CARD_STATE_UP))
1478 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00001479 if (!card->options.sniffer) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001480 spin_lock_bh(&card->mclock);
1481
Ursula Braun76b11f82010-01-11 02:50:50 +00001482 qeth_l3_add_multicast_ipv4(card);
Ursula Braun76b11f82010-01-11 02:50:50 +00001483 qeth_l3_add_multicast_ipv6(card);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001484
1485 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1486 switch (addr->disp_flag) {
1487 case QETH_DISP_ADDR_DELETE:
1488 rc = qeth_l3_deregister_addr_entry(card, addr);
1489 if (!rc || rc == IPA_RC_MC_ADDR_NOT_FOUND) {
1490 hash_del(&addr->hnode);
1491 kfree(addr);
1492 }
1493 break;
1494 case QETH_DISP_ADDR_ADD:
1495 rc = qeth_l3_register_addr_entry(card, addr);
1496 if (rc && rc != IPA_RC_LAN_OFFLINE) {
1497 hash_del(&addr->hnode);
1498 kfree(addr);
1499 break;
1500 }
1501 addr->ref_counter = 1;
1502 /* fall through */
1503 default:
1504 /* for next call to set_rx_mode(): */
1505 addr->disp_flag = QETH_DISP_ADDR_DELETE;
1506 }
1507 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001508
1509 spin_unlock_bh(&card->mclock);
1510
Ursula Braun76b11f82010-01-11 02:50:50 +00001511 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
1512 return;
1513 }
1514 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001515}
1516
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001517static int qeth_l3_arp_makerc(int rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001518{
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001519 switch (rc) {
1520 case IPA_RC_SUCCESS:
1521 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001522 case QETH_IPA_ARP_RC_NOTSUPP:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001523 case QETH_IPA_ARP_RC_Q_NOTSUPP:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001524 return -EOPNOTSUPP;
1525 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
1526 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001527 case QETH_IPA_ARP_RC_Q_NO_DATA:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001528 return -ENOENT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001529 default:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001530 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001531 }
1532}
1533
1534static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
1535{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001536 int rc;
1537
Carsten Otte847a50f2010-06-21 22:57:05 +00001538 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001539
1540 /*
1541 * currently GuestLAN only supports the ARP assist function
1542 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
1543 * thus we say EOPNOTSUPP for this ARP function
1544 */
1545 if (card->info.guestlan)
1546 return -EOPNOTSUPP;
1547 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001548 return -EOPNOTSUPP;
1549 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001550 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001551 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
1552 no_entries);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001553 if (rc)
1554 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on device %x: %#x\n",
1555 CARD_DEVID(card), rc);
1556 return qeth_l3_arp_makerc(rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001557}
1558
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001559static __u32 get_arp_entry_size(struct qeth_card *card,
1560 struct qeth_arp_query_data *qdata,
1561 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001562{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001563 __u32 rc;
1564 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001565
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001566 is_hsi = qdata->reply_bits == 5;
1567 if (type->ip == QETHARP_IP_ADDR_V4) {
1568 QETH_CARD_TEXT(card, 4, "arpev4");
1569 if (strip_entries) {
1570 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
1571 sizeof(struct qeth_arp_qi_entry7_short);
1572 } else {
1573 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
1574 sizeof(struct qeth_arp_qi_entry7);
1575 }
1576 } else if (type->ip == QETHARP_IP_ADDR_V6) {
1577 QETH_CARD_TEXT(card, 4, "arpev6");
1578 if (strip_entries) {
1579 rc = is_hsi ?
1580 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
1581 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
1582 } else {
1583 rc = is_hsi ?
1584 sizeof(struct qeth_arp_qi_entry5_ipv6) :
1585 sizeof(struct qeth_arp_qi_entry7_ipv6);
1586 }
1587 } else {
1588 QETH_CARD_TEXT(card, 4, "arpinv");
1589 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001590 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001591
1592 return rc;
1593}
1594
1595static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
1596{
1597 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
1598 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001599}
1600
1601static int qeth_l3_arp_query_cb(struct qeth_card *card,
1602 struct qeth_reply *reply, unsigned long data)
1603{
1604 struct qeth_ipa_cmd *cmd;
1605 struct qeth_arp_query_data *qdata;
1606 struct qeth_arp_query_info *qinfo;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001607 int i;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001608 int e;
1609 int entrybytes_done;
1610 int stripped_bytes;
1611 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001612
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001613 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001614
1615 qinfo = (struct qeth_arp_query_info *) reply->param;
1616 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001617 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001618 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001619 QETH_CARD_TEXT(card, 4, "arpcberr");
1620 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001621 return 0;
1622 }
1623 if (cmd->data.setassparms.hdr.return_code) {
1624 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001625 QETH_CARD_TEXT(card, 4, "setaperr");
1626 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001627 return 0;
1628 }
1629 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00001630 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001631
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001632 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
1633 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
1634 entrybytes_done = 0;
1635 for (e = 0; e < qdata->no_entries; ++e) {
1636 char *cur_entry;
1637 __u32 esize;
1638 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001639
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001640 cur_entry = &qdata->data + entrybytes_done;
1641 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
1642 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
1643 QETH_CARD_TEXT(card, 4, "pmis");
1644 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
1645 break;
1646 }
1647 esize = get_arp_entry_size(card, qdata, etype,
1648 do_strip_entries);
1649 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
1650 if (!esize)
1651 break;
1652
1653 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
1654 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
Ursula Braune0a81142012-03-07 02:06:28 +00001655 cmd->hdr.return_code = IPA_RC_ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001656 goto out_error;
1657 }
1658
1659 memcpy(qinfo->udata + qinfo->udata_offset,
1660 &qdata->data + entrybytes_done + stripped_bytes,
1661 esize);
1662 entrybytes_done += esize + stripped_bytes;
1663 qinfo->udata_offset += esize;
1664 ++qinfo->no_entries;
1665 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001666 /* check if all replies received ... */
1667 if (cmd->data.setassparms.hdr.seq_no <
1668 cmd->data.setassparms.hdr.number_of_replies)
1669 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001670 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001671 memcpy(qinfo->udata, &qinfo->no_entries, 4);
1672 /* keep STRIP_ENTRIES flag so the user program can distinguish
1673 * stripped entries from normal ones */
1674 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
1675 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
1676 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001677 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001678 return 0;
1679out_error:
1680 i = 0;
1681 memcpy(qinfo->udata, &i, 4);
1682 return 0;
1683}
1684
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001685static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
1686 enum qeth_prot_versions prot,
1687 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001688{
1689 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001690 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001691 int rc;
1692
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001693 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
1694
Thomas Richterb475e312015-12-11 12:27:54 +01001695 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
1696 IPA_CMD_ASS_ARP_QUERY_INFO,
1697 sizeof(struct qeth_arp_query_data)
1698 - sizeof(char),
1699 prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001700 if (!iob)
1701 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001702 cmd = __ipa_cmd(iob);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001703 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
Julian Wiedmann4fa55fa2018-11-08 15:06:20 +01001704 rc = qeth_send_control_data(card,
1705 QETH_SETASS_BASE_LEN + QETH_ARP_CMD_LEN,
1706 iob, qeth_l3_arp_query_cb, qinfo);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001707 if (rc)
1708 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on device %x: %#x\n",
1709 CARD_DEVID(card), rc);
1710 return qeth_l3_arp_makerc(rc);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001711}
1712
1713static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
1714{
1715 struct qeth_arp_query_info qinfo = {0, };
1716 int rc;
1717
Carsten Otte847a50f2010-06-21 22:57:05 +00001718 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001719
1720 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
1721 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001722 QETH_CARD_TEXT(card, 3, "arpqnsup");
1723 rc = -EOPNOTSUPP;
1724 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001725 }
1726 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001727 if (copy_from_user(&qinfo, udata, 6)) {
1728 rc = -EFAULT;
1729 goto out;
1730 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001731 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001732 if (!qinfo.udata) {
1733 rc = -ENOMEM;
1734 goto out;
1735 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001736 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001737 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001738 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001739 if (copy_to_user(udata, qinfo.udata, 4))
1740 rc = -EFAULT;
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001741 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001742 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001743 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
1744 /* fails in case of GuestLAN QDIO mode */
1745 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6, &qinfo);
1746 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001747 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
1748 QETH_CARD_TEXT(card, 4, "qactf");
1749 rc = -EFAULT;
1750 goto free_and_out;
1751 }
1752 QETH_CARD_TEXT(card, 4, "qacts");
1753
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001754free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001755 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001756out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001757 return rc;
1758}
1759
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001760static int qeth_l3_arp_modify_entry(struct qeth_card *card,
1761 struct qeth_arp_cache_entry *entry,
1762 enum qeth_arp_process_subcmds arp_cmd)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001763{
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001764 struct qeth_arp_cache_entry *cmd_entry;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001765 struct qeth_cmd_buffer *iob;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001766 int rc;
1767
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001768 if (arp_cmd == IPA_CMD_ASS_ARP_ADD_ENTRY)
1769 QETH_CARD_TEXT(card, 3, "arpadd");
1770 else
1771 QETH_CARD_TEXT(card, 3, "arpdel");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001772
1773 /*
1774 * currently GuestLAN only supports the ARP assist function
1775 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
1776 * thus we say EOPNOTSUPP for this ARP function
1777 */
1778 if (card->info.guestlan)
1779 return -EOPNOTSUPP;
1780 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001781 return -EOPNOTSUPP;
1782 }
1783
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001784 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, arp_cmd,
1785 sizeof(*cmd_entry), QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001786 if (!iob)
1787 return -ENOMEM;
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001788
1789 cmd_entry = &__ipa_cmd(iob)->data.setassparms.data.arp_entry;
1790 ether_addr_copy(cmd_entry->macaddr, entry->macaddr);
1791 memcpy(cmd_entry->ipaddr, entry->ipaddr, 4);
1792 rc = qeth_send_ipa_cmd(card, iob, qeth_setassparms_cb, NULL);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001793 if (rc)
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001794 QETH_DBF_MESSAGE(2, "Could not modify (cmd: %#x) ARP entry on device %x: %#x\n",
1795 arp_cmd, CARD_DEVID(card), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001796
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001797 return qeth_l3_arp_makerc(rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001798}
1799
1800static int qeth_l3_arp_flush_cache(struct qeth_card *card)
1801{
1802 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001803
Carsten Otte847a50f2010-06-21 22:57:05 +00001804 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001805
1806 /*
1807 * currently GuestLAN only supports the ARP assist function
1808 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
1809 * thus we say EOPNOTSUPP for this ARP function
1810 */
1811 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
1812 return -EOPNOTSUPP;
1813 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001814 return -EOPNOTSUPP;
1815 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001816 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001817 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
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);
1821 return qeth_l3_arp_makerc(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 Wiedmann1f979122017-12-20 20:11:04 +01001870static int qeth_l3_get_cast_type(struct sk_buff *skb)
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001871{
David S. Miller69cce1d2011-07-17 23:09:49 -07001872 struct neighbour *n = NULL;
1873 struct dst_entry *dst;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001874
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001875 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07001876 dst = skb_dst(skb);
1877 if (dst)
David S. Miller24db1ba2012-07-02 22:02:33 -07001878 n = dst_neigh_lookup_skb(dst, skb);
David S. Miller69cce1d2011-07-17 23:09:49 -07001879 if (n) {
Julian Wiedmann1f979122017-12-20 20:11:04 +01001880 int cast_type = n->type;
1881
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001882 rcu_read_unlock();
David S. Miller24db1ba2012-07-02 22:02:33 -07001883 neigh_release(n);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001884 if ((cast_type == RTN_BROADCAST) ||
1885 (cast_type == RTN_MULTICAST) ||
1886 (cast_type == RTN_ANYCAST))
1887 return cast_type;
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +02001888 return RTN_UNICAST;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001889 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001890 rcu_read_unlock();
1891
Julian Wiedmann1f979122017-12-20 20:11:04 +01001892 /* no neighbour (eg AF_PACKET), fall back to target's IP address ... */
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001893 switch (qeth_get_ip_version(skb)) {
1894 case 4:
Julian Wiedmann1f979122017-12-20 20:11:04 +01001895 return ipv4_is_multicast(ip_hdr(skb)->daddr) ?
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +02001896 RTN_MULTICAST : RTN_UNICAST;
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001897 case 6:
1898 return ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr) ?
1899 RTN_MULTICAST : RTN_UNICAST;
1900 default:
1901 /* ... and MAC address */
1902 if (ether_addr_equal_64bits(eth_hdr(skb)->h_dest,
1903 skb->dev->broadcast))
1904 return RTN_BROADCAST;
1905 if (is_multicast_ether_addr(eth_hdr(skb)->h_dest))
1906 return RTN_MULTICAST;
1907 /* default to unicast */
1908 return RTN_UNICAST;
1909 }
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001910}
1911
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001912static u8 qeth_l3_cast_type_to_flag(int cast_type)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001913{
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001914 if (cast_type == RTN_MULTICAST)
1915 return QETH_CAST_MULTICAST;
1916 if (cast_type == RTN_ANYCAST)
1917 return QETH_CAST_ANYCAST;
1918 if (cast_type == RTN_BROADCAST)
1919 return QETH_CAST_BROADCAST;
1920 return QETH_CAST_UNICAST;
1921}
David S. Miller69cce1d2011-07-17 23:09:49 -07001922
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001923static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
Julian Wiedmannf6c13142017-12-20 20:11:08 +01001924 struct sk_buff *skb, int ipv, int cast_type,
1925 unsigned int data_len)
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001926{
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001927 struct qeth_hdr_layer3 *l3_hdr = &hdr->hdr.l3;
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001928 struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
1929
Julian Wiedmannf6c13142017-12-20 20:11:08 +01001930 hdr->hdr.l3.length = data_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001931
Julian Wiedmanne517b642018-09-17 17:36:02 +02001932 if (skb_is_gso(skb)) {
Julian Wiedmann0aef8392018-10-12 17:27:15 +02001933 hdr->hdr.l3.id = QETH_HEADER_TYPE_L3_TSO;
Julian Wiedmanne517b642018-09-17 17:36:02 +02001934 } else {
1935 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001936
1937 if (skb->protocol == htons(ETH_P_AF_IUCV)) {
1938 l3_hdr->flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
1939 l3_hdr->next_hop.ipv6_addr.s6_addr16[0] = htons(0xfe80);
1940 memcpy(&l3_hdr->next_hop.ipv6_addr.s6_addr32[2],
1941 iucv_trans_hdr(skb)->destUserID, 8);
1942 return;
1943 }
1944
Julian Wiedmanne517b642018-09-17 17:36:02 +02001945 if (skb->ip_summed == CHECKSUM_PARTIAL) {
1946 qeth_tx_csum(skb, &hdr->hdr.l3.ext_flags, ipv);
1947 /* some HW requires combined L3+L4 csum offload: */
1948 if (ipv == 4)
1949 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_HDR_REQ;
1950 if (card->options.performance_stats)
1951 card->perf_stats.tx_csum++;
1952 }
1953 }
1954
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001955 if (ipv == 4 || IS_IQD(card)) {
1956 /* NETIF_F_HW_VLAN_CTAG_TX */
1957 if (skb_vlan_tag_present(skb)) {
1958 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_VLAN_FRAME;
1959 hdr->hdr.l3.vlan_id = skb_vlan_tag_get(skb);
1960 }
1961 } else if (veth->h_vlan_proto == htons(ETH_P_8021Q)) {
1962 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_INCLUDE_VLAN_TAG;
1963 hdr->hdr.l3.vlan_id = ntohs(veth->h_vlan_TCI);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001964 }
1965
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001966 /* OSA only: */
1967 if (!ipv) {
1968 hdr->hdr.l3.flags = QETH_HDR_PASSTHRU;
1969 if (ether_addr_equal_64bits(eth_hdr(skb)->h_dest,
1970 skb->dev->broadcast))
1971 hdr->hdr.l3.flags |= QETH_CAST_BROADCAST;
1972 else
1973 hdr->hdr.l3.flags |= (cast_type == RTN_MULTICAST) ?
1974 QETH_CAST_MULTICAST : QETH_CAST_UNICAST;
1975 return;
1976 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001977
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001978 hdr->hdr.l3.flags = qeth_l3_cast_type_to_flag(cast_type);
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001979 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001980 if (ipv == 4) {
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001981 struct rtable *rt = skb_rtable(skb);
David Miller87e75972012-02-01 10:49:17 +00001982
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001983 *((__be32 *) &hdr->hdr.l3.next_hop.ipv4.addr) = (rt) ?
1984 rt_nexthop(rt, ip_hdr(skb)->daddr) :
1985 ip_hdr(skb)->daddr;
1986 } else {
1987 /* IPv6 */
1988 const struct rt6_info *rt = skb_rt6_info(skb);
David Miller87e75972012-02-01 10:49:17 +00001989
Julian Wiedmannec2c6722017-08-07 13:28:39 +02001990 if (rt && !ipv6_addr_any(&rt->rt6i_gateway))
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001991 l3_hdr->next_hop.ipv6_addr = rt->rt6i_gateway;
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001992 else
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001993 l3_hdr->next_hop.ipv6_addr = ipv6_hdr(skb)->daddr;
David Miller87e75972012-02-01 10:49:17 +00001994
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001995 hdr->hdr.l3.flags |= QETH_HDR_IPV6;
1996 if (card->info.type != QETH_CARD_TYPE_IQD)
1997 hdr->hdr.l3.flags |= QETH_HDR_PASSTHRU;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001998 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001999 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002000}
2001
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02002002static void qeth_l3_fixup_headers(struct sk_buff *skb)
2003{
2004 struct iphdr *iph = ip_hdr(skb);
2005
2006 /* this is safe, IPv6 traffic takes a different path */
2007 if (skb->ip_summed == CHECKSUM_PARTIAL)
2008 iph->check = 0;
Julian Wiedmanne517b642018-09-17 17:36:02 +02002009 if (skb_is_gso(skb)) {
2010 iph->tot_len = 0;
2011 tcp_hdr(skb)->check = ~tcp_v4_check(0, iph->saddr,
2012 iph->daddr, 0);
2013 }
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02002014}
2015
Julian Wiedmann356156b2018-09-17 17:36:03 +02002016static int qeth_l3_xmit(struct qeth_card *card, struct sk_buff *skb,
2017 struct qeth_qdio_out_q *queue, int ipv, int cast_type)
Julian Wiedmanna647a022018-07-11 17:42:46 +02002018{
Julian Wiedmanna647a022018-07-11 17:42:46 +02002019 unsigned char eth_hdr[ETH_HLEN];
Julian Wiedmann81ec5432018-11-08 15:06:17 +01002020 unsigned int hw_hdr_len;
2021 int rc;
Julian Wiedmanne517b642018-09-17 17:36:02 +02002022
Julian Wiedmanna647a022018-07-11 17:42:46 +02002023 /* re-use the L2 header area for the HW header: */
Julian Wiedmann81ec5432018-11-08 15:06:17 +01002024 hw_hdr_len = skb_is_gso(skb) ? sizeof(struct qeth_hdr_tso) :
2025 sizeof(struct qeth_hdr);
Julian Wiedmanna647a022018-07-11 17:42:46 +02002026 rc = skb_cow_head(skb, hw_hdr_len - ETH_HLEN);
2027 if (rc)
2028 return rc;
2029 skb_copy_from_linear_data(skb, eth_hdr, ETH_HLEN);
2030 skb_pull(skb, ETH_HLEN);
Julian Wiedmanna647a022018-07-11 17:42:46 +02002031
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02002032 qeth_l3_fixup_headers(skb);
Julian Wiedmann81ec5432018-11-08 15:06:17 +01002033 rc = qeth_xmit(card, skb, queue, ipv, cast_type, qeth_l3_fill_header);
2034 if (rc == -EBUSY) {
2035 /* roll back to ETH header */
2036 skb_push(skb, ETH_HLEN);
2037 skb_copy_to_linear_data(skb, eth_hdr, ETH_HLEN);
Julian Wiedmanna647a022018-07-11 17:42:46 +02002038 }
2039 return rc;
2040}
2041
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002042static netdev_tx_t qeth_l3_hard_start_xmit(struct sk_buff *skb,
2043 struct net_device *dev)
2044{
2045 int cast_type = qeth_l3_get_cast_type(skb);
2046 struct qeth_card *card = dev->ml_priv;
2047 int ipv = qeth_get_ip_version(skb);
2048 struct qeth_qdio_out_q *queue;
2049 int tx_bytes = skb->len;
2050 int rc;
2051
2052 if (IS_IQD(card)) {
2053 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;
2059 }
2060
Julian Wiedmann91cc98f2018-09-26 18:29:16 +02002061 if (card->state != CARD_STATE_UP) {
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002062 card->stats.tx_carrier_errors++;
2063 goto tx_drop;
2064 }
2065
2066 if (cast_type == RTN_BROADCAST && !card->info.broadcast_capable)
2067 goto tx_drop;
2068
2069 queue = qeth_get_tx_queue(card, skb, ipv, cast_type);
2070
2071 if (card->options.performance_stats) {
2072 card->perf_stats.outbound_cnt++;
2073 card->perf_stats.outbound_start_time = qeth_get_micros();
2074 }
2075 netif_stop_queue(dev);
2076
Julian Wiedmann356156b2018-09-17 17:36:03 +02002077 if (ipv == 4 || IS_IQD(card))
Julian Wiedmanna647a022018-07-11 17:42:46 +02002078 rc = qeth_l3_xmit(card, skb, queue, ipv, cast_type);
Julian Wiedmannf13ade12018-09-17 17:35:56 +02002079 else
2080 rc = qeth_xmit(card, skb, queue, ipv, cast_type,
2081 qeth_l3_fill_header);
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002082
2083 if (!rc) {
2084 card->stats.tx_packets++;
2085 card->stats.tx_bytes += tx_bytes;
2086 if (card->options.performance_stats)
2087 card->perf_stats.outbound_time += qeth_get_micros() -
2088 card->perf_stats.outbound_start_time;
2089 netif_wake_queue(dev);
2090 return NETDEV_TX_OK;
2091 } else if (rc == -EBUSY) {
2092 return NETDEV_TX_BUSY;
2093 } /* else fall through */
Frank Blaschka4a71df52008-02-15 09:19:42 +01002094
2095tx_drop:
2096 card->stats.tx_dropped++;
2097 card->stats.tx_errors++;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002098 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02002099 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002100 return NETDEV_TX_OK;
2101}
2102
Ursula Braun39423442011-01-12 20:42:24 +00002103static int __qeth_l3_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002104{
Heiko Carstens509e2562008-07-26 02:24:10 -07002105 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002106 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002107
Carsten Otte847a50f2010-06-21 22:57:05 +00002108 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +00002109 if (card->state == CARD_STATE_UP)
2110 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002111 if (card->state != CARD_STATE_SOFTSETUP)
2112 return -ENODEV;
2113 card->data.state = CH_STATE_UP;
2114 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002115 netif_start_queue(dev);
2116
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002117 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
2118 napi_enable(&card->napi);
Julian Wiedmann4d19db72018-09-17 17:36:06 +02002119 local_bh_disable();
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002120 napi_schedule(&card->napi);
Julian Wiedmann4d19db72018-09-17 17:36:06 +02002121 /* kick-start the NAPI softirq: */
2122 local_bh_enable();
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002123 } else
2124 rc = -EIO;
2125 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002126}
2127
Ursula Braun39423442011-01-12 20:42:24 +00002128static int qeth_l3_open(struct net_device *dev)
2129{
2130 struct qeth_card *card = dev->ml_priv;
2131
2132 QETH_CARD_TEXT(card, 5, "qethope_");
2133 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
2134 QETH_CARD_TEXT(card, 3, "openREC");
2135 return -ERESTARTSYS;
2136 }
2137 return __qeth_l3_open(dev);
2138}
2139
Frank Blaschka4a71df52008-02-15 09:19:42 +01002140static int qeth_l3_stop(struct net_device *dev)
2141{
Heiko Carstens509e2562008-07-26 02:24:10 -07002142 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002143
Carsten Otte847a50f2010-06-21 22:57:05 +00002144 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002145 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002146 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002147 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002148 napi_disable(&card->napi);
2149 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002150 return 0;
2151}
2152
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07002153static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002154 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002155 .get_strings = qeth_core_get_strings,
2156 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00002157 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002158 .get_drvinfo = qeth_core_get_drvinfo,
Julian Wiedmann993e19c2017-04-11 16:11:17 +02002159 .get_link_ksettings = qeth_core_ethtool_get_link_ksettings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002160};
2161
2162/*
2163 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
2164 * NOARP on the netdevice is no option because it also turns off neighbor
2165 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
2166 * arp resolution but we want the hard header (packet socket will work
2167 * e.g. tcpdump)
2168 */
2169static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
2170{
2171 n->nud_state = NUD_NOARP;
2172 memcpy(n->ha, "FAKELL", 6);
2173 n->output = n->ops->connected_output;
2174 return 0;
2175}
2176
2177static int
2178qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
2179{
2180 if (np->tbl->family == AF_INET)
2181 np->neigh_setup = qeth_l3_neigh_setup_noarp;
2182
2183 return 0;
2184}
2185
Julian Wiedmannf13ade12018-09-17 17:35:56 +02002186static netdev_features_t qeth_l3_osa_features_check(struct sk_buff *skb,
2187 struct net_device *dev,
2188 netdev_features_t features)
2189{
2190 if (qeth_get_ip_version(skb) != 4)
2191 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
2192 return qeth_features_check(skb, dev, features);
2193}
2194
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002195static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08002196 .ndo_open = qeth_l3_open,
2197 .ndo_stop = qeth_l3_stop,
2198 .ndo_get_stats = qeth_get_stats,
2199 .ndo_start_xmit = qeth_l3_hard_start_xmit,
2200 .ndo_validate_addr = eth_validate_addr,
Julian Wiedmann00c163f2017-12-20 20:11:02 +01002201 .ndo_set_rx_mode = qeth_l3_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002202 .ndo_do_ioctl = qeth_do_ioctl,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002203 .ndo_fix_features = qeth_fix_features,
2204 .ndo_set_features = qeth_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08002205 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2206 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002207 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka8403b132009-01-08 10:50:55 -08002208};
2209
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002210static const struct net_device_ops qeth_l3_osa_netdev_ops = {
2211 .ndo_open = qeth_l3_open,
2212 .ndo_stop = qeth_l3_stop,
2213 .ndo_get_stats = qeth_get_stats,
2214 .ndo_start_xmit = qeth_l3_hard_start_xmit,
Julian Wiedmannf13ade12018-09-17 17:35:56 +02002215 .ndo_features_check = qeth_l3_osa_features_check,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002216 .ndo_validate_addr = eth_validate_addr,
Julian Wiedmann00c163f2017-12-20 20:11:02 +01002217 .ndo_set_rx_mode = qeth_l3_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002218 .ndo_do_ioctl = qeth_do_ioctl,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002219 .ndo_fix_features = qeth_fix_features,
2220 .ndo_set_features = qeth_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002221 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2222 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002223 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002224 .ndo_neigh_setup = qeth_l3_neigh_setup,
2225};
2226
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002227static int qeth_l3_setup_netdev(struct qeth_card *card, bool carrier_ok)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002228{
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002229 unsigned int headroom;
Thomas Richter1aec42b2015-01-21 13:39:10 +01002230 int rc;
2231
Julian Wiedmann30356d02018-11-02 19:04:10 +01002232 if (qeth_netdev_is_registered(card->dev))
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002233 return 0;
2234
Ursula Braun5113fec2010-05-16 21:15:14 +00002235 if (card->info.type == QETH_CARD_TYPE_OSD ||
2236 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002237 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
2238 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002239 pr_info("qeth_l3: ignoring TR device\n");
2240 return -ENODEV;
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002241 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002242
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002243 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Julian Wiedmann0f342942018-03-09 18:12:54 +01002244
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002245 /*IPv6 address autoconfiguration stuff*/
2246 qeth_l3_get_unique_id(card);
2247 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
2248 card->dev->dev_id = card->info.unique_id & 0xffff;
Julian Wiedmann0f342942018-03-09 18:12:54 +01002249
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002250 if (!card->info.guestlan) {
2251 card->dev->features |= NETIF_F_SG;
2252 card->dev->hw_features |= NETIF_F_TSO |
2253 NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
2254 card->dev->vlan_features |= NETIF_F_TSO |
2255 NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002256 }
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +02002257
2258 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) {
2259 card->dev->hw_features |= NETIF_F_IPV6_CSUM;
2260 card->dev->vlan_features |= NETIF_F_IPV6_CSUM;
2261 }
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002262 if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) {
2263 card->dev->hw_features |= NETIF_F_TSO6;
2264 card->dev->vlan_features |= NETIF_F_TSO6;
2265 }
2266
2267 /* allow for de-acceleration of NETIF_F_HW_VLAN_CTAG_TX: */
2268 if (card->dev->hw_features & NETIF_F_TSO6)
2269 headroom = sizeof(struct qeth_hdr_tso) + VLAN_HLEN;
2270 else if (card->dev->hw_features & NETIF_F_TSO)
2271 headroom = sizeof(struct qeth_hdr_tso);
2272 else
2273 headroom = sizeof(struct qeth_hdr) + VLAN_HLEN;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002274 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002275 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002276 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002277 headroom = sizeof(struct qeth_hdr) - ETH_HLEN;
Julian Wiedmanna647a022018-07-11 17:42:46 +02002278
Thomas Richter1aec42b2015-01-21 13:39:10 +01002279 rc = qeth_l3_iqd_read_initial_mac(card);
2280 if (rc)
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002281 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002282 } else
2283 return -ENODEV;
2284
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002285 card->dev->needed_headroom = headroom;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002286 card->dev->ethtool_ops = &qeth_l3_ethtool_ops;
Patrick McHardyf6469682013-04-19 02:04:27 +00002287 card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2288 NETIF_F_HW_VLAN_CTAG_RX |
2289 NETIF_F_HW_VLAN_CTAG_FILTER;
Julian Wiedmanna647a022018-07-11 17:42:46 +02002290
Eric Dumazet02875872014-10-05 18:38:35 -07002291 netif_keep_dst(card->dev);
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002292 if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6))
Julian Wiedmann371a1e72018-07-11 17:42:44 +02002293 netif_set_gso_max_size(card->dev,
2294 PAGE_SIZE * (QETH_MAX_BUFFER_ELEMENTS(card) - 1));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002295
Julian Wiedmannd73ef322017-04-11 16:11:11 +02002296 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002297 rc = register_netdev(card->dev);
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002298 if (!rc && carrier_ok)
2299 netif_carrier_on(card->dev);
2300
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002301out:
2302 if (rc)
2303 card->dev->netdev_ops = NULL;
2304 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002305}
2306
Ursula Braun79a04e42017-06-06 14:33:49 +02002307static const struct device_type qeth_l3_devtype = {
2308 .name = "qeth_layer3",
2309 .groups = qeth_l3_attr_groups,
2310};
2311
Frank Blaschka4a71df52008-02-15 09:19:42 +01002312static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
2313{
2314 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +02002315 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002316
Ursula Braun79a04e42017-06-06 14:33:49 +02002317 if (gdev->dev.type == &qeth_generic_devtype) {
2318 rc = qeth_l3_create_device_attributes(&gdev->dev);
2319 if (rc)
2320 return rc;
2321 }
Ursula Braunebccc7392017-05-10 19:07:54 +02002322 hash_init(card->ip_htable);
2323 hash_init(card->ip_mc_htable);
Frank Blaschka1da74b12011-05-12 18:45:02 +00002324 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002325 return 0;
2326}
2327
2328static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
2329{
2330 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
2331
Ursula Braun79a04e42017-06-06 14:33:49 +02002332 if (cgdev->dev.type == &qeth_generic_devtype)
2333 qeth_l3_remove_device_attributes(&cgdev->dev);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002334
Ursula Braunf2148562009-05-19 21:38:37 +00002335 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002336 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
2337
Ursula Braun70919e22011-02-26 22:41:36 -08002338 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002339 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002340
Julian Wiedmannc2780c12019-02-04 17:40:08 +01002341 cancel_work_sync(&card->close_dev_work);
Julian Wiedmann30356d02018-11-02 19:04:10 +01002342 if (qeth_netdev_is_registered(card->dev))
2343 unregister_netdev(card->dev);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002344 qeth_l3_clear_ip_htable(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002345 qeth_l3_clear_ipato_list(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002346}
2347
2348static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
2349{
2350 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
2351 int rc = 0;
2352 enum qeth_card_states recover_flag;
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002353 bool carrier_ok;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002354
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002355 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002356 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002357 QETH_DBF_TEXT(SETUP, 2, "setonlin");
2358 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002359
Frank Blaschka4a71df52008-02-15 09:19:42 +01002360 recover_flag = card->state;
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002361 rc = qeth_core_hardsetup_card(card, &carrier_ok);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002362 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01002363 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00002364 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002365 goto out_remove;
2366 }
2367
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002368 rc = qeth_l3_setup_netdev(card, carrier_ok);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002369 if (rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002370 goto out_remove;
2371
Frank Blaschka1da74b12011-05-12 18:45:02 +00002372 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
2373 if (card->info.hwtrap &&
2374 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
2375 card->info.hwtrap = 0;
2376 } else
2377 card->info.hwtrap = 0;
2378
Frank Blaschka4a71df52008-02-15 09:19:42 +01002379 card->state = CARD_STATE_HARDSETUP;
2380 qeth_print_status_message(card);
2381
2382 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002383 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002384
Frank Blaschka4a71df52008-02-15 09:19:42 +01002385 rc = qeth_l3_setadapter_parms(card);
2386 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01002387 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002388 if (!card->options.sniffer) {
2389 rc = qeth_l3_start_ipassists(card);
Stefan Raspl0f547612013-01-21 02:30:20 +00002390 if (rc) {
Ursula Braun76b11f82010-01-11 02:50:50 +00002391 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Stefan Raspl0f547612013-01-21 02:30:20 +00002392 goto out_remove;
2393 }
Ursula Braun76b11f82010-01-11 02:50:50 +00002394 rc = qeth_l3_setrouting_v4(card);
2395 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01002396 QETH_DBF_TEXT_(SETUP, 2, "4err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002397 rc = qeth_l3_setrouting_v6(card);
2398 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01002399 QETH_DBF_TEXT_(SETUP, 2, "5err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002400 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002401 netif_tx_disable(card->dev);
2402
2403 rc = qeth_init_qdio_queues(card);
2404 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002405 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00002406 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002407 goto out_remove;
2408 }
2409 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002410
2411 qeth_set_allowed_threads(card, 0xffffffff, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002412 qeth_l3_recover_ip(card);
Julian Wiedmannd025da92018-06-29 19:45:54 +02002413
2414 qeth_enable_hw_features(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002415 if (recover_flag == CARD_STATE_RECOVER) {
Ursula Braun4763b0a2011-12-19 22:56:32 +00002416 rtnl_lock();
Julian Wiedmann9aa17df2018-07-11 17:42:40 +02002417 if (recovery_mode) {
Ursula Braun39423442011-01-12 20:42:24 +00002418 __qeth_l3_open(card->dev);
Julian Wiedmann9aa17df2018-07-11 17:42:40 +02002419 qeth_l3_set_rx_mode(card->dev);
2420 } else {
Petr Machata00f54e62018-12-06 17:05:36 +00002421 dev_open(card->dev, NULL);
Julian Wiedmann9aa17df2018-07-11 17:42:40 +02002422 }
Ursula Braun4763b0a2011-12-19 22:56:32 +00002423 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002424 }
Stefan Raspl82f77cf2013-03-18 20:04:42 +00002425 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002426 /* let user_space know that device is online */
2427 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002428 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002429 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002430 return 0;
2431out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002432 qeth_l3_stop_card(card, 0);
2433 ccw_device_set_offline(CARD_DDEV(card));
2434 ccw_device_set_offline(CARD_WDEV(card));
2435 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01002436 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002437 if (recover_flag == CARD_STATE_RECOVER)
2438 card->state = CARD_STATE_RECOVER;
2439 else
2440 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00002441 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002442 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00002443 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002444}
2445
2446static int qeth_l3_set_online(struct ccwgroup_device *gdev)
2447{
2448 return __qeth_l3_set_online(gdev, 0);
2449}
2450
2451static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
2452 int recovery_mode)
2453{
2454 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
2455 int rc = 0, rc2 = 0, rc3 = 0;
2456 enum qeth_card_states recover_flag;
2457
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002458 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002459 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002460 QETH_DBF_TEXT(SETUP, 3, "setoffl");
2461 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002462
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002463 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002464 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00002465 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
2466 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
2467 card->info.hwtrap = 1;
2468 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02002469 qeth_l3_stop_card(card, recovery_mode);
Einar Lueck72861ae2011-12-19 22:56:36 +00002470 if ((card->options.cq == QETH_CQ_ENABLED) && card->dev) {
2471 rtnl_lock();
2472 call_netdevice_notifiers(NETDEV_REBOOT, card->dev);
2473 rtnl_unlock();
2474 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002475 rc = ccw_device_set_offline(CARD_DDEV(card));
2476 rc2 = ccw_device_set_offline(CARD_WDEV(card));
2477 rc3 = ccw_device_set_offline(CARD_RDEV(card));
2478 if (!rc)
2479 rc = (rc2) ? rc2 : rc3;
2480 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002481 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01002482 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002483 if (recover_flag == CARD_STATE_UP)
2484 card->state = CARD_STATE_RECOVER;
2485 /* let user_space know that device is offline */
2486 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002487 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002488 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002489 return 0;
2490}
2491
2492static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
2493{
2494 return __qeth_l3_set_offline(cgdev, 0);
2495}
2496
2497static int qeth_l3_recover(void *ptr)
2498{
2499 struct qeth_card *card;
2500 int rc = 0;
2501
2502 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00002503 QETH_CARD_TEXT(card, 2, "recover1");
2504 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002505 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
2506 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00002507 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002508 dev_warn(&card->gdev->dev,
2509 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00002510 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002511 __qeth_l3_set_offline(card->gdev, 1);
2512 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002513 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002514 dev_info(&card->gdev->dev,
2515 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02002516 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00002517 qeth_close_dev(card);
2518 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00002519 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02002520 }
Stefan Raspl65d80132013-04-07 22:19:27 +00002521 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002522 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
2523 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002524 return 0;
2525}
2526
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002527static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
2528{
2529 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
2530
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002531 netif_device_detach(card->dev);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002532 qeth_set_allowed_threads(card, 0, 1);
2533 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
2534 if (gdev->state == CCWGROUP_OFFLINE)
2535 return 0;
2536 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00002537 if (card->info.hwtrap)
2538 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002539 __qeth_l3_set_offline(card->gdev, 1);
2540 } else
2541 __qeth_l3_set_offline(card->gdev, 0);
2542 return 0;
2543}
2544
2545static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
2546{
2547 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
2548 int rc = 0;
2549
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002550 if (card->state == CARD_STATE_RECOVER) {
2551 rc = __qeth_l3_set_online(card->gdev, 1);
2552 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00002553 rtnl_lock();
2554 dev_close(card->dev);
2555 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002556 }
2557 } else
2558 rc = __qeth_l3_set_online(card->gdev, 0);
Julian Wiedmann6585ac42018-09-26 18:29:12 +02002559
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002560 qeth_set_allowed_threads(card, 0xffffffff, 0);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002561 netif_device_attach(card->dev);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002562 if (rc)
2563 dev_warn(&card->gdev->dev, "The qeth device driver "
2564 "failed to recover an error on the device\n");
2565 return rc;
2566}
2567
Eugene Crosserc044dc22014-01-29 09:23:48 +01002568/* Returns zero if the command is successfully "consumed" */
2569static int qeth_l3_control_event(struct qeth_card *card,
2570 struct qeth_ipa_cmd *cmd)
2571{
2572 return 1;
2573}
2574
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002575struct qeth_discipline qeth_l3_discipline = {
Ursula Braun79a04e42017-06-06 14:33:49 +02002576 .devtype = &qeth_l3_devtype,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02002577 .process_rx_buffer = qeth_l3_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002578 .recover = qeth_l3_recover,
2579 .setup = qeth_l3_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002580 .remove = qeth_l3_remove_device,
2581 .set_online = qeth_l3_set_online,
2582 .set_offline = qeth_l3_set_offline,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002583 .freeze = qeth_l3_pm_suspend,
2584 .thaw = qeth_l3_pm_resume,
2585 .restore = qeth_l3_pm_resume,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002586 .do_ioctl = qeth_l3_do_ioctl,
Eugene Crosserc044dc22014-01-29 09:23:48 +01002587 .control_event_handler = qeth_l3_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002588};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002589EXPORT_SYMBOL_GPL(qeth_l3_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002590
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002591static int qeth_l3_handle_ip_event(struct qeth_card *card,
2592 struct qeth_ipaddr *addr,
2593 unsigned long event)
2594{
2595 switch (event) {
2596 case NETDEV_UP:
2597 spin_lock_bh(&card->ip_lock);
2598 qeth_l3_add_ip(card, addr);
2599 spin_unlock_bh(&card->ip_lock);
2600 return NOTIFY_OK;
2601 case NETDEV_DOWN:
2602 spin_lock_bh(&card->ip_lock);
2603 qeth_l3_delete_ip(card, addr);
2604 spin_unlock_bh(&card->ip_lock);
2605 return NOTIFY_OK;
2606 default:
2607 return NOTIFY_DONE;
2608 }
2609}
2610
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002611static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2612{
2613 if (is_vlan_dev(dev))
2614 dev = vlan_dev_real_dev(dev);
2615 if (dev->netdev_ops == &qeth_l3_osa_netdev_ops ||
2616 dev->netdev_ops == &qeth_l3_netdev_ops)
2617 return (struct qeth_card *) dev->ml_priv;
2618 return NULL;
2619}
2620
Frank Blaschka4a71df52008-02-15 09:19:42 +01002621static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07002622 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002623{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002624
Frank Blaschka4a71df52008-02-15 09:19:42 +01002625 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002626 struct net_device *dev = ifa->ifa_dev->dev;
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002627 struct qeth_ipaddr addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002628 struct qeth_card *card;
2629
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09002630 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07002631 return NOTIFY_DONE;
2632
Frank Blaschka4a71df52008-02-15 09:19:42 +01002633 card = qeth_l3_get_card_from_dev(dev);
2634 if (!card)
2635 return NOTIFY_DONE;
frank.blaschka@de.ibm.com6d8823d2012-05-16 01:28:26 +00002636 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002637
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002638 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV4);
2639 addr.u.a4.addr = be32_to_cpu(ifa->ifa_address);
2640 addr.u.a4.mask = be32_to_cpu(ifa->ifa_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002641
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002642 return qeth_l3_handle_ip_event(card, &addr, event);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002643}
2644
2645static struct notifier_block qeth_l3_ip_notifier = {
2646 qeth_l3_ip_event,
2647 NULL,
2648};
2649
Frank Blaschka4a71df52008-02-15 09:19:42 +01002650static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07002651 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002652{
2653 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002654 struct net_device *dev = ifa->idev->dev;
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002655 struct qeth_ipaddr addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002656 struct qeth_card *card;
2657
Frank Blaschka4a71df52008-02-15 09:19:42 +01002658 card = qeth_l3_get_card_from_dev(dev);
2659 if (!card)
2660 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00002661 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002662 if (!qeth_is_supported(card, IPA_IPV6))
2663 return NOTIFY_DONE;
2664
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002665 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV6);
2666 addr.u.a6.addr = ifa->addr;
2667 addr.u.a6.pfxlen = ifa->prefix_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002668
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002669 return qeth_l3_handle_ip_event(card, &addr, event);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002670}
2671
2672static struct notifier_block qeth_l3_ip6_notifier = {
2673 qeth_l3_ip6_event,
2674 NULL,
2675};
Frank Blaschka4a71df52008-02-15 09:19:42 +01002676
2677static int qeth_l3_register_notifiers(void)
2678{
2679 int rc;
2680
Carsten Otte847a50f2010-06-21 22:57:05 +00002681 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002682 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
2683 if (rc)
2684 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002685 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
2686 if (rc) {
2687 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
2688 return rc;
2689 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002690 return 0;
2691}
2692
2693static void qeth_l3_unregister_notifiers(void)
2694{
Carsten Otte847a50f2010-06-21 22:57:05 +00002695 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Stefan Raspl18af5c12012-11-19 02:46:50 +00002696 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
Stefan Raspl18af5c12012-11-19 02:46:50 +00002697 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002698}
2699
2700static int __init qeth_l3_init(void)
2701{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002702 pr_info("register layer 3 discipline\n");
Julian Wiedmannc0622042017-12-20 20:10:58 +01002703 return qeth_l3_register_notifiers();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002704}
2705
2706static void __exit qeth_l3_exit(void)
2707{
2708 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002709 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002710}
2711
2712module_init(qeth_l3_init);
2713module_exit(qeth_l3_exit);
2714MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2715MODULE_DESCRIPTION("qeth layer 3 discipline");
2716MODULE_LICENSE("GPL");