blob: 46a841258fc8a3b76e653303be246f00602e58b9 [file] [log] [blame]
Frank Blaschka4a71df52008-02-15 09:19:42 +01001/*
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002 * Copyright IBM Corp. 2007, 2009
Frank Blaschka4a71df52008-02-15 09:19:42 +01003 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
4 * Frank Pavlic <fpavlic@de.ibm.com>,
5 * Thomas Spatzier <tspat@de.ibm.com>,
6 * Frank Blaschka <frank.blaschka@de.ibm.com>
7 */
8
Frank Blaschka74eacdb2008-12-25 13:39:49 +01009#define KMSG_COMPONENT "qeth"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Frank Blaschka4a71df52008-02-15 09:19:42 +010012#include <linux/module.h>
13#include <linux/moduleparam.h>
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +000014#include <linux/bitops.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010015#include <linux/string.h>
16#include <linux/errno.h>
17#include <linux/kernel.h>
18#include <linux/etherdevice.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010019#include <linux/ip.h>
Frank Blaschka64ef8952009-03-24 20:57:16 +000020#include <linux/ipv6.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010021#include <linux/inetdevice.h>
22#include <linux/igmp.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +000024#include <linux/if_vlan.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010025
26#include <net/ip.h>
27#include <net/arp.h>
David Miller87e75972012-02-01 10:49:17 +000028#include <net/route.h>
29#include <net/ip6_fib.h>
Frank Blaschka64ef8952009-03-24 20:57:16 +000030#include <net/ip6_checksum.h>
Frank Blaschkab3332932011-08-08 01:33:59 +000031#include <net/iucv/af_iucv.h>
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020032#include <linux/hashtable.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010033
Frank Blaschka4a71df52008-02-15 09:19:42 +010034#include "qeth_l3.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010035
Einar Lueckd0ddf30f2010-12-08 02:57:58 +000036
Frank Blaschka4a71df52008-02-15 09:19:42 +010037static int qeth_l3_set_offline(struct ccwgroup_device *);
Frank Blaschka4a71df52008-02-15 09:19:42 +010038static int qeth_l3_stop(struct net_device *);
39static void qeth_l3_set_multicast_list(struct net_device *);
Frank Blaschka4a71df52008-02-15 09:19:42 +010040static int qeth_l3_register_addr_entry(struct qeth_card *,
41 struct qeth_ipaddr *);
42static int qeth_l3_deregister_addr_entry(struct qeth_card *,
43 struct qeth_ipaddr *);
Frank Blaschka4a71df52008-02-15 09:19:42 +010044
Frank Blaschka4a71df52008-02-15 09:19:42 +010045static int qeth_l3_isxdigit(char *buf)
46{
47 while (*buf) {
48 if (!isxdigit(*buf++))
49 return 0;
50 }
51 return 1;
52}
53
Thomas Richter56530d62014-10-22 12:18:04 +020054static void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010055{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020056 sprintf(buf, "%pI4", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010057}
58
Thomas Richter56530d62014-10-22 12:18:04 +020059static int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +010060{
61 int count = 0, rc = 0;
Ursula Brauna68be012014-05-28 10:22:31 +020062 unsigned int in[4];
Frank Blaschka4a71df52008-02-15 09:19:42 +010063 char c;
64
65 rc = sscanf(buf, "%u.%u.%u.%u%c",
66 &in[0], &in[1], &in[2], &in[3], &c);
67 if (rc != 4 && (rc != 5 || c != '\n'))
68 return -EINVAL;
69 for (count = 0; count < 4; count++) {
70 if (in[count] > 255)
71 return -EINVAL;
72 addr[count] = in[count];
73 }
74 return 0;
75}
76
Thomas Richter56530d62014-10-22 12:18:04 +020077static void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010078{
Joe Perches963a9fd2010-09-07 21:14:40 +000079 sprintf(buf, "%pI6", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010080}
81
Thomas Richter56530d62014-10-22 12:18:04 +020082static int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +010083{
84 const char *end, *end_tmp, *start;
85 __u16 *in;
86 char num[5];
87 int num2, cnt, out, found, save_cnt;
88 unsigned short in_tmp[8] = {0, };
89
90 cnt = out = found = save_cnt = num2 = 0;
91 end = start = buf;
92 in = (__u16 *) addr;
93 memset(in, 0, 16);
94 while (*end) {
95 end = strchr(start, ':');
96 if (end == NULL) {
97 end = buf + strlen(buf);
98 end_tmp = strchr(start, '\n');
99 if (end_tmp != NULL)
100 end = end_tmp;
101 out = 1;
102 }
103 if ((end - start)) {
104 memset(num, 0, 5);
105 if ((end - start) > 4)
106 return -EINVAL;
107 memcpy(num, start, end - start);
108 if (!qeth_l3_isxdigit(num))
109 return -EINVAL;
110 sscanf(start, "%x", &num2);
111 if (found)
112 in_tmp[save_cnt++] = num2;
113 else
114 in[cnt++] = num2;
115 if (out)
116 break;
117 } else {
118 if (found)
119 return -EINVAL;
120 found = 1;
121 }
122 start = ++end;
123 }
124 if (cnt + save_cnt > 8)
125 return -EINVAL;
126 cnt = 7;
127 while (save_cnt)
128 in[cnt--] = in_tmp[--save_cnt];
129 return 0;
130}
131
132void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
133 char *buf)
134{
135 if (proto == QETH_PROT_IPV4)
136 qeth_l3_ipaddr4_to_string(addr, buf);
137 else if (proto == QETH_PROT_IPV6)
138 qeth_l3_ipaddr6_to_string(addr, buf);
139}
140
141int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
142 __u8 *addr)
143{
144 if (proto == QETH_PROT_IPV4)
145 return qeth_l3_string_to_ipaddr4(buf, addr);
146 else if (proto == QETH_PROT_IPV6)
147 return qeth_l3_string_to_ipaddr6(buf, addr);
148 else
149 return -EINVAL;
150}
151
152static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
153{
154 int i, j;
155 u8 octet;
156
157 for (i = 0; i < len; ++i) {
158 octet = addr[i];
159 for (j = 7; j >= 0; --j) {
160 bits[i*8 + j] = octet & 1;
161 octet >>= 1;
162 }
163 }
164}
165
Klaus-Dieter Wacker62982632010-07-22 23:15:03 +0000166int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100167 struct qeth_ipaddr *addr)
168{
169 struct qeth_ipato_entry *ipatoe;
170 u8 addr_bits[128] = {0, };
171 u8 ipatoe_bits[128] = {0, };
172 int rc = 0;
173
174 if (!card->ipato.enabled)
175 return 0;
176
177 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
178 (addr->proto == QETH_PROT_IPV4)? 4:16);
179 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
180 if (addr->proto != ipatoe->proto)
181 continue;
182 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
183 (ipatoe->proto == QETH_PROT_IPV4) ?
184 4 : 16);
185 if (addr->proto == QETH_PROT_IPV4)
186 rc = !memcmp(addr_bits, ipatoe_bits,
187 min(32, ipatoe->mask_bits));
188 else
189 rc = !memcmp(addr_bits, ipatoe_bits,
190 min(128, ipatoe->mask_bits));
191 if (rc)
192 break;
193 }
194 /* invert? */
195 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
196 rc = !rc;
197 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
198 rc = !rc;
199
200 return rc;
201}
202
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200203inline int
204qeth_l3_ipaddrs_is_equal(struct qeth_ipaddr *addr1, struct qeth_ipaddr *addr2)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100205{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200206 return addr1->proto == addr2->proto &&
207 !memcmp(&addr1->u, &addr2->u, sizeof(addr1->u)) &&
208 !memcmp(&addr1->mac, &addr2->mac, sizeof(addr1->mac));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100209}
210
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200211static struct qeth_ipaddr *
212qeth_l3_ip_from_hash(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100213{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200214 struct qeth_ipaddr *addr;
215
216 if (tmp_addr->is_multicast) {
217 hash_for_each_possible(card->ip_mc_htable, addr,
218 hnode, qeth_l3_ipaddr_hash(tmp_addr))
219 if (qeth_l3_ipaddrs_is_equal(tmp_addr, addr))
220 return addr;
221 } else {
222 hash_for_each_possible(card->ip_htable, addr,
223 hnode, qeth_l3_ipaddr_hash(tmp_addr))
224 if (qeth_l3_ipaddrs_is_equal(tmp_addr, addr))
225 return addr;
226 }
227
228 return NULL;
229}
230
231int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
232{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100233 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200234 struct qeth_ipaddr *addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100235
Carsten Otte847a50f2010-06-21 22:57:05 +0000236 QETH_CARD_TEXT(card, 4, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100237
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200238 if (tmp_addr->proto == QETH_PROT_IPV4)
239 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100240 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200241 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
242 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100243 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200244
245 addr = qeth_l3_ip_from_hash(card, tmp_addr);
246 if (!addr)
247 return -ENOENT;
248
249 addr->ref_counter--;
Kittipon Meesompopcb816192017-08-15 17:02:50 +0200250 if (addr->ref_counter > 0 && (addr->type == QETH_IP_TYPE_NORMAL ||
251 addr->type == QETH_IP_TYPE_RXIP))
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200252 return rc;
253 if (addr->in_progress)
254 return -EINPROGRESS;
255
Ursula Brauna7531c12016-09-15 14:39:23 +0200256 if (!qeth_card_hw_is_reachable(card)) {
257 addr->disp_flag = QETH_DISP_ADDR_DELETE;
258 return 0;
259 }
260
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200261 rc = qeth_l3_deregister_addr_entry(card, addr);
262
263 hash_del(&addr->hnode);
264 kfree(addr);
265
Frank Blaschka4a71df52008-02-15 09:19:42 +0100266 return rc;
267}
268
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200269int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100270{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100271 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200272 struct qeth_ipaddr *addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100273
Carsten Otte847a50f2010-06-21 22:57:05 +0000274 QETH_CARD_TEXT(card, 4, "addip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200275
276 if (tmp_addr->proto == QETH_PROT_IPV4)
277 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100278 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200279 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
280 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100281 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200282
283 addr = qeth_l3_ip_from_hash(card, tmp_addr);
284 if (!addr) {
285 addr = qeth_l3_get_addr_buffer(tmp_addr->proto);
286 if (!addr)
287 return -ENOMEM;
288
289 memcpy(addr, tmp_addr, sizeof(struct qeth_ipaddr));
290 addr->ref_counter = 1;
291
292 if (addr->type == QETH_IP_TYPE_NORMAL &&
293 qeth_l3_is_addr_covered_by_ipato(card, addr)) {
294 QETH_CARD_TEXT(card, 2, "tkovaddr");
295 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
296 }
297 hash_add(card->ip_htable, &addr->hnode,
298 qeth_l3_ipaddr_hash(addr));
299
Ursula Brauna7531c12016-09-15 14:39:23 +0200300 if (!qeth_card_hw_is_reachable(card)) {
301 addr->disp_flag = QETH_DISP_ADDR_ADD;
302 return 0;
303 }
304
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200305 /* qeth_l3_register_addr_entry can go to sleep
306 * if we add a IPV4 addr. It is caused by the reason
307 * that SETIP ipa cmd starts ARP staff for IPV4 addr.
308 * Thus we should unlock spinlock, and make a protection
309 * using in_progress variable to indicate that there is
310 * an hardware operation with this IPV4 address
311 */
312 if (addr->proto == QETH_PROT_IPV4) {
313 addr->in_progress = 1;
314 spin_unlock_bh(&card->ip_lock);
315 rc = qeth_l3_register_addr_entry(card, addr);
316 spin_lock_bh(&card->ip_lock);
317 addr->in_progress = 0;
318 } else
319 rc = qeth_l3_register_addr_entry(card, addr);
320
321 if (!rc || (rc == IPA_RC_DUPLICATE_IP_ADDRESS) ||
322 (rc == IPA_RC_LAN_OFFLINE)) {
323 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
324 if (addr->ref_counter < 1) {
325 qeth_l3_delete_ip(card, addr);
326 kfree(addr);
327 }
328 } else {
329 hash_del(&addr->hnode);
330 kfree(addr);
331 }
332 } else {
Kittipon Meesompopcb816192017-08-15 17:02:50 +0200333 if (addr->type == QETH_IP_TYPE_NORMAL ||
334 addr->type == QETH_IP_TYPE_RXIP)
335 addr->ref_counter++;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200336 }
337
Frank Blaschka4a71df52008-02-15 09:19:42 +0100338 return rc;
339}
340
341
Frank Blaschkab3332932011-08-08 01:33:59 +0000342struct qeth_ipaddr *qeth_l3_get_addr_buffer(
Frank Blaschka4a71df52008-02-15 09:19:42 +0100343 enum qeth_prot_versions prot)
344{
345 struct qeth_ipaddr *addr;
346
347 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200348 if (!addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100349 return NULL;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200350
Frank Blaschka4a71df52008-02-15 09:19:42 +0100351 addr->type = QETH_IP_TYPE_NORMAL;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200352 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100353 addr->proto = prot;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200354
Frank Blaschka4a71df52008-02-15 09:19:42 +0100355 return addr;
356}
357
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200358static void qeth_l3_clear_ip_htable(struct qeth_card *card, int recover)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100359{
360 struct qeth_ipaddr *addr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200361 struct hlist_node *tmp;
362 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100363
Carsten Otte847a50f2010-06-21 22:57:05 +0000364 QETH_CARD_TEXT(card, 4, "clearip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200365
Ursula Braun76b11f82010-01-11 02:50:50 +0000366 if (recover && card->options.sniffer)
367 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100368
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200369 spin_lock_bh(&card->ip_lock);
370
371 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
372 if (!recover) {
373 hash_del(&addr->hnode);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100374 kfree(addr);
375 continue;
376 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200377 addr->disp_flag = QETH_DISP_ADDR_ADD;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100378 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200379
380 spin_unlock_bh(&card->ip_lock);
381
382 spin_lock_bh(&card->mclock);
383
384 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
385 hash_del(&addr->hnode);
386 kfree(addr);
387 }
388
389 spin_unlock_bh(&card->mclock);
390
391
Frank Blaschka4a71df52008-02-15 09:19:42 +0100392}
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200393static void qeth_l3_recover_ip(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100394{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200395 struct qeth_ipaddr *addr;
396 struct hlist_node *tmp;
397 int i;
398 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100399
Ursula Brauna7531c12016-09-15 14:39:23 +0200400 QETH_CARD_TEXT(card, 4, "recovrip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100401
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200402 spin_lock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100403
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200404 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
Ursula Brauna7531c12016-09-15 14:39:23 +0200405 if (addr->disp_flag == QETH_DISP_ADDR_DELETE) {
406 qeth_l3_deregister_addr_entry(card, addr);
407 hash_del(&addr->hnode);
408 kfree(addr);
409 } else if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200410 if (addr->proto == QETH_PROT_IPV4) {
411 addr->in_progress = 1;
412 spin_unlock_bh(&card->ip_lock);
413 rc = qeth_l3_register_addr_entry(card, addr);
414 spin_lock_bh(&card->ip_lock);
415 addr->in_progress = 0;
416 } else
417 rc = qeth_l3_register_addr_entry(card, addr);
418
419 if (!rc) {
420 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Ursula Brauna7531c12016-09-15 14:39:23 +0200421 if (addr->ref_counter < 1)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200422 qeth_l3_delete_ip(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200423 } else {
424 hash_del(&addr->hnode);
425 kfree(addr);
426 }
427 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100428 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200429
430 spin_unlock_bh(&card->ip_lock);
431
Frank Blaschka4a71df52008-02-15 09:19:42 +0100432}
433
434static int qeth_l3_send_setdelmc(struct qeth_card *card,
435 struct qeth_ipaddr *addr, int ipacmd)
436{
437 int rc;
438 struct qeth_cmd_buffer *iob;
439 struct qeth_ipa_cmd *cmd;
440
Carsten Otte847a50f2010-06-21 22:57:05 +0000441 QETH_CARD_TEXT(card, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100442
443 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100444 if (!iob)
445 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100446 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
447 memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
448 if (addr->proto == QETH_PROT_IPV6)
449 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
450 sizeof(struct in6_addr));
451 else
452 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
453
454 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
455
456 return rc;
457}
458
459static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
460{
461 int i, j;
462 for (i = 0; i < 16; i++) {
463 j = (len) - (i * 8);
464 if (j >= 8)
465 netmask[i] = 0xff;
466 else if (j > 0)
467 netmask[i] = (u8)(0xFF00 >> j);
468 else
469 netmask[i] = 0;
470 }
471}
472
473static int qeth_l3_send_setdelip(struct qeth_card *card,
474 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
475{
476 int rc;
477 struct qeth_cmd_buffer *iob;
478 struct qeth_ipa_cmd *cmd;
479 __u8 netmask[16];
480
Carsten Otte847a50f2010-06-21 22:57:05 +0000481 QETH_CARD_TEXT(card, 4, "setdelip");
482 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100483
484 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100485 if (!iob)
486 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100487 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
488 if (addr->proto == QETH_PROT_IPV6) {
489 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
490 sizeof(struct in6_addr));
491 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
492 memcpy(cmd->data.setdelip6.mask, netmask,
493 sizeof(struct in6_addr));
494 cmd->data.setdelip6.flags = flags;
495 } else {
496 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
497 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
498 cmd->data.setdelip4.flags = flags;
499 }
500
501 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
502
503 return rc;
504}
505
506static int qeth_l3_send_setrouting(struct qeth_card *card,
507 enum qeth_routing_types type, enum qeth_prot_versions prot)
508{
509 int rc;
510 struct qeth_ipa_cmd *cmd;
511 struct qeth_cmd_buffer *iob;
512
Carsten Otte847a50f2010-06-21 22:57:05 +0000513 QETH_CARD_TEXT(card, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100514 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100515 if (!iob)
516 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100517 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
518 cmd->data.setrtg.type = (type);
519 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
520
521 return rc;
522}
523
Stefan Raspl82e2e782013-03-18 20:04:43 +0000524static int qeth_l3_correct_routing_type(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100525 enum qeth_routing_types *type, enum qeth_prot_versions prot)
526{
527 if (card->info.type == QETH_CARD_TYPE_IQD) {
528 switch (*type) {
529 case NO_ROUTER:
530 case PRIMARY_CONNECTOR:
531 case SECONDARY_CONNECTOR:
532 case MULTICAST_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000533 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100534 default:
535 goto out_inval;
536 }
537 } else {
538 switch (*type) {
539 case NO_ROUTER:
540 case PRIMARY_ROUTER:
541 case SECONDARY_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000542 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100543 case MULTICAST_ROUTER:
544 if (qeth_is_ipafunc_supported(card, prot,
545 IPA_OSA_MC_ROUTER))
Stefan Raspl82e2e782013-03-18 20:04:43 +0000546 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100547 default:
548 goto out_inval;
549 }
550 }
551out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100552 *type = NO_ROUTER;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000553 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100554}
555
556int qeth_l3_setrouting_v4(struct qeth_card *card)
557{
558 int rc;
559
Carsten Otte847a50f2010-06-21 22:57:05 +0000560 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100561
Stefan Raspl82e2e782013-03-18 20:04:43 +0000562 rc = qeth_l3_correct_routing_type(card, &card->options.route4.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100563 QETH_PROT_IPV4);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000564 if (rc)
565 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100566
567 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
568 QETH_PROT_IPV4);
569 if (rc) {
570 card->options.route4.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200571 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
572 " on %s. Type set to 'no router'.\n", rc,
573 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100574 }
575 return rc;
576}
577
578int qeth_l3_setrouting_v6(struct qeth_card *card)
579{
580 int rc = 0;
581
Carsten Otte847a50f2010-06-21 22:57:05 +0000582 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100583#ifdef CONFIG_QETH_IPV6
584
585 if (!qeth_is_supported(card, IPA_IPV6))
586 return 0;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000587 rc = qeth_l3_correct_routing_type(card, &card->options.route6.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100588 QETH_PROT_IPV6);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000589 if (rc)
590 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100591
592 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
593 QETH_PROT_IPV6);
594 if (rc) {
595 card->options.route6.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200596 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
597 " on %s. Type set to 'no router'.\n", rc,
598 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100599 }
600#endif
601 return rc;
602}
603
604/*
605 * IP address takeover related functions
606 */
607static void qeth_l3_clear_ipato_list(struct qeth_card *card)
608{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100609 struct qeth_ipato_entry *ipatoe, *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100610
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200611 spin_lock_bh(&card->ip_lock);
612
Frank Blaschka4a71df52008-02-15 09:19:42 +0100613 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
614 list_del(&ipatoe->entry);
615 kfree(ipatoe);
616 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200617
618 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100619}
620
621int qeth_l3_add_ipato_entry(struct qeth_card *card,
622 struct qeth_ipato_entry *new)
623{
624 struct qeth_ipato_entry *ipatoe;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100625 int rc = 0;
626
Carsten Otte847a50f2010-06-21 22:57:05 +0000627 QETH_CARD_TEXT(card, 2, "addipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200628
629 spin_lock_bh(&card->ip_lock);
630
Frank Blaschka4a71df52008-02-15 09:19:42 +0100631 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
632 if (ipatoe->proto != new->proto)
633 continue;
634 if (!memcmp(ipatoe->addr, new->addr,
635 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
636 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100637 rc = -EEXIST;
638 break;
639 }
640 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200641
Frank Blaschka4a71df52008-02-15 09:19:42 +0100642 if (!rc)
643 list_add_tail(&new->entry, &card->ipato.entries);
644
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200645 spin_unlock_bh(&card->ip_lock);
646
Frank Blaschka4a71df52008-02-15 09:19:42 +0100647 return rc;
648}
649
650void qeth_l3_del_ipato_entry(struct qeth_card *card,
651 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
652{
653 struct qeth_ipato_entry *ipatoe, *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100654
Carsten Otte847a50f2010-06-21 22:57:05 +0000655 QETH_CARD_TEXT(card, 2, "delipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200656
657 spin_lock_bh(&card->ip_lock);
658
Frank Blaschka4a71df52008-02-15 09:19:42 +0100659 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
660 if (ipatoe->proto != proto)
661 continue;
662 if (!memcmp(ipatoe->addr, addr,
663 (proto == QETH_PROT_IPV4)? 4:16) &&
664 (ipatoe->mask_bits == mask_bits)) {
665 list_del(&ipatoe->entry);
666 kfree(ipatoe);
667 }
668 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200669
670 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100671}
672
673/*
674 * VIPA related functions
675 */
676int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
677 const u8 *addr)
678{
679 struct qeth_ipaddr *ipaddr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100680 int rc = 0;
681
682 ipaddr = qeth_l3_get_addr_buffer(proto);
683 if (ipaddr) {
684 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000685 QETH_CARD_TEXT(card, 2, "addvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100686 memcpy(&ipaddr->u.a4.addr, addr, 4);
687 ipaddr->u.a4.mask = 0;
688 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000689 QETH_CARD_TEXT(card, 2, "addvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100690 memcpy(&ipaddr->u.a6.addr, addr, 16);
691 ipaddr->u.a6.pfxlen = 0;
692 }
693 ipaddr->type = QETH_IP_TYPE_VIPA;
694 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
695 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
696 } else
697 return -ENOMEM;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200698
699 spin_lock_bh(&card->ip_lock);
700
Thomas Richter732a59c2016-09-15 14:39:27 +0200701 if (qeth_l3_ip_from_hash(card, ipaddr))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100702 rc = -EEXIST;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200703 else
704 qeth_l3_add_ip(card, ipaddr);
705
706 spin_unlock_bh(&card->ip_lock);
707
708 kfree(ipaddr);
709
Frank Blaschka4a71df52008-02-15 09:19:42 +0100710 return rc;
711}
712
713void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
714 const u8 *addr)
715{
716 struct qeth_ipaddr *ipaddr;
717
718 ipaddr = qeth_l3_get_addr_buffer(proto);
719 if (ipaddr) {
720 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000721 QETH_CARD_TEXT(card, 2, "delvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100722 memcpy(&ipaddr->u.a4.addr, addr, 4);
723 ipaddr->u.a4.mask = 0;
724 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000725 QETH_CARD_TEXT(card, 2, "delvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100726 memcpy(&ipaddr->u.a6.addr, addr, 16);
727 ipaddr->u.a6.pfxlen = 0;
728 }
729 ipaddr->type = QETH_IP_TYPE_VIPA;
730 } else
731 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200732
733 spin_lock_bh(&card->ip_lock);
734 qeth_l3_delete_ip(card, ipaddr);
735 spin_unlock_bh(&card->ip_lock);
736
737 kfree(ipaddr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100738}
739
740/*
741 * proxy ARP related functions
742 */
743int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
744 const u8 *addr)
745{
746 struct qeth_ipaddr *ipaddr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100747 int rc = 0;
748
749 ipaddr = qeth_l3_get_addr_buffer(proto);
750 if (ipaddr) {
751 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000752 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100753 memcpy(&ipaddr->u.a4.addr, addr, 4);
754 ipaddr->u.a4.mask = 0;
755 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000756 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100757 memcpy(&ipaddr->u.a6.addr, addr, 16);
758 ipaddr->u.a6.pfxlen = 0;
759 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200760
Frank Blaschka4a71df52008-02-15 09:19:42 +0100761 ipaddr->type = QETH_IP_TYPE_RXIP;
762 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
763 ipaddr->del_flags = 0;
764 } else
765 return -ENOMEM;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200766
767 spin_lock_bh(&card->ip_lock);
768
Thomas Richter732a59c2016-09-15 14:39:27 +0200769 if (qeth_l3_ip_from_hash(card, ipaddr))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100770 rc = -EEXIST;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200771 else
772 qeth_l3_add_ip(card, ipaddr);
773
774 spin_unlock_bh(&card->ip_lock);
775
776 kfree(ipaddr);
777
778 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100779}
780
781void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
782 const u8 *addr)
783{
784 struct qeth_ipaddr *ipaddr;
785
786 ipaddr = qeth_l3_get_addr_buffer(proto);
787 if (ipaddr) {
788 if (proto == QETH_PROT_IPV4) {
Kittipon Meesompopea4ae352017-08-15 17:02:49 +0200789 QETH_CARD_TEXT(card, 2, "delrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100790 memcpy(&ipaddr->u.a4.addr, addr, 4);
791 ipaddr->u.a4.mask = 0;
792 } else if (proto == QETH_PROT_IPV6) {
Kittipon Meesompopea4ae352017-08-15 17:02:49 +0200793 QETH_CARD_TEXT(card, 2, "delrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100794 memcpy(&ipaddr->u.a6.addr, addr, 16);
795 ipaddr->u.a6.pfxlen = 0;
796 }
797 ipaddr->type = QETH_IP_TYPE_RXIP;
798 } else
799 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200800
801 spin_lock_bh(&card->ip_lock);
802 qeth_l3_delete_ip(card, ipaddr);
803 spin_unlock_bh(&card->ip_lock);
804
805 kfree(ipaddr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100806}
807
808static int qeth_l3_register_addr_entry(struct qeth_card *card,
809 struct qeth_ipaddr *addr)
810{
811 char buf[50];
812 int rc = 0;
813 int cnt = 3;
814
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200815
Frank Blaschka4a71df52008-02-15 09:19:42 +0100816 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000817 QETH_CARD_TEXT(card, 2, "setaddr4");
818 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100819 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000820 QETH_CARD_TEXT(card, 2, "setaddr6");
821 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
822 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100823 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000824 QETH_CARD_TEXT(card, 2, "setaddr?");
825 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100826 }
827 do {
828 if (addr->is_multicast)
829 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
830 else
831 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
832 addr->set_flags);
833 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000834 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100835 } while ((--cnt > 0) && rc);
836 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000837 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100838 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100839 dev_warn(&card->gdev->dev,
840 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100841 }
842 return rc;
843}
844
845static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
846 struct qeth_ipaddr *addr)
847{
848 int rc = 0;
849
850 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000851 QETH_CARD_TEXT(card, 2, "deladdr4");
852 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100853 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000854 QETH_CARD_TEXT(card, 2, "deladdr6");
855 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
856 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100857 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000858 QETH_CARD_TEXT(card, 2, "deladdr?");
859 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100860 }
861 if (addr->is_multicast)
862 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
863 else
864 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
865 addr->del_flags);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200866 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000867 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100868
869 return rc;
870}
871
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200872static u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100873{
874 if (cast_type == RTN_MULTICAST)
875 return QETH_CAST_MULTICAST;
876 if (cast_type == RTN_BROADCAST)
877 return QETH_CAST_BROADCAST;
878 return QETH_CAST_UNICAST;
879}
880
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200881static u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100882{
883 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
884 if (cast_type == RTN_MULTICAST)
885 return ct | QETH_CAST_MULTICAST;
886 if (cast_type == RTN_ANYCAST)
887 return ct | QETH_CAST_ANYCAST;
888 if (cast_type == RTN_BROADCAST)
889 return ct | QETH_CAST_BROADCAST;
890 return ct | QETH_CAST_UNICAST;
891}
892
Frank Blaschka4a71df52008-02-15 09:19:42 +0100893static int qeth_l3_setadapter_parms(struct qeth_card *card)
894{
Julian Wiedmann699d3fe2017-08-15 17:02:41 +0200895 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100896
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200897 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100898
Frank Blaschka4a71df52008-02-15 09:19:42 +0100899 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
900 rc = qeth_setadpparms_change_macaddr(card);
901 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100902 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -0800903 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100904 }
905
Frank Blaschka4a71df52008-02-15 09:19:42 +0100906 return rc;
907}
908
Frank Blaschka4a71df52008-02-15 09:19:42 +0100909#ifdef CONFIG_QETH_IPV6
910static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
911 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
912{
913 int rc;
914 struct qeth_cmd_buffer *iob;
915
Carsten Otte847a50f2010-06-21 22:57:05 +0000916 QETH_CARD_TEXT(card, 4, "simassp6");
Thomas Richterb475e312015-12-11 12:27:54 +0100917 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100918 0, QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100919 if (!iob)
920 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +0200921 rc = qeth_send_setassparms(card, iob, 0, 0,
Thomas Richter8f43fb02016-06-16 16:18:59 +0200922 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100923 return rc;
924}
925#endif
926
Frank Blaschka4a71df52008-02-15 09:19:42 +0100927static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
928{
929 int rc;
930
Carsten Otte847a50f2010-06-21 22:57:05 +0000931 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100932
933 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100934 dev_info(&card->gdev->dev,
935 "ARP processing not supported on %s!\n",
936 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100937 return 0;
938 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200939 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
940 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100941 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100942 dev_warn(&card->gdev->dev,
943 "Starting ARP processing support for %s failed\n",
944 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100945 }
946 return rc;
947}
948
Frank Blaschka4a71df52008-02-15 09:19:42 +0100949static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
950{
951 int rc;
952
Carsten Otte847a50f2010-06-21 22:57:05 +0000953 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100954
Frank Blaschka4a71df52008-02-15 09:19:42 +0100955 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100956 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800957 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100958 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100959 return -EOPNOTSUPP;
960 }
961
Thomas Richter4d7def22015-09-18 16:06:51 +0200962 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100963 IPA_CMD_ASS_START, 0);
964 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100965 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800966 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100967 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100968 return rc;
969}
970
971static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
972{
973 int rc = 0;
974
Carsten Otte847a50f2010-06-21 22:57:05 +0000975 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100976
977 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100978 dev_info(&card->gdev->dev,
979 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100980 return -EOPNOTSUPP;
981 }
982
Thomas Richter4d7def22015-09-18 16:06:51 +0200983 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100984 IPA_CMD_ASS_START, 0);
985 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100986 dev_warn(&card->gdev->dev,
987 "Starting VLAN support for %s failed\n",
988 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100989 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100990 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100991 }
992 return rc;
993}
994
995static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
996{
997 int rc;
998
Carsten Otte847a50f2010-06-21 22:57:05 +0000999 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001000
1001 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001002 dev_info(&card->gdev->dev,
1003 "Multicast not supported on %s\n",
1004 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001005 return -EOPNOTSUPP;
1006 }
1007
Thomas Richter4d7def22015-09-18 16:06:51 +02001008 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001009 IPA_CMD_ASS_START, 0);
1010 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001011 dev_warn(&card->gdev->dev,
1012 "Starting multicast support for %s failed\n",
1013 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001014 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001015 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001016 card->dev->flags |= IFF_MULTICAST;
1017 }
1018 return rc;
1019}
1020
Frank Blaschka4a71df52008-02-15 09:19:42 +01001021#ifdef CONFIG_QETH_IPV6
1022static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1023{
1024 int rc;
1025
Carsten Otte847a50f2010-06-21 22:57:05 +00001026 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001027
Frank Blaschka1da74b12011-05-12 18:45:02 +00001028 rc = qeth_query_ipassists(card, QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001029 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001030 dev_err(&card->gdev->dev,
1031 "Activating IPv6 support for %s failed\n",
1032 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001033 return rc;
1034 }
Julian Wiedmann23274592017-06-06 14:33:44 +02001035
1036 if (card->info.type == QETH_CARD_TYPE_IQD)
1037 goto out;
1038
Thomas Richter4d7def22015-09-18 16:06:51 +02001039 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001040 IPA_CMD_ASS_START, 3);
1041 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001042 dev_err(&card->gdev->dev,
1043 "Activating IPv6 support for %s failed\n",
1044 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001045 return rc;
1046 }
1047 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1048 IPA_CMD_ASS_START);
1049 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001050 dev_err(&card->gdev->dev,
1051 "Activating IPv6 support for %s failed\n",
1052 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001053 return rc;
1054 }
1055 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1056 IPA_CMD_ASS_START);
1057 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001058 dev_warn(&card->gdev->dev,
1059 "Enabling the passthrough mode for %s failed\n",
1060 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001061 return rc;
1062 }
1063out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001064 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001065 return 0;
1066}
1067#endif
1068
1069static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1070{
1071 int rc = 0;
1072
Carsten Otte847a50f2010-06-21 22:57:05 +00001073 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001074
1075 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001076 dev_info(&card->gdev->dev,
1077 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001078 return 0;
1079 }
1080#ifdef CONFIG_QETH_IPV6
1081 rc = qeth_l3_softsetup_ipv6(card);
1082#endif
1083 return rc ;
1084}
1085
1086static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1087{
1088 int rc;
1089
Carsten Otte847a50f2010-06-21 22:57:05 +00001090 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001091 card->info.broadcast_capable = 0;
1092 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001093 dev_info(&card->gdev->dev,
1094 "Broadcast not supported on %s\n",
1095 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001096 rc = -EOPNOTSUPP;
1097 goto out;
1098 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001099 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001100 IPA_CMD_ASS_START, 0);
1101 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001102 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1103 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001104 goto out;
1105 }
1106
Thomas Richter4d7def22015-09-18 16:06:51 +02001107 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001108 IPA_CMD_ASS_CONFIGURE, 1);
1109 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001110 dev_warn(&card->gdev->dev,
1111 "Setting up broadcast filtering for %s failed\n",
1112 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001113 goto out;
1114 }
1115 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001116 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Thomas Richter4d7def22015-09-18 16:06:51 +02001117 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001118 IPA_CMD_ASS_ENABLE, 1);
1119 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001120 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1121 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001122 goto out;
1123 }
1124 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1125out:
1126 if (card->info.broadcast_capable)
1127 card->dev->flags |= IFF_BROADCAST;
1128 else
1129 card->dev->flags &= ~IFF_BROADCAST;
1130 return rc;
1131}
1132
Frank Blaschka4a71df52008-02-15 09:19:42 +01001133static int qeth_l3_start_ipassists(struct qeth_card *card)
1134{
Carsten Otte847a50f2010-06-21 22:57:05 +00001135 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +00001136
Stefan Raspl0f547612013-01-21 02:30:20 +00001137 if (qeth_set_access_ctrl_online(card, 0))
1138 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001139 qeth_l3_start_ipa_arp_processing(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +01001140 qeth_l3_start_ipa_source_mac(card); /* go on*/
1141 qeth_l3_start_ipa_vlan(card); /* go on*/
1142 qeth_l3_start_ipa_multicast(card); /* go on*/
1143 qeth_l3_start_ipa_ipv6(card); /* go on*/
1144 qeth_l3_start_ipa_broadcast(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +01001145 return 0;
1146}
1147
Frank Blaschka4a71df52008-02-15 09:19:42 +01001148static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1149 struct qeth_reply *reply, unsigned long data)
1150{
1151 struct qeth_ipa_cmd *cmd;
1152
1153 cmd = (struct qeth_ipa_cmd *) data;
1154 if (cmd->hdr.return_code == 0)
1155 memcpy(card->dev->dev_addr,
1156 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1157 else
Joe Perches18336112012-07-12 22:33:10 -07001158 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001159
1160 return 0;
1161}
1162
1163static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1164{
1165 int rc = 0;
1166 struct qeth_cmd_buffer *iob;
1167 struct qeth_ipa_cmd *cmd;
1168
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001169 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001170
1171 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1172 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001173 if (!iob)
1174 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001175 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1176 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1177 card->info.unique_id;
1178
1179 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1180 NULL);
1181 return rc;
1182}
1183
1184static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1185 struct qeth_reply *reply, unsigned long data)
1186{
1187 struct qeth_ipa_cmd *cmd;
1188
1189 cmd = (struct qeth_ipa_cmd *) data;
1190 if (cmd->hdr.return_code == 0)
1191 card->info.unique_id = *((__u16 *)
1192 &cmd->data.create_destroy_addr.unique_id[6]);
1193 else {
1194 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1195 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001196 dev_warn(&card->gdev->dev, "The network adapter failed to "
1197 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001198 }
1199 return 0;
1200}
1201
1202static int qeth_l3_get_unique_id(struct qeth_card *card)
1203{
1204 int rc = 0;
1205 struct qeth_cmd_buffer *iob;
1206 struct qeth_ipa_cmd *cmd;
1207
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001208 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001209
1210 if (!qeth_is_supported(card, IPA_IPV6)) {
1211 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1212 UNIQUE_ID_NOT_BY_CARD;
1213 return 0;
1214 }
1215
1216 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1217 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001218 if (!iob)
1219 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001220 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1221 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1222 card->info.unique_id;
1223
1224 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1225 return rc;
1226}
1227
Ursula Braun76b11f82010-01-11 02:50:50 +00001228static int
1229qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1230 unsigned long data)
1231{
1232 struct qeth_ipa_cmd *cmd;
1233 __u16 rc;
1234
1235 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1236
1237 cmd = (struct qeth_ipa_cmd *)data;
1238 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001239 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001240 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001241 switch (cmd->data.diagass.action) {
1242 case QETH_DIAGS_CMD_TRACE_QUERY:
1243 break;
1244 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001245 switch (rc) {
1246 case 0:
1247 case IPA_RC_INVALID_SUBCMD:
1248 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1249 dev_info(&card->gdev->dev, "The HiperSockets network "
1250 "traffic analyzer is deactivated\n");
1251 break;
1252 default:
1253 break;
1254 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001255 break;
1256 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001257 switch (rc) {
1258 case 0:
1259 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1260 dev_info(&card->gdev->dev, "The HiperSockets network "
1261 "traffic analyzer is activated\n");
1262 break;
1263 case IPA_RC_HARDWARE_AUTH_ERROR:
1264 dev_warn(&card->gdev->dev, "The device is not "
1265 "authorized to run as a HiperSockets network "
1266 "traffic analyzer\n");
1267 break;
1268 case IPA_RC_TRACE_ALREADY_ACTIVE:
1269 dev_warn(&card->gdev->dev, "A HiperSockets "
1270 "network traffic analyzer is already "
1271 "active in the HiperSockets LAN\n");
1272 break;
1273 default:
1274 break;
1275 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001276 break;
1277 default:
1278 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1279 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1280 }
1281
1282 return 0;
1283}
1284
1285static int
1286qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1287{
1288 struct qeth_cmd_buffer *iob;
1289 struct qeth_ipa_cmd *cmd;
1290
1291 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1292
1293 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001294 if (!iob)
1295 return -ENOMEM;
Ursula Braun76b11f82010-01-11 02:50:50 +00001296 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1297 cmd->data.diagass.subcmd_len = 16;
1298 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1299 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1300 cmd->data.diagass.action = diags_cmd;
1301 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1302}
1303
Hans Wippel6bee4e22017-04-07 09:15:36 +02001304static void qeth_l3_get_mac_for_ipm(__be32 ipm, char *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001305{
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001306 ip_eth_mc_map(ipm, mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001307}
1308
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001309static void qeth_l3_mark_all_mc_to_be_deleted(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001310{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001311 struct qeth_ipaddr *addr;
1312 int i;
1313
1314 hash_for_each(card->ip_mc_htable, i, addr, hnode)
1315 addr->disp_flag = QETH_DISP_ADDR_DELETE;
1316
1317}
1318
1319static void qeth_l3_add_all_new_mc(struct qeth_card *card)
1320{
1321 struct qeth_ipaddr *addr;
1322 struct hlist_node *tmp;
1323 int i;
1324 int rc;
1325
1326 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1327 if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
1328 rc = qeth_l3_register_addr_entry(card, addr);
1329 if (!rc || (rc == IPA_RC_LAN_OFFLINE))
1330 addr->ref_counter = 1;
1331 else {
1332 hash_del(&addr->hnode);
1333 kfree(addr);
1334 }
1335 }
1336 }
1337
1338}
1339
1340static void qeth_l3_delete_nonused_mc(struct qeth_card *card)
1341{
1342 struct qeth_ipaddr *addr;
1343 struct hlist_node *tmp;
1344 int i;
1345 int rc;
1346
1347 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1348 if (addr->disp_flag == QETH_DISP_ADDR_DELETE) {
1349 rc = qeth_l3_deregister_addr_entry(card, addr);
1350 if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND)) {
1351 hash_del(&addr->hnode);
1352 kfree(addr);
1353 }
1354 }
1355 }
1356
1357}
1358
1359
1360static void
1361qeth_l3_add_mc_to_hash(struct qeth_card *card, struct in_device *in4_dev)
1362{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001363 struct ip_mc_list *im4;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001364 struct qeth_ipaddr *tmp, *ipm;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001365 char buf[MAX_ADDR_LEN];
1366
Carsten Otte847a50f2010-06-21 22:57:05 +00001367 QETH_CARD_TEXT(card, 4, "addmc");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001368
1369 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1370 if (!tmp)
1371 return;
1372
Sachin Santf3aa3132010-11-26 02:41:17 +00001373 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1374 im4 = rcu_dereference(im4->next_rcu)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001375 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf);
1376
Hans Wippel6bee4e22017-04-07 09:15:36 +02001377 tmp->u.a4.addr = be32_to_cpu(im4->multiaddr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001378 memcpy(tmp->mac, buf, sizeof(tmp->mac));
Julian Wiedmannbc3ab7052017-12-01 10:14:49 +01001379 tmp->is_multicast = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001380
1381 ipm = qeth_l3_ip_from_hash(card, tmp);
1382 if (ipm) {
1383 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1384 } else {
1385 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1386 if (!ipm)
1387 continue;
1388 memcpy(ipm->mac, buf, sizeof(tmp->mac));
Hans Wippel6bee4e22017-04-07 09:15:36 +02001389 ipm->u.a4.addr = be32_to_cpu(im4->multiaddr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001390 ipm->is_multicast = 1;
1391 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1392 hash_add(card->ip_mc_htable,
1393 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1394 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001395 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001396
1397 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001398}
1399
Jiri Pirko0347af52013-01-03 22:48:58 +00001400/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001401static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1402{
1403 struct in_device *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001404 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001405
Carsten Otte847a50f2010-06-21 22:57:05 +00001406 QETH_CARD_TEXT(card, 4, "addmcvl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001407
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001408 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001409 return;
1410
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001411 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1412 struct net_device *netdev;
1413
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001414 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001415 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001416 if (netdev == NULL ||
1417 !(netdev->flags & IFF_UP))
1418 continue;
Jiri Pirko0347af52013-01-03 22:48:58 +00001419 in_dev = __in_dev_get_rcu(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001420 if (!in_dev)
1421 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001422 qeth_l3_add_mc_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001423 }
1424}
1425
1426static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1427{
1428 struct in_device *in4_dev;
1429
Carsten Otte847a50f2010-06-21 22:57:05 +00001430 QETH_CARD_TEXT(card, 4, "chkmcv4");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001431
Sachin Santf3aa3132010-11-26 02:41:17 +00001432 rcu_read_lock();
Jiri Pirko0347af52013-01-03 22:48:58 +00001433 in4_dev = __in_dev_get_rcu(card->dev);
1434 if (in4_dev == NULL)
1435 goto unlock;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001436 qeth_l3_add_mc_to_hash(card, in4_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001437 qeth_l3_add_vlan_mc(card);
Jiri Pirko0347af52013-01-03 22:48:58 +00001438unlock:
Sachin Santf3aa3132010-11-26 02:41:17 +00001439 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001440}
1441
1442#ifdef CONFIG_QETH_IPV6
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001443static void
1444qeth_l3_add_mc6_to_hash(struct qeth_card *card, struct inet6_dev *in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001445{
1446 struct qeth_ipaddr *ipm;
1447 struct ifmcaddr6 *im6;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001448 struct qeth_ipaddr *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001449 char buf[MAX_ADDR_LEN];
1450
Carsten Otte847a50f2010-06-21 22:57:05 +00001451 QETH_CARD_TEXT(card, 4, "addmc6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001452
1453 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1454 if (!tmp)
1455 return;
1456
Frank Blaschka4a71df52008-02-15 09:19:42 +01001457 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1458 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001459
1460 memcpy(tmp->mac, buf, sizeof(tmp->mac));
1461 memcpy(&tmp->u.a6.addr, &im6->mca_addr.s6_addr,
1462 sizeof(struct in6_addr));
1463 tmp->is_multicast = 1;
1464
1465 ipm = qeth_l3_ip_from_hash(card, tmp);
1466 if (ipm) {
1467 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1468 continue;
1469 }
1470
Frank Blaschka4a71df52008-02-15 09:19:42 +01001471 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1472 if (!ipm)
1473 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001474
Frank Blaschka4a71df52008-02-15 09:19:42 +01001475 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1476 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1477 sizeof(struct in6_addr));
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001478 ipm->is_multicast = 1;
1479 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1480 hash_add(card->ip_mc_htable,
1481 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1482
Frank Blaschka4a71df52008-02-15 09:19:42 +01001483 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001484 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001485}
1486
Jiri Pirko0347af52013-01-03 22:48:58 +00001487/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001488static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1489{
1490 struct inet6_dev *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001491 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001492
Carsten Otte847a50f2010-06-21 22:57:05 +00001493 QETH_CARD_TEXT(card, 4, "admc6vl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001494
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001495 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001496 return;
1497
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001498 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1499 struct net_device *netdev;
1500
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001501 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001502 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001503 if (netdev == NULL ||
1504 !(netdev->flags & IFF_UP))
1505 continue;
1506 in_dev = in6_dev_get(netdev);
1507 if (!in_dev)
1508 continue;
1509 read_lock_bh(&in_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001510 qeth_l3_add_mc6_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001511 read_unlock_bh(&in_dev->lock);
1512 in6_dev_put(in_dev);
1513 }
1514}
1515
1516static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1517{
1518 struct inet6_dev *in6_dev;
1519
Carsten Otte847a50f2010-06-21 22:57:05 +00001520 QETH_CARD_TEXT(card, 4, "chkmcv6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001521
Frank Blaschka4a71df52008-02-15 09:19:42 +01001522 if (!qeth_is_supported(card, IPA_IPV6))
1523 return ;
1524 in6_dev = in6_dev_get(card->dev);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001525 if (!in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001526 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001527
Jiri Pirko0347af52013-01-03 22:48:58 +00001528 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001529 read_lock_bh(&in6_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001530 qeth_l3_add_mc6_to_hash(card, in6_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001531 qeth_l3_add_vlan_mc6(card);
1532 read_unlock_bh(&in6_dev->lock);
Jiri Pirko0347af52013-01-03 22:48:58 +00001533 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001534 in6_dev_put(in6_dev);
1535}
1536#endif /* CONFIG_QETH_IPV6 */
1537
1538static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1539 unsigned short vid)
1540{
1541 struct in_device *in_dev;
1542 struct in_ifaddr *ifa;
1543 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001544 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001545
Carsten Otte847a50f2010-06-21 22:57:05 +00001546 QETH_CARD_TEXT(card, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001547
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001548 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
frank.blaschka@de.ibm.comeabfbe62012-07-24 22:34:29 +00001549 if (!netdev)
1550 return;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001551 in_dev = in_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001552 if (!in_dev)
1553 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001554
1555 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1556 if (!addr)
Julian Wiedmann83cf79a2017-10-18 17:40:17 +02001557 goto out;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001558
1559 spin_lock_bh(&card->ip_lock);
1560
Frank Blaschka4a71df52008-02-15 09:19:42 +01001561 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
Hans Wippel6bee4e22017-04-07 09:15:36 +02001562 addr->u.a4.addr = be32_to_cpu(ifa->ifa_address);
1563 addr->u.a4.mask = be32_to_cpu(ifa->ifa_mask);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001564 addr->type = QETH_IP_TYPE_NORMAL;
1565 qeth_l3_delete_ip(card, addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001566 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001567
1568 spin_unlock_bh(&card->ip_lock);
1569
1570 kfree(addr);
Julian Wiedmann83cf79a2017-10-18 17:40:17 +02001571out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001572 in_dev_put(in_dev);
1573}
1574
1575static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1576 unsigned short vid)
1577{
1578#ifdef CONFIG_QETH_IPV6
1579 struct inet6_dev *in6_dev;
1580 struct inet6_ifaddr *ifa;
1581 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001582 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001583
Carsten Otte847a50f2010-06-21 22:57:05 +00001584 QETH_CARD_TEXT(card, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001585
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001586 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
frank.blaschka@de.ibm.comeabfbe62012-07-24 22:34:29 +00001587 if (!netdev)
1588 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001589
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001590 in6_dev = in6_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001591 if (!in6_dev)
1592 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001593
1594 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1595 if (!addr)
Julian Wiedmann83cf79a2017-10-18 17:40:17 +02001596 goto out;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001597
1598 spin_lock_bh(&card->ip_lock);
1599
Frank Blaschka70f60a22010-03-22 09:59:48 -07001600 list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001601 memcpy(&addr->u.a6.addr, &ifa->addr,
1602 sizeof(struct in6_addr));
1603 addr->u.a6.pfxlen = ifa->prefix_len;
1604 addr->type = QETH_IP_TYPE_NORMAL;
1605 qeth_l3_delete_ip(card, addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001606 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001607
1608 spin_unlock_bh(&card->ip_lock);
1609
1610 kfree(addr);
Julian Wiedmann83cf79a2017-10-18 17:40:17 +02001611out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001612 in6_dev_put(in6_dev);
1613#endif /* CONFIG_QETH_IPV6 */
1614}
1615
1616static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1617 unsigned short vid)
1618{
Jiri Pirko0347af52013-01-03 22:48:58 +00001619 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001620 qeth_l3_free_vlan_addresses4(card, vid);
1621 qeth_l3_free_vlan_addresses6(card, vid);
Jiri Pirko0347af52013-01-03 22:48:58 +00001622 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001623}
1624
Patrick McHardy80d5c362013-04-19 02:04:28 +00001625static int qeth_l3_vlan_rx_add_vid(struct net_device *dev,
1626 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001627{
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001628 struct qeth_card *card = dev->ml_priv;
1629
1630 set_bit(vid, card->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001631 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001632}
1633
Patrick McHardy80d5c362013-04-19 02:04:28 +00001634static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev,
1635 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001636{
Heiko Carstens509e2562008-07-26 02:24:10 -07001637 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001638
Carsten Otte847a50f2010-06-21 22:57:05 +00001639 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001640
Ursula Braun8e98ac42009-03-24 20:57:18 +00001641 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001642 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -05001643 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +00001644 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001645 /* unregister IP addresses of vlan device */
1646 qeth_l3_free_vlan_addresses(card, vid);
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001647 clear_bit(vid, card->active_vlans);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001648 qeth_l3_set_multicast_list(card->dev);
Jiri Pirko8e586132011-12-08 19:52:37 -05001649 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001650}
1651
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001652static void qeth_l3_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
1653 struct qeth_hdr *hdr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001654{
Hans Wippel6bee4e22017-04-07 09:15:36 +02001655 __u16 prot;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001656 struct iphdr *ip_hdr;
1657 unsigned char tg_addr[MAX_ADDR_LEN];
1658
1659 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
Hans Wippel6bee4e22017-04-07 09:15:36 +02001660 prot = (hdr->hdr.l3.flags & QETH_HDR_IPV6) ? ETH_P_IPV6 :
1661 ETH_P_IP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001662 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1663 case QETH_CAST_MULTICAST:
1664 switch (prot) {
1665#ifdef CONFIG_QETH_IPV6
Hans Wippel6bee4e22017-04-07 09:15:36 +02001666 case ETH_P_IPV6:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001667 ndisc_mc_map((struct in6_addr *)
1668 skb->data + 24,
1669 tg_addr, card->dev, 0);
1670 break;
1671#endif
Hans Wippel6bee4e22017-04-07 09:15:36 +02001672 case ETH_P_IP:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001673 ip_hdr = (struct iphdr *)skb->data;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001674 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1675 break;
1676 default:
1677 memcpy(tg_addr, card->dev->broadcast,
1678 card->dev->addr_len);
1679 }
1680 card->stats.multicast++;
1681 skb->pkt_type = PACKET_MULTICAST;
1682 break;
1683 case QETH_CAST_BROADCAST:
1684 memcpy(tg_addr, card->dev->broadcast,
1685 card->dev->addr_len);
1686 card->stats.multicast++;
1687 skb->pkt_type = PACKET_BROADCAST;
1688 break;
1689 case QETH_CAST_UNICAST:
1690 case QETH_CAST_ANYCAST:
1691 case QETH_CAST_NOCAST:
1692 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00001693 if (card->options.sniffer)
1694 skb->pkt_type = PACKET_OTHERHOST;
1695 else
1696 skb->pkt_type = PACKET_HOST;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001697 memcpy(tg_addr, card->dev->dev_addr,
1698 card->dev->addr_len);
1699 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001700 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1701 card->dev->header_ops->create(skb, card->dev, prot,
1702 tg_addr, &hdr->hdr.l3.dest_addr[2],
1703 card->dev->addr_len);
1704 else
1705 card->dev->header_ops->create(skb, card->dev, prot,
1706 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001707 }
1708
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001709 skb->protocol = eth_type_trans(skb, card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001710
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001711 /* copy VLAN tag from hdr into skb */
1712 if (!card->options.sniffer &&
1713 (hdr->hdr.l3.ext_flags & (QETH_HDR_EXT_VLAN_FRAME |
1714 QETH_HDR_EXT_INCLUDE_VLAN_TAG))) {
1715 u16 tag = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
1716 hdr->hdr.l3.vlan_id :
1717 *((u16 *)&hdr->hdr.l3.dest_addr[12]);
1718 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001719 }
1720
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001721 if (card->dev->features & NETIF_F_RXCSUM) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001722 if ((hdr->hdr.l3.ext_flags &
Ursula Braunb9139802009-05-19 21:38:40 +00001723 (QETH_HDR_EXT_CSUM_HDR_REQ |
1724 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1725 (QETH_HDR_EXT_CSUM_HDR_REQ |
1726 QETH_HDR_EXT_CSUM_TRANSP_REQ))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001727 skb->ip_summed = CHECKSUM_UNNECESSARY;
1728 else
Ursula Braunb9139802009-05-19 21:38:40 +00001729 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001730 } else
1731 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001732}
1733
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001734static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1735 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001736{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001737 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001738 struct sk_buff *skb;
1739 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001740 unsigned int len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001741 __u16 magic;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001742
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001743 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +00001744 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001745 while (budget) {
1746 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +00001747 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001748 &card->rx.b_element, &card->rx.e_offset, &hdr);
1749 if (!skb) {
1750 *done = 1;
1751 break;
1752 }
1753 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001754 switch (hdr->hdr.l3.id) {
1755 case QETH_HEADER_TYPE_LAYER3:
Frank Blaschkab3332932011-08-08 01:33:59 +00001756 magic = *(__u16 *)skb->data;
1757 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
1758 (magic == ETH_P_AF_IUCV)) {
Hans Wippel6bee4e22017-04-07 09:15:36 +02001759 skb->protocol = cpu_to_be16(ETH_P_AF_IUCV);
Frank Blaschkab3332932011-08-08 01:33:59 +00001760 skb->pkt_type = PACKET_HOST;
1761 skb->mac_header = NET_SKB_PAD;
1762 skb->dev = card->dev;
1763 len = skb->len;
1764 card->dev->header_ops->create(skb, card->dev, 0,
1765 card->dev->dev_addr, "FAKELL",
1766 card->dev->addr_len);
1767 netif_receive_skb(skb);
1768 } else {
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001769 qeth_l3_rebuild_skb(card, skb, hdr);
Frank Blaschkab3332932011-08-08 01:33:59 +00001770 len = skb->len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001771 napi_gro_receive(&card->napi, skb);
1772 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001773 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00001774 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
1775 skb->pkt_type = PACKET_HOST;
1776 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00001777 len = skb->len;
1778 netif_receive_skb(skb);
1779 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001780 default:
1781 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00001782 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001783 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001784 continue;
1785 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001786 work_done++;
1787 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001788 card->stats.rx_packets++;
1789 card->stats.rx_bytes += len;
1790 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001791 return work_done;
1792}
1793
Frank Blaschka4a71df52008-02-15 09:19:42 +01001794static int qeth_l3_verify_vlan_dev(struct net_device *dev,
1795 struct qeth_card *card)
1796{
1797 int rc = 0;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001798 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001799
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001800 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1801 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001802
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001803 rcu_read_lock();
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001804 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001805 vid);
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001806 rcu_read_unlock();
1807 if (netdev == dev) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001808 rc = QETH_VLAN_CARD;
1809 break;
1810 }
1811 }
1812
Heiko Carstens509e2562008-07-26 02:24:10 -07001813 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001814 return 0;
1815
1816 return rc;
1817}
1818
1819static int qeth_l3_verify_dev(struct net_device *dev)
1820{
1821 struct qeth_card *card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001822 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001823 unsigned long flags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001824
1825 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
1826 list_for_each_entry(card, &qeth_core_card_list.list, list) {
1827 if (card->dev == dev) {
1828 rc = QETH_REAL_CARD;
1829 break;
1830 }
1831 rc = qeth_l3_verify_vlan_dev(dev, card);
1832 if (rc)
1833 break;
1834 }
1835 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
1836
1837 return rc;
1838}
1839
1840static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
1841{
1842 struct qeth_card *card = NULL;
1843 int rc;
1844
1845 rc = qeth_l3_verify_dev(dev);
1846 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07001847 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001848 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07001849 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02001850 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001851 card = NULL;
Carsten Otte847a50f2010-06-21 22:57:05 +00001852 if (card)
1853 QETH_CARD_TEXT_(card, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001854 return card ;
1855}
1856
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +02001857static void qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001858{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001859 QETH_DBF_TEXT(SETUP, 2, "stopcard");
1860 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001861
1862 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00001863 if (card->options.sniffer &&
1864 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
1865 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001866 if (card->read.state == CH_STATE_UP &&
1867 card->write.state == CH_STATE_UP &&
1868 (card->state == CARD_STATE_UP)) {
1869 if (recovery_mode)
1870 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02001871 else {
Ursula Braun869da902010-03-08 20:36:56 +00001872 rtnl_lock();
1873 dev_close(card->dev);
1874 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02001875 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001876 card->state = CARD_STATE_SOFTSETUP;
1877 }
1878 if (card->state == CARD_STATE_SOFTSETUP) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001879 qeth_l3_clear_ip_htable(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001880 qeth_clear_ipacmd_list(card);
1881 card->state = CARD_STATE_HARDSETUP;
1882 }
1883 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001884 qeth_qdio_clear_card(card, 0);
1885 qeth_clear_qdio_buffers(card);
1886 qeth_clear_working_pool_list(card);
1887 card->state = CARD_STATE_DOWN;
1888 }
1889 if (card->state == CARD_STATE_DOWN) {
1890 qeth_clear_cmd_buffers(&card->read);
1891 qeth_clear_cmd_buffers(&card->write);
1892 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001893}
1894
Ursula Braun76b11f82010-01-11 02:50:50 +00001895/*
1896 * test for and Switch promiscuous mode (on or off)
1897 * either for guestlan or HiperSocket Sniffer
1898 */
1899static void
1900qeth_l3_handle_promisc_mode(struct qeth_card *card)
1901{
1902 struct net_device *dev = card->dev;
1903
1904 if (((dev->flags & IFF_PROMISC) &&
1905 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
1906 (!(dev->flags & IFF_PROMISC) &&
1907 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
1908 return;
1909
1910 if (card->info.guestlan) { /* Guestlan trace */
1911 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
1912 qeth_setadp_promisc_mode(card);
1913 } else if (card->options.sniffer && /* HiperSockets trace */
1914 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
1915 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001916 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001917 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
1918 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00001919 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001920 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
1921 }
1922 }
1923}
1924
Frank Blaschka4a71df52008-02-15 09:19:42 +01001925static void qeth_l3_set_multicast_list(struct net_device *dev)
1926{
Heiko Carstens509e2562008-07-26 02:24:10 -07001927 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001928
Carsten Otte847a50f2010-06-21 22:57:05 +00001929 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00001930 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
1931 (card->state != CARD_STATE_UP))
1932 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00001933 if (!card->options.sniffer) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001934
1935 spin_lock_bh(&card->mclock);
1936
1937 qeth_l3_mark_all_mc_to_be_deleted(card);
1938
Ursula Braun76b11f82010-01-11 02:50:50 +00001939 qeth_l3_add_multicast_ipv4(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001940#ifdef CONFIG_QETH_IPV6
Ursula Braun76b11f82010-01-11 02:50:50 +00001941 qeth_l3_add_multicast_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001942#endif
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001943 qeth_l3_delete_nonused_mc(card);
1944 qeth_l3_add_all_new_mc(card);
1945
1946 spin_unlock_bh(&card->mclock);
1947
Ursula Braun76b11f82010-01-11 02:50:50 +00001948 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
1949 return;
1950 }
1951 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001952}
1953
1954static const char *qeth_l3_arp_get_error_cause(int *rc)
1955{
1956 switch (*rc) {
1957 case QETH_IPA_ARP_RC_FAILED:
1958 *rc = -EIO;
1959 return "operation failed";
1960 case QETH_IPA_ARP_RC_NOTSUPP:
1961 *rc = -EOPNOTSUPP;
1962 return "operation not supported";
1963 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
1964 *rc = -EINVAL;
1965 return "argument out of range";
1966 case QETH_IPA_ARP_RC_Q_NOTSUPP:
1967 *rc = -EOPNOTSUPP;
1968 return "query operation not supported";
1969 case QETH_IPA_ARP_RC_Q_NO_DATA:
1970 *rc = -ENOENT;
1971 return "no query data available";
1972 default:
1973 return "unknown error";
1974 }
1975}
1976
1977static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
1978{
1979 int tmp;
1980 int rc;
1981
Carsten Otte847a50f2010-06-21 22:57:05 +00001982 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001983
1984 /*
1985 * currently GuestLAN only supports the ARP assist function
1986 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
1987 * thus we say EOPNOTSUPP for this ARP function
1988 */
1989 if (card->info.guestlan)
1990 return -EOPNOTSUPP;
1991 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001992 return -EOPNOTSUPP;
1993 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001994 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001995 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
1996 no_entries);
1997 if (rc) {
1998 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001999 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2000 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002001 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2002 }
2003 return rc;
2004}
2005
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002006static __u32 get_arp_entry_size(struct qeth_card *card,
2007 struct qeth_arp_query_data *qdata,
2008 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002009{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002010 __u32 rc;
2011 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002012
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002013 is_hsi = qdata->reply_bits == 5;
2014 if (type->ip == QETHARP_IP_ADDR_V4) {
2015 QETH_CARD_TEXT(card, 4, "arpev4");
2016 if (strip_entries) {
2017 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
2018 sizeof(struct qeth_arp_qi_entry7_short);
2019 } else {
2020 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
2021 sizeof(struct qeth_arp_qi_entry7);
2022 }
2023 } else if (type->ip == QETHARP_IP_ADDR_V6) {
2024 QETH_CARD_TEXT(card, 4, "arpev6");
2025 if (strip_entries) {
2026 rc = is_hsi ?
2027 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
2028 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
2029 } else {
2030 rc = is_hsi ?
2031 sizeof(struct qeth_arp_qi_entry5_ipv6) :
2032 sizeof(struct qeth_arp_qi_entry7_ipv6);
2033 }
2034 } else {
2035 QETH_CARD_TEXT(card, 4, "arpinv");
2036 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002037 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002038
2039 return rc;
2040}
2041
2042static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
2043{
2044 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
2045 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002046}
2047
2048static int qeth_l3_arp_query_cb(struct qeth_card *card,
2049 struct qeth_reply *reply, unsigned long data)
2050{
2051 struct qeth_ipa_cmd *cmd;
2052 struct qeth_arp_query_data *qdata;
2053 struct qeth_arp_query_info *qinfo;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002054 int i;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002055 int e;
2056 int entrybytes_done;
2057 int stripped_bytes;
2058 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002059
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002060 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002061
2062 qinfo = (struct qeth_arp_query_info *) reply->param;
2063 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002064 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002065 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002066 QETH_CARD_TEXT(card, 4, "arpcberr");
2067 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002068 return 0;
2069 }
2070 if (cmd->data.setassparms.hdr.return_code) {
2071 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002072 QETH_CARD_TEXT(card, 4, "setaperr");
2073 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002074 return 0;
2075 }
2076 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00002077 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002078
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002079 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
2080 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
2081 entrybytes_done = 0;
2082 for (e = 0; e < qdata->no_entries; ++e) {
2083 char *cur_entry;
2084 __u32 esize;
2085 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002086
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002087 cur_entry = &qdata->data + entrybytes_done;
2088 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
2089 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
2090 QETH_CARD_TEXT(card, 4, "pmis");
2091 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
2092 break;
2093 }
2094 esize = get_arp_entry_size(card, qdata, etype,
2095 do_strip_entries);
2096 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
2097 if (!esize)
2098 break;
2099
2100 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
2101 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
Ursula Braune0a81142012-03-07 02:06:28 +00002102 cmd->hdr.return_code = IPA_RC_ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002103 goto out_error;
2104 }
2105
2106 memcpy(qinfo->udata + qinfo->udata_offset,
2107 &qdata->data + entrybytes_done + stripped_bytes,
2108 esize);
2109 entrybytes_done += esize + stripped_bytes;
2110 qinfo->udata_offset += esize;
2111 ++qinfo->no_entries;
2112 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002113 /* check if all replies received ... */
2114 if (cmd->data.setassparms.hdr.seq_no <
2115 cmd->data.setassparms.hdr.number_of_replies)
2116 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002117 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002118 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2119 /* keep STRIP_ENTRIES flag so the user program can distinguish
2120 * stripped entries from normal ones */
2121 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2122 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2123 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002124 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002125 return 0;
2126out_error:
2127 i = 0;
2128 memcpy(qinfo->udata, &i, 4);
2129 return 0;
2130}
2131
2132static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2133 struct qeth_cmd_buffer *iob, int len,
2134 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2135 unsigned long),
2136 void *reply_param)
2137{
Carsten Otte847a50f2010-06-21 22:57:05 +00002138 QETH_CARD_TEXT(card, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002139
2140 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2141 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2142 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2143 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2144 reply_cb, reply_param);
2145}
2146
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002147static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
2148 enum qeth_prot_versions prot,
2149 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002150{
2151 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002152 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002153 int tmp;
2154 int rc;
2155
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002156 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
2157
Thomas Richterb475e312015-12-11 12:27:54 +01002158 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2159 IPA_CMD_ASS_ARP_QUERY_INFO,
2160 sizeof(struct qeth_arp_query_data)
2161 - sizeof(char),
2162 prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002163 if (!iob)
2164 return -ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002165 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2166 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
2167 cmd->data.setassparms.data.query_arp.reply_bits = 0;
2168 cmd->data.setassparms.data.query_arp.no_entries = 0;
2169 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2170 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2171 qeth_l3_arp_query_cb, (void *)qinfo);
2172 if (rc) {
2173 tmp = rc;
2174 QETH_DBF_MESSAGE(2,
2175 "Error while querying ARP cache on %s: %s "
2176 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2177 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2178 }
2179
2180 return rc;
2181}
2182
2183static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2184{
2185 struct qeth_arp_query_info qinfo = {0, };
2186 int rc;
2187
Carsten Otte847a50f2010-06-21 22:57:05 +00002188 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002189
2190 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2191 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002192 QETH_CARD_TEXT(card, 3, "arpqnsup");
2193 rc = -EOPNOTSUPP;
2194 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002195 }
2196 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002197 if (copy_from_user(&qinfo, udata, 6)) {
2198 rc = -EFAULT;
2199 goto out;
2200 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002201 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002202 if (!qinfo.udata) {
2203 rc = -ENOMEM;
2204 goto out;
2205 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002206 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002207 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002208 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002209 if (copy_to_user(udata, qinfo.udata, 4))
2210 rc = -EFAULT;
Sebastian Ott77a83ed2016-06-16 16:19:03 +02002211 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002212 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02002213#ifdef CONFIG_QETH_IPV6
2214 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
2215 /* fails in case of GuestLAN QDIO mode */
2216 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6, &qinfo);
2217 }
2218#endif
2219 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
2220 QETH_CARD_TEXT(card, 4, "qactf");
2221 rc = -EFAULT;
2222 goto free_and_out;
2223 }
2224 QETH_CARD_TEXT(card, 4, "qacts");
2225
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002226free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002227 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002228out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002229 return rc;
2230}
2231
2232static int qeth_l3_arp_add_entry(struct qeth_card *card,
2233 struct qeth_arp_cache_entry *entry)
2234{
2235 struct qeth_cmd_buffer *iob;
2236 char buf[16];
2237 int tmp;
2238 int rc;
2239
Carsten Otte847a50f2010-06-21 22:57:05 +00002240 QETH_CARD_TEXT(card, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002241
2242 /*
2243 * currently GuestLAN only supports the ARP assist function
2244 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2245 * thus we say EOPNOTSUPP for this ARP function
2246 */
2247 if (card->info.guestlan)
2248 return -EOPNOTSUPP;
2249 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002250 return -EOPNOTSUPP;
2251 }
2252
Thomas Richterb475e312015-12-11 12:27:54 +01002253 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002254 IPA_CMD_ASS_ARP_ADD_ENTRY,
2255 sizeof(struct qeth_arp_cache_entry),
2256 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002257 if (!iob)
2258 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +02002259 rc = qeth_send_setassparms(card, iob,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002260 sizeof(struct qeth_arp_cache_entry),
2261 (unsigned long) entry,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002262 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002263 if (rc) {
2264 tmp = rc;
2265 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002266 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2267 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2268 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002269 }
2270 return rc;
2271}
2272
2273static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2274 struct qeth_arp_cache_entry *entry)
2275{
2276 struct qeth_cmd_buffer *iob;
2277 char buf[16] = {0, };
2278 int tmp;
2279 int rc;
2280
Carsten Otte847a50f2010-06-21 22:57:05 +00002281 QETH_CARD_TEXT(card, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002282
2283 /*
2284 * currently GuestLAN only supports the ARP assist function
2285 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2286 * thus we say EOPNOTSUPP for this ARP function
2287 */
2288 if (card->info.guestlan)
2289 return -EOPNOTSUPP;
2290 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002291 return -EOPNOTSUPP;
2292 }
2293 memcpy(buf, entry, 12);
Thomas Richterb475e312015-12-11 12:27:54 +01002294 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002295 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2296 12,
2297 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002298 if (!iob)
2299 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +02002300 rc = qeth_send_setassparms(card, iob,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002301 12, (unsigned long)buf,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002302 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002303 if (rc) {
2304 tmp = rc;
2305 memset(buf, 0, 16);
2306 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002307 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2308 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2309 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002310 }
2311 return rc;
2312}
2313
2314static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2315{
2316 int rc;
2317 int tmp;
2318
Carsten Otte847a50f2010-06-21 22:57:05 +00002319 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002320
2321 /*
2322 * currently GuestLAN only supports the ARP assist function
2323 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2324 * thus we say EOPNOTSUPP for this ARP function
2325 */
2326 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2327 return -EOPNOTSUPP;
2328 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002329 return -EOPNOTSUPP;
2330 }
Thomas Richter4d7def22015-09-18 16:06:51 +02002331 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002332 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2333 if (rc) {
2334 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002335 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2336 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002337 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2338 }
2339 return rc;
2340}
2341
2342static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2343{
Heiko Carstens509e2562008-07-26 02:24:10 -07002344 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002345 struct qeth_arp_cache_entry arp_entry;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002346 int rc = 0;
2347
Frank Blaschka4a71df52008-02-15 09:19:42 +01002348 switch (cmd) {
2349 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2350 if (!capable(CAP_NET_ADMIN)) {
2351 rc = -EPERM;
2352 break;
2353 }
2354 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2355 break;
2356 case SIOC_QETH_ARP_QUERY_INFO:
2357 if (!capable(CAP_NET_ADMIN)) {
2358 rc = -EPERM;
2359 break;
2360 }
2361 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2362 break;
2363 case SIOC_QETH_ARP_ADD_ENTRY:
2364 if (!capable(CAP_NET_ADMIN)) {
2365 rc = -EPERM;
2366 break;
2367 }
2368 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2369 sizeof(struct qeth_arp_cache_entry)))
2370 rc = -EFAULT;
2371 else
2372 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2373 break;
2374 case SIOC_QETH_ARP_REMOVE_ENTRY:
2375 if (!capable(CAP_NET_ADMIN)) {
2376 rc = -EPERM;
2377 break;
2378 }
2379 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2380 sizeof(struct qeth_arp_cache_entry)))
2381 rc = -EFAULT;
2382 else
2383 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2384 break;
2385 case SIOC_QETH_ARP_FLUSH_CACHE:
2386 if (!capable(CAP_NET_ADMIN)) {
2387 rc = -EPERM;
2388 break;
2389 }
2390 rc = qeth_l3_arp_flush_cache(card);
2391 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002392 default:
2393 rc = -EOPNOTSUPP;
2394 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002395 return rc;
2396}
2397
Julian Wiedmanncef6ff222017-08-15 17:02:46 +02002398static int qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002399{
2400 int cast_type = RTN_UNSPEC;
David S. Miller69cce1d2011-07-17 23:09:49 -07002401 struct neighbour *n = NULL;
2402 struct dst_entry *dst;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002403
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002404 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002405 dst = skb_dst(skb);
2406 if (dst)
David S. Miller24db1ba2012-07-02 22:02:33 -07002407 n = dst_neigh_lookup_skb(dst, skb);
David S. Miller69cce1d2011-07-17 23:09:49 -07002408 if (n) {
2409 cast_type = n->type;
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002410 rcu_read_unlock();
David S. Miller24db1ba2012-07-02 22:02:33 -07002411 neigh_release(n);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002412 if ((cast_type == RTN_BROADCAST) ||
2413 (cast_type == RTN_MULTICAST) ||
2414 (cast_type == RTN_ANYCAST))
2415 return cast_type;
2416 else
2417 return RTN_UNSPEC;
2418 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002419 rcu_read_unlock();
2420
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002421 /* try something else */
Hans Wippel6bee4e22017-04-07 09:15:36 +02002422 if (be16_to_cpu(skb->protocol) == ETH_P_IPV6)
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002423 return (skb_network_header(skb)[24] == 0xff) ?
2424 RTN_MULTICAST : 0;
Hans Wippel6bee4e22017-04-07 09:15:36 +02002425 else if (be16_to_cpu(skb->protocol) == ETH_P_IP)
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002426 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2427 RTN_MULTICAST : 0;
2428 /* ... */
2429 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2430 return RTN_BROADCAST;
2431 else {
2432 u16 hdr_mac;
2433
2434 hdr_mac = *((u16 *)skb->data);
2435 /* tr multicast? */
2436 switch (card->info.link_type) {
2437 case QETH_LINK_TYPE_HSTR:
2438 case QETH_LINK_TYPE_LANE_TR:
2439 if ((hdr_mac == QETH_TR_MAC_NC) ||
2440 (hdr_mac == QETH_TR_MAC_C))
2441 return RTN_MULTICAST;
2442 break;
2443 /* eth or so multicast? */
2444 default:
2445 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2446 (hdr_mac == QETH_ETH_MAC_V6))
2447 return RTN_MULTICAST;
2448 }
2449 }
2450 return cast_type;
2451}
2452
Frank Blaschkab3332932011-08-08 01:33:59 +00002453static void qeth_l3_fill_af_iucv_hdr(struct qeth_card *card,
2454 struct qeth_hdr *hdr, struct sk_buff *skb)
2455{
2456 char daddr[16];
2457 struct af_iucv_trans_hdr *iucv_hdr;
2458
Frank Blaschkab3332932011-08-08 01:33:59 +00002459 memset(hdr, 0, sizeof(struct qeth_hdr));
2460 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2461 hdr->hdr.l3.ext_flags = 0;
Julian Wiedmannacd97762017-03-23 14:55:09 +01002462 hdr->hdr.l3.length = skb->len - ETH_HLEN;
Frank Blaschkab3332932011-08-08 01:33:59 +00002463 hdr->hdr.l3.flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
Julian Wiedmannacd97762017-03-23 14:55:09 +01002464
2465 iucv_hdr = (struct af_iucv_trans_hdr *) (skb->data + ETH_HLEN);
Frank Blaschkab3332932011-08-08 01:33:59 +00002466 memset(daddr, 0, sizeof(daddr));
2467 daddr[0] = 0xfe;
2468 daddr[1] = 0x80;
2469 memcpy(&daddr[8], iucv_hdr->destUserID, 8);
2470 memcpy(hdr->hdr.l3.dest_addr, daddr, 16);
2471}
2472
Frank Blaschka4a71df52008-02-15 09:19:42 +01002473static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2474 struct sk_buff *skb, int ipv, int cast_type)
2475{
David S. Miller69cce1d2011-07-17 23:09:49 -07002476 struct dst_entry *dst;
2477
Frank Blaschka4a71df52008-02-15 09:19:42 +01002478 memset(hdr, 0, sizeof(struct qeth_hdr));
2479 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2480 hdr->hdr.l3.ext_flags = 0;
2481
2482 /*
2483 * before we're going to overwrite this location with next hop ip.
2484 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2485 */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002486 if (skb_vlan_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002487 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2488 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2489 else
2490 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002491 hdr->hdr.l3.vlan_id = skb_vlan_tag_get(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002492 }
2493
2494 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002495
2496 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002497 dst = skb_dst(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002498 if (ipv == 4) {
David Miller87e75972012-02-01 10:49:17 +00002499 struct rtable *rt = (struct rtable *) dst;
2500 __be32 *pkey = &ip_hdr(skb)->daddr;
2501
Julian Wiedmannec2c6722017-08-07 13:28:39 +02002502 if (rt && rt->rt_gateway)
David Miller87e75972012-02-01 10:49:17 +00002503 pkey = &rt->rt_gateway;
2504
Frank Blaschka4a71df52008-02-15 09:19:42 +01002505 /* IPv4 */
2506 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2507 memset(hdr->hdr.l3.dest_addr, 0, 12);
David Miller87e75972012-02-01 10:49:17 +00002508 *((__be32 *) (&hdr->hdr.l3.dest_addr[12])) = *pkey;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002509 } else if (ipv == 6) {
David Miller87e75972012-02-01 10:49:17 +00002510 struct rt6_info *rt = (struct rt6_info *) dst;
2511 struct in6_addr *pkey = &ipv6_hdr(skb)->daddr;
2512
Julian Wiedmannec2c6722017-08-07 13:28:39 +02002513 if (rt && !ipv6_addr_any(&rt->rt6i_gateway))
David Miller87e75972012-02-01 10:49:17 +00002514 pkey = &rt->rt6i_gateway;
2515
Frank Blaschka4a71df52008-02-15 09:19:42 +01002516 /* IPv6 */
2517 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2518 if (card->info.type == QETH_CARD_TYPE_IQD)
2519 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
David Miller87e75972012-02-01 10:49:17 +00002520 memcpy(hdr->hdr.l3.dest_addr, pkey, 16);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002521 } else {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002522 if (!memcmp(skb->data + sizeof(struct qeth_hdr),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002523 skb->dev->broadcast, 6)) {
2524 /* broadcast? */
2525 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2526 QETH_HDR_PASSTHRU;
2527 } else {
2528 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2529 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2530 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2531 }
2532 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002533 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002534}
2535
Julian Wiedmanncef6ff222017-08-15 17:02:46 +02002536static void qeth_l3_hdr_csum(struct qeth_card *card, struct qeth_hdr *hdr,
2537 struct sk_buff *skb)
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002538{
2539 struct iphdr *iph = ip_hdr(skb);
2540
2541 /* tcph->check contains already the pseudo hdr checksum
2542 * so just set the header flags
2543 */
2544 if (iph->protocol == IPPROTO_UDP)
2545 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
Frank Blaschka16c0f932011-01-12 20:42:25 +00002546 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
2547 QETH_HDR_EXT_CSUM_HDR_REQ;
2548 iph->check = 0;
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002549 if (card->options.performance_stats)
2550 card->perf_stats.tx_csum++;
2551}
2552
Frank Blaschka64ef8952009-03-24 20:57:16 +00002553static void qeth_tso_fill_header(struct qeth_card *card,
2554 struct qeth_hdr *qhdr, struct sk_buff *skb)
2555{
2556 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2557 struct tcphdr *tcph = tcp_hdr(skb);
2558 struct iphdr *iph = ip_hdr(skb);
2559 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2560
2561 /*fix header to TSO values ...*/
2562 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
Frank Blaschka8fa92082010-11-26 02:41:20 +00002563 hdr->hdr.hdr.l3.length = skb->len - sizeof(struct qeth_hdr_tso);
Frank Blaschka64ef8952009-03-24 20:57:16 +00002564 /*set values which are fix for the first approach ...*/
2565 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2566 hdr->ext.imb_hdr_no = 1;
2567 hdr->ext.hdr_type = 1;
2568 hdr->ext.hdr_version = 1;
2569 hdr->ext.hdr_len = 28;
2570 /*insert non-fix values */
2571 hdr->ext.mss = skb_shinfo(skb)->gso_size;
Julian Wiedmannf8eb4932017-08-15 17:02:45 +02002572 hdr->ext.dg_hdr_len = (__u16)(ip_hdrlen(skb) + tcp_hdrlen(skb));
Frank Blaschka64ef8952009-03-24 20:57:16 +00002573 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2574 sizeof(struct qeth_hdr_tso));
2575 tcph->check = 0;
Hans Wippel6bee4e22017-04-07 09:15:36 +02002576 if (be16_to_cpu(skb->protocol) == ETH_P_IPV6) {
Frank Blaschka64ef8952009-03-24 20:57:16 +00002577 ip6h->payload_len = 0;
2578 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2579 0, IPPROTO_TCP, 0);
2580 } else {
2581 /*OSA want us to set these values ...*/
2582 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2583 0, IPPROTO_TCP, 0);
2584 iph->tot_len = 0;
2585 iph->check = 0;
2586 }
2587}
2588
Eugene Crosser2863c612016-06-16 16:18:52 +02002589/**
Eugene Crosser41aeed52016-06-16 16:18:53 +02002590 * qeth_l3_get_elements_no_tso() - find number of SBALEs for skb data for tso
2591 * @card: qeth card structure, to check max. elems.
2592 * @skb: SKB address
2593 * @extra_elems: extra elems needed, to check against max.
Eugene Crosser2863c612016-06-16 16:18:52 +02002594 *
2595 * Returns the number of pages, and thus QDIO buffer elements, needed to cover
2596 * skb data, including linear part and fragments, but excluding TCP header.
2597 * (Exclusion of TCP header distinguishes it from qeth_get_elements_no().)
2598 * Checks if the result plus extra_elems fits under the limit for the card.
2599 * Returns 0 if it does not.
2600 * Note: extra_elems is not included in the returned result.
2601 */
Eugene Crosser41aeed52016-06-16 16:18:53 +02002602static int qeth_l3_get_elements_no_tso(struct qeth_card *card,
Eugene Crosser2863c612016-06-16 16:18:52 +02002603 struct sk_buff *skb, int extra_elems)
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002604{
Eugene Crosser2863c612016-06-16 16:18:52 +02002605 addr_t tcpdptr = (addr_t)tcp_hdr(skb) + tcp_hdrlen(skb);
2606 int elements = qeth_get_elements_for_range(
2607 tcpdptr,
2608 (addr_t)skb->data + skb_headlen(skb)) +
Thomas Richter8f43fb02016-06-16 16:18:59 +02002609 qeth_get_elements_for_frags(skb);
Frank Blaschka271648b2013-03-18 20:04:44 +00002610
Eugene Crosser2863c612016-06-16 16:18:52 +02002611 if ((elements + extra_elems) > QETH_MAX_BUFFER_ELEMENTS(card)) {
2612 QETH_DBF_MESSAGE(2,
2613 "Invalid size of TSO IP packet (Number=%d / Length=%d). Discarded.\n",
2614 elements + extra_elems, skb->len);
2615 return 0;
2616 }
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002617 return elements;
2618}
2619
Julian Wiedmanne38db6b2017-04-11 16:11:14 +02002620static netdev_tx_t qeth_l3_hard_start_xmit(struct sk_buff *skb,
2621 struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002622{
2623 int rc;
Hans Wippel6bee4e22017-04-07 09:15:36 +02002624 __be16 *tag;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002625 struct qeth_hdr *hdr = NULL;
Eugene Crosser2863c612016-06-16 16:18:52 +02002626 int hdr_elements = 0;
2627 int elements;
Heiko Carstens509e2562008-07-26 02:24:10 -07002628 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002629 struct sk_buff *new_skb = NULL;
2630 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002631 int cast_type = qeth_l3_get_cast_type(card, skb);
Stefan Raspl290b8342014-04-28 10:05:08 +02002632 struct qeth_qdio_out_q *queue =
2633 card->qdio.out_qs[card->qdio.do_prio_queueing
2634 || (cast_type && card->info.is_multicast_different) ?
2635 qeth_get_priority_queue(card, skb, ipv, cast_type) :
2636 card->qdio.default_out_queue];
Frank Blaschka4a71df52008-02-15 09:19:42 +01002637 int tx_bytes = skb->len;
Julian Wiedmann13ddacb2017-08-18 10:19:06 +02002638 unsigned int hd_len = 0;
Eugene Crosser41aeed52016-06-16 16:18:53 +02002639 bool use_tso;
Frank Blaschka683d7182008-08-01 16:39:13 +02002640 int data_offset = -1;
Julian Wiedmann886e1972017-08-15 17:02:39 +02002641 unsigned int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002642
Frank Blaschkab3332932011-08-08 01:33:59 +00002643 if (((card->info.type == QETH_CARD_TYPE_IQD) &&
2644 (((card->options.cq != QETH_CQ_ENABLED) && !ipv) ||
2645 ((card->options.cq == QETH_CQ_ENABLED) &&
Hans Wippel6bee4e22017-04-07 09:15:36 +02002646 (be16_to_cpu(skb->protocol) != ETH_P_AF_IUCV)))) ||
Frank Blaschkab3332932011-08-08 01:33:59 +00002647 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002648 goto tx_drop;
2649
2650 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2651 card->stats.tx_carrier_errors++;
2652 goto tx_drop;
2653 }
2654
2655 if ((cast_type == RTN_BROADCAST) &&
2656 (card->info.broadcast_capable == 0))
2657 goto tx_drop;
2658
2659 if (card->options.performance_stats) {
2660 card->perf_stats.outbound_cnt++;
2661 card->perf_stats.outbound_start_time = qeth_get_micros();
2662 }
2663
Eugene Crosser41aeed52016-06-16 16:18:53 +02002664 /* Ignore segment size from skb_is_gso(), 1 page is always used. */
2665 use_tso = skb_is_gso(skb) &&
Julian Wiedmannf8eb4932017-08-15 17:02:45 +02002666 (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4);
Frank Blaschka683d7182008-08-01 16:39:13 +02002667
Julian Wiedmann94a9c982017-06-06 14:33:43 +02002668 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02002669 new_skb = skb;
Julian Wiedmannacd97762017-03-23 14:55:09 +01002670 data_offset = ETH_HLEN;
Julian Wiedmannf1588172017-08-18 10:19:08 +02002671 hd_len = sizeof(*hdr);
Frank Blaschka683d7182008-08-01 16:39:13 +02002672 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2673 if (!hdr)
2674 goto tx_drop;
Eugene Crosser2863c612016-06-16 16:18:52 +02002675 hdr_elements++;
Frank Blaschka683d7182008-08-01 16:39:13 +02002676 } else {
2677 /* create a clone with writeable headroom */
2678 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
2679 + VLAN_HLEN);
2680 if (!new_skb)
2681 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002682
Frank Blaschka21fde742010-03-08 20:36:54 +00002683 if (ipv == 4) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002684 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002685 }
2686
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002687 if (ipv != 4 && skb_vlan_tag_present(new_skb)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002688 skb_push(new_skb, VLAN_HLEN);
2689 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2690 skb_copy_to_linear_data_offset(new_skb, 4,
2691 new_skb->data + 8, 4);
2692 skb_copy_to_linear_data_offset(new_skb, 8,
2693 new_skb->data + 12, 4);
Hans Wippel6bee4e22017-04-07 09:15:36 +02002694 tag = (__be16 *)(new_skb->data + 12);
2695 *tag = cpu_to_be16(ETH_P_8021Q);
2696 *(tag + 1) = cpu_to_be16(skb_vlan_tag_get(new_skb));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002697 }
2698 }
2699
2700 netif_stop_queue(dev);
2701
Frank Blaschka4a71df52008-02-15 09:19:42 +01002702 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00002703 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01002704 */
Eugene Crosser41aeed52016-06-16 16:18:53 +02002705 if ((card->info.type != QETH_CARD_TYPE_IQD) &&
2706 ((use_tso && !qeth_l3_get_elements_no_tso(card, new_skb, 1)) ||
Julian Wiedmann7d969d22017-03-23 14:55:08 +01002707 (!use_tso && !qeth_get_elements_no(card, new_skb, 0, 0)))) {
Eugene Crosser6059c902016-06-16 16:18:57 +02002708 int lin_rc = skb_linearize(new_skb);
2709
2710 if (card->options.performance_stats) {
2711 if (lin_rc)
2712 card->perf_stats.tx_linfail++;
2713 else
2714 card->perf_stats.tx_lin++;
2715 }
2716 if (lin_rc)
Eugene Crosser41aeed52016-06-16 16:18:53 +02002717 goto tx_drop;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002718 }
Julian Wiedmann886e1972017-08-15 17:02:39 +02002719 nr_frags = skb_shinfo(new_skb)->nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002720
Eugene Crosser41aeed52016-06-16 16:18:53 +02002721 if (use_tso) {
Johannes Bergd58ff352017-06-16 14:29:23 +02002722 hdr = skb_push(new_skb, sizeof(struct qeth_hdr_tso));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002723 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
2724 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
2725 qeth_tso_fill_header(card, hdr, new_skb);
Eugene Crosser2863c612016-06-16 16:18:52 +02002726 hdr_elements++;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002727 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02002728 if (data_offset < 0) {
Johannes Bergd58ff352017-06-16 14:29:23 +02002729 hdr = skb_push(new_skb, sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02002730 qeth_l3_fill_header(card, hdr, new_skb, ipv,
2731 cast_type);
2732 } else {
Hans Wippel6bee4e22017-04-07 09:15:36 +02002733 if (be16_to_cpu(new_skb->protocol) == ETH_P_AF_IUCV)
Frank Blaschkab3332932011-08-08 01:33:59 +00002734 qeth_l3_fill_af_iucv_hdr(card, hdr, new_skb);
2735 else {
2736 qeth_l3_fill_header(card, hdr, new_skb, ipv,
2737 cast_type);
2738 hdr->hdr.l3.length = new_skb->len - data_offset;
2739 }
Frank Blaschka683d7182008-08-01 16:39:13 +02002740 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002741
2742 if (skb->ip_summed == CHECKSUM_PARTIAL)
2743 qeth_l3_hdr_csum(card, hdr, new_skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002744 }
2745
Eugene Crosser41aeed52016-06-16 16:18:53 +02002746 elements = use_tso ?
2747 qeth_l3_get_elements_no_tso(card, new_skb, hdr_elements) :
Julian Wiedmann7d969d22017-03-23 14:55:08 +01002748 qeth_get_elements_no(card, new_skb, hdr_elements,
2749 (data_offset > 0) ? data_offset : 0);
Eugene Crosser2863c612016-06-16 16:18:52 +02002750 if (!elements) {
Frank Blaschka64ef8952009-03-24 20:57:16 +00002751 if (data_offset >= 0)
2752 kmem_cache_free(qeth_core_header_cache, hdr);
2753 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002754 }
Eugene Crosser2863c612016-06-16 16:18:52 +02002755 elements += hdr_elements;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002756
Frank Blaschka51aa1652010-06-21 22:57:10 +00002757 if (card->info.type != QETH_CARD_TYPE_IQD) {
2758 int len;
Julian Wiedmann13ddacb2017-08-18 10:19:06 +02002759 if (use_tso) {
2760 hd_len = sizeof(struct qeth_hdr_tso) +
2761 ip_hdrlen(new_skb) + tcp_hdrlen(new_skb);
2762 len = hd_len;
2763 } else {
Frank Blaschka51aa1652010-06-21 22:57:10 +00002764 len = sizeof(struct qeth_hdr_layer3);
Julian Wiedmann13ddacb2017-08-18 10:19:06 +02002765 }
Frank Blaschka51aa1652010-06-21 22:57:10 +00002766
Stefan Raspld4ae1f52013-04-22 01:12:29 +00002767 if (qeth_hdr_chk_and_bounce(new_skb, &hdr, len))
Frank Blaschka51aa1652010-06-21 22:57:10 +00002768 goto tx_drop;
Julian Wiedmann13ddacb2017-08-18 10:19:06 +02002769 rc = qeth_do_send_packet(card, queue, new_skb, hdr, hd_len,
Julian Wiedmann9c3bfda2017-08-18 10:19:07 +02002770 hd_len, elements);
Frank Blaschka51aa1652010-06-21 22:57:10 +00002771 } else
Julian Wiedmann7c2e9ba2017-09-18 21:18:18 +02002772 rc = qeth_do_send_packet_fast(queue, new_skb, hdr, data_offset,
2773 hd_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002774
2775 if (!rc) {
2776 card->stats.tx_packets++;
2777 card->stats.tx_bytes += tx_bytes;
2778 if (new_skb != skb)
2779 dev_kfree_skb_any(skb);
2780 if (card->options.performance_stats) {
Eugene Crosser41aeed52016-06-16 16:18:53 +02002781 if (use_tso) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002782 card->perf_stats.large_send_bytes += tx_bytes;
2783 card->perf_stats.large_send_cnt++;
2784 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00002785 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002786 card->perf_stats.sg_skbs_sent++;
2787 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00002788 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002789 }
2790 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07002791 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002792 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02002793 if (data_offset >= 0)
2794 kmem_cache_free(qeth_core_header_cache, hdr);
2795
Frank Blaschka4a71df52008-02-15 09:19:42 +01002796 if (rc == -EBUSY) {
2797 if (new_skb != skb)
2798 dev_kfree_skb_any(new_skb);
2799 return NETDEV_TX_BUSY;
2800 } else
2801 goto tx_drop;
2802 }
2803
2804 netif_wake_queue(dev);
2805 if (card->options.performance_stats)
2806 card->perf_stats.outbound_time += qeth_get_micros() -
2807 card->perf_stats.outbound_start_time;
2808 return rc;
2809
2810tx_drop:
2811 card->stats.tx_dropped++;
2812 card->stats.tx_errors++;
2813 if ((new_skb != skb) && new_skb)
2814 dev_kfree_skb_any(new_skb);
2815 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02002816 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002817 return NETDEV_TX_OK;
2818}
2819
Ursula Braun39423442011-01-12 20:42:24 +00002820static int __qeth_l3_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002821{
Heiko Carstens509e2562008-07-26 02:24:10 -07002822 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002823 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002824
Carsten Otte847a50f2010-06-21 22:57:05 +00002825 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +00002826 if (card->state == CARD_STATE_UP)
2827 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002828 if (card->state != CARD_STATE_SOFTSETUP)
2829 return -ENODEV;
2830 card->data.state = CH_STATE_UP;
2831 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002832 netif_start_queue(dev);
2833
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002834 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
2835 napi_enable(&card->napi);
2836 napi_schedule(&card->napi);
2837 } else
2838 rc = -EIO;
2839 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002840}
2841
Ursula Braun39423442011-01-12 20:42:24 +00002842static int qeth_l3_open(struct net_device *dev)
2843{
2844 struct qeth_card *card = dev->ml_priv;
2845
2846 QETH_CARD_TEXT(card, 5, "qethope_");
2847 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
2848 QETH_CARD_TEXT(card, 3, "openREC");
2849 return -ERESTARTSYS;
2850 }
2851 return __qeth_l3_open(dev);
2852}
2853
Frank Blaschka4a71df52008-02-15 09:19:42 +01002854static int qeth_l3_stop(struct net_device *dev)
2855{
Heiko Carstens509e2562008-07-26 02:24:10 -07002856 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002857
Carsten Otte847a50f2010-06-21 22:57:05 +00002858 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002859 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002860 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002861 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002862 napi_disable(&card->napi);
2863 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002864 return 0;
2865}
2866
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07002867static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002868 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002869 .get_strings = qeth_core_get_strings,
2870 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00002871 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002872 .get_drvinfo = qeth_core_get_drvinfo,
Julian Wiedmann993e19c2017-04-11 16:11:17 +02002873 .get_link_ksettings = qeth_core_ethtool_get_link_ksettings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002874};
2875
2876/*
2877 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
2878 * NOARP on the netdevice is no option because it also turns off neighbor
2879 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
2880 * arp resolution but we want the hard header (packet socket will work
2881 * e.g. tcpdump)
2882 */
2883static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
2884{
2885 n->nud_state = NUD_NOARP;
2886 memcpy(n->ha, "FAKELL", 6);
2887 n->output = n->ops->connected_output;
2888 return 0;
2889}
2890
2891static int
2892qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
2893{
2894 if (np->tbl->family == AF_INET)
2895 np->neigh_setup = qeth_l3_neigh_setup_noarp;
2896
2897 return 0;
2898}
2899
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002900static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08002901 .ndo_open = qeth_l3_open,
2902 .ndo_stop = qeth_l3_stop,
2903 .ndo_get_stats = qeth_get_stats,
2904 .ndo_start_xmit = qeth_l3_hard_start_xmit,
2905 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002906 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002907 .ndo_do_ioctl = qeth_do_ioctl,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002908 .ndo_change_mtu = qeth_change_mtu,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002909 .ndo_fix_features = qeth_fix_features,
2910 .ndo_set_features = qeth_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08002911 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2912 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002913 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka8403b132009-01-08 10:50:55 -08002914};
2915
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002916static const struct net_device_ops qeth_l3_osa_netdev_ops = {
2917 .ndo_open = qeth_l3_open,
2918 .ndo_stop = qeth_l3_stop,
2919 .ndo_get_stats = qeth_get_stats,
2920 .ndo_start_xmit = qeth_l3_hard_start_xmit,
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +01002921 .ndo_features_check = qeth_features_check,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002922 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002923 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002924 .ndo_do_ioctl = qeth_do_ioctl,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002925 .ndo_change_mtu = qeth_change_mtu,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002926 .ndo_fix_features = qeth_fix_features,
2927 .ndo_set_features = qeth_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002928 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2929 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002930 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002931 .ndo_neigh_setup = qeth_l3_neigh_setup,
2932};
2933
Frank Blaschka4a71df52008-02-15 09:19:42 +01002934static int qeth_l3_setup_netdev(struct qeth_card *card)
2935{
Thomas Richter1aec42b2015-01-21 13:39:10 +01002936 int rc;
2937
Ursula Braun5113fec2010-05-16 21:15:14 +00002938 if (card->info.type == QETH_CARD_TYPE_OSD ||
2939 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002940 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
2941 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002942 pr_info("qeth_l3: ignoring TR device\n");
2943 return -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002944 } else {
2945 card->dev = alloc_etherdev(0);
2946 if (!card->dev)
2947 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002948 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002949
2950 /*IPv6 address autoconfiguration stuff*/
2951 qeth_l3_get_unique_id(card);
2952 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
2953 card->dev->dev_id = card->info.unique_id &
2954 0xffff;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00002955 if (!card->info.guestlan) {
2956 card->dev->hw_features = NETIF_F_SG |
2957 NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
2958 NETIF_F_TSO;
Hans Wippel9bdc4412016-06-16 16:19:00 +02002959 card->dev->vlan_features = NETIF_F_SG |
2960 NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
2961 NETIF_F_TSO;
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +01002962 card->dev->features |= NETIF_F_SG;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00002963 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002964 }
2965 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
Tom Gundersenc835a672014-07-14 16:37:24 +02002966 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
2967 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002968 if (!card->dev)
2969 return -ENODEV;
2970 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002971 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Thomas Richter1aec42b2015-01-21 13:39:10 +01002972 rc = qeth_l3_iqd_read_initial_mac(card);
2973 if (rc)
2974 return rc;
Frank Blaschkab3332932011-08-08 01:33:59 +00002975 if (card->options.hsuid[0])
2976 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002977 } else
2978 return -ENODEV;
2979
Heiko Carstens509e2562008-07-26 02:24:10 -07002980 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002981 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002982 card->dev->mtu = card->info.initial_mtu;
Jarod Wilson46b3ef42016-10-20 13:55:23 -04002983 card->dev->min_mtu = 64;
2984 card->dev->max_mtu = ETH_MAX_MTU;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002985 card->dev->ethtool_ops = &qeth_l3_ethtool_ops;
Patrick McHardyf6469682013-04-19 02:04:27 +00002986 card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2987 NETIF_F_HW_VLAN_CTAG_RX |
2988 NETIF_F_HW_VLAN_CTAG_FILTER;
Eric Dumazet02875872014-10-05 18:38:35 -07002989 netif_keep_dst(card->dev);
Eugene Crosser8bad55f2016-06-16 16:18:54 +02002990 card->dev->gso_max_size = (QETH_MAX_BUFFER_ELEMENTS(card) - 1) *
2991 PAGE_SIZE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002992
2993 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Julian Wiedmannd73ef322017-04-11 16:11:11 +02002994 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Ursula Braune5ebe632015-12-11 12:27:55 +01002995 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002996 return register_netdev(card->dev);
2997}
2998
Ursula Braun79a04e42017-06-06 14:33:49 +02002999static const struct device_type qeth_l3_devtype = {
3000 .name = "qeth_layer3",
3001 .groups = qeth_l3_attr_groups,
3002};
3003
Frank Blaschka4a71df52008-02-15 09:19:42 +01003004static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3005{
3006 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +02003007 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003008
Ursula Braun79a04e42017-06-06 14:33:49 +02003009 if (gdev->dev.type == &qeth_generic_devtype) {
3010 rc = qeth_l3_create_device_attributes(&gdev->dev);
3011 if (rc)
3012 return rc;
3013 }
Ursula Braunebccc7392017-05-10 19:07:54 +02003014 hash_init(card->ip_htable);
3015 hash_init(card->ip_mc_htable);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003016 card->options.layer2 = 0;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003017 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003018 return 0;
3019}
3020
3021static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3022{
3023 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3024
Ursula Braun79a04e42017-06-06 14:33:49 +02003025 if (cgdev->dev.type == &qeth_generic_devtype)
3026 qeth_l3_remove_device_attributes(&cgdev->dev);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003027
Ursula Braunf2148562009-05-19 21:38:37 +00003028 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003029 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3030
Ursula Braun70919e22011-02-26 22:41:36 -08003031 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003032 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003033
3034 if (card->dev) {
Ursula Braun7831b4f2016-07-04 14:07:16 +02003035 netif_napi_del(&card->napi);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003036 unregister_netdev(card->dev);
3037 card->dev = NULL;
3038 }
3039
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003040 qeth_l3_clear_ip_htable(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003041 qeth_l3_clear_ipato_list(card);
3042 return;
3043}
3044
3045static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3046{
3047 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3048 int rc = 0;
3049 enum qeth_card_states recover_flag;
3050
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003051 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003052 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003053 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3054 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003055
Frank Blaschka4a71df52008-02-15 09:19:42 +01003056 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003057 rc = qeth_core_hardsetup_card(card);
3058 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01003059 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003060 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003061 goto out_remove;
3062 }
3063
Ursula Braunaa909222009-11-12 00:11:43 +00003064 if (!card->dev && qeth_l3_setup_netdev(card)) {
3065 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003066 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00003067 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003068
Frank Blaschka1da74b12011-05-12 18:45:02 +00003069 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
3070 if (card->info.hwtrap &&
3071 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
3072 card->info.hwtrap = 0;
3073 } else
3074 card->info.hwtrap = 0;
3075
Frank Blaschka4a71df52008-02-15 09:19:42 +01003076 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003077 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003078 qeth_print_status_message(card);
3079
3080 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003081 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003082
Frank Blaschka4a71df52008-02-15 09:19:42 +01003083 rc = qeth_l3_setadapter_parms(card);
3084 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003085 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003086 if (!card->options.sniffer) {
3087 rc = qeth_l3_start_ipassists(card);
Stefan Raspl0f547612013-01-21 02:30:20 +00003088 if (rc) {
Ursula Braun76b11f82010-01-11 02:50:50 +00003089 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Stefan Raspl0f547612013-01-21 02:30:20 +00003090 goto out_remove;
3091 }
Ursula Braun76b11f82010-01-11 02:50:50 +00003092 rc = qeth_l3_setrouting_v4(card);
3093 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003094 QETH_DBF_TEXT_(SETUP, 2, "4err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003095 rc = qeth_l3_setrouting_v6(card);
3096 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003097 QETH_DBF_TEXT_(SETUP, 2, "5err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003098 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003099 netif_tx_disable(card->dev);
3100
3101 rc = qeth_init_qdio_queues(card);
3102 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003103 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003104 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003105 goto out_remove;
3106 }
3107 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003108
3109 qeth_set_allowed_threads(card, 0xffffffff, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003110 qeth_l3_recover_ip(card);
Ursula Braun2b6203b2010-11-26 02:41:19 +00003111 if (card->lan_online)
3112 netif_carrier_on(card->dev);
3113 else
3114 netif_carrier_off(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003115 if (recover_flag == CARD_STATE_RECOVER) {
Ursula Braun4763b0a2011-12-19 22:56:32 +00003116 rtnl_lock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003117 if (recovery_mode)
Ursula Braun39423442011-01-12 20:42:24 +00003118 __qeth_l3_open(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00003119 else
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003120 dev_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003121 qeth_l3_set_multicast_list(card->dev);
Hans Wippele830baa2016-09-15 14:39:21 +02003122 qeth_recover_features(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00003123 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01003124 }
Stefan Raspl82f77cf2013-03-18 20:04:42 +00003125 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003126 /* let user_space know that device is online */
3127 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003128 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003129 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003130 return 0;
3131out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003132 qeth_l3_stop_card(card, 0);
3133 ccw_device_set_offline(CARD_DDEV(card));
3134 ccw_device_set_offline(CARD_WDEV(card));
3135 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01003136 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003137 if (recover_flag == CARD_STATE_RECOVER)
3138 card->state = CARD_STATE_RECOVER;
3139 else
3140 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00003141 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003142 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00003143 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003144}
3145
3146static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3147{
3148 return __qeth_l3_set_online(gdev, 0);
3149}
3150
3151static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3152 int recovery_mode)
3153{
3154 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3155 int rc = 0, rc2 = 0, rc3 = 0;
3156 enum qeth_card_states recover_flag;
3157
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003158 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003159 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003160 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3161 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003162
3163 if (card->dev && netif_carrier_ok(card->dev))
3164 netif_carrier_off(card->dev);
3165 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003166 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
3167 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
3168 card->info.hwtrap = 1;
3169 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02003170 qeth_l3_stop_card(card, recovery_mode);
Einar Lueck72861ae2011-12-19 22:56:36 +00003171 if ((card->options.cq == QETH_CQ_ENABLED) && card->dev) {
3172 rtnl_lock();
3173 call_netdevice_notifiers(NETDEV_REBOOT, card->dev);
3174 rtnl_unlock();
3175 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003176 rc = ccw_device_set_offline(CARD_DDEV(card));
3177 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3178 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3179 if (!rc)
3180 rc = (rc2) ? rc2 : rc3;
3181 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003182 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01003183 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003184 if (recover_flag == CARD_STATE_UP)
3185 card->state = CARD_STATE_RECOVER;
3186 /* let user_space know that device is offline */
3187 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003188 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003189 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003190 return 0;
3191}
3192
3193static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3194{
3195 return __qeth_l3_set_offline(cgdev, 0);
3196}
3197
3198static int qeth_l3_recover(void *ptr)
3199{
3200 struct qeth_card *card;
3201 int rc = 0;
3202
3203 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00003204 QETH_CARD_TEXT(card, 2, "recover1");
3205 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003206 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3207 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00003208 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003209 dev_warn(&card->gdev->dev,
3210 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00003211 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003212 __qeth_l3_set_offline(card->gdev, 1);
3213 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003214 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003215 dev_info(&card->gdev->dev,
3216 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003217 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00003218 qeth_close_dev(card);
3219 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00003220 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003221 }
Stefan Raspl65d80132013-04-07 22:19:27 +00003222 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003223 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3224 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003225 return 0;
3226}
3227
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003228static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3229{
3230 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3231
3232 if (card->dev)
3233 netif_device_detach(card->dev);
3234 qeth_set_allowed_threads(card, 0, 1);
3235 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3236 if (gdev->state == CCWGROUP_OFFLINE)
3237 return 0;
3238 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00003239 if (card->info.hwtrap)
3240 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003241 __qeth_l3_set_offline(card->gdev, 1);
3242 } else
3243 __qeth_l3_set_offline(card->gdev, 0);
3244 return 0;
3245}
3246
3247static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3248{
3249 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3250 int rc = 0;
3251
3252 if (gdev->state == CCWGROUP_OFFLINE)
3253 goto out;
3254
3255 if (card->state == CARD_STATE_RECOVER) {
3256 rc = __qeth_l3_set_online(card->gdev, 1);
3257 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00003258 rtnl_lock();
3259 dev_close(card->dev);
3260 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003261 }
3262 } else
3263 rc = __qeth_l3_set_online(card->gdev, 0);
3264out:
3265 qeth_set_allowed_threads(card, 0xffffffff, 0);
3266 if (card->dev)
3267 netif_device_attach(card->dev);
3268 if (rc)
3269 dev_warn(&card->gdev->dev, "The qeth device driver "
3270 "failed to recover an error on the device\n");
3271 return rc;
3272}
3273
Eugene Crosserc044dc22014-01-29 09:23:48 +01003274/* Returns zero if the command is successfully "consumed" */
3275static int qeth_l3_control_event(struct qeth_card *card,
3276 struct qeth_ipa_cmd *cmd)
3277{
3278 return 1;
3279}
3280
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003281struct qeth_discipline qeth_l3_discipline = {
Ursula Braun79a04e42017-06-06 14:33:49 +02003282 .devtype = &qeth_l3_devtype,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003283 .start_poll = qeth_qdio_start_poll,
3284 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
3285 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02003286 .process_rx_buffer = qeth_l3_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003287 .recover = qeth_l3_recover,
3288 .setup = qeth_l3_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003289 .remove = qeth_l3_remove_device,
3290 .set_online = qeth_l3_set_online,
3291 .set_offline = qeth_l3_set_offline,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003292 .freeze = qeth_l3_pm_suspend,
3293 .thaw = qeth_l3_pm_resume,
3294 .restore = qeth_l3_pm_resume,
Julian Wiedmann942d6982017-04-11 16:11:10 +02003295 .do_ioctl = qeth_l3_do_ioctl,
Eugene Crosserc044dc22014-01-29 09:23:48 +01003296 .control_event_handler = qeth_l3_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003297};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003298EXPORT_SYMBOL_GPL(qeth_l3_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003299
3300static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003301 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003302{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003303
Frank Blaschka4a71df52008-02-15 09:19:42 +01003304 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3305 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3306 struct qeth_ipaddr *addr;
3307 struct qeth_card *card;
3308
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003309 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003310 return NOTIFY_DONE;
3311
Frank Blaschka4a71df52008-02-15 09:19:42 +01003312 card = qeth_l3_get_card_from_dev(dev);
3313 if (!card)
3314 return NOTIFY_DONE;
frank.blaschka@de.ibm.com6d8823d2012-05-16 01:28:26 +00003315 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003316
3317 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003318 if (addr) {
Hans Wippel6bee4e22017-04-07 09:15:36 +02003319 addr->u.a4.addr = be32_to_cpu(ifa->ifa_address);
3320 addr->u.a4.mask = be32_to_cpu(ifa->ifa_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003321 addr->type = QETH_IP_TYPE_NORMAL;
3322 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003323 return NOTIFY_DONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003324
3325 switch (event) {
3326 case NETDEV_UP:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003327 spin_lock_bh(&card->ip_lock);
3328 qeth_l3_add_ip(card, addr);
3329 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003330 break;
3331 case NETDEV_DOWN:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003332 spin_lock_bh(&card->ip_lock);
3333 qeth_l3_delete_ip(card, addr);
3334 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003335 break;
3336 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003337
3338 kfree(addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003339 return NOTIFY_DONE;
3340}
3341
3342static struct notifier_block qeth_l3_ip_notifier = {
3343 qeth_l3_ip_event,
3344 NULL,
3345};
3346
3347#ifdef CONFIG_QETH_IPV6
3348/**
3349 * IPv6 event handler
3350 */
3351static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003352 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003353{
3354 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3355 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3356 struct qeth_ipaddr *addr;
3357 struct qeth_card *card;
3358
Frank Blaschka4a71df52008-02-15 09:19:42 +01003359 card = qeth_l3_get_card_from_dev(dev);
3360 if (!card)
3361 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00003362 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003363 if (!qeth_is_supported(card, IPA_IPV6))
3364 return NOTIFY_DONE;
3365
3366 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003367 if (addr) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003368 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3369 addr->u.a6.pfxlen = ifa->prefix_len;
3370 addr->type = QETH_IP_TYPE_NORMAL;
3371 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003372 return NOTIFY_DONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003373
3374 switch (event) {
3375 case NETDEV_UP:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003376 spin_lock_bh(&card->ip_lock);
3377 qeth_l3_add_ip(card, addr);
3378 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003379 break;
3380 case NETDEV_DOWN:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003381 spin_lock_bh(&card->ip_lock);
3382 qeth_l3_delete_ip(card, addr);
3383 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003384 break;
3385 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003386
3387 kfree(addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003388 return NOTIFY_DONE;
3389}
3390
3391static struct notifier_block qeth_l3_ip6_notifier = {
3392 qeth_l3_ip6_event,
3393 NULL,
3394};
3395#endif
3396
3397static int qeth_l3_register_notifiers(void)
3398{
3399 int rc;
3400
Carsten Otte847a50f2010-06-21 22:57:05 +00003401 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003402 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3403 if (rc)
3404 return rc;
3405#ifdef CONFIG_QETH_IPV6
3406 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3407 if (rc) {
3408 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3409 return rc;
3410 }
3411#else
Joe Perchesbaebc702016-03-03 20:49:57 -08003412 pr_warn("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003413#endif
3414 return 0;
3415}
3416
3417static void qeth_l3_unregister_notifiers(void)
3418{
3419
Carsten Otte847a50f2010-06-21 22:57:05 +00003420 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Stefan Raspl18af5c12012-11-19 02:46:50 +00003421 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003422#ifdef CONFIG_QETH_IPV6
Stefan Raspl18af5c12012-11-19 02:46:50 +00003423 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003424#endif /* QETH_IPV6 */
3425}
3426
3427static int __init qeth_l3_init(void)
3428{
3429 int rc = 0;
3430
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003431 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003432 rc = qeth_l3_register_notifiers();
3433 return rc;
3434}
3435
3436static void __exit qeth_l3_exit(void)
3437{
3438 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003439 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003440}
3441
3442module_init(qeth_l3_init);
3443module_exit(qeth_l3_exit);
3444MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3445MODULE_DESCRIPTION("qeth layer 3 discipline");
3446MODULE_LICENSE("GPL");