blob: 93fa3316ec556325f3b0a98a960b95cc27cc07f8 [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>
19#include <linux/mii.h>
20#include <linux/ip.h>
Frank Blaschka64ef8952009-03-24 20:57:16 +000021#include <linux/ipv6.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010022#include <linux/inetdevice.h>
23#include <linux/igmp.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +000025#include <linux/if_vlan.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010026
27#include <net/ip.h>
28#include <net/arp.h>
David Miller87e75972012-02-01 10:49:17 +000029#include <net/route.h>
30#include <net/ip6_fib.h>
Frank Blaschka64ef8952009-03-24 20:57:16 +000031#include <net/ip6_checksum.h>
Frank Blaschkab3332932011-08-08 01:33:59 +000032#include <net/iucv/af_iucv.h>
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020033#include <linux/hashtable.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010034
Frank Blaschka4a71df52008-02-15 09:19:42 +010035#include "qeth_l3.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010036
Einar Lueckd0ddf30f2010-12-08 02:57:58 +000037
Frank Blaschka4a71df52008-02-15 09:19:42 +010038static int qeth_l3_set_offline(struct ccwgroup_device *);
39static int qeth_l3_recover(void *);
40static int qeth_l3_stop(struct net_device *);
41static void qeth_l3_set_multicast_list(struct net_device *);
42static int qeth_l3_neigh_setup(struct net_device *, struct neigh_parms *);
43static int qeth_l3_register_addr_entry(struct qeth_card *,
44 struct qeth_ipaddr *);
45static int qeth_l3_deregister_addr_entry(struct qeth_card *,
46 struct qeth_ipaddr *);
47static int __qeth_l3_set_online(struct ccwgroup_device *, int);
48static int __qeth_l3_set_offline(struct ccwgroup_device *, int);
49
Frank Blaschka4a71df52008-02-15 09:19:42 +010050static int qeth_l3_isxdigit(char *buf)
51{
52 while (*buf) {
53 if (!isxdigit(*buf++))
54 return 0;
55 }
56 return 1;
57}
58
Thomas Richter56530d62014-10-22 12:18:04 +020059static void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010060{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020061 sprintf(buf, "%pI4", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010062}
63
Thomas Richter56530d62014-10-22 12:18:04 +020064static int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +010065{
66 int count = 0, rc = 0;
Ursula Brauna68be012014-05-28 10:22:31 +020067 unsigned int in[4];
Frank Blaschka4a71df52008-02-15 09:19:42 +010068 char c;
69
70 rc = sscanf(buf, "%u.%u.%u.%u%c",
71 &in[0], &in[1], &in[2], &in[3], &c);
72 if (rc != 4 && (rc != 5 || c != '\n'))
73 return -EINVAL;
74 for (count = 0; count < 4; count++) {
75 if (in[count] > 255)
76 return -EINVAL;
77 addr[count] = in[count];
78 }
79 return 0;
80}
81
Thomas Richter56530d62014-10-22 12:18:04 +020082static void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010083{
Joe Perches963a9fd2010-09-07 21:14:40 +000084 sprintf(buf, "%pI6", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010085}
86
Thomas Richter56530d62014-10-22 12:18:04 +020087static int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +010088{
89 const char *end, *end_tmp, *start;
90 __u16 *in;
91 char num[5];
92 int num2, cnt, out, found, save_cnt;
93 unsigned short in_tmp[8] = {0, };
94
95 cnt = out = found = save_cnt = num2 = 0;
96 end = start = buf;
97 in = (__u16 *) addr;
98 memset(in, 0, 16);
99 while (*end) {
100 end = strchr(start, ':');
101 if (end == NULL) {
102 end = buf + strlen(buf);
103 end_tmp = strchr(start, '\n');
104 if (end_tmp != NULL)
105 end = end_tmp;
106 out = 1;
107 }
108 if ((end - start)) {
109 memset(num, 0, 5);
110 if ((end - start) > 4)
111 return -EINVAL;
112 memcpy(num, start, end - start);
113 if (!qeth_l3_isxdigit(num))
114 return -EINVAL;
115 sscanf(start, "%x", &num2);
116 if (found)
117 in_tmp[save_cnt++] = num2;
118 else
119 in[cnt++] = num2;
120 if (out)
121 break;
122 } else {
123 if (found)
124 return -EINVAL;
125 found = 1;
126 }
127 start = ++end;
128 }
129 if (cnt + save_cnt > 8)
130 return -EINVAL;
131 cnt = 7;
132 while (save_cnt)
133 in[cnt--] = in_tmp[--save_cnt];
134 return 0;
135}
136
137void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
138 char *buf)
139{
140 if (proto == QETH_PROT_IPV4)
141 qeth_l3_ipaddr4_to_string(addr, buf);
142 else if (proto == QETH_PROT_IPV6)
143 qeth_l3_ipaddr6_to_string(addr, buf);
144}
145
146int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
147 __u8 *addr)
148{
149 if (proto == QETH_PROT_IPV4)
150 return qeth_l3_string_to_ipaddr4(buf, addr);
151 else if (proto == QETH_PROT_IPV6)
152 return qeth_l3_string_to_ipaddr6(buf, addr);
153 else
154 return -EINVAL;
155}
156
157static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
158{
159 int i, j;
160 u8 octet;
161
162 for (i = 0; i < len; ++i) {
163 octet = addr[i];
164 for (j = 7; j >= 0; --j) {
165 bits[i*8 + j] = octet & 1;
166 octet >>= 1;
167 }
168 }
169}
170
Klaus-Dieter Wacker62982632010-07-22 23:15:03 +0000171int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100172 struct qeth_ipaddr *addr)
173{
174 struct qeth_ipato_entry *ipatoe;
175 u8 addr_bits[128] = {0, };
176 u8 ipatoe_bits[128] = {0, };
177 int rc = 0;
178
179 if (!card->ipato.enabled)
180 return 0;
181
182 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
183 (addr->proto == QETH_PROT_IPV4)? 4:16);
184 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
185 if (addr->proto != ipatoe->proto)
186 continue;
187 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
188 (ipatoe->proto == QETH_PROT_IPV4) ?
189 4 : 16);
190 if (addr->proto == QETH_PROT_IPV4)
191 rc = !memcmp(addr_bits, ipatoe_bits,
192 min(32, ipatoe->mask_bits));
193 else
194 rc = !memcmp(addr_bits, ipatoe_bits,
195 min(128, ipatoe->mask_bits));
196 if (rc)
197 break;
198 }
199 /* invert? */
200 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
201 rc = !rc;
202 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
203 rc = !rc;
204
205 return rc;
206}
207
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200208inline int
209qeth_l3_ipaddrs_is_equal(struct qeth_ipaddr *addr1, struct qeth_ipaddr *addr2)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100210{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200211 return addr1->proto == addr2->proto &&
212 !memcmp(&addr1->u, &addr2->u, sizeof(addr1->u)) &&
213 !memcmp(&addr1->mac, &addr2->mac, sizeof(addr1->mac));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100214}
215
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200216static struct qeth_ipaddr *
217qeth_l3_ip_from_hash(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100218{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200219 struct qeth_ipaddr *addr;
220
221 if (tmp_addr->is_multicast) {
222 hash_for_each_possible(card->ip_mc_htable, addr,
223 hnode, qeth_l3_ipaddr_hash(tmp_addr))
224 if (qeth_l3_ipaddrs_is_equal(tmp_addr, addr))
225 return addr;
226 } else {
227 hash_for_each_possible(card->ip_htable, addr,
228 hnode, qeth_l3_ipaddr_hash(tmp_addr))
229 if (qeth_l3_ipaddrs_is_equal(tmp_addr, addr))
230 return addr;
231 }
232
233 return NULL;
234}
235
236int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
237{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100238 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200239 struct qeth_ipaddr *addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100240
Carsten Otte847a50f2010-06-21 22:57:05 +0000241 QETH_CARD_TEXT(card, 4, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100242
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200243 if (tmp_addr->proto == QETH_PROT_IPV4)
244 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100245 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200246 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
247 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100248 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200249
250 addr = qeth_l3_ip_from_hash(card, tmp_addr);
251 if (!addr)
252 return -ENOENT;
253
254 addr->ref_counter--;
255 if (addr->type == QETH_IP_TYPE_NORMAL && addr->ref_counter > 0)
256 return rc;
257 if (addr->in_progress)
258 return -EINPROGRESS;
259
Ursula Brauna7531c12016-09-15 14:39:23 +0200260 if (!qeth_card_hw_is_reachable(card)) {
261 addr->disp_flag = QETH_DISP_ADDR_DELETE;
262 return 0;
263 }
264
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200265 rc = qeth_l3_deregister_addr_entry(card, addr);
266
267 hash_del(&addr->hnode);
268 kfree(addr);
269
Frank Blaschka4a71df52008-02-15 09:19:42 +0100270 return rc;
271}
272
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200273int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100274{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100275 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200276 struct qeth_ipaddr *addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100277
Carsten Otte847a50f2010-06-21 22:57:05 +0000278 QETH_CARD_TEXT(card, 4, "addip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200279
280 if (tmp_addr->proto == QETH_PROT_IPV4)
281 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100282 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200283 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
284 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100285 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200286
287 addr = qeth_l3_ip_from_hash(card, tmp_addr);
288 if (!addr) {
289 addr = qeth_l3_get_addr_buffer(tmp_addr->proto);
290 if (!addr)
291 return -ENOMEM;
292
293 memcpy(addr, tmp_addr, sizeof(struct qeth_ipaddr));
294 addr->ref_counter = 1;
295
296 if (addr->type == QETH_IP_TYPE_NORMAL &&
297 qeth_l3_is_addr_covered_by_ipato(card, addr)) {
298 QETH_CARD_TEXT(card, 2, "tkovaddr");
299 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
300 }
301 hash_add(card->ip_htable, &addr->hnode,
302 qeth_l3_ipaddr_hash(addr));
303
Ursula Brauna7531c12016-09-15 14:39:23 +0200304 if (!qeth_card_hw_is_reachable(card)) {
305 addr->disp_flag = QETH_DISP_ADDR_ADD;
306 return 0;
307 }
308
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200309 /* qeth_l3_register_addr_entry can go to sleep
310 * if we add a IPV4 addr. It is caused by the reason
311 * that SETIP ipa cmd starts ARP staff for IPV4 addr.
312 * Thus we should unlock spinlock, and make a protection
313 * using in_progress variable to indicate that there is
314 * an hardware operation with this IPV4 address
315 */
316 if (addr->proto == QETH_PROT_IPV4) {
317 addr->in_progress = 1;
318 spin_unlock_bh(&card->ip_lock);
319 rc = qeth_l3_register_addr_entry(card, addr);
320 spin_lock_bh(&card->ip_lock);
321 addr->in_progress = 0;
322 } else
323 rc = qeth_l3_register_addr_entry(card, addr);
324
325 if (!rc || (rc == IPA_RC_DUPLICATE_IP_ADDRESS) ||
326 (rc == IPA_RC_LAN_OFFLINE)) {
327 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
328 if (addr->ref_counter < 1) {
329 qeth_l3_delete_ip(card, addr);
330 kfree(addr);
331 }
332 } else {
333 hash_del(&addr->hnode);
334 kfree(addr);
335 }
336 } else {
337 if (addr->type == QETH_IP_TYPE_NORMAL)
338 addr->ref_counter++;
339 }
340
Frank Blaschka4a71df52008-02-15 09:19:42 +0100341 return rc;
342}
343
344
Frank Blaschkab3332932011-08-08 01:33:59 +0000345struct qeth_ipaddr *qeth_l3_get_addr_buffer(
Frank Blaschka4a71df52008-02-15 09:19:42 +0100346 enum qeth_prot_versions prot)
347{
348 struct qeth_ipaddr *addr;
349
350 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200351 if (!addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100352 return NULL;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200353
Frank Blaschka4a71df52008-02-15 09:19:42 +0100354 addr->type = QETH_IP_TYPE_NORMAL;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200355 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100356 addr->proto = prot;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200357
Frank Blaschka4a71df52008-02-15 09:19:42 +0100358 return addr;
359}
360
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200361static void qeth_l3_clear_ip_htable(struct qeth_card *card, int recover)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100362{
363 struct qeth_ipaddr *addr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200364 struct hlist_node *tmp;
365 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100366
Carsten Otte847a50f2010-06-21 22:57:05 +0000367 QETH_CARD_TEXT(card, 4, "clearip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200368
Ursula Braun76b11f82010-01-11 02:50:50 +0000369 if (recover && card->options.sniffer)
370 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100371
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200372 spin_lock_bh(&card->ip_lock);
373
374 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
375 if (!recover) {
376 hash_del(&addr->hnode);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100377 kfree(addr);
378 continue;
379 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200380 addr->disp_flag = QETH_DISP_ADDR_ADD;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100381 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200382
383 spin_unlock_bh(&card->ip_lock);
384
385 spin_lock_bh(&card->mclock);
386
387 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
388 hash_del(&addr->hnode);
389 kfree(addr);
390 }
391
392 spin_unlock_bh(&card->mclock);
393
394
Frank Blaschka4a71df52008-02-15 09:19:42 +0100395}
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200396static void qeth_l3_recover_ip(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100397{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200398 struct qeth_ipaddr *addr;
399 struct hlist_node *tmp;
400 int i;
401 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100402
Ursula Brauna7531c12016-09-15 14:39:23 +0200403 QETH_CARD_TEXT(card, 4, "recovrip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100404
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200405 spin_lock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100406
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200407 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
Ursula Brauna7531c12016-09-15 14:39:23 +0200408 if (addr->disp_flag == QETH_DISP_ADDR_DELETE) {
409 qeth_l3_deregister_addr_entry(card, addr);
410 hash_del(&addr->hnode);
411 kfree(addr);
412 } else if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200413 if (addr->proto == QETH_PROT_IPV4) {
414 addr->in_progress = 1;
415 spin_unlock_bh(&card->ip_lock);
416 rc = qeth_l3_register_addr_entry(card, addr);
417 spin_lock_bh(&card->ip_lock);
418 addr->in_progress = 0;
419 } else
420 rc = qeth_l3_register_addr_entry(card, addr);
421
422 if (!rc) {
423 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Ursula Brauna7531c12016-09-15 14:39:23 +0200424 if (addr->ref_counter < 1)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200425 qeth_l3_delete_ip(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200426 } else {
427 hash_del(&addr->hnode);
428 kfree(addr);
429 }
430 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100431 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200432
433 spin_unlock_bh(&card->ip_lock);
434
Frank Blaschka4a71df52008-02-15 09:19:42 +0100435}
436
437static int qeth_l3_send_setdelmc(struct qeth_card *card,
438 struct qeth_ipaddr *addr, int ipacmd)
439{
440 int rc;
441 struct qeth_cmd_buffer *iob;
442 struct qeth_ipa_cmd *cmd;
443
Carsten Otte847a50f2010-06-21 22:57:05 +0000444 QETH_CARD_TEXT(card, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100445
446 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100447 if (!iob)
448 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100449 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
450 memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
451 if (addr->proto == QETH_PROT_IPV6)
452 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
453 sizeof(struct in6_addr));
454 else
455 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
456
457 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
458
459 return rc;
460}
461
462static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
463{
464 int i, j;
465 for (i = 0; i < 16; i++) {
466 j = (len) - (i * 8);
467 if (j >= 8)
468 netmask[i] = 0xff;
469 else if (j > 0)
470 netmask[i] = (u8)(0xFF00 >> j);
471 else
472 netmask[i] = 0;
473 }
474}
475
476static int qeth_l3_send_setdelip(struct qeth_card *card,
477 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
478{
479 int rc;
480 struct qeth_cmd_buffer *iob;
481 struct qeth_ipa_cmd *cmd;
482 __u8 netmask[16];
483
Carsten Otte847a50f2010-06-21 22:57:05 +0000484 QETH_CARD_TEXT(card, 4, "setdelip");
485 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100486
487 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100488 if (!iob)
489 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100490 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
491 if (addr->proto == QETH_PROT_IPV6) {
492 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
493 sizeof(struct in6_addr));
494 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
495 memcpy(cmd->data.setdelip6.mask, netmask,
496 sizeof(struct in6_addr));
497 cmd->data.setdelip6.flags = flags;
498 } else {
499 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
500 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
501 cmd->data.setdelip4.flags = flags;
502 }
503
504 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
505
506 return rc;
507}
508
509static int qeth_l3_send_setrouting(struct qeth_card *card,
510 enum qeth_routing_types type, enum qeth_prot_versions prot)
511{
512 int rc;
513 struct qeth_ipa_cmd *cmd;
514 struct qeth_cmd_buffer *iob;
515
Carsten Otte847a50f2010-06-21 22:57:05 +0000516 QETH_CARD_TEXT(card, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100517 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100518 if (!iob)
519 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100520 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
521 cmd->data.setrtg.type = (type);
522 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
523
524 return rc;
525}
526
Stefan Raspl82e2e782013-03-18 20:04:43 +0000527static int qeth_l3_correct_routing_type(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100528 enum qeth_routing_types *type, enum qeth_prot_versions prot)
529{
530 if (card->info.type == QETH_CARD_TYPE_IQD) {
531 switch (*type) {
532 case NO_ROUTER:
533 case PRIMARY_CONNECTOR:
534 case SECONDARY_CONNECTOR:
535 case MULTICAST_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000536 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100537 default:
538 goto out_inval;
539 }
540 } else {
541 switch (*type) {
542 case NO_ROUTER:
543 case PRIMARY_ROUTER:
544 case SECONDARY_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000545 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100546 case MULTICAST_ROUTER:
547 if (qeth_is_ipafunc_supported(card, prot,
548 IPA_OSA_MC_ROUTER))
Stefan Raspl82e2e782013-03-18 20:04:43 +0000549 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100550 default:
551 goto out_inval;
552 }
553 }
554out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100555 *type = NO_ROUTER;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000556 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100557}
558
559int qeth_l3_setrouting_v4(struct qeth_card *card)
560{
561 int rc;
562
Carsten Otte847a50f2010-06-21 22:57:05 +0000563 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100564
Stefan Raspl82e2e782013-03-18 20:04:43 +0000565 rc = qeth_l3_correct_routing_type(card, &card->options.route4.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100566 QETH_PROT_IPV4);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000567 if (rc)
568 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100569
570 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
571 QETH_PROT_IPV4);
572 if (rc) {
573 card->options.route4.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200574 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
575 " on %s. Type set to 'no router'.\n", rc,
576 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100577 }
578 return rc;
579}
580
581int qeth_l3_setrouting_v6(struct qeth_card *card)
582{
583 int rc = 0;
584
Carsten Otte847a50f2010-06-21 22:57:05 +0000585 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100586#ifdef CONFIG_QETH_IPV6
587
588 if (!qeth_is_supported(card, IPA_IPV6))
589 return 0;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000590 rc = qeth_l3_correct_routing_type(card, &card->options.route6.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100591 QETH_PROT_IPV6);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000592 if (rc)
593 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100594
595 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
596 QETH_PROT_IPV6);
597 if (rc) {
598 card->options.route6.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200599 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
600 " on %s. Type set to 'no router'.\n", rc,
601 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100602 }
603#endif
604 return rc;
605}
606
607/*
608 * IP address takeover related functions
609 */
610static void qeth_l3_clear_ipato_list(struct qeth_card *card)
611{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100612 struct qeth_ipato_entry *ipatoe, *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100613
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200614 spin_lock_bh(&card->ip_lock);
615
Frank Blaschka4a71df52008-02-15 09:19:42 +0100616 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
617 list_del(&ipatoe->entry);
618 kfree(ipatoe);
619 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200620
621 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100622}
623
624int qeth_l3_add_ipato_entry(struct qeth_card *card,
625 struct qeth_ipato_entry *new)
626{
627 struct qeth_ipato_entry *ipatoe;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100628 int rc = 0;
629
Carsten Otte847a50f2010-06-21 22:57:05 +0000630 QETH_CARD_TEXT(card, 2, "addipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200631
632 spin_lock_bh(&card->ip_lock);
633
Frank Blaschka4a71df52008-02-15 09:19:42 +0100634 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
635 if (ipatoe->proto != new->proto)
636 continue;
637 if (!memcmp(ipatoe->addr, new->addr,
638 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
639 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100640 rc = -EEXIST;
641 break;
642 }
643 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200644
Frank Blaschka4a71df52008-02-15 09:19:42 +0100645 if (!rc)
646 list_add_tail(&new->entry, &card->ipato.entries);
647
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200648 spin_unlock_bh(&card->ip_lock);
649
Frank Blaschka4a71df52008-02-15 09:19:42 +0100650 return rc;
651}
652
653void qeth_l3_del_ipato_entry(struct qeth_card *card,
654 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
655{
656 struct qeth_ipato_entry *ipatoe, *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100657
Carsten Otte847a50f2010-06-21 22:57:05 +0000658 QETH_CARD_TEXT(card, 2, "delipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200659
660 spin_lock_bh(&card->ip_lock);
661
Frank Blaschka4a71df52008-02-15 09:19:42 +0100662 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
663 if (ipatoe->proto != proto)
664 continue;
665 if (!memcmp(ipatoe->addr, addr,
666 (proto == QETH_PROT_IPV4)? 4:16) &&
667 (ipatoe->mask_bits == mask_bits)) {
668 list_del(&ipatoe->entry);
669 kfree(ipatoe);
670 }
671 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200672
673 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100674}
675
676/*
677 * VIPA related functions
678 */
679int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
680 const u8 *addr)
681{
682 struct qeth_ipaddr *ipaddr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100683 int rc = 0;
684
685 ipaddr = qeth_l3_get_addr_buffer(proto);
686 if (ipaddr) {
687 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000688 QETH_CARD_TEXT(card, 2, "addvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100689 memcpy(&ipaddr->u.a4.addr, addr, 4);
690 ipaddr->u.a4.mask = 0;
691 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000692 QETH_CARD_TEXT(card, 2, "addvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100693 memcpy(&ipaddr->u.a6.addr, addr, 16);
694 ipaddr->u.a6.pfxlen = 0;
695 }
696 ipaddr->type = QETH_IP_TYPE_VIPA;
697 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
698 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
699 } else
700 return -ENOMEM;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200701
702 spin_lock_bh(&card->ip_lock);
703
Thomas Richter732a59c2016-09-15 14:39:27 +0200704 if (qeth_l3_ip_from_hash(card, ipaddr))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100705 rc = -EEXIST;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200706 else
707 qeth_l3_add_ip(card, ipaddr);
708
709 spin_unlock_bh(&card->ip_lock);
710
711 kfree(ipaddr);
712
Frank Blaschka4a71df52008-02-15 09:19:42 +0100713 return rc;
714}
715
716void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
717 const u8 *addr)
718{
719 struct qeth_ipaddr *ipaddr;
720
721 ipaddr = qeth_l3_get_addr_buffer(proto);
722 if (ipaddr) {
723 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000724 QETH_CARD_TEXT(card, 2, "delvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100725 memcpy(&ipaddr->u.a4.addr, addr, 4);
726 ipaddr->u.a4.mask = 0;
727 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000728 QETH_CARD_TEXT(card, 2, "delvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100729 memcpy(&ipaddr->u.a6.addr, addr, 16);
730 ipaddr->u.a6.pfxlen = 0;
731 }
732 ipaddr->type = QETH_IP_TYPE_VIPA;
733 } else
734 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200735
736 spin_lock_bh(&card->ip_lock);
737 qeth_l3_delete_ip(card, ipaddr);
738 spin_unlock_bh(&card->ip_lock);
739
740 kfree(ipaddr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100741}
742
743/*
744 * proxy ARP related functions
745 */
746int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
747 const u8 *addr)
748{
749 struct qeth_ipaddr *ipaddr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100750 int rc = 0;
751
752 ipaddr = qeth_l3_get_addr_buffer(proto);
753 if (ipaddr) {
754 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000755 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100756 memcpy(&ipaddr->u.a4.addr, addr, 4);
757 ipaddr->u.a4.mask = 0;
758 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000759 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100760 memcpy(&ipaddr->u.a6.addr, addr, 16);
761 ipaddr->u.a6.pfxlen = 0;
762 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200763
Frank Blaschka4a71df52008-02-15 09:19:42 +0100764 ipaddr->type = QETH_IP_TYPE_RXIP;
765 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
766 ipaddr->del_flags = 0;
767 } else
768 return -ENOMEM;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200769
770 spin_lock_bh(&card->ip_lock);
771
Thomas Richter732a59c2016-09-15 14:39:27 +0200772 if (qeth_l3_ip_from_hash(card, ipaddr))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100773 rc = -EEXIST;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200774 else
775 qeth_l3_add_ip(card, ipaddr);
776
777 spin_unlock_bh(&card->ip_lock);
778
779 kfree(ipaddr);
780
781 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100782}
783
784void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
785 const u8 *addr)
786{
787 struct qeth_ipaddr *ipaddr;
788
789 ipaddr = qeth_l3_get_addr_buffer(proto);
790 if (ipaddr) {
791 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000792 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100793 memcpy(&ipaddr->u.a4.addr, addr, 4);
794 ipaddr->u.a4.mask = 0;
795 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000796 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100797 memcpy(&ipaddr->u.a6.addr, addr, 16);
798 ipaddr->u.a6.pfxlen = 0;
799 }
800 ipaddr->type = QETH_IP_TYPE_RXIP;
801 } else
802 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200803
804 spin_lock_bh(&card->ip_lock);
805 qeth_l3_delete_ip(card, ipaddr);
806 spin_unlock_bh(&card->ip_lock);
807
808 kfree(ipaddr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100809}
810
811static int qeth_l3_register_addr_entry(struct qeth_card *card,
812 struct qeth_ipaddr *addr)
813{
814 char buf[50];
815 int rc = 0;
816 int cnt = 3;
817
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200818
Frank Blaschka4a71df52008-02-15 09:19:42 +0100819 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000820 QETH_CARD_TEXT(card, 2, "setaddr4");
821 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100822 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000823 QETH_CARD_TEXT(card, 2, "setaddr6");
824 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
825 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100826 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000827 QETH_CARD_TEXT(card, 2, "setaddr?");
828 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100829 }
830 do {
831 if (addr->is_multicast)
832 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
833 else
834 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
835 addr->set_flags);
836 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000837 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100838 } while ((--cnt > 0) && rc);
839 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000840 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100841 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100842 dev_warn(&card->gdev->dev,
843 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100844 }
845 return rc;
846}
847
848static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
849 struct qeth_ipaddr *addr)
850{
851 int rc = 0;
852
853 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000854 QETH_CARD_TEXT(card, 2, "deladdr4");
855 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100856 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000857 QETH_CARD_TEXT(card, 2, "deladdr6");
858 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
859 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100860 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000861 QETH_CARD_TEXT(card, 2, "deladdr?");
862 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100863 }
864 if (addr->is_multicast)
865 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
866 else
867 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
868 addr->del_flags);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200869 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000870 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100871
872 return rc;
873}
874
875static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
876{
877 if (cast_type == RTN_MULTICAST)
878 return QETH_CAST_MULTICAST;
879 if (cast_type == RTN_BROADCAST)
880 return QETH_CAST_BROADCAST;
881 return QETH_CAST_UNICAST;
882}
883
884static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
885{
886 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
887 if (cast_type == RTN_MULTICAST)
888 return ct | QETH_CAST_MULTICAST;
889 if (cast_type == RTN_ANYCAST)
890 return ct | QETH_CAST_ANYCAST;
891 if (cast_type == RTN_BROADCAST)
892 return ct | QETH_CAST_BROADCAST;
893 return ct | QETH_CAST_UNICAST;
894}
895
Frank Blaschka4a71df52008-02-15 09:19:42 +0100896static int qeth_l3_setadapter_parms(struct qeth_card *card)
897{
898 int rc;
899
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200900 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100901
902 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100903 dev_info(&card->gdev->dev,
904 "set adapter parameters not supported.\n");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200905 QETH_DBF_TEXT(SETUP, 2, " notsupp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100906 return 0;
907 }
908 rc = qeth_query_setadapterparms(card);
909 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100910 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
Kay Sievers7f6d95e2009-03-24 20:57:14 +0000911 "0x%x\n", dev_name(&card->gdev->dev), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100912 return rc;
913 }
914 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
915 rc = qeth_setadpparms_change_macaddr(card);
916 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100917 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -0800918 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100919 }
920
Frank Blaschka4a71df52008-02-15 09:19:42 +0100921 return rc;
922}
923
Frank Blaschka4a71df52008-02-15 09:19:42 +0100924#ifdef CONFIG_QETH_IPV6
925static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
926 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
927{
928 int rc;
929 struct qeth_cmd_buffer *iob;
930
Carsten Otte847a50f2010-06-21 22:57:05 +0000931 QETH_CARD_TEXT(card, 4, "simassp6");
Thomas Richterb475e312015-12-11 12:27:54 +0100932 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100933 0, QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100934 if (!iob)
935 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +0200936 rc = qeth_send_setassparms(card, iob, 0, 0,
Thomas Richter8f43fb02016-06-16 16:18:59 +0200937 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100938 return rc;
939}
940#endif
941
Frank Blaschka4a71df52008-02-15 09:19:42 +0100942static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
943{
944 int rc;
945
Carsten Otte847a50f2010-06-21 22:57:05 +0000946 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100947
948 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100949 dev_info(&card->gdev->dev,
950 "ARP processing not supported on %s!\n",
951 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100952 return 0;
953 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200954 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
955 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100956 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100957 dev_warn(&card->gdev->dev,
958 "Starting ARP processing support for %s failed\n",
959 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100960 }
961 return rc;
962}
963
964static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
965{
966 int rc;
967
Carsten Otte847a50f2010-06-21 22:57:05 +0000968 QETH_CARD_TEXT(card, 3, "ipaipfrg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100969
970 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100971 dev_info(&card->gdev->dev,
972 "Hardware IP fragmentation not supported on %s\n",
973 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100974 return -EOPNOTSUPP;
975 }
976
Thomas Richter4d7def22015-09-18 16:06:51 +0200977 rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100978 IPA_CMD_ASS_START, 0);
979 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100980 dev_warn(&card->gdev->dev,
981 "Starting IP fragmentation support for %s failed\n",
982 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100983 } else
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100984 dev_info(&card->gdev->dev,
985 "Hardware IP fragmentation enabled \n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100986 return rc;
987}
988
989static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
990{
991 int rc;
992
Carsten Otte847a50f2010-06-21 22:57:05 +0000993 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100994
Frank Blaschka4a71df52008-02-15 09:19:42 +0100995 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100996 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800997 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100998 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100999 return -EOPNOTSUPP;
1000 }
1001
Thomas Richter4d7def22015-09-18 16:06:51 +02001002 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001003 IPA_CMD_ASS_START, 0);
1004 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001005 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001006 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001007 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001008 return rc;
1009}
1010
1011static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1012{
1013 int rc = 0;
1014
Carsten Otte847a50f2010-06-21 22:57:05 +00001015 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001016
1017 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001018 dev_info(&card->gdev->dev,
1019 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001020 return -EOPNOTSUPP;
1021 }
1022
Thomas Richter4d7def22015-09-18 16:06:51 +02001023 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001024 IPA_CMD_ASS_START, 0);
1025 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001026 dev_warn(&card->gdev->dev,
1027 "Starting VLAN support for %s failed\n",
1028 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001029 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001030 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001031 }
1032 return rc;
1033}
1034
1035static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1036{
1037 int rc;
1038
Carsten Otte847a50f2010-06-21 22:57:05 +00001039 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001040
1041 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001042 dev_info(&card->gdev->dev,
1043 "Multicast not supported on %s\n",
1044 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001045 return -EOPNOTSUPP;
1046 }
1047
Thomas Richter4d7def22015-09-18 16:06:51 +02001048 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001049 IPA_CMD_ASS_START, 0);
1050 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001051 dev_warn(&card->gdev->dev,
1052 "Starting multicast support for %s failed\n",
1053 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001054 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001055 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001056 card->dev->flags |= IFF_MULTICAST;
1057 }
1058 return rc;
1059}
1060
Frank Blaschka4a71df52008-02-15 09:19:42 +01001061#ifdef CONFIG_QETH_IPV6
1062static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1063{
1064 int rc;
1065
Carsten Otte847a50f2010-06-21 22:57:05 +00001066 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001067
1068 if (card->info.type == QETH_CARD_TYPE_IQD)
1069 goto out;
1070
Frank Blaschka1da74b12011-05-12 18:45:02 +00001071 rc = qeth_query_ipassists(card, QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001072 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001073 dev_err(&card->gdev->dev,
1074 "Activating IPv6 support for %s failed\n",
1075 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001076 return rc;
1077 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001078 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001079 IPA_CMD_ASS_START, 3);
1080 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001081 dev_err(&card->gdev->dev,
1082 "Activating IPv6 support for %s failed\n",
1083 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001084 return rc;
1085 }
1086 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1087 IPA_CMD_ASS_START);
1088 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001089 dev_err(&card->gdev->dev,
1090 "Activating IPv6 support for %s failed\n",
1091 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001092 return rc;
1093 }
1094 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1095 IPA_CMD_ASS_START);
1096 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001097 dev_warn(&card->gdev->dev,
1098 "Enabling the passthrough mode for %s failed\n",
1099 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001100 return rc;
1101 }
1102out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001103 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001104 return 0;
1105}
1106#endif
1107
1108static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1109{
1110 int rc = 0;
1111
Carsten Otte847a50f2010-06-21 22:57:05 +00001112 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001113
1114 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001115 dev_info(&card->gdev->dev,
1116 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001117 return 0;
1118 }
1119#ifdef CONFIG_QETH_IPV6
1120 rc = qeth_l3_softsetup_ipv6(card);
1121#endif
1122 return rc ;
1123}
1124
1125static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1126{
1127 int rc;
1128
Carsten Otte847a50f2010-06-21 22:57:05 +00001129 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001130 card->info.broadcast_capable = 0;
1131 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001132 dev_info(&card->gdev->dev,
1133 "Broadcast not supported on %s\n",
1134 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001135 rc = -EOPNOTSUPP;
1136 goto out;
1137 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001138 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001139 IPA_CMD_ASS_START, 0);
1140 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001141 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1142 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001143 goto out;
1144 }
1145
Thomas Richter4d7def22015-09-18 16:06:51 +02001146 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001147 IPA_CMD_ASS_CONFIGURE, 1);
1148 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001149 dev_warn(&card->gdev->dev,
1150 "Setting up broadcast filtering for %s failed\n",
1151 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001152 goto out;
1153 }
1154 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001155 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Thomas Richter4d7def22015-09-18 16:06:51 +02001156 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001157 IPA_CMD_ASS_ENABLE, 1);
1158 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001159 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1160 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001161 goto out;
1162 }
1163 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1164out:
1165 if (card->info.broadcast_capable)
1166 card->dev->flags |= IFF_BROADCAST;
1167 else
1168 card->dev->flags &= ~IFF_BROADCAST;
1169 return rc;
1170}
1171
Frank Blaschka4a71df52008-02-15 09:19:42 +01001172static int qeth_l3_start_ipassists(struct qeth_card *card)
1173{
Carsten Otte847a50f2010-06-21 22:57:05 +00001174 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +00001175
Stefan Raspl0f547612013-01-21 02:30:20 +00001176 if (qeth_set_access_ctrl_online(card, 0))
1177 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001178 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1179 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1180 qeth_l3_start_ipa_source_mac(card); /* go on*/
1181 qeth_l3_start_ipa_vlan(card); /* go on*/
1182 qeth_l3_start_ipa_multicast(card); /* go on*/
1183 qeth_l3_start_ipa_ipv6(card); /* go on*/
1184 qeth_l3_start_ipa_broadcast(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +01001185 return 0;
1186}
1187
Frank Blaschka4a71df52008-02-15 09:19:42 +01001188static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1189 struct qeth_reply *reply, unsigned long data)
1190{
1191 struct qeth_ipa_cmd *cmd;
1192
1193 cmd = (struct qeth_ipa_cmd *) data;
1194 if (cmd->hdr.return_code == 0)
1195 memcpy(card->dev->dev_addr,
1196 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1197 else
Joe Perches18336112012-07-12 22:33:10 -07001198 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001199
1200 return 0;
1201}
1202
1203static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1204{
1205 int rc = 0;
1206 struct qeth_cmd_buffer *iob;
1207 struct qeth_ipa_cmd *cmd;
1208
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001209 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001210
1211 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1212 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001213 if (!iob)
1214 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001215 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1216 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1217 card->info.unique_id;
1218
1219 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1220 NULL);
1221 return rc;
1222}
1223
1224static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1225 struct qeth_reply *reply, unsigned long data)
1226{
1227 struct qeth_ipa_cmd *cmd;
1228
1229 cmd = (struct qeth_ipa_cmd *) data;
1230 if (cmd->hdr.return_code == 0)
1231 card->info.unique_id = *((__u16 *)
1232 &cmd->data.create_destroy_addr.unique_id[6]);
1233 else {
1234 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1235 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001236 dev_warn(&card->gdev->dev, "The network adapter failed to "
1237 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001238 }
1239 return 0;
1240}
1241
1242static int qeth_l3_get_unique_id(struct qeth_card *card)
1243{
1244 int rc = 0;
1245 struct qeth_cmd_buffer *iob;
1246 struct qeth_ipa_cmd *cmd;
1247
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001248 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001249
1250 if (!qeth_is_supported(card, IPA_IPV6)) {
1251 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1252 UNIQUE_ID_NOT_BY_CARD;
1253 return 0;
1254 }
1255
1256 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1257 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001258 if (!iob)
1259 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001260 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1261 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1262 card->info.unique_id;
1263
1264 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1265 return rc;
1266}
1267
Ursula Braun76b11f82010-01-11 02:50:50 +00001268static int
1269qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1270 unsigned long data)
1271{
1272 struct qeth_ipa_cmd *cmd;
1273 __u16 rc;
1274
1275 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1276
1277 cmd = (struct qeth_ipa_cmd *)data;
1278 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001279 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001280 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001281 switch (cmd->data.diagass.action) {
1282 case QETH_DIAGS_CMD_TRACE_QUERY:
1283 break;
1284 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001285 switch (rc) {
1286 case 0:
1287 case IPA_RC_INVALID_SUBCMD:
1288 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1289 dev_info(&card->gdev->dev, "The HiperSockets network "
1290 "traffic analyzer is deactivated\n");
1291 break;
1292 default:
1293 break;
1294 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001295 break;
1296 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001297 switch (rc) {
1298 case 0:
1299 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1300 dev_info(&card->gdev->dev, "The HiperSockets network "
1301 "traffic analyzer is activated\n");
1302 break;
1303 case IPA_RC_HARDWARE_AUTH_ERROR:
1304 dev_warn(&card->gdev->dev, "The device is not "
1305 "authorized to run as a HiperSockets network "
1306 "traffic analyzer\n");
1307 break;
1308 case IPA_RC_TRACE_ALREADY_ACTIVE:
1309 dev_warn(&card->gdev->dev, "A HiperSockets "
1310 "network traffic analyzer is already "
1311 "active in the HiperSockets LAN\n");
1312 break;
1313 default:
1314 break;
1315 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001316 break;
1317 default:
1318 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1319 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1320 }
1321
1322 return 0;
1323}
1324
1325static int
1326qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1327{
1328 struct qeth_cmd_buffer *iob;
1329 struct qeth_ipa_cmd *cmd;
1330
1331 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1332
1333 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001334 if (!iob)
1335 return -ENOMEM;
Ursula Braun76b11f82010-01-11 02:50:50 +00001336 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1337 cmd->data.diagass.subcmd_len = 16;
1338 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1339 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1340 cmd->data.diagass.action = diags_cmd;
1341 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1342}
1343
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001344static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001345{
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001346 ip_eth_mc_map(ipm, mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001347}
1348
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001349static void qeth_l3_mark_all_mc_to_be_deleted(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001350{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001351 struct qeth_ipaddr *addr;
1352 int i;
1353
1354 hash_for_each(card->ip_mc_htable, i, addr, hnode)
1355 addr->disp_flag = QETH_DISP_ADDR_DELETE;
1356
1357}
1358
1359static void qeth_l3_add_all_new_mc(struct qeth_card *card)
1360{
1361 struct qeth_ipaddr *addr;
1362 struct hlist_node *tmp;
1363 int i;
1364 int rc;
1365
1366 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1367 if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
1368 rc = qeth_l3_register_addr_entry(card, addr);
1369 if (!rc || (rc == IPA_RC_LAN_OFFLINE))
1370 addr->ref_counter = 1;
1371 else {
1372 hash_del(&addr->hnode);
1373 kfree(addr);
1374 }
1375 }
1376 }
1377
1378}
1379
1380static void qeth_l3_delete_nonused_mc(struct qeth_card *card)
1381{
1382 struct qeth_ipaddr *addr;
1383 struct hlist_node *tmp;
1384 int i;
1385 int rc;
1386
1387 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1388 if (addr->disp_flag == QETH_DISP_ADDR_DELETE) {
1389 rc = qeth_l3_deregister_addr_entry(card, addr);
1390 if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND)) {
1391 hash_del(&addr->hnode);
1392 kfree(addr);
1393 }
1394 }
1395 }
1396
1397}
1398
1399
1400static void
1401qeth_l3_add_mc_to_hash(struct qeth_card *card, struct in_device *in4_dev)
1402{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001403 struct ip_mc_list *im4;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001404 struct qeth_ipaddr *tmp, *ipm;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001405 char buf[MAX_ADDR_LEN];
1406
Carsten Otte847a50f2010-06-21 22:57:05 +00001407 QETH_CARD_TEXT(card, 4, "addmc");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001408
1409 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1410 if (!tmp)
1411 return;
1412
Sachin Santf3aa3132010-11-26 02:41:17 +00001413 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1414 im4 = rcu_dereference(im4->next_rcu)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001415 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf);
1416
1417 tmp->u.a4.addr = im4->multiaddr;
1418 memcpy(tmp->mac, buf, sizeof(tmp->mac));
1419
1420 ipm = qeth_l3_ip_from_hash(card, tmp);
1421 if (ipm) {
1422 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1423 } else {
1424 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1425 if (!ipm)
1426 continue;
1427 memcpy(ipm->mac, buf, sizeof(tmp->mac));
1428 ipm->u.a4.addr = im4->multiaddr;
1429 ipm->is_multicast = 1;
1430 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1431 hash_add(card->ip_mc_htable,
1432 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1433 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001434 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001435
1436 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001437}
1438
Jiri Pirko0347af52013-01-03 22:48:58 +00001439/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001440static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1441{
1442 struct in_device *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001443 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001444
Carsten Otte847a50f2010-06-21 22:57:05 +00001445 QETH_CARD_TEXT(card, 4, "addmcvl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001446
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001447 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001448 return;
1449
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001450 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1451 struct net_device *netdev;
1452
dingtianhongf06c7f92014-05-09 14:58:05 +08001453 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001454 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001455 if (netdev == NULL ||
1456 !(netdev->flags & IFF_UP))
1457 continue;
Jiri Pirko0347af52013-01-03 22:48:58 +00001458 in_dev = __in_dev_get_rcu(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001459 if (!in_dev)
1460 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001461 qeth_l3_add_mc_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001462 }
1463}
1464
1465static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1466{
1467 struct in_device *in4_dev;
1468
Carsten Otte847a50f2010-06-21 22:57:05 +00001469 QETH_CARD_TEXT(card, 4, "chkmcv4");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001470
Sachin Santf3aa3132010-11-26 02:41:17 +00001471 rcu_read_lock();
Jiri Pirko0347af52013-01-03 22:48:58 +00001472 in4_dev = __in_dev_get_rcu(card->dev);
1473 if (in4_dev == NULL)
1474 goto unlock;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001475 qeth_l3_add_mc_to_hash(card, in4_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001476 qeth_l3_add_vlan_mc(card);
Jiri Pirko0347af52013-01-03 22:48:58 +00001477unlock:
Sachin Santf3aa3132010-11-26 02:41:17 +00001478 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001479}
1480
1481#ifdef CONFIG_QETH_IPV6
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001482static void
1483qeth_l3_add_mc6_to_hash(struct qeth_card *card, struct inet6_dev *in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001484{
1485 struct qeth_ipaddr *ipm;
1486 struct ifmcaddr6 *im6;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001487 struct qeth_ipaddr *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001488 char buf[MAX_ADDR_LEN];
1489
Carsten Otte847a50f2010-06-21 22:57:05 +00001490 QETH_CARD_TEXT(card, 4, "addmc6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001491
1492 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1493 if (!tmp)
1494 return;
1495
Frank Blaschka4a71df52008-02-15 09:19:42 +01001496 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1497 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001498
1499 memcpy(tmp->mac, buf, sizeof(tmp->mac));
1500 memcpy(&tmp->u.a6.addr, &im6->mca_addr.s6_addr,
1501 sizeof(struct in6_addr));
1502 tmp->is_multicast = 1;
1503
1504 ipm = qeth_l3_ip_from_hash(card, tmp);
1505 if (ipm) {
1506 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1507 continue;
1508 }
1509
Frank Blaschka4a71df52008-02-15 09:19:42 +01001510 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1511 if (!ipm)
1512 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001513
Frank Blaschka4a71df52008-02-15 09:19:42 +01001514 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1515 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1516 sizeof(struct in6_addr));
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001517 ipm->is_multicast = 1;
1518 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1519 hash_add(card->ip_mc_htable,
1520 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1521
Frank Blaschka4a71df52008-02-15 09:19:42 +01001522 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001523 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001524}
1525
Jiri Pirko0347af52013-01-03 22:48:58 +00001526/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001527static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1528{
1529 struct inet6_dev *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001530 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001531
Carsten Otte847a50f2010-06-21 22:57:05 +00001532 QETH_CARD_TEXT(card, 4, "admc6vl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001533
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001534 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001535 return;
1536
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001537 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1538 struct net_device *netdev;
1539
dingtianhongf06c7f92014-05-09 14:58:05 +08001540 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001541 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001542 if (netdev == NULL ||
1543 !(netdev->flags & IFF_UP))
1544 continue;
1545 in_dev = in6_dev_get(netdev);
1546 if (!in_dev)
1547 continue;
1548 read_lock_bh(&in_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001549 qeth_l3_add_mc6_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001550 read_unlock_bh(&in_dev->lock);
1551 in6_dev_put(in_dev);
1552 }
1553}
1554
1555static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1556{
1557 struct inet6_dev *in6_dev;
1558
Carsten Otte847a50f2010-06-21 22:57:05 +00001559 QETH_CARD_TEXT(card, 4, "chkmcv6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001560
Frank Blaschka4a71df52008-02-15 09:19:42 +01001561 if (!qeth_is_supported(card, IPA_IPV6))
1562 return ;
1563 in6_dev = in6_dev_get(card->dev);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001564 if (!in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001565 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001566
Jiri Pirko0347af52013-01-03 22:48:58 +00001567 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001568 read_lock_bh(&in6_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001569 qeth_l3_add_mc6_to_hash(card, in6_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001570 qeth_l3_add_vlan_mc6(card);
1571 read_unlock_bh(&in6_dev->lock);
Jiri Pirko0347af52013-01-03 22:48:58 +00001572 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001573 in6_dev_put(in6_dev);
1574}
1575#endif /* CONFIG_QETH_IPV6 */
1576
1577static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1578 unsigned short vid)
1579{
1580 struct in_device *in_dev;
1581 struct in_ifaddr *ifa;
1582 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001583 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001584
Carsten Otte847a50f2010-06-21 22:57:05 +00001585 QETH_CARD_TEXT(card, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001586
dingtianhongf06c7f92014-05-09 14:58:05 +08001587 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
frank.blaschka@de.ibm.comeabfbe62012-07-24 22:34:29 +00001588 if (!netdev)
1589 return;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001590 in_dev = in_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001591 if (!in_dev)
1592 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001593
1594 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1595 if (!addr)
1596 return;
1597
1598 spin_lock_bh(&card->ip_lock);
1599
Frank Blaschka4a71df52008-02-15 09:19:42 +01001600 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001601 addr->u.a4.addr = ifa->ifa_address;
1602 addr->u.a4.mask = ifa->ifa_mask;
1603 addr->type = QETH_IP_TYPE_NORMAL;
1604 qeth_l3_delete_ip(card, addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001605 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001606
1607 spin_unlock_bh(&card->ip_lock);
1608
1609 kfree(addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001610 in_dev_put(in_dev);
1611}
1612
1613static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1614 unsigned short vid)
1615{
1616#ifdef CONFIG_QETH_IPV6
1617 struct inet6_dev *in6_dev;
1618 struct inet6_ifaddr *ifa;
1619 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001620 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001621
Carsten Otte847a50f2010-06-21 22:57:05 +00001622 QETH_CARD_TEXT(card, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001623
dingtianhongf06c7f92014-05-09 14:58:05 +08001624 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
frank.blaschka@de.ibm.comeabfbe62012-07-24 22:34:29 +00001625 if (!netdev)
1626 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001627
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001628 in6_dev = in6_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001629 if (!in6_dev)
1630 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001631
1632 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1633 if (!addr)
1634 return;
1635
1636 spin_lock_bh(&card->ip_lock);
1637
Frank Blaschka70f60a22010-03-22 09:59:48 -07001638 list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001639 memcpy(&addr->u.a6.addr, &ifa->addr,
1640 sizeof(struct in6_addr));
1641 addr->u.a6.pfxlen = ifa->prefix_len;
1642 addr->type = QETH_IP_TYPE_NORMAL;
1643 qeth_l3_delete_ip(card, addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001644 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001645
1646 spin_unlock_bh(&card->ip_lock);
1647
1648 kfree(addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001649 in6_dev_put(in6_dev);
1650#endif /* CONFIG_QETH_IPV6 */
1651}
1652
1653static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1654 unsigned short vid)
1655{
Jiri Pirko0347af52013-01-03 22:48:58 +00001656 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001657 qeth_l3_free_vlan_addresses4(card, vid);
1658 qeth_l3_free_vlan_addresses6(card, vid);
Jiri Pirko0347af52013-01-03 22:48:58 +00001659 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001660}
1661
Patrick McHardy80d5c362013-04-19 02:04:28 +00001662static int qeth_l3_vlan_rx_add_vid(struct net_device *dev,
1663 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001664{
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001665 struct qeth_card *card = dev->ml_priv;
1666
1667 set_bit(vid, card->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001668 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001669}
1670
Patrick McHardy80d5c362013-04-19 02:04:28 +00001671static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev,
1672 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001673{
Heiko Carstens509e2562008-07-26 02:24:10 -07001674 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001675
Carsten Otte847a50f2010-06-21 22:57:05 +00001676 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001677
Ursula Braun8e98ac42009-03-24 20:57:18 +00001678 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001679 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -05001680 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +00001681 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001682 /* unregister IP addresses of vlan device */
1683 qeth_l3_free_vlan_addresses(card, vid);
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001684 clear_bit(vid, card->active_vlans);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001685 qeth_l3_set_multicast_list(card->dev);
Jiri Pirko8e586132011-12-08 19:52:37 -05001686 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001687}
1688
Ursula Braun10651db2010-10-01 02:51:13 +00001689static inline int qeth_l3_rebuild_skb(struct qeth_card *card,
1690 struct sk_buff *skb, struct qeth_hdr *hdr,
1691 unsigned short *vlan_id)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001692{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001693 __be16 prot;
1694 struct iphdr *ip_hdr;
1695 unsigned char tg_addr[MAX_ADDR_LEN];
Ursula Braun10651db2010-10-01 02:51:13 +00001696 int is_vlan = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001697
1698 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1699 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
1700 ETH_P_IP);
1701 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1702 case QETH_CAST_MULTICAST:
1703 switch (prot) {
1704#ifdef CONFIG_QETH_IPV6
1705 case __constant_htons(ETH_P_IPV6):
1706 ndisc_mc_map((struct in6_addr *)
1707 skb->data + 24,
1708 tg_addr, card->dev, 0);
1709 break;
1710#endif
1711 case __constant_htons(ETH_P_IP):
1712 ip_hdr = (struct iphdr *)skb->data;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001713 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1714 break;
1715 default:
1716 memcpy(tg_addr, card->dev->broadcast,
1717 card->dev->addr_len);
1718 }
1719 card->stats.multicast++;
1720 skb->pkt_type = PACKET_MULTICAST;
1721 break;
1722 case QETH_CAST_BROADCAST:
1723 memcpy(tg_addr, card->dev->broadcast,
1724 card->dev->addr_len);
1725 card->stats.multicast++;
1726 skb->pkt_type = PACKET_BROADCAST;
1727 break;
1728 case QETH_CAST_UNICAST:
1729 case QETH_CAST_ANYCAST:
1730 case QETH_CAST_NOCAST:
1731 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00001732 if (card->options.sniffer)
1733 skb->pkt_type = PACKET_OTHERHOST;
1734 else
1735 skb->pkt_type = PACKET_HOST;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001736 memcpy(tg_addr, card->dev->dev_addr,
1737 card->dev->addr_len);
1738 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001739 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1740 card->dev->header_ops->create(skb, card->dev, prot,
1741 tg_addr, &hdr->hdr.l3.dest_addr[2],
1742 card->dev->addr_len);
1743 else
1744 card->dev->header_ops->create(skb, card->dev, prot,
1745 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001746 }
1747
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001748 skb->protocol = eth_type_trans(skb, card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001749
1750 if (hdr->hdr.l3.ext_flags &
1751 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
Ursula Braun10651db2010-10-01 02:51:13 +00001752 *vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
Frank Blaschka4a71df52008-02-15 09:19:42 +01001753 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
Ursula Braun10651db2010-10-01 02:51:13 +00001754 is_vlan = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001755 }
1756
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001757 if (card->dev->features & NETIF_F_RXCSUM) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001758 if ((hdr->hdr.l3.ext_flags &
Ursula Braunb9139802009-05-19 21:38:40 +00001759 (QETH_HDR_EXT_CSUM_HDR_REQ |
1760 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1761 (QETH_HDR_EXT_CSUM_HDR_REQ |
1762 QETH_HDR_EXT_CSUM_TRANSP_REQ))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001763 skb->ip_summed = CHECKSUM_UNNECESSARY;
1764 else
Ursula Braunb9139802009-05-19 21:38:40 +00001765 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001766 } else
1767 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun10651db2010-10-01 02:51:13 +00001768 return is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001769}
1770
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001771static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1772 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001773{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001774 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001775 struct sk_buff *skb;
1776 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001777 __u16 vlan_tag = 0;
Ursula Braun10651db2010-10-01 02:51:13 +00001778 int is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001779 unsigned int len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001780 __u16 magic;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001781
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001782 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +00001783 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001784 while (budget) {
1785 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +00001786 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001787 &card->rx.b_element, &card->rx.e_offset, &hdr);
1788 if (!skb) {
1789 *done = 1;
1790 break;
1791 }
1792 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001793 switch (hdr->hdr.l3.id) {
1794 case QETH_HEADER_TYPE_LAYER3:
Frank Blaschkab3332932011-08-08 01:33:59 +00001795 magic = *(__u16 *)skb->data;
1796 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
1797 (magic == ETH_P_AF_IUCV)) {
1798 skb->protocol = ETH_P_AF_IUCV;
1799 skb->pkt_type = PACKET_HOST;
1800 skb->mac_header = NET_SKB_PAD;
1801 skb->dev = card->dev;
1802 len = skb->len;
1803 card->dev->header_ops->create(skb, card->dev, 0,
1804 card->dev->dev_addr, "FAKELL",
1805 card->dev->addr_len);
1806 netif_receive_skb(skb);
1807 } else {
1808 is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
Ursula Braun10651db2010-10-01 02:51:13 +00001809 &vlan_tag);
Frank Blaschkab3332932011-08-08 01:33:59 +00001810 len = skb->len;
1811 if (is_vlan && !card->options.sniffer)
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001812 __vlan_hwaccel_put_tag(skb,
1813 htons(ETH_P_8021Q), vlan_tag);
Frank Blaschkab3332932011-08-08 01:33:59 +00001814 napi_gro_receive(&card->napi, skb);
1815 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001816 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00001817 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
1818 skb->pkt_type = PACKET_HOST;
1819 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00001820 len = skb->len;
1821 netif_receive_skb(skb);
1822 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001823 default:
1824 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00001825 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001826 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001827 continue;
1828 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001829 work_done++;
1830 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001831 card->stats.rx_packets++;
1832 card->stats.rx_bytes += len;
1833 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001834 return work_done;
1835}
1836
1837static int qeth_l3_poll(struct napi_struct *napi, int budget)
1838{
1839 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
1840 int work_done = 0;
1841 struct qeth_qdio_buffer *buffer;
1842 int done;
1843 int new_budget = budget;
1844
1845 if (card->options.performance_stats) {
1846 card->perf_stats.inbound_cnt++;
1847 card->perf_stats.inbound_start_time = qeth_get_micros();
1848 }
1849
1850 while (1) {
1851 if (!card->rx.b_count) {
1852 card->rx.qdio_err = 0;
1853 card->rx.b_count = qdio_get_next_buffers(
1854 card->data.ccwdev, 0, &card->rx.b_index,
1855 &card->rx.qdio_err);
1856 if (card->rx.b_count <= 0) {
1857 card->rx.b_count = 0;
1858 break;
1859 }
1860 card->rx.b_element =
1861 &card->qdio.in_q->bufs[card->rx.b_index]
1862 .buffer->element[0];
1863 card->rx.e_offset = 0;
1864 }
1865
1866 while (card->rx.b_count) {
1867 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
1868 if (!(card->rx.qdio_err &&
1869 qeth_check_qdio_errors(card, buffer->buffer,
1870 card->rx.qdio_err, "qinerr")))
1871 work_done += qeth_l3_process_inbound_buffer(
1872 card, new_budget, &done);
1873 else
1874 done = 1;
1875
1876 if (done) {
1877 if (card->options.performance_stats)
1878 card->perf_stats.bufs_rec++;
1879 qeth_put_buffer_pool_entry(card,
1880 buffer->pool_entry);
1881 qeth_queue_input_buffer(card, card->rx.b_index);
1882 card->rx.b_count--;
1883 if (card->rx.b_count) {
1884 card->rx.b_index =
1885 (card->rx.b_index + 1) %
1886 QDIO_MAX_BUFFERS_PER_Q;
1887 card->rx.b_element =
1888 &card->qdio.in_q
1889 ->bufs[card->rx.b_index]
1890 .buffer->element[0];
1891 card->rx.e_offset = 0;
1892 }
1893 }
1894
1895 if (work_done >= budget)
1896 goto out;
1897 else
1898 new_budget = budget - work_done;
1899 }
1900 }
1901
1902 napi_complete(napi);
1903 if (qdio_start_irq(card->data.ccwdev, 0))
1904 napi_schedule(&card->napi);
1905out:
1906 if (card->options.performance_stats)
1907 card->perf_stats.inbound_time += qeth_get_micros() -
1908 card->perf_stats.inbound_start_time;
1909 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001910}
1911
1912static int qeth_l3_verify_vlan_dev(struct net_device *dev,
1913 struct qeth_card *card)
1914{
1915 int rc = 0;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001916 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001917
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001918 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1919 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001920
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001921 rcu_read_lock();
dingtianhongf06c7f92014-05-09 14:58:05 +08001922 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001923 vid);
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001924 rcu_read_unlock();
1925 if (netdev == dev) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001926 rc = QETH_VLAN_CARD;
1927 break;
1928 }
1929 }
1930
Heiko Carstens509e2562008-07-26 02:24:10 -07001931 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001932 return 0;
1933
1934 return rc;
1935}
1936
1937static int qeth_l3_verify_dev(struct net_device *dev)
1938{
1939 struct qeth_card *card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001940 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001941 unsigned long flags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001942
1943 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
1944 list_for_each_entry(card, &qeth_core_card_list.list, list) {
1945 if (card->dev == dev) {
1946 rc = QETH_REAL_CARD;
1947 break;
1948 }
1949 rc = qeth_l3_verify_vlan_dev(dev, card);
1950 if (rc)
1951 break;
1952 }
1953 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
1954
1955 return rc;
1956}
1957
1958static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
1959{
1960 struct qeth_card *card = NULL;
1961 int rc;
1962
1963 rc = qeth_l3_verify_dev(dev);
1964 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07001965 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001966 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07001967 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02001968 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001969 card = NULL;
Carsten Otte847a50f2010-06-21 22:57:05 +00001970 if (card)
1971 QETH_CARD_TEXT_(card, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001972 return card ;
1973}
1974
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +02001975static void qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001976{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001977 QETH_DBF_TEXT(SETUP, 2, "stopcard");
1978 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001979
1980 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00001981 if (card->options.sniffer &&
1982 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
1983 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001984 if (card->read.state == CH_STATE_UP &&
1985 card->write.state == CH_STATE_UP &&
1986 (card->state == CARD_STATE_UP)) {
1987 if (recovery_mode)
1988 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02001989 else {
Ursula Braun869da902010-03-08 20:36:56 +00001990 rtnl_lock();
1991 dev_close(card->dev);
1992 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02001993 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001994 card->state = CARD_STATE_SOFTSETUP;
1995 }
1996 if (card->state == CARD_STATE_SOFTSETUP) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001997 qeth_l3_clear_ip_htable(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001998 qeth_clear_ipacmd_list(card);
1999 card->state = CARD_STATE_HARDSETUP;
2000 }
2001 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002002 qeth_qdio_clear_card(card, 0);
2003 qeth_clear_qdio_buffers(card);
2004 qeth_clear_working_pool_list(card);
2005 card->state = CARD_STATE_DOWN;
2006 }
2007 if (card->state == CARD_STATE_DOWN) {
2008 qeth_clear_cmd_buffers(&card->read);
2009 qeth_clear_cmd_buffers(&card->write);
2010 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002011}
2012
Ursula Braun76b11f82010-01-11 02:50:50 +00002013/*
2014 * test for and Switch promiscuous mode (on or off)
2015 * either for guestlan or HiperSocket Sniffer
2016 */
2017static void
2018qeth_l3_handle_promisc_mode(struct qeth_card *card)
2019{
2020 struct net_device *dev = card->dev;
2021
2022 if (((dev->flags & IFF_PROMISC) &&
2023 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
2024 (!(dev->flags & IFF_PROMISC) &&
2025 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
2026 return;
2027
2028 if (card->info.guestlan) { /* Guestlan trace */
2029 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2030 qeth_setadp_promisc_mode(card);
2031 } else if (card->options.sniffer && /* HiperSockets trace */
2032 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
2033 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002034 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002035 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
2036 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00002037 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002038 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2039 }
2040 }
2041}
2042
Frank Blaschka4a71df52008-02-15 09:19:42 +01002043static void qeth_l3_set_multicast_list(struct net_device *dev)
2044{
Heiko Carstens509e2562008-07-26 02:24:10 -07002045 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002046
Carsten Otte847a50f2010-06-21 22:57:05 +00002047 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00002048 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
2049 (card->state != CARD_STATE_UP))
2050 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00002051 if (!card->options.sniffer) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002052
2053 spin_lock_bh(&card->mclock);
2054
2055 qeth_l3_mark_all_mc_to_be_deleted(card);
2056
Ursula Braun76b11f82010-01-11 02:50:50 +00002057 qeth_l3_add_multicast_ipv4(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002058#ifdef CONFIG_QETH_IPV6
Ursula Braun76b11f82010-01-11 02:50:50 +00002059 qeth_l3_add_multicast_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002060#endif
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002061 qeth_l3_delete_nonused_mc(card);
2062 qeth_l3_add_all_new_mc(card);
2063
2064 spin_unlock_bh(&card->mclock);
2065
Ursula Braun76b11f82010-01-11 02:50:50 +00002066 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2067 return;
2068 }
2069 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002070}
2071
2072static const char *qeth_l3_arp_get_error_cause(int *rc)
2073{
2074 switch (*rc) {
2075 case QETH_IPA_ARP_RC_FAILED:
2076 *rc = -EIO;
2077 return "operation failed";
2078 case QETH_IPA_ARP_RC_NOTSUPP:
2079 *rc = -EOPNOTSUPP;
2080 return "operation not supported";
2081 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2082 *rc = -EINVAL;
2083 return "argument out of range";
2084 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2085 *rc = -EOPNOTSUPP;
2086 return "query operation not supported";
2087 case QETH_IPA_ARP_RC_Q_NO_DATA:
2088 *rc = -ENOENT;
2089 return "no query data available";
2090 default:
2091 return "unknown error";
2092 }
2093}
2094
2095static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2096{
2097 int tmp;
2098 int rc;
2099
Carsten Otte847a50f2010-06-21 22:57:05 +00002100 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002101
2102 /*
2103 * currently GuestLAN only supports the ARP assist function
2104 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2105 * thus we say EOPNOTSUPP for this ARP function
2106 */
2107 if (card->info.guestlan)
2108 return -EOPNOTSUPP;
2109 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002110 return -EOPNOTSUPP;
2111 }
Thomas Richter4d7def22015-09-18 16:06:51 +02002112 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002113 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2114 no_entries);
2115 if (rc) {
2116 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002117 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2118 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002119 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2120 }
2121 return rc;
2122}
2123
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002124static __u32 get_arp_entry_size(struct qeth_card *card,
2125 struct qeth_arp_query_data *qdata,
2126 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002127{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002128 __u32 rc;
2129 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002130
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002131 is_hsi = qdata->reply_bits == 5;
2132 if (type->ip == QETHARP_IP_ADDR_V4) {
2133 QETH_CARD_TEXT(card, 4, "arpev4");
2134 if (strip_entries) {
2135 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
2136 sizeof(struct qeth_arp_qi_entry7_short);
2137 } else {
2138 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
2139 sizeof(struct qeth_arp_qi_entry7);
2140 }
2141 } else if (type->ip == QETHARP_IP_ADDR_V6) {
2142 QETH_CARD_TEXT(card, 4, "arpev6");
2143 if (strip_entries) {
2144 rc = is_hsi ?
2145 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
2146 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
2147 } else {
2148 rc = is_hsi ?
2149 sizeof(struct qeth_arp_qi_entry5_ipv6) :
2150 sizeof(struct qeth_arp_qi_entry7_ipv6);
2151 }
2152 } else {
2153 QETH_CARD_TEXT(card, 4, "arpinv");
2154 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002155 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002156
2157 return rc;
2158}
2159
2160static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
2161{
2162 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
2163 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002164}
2165
2166static int qeth_l3_arp_query_cb(struct qeth_card *card,
2167 struct qeth_reply *reply, unsigned long data)
2168{
2169 struct qeth_ipa_cmd *cmd;
2170 struct qeth_arp_query_data *qdata;
2171 struct qeth_arp_query_info *qinfo;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002172 int i;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002173 int e;
2174 int entrybytes_done;
2175 int stripped_bytes;
2176 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002177
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002178 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002179
2180 qinfo = (struct qeth_arp_query_info *) reply->param;
2181 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002182 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002183 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002184 QETH_CARD_TEXT(card, 4, "arpcberr");
2185 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002186 return 0;
2187 }
2188 if (cmd->data.setassparms.hdr.return_code) {
2189 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002190 QETH_CARD_TEXT(card, 4, "setaperr");
2191 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002192 return 0;
2193 }
2194 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00002195 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002196
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002197 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
2198 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
2199 entrybytes_done = 0;
2200 for (e = 0; e < qdata->no_entries; ++e) {
2201 char *cur_entry;
2202 __u32 esize;
2203 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002204
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002205 cur_entry = &qdata->data + entrybytes_done;
2206 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
2207 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
2208 QETH_CARD_TEXT(card, 4, "pmis");
2209 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
2210 break;
2211 }
2212 esize = get_arp_entry_size(card, qdata, etype,
2213 do_strip_entries);
2214 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
2215 if (!esize)
2216 break;
2217
2218 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
2219 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
Ursula Braune0a81142012-03-07 02:06:28 +00002220 cmd->hdr.return_code = IPA_RC_ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002221 goto out_error;
2222 }
2223
2224 memcpy(qinfo->udata + qinfo->udata_offset,
2225 &qdata->data + entrybytes_done + stripped_bytes,
2226 esize);
2227 entrybytes_done += esize + stripped_bytes;
2228 qinfo->udata_offset += esize;
2229 ++qinfo->no_entries;
2230 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002231 /* check if all replies received ... */
2232 if (cmd->data.setassparms.hdr.seq_no <
2233 cmd->data.setassparms.hdr.number_of_replies)
2234 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002235 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002236 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2237 /* keep STRIP_ENTRIES flag so the user program can distinguish
2238 * stripped entries from normal ones */
2239 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2240 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2241 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002242 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002243 return 0;
2244out_error:
2245 i = 0;
2246 memcpy(qinfo->udata, &i, 4);
2247 return 0;
2248}
2249
2250static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2251 struct qeth_cmd_buffer *iob, int len,
2252 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2253 unsigned long),
2254 void *reply_param)
2255{
Carsten Otte847a50f2010-06-21 22:57:05 +00002256 QETH_CARD_TEXT(card, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002257
2258 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2259 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2260 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2261 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2262 reply_cb, reply_param);
2263}
2264
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002265static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
2266 enum qeth_prot_versions prot,
2267 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002268{
2269 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002270 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002271 int tmp;
2272 int rc;
2273
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002274 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
2275
Thomas Richterb475e312015-12-11 12:27:54 +01002276 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2277 IPA_CMD_ASS_ARP_QUERY_INFO,
2278 sizeof(struct qeth_arp_query_data)
2279 - sizeof(char),
2280 prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002281 if (!iob)
2282 return -ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002283 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2284 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
2285 cmd->data.setassparms.data.query_arp.reply_bits = 0;
2286 cmd->data.setassparms.data.query_arp.no_entries = 0;
2287 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2288 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2289 qeth_l3_arp_query_cb, (void *)qinfo);
2290 if (rc) {
2291 tmp = rc;
2292 QETH_DBF_MESSAGE(2,
2293 "Error while querying ARP cache on %s: %s "
2294 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2295 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2296 }
2297
2298 return rc;
2299}
2300
2301static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2302{
2303 struct qeth_arp_query_info qinfo = {0, };
2304 int rc;
2305
Carsten Otte847a50f2010-06-21 22:57:05 +00002306 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002307
2308 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2309 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002310 QETH_CARD_TEXT(card, 3, "arpqnsup");
2311 rc = -EOPNOTSUPP;
2312 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002313 }
2314 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002315 if (copy_from_user(&qinfo, udata, 6)) {
2316 rc = -EFAULT;
2317 goto out;
2318 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002319 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002320 if (!qinfo.udata) {
2321 rc = -ENOMEM;
2322 goto out;
2323 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002324 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002325 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002326 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002327 if (copy_to_user(udata, qinfo.udata, 4))
2328 rc = -EFAULT;
Sebastian Ott77a83ed2016-06-16 16:19:03 +02002329 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002330 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02002331#ifdef CONFIG_QETH_IPV6
2332 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
2333 /* fails in case of GuestLAN QDIO mode */
2334 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6, &qinfo);
2335 }
2336#endif
2337 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
2338 QETH_CARD_TEXT(card, 4, "qactf");
2339 rc = -EFAULT;
2340 goto free_and_out;
2341 }
2342 QETH_CARD_TEXT(card, 4, "qacts");
2343
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002344free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002345 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002346out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002347 return rc;
2348}
2349
2350static int qeth_l3_arp_add_entry(struct qeth_card *card,
2351 struct qeth_arp_cache_entry *entry)
2352{
2353 struct qeth_cmd_buffer *iob;
2354 char buf[16];
2355 int tmp;
2356 int rc;
2357
Carsten Otte847a50f2010-06-21 22:57:05 +00002358 QETH_CARD_TEXT(card, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002359
2360 /*
2361 * currently GuestLAN only supports the ARP assist function
2362 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2363 * thus we say EOPNOTSUPP for this ARP function
2364 */
2365 if (card->info.guestlan)
2366 return -EOPNOTSUPP;
2367 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002368 return -EOPNOTSUPP;
2369 }
2370
Thomas Richterb475e312015-12-11 12:27:54 +01002371 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002372 IPA_CMD_ASS_ARP_ADD_ENTRY,
2373 sizeof(struct qeth_arp_cache_entry),
2374 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002375 if (!iob)
2376 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +02002377 rc = qeth_send_setassparms(card, iob,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002378 sizeof(struct qeth_arp_cache_entry),
2379 (unsigned long) entry,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002380 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002381 if (rc) {
2382 tmp = rc;
2383 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002384 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2385 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2386 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002387 }
2388 return rc;
2389}
2390
2391static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2392 struct qeth_arp_cache_entry *entry)
2393{
2394 struct qeth_cmd_buffer *iob;
2395 char buf[16] = {0, };
2396 int tmp;
2397 int rc;
2398
Carsten Otte847a50f2010-06-21 22:57:05 +00002399 QETH_CARD_TEXT(card, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002400
2401 /*
2402 * currently GuestLAN only supports the ARP assist function
2403 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2404 * thus we say EOPNOTSUPP for this ARP function
2405 */
2406 if (card->info.guestlan)
2407 return -EOPNOTSUPP;
2408 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002409 return -EOPNOTSUPP;
2410 }
2411 memcpy(buf, entry, 12);
Thomas Richterb475e312015-12-11 12:27:54 +01002412 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002413 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2414 12,
2415 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002416 if (!iob)
2417 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +02002418 rc = qeth_send_setassparms(card, iob,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002419 12, (unsigned long)buf,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002420 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002421 if (rc) {
2422 tmp = rc;
2423 memset(buf, 0, 16);
2424 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002425 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2426 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2427 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002428 }
2429 return rc;
2430}
2431
2432static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2433{
2434 int rc;
2435 int tmp;
2436
Carsten Otte847a50f2010-06-21 22:57:05 +00002437 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002438
2439 /*
2440 * currently GuestLAN only supports the ARP assist function
2441 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2442 * thus we say EOPNOTSUPP for this ARP function
2443 */
2444 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2445 return -EOPNOTSUPP;
2446 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002447 return -EOPNOTSUPP;
2448 }
Thomas Richter4d7def22015-09-18 16:06:51 +02002449 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002450 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2451 if (rc) {
2452 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002453 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2454 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002455 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2456 }
2457 return rc;
2458}
2459
2460static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2461{
Heiko Carstens509e2562008-07-26 02:24:10 -07002462 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002463 struct qeth_arp_cache_entry arp_entry;
2464 struct mii_ioctl_data *mii_data;
2465 int rc = 0;
2466
2467 if (!card)
2468 return -ENODEV;
2469
Eugene Crosserc3521252015-01-16 14:05:47 +01002470 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002471 return -ENODEV;
2472
2473 switch (cmd) {
2474 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2475 if (!capable(CAP_NET_ADMIN)) {
2476 rc = -EPERM;
2477 break;
2478 }
2479 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2480 break;
2481 case SIOC_QETH_ARP_QUERY_INFO:
2482 if (!capable(CAP_NET_ADMIN)) {
2483 rc = -EPERM;
2484 break;
2485 }
2486 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2487 break;
2488 case SIOC_QETH_ARP_ADD_ENTRY:
2489 if (!capable(CAP_NET_ADMIN)) {
2490 rc = -EPERM;
2491 break;
2492 }
2493 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2494 sizeof(struct qeth_arp_cache_entry)))
2495 rc = -EFAULT;
2496 else
2497 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2498 break;
2499 case SIOC_QETH_ARP_REMOVE_ENTRY:
2500 if (!capable(CAP_NET_ADMIN)) {
2501 rc = -EPERM;
2502 break;
2503 }
2504 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2505 sizeof(struct qeth_arp_cache_entry)))
2506 rc = -EFAULT;
2507 else
2508 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2509 break;
2510 case SIOC_QETH_ARP_FLUSH_CACHE:
2511 if (!capable(CAP_NET_ADMIN)) {
2512 rc = -EPERM;
2513 break;
2514 }
2515 rc = qeth_l3_arp_flush_cache(card);
2516 break;
2517 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2518 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2519 break;
2520 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +00002521 if ((card->info.type == QETH_CARD_TYPE_OSD ||
2522 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01002523 !card->info.guestlan)
2524 return 1;
2525 return 0;
2526 break;
2527 case SIOCGMIIPHY:
2528 mii_data = if_mii(rq);
2529 mii_data->phy_id = 0;
2530 break;
2531 case SIOCGMIIREG:
2532 mii_data = if_mii(rq);
2533 if (mii_data->phy_id != 0)
2534 rc = -EINVAL;
2535 else
2536 mii_data->val_out = qeth_mdio_read(dev,
2537 mii_data->phy_id,
2538 mii_data->reg_num);
2539 break;
Frank Blaschkac3ab96f2012-02-08 00:19:49 +00002540 case SIOC_QETH_QUERY_OAT:
2541 rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data);
2542 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002543 default:
2544 rc = -EOPNOTSUPP;
2545 }
2546 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00002547 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002548 return rc;
2549}
2550
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002551int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2552{
2553 int cast_type = RTN_UNSPEC;
David S. Miller69cce1d2011-07-17 23:09:49 -07002554 struct neighbour *n = NULL;
2555 struct dst_entry *dst;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002556
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002557 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002558 dst = skb_dst(skb);
2559 if (dst)
David S. Miller24db1ba2012-07-02 22:02:33 -07002560 n = dst_neigh_lookup_skb(dst, skb);
David S. Miller69cce1d2011-07-17 23:09:49 -07002561 if (n) {
2562 cast_type = n->type;
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002563 rcu_read_unlock();
David S. Miller24db1ba2012-07-02 22:02:33 -07002564 neigh_release(n);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002565 if ((cast_type == RTN_BROADCAST) ||
2566 (cast_type == RTN_MULTICAST) ||
2567 (cast_type == RTN_ANYCAST))
2568 return cast_type;
2569 else
2570 return RTN_UNSPEC;
2571 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002572 rcu_read_unlock();
2573
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002574 /* try something else */
2575 if (skb->protocol == ETH_P_IPV6)
2576 return (skb_network_header(skb)[24] == 0xff) ?
2577 RTN_MULTICAST : 0;
2578 else if (skb->protocol == ETH_P_IP)
2579 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2580 RTN_MULTICAST : 0;
2581 /* ... */
2582 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2583 return RTN_BROADCAST;
2584 else {
2585 u16 hdr_mac;
2586
2587 hdr_mac = *((u16 *)skb->data);
2588 /* tr multicast? */
2589 switch (card->info.link_type) {
2590 case QETH_LINK_TYPE_HSTR:
2591 case QETH_LINK_TYPE_LANE_TR:
2592 if ((hdr_mac == QETH_TR_MAC_NC) ||
2593 (hdr_mac == QETH_TR_MAC_C))
2594 return RTN_MULTICAST;
2595 break;
2596 /* eth or so multicast? */
2597 default:
2598 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2599 (hdr_mac == QETH_ETH_MAC_V6))
2600 return RTN_MULTICAST;
2601 }
2602 }
2603 return cast_type;
2604}
2605
Frank Blaschkab3332932011-08-08 01:33:59 +00002606static void qeth_l3_fill_af_iucv_hdr(struct qeth_card *card,
2607 struct qeth_hdr *hdr, struct sk_buff *skb)
2608{
2609 char daddr[16];
2610 struct af_iucv_trans_hdr *iucv_hdr;
2611
2612 skb_pull(skb, 14);
2613 card->dev->header_ops->create(skb, card->dev, 0,
2614 card->dev->dev_addr, card->dev->dev_addr,
2615 card->dev->addr_len);
2616 skb_pull(skb, 14);
2617 iucv_hdr = (struct af_iucv_trans_hdr *)skb->data;
2618 memset(hdr, 0, sizeof(struct qeth_hdr));
2619 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2620 hdr->hdr.l3.ext_flags = 0;
2621 hdr->hdr.l3.length = skb->len;
2622 hdr->hdr.l3.flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
2623 memset(daddr, 0, sizeof(daddr));
2624 daddr[0] = 0xfe;
2625 daddr[1] = 0x80;
2626 memcpy(&daddr[8], iucv_hdr->destUserID, 8);
2627 memcpy(hdr->hdr.l3.dest_addr, daddr, 16);
2628}
2629
Frank Blaschka4a71df52008-02-15 09:19:42 +01002630static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2631 struct sk_buff *skb, int ipv, int cast_type)
2632{
David S. Miller69cce1d2011-07-17 23:09:49 -07002633 struct dst_entry *dst;
2634
Frank Blaschka4a71df52008-02-15 09:19:42 +01002635 memset(hdr, 0, sizeof(struct qeth_hdr));
2636 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2637 hdr->hdr.l3.ext_flags = 0;
2638
2639 /*
2640 * before we're going to overwrite this location with next hop ip.
2641 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2642 */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002643 if (skb_vlan_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002644 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2645 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2646 else
2647 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002648 hdr->hdr.l3.vlan_id = skb_vlan_tag_get(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002649 }
2650
2651 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002652
2653 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002654 dst = skb_dst(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002655 if (ipv == 4) {
David Miller87e75972012-02-01 10:49:17 +00002656 struct rtable *rt = (struct rtable *) dst;
2657 __be32 *pkey = &ip_hdr(skb)->daddr;
2658
2659 if (rt->rt_gateway)
2660 pkey = &rt->rt_gateway;
2661
Frank Blaschka4a71df52008-02-15 09:19:42 +01002662 /* IPv4 */
2663 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2664 memset(hdr->hdr.l3.dest_addr, 0, 12);
David Miller87e75972012-02-01 10:49:17 +00002665 *((__be32 *) (&hdr->hdr.l3.dest_addr[12])) = *pkey;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002666 } else if (ipv == 6) {
David Miller87e75972012-02-01 10:49:17 +00002667 struct rt6_info *rt = (struct rt6_info *) dst;
2668 struct in6_addr *pkey = &ipv6_hdr(skb)->daddr;
2669
2670 if (!ipv6_addr_any(&rt->rt6i_gateway))
2671 pkey = &rt->rt6i_gateway;
2672
Frank Blaschka4a71df52008-02-15 09:19:42 +01002673 /* IPv6 */
2674 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2675 if (card->info.type == QETH_CARD_TYPE_IQD)
2676 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
David Miller87e75972012-02-01 10:49:17 +00002677 memcpy(hdr->hdr.l3.dest_addr, pkey, 16);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002678 } else {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002679 if (!memcmp(skb->data + sizeof(struct qeth_hdr),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002680 skb->dev->broadcast, 6)) {
2681 /* broadcast? */
2682 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2683 QETH_HDR_PASSTHRU;
2684 } else {
2685 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2686 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2687 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2688 }
2689 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002690 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002691}
2692
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002693static inline void qeth_l3_hdr_csum(struct qeth_card *card,
2694 struct qeth_hdr *hdr, struct sk_buff *skb)
2695{
2696 struct iphdr *iph = ip_hdr(skb);
2697
2698 /* tcph->check contains already the pseudo hdr checksum
2699 * so just set the header flags
2700 */
2701 if (iph->protocol == IPPROTO_UDP)
2702 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
Frank Blaschka16c0f932011-01-12 20:42:25 +00002703 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
2704 QETH_HDR_EXT_CSUM_HDR_REQ;
2705 iph->check = 0;
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002706 if (card->options.performance_stats)
2707 card->perf_stats.tx_csum++;
2708}
2709
Frank Blaschka64ef8952009-03-24 20:57:16 +00002710static void qeth_tso_fill_header(struct qeth_card *card,
2711 struct qeth_hdr *qhdr, struct sk_buff *skb)
2712{
2713 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2714 struct tcphdr *tcph = tcp_hdr(skb);
2715 struct iphdr *iph = ip_hdr(skb);
2716 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2717
2718 /*fix header to TSO values ...*/
2719 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
Frank Blaschka8fa92082010-11-26 02:41:20 +00002720 hdr->hdr.hdr.l3.length = skb->len - sizeof(struct qeth_hdr_tso);
Frank Blaschka64ef8952009-03-24 20:57:16 +00002721 /*set values which are fix for the first approach ...*/
2722 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2723 hdr->ext.imb_hdr_no = 1;
2724 hdr->ext.hdr_type = 1;
2725 hdr->ext.hdr_version = 1;
2726 hdr->ext.hdr_len = 28;
2727 /*insert non-fix values */
2728 hdr->ext.mss = skb_shinfo(skb)->gso_size;
2729 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
2730 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2731 sizeof(struct qeth_hdr_tso));
2732 tcph->check = 0;
2733 if (skb->protocol == ETH_P_IPV6) {
2734 ip6h->payload_len = 0;
2735 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2736 0, IPPROTO_TCP, 0);
2737 } else {
2738 /*OSA want us to set these values ...*/
2739 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2740 0, IPPROTO_TCP, 0);
2741 iph->tot_len = 0;
2742 iph->check = 0;
2743 }
2744}
2745
Eugene Crosser2863c612016-06-16 16:18:52 +02002746/**
Eugene Crosser41aeed52016-06-16 16:18:53 +02002747 * qeth_l3_get_elements_no_tso() - find number of SBALEs for skb data for tso
2748 * @card: qeth card structure, to check max. elems.
2749 * @skb: SKB address
2750 * @extra_elems: extra elems needed, to check against max.
Eugene Crosser2863c612016-06-16 16:18:52 +02002751 *
2752 * Returns the number of pages, and thus QDIO buffer elements, needed to cover
2753 * skb data, including linear part and fragments, but excluding TCP header.
2754 * (Exclusion of TCP header distinguishes it from qeth_get_elements_no().)
2755 * Checks if the result plus extra_elems fits under the limit for the card.
2756 * Returns 0 if it does not.
2757 * Note: extra_elems is not included in the returned result.
2758 */
Eugene Crosser41aeed52016-06-16 16:18:53 +02002759static int qeth_l3_get_elements_no_tso(struct qeth_card *card,
Eugene Crosser2863c612016-06-16 16:18:52 +02002760 struct sk_buff *skb, int extra_elems)
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002761{
Eugene Crosser2863c612016-06-16 16:18:52 +02002762 addr_t tcpdptr = (addr_t)tcp_hdr(skb) + tcp_hdrlen(skb);
2763 int elements = qeth_get_elements_for_range(
2764 tcpdptr,
2765 (addr_t)skb->data + skb_headlen(skb)) +
Thomas Richter8f43fb02016-06-16 16:18:59 +02002766 qeth_get_elements_for_frags(skb);
Frank Blaschka271648b2013-03-18 20:04:44 +00002767
Eugene Crosser2863c612016-06-16 16:18:52 +02002768 if ((elements + extra_elems) > QETH_MAX_BUFFER_ELEMENTS(card)) {
2769 QETH_DBF_MESSAGE(2,
2770 "Invalid size of TSO IP packet (Number=%d / Length=%d). Discarded.\n",
2771 elements + extra_elems, skb->len);
2772 return 0;
2773 }
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002774 return elements;
2775}
2776
Frank Blaschka4a71df52008-02-15 09:19:42 +01002777static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2778{
2779 int rc;
2780 u16 *tag;
2781 struct qeth_hdr *hdr = NULL;
Eugene Crosser2863c612016-06-16 16:18:52 +02002782 int hdr_elements = 0;
2783 int elements;
Heiko Carstens509e2562008-07-26 02:24:10 -07002784 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002785 struct sk_buff *new_skb = NULL;
2786 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002787 int cast_type = qeth_l3_get_cast_type(card, skb);
Stefan Raspl290b8342014-04-28 10:05:08 +02002788 struct qeth_qdio_out_q *queue =
2789 card->qdio.out_qs[card->qdio.do_prio_queueing
2790 || (cast_type && card->info.is_multicast_different) ?
2791 qeth_get_priority_queue(card, skb, ipv, cast_type) :
2792 card->qdio.default_out_queue];
Frank Blaschka4a71df52008-02-15 09:19:42 +01002793 int tx_bytes = skb->len;
Eugene Crosser41aeed52016-06-16 16:18:53 +02002794 bool use_tso;
Frank Blaschka683d7182008-08-01 16:39:13 +02002795 int data_offset = -1;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002796 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002797
Frank Blaschkab3332932011-08-08 01:33:59 +00002798 if (((card->info.type == QETH_CARD_TYPE_IQD) &&
2799 (((card->options.cq != QETH_CQ_ENABLED) && !ipv) ||
2800 ((card->options.cq == QETH_CQ_ENABLED) &&
2801 (skb->protocol != ETH_P_AF_IUCV)))) ||
2802 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002803 goto tx_drop;
2804
2805 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2806 card->stats.tx_carrier_errors++;
2807 goto tx_drop;
2808 }
2809
2810 if ((cast_type == RTN_BROADCAST) &&
2811 (card->info.broadcast_capable == 0))
2812 goto tx_drop;
2813
2814 if (card->options.performance_stats) {
2815 card->perf_stats.outbound_cnt++;
2816 card->perf_stats.outbound_start_time = qeth_get_micros();
2817 }
2818
Eugene Crosser41aeed52016-06-16 16:18:53 +02002819 /* Ignore segment size from skb_is_gso(), 1 page is always used. */
2820 use_tso = skb_is_gso(skb) &&
2821 (qeth_get_ip_protocol(skb) == IPPROTO_TCP) && (ipv == 4);
Frank Blaschka683d7182008-08-01 16:39:13 +02002822
Eugene Crosser41aeed52016-06-16 16:18:53 +02002823 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
2824 !skb_is_nonlinear(skb)) {
Frank Blaschka683d7182008-08-01 16:39:13 +02002825 new_skb = skb;
Frank Blaschkab3332932011-08-08 01:33:59 +00002826 if (new_skb->protocol == ETH_P_AF_IUCV)
2827 data_offset = 0;
2828 else
2829 data_offset = ETH_HLEN;
Frank Blaschka683d7182008-08-01 16:39:13 +02002830 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2831 if (!hdr)
2832 goto tx_drop;
Eugene Crosser2863c612016-06-16 16:18:52 +02002833 hdr_elements++;
Frank Blaschka683d7182008-08-01 16:39:13 +02002834 } else {
2835 /* create a clone with writeable headroom */
2836 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
2837 + VLAN_HLEN);
2838 if (!new_skb)
2839 goto tx_drop;
2840 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002841
2842 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02002843 if (data_offset < 0)
2844 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002845 } else {
Frank Blaschka21fde742010-03-08 20:36:54 +00002846 if (ipv == 4) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002847 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002848 }
2849
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002850 if (ipv != 4 && skb_vlan_tag_present(new_skb)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002851 skb_push(new_skb, VLAN_HLEN);
2852 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2853 skb_copy_to_linear_data_offset(new_skb, 4,
2854 new_skb->data + 8, 4);
2855 skb_copy_to_linear_data_offset(new_skb, 8,
2856 new_skb->data + 12, 4);
2857 tag = (u16 *)(new_skb->data + 12);
2858 *tag = __constant_htons(ETH_P_8021Q);
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002859 *(tag + 1) = htons(skb_vlan_tag_get(new_skb));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002860 }
2861 }
2862
2863 netif_stop_queue(dev);
2864
Frank Blaschka4a71df52008-02-15 09:19:42 +01002865 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00002866 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01002867 */
Eugene Crosser41aeed52016-06-16 16:18:53 +02002868 if ((card->info.type != QETH_CARD_TYPE_IQD) &&
2869 ((use_tso && !qeth_l3_get_elements_no_tso(card, new_skb, 1)) ||
2870 (!use_tso && !qeth_get_elements_no(card, new_skb, 0)))) {
Eugene Crosser6059c902016-06-16 16:18:57 +02002871 int lin_rc = skb_linearize(new_skb);
2872
2873 if (card->options.performance_stats) {
2874 if (lin_rc)
2875 card->perf_stats.tx_linfail++;
2876 else
2877 card->perf_stats.tx_lin++;
2878 }
2879 if (lin_rc)
Eugene Crosser41aeed52016-06-16 16:18:53 +02002880 goto tx_drop;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002881 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002882
Eugene Crosser41aeed52016-06-16 16:18:53 +02002883 if (use_tso) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002884 hdr = (struct qeth_hdr *)skb_push(new_skb,
2885 sizeof(struct qeth_hdr_tso));
2886 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
2887 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
2888 qeth_tso_fill_header(card, hdr, new_skb);
Eugene Crosser2863c612016-06-16 16:18:52 +02002889 hdr_elements++;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002890 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02002891 if (data_offset < 0) {
2892 hdr = (struct qeth_hdr *)skb_push(new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002893 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02002894 qeth_l3_fill_header(card, hdr, new_skb, ipv,
2895 cast_type);
2896 } else {
Frank Blaschkab3332932011-08-08 01:33:59 +00002897 if (new_skb->protocol == ETH_P_AF_IUCV)
2898 qeth_l3_fill_af_iucv_hdr(card, hdr, new_skb);
2899 else {
2900 qeth_l3_fill_header(card, hdr, new_skb, ipv,
2901 cast_type);
2902 hdr->hdr.l3.length = new_skb->len - data_offset;
2903 }
Frank Blaschka683d7182008-08-01 16:39:13 +02002904 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002905
2906 if (skb->ip_summed == CHECKSUM_PARTIAL)
2907 qeth_l3_hdr_csum(card, hdr, new_skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002908 }
2909
Eugene Crosser41aeed52016-06-16 16:18:53 +02002910 elements = use_tso ?
2911 qeth_l3_get_elements_no_tso(card, new_skb, hdr_elements) :
2912 qeth_get_elements_no(card, new_skb, hdr_elements);
Eugene Crosser2863c612016-06-16 16:18:52 +02002913 if (!elements) {
Frank Blaschka64ef8952009-03-24 20:57:16 +00002914 if (data_offset >= 0)
2915 kmem_cache_free(qeth_core_header_cache, hdr);
2916 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002917 }
Eugene Crosser2863c612016-06-16 16:18:52 +02002918 elements += hdr_elements;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002919
Frank Blaschka51aa1652010-06-21 22:57:10 +00002920 if (card->info.type != QETH_CARD_TYPE_IQD) {
2921 int len;
Eugene Crosser41aeed52016-06-16 16:18:53 +02002922 if (use_tso)
Frank Blaschka51aa1652010-06-21 22:57:10 +00002923 len = ((unsigned long)tcp_hdr(new_skb) +
Eugene Crosser2863c612016-06-16 16:18:52 +02002924 tcp_hdrlen(new_skb)) -
Frank Blaschka51aa1652010-06-21 22:57:10 +00002925 (unsigned long)new_skb->data;
2926 else
2927 len = sizeof(struct qeth_hdr_layer3);
2928
Stefan Raspld4ae1f52013-04-22 01:12:29 +00002929 if (qeth_hdr_chk_and_bounce(new_skb, &hdr, len))
Frank Blaschka51aa1652010-06-21 22:57:10 +00002930 goto tx_drop;
Eugene Crosser2863c612016-06-16 16:18:52 +02002931 rc = qeth_do_send_packet(card, queue, new_skb, hdr, elements);
Frank Blaschka51aa1652010-06-21 22:57:10 +00002932 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +01002933 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Eugene Crosser2863c612016-06-16 16:18:52 +02002934 elements, data_offset, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002935
2936 if (!rc) {
2937 card->stats.tx_packets++;
2938 card->stats.tx_bytes += tx_bytes;
2939 if (new_skb != skb)
2940 dev_kfree_skb_any(skb);
2941 if (card->options.performance_stats) {
Eugene Crosser2863c612016-06-16 16:18:52 +02002942 nr_frags = skb_shinfo(new_skb)->nr_frags;
Eugene Crosser41aeed52016-06-16 16:18:53 +02002943 if (use_tso) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002944 card->perf_stats.large_send_bytes += tx_bytes;
2945 card->perf_stats.large_send_cnt++;
2946 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00002947 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002948 card->perf_stats.sg_skbs_sent++;
2949 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00002950 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002951 }
2952 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07002953 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002954 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02002955 if (data_offset >= 0)
2956 kmem_cache_free(qeth_core_header_cache, hdr);
2957
Frank Blaschka4a71df52008-02-15 09:19:42 +01002958 if (rc == -EBUSY) {
2959 if (new_skb != skb)
2960 dev_kfree_skb_any(new_skb);
2961 return NETDEV_TX_BUSY;
2962 } else
2963 goto tx_drop;
2964 }
2965
2966 netif_wake_queue(dev);
2967 if (card->options.performance_stats)
2968 card->perf_stats.outbound_time += qeth_get_micros() -
2969 card->perf_stats.outbound_start_time;
2970 return rc;
2971
2972tx_drop:
2973 card->stats.tx_dropped++;
2974 card->stats.tx_errors++;
2975 if ((new_skb != skb) && new_skb)
2976 dev_kfree_skb_any(new_skb);
2977 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02002978 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002979 return NETDEV_TX_OK;
2980}
2981
Ursula Braun39423442011-01-12 20:42:24 +00002982static int __qeth_l3_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002983{
Heiko Carstens509e2562008-07-26 02:24:10 -07002984 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002985 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002986
Carsten Otte847a50f2010-06-21 22:57:05 +00002987 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +00002988 if (card->state == CARD_STATE_UP)
2989 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002990 if (card->state != CARD_STATE_SOFTSETUP)
2991 return -ENODEV;
2992 card->data.state = CH_STATE_UP;
2993 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002994 netif_start_queue(dev);
2995
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002996 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
2997 napi_enable(&card->napi);
2998 napi_schedule(&card->napi);
2999 } else
3000 rc = -EIO;
3001 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003002}
3003
Ursula Braun39423442011-01-12 20:42:24 +00003004static int qeth_l3_open(struct net_device *dev)
3005{
3006 struct qeth_card *card = dev->ml_priv;
3007
3008 QETH_CARD_TEXT(card, 5, "qethope_");
3009 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
3010 QETH_CARD_TEXT(card, 3, "openREC");
3011 return -ERESTARTSYS;
3012 }
3013 return __qeth_l3_open(dev);
3014}
3015
Frank Blaschka4a71df52008-02-15 09:19:42 +01003016static int qeth_l3_stop(struct net_device *dev)
3017{
Heiko Carstens509e2562008-07-26 02:24:10 -07003018 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003019
Carsten Otte847a50f2010-06-21 22:57:05 +00003020 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003021 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003022 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003023 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003024 napi_disable(&card->napi);
3025 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003026 return 0;
3027}
3028
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07003029static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003030 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003031 .get_strings = qeth_core_get_strings,
3032 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00003033 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003034 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02003035 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003036};
3037
3038/*
3039 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3040 * NOARP on the netdevice is no option because it also turns off neighbor
3041 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3042 * arp resolution but we want the hard header (packet socket will work
3043 * e.g. tcpdump)
3044 */
3045static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
3046{
3047 n->nud_state = NUD_NOARP;
3048 memcpy(n->ha, "FAKELL", 6);
3049 n->output = n->ops->connected_output;
3050 return 0;
3051}
3052
3053static int
3054qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
3055{
3056 if (np->tbl->family == AF_INET)
3057 np->neigh_setup = qeth_l3_neigh_setup_noarp;
3058
3059 return 0;
3060}
3061
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003062static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08003063 .ndo_open = qeth_l3_open,
3064 .ndo_stop = qeth_l3_stop,
3065 .ndo_get_stats = qeth_get_stats,
3066 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3067 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003068 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003069 .ndo_do_ioctl = qeth_l3_do_ioctl,
3070 .ndo_change_mtu = qeth_change_mtu,
Thomas Richter8f43fb02016-06-16 16:18:59 +02003071 .ndo_fix_features = qeth_fix_features,
3072 .ndo_set_features = qeth_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08003073 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3074 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003075 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka8403b132009-01-08 10:50:55 -08003076};
3077
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003078static const struct net_device_ops qeth_l3_osa_netdev_ops = {
3079 .ndo_open = qeth_l3_open,
3080 .ndo_stop = qeth_l3_stop,
3081 .ndo_get_stats = qeth_get_stats,
3082 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3083 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003084 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003085 .ndo_do_ioctl = qeth_l3_do_ioctl,
3086 .ndo_change_mtu = qeth_change_mtu,
Thomas Richter8f43fb02016-06-16 16:18:59 +02003087 .ndo_fix_features = qeth_fix_features,
3088 .ndo_set_features = qeth_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003089 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3090 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003091 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003092 .ndo_neigh_setup = qeth_l3_neigh_setup,
3093};
3094
Frank Blaschka4a71df52008-02-15 09:19:42 +01003095static int qeth_l3_setup_netdev(struct qeth_card *card)
3096{
Thomas Richter1aec42b2015-01-21 13:39:10 +01003097 int rc;
3098
Ursula Braun5113fec2010-05-16 21:15:14 +00003099 if (card->info.type == QETH_CARD_TYPE_OSD ||
3100 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003101 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3102 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04003103 pr_info("qeth_l3: ignoring TR device\n");
3104 return -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003105 } else {
3106 card->dev = alloc_etherdev(0);
3107 if (!card->dev)
3108 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003109 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003110
3111 /*IPv6 address autoconfiguration stuff*/
3112 qeth_l3_get_unique_id(card);
3113 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
3114 card->dev->dev_id = card->info.unique_id &
3115 0xffff;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00003116 if (!card->info.guestlan) {
3117 card->dev->hw_features = NETIF_F_SG |
3118 NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
3119 NETIF_F_TSO;
Hans Wippel9bdc4412016-06-16 16:19:00 +02003120 card->dev->vlan_features = NETIF_F_SG |
3121 NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
3122 NETIF_F_TSO;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00003123 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003124 }
3125 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
Tom Gundersenc835a672014-07-14 16:37:24 +02003126 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
3127 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003128 if (!card->dev)
3129 return -ENODEV;
3130 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003131 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Thomas Richter1aec42b2015-01-21 13:39:10 +01003132 rc = qeth_l3_iqd_read_initial_mac(card);
3133 if (rc)
3134 return rc;
Frank Blaschkab3332932011-08-08 01:33:59 +00003135 if (card->options.hsuid[0])
3136 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003137 } else
3138 return -ENODEV;
3139
Heiko Carstens509e2562008-07-26 02:24:10 -07003140 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003141 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003142 card->dev->mtu = card->info.initial_mtu;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00003143 card->dev->ethtool_ops = &qeth_l3_ethtool_ops;
Patrick McHardyf6469682013-04-19 02:04:27 +00003144 card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
3145 NETIF_F_HW_VLAN_CTAG_RX |
3146 NETIF_F_HW_VLAN_CTAG_FILTER;
Eric Dumazet02875872014-10-05 18:38:35 -07003147 netif_keep_dst(card->dev);
Eugene Crosser8bad55f2016-06-16 16:18:54 +02003148 card->dev->gso_max_size = (QETH_MAX_BUFFER_ELEMENTS(card) - 1) *
3149 PAGE_SIZE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003150
3151 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003152 netif_napi_add(card->dev, &card->napi, qeth_l3_poll, QETH_NAPI_WEIGHT);
Ursula Braune5ebe632015-12-11 12:27:55 +01003153 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003154 return register_netdev(card->dev);
3155}
3156
Frank Blaschka4a71df52008-02-15 09:19:42 +01003157static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3158{
3159 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun25c1a1e2017-05-10 19:07:51 +02003160 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003161
Ursula Braun25c1a1e2017-05-10 19:07:51 +02003162 rc = qeth_l3_create_device_attributes(&gdev->dev);
3163 if (rc)
3164 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003165 card->options.layer2 = 0;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003166 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003167 return 0;
3168}
3169
3170static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3171{
3172 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3173
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003174 qeth_l3_remove_device_attributes(&cgdev->dev);
3175
Ursula Braunf2148562009-05-19 21:38:37 +00003176 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003177 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3178
Ursula Braun70919e22011-02-26 22:41:36 -08003179 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003180 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003181
3182 if (card->dev) {
Ursula Braun7831b4f2016-07-04 14:07:16 +02003183 netif_napi_del(&card->napi);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003184 unregister_netdev(card->dev);
3185 card->dev = NULL;
3186 }
3187
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003188 qeth_l3_clear_ip_htable(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003189 qeth_l3_clear_ipato_list(card);
3190 return;
3191}
3192
3193static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3194{
3195 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3196 int rc = 0;
3197 enum qeth_card_states recover_flag;
3198
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003199 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003200 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003201 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3202 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003203
Frank Blaschka4a71df52008-02-15 09:19:42 +01003204 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003205 rc = qeth_core_hardsetup_card(card);
3206 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01003207 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003208 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003209 goto out_remove;
3210 }
3211
Ursula Braunaa909222009-11-12 00:11:43 +00003212 if (!card->dev && qeth_l3_setup_netdev(card)) {
3213 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003214 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00003215 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003216
Frank Blaschka1da74b12011-05-12 18:45:02 +00003217 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
3218 if (card->info.hwtrap &&
3219 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
3220 card->info.hwtrap = 0;
3221 } else
3222 card->info.hwtrap = 0;
3223
Frank Blaschka4a71df52008-02-15 09:19:42 +01003224 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003225 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003226 qeth_print_status_message(card);
3227
3228 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003229 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003230
3231 rc = qeth_send_startlan(card);
3232 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003233 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003234 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003235 dev_warn(&card->gdev->dev,
3236 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003237 card->lan_online = 0;
Ursula Braun2b6203b2010-11-26 02:41:19 +00003238 goto contin;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003239 }
Ursula Braunaa909222009-11-12 00:11:43 +00003240 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00003241 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003242 } else
3243 card->lan_online = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003244
Ursula Braun2b6203b2010-11-26 02:41:19 +00003245contin:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003246 rc = qeth_l3_setadapter_parms(card);
3247 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003248 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003249 if (!card->options.sniffer) {
3250 rc = qeth_l3_start_ipassists(card);
Stefan Raspl0f547612013-01-21 02:30:20 +00003251 if (rc) {
Ursula Braun76b11f82010-01-11 02:50:50 +00003252 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Stefan Raspl0f547612013-01-21 02:30:20 +00003253 goto out_remove;
3254 }
Ursula Braun76b11f82010-01-11 02:50:50 +00003255 rc = qeth_l3_setrouting_v4(card);
3256 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003257 QETH_DBF_TEXT_(SETUP, 2, "4err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003258 rc = qeth_l3_setrouting_v6(card);
3259 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003260 QETH_DBF_TEXT_(SETUP, 2, "5err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003261 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003262 netif_tx_disable(card->dev);
3263
3264 rc = qeth_init_qdio_queues(card);
3265 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003266 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003267 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003268 goto out_remove;
3269 }
3270 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003271
3272 qeth_set_allowed_threads(card, 0xffffffff, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003273 qeth_l3_recover_ip(card);
Ursula Braun2b6203b2010-11-26 02:41:19 +00003274 if (card->lan_online)
3275 netif_carrier_on(card->dev);
3276 else
3277 netif_carrier_off(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003278 if (recover_flag == CARD_STATE_RECOVER) {
Ursula Braun4763b0a2011-12-19 22:56:32 +00003279 rtnl_lock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003280 if (recovery_mode)
Ursula Braun39423442011-01-12 20:42:24 +00003281 __qeth_l3_open(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00003282 else
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003283 dev_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003284 qeth_l3_set_multicast_list(card->dev);
Hans Wippele830baa2016-09-15 14:39:21 +02003285 qeth_recover_features(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00003286 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01003287 }
Stefan Raspl82f77cf2013-03-18 20:04:42 +00003288 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003289 /* let user_space know that device is online */
3290 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003291 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003292 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003293 return 0;
3294out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003295 qeth_l3_stop_card(card, 0);
3296 ccw_device_set_offline(CARD_DDEV(card));
3297 ccw_device_set_offline(CARD_WDEV(card));
3298 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01003299 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003300 if (recover_flag == CARD_STATE_RECOVER)
3301 card->state = CARD_STATE_RECOVER;
3302 else
3303 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00003304 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003305 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00003306 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003307}
3308
3309static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3310{
3311 return __qeth_l3_set_online(gdev, 0);
3312}
3313
3314static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3315 int recovery_mode)
3316{
3317 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3318 int rc = 0, rc2 = 0, rc3 = 0;
3319 enum qeth_card_states recover_flag;
3320
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003321 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003322 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003323 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3324 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003325
3326 if (card->dev && netif_carrier_ok(card->dev))
3327 netif_carrier_off(card->dev);
3328 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003329 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
3330 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
3331 card->info.hwtrap = 1;
3332 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02003333 qeth_l3_stop_card(card, recovery_mode);
Einar Lueck72861ae2011-12-19 22:56:36 +00003334 if ((card->options.cq == QETH_CQ_ENABLED) && card->dev) {
3335 rtnl_lock();
3336 call_netdevice_notifiers(NETDEV_REBOOT, card->dev);
3337 rtnl_unlock();
3338 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003339 rc = ccw_device_set_offline(CARD_DDEV(card));
3340 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3341 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3342 if (!rc)
3343 rc = (rc2) ? rc2 : rc3;
3344 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003345 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01003346 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003347 if (recover_flag == CARD_STATE_UP)
3348 card->state = CARD_STATE_RECOVER;
3349 /* let user_space know that device is offline */
3350 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003351 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003352 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003353 return 0;
3354}
3355
3356static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3357{
3358 return __qeth_l3_set_offline(cgdev, 0);
3359}
3360
3361static int qeth_l3_recover(void *ptr)
3362{
3363 struct qeth_card *card;
3364 int rc = 0;
3365
3366 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00003367 QETH_CARD_TEXT(card, 2, "recover1");
3368 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003369 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3370 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00003371 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003372 dev_warn(&card->gdev->dev,
3373 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00003374 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003375 __qeth_l3_set_offline(card->gdev, 1);
3376 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003377 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003378 dev_info(&card->gdev->dev,
3379 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003380 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00003381 qeth_close_dev(card);
3382 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00003383 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003384 }
Stefan Raspl65d80132013-04-07 22:19:27 +00003385 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003386 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3387 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003388 return 0;
3389}
3390
3391static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3392{
3393 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braunf78ac2b2011-12-19 22:56:33 +00003394 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka1da74b12011-05-12 18:45:02 +00003395 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
3396 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003397 qeth_qdio_clear_card(card, 0);
3398 qeth_clear_qdio_buffers(card);
Ursula Braun22ae2792014-02-24 13:12:06 +01003399 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003400}
3401
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003402static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3403{
3404 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3405
3406 if (card->dev)
3407 netif_device_detach(card->dev);
3408 qeth_set_allowed_threads(card, 0, 1);
3409 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3410 if (gdev->state == CCWGROUP_OFFLINE)
3411 return 0;
3412 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00003413 if (card->info.hwtrap)
3414 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003415 __qeth_l3_set_offline(card->gdev, 1);
3416 } else
3417 __qeth_l3_set_offline(card->gdev, 0);
3418 return 0;
3419}
3420
3421static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3422{
3423 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3424 int rc = 0;
3425
3426 if (gdev->state == CCWGROUP_OFFLINE)
3427 goto out;
3428
3429 if (card->state == CARD_STATE_RECOVER) {
3430 rc = __qeth_l3_set_online(card->gdev, 1);
3431 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00003432 rtnl_lock();
3433 dev_close(card->dev);
3434 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003435 }
3436 } else
3437 rc = __qeth_l3_set_online(card->gdev, 0);
3438out:
3439 qeth_set_allowed_threads(card, 0xffffffff, 0);
3440 if (card->dev)
3441 netif_device_attach(card->dev);
3442 if (rc)
3443 dev_warn(&card->gdev->dev, "The qeth device driver "
3444 "failed to recover an error on the device\n");
3445 return rc;
3446}
3447
Eugene Crosserc044dc22014-01-29 09:23:48 +01003448/* Returns zero if the command is successfully "consumed" */
3449static int qeth_l3_control_event(struct qeth_card *card,
3450 struct qeth_ipa_cmd *cmd)
3451{
3452 return 1;
3453}
3454
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003455struct qeth_discipline qeth_l3_discipline = {
3456 .start_poll = qeth_qdio_start_poll,
3457 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
3458 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
3459 .recover = qeth_l3_recover,
3460 .setup = qeth_l3_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003461 .remove = qeth_l3_remove_device,
3462 .set_online = qeth_l3_set_online,
3463 .set_offline = qeth_l3_set_offline,
3464 .shutdown = qeth_l3_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003465 .freeze = qeth_l3_pm_suspend,
3466 .thaw = qeth_l3_pm_resume,
3467 .restore = qeth_l3_pm_resume,
Eugene Crosserc044dc22014-01-29 09:23:48 +01003468 .control_event_handler = qeth_l3_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003469};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003470EXPORT_SYMBOL_GPL(qeth_l3_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003471
3472static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003473 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003474{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003475
Frank Blaschka4a71df52008-02-15 09:19:42 +01003476 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3477 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3478 struct qeth_ipaddr *addr;
3479 struct qeth_card *card;
3480
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003481 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003482 return NOTIFY_DONE;
3483
Frank Blaschka4a71df52008-02-15 09:19:42 +01003484 card = qeth_l3_get_card_from_dev(dev);
3485 if (!card)
3486 return NOTIFY_DONE;
frank.blaschka@de.ibm.com6d8823d2012-05-16 01:28:26 +00003487 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003488
3489 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003490 if (addr) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003491 addr->u.a4.addr = ifa->ifa_address;
3492 addr->u.a4.mask = ifa->ifa_mask;
3493 addr->type = QETH_IP_TYPE_NORMAL;
3494 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003495 return NOTIFY_DONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003496
3497 switch (event) {
3498 case NETDEV_UP:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003499 spin_lock_bh(&card->ip_lock);
3500 qeth_l3_add_ip(card, addr);
3501 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003502 break;
3503 case NETDEV_DOWN:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003504 spin_lock_bh(&card->ip_lock);
3505 qeth_l3_delete_ip(card, addr);
3506 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003507 break;
3508 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003509
3510 kfree(addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003511 return NOTIFY_DONE;
3512}
3513
3514static struct notifier_block qeth_l3_ip_notifier = {
3515 qeth_l3_ip_event,
3516 NULL,
3517};
3518
3519#ifdef CONFIG_QETH_IPV6
3520/**
3521 * IPv6 event handler
3522 */
3523static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003524 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003525{
3526 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3527 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3528 struct qeth_ipaddr *addr;
3529 struct qeth_card *card;
3530
Frank Blaschka4a71df52008-02-15 09:19:42 +01003531 card = qeth_l3_get_card_from_dev(dev);
3532 if (!card)
3533 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00003534 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003535 if (!qeth_is_supported(card, IPA_IPV6))
3536 return NOTIFY_DONE;
3537
3538 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003539 if (addr) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003540 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3541 addr->u.a6.pfxlen = ifa->prefix_len;
3542 addr->type = QETH_IP_TYPE_NORMAL;
3543 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003544 return NOTIFY_DONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003545
3546 switch (event) {
3547 case NETDEV_UP:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003548 spin_lock_bh(&card->ip_lock);
3549 qeth_l3_add_ip(card, addr);
3550 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003551 break;
3552 case NETDEV_DOWN:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003553 spin_lock_bh(&card->ip_lock);
3554 qeth_l3_delete_ip(card, addr);
3555 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003556 break;
3557 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003558
3559 kfree(addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003560 return NOTIFY_DONE;
3561}
3562
3563static struct notifier_block qeth_l3_ip6_notifier = {
3564 qeth_l3_ip6_event,
3565 NULL,
3566};
3567#endif
3568
3569static int qeth_l3_register_notifiers(void)
3570{
3571 int rc;
3572
Carsten Otte847a50f2010-06-21 22:57:05 +00003573 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003574 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3575 if (rc)
3576 return rc;
3577#ifdef CONFIG_QETH_IPV6
3578 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3579 if (rc) {
3580 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3581 return rc;
3582 }
3583#else
Joe Perchesbaebc702016-03-03 20:49:57 -08003584 pr_warn("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003585#endif
3586 return 0;
3587}
3588
3589static void qeth_l3_unregister_notifiers(void)
3590{
3591
Carsten Otte847a50f2010-06-21 22:57:05 +00003592 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Stefan Raspl18af5c12012-11-19 02:46:50 +00003593 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003594#ifdef CONFIG_QETH_IPV6
Stefan Raspl18af5c12012-11-19 02:46:50 +00003595 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003596#endif /* QETH_IPV6 */
3597}
3598
3599static int __init qeth_l3_init(void)
3600{
3601 int rc = 0;
3602
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003603 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003604 rc = qeth_l3_register_notifiers();
3605 return rc;
3606}
3607
3608static void __exit qeth_l3_exit(void)
3609{
3610 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003611 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003612}
3613
3614module_init(qeth_l3_init);
3615module_exit(qeth_l3_exit);
3616MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3617MODULE_DESCRIPTION("qeth layer 3 discipline");
3618MODULE_LICENSE("GPL");