blob: 72934666fedf0193bef37fcc5378127ed2a540c7 [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
260 rc = qeth_l3_deregister_addr_entry(card, addr);
261
262 hash_del(&addr->hnode);
263 kfree(addr);
264
Frank Blaschka4a71df52008-02-15 09:19:42 +0100265 return rc;
266}
267
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200268int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100269{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100270 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200271 struct qeth_ipaddr *addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100272
Carsten Otte847a50f2010-06-21 22:57:05 +0000273 QETH_CARD_TEXT(card, 4, "addip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200274
275 if (tmp_addr->proto == QETH_PROT_IPV4)
276 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100277 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200278 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
279 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100280 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200281
282 addr = qeth_l3_ip_from_hash(card, tmp_addr);
283 if (!addr) {
284 addr = qeth_l3_get_addr_buffer(tmp_addr->proto);
285 if (!addr)
286 return -ENOMEM;
287
288 memcpy(addr, tmp_addr, sizeof(struct qeth_ipaddr));
289 addr->ref_counter = 1;
290
291 if (addr->type == QETH_IP_TYPE_NORMAL &&
292 qeth_l3_is_addr_covered_by_ipato(card, addr)) {
293 QETH_CARD_TEXT(card, 2, "tkovaddr");
294 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
295 }
296 hash_add(card->ip_htable, &addr->hnode,
297 qeth_l3_ipaddr_hash(addr));
298
299 /* qeth_l3_register_addr_entry can go to sleep
300 * if we add a IPV4 addr. It is caused by the reason
301 * that SETIP ipa cmd starts ARP staff for IPV4 addr.
302 * Thus we should unlock spinlock, and make a protection
303 * using in_progress variable to indicate that there is
304 * an hardware operation with this IPV4 address
305 */
306 if (addr->proto == QETH_PROT_IPV4) {
307 addr->in_progress = 1;
308 spin_unlock_bh(&card->ip_lock);
309 rc = qeth_l3_register_addr_entry(card, addr);
310 spin_lock_bh(&card->ip_lock);
311 addr->in_progress = 0;
312 } else
313 rc = qeth_l3_register_addr_entry(card, addr);
314
315 if (!rc || (rc == IPA_RC_DUPLICATE_IP_ADDRESS) ||
316 (rc == IPA_RC_LAN_OFFLINE)) {
317 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
318 if (addr->ref_counter < 1) {
319 qeth_l3_delete_ip(card, addr);
320 kfree(addr);
321 }
322 } else {
323 hash_del(&addr->hnode);
324 kfree(addr);
325 }
326 } else {
327 if (addr->type == QETH_IP_TYPE_NORMAL)
328 addr->ref_counter++;
329 }
330
Frank Blaschka4a71df52008-02-15 09:19:42 +0100331 return rc;
332}
333
334
Frank Blaschkab3332932011-08-08 01:33:59 +0000335struct qeth_ipaddr *qeth_l3_get_addr_buffer(
Frank Blaschka4a71df52008-02-15 09:19:42 +0100336 enum qeth_prot_versions prot)
337{
338 struct qeth_ipaddr *addr;
339
340 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200341 if (!addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100342 return NULL;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200343
Frank Blaschka4a71df52008-02-15 09:19:42 +0100344 addr->type = QETH_IP_TYPE_NORMAL;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200345 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100346 addr->proto = prot;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200347
Frank Blaschka4a71df52008-02-15 09:19:42 +0100348 return addr;
349}
350
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200351static void qeth_l3_clear_ip_htable(struct qeth_card *card, int recover)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100352{
353 struct qeth_ipaddr *addr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200354 struct hlist_node *tmp;
355 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100356
Carsten Otte847a50f2010-06-21 22:57:05 +0000357 QETH_CARD_TEXT(card, 4, "clearip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200358
Ursula Braun76b11f82010-01-11 02:50:50 +0000359 if (recover && card->options.sniffer)
360 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100361
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200362 spin_lock_bh(&card->ip_lock);
363
364 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
365 if (!recover) {
366 hash_del(&addr->hnode);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100367 kfree(addr);
368 continue;
369 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200370 addr->disp_flag = QETH_DISP_ADDR_ADD;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100371 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200372
373 spin_unlock_bh(&card->ip_lock);
374
375 spin_lock_bh(&card->mclock);
376
377 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
378 hash_del(&addr->hnode);
379 kfree(addr);
380 }
381
382 spin_unlock_bh(&card->mclock);
383
384
Frank Blaschka4a71df52008-02-15 09:19:42 +0100385}
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200386static void qeth_l3_recover_ip(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100387{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200388 struct qeth_ipaddr *addr;
389 struct hlist_node *tmp;
390 int i;
391 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100392
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200393 QETH_CARD_TEXT(card, 4, "recoverip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100394
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200395 spin_lock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100396
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200397 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
398 if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
399 if (addr->proto == QETH_PROT_IPV4) {
400 addr->in_progress = 1;
401 spin_unlock_bh(&card->ip_lock);
402 rc = qeth_l3_register_addr_entry(card, addr);
403 spin_lock_bh(&card->ip_lock);
404 addr->in_progress = 0;
405 } else
406 rc = qeth_l3_register_addr_entry(card, addr);
407
408 if (!rc) {
409 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
410 if (addr->ref_counter < 1) {
411 qeth_l3_delete_ip(card, addr);
412 kfree(addr);
413 }
414 } else {
415 hash_del(&addr->hnode);
416 kfree(addr);
417 }
418 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100419 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200420
421 spin_unlock_bh(&card->ip_lock);
422
Frank Blaschka4a71df52008-02-15 09:19:42 +0100423}
424
425static int qeth_l3_send_setdelmc(struct qeth_card *card,
426 struct qeth_ipaddr *addr, int ipacmd)
427{
428 int rc;
429 struct qeth_cmd_buffer *iob;
430 struct qeth_ipa_cmd *cmd;
431
Carsten Otte847a50f2010-06-21 22:57:05 +0000432 QETH_CARD_TEXT(card, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100433
434 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100435 if (!iob)
436 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100437 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
438 memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
439 if (addr->proto == QETH_PROT_IPV6)
440 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
441 sizeof(struct in6_addr));
442 else
443 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
444
445 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
446
447 return rc;
448}
449
450static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
451{
452 int i, j;
453 for (i = 0; i < 16; i++) {
454 j = (len) - (i * 8);
455 if (j >= 8)
456 netmask[i] = 0xff;
457 else if (j > 0)
458 netmask[i] = (u8)(0xFF00 >> j);
459 else
460 netmask[i] = 0;
461 }
462}
463
464static int qeth_l3_send_setdelip(struct qeth_card *card,
465 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
466{
467 int rc;
468 struct qeth_cmd_buffer *iob;
469 struct qeth_ipa_cmd *cmd;
470 __u8 netmask[16];
471
Carsten Otte847a50f2010-06-21 22:57:05 +0000472 QETH_CARD_TEXT(card, 4, "setdelip");
473 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100474
475 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100476 if (!iob)
477 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100478 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
479 if (addr->proto == QETH_PROT_IPV6) {
480 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
481 sizeof(struct in6_addr));
482 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
483 memcpy(cmd->data.setdelip6.mask, netmask,
484 sizeof(struct in6_addr));
485 cmd->data.setdelip6.flags = flags;
486 } else {
487 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
488 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
489 cmd->data.setdelip4.flags = flags;
490 }
491
492 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
493
494 return rc;
495}
496
497static int qeth_l3_send_setrouting(struct qeth_card *card,
498 enum qeth_routing_types type, enum qeth_prot_versions prot)
499{
500 int rc;
501 struct qeth_ipa_cmd *cmd;
502 struct qeth_cmd_buffer *iob;
503
Carsten Otte847a50f2010-06-21 22:57:05 +0000504 QETH_CARD_TEXT(card, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100505 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100506 if (!iob)
507 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100508 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
509 cmd->data.setrtg.type = (type);
510 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
511
512 return rc;
513}
514
Stefan Raspl82e2e782013-03-18 20:04:43 +0000515static int qeth_l3_correct_routing_type(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100516 enum qeth_routing_types *type, enum qeth_prot_versions prot)
517{
518 if (card->info.type == QETH_CARD_TYPE_IQD) {
519 switch (*type) {
520 case NO_ROUTER:
521 case PRIMARY_CONNECTOR:
522 case SECONDARY_CONNECTOR:
523 case MULTICAST_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000524 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100525 default:
526 goto out_inval;
527 }
528 } else {
529 switch (*type) {
530 case NO_ROUTER:
531 case PRIMARY_ROUTER:
532 case SECONDARY_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000533 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100534 case MULTICAST_ROUTER:
535 if (qeth_is_ipafunc_supported(card, prot,
536 IPA_OSA_MC_ROUTER))
Stefan Raspl82e2e782013-03-18 20:04:43 +0000537 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100538 default:
539 goto out_inval;
540 }
541 }
542out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100543 *type = NO_ROUTER;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000544 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100545}
546
547int qeth_l3_setrouting_v4(struct qeth_card *card)
548{
549 int rc;
550
Carsten Otte847a50f2010-06-21 22:57:05 +0000551 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100552
Stefan Raspl82e2e782013-03-18 20:04:43 +0000553 rc = qeth_l3_correct_routing_type(card, &card->options.route4.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100554 QETH_PROT_IPV4);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000555 if (rc)
556 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100557
558 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
559 QETH_PROT_IPV4);
560 if (rc) {
561 card->options.route4.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200562 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
563 " on %s. Type set to 'no router'.\n", rc,
564 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100565 }
566 return rc;
567}
568
569int qeth_l3_setrouting_v6(struct qeth_card *card)
570{
571 int rc = 0;
572
Carsten Otte847a50f2010-06-21 22:57:05 +0000573 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100574#ifdef CONFIG_QETH_IPV6
575
576 if (!qeth_is_supported(card, IPA_IPV6))
577 return 0;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000578 rc = qeth_l3_correct_routing_type(card, &card->options.route6.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100579 QETH_PROT_IPV6);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000580 if (rc)
581 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100582
583 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
584 QETH_PROT_IPV6);
585 if (rc) {
586 card->options.route6.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200587 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
588 " on %s. Type set to 'no router'.\n", rc,
589 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100590 }
591#endif
592 return rc;
593}
594
595/*
596 * IP address takeover related functions
597 */
598static void qeth_l3_clear_ipato_list(struct qeth_card *card)
599{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100600 struct qeth_ipato_entry *ipatoe, *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100601
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200602 spin_lock_bh(&card->ip_lock);
603
Frank Blaschka4a71df52008-02-15 09:19:42 +0100604 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
605 list_del(&ipatoe->entry);
606 kfree(ipatoe);
607 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200608
609 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100610}
611
612int qeth_l3_add_ipato_entry(struct qeth_card *card,
613 struct qeth_ipato_entry *new)
614{
615 struct qeth_ipato_entry *ipatoe;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100616 int rc = 0;
617
Carsten Otte847a50f2010-06-21 22:57:05 +0000618 QETH_CARD_TEXT(card, 2, "addipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200619
620 spin_lock_bh(&card->ip_lock);
621
Frank Blaschka4a71df52008-02-15 09:19:42 +0100622 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
623 if (ipatoe->proto != new->proto)
624 continue;
625 if (!memcmp(ipatoe->addr, new->addr,
626 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
627 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100628 rc = -EEXIST;
629 break;
630 }
631 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200632
Frank Blaschka4a71df52008-02-15 09:19:42 +0100633 if (!rc)
634 list_add_tail(&new->entry, &card->ipato.entries);
635
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200636 spin_unlock_bh(&card->ip_lock);
637
Frank Blaschka4a71df52008-02-15 09:19:42 +0100638 return rc;
639}
640
641void qeth_l3_del_ipato_entry(struct qeth_card *card,
642 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
643{
644 struct qeth_ipato_entry *ipatoe, *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100645
Carsten Otte847a50f2010-06-21 22:57:05 +0000646 QETH_CARD_TEXT(card, 2, "delipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200647
648 spin_lock_bh(&card->ip_lock);
649
Frank Blaschka4a71df52008-02-15 09:19:42 +0100650 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
651 if (ipatoe->proto != proto)
652 continue;
653 if (!memcmp(ipatoe->addr, addr,
654 (proto == QETH_PROT_IPV4)? 4:16) &&
655 (ipatoe->mask_bits == mask_bits)) {
656 list_del(&ipatoe->entry);
657 kfree(ipatoe);
658 }
659 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200660
661 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100662}
663
664/*
665 * VIPA related functions
666 */
667int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
668 const u8 *addr)
669{
670 struct qeth_ipaddr *ipaddr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100671 int rc = 0;
672
673 ipaddr = qeth_l3_get_addr_buffer(proto);
674 if (ipaddr) {
675 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000676 QETH_CARD_TEXT(card, 2, "addvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100677 memcpy(&ipaddr->u.a4.addr, addr, 4);
678 ipaddr->u.a4.mask = 0;
679 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000680 QETH_CARD_TEXT(card, 2, "addvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100681 memcpy(&ipaddr->u.a6.addr, addr, 16);
682 ipaddr->u.a6.pfxlen = 0;
683 }
684 ipaddr->type = QETH_IP_TYPE_VIPA;
685 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
686 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
687 } else
688 return -ENOMEM;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200689
690 spin_lock_bh(&card->ip_lock);
691
692 if (!qeth_l3_ip_from_hash(card, ipaddr))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100693 rc = -EEXIST;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200694 else
695 qeth_l3_add_ip(card, ipaddr);
696
697 spin_unlock_bh(&card->ip_lock);
698
699 kfree(ipaddr);
700
Frank Blaschka4a71df52008-02-15 09:19:42 +0100701 return rc;
702}
703
704void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
705 const u8 *addr)
706{
707 struct qeth_ipaddr *ipaddr;
708
709 ipaddr = qeth_l3_get_addr_buffer(proto);
710 if (ipaddr) {
711 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000712 QETH_CARD_TEXT(card, 2, "delvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100713 memcpy(&ipaddr->u.a4.addr, addr, 4);
714 ipaddr->u.a4.mask = 0;
715 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000716 QETH_CARD_TEXT(card, 2, "delvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100717 memcpy(&ipaddr->u.a6.addr, addr, 16);
718 ipaddr->u.a6.pfxlen = 0;
719 }
720 ipaddr->type = QETH_IP_TYPE_VIPA;
721 } else
722 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200723
724 spin_lock_bh(&card->ip_lock);
725 qeth_l3_delete_ip(card, ipaddr);
726 spin_unlock_bh(&card->ip_lock);
727
728 kfree(ipaddr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100729}
730
731/*
732 * proxy ARP related functions
733 */
734int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
735 const u8 *addr)
736{
737 struct qeth_ipaddr *ipaddr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100738 int rc = 0;
739
740 ipaddr = qeth_l3_get_addr_buffer(proto);
741 if (ipaddr) {
742 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000743 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100744 memcpy(&ipaddr->u.a4.addr, addr, 4);
745 ipaddr->u.a4.mask = 0;
746 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000747 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100748 memcpy(&ipaddr->u.a6.addr, addr, 16);
749 ipaddr->u.a6.pfxlen = 0;
750 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200751
Frank Blaschka4a71df52008-02-15 09:19:42 +0100752 ipaddr->type = QETH_IP_TYPE_RXIP;
753 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
754 ipaddr->del_flags = 0;
755 } else
756 return -ENOMEM;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200757
758 spin_lock_bh(&card->ip_lock);
759
760 if (!qeth_l3_ip_from_hash(card, ipaddr))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100761 rc = -EEXIST;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200762 else
763 qeth_l3_add_ip(card, ipaddr);
764
765 spin_unlock_bh(&card->ip_lock);
766
767 kfree(ipaddr);
768
769 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100770}
771
772void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
773 const u8 *addr)
774{
775 struct qeth_ipaddr *ipaddr;
776
777 ipaddr = qeth_l3_get_addr_buffer(proto);
778 if (ipaddr) {
779 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000780 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100781 memcpy(&ipaddr->u.a4.addr, addr, 4);
782 ipaddr->u.a4.mask = 0;
783 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000784 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100785 memcpy(&ipaddr->u.a6.addr, addr, 16);
786 ipaddr->u.a6.pfxlen = 0;
787 }
788 ipaddr->type = QETH_IP_TYPE_RXIP;
789 } else
790 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200791
792 spin_lock_bh(&card->ip_lock);
793 qeth_l3_delete_ip(card, ipaddr);
794 spin_unlock_bh(&card->ip_lock);
795
796 kfree(ipaddr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100797}
798
799static int qeth_l3_register_addr_entry(struct qeth_card *card,
800 struct qeth_ipaddr *addr)
801{
802 char buf[50];
803 int rc = 0;
804 int cnt = 3;
805
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200806
Frank Blaschka4a71df52008-02-15 09:19:42 +0100807 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000808 QETH_CARD_TEXT(card, 2, "setaddr4");
809 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100810 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000811 QETH_CARD_TEXT(card, 2, "setaddr6");
812 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
813 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100814 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000815 QETH_CARD_TEXT(card, 2, "setaddr?");
816 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100817 }
818 do {
819 if (addr->is_multicast)
820 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
821 else
822 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
823 addr->set_flags);
824 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000825 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100826 } while ((--cnt > 0) && rc);
827 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000828 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100829 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100830 dev_warn(&card->gdev->dev,
831 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100832 }
833 return rc;
834}
835
836static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
837 struct qeth_ipaddr *addr)
838{
839 int rc = 0;
840
841 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000842 QETH_CARD_TEXT(card, 2, "deladdr4");
843 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100844 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000845 QETH_CARD_TEXT(card, 2, "deladdr6");
846 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
847 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100848 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000849 QETH_CARD_TEXT(card, 2, "deladdr?");
850 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100851 }
852 if (addr->is_multicast)
853 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
854 else
855 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
856 addr->del_flags);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200857 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000858 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100859
860 return rc;
861}
862
863static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
864{
865 if (cast_type == RTN_MULTICAST)
866 return QETH_CAST_MULTICAST;
867 if (cast_type == RTN_BROADCAST)
868 return QETH_CAST_BROADCAST;
869 return QETH_CAST_UNICAST;
870}
871
872static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
873{
874 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
875 if (cast_type == RTN_MULTICAST)
876 return ct | QETH_CAST_MULTICAST;
877 if (cast_type == RTN_ANYCAST)
878 return ct | QETH_CAST_ANYCAST;
879 if (cast_type == RTN_BROADCAST)
880 return ct | QETH_CAST_BROADCAST;
881 return ct | QETH_CAST_UNICAST;
882}
883
Frank Blaschka4a71df52008-02-15 09:19:42 +0100884static int qeth_l3_setadapter_parms(struct qeth_card *card)
885{
886 int rc;
887
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200888 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100889
890 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100891 dev_info(&card->gdev->dev,
892 "set adapter parameters not supported.\n");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200893 QETH_DBF_TEXT(SETUP, 2, " notsupp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100894 return 0;
895 }
896 rc = qeth_query_setadapterparms(card);
897 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100898 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
Kay Sievers7f6d95e2009-03-24 20:57:14 +0000899 "0x%x\n", dev_name(&card->gdev->dev), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100900 return rc;
901 }
902 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
903 rc = qeth_setadpparms_change_macaddr(card);
904 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100905 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -0800906 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100907 }
908
Frank Blaschka4a71df52008-02-15 09:19:42 +0100909 return rc;
910}
911
Frank Blaschka4a71df52008-02-15 09:19:42 +0100912#ifdef CONFIG_QETH_IPV6
913static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
914 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
915{
916 int rc;
917 struct qeth_cmd_buffer *iob;
918
Carsten Otte847a50f2010-06-21 22:57:05 +0000919 QETH_CARD_TEXT(card, 4, "simassp6");
Thomas Richterb475e312015-12-11 12:27:54 +0100920 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100921 0, QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100922 if (!iob)
923 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +0200924 rc = qeth_send_setassparms(card, iob, 0, 0,
Thomas Richter8f43fb02016-06-16 16:18:59 +0200925 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100926 return rc;
927}
928#endif
929
Frank Blaschka4a71df52008-02-15 09:19:42 +0100930static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
931{
932 int rc;
933
Carsten Otte847a50f2010-06-21 22:57:05 +0000934 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100935
936 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100937 dev_info(&card->gdev->dev,
938 "ARP processing not supported on %s!\n",
939 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100940 return 0;
941 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200942 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
943 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100944 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100945 dev_warn(&card->gdev->dev,
946 "Starting ARP processing support for %s failed\n",
947 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100948 }
949 return rc;
950}
951
952static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
953{
954 int rc;
955
Carsten Otte847a50f2010-06-21 22:57:05 +0000956 QETH_CARD_TEXT(card, 3, "ipaipfrg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100957
958 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100959 dev_info(&card->gdev->dev,
960 "Hardware IP fragmentation not supported on %s\n",
961 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100962 return -EOPNOTSUPP;
963 }
964
Thomas Richter4d7def22015-09-18 16:06:51 +0200965 rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100966 IPA_CMD_ASS_START, 0);
967 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100968 dev_warn(&card->gdev->dev,
969 "Starting IP fragmentation support for %s failed\n",
970 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100971 } else
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100972 dev_info(&card->gdev->dev,
973 "Hardware IP fragmentation enabled \n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100974 return rc;
975}
976
977static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
978{
979 int rc;
980
Carsten Otte847a50f2010-06-21 22:57:05 +0000981 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100982
Frank Blaschka4a71df52008-02-15 09:19:42 +0100983 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100984 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800985 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100986 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100987 return -EOPNOTSUPP;
988 }
989
Thomas Richter4d7def22015-09-18 16:06:51 +0200990 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100991 IPA_CMD_ASS_START, 0);
992 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100993 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800994 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100995 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100996 return rc;
997}
998
999static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1000{
1001 int rc = 0;
1002
Carsten Otte847a50f2010-06-21 22:57:05 +00001003 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001004
1005 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001006 dev_info(&card->gdev->dev,
1007 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001008 return -EOPNOTSUPP;
1009 }
1010
Thomas Richter4d7def22015-09-18 16:06:51 +02001011 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001012 IPA_CMD_ASS_START, 0);
1013 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001014 dev_warn(&card->gdev->dev,
1015 "Starting VLAN support for %s failed\n",
1016 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001017 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001018 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001019 }
1020 return rc;
1021}
1022
1023static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1024{
1025 int rc;
1026
Carsten Otte847a50f2010-06-21 22:57:05 +00001027 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001028
1029 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001030 dev_info(&card->gdev->dev,
1031 "Multicast not supported on %s\n",
1032 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001033 return -EOPNOTSUPP;
1034 }
1035
Thomas Richter4d7def22015-09-18 16:06:51 +02001036 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001037 IPA_CMD_ASS_START, 0);
1038 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001039 dev_warn(&card->gdev->dev,
1040 "Starting multicast support for %s failed\n",
1041 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001042 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001043 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001044 card->dev->flags |= IFF_MULTICAST;
1045 }
1046 return rc;
1047}
1048
Frank Blaschka4a71df52008-02-15 09:19:42 +01001049#ifdef CONFIG_QETH_IPV6
1050static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1051{
1052 int rc;
1053
Carsten Otte847a50f2010-06-21 22:57:05 +00001054 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001055
1056 if (card->info.type == QETH_CARD_TYPE_IQD)
1057 goto out;
1058
Frank Blaschka1da74b12011-05-12 18:45:02 +00001059 rc = qeth_query_ipassists(card, QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001060 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001061 dev_err(&card->gdev->dev,
1062 "Activating IPv6 support for %s failed\n",
1063 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001064 return rc;
1065 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001066 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001067 IPA_CMD_ASS_START, 3);
1068 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001069 dev_err(&card->gdev->dev,
1070 "Activating IPv6 support for %s failed\n",
1071 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001072 return rc;
1073 }
1074 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1075 IPA_CMD_ASS_START);
1076 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001077 dev_err(&card->gdev->dev,
1078 "Activating IPv6 support for %s failed\n",
1079 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001080 return rc;
1081 }
1082 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1083 IPA_CMD_ASS_START);
1084 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001085 dev_warn(&card->gdev->dev,
1086 "Enabling the passthrough mode for %s failed\n",
1087 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001088 return rc;
1089 }
1090out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001091 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001092 return 0;
1093}
1094#endif
1095
1096static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1097{
1098 int rc = 0;
1099
Carsten Otte847a50f2010-06-21 22:57:05 +00001100 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001101
1102 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001103 dev_info(&card->gdev->dev,
1104 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001105 return 0;
1106 }
1107#ifdef CONFIG_QETH_IPV6
1108 rc = qeth_l3_softsetup_ipv6(card);
1109#endif
1110 return rc ;
1111}
1112
1113static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1114{
1115 int rc;
1116
Carsten Otte847a50f2010-06-21 22:57:05 +00001117 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001118 card->info.broadcast_capable = 0;
1119 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001120 dev_info(&card->gdev->dev,
1121 "Broadcast not supported on %s\n",
1122 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001123 rc = -EOPNOTSUPP;
1124 goto out;
1125 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001126 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001127 IPA_CMD_ASS_START, 0);
1128 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001129 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1130 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001131 goto out;
1132 }
1133
Thomas Richter4d7def22015-09-18 16:06:51 +02001134 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001135 IPA_CMD_ASS_CONFIGURE, 1);
1136 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001137 dev_warn(&card->gdev->dev,
1138 "Setting up broadcast filtering for %s failed\n",
1139 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001140 goto out;
1141 }
1142 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001143 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Thomas Richter4d7def22015-09-18 16:06:51 +02001144 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001145 IPA_CMD_ASS_ENABLE, 1);
1146 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001147 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1148 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001149 goto out;
1150 }
1151 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1152out:
1153 if (card->info.broadcast_capable)
1154 card->dev->flags |= IFF_BROADCAST;
1155 else
1156 card->dev->flags &= ~IFF_BROADCAST;
1157 return rc;
1158}
1159
Frank Blaschka4a71df52008-02-15 09:19:42 +01001160static int qeth_l3_start_ipassists(struct qeth_card *card)
1161{
Carsten Otte847a50f2010-06-21 22:57:05 +00001162 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +00001163
Stefan Raspl0f547612013-01-21 02:30:20 +00001164 if (qeth_set_access_ctrl_online(card, 0))
1165 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001166 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1167 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1168 qeth_l3_start_ipa_source_mac(card); /* go on*/
1169 qeth_l3_start_ipa_vlan(card); /* go on*/
1170 qeth_l3_start_ipa_multicast(card); /* go on*/
1171 qeth_l3_start_ipa_ipv6(card); /* go on*/
1172 qeth_l3_start_ipa_broadcast(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +01001173 return 0;
1174}
1175
Frank Blaschka4a71df52008-02-15 09:19:42 +01001176static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1177 struct qeth_reply *reply, unsigned long data)
1178{
1179 struct qeth_ipa_cmd *cmd;
1180
1181 cmd = (struct qeth_ipa_cmd *) data;
1182 if (cmd->hdr.return_code == 0)
1183 memcpy(card->dev->dev_addr,
1184 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1185 else
Joe Perches18336112012-07-12 22:33:10 -07001186 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001187
1188 return 0;
1189}
1190
1191static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1192{
1193 int rc = 0;
1194 struct qeth_cmd_buffer *iob;
1195 struct qeth_ipa_cmd *cmd;
1196
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001197 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001198
1199 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1200 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001201 if (!iob)
1202 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001203 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1204 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1205 card->info.unique_id;
1206
1207 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1208 NULL);
1209 return rc;
1210}
1211
1212static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1213 struct qeth_reply *reply, unsigned long data)
1214{
1215 struct qeth_ipa_cmd *cmd;
1216
1217 cmd = (struct qeth_ipa_cmd *) data;
1218 if (cmd->hdr.return_code == 0)
1219 card->info.unique_id = *((__u16 *)
1220 &cmd->data.create_destroy_addr.unique_id[6]);
1221 else {
1222 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1223 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001224 dev_warn(&card->gdev->dev, "The network adapter failed to "
1225 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001226 }
1227 return 0;
1228}
1229
1230static int qeth_l3_get_unique_id(struct qeth_card *card)
1231{
1232 int rc = 0;
1233 struct qeth_cmd_buffer *iob;
1234 struct qeth_ipa_cmd *cmd;
1235
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001236 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001237
1238 if (!qeth_is_supported(card, IPA_IPV6)) {
1239 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1240 UNIQUE_ID_NOT_BY_CARD;
1241 return 0;
1242 }
1243
1244 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1245 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001246 if (!iob)
1247 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001248 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1249 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1250 card->info.unique_id;
1251
1252 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1253 return rc;
1254}
1255
Ursula Braun76b11f82010-01-11 02:50:50 +00001256static int
1257qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1258 unsigned long data)
1259{
1260 struct qeth_ipa_cmd *cmd;
1261 __u16 rc;
1262
1263 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1264
1265 cmd = (struct qeth_ipa_cmd *)data;
1266 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001267 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001268 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001269 switch (cmd->data.diagass.action) {
1270 case QETH_DIAGS_CMD_TRACE_QUERY:
1271 break;
1272 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001273 switch (rc) {
1274 case 0:
1275 case IPA_RC_INVALID_SUBCMD:
1276 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1277 dev_info(&card->gdev->dev, "The HiperSockets network "
1278 "traffic analyzer is deactivated\n");
1279 break;
1280 default:
1281 break;
1282 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001283 break;
1284 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001285 switch (rc) {
1286 case 0:
1287 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1288 dev_info(&card->gdev->dev, "The HiperSockets network "
1289 "traffic analyzer is activated\n");
1290 break;
1291 case IPA_RC_HARDWARE_AUTH_ERROR:
1292 dev_warn(&card->gdev->dev, "The device is not "
1293 "authorized to run as a HiperSockets network "
1294 "traffic analyzer\n");
1295 break;
1296 case IPA_RC_TRACE_ALREADY_ACTIVE:
1297 dev_warn(&card->gdev->dev, "A HiperSockets "
1298 "network traffic analyzer is already "
1299 "active in the HiperSockets LAN\n");
1300 break;
1301 default:
1302 break;
1303 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001304 break;
1305 default:
1306 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1307 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1308 }
1309
1310 return 0;
1311}
1312
1313static int
1314qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1315{
1316 struct qeth_cmd_buffer *iob;
1317 struct qeth_ipa_cmd *cmd;
1318
1319 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1320
1321 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001322 if (!iob)
1323 return -ENOMEM;
Ursula Braun76b11f82010-01-11 02:50:50 +00001324 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1325 cmd->data.diagass.subcmd_len = 16;
1326 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1327 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1328 cmd->data.diagass.action = diags_cmd;
1329 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1330}
1331
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001332static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001333{
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001334 ip_eth_mc_map(ipm, mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001335}
1336
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001337static void qeth_l3_mark_all_mc_to_be_deleted(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001338{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001339 struct qeth_ipaddr *addr;
1340 int i;
1341
1342 hash_for_each(card->ip_mc_htable, i, addr, hnode)
1343 addr->disp_flag = QETH_DISP_ADDR_DELETE;
1344
1345}
1346
1347static void qeth_l3_add_all_new_mc(struct qeth_card *card)
1348{
1349 struct qeth_ipaddr *addr;
1350 struct hlist_node *tmp;
1351 int i;
1352 int rc;
1353
1354 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1355 if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
1356 rc = qeth_l3_register_addr_entry(card, addr);
1357 if (!rc || (rc == IPA_RC_LAN_OFFLINE))
1358 addr->ref_counter = 1;
1359 else {
1360 hash_del(&addr->hnode);
1361 kfree(addr);
1362 }
1363 }
1364 }
1365
1366}
1367
1368static void qeth_l3_delete_nonused_mc(struct qeth_card *card)
1369{
1370 struct qeth_ipaddr *addr;
1371 struct hlist_node *tmp;
1372 int i;
1373 int rc;
1374
1375 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1376 if (addr->disp_flag == QETH_DISP_ADDR_DELETE) {
1377 rc = qeth_l3_deregister_addr_entry(card, addr);
1378 if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND)) {
1379 hash_del(&addr->hnode);
1380 kfree(addr);
1381 }
1382 }
1383 }
1384
1385}
1386
1387
1388static void
1389qeth_l3_add_mc_to_hash(struct qeth_card *card, struct in_device *in4_dev)
1390{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001391 struct ip_mc_list *im4;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001392 struct qeth_ipaddr *tmp, *ipm;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001393 char buf[MAX_ADDR_LEN];
1394
Carsten Otte847a50f2010-06-21 22:57:05 +00001395 QETH_CARD_TEXT(card, 4, "addmc");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001396
1397 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1398 if (!tmp)
1399 return;
1400
Sachin Santf3aa3132010-11-26 02:41:17 +00001401 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1402 im4 = rcu_dereference(im4->next_rcu)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001403 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf);
1404
1405 tmp->u.a4.addr = im4->multiaddr;
1406 memcpy(tmp->mac, buf, sizeof(tmp->mac));
1407
1408 ipm = qeth_l3_ip_from_hash(card, tmp);
1409 if (ipm) {
1410 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1411 } else {
1412 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1413 if (!ipm)
1414 continue;
1415 memcpy(ipm->mac, buf, sizeof(tmp->mac));
1416 ipm->u.a4.addr = im4->multiaddr;
1417 ipm->is_multicast = 1;
1418 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1419 hash_add(card->ip_mc_htable,
1420 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1421 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001422 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001423
1424 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001425}
1426
Jiri Pirko0347af52013-01-03 22:48:58 +00001427/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001428static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1429{
1430 struct in_device *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001431 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001432
Carsten Otte847a50f2010-06-21 22:57:05 +00001433 QETH_CARD_TEXT(card, 4, "addmcvl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001434
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001435 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001436 return;
1437
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001438 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1439 struct net_device *netdev;
1440
dingtianhongf06c7f92014-05-09 14:58:05 +08001441 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001442 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001443 if (netdev == NULL ||
1444 !(netdev->flags & IFF_UP))
1445 continue;
Jiri Pirko0347af52013-01-03 22:48:58 +00001446 in_dev = __in_dev_get_rcu(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001447 if (!in_dev)
1448 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001449 qeth_l3_add_mc_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001450 }
1451}
1452
1453static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1454{
1455 struct in_device *in4_dev;
1456
Carsten Otte847a50f2010-06-21 22:57:05 +00001457 QETH_CARD_TEXT(card, 4, "chkmcv4");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001458
Sachin Santf3aa3132010-11-26 02:41:17 +00001459 rcu_read_lock();
Jiri Pirko0347af52013-01-03 22:48:58 +00001460 in4_dev = __in_dev_get_rcu(card->dev);
1461 if (in4_dev == NULL)
1462 goto unlock;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001463 qeth_l3_add_mc_to_hash(card, in4_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001464 qeth_l3_add_vlan_mc(card);
Jiri Pirko0347af52013-01-03 22:48:58 +00001465unlock:
Sachin Santf3aa3132010-11-26 02:41:17 +00001466 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001467}
1468
1469#ifdef CONFIG_QETH_IPV6
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001470static void
1471qeth_l3_add_mc6_to_hash(struct qeth_card *card, struct inet6_dev *in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001472{
1473 struct qeth_ipaddr *ipm;
1474 struct ifmcaddr6 *im6;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001475 struct qeth_ipaddr *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001476 char buf[MAX_ADDR_LEN];
1477
Carsten Otte847a50f2010-06-21 22:57:05 +00001478 QETH_CARD_TEXT(card, 4, "addmc6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001479
1480 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1481 if (!tmp)
1482 return;
1483
Frank Blaschka4a71df52008-02-15 09:19:42 +01001484 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1485 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001486
1487 memcpy(tmp->mac, buf, sizeof(tmp->mac));
1488 memcpy(&tmp->u.a6.addr, &im6->mca_addr.s6_addr,
1489 sizeof(struct in6_addr));
1490 tmp->is_multicast = 1;
1491
1492 ipm = qeth_l3_ip_from_hash(card, tmp);
1493 if (ipm) {
1494 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1495 continue;
1496 }
1497
Frank Blaschka4a71df52008-02-15 09:19:42 +01001498 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1499 if (!ipm)
1500 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001501
Frank Blaschka4a71df52008-02-15 09:19:42 +01001502 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1503 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1504 sizeof(struct in6_addr));
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001505 ipm->is_multicast = 1;
1506 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1507 hash_add(card->ip_mc_htable,
1508 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1509
Frank Blaschka4a71df52008-02-15 09:19:42 +01001510 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001511 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001512}
1513
Jiri Pirko0347af52013-01-03 22:48:58 +00001514/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001515static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1516{
1517 struct inet6_dev *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001518 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001519
Carsten Otte847a50f2010-06-21 22:57:05 +00001520 QETH_CARD_TEXT(card, 4, "admc6vl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001521
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001522 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001523 return;
1524
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001525 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1526 struct net_device *netdev;
1527
dingtianhongf06c7f92014-05-09 14:58:05 +08001528 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001529 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001530 if (netdev == NULL ||
1531 !(netdev->flags & IFF_UP))
1532 continue;
1533 in_dev = in6_dev_get(netdev);
1534 if (!in_dev)
1535 continue;
1536 read_lock_bh(&in_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001537 qeth_l3_add_mc6_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001538 read_unlock_bh(&in_dev->lock);
1539 in6_dev_put(in_dev);
1540 }
1541}
1542
1543static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1544{
1545 struct inet6_dev *in6_dev;
1546
Carsten Otte847a50f2010-06-21 22:57:05 +00001547 QETH_CARD_TEXT(card, 4, "chkmcv6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001548
Frank Blaschka4a71df52008-02-15 09:19:42 +01001549 if (!qeth_is_supported(card, IPA_IPV6))
1550 return ;
1551 in6_dev = in6_dev_get(card->dev);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001552 if (!in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001553 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001554
Jiri Pirko0347af52013-01-03 22:48:58 +00001555 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001556 read_lock_bh(&in6_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001557 qeth_l3_add_mc6_to_hash(card, in6_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001558 qeth_l3_add_vlan_mc6(card);
1559 read_unlock_bh(&in6_dev->lock);
Jiri Pirko0347af52013-01-03 22:48:58 +00001560 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001561 in6_dev_put(in6_dev);
1562}
1563#endif /* CONFIG_QETH_IPV6 */
1564
1565static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1566 unsigned short vid)
1567{
1568 struct in_device *in_dev;
1569 struct in_ifaddr *ifa;
1570 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001571 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001572
Carsten Otte847a50f2010-06-21 22:57:05 +00001573 QETH_CARD_TEXT(card, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001574
dingtianhongf06c7f92014-05-09 14:58:05 +08001575 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
frank.blaschka@de.ibm.comeabfbe62012-07-24 22:34:29 +00001576 if (!netdev)
1577 return;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001578 in_dev = in_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001579 if (!in_dev)
1580 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001581
1582 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1583 if (!addr)
1584 return;
1585
1586 spin_lock_bh(&card->ip_lock);
1587
Frank Blaschka4a71df52008-02-15 09:19:42 +01001588 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001589 addr->u.a4.addr = ifa->ifa_address;
1590 addr->u.a4.mask = ifa->ifa_mask;
1591 addr->type = QETH_IP_TYPE_NORMAL;
1592 qeth_l3_delete_ip(card, addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001593 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001594
1595 spin_unlock_bh(&card->ip_lock);
1596
1597 kfree(addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001598 in_dev_put(in_dev);
1599}
1600
1601static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1602 unsigned short vid)
1603{
1604#ifdef CONFIG_QETH_IPV6
1605 struct inet6_dev *in6_dev;
1606 struct inet6_ifaddr *ifa;
1607 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001608 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001609
Carsten Otte847a50f2010-06-21 22:57:05 +00001610 QETH_CARD_TEXT(card, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001611
dingtianhongf06c7f92014-05-09 14:58:05 +08001612 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
frank.blaschka@de.ibm.comeabfbe62012-07-24 22:34:29 +00001613 if (!netdev)
1614 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001615
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001616 in6_dev = in6_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001617 if (!in6_dev)
1618 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001619
1620 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1621 if (!addr)
1622 return;
1623
1624 spin_lock_bh(&card->ip_lock);
1625
Frank Blaschka70f60a22010-03-22 09:59:48 -07001626 list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001627 memcpy(&addr->u.a6.addr, &ifa->addr,
1628 sizeof(struct in6_addr));
1629 addr->u.a6.pfxlen = ifa->prefix_len;
1630 addr->type = QETH_IP_TYPE_NORMAL;
1631 qeth_l3_delete_ip(card, addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001632 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001633
1634 spin_unlock_bh(&card->ip_lock);
1635
1636 kfree(addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001637 in6_dev_put(in6_dev);
1638#endif /* CONFIG_QETH_IPV6 */
1639}
1640
1641static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1642 unsigned short vid)
1643{
Jiri Pirko0347af52013-01-03 22:48:58 +00001644 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001645 qeth_l3_free_vlan_addresses4(card, vid);
1646 qeth_l3_free_vlan_addresses6(card, vid);
Jiri Pirko0347af52013-01-03 22:48:58 +00001647 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001648}
1649
Patrick McHardy80d5c362013-04-19 02:04:28 +00001650static int qeth_l3_vlan_rx_add_vid(struct net_device *dev,
1651 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001652{
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001653 struct qeth_card *card = dev->ml_priv;
1654
1655 set_bit(vid, card->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001656 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001657}
1658
Patrick McHardy80d5c362013-04-19 02:04:28 +00001659static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev,
1660 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001661{
Heiko Carstens509e2562008-07-26 02:24:10 -07001662 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001663
Carsten Otte847a50f2010-06-21 22:57:05 +00001664 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001665
Ursula Braun8e98ac42009-03-24 20:57:18 +00001666 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001667 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -05001668 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +00001669 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001670 /* unregister IP addresses of vlan device */
1671 qeth_l3_free_vlan_addresses(card, vid);
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001672 clear_bit(vid, card->active_vlans);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001673 qeth_l3_set_multicast_list(card->dev);
Jiri Pirko8e586132011-12-08 19:52:37 -05001674 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001675}
1676
Ursula Braun10651db2010-10-01 02:51:13 +00001677static inline int qeth_l3_rebuild_skb(struct qeth_card *card,
1678 struct sk_buff *skb, struct qeth_hdr *hdr,
1679 unsigned short *vlan_id)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001680{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001681 __be16 prot;
1682 struct iphdr *ip_hdr;
1683 unsigned char tg_addr[MAX_ADDR_LEN];
Ursula Braun10651db2010-10-01 02:51:13 +00001684 int is_vlan = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001685
1686 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1687 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
1688 ETH_P_IP);
1689 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1690 case QETH_CAST_MULTICAST:
1691 switch (prot) {
1692#ifdef CONFIG_QETH_IPV6
1693 case __constant_htons(ETH_P_IPV6):
1694 ndisc_mc_map((struct in6_addr *)
1695 skb->data + 24,
1696 tg_addr, card->dev, 0);
1697 break;
1698#endif
1699 case __constant_htons(ETH_P_IP):
1700 ip_hdr = (struct iphdr *)skb->data;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001701 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1702 break;
1703 default:
1704 memcpy(tg_addr, card->dev->broadcast,
1705 card->dev->addr_len);
1706 }
1707 card->stats.multicast++;
1708 skb->pkt_type = PACKET_MULTICAST;
1709 break;
1710 case QETH_CAST_BROADCAST:
1711 memcpy(tg_addr, card->dev->broadcast,
1712 card->dev->addr_len);
1713 card->stats.multicast++;
1714 skb->pkt_type = PACKET_BROADCAST;
1715 break;
1716 case QETH_CAST_UNICAST:
1717 case QETH_CAST_ANYCAST:
1718 case QETH_CAST_NOCAST:
1719 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00001720 if (card->options.sniffer)
1721 skb->pkt_type = PACKET_OTHERHOST;
1722 else
1723 skb->pkt_type = PACKET_HOST;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001724 memcpy(tg_addr, card->dev->dev_addr,
1725 card->dev->addr_len);
1726 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001727 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1728 card->dev->header_ops->create(skb, card->dev, prot,
1729 tg_addr, &hdr->hdr.l3.dest_addr[2],
1730 card->dev->addr_len);
1731 else
1732 card->dev->header_ops->create(skb, card->dev, prot,
1733 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001734 }
1735
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001736 skb->protocol = eth_type_trans(skb, card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001737
1738 if (hdr->hdr.l3.ext_flags &
1739 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
Ursula Braun10651db2010-10-01 02:51:13 +00001740 *vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
Frank Blaschka4a71df52008-02-15 09:19:42 +01001741 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
Ursula Braun10651db2010-10-01 02:51:13 +00001742 is_vlan = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001743 }
1744
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001745 if (card->dev->features & NETIF_F_RXCSUM) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001746 if ((hdr->hdr.l3.ext_flags &
Ursula Braunb9139802009-05-19 21:38:40 +00001747 (QETH_HDR_EXT_CSUM_HDR_REQ |
1748 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1749 (QETH_HDR_EXT_CSUM_HDR_REQ |
1750 QETH_HDR_EXT_CSUM_TRANSP_REQ))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001751 skb->ip_summed = CHECKSUM_UNNECESSARY;
1752 else
Ursula Braunb9139802009-05-19 21:38:40 +00001753 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001754 } else
1755 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun10651db2010-10-01 02:51:13 +00001756 return is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001757}
1758
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001759static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1760 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001761{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001762 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001763 struct sk_buff *skb;
1764 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001765 __u16 vlan_tag = 0;
Ursula Braun10651db2010-10-01 02:51:13 +00001766 int is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001767 unsigned int len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001768 __u16 magic;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001769
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001770 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +00001771 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001772 while (budget) {
1773 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +00001774 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001775 &card->rx.b_element, &card->rx.e_offset, &hdr);
1776 if (!skb) {
1777 *done = 1;
1778 break;
1779 }
1780 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001781 switch (hdr->hdr.l3.id) {
1782 case QETH_HEADER_TYPE_LAYER3:
Frank Blaschkab3332932011-08-08 01:33:59 +00001783 magic = *(__u16 *)skb->data;
1784 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
1785 (magic == ETH_P_AF_IUCV)) {
1786 skb->protocol = ETH_P_AF_IUCV;
1787 skb->pkt_type = PACKET_HOST;
1788 skb->mac_header = NET_SKB_PAD;
1789 skb->dev = card->dev;
1790 len = skb->len;
1791 card->dev->header_ops->create(skb, card->dev, 0,
1792 card->dev->dev_addr, "FAKELL",
1793 card->dev->addr_len);
1794 netif_receive_skb(skb);
1795 } else {
1796 is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
Ursula Braun10651db2010-10-01 02:51:13 +00001797 &vlan_tag);
Frank Blaschkab3332932011-08-08 01:33:59 +00001798 len = skb->len;
1799 if (is_vlan && !card->options.sniffer)
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001800 __vlan_hwaccel_put_tag(skb,
1801 htons(ETH_P_8021Q), vlan_tag);
Frank Blaschkab3332932011-08-08 01:33:59 +00001802 napi_gro_receive(&card->napi, skb);
1803 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001804 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00001805 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
1806 skb->pkt_type = PACKET_HOST;
1807 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00001808 len = skb->len;
1809 netif_receive_skb(skb);
1810 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001811 default:
1812 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00001813 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001814 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001815 continue;
1816 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001817 work_done++;
1818 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001819 card->stats.rx_packets++;
1820 card->stats.rx_bytes += len;
1821 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001822 return work_done;
1823}
1824
1825static int qeth_l3_poll(struct napi_struct *napi, int budget)
1826{
1827 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
1828 int work_done = 0;
1829 struct qeth_qdio_buffer *buffer;
1830 int done;
1831 int new_budget = budget;
1832
1833 if (card->options.performance_stats) {
1834 card->perf_stats.inbound_cnt++;
1835 card->perf_stats.inbound_start_time = qeth_get_micros();
1836 }
1837
1838 while (1) {
1839 if (!card->rx.b_count) {
1840 card->rx.qdio_err = 0;
1841 card->rx.b_count = qdio_get_next_buffers(
1842 card->data.ccwdev, 0, &card->rx.b_index,
1843 &card->rx.qdio_err);
1844 if (card->rx.b_count <= 0) {
1845 card->rx.b_count = 0;
1846 break;
1847 }
1848 card->rx.b_element =
1849 &card->qdio.in_q->bufs[card->rx.b_index]
1850 .buffer->element[0];
1851 card->rx.e_offset = 0;
1852 }
1853
1854 while (card->rx.b_count) {
1855 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
1856 if (!(card->rx.qdio_err &&
1857 qeth_check_qdio_errors(card, buffer->buffer,
1858 card->rx.qdio_err, "qinerr")))
1859 work_done += qeth_l3_process_inbound_buffer(
1860 card, new_budget, &done);
1861 else
1862 done = 1;
1863
1864 if (done) {
1865 if (card->options.performance_stats)
1866 card->perf_stats.bufs_rec++;
1867 qeth_put_buffer_pool_entry(card,
1868 buffer->pool_entry);
1869 qeth_queue_input_buffer(card, card->rx.b_index);
1870 card->rx.b_count--;
1871 if (card->rx.b_count) {
1872 card->rx.b_index =
1873 (card->rx.b_index + 1) %
1874 QDIO_MAX_BUFFERS_PER_Q;
1875 card->rx.b_element =
1876 &card->qdio.in_q
1877 ->bufs[card->rx.b_index]
1878 .buffer->element[0];
1879 card->rx.e_offset = 0;
1880 }
1881 }
1882
1883 if (work_done >= budget)
1884 goto out;
1885 else
1886 new_budget = budget - work_done;
1887 }
1888 }
1889
1890 napi_complete(napi);
1891 if (qdio_start_irq(card->data.ccwdev, 0))
1892 napi_schedule(&card->napi);
1893out:
1894 if (card->options.performance_stats)
1895 card->perf_stats.inbound_time += qeth_get_micros() -
1896 card->perf_stats.inbound_start_time;
1897 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001898}
1899
1900static int qeth_l3_verify_vlan_dev(struct net_device *dev,
1901 struct qeth_card *card)
1902{
1903 int rc = 0;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001904 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001905
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001906 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1907 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001908
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001909 rcu_read_lock();
dingtianhongf06c7f92014-05-09 14:58:05 +08001910 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001911 vid);
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001912 rcu_read_unlock();
1913 if (netdev == dev) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001914 rc = QETH_VLAN_CARD;
1915 break;
1916 }
1917 }
1918
Heiko Carstens509e2562008-07-26 02:24:10 -07001919 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001920 return 0;
1921
1922 return rc;
1923}
1924
1925static int qeth_l3_verify_dev(struct net_device *dev)
1926{
1927 struct qeth_card *card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001928 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001929 unsigned long flags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001930
1931 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
1932 list_for_each_entry(card, &qeth_core_card_list.list, list) {
1933 if (card->dev == dev) {
1934 rc = QETH_REAL_CARD;
1935 break;
1936 }
1937 rc = qeth_l3_verify_vlan_dev(dev, card);
1938 if (rc)
1939 break;
1940 }
1941 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
1942
1943 return rc;
1944}
1945
1946static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
1947{
1948 struct qeth_card *card = NULL;
1949 int rc;
1950
1951 rc = qeth_l3_verify_dev(dev);
1952 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07001953 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001954 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07001955 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02001956 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001957 card = NULL;
Carsten Otte847a50f2010-06-21 22:57:05 +00001958 if (card)
1959 QETH_CARD_TEXT_(card, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001960 return card ;
1961}
1962
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +02001963static void qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001964{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001965 QETH_DBF_TEXT(SETUP, 2, "stopcard");
1966 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001967
1968 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00001969 if (card->options.sniffer &&
1970 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
1971 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001972 if (card->read.state == CH_STATE_UP &&
1973 card->write.state == CH_STATE_UP &&
1974 (card->state == CARD_STATE_UP)) {
1975 if (recovery_mode)
1976 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02001977 else {
Ursula Braun869da902010-03-08 20:36:56 +00001978 rtnl_lock();
1979 dev_close(card->dev);
1980 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02001981 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001982 card->state = CARD_STATE_SOFTSETUP;
1983 }
1984 if (card->state == CARD_STATE_SOFTSETUP) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001985 qeth_l3_clear_ip_htable(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001986 qeth_clear_ipacmd_list(card);
1987 card->state = CARD_STATE_HARDSETUP;
1988 }
1989 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001990 qeth_qdio_clear_card(card, 0);
1991 qeth_clear_qdio_buffers(card);
1992 qeth_clear_working_pool_list(card);
1993 card->state = CARD_STATE_DOWN;
1994 }
1995 if (card->state == CARD_STATE_DOWN) {
1996 qeth_clear_cmd_buffers(&card->read);
1997 qeth_clear_cmd_buffers(&card->write);
1998 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001999}
2000
Ursula Braun76b11f82010-01-11 02:50:50 +00002001/*
2002 * test for and Switch promiscuous mode (on or off)
2003 * either for guestlan or HiperSocket Sniffer
2004 */
2005static void
2006qeth_l3_handle_promisc_mode(struct qeth_card *card)
2007{
2008 struct net_device *dev = card->dev;
2009
2010 if (((dev->flags & IFF_PROMISC) &&
2011 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
2012 (!(dev->flags & IFF_PROMISC) &&
2013 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
2014 return;
2015
2016 if (card->info.guestlan) { /* Guestlan trace */
2017 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2018 qeth_setadp_promisc_mode(card);
2019 } else if (card->options.sniffer && /* HiperSockets trace */
2020 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
2021 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002022 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002023 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
2024 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00002025 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002026 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2027 }
2028 }
2029}
2030
Frank Blaschka4a71df52008-02-15 09:19:42 +01002031static void qeth_l3_set_multicast_list(struct net_device *dev)
2032{
Heiko Carstens509e2562008-07-26 02:24:10 -07002033 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002034
Carsten Otte847a50f2010-06-21 22:57:05 +00002035 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00002036 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
2037 (card->state != CARD_STATE_UP))
2038 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00002039 if (!card->options.sniffer) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002040
2041 spin_lock_bh(&card->mclock);
2042
2043 qeth_l3_mark_all_mc_to_be_deleted(card);
2044
Ursula Braun76b11f82010-01-11 02:50:50 +00002045 qeth_l3_add_multicast_ipv4(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002046#ifdef CONFIG_QETH_IPV6
Ursula Braun76b11f82010-01-11 02:50:50 +00002047 qeth_l3_add_multicast_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002048#endif
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002049 qeth_l3_delete_nonused_mc(card);
2050 qeth_l3_add_all_new_mc(card);
2051
2052 spin_unlock_bh(&card->mclock);
2053
Ursula Braun76b11f82010-01-11 02:50:50 +00002054 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2055 return;
2056 }
2057 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002058}
2059
2060static const char *qeth_l3_arp_get_error_cause(int *rc)
2061{
2062 switch (*rc) {
2063 case QETH_IPA_ARP_RC_FAILED:
2064 *rc = -EIO;
2065 return "operation failed";
2066 case QETH_IPA_ARP_RC_NOTSUPP:
2067 *rc = -EOPNOTSUPP;
2068 return "operation not supported";
2069 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2070 *rc = -EINVAL;
2071 return "argument out of range";
2072 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2073 *rc = -EOPNOTSUPP;
2074 return "query operation not supported";
2075 case QETH_IPA_ARP_RC_Q_NO_DATA:
2076 *rc = -ENOENT;
2077 return "no query data available";
2078 default:
2079 return "unknown error";
2080 }
2081}
2082
2083static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2084{
2085 int tmp;
2086 int rc;
2087
Carsten Otte847a50f2010-06-21 22:57:05 +00002088 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002089
2090 /*
2091 * currently GuestLAN only supports the ARP assist function
2092 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2093 * thus we say EOPNOTSUPP for this ARP function
2094 */
2095 if (card->info.guestlan)
2096 return -EOPNOTSUPP;
2097 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002098 return -EOPNOTSUPP;
2099 }
Thomas Richter4d7def22015-09-18 16:06:51 +02002100 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002101 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2102 no_entries);
2103 if (rc) {
2104 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002105 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2106 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002107 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2108 }
2109 return rc;
2110}
2111
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002112static __u32 get_arp_entry_size(struct qeth_card *card,
2113 struct qeth_arp_query_data *qdata,
2114 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002115{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002116 __u32 rc;
2117 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002118
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002119 is_hsi = qdata->reply_bits == 5;
2120 if (type->ip == QETHARP_IP_ADDR_V4) {
2121 QETH_CARD_TEXT(card, 4, "arpev4");
2122 if (strip_entries) {
2123 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
2124 sizeof(struct qeth_arp_qi_entry7_short);
2125 } else {
2126 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
2127 sizeof(struct qeth_arp_qi_entry7);
2128 }
2129 } else if (type->ip == QETHARP_IP_ADDR_V6) {
2130 QETH_CARD_TEXT(card, 4, "arpev6");
2131 if (strip_entries) {
2132 rc = is_hsi ?
2133 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
2134 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
2135 } else {
2136 rc = is_hsi ?
2137 sizeof(struct qeth_arp_qi_entry5_ipv6) :
2138 sizeof(struct qeth_arp_qi_entry7_ipv6);
2139 }
2140 } else {
2141 QETH_CARD_TEXT(card, 4, "arpinv");
2142 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002143 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002144
2145 return rc;
2146}
2147
2148static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
2149{
2150 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
2151 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002152}
2153
2154static int qeth_l3_arp_query_cb(struct qeth_card *card,
2155 struct qeth_reply *reply, unsigned long data)
2156{
2157 struct qeth_ipa_cmd *cmd;
2158 struct qeth_arp_query_data *qdata;
2159 struct qeth_arp_query_info *qinfo;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002160 int i;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002161 int e;
2162 int entrybytes_done;
2163 int stripped_bytes;
2164 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002165
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002166 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002167
2168 qinfo = (struct qeth_arp_query_info *) reply->param;
2169 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002170 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002171 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002172 QETH_CARD_TEXT(card, 4, "arpcberr");
2173 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002174 return 0;
2175 }
2176 if (cmd->data.setassparms.hdr.return_code) {
2177 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002178 QETH_CARD_TEXT(card, 4, "setaperr");
2179 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002180 return 0;
2181 }
2182 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00002183 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002184
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002185 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
2186 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
2187 entrybytes_done = 0;
2188 for (e = 0; e < qdata->no_entries; ++e) {
2189 char *cur_entry;
2190 __u32 esize;
2191 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002192
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002193 cur_entry = &qdata->data + entrybytes_done;
2194 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
2195 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
2196 QETH_CARD_TEXT(card, 4, "pmis");
2197 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
2198 break;
2199 }
2200 esize = get_arp_entry_size(card, qdata, etype,
2201 do_strip_entries);
2202 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
2203 if (!esize)
2204 break;
2205
2206 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
2207 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
Ursula Braune0a81142012-03-07 02:06:28 +00002208 cmd->hdr.return_code = IPA_RC_ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002209 goto out_error;
2210 }
2211
2212 memcpy(qinfo->udata + qinfo->udata_offset,
2213 &qdata->data + entrybytes_done + stripped_bytes,
2214 esize);
2215 entrybytes_done += esize + stripped_bytes;
2216 qinfo->udata_offset += esize;
2217 ++qinfo->no_entries;
2218 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002219 /* check if all replies received ... */
2220 if (cmd->data.setassparms.hdr.seq_no <
2221 cmd->data.setassparms.hdr.number_of_replies)
2222 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002223 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002224 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2225 /* keep STRIP_ENTRIES flag so the user program can distinguish
2226 * stripped entries from normal ones */
2227 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2228 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2229 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002230 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002231 return 0;
2232out_error:
2233 i = 0;
2234 memcpy(qinfo->udata, &i, 4);
2235 return 0;
2236}
2237
2238static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2239 struct qeth_cmd_buffer *iob, int len,
2240 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2241 unsigned long),
2242 void *reply_param)
2243{
Carsten Otte847a50f2010-06-21 22:57:05 +00002244 QETH_CARD_TEXT(card, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002245
2246 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2247 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2248 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2249 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2250 reply_cb, reply_param);
2251}
2252
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002253static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
2254 enum qeth_prot_versions prot,
2255 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002256{
2257 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002258 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002259 int tmp;
2260 int rc;
2261
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002262 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
2263
Thomas Richterb475e312015-12-11 12:27:54 +01002264 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2265 IPA_CMD_ASS_ARP_QUERY_INFO,
2266 sizeof(struct qeth_arp_query_data)
2267 - sizeof(char),
2268 prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002269 if (!iob)
2270 return -ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002271 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2272 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
2273 cmd->data.setassparms.data.query_arp.reply_bits = 0;
2274 cmd->data.setassparms.data.query_arp.no_entries = 0;
2275 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2276 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2277 qeth_l3_arp_query_cb, (void *)qinfo);
2278 if (rc) {
2279 tmp = rc;
2280 QETH_DBF_MESSAGE(2,
2281 "Error while querying ARP cache on %s: %s "
2282 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2283 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2284 }
2285
2286 return rc;
2287}
2288
2289static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2290{
2291 struct qeth_arp_query_info qinfo = {0, };
2292 int rc;
2293
Carsten Otte847a50f2010-06-21 22:57:05 +00002294 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002295
2296 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2297 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002298 QETH_CARD_TEXT(card, 3, "arpqnsup");
2299 rc = -EOPNOTSUPP;
2300 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002301 }
2302 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002303 if (copy_from_user(&qinfo, udata, 6)) {
2304 rc = -EFAULT;
2305 goto out;
2306 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002307 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002308 if (!qinfo.udata) {
2309 rc = -ENOMEM;
2310 goto out;
2311 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002312 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002313 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002314 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002315 if (copy_to_user(udata, qinfo.udata, 4))
2316 rc = -EFAULT;
Sebastian Ott77a83ed2016-06-16 16:19:03 +02002317 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002318 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02002319#ifdef CONFIG_QETH_IPV6
2320 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
2321 /* fails in case of GuestLAN QDIO mode */
2322 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6, &qinfo);
2323 }
2324#endif
2325 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
2326 QETH_CARD_TEXT(card, 4, "qactf");
2327 rc = -EFAULT;
2328 goto free_and_out;
2329 }
2330 QETH_CARD_TEXT(card, 4, "qacts");
2331
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002332free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002333 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002334out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002335 return rc;
2336}
2337
2338static int qeth_l3_arp_add_entry(struct qeth_card *card,
2339 struct qeth_arp_cache_entry *entry)
2340{
2341 struct qeth_cmd_buffer *iob;
2342 char buf[16];
2343 int tmp;
2344 int rc;
2345
Carsten Otte847a50f2010-06-21 22:57:05 +00002346 QETH_CARD_TEXT(card, 3, "arpadent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002347
2348 /*
2349 * currently GuestLAN only supports the ARP assist function
2350 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
2351 * thus we say EOPNOTSUPP for this ARP function
2352 */
2353 if (card->info.guestlan)
2354 return -EOPNOTSUPP;
2355 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002356 return -EOPNOTSUPP;
2357 }
2358
Thomas Richterb475e312015-12-11 12:27:54 +01002359 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002360 IPA_CMD_ASS_ARP_ADD_ENTRY,
2361 sizeof(struct qeth_arp_cache_entry),
2362 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002363 if (!iob)
2364 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +02002365 rc = qeth_send_setassparms(card, iob,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002366 sizeof(struct qeth_arp_cache_entry),
2367 (unsigned long) entry,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002368 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002369 if (rc) {
2370 tmp = rc;
2371 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002372 QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
2373 "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2374 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002375 }
2376 return rc;
2377}
2378
2379static int qeth_l3_arp_remove_entry(struct qeth_card *card,
2380 struct qeth_arp_cache_entry *entry)
2381{
2382 struct qeth_cmd_buffer *iob;
2383 char buf[16] = {0, };
2384 int tmp;
2385 int rc;
2386
Carsten Otte847a50f2010-06-21 22:57:05 +00002387 QETH_CARD_TEXT(card, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002388
2389 /*
2390 * currently GuestLAN only supports the ARP assist function
2391 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2392 * thus we say EOPNOTSUPP for this ARP function
2393 */
2394 if (card->info.guestlan)
2395 return -EOPNOTSUPP;
2396 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002397 return -EOPNOTSUPP;
2398 }
2399 memcpy(buf, entry, 12);
Thomas Richterb475e312015-12-11 12:27:54 +01002400 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002401 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2402 12,
2403 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002404 if (!iob)
2405 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +02002406 rc = qeth_send_setassparms(card, iob,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002407 12, (unsigned long)buf,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002408 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002409 if (rc) {
2410 tmp = rc;
2411 memset(buf, 0, 16);
2412 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002413 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2414 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2415 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002416 }
2417 return rc;
2418}
2419
2420static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2421{
2422 int rc;
2423 int tmp;
2424
Carsten Otte847a50f2010-06-21 22:57:05 +00002425 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002426
2427 /*
2428 * currently GuestLAN only supports the ARP assist function
2429 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2430 * thus we say EOPNOTSUPP for this ARP function
2431 */
2432 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2433 return -EOPNOTSUPP;
2434 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002435 return -EOPNOTSUPP;
2436 }
Thomas Richter4d7def22015-09-18 16:06:51 +02002437 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002438 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2439 if (rc) {
2440 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002441 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2442 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002443 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2444 }
2445 return rc;
2446}
2447
2448static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2449{
Heiko Carstens509e2562008-07-26 02:24:10 -07002450 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002451 struct qeth_arp_cache_entry arp_entry;
2452 struct mii_ioctl_data *mii_data;
2453 int rc = 0;
2454
2455 if (!card)
2456 return -ENODEV;
2457
Eugene Crosserc3521252015-01-16 14:05:47 +01002458 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002459 return -ENODEV;
2460
2461 switch (cmd) {
2462 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2463 if (!capable(CAP_NET_ADMIN)) {
2464 rc = -EPERM;
2465 break;
2466 }
2467 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2468 break;
2469 case SIOC_QETH_ARP_QUERY_INFO:
2470 if (!capable(CAP_NET_ADMIN)) {
2471 rc = -EPERM;
2472 break;
2473 }
2474 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2475 break;
2476 case SIOC_QETH_ARP_ADD_ENTRY:
2477 if (!capable(CAP_NET_ADMIN)) {
2478 rc = -EPERM;
2479 break;
2480 }
2481 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2482 sizeof(struct qeth_arp_cache_entry)))
2483 rc = -EFAULT;
2484 else
2485 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2486 break;
2487 case SIOC_QETH_ARP_REMOVE_ENTRY:
2488 if (!capable(CAP_NET_ADMIN)) {
2489 rc = -EPERM;
2490 break;
2491 }
2492 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2493 sizeof(struct qeth_arp_cache_entry)))
2494 rc = -EFAULT;
2495 else
2496 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2497 break;
2498 case SIOC_QETH_ARP_FLUSH_CACHE:
2499 if (!capable(CAP_NET_ADMIN)) {
2500 rc = -EPERM;
2501 break;
2502 }
2503 rc = qeth_l3_arp_flush_cache(card);
2504 break;
2505 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2506 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2507 break;
2508 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +00002509 if ((card->info.type == QETH_CARD_TYPE_OSD ||
2510 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01002511 !card->info.guestlan)
2512 return 1;
2513 return 0;
2514 break;
2515 case SIOCGMIIPHY:
2516 mii_data = if_mii(rq);
2517 mii_data->phy_id = 0;
2518 break;
2519 case SIOCGMIIREG:
2520 mii_data = if_mii(rq);
2521 if (mii_data->phy_id != 0)
2522 rc = -EINVAL;
2523 else
2524 mii_data->val_out = qeth_mdio_read(dev,
2525 mii_data->phy_id,
2526 mii_data->reg_num);
2527 break;
Frank Blaschkac3ab96f2012-02-08 00:19:49 +00002528 case SIOC_QETH_QUERY_OAT:
2529 rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data);
2530 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002531 default:
2532 rc = -EOPNOTSUPP;
2533 }
2534 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00002535 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002536 return rc;
2537}
2538
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002539int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2540{
2541 int cast_type = RTN_UNSPEC;
David S. Miller69cce1d2011-07-17 23:09:49 -07002542 struct neighbour *n = NULL;
2543 struct dst_entry *dst;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002544
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002545 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002546 dst = skb_dst(skb);
2547 if (dst)
David S. Miller24db1ba2012-07-02 22:02:33 -07002548 n = dst_neigh_lookup_skb(dst, skb);
David S. Miller69cce1d2011-07-17 23:09:49 -07002549 if (n) {
2550 cast_type = n->type;
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002551 rcu_read_unlock();
David S. Miller24db1ba2012-07-02 22:02:33 -07002552 neigh_release(n);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002553 if ((cast_type == RTN_BROADCAST) ||
2554 (cast_type == RTN_MULTICAST) ||
2555 (cast_type == RTN_ANYCAST))
2556 return cast_type;
2557 else
2558 return RTN_UNSPEC;
2559 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002560 rcu_read_unlock();
2561
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002562 /* try something else */
2563 if (skb->protocol == ETH_P_IPV6)
2564 return (skb_network_header(skb)[24] == 0xff) ?
2565 RTN_MULTICAST : 0;
2566 else if (skb->protocol == ETH_P_IP)
2567 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2568 RTN_MULTICAST : 0;
2569 /* ... */
2570 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2571 return RTN_BROADCAST;
2572 else {
2573 u16 hdr_mac;
2574
2575 hdr_mac = *((u16 *)skb->data);
2576 /* tr multicast? */
2577 switch (card->info.link_type) {
2578 case QETH_LINK_TYPE_HSTR:
2579 case QETH_LINK_TYPE_LANE_TR:
2580 if ((hdr_mac == QETH_TR_MAC_NC) ||
2581 (hdr_mac == QETH_TR_MAC_C))
2582 return RTN_MULTICAST;
2583 break;
2584 /* eth or so multicast? */
2585 default:
2586 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2587 (hdr_mac == QETH_ETH_MAC_V6))
2588 return RTN_MULTICAST;
2589 }
2590 }
2591 return cast_type;
2592}
2593
Frank Blaschkab3332932011-08-08 01:33:59 +00002594static void qeth_l3_fill_af_iucv_hdr(struct qeth_card *card,
2595 struct qeth_hdr *hdr, struct sk_buff *skb)
2596{
2597 char daddr[16];
2598 struct af_iucv_trans_hdr *iucv_hdr;
2599
2600 skb_pull(skb, 14);
2601 card->dev->header_ops->create(skb, card->dev, 0,
2602 card->dev->dev_addr, card->dev->dev_addr,
2603 card->dev->addr_len);
2604 skb_pull(skb, 14);
2605 iucv_hdr = (struct af_iucv_trans_hdr *)skb->data;
2606 memset(hdr, 0, sizeof(struct qeth_hdr));
2607 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2608 hdr->hdr.l3.ext_flags = 0;
2609 hdr->hdr.l3.length = skb->len;
2610 hdr->hdr.l3.flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
2611 memset(daddr, 0, sizeof(daddr));
2612 daddr[0] = 0xfe;
2613 daddr[1] = 0x80;
2614 memcpy(&daddr[8], iucv_hdr->destUserID, 8);
2615 memcpy(hdr->hdr.l3.dest_addr, daddr, 16);
2616}
2617
Frank Blaschka4a71df52008-02-15 09:19:42 +01002618static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2619 struct sk_buff *skb, int ipv, int cast_type)
2620{
David S. Miller69cce1d2011-07-17 23:09:49 -07002621 struct dst_entry *dst;
2622
Frank Blaschka4a71df52008-02-15 09:19:42 +01002623 memset(hdr, 0, sizeof(struct qeth_hdr));
2624 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2625 hdr->hdr.l3.ext_flags = 0;
2626
2627 /*
2628 * before we're going to overwrite this location with next hop ip.
2629 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2630 */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002631 if (skb_vlan_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002632 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2633 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2634 else
2635 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002636 hdr->hdr.l3.vlan_id = skb_vlan_tag_get(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002637 }
2638
2639 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002640
2641 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002642 dst = skb_dst(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002643 if (ipv == 4) {
David Miller87e75972012-02-01 10:49:17 +00002644 struct rtable *rt = (struct rtable *) dst;
2645 __be32 *pkey = &ip_hdr(skb)->daddr;
2646
2647 if (rt->rt_gateway)
2648 pkey = &rt->rt_gateway;
2649
Frank Blaschka4a71df52008-02-15 09:19:42 +01002650 /* IPv4 */
2651 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2652 memset(hdr->hdr.l3.dest_addr, 0, 12);
David Miller87e75972012-02-01 10:49:17 +00002653 *((__be32 *) (&hdr->hdr.l3.dest_addr[12])) = *pkey;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002654 } else if (ipv == 6) {
David Miller87e75972012-02-01 10:49:17 +00002655 struct rt6_info *rt = (struct rt6_info *) dst;
2656 struct in6_addr *pkey = &ipv6_hdr(skb)->daddr;
2657
2658 if (!ipv6_addr_any(&rt->rt6i_gateway))
2659 pkey = &rt->rt6i_gateway;
2660
Frank Blaschka4a71df52008-02-15 09:19:42 +01002661 /* IPv6 */
2662 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2663 if (card->info.type == QETH_CARD_TYPE_IQD)
2664 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
David Miller87e75972012-02-01 10:49:17 +00002665 memcpy(hdr->hdr.l3.dest_addr, pkey, 16);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002666 } else {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002667 if (!memcmp(skb->data + sizeof(struct qeth_hdr),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002668 skb->dev->broadcast, 6)) {
2669 /* broadcast? */
2670 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2671 QETH_HDR_PASSTHRU;
2672 } else {
2673 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2674 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2675 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2676 }
2677 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002678 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002679}
2680
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002681static inline void qeth_l3_hdr_csum(struct qeth_card *card,
2682 struct qeth_hdr *hdr, struct sk_buff *skb)
2683{
2684 struct iphdr *iph = ip_hdr(skb);
2685
2686 /* tcph->check contains already the pseudo hdr checksum
2687 * so just set the header flags
2688 */
2689 if (iph->protocol == IPPROTO_UDP)
2690 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
Frank Blaschka16c0f932011-01-12 20:42:25 +00002691 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
2692 QETH_HDR_EXT_CSUM_HDR_REQ;
2693 iph->check = 0;
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002694 if (card->options.performance_stats)
2695 card->perf_stats.tx_csum++;
2696}
2697
Frank Blaschka64ef8952009-03-24 20:57:16 +00002698static void qeth_tso_fill_header(struct qeth_card *card,
2699 struct qeth_hdr *qhdr, struct sk_buff *skb)
2700{
2701 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2702 struct tcphdr *tcph = tcp_hdr(skb);
2703 struct iphdr *iph = ip_hdr(skb);
2704 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2705
2706 /*fix header to TSO values ...*/
2707 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
Frank Blaschka8fa92082010-11-26 02:41:20 +00002708 hdr->hdr.hdr.l3.length = skb->len - sizeof(struct qeth_hdr_tso);
Frank Blaschka64ef8952009-03-24 20:57:16 +00002709 /*set values which are fix for the first approach ...*/
2710 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2711 hdr->ext.imb_hdr_no = 1;
2712 hdr->ext.hdr_type = 1;
2713 hdr->ext.hdr_version = 1;
2714 hdr->ext.hdr_len = 28;
2715 /*insert non-fix values */
2716 hdr->ext.mss = skb_shinfo(skb)->gso_size;
2717 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
2718 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2719 sizeof(struct qeth_hdr_tso));
2720 tcph->check = 0;
2721 if (skb->protocol == ETH_P_IPV6) {
2722 ip6h->payload_len = 0;
2723 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2724 0, IPPROTO_TCP, 0);
2725 } else {
2726 /*OSA want us to set these values ...*/
2727 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2728 0, IPPROTO_TCP, 0);
2729 iph->tot_len = 0;
2730 iph->check = 0;
2731 }
2732}
2733
Eugene Crosser2863c612016-06-16 16:18:52 +02002734/**
Eugene Crosser41aeed52016-06-16 16:18:53 +02002735 * qeth_l3_get_elements_no_tso() - find number of SBALEs for skb data for tso
2736 * @card: qeth card structure, to check max. elems.
2737 * @skb: SKB address
2738 * @extra_elems: extra elems needed, to check against max.
Eugene Crosser2863c612016-06-16 16:18:52 +02002739 *
2740 * Returns the number of pages, and thus QDIO buffer elements, needed to cover
2741 * skb data, including linear part and fragments, but excluding TCP header.
2742 * (Exclusion of TCP header distinguishes it from qeth_get_elements_no().)
2743 * Checks if the result plus extra_elems fits under the limit for the card.
2744 * Returns 0 if it does not.
2745 * Note: extra_elems is not included in the returned result.
2746 */
Eugene Crosser41aeed52016-06-16 16:18:53 +02002747static int qeth_l3_get_elements_no_tso(struct qeth_card *card,
Eugene Crosser2863c612016-06-16 16:18:52 +02002748 struct sk_buff *skb, int extra_elems)
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002749{
Eugene Crosser2863c612016-06-16 16:18:52 +02002750 addr_t tcpdptr = (addr_t)tcp_hdr(skb) + tcp_hdrlen(skb);
2751 int elements = qeth_get_elements_for_range(
2752 tcpdptr,
2753 (addr_t)skb->data + skb_headlen(skb)) +
Thomas Richter8f43fb02016-06-16 16:18:59 +02002754 qeth_get_elements_for_frags(skb);
Frank Blaschka271648b2013-03-18 20:04:44 +00002755
Eugene Crosser2863c612016-06-16 16:18:52 +02002756 if ((elements + extra_elems) > QETH_MAX_BUFFER_ELEMENTS(card)) {
2757 QETH_DBF_MESSAGE(2,
2758 "Invalid size of TSO IP packet (Number=%d / Length=%d). Discarded.\n",
2759 elements + extra_elems, skb->len);
2760 return 0;
2761 }
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002762 return elements;
2763}
2764
Frank Blaschka4a71df52008-02-15 09:19:42 +01002765static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2766{
2767 int rc;
2768 u16 *tag;
2769 struct qeth_hdr *hdr = NULL;
Eugene Crosser2863c612016-06-16 16:18:52 +02002770 int hdr_elements = 0;
2771 int elements;
Heiko Carstens509e2562008-07-26 02:24:10 -07002772 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002773 struct sk_buff *new_skb = NULL;
2774 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002775 int cast_type = qeth_l3_get_cast_type(card, skb);
Stefan Raspl290b8342014-04-28 10:05:08 +02002776 struct qeth_qdio_out_q *queue =
2777 card->qdio.out_qs[card->qdio.do_prio_queueing
2778 || (cast_type && card->info.is_multicast_different) ?
2779 qeth_get_priority_queue(card, skb, ipv, cast_type) :
2780 card->qdio.default_out_queue];
Frank Blaschka4a71df52008-02-15 09:19:42 +01002781 int tx_bytes = skb->len;
Eugene Crosser41aeed52016-06-16 16:18:53 +02002782 bool use_tso;
Frank Blaschka683d7182008-08-01 16:39:13 +02002783 int data_offset = -1;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002784 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002785
Frank Blaschkab3332932011-08-08 01:33:59 +00002786 if (((card->info.type == QETH_CARD_TYPE_IQD) &&
2787 (((card->options.cq != QETH_CQ_ENABLED) && !ipv) ||
2788 ((card->options.cq == QETH_CQ_ENABLED) &&
2789 (skb->protocol != ETH_P_AF_IUCV)))) ||
2790 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002791 goto tx_drop;
2792
2793 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2794 card->stats.tx_carrier_errors++;
2795 goto tx_drop;
2796 }
2797
2798 if ((cast_type == RTN_BROADCAST) &&
2799 (card->info.broadcast_capable == 0))
2800 goto tx_drop;
2801
2802 if (card->options.performance_stats) {
2803 card->perf_stats.outbound_cnt++;
2804 card->perf_stats.outbound_start_time = qeth_get_micros();
2805 }
2806
Eugene Crosser41aeed52016-06-16 16:18:53 +02002807 /* Ignore segment size from skb_is_gso(), 1 page is always used. */
2808 use_tso = skb_is_gso(skb) &&
2809 (qeth_get_ip_protocol(skb) == IPPROTO_TCP) && (ipv == 4);
Frank Blaschka683d7182008-08-01 16:39:13 +02002810
Eugene Crosser41aeed52016-06-16 16:18:53 +02002811 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
2812 !skb_is_nonlinear(skb)) {
Frank Blaschka683d7182008-08-01 16:39:13 +02002813 new_skb = skb;
Frank Blaschkab3332932011-08-08 01:33:59 +00002814 if (new_skb->protocol == ETH_P_AF_IUCV)
2815 data_offset = 0;
2816 else
2817 data_offset = ETH_HLEN;
Frank Blaschka683d7182008-08-01 16:39:13 +02002818 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2819 if (!hdr)
2820 goto tx_drop;
Eugene Crosser2863c612016-06-16 16:18:52 +02002821 hdr_elements++;
Frank Blaschka683d7182008-08-01 16:39:13 +02002822 } else {
2823 /* create a clone with writeable headroom */
2824 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
2825 + VLAN_HLEN);
2826 if (!new_skb)
2827 goto tx_drop;
2828 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002829
2830 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02002831 if (data_offset < 0)
2832 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002833 } else {
Frank Blaschka21fde742010-03-08 20:36:54 +00002834 if (ipv == 4) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002835 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002836 }
2837
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002838 if (ipv != 4 && skb_vlan_tag_present(new_skb)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002839 skb_push(new_skb, VLAN_HLEN);
2840 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2841 skb_copy_to_linear_data_offset(new_skb, 4,
2842 new_skb->data + 8, 4);
2843 skb_copy_to_linear_data_offset(new_skb, 8,
2844 new_skb->data + 12, 4);
2845 tag = (u16 *)(new_skb->data + 12);
2846 *tag = __constant_htons(ETH_P_8021Q);
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002847 *(tag + 1) = htons(skb_vlan_tag_get(new_skb));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002848 }
2849 }
2850
2851 netif_stop_queue(dev);
2852
Frank Blaschka4a71df52008-02-15 09:19:42 +01002853 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00002854 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01002855 */
Eugene Crosser41aeed52016-06-16 16:18:53 +02002856 if ((card->info.type != QETH_CARD_TYPE_IQD) &&
2857 ((use_tso && !qeth_l3_get_elements_no_tso(card, new_skb, 1)) ||
2858 (!use_tso && !qeth_get_elements_no(card, new_skb, 0)))) {
Eugene Crosser6059c902016-06-16 16:18:57 +02002859 int lin_rc = skb_linearize(new_skb);
2860
2861 if (card->options.performance_stats) {
2862 if (lin_rc)
2863 card->perf_stats.tx_linfail++;
2864 else
2865 card->perf_stats.tx_lin++;
2866 }
2867 if (lin_rc)
Eugene Crosser41aeed52016-06-16 16:18:53 +02002868 goto tx_drop;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002869 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002870
Eugene Crosser41aeed52016-06-16 16:18:53 +02002871 if (use_tso) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002872 hdr = (struct qeth_hdr *)skb_push(new_skb,
2873 sizeof(struct qeth_hdr_tso));
2874 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
2875 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
2876 qeth_tso_fill_header(card, hdr, new_skb);
Eugene Crosser2863c612016-06-16 16:18:52 +02002877 hdr_elements++;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002878 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02002879 if (data_offset < 0) {
2880 hdr = (struct qeth_hdr *)skb_push(new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002881 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02002882 qeth_l3_fill_header(card, hdr, new_skb, ipv,
2883 cast_type);
2884 } else {
Frank Blaschkab3332932011-08-08 01:33:59 +00002885 if (new_skb->protocol == ETH_P_AF_IUCV)
2886 qeth_l3_fill_af_iucv_hdr(card, hdr, new_skb);
2887 else {
2888 qeth_l3_fill_header(card, hdr, new_skb, ipv,
2889 cast_type);
2890 hdr->hdr.l3.length = new_skb->len - data_offset;
2891 }
Frank Blaschka683d7182008-08-01 16:39:13 +02002892 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002893
2894 if (skb->ip_summed == CHECKSUM_PARTIAL)
2895 qeth_l3_hdr_csum(card, hdr, new_skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002896 }
2897
Eugene Crosser41aeed52016-06-16 16:18:53 +02002898 elements = use_tso ?
2899 qeth_l3_get_elements_no_tso(card, new_skb, hdr_elements) :
2900 qeth_get_elements_no(card, new_skb, hdr_elements);
Eugene Crosser2863c612016-06-16 16:18:52 +02002901 if (!elements) {
Frank Blaschka64ef8952009-03-24 20:57:16 +00002902 if (data_offset >= 0)
2903 kmem_cache_free(qeth_core_header_cache, hdr);
2904 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002905 }
Eugene Crosser2863c612016-06-16 16:18:52 +02002906 elements += hdr_elements;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002907
Frank Blaschka51aa1652010-06-21 22:57:10 +00002908 if (card->info.type != QETH_CARD_TYPE_IQD) {
2909 int len;
Eugene Crosser41aeed52016-06-16 16:18:53 +02002910 if (use_tso)
Frank Blaschka51aa1652010-06-21 22:57:10 +00002911 len = ((unsigned long)tcp_hdr(new_skb) +
Eugene Crosser2863c612016-06-16 16:18:52 +02002912 tcp_hdrlen(new_skb)) -
Frank Blaschka51aa1652010-06-21 22:57:10 +00002913 (unsigned long)new_skb->data;
2914 else
2915 len = sizeof(struct qeth_hdr_layer3);
2916
Stefan Raspld4ae1f52013-04-22 01:12:29 +00002917 if (qeth_hdr_chk_and_bounce(new_skb, &hdr, len))
Frank Blaschka51aa1652010-06-21 22:57:10 +00002918 goto tx_drop;
Eugene Crosser2863c612016-06-16 16:18:52 +02002919 rc = qeth_do_send_packet(card, queue, new_skb, hdr, elements);
Frank Blaschka51aa1652010-06-21 22:57:10 +00002920 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +01002921 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Eugene Crosser2863c612016-06-16 16:18:52 +02002922 elements, data_offset, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002923
2924 if (!rc) {
2925 card->stats.tx_packets++;
2926 card->stats.tx_bytes += tx_bytes;
2927 if (new_skb != skb)
2928 dev_kfree_skb_any(skb);
2929 if (card->options.performance_stats) {
Eugene Crosser2863c612016-06-16 16:18:52 +02002930 nr_frags = skb_shinfo(new_skb)->nr_frags;
Eugene Crosser41aeed52016-06-16 16:18:53 +02002931 if (use_tso) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002932 card->perf_stats.large_send_bytes += tx_bytes;
2933 card->perf_stats.large_send_cnt++;
2934 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00002935 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002936 card->perf_stats.sg_skbs_sent++;
2937 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00002938 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002939 }
2940 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07002941 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002942 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02002943 if (data_offset >= 0)
2944 kmem_cache_free(qeth_core_header_cache, hdr);
2945
Frank Blaschka4a71df52008-02-15 09:19:42 +01002946 if (rc == -EBUSY) {
2947 if (new_skb != skb)
2948 dev_kfree_skb_any(new_skb);
2949 return NETDEV_TX_BUSY;
2950 } else
2951 goto tx_drop;
2952 }
2953
2954 netif_wake_queue(dev);
2955 if (card->options.performance_stats)
2956 card->perf_stats.outbound_time += qeth_get_micros() -
2957 card->perf_stats.outbound_start_time;
2958 return rc;
2959
2960tx_drop:
2961 card->stats.tx_dropped++;
2962 card->stats.tx_errors++;
2963 if ((new_skb != skb) && new_skb)
2964 dev_kfree_skb_any(new_skb);
2965 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02002966 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002967 return NETDEV_TX_OK;
2968}
2969
Ursula Braun39423442011-01-12 20:42:24 +00002970static int __qeth_l3_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002971{
Heiko Carstens509e2562008-07-26 02:24:10 -07002972 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002973 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002974
Carsten Otte847a50f2010-06-21 22:57:05 +00002975 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +00002976 if (card->state == CARD_STATE_UP)
2977 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002978 if (card->state != CARD_STATE_SOFTSETUP)
2979 return -ENODEV;
2980 card->data.state = CH_STATE_UP;
2981 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002982 netif_start_queue(dev);
2983
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002984 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
2985 napi_enable(&card->napi);
2986 napi_schedule(&card->napi);
2987 } else
2988 rc = -EIO;
2989 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002990}
2991
Ursula Braun39423442011-01-12 20:42:24 +00002992static int qeth_l3_open(struct net_device *dev)
2993{
2994 struct qeth_card *card = dev->ml_priv;
2995
2996 QETH_CARD_TEXT(card, 5, "qethope_");
2997 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
2998 QETH_CARD_TEXT(card, 3, "openREC");
2999 return -ERESTARTSYS;
3000 }
3001 return __qeth_l3_open(dev);
3002}
3003
Frank Blaschka4a71df52008-02-15 09:19:42 +01003004static int qeth_l3_stop(struct net_device *dev)
3005{
Heiko Carstens509e2562008-07-26 02:24:10 -07003006 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003007
Carsten Otte847a50f2010-06-21 22:57:05 +00003008 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003009 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003010 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003011 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003012 napi_disable(&card->napi);
3013 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003014 return 0;
3015}
3016
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07003017static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003018 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003019 .get_strings = qeth_core_get_strings,
3020 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00003021 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003022 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02003023 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003024};
3025
3026/*
3027 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3028 * NOARP on the netdevice is no option because it also turns off neighbor
3029 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3030 * arp resolution but we want the hard header (packet socket will work
3031 * e.g. tcpdump)
3032 */
3033static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
3034{
3035 n->nud_state = NUD_NOARP;
3036 memcpy(n->ha, "FAKELL", 6);
3037 n->output = n->ops->connected_output;
3038 return 0;
3039}
3040
3041static int
3042qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
3043{
3044 if (np->tbl->family == AF_INET)
3045 np->neigh_setup = qeth_l3_neigh_setup_noarp;
3046
3047 return 0;
3048}
3049
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003050static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08003051 .ndo_open = qeth_l3_open,
3052 .ndo_stop = qeth_l3_stop,
3053 .ndo_get_stats = qeth_get_stats,
3054 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3055 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003056 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003057 .ndo_do_ioctl = qeth_l3_do_ioctl,
3058 .ndo_change_mtu = qeth_change_mtu,
Thomas Richter8f43fb02016-06-16 16:18:59 +02003059 .ndo_fix_features = qeth_fix_features,
3060 .ndo_set_features = qeth_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08003061 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3062 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003063 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka8403b132009-01-08 10:50:55 -08003064};
3065
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003066static const struct net_device_ops qeth_l3_osa_netdev_ops = {
3067 .ndo_open = qeth_l3_open,
3068 .ndo_stop = qeth_l3_stop,
3069 .ndo_get_stats = qeth_get_stats,
3070 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3071 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003072 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003073 .ndo_do_ioctl = qeth_l3_do_ioctl,
3074 .ndo_change_mtu = qeth_change_mtu,
Thomas Richter8f43fb02016-06-16 16:18:59 +02003075 .ndo_fix_features = qeth_fix_features,
3076 .ndo_set_features = qeth_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003077 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3078 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003079 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003080 .ndo_neigh_setup = qeth_l3_neigh_setup,
3081};
3082
Frank Blaschka4a71df52008-02-15 09:19:42 +01003083static int qeth_l3_setup_netdev(struct qeth_card *card)
3084{
Thomas Richter1aec42b2015-01-21 13:39:10 +01003085 int rc;
3086
Ursula Braun5113fec2010-05-16 21:15:14 +00003087 if (card->info.type == QETH_CARD_TYPE_OSD ||
3088 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003089 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3090 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04003091 pr_info("qeth_l3: ignoring TR device\n");
3092 return -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003093 } else {
3094 card->dev = alloc_etherdev(0);
3095 if (!card->dev)
3096 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003097 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003098
3099 /*IPv6 address autoconfiguration stuff*/
3100 qeth_l3_get_unique_id(card);
3101 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
3102 card->dev->dev_id = card->info.unique_id &
3103 0xffff;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00003104 if (!card->info.guestlan) {
3105 card->dev->hw_features = NETIF_F_SG |
3106 NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
3107 NETIF_F_TSO;
Hans Wippel9bdc4412016-06-16 16:19:00 +02003108 card->dev->vlan_features = NETIF_F_SG |
3109 NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
3110 NETIF_F_TSO;
Thomas Richter8f43fb02016-06-16 16:18:59 +02003111 card->dev->features = NETIF_F_SG;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00003112 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003113 }
3114 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
Tom Gundersenc835a672014-07-14 16:37:24 +02003115 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
3116 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003117 if (!card->dev)
3118 return -ENODEV;
3119 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003120 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Thomas Richter1aec42b2015-01-21 13:39:10 +01003121 rc = qeth_l3_iqd_read_initial_mac(card);
3122 if (rc)
3123 return rc;
Frank Blaschkab3332932011-08-08 01:33:59 +00003124 if (card->options.hsuid[0])
3125 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003126 } else
3127 return -ENODEV;
3128
Heiko Carstens509e2562008-07-26 02:24:10 -07003129 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003130 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003131 card->dev->mtu = card->info.initial_mtu;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00003132 card->dev->ethtool_ops = &qeth_l3_ethtool_ops;
Patrick McHardyf6469682013-04-19 02:04:27 +00003133 card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
3134 NETIF_F_HW_VLAN_CTAG_RX |
3135 NETIF_F_HW_VLAN_CTAG_FILTER;
Eric Dumazet02875872014-10-05 18:38:35 -07003136 netif_keep_dst(card->dev);
Eugene Crosser8bad55f2016-06-16 16:18:54 +02003137 card->dev->gso_max_size = (QETH_MAX_BUFFER_ELEMENTS(card) - 1) *
3138 PAGE_SIZE;
3139 card->dev->gso_max_segs = (QETH_MAX_BUFFER_ELEMENTS(card) - 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003140
3141 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003142 netif_napi_add(card->dev, &card->napi, qeth_l3_poll, QETH_NAPI_WEIGHT);
Ursula Braune5ebe632015-12-11 12:27:55 +01003143 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003144 return register_netdev(card->dev);
3145}
3146
Frank Blaschka4a71df52008-02-15 09:19:42 +01003147static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3148{
3149 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3150
3151 qeth_l3_create_device_attributes(&gdev->dev);
3152 card->options.layer2 = 0;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003153 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003154 return 0;
3155}
3156
3157static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3158{
3159 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3160
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003161 qeth_l3_remove_device_attributes(&cgdev->dev);
3162
Ursula Braunf2148562009-05-19 21:38:37 +00003163 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003164 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3165
Ursula Braun70919e22011-02-26 22:41:36 -08003166 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003167 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003168
3169 if (card->dev) {
Ursula Braun7831b4f2016-07-04 14:07:16 +02003170 netif_napi_del(&card->napi);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003171 unregister_netdev(card->dev);
3172 card->dev = NULL;
3173 }
3174
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003175 qeth_l3_clear_ip_htable(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003176 qeth_l3_clear_ipato_list(card);
3177 return;
3178}
3179
3180static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3181{
3182 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3183 int rc = 0;
3184 enum qeth_card_states recover_flag;
3185
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003186 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003187 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003188 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3189 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003190
Frank Blaschka4a71df52008-02-15 09:19:42 +01003191 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003192 rc = qeth_core_hardsetup_card(card);
3193 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01003194 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003195 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003196 goto out_remove;
3197 }
3198
Ursula Braunaa909222009-11-12 00:11:43 +00003199 if (!card->dev && qeth_l3_setup_netdev(card)) {
3200 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003201 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00003202 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003203
Frank Blaschka1da74b12011-05-12 18:45:02 +00003204 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
3205 if (card->info.hwtrap &&
3206 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
3207 card->info.hwtrap = 0;
3208 } else
3209 card->info.hwtrap = 0;
3210
Frank Blaschka4a71df52008-02-15 09:19:42 +01003211 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003212 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003213 qeth_print_status_message(card);
3214
3215 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003216 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003217
3218 rc = qeth_send_startlan(card);
3219 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003220 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003221 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003222 dev_warn(&card->gdev->dev,
3223 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003224 card->lan_online = 0;
Ursula Braun2b6203b2010-11-26 02:41:19 +00003225 goto contin;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003226 }
Ursula Braunaa909222009-11-12 00:11:43 +00003227 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00003228 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003229 } else
3230 card->lan_online = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003231
Ursula Braun2b6203b2010-11-26 02:41:19 +00003232contin:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003233 rc = qeth_l3_setadapter_parms(card);
3234 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003235 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003236 if (!card->options.sniffer) {
3237 rc = qeth_l3_start_ipassists(card);
Stefan Raspl0f547612013-01-21 02:30:20 +00003238 if (rc) {
Ursula Braun76b11f82010-01-11 02:50:50 +00003239 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Stefan Raspl0f547612013-01-21 02:30:20 +00003240 goto out_remove;
3241 }
Ursula Braun76b11f82010-01-11 02:50:50 +00003242 rc = qeth_l3_setrouting_v4(card);
3243 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003244 QETH_DBF_TEXT_(SETUP, 2, "4err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003245 rc = qeth_l3_setrouting_v6(card);
3246 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003247 QETH_DBF_TEXT_(SETUP, 2, "5err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003248 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003249 netif_tx_disable(card->dev);
3250
3251 rc = qeth_init_qdio_queues(card);
3252 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003253 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003254 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003255 goto out_remove;
3256 }
3257 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003258
3259 qeth_set_allowed_threads(card, 0xffffffff, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003260 qeth_l3_recover_ip(card);
Ursula Braun2b6203b2010-11-26 02:41:19 +00003261 if (card->lan_online)
3262 netif_carrier_on(card->dev);
3263 else
3264 netif_carrier_off(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003265 if (recover_flag == CARD_STATE_RECOVER) {
Ursula Braun4763b0a2011-12-19 22:56:32 +00003266 rtnl_lock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003267 if (recovery_mode)
Ursula Braun39423442011-01-12 20:42:24 +00003268 __qeth_l3_open(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00003269 else
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003270 dev_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003271 qeth_l3_set_multicast_list(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00003272 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01003273 }
Stefan Raspl82f77cf2013-03-18 20:04:42 +00003274 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003275 /* let user_space know that device is online */
3276 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003277 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003278 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003279 return 0;
3280out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003281 qeth_l3_stop_card(card, 0);
3282 ccw_device_set_offline(CARD_DDEV(card));
3283 ccw_device_set_offline(CARD_WDEV(card));
3284 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01003285 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003286 if (recover_flag == CARD_STATE_RECOVER)
3287 card->state = CARD_STATE_RECOVER;
3288 else
3289 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00003290 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003291 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00003292 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003293}
3294
3295static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3296{
3297 return __qeth_l3_set_online(gdev, 0);
3298}
3299
3300static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3301 int recovery_mode)
3302{
3303 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3304 int rc = 0, rc2 = 0, rc3 = 0;
3305 enum qeth_card_states recover_flag;
3306
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003307 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003308 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003309 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3310 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003311
3312 if (card->dev && netif_carrier_ok(card->dev))
3313 netif_carrier_off(card->dev);
3314 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003315 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
3316 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
3317 card->info.hwtrap = 1;
3318 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02003319 qeth_l3_stop_card(card, recovery_mode);
Einar Lueck72861ae2011-12-19 22:56:36 +00003320 if ((card->options.cq == QETH_CQ_ENABLED) && card->dev) {
3321 rtnl_lock();
3322 call_netdevice_notifiers(NETDEV_REBOOT, card->dev);
3323 rtnl_unlock();
3324 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003325 rc = ccw_device_set_offline(CARD_DDEV(card));
3326 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3327 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3328 if (!rc)
3329 rc = (rc2) ? rc2 : rc3;
3330 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003331 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01003332 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003333 if (recover_flag == CARD_STATE_UP)
3334 card->state = CARD_STATE_RECOVER;
3335 /* let user_space know that device is offline */
3336 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003337 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003338 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003339 return 0;
3340}
3341
3342static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3343{
3344 return __qeth_l3_set_offline(cgdev, 0);
3345}
3346
3347static int qeth_l3_recover(void *ptr)
3348{
3349 struct qeth_card *card;
3350 int rc = 0;
3351
3352 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00003353 QETH_CARD_TEXT(card, 2, "recover1");
3354 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003355 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3356 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00003357 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003358 dev_warn(&card->gdev->dev,
3359 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00003360 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003361 __qeth_l3_set_offline(card->gdev, 1);
3362 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003363 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003364 dev_info(&card->gdev->dev,
3365 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003366 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00003367 qeth_close_dev(card);
3368 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00003369 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003370 }
Stefan Raspl65d80132013-04-07 22:19:27 +00003371 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003372 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3373 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003374 return 0;
3375}
3376
3377static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3378{
3379 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braunf78ac2b2011-12-19 22:56:33 +00003380 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka1da74b12011-05-12 18:45:02 +00003381 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
3382 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003383 qeth_qdio_clear_card(card, 0);
3384 qeth_clear_qdio_buffers(card);
Ursula Braun22ae2792014-02-24 13:12:06 +01003385 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003386}
3387
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003388static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3389{
3390 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3391
3392 if (card->dev)
3393 netif_device_detach(card->dev);
3394 qeth_set_allowed_threads(card, 0, 1);
3395 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3396 if (gdev->state == CCWGROUP_OFFLINE)
3397 return 0;
3398 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00003399 if (card->info.hwtrap)
3400 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003401 __qeth_l3_set_offline(card->gdev, 1);
3402 } else
3403 __qeth_l3_set_offline(card->gdev, 0);
3404 return 0;
3405}
3406
3407static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3408{
3409 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3410 int rc = 0;
3411
3412 if (gdev->state == CCWGROUP_OFFLINE)
3413 goto out;
3414
3415 if (card->state == CARD_STATE_RECOVER) {
3416 rc = __qeth_l3_set_online(card->gdev, 1);
3417 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00003418 rtnl_lock();
3419 dev_close(card->dev);
3420 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003421 }
3422 } else
3423 rc = __qeth_l3_set_online(card->gdev, 0);
3424out:
3425 qeth_set_allowed_threads(card, 0xffffffff, 0);
3426 if (card->dev)
3427 netif_device_attach(card->dev);
3428 if (rc)
3429 dev_warn(&card->gdev->dev, "The qeth device driver "
3430 "failed to recover an error on the device\n");
3431 return rc;
3432}
3433
Eugene Crosserc044dc22014-01-29 09:23:48 +01003434/* Returns zero if the command is successfully "consumed" */
3435static int qeth_l3_control_event(struct qeth_card *card,
3436 struct qeth_ipa_cmd *cmd)
3437{
3438 return 1;
3439}
3440
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003441struct qeth_discipline qeth_l3_discipline = {
3442 .start_poll = qeth_qdio_start_poll,
3443 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
3444 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
3445 .recover = qeth_l3_recover,
3446 .setup = qeth_l3_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003447 .remove = qeth_l3_remove_device,
3448 .set_online = qeth_l3_set_online,
3449 .set_offline = qeth_l3_set_offline,
3450 .shutdown = qeth_l3_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003451 .freeze = qeth_l3_pm_suspend,
3452 .thaw = qeth_l3_pm_resume,
3453 .restore = qeth_l3_pm_resume,
Eugene Crosserc044dc22014-01-29 09:23:48 +01003454 .control_event_handler = qeth_l3_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003455};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003456EXPORT_SYMBOL_GPL(qeth_l3_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003457
3458static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003459 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003460{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003461
Frank Blaschka4a71df52008-02-15 09:19:42 +01003462 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3463 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3464 struct qeth_ipaddr *addr;
3465 struct qeth_card *card;
3466
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003467 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003468 return NOTIFY_DONE;
3469
Frank Blaschka4a71df52008-02-15 09:19:42 +01003470 card = qeth_l3_get_card_from_dev(dev);
3471 if (!card)
3472 return NOTIFY_DONE;
frank.blaschka@de.ibm.com6d8823d2012-05-16 01:28:26 +00003473 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003474
3475 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003476 if (addr) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003477 addr->u.a4.addr = ifa->ifa_address;
3478 addr->u.a4.mask = ifa->ifa_mask;
3479 addr->type = QETH_IP_TYPE_NORMAL;
3480 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003481 return NOTIFY_DONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003482
3483 switch (event) {
3484 case NETDEV_UP:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003485 spin_lock_bh(&card->ip_lock);
3486 qeth_l3_add_ip(card, addr);
3487 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003488 break;
3489 case NETDEV_DOWN:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003490 spin_lock_bh(&card->ip_lock);
3491 qeth_l3_delete_ip(card, addr);
3492 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003493 break;
3494 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003495
3496 kfree(addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003497 return NOTIFY_DONE;
3498}
3499
3500static struct notifier_block qeth_l3_ip_notifier = {
3501 qeth_l3_ip_event,
3502 NULL,
3503};
3504
3505#ifdef CONFIG_QETH_IPV6
3506/**
3507 * IPv6 event handler
3508 */
3509static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003510 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003511{
3512 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3513 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3514 struct qeth_ipaddr *addr;
3515 struct qeth_card *card;
3516
Frank Blaschka4a71df52008-02-15 09:19:42 +01003517 card = qeth_l3_get_card_from_dev(dev);
3518 if (!card)
3519 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00003520 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003521 if (!qeth_is_supported(card, IPA_IPV6))
3522 return NOTIFY_DONE;
3523
3524 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003525 if (addr) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003526 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3527 addr->u.a6.pfxlen = ifa->prefix_len;
3528 addr->type = QETH_IP_TYPE_NORMAL;
3529 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003530 return NOTIFY_DONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003531
3532 switch (event) {
3533 case NETDEV_UP:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003534 spin_lock_bh(&card->ip_lock);
3535 qeth_l3_add_ip(card, addr);
3536 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003537 break;
3538 case NETDEV_DOWN:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003539 spin_lock_bh(&card->ip_lock);
3540 qeth_l3_delete_ip(card, addr);
3541 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003542 break;
3543 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003544
3545 kfree(addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003546 return NOTIFY_DONE;
3547}
3548
3549static struct notifier_block qeth_l3_ip6_notifier = {
3550 qeth_l3_ip6_event,
3551 NULL,
3552};
3553#endif
3554
3555static int qeth_l3_register_notifiers(void)
3556{
3557 int rc;
3558
Carsten Otte847a50f2010-06-21 22:57:05 +00003559 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003560 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3561 if (rc)
3562 return rc;
3563#ifdef CONFIG_QETH_IPV6
3564 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3565 if (rc) {
3566 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3567 return rc;
3568 }
3569#else
Joe Perchesbaebc702016-03-03 20:49:57 -08003570 pr_warn("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003571#endif
3572 return 0;
3573}
3574
3575static void qeth_l3_unregister_notifiers(void)
3576{
3577
Carsten Otte847a50f2010-06-21 22:57:05 +00003578 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Stefan Raspl18af5c12012-11-19 02:46:50 +00003579 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003580#ifdef CONFIG_QETH_IPV6
Stefan Raspl18af5c12012-11-19 02:46:50 +00003581 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003582#endif /* QETH_IPV6 */
3583}
3584
3585static int __init qeth_l3_init(void)
3586{
3587 int rc = 0;
3588
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003589 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003590 rc = qeth_l3_register_notifiers();
3591 return rc;
3592}
3593
3594static void __exit qeth_l3_exit(void)
3595{
3596 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003597 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003598}
3599
3600module_init(qeth_l3_init);
3601module_exit(qeth_l3_exit);
3602MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3603MODULE_DESCRIPTION("qeth layer 3 discipline");
3604MODULE_LICENSE("GPL");