blob: 0e8ed8787fd3ebe0aadba37a786181d99d0067ee [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_send_simple_setassparms_ipv6(struct qeth_card *card,
739 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
740{
741 int rc;
742 struct qeth_cmd_buffer *iob;
743
Carsten Otte847a50f2010-06-21 22:57:05 +0000744 QETH_CARD_TEXT(card, 4, "simassp6");
Thomas Richterb475e312015-12-11 12:27:54 +0100745 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100746 0, QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100747 if (!iob)
748 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +0200749 rc = qeth_send_setassparms(card, iob, 0, 0,
Thomas Richter8f43fb02016-06-16 16:18:59 +0200750 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100751 return rc;
752}
Frank Blaschka4a71df52008-02-15 09:19:42 +0100753
Frank Blaschka4a71df52008-02-15 09:19:42 +0100754static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
755{
756 int rc;
757
Carsten Otte847a50f2010-06-21 22:57:05 +0000758 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100759
760 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100761 dev_info(&card->gdev->dev,
762 "ARP processing not supported on %s!\n",
763 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100764 return 0;
765 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200766 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
767 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100768 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100769 dev_warn(&card->gdev->dev,
770 "Starting ARP processing support for %s failed\n",
771 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100772 }
773 return rc;
774}
775
Frank Blaschka4a71df52008-02-15 09:19:42 +0100776static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
777{
778 int rc;
779
Carsten Otte847a50f2010-06-21 22:57:05 +0000780 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100781
Frank Blaschka4a71df52008-02-15 09:19:42 +0100782 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100783 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800784 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100785 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100786 return -EOPNOTSUPP;
787 }
788
Thomas Richter4d7def22015-09-18 16:06:51 +0200789 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100790 IPA_CMD_ASS_START, 0);
791 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100792 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800793 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100794 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100795 return rc;
796}
797
798static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
799{
800 int rc = 0;
801
Carsten Otte847a50f2010-06-21 22:57:05 +0000802 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100803
804 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100805 dev_info(&card->gdev->dev,
806 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100807 return -EOPNOTSUPP;
808 }
809
Thomas Richter4d7def22015-09-18 16:06:51 +0200810 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100811 IPA_CMD_ASS_START, 0);
812 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100813 dev_warn(&card->gdev->dev,
814 "Starting VLAN support for %s failed\n",
815 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100816 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100817 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100818 }
819 return rc;
820}
821
822static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
823{
824 int rc;
825
Carsten Otte847a50f2010-06-21 22:57:05 +0000826 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100827
828 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100829 dev_info(&card->gdev->dev,
830 "Multicast not supported on %s\n",
831 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100832 return -EOPNOTSUPP;
833 }
834
Thomas Richter4d7def22015-09-18 16:06:51 +0200835 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100836 IPA_CMD_ASS_START, 0);
837 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100838 dev_warn(&card->gdev->dev,
839 "Starting multicast support for %s failed\n",
840 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100841 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100842 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100843 card->dev->flags |= IFF_MULTICAST;
844 }
845 return rc;
846}
847
Frank Blaschka4a71df52008-02-15 09:19:42 +0100848static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
849{
850 int rc;
851
Carsten Otte847a50f2010-06-21 22:57:05 +0000852 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100853
Frank Blaschka1da74b12011-05-12 18:45:02 +0000854 rc = qeth_query_ipassists(card, QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100855 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100856 dev_err(&card->gdev->dev,
857 "Activating IPv6 support for %s failed\n",
858 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100859 return rc;
860 }
Julian Wiedmann23274592017-06-06 14:33:44 +0200861
862 if (card->info.type == QETH_CARD_TYPE_IQD)
863 goto out;
864
Thomas Richter4d7def22015-09-18 16:06:51 +0200865 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100866 IPA_CMD_ASS_START, 3);
867 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100868 dev_err(&card->gdev->dev,
869 "Activating IPv6 support for %s failed\n",
870 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100871 return rc;
872 }
873 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
874 IPA_CMD_ASS_START);
875 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100876 dev_err(&card->gdev->dev,
877 "Activating IPv6 support for %s failed\n",
878 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100879 return rc;
880 }
881 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
882 IPA_CMD_ASS_START);
883 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100884 dev_warn(&card->gdev->dev,
885 "Enabling the passthrough mode for %s failed\n",
886 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100887 return rc;
888 }
889out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100890 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100891 return 0;
892}
Frank Blaschka4a71df52008-02-15 09:19:42 +0100893
894static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
895{
Carsten Otte847a50f2010-06-21 22:57:05 +0000896 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100897
898 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100899 dev_info(&card->gdev->dev,
900 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100901 return 0;
902 }
Julian Wiedmannc0622042017-12-20 20:10:58 +0100903 return qeth_l3_softsetup_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100904}
905
906static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
907{
908 int rc;
909
Carsten Otte847a50f2010-06-21 22:57:05 +0000910 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100911 card->info.broadcast_capable = 0;
912 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100913 dev_info(&card->gdev->dev,
914 "Broadcast not supported on %s\n",
915 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100916 rc = -EOPNOTSUPP;
917 goto out;
918 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200919 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100920 IPA_CMD_ASS_START, 0);
921 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100922 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
923 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100924 goto out;
925 }
926
Thomas Richter4d7def22015-09-18 16:06:51 +0200927 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100928 IPA_CMD_ASS_CONFIGURE, 1);
929 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100930 dev_warn(&card->gdev->dev,
931 "Setting up broadcast filtering for %s failed\n",
932 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100933 goto out;
934 }
935 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100936 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Thomas Richter4d7def22015-09-18 16:06:51 +0200937 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100938 IPA_CMD_ASS_ENABLE, 1);
939 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100940 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
941 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100942 goto out;
943 }
944 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
945out:
946 if (card->info.broadcast_capable)
947 card->dev->flags |= IFF_BROADCAST;
948 else
949 card->dev->flags &= ~IFF_BROADCAST;
950 return rc;
951}
952
Frank Blaschka4a71df52008-02-15 09:19:42 +0100953static int qeth_l3_start_ipassists(struct qeth_card *card)
954{
Carsten Otte847a50f2010-06-21 22:57:05 +0000955 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +0000956
Stefan Raspl0f547612013-01-21 02:30:20 +0000957 if (qeth_set_access_ctrl_online(card, 0))
958 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100959 qeth_l3_start_ipa_arp_processing(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +0100960 qeth_l3_start_ipa_source_mac(card); /* go on*/
961 qeth_l3_start_ipa_vlan(card); /* go on*/
962 qeth_l3_start_ipa_multicast(card); /* go on*/
963 qeth_l3_start_ipa_ipv6(card); /* go on*/
964 qeth_l3_start_ipa_broadcast(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +0100965 return 0;
966}
967
Frank Blaschka4a71df52008-02-15 09:19:42 +0100968static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
969 struct qeth_reply *reply, unsigned long data)
970{
971 struct qeth_ipa_cmd *cmd;
972
973 cmd = (struct qeth_ipa_cmd *) data;
974 if (cmd->hdr.return_code == 0)
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100975 ether_addr_copy(card->dev->dev_addr,
976 cmd->data.create_destroy_addr.unique_id);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100977 else
Joe Perches18336112012-07-12 22:33:10 -0700978 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100979
980 return 0;
981}
982
983static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
984{
985 int rc = 0;
986 struct qeth_cmd_buffer *iob;
987 struct qeth_ipa_cmd *cmd;
988
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200989 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100990
991 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
992 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100993 if (!iob)
994 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100995 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100996 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
997 card->info.unique_id;
998
999 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1000 NULL);
1001 return rc;
1002}
1003
1004static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1005 struct qeth_reply *reply, unsigned long data)
1006{
1007 struct qeth_ipa_cmd *cmd;
1008
1009 cmd = (struct qeth_ipa_cmd *) data;
1010 if (cmd->hdr.return_code == 0)
1011 card->info.unique_id = *((__u16 *)
1012 &cmd->data.create_destroy_addr.unique_id[6]);
1013 else {
1014 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1015 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001016 dev_warn(&card->gdev->dev, "The network adapter failed to "
1017 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001018 }
1019 return 0;
1020}
1021
1022static int qeth_l3_get_unique_id(struct qeth_card *card)
1023{
1024 int rc = 0;
1025 struct qeth_cmd_buffer *iob;
1026 struct qeth_ipa_cmd *cmd;
1027
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001028 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001029
1030 if (!qeth_is_supported(card, IPA_IPV6)) {
1031 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1032 UNIQUE_ID_NOT_BY_CARD;
1033 return 0;
1034 }
1035
1036 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1037 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001038 if (!iob)
1039 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001040 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001041 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1042 card->info.unique_id;
1043
1044 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1045 return rc;
1046}
1047
Ursula Braun76b11f82010-01-11 02:50:50 +00001048static int
1049qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1050 unsigned long data)
1051{
1052 struct qeth_ipa_cmd *cmd;
1053 __u16 rc;
1054
1055 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1056
1057 cmd = (struct qeth_ipa_cmd *)data;
1058 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001059 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001060 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001061 switch (cmd->data.diagass.action) {
1062 case QETH_DIAGS_CMD_TRACE_QUERY:
1063 break;
1064 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001065 switch (rc) {
1066 case 0:
1067 case IPA_RC_INVALID_SUBCMD:
1068 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1069 dev_info(&card->gdev->dev, "The HiperSockets network "
1070 "traffic analyzer is deactivated\n");
1071 break;
1072 default:
1073 break;
1074 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001075 break;
1076 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001077 switch (rc) {
1078 case 0:
1079 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1080 dev_info(&card->gdev->dev, "The HiperSockets network "
1081 "traffic analyzer is activated\n");
1082 break;
1083 case IPA_RC_HARDWARE_AUTH_ERROR:
1084 dev_warn(&card->gdev->dev, "The device is not "
1085 "authorized to run as a HiperSockets network "
1086 "traffic analyzer\n");
1087 break;
1088 case IPA_RC_TRACE_ALREADY_ACTIVE:
1089 dev_warn(&card->gdev->dev, "A HiperSockets "
1090 "network traffic analyzer is already "
1091 "active in the HiperSockets LAN\n");
1092 break;
1093 default:
1094 break;
1095 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001096 break;
1097 default:
1098 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1099 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1100 }
1101
1102 return 0;
1103}
1104
1105static int
1106qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1107{
1108 struct qeth_cmd_buffer *iob;
1109 struct qeth_ipa_cmd *cmd;
1110
1111 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1112
1113 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001114 if (!iob)
1115 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001116 cmd = __ipa_cmd(iob);
Ursula Braun76b11f82010-01-11 02:50:50 +00001117 cmd->data.diagass.subcmd_len = 16;
1118 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1119 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1120 cmd->data.diagass.action = diags_cmd;
1121 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1122}
1123
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001124static void
1125qeth_l3_add_mc_to_hash(struct qeth_card *card, struct in_device *in4_dev)
1126{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001127 struct ip_mc_list *im4;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001128 struct qeth_ipaddr *tmp, *ipm;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001129
Carsten Otte847a50f2010-06-21 22:57:05 +00001130 QETH_CARD_TEXT(card, 4, "addmc");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001131
1132 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001133 if (!tmp)
1134 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001135
Sachin Santf3aa3132010-11-26 02:41:17 +00001136 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1137 im4 = rcu_dereference(im4->next_rcu)) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001138 ip_eth_mc_map(im4->multiaddr, tmp->mac);
Hans Wippel6bee4e22017-04-07 09:15:36 +02001139 tmp->u.a4.addr = be32_to_cpu(im4->multiaddr);
Julian Wiedmannbc3ab7052017-12-01 10:14:49 +01001140 tmp->is_multicast = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001141
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001142 ipm = qeth_l3_find_addr_by_ip(card, tmp);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001143 if (ipm) {
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001144 /* for mcast, by-IP match means full match */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001145 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1146 } else {
1147 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1148 if (!ipm)
1149 continue;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001150 ether_addr_copy(ipm->mac, tmp->mac);
Hans Wippel6bee4e22017-04-07 09:15:36 +02001151 ipm->u.a4.addr = be32_to_cpu(im4->multiaddr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001152 ipm->is_multicast = 1;
1153 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1154 hash_add(card->ip_mc_htable,
1155 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1156 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001157 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001158
1159 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001160}
1161
Jiri Pirko0347af52013-01-03 22:48:58 +00001162/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001163static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1164{
1165 struct in_device *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001166 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001167
Carsten Otte847a50f2010-06-21 22:57:05 +00001168 QETH_CARD_TEXT(card, 4, "addmcvl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001169
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001170 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001171 return;
1172
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001173 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1174 struct net_device *netdev;
1175
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001176 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001177 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001178 if (netdev == NULL ||
1179 !(netdev->flags & IFF_UP))
1180 continue;
Jiri Pirko0347af52013-01-03 22:48:58 +00001181 in_dev = __in_dev_get_rcu(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001182 if (!in_dev)
1183 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001184 qeth_l3_add_mc_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001185 }
1186}
1187
1188static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1189{
1190 struct in_device *in4_dev;
1191
Carsten Otte847a50f2010-06-21 22:57:05 +00001192 QETH_CARD_TEXT(card, 4, "chkmcv4");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001193
Sachin Santf3aa3132010-11-26 02:41:17 +00001194 rcu_read_lock();
Jiri Pirko0347af52013-01-03 22:48:58 +00001195 in4_dev = __in_dev_get_rcu(card->dev);
1196 if (in4_dev == NULL)
1197 goto unlock;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001198 qeth_l3_add_mc_to_hash(card, in4_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001199 qeth_l3_add_vlan_mc(card);
Jiri Pirko0347af52013-01-03 22:48:58 +00001200unlock:
Sachin Santf3aa3132010-11-26 02:41:17 +00001201 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001202}
1203
Julian Wiedmannc0622042017-12-20 20:10:58 +01001204static void qeth_l3_add_mc6_to_hash(struct qeth_card *card,
1205 struct inet6_dev *in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001206{
1207 struct qeth_ipaddr *ipm;
1208 struct ifmcaddr6 *im6;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001209 struct qeth_ipaddr *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001210
Carsten Otte847a50f2010-06-21 22:57:05 +00001211 QETH_CARD_TEXT(card, 4, "addmc6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001212
1213 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001214 if (!tmp)
1215 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001216
Frank Blaschka4a71df52008-02-15 09:19:42 +01001217 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001218 ipv6_eth_mc_map(&im6->mca_addr, tmp->mac);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001219 memcpy(&tmp->u.a6.addr, &im6->mca_addr.s6_addr,
1220 sizeof(struct in6_addr));
1221 tmp->is_multicast = 1;
1222
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001223 ipm = qeth_l3_find_addr_by_ip(card, tmp);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001224 if (ipm) {
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001225 /* for mcast, by-IP match means full match */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001226 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1227 continue;
1228 }
1229
Frank Blaschka4a71df52008-02-15 09:19:42 +01001230 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1231 if (!ipm)
1232 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001233
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001234 ether_addr_copy(ipm->mac, tmp->mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001235 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1236 sizeof(struct in6_addr));
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001237 ipm->is_multicast = 1;
1238 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1239 hash_add(card->ip_mc_htable,
1240 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1241
Frank Blaschka4a71df52008-02-15 09:19:42 +01001242 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001243 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001244}
1245
Jiri Pirko0347af52013-01-03 22:48:58 +00001246/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001247static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1248{
1249 struct inet6_dev *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001250 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001251
Carsten Otte847a50f2010-06-21 22:57:05 +00001252 QETH_CARD_TEXT(card, 4, "admc6vl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001253
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001254 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001255 return;
1256
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001257 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1258 struct net_device *netdev;
1259
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001260 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001261 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001262 if (netdev == NULL ||
1263 !(netdev->flags & IFF_UP))
1264 continue;
1265 in_dev = in6_dev_get(netdev);
1266 if (!in_dev)
1267 continue;
1268 read_lock_bh(&in_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001269 qeth_l3_add_mc6_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001270 read_unlock_bh(&in_dev->lock);
1271 in6_dev_put(in_dev);
1272 }
1273}
1274
1275static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1276{
1277 struct inet6_dev *in6_dev;
1278
Carsten Otte847a50f2010-06-21 22:57:05 +00001279 QETH_CARD_TEXT(card, 4, "chkmcv6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001280
Frank Blaschka4a71df52008-02-15 09:19:42 +01001281 if (!qeth_is_supported(card, IPA_IPV6))
1282 return ;
1283 in6_dev = in6_dev_get(card->dev);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001284 if (!in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001285 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001286
Jiri Pirko0347af52013-01-03 22:48:58 +00001287 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001288 read_lock_bh(&in6_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001289 qeth_l3_add_mc6_to_hash(card, in6_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001290 qeth_l3_add_vlan_mc6(card);
1291 read_unlock_bh(&in6_dev->lock);
Jiri Pirko0347af52013-01-03 22:48:58 +00001292 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001293 in6_dev_put(in6_dev);
1294}
Frank Blaschka4a71df52008-02-15 09:19:42 +01001295
Patrick McHardy80d5c362013-04-19 02:04:28 +00001296static int qeth_l3_vlan_rx_add_vid(struct net_device *dev,
1297 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001298{
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001299 struct qeth_card *card = dev->ml_priv;
1300
1301 set_bit(vid, card->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001302 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001303}
1304
Patrick McHardy80d5c362013-04-19 02:04:28 +00001305static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev,
1306 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001307{
Heiko Carstens509e2562008-07-26 02:24:10 -07001308 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001309
Carsten Otte847a50f2010-06-21 22:57:05 +00001310 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001311
Ursula Braun8e98ac42009-03-24 20:57:18 +00001312 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001313 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -05001314 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +00001315 }
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001316 clear_bit(vid, card->active_vlans);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001317 qeth_l3_set_rx_mode(dev);
Jiri Pirko8e586132011-12-08 19:52:37 -05001318 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001319}
1320
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001321static void qeth_l3_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
1322 struct qeth_hdr *hdr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001323{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001324 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001325 u16 prot = (hdr->hdr.l3.flags & QETH_HDR_IPV6) ? ETH_P_IPV6 :
1326 ETH_P_IP;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001327 unsigned char tg_addr[ETH_ALEN];
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001328
1329 skb_reset_network_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001330 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1331 case QETH_CAST_MULTICAST:
Julian Wiedmannc0622042017-12-20 20:10:58 +01001332 if (prot == ETH_P_IP)
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001333 ip_eth_mc_map(ip_hdr(skb)->daddr, tg_addr);
Julian Wiedmannc0622042017-12-20 20:10:58 +01001334 else
1335 ipv6_eth_mc_map(&ipv6_hdr(skb)->daddr, tg_addr);
1336
Frank Blaschka4a71df52008-02-15 09:19:42 +01001337 card->stats.multicast++;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001338 break;
1339 case QETH_CAST_BROADCAST:
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001340 ether_addr_copy(tg_addr, card->dev->broadcast);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001341 card->stats.multicast++;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001342 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001343 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00001344 if (card->options.sniffer)
1345 skb->pkt_type = PACKET_OTHERHOST;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001346 ether_addr_copy(tg_addr, card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001347 }
Julian Wiedmann04f67392018-03-09 18:12:58 +01001348
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001349 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1350 card->dev->header_ops->create(skb, card->dev, prot,
Julian Wiedmanna8433832017-12-20 20:11:06 +01001351 tg_addr, &hdr->hdr.l3.next_hop.rx.src_mac,
Julian Wiedmannf0ea8bf2018-03-09 18:12:56 +01001352 skb->len);
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001353 else
1354 card->dev->header_ops->create(skb, card->dev, prot,
Julian Wiedmannf0ea8bf2018-03-09 18:12:56 +01001355 tg_addr, "FAKELL", skb->len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001356 }
1357
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001358 skb->protocol = eth_type_trans(skb, card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001359
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001360 /* copy VLAN tag from hdr into skb */
1361 if (!card->options.sniffer &&
1362 (hdr->hdr.l3.ext_flags & (QETH_HDR_EXT_VLAN_FRAME |
1363 QETH_HDR_EXT_INCLUDE_VLAN_TAG))) {
1364 u16 tag = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
1365 hdr->hdr.l3.vlan_id :
Julian Wiedmanna8433832017-12-20 20:11:06 +01001366 hdr->hdr.l3.next_hop.rx.vlan_id;
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001367 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001368 }
1369
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001370 if (card->dev->features & NETIF_F_RXCSUM) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001371 if ((hdr->hdr.l3.ext_flags &
Ursula Braunb9139802009-05-19 21:38:40 +00001372 (QETH_HDR_EXT_CSUM_HDR_REQ |
1373 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1374 (QETH_HDR_EXT_CSUM_HDR_REQ |
1375 QETH_HDR_EXT_CSUM_TRANSP_REQ))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001376 skb->ip_summed = CHECKSUM_UNNECESSARY;
1377 else
Ursula Braunb9139802009-05-19 21:38:40 +00001378 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001379 } else
1380 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001381}
1382
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001383static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1384 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001385{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001386 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001387 struct sk_buff *skb;
1388 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001389 unsigned int len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001390 __u16 magic;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001391
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001392 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +00001393 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001394 while (budget) {
1395 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +00001396 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001397 &card->rx.b_element, &card->rx.e_offset, &hdr);
1398 if (!skb) {
1399 *done = 1;
1400 break;
1401 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001402 switch (hdr->hdr.l3.id) {
1403 case QETH_HEADER_TYPE_LAYER3:
Frank Blaschkab3332932011-08-08 01:33:59 +00001404 magic = *(__u16 *)skb->data;
1405 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
1406 (magic == ETH_P_AF_IUCV)) {
Hans Wippel6bee4e22017-04-07 09:15:36 +02001407 skb->protocol = cpu_to_be16(ETH_P_AF_IUCV);
Frank Blaschkab3332932011-08-08 01:33:59 +00001408 len = skb->len;
1409 card->dev->header_ops->create(skb, card->dev, 0,
Julian Wiedmannf0ea8bf2018-03-09 18:12:56 +01001410 card->dev->dev_addr, "FAKELL", len);
Julian Wiedmann37cf05d2018-03-09 18:12:57 +01001411 skb_reset_mac_header(skb);
Frank Blaschkab3332932011-08-08 01:33:59 +00001412 netif_receive_skb(skb);
1413 } else {
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001414 qeth_l3_rebuild_skb(card, skb, hdr);
Frank Blaschkab3332932011-08-08 01:33:59 +00001415 len = skb->len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001416 napi_gro_receive(&card->napi, skb);
1417 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001418 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00001419 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
Ursula Braun76b11f82010-01-11 02:50:50 +00001420 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00001421 len = skb->len;
1422 netif_receive_skb(skb);
1423 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001424 default:
1425 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00001426 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001427 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001428 continue;
1429 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001430 work_done++;
1431 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001432 card->stats.rx_packets++;
1433 card->stats.rx_bytes += len;
1434 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001435 return work_done;
1436}
1437
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +02001438static void qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001439{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001440 QETH_DBF_TEXT(SETUP, 2, "stopcard");
1441 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001442
1443 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00001444 if (card->options.sniffer &&
1445 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
1446 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001447 if (card->read.state == CH_STATE_UP &&
1448 card->write.state == CH_STATE_UP &&
1449 (card->state == CARD_STATE_UP)) {
1450 if (recovery_mode)
1451 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02001452 else {
Ursula Braun869da902010-03-08 20:36:56 +00001453 rtnl_lock();
1454 dev_close(card->dev);
1455 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02001456 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001457 card->state = CARD_STATE_SOFTSETUP;
1458 }
1459 if (card->state == CARD_STATE_SOFTSETUP) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001460 qeth_l3_clear_ip_htable(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001461 qeth_clear_ipacmd_list(card);
1462 card->state = CARD_STATE_HARDSETUP;
1463 }
1464 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001465 qeth_qdio_clear_card(card, 0);
1466 qeth_clear_qdio_buffers(card);
1467 qeth_clear_working_pool_list(card);
1468 card->state = CARD_STATE_DOWN;
1469 }
1470 if (card->state == CARD_STATE_DOWN) {
1471 qeth_clear_cmd_buffers(&card->read);
1472 qeth_clear_cmd_buffers(&card->write);
1473 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001474}
1475
Ursula Braun76b11f82010-01-11 02:50:50 +00001476/*
1477 * test for and Switch promiscuous mode (on or off)
1478 * either for guestlan or HiperSocket Sniffer
1479 */
1480static void
1481qeth_l3_handle_promisc_mode(struct qeth_card *card)
1482{
1483 struct net_device *dev = card->dev;
1484
1485 if (((dev->flags & IFF_PROMISC) &&
1486 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
1487 (!(dev->flags & IFF_PROMISC) &&
1488 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
1489 return;
1490
1491 if (card->info.guestlan) { /* Guestlan trace */
1492 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
1493 qeth_setadp_promisc_mode(card);
1494 } else if (card->options.sniffer && /* HiperSockets trace */
1495 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
1496 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001497 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001498 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
1499 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00001500 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001501 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
1502 }
1503 }
1504}
1505
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001506static void qeth_l3_set_rx_mode(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001507{
Heiko Carstens509e2562008-07-26 02:24:10 -07001508 struct qeth_card *card = dev->ml_priv;
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001509 struct qeth_ipaddr *addr;
1510 struct hlist_node *tmp;
1511 int i, rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001512
Carsten Otte847a50f2010-06-21 22:57:05 +00001513 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00001514 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
1515 (card->state != CARD_STATE_UP))
1516 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00001517 if (!card->options.sniffer) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001518 spin_lock_bh(&card->mclock);
1519
Ursula Braun76b11f82010-01-11 02:50:50 +00001520 qeth_l3_add_multicast_ipv4(card);
Ursula Braun76b11f82010-01-11 02:50:50 +00001521 qeth_l3_add_multicast_ipv6(card);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001522
1523 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1524 switch (addr->disp_flag) {
1525 case QETH_DISP_ADDR_DELETE:
1526 rc = qeth_l3_deregister_addr_entry(card, addr);
1527 if (!rc || rc == IPA_RC_MC_ADDR_NOT_FOUND) {
1528 hash_del(&addr->hnode);
1529 kfree(addr);
1530 }
1531 break;
1532 case QETH_DISP_ADDR_ADD:
1533 rc = qeth_l3_register_addr_entry(card, addr);
1534 if (rc && rc != IPA_RC_LAN_OFFLINE) {
1535 hash_del(&addr->hnode);
1536 kfree(addr);
1537 break;
1538 }
1539 addr->ref_counter = 1;
1540 /* fall through */
1541 default:
1542 /* for next call to set_rx_mode(): */
1543 addr->disp_flag = QETH_DISP_ADDR_DELETE;
1544 }
1545 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001546
1547 spin_unlock_bh(&card->mclock);
1548
Ursula Braun76b11f82010-01-11 02:50:50 +00001549 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
1550 return;
1551 }
1552 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001553}
1554
1555static const char *qeth_l3_arp_get_error_cause(int *rc)
1556{
1557 switch (*rc) {
1558 case QETH_IPA_ARP_RC_FAILED:
1559 *rc = -EIO;
1560 return "operation failed";
1561 case QETH_IPA_ARP_RC_NOTSUPP:
1562 *rc = -EOPNOTSUPP;
1563 return "operation not supported";
1564 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
1565 *rc = -EINVAL;
1566 return "argument out of range";
1567 case QETH_IPA_ARP_RC_Q_NOTSUPP:
1568 *rc = -EOPNOTSUPP;
1569 return "query operation not supported";
1570 case QETH_IPA_ARP_RC_Q_NO_DATA:
1571 *rc = -ENOENT;
1572 return "no query data available";
1573 default:
1574 return "unknown error";
1575 }
1576}
1577
1578static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
1579{
1580 int tmp;
1581 int rc;
1582
Carsten Otte847a50f2010-06-21 22:57:05 +00001583 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001584
1585 /*
1586 * currently GuestLAN only supports the ARP assist function
1587 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
1588 * thus we say EOPNOTSUPP for this ARP function
1589 */
1590 if (card->info.guestlan)
1591 return -EOPNOTSUPP;
1592 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001593 return -EOPNOTSUPP;
1594 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001595 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001596 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
1597 no_entries);
1598 if (rc) {
1599 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001600 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
1601 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01001602 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
1603 }
1604 return rc;
1605}
1606
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001607static __u32 get_arp_entry_size(struct qeth_card *card,
1608 struct qeth_arp_query_data *qdata,
1609 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001610{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001611 __u32 rc;
1612 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001613
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001614 is_hsi = qdata->reply_bits == 5;
1615 if (type->ip == QETHARP_IP_ADDR_V4) {
1616 QETH_CARD_TEXT(card, 4, "arpev4");
1617 if (strip_entries) {
1618 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
1619 sizeof(struct qeth_arp_qi_entry7_short);
1620 } else {
1621 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
1622 sizeof(struct qeth_arp_qi_entry7);
1623 }
1624 } else if (type->ip == QETHARP_IP_ADDR_V6) {
1625 QETH_CARD_TEXT(card, 4, "arpev6");
1626 if (strip_entries) {
1627 rc = is_hsi ?
1628 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
1629 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
1630 } else {
1631 rc = is_hsi ?
1632 sizeof(struct qeth_arp_qi_entry5_ipv6) :
1633 sizeof(struct qeth_arp_qi_entry7_ipv6);
1634 }
1635 } else {
1636 QETH_CARD_TEXT(card, 4, "arpinv");
1637 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001638 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001639
1640 return rc;
1641}
1642
1643static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
1644{
1645 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
1646 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001647}
1648
1649static int qeth_l3_arp_query_cb(struct qeth_card *card,
1650 struct qeth_reply *reply, unsigned long data)
1651{
1652 struct qeth_ipa_cmd *cmd;
1653 struct qeth_arp_query_data *qdata;
1654 struct qeth_arp_query_info *qinfo;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001655 int i;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001656 int e;
1657 int entrybytes_done;
1658 int stripped_bytes;
1659 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001660
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001661 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001662
1663 qinfo = (struct qeth_arp_query_info *) reply->param;
1664 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001665 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001666 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001667 QETH_CARD_TEXT(card, 4, "arpcberr");
1668 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001669 return 0;
1670 }
1671 if (cmd->data.setassparms.hdr.return_code) {
1672 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001673 QETH_CARD_TEXT(card, 4, "setaperr");
1674 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001675 return 0;
1676 }
1677 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00001678 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001679
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001680 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
1681 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
1682 entrybytes_done = 0;
1683 for (e = 0; e < qdata->no_entries; ++e) {
1684 char *cur_entry;
1685 __u32 esize;
1686 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001687
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001688 cur_entry = &qdata->data + entrybytes_done;
1689 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
1690 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
1691 QETH_CARD_TEXT(card, 4, "pmis");
1692 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
1693 break;
1694 }
1695 esize = get_arp_entry_size(card, qdata, etype,
1696 do_strip_entries);
1697 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
1698 if (!esize)
1699 break;
1700
1701 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
1702 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
Ursula Braune0a81142012-03-07 02:06:28 +00001703 cmd->hdr.return_code = IPA_RC_ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001704 goto out_error;
1705 }
1706
1707 memcpy(qinfo->udata + qinfo->udata_offset,
1708 &qdata->data + entrybytes_done + stripped_bytes,
1709 esize);
1710 entrybytes_done += esize + stripped_bytes;
1711 qinfo->udata_offset += esize;
1712 ++qinfo->no_entries;
1713 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001714 /* check if all replies received ... */
1715 if (cmd->data.setassparms.hdr.seq_no <
1716 cmd->data.setassparms.hdr.number_of_replies)
1717 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001718 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001719 memcpy(qinfo->udata, &qinfo->no_entries, 4);
1720 /* keep STRIP_ENTRIES flag so the user program can distinguish
1721 * stripped entries from normal ones */
1722 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
1723 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
1724 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001725 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001726 return 0;
1727out_error:
1728 i = 0;
1729 memcpy(qinfo->udata, &i, 4);
1730 return 0;
1731}
1732
1733static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
1734 struct qeth_cmd_buffer *iob, int len,
1735 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
1736 unsigned long),
1737 void *reply_param)
1738{
Carsten Otte847a50f2010-06-21 22:57:05 +00001739 QETH_CARD_TEXT(card, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001740
1741 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
1742 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
1743 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
1744 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
1745 reply_cb, reply_param);
1746}
1747
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001748static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
1749 enum qeth_prot_versions prot,
1750 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001751{
1752 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001753 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001754 int tmp;
1755 int rc;
1756
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001757 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
1758
Thomas Richterb475e312015-12-11 12:27:54 +01001759 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
1760 IPA_CMD_ASS_ARP_QUERY_INFO,
1761 sizeof(struct qeth_arp_query_data)
1762 - sizeof(char),
1763 prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001764 if (!iob)
1765 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001766 cmd = __ipa_cmd(iob);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001767 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
1768 cmd->data.setassparms.data.query_arp.reply_bits = 0;
1769 cmd->data.setassparms.data.query_arp.no_entries = 0;
1770 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
1771 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
1772 qeth_l3_arp_query_cb, (void *)qinfo);
1773 if (rc) {
1774 tmp = rc;
1775 QETH_DBF_MESSAGE(2,
1776 "Error while querying ARP cache on %s: %s "
1777 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
1778 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
1779 }
1780
1781 return rc;
1782}
1783
1784static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
1785{
1786 struct qeth_arp_query_info qinfo = {0, };
1787 int rc;
1788
Carsten Otte847a50f2010-06-21 22:57:05 +00001789 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001790
1791 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
1792 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001793 QETH_CARD_TEXT(card, 3, "arpqnsup");
1794 rc = -EOPNOTSUPP;
1795 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001796 }
1797 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001798 if (copy_from_user(&qinfo, udata, 6)) {
1799 rc = -EFAULT;
1800 goto out;
1801 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001802 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001803 if (!qinfo.udata) {
1804 rc = -ENOMEM;
1805 goto out;
1806 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001807 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001808 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001809 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001810 if (copy_to_user(udata, qinfo.udata, 4))
1811 rc = -EFAULT;
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001812 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001813 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001814 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
1815 /* fails in case of GuestLAN QDIO mode */
1816 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6, &qinfo);
1817 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001818 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
1819 QETH_CARD_TEXT(card, 4, "qactf");
1820 rc = -EFAULT;
1821 goto free_and_out;
1822 }
1823 QETH_CARD_TEXT(card, 4, "qacts");
1824
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001825free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001826 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001827out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001828 return rc;
1829}
1830
1831static int qeth_l3_arp_add_entry(struct qeth_card *card,
1832 struct qeth_arp_cache_entry *entry)
1833{
1834 struct qeth_cmd_buffer *iob;
1835 char buf[16];
1836 int tmp;
1837 int rc;
1838
Carsten Otte847a50f2010-06-21 22:57:05 +00001839 QETH_CARD_TEXT(card, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001840
1841 /*
1842 * currently GuestLAN only supports the ARP assist function
1843 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
1844 * thus we say EOPNOTSUPP for this ARP function
1845 */
1846 if (card->info.guestlan)
1847 return -EOPNOTSUPP;
1848 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001849 return -EOPNOTSUPP;
1850 }
1851
Thomas Richterb475e312015-12-11 12:27:54 +01001852 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001853 IPA_CMD_ASS_ARP_ADD_ENTRY,
1854 sizeof(struct qeth_arp_cache_entry),
1855 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001856 if (!iob)
1857 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +02001858 rc = qeth_send_setassparms(card, iob,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001859 sizeof(struct qeth_arp_cache_entry),
1860 (unsigned long) entry,
Thomas Richter8f43fb02016-06-16 16:18:59 +02001861 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001862 if (rc) {
1863 tmp = rc;
1864 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001865 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
1866 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
1867 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001868 }
1869 return rc;
1870}
1871
1872static int qeth_l3_arp_remove_entry(struct qeth_card *card,
1873 struct qeth_arp_cache_entry *entry)
1874{
1875 struct qeth_cmd_buffer *iob;
1876 char buf[16] = {0, };
1877 int tmp;
1878 int rc;
1879
Carsten Otte847a50f2010-06-21 22:57:05 +00001880 QETH_CARD_TEXT(card, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001881
1882 /*
1883 * currently GuestLAN only supports the ARP assist function
1884 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
1885 * thus we say EOPNOTSUPP for this ARP function
1886 */
1887 if (card->info.guestlan)
1888 return -EOPNOTSUPP;
1889 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001890 return -EOPNOTSUPP;
1891 }
1892 memcpy(buf, entry, 12);
Thomas Richterb475e312015-12-11 12:27:54 +01001893 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001894 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
1895 12,
1896 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001897 if (!iob)
1898 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +02001899 rc = qeth_send_setassparms(card, iob,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001900 12, (unsigned long)buf,
Thomas Richter8f43fb02016-06-16 16:18:59 +02001901 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001902 if (rc) {
1903 tmp = rc;
1904 memset(buf, 0, 16);
1905 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001906 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
1907 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
1908 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001909 }
1910 return rc;
1911}
1912
1913static int qeth_l3_arp_flush_cache(struct qeth_card *card)
1914{
1915 int rc;
1916 int tmp;
1917
Carsten Otte847a50f2010-06-21 22:57:05 +00001918 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001919
1920 /*
1921 * currently GuestLAN only supports the ARP assist function
1922 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
1923 * thus we say EOPNOTSUPP for this ARP function
1924 */
1925 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
1926 return -EOPNOTSUPP;
1927 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001928 return -EOPNOTSUPP;
1929 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001930 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001931 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
1932 if (rc) {
1933 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001934 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
1935 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01001936 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
1937 }
1938 return rc;
1939}
1940
1941static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1942{
Heiko Carstens509e2562008-07-26 02:24:10 -07001943 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001944 struct qeth_arp_cache_entry arp_entry;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001945 int rc = 0;
1946
Frank Blaschka4a71df52008-02-15 09:19:42 +01001947 switch (cmd) {
1948 case SIOC_QETH_ARP_SET_NO_ENTRIES:
1949 if (!capable(CAP_NET_ADMIN)) {
1950 rc = -EPERM;
1951 break;
1952 }
1953 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
1954 break;
1955 case SIOC_QETH_ARP_QUERY_INFO:
1956 if (!capable(CAP_NET_ADMIN)) {
1957 rc = -EPERM;
1958 break;
1959 }
1960 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
1961 break;
1962 case SIOC_QETH_ARP_ADD_ENTRY:
1963 if (!capable(CAP_NET_ADMIN)) {
1964 rc = -EPERM;
1965 break;
1966 }
1967 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
1968 sizeof(struct qeth_arp_cache_entry)))
1969 rc = -EFAULT;
1970 else
1971 rc = qeth_l3_arp_add_entry(card, &arp_entry);
1972 break;
1973 case SIOC_QETH_ARP_REMOVE_ENTRY:
1974 if (!capable(CAP_NET_ADMIN)) {
1975 rc = -EPERM;
1976 break;
1977 }
1978 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
1979 sizeof(struct qeth_arp_cache_entry)))
1980 rc = -EFAULT;
1981 else
1982 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
1983 break;
1984 case SIOC_QETH_ARP_FLUSH_CACHE:
1985 if (!capable(CAP_NET_ADMIN)) {
1986 rc = -EPERM;
1987 break;
1988 }
1989 rc = qeth_l3_arp_flush_cache(card);
1990 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001991 default:
1992 rc = -EOPNOTSUPP;
1993 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001994 return rc;
1995}
1996
Julian Wiedmann1f979122017-12-20 20:11:04 +01001997static int qeth_l3_get_cast_type(struct sk_buff *skb)
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001998{
David S. Miller69cce1d2011-07-17 23:09:49 -07001999 struct neighbour *n = NULL;
2000 struct dst_entry *dst;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002001
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002002 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002003 dst = skb_dst(skb);
2004 if (dst)
David S. Miller24db1ba2012-07-02 22:02:33 -07002005 n = dst_neigh_lookup_skb(dst, skb);
David S. Miller69cce1d2011-07-17 23:09:49 -07002006 if (n) {
Julian Wiedmann1f979122017-12-20 20:11:04 +01002007 int cast_type = n->type;
2008
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002009 rcu_read_unlock();
David S. Miller24db1ba2012-07-02 22:02:33 -07002010 neigh_release(n);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002011 if ((cast_type == RTN_BROADCAST) ||
2012 (cast_type == RTN_MULTICAST) ||
2013 (cast_type == RTN_ANYCAST))
2014 return cast_type;
Julian Wiedmann1f979122017-12-20 20:11:04 +01002015 return RTN_UNSPEC;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002016 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002017 rcu_read_unlock();
2018
Julian Wiedmann1f979122017-12-20 20:11:04 +01002019 /* no neighbour (eg AF_PACKET), fall back to target's IP address ... */
Hans Wippel6bee4e22017-04-07 09:15:36 +02002020 if (be16_to_cpu(skb->protocol) == ETH_P_IPV6)
Julian Wiedmann1f979122017-12-20 20:11:04 +01002021 return ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr) ?
2022 RTN_MULTICAST : RTN_UNSPEC;
Hans Wippel6bee4e22017-04-07 09:15:36 +02002023 else if (be16_to_cpu(skb->protocol) == ETH_P_IP)
Julian Wiedmann1f979122017-12-20 20:11:04 +01002024 return ipv4_is_multicast(ip_hdr(skb)->daddr) ?
2025 RTN_MULTICAST : RTN_UNSPEC;
2026
2027 /* ... and MAC address */
Julian Wiedmann99f0b852017-12-20 20:11:01 +01002028 if (ether_addr_equal_64bits(eth_hdr(skb)->h_dest, skb->dev->broadcast))
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002029 return RTN_BROADCAST;
Julian Wiedmanna65d1412017-12-20 20:11:05 +01002030 if (is_multicast_ether_addr(eth_hdr(skb)->h_dest))
Julian Wiedmann1f979122017-12-20 20:11:04 +01002031 return RTN_MULTICAST;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002032
Julian Wiedmann1f979122017-12-20 20:11:04 +01002033 /* default to unicast */
2034 return RTN_UNSPEC;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002035}
2036
Frank Blaschkab3332932011-08-08 01:33:59 +00002037static void qeth_l3_fill_af_iucv_hdr(struct qeth_card *card,
2038 struct qeth_hdr *hdr, struct sk_buff *skb)
2039{
2040 char daddr[16];
2041 struct af_iucv_trans_hdr *iucv_hdr;
2042
Frank Blaschkab3332932011-08-08 01:33:59 +00002043 memset(hdr, 0, sizeof(struct qeth_hdr));
2044 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2045 hdr->hdr.l3.ext_flags = 0;
Julian Wiedmannacd97762017-03-23 14:55:09 +01002046 hdr->hdr.l3.length = skb->len - ETH_HLEN;
Frank Blaschkab3332932011-08-08 01:33:59 +00002047 hdr->hdr.l3.flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
Julian Wiedmannacd97762017-03-23 14:55:09 +01002048
2049 iucv_hdr = (struct af_iucv_trans_hdr *) (skb->data + ETH_HLEN);
Frank Blaschkab3332932011-08-08 01:33:59 +00002050 memset(daddr, 0, sizeof(daddr));
2051 daddr[0] = 0xfe;
2052 daddr[1] = 0x80;
2053 memcpy(&daddr[8], iucv_hdr->destUserID, 8);
Julian Wiedmanna8433832017-12-20 20:11:06 +01002054 memcpy(hdr->hdr.l3.next_hop.ipv6_addr, daddr, 16);
Frank Blaschkab3332932011-08-08 01:33:59 +00002055}
2056
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002057static u8 qeth_l3_cast_type_to_flag(int cast_type)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002058{
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002059 if (cast_type == RTN_MULTICAST)
2060 return QETH_CAST_MULTICAST;
2061 if (cast_type == RTN_ANYCAST)
2062 return QETH_CAST_ANYCAST;
2063 if (cast_type == RTN_BROADCAST)
2064 return QETH_CAST_BROADCAST;
2065 return QETH_CAST_UNICAST;
2066}
David S. Miller69cce1d2011-07-17 23:09:49 -07002067
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002068static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
Julian Wiedmannf6c13142017-12-20 20:11:08 +01002069 struct sk_buff *skb, int ipv, int cast_type,
2070 unsigned int data_len)
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002071{
Frank Blaschka4a71df52008-02-15 09:19:42 +01002072 memset(hdr, 0, sizeof(struct qeth_hdr));
2073 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
Julian Wiedmannf6c13142017-12-20 20:11:08 +01002074 hdr->hdr.l3.length = data_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002075
2076 /*
2077 * before we're going to overwrite this location with next hop ip.
2078 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2079 */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002080 if (skb_vlan_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002081 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2082 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2083 else
2084 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002085 hdr->hdr.l3.vlan_id = skb_vlan_tag_get(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002086 }
2087
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002088 /* OSA only: */
2089 if (!ipv) {
2090 hdr->hdr.l3.flags = QETH_HDR_PASSTHRU;
2091 if (ether_addr_equal_64bits(eth_hdr(skb)->h_dest,
2092 skb->dev->broadcast))
2093 hdr->hdr.l3.flags |= QETH_CAST_BROADCAST;
2094 else
2095 hdr->hdr.l3.flags |= (cast_type == RTN_MULTICAST) ?
2096 QETH_CAST_MULTICAST : QETH_CAST_UNICAST;
2097 return;
2098 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002099
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002100 hdr->hdr.l3.flags = qeth_l3_cast_type_to_flag(cast_type);
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002101 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002102 if (ipv == 4) {
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002103 struct rtable *rt = skb_rtable(skb);
David Miller87e75972012-02-01 10:49:17 +00002104
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002105 *((__be32 *) &hdr->hdr.l3.next_hop.ipv4.addr) = (rt) ?
2106 rt_nexthop(rt, ip_hdr(skb)->daddr) :
2107 ip_hdr(skb)->daddr;
2108 } else {
2109 /* IPv6 */
2110 const struct rt6_info *rt = skb_rt6_info(skb);
2111 const struct in6_addr *next_hop;
David Miller87e75972012-02-01 10:49:17 +00002112
Julian Wiedmannec2c6722017-08-07 13:28:39 +02002113 if (rt && !ipv6_addr_any(&rt->rt6i_gateway))
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002114 next_hop = &rt->rt6i_gateway;
2115 else
2116 next_hop = &ipv6_hdr(skb)->daddr;
2117 memcpy(hdr->hdr.l3.next_hop.ipv6_addr, next_hop, 16);
David Miller87e75972012-02-01 10:49:17 +00002118
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002119 hdr->hdr.l3.flags |= QETH_HDR_IPV6;
2120 if (card->info.type != QETH_CARD_TYPE_IQD)
2121 hdr->hdr.l3.flags |= QETH_HDR_PASSTHRU;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002122 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002123 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002124}
2125
Julian Wiedmanncef6ff222017-08-15 17:02:46 +02002126static void qeth_l3_hdr_csum(struct qeth_card *card, struct qeth_hdr *hdr,
2127 struct sk_buff *skb)
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002128{
2129 struct iphdr *iph = ip_hdr(skb);
2130
2131 /* tcph->check contains already the pseudo hdr checksum
2132 * so just set the header flags
2133 */
2134 if (iph->protocol == IPPROTO_UDP)
2135 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
Frank Blaschka16c0f932011-01-12 20:42:25 +00002136 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
2137 QETH_HDR_EXT_CSUM_HDR_REQ;
2138 iph->check = 0;
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002139 if (card->options.performance_stats)
2140 card->perf_stats.tx_csum++;
2141}
2142
Frank Blaschka64ef8952009-03-24 20:57:16 +00002143static void qeth_tso_fill_header(struct qeth_card *card,
2144 struct qeth_hdr *qhdr, struct sk_buff *skb)
2145{
2146 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2147 struct tcphdr *tcph = tcp_hdr(skb);
2148 struct iphdr *iph = ip_hdr(skb);
2149 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2150
2151 /*fix header to TSO values ...*/
2152 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
2153 /*set values which are fix for the first approach ...*/
2154 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2155 hdr->ext.imb_hdr_no = 1;
2156 hdr->ext.hdr_type = 1;
2157 hdr->ext.hdr_version = 1;
2158 hdr->ext.hdr_len = 28;
2159 /*insert non-fix values */
2160 hdr->ext.mss = skb_shinfo(skb)->gso_size;
Julian Wiedmannf8eb4932017-08-15 17:02:45 +02002161 hdr->ext.dg_hdr_len = (__u16)(ip_hdrlen(skb) + tcp_hdrlen(skb));
Frank Blaschka64ef8952009-03-24 20:57:16 +00002162 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2163 sizeof(struct qeth_hdr_tso));
2164 tcph->check = 0;
Hans Wippel6bee4e22017-04-07 09:15:36 +02002165 if (be16_to_cpu(skb->protocol) == ETH_P_IPV6) {
Frank Blaschka64ef8952009-03-24 20:57:16 +00002166 ip6h->payload_len = 0;
2167 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2168 0, IPPROTO_TCP, 0);
2169 } else {
2170 /*OSA want us to set these values ...*/
2171 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2172 0, IPPROTO_TCP, 0);
2173 iph->tot_len = 0;
2174 iph->check = 0;
2175 }
2176}
2177
Eugene Crosser2863c612016-06-16 16:18:52 +02002178/**
Eugene Crosser41aeed52016-06-16 16:18:53 +02002179 * qeth_l3_get_elements_no_tso() - find number of SBALEs for skb data for tso
2180 * @card: qeth card structure, to check max. elems.
2181 * @skb: SKB address
2182 * @extra_elems: extra elems needed, to check against max.
Eugene Crosser2863c612016-06-16 16:18:52 +02002183 *
2184 * Returns the number of pages, and thus QDIO buffer elements, needed to cover
2185 * skb data, including linear part and fragments, but excluding TCP header.
2186 * (Exclusion of TCP header distinguishes it from qeth_get_elements_no().)
2187 * Checks if the result plus extra_elems fits under the limit for the card.
2188 * Returns 0 if it does not.
2189 * Note: extra_elems is not included in the returned result.
2190 */
Eugene Crosser41aeed52016-06-16 16:18:53 +02002191static int qeth_l3_get_elements_no_tso(struct qeth_card *card,
Eugene Crosser2863c612016-06-16 16:18:52 +02002192 struct sk_buff *skb, int extra_elems)
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002193{
Julian Wiedmann12472af2018-02-27 18:58:12 +01002194 addr_t start = (addr_t)tcp_hdr(skb) + tcp_hdrlen(skb);
2195 addr_t end = (addr_t)skb->data + skb_headlen(skb);
2196 int elements = qeth_get_elements_for_frags(skb);
2197
2198 if (start != end)
2199 elements += qeth_get_elements_for_range(start, end);
Frank Blaschka271648b2013-03-18 20:04:44 +00002200
Eugene Crosser2863c612016-06-16 16:18:52 +02002201 if ((elements + extra_elems) > QETH_MAX_BUFFER_ELEMENTS(card)) {
2202 QETH_DBF_MESSAGE(2,
2203 "Invalid size of TSO IP packet (Number=%d / Length=%d). Discarded.\n",
2204 elements + extra_elems, skb->len);
2205 return 0;
2206 }
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002207 return elements;
2208}
2209
Julian Wiedmanne38db6b2017-04-11 16:11:14 +02002210static netdev_tx_t qeth_l3_hard_start_xmit(struct sk_buff *skb,
2211 struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002212{
2213 int rc;
Hans Wippel6bee4e22017-04-07 09:15:36 +02002214 __be16 *tag;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002215 struct qeth_hdr *hdr = NULL;
Eugene Crosser2863c612016-06-16 16:18:52 +02002216 int hdr_elements = 0;
2217 int elements;
Heiko Carstens509e2562008-07-26 02:24:10 -07002218 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002219 struct sk_buff *new_skb = NULL;
2220 int ipv = qeth_get_ip_version(skb);
Julian Wiedmann1f979122017-12-20 20:11:04 +01002221 int cast_type = qeth_l3_get_cast_type(skb);
Stefan Raspl290b8342014-04-28 10:05:08 +02002222 struct qeth_qdio_out_q *queue =
2223 card->qdio.out_qs[card->qdio.do_prio_queueing
2224 || (cast_type && card->info.is_multicast_different) ?
2225 qeth_get_priority_queue(card, skb, ipv, cast_type) :
2226 card->qdio.default_out_queue];
Frank Blaschka4a71df52008-02-15 09:19:42 +01002227 int tx_bytes = skb->len;
Julian Wiedmann13ddacb2017-08-18 10:19:06 +02002228 unsigned int hd_len = 0;
Eugene Crosser41aeed52016-06-16 16:18:53 +02002229 bool use_tso;
Frank Blaschka683d7182008-08-01 16:39:13 +02002230 int data_offset = -1;
Julian Wiedmann886e1972017-08-15 17:02:39 +02002231 unsigned int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002232
Frank Blaschkab3332932011-08-08 01:33:59 +00002233 if (((card->info.type == QETH_CARD_TYPE_IQD) &&
2234 (((card->options.cq != QETH_CQ_ENABLED) && !ipv) ||
2235 ((card->options.cq == QETH_CQ_ENABLED) &&
Hans Wippel6bee4e22017-04-07 09:15:36 +02002236 (be16_to_cpu(skb->protocol) != ETH_P_AF_IUCV)))) ||
Frank Blaschkab3332932011-08-08 01:33:59 +00002237 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002238 goto tx_drop;
2239
2240 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2241 card->stats.tx_carrier_errors++;
2242 goto tx_drop;
2243 }
2244
2245 if ((cast_type == RTN_BROADCAST) &&
2246 (card->info.broadcast_capable == 0))
2247 goto tx_drop;
2248
2249 if (card->options.performance_stats) {
2250 card->perf_stats.outbound_cnt++;
2251 card->perf_stats.outbound_start_time = qeth_get_micros();
2252 }
2253
Eugene Crosser41aeed52016-06-16 16:18:53 +02002254 /* Ignore segment size from skb_is_gso(), 1 page is always used. */
2255 use_tso = skb_is_gso(skb) &&
Julian Wiedmannf8eb4932017-08-15 17:02:45 +02002256 (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4);
Frank Blaschka683d7182008-08-01 16:39:13 +02002257
Julian Wiedmann94a9c982017-06-06 14:33:43 +02002258 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02002259 new_skb = skb;
Julian Wiedmannacd97762017-03-23 14:55:09 +01002260 data_offset = ETH_HLEN;
Julian Wiedmannf1588172017-08-18 10:19:08 +02002261 hd_len = sizeof(*hdr);
Frank Blaschka683d7182008-08-01 16:39:13 +02002262 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2263 if (!hdr)
2264 goto tx_drop;
Eugene Crosser2863c612016-06-16 16:18:52 +02002265 hdr_elements++;
Frank Blaschka683d7182008-08-01 16:39:13 +02002266 } else {
2267 /* create a clone with writeable headroom */
2268 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
2269 + VLAN_HLEN);
2270 if (!new_skb)
2271 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002272
Frank Blaschka21fde742010-03-08 20:36:54 +00002273 if (ipv == 4) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002274 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002275 }
2276
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002277 if (ipv != 4 && skb_vlan_tag_present(new_skb)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002278 skb_push(new_skb, VLAN_HLEN);
2279 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2280 skb_copy_to_linear_data_offset(new_skb, 4,
2281 new_skb->data + 8, 4);
2282 skb_copy_to_linear_data_offset(new_skb, 8,
2283 new_skb->data + 12, 4);
Hans Wippel6bee4e22017-04-07 09:15:36 +02002284 tag = (__be16 *)(new_skb->data + 12);
2285 *tag = cpu_to_be16(ETH_P_8021Q);
2286 *(tag + 1) = cpu_to_be16(skb_vlan_tag_get(new_skb));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002287 }
2288 }
2289
2290 netif_stop_queue(dev);
2291
Frank Blaschka4a71df52008-02-15 09:19:42 +01002292 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00002293 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01002294 */
Eugene Crosser41aeed52016-06-16 16:18:53 +02002295 if ((card->info.type != QETH_CARD_TYPE_IQD) &&
2296 ((use_tso && !qeth_l3_get_elements_no_tso(card, new_skb, 1)) ||
Julian Wiedmann7d969d22017-03-23 14:55:08 +01002297 (!use_tso && !qeth_get_elements_no(card, new_skb, 0, 0)))) {
Eugene Crosser6059c902016-06-16 16:18:57 +02002298 int lin_rc = skb_linearize(new_skb);
2299
2300 if (card->options.performance_stats) {
2301 if (lin_rc)
2302 card->perf_stats.tx_linfail++;
2303 else
2304 card->perf_stats.tx_lin++;
2305 }
2306 if (lin_rc)
Eugene Crosser41aeed52016-06-16 16:18:53 +02002307 goto tx_drop;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002308 }
Julian Wiedmann886e1972017-08-15 17:02:39 +02002309 nr_frags = skb_shinfo(new_skb)->nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002310
Eugene Crosser41aeed52016-06-16 16:18:53 +02002311 if (use_tso) {
Johannes Bergd58ff352017-06-16 14:29:23 +02002312 hdr = skb_push(new_skb, sizeof(struct qeth_hdr_tso));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002313 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
Julian Wiedmannf6c13142017-12-20 20:11:08 +01002314 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type,
2315 new_skb->len - sizeof(struct qeth_hdr_tso));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002316 qeth_tso_fill_header(card, hdr, new_skb);
Eugene Crosser2863c612016-06-16 16:18:52 +02002317 hdr_elements++;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002318 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02002319 if (data_offset < 0) {
Johannes Bergd58ff352017-06-16 14:29:23 +02002320 hdr = skb_push(new_skb, sizeof(struct qeth_hdr));
Julian Wiedmannf6c13142017-12-20 20:11:08 +01002321 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type,
2322 new_skb->len -
2323 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02002324 } else {
Hans Wippel6bee4e22017-04-07 09:15:36 +02002325 if (be16_to_cpu(new_skb->protocol) == ETH_P_AF_IUCV)
Frank Blaschkab3332932011-08-08 01:33:59 +00002326 qeth_l3_fill_af_iucv_hdr(card, hdr, new_skb);
2327 else {
2328 qeth_l3_fill_header(card, hdr, new_skb, ipv,
Julian Wiedmannf6c13142017-12-20 20:11:08 +01002329 cast_type,
2330 new_skb->len - data_offset);
Frank Blaschkab3332932011-08-08 01:33:59 +00002331 }
Frank Blaschka683d7182008-08-01 16:39:13 +02002332 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002333
2334 if (skb->ip_summed == CHECKSUM_PARTIAL)
2335 qeth_l3_hdr_csum(card, hdr, new_skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002336 }
2337
Eugene Crosser41aeed52016-06-16 16:18:53 +02002338 elements = use_tso ?
2339 qeth_l3_get_elements_no_tso(card, new_skb, hdr_elements) :
Julian Wiedmann7d969d22017-03-23 14:55:08 +01002340 qeth_get_elements_no(card, new_skb, hdr_elements,
2341 (data_offset > 0) ? data_offset : 0);
Eugene Crosser2863c612016-06-16 16:18:52 +02002342 if (!elements) {
Frank Blaschka64ef8952009-03-24 20:57:16 +00002343 if (data_offset >= 0)
2344 kmem_cache_free(qeth_core_header_cache, hdr);
2345 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002346 }
Eugene Crosser2863c612016-06-16 16:18:52 +02002347 elements += hdr_elements;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002348
Frank Blaschka51aa1652010-06-21 22:57:10 +00002349 if (card->info.type != QETH_CARD_TYPE_IQD) {
2350 int len;
Julian Wiedmann13ddacb2017-08-18 10:19:06 +02002351 if (use_tso) {
2352 hd_len = sizeof(struct qeth_hdr_tso) +
2353 ip_hdrlen(new_skb) + tcp_hdrlen(new_skb);
2354 len = hd_len;
2355 } else {
Frank Blaschka51aa1652010-06-21 22:57:10 +00002356 len = sizeof(struct qeth_hdr_layer3);
Julian Wiedmann13ddacb2017-08-18 10:19:06 +02002357 }
Frank Blaschka51aa1652010-06-21 22:57:10 +00002358
Stefan Raspld4ae1f52013-04-22 01:12:29 +00002359 if (qeth_hdr_chk_and_bounce(new_skb, &hdr, len))
Frank Blaschka51aa1652010-06-21 22:57:10 +00002360 goto tx_drop;
Julian Wiedmann13ddacb2017-08-18 10:19:06 +02002361 rc = qeth_do_send_packet(card, queue, new_skb, hdr, hd_len,
Julian Wiedmann9c3bfda2017-08-18 10:19:07 +02002362 hd_len, elements);
Frank Blaschka51aa1652010-06-21 22:57:10 +00002363 } else
Julian Wiedmann7c2e9ba2017-09-18 21:18:18 +02002364 rc = qeth_do_send_packet_fast(queue, new_skb, hdr, data_offset,
2365 hd_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002366
2367 if (!rc) {
2368 card->stats.tx_packets++;
2369 card->stats.tx_bytes += tx_bytes;
2370 if (new_skb != skb)
2371 dev_kfree_skb_any(skb);
2372 if (card->options.performance_stats) {
Eugene Crosser41aeed52016-06-16 16:18:53 +02002373 if (use_tso) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002374 card->perf_stats.large_send_bytes += tx_bytes;
2375 card->perf_stats.large_send_cnt++;
2376 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00002377 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002378 card->perf_stats.sg_skbs_sent++;
2379 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00002380 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002381 }
2382 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07002383 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002384 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02002385 if (data_offset >= 0)
2386 kmem_cache_free(qeth_core_header_cache, hdr);
2387
Frank Blaschka4a71df52008-02-15 09:19:42 +01002388 if (rc == -EBUSY) {
2389 if (new_skb != skb)
2390 dev_kfree_skb_any(new_skb);
2391 return NETDEV_TX_BUSY;
2392 } else
2393 goto tx_drop;
2394 }
2395
2396 netif_wake_queue(dev);
2397 if (card->options.performance_stats)
2398 card->perf_stats.outbound_time += qeth_get_micros() -
2399 card->perf_stats.outbound_start_time;
2400 return rc;
2401
2402tx_drop:
2403 card->stats.tx_dropped++;
2404 card->stats.tx_errors++;
2405 if ((new_skb != skb) && new_skb)
2406 dev_kfree_skb_any(new_skb);
2407 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02002408 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002409 return NETDEV_TX_OK;
2410}
2411
Ursula Braun39423442011-01-12 20:42:24 +00002412static int __qeth_l3_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002413{
Heiko Carstens509e2562008-07-26 02:24:10 -07002414 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002415 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002416
Carsten Otte847a50f2010-06-21 22:57:05 +00002417 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +00002418 if (card->state == CARD_STATE_UP)
2419 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002420 if (card->state != CARD_STATE_SOFTSETUP)
2421 return -ENODEV;
2422 card->data.state = CH_STATE_UP;
2423 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002424 netif_start_queue(dev);
2425
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002426 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
2427 napi_enable(&card->napi);
2428 napi_schedule(&card->napi);
2429 } else
2430 rc = -EIO;
2431 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002432}
2433
Ursula Braun39423442011-01-12 20:42:24 +00002434static int qeth_l3_open(struct net_device *dev)
2435{
2436 struct qeth_card *card = dev->ml_priv;
2437
2438 QETH_CARD_TEXT(card, 5, "qethope_");
2439 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
2440 QETH_CARD_TEXT(card, 3, "openREC");
2441 return -ERESTARTSYS;
2442 }
2443 return __qeth_l3_open(dev);
2444}
2445
Frank Blaschka4a71df52008-02-15 09:19:42 +01002446static int qeth_l3_stop(struct net_device *dev)
2447{
Heiko Carstens509e2562008-07-26 02:24:10 -07002448 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002449
Carsten Otte847a50f2010-06-21 22:57:05 +00002450 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002451 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002452 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002453 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002454 napi_disable(&card->napi);
2455 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002456 return 0;
2457}
2458
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07002459static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002460 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002461 .get_strings = qeth_core_get_strings,
2462 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00002463 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002464 .get_drvinfo = qeth_core_get_drvinfo,
Julian Wiedmann993e19c2017-04-11 16:11:17 +02002465 .get_link_ksettings = qeth_core_ethtool_get_link_ksettings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002466};
2467
2468/*
2469 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
2470 * NOARP on the netdevice is no option because it also turns off neighbor
2471 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
2472 * arp resolution but we want the hard header (packet socket will work
2473 * e.g. tcpdump)
2474 */
2475static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
2476{
2477 n->nud_state = NUD_NOARP;
2478 memcpy(n->ha, "FAKELL", 6);
2479 n->output = n->ops->connected_output;
2480 return 0;
2481}
2482
2483static int
2484qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
2485{
2486 if (np->tbl->family == AF_INET)
2487 np->neigh_setup = qeth_l3_neigh_setup_noarp;
2488
2489 return 0;
2490}
2491
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002492static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08002493 .ndo_open = qeth_l3_open,
2494 .ndo_stop = qeth_l3_stop,
2495 .ndo_get_stats = qeth_get_stats,
2496 .ndo_start_xmit = qeth_l3_hard_start_xmit,
2497 .ndo_validate_addr = eth_validate_addr,
Julian Wiedmann00c163f2017-12-20 20:11:02 +01002498 .ndo_set_rx_mode = qeth_l3_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002499 .ndo_do_ioctl = qeth_do_ioctl,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002500 .ndo_change_mtu = qeth_change_mtu,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002501 .ndo_fix_features = qeth_fix_features,
2502 .ndo_set_features = qeth_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08002503 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2504 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002505 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka8403b132009-01-08 10:50:55 -08002506};
2507
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002508static const struct net_device_ops qeth_l3_osa_netdev_ops = {
2509 .ndo_open = qeth_l3_open,
2510 .ndo_stop = qeth_l3_stop,
2511 .ndo_get_stats = qeth_get_stats,
2512 .ndo_start_xmit = qeth_l3_hard_start_xmit,
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +01002513 .ndo_features_check = qeth_features_check,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002514 .ndo_validate_addr = eth_validate_addr,
Julian Wiedmann00c163f2017-12-20 20:11:02 +01002515 .ndo_set_rx_mode = qeth_l3_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002516 .ndo_do_ioctl = qeth_do_ioctl,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002517 .ndo_change_mtu = qeth_change_mtu,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002518 .ndo_fix_features = qeth_fix_features,
2519 .ndo_set_features = qeth_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002520 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2521 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002522 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002523 .ndo_neigh_setup = qeth_l3_neigh_setup,
2524};
2525
Frank Blaschka4a71df52008-02-15 09:19:42 +01002526static int qeth_l3_setup_netdev(struct qeth_card *card)
2527{
Thomas Richter1aec42b2015-01-21 13:39:10 +01002528 int rc;
2529
Ursula Braun5113fec2010-05-16 21:15:14 +00002530 if (card->info.type == QETH_CARD_TYPE_OSD ||
2531 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002532 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
2533 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002534 pr_info("qeth_l3: ignoring TR device\n");
2535 return -ENODEV;
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002536 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002537
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002538 card->dev = alloc_etherdev(0);
2539 if (!card->dev)
2540 return -ENODEV;
2541 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Julian Wiedmann0f342942018-03-09 18:12:54 +01002542
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002543 /*IPv6 address autoconfiguration stuff*/
2544 qeth_l3_get_unique_id(card);
2545 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
2546 card->dev->dev_id = card->info.unique_id & 0xffff;
Julian Wiedmann0f342942018-03-09 18:12:54 +01002547
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002548 card->dev->hw_features |= NETIF_F_SG;
2549 card->dev->vlan_features |= NETIF_F_SG;
2550
2551 if (!card->info.guestlan) {
2552 card->dev->features |= NETIF_F_SG;
2553 card->dev->hw_features |= NETIF_F_TSO |
2554 NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
2555 card->dev->vlan_features |= NETIF_F_TSO |
2556 NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002557 }
2558 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
Tom Gundersenc835a672014-07-14 16:37:24 +02002559 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
2560 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002561 if (!card->dev)
2562 return -ENODEV;
2563 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002564 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Thomas Richter1aec42b2015-01-21 13:39:10 +01002565 rc = qeth_l3_iqd_read_initial_mac(card);
2566 if (rc)
2567 return rc;
Frank Blaschkab3332932011-08-08 01:33:59 +00002568 if (card->options.hsuid[0])
2569 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002570 } else
2571 return -ENODEV;
2572
Heiko Carstens509e2562008-07-26 02:24:10 -07002573 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002574 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002575 card->dev->mtu = card->info.initial_mtu;
Jarod Wilson46b3ef42016-10-20 13:55:23 -04002576 card->dev->min_mtu = 64;
2577 card->dev->max_mtu = ETH_MAX_MTU;
Ursula Braun71c46892018-04-26 09:42:15 +02002578 card->dev->dev_port = card->info.portno;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002579 card->dev->ethtool_ops = &qeth_l3_ethtool_ops;
Patrick McHardyf6469682013-04-19 02:04:27 +00002580 card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2581 NETIF_F_HW_VLAN_CTAG_RX |
2582 NETIF_F_HW_VLAN_CTAG_FILTER;
Eric Dumazet02875872014-10-05 18:38:35 -07002583 netif_keep_dst(card->dev);
Julian Wiedmann0cbff6d2017-12-01 10:14:51 +01002584 netif_set_gso_max_size(card->dev, (QETH_MAX_BUFFER_ELEMENTS(card) - 1) *
2585 PAGE_SIZE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002586
2587 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Julian Wiedmannd73ef322017-04-11 16:11:11 +02002588 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Ursula Braune5ebe632015-12-11 12:27:55 +01002589 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002590 return register_netdev(card->dev);
2591}
2592
Ursula Braun79a04e42017-06-06 14:33:49 +02002593static const struct device_type qeth_l3_devtype = {
2594 .name = "qeth_layer3",
2595 .groups = qeth_l3_attr_groups,
2596};
2597
Frank Blaschka4a71df52008-02-15 09:19:42 +01002598static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
2599{
2600 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +02002601 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002602
Ursula Braun79a04e42017-06-06 14:33:49 +02002603 if (gdev->dev.type == &qeth_generic_devtype) {
2604 rc = qeth_l3_create_device_attributes(&gdev->dev);
2605 if (rc)
2606 return rc;
2607 }
Ursula Braunebccc7392017-05-10 19:07:54 +02002608 hash_init(card->ip_htable);
2609 hash_init(card->ip_mc_htable);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002610 card->options.layer2 = 0;
Frank Blaschka1da74b12011-05-12 18:45:02 +00002611 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002612 return 0;
2613}
2614
2615static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
2616{
2617 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
2618
Ursula Braun79a04e42017-06-06 14:33:49 +02002619 if (cgdev->dev.type == &qeth_generic_devtype)
2620 qeth_l3_remove_device_attributes(&cgdev->dev);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002621
Ursula Braunf2148562009-05-19 21:38:37 +00002622 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002623 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
2624
Ursula Braun70919e22011-02-26 22:41:36 -08002625 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002626 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002627
2628 if (card->dev) {
2629 unregister_netdev(card->dev);
Julian Wiedmann6be68732018-03-20 07:59:12 +01002630 free_netdev(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002631 card->dev = NULL;
2632 }
2633
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002634 qeth_l3_clear_ip_htable(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002635 qeth_l3_clear_ipato_list(card);
2636 return;
2637}
2638
2639static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
2640{
2641 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
2642 int rc = 0;
2643 enum qeth_card_states recover_flag;
2644
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002645 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002646 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002647 QETH_DBF_TEXT(SETUP, 2, "setonlin");
2648 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002649
Frank Blaschka4a71df52008-02-15 09:19:42 +01002650 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002651 rc = qeth_core_hardsetup_card(card);
2652 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01002653 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00002654 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002655 goto out_remove;
2656 }
2657
Ursula Braunaa909222009-11-12 00:11:43 +00002658 if (!card->dev && qeth_l3_setup_netdev(card)) {
2659 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002660 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00002661 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002662
Frank Blaschka1da74b12011-05-12 18:45:02 +00002663 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
2664 if (card->info.hwtrap &&
2665 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
2666 card->info.hwtrap = 0;
2667 } else
2668 card->info.hwtrap = 0;
2669
Frank Blaschka4a71df52008-02-15 09:19:42 +01002670 card->state = CARD_STATE_HARDSETUP;
2671 qeth_print_status_message(card);
2672
2673 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002674 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002675
Frank Blaschka4a71df52008-02-15 09:19:42 +01002676 rc = qeth_l3_setadapter_parms(card);
2677 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01002678 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002679 if (!card->options.sniffer) {
2680 rc = qeth_l3_start_ipassists(card);
Stefan Raspl0f547612013-01-21 02:30:20 +00002681 if (rc) {
Ursula Braun76b11f82010-01-11 02:50:50 +00002682 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Stefan Raspl0f547612013-01-21 02:30:20 +00002683 goto out_remove;
2684 }
Ursula Braun76b11f82010-01-11 02:50:50 +00002685 rc = qeth_l3_setrouting_v4(card);
2686 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01002687 QETH_DBF_TEXT_(SETUP, 2, "4err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002688 rc = qeth_l3_setrouting_v6(card);
2689 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01002690 QETH_DBF_TEXT_(SETUP, 2, "5err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002691 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002692 netif_tx_disable(card->dev);
2693
2694 rc = qeth_init_qdio_queues(card);
2695 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002696 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00002697 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002698 goto out_remove;
2699 }
2700 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002701
2702 qeth_set_allowed_threads(card, 0xffffffff, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002703 qeth_l3_recover_ip(card);
Ursula Braun2b6203b2010-11-26 02:41:19 +00002704 if (card->lan_online)
2705 netif_carrier_on(card->dev);
2706 else
2707 netif_carrier_off(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002708 if (recover_flag == CARD_STATE_RECOVER) {
Ursula Braun4763b0a2011-12-19 22:56:32 +00002709 rtnl_lock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002710 if (recovery_mode)
Ursula Braun39423442011-01-12 20:42:24 +00002711 __qeth_l3_open(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00002712 else
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002713 dev_open(card->dev);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01002714 qeth_l3_set_rx_mode(card->dev);
Hans Wippele830baa2016-09-15 14:39:21 +02002715 qeth_recover_features(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00002716 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002717 }
Stefan Raspl82f77cf2013-03-18 20:04:42 +00002718 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002719 /* let user_space know that device is online */
2720 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002721 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002722 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002723 return 0;
2724out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002725 qeth_l3_stop_card(card, 0);
2726 ccw_device_set_offline(CARD_DDEV(card));
2727 ccw_device_set_offline(CARD_WDEV(card));
2728 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01002729 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002730 if (recover_flag == CARD_STATE_RECOVER)
2731 card->state = CARD_STATE_RECOVER;
2732 else
2733 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00002734 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002735 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00002736 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002737}
2738
2739static int qeth_l3_set_online(struct ccwgroup_device *gdev)
2740{
2741 return __qeth_l3_set_online(gdev, 0);
2742}
2743
2744static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
2745 int recovery_mode)
2746{
2747 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
2748 int rc = 0, rc2 = 0, rc3 = 0;
2749 enum qeth_card_states recover_flag;
2750
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002751 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002752 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002753 QETH_DBF_TEXT(SETUP, 3, "setoffl");
2754 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002755
2756 if (card->dev && netif_carrier_ok(card->dev))
2757 netif_carrier_off(card->dev);
2758 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00002759 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
2760 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
2761 card->info.hwtrap = 1;
2762 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02002763 qeth_l3_stop_card(card, recovery_mode);
Einar Lueck72861ae2011-12-19 22:56:36 +00002764 if ((card->options.cq == QETH_CQ_ENABLED) && card->dev) {
2765 rtnl_lock();
2766 call_netdevice_notifiers(NETDEV_REBOOT, card->dev);
2767 rtnl_unlock();
2768 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002769 rc = ccw_device_set_offline(CARD_DDEV(card));
2770 rc2 = ccw_device_set_offline(CARD_WDEV(card));
2771 rc3 = ccw_device_set_offline(CARD_RDEV(card));
2772 if (!rc)
2773 rc = (rc2) ? rc2 : rc3;
2774 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002775 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01002776 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002777 if (recover_flag == CARD_STATE_UP)
2778 card->state = CARD_STATE_RECOVER;
2779 /* let user_space know that device is offline */
2780 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002781 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002782 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002783 return 0;
2784}
2785
2786static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
2787{
2788 return __qeth_l3_set_offline(cgdev, 0);
2789}
2790
2791static int qeth_l3_recover(void *ptr)
2792{
2793 struct qeth_card *card;
2794 int rc = 0;
2795
2796 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00002797 QETH_CARD_TEXT(card, 2, "recover1");
2798 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002799 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
2800 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00002801 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002802 dev_warn(&card->gdev->dev,
2803 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00002804 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002805 __qeth_l3_set_offline(card->gdev, 1);
2806 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002807 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002808 dev_info(&card->gdev->dev,
2809 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02002810 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00002811 qeth_close_dev(card);
2812 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00002813 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02002814 }
Stefan Raspl65d80132013-04-07 22:19:27 +00002815 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002816 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
2817 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002818 return 0;
2819}
2820
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002821static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
2822{
2823 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
2824
2825 if (card->dev)
2826 netif_device_detach(card->dev);
2827 qeth_set_allowed_threads(card, 0, 1);
2828 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
2829 if (gdev->state == CCWGROUP_OFFLINE)
2830 return 0;
2831 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00002832 if (card->info.hwtrap)
2833 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002834 __qeth_l3_set_offline(card->gdev, 1);
2835 } else
2836 __qeth_l3_set_offline(card->gdev, 0);
2837 return 0;
2838}
2839
2840static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
2841{
2842 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
2843 int rc = 0;
2844
2845 if (gdev->state == CCWGROUP_OFFLINE)
2846 goto out;
2847
2848 if (card->state == CARD_STATE_RECOVER) {
2849 rc = __qeth_l3_set_online(card->gdev, 1);
2850 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00002851 rtnl_lock();
2852 dev_close(card->dev);
2853 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002854 }
2855 } else
2856 rc = __qeth_l3_set_online(card->gdev, 0);
2857out:
2858 qeth_set_allowed_threads(card, 0xffffffff, 0);
2859 if (card->dev)
2860 netif_device_attach(card->dev);
2861 if (rc)
2862 dev_warn(&card->gdev->dev, "The qeth device driver "
2863 "failed to recover an error on the device\n");
2864 return rc;
2865}
2866
Eugene Crosserc044dc22014-01-29 09:23:48 +01002867/* Returns zero if the command is successfully "consumed" */
2868static int qeth_l3_control_event(struct qeth_card *card,
2869 struct qeth_ipa_cmd *cmd)
2870{
2871 return 1;
2872}
2873
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002874struct qeth_discipline qeth_l3_discipline = {
Ursula Braun79a04e42017-06-06 14:33:49 +02002875 .devtype = &qeth_l3_devtype,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02002876 .process_rx_buffer = qeth_l3_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002877 .recover = qeth_l3_recover,
2878 .setup = qeth_l3_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002879 .remove = qeth_l3_remove_device,
2880 .set_online = qeth_l3_set_online,
2881 .set_offline = qeth_l3_set_offline,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002882 .freeze = qeth_l3_pm_suspend,
2883 .thaw = qeth_l3_pm_resume,
2884 .restore = qeth_l3_pm_resume,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002885 .do_ioctl = qeth_l3_do_ioctl,
Eugene Crosserc044dc22014-01-29 09:23:48 +01002886 .control_event_handler = qeth_l3_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002887};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002888EXPORT_SYMBOL_GPL(qeth_l3_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002889
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002890static int qeth_l3_handle_ip_event(struct qeth_card *card,
2891 struct qeth_ipaddr *addr,
2892 unsigned long event)
2893{
2894 switch (event) {
2895 case NETDEV_UP:
2896 spin_lock_bh(&card->ip_lock);
2897 qeth_l3_add_ip(card, addr);
2898 spin_unlock_bh(&card->ip_lock);
2899 return NOTIFY_OK;
2900 case NETDEV_DOWN:
2901 spin_lock_bh(&card->ip_lock);
2902 qeth_l3_delete_ip(card, addr);
2903 spin_unlock_bh(&card->ip_lock);
2904 return NOTIFY_OK;
2905 default:
2906 return NOTIFY_DONE;
2907 }
2908}
2909
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002910static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2911{
2912 if (is_vlan_dev(dev))
2913 dev = vlan_dev_real_dev(dev);
2914 if (dev->netdev_ops == &qeth_l3_osa_netdev_ops ||
2915 dev->netdev_ops == &qeth_l3_netdev_ops)
2916 return (struct qeth_card *) dev->ml_priv;
2917 return NULL;
2918}
2919
Frank Blaschka4a71df52008-02-15 09:19:42 +01002920static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07002921 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002922{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002923
Frank Blaschka4a71df52008-02-15 09:19:42 +01002924 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002925 struct net_device *dev = ifa->ifa_dev->dev;
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002926 struct qeth_ipaddr addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002927 struct qeth_card *card;
2928
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09002929 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07002930 return NOTIFY_DONE;
2931
Frank Blaschka4a71df52008-02-15 09:19:42 +01002932 card = qeth_l3_get_card_from_dev(dev);
2933 if (!card)
2934 return NOTIFY_DONE;
frank.blaschka@de.ibm.com6d8823d2012-05-16 01:28:26 +00002935 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002936
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002937 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV4);
2938 addr.u.a4.addr = be32_to_cpu(ifa->ifa_address);
2939 addr.u.a4.mask = be32_to_cpu(ifa->ifa_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002940
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002941 return qeth_l3_handle_ip_event(card, &addr, event);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002942}
2943
2944static struct notifier_block qeth_l3_ip_notifier = {
2945 qeth_l3_ip_event,
2946 NULL,
2947};
2948
Frank Blaschka4a71df52008-02-15 09:19:42 +01002949static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07002950 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002951{
2952 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002953 struct net_device *dev = ifa->idev->dev;
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002954 struct qeth_ipaddr addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002955 struct qeth_card *card;
2956
Frank Blaschka4a71df52008-02-15 09:19:42 +01002957 card = qeth_l3_get_card_from_dev(dev);
2958 if (!card)
2959 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00002960 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002961 if (!qeth_is_supported(card, IPA_IPV6))
2962 return NOTIFY_DONE;
2963
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002964 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV6);
2965 addr.u.a6.addr = ifa->addr;
2966 addr.u.a6.pfxlen = ifa->prefix_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002967
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002968 return qeth_l3_handle_ip_event(card, &addr, event);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002969}
2970
2971static struct notifier_block qeth_l3_ip6_notifier = {
2972 qeth_l3_ip6_event,
2973 NULL,
2974};
Frank Blaschka4a71df52008-02-15 09:19:42 +01002975
2976static int qeth_l3_register_notifiers(void)
2977{
2978 int rc;
2979
Carsten Otte847a50f2010-06-21 22:57:05 +00002980 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002981 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
2982 if (rc)
2983 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002984 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
2985 if (rc) {
2986 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
2987 return rc;
2988 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002989 return 0;
2990}
2991
2992static void qeth_l3_unregister_notifiers(void)
2993{
Carsten Otte847a50f2010-06-21 22:57:05 +00002994 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Stefan Raspl18af5c12012-11-19 02:46:50 +00002995 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
Stefan Raspl18af5c12012-11-19 02:46:50 +00002996 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002997}
2998
2999static int __init qeth_l3_init(void)
3000{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003001 pr_info("register layer 3 discipline\n");
Julian Wiedmannc0622042017-12-20 20:10:58 +01003002 return qeth_l3_register_notifiers();
Frank Blaschka4a71df52008-02-15 09:19:42 +01003003}
3004
3005static void __exit qeth_l3_exit(void)
3006{
3007 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003008 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003009}
3010
3011module_init(qeth_l3_init);
3012module_exit(qeth_l3_exit);
3013MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3014MODULE_DESCRIPTION("qeth layer 3 discipline");
3015MODULE_LICENSE("GPL");