blob: 6e0354ef4b8629827e4c8ef40b9d569bc11e354b [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--;
250 if (addr->type == QETH_IP_TYPE_NORMAL && addr->ref_counter > 0)
251 return rc;
252 if (addr->in_progress)
253 return -EINPROGRESS;
254
Ursula Brauna7531c12016-09-15 14:39:23 +0200255 if (!qeth_card_hw_is_reachable(card)) {
256 addr->disp_flag = QETH_DISP_ADDR_DELETE;
257 return 0;
258 }
259
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200260 rc = qeth_l3_deregister_addr_entry(card, addr);
261
262 hash_del(&addr->hnode);
263 kfree(addr);
264
Frank Blaschka4a71df52008-02-15 09:19:42 +0100265 return rc;
266}
267
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200268int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100269{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100270 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200271 struct qeth_ipaddr *addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100272
Carsten Otte847a50f2010-06-21 22:57:05 +0000273 QETH_CARD_TEXT(card, 4, "addip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200274
275 if (tmp_addr->proto == QETH_PROT_IPV4)
276 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100277 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200278 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
279 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100280 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200281
282 addr = qeth_l3_ip_from_hash(card, tmp_addr);
283 if (!addr) {
284 addr = qeth_l3_get_addr_buffer(tmp_addr->proto);
285 if (!addr)
286 return -ENOMEM;
287
288 memcpy(addr, tmp_addr, sizeof(struct qeth_ipaddr));
289 addr->ref_counter = 1;
290
291 if (addr->type == QETH_IP_TYPE_NORMAL &&
292 qeth_l3_is_addr_covered_by_ipato(card, addr)) {
293 QETH_CARD_TEXT(card, 2, "tkovaddr");
294 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
295 }
296 hash_add(card->ip_htable, &addr->hnode,
297 qeth_l3_ipaddr_hash(addr));
298
Ursula Brauna7531c12016-09-15 14:39:23 +0200299 if (!qeth_card_hw_is_reachable(card)) {
300 addr->disp_flag = QETH_DISP_ADDR_ADD;
301 return 0;
302 }
303
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200304 /* qeth_l3_register_addr_entry can go to sleep
305 * if we add a IPV4 addr. It is caused by the reason
306 * that SETIP ipa cmd starts ARP staff for IPV4 addr.
307 * Thus we should unlock spinlock, and make a protection
308 * using in_progress variable to indicate that there is
309 * an hardware operation with this IPV4 address
310 */
311 if (addr->proto == QETH_PROT_IPV4) {
312 addr->in_progress = 1;
313 spin_unlock_bh(&card->ip_lock);
314 rc = qeth_l3_register_addr_entry(card, addr);
315 spin_lock_bh(&card->ip_lock);
316 addr->in_progress = 0;
317 } else
318 rc = qeth_l3_register_addr_entry(card, addr);
319
320 if (!rc || (rc == IPA_RC_DUPLICATE_IP_ADDRESS) ||
321 (rc == IPA_RC_LAN_OFFLINE)) {
322 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
323 if (addr->ref_counter < 1) {
324 qeth_l3_delete_ip(card, addr);
325 kfree(addr);
326 }
327 } else {
328 hash_del(&addr->hnode);
329 kfree(addr);
330 }
331 } else {
332 if (addr->type == QETH_IP_TYPE_NORMAL)
333 addr->ref_counter++;
334 }
335
Frank Blaschka4a71df52008-02-15 09:19:42 +0100336 return rc;
337}
338
339
Frank Blaschkab3332932011-08-08 01:33:59 +0000340struct qeth_ipaddr *qeth_l3_get_addr_buffer(
Frank Blaschka4a71df52008-02-15 09:19:42 +0100341 enum qeth_prot_versions prot)
342{
343 struct qeth_ipaddr *addr;
344
345 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200346 if (!addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100347 return NULL;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200348
Frank Blaschka4a71df52008-02-15 09:19:42 +0100349 addr->type = QETH_IP_TYPE_NORMAL;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200350 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100351 addr->proto = prot;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200352
Frank Blaschka4a71df52008-02-15 09:19:42 +0100353 return addr;
354}
355
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200356static void qeth_l3_clear_ip_htable(struct qeth_card *card, int recover)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100357{
358 struct qeth_ipaddr *addr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200359 struct hlist_node *tmp;
360 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100361
Carsten Otte847a50f2010-06-21 22:57:05 +0000362 QETH_CARD_TEXT(card, 4, "clearip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200363
Ursula Braun76b11f82010-01-11 02:50:50 +0000364 if (recover && card->options.sniffer)
365 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100366
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200367 spin_lock_bh(&card->ip_lock);
368
369 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
370 if (!recover) {
371 hash_del(&addr->hnode);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100372 kfree(addr);
373 continue;
374 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200375 addr->disp_flag = QETH_DISP_ADDR_ADD;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100376 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200377
378 spin_unlock_bh(&card->ip_lock);
379
380 spin_lock_bh(&card->mclock);
381
382 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
383 hash_del(&addr->hnode);
384 kfree(addr);
385 }
386
387 spin_unlock_bh(&card->mclock);
388
389
Frank Blaschka4a71df52008-02-15 09:19:42 +0100390}
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200391static void qeth_l3_recover_ip(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100392{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200393 struct qeth_ipaddr *addr;
394 struct hlist_node *tmp;
395 int i;
396 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100397
Ursula Brauna7531c12016-09-15 14:39:23 +0200398 QETH_CARD_TEXT(card, 4, "recovrip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100399
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200400 spin_lock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100401
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200402 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
Ursula Brauna7531c12016-09-15 14:39:23 +0200403 if (addr->disp_flag == QETH_DISP_ADDR_DELETE) {
404 qeth_l3_deregister_addr_entry(card, addr);
405 hash_del(&addr->hnode);
406 kfree(addr);
407 } else if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200408 if (addr->proto == QETH_PROT_IPV4) {
409 addr->in_progress = 1;
410 spin_unlock_bh(&card->ip_lock);
411 rc = qeth_l3_register_addr_entry(card, addr);
412 spin_lock_bh(&card->ip_lock);
413 addr->in_progress = 0;
414 } else
415 rc = qeth_l3_register_addr_entry(card, addr);
416
417 if (!rc) {
418 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Ursula Brauna7531c12016-09-15 14:39:23 +0200419 if (addr->ref_counter < 1)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200420 qeth_l3_delete_ip(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200421 } else {
422 hash_del(&addr->hnode);
423 kfree(addr);
424 }
425 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100426 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200427
428 spin_unlock_bh(&card->ip_lock);
429
Frank Blaschka4a71df52008-02-15 09:19:42 +0100430}
431
432static int qeth_l3_send_setdelmc(struct qeth_card *card,
433 struct qeth_ipaddr *addr, int ipacmd)
434{
435 int rc;
436 struct qeth_cmd_buffer *iob;
437 struct qeth_ipa_cmd *cmd;
438
Carsten Otte847a50f2010-06-21 22:57:05 +0000439 QETH_CARD_TEXT(card, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100440
441 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100442 if (!iob)
443 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100444 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
445 memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
446 if (addr->proto == QETH_PROT_IPV6)
447 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
448 sizeof(struct in6_addr));
449 else
450 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
451
452 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
453
454 return rc;
455}
456
457static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
458{
459 int i, j;
460 for (i = 0; i < 16; i++) {
461 j = (len) - (i * 8);
462 if (j >= 8)
463 netmask[i] = 0xff;
464 else if (j > 0)
465 netmask[i] = (u8)(0xFF00 >> j);
466 else
467 netmask[i] = 0;
468 }
469}
470
471static int qeth_l3_send_setdelip(struct qeth_card *card,
472 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
473{
474 int rc;
475 struct qeth_cmd_buffer *iob;
476 struct qeth_ipa_cmd *cmd;
477 __u8 netmask[16];
478
Carsten Otte847a50f2010-06-21 22:57:05 +0000479 QETH_CARD_TEXT(card, 4, "setdelip");
480 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100481
482 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100483 if (!iob)
484 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100485 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
486 if (addr->proto == QETH_PROT_IPV6) {
487 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
488 sizeof(struct in6_addr));
489 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
490 memcpy(cmd->data.setdelip6.mask, netmask,
491 sizeof(struct in6_addr));
492 cmd->data.setdelip6.flags = flags;
493 } else {
494 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
495 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
496 cmd->data.setdelip4.flags = flags;
497 }
498
499 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
500
501 return rc;
502}
503
504static int qeth_l3_send_setrouting(struct qeth_card *card,
505 enum qeth_routing_types type, enum qeth_prot_versions prot)
506{
507 int rc;
508 struct qeth_ipa_cmd *cmd;
509 struct qeth_cmd_buffer *iob;
510
Carsten Otte847a50f2010-06-21 22:57:05 +0000511 QETH_CARD_TEXT(card, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100512 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100513 if (!iob)
514 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100515 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
516 cmd->data.setrtg.type = (type);
517 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
518
519 return rc;
520}
521
Stefan Raspl82e2e782013-03-18 20:04:43 +0000522static int qeth_l3_correct_routing_type(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100523 enum qeth_routing_types *type, enum qeth_prot_versions prot)
524{
525 if (card->info.type == QETH_CARD_TYPE_IQD) {
526 switch (*type) {
527 case NO_ROUTER:
528 case PRIMARY_CONNECTOR:
529 case SECONDARY_CONNECTOR:
530 case MULTICAST_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000531 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100532 default:
533 goto out_inval;
534 }
535 } else {
536 switch (*type) {
537 case NO_ROUTER:
538 case PRIMARY_ROUTER:
539 case SECONDARY_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000540 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100541 case MULTICAST_ROUTER:
542 if (qeth_is_ipafunc_supported(card, prot,
543 IPA_OSA_MC_ROUTER))
Stefan Raspl82e2e782013-03-18 20:04:43 +0000544 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100545 default:
546 goto out_inval;
547 }
548 }
549out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100550 *type = NO_ROUTER;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000551 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100552}
553
554int qeth_l3_setrouting_v4(struct qeth_card *card)
555{
556 int rc;
557
Carsten Otte847a50f2010-06-21 22:57:05 +0000558 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100559
Stefan Raspl82e2e782013-03-18 20:04:43 +0000560 rc = qeth_l3_correct_routing_type(card, &card->options.route4.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100561 QETH_PROT_IPV4);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000562 if (rc)
563 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100564
565 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
566 QETH_PROT_IPV4);
567 if (rc) {
568 card->options.route4.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200569 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
570 " on %s. Type set to 'no router'.\n", rc,
571 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100572 }
573 return rc;
574}
575
576int qeth_l3_setrouting_v6(struct qeth_card *card)
577{
578 int rc = 0;
579
Carsten Otte847a50f2010-06-21 22:57:05 +0000580 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100581#ifdef CONFIG_QETH_IPV6
582
583 if (!qeth_is_supported(card, IPA_IPV6))
584 return 0;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000585 rc = qeth_l3_correct_routing_type(card, &card->options.route6.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100586 QETH_PROT_IPV6);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000587 if (rc)
588 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100589
590 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
591 QETH_PROT_IPV6);
592 if (rc) {
593 card->options.route6.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200594 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
595 " on %s. Type set to 'no router'.\n", rc,
596 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100597 }
598#endif
599 return rc;
600}
601
602/*
603 * IP address takeover related functions
604 */
605static void qeth_l3_clear_ipato_list(struct qeth_card *card)
606{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100607 struct qeth_ipato_entry *ipatoe, *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100608
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200609 spin_lock_bh(&card->ip_lock);
610
Frank Blaschka4a71df52008-02-15 09:19:42 +0100611 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
612 list_del(&ipatoe->entry);
613 kfree(ipatoe);
614 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200615
616 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100617}
618
619int qeth_l3_add_ipato_entry(struct qeth_card *card,
620 struct qeth_ipato_entry *new)
621{
622 struct qeth_ipato_entry *ipatoe;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100623 int rc = 0;
624
Carsten Otte847a50f2010-06-21 22:57:05 +0000625 QETH_CARD_TEXT(card, 2, "addipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200626
627 spin_lock_bh(&card->ip_lock);
628
Frank Blaschka4a71df52008-02-15 09:19:42 +0100629 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
630 if (ipatoe->proto != new->proto)
631 continue;
632 if (!memcmp(ipatoe->addr, new->addr,
633 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
634 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100635 rc = -EEXIST;
636 break;
637 }
638 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200639
Frank Blaschka4a71df52008-02-15 09:19:42 +0100640 if (!rc)
641 list_add_tail(&new->entry, &card->ipato.entries);
642
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200643 spin_unlock_bh(&card->ip_lock);
644
Frank Blaschka4a71df52008-02-15 09:19:42 +0100645 return rc;
646}
647
648void qeth_l3_del_ipato_entry(struct qeth_card *card,
649 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
650{
651 struct qeth_ipato_entry *ipatoe, *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100652
Carsten Otte847a50f2010-06-21 22:57:05 +0000653 QETH_CARD_TEXT(card, 2, "delipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200654
655 spin_lock_bh(&card->ip_lock);
656
Frank Blaschka4a71df52008-02-15 09:19:42 +0100657 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
658 if (ipatoe->proto != proto)
659 continue;
660 if (!memcmp(ipatoe->addr, addr,
661 (proto == QETH_PROT_IPV4)? 4:16) &&
662 (ipatoe->mask_bits == mask_bits)) {
663 list_del(&ipatoe->entry);
664 kfree(ipatoe);
665 }
666 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200667
668 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100669}
670
671/*
672 * VIPA related functions
673 */
674int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
675 const u8 *addr)
676{
677 struct qeth_ipaddr *ipaddr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100678 int rc = 0;
679
680 ipaddr = qeth_l3_get_addr_buffer(proto);
681 if (ipaddr) {
682 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000683 QETH_CARD_TEXT(card, 2, "addvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100684 memcpy(&ipaddr->u.a4.addr, addr, 4);
685 ipaddr->u.a4.mask = 0;
686 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000687 QETH_CARD_TEXT(card, 2, "addvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100688 memcpy(&ipaddr->u.a6.addr, addr, 16);
689 ipaddr->u.a6.pfxlen = 0;
690 }
691 ipaddr->type = QETH_IP_TYPE_VIPA;
692 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
693 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
694 } else
695 return -ENOMEM;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200696
697 spin_lock_bh(&card->ip_lock);
698
Thomas Richter732a59c2016-09-15 14:39:27 +0200699 if (qeth_l3_ip_from_hash(card, ipaddr))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100700 rc = -EEXIST;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200701 else
702 qeth_l3_add_ip(card, ipaddr);
703
704 spin_unlock_bh(&card->ip_lock);
705
706 kfree(ipaddr);
707
Frank Blaschka4a71df52008-02-15 09:19:42 +0100708 return rc;
709}
710
711void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
712 const u8 *addr)
713{
714 struct qeth_ipaddr *ipaddr;
715
716 ipaddr = qeth_l3_get_addr_buffer(proto);
717 if (ipaddr) {
718 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000719 QETH_CARD_TEXT(card, 2, "delvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100720 memcpy(&ipaddr->u.a4.addr, addr, 4);
721 ipaddr->u.a4.mask = 0;
722 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000723 QETH_CARD_TEXT(card, 2, "delvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100724 memcpy(&ipaddr->u.a6.addr, addr, 16);
725 ipaddr->u.a6.pfxlen = 0;
726 }
727 ipaddr->type = QETH_IP_TYPE_VIPA;
728 } else
729 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200730
731 spin_lock_bh(&card->ip_lock);
732 qeth_l3_delete_ip(card, ipaddr);
733 spin_unlock_bh(&card->ip_lock);
734
735 kfree(ipaddr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100736}
737
738/*
739 * proxy ARP related functions
740 */
741int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
742 const u8 *addr)
743{
744 struct qeth_ipaddr *ipaddr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100745 int rc = 0;
746
747 ipaddr = qeth_l3_get_addr_buffer(proto);
748 if (ipaddr) {
749 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000750 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100751 memcpy(&ipaddr->u.a4.addr, addr, 4);
752 ipaddr->u.a4.mask = 0;
753 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000754 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100755 memcpy(&ipaddr->u.a6.addr, addr, 16);
756 ipaddr->u.a6.pfxlen = 0;
757 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200758
Frank Blaschka4a71df52008-02-15 09:19:42 +0100759 ipaddr->type = QETH_IP_TYPE_RXIP;
760 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
761 ipaddr->del_flags = 0;
762 } else
763 return -ENOMEM;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200764
765 spin_lock_bh(&card->ip_lock);
766
Thomas Richter732a59c2016-09-15 14:39:27 +0200767 if (qeth_l3_ip_from_hash(card, ipaddr))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100768 rc = -EEXIST;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200769 else
770 qeth_l3_add_ip(card, ipaddr);
771
772 spin_unlock_bh(&card->ip_lock);
773
774 kfree(ipaddr);
775
776 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100777}
778
779void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
780 const u8 *addr)
781{
782 struct qeth_ipaddr *ipaddr;
783
784 ipaddr = qeth_l3_get_addr_buffer(proto);
785 if (ipaddr) {
786 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000787 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100788 memcpy(&ipaddr->u.a4.addr, addr, 4);
789 ipaddr->u.a4.mask = 0;
790 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000791 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100792 memcpy(&ipaddr->u.a6.addr, addr, 16);
793 ipaddr->u.a6.pfxlen = 0;
794 }
795 ipaddr->type = QETH_IP_TYPE_RXIP;
796 } else
797 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200798
799 spin_lock_bh(&card->ip_lock);
800 qeth_l3_delete_ip(card, ipaddr);
801 spin_unlock_bh(&card->ip_lock);
802
803 kfree(ipaddr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100804}
805
806static int qeth_l3_register_addr_entry(struct qeth_card *card,
807 struct qeth_ipaddr *addr)
808{
809 char buf[50];
810 int rc = 0;
811 int cnt = 3;
812
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200813
Frank Blaschka4a71df52008-02-15 09:19:42 +0100814 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000815 QETH_CARD_TEXT(card, 2, "setaddr4");
816 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100817 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000818 QETH_CARD_TEXT(card, 2, "setaddr6");
819 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
820 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100821 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000822 QETH_CARD_TEXT(card, 2, "setaddr?");
823 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100824 }
825 do {
826 if (addr->is_multicast)
827 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
828 else
829 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
830 addr->set_flags);
831 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000832 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100833 } while ((--cnt > 0) && rc);
834 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000835 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100836 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100837 dev_warn(&card->gdev->dev,
838 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100839 }
840 return rc;
841}
842
843static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
844 struct qeth_ipaddr *addr)
845{
846 int rc = 0;
847
848 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000849 QETH_CARD_TEXT(card, 2, "deladdr4");
850 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100851 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000852 QETH_CARD_TEXT(card, 2, "deladdr6");
853 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
854 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100855 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000856 QETH_CARD_TEXT(card, 2, "deladdr?");
857 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100858 }
859 if (addr->is_multicast)
860 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
861 else
862 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
863 addr->del_flags);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200864 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000865 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100866
867 return rc;
868}
869
870static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
871{
872 if (cast_type == RTN_MULTICAST)
873 return QETH_CAST_MULTICAST;
874 if (cast_type == RTN_BROADCAST)
875 return QETH_CAST_BROADCAST;
876 return QETH_CAST_UNICAST;
877}
878
879static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
880{
881 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
882 if (cast_type == RTN_MULTICAST)
883 return ct | QETH_CAST_MULTICAST;
884 if (cast_type == RTN_ANYCAST)
885 return ct | QETH_CAST_ANYCAST;
886 if (cast_type == RTN_BROADCAST)
887 return ct | QETH_CAST_BROADCAST;
888 return ct | QETH_CAST_UNICAST;
889}
890
Frank Blaschka4a71df52008-02-15 09:19:42 +0100891static int qeth_l3_setadapter_parms(struct qeth_card *card)
892{
893 int rc;
894
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200895 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100896
897 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100898 dev_info(&card->gdev->dev,
899 "set adapter parameters not supported.\n");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200900 QETH_DBF_TEXT(SETUP, 2, " notsupp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100901 return 0;
902 }
903 rc = qeth_query_setadapterparms(card);
904 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100905 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
Kay Sievers7f6d95e2009-03-24 20:57:14 +0000906 "0x%x\n", dev_name(&card->gdev->dev), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100907 return rc;
908 }
909 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
910 rc = qeth_setadpparms_change_macaddr(card);
911 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100912 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -0800913 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100914 }
915
Frank Blaschka4a71df52008-02-15 09:19:42 +0100916 return rc;
917}
918
Frank Blaschka4a71df52008-02-15 09:19:42 +0100919#ifdef CONFIG_QETH_IPV6
920static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
921 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
922{
923 int rc;
924 struct qeth_cmd_buffer *iob;
925
Carsten Otte847a50f2010-06-21 22:57:05 +0000926 QETH_CARD_TEXT(card, 4, "simassp6");
Thomas Richterb475e312015-12-11 12:27:54 +0100927 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100928 0, QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100929 if (!iob)
930 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +0200931 rc = qeth_send_setassparms(card, iob, 0, 0,
Thomas Richter8f43fb02016-06-16 16:18:59 +0200932 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100933 return rc;
934}
935#endif
936
Frank Blaschka4a71df52008-02-15 09:19:42 +0100937static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
938{
939 int rc;
940
Carsten Otte847a50f2010-06-21 22:57:05 +0000941 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100942
943 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100944 dev_info(&card->gdev->dev,
945 "ARP processing not supported on %s!\n",
946 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100947 return 0;
948 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200949 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
950 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100951 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100952 dev_warn(&card->gdev->dev,
953 "Starting ARP processing support for %s failed\n",
954 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100955 }
956 return rc;
957}
958
959static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
960{
961 int rc;
962
Carsten Otte847a50f2010-06-21 22:57:05 +0000963 QETH_CARD_TEXT(card, 3, "ipaipfrg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100964
965 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100966 dev_info(&card->gdev->dev,
967 "Hardware IP fragmentation not supported on %s\n",
968 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100969 return -EOPNOTSUPP;
970 }
971
Thomas Richter4d7def22015-09-18 16:06:51 +0200972 rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100973 IPA_CMD_ASS_START, 0);
974 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100975 dev_warn(&card->gdev->dev,
976 "Starting IP fragmentation support for %s failed\n",
977 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100978 } else
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100979 dev_info(&card->gdev->dev,
980 "Hardware IP fragmentation enabled \n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100981 return rc;
982}
983
984static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
985{
986 int rc;
987
Carsten Otte847a50f2010-06-21 22:57:05 +0000988 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100989
Frank Blaschka4a71df52008-02-15 09:19:42 +0100990 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100991 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800992 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100993 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100994 return -EOPNOTSUPP;
995 }
996
Thomas Richter4d7def22015-09-18 16:06:51 +0200997 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100998 IPA_CMD_ASS_START, 0);
999 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001000 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001001 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001002 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001003 return rc;
1004}
1005
1006static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1007{
1008 int rc = 0;
1009
Carsten Otte847a50f2010-06-21 22:57:05 +00001010 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001011
1012 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001013 dev_info(&card->gdev->dev,
1014 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001015 return -EOPNOTSUPP;
1016 }
1017
Thomas Richter4d7def22015-09-18 16:06:51 +02001018 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001019 IPA_CMD_ASS_START, 0);
1020 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001021 dev_warn(&card->gdev->dev,
1022 "Starting VLAN support for %s failed\n",
1023 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001024 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001025 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001026 }
1027 return rc;
1028}
1029
1030static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1031{
1032 int rc;
1033
Carsten Otte847a50f2010-06-21 22:57:05 +00001034 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001035
1036 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001037 dev_info(&card->gdev->dev,
1038 "Multicast not supported on %s\n",
1039 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001040 return -EOPNOTSUPP;
1041 }
1042
Thomas Richter4d7def22015-09-18 16:06:51 +02001043 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001044 IPA_CMD_ASS_START, 0);
1045 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001046 dev_warn(&card->gdev->dev,
1047 "Starting multicast support for %s failed\n",
1048 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001049 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001050 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001051 card->dev->flags |= IFF_MULTICAST;
1052 }
1053 return rc;
1054}
1055
Frank Blaschka4a71df52008-02-15 09:19:42 +01001056#ifdef CONFIG_QETH_IPV6
1057static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1058{
1059 int rc;
1060
Carsten Otte847a50f2010-06-21 22:57:05 +00001061 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001062
1063 if (card->info.type == QETH_CARD_TYPE_IQD)
1064 goto out;
1065
Frank Blaschka1da74b12011-05-12 18:45:02 +00001066 rc = qeth_query_ipassists(card, QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001067 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001068 dev_err(&card->gdev->dev,
1069 "Activating IPv6 support for %s failed\n",
1070 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001071 return rc;
1072 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001073 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001074 IPA_CMD_ASS_START, 3);
1075 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001076 dev_err(&card->gdev->dev,
1077 "Activating IPv6 support for %s failed\n",
1078 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001079 return rc;
1080 }
1081 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1082 IPA_CMD_ASS_START);
1083 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001084 dev_err(&card->gdev->dev,
1085 "Activating IPv6 support for %s failed\n",
1086 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001087 return rc;
1088 }
1089 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1090 IPA_CMD_ASS_START);
1091 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001092 dev_warn(&card->gdev->dev,
1093 "Enabling the passthrough mode for %s failed\n",
1094 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001095 return rc;
1096 }
1097out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001098 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001099 return 0;
1100}
1101#endif
1102
1103static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1104{
1105 int rc = 0;
1106
Carsten Otte847a50f2010-06-21 22:57:05 +00001107 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001108
1109 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001110 dev_info(&card->gdev->dev,
1111 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001112 return 0;
1113 }
1114#ifdef CONFIG_QETH_IPV6
1115 rc = qeth_l3_softsetup_ipv6(card);
1116#endif
1117 return rc ;
1118}
1119
1120static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1121{
1122 int rc;
1123
Carsten Otte847a50f2010-06-21 22:57:05 +00001124 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001125 card->info.broadcast_capable = 0;
1126 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001127 dev_info(&card->gdev->dev,
1128 "Broadcast not supported on %s\n",
1129 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001130 rc = -EOPNOTSUPP;
1131 goto out;
1132 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001133 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001134 IPA_CMD_ASS_START, 0);
1135 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001136 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1137 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001138 goto out;
1139 }
1140
Thomas Richter4d7def22015-09-18 16:06:51 +02001141 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001142 IPA_CMD_ASS_CONFIGURE, 1);
1143 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001144 dev_warn(&card->gdev->dev,
1145 "Setting up broadcast filtering for %s failed\n",
1146 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001147 goto out;
1148 }
1149 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001150 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Thomas Richter4d7def22015-09-18 16:06:51 +02001151 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001152 IPA_CMD_ASS_ENABLE, 1);
1153 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001154 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1155 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001156 goto out;
1157 }
1158 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1159out:
1160 if (card->info.broadcast_capable)
1161 card->dev->flags |= IFF_BROADCAST;
1162 else
1163 card->dev->flags &= ~IFF_BROADCAST;
1164 return rc;
1165}
1166
Frank Blaschka4a71df52008-02-15 09:19:42 +01001167static int qeth_l3_start_ipassists(struct qeth_card *card)
1168{
Carsten Otte847a50f2010-06-21 22:57:05 +00001169 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +00001170
Stefan Raspl0f547612013-01-21 02:30:20 +00001171 if (qeth_set_access_ctrl_online(card, 0))
1172 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001173 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1174 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1175 qeth_l3_start_ipa_source_mac(card); /* go on*/
1176 qeth_l3_start_ipa_vlan(card); /* go on*/
1177 qeth_l3_start_ipa_multicast(card); /* go on*/
1178 qeth_l3_start_ipa_ipv6(card); /* go on*/
1179 qeth_l3_start_ipa_broadcast(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +01001180 return 0;
1181}
1182
Frank Blaschka4a71df52008-02-15 09:19:42 +01001183static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1184 struct qeth_reply *reply, unsigned long data)
1185{
1186 struct qeth_ipa_cmd *cmd;
1187
1188 cmd = (struct qeth_ipa_cmd *) data;
1189 if (cmd->hdr.return_code == 0)
1190 memcpy(card->dev->dev_addr,
1191 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1192 else
Joe Perches18336112012-07-12 22:33:10 -07001193 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001194
1195 return 0;
1196}
1197
1198static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1199{
1200 int rc = 0;
1201 struct qeth_cmd_buffer *iob;
1202 struct qeth_ipa_cmd *cmd;
1203
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001204 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001205
1206 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1207 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001208 if (!iob)
1209 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001210 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1211 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1212 card->info.unique_id;
1213
1214 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1215 NULL);
1216 return rc;
1217}
1218
1219static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1220 struct qeth_reply *reply, unsigned long data)
1221{
1222 struct qeth_ipa_cmd *cmd;
1223
1224 cmd = (struct qeth_ipa_cmd *) data;
1225 if (cmd->hdr.return_code == 0)
1226 card->info.unique_id = *((__u16 *)
1227 &cmd->data.create_destroy_addr.unique_id[6]);
1228 else {
1229 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1230 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001231 dev_warn(&card->gdev->dev, "The network adapter failed to "
1232 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001233 }
1234 return 0;
1235}
1236
1237static int qeth_l3_get_unique_id(struct qeth_card *card)
1238{
1239 int rc = 0;
1240 struct qeth_cmd_buffer *iob;
1241 struct qeth_ipa_cmd *cmd;
1242
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001243 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001244
1245 if (!qeth_is_supported(card, IPA_IPV6)) {
1246 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1247 UNIQUE_ID_NOT_BY_CARD;
1248 return 0;
1249 }
1250
1251 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1252 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001253 if (!iob)
1254 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001255 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1256 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1257 card->info.unique_id;
1258
1259 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1260 return rc;
1261}
1262
Ursula Braun76b11f82010-01-11 02:50:50 +00001263static int
1264qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1265 unsigned long data)
1266{
1267 struct qeth_ipa_cmd *cmd;
1268 __u16 rc;
1269
1270 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1271
1272 cmd = (struct qeth_ipa_cmd *)data;
1273 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001274 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001275 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001276 switch (cmd->data.diagass.action) {
1277 case QETH_DIAGS_CMD_TRACE_QUERY:
1278 break;
1279 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001280 switch (rc) {
1281 case 0:
1282 case IPA_RC_INVALID_SUBCMD:
1283 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1284 dev_info(&card->gdev->dev, "The HiperSockets network "
1285 "traffic analyzer is deactivated\n");
1286 break;
1287 default:
1288 break;
1289 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001290 break;
1291 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001292 switch (rc) {
1293 case 0:
1294 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1295 dev_info(&card->gdev->dev, "The HiperSockets network "
1296 "traffic analyzer is activated\n");
1297 break;
1298 case IPA_RC_HARDWARE_AUTH_ERROR:
1299 dev_warn(&card->gdev->dev, "The device is not "
1300 "authorized to run as a HiperSockets network "
1301 "traffic analyzer\n");
1302 break;
1303 case IPA_RC_TRACE_ALREADY_ACTIVE:
1304 dev_warn(&card->gdev->dev, "A HiperSockets "
1305 "network traffic analyzer is already "
1306 "active in the HiperSockets LAN\n");
1307 break;
1308 default:
1309 break;
1310 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001311 break;
1312 default:
1313 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1314 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1315 }
1316
1317 return 0;
1318}
1319
1320static int
1321qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1322{
1323 struct qeth_cmd_buffer *iob;
1324 struct qeth_ipa_cmd *cmd;
1325
1326 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1327
1328 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001329 if (!iob)
1330 return -ENOMEM;
Ursula Braun76b11f82010-01-11 02:50:50 +00001331 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1332 cmd->data.diagass.subcmd_len = 16;
1333 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1334 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1335 cmd->data.diagass.action = diags_cmd;
1336 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1337}
1338
Hans Wippel6bee4e22017-04-07 09:15:36 +02001339static void qeth_l3_get_mac_for_ipm(__be32 ipm, char *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001340{
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001341 ip_eth_mc_map(ipm, mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001342}
1343
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001344static void qeth_l3_mark_all_mc_to_be_deleted(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001345{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001346 struct qeth_ipaddr *addr;
1347 int i;
1348
1349 hash_for_each(card->ip_mc_htable, i, addr, hnode)
1350 addr->disp_flag = QETH_DISP_ADDR_DELETE;
1351
1352}
1353
1354static void qeth_l3_add_all_new_mc(struct qeth_card *card)
1355{
1356 struct qeth_ipaddr *addr;
1357 struct hlist_node *tmp;
1358 int i;
1359 int rc;
1360
1361 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1362 if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
1363 rc = qeth_l3_register_addr_entry(card, addr);
1364 if (!rc || (rc == IPA_RC_LAN_OFFLINE))
1365 addr->ref_counter = 1;
1366 else {
1367 hash_del(&addr->hnode);
1368 kfree(addr);
1369 }
1370 }
1371 }
1372
1373}
1374
1375static void qeth_l3_delete_nonused_mc(struct qeth_card *card)
1376{
1377 struct qeth_ipaddr *addr;
1378 struct hlist_node *tmp;
1379 int i;
1380 int rc;
1381
1382 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1383 if (addr->disp_flag == QETH_DISP_ADDR_DELETE) {
1384 rc = qeth_l3_deregister_addr_entry(card, addr);
1385 if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND)) {
1386 hash_del(&addr->hnode);
1387 kfree(addr);
1388 }
1389 }
1390 }
1391
1392}
1393
1394
1395static void
1396qeth_l3_add_mc_to_hash(struct qeth_card *card, struct in_device *in4_dev)
1397{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001398 struct ip_mc_list *im4;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001399 struct qeth_ipaddr *tmp, *ipm;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001400 char buf[MAX_ADDR_LEN];
1401
Carsten Otte847a50f2010-06-21 22:57:05 +00001402 QETH_CARD_TEXT(card, 4, "addmc");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001403
1404 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1405 if (!tmp)
1406 return;
1407
Sachin Santf3aa3132010-11-26 02:41:17 +00001408 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1409 im4 = rcu_dereference(im4->next_rcu)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001410 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf);
1411
Hans Wippel6bee4e22017-04-07 09:15:36 +02001412 tmp->u.a4.addr = be32_to_cpu(im4->multiaddr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001413 memcpy(tmp->mac, buf, sizeof(tmp->mac));
1414
1415 ipm = qeth_l3_ip_from_hash(card, tmp);
1416 if (ipm) {
1417 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1418 } else {
1419 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1420 if (!ipm)
1421 continue;
1422 memcpy(ipm->mac, buf, sizeof(tmp->mac));
Hans Wippel6bee4e22017-04-07 09:15:36 +02001423 ipm->u.a4.addr = be32_to_cpu(im4->multiaddr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001424 ipm->is_multicast = 1;
1425 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1426 hash_add(card->ip_mc_htable,
1427 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1428 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001429 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001430
1431 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001432}
1433
Jiri Pirko0347af52013-01-03 22:48:58 +00001434/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001435static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1436{
1437 struct in_device *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001438 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001439
Carsten Otte847a50f2010-06-21 22:57:05 +00001440 QETH_CARD_TEXT(card, 4, "addmcvl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001441
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001442 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001443 return;
1444
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001445 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1446 struct net_device *netdev;
1447
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001448 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001449 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001450 if (netdev == NULL ||
1451 !(netdev->flags & IFF_UP))
1452 continue;
Jiri Pirko0347af52013-01-03 22:48:58 +00001453 in_dev = __in_dev_get_rcu(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001454 if (!in_dev)
1455 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001456 qeth_l3_add_mc_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001457 }
1458}
1459
1460static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1461{
1462 struct in_device *in4_dev;
1463
Carsten Otte847a50f2010-06-21 22:57:05 +00001464 QETH_CARD_TEXT(card, 4, "chkmcv4");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001465
Sachin Santf3aa3132010-11-26 02:41:17 +00001466 rcu_read_lock();
Jiri Pirko0347af52013-01-03 22:48:58 +00001467 in4_dev = __in_dev_get_rcu(card->dev);
1468 if (in4_dev == NULL)
1469 goto unlock;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001470 qeth_l3_add_mc_to_hash(card, in4_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001471 qeth_l3_add_vlan_mc(card);
Jiri Pirko0347af52013-01-03 22:48:58 +00001472unlock:
Sachin Santf3aa3132010-11-26 02:41:17 +00001473 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001474}
1475
1476#ifdef CONFIG_QETH_IPV6
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001477static void
1478qeth_l3_add_mc6_to_hash(struct qeth_card *card, struct inet6_dev *in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001479{
1480 struct qeth_ipaddr *ipm;
1481 struct ifmcaddr6 *im6;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001482 struct qeth_ipaddr *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001483 char buf[MAX_ADDR_LEN];
1484
Carsten Otte847a50f2010-06-21 22:57:05 +00001485 QETH_CARD_TEXT(card, 4, "addmc6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001486
1487 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1488 if (!tmp)
1489 return;
1490
Frank Blaschka4a71df52008-02-15 09:19:42 +01001491 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1492 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001493
1494 memcpy(tmp->mac, buf, sizeof(tmp->mac));
1495 memcpy(&tmp->u.a6.addr, &im6->mca_addr.s6_addr,
1496 sizeof(struct in6_addr));
1497 tmp->is_multicast = 1;
1498
1499 ipm = qeth_l3_ip_from_hash(card, tmp);
1500 if (ipm) {
1501 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1502 continue;
1503 }
1504
Frank Blaschka4a71df52008-02-15 09:19:42 +01001505 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1506 if (!ipm)
1507 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001508
Frank Blaschka4a71df52008-02-15 09:19:42 +01001509 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1510 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1511 sizeof(struct in6_addr));
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001512 ipm->is_multicast = 1;
1513 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1514 hash_add(card->ip_mc_htable,
1515 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1516
Frank Blaschka4a71df52008-02-15 09:19:42 +01001517 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001518 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001519}
1520
Jiri Pirko0347af52013-01-03 22:48:58 +00001521/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001522static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1523{
1524 struct inet6_dev *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001525 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001526
Carsten Otte847a50f2010-06-21 22:57:05 +00001527 QETH_CARD_TEXT(card, 4, "admc6vl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001528
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001529 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001530 return;
1531
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001532 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1533 struct net_device *netdev;
1534
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001535 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001536 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001537 if (netdev == NULL ||
1538 !(netdev->flags & IFF_UP))
1539 continue;
1540 in_dev = in6_dev_get(netdev);
1541 if (!in_dev)
1542 continue;
1543 read_lock_bh(&in_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001544 qeth_l3_add_mc6_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001545 read_unlock_bh(&in_dev->lock);
1546 in6_dev_put(in_dev);
1547 }
1548}
1549
1550static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1551{
1552 struct inet6_dev *in6_dev;
1553
Carsten Otte847a50f2010-06-21 22:57:05 +00001554 QETH_CARD_TEXT(card, 4, "chkmcv6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001555
Frank Blaschka4a71df52008-02-15 09:19:42 +01001556 if (!qeth_is_supported(card, IPA_IPV6))
1557 return ;
1558 in6_dev = in6_dev_get(card->dev);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001559 if (!in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001560 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001561
Jiri Pirko0347af52013-01-03 22:48:58 +00001562 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001563 read_lock_bh(&in6_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001564 qeth_l3_add_mc6_to_hash(card, in6_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001565 qeth_l3_add_vlan_mc6(card);
1566 read_unlock_bh(&in6_dev->lock);
Jiri Pirko0347af52013-01-03 22:48:58 +00001567 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001568 in6_dev_put(in6_dev);
1569}
1570#endif /* CONFIG_QETH_IPV6 */
1571
1572static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1573 unsigned short vid)
1574{
1575 struct in_device *in_dev;
1576 struct in_ifaddr *ifa;
1577 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001578 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001579
Carsten Otte847a50f2010-06-21 22:57:05 +00001580 QETH_CARD_TEXT(card, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001581
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001582 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
frank.blaschka@de.ibm.comeabfbe62012-07-24 22:34:29 +00001583 if (!netdev)
1584 return;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001585 in_dev = in_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001586 if (!in_dev)
1587 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001588
1589 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1590 if (!addr)
1591 return;
1592
1593 spin_lock_bh(&card->ip_lock);
1594
Frank Blaschka4a71df52008-02-15 09:19:42 +01001595 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
Hans Wippel6bee4e22017-04-07 09:15:36 +02001596 addr->u.a4.addr = be32_to_cpu(ifa->ifa_address);
1597 addr->u.a4.mask = be32_to_cpu(ifa->ifa_mask);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001598 addr->type = QETH_IP_TYPE_NORMAL;
1599 qeth_l3_delete_ip(card, addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001600 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001601
1602 spin_unlock_bh(&card->ip_lock);
1603
1604 kfree(addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001605 in_dev_put(in_dev);
1606}
1607
1608static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1609 unsigned short vid)
1610{
1611#ifdef CONFIG_QETH_IPV6
1612 struct inet6_dev *in6_dev;
1613 struct inet6_ifaddr *ifa;
1614 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001615 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001616
Carsten Otte847a50f2010-06-21 22:57:05 +00001617 QETH_CARD_TEXT(card, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001618
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001619 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
frank.blaschka@de.ibm.comeabfbe62012-07-24 22:34:29 +00001620 if (!netdev)
1621 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001622
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001623 in6_dev = in6_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001624 if (!in6_dev)
1625 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001626
1627 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1628 if (!addr)
1629 return;
1630
1631 spin_lock_bh(&card->ip_lock);
1632
Frank Blaschka70f60a22010-03-22 09:59:48 -07001633 list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001634 memcpy(&addr->u.a6.addr, &ifa->addr,
1635 sizeof(struct in6_addr));
1636 addr->u.a6.pfxlen = ifa->prefix_len;
1637 addr->type = QETH_IP_TYPE_NORMAL;
1638 qeth_l3_delete_ip(card, addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001639 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001640
1641 spin_unlock_bh(&card->ip_lock);
1642
1643 kfree(addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001644 in6_dev_put(in6_dev);
1645#endif /* CONFIG_QETH_IPV6 */
1646}
1647
1648static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1649 unsigned short vid)
1650{
Jiri Pirko0347af52013-01-03 22:48:58 +00001651 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001652 qeth_l3_free_vlan_addresses4(card, vid);
1653 qeth_l3_free_vlan_addresses6(card, vid);
Jiri Pirko0347af52013-01-03 22:48:58 +00001654 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001655}
1656
Patrick McHardy80d5c362013-04-19 02:04:28 +00001657static int qeth_l3_vlan_rx_add_vid(struct net_device *dev,
1658 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001659{
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001660 struct qeth_card *card = dev->ml_priv;
1661
1662 set_bit(vid, card->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001663 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001664}
1665
Patrick McHardy80d5c362013-04-19 02:04:28 +00001666static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev,
1667 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001668{
Heiko Carstens509e2562008-07-26 02:24:10 -07001669 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001670
Carsten Otte847a50f2010-06-21 22:57:05 +00001671 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001672
Ursula Braun8e98ac42009-03-24 20:57:18 +00001673 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001674 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -05001675 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +00001676 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001677 /* unregister IP addresses of vlan device */
1678 qeth_l3_free_vlan_addresses(card, vid);
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001679 clear_bit(vid, card->active_vlans);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001680 qeth_l3_set_multicast_list(card->dev);
Jiri Pirko8e586132011-12-08 19:52:37 -05001681 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001682}
1683
Ursula Braun10651db2010-10-01 02:51:13 +00001684static inline int qeth_l3_rebuild_skb(struct qeth_card *card,
1685 struct sk_buff *skb, struct qeth_hdr *hdr,
1686 unsigned short *vlan_id)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001687{
Hans Wippel6bee4e22017-04-07 09:15:36 +02001688 __u16 prot;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001689 struct iphdr *ip_hdr;
1690 unsigned char tg_addr[MAX_ADDR_LEN];
Ursula Braun10651db2010-10-01 02:51:13 +00001691 int is_vlan = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001692
1693 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
Hans Wippel6bee4e22017-04-07 09:15:36 +02001694 prot = (hdr->hdr.l3.flags & QETH_HDR_IPV6) ? ETH_P_IPV6 :
1695 ETH_P_IP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001696 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1697 case QETH_CAST_MULTICAST:
1698 switch (prot) {
1699#ifdef CONFIG_QETH_IPV6
Hans Wippel6bee4e22017-04-07 09:15:36 +02001700 case ETH_P_IPV6:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001701 ndisc_mc_map((struct in6_addr *)
1702 skb->data + 24,
1703 tg_addr, card->dev, 0);
1704 break;
1705#endif
Hans Wippel6bee4e22017-04-07 09:15:36 +02001706 case ETH_P_IP:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001707 ip_hdr = (struct iphdr *)skb->data;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001708 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1709 break;
1710 default:
1711 memcpy(tg_addr, card->dev->broadcast,
1712 card->dev->addr_len);
1713 }
1714 card->stats.multicast++;
1715 skb->pkt_type = PACKET_MULTICAST;
1716 break;
1717 case QETH_CAST_BROADCAST:
1718 memcpy(tg_addr, card->dev->broadcast,
1719 card->dev->addr_len);
1720 card->stats.multicast++;
1721 skb->pkt_type = PACKET_BROADCAST;
1722 break;
1723 case QETH_CAST_UNICAST:
1724 case QETH_CAST_ANYCAST:
1725 case QETH_CAST_NOCAST:
1726 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00001727 if (card->options.sniffer)
1728 skb->pkt_type = PACKET_OTHERHOST;
1729 else
1730 skb->pkt_type = PACKET_HOST;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001731 memcpy(tg_addr, card->dev->dev_addr,
1732 card->dev->addr_len);
1733 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001734 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1735 card->dev->header_ops->create(skb, card->dev, prot,
1736 tg_addr, &hdr->hdr.l3.dest_addr[2],
1737 card->dev->addr_len);
1738 else
1739 card->dev->header_ops->create(skb, card->dev, prot,
1740 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001741 }
1742
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001743 skb->protocol = eth_type_trans(skb, card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001744
1745 if (hdr->hdr.l3.ext_flags &
1746 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
Ursula Braun10651db2010-10-01 02:51:13 +00001747 *vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
Frank Blaschka4a71df52008-02-15 09:19:42 +01001748 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
Ursula Braun10651db2010-10-01 02:51:13 +00001749 is_vlan = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001750 }
1751
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001752 if (card->dev->features & NETIF_F_RXCSUM) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001753 if ((hdr->hdr.l3.ext_flags &
Ursula Braunb9139802009-05-19 21:38:40 +00001754 (QETH_HDR_EXT_CSUM_HDR_REQ |
1755 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1756 (QETH_HDR_EXT_CSUM_HDR_REQ |
1757 QETH_HDR_EXT_CSUM_TRANSP_REQ))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001758 skb->ip_summed = CHECKSUM_UNNECESSARY;
1759 else
Ursula Braunb9139802009-05-19 21:38:40 +00001760 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001761 } else
1762 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun10651db2010-10-01 02:51:13 +00001763 return is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001764}
1765
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001766static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1767 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001768{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001769 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001770 struct sk_buff *skb;
1771 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001772 __u16 vlan_tag = 0;
Ursula Braun10651db2010-10-01 02:51:13 +00001773 int is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001774 unsigned int len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001775 __u16 magic;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001776
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001777 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +00001778 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001779 while (budget) {
1780 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +00001781 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001782 &card->rx.b_element, &card->rx.e_offset, &hdr);
1783 if (!skb) {
1784 *done = 1;
1785 break;
1786 }
1787 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001788 switch (hdr->hdr.l3.id) {
1789 case QETH_HEADER_TYPE_LAYER3:
Frank Blaschkab3332932011-08-08 01:33:59 +00001790 magic = *(__u16 *)skb->data;
1791 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
1792 (magic == ETH_P_AF_IUCV)) {
Hans Wippel6bee4e22017-04-07 09:15:36 +02001793 skb->protocol = cpu_to_be16(ETH_P_AF_IUCV);
Frank Blaschkab3332932011-08-08 01:33:59 +00001794 skb->pkt_type = PACKET_HOST;
1795 skb->mac_header = NET_SKB_PAD;
1796 skb->dev = card->dev;
1797 len = skb->len;
1798 card->dev->header_ops->create(skb, card->dev, 0,
1799 card->dev->dev_addr, "FAKELL",
1800 card->dev->addr_len);
1801 netif_receive_skb(skb);
1802 } else {
1803 is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
Ursula Braun10651db2010-10-01 02:51:13 +00001804 &vlan_tag);
Frank Blaschkab3332932011-08-08 01:33:59 +00001805 len = skb->len;
1806 if (is_vlan && !card->options.sniffer)
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001807 __vlan_hwaccel_put_tag(skb,
1808 htons(ETH_P_8021Q), vlan_tag);
Frank Blaschkab3332932011-08-08 01:33:59 +00001809 napi_gro_receive(&card->napi, skb);
1810 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001811 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00001812 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
1813 skb->pkt_type = PACKET_HOST;
1814 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00001815 len = skb->len;
1816 netif_receive_skb(skb);
1817 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001818 default:
1819 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00001820 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001821 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001822 continue;
1823 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001824 work_done++;
1825 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001826 card->stats.rx_packets++;
1827 card->stats.rx_bytes += len;
1828 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001829 return work_done;
1830}
1831
Frank Blaschka4a71df52008-02-15 09:19:42 +01001832static int qeth_l3_verify_vlan_dev(struct net_device *dev,
1833 struct qeth_card *card)
1834{
1835 int rc = 0;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001836 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001837
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001838 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1839 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001840
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001841 rcu_read_lock();
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001842 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001843 vid);
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001844 rcu_read_unlock();
1845 if (netdev == dev) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001846 rc = QETH_VLAN_CARD;
1847 break;
1848 }
1849 }
1850
Heiko Carstens509e2562008-07-26 02:24:10 -07001851 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001852 return 0;
1853
1854 return rc;
1855}
1856
1857static int qeth_l3_verify_dev(struct net_device *dev)
1858{
1859 struct qeth_card *card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001860 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001861 unsigned long flags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001862
1863 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
1864 list_for_each_entry(card, &qeth_core_card_list.list, list) {
1865 if (card->dev == dev) {
1866 rc = QETH_REAL_CARD;
1867 break;
1868 }
1869 rc = qeth_l3_verify_vlan_dev(dev, card);
1870 if (rc)
1871 break;
1872 }
1873 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
1874
1875 return rc;
1876}
1877
1878static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
1879{
1880 struct qeth_card *card = NULL;
1881 int rc;
1882
1883 rc = qeth_l3_verify_dev(dev);
1884 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07001885 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001886 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07001887 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02001888 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001889 card = NULL;
Carsten Otte847a50f2010-06-21 22:57:05 +00001890 if (card)
1891 QETH_CARD_TEXT_(card, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001892 return card ;
1893}
1894
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +02001895static void qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001896{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001897 QETH_DBF_TEXT(SETUP, 2, "stopcard");
1898 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001899
1900 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00001901 if (card->options.sniffer &&
1902 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
1903 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001904 if (card->read.state == CH_STATE_UP &&
1905 card->write.state == CH_STATE_UP &&
1906 (card->state == CARD_STATE_UP)) {
1907 if (recovery_mode)
1908 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02001909 else {
Ursula Braun869da902010-03-08 20:36:56 +00001910 rtnl_lock();
1911 dev_close(card->dev);
1912 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02001913 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001914 card->state = CARD_STATE_SOFTSETUP;
1915 }
1916 if (card->state == CARD_STATE_SOFTSETUP) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001917 qeth_l3_clear_ip_htable(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001918 qeth_clear_ipacmd_list(card);
1919 card->state = CARD_STATE_HARDSETUP;
1920 }
1921 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001922 qeth_qdio_clear_card(card, 0);
1923 qeth_clear_qdio_buffers(card);
1924 qeth_clear_working_pool_list(card);
1925 card->state = CARD_STATE_DOWN;
1926 }
1927 if (card->state == CARD_STATE_DOWN) {
1928 qeth_clear_cmd_buffers(&card->read);
1929 qeth_clear_cmd_buffers(&card->write);
1930 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001931}
1932
Ursula Braun76b11f82010-01-11 02:50:50 +00001933/*
1934 * test for and Switch promiscuous mode (on or off)
1935 * either for guestlan or HiperSocket Sniffer
1936 */
1937static void
1938qeth_l3_handle_promisc_mode(struct qeth_card *card)
1939{
1940 struct net_device *dev = card->dev;
1941
1942 if (((dev->flags & IFF_PROMISC) &&
1943 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
1944 (!(dev->flags & IFF_PROMISC) &&
1945 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
1946 return;
1947
1948 if (card->info.guestlan) { /* Guestlan trace */
1949 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
1950 qeth_setadp_promisc_mode(card);
1951 } else if (card->options.sniffer && /* HiperSockets trace */
1952 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
1953 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001954 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001955 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
1956 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00001957 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001958 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
1959 }
1960 }
1961}
1962
Frank Blaschka4a71df52008-02-15 09:19:42 +01001963static void qeth_l3_set_multicast_list(struct net_device *dev)
1964{
Heiko Carstens509e2562008-07-26 02:24:10 -07001965 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001966
Carsten Otte847a50f2010-06-21 22:57:05 +00001967 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00001968 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
1969 (card->state != CARD_STATE_UP))
1970 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00001971 if (!card->options.sniffer) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001972
1973 spin_lock_bh(&card->mclock);
1974
1975 qeth_l3_mark_all_mc_to_be_deleted(card);
1976
Ursula Braun76b11f82010-01-11 02:50:50 +00001977 qeth_l3_add_multicast_ipv4(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001978#ifdef CONFIG_QETH_IPV6
Ursula Braun76b11f82010-01-11 02:50:50 +00001979 qeth_l3_add_multicast_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001980#endif
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001981 qeth_l3_delete_nonused_mc(card);
1982 qeth_l3_add_all_new_mc(card);
1983
1984 spin_unlock_bh(&card->mclock);
1985
Ursula Braun76b11f82010-01-11 02:50:50 +00001986 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
1987 return;
1988 }
1989 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001990}
1991
1992static const char *qeth_l3_arp_get_error_cause(int *rc)
1993{
1994 switch (*rc) {
1995 case QETH_IPA_ARP_RC_FAILED:
1996 *rc = -EIO;
1997 return "operation failed";
1998 case QETH_IPA_ARP_RC_NOTSUPP:
1999 *rc = -EOPNOTSUPP;
2000 return "operation not supported";
2001 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2002 *rc = -EINVAL;
2003 return "argument out of range";
2004 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2005 *rc = -EOPNOTSUPP;
2006 return "query operation not supported";
2007 case QETH_IPA_ARP_RC_Q_NO_DATA:
2008 *rc = -ENOENT;
2009 return "no query data available";
2010 default:
2011 return "unknown error";
2012 }
2013}
2014
2015static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2016{
2017 int tmp;
2018 int rc;
2019
Carsten Otte847a50f2010-06-21 22:57:05 +00002020 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002021
2022 /*
2023 * currently GuestLAN only supports the ARP assist function
2024 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2025 * thus we say EOPNOTSUPP for this ARP function
2026 */
2027 if (card->info.guestlan)
2028 return -EOPNOTSUPP;
2029 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002030 return -EOPNOTSUPP;
2031 }
Thomas Richter4d7def22015-09-18 16:06:51 +02002032 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002033 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2034 no_entries);
2035 if (rc) {
2036 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002037 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2038 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002039 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2040 }
2041 return rc;
2042}
2043
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002044static __u32 get_arp_entry_size(struct qeth_card *card,
2045 struct qeth_arp_query_data *qdata,
2046 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002047{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002048 __u32 rc;
2049 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002050
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002051 is_hsi = qdata->reply_bits == 5;
2052 if (type->ip == QETHARP_IP_ADDR_V4) {
2053 QETH_CARD_TEXT(card, 4, "arpev4");
2054 if (strip_entries) {
2055 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
2056 sizeof(struct qeth_arp_qi_entry7_short);
2057 } else {
2058 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
2059 sizeof(struct qeth_arp_qi_entry7);
2060 }
2061 } else if (type->ip == QETHARP_IP_ADDR_V6) {
2062 QETH_CARD_TEXT(card, 4, "arpev6");
2063 if (strip_entries) {
2064 rc = is_hsi ?
2065 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
2066 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
2067 } else {
2068 rc = is_hsi ?
2069 sizeof(struct qeth_arp_qi_entry5_ipv6) :
2070 sizeof(struct qeth_arp_qi_entry7_ipv6);
2071 }
2072 } else {
2073 QETH_CARD_TEXT(card, 4, "arpinv");
2074 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002075 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002076
2077 return rc;
2078}
2079
2080static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
2081{
2082 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
2083 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002084}
2085
2086static int qeth_l3_arp_query_cb(struct qeth_card *card,
2087 struct qeth_reply *reply, unsigned long data)
2088{
2089 struct qeth_ipa_cmd *cmd;
2090 struct qeth_arp_query_data *qdata;
2091 struct qeth_arp_query_info *qinfo;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002092 int i;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002093 int e;
2094 int entrybytes_done;
2095 int stripped_bytes;
2096 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002097
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002098 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002099
2100 qinfo = (struct qeth_arp_query_info *) reply->param;
2101 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002102 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002103 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002104 QETH_CARD_TEXT(card, 4, "arpcberr");
2105 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002106 return 0;
2107 }
2108 if (cmd->data.setassparms.hdr.return_code) {
2109 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002110 QETH_CARD_TEXT(card, 4, "setaperr");
2111 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002112 return 0;
2113 }
2114 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00002115 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002116
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002117 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
2118 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
2119 entrybytes_done = 0;
2120 for (e = 0; e < qdata->no_entries; ++e) {
2121 char *cur_entry;
2122 __u32 esize;
2123 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002124
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002125 cur_entry = &qdata->data + entrybytes_done;
2126 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
2127 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
2128 QETH_CARD_TEXT(card, 4, "pmis");
2129 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
2130 break;
2131 }
2132 esize = get_arp_entry_size(card, qdata, etype,
2133 do_strip_entries);
2134 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
2135 if (!esize)
2136 break;
2137
2138 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
2139 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
Ursula Braune0a81142012-03-07 02:06:28 +00002140 cmd->hdr.return_code = IPA_RC_ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002141 goto out_error;
2142 }
2143
2144 memcpy(qinfo->udata + qinfo->udata_offset,
2145 &qdata->data + entrybytes_done + stripped_bytes,
2146 esize);
2147 entrybytes_done += esize + stripped_bytes;
2148 qinfo->udata_offset += esize;
2149 ++qinfo->no_entries;
2150 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002151 /* check if all replies received ... */
2152 if (cmd->data.setassparms.hdr.seq_no <
2153 cmd->data.setassparms.hdr.number_of_replies)
2154 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002155 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002156 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2157 /* keep STRIP_ENTRIES flag so the user program can distinguish
2158 * stripped entries from normal ones */
2159 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2160 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2161 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002162 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002163 return 0;
2164out_error:
2165 i = 0;
2166 memcpy(qinfo->udata, &i, 4);
2167 return 0;
2168}
2169
2170static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2171 struct qeth_cmd_buffer *iob, int len,
2172 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2173 unsigned long),
2174 void *reply_param)
2175{
Carsten Otte847a50f2010-06-21 22:57:05 +00002176 QETH_CARD_TEXT(card, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002177
2178 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2179 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2180 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2181 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2182 reply_cb, reply_param);
2183}
2184
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002185static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
2186 enum qeth_prot_versions prot,
2187 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002188{
2189 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002190 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002191 int tmp;
2192 int rc;
2193
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002194 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
2195
Thomas Richterb475e312015-12-11 12:27:54 +01002196 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2197 IPA_CMD_ASS_ARP_QUERY_INFO,
2198 sizeof(struct qeth_arp_query_data)
2199 - sizeof(char),
2200 prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002201 if (!iob)
2202 return -ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002203 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2204 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
2205 cmd->data.setassparms.data.query_arp.reply_bits = 0;
2206 cmd->data.setassparms.data.query_arp.no_entries = 0;
2207 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2208 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2209 qeth_l3_arp_query_cb, (void *)qinfo);
2210 if (rc) {
2211 tmp = rc;
2212 QETH_DBF_MESSAGE(2,
2213 "Error while querying ARP cache on %s: %s "
2214 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2215 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2216 }
2217
2218 return rc;
2219}
2220
2221static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2222{
2223 struct qeth_arp_query_info qinfo = {0, };
2224 int rc;
2225
Carsten Otte847a50f2010-06-21 22:57:05 +00002226 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002227
2228 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2229 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002230 QETH_CARD_TEXT(card, 3, "arpqnsup");
2231 rc = -EOPNOTSUPP;
2232 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002233 }
2234 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002235 if (copy_from_user(&qinfo, udata, 6)) {
2236 rc = -EFAULT;
2237 goto out;
2238 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002239 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002240 if (!qinfo.udata) {
2241 rc = -ENOMEM;
2242 goto out;
2243 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002244 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002245 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002246 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002247 if (copy_to_user(udata, qinfo.udata, 4))
2248 rc = -EFAULT;
Sebastian Ott77a83ed2016-06-16 16:19:03 +02002249 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002250 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02002251#ifdef CONFIG_QETH_IPV6
2252 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
2253 /* fails in case of GuestLAN QDIO mode */
2254 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6, &qinfo);
2255 }
2256#endif
2257 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
2258 QETH_CARD_TEXT(card, 4, "qactf");
2259 rc = -EFAULT;
2260 goto free_and_out;
2261 }
2262 QETH_CARD_TEXT(card, 4, "qacts");
2263
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002264free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002265 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002266out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002267 return rc;
2268}
2269
2270static int qeth_l3_arp_add_entry(struct qeth_card *card,
2271 struct qeth_arp_cache_entry *entry)
2272{
2273 struct qeth_cmd_buffer *iob;
2274 char buf[16];
2275 int tmp;
2276 int rc;
2277
Carsten Otte847a50f2010-06-21 22:57:05 +00002278 QETH_CARD_TEXT(card, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002279
2280 /*
2281 * currently GuestLAN only supports the ARP assist function
2282 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2283 * thus we say EOPNOTSUPP for this ARP function
2284 */
2285 if (card->info.guestlan)
2286 return -EOPNOTSUPP;
2287 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002288 return -EOPNOTSUPP;
2289 }
2290
Thomas Richterb475e312015-12-11 12:27:54 +01002291 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002292 IPA_CMD_ASS_ARP_ADD_ENTRY,
2293 sizeof(struct qeth_arp_cache_entry),
2294 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002295 if (!iob)
2296 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +02002297 rc = qeth_send_setassparms(card, iob,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002298 sizeof(struct qeth_arp_cache_entry),
2299 (unsigned long) entry,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002300 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002301 if (rc) {
2302 tmp = rc;
2303 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002304 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2305 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2306 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002307 }
2308 return rc;
2309}
2310
2311static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2312 struct qeth_arp_cache_entry *entry)
2313{
2314 struct qeth_cmd_buffer *iob;
2315 char buf[16] = {0, };
2316 int tmp;
2317 int rc;
2318
Carsten Otte847a50f2010-06-21 22:57:05 +00002319 QETH_CARD_TEXT(card, 3, "arprment");
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_REMOVE_ENTRY;
2324 * thus we say EOPNOTSUPP for this ARP function
2325 */
2326 if (card->info.guestlan)
2327 return -EOPNOTSUPP;
2328 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002329 return -EOPNOTSUPP;
2330 }
2331 memcpy(buf, entry, 12);
Thomas Richterb475e312015-12-11 12:27:54 +01002332 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002333 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2334 12,
2335 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002336 if (!iob)
2337 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +02002338 rc = qeth_send_setassparms(card, iob,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002339 12, (unsigned long)buf,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002340 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002341 if (rc) {
2342 tmp = rc;
2343 memset(buf, 0, 16);
2344 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002345 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2346 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2347 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002348 }
2349 return rc;
2350}
2351
2352static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2353{
2354 int rc;
2355 int tmp;
2356
Carsten Otte847a50f2010-06-21 22:57:05 +00002357 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002358
2359 /*
2360 * currently GuestLAN only supports the ARP assist function
2361 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2362 * thus we say EOPNOTSUPP for this ARP function
2363 */
2364 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2365 return -EOPNOTSUPP;
2366 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002367 return -EOPNOTSUPP;
2368 }
Thomas Richter4d7def22015-09-18 16:06:51 +02002369 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002370 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2371 if (rc) {
2372 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002373 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2374 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002375 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2376 }
2377 return rc;
2378}
2379
2380static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2381{
Heiko Carstens509e2562008-07-26 02:24:10 -07002382 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002383 struct qeth_arp_cache_entry arp_entry;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002384 int rc = 0;
2385
Frank Blaschka4a71df52008-02-15 09:19:42 +01002386 switch (cmd) {
2387 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2388 if (!capable(CAP_NET_ADMIN)) {
2389 rc = -EPERM;
2390 break;
2391 }
2392 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2393 break;
2394 case SIOC_QETH_ARP_QUERY_INFO:
2395 if (!capable(CAP_NET_ADMIN)) {
2396 rc = -EPERM;
2397 break;
2398 }
2399 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2400 break;
2401 case SIOC_QETH_ARP_ADD_ENTRY:
2402 if (!capable(CAP_NET_ADMIN)) {
2403 rc = -EPERM;
2404 break;
2405 }
2406 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2407 sizeof(struct qeth_arp_cache_entry)))
2408 rc = -EFAULT;
2409 else
2410 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2411 break;
2412 case SIOC_QETH_ARP_REMOVE_ENTRY:
2413 if (!capable(CAP_NET_ADMIN)) {
2414 rc = -EPERM;
2415 break;
2416 }
2417 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2418 sizeof(struct qeth_arp_cache_entry)))
2419 rc = -EFAULT;
2420 else
2421 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2422 break;
2423 case SIOC_QETH_ARP_FLUSH_CACHE:
2424 if (!capable(CAP_NET_ADMIN)) {
2425 rc = -EPERM;
2426 break;
2427 }
2428 rc = qeth_l3_arp_flush_cache(card);
2429 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002430 default:
2431 rc = -EOPNOTSUPP;
2432 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002433 return rc;
2434}
2435
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002436int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2437{
2438 int cast_type = RTN_UNSPEC;
David S. Miller69cce1d2011-07-17 23:09:49 -07002439 struct neighbour *n = NULL;
2440 struct dst_entry *dst;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002441
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002442 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002443 dst = skb_dst(skb);
2444 if (dst)
David S. Miller24db1ba2012-07-02 22:02:33 -07002445 n = dst_neigh_lookup_skb(dst, skb);
David S. Miller69cce1d2011-07-17 23:09:49 -07002446 if (n) {
2447 cast_type = n->type;
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002448 rcu_read_unlock();
David S. Miller24db1ba2012-07-02 22:02:33 -07002449 neigh_release(n);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002450 if ((cast_type == RTN_BROADCAST) ||
2451 (cast_type == RTN_MULTICAST) ||
2452 (cast_type == RTN_ANYCAST))
2453 return cast_type;
2454 else
2455 return RTN_UNSPEC;
2456 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002457 rcu_read_unlock();
2458
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002459 /* try something else */
Hans Wippel6bee4e22017-04-07 09:15:36 +02002460 if (be16_to_cpu(skb->protocol) == ETH_P_IPV6)
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002461 return (skb_network_header(skb)[24] == 0xff) ?
2462 RTN_MULTICAST : 0;
Hans Wippel6bee4e22017-04-07 09:15:36 +02002463 else if (be16_to_cpu(skb->protocol) == ETH_P_IP)
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002464 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2465 RTN_MULTICAST : 0;
2466 /* ... */
2467 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2468 return RTN_BROADCAST;
2469 else {
2470 u16 hdr_mac;
2471
2472 hdr_mac = *((u16 *)skb->data);
2473 /* tr multicast? */
2474 switch (card->info.link_type) {
2475 case QETH_LINK_TYPE_HSTR:
2476 case QETH_LINK_TYPE_LANE_TR:
2477 if ((hdr_mac == QETH_TR_MAC_NC) ||
2478 (hdr_mac == QETH_TR_MAC_C))
2479 return RTN_MULTICAST;
2480 break;
2481 /* eth or so multicast? */
2482 default:
2483 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2484 (hdr_mac == QETH_ETH_MAC_V6))
2485 return RTN_MULTICAST;
2486 }
2487 }
2488 return cast_type;
2489}
2490
Frank Blaschkab3332932011-08-08 01:33:59 +00002491static void qeth_l3_fill_af_iucv_hdr(struct qeth_card *card,
2492 struct qeth_hdr *hdr, struct sk_buff *skb)
2493{
2494 char daddr[16];
2495 struct af_iucv_trans_hdr *iucv_hdr;
2496
Frank Blaschkab3332932011-08-08 01:33:59 +00002497 memset(hdr, 0, sizeof(struct qeth_hdr));
2498 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2499 hdr->hdr.l3.ext_flags = 0;
Julian Wiedmannacd97762017-03-23 14:55:09 +01002500 hdr->hdr.l3.length = skb->len - ETH_HLEN;
Frank Blaschkab3332932011-08-08 01:33:59 +00002501 hdr->hdr.l3.flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
Julian Wiedmannacd97762017-03-23 14:55:09 +01002502
2503 iucv_hdr = (struct af_iucv_trans_hdr *) (skb->data + ETH_HLEN);
Frank Blaschkab3332932011-08-08 01:33:59 +00002504 memset(daddr, 0, sizeof(daddr));
2505 daddr[0] = 0xfe;
2506 daddr[1] = 0x80;
2507 memcpy(&daddr[8], iucv_hdr->destUserID, 8);
2508 memcpy(hdr->hdr.l3.dest_addr, daddr, 16);
2509}
2510
Frank Blaschka4a71df52008-02-15 09:19:42 +01002511static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2512 struct sk_buff *skb, int ipv, int cast_type)
2513{
David S. Miller69cce1d2011-07-17 23:09:49 -07002514 struct dst_entry *dst;
2515
Frank Blaschka4a71df52008-02-15 09:19:42 +01002516 memset(hdr, 0, sizeof(struct qeth_hdr));
2517 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2518 hdr->hdr.l3.ext_flags = 0;
2519
2520 /*
2521 * before we're going to overwrite this location with next hop ip.
2522 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2523 */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002524 if (skb_vlan_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002525 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2526 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2527 else
2528 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002529 hdr->hdr.l3.vlan_id = skb_vlan_tag_get(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002530 }
2531
2532 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002533
2534 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002535 dst = skb_dst(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002536 if (ipv == 4) {
David Miller87e75972012-02-01 10:49:17 +00002537 struct rtable *rt = (struct rtable *) dst;
2538 __be32 *pkey = &ip_hdr(skb)->daddr;
2539
2540 if (rt->rt_gateway)
2541 pkey = &rt->rt_gateway;
2542
Frank Blaschka4a71df52008-02-15 09:19:42 +01002543 /* IPv4 */
2544 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2545 memset(hdr->hdr.l3.dest_addr, 0, 12);
David Miller87e75972012-02-01 10:49:17 +00002546 *((__be32 *) (&hdr->hdr.l3.dest_addr[12])) = *pkey;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002547 } else if (ipv == 6) {
David Miller87e75972012-02-01 10:49:17 +00002548 struct rt6_info *rt = (struct rt6_info *) dst;
2549 struct in6_addr *pkey = &ipv6_hdr(skb)->daddr;
2550
2551 if (!ipv6_addr_any(&rt->rt6i_gateway))
2552 pkey = &rt->rt6i_gateway;
2553
Frank Blaschka4a71df52008-02-15 09:19:42 +01002554 /* IPv6 */
2555 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2556 if (card->info.type == QETH_CARD_TYPE_IQD)
2557 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
David Miller87e75972012-02-01 10:49:17 +00002558 memcpy(hdr->hdr.l3.dest_addr, pkey, 16);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002559 } else {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002560 if (!memcmp(skb->data + sizeof(struct qeth_hdr),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002561 skb->dev->broadcast, 6)) {
2562 /* broadcast? */
2563 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2564 QETH_HDR_PASSTHRU;
2565 } else {
2566 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2567 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2568 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2569 }
2570 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002571 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002572}
2573
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002574static inline void qeth_l3_hdr_csum(struct qeth_card *card,
2575 struct qeth_hdr *hdr, struct sk_buff *skb)
2576{
2577 struct iphdr *iph = ip_hdr(skb);
2578
2579 /* tcph->check contains already the pseudo hdr checksum
2580 * so just set the header flags
2581 */
2582 if (iph->protocol == IPPROTO_UDP)
2583 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
Frank Blaschka16c0f932011-01-12 20:42:25 +00002584 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
2585 QETH_HDR_EXT_CSUM_HDR_REQ;
2586 iph->check = 0;
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002587 if (card->options.performance_stats)
2588 card->perf_stats.tx_csum++;
2589}
2590
Frank Blaschka64ef8952009-03-24 20:57:16 +00002591static void qeth_tso_fill_header(struct qeth_card *card,
2592 struct qeth_hdr *qhdr, struct sk_buff *skb)
2593{
2594 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2595 struct tcphdr *tcph = tcp_hdr(skb);
2596 struct iphdr *iph = ip_hdr(skb);
2597 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2598
2599 /*fix header to TSO values ...*/
2600 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
Frank Blaschka8fa92082010-11-26 02:41:20 +00002601 hdr->hdr.hdr.l3.length = skb->len - sizeof(struct qeth_hdr_tso);
Frank Blaschka64ef8952009-03-24 20:57:16 +00002602 /*set values which are fix for the first approach ...*/
2603 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2604 hdr->ext.imb_hdr_no = 1;
2605 hdr->ext.hdr_type = 1;
2606 hdr->ext.hdr_version = 1;
2607 hdr->ext.hdr_len = 28;
2608 /*insert non-fix values */
2609 hdr->ext.mss = skb_shinfo(skb)->gso_size;
2610 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
2611 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2612 sizeof(struct qeth_hdr_tso));
2613 tcph->check = 0;
Hans Wippel6bee4e22017-04-07 09:15:36 +02002614 if (be16_to_cpu(skb->protocol) == ETH_P_IPV6) {
Frank Blaschka64ef8952009-03-24 20:57:16 +00002615 ip6h->payload_len = 0;
2616 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2617 0, IPPROTO_TCP, 0);
2618 } else {
2619 /*OSA want us to set these values ...*/
2620 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2621 0, IPPROTO_TCP, 0);
2622 iph->tot_len = 0;
2623 iph->check = 0;
2624 }
2625}
2626
Eugene Crosser2863c612016-06-16 16:18:52 +02002627/**
Eugene Crosser41aeed52016-06-16 16:18:53 +02002628 * qeth_l3_get_elements_no_tso() - find number of SBALEs for skb data for tso
2629 * @card: qeth card structure, to check max. elems.
2630 * @skb: SKB address
2631 * @extra_elems: extra elems needed, to check against max.
Eugene Crosser2863c612016-06-16 16:18:52 +02002632 *
2633 * Returns the number of pages, and thus QDIO buffer elements, needed to cover
2634 * skb data, including linear part and fragments, but excluding TCP header.
2635 * (Exclusion of TCP header distinguishes it from qeth_get_elements_no().)
2636 * Checks if the result plus extra_elems fits under the limit for the card.
2637 * Returns 0 if it does not.
2638 * Note: extra_elems is not included in the returned result.
2639 */
Eugene Crosser41aeed52016-06-16 16:18:53 +02002640static int qeth_l3_get_elements_no_tso(struct qeth_card *card,
Eugene Crosser2863c612016-06-16 16:18:52 +02002641 struct sk_buff *skb, int extra_elems)
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002642{
Eugene Crosser2863c612016-06-16 16:18:52 +02002643 addr_t tcpdptr = (addr_t)tcp_hdr(skb) + tcp_hdrlen(skb);
2644 int elements = qeth_get_elements_for_range(
2645 tcpdptr,
2646 (addr_t)skb->data + skb_headlen(skb)) +
Thomas Richter8f43fb02016-06-16 16:18:59 +02002647 qeth_get_elements_for_frags(skb);
Frank Blaschka271648b2013-03-18 20:04:44 +00002648
Eugene Crosser2863c612016-06-16 16:18:52 +02002649 if ((elements + extra_elems) > QETH_MAX_BUFFER_ELEMENTS(card)) {
2650 QETH_DBF_MESSAGE(2,
2651 "Invalid size of TSO IP packet (Number=%d / Length=%d). Discarded.\n",
2652 elements + extra_elems, skb->len);
2653 return 0;
2654 }
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002655 return elements;
2656}
2657
Julian Wiedmanne38db6b2017-04-11 16:11:14 +02002658static netdev_tx_t qeth_l3_hard_start_xmit(struct sk_buff *skb,
2659 struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002660{
2661 int rc;
Hans Wippel6bee4e22017-04-07 09:15:36 +02002662 __be16 *tag;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002663 struct qeth_hdr *hdr = NULL;
Eugene Crosser2863c612016-06-16 16:18:52 +02002664 int hdr_elements = 0;
2665 int elements;
Heiko Carstens509e2562008-07-26 02:24:10 -07002666 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002667 struct sk_buff *new_skb = NULL;
2668 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002669 int cast_type = qeth_l3_get_cast_type(card, skb);
Stefan Raspl290b8342014-04-28 10:05:08 +02002670 struct qeth_qdio_out_q *queue =
2671 card->qdio.out_qs[card->qdio.do_prio_queueing
2672 || (cast_type && card->info.is_multicast_different) ?
2673 qeth_get_priority_queue(card, skb, ipv, cast_type) :
2674 card->qdio.default_out_queue];
Frank Blaschka4a71df52008-02-15 09:19:42 +01002675 int tx_bytes = skb->len;
Eugene Crosser41aeed52016-06-16 16:18:53 +02002676 bool use_tso;
Frank Blaschka683d7182008-08-01 16:39:13 +02002677 int data_offset = -1;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002678 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002679
Frank Blaschkab3332932011-08-08 01:33:59 +00002680 if (((card->info.type == QETH_CARD_TYPE_IQD) &&
2681 (((card->options.cq != QETH_CQ_ENABLED) && !ipv) ||
2682 ((card->options.cq == QETH_CQ_ENABLED) &&
Hans Wippel6bee4e22017-04-07 09:15:36 +02002683 (be16_to_cpu(skb->protocol) != ETH_P_AF_IUCV)))) ||
Frank Blaschkab3332932011-08-08 01:33:59 +00002684 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002685 goto tx_drop;
2686
2687 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2688 card->stats.tx_carrier_errors++;
2689 goto tx_drop;
2690 }
2691
2692 if ((cast_type == RTN_BROADCAST) &&
2693 (card->info.broadcast_capable == 0))
2694 goto tx_drop;
2695
2696 if (card->options.performance_stats) {
2697 card->perf_stats.outbound_cnt++;
2698 card->perf_stats.outbound_start_time = qeth_get_micros();
2699 }
2700
Eugene Crosser41aeed52016-06-16 16:18:53 +02002701 /* Ignore segment size from skb_is_gso(), 1 page is always used. */
2702 use_tso = skb_is_gso(skb) &&
2703 (qeth_get_ip_protocol(skb) == IPPROTO_TCP) && (ipv == 4);
Frank Blaschka683d7182008-08-01 16:39:13 +02002704
Eugene Crosser41aeed52016-06-16 16:18:53 +02002705 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
2706 !skb_is_nonlinear(skb)) {
Frank Blaschka683d7182008-08-01 16:39:13 +02002707 new_skb = skb;
Julian Wiedmannacd97762017-03-23 14:55:09 +01002708 data_offset = ETH_HLEN;
Frank Blaschka683d7182008-08-01 16:39:13 +02002709 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2710 if (!hdr)
2711 goto tx_drop;
Eugene Crosser2863c612016-06-16 16:18:52 +02002712 hdr_elements++;
Frank Blaschka683d7182008-08-01 16:39:13 +02002713 } else {
2714 /* create a clone with writeable headroom */
2715 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
2716 + VLAN_HLEN);
2717 if (!new_skb)
2718 goto tx_drop;
2719 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002720
2721 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02002722 if (data_offset < 0)
2723 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002724 } else {
Frank Blaschka21fde742010-03-08 20:36:54 +00002725 if (ipv == 4) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002726 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002727 }
2728
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002729 if (ipv != 4 && skb_vlan_tag_present(new_skb)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002730 skb_push(new_skb, VLAN_HLEN);
2731 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2732 skb_copy_to_linear_data_offset(new_skb, 4,
2733 new_skb->data + 8, 4);
2734 skb_copy_to_linear_data_offset(new_skb, 8,
2735 new_skb->data + 12, 4);
Hans Wippel6bee4e22017-04-07 09:15:36 +02002736 tag = (__be16 *)(new_skb->data + 12);
2737 *tag = cpu_to_be16(ETH_P_8021Q);
2738 *(tag + 1) = cpu_to_be16(skb_vlan_tag_get(new_skb));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002739 }
2740 }
2741
2742 netif_stop_queue(dev);
2743
Frank Blaschka4a71df52008-02-15 09:19:42 +01002744 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00002745 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01002746 */
Eugene Crosser41aeed52016-06-16 16:18:53 +02002747 if ((card->info.type != QETH_CARD_TYPE_IQD) &&
2748 ((use_tso && !qeth_l3_get_elements_no_tso(card, new_skb, 1)) ||
Julian Wiedmann7d969d22017-03-23 14:55:08 +01002749 (!use_tso && !qeth_get_elements_no(card, new_skb, 0, 0)))) {
Eugene Crosser6059c902016-06-16 16:18:57 +02002750 int lin_rc = skb_linearize(new_skb);
2751
2752 if (card->options.performance_stats) {
2753 if (lin_rc)
2754 card->perf_stats.tx_linfail++;
2755 else
2756 card->perf_stats.tx_lin++;
2757 }
2758 if (lin_rc)
Eugene Crosser41aeed52016-06-16 16:18:53 +02002759 goto tx_drop;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002760 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002761
Eugene Crosser41aeed52016-06-16 16:18:53 +02002762 if (use_tso) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002763 hdr = (struct qeth_hdr *)skb_push(new_skb,
2764 sizeof(struct qeth_hdr_tso));
2765 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
2766 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
2767 qeth_tso_fill_header(card, hdr, new_skb);
Eugene Crosser2863c612016-06-16 16:18:52 +02002768 hdr_elements++;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002769 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02002770 if (data_offset < 0) {
2771 hdr = (struct qeth_hdr *)skb_push(new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002772 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02002773 qeth_l3_fill_header(card, hdr, new_skb, ipv,
2774 cast_type);
2775 } else {
Hans Wippel6bee4e22017-04-07 09:15:36 +02002776 if (be16_to_cpu(new_skb->protocol) == ETH_P_AF_IUCV)
Frank Blaschkab3332932011-08-08 01:33:59 +00002777 qeth_l3_fill_af_iucv_hdr(card, hdr, new_skb);
2778 else {
2779 qeth_l3_fill_header(card, hdr, new_skb, ipv,
2780 cast_type);
2781 hdr->hdr.l3.length = new_skb->len - data_offset;
2782 }
Frank Blaschka683d7182008-08-01 16:39:13 +02002783 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002784
2785 if (skb->ip_summed == CHECKSUM_PARTIAL)
2786 qeth_l3_hdr_csum(card, hdr, new_skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002787 }
2788
Eugene Crosser41aeed52016-06-16 16:18:53 +02002789 elements = use_tso ?
2790 qeth_l3_get_elements_no_tso(card, new_skb, hdr_elements) :
Julian Wiedmann7d969d22017-03-23 14:55:08 +01002791 qeth_get_elements_no(card, new_skb, hdr_elements,
2792 (data_offset > 0) ? data_offset : 0);
Eugene Crosser2863c612016-06-16 16:18:52 +02002793 if (!elements) {
Frank Blaschka64ef8952009-03-24 20:57:16 +00002794 if (data_offset >= 0)
2795 kmem_cache_free(qeth_core_header_cache, hdr);
2796 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002797 }
Eugene Crosser2863c612016-06-16 16:18:52 +02002798 elements += hdr_elements;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002799
Frank Blaschka51aa1652010-06-21 22:57:10 +00002800 if (card->info.type != QETH_CARD_TYPE_IQD) {
2801 int len;
Eugene Crosser41aeed52016-06-16 16:18:53 +02002802 if (use_tso)
Frank Blaschka51aa1652010-06-21 22:57:10 +00002803 len = ((unsigned long)tcp_hdr(new_skb) +
Eugene Crosser2863c612016-06-16 16:18:52 +02002804 tcp_hdrlen(new_skb)) -
Frank Blaschka51aa1652010-06-21 22:57:10 +00002805 (unsigned long)new_skb->data;
2806 else
2807 len = sizeof(struct qeth_hdr_layer3);
2808
Stefan Raspld4ae1f52013-04-22 01:12:29 +00002809 if (qeth_hdr_chk_and_bounce(new_skb, &hdr, len))
Frank Blaschka51aa1652010-06-21 22:57:10 +00002810 goto tx_drop;
Eugene Crosser2863c612016-06-16 16:18:52 +02002811 rc = qeth_do_send_packet(card, queue, new_skb, hdr, elements);
Frank Blaschka51aa1652010-06-21 22:57:10 +00002812 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +01002813 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Julian Wiedmann4e8d7e62017-04-11 16:11:13 +02002814 data_offset, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002815
2816 if (!rc) {
2817 card->stats.tx_packets++;
2818 card->stats.tx_bytes += tx_bytes;
2819 if (new_skb != skb)
2820 dev_kfree_skb_any(skb);
2821 if (card->options.performance_stats) {
Eugene Crosser2863c612016-06-16 16:18:52 +02002822 nr_frags = skb_shinfo(new_skb)->nr_frags;
Eugene Crosser41aeed52016-06-16 16:18:53 +02002823 if (use_tso) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002824 card->perf_stats.large_send_bytes += tx_bytes;
2825 card->perf_stats.large_send_cnt++;
2826 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00002827 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002828 card->perf_stats.sg_skbs_sent++;
2829 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00002830 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002831 }
2832 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07002833 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002834 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02002835 if (data_offset >= 0)
2836 kmem_cache_free(qeth_core_header_cache, hdr);
2837
Frank Blaschka4a71df52008-02-15 09:19:42 +01002838 if (rc == -EBUSY) {
2839 if (new_skb != skb)
2840 dev_kfree_skb_any(new_skb);
2841 return NETDEV_TX_BUSY;
2842 } else
2843 goto tx_drop;
2844 }
2845
2846 netif_wake_queue(dev);
2847 if (card->options.performance_stats)
2848 card->perf_stats.outbound_time += qeth_get_micros() -
2849 card->perf_stats.outbound_start_time;
2850 return rc;
2851
2852tx_drop:
2853 card->stats.tx_dropped++;
2854 card->stats.tx_errors++;
2855 if ((new_skb != skb) && new_skb)
2856 dev_kfree_skb_any(new_skb);
2857 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02002858 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002859 return NETDEV_TX_OK;
2860}
2861
Ursula Braun39423442011-01-12 20:42:24 +00002862static int __qeth_l3_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002863{
Heiko Carstens509e2562008-07-26 02:24:10 -07002864 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002865 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002866
Carsten Otte847a50f2010-06-21 22:57:05 +00002867 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +00002868 if (card->state == CARD_STATE_UP)
2869 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002870 if (card->state != CARD_STATE_SOFTSETUP)
2871 return -ENODEV;
2872 card->data.state = CH_STATE_UP;
2873 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002874 netif_start_queue(dev);
2875
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002876 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
2877 napi_enable(&card->napi);
2878 napi_schedule(&card->napi);
2879 } else
2880 rc = -EIO;
2881 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002882}
2883
Ursula Braun39423442011-01-12 20:42:24 +00002884static int qeth_l3_open(struct net_device *dev)
2885{
2886 struct qeth_card *card = dev->ml_priv;
2887
2888 QETH_CARD_TEXT(card, 5, "qethope_");
2889 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
2890 QETH_CARD_TEXT(card, 3, "openREC");
2891 return -ERESTARTSYS;
2892 }
2893 return __qeth_l3_open(dev);
2894}
2895
Frank Blaschka4a71df52008-02-15 09:19:42 +01002896static int qeth_l3_stop(struct net_device *dev)
2897{
Heiko Carstens509e2562008-07-26 02:24:10 -07002898 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002899
Carsten Otte847a50f2010-06-21 22:57:05 +00002900 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002901 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002902 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002903 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002904 napi_disable(&card->napi);
2905 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002906 return 0;
2907}
2908
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07002909static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002910 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002911 .get_strings = qeth_core_get_strings,
2912 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00002913 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002914 .get_drvinfo = qeth_core_get_drvinfo,
Julian Wiedmann993e19c2017-04-11 16:11:17 +02002915 .get_link_ksettings = qeth_core_ethtool_get_link_ksettings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002916};
2917
2918/*
2919 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
2920 * NOARP on the netdevice is no option because it also turns off neighbor
2921 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
2922 * arp resolution but we want the hard header (packet socket will work
2923 * e.g. tcpdump)
2924 */
2925static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
2926{
2927 n->nud_state = NUD_NOARP;
2928 memcpy(n->ha, "FAKELL", 6);
2929 n->output = n->ops->connected_output;
2930 return 0;
2931}
2932
2933static int
2934qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
2935{
2936 if (np->tbl->family == AF_INET)
2937 np->neigh_setup = qeth_l3_neigh_setup_noarp;
2938
2939 return 0;
2940}
2941
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002942static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08002943 .ndo_open = qeth_l3_open,
2944 .ndo_stop = qeth_l3_stop,
2945 .ndo_get_stats = qeth_get_stats,
2946 .ndo_start_xmit = qeth_l3_hard_start_xmit,
2947 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002948 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002949 .ndo_do_ioctl = qeth_do_ioctl,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002950 .ndo_change_mtu = qeth_change_mtu,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002951 .ndo_fix_features = qeth_fix_features,
2952 .ndo_set_features = qeth_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08002953 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2954 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002955 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka8403b132009-01-08 10:50:55 -08002956};
2957
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002958static const struct net_device_ops qeth_l3_osa_netdev_ops = {
2959 .ndo_open = qeth_l3_open,
2960 .ndo_stop = qeth_l3_stop,
2961 .ndo_get_stats = qeth_get_stats,
2962 .ndo_start_xmit = qeth_l3_hard_start_xmit,
2963 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002964 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002965 .ndo_do_ioctl = qeth_do_ioctl,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002966 .ndo_change_mtu = qeth_change_mtu,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002967 .ndo_fix_features = qeth_fix_features,
2968 .ndo_set_features = qeth_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002969 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2970 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002971 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002972 .ndo_neigh_setup = qeth_l3_neigh_setup,
2973};
2974
Frank Blaschka4a71df52008-02-15 09:19:42 +01002975static int qeth_l3_setup_netdev(struct qeth_card *card)
2976{
Thomas Richter1aec42b2015-01-21 13:39:10 +01002977 int rc;
2978
Ursula Braun5113fec2010-05-16 21:15:14 +00002979 if (card->info.type == QETH_CARD_TYPE_OSD ||
2980 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002981 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
2982 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002983 pr_info("qeth_l3: ignoring TR device\n");
2984 return -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002985 } else {
2986 card->dev = alloc_etherdev(0);
2987 if (!card->dev)
2988 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002989 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002990
2991 /*IPv6 address autoconfiguration stuff*/
2992 qeth_l3_get_unique_id(card);
2993 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
2994 card->dev->dev_id = card->info.unique_id &
2995 0xffff;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00002996 if (!card->info.guestlan) {
2997 card->dev->hw_features = NETIF_F_SG |
2998 NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
2999 NETIF_F_TSO;
Hans Wippel9bdc4412016-06-16 16:19:00 +02003000 card->dev->vlan_features = NETIF_F_SG |
3001 NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
3002 NETIF_F_TSO;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00003003 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003004 }
3005 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
Tom Gundersenc835a672014-07-14 16:37:24 +02003006 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
3007 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003008 if (!card->dev)
3009 return -ENODEV;
3010 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003011 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Thomas Richter1aec42b2015-01-21 13:39:10 +01003012 rc = qeth_l3_iqd_read_initial_mac(card);
3013 if (rc)
3014 return rc;
Frank Blaschkab3332932011-08-08 01:33:59 +00003015 if (card->options.hsuid[0])
3016 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003017 } else
3018 return -ENODEV;
3019
Heiko Carstens509e2562008-07-26 02:24:10 -07003020 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003021 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003022 card->dev->mtu = card->info.initial_mtu;
Jarod Wilson46b3ef42016-10-20 13:55:23 -04003023 card->dev->min_mtu = 64;
3024 card->dev->max_mtu = ETH_MAX_MTU;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00003025 card->dev->ethtool_ops = &qeth_l3_ethtool_ops;
Patrick McHardyf6469682013-04-19 02:04:27 +00003026 card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
3027 NETIF_F_HW_VLAN_CTAG_RX |
3028 NETIF_F_HW_VLAN_CTAG_FILTER;
Eric Dumazet02875872014-10-05 18:38:35 -07003029 netif_keep_dst(card->dev);
Eugene Crosser8bad55f2016-06-16 16:18:54 +02003030 card->dev->gso_max_size = (QETH_MAX_BUFFER_ELEMENTS(card) - 1) *
3031 PAGE_SIZE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003032
3033 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Julian Wiedmannd73ef322017-04-11 16:11:11 +02003034 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Ursula Braune5ebe632015-12-11 12:27:55 +01003035 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003036 return register_netdev(card->dev);
3037}
3038
Frank Blaschka4a71df52008-02-15 09:19:42 +01003039static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3040{
3041 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3042
3043 qeth_l3_create_device_attributes(&gdev->dev);
3044 card->options.layer2 = 0;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003045 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003046 return 0;
3047}
3048
3049static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3050{
3051 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3052
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003053 qeth_l3_remove_device_attributes(&cgdev->dev);
3054
Ursula Braunf2148562009-05-19 21:38:37 +00003055 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003056 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3057
Ursula Braun70919e22011-02-26 22:41:36 -08003058 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003059 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003060
3061 if (card->dev) {
Ursula Braun7831b4f2016-07-04 14:07:16 +02003062 netif_napi_del(&card->napi);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003063 unregister_netdev(card->dev);
3064 card->dev = NULL;
3065 }
3066
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003067 qeth_l3_clear_ip_htable(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003068 qeth_l3_clear_ipato_list(card);
3069 return;
3070}
3071
3072static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3073{
3074 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3075 int rc = 0;
3076 enum qeth_card_states recover_flag;
3077
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003078 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003079 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003080 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3081 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003082
Frank Blaschka4a71df52008-02-15 09:19:42 +01003083 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003084 rc = qeth_core_hardsetup_card(card);
3085 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01003086 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003087 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003088 goto out_remove;
3089 }
3090
Ursula Braunaa909222009-11-12 00:11:43 +00003091 if (!card->dev && qeth_l3_setup_netdev(card)) {
3092 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003093 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00003094 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003095
Frank Blaschka1da74b12011-05-12 18:45:02 +00003096 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
3097 if (card->info.hwtrap &&
3098 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
3099 card->info.hwtrap = 0;
3100 } else
3101 card->info.hwtrap = 0;
3102
Frank Blaschka4a71df52008-02-15 09:19:42 +01003103 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003104 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003105 qeth_print_status_message(card);
3106
3107 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003108 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003109
Frank Blaschka4a71df52008-02-15 09:19:42 +01003110 rc = qeth_l3_setadapter_parms(card);
3111 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003112 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003113 if (!card->options.sniffer) {
3114 rc = qeth_l3_start_ipassists(card);
Stefan Raspl0f547612013-01-21 02:30:20 +00003115 if (rc) {
Ursula Braun76b11f82010-01-11 02:50:50 +00003116 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Stefan Raspl0f547612013-01-21 02:30:20 +00003117 goto out_remove;
3118 }
Ursula Braun76b11f82010-01-11 02:50:50 +00003119 rc = qeth_l3_setrouting_v4(card);
3120 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003121 QETH_DBF_TEXT_(SETUP, 2, "4err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003122 rc = qeth_l3_setrouting_v6(card);
3123 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003124 QETH_DBF_TEXT_(SETUP, 2, "5err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003125 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003126 netif_tx_disable(card->dev);
3127
3128 rc = qeth_init_qdio_queues(card);
3129 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003130 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003131 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003132 goto out_remove;
3133 }
3134 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003135
3136 qeth_set_allowed_threads(card, 0xffffffff, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003137 qeth_l3_recover_ip(card);
Ursula Braun2b6203b2010-11-26 02:41:19 +00003138 if (card->lan_online)
3139 netif_carrier_on(card->dev);
3140 else
3141 netif_carrier_off(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003142 if (recover_flag == CARD_STATE_RECOVER) {
Ursula Braun4763b0a2011-12-19 22:56:32 +00003143 rtnl_lock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003144 if (recovery_mode)
Ursula Braun39423442011-01-12 20:42:24 +00003145 __qeth_l3_open(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00003146 else
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003147 dev_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003148 qeth_l3_set_multicast_list(card->dev);
Hans Wippele830baa2016-09-15 14:39:21 +02003149 qeth_recover_features(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00003150 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01003151 }
Stefan Raspl82f77cf2013-03-18 20:04:42 +00003152 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003153 /* let user_space know that device is online */
3154 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003155 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003156 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003157 return 0;
3158out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003159 qeth_l3_stop_card(card, 0);
3160 ccw_device_set_offline(CARD_DDEV(card));
3161 ccw_device_set_offline(CARD_WDEV(card));
3162 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01003163 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003164 if (recover_flag == CARD_STATE_RECOVER)
3165 card->state = CARD_STATE_RECOVER;
3166 else
3167 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00003168 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003169 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00003170 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003171}
3172
3173static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3174{
3175 return __qeth_l3_set_online(gdev, 0);
3176}
3177
3178static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3179 int recovery_mode)
3180{
3181 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3182 int rc = 0, rc2 = 0, rc3 = 0;
3183 enum qeth_card_states recover_flag;
3184
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003185 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003186 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003187 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3188 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003189
3190 if (card->dev && netif_carrier_ok(card->dev))
3191 netif_carrier_off(card->dev);
3192 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003193 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
3194 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
3195 card->info.hwtrap = 1;
3196 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02003197 qeth_l3_stop_card(card, recovery_mode);
Einar Lueck72861ae2011-12-19 22:56:36 +00003198 if ((card->options.cq == QETH_CQ_ENABLED) && card->dev) {
3199 rtnl_lock();
3200 call_netdevice_notifiers(NETDEV_REBOOT, card->dev);
3201 rtnl_unlock();
3202 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003203 rc = ccw_device_set_offline(CARD_DDEV(card));
3204 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3205 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3206 if (!rc)
3207 rc = (rc2) ? rc2 : rc3;
3208 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003209 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01003210 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003211 if (recover_flag == CARD_STATE_UP)
3212 card->state = CARD_STATE_RECOVER;
3213 /* let user_space know that device is offline */
3214 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003215 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003216 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003217 return 0;
3218}
3219
3220static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3221{
3222 return __qeth_l3_set_offline(cgdev, 0);
3223}
3224
3225static int qeth_l3_recover(void *ptr)
3226{
3227 struct qeth_card *card;
3228 int rc = 0;
3229
3230 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00003231 QETH_CARD_TEXT(card, 2, "recover1");
3232 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003233 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3234 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00003235 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003236 dev_warn(&card->gdev->dev,
3237 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00003238 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003239 __qeth_l3_set_offline(card->gdev, 1);
3240 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003241 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003242 dev_info(&card->gdev->dev,
3243 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003244 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00003245 qeth_close_dev(card);
3246 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00003247 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003248 }
Stefan Raspl65d80132013-04-07 22:19:27 +00003249 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003250 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3251 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003252 return 0;
3253}
3254
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003255static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3256{
3257 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3258
3259 if (card->dev)
3260 netif_device_detach(card->dev);
3261 qeth_set_allowed_threads(card, 0, 1);
3262 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3263 if (gdev->state == CCWGROUP_OFFLINE)
3264 return 0;
3265 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00003266 if (card->info.hwtrap)
3267 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003268 __qeth_l3_set_offline(card->gdev, 1);
3269 } else
3270 __qeth_l3_set_offline(card->gdev, 0);
3271 return 0;
3272}
3273
3274static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3275{
3276 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3277 int rc = 0;
3278
3279 if (gdev->state == CCWGROUP_OFFLINE)
3280 goto out;
3281
3282 if (card->state == CARD_STATE_RECOVER) {
3283 rc = __qeth_l3_set_online(card->gdev, 1);
3284 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00003285 rtnl_lock();
3286 dev_close(card->dev);
3287 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003288 }
3289 } else
3290 rc = __qeth_l3_set_online(card->gdev, 0);
3291out:
3292 qeth_set_allowed_threads(card, 0xffffffff, 0);
3293 if (card->dev)
3294 netif_device_attach(card->dev);
3295 if (rc)
3296 dev_warn(&card->gdev->dev, "The qeth device driver "
3297 "failed to recover an error on the device\n");
3298 return rc;
3299}
3300
Eugene Crosserc044dc22014-01-29 09:23:48 +01003301/* Returns zero if the command is successfully "consumed" */
3302static int qeth_l3_control_event(struct qeth_card *card,
3303 struct qeth_ipa_cmd *cmd)
3304{
3305 return 1;
3306}
3307
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003308struct qeth_discipline qeth_l3_discipline = {
3309 .start_poll = qeth_qdio_start_poll,
3310 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
3311 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02003312 .process_rx_buffer = qeth_l3_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003313 .recover = qeth_l3_recover,
3314 .setup = qeth_l3_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003315 .remove = qeth_l3_remove_device,
3316 .set_online = qeth_l3_set_online,
3317 .set_offline = qeth_l3_set_offline,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003318 .freeze = qeth_l3_pm_suspend,
3319 .thaw = qeth_l3_pm_resume,
3320 .restore = qeth_l3_pm_resume,
Julian Wiedmann942d6982017-04-11 16:11:10 +02003321 .do_ioctl = qeth_l3_do_ioctl,
Eugene Crosserc044dc22014-01-29 09:23:48 +01003322 .control_event_handler = qeth_l3_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003323};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003324EXPORT_SYMBOL_GPL(qeth_l3_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003325
3326static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003327 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003328{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003329
Frank Blaschka4a71df52008-02-15 09:19:42 +01003330 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3331 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3332 struct qeth_ipaddr *addr;
3333 struct qeth_card *card;
3334
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003335 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003336 return NOTIFY_DONE;
3337
Frank Blaschka4a71df52008-02-15 09:19:42 +01003338 card = qeth_l3_get_card_from_dev(dev);
3339 if (!card)
3340 return NOTIFY_DONE;
frank.blaschka@de.ibm.com6d8823d2012-05-16 01:28:26 +00003341 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003342
3343 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003344 if (addr) {
Hans Wippel6bee4e22017-04-07 09:15:36 +02003345 addr->u.a4.addr = be32_to_cpu(ifa->ifa_address);
3346 addr->u.a4.mask = be32_to_cpu(ifa->ifa_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003347 addr->type = QETH_IP_TYPE_NORMAL;
3348 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003349 return NOTIFY_DONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003350
3351 switch (event) {
3352 case NETDEV_UP:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003353 spin_lock_bh(&card->ip_lock);
3354 qeth_l3_add_ip(card, addr);
3355 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003356 break;
3357 case NETDEV_DOWN:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003358 spin_lock_bh(&card->ip_lock);
3359 qeth_l3_delete_ip(card, addr);
3360 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003361 break;
3362 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003363
3364 kfree(addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003365 return NOTIFY_DONE;
3366}
3367
3368static struct notifier_block qeth_l3_ip_notifier = {
3369 qeth_l3_ip_event,
3370 NULL,
3371};
3372
3373#ifdef CONFIG_QETH_IPV6
3374/**
3375 * IPv6 event handler
3376 */
3377static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003378 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003379{
3380 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3381 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3382 struct qeth_ipaddr *addr;
3383 struct qeth_card *card;
3384
Frank Blaschka4a71df52008-02-15 09:19:42 +01003385 card = qeth_l3_get_card_from_dev(dev);
3386 if (!card)
3387 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00003388 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003389 if (!qeth_is_supported(card, IPA_IPV6))
3390 return NOTIFY_DONE;
3391
3392 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003393 if (addr) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003394 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3395 addr->u.a6.pfxlen = ifa->prefix_len;
3396 addr->type = QETH_IP_TYPE_NORMAL;
3397 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003398 return NOTIFY_DONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003399
3400 switch (event) {
3401 case NETDEV_UP:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003402 spin_lock_bh(&card->ip_lock);
3403 qeth_l3_add_ip(card, addr);
3404 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003405 break;
3406 case NETDEV_DOWN:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003407 spin_lock_bh(&card->ip_lock);
3408 qeth_l3_delete_ip(card, addr);
3409 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003410 break;
3411 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003412
3413 kfree(addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003414 return NOTIFY_DONE;
3415}
3416
3417static struct notifier_block qeth_l3_ip6_notifier = {
3418 qeth_l3_ip6_event,
3419 NULL,
3420};
3421#endif
3422
3423static int qeth_l3_register_notifiers(void)
3424{
3425 int rc;
3426
Carsten Otte847a50f2010-06-21 22:57:05 +00003427 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003428 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3429 if (rc)
3430 return rc;
3431#ifdef CONFIG_QETH_IPV6
3432 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3433 if (rc) {
3434 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3435 return rc;
3436 }
3437#else
Joe Perchesbaebc702016-03-03 20:49:57 -08003438 pr_warn("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003439#endif
3440 return 0;
3441}
3442
3443static void qeth_l3_unregister_notifiers(void)
3444{
3445
Carsten Otte847a50f2010-06-21 22:57:05 +00003446 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Stefan Raspl18af5c12012-11-19 02:46:50 +00003447 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003448#ifdef CONFIG_QETH_IPV6
Stefan Raspl18af5c12012-11-19 02:46:50 +00003449 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003450#endif /* QETH_IPV6 */
3451}
3452
3453static int __init qeth_l3_init(void)
3454{
3455 int rc = 0;
3456
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003457 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003458 rc = qeth_l3_register_notifiers();
3459 return rc;
3460}
3461
3462static void __exit qeth_l3_exit(void)
3463{
3464 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003465 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003466}
3467
3468module_init(qeth_l3_init);
3469module_exit(qeth_l3_exit);
3470MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3471MODULE_DESCRIPTION("qeth layer 3 discipline");
3472MODULE_LICENSE("GPL");