blob: 5905dc63e2569baf761611ad25bf3b91786a3235 [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 Blaschka64ef8952009-03-24 20:57:16 +000036#include <net/ip6_checksum.h>
Frank Blaschkab3332932011-08-08 01:33:59 +000037#include <net/iucv/af_iucv.h>
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020038#include <linux/hashtable.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010039
Frank Blaschka4a71df52008-02-15 09:19:42 +010040#include "qeth_l3.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010041
Einar Lueckd0ddf30f2010-12-08 02:57:58 +000042
Frank Blaschka4a71df52008-02-15 09:19:42 +010043static int qeth_l3_set_offline(struct ccwgroup_device *);
Frank Blaschka4a71df52008-02-15 09:19:42 +010044static int qeth_l3_stop(struct net_device *);
Julian Wiedmann00c163f2017-12-20 20:11:02 +010045static void qeth_l3_set_rx_mode(struct net_device *dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +010046static int qeth_l3_register_addr_entry(struct qeth_card *,
47 struct qeth_ipaddr *);
48static int qeth_l3_deregister_addr_entry(struct qeth_card *,
49 struct qeth_ipaddr *);
Frank Blaschka4a71df52008-02-15 09:19:42 +010050
Thomas Richter56530d62014-10-22 12:18:04 +020051static void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010052{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020053 sprintf(buf, "%pI4", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010054}
55
Thomas Richter56530d62014-10-22 12:18:04 +020056static void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010057{
Joe Perches963a9fd2010-09-07 21:14:40 +000058 sprintf(buf, "%pI6", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010059}
60
Frank Blaschka4a71df52008-02-15 09:19:42 +010061void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
62 char *buf)
63{
64 if (proto == QETH_PROT_IPV4)
65 qeth_l3_ipaddr4_to_string(addr, buf);
66 else if (proto == QETH_PROT_IPV6)
67 qeth_l3_ipaddr6_to_string(addr, buf);
68}
69
Julian Wiedmann1617dae2018-03-09 18:13:02 +010070static struct qeth_ipaddr *qeth_l3_get_addr_buffer(enum qeth_prot_versions prot)
Julian Wiedmannd66b1c02018-03-09 18:13:00 +010071{
72 struct qeth_ipaddr *addr = kmalloc(sizeof(*addr), GFP_ATOMIC);
73
74 if (addr)
75 qeth_l3_init_ipaddr(addr, QETH_IP_TYPE_NORMAL, prot);
76 return addr;
77}
78
Julian Wiedmannc5c48c52018-02-27 18:58:16 +010079static struct qeth_ipaddr *qeth_l3_find_addr_by_ip(struct qeth_card *card,
80 struct qeth_ipaddr *query)
81{
82 u64 key = qeth_l3_ipaddr_hash(query);
83 struct qeth_ipaddr *addr;
84
85 if (query->is_multicast) {
86 hash_for_each_possible(card->ip_mc_htable, addr, hnode, key)
87 if (qeth_l3_addr_match_ip(addr, query))
88 return addr;
89 } else {
90 hash_for_each_possible(card->ip_htable, addr, hnode, key)
91 if (qeth_l3_addr_match_ip(addr, query))
92 return addr;
93 }
94 return NULL;
95}
96
Frank Blaschka4a71df52008-02-15 09:19:42 +010097static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
98{
99 int i, j;
100 u8 octet;
101
102 for (i = 0; i < len; ++i) {
103 octet = addr[i];
104 for (j = 7; j >= 0; --j) {
105 bits[i*8 + j] = octet & 1;
106 octet >>= 1;
107 }
108 }
109}
110
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100111static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
112 struct qeth_ipaddr *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100113{
114 struct qeth_ipato_entry *ipatoe;
115 u8 addr_bits[128] = {0, };
116 u8 ipatoe_bits[128] = {0, };
117 int rc = 0;
118
119 if (!card->ipato.enabled)
120 return 0;
Julian Wiedmannb22d73d62017-12-13 18:56:30 +0100121 if (addr->type != QETH_IP_TYPE_NORMAL)
122 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100123
124 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
125 (addr->proto == QETH_PROT_IPV4)? 4:16);
126 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
127 if (addr->proto != ipatoe->proto)
128 continue;
129 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
130 (ipatoe->proto == QETH_PROT_IPV4) ?
131 4 : 16);
132 if (addr->proto == QETH_PROT_IPV4)
133 rc = !memcmp(addr_bits, ipatoe_bits,
134 min(32, ipatoe->mask_bits));
135 else
136 rc = !memcmp(addr_bits, ipatoe_bits,
137 min(128, ipatoe->mask_bits));
138 if (rc)
139 break;
140 }
141 /* invert? */
142 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
143 rc = !rc;
144 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
145 rc = !rc;
146
147 return rc;
148}
149
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100150static int qeth_l3_delete_ip(struct qeth_card *card,
151 struct qeth_ipaddr *tmp_addr)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200152{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100153 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200154 struct qeth_ipaddr *addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100155
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100156 if (tmp_addr->type == QETH_IP_TYPE_RXIP)
157 QETH_CARD_TEXT(card, 2, "delrxip");
158 else if (tmp_addr->type == QETH_IP_TYPE_VIPA)
159 QETH_CARD_TEXT(card, 2, "delvipa");
160 else
161 QETH_CARD_TEXT(card, 2, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100162
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200163 if (tmp_addr->proto == QETH_PROT_IPV4)
164 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100165 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200166 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
167 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100168 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200169
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100170 addr = qeth_l3_find_addr_by_ip(card, tmp_addr);
171 if (!addr || !qeth_l3_addr_match_all(addr, tmp_addr))
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200172 return -ENOENT;
173
174 addr->ref_counter--;
Julian Wiedmann4964c662018-02-27 18:58:15 +0100175 if (addr->type == QETH_IP_TYPE_NORMAL && addr->ref_counter > 0)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200176 return rc;
177 if (addr->in_progress)
178 return -EINPROGRESS;
179
Julian Wiedmann98d823a2018-02-27 18:58:13 +0100180 if (qeth_card_hw_is_reachable(card))
181 rc = qeth_l3_deregister_addr_entry(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200182
183 hash_del(&addr->hnode);
184 kfree(addr);
185
Frank Blaschka4a71df52008-02-15 09:19:42 +0100186 return rc;
187}
188
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100189static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100190{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100191 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200192 struct qeth_ipaddr *addr;
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100193 char buf[40];
Frank Blaschka4a71df52008-02-15 09:19:42 +0100194
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100195 if (tmp_addr->type == QETH_IP_TYPE_RXIP)
196 QETH_CARD_TEXT(card, 2, "addrxip");
197 else if (tmp_addr->type == QETH_IP_TYPE_VIPA)
198 QETH_CARD_TEXT(card, 2, "addvipa");
199 else
200 QETH_CARD_TEXT(card, 2, "addip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200201
202 if (tmp_addr->proto == QETH_PROT_IPV4)
203 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100204 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200205 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
206 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100207 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200208
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100209 addr = qeth_l3_find_addr_by_ip(card, tmp_addr);
210 if (addr) {
211 if (tmp_addr->type != QETH_IP_TYPE_NORMAL)
212 return -EADDRINUSE;
213 if (qeth_l3_addr_match_all(addr, tmp_addr)) {
214 addr->ref_counter++;
215 return 0;
216 }
217 qeth_l3_ipaddr_to_string(tmp_addr->proto, (u8 *)&tmp_addr->u,
218 buf);
219 dev_warn(&card->gdev->dev,
220 "Registering IP address %s failed\n", buf);
221 return -EADDRINUSE;
222 } else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200223 addr = qeth_l3_get_addr_buffer(tmp_addr->proto);
224 if (!addr)
225 return -ENOMEM;
226
227 memcpy(addr, tmp_addr, sizeof(struct qeth_ipaddr));
228 addr->ref_counter = 1;
229
Julian Wiedmannb22d73d62017-12-13 18:56:30 +0100230 if (qeth_l3_is_addr_covered_by_ipato(card, addr)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200231 QETH_CARD_TEXT(card, 2, "tkovaddr");
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100232 addr->ipato = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200233 }
234 hash_add(card->ip_htable, &addr->hnode,
235 qeth_l3_ipaddr_hash(addr));
236
Ursula Brauna7531c12016-09-15 14:39:23 +0200237 if (!qeth_card_hw_is_reachable(card)) {
238 addr->disp_flag = QETH_DISP_ADDR_ADD;
239 return 0;
240 }
241
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200242 /* qeth_l3_register_addr_entry can go to sleep
243 * if we add a IPV4 addr. It is caused by the reason
244 * that SETIP ipa cmd starts ARP staff for IPV4 addr.
245 * Thus we should unlock spinlock, and make a protection
246 * using in_progress variable to indicate that there is
247 * an hardware operation with this IPV4 address
248 */
249 if (addr->proto == QETH_PROT_IPV4) {
250 addr->in_progress = 1;
251 spin_unlock_bh(&card->ip_lock);
252 rc = qeth_l3_register_addr_entry(card, addr);
253 spin_lock_bh(&card->ip_lock);
254 addr->in_progress = 0;
255 } else
256 rc = qeth_l3_register_addr_entry(card, addr);
257
258 if (!rc || (rc == IPA_RC_DUPLICATE_IP_ADDRESS) ||
259 (rc == IPA_RC_LAN_OFFLINE)) {
260 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
261 if (addr->ref_counter < 1) {
Julian Wiedmann14d066c2018-02-27 18:58:14 +0100262 qeth_l3_deregister_addr_entry(card, addr);
263 hash_del(&addr->hnode);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200264 kfree(addr);
265 }
266 } else {
267 hash_del(&addr->hnode);
268 kfree(addr);
269 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200270 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100271 return rc;
272}
273
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200274static void qeth_l3_clear_ip_htable(struct qeth_card *card, int recover)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100275{
276 struct qeth_ipaddr *addr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200277 struct hlist_node *tmp;
278 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100279
Carsten Otte847a50f2010-06-21 22:57:05 +0000280 QETH_CARD_TEXT(card, 4, "clearip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200281
Ursula Braun76b11f82010-01-11 02:50:50 +0000282 if (recover && card->options.sniffer)
283 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100284
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200285 spin_lock_bh(&card->ip_lock);
286
287 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
288 if (!recover) {
289 hash_del(&addr->hnode);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100290 kfree(addr);
291 continue;
292 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200293 addr->disp_flag = QETH_DISP_ADDR_ADD;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100294 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200295
296 spin_unlock_bh(&card->ip_lock);
297
298 spin_lock_bh(&card->mclock);
299
300 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
301 hash_del(&addr->hnode);
302 kfree(addr);
303 }
304
305 spin_unlock_bh(&card->mclock);
306
307
Frank Blaschka4a71df52008-02-15 09:19:42 +0100308}
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200309static void qeth_l3_recover_ip(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100310{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200311 struct qeth_ipaddr *addr;
312 struct hlist_node *tmp;
313 int i;
314 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100315
Ursula Brauna7531c12016-09-15 14:39:23 +0200316 QETH_CARD_TEXT(card, 4, "recovrip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100317
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200318 spin_lock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100319
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200320 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
Julian Wiedmann98d823a2018-02-27 18:58:13 +0100321 if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200322 if (addr->proto == QETH_PROT_IPV4) {
323 addr->in_progress = 1;
324 spin_unlock_bh(&card->ip_lock);
325 rc = qeth_l3_register_addr_entry(card, addr);
326 spin_lock_bh(&card->ip_lock);
327 addr->in_progress = 0;
328 } else
329 rc = qeth_l3_register_addr_entry(card, addr);
330
331 if (!rc) {
332 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Ursula Brauna7531c12016-09-15 14:39:23 +0200333 if (addr->ref_counter < 1)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200334 qeth_l3_delete_ip(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200335 } else {
336 hash_del(&addr->hnode);
337 kfree(addr);
338 }
339 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100340 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200341
342 spin_unlock_bh(&card->ip_lock);
343
Frank Blaschka4a71df52008-02-15 09:19:42 +0100344}
345
346static int qeth_l3_send_setdelmc(struct qeth_card *card,
347 struct qeth_ipaddr *addr, int ipacmd)
348{
349 int rc;
350 struct qeth_cmd_buffer *iob;
351 struct qeth_ipa_cmd *cmd;
352
Carsten Otte847a50f2010-06-21 22:57:05 +0000353 QETH_CARD_TEXT(card, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100354
355 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100356 if (!iob)
357 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100358 cmd = __ipa_cmd(iob);
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100359 ether_addr_copy(cmd->data.setdelipm.mac, addr->mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100360 if (addr->proto == QETH_PROT_IPV6)
361 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
362 sizeof(struct in6_addr));
363 else
364 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
365
366 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
367
368 return rc;
369}
370
371static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
372{
373 int i, j;
374 for (i = 0; i < 16; i++) {
375 j = (len) - (i * 8);
376 if (j >= 8)
377 netmask[i] = 0xff;
378 else if (j > 0)
379 netmask[i] = (u8)(0xFF00 >> j);
380 else
381 netmask[i] = 0;
382 }
383}
384
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100385static u32 qeth_l3_get_setdelip_flags(struct qeth_ipaddr *addr, bool set)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100386{
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100387 switch (addr->type) {
388 case QETH_IP_TYPE_RXIP:
389 return (set) ? QETH_IPA_SETIP_TAKEOVER_FLAG : 0;
390 case QETH_IP_TYPE_VIPA:
391 return (set) ? QETH_IPA_SETIP_VIPA_FLAG :
392 QETH_IPA_DELIP_VIPA_FLAG;
393 default:
394 return (set && addr->ipato) ? QETH_IPA_SETIP_TAKEOVER_FLAG : 0;
395 }
396}
397
398static int qeth_l3_send_setdelip(struct qeth_card *card,
399 struct qeth_ipaddr *addr,
400 enum qeth_ipa_cmds ipacmd)
401{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100402 struct qeth_cmd_buffer *iob;
403 struct qeth_ipa_cmd *cmd;
404 __u8 netmask[16];
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100405 u32 flags;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100406
Carsten Otte847a50f2010-06-21 22:57:05 +0000407 QETH_CARD_TEXT(card, 4, "setdelip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100408
409 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100410 if (!iob)
411 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100412 cmd = __ipa_cmd(iob);
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100413
414 flags = qeth_l3_get_setdelip_flags(addr, ipacmd == IPA_CMD_SETIP);
415 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
416
Frank Blaschka4a71df52008-02-15 09:19:42 +0100417 if (addr->proto == QETH_PROT_IPV6) {
418 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
419 sizeof(struct in6_addr));
420 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
421 memcpy(cmd->data.setdelip6.mask, netmask,
422 sizeof(struct in6_addr));
423 cmd->data.setdelip6.flags = flags;
424 } else {
425 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
426 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
427 cmd->data.setdelip4.flags = flags;
428 }
429
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100430 return qeth_send_ipa_cmd(card, iob, NULL, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100431}
432
433static int qeth_l3_send_setrouting(struct qeth_card *card,
434 enum qeth_routing_types type, enum qeth_prot_versions prot)
435{
436 int rc;
437 struct qeth_ipa_cmd *cmd;
438 struct qeth_cmd_buffer *iob;
439
Carsten Otte847a50f2010-06-21 22:57:05 +0000440 QETH_CARD_TEXT(card, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100441 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100442 if (!iob)
443 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100444 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100445 cmd->data.setrtg.type = (type);
446 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
447
448 return rc;
449}
450
Stefan Raspl82e2e782013-03-18 20:04:43 +0000451static int qeth_l3_correct_routing_type(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100452 enum qeth_routing_types *type, enum qeth_prot_versions prot)
453{
454 if (card->info.type == QETH_CARD_TYPE_IQD) {
455 switch (*type) {
456 case NO_ROUTER:
457 case PRIMARY_CONNECTOR:
458 case SECONDARY_CONNECTOR:
459 case MULTICAST_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000460 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100461 default:
462 goto out_inval;
463 }
464 } else {
465 switch (*type) {
466 case NO_ROUTER:
467 case PRIMARY_ROUTER:
468 case SECONDARY_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000469 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100470 case MULTICAST_ROUTER:
471 if (qeth_is_ipafunc_supported(card, prot,
472 IPA_OSA_MC_ROUTER))
Stefan Raspl82e2e782013-03-18 20:04:43 +0000473 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100474 default:
475 goto out_inval;
476 }
477 }
478out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100479 *type = NO_ROUTER;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000480 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100481}
482
483int qeth_l3_setrouting_v4(struct qeth_card *card)
484{
485 int rc;
486
Carsten Otte847a50f2010-06-21 22:57:05 +0000487 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100488
Stefan Raspl82e2e782013-03-18 20:04:43 +0000489 rc = qeth_l3_correct_routing_type(card, &card->options.route4.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100490 QETH_PROT_IPV4);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000491 if (rc)
492 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100493
494 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
495 QETH_PROT_IPV4);
496 if (rc) {
497 card->options.route4.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200498 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
499 " on %s. Type set to 'no router'.\n", rc,
500 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100501 }
502 return rc;
503}
504
505int qeth_l3_setrouting_v6(struct qeth_card *card)
506{
507 int rc = 0;
508
Carsten Otte847a50f2010-06-21 22:57:05 +0000509 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100510
511 if (!qeth_is_supported(card, IPA_IPV6))
512 return 0;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000513 rc = qeth_l3_correct_routing_type(card, &card->options.route6.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100514 QETH_PROT_IPV6);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000515 if (rc)
516 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100517
518 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
519 QETH_PROT_IPV6);
520 if (rc) {
521 card->options.route6.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200522 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
523 " on %s. Type set to 'no router'.\n", rc,
524 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100525 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100526 return rc;
527}
528
529/*
530 * IP address takeover related functions
531 */
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100532
533/**
534 * qeth_l3_update_ipato() - Update 'takeover' property, for all NORMAL IPs.
535 *
536 * Caller must hold ip_lock.
537 */
538void qeth_l3_update_ipato(struct qeth_card *card)
539{
540 struct qeth_ipaddr *addr;
541 unsigned int i;
542
543 hash_for_each(card->ip_htable, i, addr, hnode) {
544 if (addr->type != QETH_IP_TYPE_NORMAL)
545 continue;
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100546 addr->ipato = qeth_l3_is_addr_covered_by_ipato(card, addr);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100547 }
548}
549
Frank Blaschka4a71df52008-02-15 09:19:42 +0100550static void qeth_l3_clear_ipato_list(struct qeth_card *card)
551{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100552 struct qeth_ipato_entry *ipatoe, *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100553
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200554 spin_lock_bh(&card->ip_lock);
555
Frank Blaschka4a71df52008-02-15 09:19:42 +0100556 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
557 list_del(&ipatoe->entry);
558 kfree(ipatoe);
559 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200560
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100561 qeth_l3_update_ipato(card);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200562 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100563}
564
565int qeth_l3_add_ipato_entry(struct qeth_card *card,
566 struct qeth_ipato_entry *new)
567{
568 struct qeth_ipato_entry *ipatoe;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100569 int rc = 0;
570
Carsten Otte847a50f2010-06-21 22:57:05 +0000571 QETH_CARD_TEXT(card, 2, "addipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200572
573 spin_lock_bh(&card->ip_lock);
574
Frank Blaschka4a71df52008-02-15 09:19:42 +0100575 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
576 if (ipatoe->proto != new->proto)
577 continue;
578 if (!memcmp(ipatoe->addr, new->addr,
579 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
580 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100581 rc = -EEXIST;
582 break;
583 }
584 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200585
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100586 if (!rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100587 list_add_tail(&new->entry, &card->ipato.entries);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100588 qeth_l3_update_ipato(card);
589 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100590
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200591 spin_unlock_bh(&card->ip_lock);
592
Frank Blaschka4a71df52008-02-15 09:19:42 +0100593 return rc;
594}
595
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100596int qeth_l3_del_ipato_entry(struct qeth_card *card,
597 enum qeth_prot_versions proto, u8 *addr,
598 int mask_bits)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100599{
600 struct qeth_ipato_entry *ipatoe, *tmp;
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100601 int rc = -ENOENT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100602
Carsten Otte847a50f2010-06-21 22:57:05 +0000603 QETH_CARD_TEXT(card, 2, "delipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200604
605 spin_lock_bh(&card->ip_lock);
606
Frank Blaschka4a71df52008-02-15 09:19:42 +0100607 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
608 if (ipatoe->proto != proto)
609 continue;
610 if (!memcmp(ipatoe->addr, addr,
611 (proto == QETH_PROT_IPV4)? 4:16) &&
612 (ipatoe->mask_bits == mask_bits)) {
613 list_del(&ipatoe->entry);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100614 qeth_l3_update_ipato(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100615 kfree(ipatoe);
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100616 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100617 }
618 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200619
620 spin_unlock_bh(&card->ip_lock);
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100621 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100622}
623
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100624int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip,
625 enum qeth_ip_types type,
626 enum qeth_prot_versions proto)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100627{
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100628 struct qeth_ipaddr addr;
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100629 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100630
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100631 qeth_l3_init_ipaddr(&addr, type, proto);
632 if (proto == QETH_PROT_IPV4)
633 memcpy(&addr.u.a4.addr, ip, 4);
634 else
635 memcpy(&addr.u.a6.addr, ip, 16);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200636
637 spin_lock_bh(&card->ip_lock);
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100638 rc = add ? qeth_l3_add_ip(card, &addr) : qeth_l3_delete_ip(card, &addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200639 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100640 return rc;
641}
642
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100643int qeth_l3_modify_hsuid(struct qeth_card *card, bool add)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100644{
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100645 struct qeth_ipaddr addr;
646 int rc, i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100647
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100648 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV6);
649 addr.u.a6.addr.s6_addr[0] = 0xfe;
650 addr.u.a6.addr.s6_addr[1] = 0x80;
651 for (i = 0; i < 8; i++)
652 addr.u.a6.addr.s6_addr[8+i] = card->options.hsuid[i];
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200653
654 spin_lock_bh(&card->ip_lock);
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100655 rc = add ? qeth_l3_add_ip(card, &addr) : qeth_l3_delete_ip(card, &addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200656 spin_unlock_bh(&card->ip_lock);
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100657 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100658}
659
660static int qeth_l3_register_addr_entry(struct qeth_card *card,
661 struct qeth_ipaddr *addr)
662{
663 char buf[50];
664 int rc = 0;
665 int cnt = 3;
666
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200667
Frank Blaschka4a71df52008-02-15 09:19:42 +0100668 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000669 QETH_CARD_TEXT(card, 2, "setaddr4");
670 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100671 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000672 QETH_CARD_TEXT(card, 2, "setaddr6");
673 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
674 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100675 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000676 QETH_CARD_TEXT(card, 2, "setaddr?");
677 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100678 }
679 do {
680 if (addr->is_multicast)
681 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
682 else
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100683 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100684 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000685 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100686 } while ((--cnt > 0) && rc);
687 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000688 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100689 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100690 dev_warn(&card->gdev->dev,
691 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100692 }
693 return rc;
694}
695
696static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
697 struct qeth_ipaddr *addr)
698{
699 int rc = 0;
700
701 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000702 QETH_CARD_TEXT(card, 2, "deladdr4");
703 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100704 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000705 QETH_CARD_TEXT(card, 2, "deladdr6");
706 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
707 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100708 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000709 QETH_CARD_TEXT(card, 2, "deladdr?");
710 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100711 }
712 if (addr->is_multicast)
713 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
714 else
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100715 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200716 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000717 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100718
719 return rc;
720}
721
Frank Blaschka4a71df52008-02-15 09:19:42 +0100722static int qeth_l3_setadapter_parms(struct qeth_card *card)
723{
Julian Wiedmann699d3fe2017-08-15 17:02:41 +0200724 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100725
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200726 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100727
Frank Blaschka4a71df52008-02-15 09:19:42 +0100728 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
729 rc = qeth_setadpparms_change_macaddr(card);
730 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100731 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -0800732 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100733 }
734
Frank Blaschka4a71df52008-02-15 09:19:42 +0100735 return rc;
736}
737
Frank Blaschka4a71df52008-02-15 09:19:42 +0100738static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
739{
740 int rc;
741
Carsten Otte847a50f2010-06-21 22:57:05 +0000742 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100743
744 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100745 dev_info(&card->gdev->dev,
746 "ARP processing not supported on %s!\n",
747 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100748 return 0;
749 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200750 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
751 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100752 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100753 dev_warn(&card->gdev->dev,
754 "Starting ARP processing support for %s failed\n",
755 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100756 }
757 return rc;
758}
759
Frank Blaschka4a71df52008-02-15 09:19:42 +0100760static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
761{
762 int rc;
763
Carsten Otte847a50f2010-06-21 22:57:05 +0000764 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100765
Frank Blaschka4a71df52008-02-15 09:19:42 +0100766 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100767 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800768 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100769 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100770 return -EOPNOTSUPP;
771 }
772
Thomas Richter4d7def22015-09-18 16:06:51 +0200773 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100774 IPA_CMD_ASS_START, 0);
775 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100776 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800777 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100778 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100779 return rc;
780}
781
782static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
783{
784 int rc = 0;
785
Carsten Otte847a50f2010-06-21 22:57:05 +0000786 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100787
788 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100789 dev_info(&card->gdev->dev,
790 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100791 return -EOPNOTSUPP;
792 }
793
Thomas Richter4d7def22015-09-18 16:06:51 +0200794 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100795 IPA_CMD_ASS_START, 0);
796 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100797 dev_warn(&card->gdev->dev,
798 "Starting VLAN support for %s failed\n",
799 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100800 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100801 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100802 }
803 return rc;
804}
805
806static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
807{
808 int rc;
809
Carsten Otte847a50f2010-06-21 22:57:05 +0000810 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100811
812 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100813 dev_info(&card->gdev->dev,
814 "Multicast not supported on %s\n",
815 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100816 return -EOPNOTSUPP;
817 }
818
Thomas Richter4d7def22015-09-18 16:06:51 +0200819 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100820 IPA_CMD_ASS_START, 0);
821 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100822 dev_warn(&card->gdev->dev,
823 "Starting multicast support for %s failed\n",
824 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100825 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100826 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100827 card->dev->flags |= IFF_MULTICAST;
828 }
829 return rc;
830}
831
Frank Blaschka4a71df52008-02-15 09:19:42 +0100832static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
833{
834 int rc;
835
Carsten Otte847a50f2010-06-21 22:57:05 +0000836 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100837
Julian Wiedmann23274592017-06-06 14:33:44 +0200838 if (card->info.type == QETH_CARD_TYPE_IQD)
839 goto out;
840
Thomas Richter4d7def22015-09-18 16:06:51 +0200841 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100842 IPA_CMD_ASS_START, 3);
843 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100844 dev_err(&card->gdev->dev,
845 "Activating IPv6 support for %s failed\n",
846 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100847 return rc;
848 }
Kittipon Meesompopa8155b02018-04-26 09:42:21 +0200849 rc = qeth_send_simple_setassparms_v6(card, IPA_IPV6,
850 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100851 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100852 dev_err(&card->gdev->dev,
853 "Activating IPv6 support for %s failed\n",
854 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100855 return rc;
856 }
Kittipon Meesompopa8155b02018-04-26 09:42:21 +0200857 rc = qeth_send_simple_setassparms_v6(card, IPA_PASSTHRU,
858 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100859 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100860 dev_warn(&card->gdev->dev,
861 "Enabling the passthrough mode for %s failed\n",
862 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100863 return rc;
864 }
865out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100866 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100867 return 0;
868}
Frank Blaschka4a71df52008-02-15 09:19:42 +0100869
870static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
871{
Carsten Otte847a50f2010-06-21 22:57:05 +0000872 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100873
874 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100875 dev_info(&card->gdev->dev,
876 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100877 return 0;
878 }
Julian Wiedmannc0622042017-12-20 20:10:58 +0100879 return qeth_l3_softsetup_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100880}
881
882static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
883{
884 int rc;
885
Carsten Otte847a50f2010-06-21 22:57:05 +0000886 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100887 card->info.broadcast_capable = 0;
888 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100889 dev_info(&card->gdev->dev,
890 "Broadcast not supported on %s\n",
891 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100892 rc = -EOPNOTSUPP;
893 goto out;
894 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200895 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100896 IPA_CMD_ASS_START, 0);
897 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100898 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
899 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100900 goto out;
901 }
902
Thomas Richter4d7def22015-09-18 16:06:51 +0200903 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100904 IPA_CMD_ASS_CONFIGURE, 1);
905 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100906 dev_warn(&card->gdev->dev,
907 "Setting up broadcast filtering for %s failed\n",
908 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100909 goto out;
910 }
911 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100912 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Thomas Richter4d7def22015-09-18 16:06:51 +0200913 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100914 IPA_CMD_ASS_ENABLE, 1);
915 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100916 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
917 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100918 goto out;
919 }
920 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
921out:
922 if (card->info.broadcast_capable)
923 card->dev->flags |= IFF_BROADCAST;
924 else
925 card->dev->flags &= ~IFF_BROADCAST;
926 return rc;
927}
928
Frank Blaschka4a71df52008-02-15 09:19:42 +0100929static int qeth_l3_start_ipassists(struct qeth_card *card)
930{
Carsten Otte847a50f2010-06-21 22:57:05 +0000931 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +0000932
Stefan Raspl0f547612013-01-21 02:30:20 +0000933 if (qeth_set_access_ctrl_online(card, 0))
934 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100935 qeth_l3_start_ipa_arp_processing(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +0100936 qeth_l3_start_ipa_source_mac(card); /* go on*/
937 qeth_l3_start_ipa_vlan(card); /* go on*/
938 qeth_l3_start_ipa_multicast(card); /* go on*/
939 qeth_l3_start_ipa_ipv6(card); /* go on*/
940 qeth_l3_start_ipa_broadcast(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +0100941 return 0;
942}
943
Frank Blaschka4a71df52008-02-15 09:19:42 +0100944static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
945 struct qeth_reply *reply, unsigned long data)
946{
947 struct qeth_ipa_cmd *cmd;
948
949 cmd = (struct qeth_ipa_cmd *) data;
950 if (cmd->hdr.return_code == 0)
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100951 ether_addr_copy(card->dev->dev_addr,
952 cmd->data.create_destroy_addr.unique_id);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100953 else
Joe Perches18336112012-07-12 22:33:10 -0700954 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100955
956 return 0;
957}
958
959static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
960{
961 int rc = 0;
962 struct qeth_cmd_buffer *iob;
963 struct qeth_ipa_cmd *cmd;
964
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200965 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100966
967 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
968 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100969 if (!iob)
970 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100971 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100972 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
973 card->info.unique_id;
974
975 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
976 NULL);
977 return rc;
978}
979
980static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
981 struct qeth_reply *reply, unsigned long data)
982{
983 struct qeth_ipa_cmd *cmd;
984
985 cmd = (struct qeth_ipa_cmd *) data;
986 if (cmd->hdr.return_code == 0)
987 card->info.unique_id = *((__u16 *)
988 &cmd->data.create_destroy_addr.unique_id[6]);
989 else {
990 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
991 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100992 dev_warn(&card->gdev->dev, "The network adapter failed to "
993 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100994 }
995 return 0;
996}
997
998static int qeth_l3_get_unique_id(struct qeth_card *card)
999{
1000 int rc = 0;
1001 struct qeth_cmd_buffer *iob;
1002 struct qeth_ipa_cmd *cmd;
1003
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001004 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001005
1006 if (!qeth_is_supported(card, IPA_IPV6)) {
1007 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1008 UNIQUE_ID_NOT_BY_CARD;
1009 return 0;
1010 }
1011
1012 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1013 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001014 if (!iob)
1015 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001016 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001017 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1018 card->info.unique_id;
1019
1020 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1021 return rc;
1022}
1023
Ursula Braun76b11f82010-01-11 02:50:50 +00001024static int
1025qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1026 unsigned long data)
1027{
1028 struct qeth_ipa_cmd *cmd;
1029 __u16 rc;
1030
1031 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1032
1033 cmd = (struct qeth_ipa_cmd *)data;
1034 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001035 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001036 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001037 switch (cmd->data.diagass.action) {
1038 case QETH_DIAGS_CMD_TRACE_QUERY:
1039 break;
1040 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001041 switch (rc) {
1042 case 0:
1043 case IPA_RC_INVALID_SUBCMD:
1044 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1045 dev_info(&card->gdev->dev, "The HiperSockets network "
1046 "traffic analyzer is deactivated\n");
1047 break;
1048 default:
1049 break;
1050 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001051 break;
1052 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001053 switch (rc) {
1054 case 0:
1055 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1056 dev_info(&card->gdev->dev, "The HiperSockets network "
1057 "traffic analyzer is activated\n");
1058 break;
1059 case IPA_RC_HARDWARE_AUTH_ERROR:
1060 dev_warn(&card->gdev->dev, "The device is not "
1061 "authorized to run as a HiperSockets network "
1062 "traffic analyzer\n");
1063 break;
1064 case IPA_RC_TRACE_ALREADY_ACTIVE:
1065 dev_warn(&card->gdev->dev, "A HiperSockets "
1066 "network traffic analyzer is already "
1067 "active in the HiperSockets LAN\n");
1068 break;
1069 default:
1070 break;
1071 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001072 break;
1073 default:
1074 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1075 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1076 }
1077
1078 return 0;
1079}
1080
1081static int
1082qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1083{
1084 struct qeth_cmd_buffer *iob;
1085 struct qeth_ipa_cmd *cmd;
1086
1087 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1088
1089 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001090 if (!iob)
1091 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001092 cmd = __ipa_cmd(iob);
Ursula Braun76b11f82010-01-11 02:50:50 +00001093 cmd->data.diagass.subcmd_len = 16;
1094 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1095 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1096 cmd->data.diagass.action = diags_cmd;
1097 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1098}
1099
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001100static void
1101qeth_l3_add_mc_to_hash(struct qeth_card *card, struct in_device *in4_dev)
1102{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001103 struct ip_mc_list *im4;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001104 struct qeth_ipaddr *tmp, *ipm;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001105
Carsten Otte847a50f2010-06-21 22:57:05 +00001106 QETH_CARD_TEXT(card, 4, "addmc");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001107
1108 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001109 if (!tmp)
1110 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001111
Sachin Santf3aa3132010-11-26 02:41:17 +00001112 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1113 im4 = rcu_dereference(im4->next_rcu)) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001114 ip_eth_mc_map(im4->multiaddr, tmp->mac);
Hans Wippel6bee4e22017-04-07 09:15:36 +02001115 tmp->u.a4.addr = be32_to_cpu(im4->multiaddr);
Julian Wiedmannbc3ab7052017-12-01 10:14:49 +01001116 tmp->is_multicast = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001117
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001118 ipm = qeth_l3_find_addr_by_ip(card, tmp);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001119 if (ipm) {
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001120 /* for mcast, by-IP match means full match */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001121 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1122 } else {
1123 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1124 if (!ipm)
1125 continue;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001126 ether_addr_copy(ipm->mac, tmp->mac);
Hans Wippel6bee4e22017-04-07 09:15:36 +02001127 ipm->u.a4.addr = be32_to_cpu(im4->multiaddr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001128 ipm->is_multicast = 1;
1129 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1130 hash_add(card->ip_mc_htable,
1131 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1132 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001133 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001134
1135 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001136}
1137
Jiri Pirko0347af52013-01-03 22:48:58 +00001138/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001139static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1140{
1141 struct in_device *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001142 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001143
Carsten Otte847a50f2010-06-21 22:57:05 +00001144 QETH_CARD_TEXT(card, 4, "addmcvl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001145
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001146 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001147 return;
1148
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001149 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1150 struct net_device *netdev;
1151
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001152 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001153 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001154 if (netdev == NULL ||
1155 !(netdev->flags & IFF_UP))
1156 continue;
Jiri Pirko0347af52013-01-03 22:48:58 +00001157 in_dev = __in_dev_get_rcu(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001158 if (!in_dev)
1159 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001160 qeth_l3_add_mc_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001161 }
1162}
1163
1164static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1165{
1166 struct in_device *in4_dev;
1167
Carsten Otte847a50f2010-06-21 22:57:05 +00001168 QETH_CARD_TEXT(card, 4, "chkmcv4");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001169
Sachin Santf3aa3132010-11-26 02:41:17 +00001170 rcu_read_lock();
Jiri Pirko0347af52013-01-03 22:48:58 +00001171 in4_dev = __in_dev_get_rcu(card->dev);
1172 if (in4_dev == NULL)
1173 goto unlock;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001174 qeth_l3_add_mc_to_hash(card, in4_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001175 qeth_l3_add_vlan_mc(card);
Jiri Pirko0347af52013-01-03 22:48:58 +00001176unlock:
Sachin Santf3aa3132010-11-26 02:41:17 +00001177 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001178}
1179
Julian Wiedmannc0622042017-12-20 20:10:58 +01001180static void qeth_l3_add_mc6_to_hash(struct qeth_card *card,
1181 struct inet6_dev *in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001182{
1183 struct qeth_ipaddr *ipm;
1184 struct ifmcaddr6 *im6;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001185 struct qeth_ipaddr *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001186
Carsten Otte847a50f2010-06-21 22:57:05 +00001187 QETH_CARD_TEXT(card, 4, "addmc6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001188
1189 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001190 if (!tmp)
1191 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001192
Frank Blaschka4a71df52008-02-15 09:19:42 +01001193 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001194 ipv6_eth_mc_map(&im6->mca_addr, tmp->mac);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001195 memcpy(&tmp->u.a6.addr, &im6->mca_addr.s6_addr,
1196 sizeof(struct in6_addr));
1197 tmp->is_multicast = 1;
1198
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001199 ipm = qeth_l3_find_addr_by_ip(card, tmp);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001200 if (ipm) {
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001201 /* for mcast, by-IP match means full match */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001202 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1203 continue;
1204 }
1205
Frank Blaschka4a71df52008-02-15 09:19:42 +01001206 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1207 if (!ipm)
1208 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001209
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001210 ether_addr_copy(ipm->mac, tmp->mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001211 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1212 sizeof(struct in6_addr));
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001213 ipm->is_multicast = 1;
1214 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1215 hash_add(card->ip_mc_htable,
1216 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1217
Frank Blaschka4a71df52008-02-15 09:19:42 +01001218 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001219 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001220}
1221
Jiri Pirko0347af52013-01-03 22:48:58 +00001222/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001223static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1224{
1225 struct inet6_dev *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001226 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001227
Carsten Otte847a50f2010-06-21 22:57:05 +00001228 QETH_CARD_TEXT(card, 4, "admc6vl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001229
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001230 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001231 return;
1232
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001233 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1234 struct net_device *netdev;
1235
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001236 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001237 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001238 if (netdev == NULL ||
1239 !(netdev->flags & IFF_UP))
1240 continue;
1241 in_dev = in6_dev_get(netdev);
1242 if (!in_dev)
1243 continue;
1244 read_lock_bh(&in_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001245 qeth_l3_add_mc6_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001246 read_unlock_bh(&in_dev->lock);
1247 in6_dev_put(in_dev);
1248 }
1249}
1250
1251static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1252{
1253 struct inet6_dev *in6_dev;
1254
Carsten Otte847a50f2010-06-21 22:57:05 +00001255 QETH_CARD_TEXT(card, 4, "chkmcv6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001256
Frank Blaschka4a71df52008-02-15 09:19:42 +01001257 if (!qeth_is_supported(card, IPA_IPV6))
1258 return ;
1259 in6_dev = in6_dev_get(card->dev);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001260 if (!in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001261 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001262
Jiri Pirko0347af52013-01-03 22:48:58 +00001263 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001264 read_lock_bh(&in6_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001265 qeth_l3_add_mc6_to_hash(card, in6_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001266 qeth_l3_add_vlan_mc6(card);
1267 read_unlock_bh(&in6_dev->lock);
Jiri Pirko0347af52013-01-03 22:48:58 +00001268 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001269 in6_dev_put(in6_dev);
1270}
Frank Blaschka4a71df52008-02-15 09:19:42 +01001271
Patrick McHardy80d5c362013-04-19 02:04:28 +00001272static int qeth_l3_vlan_rx_add_vid(struct net_device *dev,
1273 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001274{
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001275 struct qeth_card *card = dev->ml_priv;
1276
1277 set_bit(vid, card->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001278 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001279}
1280
Patrick McHardy80d5c362013-04-19 02:04:28 +00001281static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev,
1282 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001283{
Heiko Carstens509e2562008-07-26 02:24:10 -07001284 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001285
Carsten Otte847a50f2010-06-21 22:57:05 +00001286 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001287
Ursula Braun8e98ac42009-03-24 20:57:18 +00001288 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001289 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -05001290 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +00001291 }
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001292 clear_bit(vid, card->active_vlans);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001293 qeth_l3_set_rx_mode(dev);
Jiri Pirko8e586132011-12-08 19:52:37 -05001294 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001295}
1296
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001297static void qeth_l3_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
1298 struct qeth_hdr *hdr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001299{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001300 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001301 u16 prot = (hdr->hdr.l3.flags & QETH_HDR_IPV6) ? ETH_P_IPV6 :
1302 ETH_P_IP;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001303 unsigned char tg_addr[ETH_ALEN];
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001304
1305 skb_reset_network_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001306 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1307 case QETH_CAST_MULTICAST:
Julian Wiedmannc0622042017-12-20 20:10:58 +01001308 if (prot == ETH_P_IP)
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001309 ip_eth_mc_map(ip_hdr(skb)->daddr, tg_addr);
Julian Wiedmannc0622042017-12-20 20:10:58 +01001310 else
1311 ipv6_eth_mc_map(&ipv6_hdr(skb)->daddr, tg_addr);
1312
Frank Blaschka4a71df52008-02-15 09:19:42 +01001313 card->stats.multicast++;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001314 break;
1315 case QETH_CAST_BROADCAST:
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001316 ether_addr_copy(tg_addr, card->dev->broadcast);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001317 card->stats.multicast++;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001318 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001319 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00001320 if (card->options.sniffer)
1321 skb->pkt_type = PACKET_OTHERHOST;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001322 ether_addr_copy(tg_addr, card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001323 }
Julian Wiedmann04f67392018-03-09 18:12:58 +01001324
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001325 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1326 card->dev->header_ops->create(skb, card->dev, prot,
Julian Wiedmanna8433832017-12-20 20:11:06 +01001327 tg_addr, &hdr->hdr.l3.next_hop.rx.src_mac,
Julian Wiedmannf0ea8bf2018-03-09 18:12:56 +01001328 skb->len);
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001329 else
1330 card->dev->header_ops->create(skb, card->dev, prot,
Julian Wiedmannf0ea8bf2018-03-09 18:12:56 +01001331 tg_addr, "FAKELL", skb->len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001332 }
1333
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001334 skb->protocol = eth_type_trans(skb, card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001335
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001336 /* copy VLAN tag from hdr into skb */
1337 if (!card->options.sniffer &&
1338 (hdr->hdr.l3.ext_flags & (QETH_HDR_EXT_VLAN_FRAME |
1339 QETH_HDR_EXT_INCLUDE_VLAN_TAG))) {
1340 u16 tag = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
1341 hdr->hdr.l3.vlan_id :
Julian Wiedmanna8433832017-12-20 20:11:06 +01001342 hdr->hdr.l3.next_hop.rx.vlan_id;
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001343 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001344 }
1345
Julian Wiedmann6195b932018-04-26 09:42:17 +02001346 qeth_rx_csum(card, skb, hdr->hdr.l3.ext_flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001347}
1348
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001349static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1350 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001351{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001352 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001353 struct sk_buff *skb;
1354 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001355 unsigned int len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001356 __u16 magic;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001357
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001358 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +00001359 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001360 while (budget) {
1361 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +00001362 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001363 &card->rx.b_element, &card->rx.e_offset, &hdr);
1364 if (!skb) {
1365 *done = 1;
1366 break;
1367 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001368 switch (hdr->hdr.l3.id) {
1369 case QETH_HEADER_TYPE_LAYER3:
Frank Blaschkab3332932011-08-08 01:33:59 +00001370 magic = *(__u16 *)skb->data;
1371 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
1372 (magic == ETH_P_AF_IUCV)) {
Hans Wippel6bee4e22017-04-07 09:15:36 +02001373 skb->protocol = cpu_to_be16(ETH_P_AF_IUCV);
Frank Blaschkab3332932011-08-08 01:33:59 +00001374 len = skb->len;
1375 card->dev->header_ops->create(skb, card->dev, 0,
Julian Wiedmannf0ea8bf2018-03-09 18:12:56 +01001376 card->dev->dev_addr, "FAKELL", len);
Julian Wiedmann37cf05d2018-03-09 18:12:57 +01001377 skb_reset_mac_header(skb);
Frank Blaschkab3332932011-08-08 01:33:59 +00001378 netif_receive_skb(skb);
1379 } else {
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001380 qeth_l3_rebuild_skb(card, skb, hdr);
Frank Blaschkab3332932011-08-08 01:33:59 +00001381 len = skb->len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001382 napi_gro_receive(&card->napi, skb);
1383 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001384 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00001385 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
Ursula Braun76b11f82010-01-11 02:50:50 +00001386 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00001387 len = skb->len;
1388 netif_receive_skb(skb);
1389 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001390 default:
1391 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00001392 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001393 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001394 continue;
1395 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001396 work_done++;
1397 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001398 card->stats.rx_packets++;
1399 card->stats.rx_bytes += len;
1400 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001401 return work_done;
1402}
1403
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +02001404static void qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001405{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001406 QETH_DBF_TEXT(SETUP, 2, "stopcard");
1407 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001408
1409 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00001410 if (card->options.sniffer &&
1411 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
1412 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001413 if (card->read.state == CH_STATE_UP &&
1414 card->write.state == CH_STATE_UP &&
1415 (card->state == CARD_STATE_UP)) {
1416 if (recovery_mode)
1417 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02001418 else {
Ursula Braun869da902010-03-08 20:36:56 +00001419 rtnl_lock();
1420 dev_close(card->dev);
1421 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02001422 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001423 card->state = CARD_STATE_SOFTSETUP;
1424 }
1425 if (card->state == CARD_STATE_SOFTSETUP) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001426 qeth_l3_clear_ip_htable(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001427 qeth_clear_ipacmd_list(card);
1428 card->state = CARD_STATE_HARDSETUP;
1429 }
1430 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001431 qeth_qdio_clear_card(card, 0);
1432 qeth_clear_qdio_buffers(card);
1433 qeth_clear_working_pool_list(card);
1434 card->state = CARD_STATE_DOWN;
1435 }
1436 if (card->state == CARD_STATE_DOWN) {
1437 qeth_clear_cmd_buffers(&card->read);
1438 qeth_clear_cmd_buffers(&card->write);
1439 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001440}
1441
Ursula Braun76b11f82010-01-11 02:50:50 +00001442/*
1443 * test for and Switch promiscuous mode (on or off)
1444 * either for guestlan or HiperSocket Sniffer
1445 */
1446static void
1447qeth_l3_handle_promisc_mode(struct qeth_card *card)
1448{
1449 struct net_device *dev = card->dev;
1450
1451 if (((dev->flags & IFF_PROMISC) &&
1452 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
1453 (!(dev->flags & IFF_PROMISC) &&
1454 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
1455 return;
1456
1457 if (card->info.guestlan) { /* Guestlan trace */
1458 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
1459 qeth_setadp_promisc_mode(card);
1460 } else if (card->options.sniffer && /* HiperSockets trace */
1461 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
1462 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001463 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001464 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
1465 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00001466 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001467 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
1468 }
1469 }
1470}
1471
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001472static void qeth_l3_set_rx_mode(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001473{
Heiko Carstens509e2562008-07-26 02:24:10 -07001474 struct qeth_card *card = dev->ml_priv;
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001475 struct qeth_ipaddr *addr;
1476 struct hlist_node *tmp;
1477 int i, rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001478
Carsten Otte847a50f2010-06-21 22:57:05 +00001479 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00001480 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
1481 (card->state != CARD_STATE_UP))
1482 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00001483 if (!card->options.sniffer) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001484 spin_lock_bh(&card->mclock);
1485
Ursula Braun76b11f82010-01-11 02:50:50 +00001486 qeth_l3_add_multicast_ipv4(card);
Ursula Braun76b11f82010-01-11 02:50:50 +00001487 qeth_l3_add_multicast_ipv6(card);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001488
1489 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1490 switch (addr->disp_flag) {
1491 case QETH_DISP_ADDR_DELETE:
1492 rc = qeth_l3_deregister_addr_entry(card, addr);
1493 if (!rc || rc == IPA_RC_MC_ADDR_NOT_FOUND) {
1494 hash_del(&addr->hnode);
1495 kfree(addr);
1496 }
1497 break;
1498 case QETH_DISP_ADDR_ADD:
1499 rc = qeth_l3_register_addr_entry(card, addr);
1500 if (rc && rc != IPA_RC_LAN_OFFLINE) {
1501 hash_del(&addr->hnode);
1502 kfree(addr);
1503 break;
1504 }
1505 addr->ref_counter = 1;
1506 /* fall through */
1507 default:
1508 /* for next call to set_rx_mode(): */
1509 addr->disp_flag = QETH_DISP_ADDR_DELETE;
1510 }
1511 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001512
1513 spin_unlock_bh(&card->mclock);
1514
Ursula Braun76b11f82010-01-11 02:50:50 +00001515 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
1516 return;
1517 }
1518 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001519}
1520
1521static const char *qeth_l3_arp_get_error_cause(int *rc)
1522{
1523 switch (*rc) {
1524 case QETH_IPA_ARP_RC_FAILED:
1525 *rc = -EIO;
1526 return "operation failed";
1527 case QETH_IPA_ARP_RC_NOTSUPP:
1528 *rc = -EOPNOTSUPP;
1529 return "operation not supported";
1530 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
1531 *rc = -EINVAL;
1532 return "argument out of range";
1533 case QETH_IPA_ARP_RC_Q_NOTSUPP:
1534 *rc = -EOPNOTSUPP;
1535 return "query operation not supported";
1536 case QETH_IPA_ARP_RC_Q_NO_DATA:
1537 *rc = -ENOENT;
1538 return "no query data available";
1539 default:
1540 return "unknown error";
1541 }
1542}
1543
1544static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
1545{
1546 int tmp;
1547 int rc;
1548
Carsten Otte847a50f2010-06-21 22:57:05 +00001549 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001550
1551 /*
1552 * currently GuestLAN only supports the ARP assist function
1553 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
1554 * thus we say EOPNOTSUPP for this ARP function
1555 */
1556 if (card->info.guestlan)
1557 return -EOPNOTSUPP;
1558 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001559 return -EOPNOTSUPP;
1560 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001561 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001562 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
1563 no_entries);
1564 if (rc) {
1565 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001566 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
1567 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01001568 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
1569 }
1570 return rc;
1571}
1572
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001573static __u32 get_arp_entry_size(struct qeth_card *card,
1574 struct qeth_arp_query_data *qdata,
1575 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001576{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001577 __u32 rc;
1578 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001579
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001580 is_hsi = qdata->reply_bits == 5;
1581 if (type->ip == QETHARP_IP_ADDR_V4) {
1582 QETH_CARD_TEXT(card, 4, "arpev4");
1583 if (strip_entries) {
1584 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
1585 sizeof(struct qeth_arp_qi_entry7_short);
1586 } else {
1587 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
1588 sizeof(struct qeth_arp_qi_entry7);
1589 }
1590 } else if (type->ip == QETHARP_IP_ADDR_V6) {
1591 QETH_CARD_TEXT(card, 4, "arpev6");
1592 if (strip_entries) {
1593 rc = is_hsi ?
1594 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
1595 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
1596 } else {
1597 rc = is_hsi ?
1598 sizeof(struct qeth_arp_qi_entry5_ipv6) :
1599 sizeof(struct qeth_arp_qi_entry7_ipv6);
1600 }
1601 } else {
1602 QETH_CARD_TEXT(card, 4, "arpinv");
1603 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001604 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001605
1606 return rc;
1607}
1608
1609static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
1610{
1611 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
1612 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001613}
1614
1615static int qeth_l3_arp_query_cb(struct qeth_card *card,
1616 struct qeth_reply *reply, unsigned long data)
1617{
1618 struct qeth_ipa_cmd *cmd;
1619 struct qeth_arp_query_data *qdata;
1620 struct qeth_arp_query_info *qinfo;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001621 int i;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001622 int e;
1623 int entrybytes_done;
1624 int stripped_bytes;
1625 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001626
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001627 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001628
1629 qinfo = (struct qeth_arp_query_info *) reply->param;
1630 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001631 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001632 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001633 QETH_CARD_TEXT(card, 4, "arpcberr");
1634 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001635 return 0;
1636 }
1637 if (cmd->data.setassparms.hdr.return_code) {
1638 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001639 QETH_CARD_TEXT(card, 4, "setaperr");
1640 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001641 return 0;
1642 }
1643 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00001644 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001645
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001646 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
1647 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
1648 entrybytes_done = 0;
1649 for (e = 0; e < qdata->no_entries; ++e) {
1650 char *cur_entry;
1651 __u32 esize;
1652 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001653
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001654 cur_entry = &qdata->data + entrybytes_done;
1655 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
1656 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
1657 QETH_CARD_TEXT(card, 4, "pmis");
1658 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
1659 break;
1660 }
1661 esize = get_arp_entry_size(card, qdata, etype,
1662 do_strip_entries);
1663 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
1664 if (!esize)
1665 break;
1666
1667 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
1668 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
Ursula Braune0a81142012-03-07 02:06:28 +00001669 cmd->hdr.return_code = IPA_RC_ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001670 goto out_error;
1671 }
1672
1673 memcpy(qinfo->udata + qinfo->udata_offset,
1674 &qdata->data + entrybytes_done + stripped_bytes,
1675 esize);
1676 entrybytes_done += esize + stripped_bytes;
1677 qinfo->udata_offset += esize;
1678 ++qinfo->no_entries;
1679 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001680 /* check if all replies received ... */
1681 if (cmd->data.setassparms.hdr.seq_no <
1682 cmd->data.setassparms.hdr.number_of_replies)
1683 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001684 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001685 memcpy(qinfo->udata, &qinfo->no_entries, 4);
1686 /* keep STRIP_ENTRIES flag so the user program can distinguish
1687 * stripped entries from normal ones */
1688 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
1689 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
1690 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001691 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001692 return 0;
1693out_error:
1694 i = 0;
1695 memcpy(qinfo->udata, &i, 4);
1696 return 0;
1697}
1698
1699static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
1700 struct qeth_cmd_buffer *iob, int len,
1701 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1702 unsigned long),
1703 void *reply_param)
1704{
Carsten Otte847a50f2010-06-21 22:57:05 +00001705 QETH_CARD_TEXT(card, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001706
1707 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
1708 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
1709 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
1710 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
1711 reply_cb, reply_param);
1712}
1713
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001714static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
1715 enum qeth_prot_versions prot,
1716 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001717{
1718 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001719 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001720 int tmp;
1721 int rc;
1722
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001723 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
1724
Thomas Richterb475e312015-12-11 12:27:54 +01001725 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
1726 IPA_CMD_ASS_ARP_QUERY_INFO,
1727 sizeof(struct qeth_arp_query_data)
1728 - sizeof(char),
1729 prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001730 if (!iob)
1731 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001732 cmd = __ipa_cmd(iob);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001733 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
1734 cmd->data.setassparms.data.query_arp.reply_bits = 0;
1735 cmd->data.setassparms.data.query_arp.no_entries = 0;
1736 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
1737 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
1738 qeth_l3_arp_query_cb, (void *)qinfo);
1739 if (rc) {
1740 tmp = rc;
1741 QETH_DBF_MESSAGE(2,
1742 "Error while querying ARP cache on %s: %s "
1743 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
1744 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
1745 }
1746
1747 return rc;
1748}
1749
1750static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
1751{
1752 struct qeth_arp_query_info qinfo = {0, };
1753 int rc;
1754
Carsten Otte847a50f2010-06-21 22:57:05 +00001755 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001756
1757 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
1758 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001759 QETH_CARD_TEXT(card, 3, "arpqnsup");
1760 rc = -EOPNOTSUPP;
1761 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001762 }
1763 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001764 if (copy_from_user(&qinfo, udata, 6)) {
1765 rc = -EFAULT;
1766 goto out;
1767 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001768 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001769 if (!qinfo.udata) {
1770 rc = -ENOMEM;
1771 goto out;
1772 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001773 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001774 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001775 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001776 if (copy_to_user(udata, qinfo.udata, 4))
1777 rc = -EFAULT;
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001778 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001779 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001780 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
1781 /* fails in case of GuestLAN QDIO mode */
1782 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6, &qinfo);
1783 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001784 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
1785 QETH_CARD_TEXT(card, 4, "qactf");
1786 rc = -EFAULT;
1787 goto free_and_out;
1788 }
1789 QETH_CARD_TEXT(card, 4, "qacts");
1790
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001791free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001792 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001793out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001794 return rc;
1795}
1796
1797static int qeth_l3_arp_add_entry(struct qeth_card *card,
1798 struct qeth_arp_cache_entry *entry)
1799{
1800 struct qeth_cmd_buffer *iob;
1801 char buf[16];
1802 int tmp;
1803 int rc;
1804
Carsten Otte847a50f2010-06-21 22:57:05 +00001805 QETH_CARD_TEXT(card, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001806
1807 /*
1808 * currently GuestLAN only supports the ARP assist function
1809 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
1810 * thus we say EOPNOTSUPP for this ARP function
1811 */
1812 if (card->info.guestlan)
1813 return -EOPNOTSUPP;
1814 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001815 return -EOPNOTSUPP;
1816 }
1817
Thomas Richterb475e312015-12-11 12:27:54 +01001818 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001819 IPA_CMD_ASS_ARP_ADD_ENTRY,
1820 sizeof(struct qeth_arp_cache_entry),
1821 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001822 if (!iob)
1823 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +02001824 rc = qeth_send_setassparms(card, iob,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001825 sizeof(struct qeth_arp_cache_entry),
1826 (unsigned long) entry,
Thomas Richter8f43fb02016-06-16 16:18:59 +02001827 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001828 if (rc) {
1829 tmp = rc;
1830 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001831 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
1832 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
1833 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001834 }
1835 return rc;
1836}
1837
1838static int qeth_l3_arp_remove_entry(struct qeth_card *card,
1839 struct qeth_arp_cache_entry *entry)
1840{
1841 struct qeth_cmd_buffer *iob;
1842 char buf[16] = {0, };
1843 int tmp;
1844 int rc;
1845
Carsten Otte847a50f2010-06-21 22:57:05 +00001846 QETH_CARD_TEXT(card, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001847
1848 /*
1849 * currently GuestLAN only supports the ARP assist function
1850 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
1851 * thus we say EOPNOTSUPP for this ARP function
1852 */
1853 if (card->info.guestlan)
1854 return -EOPNOTSUPP;
1855 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001856 return -EOPNOTSUPP;
1857 }
1858 memcpy(buf, entry, 12);
Thomas Richterb475e312015-12-11 12:27:54 +01001859 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001860 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
1861 12,
1862 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001863 if (!iob)
1864 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +02001865 rc = qeth_send_setassparms(card, iob,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001866 12, (unsigned long)buf,
Thomas Richter8f43fb02016-06-16 16:18:59 +02001867 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001868 if (rc) {
1869 tmp = rc;
1870 memset(buf, 0, 16);
1871 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001872 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
1873 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
1874 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001875 }
1876 return rc;
1877}
1878
1879static int qeth_l3_arp_flush_cache(struct qeth_card *card)
1880{
1881 int rc;
1882 int tmp;
1883
Carsten Otte847a50f2010-06-21 22:57:05 +00001884 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001885
1886 /*
1887 * currently GuestLAN only supports the ARP assist function
1888 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
1889 * thus we say EOPNOTSUPP for this ARP function
1890 */
1891 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
1892 return -EOPNOTSUPP;
1893 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001894 return -EOPNOTSUPP;
1895 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001896 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001897 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
1898 if (rc) {
1899 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001900 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
1901 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01001902 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
1903 }
1904 return rc;
1905}
1906
1907static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1908{
Heiko Carstens509e2562008-07-26 02:24:10 -07001909 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001910 struct qeth_arp_cache_entry arp_entry;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001911 int rc = 0;
1912
Frank Blaschka4a71df52008-02-15 09:19:42 +01001913 switch (cmd) {
1914 case SIOC_QETH_ARP_SET_NO_ENTRIES:
1915 if (!capable(CAP_NET_ADMIN)) {
1916 rc = -EPERM;
1917 break;
1918 }
1919 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
1920 break;
1921 case SIOC_QETH_ARP_QUERY_INFO:
1922 if (!capable(CAP_NET_ADMIN)) {
1923 rc = -EPERM;
1924 break;
1925 }
1926 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
1927 break;
1928 case SIOC_QETH_ARP_ADD_ENTRY:
1929 if (!capable(CAP_NET_ADMIN)) {
1930 rc = -EPERM;
1931 break;
1932 }
1933 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
1934 sizeof(struct qeth_arp_cache_entry)))
1935 rc = -EFAULT;
1936 else
1937 rc = qeth_l3_arp_add_entry(card, &arp_entry);
1938 break;
1939 case SIOC_QETH_ARP_REMOVE_ENTRY:
1940 if (!capable(CAP_NET_ADMIN)) {
1941 rc = -EPERM;
1942 break;
1943 }
1944 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
1945 sizeof(struct qeth_arp_cache_entry)))
1946 rc = -EFAULT;
1947 else
1948 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
1949 break;
1950 case SIOC_QETH_ARP_FLUSH_CACHE:
1951 if (!capable(CAP_NET_ADMIN)) {
1952 rc = -EPERM;
1953 break;
1954 }
1955 rc = qeth_l3_arp_flush_cache(card);
1956 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001957 default:
1958 rc = -EOPNOTSUPP;
1959 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001960 return rc;
1961}
1962
Julian Wiedmann1f979122017-12-20 20:11:04 +01001963static int qeth_l3_get_cast_type(struct sk_buff *skb)
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001964{
David S. Miller69cce1d2011-07-17 23:09:49 -07001965 struct neighbour *n = NULL;
1966 struct dst_entry *dst;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001967
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001968 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07001969 dst = skb_dst(skb);
1970 if (dst)
David S. Miller24db1ba2012-07-02 22:02:33 -07001971 n = dst_neigh_lookup_skb(dst, skb);
David S. Miller69cce1d2011-07-17 23:09:49 -07001972 if (n) {
Julian Wiedmann1f979122017-12-20 20:11:04 +01001973 int cast_type = n->type;
1974
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001975 rcu_read_unlock();
David S. Miller24db1ba2012-07-02 22:02:33 -07001976 neigh_release(n);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001977 if ((cast_type == RTN_BROADCAST) ||
1978 (cast_type == RTN_MULTICAST) ||
1979 (cast_type == RTN_ANYCAST))
1980 return cast_type;
Julian Wiedmann1f979122017-12-20 20:11:04 +01001981 return RTN_UNSPEC;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001982 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001983 rcu_read_unlock();
1984
Julian Wiedmann1f979122017-12-20 20:11:04 +01001985 /* no neighbour (eg AF_PACKET), fall back to target's IP address ... */
Hans Wippel6bee4e22017-04-07 09:15:36 +02001986 if (be16_to_cpu(skb->protocol) == ETH_P_IPV6)
Julian Wiedmann1f979122017-12-20 20:11:04 +01001987 return ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr) ?
1988 RTN_MULTICAST : RTN_UNSPEC;
Hans Wippel6bee4e22017-04-07 09:15:36 +02001989 else if (be16_to_cpu(skb->protocol) == ETH_P_IP)
Julian Wiedmann1f979122017-12-20 20:11:04 +01001990 return ipv4_is_multicast(ip_hdr(skb)->daddr) ?
1991 RTN_MULTICAST : RTN_UNSPEC;
1992
1993 /* ... and MAC address */
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001994 if (ether_addr_equal_64bits(eth_hdr(skb)->h_dest, skb->dev->broadcast))
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001995 return RTN_BROADCAST;
Julian Wiedmanna65d1412017-12-20 20:11:05 +01001996 if (is_multicast_ether_addr(eth_hdr(skb)->h_dest))
Julian Wiedmann1f979122017-12-20 20:11:04 +01001997 return RTN_MULTICAST;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001998
Julian Wiedmann1f979122017-12-20 20:11:04 +01001999 /* default to unicast */
2000 return RTN_UNSPEC;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002001}
2002
Frank Blaschkab3332932011-08-08 01:33:59 +00002003static void qeth_l3_fill_af_iucv_hdr(struct qeth_card *card,
2004 struct qeth_hdr *hdr, struct sk_buff *skb)
2005{
2006 char daddr[16];
2007 struct af_iucv_trans_hdr *iucv_hdr;
2008
Frank Blaschkab3332932011-08-08 01:33:59 +00002009 memset(hdr, 0, sizeof(struct qeth_hdr));
2010 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2011 hdr->hdr.l3.ext_flags = 0;
Julian Wiedmannacd97762017-03-23 14:55:09 +01002012 hdr->hdr.l3.length = skb->len - ETH_HLEN;
Frank Blaschkab3332932011-08-08 01:33:59 +00002013 hdr->hdr.l3.flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
Julian Wiedmannacd97762017-03-23 14:55:09 +01002014
2015 iucv_hdr = (struct af_iucv_trans_hdr *) (skb->data + ETH_HLEN);
Frank Blaschkab3332932011-08-08 01:33:59 +00002016 memset(daddr, 0, sizeof(daddr));
2017 daddr[0] = 0xfe;
2018 daddr[1] = 0x80;
2019 memcpy(&daddr[8], iucv_hdr->destUserID, 8);
Julian Wiedmanna8433832017-12-20 20:11:06 +01002020 memcpy(hdr->hdr.l3.next_hop.ipv6_addr, daddr, 16);
Frank Blaschkab3332932011-08-08 01:33:59 +00002021}
2022
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002023static u8 qeth_l3_cast_type_to_flag(int cast_type)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002024{
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002025 if (cast_type == RTN_MULTICAST)
2026 return QETH_CAST_MULTICAST;
2027 if (cast_type == RTN_ANYCAST)
2028 return QETH_CAST_ANYCAST;
2029 if (cast_type == RTN_BROADCAST)
2030 return QETH_CAST_BROADCAST;
2031 return QETH_CAST_UNICAST;
2032}
David S. Miller69cce1d2011-07-17 23:09:49 -07002033
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002034static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
Julian Wiedmannf6c13142017-12-20 20:11:08 +01002035 struct sk_buff *skb, int ipv, int cast_type,
2036 unsigned int data_len)
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002037{
Frank Blaschka4a71df52008-02-15 09:19:42 +01002038 memset(hdr, 0, sizeof(struct qeth_hdr));
2039 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
Julian Wiedmannf6c13142017-12-20 20:11:08 +01002040 hdr->hdr.l3.length = data_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002041
2042 /*
2043 * before we're going to overwrite this location with next hop ip.
2044 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2045 */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002046 if (skb_vlan_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002047 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2048 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2049 else
2050 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002051 hdr->hdr.l3.vlan_id = skb_vlan_tag_get(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002052 }
2053
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002054 /* OSA only: */
2055 if (!ipv) {
2056 hdr->hdr.l3.flags = QETH_HDR_PASSTHRU;
2057 if (ether_addr_equal_64bits(eth_hdr(skb)->h_dest,
2058 skb->dev->broadcast))
2059 hdr->hdr.l3.flags |= QETH_CAST_BROADCAST;
2060 else
2061 hdr->hdr.l3.flags |= (cast_type == RTN_MULTICAST) ?
2062 QETH_CAST_MULTICAST : QETH_CAST_UNICAST;
2063 return;
2064 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002065
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002066 hdr->hdr.l3.flags = qeth_l3_cast_type_to_flag(cast_type);
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002067 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002068 if (ipv == 4) {
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002069 struct rtable *rt = skb_rtable(skb);
David Miller87e75972012-02-01 10:49:17 +00002070
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002071 *((__be32 *) &hdr->hdr.l3.next_hop.ipv4.addr) = (rt) ?
2072 rt_nexthop(rt, ip_hdr(skb)->daddr) :
2073 ip_hdr(skb)->daddr;
2074 } else {
2075 /* IPv6 */
2076 const struct rt6_info *rt = skb_rt6_info(skb);
2077 const struct in6_addr *next_hop;
David Miller87e75972012-02-01 10:49:17 +00002078
Julian Wiedmannec2c6722017-08-07 13:28:39 +02002079 if (rt && !ipv6_addr_any(&rt->rt6i_gateway))
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002080 next_hop = &rt->rt6i_gateway;
2081 else
2082 next_hop = &ipv6_hdr(skb)->daddr;
2083 memcpy(hdr->hdr.l3.next_hop.ipv6_addr, next_hop, 16);
David Miller87e75972012-02-01 10:49:17 +00002084
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002085 hdr->hdr.l3.flags |= QETH_HDR_IPV6;
2086 if (card->info.type != QETH_CARD_TYPE_IQD)
2087 hdr->hdr.l3.flags |= QETH_HDR_PASSTHRU;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002088 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002089 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002090}
2091
Frank Blaschka64ef8952009-03-24 20:57:16 +00002092static void qeth_tso_fill_header(struct qeth_card *card,
2093 struct qeth_hdr *qhdr, struct sk_buff *skb)
2094{
2095 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2096 struct tcphdr *tcph = tcp_hdr(skb);
2097 struct iphdr *iph = ip_hdr(skb);
2098 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2099
2100 /*fix header to TSO values ...*/
2101 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
2102 /*set values which are fix for the first approach ...*/
2103 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2104 hdr->ext.imb_hdr_no = 1;
2105 hdr->ext.hdr_type = 1;
2106 hdr->ext.hdr_version = 1;
2107 hdr->ext.hdr_len = 28;
2108 /*insert non-fix values */
2109 hdr->ext.mss = skb_shinfo(skb)->gso_size;
Julian Wiedmannf8eb4932017-08-15 17:02:45 +02002110 hdr->ext.dg_hdr_len = (__u16)(ip_hdrlen(skb) + tcp_hdrlen(skb));
Frank Blaschka64ef8952009-03-24 20:57:16 +00002111 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2112 sizeof(struct qeth_hdr_tso));
2113 tcph->check = 0;
Hans Wippel6bee4e22017-04-07 09:15:36 +02002114 if (be16_to_cpu(skb->protocol) == ETH_P_IPV6) {
Frank Blaschka64ef8952009-03-24 20:57:16 +00002115 ip6h->payload_len = 0;
2116 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2117 0, IPPROTO_TCP, 0);
2118 } else {
2119 /*OSA want us to set these values ...*/
2120 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2121 0, IPPROTO_TCP, 0);
2122 iph->tot_len = 0;
2123 iph->check = 0;
2124 }
2125}
2126
Eugene Crosser2863c612016-06-16 16:18:52 +02002127/**
Eugene Crosser41aeed52016-06-16 16:18:53 +02002128 * qeth_l3_get_elements_no_tso() - find number of SBALEs for skb data for tso
2129 * @card: qeth card structure, to check max. elems.
2130 * @skb: SKB address
2131 * @extra_elems: extra elems needed, to check against max.
Eugene Crosser2863c612016-06-16 16:18:52 +02002132 *
2133 * Returns the number of pages, and thus QDIO buffer elements, needed to cover
2134 * skb data, including linear part and fragments, but excluding TCP header.
2135 * (Exclusion of TCP header distinguishes it from qeth_get_elements_no().)
2136 * Checks if the result plus extra_elems fits under the limit for the card.
2137 * Returns 0 if it does not.
2138 * Note: extra_elems is not included in the returned result.
2139 */
Eugene Crosser41aeed52016-06-16 16:18:53 +02002140static int qeth_l3_get_elements_no_tso(struct qeth_card *card,
Eugene Crosser2863c612016-06-16 16:18:52 +02002141 struct sk_buff *skb, int extra_elems)
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002142{
Julian Wiedmann12472af2018-02-27 18:58:12 +01002143 addr_t start = (addr_t)tcp_hdr(skb) + tcp_hdrlen(skb);
2144 addr_t end = (addr_t)skb->data + skb_headlen(skb);
2145 int elements = qeth_get_elements_for_frags(skb);
2146
2147 if (start != end)
2148 elements += qeth_get_elements_for_range(start, end);
Frank Blaschka271648b2013-03-18 20:04:44 +00002149
Eugene Crosser2863c612016-06-16 16:18:52 +02002150 if ((elements + extra_elems) > QETH_MAX_BUFFER_ELEMENTS(card)) {
2151 QETH_DBF_MESSAGE(2,
2152 "Invalid size of TSO IP packet (Number=%d / Length=%d). Discarded.\n",
2153 elements + extra_elems, skb->len);
2154 return 0;
2155 }
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002156 return elements;
2157}
2158
Julian Wiedmanne38db6b2017-04-11 16:11:14 +02002159static netdev_tx_t qeth_l3_hard_start_xmit(struct sk_buff *skb,
2160 struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002161{
2162 int rc;
Hans Wippel6bee4e22017-04-07 09:15:36 +02002163 __be16 *tag;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002164 struct qeth_hdr *hdr = NULL;
Eugene Crosser2863c612016-06-16 16:18:52 +02002165 int hdr_elements = 0;
2166 int elements;
Heiko Carstens509e2562008-07-26 02:24:10 -07002167 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002168 struct sk_buff *new_skb = NULL;
2169 int ipv = qeth_get_ip_version(skb);
Julian Wiedmann1f979122017-12-20 20:11:04 +01002170 int cast_type = qeth_l3_get_cast_type(skb);
Stefan Raspl290b8342014-04-28 10:05:08 +02002171 struct qeth_qdio_out_q *queue =
2172 card->qdio.out_qs[card->qdio.do_prio_queueing
2173 || (cast_type && card->info.is_multicast_different) ?
2174 qeth_get_priority_queue(card, skb, ipv, cast_type) :
2175 card->qdio.default_out_queue];
Frank Blaschka4a71df52008-02-15 09:19:42 +01002176 int tx_bytes = skb->len;
Julian Wiedmann13ddacb2017-08-18 10:19:06 +02002177 unsigned int hd_len = 0;
Eugene Crosser41aeed52016-06-16 16:18:53 +02002178 bool use_tso;
Frank Blaschka683d7182008-08-01 16:39:13 +02002179 int data_offset = -1;
Julian Wiedmann886e1972017-08-15 17:02:39 +02002180 unsigned int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002181
Frank Blaschkab3332932011-08-08 01:33:59 +00002182 if (((card->info.type == QETH_CARD_TYPE_IQD) &&
2183 (((card->options.cq != QETH_CQ_ENABLED) && !ipv) ||
2184 ((card->options.cq == QETH_CQ_ENABLED) &&
Hans Wippel6bee4e22017-04-07 09:15:36 +02002185 (be16_to_cpu(skb->protocol) != ETH_P_AF_IUCV)))) ||
Frank Blaschkab3332932011-08-08 01:33:59 +00002186 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002187 goto tx_drop;
2188
2189 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2190 card->stats.tx_carrier_errors++;
2191 goto tx_drop;
2192 }
2193
2194 if ((cast_type == RTN_BROADCAST) &&
2195 (card->info.broadcast_capable == 0))
2196 goto tx_drop;
2197
2198 if (card->options.performance_stats) {
2199 card->perf_stats.outbound_cnt++;
2200 card->perf_stats.outbound_start_time = qeth_get_micros();
2201 }
2202
Eugene Crosser41aeed52016-06-16 16:18:53 +02002203 /* Ignore segment size from skb_is_gso(), 1 page is always used. */
2204 use_tso = skb_is_gso(skb) &&
Julian Wiedmannf8eb4932017-08-15 17:02:45 +02002205 (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4);
Frank Blaschka683d7182008-08-01 16:39:13 +02002206
Julian Wiedmann94a9c982017-06-06 14:33:43 +02002207 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02002208 new_skb = skb;
Julian Wiedmannacd97762017-03-23 14:55:09 +01002209 data_offset = ETH_HLEN;
Julian Wiedmannf1588172017-08-18 10:19:08 +02002210 hd_len = sizeof(*hdr);
Frank Blaschka683d7182008-08-01 16:39:13 +02002211 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2212 if (!hdr)
2213 goto tx_drop;
Eugene Crosser2863c612016-06-16 16:18:52 +02002214 hdr_elements++;
Frank Blaschka683d7182008-08-01 16:39:13 +02002215 } else {
2216 /* create a clone with writeable headroom */
2217 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
2218 + VLAN_HLEN);
2219 if (!new_skb)
2220 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002221
Frank Blaschka21fde742010-03-08 20:36:54 +00002222 if (ipv == 4) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002223 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002224 }
2225
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002226 if (ipv != 4 && skb_vlan_tag_present(new_skb)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002227 skb_push(new_skb, VLAN_HLEN);
2228 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2229 skb_copy_to_linear_data_offset(new_skb, 4,
2230 new_skb->data + 8, 4);
2231 skb_copy_to_linear_data_offset(new_skb, 8,
2232 new_skb->data + 12, 4);
Hans Wippel6bee4e22017-04-07 09:15:36 +02002233 tag = (__be16 *)(new_skb->data + 12);
2234 *tag = cpu_to_be16(ETH_P_8021Q);
2235 *(tag + 1) = cpu_to_be16(skb_vlan_tag_get(new_skb));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002236 }
2237 }
2238
2239 netif_stop_queue(dev);
2240
Frank Blaschka4a71df52008-02-15 09:19:42 +01002241 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00002242 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01002243 */
Eugene Crosser41aeed52016-06-16 16:18:53 +02002244 if ((card->info.type != QETH_CARD_TYPE_IQD) &&
2245 ((use_tso && !qeth_l3_get_elements_no_tso(card, new_skb, 1)) ||
Julian Wiedmann7d969d22017-03-23 14:55:08 +01002246 (!use_tso && !qeth_get_elements_no(card, new_skb, 0, 0)))) {
Eugene Crosser6059c902016-06-16 16:18:57 +02002247 int lin_rc = skb_linearize(new_skb);
2248
2249 if (card->options.performance_stats) {
2250 if (lin_rc)
2251 card->perf_stats.tx_linfail++;
2252 else
2253 card->perf_stats.tx_lin++;
2254 }
2255 if (lin_rc)
Eugene Crosser41aeed52016-06-16 16:18:53 +02002256 goto tx_drop;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002257 }
Julian Wiedmann886e1972017-08-15 17:02:39 +02002258 nr_frags = skb_shinfo(new_skb)->nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002259
Eugene Crosser41aeed52016-06-16 16:18:53 +02002260 if (use_tso) {
Johannes Bergd58ff352017-06-16 14:29:23 +02002261 hdr = skb_push(new_skb, sizeof(struct qeth_hdr_tso));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002262 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
Julian Wiedmannf6c13142017-12-20 20:11:08 +01002263 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type,
2264 new_skb->len - sizeof(struct qeth_hdr_tso));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002265 qeth_tso_fill_header(card, hdr, new_skb);
Eugene Crosser2863c612016-06-16 16:18:52 +02002266 hdr_elements++;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002267 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02002268 if (data_offset < 0) {
Johannes Bergd58ff352017-06-16 14:29:23 +02002269 hdr = skb_push(new_skb, sizeof(struct qeth_hdr));
Julian Wiedmannf6c13142017-12-20 20:11:08 +01002270 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type,
2271 new_skb->len -
2272 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02002273 } else {
Hans Wippel6bee4e22017-04-07 09:15:36 +02002274 if (be16_to_cpu(new_skb->protocol) == ETH_P_AF_IUCV)
Frank Blaschkab3332932011-08-08 01:33:59 +00002275 qeth_l3_fill_af_iucv_hdr(card, hdr, new_skb);
2276 else {
2277 qeth_l3_fill_header(card, hdr, new_skb, ipv,
Julian Wiedmannf6c13142017-12-20 20:11:08 +01002278 cast_type,
2279 new_skb->len - data_offset);
Frank Blaschkab3332932011-08-08 01:33:59 +00002280 }
Frank Blaschka683d7182008-08-01 16:39:13 +02002281 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002282
Julian Wiedmann6195b932018-04-26 09:42:17 +02002283 if (new_skb->ip_summed == CHECKSUM_PARTIAL) {
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +02002284 qeth_tx_csum(new_skb, &hdr->hdr.l3.ext_flags, ipv);
Julian Wiedmann6195b932018-04-26 09:42:17 +02002285 if (card->options.performance_stats)
2286 card->perf_stats.tx_csum++;
2287 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002288 }
2289
Eugene Crosser41aeed52016-06-16 16:18:53 +02002290 elements = use_tso ?
2291 qeth_l3_get_elements_no_tso(card, new_skb, hdr_elements) :
Julian Wiedmann7d969d22017-03-23 14:55:08 +01002292 qeth_get_elements_no(card, new_skb, hdr_elements,
2293 (data_offset > 0) ? data_offset : 0);
Eugene Crosser2863c612016-06-16 16:18:52 +02002294 if (!elements) {
Frank Blaschka64ef8952009-03-24 20:57:16 +00002295 if (data_offset >= 0)
2296 kmem_cache_free(qeth_core_header_cache, hdr);
2297 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002298 }
Eugene Crosser2863c612016-06-16 16:18:52 +02002299 elements += hdr_elements;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002300
Frank Blaschka51aa1652010-06-21 22:57:10 +00002301 if (card->info.type != QETH_CARD_TYPE_IQD) {
2302 int len;
Julian Wiedmann13ddacb2017-08-18 10:19:06 +02002303 if (use_tso) {
2304 hd_len = sizeof(struct qeth_hdr_tso) +
2305 ip_hdrlen(new_skb) + tcp_hdrlen(new_skb);
2306 len = hd_len;
2307 } else {
Frank Blaschka51aa1652010-06-21 22:57:10 +00002308 len = sizeof(struct qeth_hdr_layer3);
Julian Wiedmann13ddacb2017-08-18 10:19:06 +02002309 }
Frank Blaschka51aa1652010-06-21 22:57:10 +00002310
Stefan Raspld4ae1f52013-04-22 01:12:29 +00002311 if (qeth_hdr_chk_and_bounce(new_skb, &hdr, len))
Frank Blaschka51aa1652010-06-21 22:57:10 +00002312 goto tx_drop;
Julian Wiedmann13ddacb2017-08-18 10:19:06 +02002313 rc = qeth_do_send_packet(card, queue, new_skb, hdr, hd_len,
Julian Wiedmann9c3bfda2017-08-18 10:19:07 +02002314 hd_len, elements);
Frank Blaschka51aa1652010-06-21 22:57:10 +00002315 } else
Julian Wiedmann7c2e9ba2017-09-18 21:18:18 +02002316 rc = qeth_do_send_packet_fast(queue, new_skb, hdr, data_offset,
2317 hd_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002318
2319 if (!rc) {
2320 card->stats.tx_packets++;
2321 card->stats.tx_bytes += tx_bytes;
2322 if (new_skb != skb)
2323 dev_kfree_skb_any(skb);
2324 if (card->options.performance_stats) {
Eugene Crosser41aeed52016-06-16 16:18:53 +02002325 if (use_tso) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002326 card->perf_stats.large_send_bytes += tx_bytes;
2327 card->perf_stats.large_send_cnt++;
2328 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00002329 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002330 card->perf_stats.sg_skbs_sent++;
2331 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00002332 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002333 }
2334 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07002335 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002336 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02002337 if (data_offset >= 0)
2338 kmem_cache_free(qeth_core_header_cache, hdr);
2339
Frank Blaschka4a71df52008-02-15 09:19:42 +01002340 if (rc == -EBUSY) {
2341 if (new_skb != skb)
2342 dev_kfree_skb_any(new_skb);
2343 return NETDEV_TX_BUSY;
2344 } else
2345 goto tx_drop;
2346 }
2347
2348 netif_wake_queue(dev);
2349 if (card->options.performance_stats)
2350 card->perf_stats.outbound_time += qeth_get_micros() -
2351 card->perf_stats.outbound_start_time;
2352 return rc;
2353
2354tx_drop:
2355 card->stats.tx_dropped++;
2356 card->stats.tx_errors++;
2357 if ((new_skb != skb) && new_skb)
2358 dev_kfree_skb_any(new_skb);
2359 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02002360 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002361 return NETDEV_TX_OK;
2362}
2363
Ursula Braun39423442011-01-12 20:42:24 +00002364static int __qeth_l3_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002365{
Heiko Carstens509e2562008-07-26 02:24:10 -07002366 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002367 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002368
Carsten Otte847a50f2010-06-21 22:57:05 +00002369 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +00002370 if (card->state == CARD_STATE_UP)
2371 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002372 if (card->state != CARD_STATE_SOFTSETUP)
2373 return -ENODEV;
2374 card->data.state = CH_STATE_UP;
2375 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002376 netif_start_queue(dev);
2377
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002378 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
2379 napi_enable(&card->napi);
2380 napi_schedule(&card->napi);
2381 } else
2382 rc = -EIO;
2383 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002384}
2385
Ursula Braun39423442011-01-12 20:42:24 +00002386static int qeth_l3_open(struct net_device *dev)
2387{
2388 struct qeth_card *card = dev->ml_priv;
2389
2390 QETH_CARD_TEXT(card, 5, "qethope_");
2391 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
2392 QETH_CARD_TEXT(card, 3, "openREC");
2393 return -ERESTARTSYS;
2394 }
2395 return __qeth_l3_open(dev);
2396}
2397
Frank Blaschka4a71df52008-02-15 09:19:42 +01002398static int qeth_l3_stop(struct net_device *dev)
2399{
Heiko Carstens509e2562008-07-26 02:24:10 -07002400 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002401
Carsten Otte847a50f2010-06-21 22:57:05 +00002402 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002403 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002404 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002405 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002406 napi_disable(&card->napi);
2407 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002408 return 0;
2409}
2410
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07002411static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002412 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002413 .get_strings = qeth_core_get_strings,
2414 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00002415 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002416 .get_drvinfo = qeth_core_get_drvinfo,
Julian Wiedmann993e19c2017-04-11 16:11:17 +02002417 .get_link_ksettings = qeth_core_ethtool_get_link_ksettings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002418};
2419
2420/*
2421 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
2422 * NOARP on the netdevice is no option because it also turns off neighbor
2423 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
2424 * arp resolution but we want the hard header (packet socket will work
2425 * e.g. tcpdump)
2426 */
2427static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
2428{
2429 n->nud_state = NUD_NOARP;
2430 memcpy(n->ha, "FAKELL", 6);
2431 n->output = n->ops->connected_output;
2432 return 0;
2433}
2434
2435static int
2436qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
2437{
2438 if (np->tbl->family == AF_INET)
2439 np->neigh_setup = qeth_l3_neigh_setup_noarp;
2440
2441 return 0;
2442}
2443
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002444static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08002445 .ndo_open = qeth_l3_open,
2446 .ndo_stop = qeth_l3_stop,
2447 .ndo_get_stats = qeth_get_stats,
2448 .ndo_start_xmit = qeth_l3_hard_start_xmit,
2449 .ndo_validate_addr = eth_validate_addr,
Julian Wiedmann00c163f2017-12-20 20:11:02 +01002450 .ndo_set_rx_mode = qeth_l3_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002451 .ndo_do_ioctl = qeth_do_ioctl,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002452 .ndo_change_mtu = qeth_change_mtu,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002453 .ndo_fix_features = qeth_fix_features,
2454 .ndo_set_features = qeth_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08002455 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2456 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002457 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka8403b132009-01-08 10:50:55 -08002458};
2459
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002460static const struct net_device_ops qeth_l3_osa_netdev_ops = {
2461 .ndo_open = qeth_l3_open,
2462 .ndo_stop = qeth_l3_stop,
2463 .ndo_get_stats = qeth_get_stats,
2464 .ndo_start_xmit = qeth_l3_hard_start_xmit,
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +01002465 .ndo_features_check = qeth_features_check,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002466 .ndo_validate_addr = eth_validate_addr,
Julian Wiedmann00c163f2017-12-20 20:11:02 +01002467 .ndo_set_rx_mode = qeth_l3_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002468 .ndo_do_ioctl = qeth_do_ioctl,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002469 .ndo_change_mtu = qeth_change_mtu,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002470 .ndo_fix_features = qeth_fix_features,
2471 .ndo_set_features = qeth_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002472 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2473 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002474 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002475 .ndo_neigh_setup = qeth_l3_neigh_setup,
2476};
2477
Frank Blaschka4a71df52008-02-15 09:19:42 +01002478static int qeth_l3_setup_netdev(struct qeth_card *card)
2479{
Thomas Richter1aec42b2015-01-21 13:39:10 +01002480 int rc;
2481
Ursula Braun5113fec2010-05-16 21:15:14 +00002482 if (card->info.type == QETH_CARD_TYPE_OSD ||
2483 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002484 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
2485 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002486 pr_info("qeth_l3: ignoring TR device\n");
2487 return -ENODEV;
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002488 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002489
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002490 card->dev = alloc_etherdev(0);
2491 if (!card->dev)
2492 return -ENODEV;
2493 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Julian Wiedmann0f342942018-03-09 18:12:54 +01002494
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002495 /*IPv6 address autoconfiguration stuff*/
2496 qeth_l3_get_unique_id(card);
2497 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
2498 card->dev->dev_id = card->info.unique_id & 0xffff;
Julian Wiedmann0f342942018-03-09 18:12:54 +01002499
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002500 card->dev->hw_features |= NETIF_F_SG;
2501 card->dev->vlan_features |= NETIF_F_SG;
2502
2503 if (!card->info.guestlan) {
2504 card->dev->features |= NETIF_F_SG;
2505 card->dev->hw_features |= NETIF_F_TSO |
2506 NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
2507 card->dev->vlan_features |= NETIF_F_TSO |
2508 NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002509 }
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +02002510
2511 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) {
2512 card->dev->hw_features |= NETIF_F_IPV6_CSUM;
2513 card->dev->vlan_features |= NETIF_F_IPV6_CSUM;
2514 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002515 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
Tom Gundersenc835a672014-07-14 16:37:24 +02002516 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
2517 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002518 if (!card->dev)
2519 return -ENODEV;
2520 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002521 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Thomas Richter1aec42b2015-01-21 13:39:10 +01002522 rc = qeth_l3_iqd_read_initial_mac(card);
2523 if (rc)
2524 return rc;
Frank Blaschkab3332932011-08-08 01:33:59 +00002525 if (card->options.hsuid[0])
2526 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002527 } else
2528 return -ENODEV;
2529
Heiko Carstens509e2562008-07-26 02:24:10 -07002530 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002531 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002532 card->dev->mtu = card->info.initial_mtu;
Jarod Wilson46b3ef42016-10-20 13:55:23 -04002533 card->dev->min_mtu = 64;
2534 card->dev->max_mtu = ETH_MAX_MTU;
Ursula Braun71c46892018-04-26 09:42:15 +02002535 card->dev->dev_port = card->info.portno;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002536 card->dev->ethtool_ops = &qeth_l3_ethtool_ops;
Patrick McHardyf6469682013-04-19 02:04:27 +00002537 card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2538 NETIF_F_HW_VLAN_CTAG_RX |
2539 NETIF_F_HW_VLAN_CTAG_FILTER;
Eric Dumazet02875872014-10-05 18:38:35 -07002540 netif_keep_dst(card->dev);
Julian Wiedmann0cbff6d2017-12-01 10:14:51 +01002541 netif_set_gso_max_size(card->dev, (QETH_MAX_BUFFER_ELEMENTS(card) - 1) *
2542 PAGE_SIZE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002543
2544 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Julian Wiedmannd73ef322017-04-11 16:11:11 +02002545 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Ursula Braune5ebe632015-12-11 12:27:55 +01002546 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002547 return register_netdev(card->dev);
2548}
2549
Ursula Braun79a04e42017-06-06 14:33:49 +02002550static const struct device_type qeth_l3_devtype = {
2551 .name = "qeth_layer3",
2552 .groups = qeth_l3_attr_groups,
2553};
2554
Frank Blaschka4a71df52008-02-15 09:19:42 +01002555static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
2556{
2557 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +02002558 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002559
Ursula Braun79a04e42017-06-06 14:33:49 +02002560 if (gdev->dev.type == &qeth_generic_devtype) {
2561 rc = qeth_l3_create_device_attributes(&gdev->dev);
2562 if (rc)
2563 return rc;
2564 }
Ursula Braunebccc7392017-05-10 19:07:54 +02002565 hash_init(card->ip_htable);
2566 hash_init(card->ip_mc_htable);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002567 card->options.layer2 = 0;
Frank Blaschka1da74b12011-05-12 18:45:02 +00002568 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002569 return 0;
2570}
2571
2572static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
2573{
2574 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
2575
Ursula Braun79a04e42017-06-06 14:33:49 +02002576 if (cgdev->dev.type == &qeth_generic_devtype)
2577 qeth_l3_remove_device_attributes(&cgdev->dev);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002578
Ursula Braunf2148562009-05-19 21:38:37 +00002579 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002580 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
2581
Ursula Braun70919e22011-02-26 22:41:36 -08002582 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002583 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002584
2585 if (card->dev) {
2586 unregister_netdev(card->dev);
Julian Wiedmann6be68732018-03-20 07:59:12 +01002587 free_netdev(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002588 card->dev = NULL;
2589 }
2590
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002591 qeth_l3_clear_ip_htable(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002592 qeth_l3_clear_ipato_list(card);
2593 return;
2594}
2595
2596static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
2597{
2598 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
2599 int rc = 0;
2600 enum qeth_card_states recover_flag;
2601
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002602 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002603 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002604 QETH_DBF_TEXT(SETUP, 2, "setonlin");
2605 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002606
Frank Blaschka4a71df52008-02-15 09:19:42 +01002607 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002608 rc = qeth_core_hardsetup_card(card);
2609 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01002610 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00002611 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002612 goto out_remove;
2613 }
2614
Ursula Braunaa909222009-11-12 00:11:43 +00002615 if (!card->dev && qeth_l3_setup_netdev(card)) {
2616 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002617 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00002618 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002619
Frank Blaschka1da74b12011-05-12 18:45:02 +00002620 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
2621 if (card->info.hwtrap &&
2622 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
2623 card->info.hwtrap = 0;
2624 } else
2625 card->info.hwtrap = 0;
2626
Frank Blaschka4a71df52008-02-15 09:19:42 +01002627 card->state = CARD_STATE_HARDSETUP;
2628 qeth_print_status_message(card);
2629
2630 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002631 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002632
Frank Blaschka4a71df52008-02-15 09:19:42 +01002633 rc = qeth_l3_setadapter_parms(card);
2634 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01002635 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002636 if (!card->options.sniffer) {
2637 rc = qeth_l3_start_ipassists(card);
Stefan Raspl0f547612013-01-21 02:30:20 +00002638 if (rc) {
Ursula Braun76b11f82010-01-11 02:50:50 +00002639 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Stefan Raspl0f547612013-01-21 02:30:20 +00002640 goto out_remove;
2641 }
Ursula Braun76b11f82010-01-11 02:50:50 +00002642 rc = qeth_l3_setrouting_v4(card);
2643 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01002644 QETH_DBF_TEXT_(SETUP, 2, "4err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002645 rc = qeth_l3_setrouting_v6(card);
2646 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01002647 QETH_DBF_TEXT_(SETUP, 2, "5err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002648 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002649 netif_tx_disable(card->dev);
2650
2651 rc = qeth_init_qdio_queues(card);
2652 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002653 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00002654 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002655 goto out_remove;
2656 }
2657 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002658
2659 qeth_set_allowed_threads(card, 0xffffffff, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002660 qeth_l3_recover_ip(card);
Ursula Braun2b6203b2010-11-26 02:41:19 +00002661 if (card->lan_online)
2662 netif_carrier_on(card->dev);
2663 else
2664 netif_carrier_off(card->dev);
Julian Wiedmannd025da92018-06-29 19:45:54 +02002665
2666 qeth_enable_hw_features(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002667 if (recover_flag == CARD_STATE_RECOVER) {
Ursula Braun4763b0a2011-12-19 22:56:32 +00002668 rtnl_lock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002669 if (recovery_mode)
Ursula Braun39423442011-01-12 20:42:24 +00002670 __qeth_l3_open(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00002671 else
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002672 dev_open(card->dev);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01002673 qeth_l3_set_rx_mode(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00002674 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002675 }
Stefan Raspl82f77cf2013-03-18 20:04:42 +00002676 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002677 /* let user_space know that device is online */
2678 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002679 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002680 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002681 return 0;
2682out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002683 qeth_l3_stop_card(card, 0);
2684 ccw_device_set_offline(CARD_DDEV(card));
2685 ccw_device_set_offline(CARD_WDEV(card));
2686 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01002687 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002688 if (recover_flag == CARD_STATE_RECOVER)
2689 card->state = CARD_STATE_RECOVER;
2690 else
2691 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00002692 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002693 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00002694 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002695}
2696
2697static int qeth_l3_set_online(struct ccwgroup_device *gdev)
2698{
2699 return __qeth_l3_set_online(gdev, 0);
2700}
2701
2702static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
2703 int recovery_mode)
2704{
2705 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
2706 int rc = 0, rc2 = 0, rc3 = 0;
2707 enum qeth_card_states recover_flag;
2708
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002709 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002710 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002711 QETH_DBF_TEXT(SETUP, 3, "setoffl");
2712 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002713
2714 if (card->dev && netif_carrier_ok(card->dev))
2715 netif_carrier_off(card->dev);
2716 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00002717 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
2718 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
2719 card->info.hwtrap = 1;
2720 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02002721 qeth_l3_stop_card(card, recovery_mode);
Einar Lueck72861ae2011-12-19 22:56:36 +00002722 if ((card->options.cq == QETH_CQ_ENABLED) && card->dev) {
2723 rtnl_lock();
2724 call_netdevice_notifiers(NETDEV_REBOOT, card->dev);
2725 rtnl_unlock();
2726 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002727 rc = ccw_device_set_offline(CARD_DDEV(card));
2728 rc2 = ccw_device_set_offline(CARD_WDEV(card));
2729 rc3 = ccw_device_set_offline(CARD_RDEV(card));
2730 if (!rc)
2731 rc = (rc2) ? rc2 : rc3;
2732 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002733 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01002734 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002735 if (recover_flag == CARD_STATE_UP)
2736 card->state = CARD_STATE_RECOVER;
2737 /* let user_space know that device is offline */
2738 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002739 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002740 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002741 return 0;
2742}
2743
2744static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
2745{
2746 return __qeth_l3_set_offline(cgdev, 0);
2747}
2748
2749static int qeth_l3_recover(void *ptr)
2750{
2751 struct qeth_card *card;
2752 int rc = 0;
2753
2754 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00002755 QETH_CARD_TEXT(card, 2, "recover1");
2756 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002757 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
2758 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00002759 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002760 dev_warn(&card->gdev->dev,
2761 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00002762 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002763 __qeth_l3_set_offline(card->gdev, 1);
2764 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002765 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002766 dev_info(&card->gdev->dev,
2767 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02002768 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00002769 qeth_close_dev(card);
2770 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00002771 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02002772 }
Stefan Raspl65d80132013-04-07 22:19:27 +00002773 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002774 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
2775 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002776 return 0;
2777}
2778
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002779static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
2780{
2781 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
2782
2783 if (card->dev)
2784 netif_device_detach(card->dev);
2785 qeth_set_allowed_threads(card, 0, 1);
2786 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
2787 if (gdev->state == CCWGROUP_OFFLINE)
2788 return 0;
2789 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00002790 if (card->info.hwtrap)
2791 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002792 __qeth_l3_set_offline(card->gdev, 1);
2793 } else
2794 __qeth_l3_set_offline(card->gdev, 0);
2795 return 0;
2796}
2797
2798static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
2799{
2800 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
2801 int rc = 0;
2802
2803 if (gdev->state == CCWGROUP_OFFLINE)
2804 goto out;
2805
2806 if (card->state == CARD_STATE_RECOVER) {
2807 rc = __qeth_l3_set_online(card->gdev, 1);
2808 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00002809 rtnl_lock();
2810 dev_close(card->dev);
2811 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002812 }
2813 } else
2814 rc = __qeth_l3_set_online(card->gdev, 0);
2815out:
2816 qeth_set_allowed_threads(card, 0xffffffff, 0);
2817 if (card->dev)
2818 netif_device_attach(card->dev);
2819 if (rc)
2820 dev_warn(&card->gdev->dev, "The qeth device driver "
2821 "failed to recover an error on the device\n");
2822 return rc;
2823}
2824
Eugene Crosserc044dc22014-01-29 09:23:48 +01002825/* Returns zero if the command is successfully "consumed" */
2826static int qeth_l3_control_event(struct qeth_card *card,
2827 struct qeth_ipa_cmd *cmd)
2828{
2829 return 1;
2830}
2831
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002832struct qeth_discipline qeth_l3_discipline = {
Ursula Braun79a04e42017-06-06 14:33:49 +02002833 .devtype = &qeth_l3_devtype,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02002834 .process_rx_buffer = qeth_l3_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002835 .recover = qeth_l3_recover,
2836 .setup = qeth_l3_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002837 .remove = qeth_l3_remove_device,
2838 .set_online = qeth_l3_set_online,
2839 .set_offline = qeth_l3_set_offline,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002840 .freeze = qeth_l3_pm_suspend,
2841 .thaw = qeth_l3_pm_resume,
2842 .restore = qeth_l3_pm_resume,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002843 .do_ioctl = qeth_l3_do_ioctl,
Eugene Crosserc044dc22014-01-29 09:23:48 +01002844 .control_event_handler = qeth_l3_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002845};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002846EXPORT_SYMBOL_GPL(qeth_l3_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002847
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002848static int qeth_l3_handle_ip_event(struct qeth_card *card,
2849 struct qeth_ipaddr *addr,
2850 unsigned long event)
2851{
2852 switch (event) {
2853 case NETDEV_UP:
2854 spin_lock_bh(&card->ip_lock);
2855 qeth_l3_add_ip(card, addr);
2856 spin_unlock_bh(&card->ip_lock);
2857 return NOTIFY_OK;
2858 case NETDEV_DOWN:
2859 spin_lock_bh(&card->ip_lock);
2860 qeth_l3_delete_ip(card, addr);
2861 spin_unlock_bh(&card->ip_lock);
2862 return NOTIFY_OK;
2863 default:
2864 return NOTIFY_DONE;
2865 }
2866}
2867
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002868static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2869{
2870 if (is_vlan_dev(dev))
2871 dev = vlan_dev_real_dev(dev);
2872 if (dev->netdev_ops == &qeth_l3_osa_netdev_ops ||
2873 dev->netdev_ops == &qeth_l3_netdev_ops)
2874 return (struct qeth_card *) dev->ml_priv;
2875 return NULL;
2876}
2877
Frank Blaschka4a71df52008-02-15 09:19:42 +01002878static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07002879 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002880{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002881
Frank Blaschka4a71df52008-02-15 09:19:42 +01002882 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002883 struct net_device *dev = ifa->ifa_dev->dev;
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002884 struct qeth_ipaddr addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002885 struct qeth_card *card;
2886
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09002887 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07002888 return NOTIFY_DONE;
2889
Frank Blaschka4a71df52008-02-15 09:19:42 +01002890 card = qeth_l3_get_card_from_dev(dev);
2891 if (!card)
2892 return NOTIFY_DONE;
frank.blaschka@de.ibm.com6d8823d2012-05-16 01:28:26 +00002893 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002894
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002895 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV4);
2896 addr.u.a4.addr = be32_to_cpu(ifa->ifa_address);
2897 addr.u.a4.mask = be32_to_cpu(ifa->ifa_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002898
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002899 return qeth_l3_handle_ip_event(card, &addr, event);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002900}
2901
2902static struct notifier_block qeth_l3_ip_notifier = {
2903 qeth_l3_ip_event,
2904 NULL,
2905};
2906
Frank Blaschka4a71df52008-02-15 09:19:42 +01002907static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07002908 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002909{
2910 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002911 struct net_device *dev = ifa->idev->dev;
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002912 struct qeth_ipaddr addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002913 struct qeth_card *card;
2914
Frank Blaschka4a71df52008-02-15 09:19:42 +01002915 card = qeth_l3_get_card_from_dev(dev);
2916 if (!card)
2917 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00002918 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002919 if (!qeth_is_supported(card, IPA_IPV6))
2920 return NOTIFY_DONE;
2921
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002922 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV6);
2923 addr.u.a6.addr = ifa->addr;
2924 addr.u.a6.pfxlen = ifa->prefix_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002925
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002926 return qeth_l3_handle_ip_event(card, &addr, event);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002927}
2928
2929static struct notifier_block qeth_l3_ip6_notifier = {
2930 qeth_l3_ip6_event,
2931 NULL,
2932};
Frank Blaschka4a71df52008-02-15 09:19:42 +01002933
2934static int qeth_l3_register_notifiers(void)
2935{
2936 int rc;
2937
Carsten Otte847a50f2010-06-21 22:57:05 +00002938 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002939 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
2940 if (rc)
2941 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002942 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
2943 if (rc) {
2944 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
2945 return rc;
2946 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002947 return 0;
2948}
2949
2950static void qeth_l3_unregister_notifiers(void)
2951{
Carsten Otte847a50f2010-06-21 22:57:05 +00002952 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Stefan Raspl18af5c12012-11-19 02:46:50 +00002953 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
Stefan Raspl18af5c12012-11-19 02:46:50 +00002954 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002955}
2956
2957static int __init qeth_l3_init(void)
2958{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002959 pr_info("register layer 3 discipline\n");
Julian Wiedmannc0622042017-12-20 20:10:58 +01002960 return qeth_l3_register_notifiers();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002961}
2962
2963static void __exit qeth_l3_exit(void)
2964{
2965 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002966 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002967}
2968
2969module_init(qeth_l3_init);
2970module_exit(qeth_l3_exit);
2971MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2972MODULE_DESCRIPTION("qeth layer 3 discipline");
2973MODULE_LICENSE("GPL");