blob: 1487f8a0c575e5a256c3b75ca117bdc50c401412 [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
Julian Wiedmann67b539c2017-12-13 18:56:32 +0100171static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
172 struct qeth_ipaddr *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100173{
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;
Julian Wiedmann475018c2017-12-13 18:56:30 +0100181 if (addr->type != QETH_IP_TYPE_NORMAL)
182 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100183
184 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
185 (addr->proto == QETH_PROT_IPV4)? 4:16);
186 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
187 if (addr->proto != ipatoe->proto)
188 continue;
189 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
190 (ipatoe->proto == QETH_PROT_IPV4) ?
191 4 : 16);
192 if (addr->proto == QETH_PROT_IPV4)
193 rc = !memcmp(addr_bits, ipatoe_bits,
194 min(32, ipatoe->mask_bits));
195 else
196 rc = !memcmp(addr_bits, ipatoe_bits,
197 min(128, ipatoe->mask_bits));
198 if (rc)
199 break;
200 }
201 /* invert? */
202 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
203 rc = !rc;
204 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
205 rc = !rc;
206
207 return rc;
208}
209
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200210inline int
211qeth_l3_ipaddrs_is_equal(struct qeth_ipaddr *addr1, struct qeth_ipaddr *addr2)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100212{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200213 return addr1->proto == addr2->proto &&
214 !memcmp(&addr1->u, &addr2->u, sizeof(addr1->u)) &&
215 !memcmp(&addr1->mac, &addr2->mac, sizeof(addr1->mac));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100216}
217
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200218static struct qeth_ipaddr *
219qeth_l3_ip_from_hash(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100220{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200221 struct qeth_ipaddr *addr;
222
223 if (tmp_addr->is_multicast) {
224 hash_for_each_possible(card->ip_mc_htable, addr,
225 hnode, qeth_l3_ipaddr_hash(tmp_addr))
226 if (qeth_l3_ipaddrs_is_equal(tmp_addr, addr))
227 return addr;
228 } else {
229 hash_for_each_possible(card->ip_htable, addr,
230 hnode, qeth_l3_ipaddr_hash(tmp_addr))
231 if (qeth_l3_ipaddrs_is_equal(tmp_addr, addr))
232 return addr;
233 }
234
235 return NULL;
236}
237
238int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
239{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100240 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200241 struct qeth_ipaddr *addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100242
Carsten Otte847a50f2010-06-21 22:57:05 +0000243 QETH_CARD_TEXT(card, 4, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100244
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200245 if (tmp_addr->proto == QETH_PROT_IPV4)
246 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100247 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200248 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
249 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100250 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200251
252 addr = qeth_l3_ip_from_hash(card, tmp_addr);
253 if (!addr)
254 return -ENOENT;
255
256 addr->ref_counter--;
257 if (addr->type == QETH_IP_TYPE_NORMAL && addr->ref_counter > 0)
258 return rc;
259 if (addr->in_progress)
260 return -EINPROGRESS;
261
Ursula Brauna7531c12016-09-15 14:39:23 +0200262 if (!qeth_card_hw_is_reachable(card)) {
263 addr->disp_flag = QETH_DISP_ADDR_DELETE;
264 return 0;
265 }
266
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200267 rc = qeth_l3_deregister_addr_entry(card, addr);
268
269 hash_del(&addr->hnode);
270 kfree(addr);
271
Frank Blaschka4a71df52008-02-15 09:19:42 +0100272 return rc;
273}
274
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200275int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100276{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100277 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200278 struct qeth_ipaddr *addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100279
Carsten Otte847a50f2010-06-21 22:57:05 +0000280 QETH_CARD_TEXT(card, 4, "addip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200281
282 if (tmp_addr->proto == QETH_PROT_IPV4)
283 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100284 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200285 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
286 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100287 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200288
289 addr = qeth_l3_ip_from_hash(card, tmp_addr);
290 if (!addr) {
291 addr = qeth_l3_get_addr_buffer(tmp_addr->proto);
292 if (!addr)
293 return -ENOMEM;
294
295 memcpy(addr, tmp_addr, sizeof(struct qeth_ipaddr));
296 addr->ref_counter = 1;
297
Julian Wiedmann475018c2017-12-13 18:56:30 +0100298 if (qeth_l3_is_addr_covered_by_ipato(card, addr)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200299 QETH_CARD_TEXT(card, 2, "tkovaddr");
300 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
301 }
302 hash_add(card->ip_htable, &addr->hnode,
303 qeth_l3_ipaddr_hash(addr));
304
Ursula Brauna7531c12016-09-15 14:39:23 +0200305 if (!qeth_card_hw_is_reachable(card)) {
306 addr->disp_flag = QETH_DISP_ADDR_ADD;
307 return 0;
308 }
309
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200310 /* qeth_l3_register_addr_entry can go to sleep
311 * if we add a IPV4 addr. It is caused by the reason
312 * that SETIP ipa cmd starts ARP staff for IPV4 addr.
313 * Thus we should unlock spinlock, and make a protection
314 * using in_progress variable to indicate that there is
315 * an hardware operation with this IPV4 address
316 */
317 if (addr->proto == QETH_PROT_IPV4) {
318 addr->in_progress = 1;
319 spin_unlock_bh(&card->ip_lock);
320 rc = qeth_l3_register_addr_entry(card, addr);
321 spin_lock_bh(&card->ip_lock);
322 addr->in_progress = 0;
323 } else
324 rc = qeth_l3_register_addr_entry(card, addr);
325
326 if (!rc || (rc == IPA_RC_DUPLICATE_IP_ADDRESS) ||
327 (rc == IPA_RC_LAN_OFFLINE)) {
328 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
329 if (addr->ref_counter < 1) {
330 qeth_l3_delete_ip(card, addr);
331 kfree(addr);
332 }
333 } else {
334 hash_del(&addr->hnode);
335 kfree(addr);
336 }
337 } else {
338 if (addr->type == QETH_IP_TYPE_NORMAL)
339 addr->ref_counter++;
340 }
341
Frank Blaschka4a71df52008-02-15 09:19:42 +0100342 return rc;
343}
344
345
Frank Blaschkab3332932011-08-08 01:33:59 +0000346struct qeth_ipaddr *qeth_l3_get_addr_buffer(
Frank Blaschka4a71df52008-02-15 09:19:42 +0100347 enum qeth_prot_versions prot)
348{
349 struct qeth_ipaddr *addr;
350
351 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200352 if (!addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100353 return NULL;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200354
Frank Blaschka4a71df52008-02-15 09:19:42 +0100355 addr->type = QETH_IP_TYPE_NORMAL;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200356 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100357 addr->proto = prot;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200358
Frank Blaschka4a71df52008-02-15 09:19:42 +0100359 return addr;
360}
361
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200362static void qeth_l3_clear_ip_htable(struct qeth_card *card, int recover)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100363{
364 struct qeth_ipaddr *addr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200365 struct hlist_node *tmp;
366 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100367
Carsten Otte847a50f2010-06-21 22:57:05 +0000368 QETH_CARD_TEXT(card, 4, "clearip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200369
Ursula Braun76b11f82010-01-11 02:50:50 +0000370 if (recover && card->options.sniffer)
371 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100372
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200373 spin_lock_bh(&card->ip_lock);
374
375 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
376 if (!recover) {
377 hash_del(&addr->hnode);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100378 kfree(addr);
379 continue;
380 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200381 addr->disp_flag = QETH_DISP_ADDR_ADD;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100382 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200383
384 spin_unlock_bh(&card->ip_lock);
385
386 spin_lock_bh(&card->mclock);
387
388 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
389 hash_del(&addr->hnode);
390 kfree(addr);
391 }
392
393 spin_unlock_bh(&card->mclock);
394
395
Frank Blaschka4a71df52008-02-15 09:19:42 +0100396}
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200397static void qeth_l3_recover_ip(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100398{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200399 struct qeth_ipaddr *addr;
400 struct hlist_node *tmp;
401 int i;
402 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100403
Ursula Brauna7531c12016-09-15 14:39:23 +0200404 QETH_CARD_TEXT(card, 4, "recovrip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100405
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200406 spin_lock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100407
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200408 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
Ursula Brauna7531c12016-09-15 14:39:23 +0200409 if (addr->disp_flag == QETH_DISP_ADDR_DELETE) {
410 qeth_l3_deregister_addr_entry(card, addr);
411 hash_del(&addr->hnode);
412 kfree(addr);
413 } else if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200414 if (addr->proto == QETH_PROT_IPV4) {
415 addr->in_progress = 1;
416 spin_unlock_bh(&card->ip_lock);
417 rc = qeth_l3_register_addr_entry(card, addr);
418 spin_lock_bh(&card->ip_lock);
419 addr->in_progress = 0;
420 } else
421 rc = qeth_l3_register_addr_entry(card, addr);
422
423 if (!rc) {
424 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Ursula Brauna7531c12016-09-15 14:39:23 +0200425 if (addr->ref_counter < 1)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200426 qeth_l3_delete_ip(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200427 } else {
428 hash_del(&addr->hnode);
429 kfree(addr);
430 }
431 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100432 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200433
434 spin_unlock_bh(&card->ip_lock);
435
Frank Blaschka4a71df52008-02-15 09:19:42 +0100436}
437
438static int qeth_l3_send_setdelmc(struct qeth_card *card,
439 struct qeth_ipaddr *addr, int ipacmd)
440{
441 int rc;
442 struct qeth_cmd_buffer *iob;
443 struct qeth_ipa_cmd *cmd;
444
Carsten Otte847a50f2010-06-21 22:57:05 +0000445 QETH_CARD_TEXT(card, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100446
447 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100448 if (!iob)
449 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100450 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
451 memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
452 if (addr->proto == QETH_PROT_IPV6)
453 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
454 sizeof(struct in6_addr));
455 else
456 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
457
458 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
459
460 return rc;
461}
462
463static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
464{
465 int i, j;
466 for (i = 0; i < 16; i++) {
467 j = (len) - (i * 8);
468 if (j >= 8)
469 netmask[i] = 0xff;
470 else if (j > 0)
471 netmask[i] = (u8)(0xFF00 >> j);
472 else
473 netmask[i] = 0;
474 }
475}
476
477static int qeth_l3_send_setdelip(struct qeth_card *card,
478 struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
479{
480 int rc;
481 struct qeth_cmd_buffer *iob;
482 struct qeth_ipa_cmd *cmd;
483 __u8 netmask[16];
484
Carsten Otte847a50f2010-06-21 22:57:05 +0000485 QETH_CARD_TEXT(card, 4, "setdelip");
486 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100487
488 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100489 if (!iob)
490 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100491 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
492 if (addr->proto == QETH_PROT_IPV6) {
493 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
494 sizeof(struct in6_addr));
495 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
496 memcpy(cmd->data.setdelip6.mask, netmask,
497 sizeof(struct in6_addr));
498 cmd->data.setdelip6.flags = flags;
499 } else {
500 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
501 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
502 cmd->data.setdelip4.flags = flags;
503 }
504
505 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
506
507 return rc;
508}
509
510static int qeth_l3_send_setrouting(struct qeth_card *card,
511 enum qeth_routing_types type, enum qeth_prot_versions prot)
512{
513 int rc;
514 struct qeth_ipa_cmd *cmd;
515 struct qeth_cmd_buffer *iob;
516
Carsten Otte847a50f2010-06-21 22:57:05 +0000517 QETH_CARD_TEXT(card, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100518 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100519 if (!iob)
520 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100521 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
522 cmd->data.setrtg.type = (type);
523 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
524
525 return rc;
526}
527
Stefan Raspl82e2e782013-03-18 20:04:43 +0000528static int qeth_l3_correct_routing_type(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100529 enum qeth_routing_types *type, enum qeth_prot_versions prot)
530{
531 if (card->info.type == QETH_CARD_TYPE_IQD) {
532 switch (*type) {
533 case NO_ROUTER:
534 case PRIMARY_CONNECTOR:
535 case SECONDARY_CONNECTOR:
536 case MULTICAST_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 } else {
542 switch (*type) {
543 case NO_ROUTER:
544 case PRIMARY_ROUTER:
545 case SECONDARY_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000546 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100547 case MULTICAST_ROUTER:
548 if (qeth_is_ipafunc_supported(card, prot,
549 IPA_OSA_MC_ROUTER))
Stefan Raspl82e2e782013-03-18 20:04:43 +0000550 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100551 default:
552 goto out_inval;
553 }
554 }
555out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100556 *type = NO_ROUTER;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000557 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100558}
559
560int qeth_l3_setrouting_v4(struct qeth_card *card)
561{
562 int rc;
563
Carsten Otte847a50f2010-06-21 22:57:05 +0000564 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100565
Stefan Raspl82e2e782013-03-18 20:04:43 +0000566 rc = qeth_l3_correct_routing_type(card, &card->options.route4.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100567 QETH_PROT_IPV4);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000568 if (rc)
569 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100570
571 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
572 QETH_PROT_IPV4);
573 if (rc) {
574 card->options.route4.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200575 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
576 " on %s. Type set to 'no router'.\n", rc,
577 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100578 }
579 return rc;
580}
581
582int qeth_l3_setrouting_v6(struct qeth_card *card)
583{
584 int rc = 0;
585
Carsten Otte847a50f2010-06-21 22:57:05 +0000586 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100587#ifdef CONFIG_QETH_IPV6
588
589 if (!qeth_is_supported(card, IPA_IPV6))
590 return 0;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000591 rc = qeth_l3_correct_routing_type(card, &card->options.route6.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100592 QETH_PROT_IPV6);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000593 if (rc)
594 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100595
596 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
597 QETH_PROT_IPV6);
598 if (rc) {
599 card->options.route6.type = NO_ROUTER;
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200600 QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
601 " on %s. Type set to 'no router'.\n", rc,
602 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100603 }
604#endif
605 return rc;
606}
607
608/*
609 * IP address takeover related functions
610 */
Julian Wiedmann67b539c2017-12-13 18:56:32 +0100611
612/**
613 * qeth_l3_update_ipato() - Update 'takeover' property, for all NORMAL IPs.
614 *
615 * Caller must hold ip_lock.
616 */
617void qeth_l3_update_ipato(struct qeth_card *card)
618{
619 struct qeth_ipaddr *addr;
620 unsigned int i;
621
622 hash_for_each(card->ip_htable, i, addr, hnode) {
623 if (addr->type != QETH_IP_TYPE_NORMAL)
624 continue;
625 if (qeth_l3_is_addr_covered_by_ipato(card, addr))
626 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
627 else
628 addr->set_flags &= ~QETH_IPA_SETIP_TAKEOVER_FLAG;
629 }
630}
631
Frank Blaschka4a71df52008-02-15 09:19:42 +0100632static void qeth_l3_clear_ipato_list(struct qeth_card *card)
633{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100634 struct qeth_ipato_entry *ipatoe, *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100635
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200636 spin_lock_bh(&card->ip_lock);
637
Frank Blaschka4a71df52008-02-15 09:19:42 +0100638 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
639 list_del(&ipatoe->entry);
640 kfree(ipatoe);
641 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200642
Julian Wiedmann67b539c2017-12-13 18:56:32 +0100643 qeth_l3_update_ipato(card);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200644 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100645}
646
647int qeth_l3_add_ipato_entry(struct qeth_card *card,
648 struct qeth_ipato_entry *new)
649{
650 struct qeth_ipato_entry *ipatoe;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100651 int rc = 0;
652
Carsten Otte847a50f2010-06-21 22:57:05 +0000653 QETH_CARD_TEXT(card, 2, "addipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200654
655 spin_lock_bh(&card->ip_lock);
656
Frank Blaschka4a71df52008-02-15 09:19:42 +0100657 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
658 if (ipatoe->proto != new->proto)
659 continue;
660 if (!memcmp(ipatoe->addr, new->addr,
661 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
662 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100663 rc = -EEXIST;
664 break;
665 }
666 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200667
Julian Wiedmann67b539c2017-12-13 18:56:32 +0100668 if (!rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100669 list_add_tail(&new->entry, &card->ipato.entries);
Julian Wiedmann67b539c2017-12-13 18:56:32 +0100670 qeth_l3_update_ipato(card);
671 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100672
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200673 spin_unlock_bh(&card->ip_lock);
674
Frank Blaschka4a71df52008-02-15 09:19:42 +0100675 return rc;
676}
677
678void qeth_l3_del_ipato_entry(struct qeth_card *card,
679 enum qeth_prot_versions proto, u8 *addr, int mask_bits)
680{
681 struct qeth_ipato_entry *ipatoe, *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100682
Carsten Otte847a50f2010-06-21 22:57:05 +0000683 QETH_CARD_TEXT(card, 2, "delipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200684
685 spin_lock_bh(&card->ip_lock);
686
Frank Blaschka4a71df52008-02-15 09:19:42 +0100687 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
688 if (ipatoe->proto != proto)
689 continue;
690 if (!memcmp(ipatoe->addr, addr,
691 (proto == QETH_PROT_IPV4)? 4:16) &&
692 (ipatoe->mask_bits == mask_bits)) {
693 list_del(&ipatoe->entry);
Julian Wiedmann67b539c2017-12-13 18:56:32 +0100694 qeth_l3_update_ipato(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100695 kfree(ipatoe);
696 }
697 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200698
699 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100700}
701
702/*
703 * VIPA related functions
704 */
705int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
706 const u8 *addr)
707{
708 struct qeth_ipaddr *ipaddr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100709 int rc = 0;
710
711 ipaddr = qeth_l3_get_addr_buffer(proto);
712 if (ipaddr) {
713 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000714 QETH_CARD_TEXT(card, 2, "addvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100715 memcpy(&ipaddr->u.a4.addr, addr, 4);
716 ipaddr->u.a4.mask = 0;
717 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000718 QETH_CARD_TEXT(card, 2, "addvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100719 memcpy(&ipaddr->u.a6.addr, addr, 16);
720 ipaddr->u.a6.pfxlen = 0;
721 }
722 ipaddr->type = QETH_IP_TYPE_VIPA;
723 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
724 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
725 } else
726 return -ENOMEM;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200727
728 spin_lock_bh(&card->ip_lock);
729
Thomas Richter732a59c2016-09-15 14:39:27 +0200730 if (qeth_l3_ip_from_hash(card, ipaddr))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100731 rc = -EEXIST;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200732 else
733 qeth_l3_add_ip(card, ipaddr);
734
735 spin_unlock_bh(&card->ip_lock);
736
737 kfree(ipaddr);
738
Frank Blaschka4a71df52008-02-15 09:19:42 +0100739 return rc;
740}
741
742void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
743 const u8 *addr)
744{
745 struct qeth_ipaddr *ipaddr;
746
747 ipaddr = qeth_l3_get_addr_buffer(proto);
748 if (ipaddr) {
749 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000750 QETH_CARD_TEXT(card, 2, "delvipa4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100751 memcpy(&ipaddr->u.a4.addr, addr, 4);
752 ipaddr->u.a4.mask = 0;
753 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000754 QETH_CARD_TEXT(card, 2, "delvipa6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100755 memcpy(&ipaddr->u.a6.addr, addr, 16);
756 ipaddr->u.a6.pfxlen = 0;
757 }
758 ipaddr->type = QETH_IP_TYPE_VIPA;
759 } else
760 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200761
762 spin_lock_bh(&card->ip_lock);
763 qeth_l3_delete_ip(card, ipaddr);
764 spin_unlock_bh(&card->ip_lock);
765
766 kfree(ipaddr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100767}
768
769/*
770 * proxy ARP related functions
771 */
772int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
773 const u8 *addr)
774{
775 struct qeth_ipaddr *ipaddr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100776 int rc = 0;
777
778 ipaddr = qeth_l3_get_addr_buffer(proto);
779 if (ipaddr) {
780 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000781 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100782 memcpy(&ipaddr->u.a4.addr, addr, 4);
783 ipaddr->u.a4.mask = 0;
784 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000785 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100786 memcpy(&ipaddr->u.a6.addr, addr, 16);
787 ipaddr->u.a6.pfxlen = 0;
788 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200789
Frank Blaschka4a71df52008-02-15 09:19:42 +0100790 ipaddr->type = QETH_IP_TYPE_RXIP;
791 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
792 ipaddr->del_flags = 0;
793 } else
794 return -ENOMEM;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200795
796 spin_lock_bh(&card->ip_lock);
797
Thomas Richter732a59c2016-09-15 14:39:27 +0200798 if (qeth_l3_ip_from_hash(card, ipaddr))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100799 rc = -EEXIST;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200800 else
801 qeth_l3_add_ip(card, ipaddr);
802
803 spin_unlock_bh(&card->ip_lock);
804
805 kfree(ipaddr);
806
807 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100808}
809
810void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
811 const u8 *addr)
812{
813 struct qeth_ipaddr *ipaddr;
814
815 ipaddr = qeth_l3_get_addr_buffer(proto);
816 if (ipaddr) {
817 if (proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000818 QETH_CARD_TEXT(card, 2, "addrxip4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100819 memcpy(&ipaddr->u.a4.addr, addr, 4);
820 ipaddr->u.a4.mask = 0;
821 } else if (proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000822 QETH_CARD_TEXT(card, 2, "addrxip6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100823 memcpy(&ipaddr->u.a6.addr, addr, 16);
824 ipaddr->u.a6.pfxlen = 0;
825 }
826 ipaddr->type = QETH_IP_TYPE_RXIP;
827 } else
828 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200829
830 spin_lock_bh(&card->ip_lock);
831 qeth_l3_delete_ip(card, ipaddr);
832 spin_unlock_bh(&card->ip_lock);
833
834 kfree(ipaddr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100835}
836
837static int qeth_l3_register_addr_entry(struct qeth_card *card,
838 struct qeth_ipaddr *addr)
839{
840 char buf[50];
841 int rc = 0;
842 int cnt = 3;
843
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200844
Frank Blaschka4a71df52008-02-15 09:19:42 +0100845 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000846 QETH_CARD_TEXT(card, 2, "setaddr4");
847 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100848 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000849 QETH_CARD_TEXT(card, 2, "setaddr6");
850 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
851 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100852 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000853 QETH_CARD_TEXT(card, 2, "setaddr?");
854 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100855 }
856 do {
857 if (addr->is_multicast)
858 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
859 else
860 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
861 addr->set_flags);
862 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000863 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100864 } while ((--cnt > 0) && rc);
865 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000866 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100867 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100868 dev_warn(&card->gdev->dev,
869 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100870 }
871 return rc;
872}
873
874static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
875 struct qeth_ipaddr *addr)
876{
877 int rc = 0;
878
879 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000880 QETH_CARD_TEXT(card, 2, "deladdr4");
881 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100882 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000883 QETH_CARD_TEXT(card, 2, "deladdr6");
884 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
885 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100886 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000887 QETH_CARD_TEXT(card, 2, "deladdr?");
888 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100889 }
890 if (addr->is_multicast)
891 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
892 else
893 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
894 addr->del_flags);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200895 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000896 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100897
898 return rc;
899}
900
901static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
902{
903 if (cast_type == RTN_MULTICAST)
904 return QETH_CAST_MULTICAST;
905 if (cast_type == RTN_BROADCAST)
906 return QETH_CAST_BROADCAST;
907 return QETH_CAST_UNICAST;
908}
909
910static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
911{
912 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
913 if (cast_type == RTN_MULTICAST)
914 return ct | QETH_CAST_MULTICAST;
915 if (cast_type == RTN_ANYCAST)
916 return ct | QETH_CAST_ANYCAST;
917 if (cast_type == RTN_BROADCAST)
918 return ct | QETH_CAST_BROADCAST;
919 return ct | QETH_CAST_UNICAST;
920}
921
Frank Blaschka4a71df52008-02-15 09:19:42 +0100922static int qeth_l3_setadapter_parms(struct qeth_card *card)
923{
924 int rc;
925
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200926 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100927
928 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100929 dev_info(&card->gdev->dev,
930 "set adapter parameters not supported.\n");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200931 QETH_DBF_TEXT(SETUP, 2, " notsupp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100932 return 0;
933 }
934 rc = qeth_query_setadapterparms(card);
935 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100936 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
Kay Sievers7f6d95e2009-03-24 20:57:14 +0000937 "0x%x\n", dev_name(&card->gdev->dev), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100938 return rc;
939 }
940 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
941 rc = qeth_setadpparms_change_macaddr(card);
942 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100943 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -0800944 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100945 }
946
Frank Blaschka4a71df52008-02-15 09:19:42 +0100947 return rc;
948}
949
Frank Blaschka4a71df52008-02-15 09:19:42 +0100950#ifdef CONFIG_QETH_IPV6
951static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
952 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
953{
954 int rc;
955 struct qeth_cmd_buffer *iob;
956
Carsten Otte847a50f2010-06-21 22:57:05 +0000957 QETH_CARD_TEXT(card, 4, "simassp6");
Thomas Richterb475e312015-12-11 12:27:54 +0100958 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100959 0, QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100960 if (!iob)
961 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +0200962 rc = qeth_send_setassparms(card, iob, 0, 0,
Thomas Richter8f43fb02016-06-16 16:18:59 +0200963 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100964 return rc;
965}
966#endif
967
Frank Blaschka4a71df52008-02-15 09:19:42 +0100968static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
969{
970 int rc;
971
Carsten Otte847a50f2010-06-21 22:57:05 +0000972 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100973
974 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100975 dev_info(&card->gdev->dev,
976 "ARP processing not supported on %s!\n",
977 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100978 return 0;
979 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200980 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
981 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100982 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100983 dev_warn(&card->gdev->dev,
984 "Starting ARP processing support for %s failed\n",
985 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100986 }
987 return rc;
988}
989
990static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
991{
992 int rc;
993
Carsten Otte847a50f2010-06-21 22:57:05 +0000994 QETH_CARD_TEXT(card, 3, "ipaipfrg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100995
996 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100997 dev_info(&card->gdev->dev,
998 "Hardware IP fragmentation not supported on %s\n",
999 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001000 return -EOPNOTSUPP;
1001 }
1002
Thomas Richter4d7def22015-09-18 16:06:51 +02001003 rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001004 IPA_CMD_ASS_START, 0);
1005 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001006 dev_warn(&card->gdev->dev,
1007 "Starting IP fragmentation support for %s failed\n",
1008 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001009 } else
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001010 dev_info(&card->gdev->dev,
1011 "Hardware IP fragmentation enabled \n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001012 return rc;
1013}
1014
1015static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
1016{
1017 int rc;
1018
Carsten Otte847a50f2010-06-21 22:57:05 +00001019 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001020
Frank Blaschka4a71df52008-02-15 09:19:42 +01001021 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001022 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001023 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001024 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001025 return -EOPNOTSUPP;
1026 }
1027
Thomas Richter4d7def22015-09-18 16:06:51 +02001028 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001029 IPA_CMD_ASS_START, 0);
1030 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001031 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001032 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001033 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001034 return rc;
1035}
1036
1037static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
1038{
1039 int rc = 0;
1040
Carsten Otte847a50f2010-06-21 22:57:05 +00001041 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001042
1043 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001044 dev_info(&card->gdev->dev,
1045 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001046 return -EOPNOTSUPP;
1047 }
1048
Thomas Richter4d7def22015-09-18 16:06:51 +02001049 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001050 IPA_CMD_ASS_START, 0);
1051 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001052 dev_warn(&card->gdev->dev,
1053 "Starting VLAN support for %s failed\n",
1054 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001055 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001056 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001057 }
1058 return rc;
1059}
1060
1061static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
1062{
1063 int rc;
1064
Carsten Otte847a50f2010-06-21 22:57:05 +00001065 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001066
1067 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001068 dev_info(&card->gdev->dev,
1069 "Multicast not supported on %s\n",
1070 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001071 return -EOPNOTSUPP;
1072 }
1073
Thomas Richter4d7def22015-09-18 16:06:51 +02001074 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001075 IPA_CMD_ASS_START, 0);
1076 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001077 dev_warn(&card->gdev->dev,
1078 "Starting multicast support for %s failed\n",
1079 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001080 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001081 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001082 card->dev->flags |= IFF_MULTICAST;
1083 }
1084 return rc;
1085}
1086
Frank Blaschka4a71df52008-02-15 09:19:42 +01001087#ifdef CONFIG_QETH_IPV6
1088static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
1089{
1090 int rc;
1091
Carsten Otte847a50f2010-06-21 22:57:05 +00001092 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001093
1094 if (card->info.type == QETH_CARD_TYPE_IQD)
1095 goto out;
1096
Frank Blaschka1da74b12011-05-12 18:45:02 +00001097 rc = qeth_query_ipassists(card, QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001098 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001099 dev_err(&card->gdev->dev,
1100 "Activating IPv6 support for %s failed\n",
1101 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001102 return rc;
1103 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001104 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001105 IPA_CMD_ASS_START, 3);
1106 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001107 dev_err(&card->gdev->dev,
1108 "Activating IPv6 support for %s failed\n",
1109 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001110 return rc;
1111 }
1112 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
1113 IPA_CMD_ASS_START);
1114 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001115 dev_err(&card->gdev->dev,
1116 "Activating IPv6 support for %s failed\n",
1117 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001118 return rc;
1119 }
1120 rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
1121 IPA_CMD_ASS_START);
1122 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001123 dev_warn(&card->gdev->dev,
1124 "Enabling the passthrough mode for %s failed\n",
1125 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001126 return rc;
1127 }
1128out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001129 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001130 return 0;
1131}
1132#endif
1133
1134static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
1135{
1136 int rc = 0;
1137
Carsten Otte847a50f2010-06-21 22:57:05 +00001138 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001139
1140 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001141 dev_info(&card->gdev->dev,
1142 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001143 return 0;
1144 }
1145#ifdef CONFIG_QETH_IPV6
1146 rc = qeth_l3_softsetup_ipv6(card);
1147#endif
1148 return rc ;
1149}
1150
1151static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
1152{
1153 int rc;
1154
Carsten Otte847a50f2010-06-21 22:57:05 +00001155 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001156 card->info.broadcast_capable = 0;
1157 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001158 dev_info(&card->gdev->dev,
1159 "Broadcast not supported on %s\n",
1160 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001161 rc = -EOPNOTSUPP;
1162 goto out;
1163 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001164 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001165 IPA_CMD_ASS_START, 0);
1166 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001167 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
1168 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001169 goto out;
1170 }
1171
Thomas Richter4d7def22015-09-18 16:06:51 +02001172 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001173 IPA_CMD_ASS_CONFIGURE, 1);
1174 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001175 dev_warn(&card->gdev->dev,
1176 "Setting up broadcast filtering for %s failed\n",
1177 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001178 goto out;
1179 }
1180 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001181 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Thomas Richter4d7def22015-09-18 16:06:51 +02001182 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001183 IPA_CMD_ASS_ENABLE, 1);
1184 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001185 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
1186 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001187 goto out;
1188 }
1189 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
1190out:
1191 if (card->info.broadcast_capable)
1192 card->dev->flags |= IFF_BROADCAST;
1193 else
1194 card->dev->flags &= ~IFF_BROADCAST;
1195 return rc;
1196}
1197
Frank Blaschka4a71df52008-02-15 09:19:42 +01001198static int qeth_l3_start_ipassists(struct qeth_card *card)
1199{
Carsten Otte847a50f2010-06-21 22:57:05 +00001200 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +00001201
Stefan Raspl0f547612013-01-21 02:30:20 +00001202 if (qeth_set_access_ctrl_online(card, 0))
1203 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001204 qeth_l3_start_ipa_arp_processing(card); /* go on*/
1205 qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
1206 qeth_l3_start_ipa_source_mac(card); /* go on*/
1207 qeth_l3_start_ipa_vlan(card); /* go on*/
1208 qeth_l3_start_ipa_multicast(card); /* go on*/
1209 qeth_l3_start_ipa_ipv6(card); /* go on*/
1210 qeth_l3_start_ipa_broadcast(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +01001211 return 0;
1212}
1213
Frank Blaschka4a71df52008-02-15 09:19:42 +01001214static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
1215 struct qeth_reply *reply, unsigned long data)
1216{
1217 struct qeth_ipa_cmd *cmd;
1218
1219 cmd = (struct qeth_ipa_cmd *) data;
1220 if (cmd->hdr.return_code == 0)
1221 memcpy(card->dev->dev_addr,
1222 cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
1223 else
Joe Perches18336112012-07-12 22:33:10 -07001224 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001225
1226 return 0;
1227}
1228
1229static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
1230{
1231 int rc = 0;
1232 struct qeth_cmd_buffer *iob;
1233 struct qeth_ipa_cmd *cmd;
1234
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001235 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001236
1237 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1238 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001239 if (!iob)
1240 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001241 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1242 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1243 card->info.unique_id;
1244
1245 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
1246 NULL);
1247 return rc;
1248}
1249
1250static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
1251 struct qeth_reply *reply, unsigned long data)
1252{
1253 struct qeth_ipa_cmd *cmd;
1254
1255 cmd = (struct qeth_ipa_cmd *) data;
1256 if (cmd->hdr.return_code == 0)
1257 card->info.unique_id = *((__u16 *)
1258 &cmd->data.create_destroy_addr.unique_id[6]);
1259 else {
1260 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1261 UNIQUE_ID_NOT_BY_CARD;
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001262 dev_warn(&card->gdev->dev, "The network adapter failed to "
1263 "generate a unique ID\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001264 }
1265 return 0;
1266}
1267
1268static int qeth_l3_get_unique_id(struct qeth_card *card)
1269{
1270 int rc = 0;
1271 struct qeth_cmd_buffer *iob;
1272 struct qeth_ipa_cmd *cmd;
1273
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001274 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001275
1276 if (!qeth_is_supported(card, IPA_IPV6)) {
1277 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1278 UNIQUE_ID_NOT_BY_CARD;
1279 return 0;
1280 }
1281
1282 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1283 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001284 if (!iob)
1285 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001286 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1287 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1288 card->info.unique_id;
1289
1290 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1291 return rc;
1292}
1293
Ursula Braun76b11f82010-01-11 02:50:50 +00001294static int
1295qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1296 unsigned long data)
1297{
1298 struct qeth_ipa_cmd *cmd;
1299 __u16 rc;
1300
1301 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1302
1303 cmd = (struct qeth_ipa_cmd *)data;
1304 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001305 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001306 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001307 switch (cmd->data.diagass.action) {
1308 case QETH_DIAGS_CMD_TRACE_QUERY:
1309 break;
1310 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001311 switch (rc) {
1312 case 0:
1313 case IPA_RC_INVALID_SUBCMD:
1314 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1315 dev_info(&card->gdev->dev, "The HiperSockets network "
1316 "traffic analyzer is deactivated\n");
1317 break;
1318 default:
1319 break;
1320 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001321 break;
1322 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001323 switch (rc) {
1324 case 0:
1325 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1326 dev_info(&card->gdev->dev, "The HiperSockets network "
1327 "traffic analyzer is activated\n");
1328 break;
1329 case IPA_RC_HARDWARE_AUTH_ERROR:
1330 dev_warn(&card->gdev->dev, "The device is not "
1331 "authorized to run as a HiperSockets network "
1332 "traffic analyzer\n");
1333 break;
1334 case IPA_RC_TRACE_ALREADY_ACTIVE:
1335 dev_warn(&card->gdev->dev, "A HiperSockets "
1336 "network traffic analyzer is already "
1337 "active in the HiperSockets LAN\n");
1338 break;
1339 default:
1340 break;
1341 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001342 break;
1343 default:
1344 QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
1345 cmd->data.diagass.action, QETH_CARD_IFNAME(card));
1346 }
1347
1348 return 0;
1349}
1350
1351static int
1352qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1353{
1354 struct qeth_cmd_buffer *iob;
1355 struct qeth_ipa_cmd *cmd;
1356
1357 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1358
1359 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001360 if (!iob)
1361 return -ENOMEM;
Ursula Braun76b11f82010-01-11 02:50:50 +00001362 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1363 cmd->data.diagass.subcmd_len = 16;
1364 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1365 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1366 cmd->data.diagass.action = diags_cmd;
1367 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1368}
1369
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001370static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001371{
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001372 ip_eth_mc_map(ipm, mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001373}
1374
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001375static void qeth_l3_mark_all_mc_to_be_deleted(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001376{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001377 struct qeth_ipaddr *addr;
1378 int i;
1379
1380 hash_for_each(card->ip_mc_htable, i, addr, hnode)
1381 addr->disp_flag = QETH_DISP_ADDR_DELETE;
1382
1383}
1384
1385static void qeth_l3_add_all_new_mc(struct qeth_card *card)
1386{
1387 struct qeth_ipaddr *addr;
1388 struct hlist_node *tmp;
1389 int i;
1390 int rc;
1391
1392 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1393 if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
1394 rc = qeth_l3_register_addr_entry(card, addr);
1395 if (!rc || (rc == IPA_RC_LAN_OFFLINE))
1396 addr->ref_counter = 1;
1397 else {
1398 hash_del(&addr->hnode);
1399 kfree(addr);
1400 }
1401 }
1402 }
1403
1404}
1405
1406static void qeth_l3_delete_nonused_mc(struct qeth_card *card)
1407{
1408 struct qeth_ipaddr *addr;
1409 struct hlist_node *tmp;
1410 int i;
1411 int rc;
1412
1413 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1414 if (addr->disp_flag == QETH_DISP_ADDR_DELETE) {
1415 rc = qeth_l3_deregister_addr_entry(card, addr);
1416 if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND)) {
1417 hash_del(&addr->hnode);
1418 kfree(addr);
1419 }
1420 }
1421 }
1422
1423}
1424
1425
1426static void
1427qeth_l3_add_mc_to_hash(struct qeth_card *card, struct in_device *in4_dev)
1428{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001429 struct ip_mc_list *im4;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001430 struct qeth_ipaddr *tmp, *ipm;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001431 char buf[MAX_ADDR_LEN];
1432
Carsten Otte847a50f2010-06-21 22:57:05 +00001433 QETH_CARD_TEXT(card, 4, "addmc");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001434
1435 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1436 if (!tmp)
1437 return;
1438
Sachin Santf3aa3132010-11-26 02:41:17 +00001439 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1440 im4 = rcu_dereference(im4->next_rcu)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001441 qeth_l3_get_mac_for_ipm(im4->multiaddr, buf);
1442
1443 tmp->u.a4.addr = im4->multiaddr;
1444 memcpy(tmp->mac, buf, sizeof(tmp->mac));
Julian Wiedmann0cfe6df2017-12-01 10:14:49 +01001445 tmp->is_multicast = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001446
1447 ipm = qeth_l3_ip_from_hash(card, tmp);
1448 if (ipm) {
1449 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1450 } else {
1451 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1452 if (!ipm)
1453 continue;
1454 memcpy(ipm->mac, buf, sizeof(tmp->mac));
1455 ipm->u.a4.addr = im4->multiaddr;
1456 ipm->is_multicast = 1;
1457 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1458 hash_add(card->ip_mc_htable,
1459 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1460 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001461 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001462
1463 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001464}
1465
Jiri Pirko0347af52013-01-03 22:48:58 +00001466/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001467static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1468{
1469 struct in_device *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001470 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001471
Carsten Otte847a50f2010-06-21 22:57:05 +00001472 QETH_CARD_TEXT(card, 4, "addmcvl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001473
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001474 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001475 return;
1476
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001477 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1478 struct net_device *netdev;
1479
dingtianhongf06c7f92014-05-09 14:58:05 +08001480 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001481 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001482 if (netdev == NULL ||
1483 !(netdev->flags & IFF_UP))
1484 continue;
Jiri Pirko0347af52013-01-03 22:48:58 +00001485 in_dev = __in_dev_get_rcu(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001486 if (!in_dev)
1487 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001488 qeth_l3_add_mc_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001489 }
1490}
1491
1492static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1493{
1494 struct in_device *in4_dev;
1495
Carsten Otte847a50f2010-06-21 22:57:05 +00001496 QETH_CARD_TEXT(card, 4, "chkmcv4");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001497
Sachin Santf3aa3132010-11-26 02:41:17 +00001498 rcu_read_lock();
Jiri Pirko0347af52013-01-03 22:48:58 +00001499 in4_dev = __in_dev_get_rcu(card->dev);
1500 if (in4_dev == NULL)
1501 goto unlock;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001502 qeth_l3_add_mc_to_hash(card, in4_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001503 qeth_l3_add_vlan_mc(card);
Jiri Pirko0347af52013-01-03 22:48:58 +00001504unlock:
Sachin Santf3aa3132010-11-26 02:41:17 +00001505 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001506}
1507
1508#ifdef CONFIG_QETH_IPV6
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001509static void
1510qeth_l3_add_mc6_to_hash(struct qeth_card *card, struct inet6_dev *in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001511{
1512 struct qeth_ipaddr *ipm;
1513 struct ifmcaddr6 *im6;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001514 struct qeth_ipaddr *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001515 char buf[MAX_ADDR_LEN];
1516
Carsten Otte847a50f2010-06-21 22:57:05 +00001517 QETH_CARD_TEXT(card, 4, "addmc6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001518
1519 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1520 if (!tmp)
1521 return;
1522
Frank Blaschka4a71df52008-02-15 09:19:42 +01001523 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
1524 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001525
1526 memcpy(tmp->mac, buf, sizeof(tmp->mac));
1527 memcpy(&tmp->u.a6.addr, &im6->mca_addr.s6_addr,
1528 sizeof(struct in6_addr));
1529 tmp->is_multicast = 1;
1530
1531 ipm = qeth_l3_ip_from_hash(card, tmp);
1532 if (ipm) {
1533 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1534 continue;
1535 }
1536
Frank Blaschka4a71df52008-02-15 09:19:42 +01001537 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1538 if (!ipm)
1539 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001540
Frank Blaschka4a71df52008-02-15 09:19:42 +01001541 memcpy(ipm->mac, buf, OSA_ADDR_LEN);
1542 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1543 sizeof(struct in6_addr));
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001544 ipm->is_multicast = 1;
1545 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1546 hash_add(card->ip_mc_htable,
1547 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1548
Frank Blaschka4a71df52008-02-15 09:19:42 +01001549 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001550 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001551}
1552
Jiri Pirko0347af52013-01-03 22:48:58 +00001553/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001554static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1555{
1556 struct inet6_dev *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001557 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001558
Carsten Otte847a50f2010-06-21 22:57:05 +00001559 QETH_CARD_TEXT(card, 4, "admc6vl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001560
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001561 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001562 return;
1563
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001564 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1565 struct net_device *netdev;
1566
dingtianhongf06c7f92014-05-09 14:58:05 +08001567 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001568 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001569 if (netdev == NULL ||
1570 !(netdev->flags & IFF_UP))
1571 continue;
1572 in_dev = in6_dev_get(netdev);
1573 if (!in_dev)
1574 continue;
1575 read_lock_bh(&in_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001576 qeth_l3_add_mc6_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001577 read_unlock_bh(&in_dev->lock);
1578 in6_dev_put(in_dev);
1579 }
1580}
1581
1582static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1583{
1584 struct inet6_dev *in6_dev;
1585
Carsten Otte847a50f2010-06-21 22:57:05 +00001586 QETH_CARD_TEXT(card, 4, "chkmcv6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001587
Frank Blaschka4a71df52008-02-15 09:19:42 +01001588 if (!qeth_is_supported(card, IPA_IPV6))
1589 return ;
1590 in6_dev = in6_dev_get(card->dev);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001591 if (!in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001592 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001593
Jiri Pirko0347af52013-01-03 22:48:58 +00001594 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001595 read_lock_bh(&in6_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001596 qeth_l3_add_mc6_to_hash(card, in6_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001597 qeth_l3_add_vlan_mc6(card);
1598 read_unlock_bh(&in6_dev->lock);
Jiri Pirko0347af52013-01-03 22:48:58 +00001599 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001600 in6_dev_put(in6_dev);
1601}
1602#endif /* CONFIG_QETH_IPV6 */
1603
1604static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
1605 unsigned short vid)
1606{
1607 struct in_device *in_dev;
1608 struct in_ifaddr *ifa;
1609 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001610 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001611
Carsten Otte847a50f2010-06-21 22:57:05 +00001612 QETH_CARD_TEXT(card, 4, "frvaddr4");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001613
dingtianhongf06c7f92014-05-09 14:58:05 +08001614 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
frank.blaschka@de.ibm.comeabfbe62012-07-24 22:34:29 +00001615 if (!netdev)
1616 return;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001617 in_dev = in_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001618 if (!in_dev)
1619 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001620
1621 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1622 if (!addr)
Julian Wiedmann20610f52017-10-18 17:40:17 +02001623 goto out;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001624
1625 spin_lock_bh(&card->ip_lock);
1626
Frank Blaschka4a71df52008-02-15 09:19:42 +01001627 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001628 addr->u.a4.addr = ifa->ifa_address;
1629 addr->u.a4.mask = ifa->ifa_mask;
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);
Julian Wiedmann20610f52017-10-18 17:40:17 +02001637out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001638 in_dev_put(in_dev);
1639}
1640
1641static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
1642 unsigned short vid)
1643{
1644#ifdef CONFIG_QETH_IPV6
1645 struct inet6_dev *in6_dev;
1646 struct inet6_ifaddr *ifa;
1647 struct qeth_ipaddr *addr;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001648 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001649
Carsten Otte847a50f2010-06-21 22:57:05 +00001650 QETH_CARD_TEXT(card, 4, "frvaddr6");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001651
dingtianhongf06c7f92014-05-09 14:58:05 +08001652 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
frank.blaschka@de.ibm.comeabfbe62012-07-24 22:34:29 +00001653 if (!netdev)
1654 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001655
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001656 in6_dev = in6_dev_get(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001657 if (!in6_dev)
1658 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001659
1660 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1661 if (!addr)
Julian Wiedmann20610f52017-10-18 17:40:17 +02001662 goto out;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001663
1664 spin_lock_bh(&card->ip_lock);
1665
Frank Blaschka70f60a22010-03-22 09:59:48 -07001666 list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001667 memcpy(&addr->u.a6.addr, &ifa->addr,
1668 sizeof(struct in6_addr));
1669 addr->u.a6.pfxlen = ifa->prefix_len;
1670 addr->type = QETH_IP_TYPE_NORMAL;
1671 qeth_l3_delete_ip(card, addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001672 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001673
1674 spin_unlock_bh(&card->ip_lock);
1675
1676 kfree(addr);
Julian Wiedmann20610f52017-10-18 17:40:17 +02001677out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001678 in6_dev_put(in6_dev);
1679#endif /* CONFIG_QETH_IPV6 */
1680}
1681
1682static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1683 unsigned short vid)
1684{
Jiri Pirko0347af52013-01-03 22:48:58 +00001685 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001686 qeth_l3_free_vlan_addresses4(card, vid);
1687 qeth_l3_free_vlan_addresses6(card, vid);
Jiri Pirko0347af52013-01-03 22:48:58 +00001688 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001689}
1690
Patrick McHardy80d5c362013-04-19 02:04:28 +00001691static int qeth_l3_vlan_rx_add_vid(struct net_device *dev,
1692 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001693{
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001694 struct qeth_card *card = dev->ml_priv;
1695
1696 set_bit(vid, card->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001697 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001698}
1699
Patrick McHardy80d5c362013-04-19 02:04:28 +00001700static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev,
1701 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001702{
Heiko Carstens509e2562008-07-26 02:24:10 -07001703 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001704
Carsten Otte847a50f2010-06-21 22:57:05 +00001705 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001706
Ursula Braun8e98ac42009-03-24 20:57:18 +00001707 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001708 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -05001709 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +00001710 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001711 /* unregister IP addresses of vlan device */
1712 qeth_l3_free_vlan_addresses(card, vid);
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001713 clear_bit(vid, card->active_vlans);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001714 qeth_l3_set_multicast_list(card->dev);
Jiri Pirko8e586132011-12-08 19:52:37 -05001715 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001716}
1717
Ursula Braun10651db2010-10-01 02:51:13 +00001718static inline int qeth_l3_rebuild_skb(struct qeth_card *card,
1719 struct sk_buff *skb, struct qeth_hdr *hdr,
1720 unsigned short *vlan_id)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001721{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001722 __be16 prot;
1723 struct iphdr *ip_hdr;
1724 unsigned char tg_addr[MAX_ADDR_LEN];
Ursula Braun10651db2010-10-01 02:51:13 +00001725 int is_vlan = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001726
1727 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
1728 prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
1729 ETH_P_IP);
1730 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1731 case QETH_CAST_MULTICAST:
1732 switch (prot) {
1733#ifdef CONFIG_QETH_IPV6
1734 case __constant_htons(ETH_P_IPV6):
1735 ndisc_mc_map((struct in6_addr *)
1736 skb->data + 24,
1737 tg_addr, card->dev, 0);
1738 break;
1739#endif
1740 case __constant_htons(ETH_P_IP):
1741 ip_hdr = (struct iphdr *)skb->data;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001742 ip_eth_mc_map(ip_hdr->daddr, tg_addr);
1743 break;
1744 default:
1745 memcpy(tg_addr, card->dev->broadcast,
1746 card->dev->addr_len);
1747 }
1748 card->stats.multicast++;
1749 skb->pkt_type = PACKET_MULTICAST;
1750 break;
1751 case QETH_CAST_BROADCAST:
1752 memcpy(tg_addr, card->dev->broadcast,
1753 card->dev->addr_len);
1754 card->stats.multicast++;
1755 skb->pkt_type = PACKET_BROADCAST;
1756 break;
1757 case QETH_CAST_UNICAST:
1758 case QETH_CAST_ANYCAST:
1759 case QETH_CAST_NOCAST:
1760 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00001761 if (card->options.sniffer)
1762 skb->pkt_type = PACKET_OTHERHOST;
1763 else
1764 skb->pkt_type = PACKET_HOST;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001765 memcpy(tg_addr, card->dev->dev_addr,
1766 card->dev->addr_len);
1767 }
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001768 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1769 card->dev->header_ops->create(skb, card->dev, prot,
1770 tg_addr, &hdr->hdr.l3.dest_addr[2],
1771 card->dev->addr_len);
1772 else
1773 card->dev->header_ops->create(skb, card->dev, prot,
1774 tg_addr, "FAKELL", card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001775 }
1776
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001777 skb->protocol = eth_type_trans(skb, card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001778
1779 if (hdr->hdr.l3.ext_flags &
1780 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
Ursula Braun10651db2010-10-01 02:51:13 +00001781 *vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
Frank Blaschka4a71df52008-02-15 09:19:42 +01001782 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
Ursula Braun10651db2010-10-01 02:51:13 +00001783 is_vlan = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001784 }
1785
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001786 if (card->dev->features & NETIF_F_RXCSUM) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001787 if ((hdr->hdr.l3.ext_flags &
Ursula Braunb9139802009-05-19 21:38:40 +00001788 (QETH_HDR_EXT_CSUM_HDR_REQ |
1789 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
1790 (QETH_HDR_EXT_CSUM_HDR_REQ |
1791 QETH_HDR_EXT_CSUM_TRANSP_REQ))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001792 skb->ip_summed = CHECKSUM_UNNECESSARY;
1793 else
Ursula Braunb9139802009-05-19 21:38:40 +00001794 skb->ip_summed = CHECKSUM_NONE;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00001795 } else
1796 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun10651db2010-10-01 02:51:13 +00001797 return is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001798}
1799
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001800static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1801 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001802{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001803 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001804 struct sk_buff *skb;
1805 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001806 __u16 vlan_tag = 0;
Ursula Braun10651db2010-10-01 02:51:13 +00001807 int is_vlan;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001808 unsigned int len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001809 __u16 magic;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001810
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001811 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +00001812 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001813 while (budget) {
1814 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +00001815 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001816 &card->rx.b_element, &card->rx.e_offset, &hdr);
1817 if (!skb) {
1818 *done = 1;
1819 break;
1820 }
1821 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001822 switch (hdr->hdr.l3.id) {
1823 case QETH_HEADER_TYPE_LAYER3:
Frank Blaschkab3332932011-08-08 01:33:59 +00001824 magic = *(__u16 *)skb->data;
1825 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
1826 (magic == ETH_P_AF_IUCV)) {
1827 skb->protocol = ETH_P_AF_IUCV;
1828 skb->pkt_type = PACKET_HOST;
1829 skb->mac_header = NET_SKB_PAD;
1830 skb->dev = card->dev;
1831 len = skb->len;
1832 card->dev->header_ops->create(skb, card->dev, 0,
1833 card->dev->dev_addr, "FAKELL",
1834 card->dev->addr_len);
1835 netif_receive_skb(skb);
1836 } else {
1837 is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
Ursula Braun10651db2010-10-01 02:51:13 +00001838 &vlan_tag);
Frank Blaschkab3332932011-08-08 01:33:59 +00001839 len = skb->len;
1840 if (is_vlan && !card->options.sniffer)
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001841 __vlan_hwaccel_put_tag(skb,
1842 htons(ETH_P_8021Q), vlan_tag);
Frank Blaschkab3332932011-08-08 01:33:59 +00001843 napi_gro_receive(&card->napi, skb);
1844 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001845 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00001846 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
1847 skb->pkt_type = PACKET_HOST;
1848 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00001849 len = skb->len;
1850 netif_receive_skb(skb);
1851 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001852 default:
1853 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00001854 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001855 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001856 continue;
1857 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001858 work_done++;
1859 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001860 card->stats.rx_packets++;
1861 card->stats.rx_bytes += len;
1862 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001863 return work_done;
1864}
1865
1866static int qeth_l3_poll(struct napi_struct *napi, int budget)
1867{
1868 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
1869 int work_done = 0;
1870 struct qeth_qdio_buffer *buffer;
1871 int done;
1872 int new_budget = budget;
1873
1874 if (card->options.performance_stats) {
1875 card->perf_stats.inbound_cnt++;
1876 card->perf_stats.inbound_start_time = qeth_get_micros();
1877 }
1878
1879 while (1) {
1880 if (!card->rx.b_count) {
1881 card->rx.qdio_err = 0;
1882 card->rx.b_count = qdio_get_next_buffers(
1883 card->data.ccwdev, 0, &card->rx.b_index,
1884 &card->rx.qdio_err);
1885 if (card->rx.b_count <= 0) {
1886 card->rx.b_count = 0;
1887 break;
1888 }
1889 card->rx.b_element =
1890 &card->qdio.in_q->bufs[card->rx.b_index]
1891 .buffer->element[0];
1892 card->rx.e_offset = 0;
1893 }
1894
1895 while (card->rx.b_count) {
1896 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
1897 if (!(card->rx.qdio_err &&
1898 qeth_check_qdio_errors(card, buffer->buffer,
1899 card->rx.qdio_err, "qinerr")))
1900 work_done += qeth_l3_process_inbound_buffer(
1901 card, new_budget, &done);
1902 else
1903 done = 1;
1904
1905 if (done) {
1906 if (card->options.performance_stats)
1907 card->perf_stats.bufs_rec++;
1908 qeth_put_buffer_pool_entry(card,
1909 buffer->pool_entry);
1910 qeth_queue_input_buffer(card, card->rx.b_index);
1911 card->rx.b_count--;
1912 if (card->rx.b_count) {
1913 card->rx.b_index =
1914 (card->rx.b_index + 1) %
1915 QDIO_MAX_BUFFERS_PER_Q;
1916 card->rx.b_element =
1917 &card->qdio.in_q
1918 ->bufs[card->rx.b_index]
1919 .buffer->element[0];
1920 card->rx.e_offset = 0;
1921 }
1922 }
1923
1924 if (work_done >= budget)
1925 goto out;
1926 else
1927 new_budget = budget - work_done;
1928 }
1929 }
1930
1931 napi_complete(napi);
1932 if (qdio_start_irq(card->data.ccwdev, 0))
1933 napi_schedule(&card->napi);
1934out:
1935 if (card->options.performance_stats)
1936 card->perf_stats.inbound_time += qeth_get_micros() -
1937 card->perf_stats.inbound_start_time;
1938 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001939}
1940
1941static int qeth_l3_verify_vlan_dev(struct net_device *dev,
1942 struct qeth_card *card)
1943{
1944 int rc = 0;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001945 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001946
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001947 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1948 struct net_device *netdev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001949
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001950 rcu_read_lock();
dingtianhongf06c7f92014-05-09 14:58:05 +08001951 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001952 vid);
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001953 rcu_read_unlock();
1954 if (netdev == dev) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001955 rc = QETH_VLAN_CARD;
1956 break;
1957 }
1958 }
1959
Heiko Carstens509e2562008-07-26 02:24:10 -07001960 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001961 return 0;
1962
1963 return rc;
1964}
1965
1966static int qeth_l3_verify_dev(struct net_device *dev)
1967{
1968 struct qeth_card *card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001969 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001970 unsigned long flags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001971
1972 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
1973 list_for_each_entry(card, &qeth_core_card_list.list, list) {
1974 if (card->dev == dev) {
1975 rc = QETH_REAL_CARD;
1976 break;
1977 }
1978 rc = qeth_l3_verify_vlan_dev(dev, card);
1979 if (rc)
1980 break;
1981 }
1982 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
1983
1984 return rc;
1985}
1986
1987static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
1988{
1989 struct qeth_card *card = NULL;
1990 int rc;
1991
1992 rc = qeth_l3_verify_dev(dev);
1993 if (rc == QETH_REAL_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07001994 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001995 else if (rc == QETH_VLAN_CARD)
Heiko Carstens509e2562008-07-26 02:24:10 -07001996 card = vlan_dev_real_dev(dev)->ml_priv;
Frank Blaschkae5bd7be2008-06-06 12:37:44 +02001997 if (card && card->options.layer2)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001998 card = NULL;
Carsten Otte847a50f2010-06-21 22:57:05 +00001999 if (card)
2000 QETH_CARD_TEXT_(card, 4, "%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002001 return card ;
2002}
2003
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +02002004static void qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002005{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002006 QETH_DBF_TEXT(SETUP, 2, "stopcard");
2007 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002008
2009 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00002010 if (card->options.sniffer &&
2011 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
2012 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002013 if (card->read.state == CH_STATE_UP &&
2014 card->write.state == CH_STATE_UP &&
2015 (card->state == CARD_STATE_UP)) {
2016 if (recovery_mode)
2017 qeth_l3_stop(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002018 else {
Ursula Braun869da902010-03-08 20:36:56 +00002019 rtnl_lock();
2020 dev_close(card->dev);
2021 rtnl_unlock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02002022 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002023 card->state = CARD_STATE_SOFTSETUP;
2024 }
2025 if (card->state == CARD_STATE_SOFTSETUP) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002026 qeth_l3_clear_ip_htable(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002027 qeth_clear_ipacmd_list(card);
2028 card->state = CARD_STATE_HARDSETUP;
2029 }
2030 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002031 qeth_qdio_clear_card(card, 0);
2032 qeth_clear_qdio_buffers(card);
2033 qeth_clear_working_pool_list(card);
2034 card->state = CARD_STATE_DOWN;
2035 }
2036 if (card->state == CARD_STATE_DOWN) {
2037 qeth_clear_cmd_buffers(&card->read);
2038 qeth_clear_cmd_buffers(&card->write);
2039 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002040}
2041
Ursula Braun76b11f82010-01-11 02:50:50 +00002042/*
2043 * test for and Switch promiscuous mode (on or off)
2044 * either for guestlan or HiperSocket Sniffer
2045 */
2046static void
2047qeth_l3_handle_promisc_mode(struct qeth_card *card)
2048{
2049 struct net_device *dev = card->dev;
2050
2051 if (((dev->flags & IFF_PROMISC) &&
2052 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
2053 (!(dev->flags & IFF_PROMISC) &&
2054 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
2055 return;
2056
2057 if (card->info.guestlan) { /* Guestlan trace */
2058 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2059 qeth_setadp_promisc_mode(card);
2060 } else if (card->options.sniffer && /* HiperSockets trace */
2061 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
2062 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00002063 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002064 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
2065 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00002066 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00002067 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
2068 }
2069 }
2070}
2071
Frank Blaschka4a71df52008-02-15 09:19:42 +01002072static void qeth_l3_set_multicast_list(struct net_device *dev)
2073{
Heiko Carstens509e2562008-07-26 02:24:10 -07002074 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002075
Carsten Otte847a50f2010-06-21 22:57:05 +00002076 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +00002077 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
2078 (card->state != CARD_STATE_UP))
2079 return;
Ursula Braun76b11f82010-01-11 02:50:50 +00002080 if (!card->options.sniffer) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002081
2082 spin_lock_bh(&card->mclock);
2083
2084 qeth_l3_mark_all_mc_to_be_deleted(card);
2085
Ursula Braun76b11f82010-01-11 02:50:50 +00002086 qeth_l3_add_multicast_ipv4(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002087#ifdef CONFIG_QETH_IPV6
Ursula Braun76b11f82010-01-11 02:50:50 +00002088 qeth_l3_add_multicast_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002089#endif
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002090 qeth_l3_delete_nonused_mc(card);
2091 qeth_l3_add_all_new_mc(card);
2092
2093 spin_unlock_bh(&card->mclock);
2094
Ursula Braun76b11f82010-01-11 02:50:50 +00002095 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
2096 return;
2097 }
2098 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002099}
2100
2101static const char *qeth_l3_arp_get_error_cause(int *rc)
2102{
2103 switch (*rc) {
2104 case QETH_IPA_ARP_RC_FAILED:
2105 *rc = -EIO;
2106 return "operation failed";
2107 case QETH_IPA_ARP_RC_NOTSUPP:
2108 *rc = -EOPNOTSUPP;
2109 return "operation not supported";
2110 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
2111 *rc = -EINVAL;
2112 return "argument out of range";
2113 case QETH_IPA_ARP_RC_Q_NOTSUPP:
2114 *rc = -EOPNOTSUPP;
2115 return "query operation not supported";
2116 case QETH_IPA_ARP_RC_Q_NO_DATA:
2117 *rc = -ENOENT;
2118 return "no query data available";
2119 default:
2120 return "unknown error";
2121 }
2122}
2123
2124static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
2125{
2126 int tmp;
2127 int rc;
2128
Carsten Otte847a50f2010-06-21 22:57:05 +00002129 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002130
2131 /*
2132 * currently GuestLAN only supports the ARP assist function
2133 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
2134 * thus we say EOPNOTSUPP for this ARP function
2135 */
2136 if (card->info.guestlan)
2137 return -EOPNOTSUPP;
2138 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002139 return -EOPNOTSUPP;
2140 }
Thomas Richter4d7def22015-09-18 16:06:51 +02002141 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002142 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
2143 no_entries);
2144 if (rc) {
2145 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002146 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
2147 "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002148 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2149 }
2150 return rc;
2151}
2152
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002153static __u32 get_arp_entry_size(struct qeth_card *card,
2154 struct qeth_arp_query_data *qdata,
2155 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002156{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002157 __u32 rc;
2158 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002159
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002160 is_hsi = qdata->reply_bits == 5;
2161 if (type->ip == QETHARP_IP_ADDR_V4) {
2162 QETH_CARD_TEXT(card, 4, "arpev4");
2163 if (strip_entries) {
2164 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
2165 sizeof(struct qeth_arp_qi_entry7_short);
2166 } else {
2167 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
2168 sizeof(struct qeth_arp_qi_entry7);
2169 }
2170 } else if (type->ip == QETHARP_IP_ADDR_V6) {
2171 QETH_CARD_TEXT(card, 4, "arpev6");
2172 if (strip_entries) {
2173 rc = is_hsi ?
2174 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
2175 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
2176 } else {
2177 rc = is_hsi ?
2178 sizeof(struct qeth_arp_qi_entry5_ipv6) :
2179 sizeof(struct qeth_arp_qi_entry7_ipv6);
2180 }
2181 } else {
2182 QETH_CARD_TEXT(card, 4, "arpinv");
2183 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002184 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002185
2186 return rc;
2187}
2188
2189static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
2190{
2191 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
2192 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002193}
2194
2195static int qeth_l3_arp_query_cb(struct qeth_card *card,
2196 struct qeth_reply *reply, unsigned long data)
2197{
2198 struct qeth_ipa_cmd *cmd;
2199 struct qeth_arp_query_data *qdata;
2200 struct qeth_arp_query_info *qinfo;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002201 int i;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002202 int e;
2203 int entrybytes_done;
2204 int stripped_bytes;
2205 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002206
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002207 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002208
2209 qinfo = (struct qeth_arp_query_info *) reply->param;
2210 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002211 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002212 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002213 QETH_CARD_TEXT(card, 4, "arpcberr");
2214 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002215 return 0;
2216 }
2217 if (cmd->data.setassparms.hdr.return_code) {
2218 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002219 QETH_CARD_TEXT(card, 4, "setaperr");
2220 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002221 return 0;
2222 }
2223 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00002224 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002225
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002226 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
2227 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
2228 entrybytes_done = 0;
2229 for (e = 0; e < qdata->no_entries; ++e) {
2230 char *cur_entry;
2231 __u32 esize;
2232 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002233
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002234 cur_entry = &qdata->data + entrybytes_done;
2235 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
2236 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
2237 QETH_CARD_TEXT(card, 4, "pmis");
2238 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
2239 break;
2240 }
2241 esize = get_arp_entry_size(card, qdata, etype,
2242 do_strip_entries);
2243 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
2244 if (!esize)
2245 break;
2246
2247 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
2248 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
Ursula Braune0a81142012-03-07 02:06:28 +00002249 cmd->hdr.return_code = IPA_RC_ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002250 goto out_error;
2251 }
2252
2253 memcpy(qinfo->udata + qinfo->udata_offset,
2254 &qdata->data + entrybytes_done + stripped_bytes,
2255 esize);
2256 entrybytes_done += esize + stripped_bytes;
2257 qinfo->udata_offset += esize;
2258 ++qinfo->no_entries;
2259 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002260 /* check if all replies received ... */
2261 if (cmd->data.setassparms.hdr.seq_no <
2262 cmd->data.setassparms.hdr.number_of_replies)
2263 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002264 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002265 memcpy(qinfo->udata, &qinfo->no_entries, 4);
2266 /* keep STRIP_ENTRIES flag so the user program can distinguish
2267 * stripped entries from normal ones */
2268 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
2269 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
2270 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002271 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002272 return 0;
2273out_error:
2274 i = 0;
2275 memcpy(qinfo->udata, &i, 4);
2276 return 0;
2277}
2278
2279static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
2280 struct qeth_cmd_buffer *iob, int len,
2281 int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
2282 unsigned long),
2283 void *reply_param)
2284{
Carsten Otte847a50f2010-06-21 22:57:05 +00002285 QETH_CARD_TEXT(card, 4, "sendarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002286
2287 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
2288 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
2289 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
2290 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
2291 reply_cb, reply_param);
2292}
2293
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002294static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
2295 enum qeth_prot_versions prot,
2296 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002297{
2298 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002299 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002300 int tmp;
2301 int rc;
2302
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002303 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
2304
Thomas Richterb475e312015-12-11 12:27:54 +01002305 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
2306 IPA_CMD_ASS_ARP_QUERY_INFO,
2307 sizeof(struct qeth_arp_query_data)
2308 - sizeof(char),
2309 prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002310 if (!iob)
2311 return -ENOMEM;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002312 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2313 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
2314 cmd->data.setassparms.data.query_arp.reply_bits = 0;
2315 cmd->data.setassparms.data.query_arp.no_entries = 0;
2316 rc = qeth_l3_send_ipa_arp_cmd(card, iob,
2317 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
2318 qeth_l3_arp_query_cb, (void *)qinfo);
2319 if (rc) {
2320 tmp = rc;
2321 QETH_DBF_MESSAGE(2,
2322 "Error while querying ARP cache on %s: %s "
2323 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
2324 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2325 }
2326
2327 return rc;
2328}
2329
2330static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
2331{
2332 struct qeth_arp_query_info qinfo = {0, };
2333 int rc;
2334
Carsten Otte847a50f2010-06-21 22:57:05 +00002335 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002336
2337 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
2338 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002339 QETH_CARD_TEXT(card, 3, "arpqnsup");
2340 rc = -EOPNOTSUPP;
2341 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002342 }
2343 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002344 if (copy_from_user(&qinfo, udata, 6)) {
2345 rc = -EFAULT;
2346 goto out;
2347 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002348 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002349 if (!qinfo.udata) {
2350 rc = -ENOMEM;
2351 goto out;
2352 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002353 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002354 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002355 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002356 if (copy_to_user(udata, qinfo.udata, 4))
2357 rc = -EFAULT;
Sebastian Ott77a83ed2016-06-16 16:19:03 +02002358 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002359 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02002360#ifdef CONFIG_QETH_IPV6
2361 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
2362 /* fails in case of GuestLAN QDIO mode */
2363 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6, &qinfo);
2364 }
2365#endif
2366 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
2367 QETH_CARD_TEXT(card, 4, "qactf");
2368 rc = -EFAULT;
2369 goto free_and_out;
2370 }
2371 QETH_CARD_TEXT(card, 4, "qacts");
2372
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002373free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002374 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00002375out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01002376 return rc;
2377}
2378
2379static int qeth_l3_arp_add_entry(struct qeth_card *card,
2380 struct qeth_arp_cache_entry *entry)
2381{
2382 struct qeth_cmd_buffer *iob;
2383 char buf[16];
2384 int tmp;
2385 int rc;
2386
Carsten Otte847a50f2010-06-21 22:57:05 +00002387 QETH_CARD_TEXT(card, 3, "arpadent");
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_ADD_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
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_ADD_ENTRY,
2402 sizeof(struct qeth_arp_cache_entry),
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 sizeof(struct qeth_arp_cache_entry),
2408 (unsigned long) entry,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002409 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002410 if (rc) {
2411 tmp = rc;
2412 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002413 QETH_DBF_MESSAGE(2, "Could not add 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_remove_entry(struct qeth_card *card,
2421 struct qeth_arp_cache_entry *entry)
2422{
2423 struct qeth_cmd_buffer *iob;
2424 char buf[16] = {0, };
2425 int tmp;
2426 int rc;
2427
Carsten Otte847a50f2010-06-21 22:57:05 +00002428 QETH_CARD_TEXT(card, 3, "arprment");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002429
2430 /*
2431 * currently GuestLAN only supports the ARP assist function
2432 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
2433 * thus we say EOPNOTSUPP for this ARP function
2434 */
2435 if (card->info.guestlan)
2436 return -EOPNOTSUPP;
2437 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002438 return -EOPNOTSUPP;
2439 }
2440 memcpy(buf, entry, 12);
Thomas Richterb475e312015-12-11 12:27:54 +01002441 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002442 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
2443 12,
2444 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002445 if (!iob)
2446 return -ENOMEM;
Thomas Richter4d7def22015-09-18 16:06:51 +02002447 rc = qeth_send_setassparms(card, iob,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002448 12, (unsigned long)buf,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002449 qeth_setassparms_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002450 if (rc) {
2451 tmp = rc;
2452 memset(buf, 0, 16);
2453 qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002454 QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
2455 " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
2456 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002457 }
2458 return rc;
2459}
2460
2461static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2462{
2463 int rc;
2464 int tmp;
2465
Carsten Otte847a50f2010-06-21 22:57:05 +00002466 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002467
2468 /*
2469 * currently GuestLAN only supports the ARP assist function
2470 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
2471 * thus we say EOPNOTSUPP for this ARP function
2472 */
2473 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
2474 return -EOPNOTSUPP;
2475 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002476 return -EOPNOTSUPP;
2477 }
Thomas Richter4d7def22015-09-18 16:06:51 +02002478 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002479 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
2480 if (rc) {
2481 tmp = rc;
Frank Blaschka14cc21b2008-06-06 12:37:46 +02002482 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
2483 "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002484 qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
2485 }
2486 return rc;
2487}
2488
2489static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2490{
Heiko Carstens509e2562008-07-26 02:24:10 -07002491 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002492 struct qeth_arp_cache_entry arp_entry;
2493 struct mii_ioctl_data *mii_data;
2494 int rc = 0;
2495
2496 if (!card)
2497 return -ENODEV;
2498
Eugene Crosserc3521252015-01-16 14:05:47 +01002499 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002500 return -ENODEV;
2501
2502 switch (cmd) {
2503 case SIOC_QETH_ARP_SET_NO_ENTRIES:
2504 if (!capable(CAP_NET_ADMIN)) {
2505 rc = -EPERM;
2506 break;
2507 }
2508 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
2509 break;
2510 case SIOC_QETH_ARP_QUERY_INFO:
2511 if (!capable(CAP_NET_ADMIN)) {
2512 rc = -EPERM;
2513 break;
2514 }
2515 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
2516 break;
2517 case SIOC_QETH_ARP_ADD_ENTRY:
2518 if (!capable(CAP_NET_ADMIN)) {
2519 rc = -EPERM;
2520 break;
2521 }
2522 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2523 sizeof(struct qeth_arp_cache_entry)))
2524 rc = -EFAULT;
2525 else
2526 rc = qeth_l3_arp_add_entry(card, &arp_entry);
2527 break;
2528 case SIOC_QETH_ARP_REMOVE_ENTRY:
2529 if (!capable(CAP_NET_ADMIN)) {
2530 rc = -EPERM;
2531 break;
2532 }
2533 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
2534 sizeof(struct qeth_arp_cache_entry)))
2535 rc = -EFAULT;
2536 else
2537 rc = qeth_l3_arp_remove_entry(card, &arp_entry);
2538 break;
2539 case SIOC_QETH_ARP_FLUSH_CACHE:
2540 if (!capable(CAP_NET_ADMIN)) {
2541 rc = -EPERM;
2542 break;
2543 }
2544 rc = qeth_l3_arp_flush_cache(card);
2545 break;
2546 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
2547 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
2548 break;
2549 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +00002550 if ((card->info.type == QETH_CARD_TYPE_OSD ||
2551 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +01002552 !card->info.guestlan)
2553 return 1;
2554 return 0;
2555 break;
2556 case SIOCGMIIPHY:
2557 mii_data = if_mii(rq);
2558 mii_data->phy_id = 0;
2559 break;
2560 case SIOCGMIIREG:
2561 mii_data = if_mii(rq);
2562 if (mii_data->phy_id != 0)
2563 rc = -EINVAL;
2564 else
2565 mii_data->val_out = qeth_mdio_read(dev,
2566 mii_data->phy_id,
2567 mii_data->reg_num);
2568 break;
Frank Blaschkac3ab96f2012-02-08 00:19:49 +00002569 case SIOC_QETH_QUERY_OAT:
2570 rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data);
2571 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002572 default:
2573 rc = -EOPNOTSUPP;
2574 }
2575 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00002576 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002577 return rc;
2578}
2579
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002580int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2581{
2582 int cast_type = RTN_UNSPEC;
David S. Miller69cce1d2011-07-17 23:09:49 -07002583 struct neighbour *n = NULL;
2584 struct dst_entry *dst;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002585
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002586 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002587 dst = skb_dst(skb);
2588 if (dst)
David S. Miller24db1ba2012-07-02 22:02:33 -07002589 n = dst_neigh_lookup_skb(dst, skb);
David S. Miller69cce1d2011-07-17 23:09:49 -07002590 if (n) {
2591 cast_type = n->type;
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002592 rcu_read_unlock();
David S. Miller24db1ba2012-07-02 22:02:33 -07002593 neigh_release(n);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002594 if ((cast_type == RTN_BROADCAST) ||
2595 (cast_type == RTN_MULTICAST) ||
2596 (cast_type == RTN_ANYCAST))
2597 return cast_type;
2598 else
2599 return RTN_UNSPEC;
2600 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002601 rcu_read_unlock();
2602
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002603 /* try something else */
2604 if (skb->protocol == ETH_P_IPV6)
2605 return (skb_network_header(skb)[24] == 0xff) ?
2606 RTN_MULTICAST : 0;
2607 else if (skb->protocol == ETH_P_IP)
2608 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
2609 RTN_MULTICAST : 0;
2610 /* ... */
2611 if (!memcmp(skb->data, skb->dev->broadcast, 6))
2612 return RTN_BROADCAST;
2613 else {
2614 u16 hdr_mac;
2615
2616 hdr_mac = *((u16 *)skb->data);
2617 /* tr multicast? */
2618 switch (card->info.link_type) {
2619 case QETH_LINK_TYPE_HSTR:
2620 case QETH_LINK_TYPE_LANE_TR:
2621 if ((hdr_mac == QETH_TR_MAC_NC) ||
2622 (hdr_mac == QETH_TR_MAC_C))
2623 return RTN_MULTICAST;
2624 break;
2625 /* eth or so multicast? */
2626 default:
2627 if ((hdr_mac == QETH_ETH_MAC_V4) ||
2628 (hdr_mac == QETH_ETH_MAC_V6))
2629 return RTN_MULTICAST;
2630 }
2631 }
2632 return cast_type;
2633}
2634
Frank Blaschkab3332932011-08-08 01:33:59 +00002635static void qeth_l3_fill_af_iucv_hdr(struct qeth_card *card,
2636 struct qeth_hdr *hdr, struct sk_buff *skb)
2637{
2638 char daddr[16];
2639 struct af_iucv_trans_hdr *iucv_hdr;
2640
Frank Blaschkab3332932011-08-08 01:33:59 +00002641 memset(hdr, 0, sizeof(struct qeth_hdr));
2642 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2643 hdr->hdr.l3.ext_flags = 0;
Julian Wiedmann51533c42017-03-23 14:55:09 +01002644 hdr->hdr.l3.length = skb->len - ETH_HLEN;
Frank Blaschkab3332932011-08-08 01:33:59 +00002645 hdr->hdr.l3.flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
Julian Wiedmann51533c42017-03-23 14:55:09 +01002646
2647 iucv_hdr = (struct af_iucv_trans_hdr *) (skb->data + ETH_HLEN);
Frank Blaschkab3332932011-08-08 01:33:59 +00002648 memset(daddr, 0, sizeof(daddr));
2649 daddr[0] = 0xfe;
2650 daddr[1] = 0x80;
2651 memcpy(&daddr[8], iucv_hdr->destUserID, 8);
2652 memcpy(hdr->hdr.l3.dest_addr, daddr, 16);
2653}
2654
Frank Blaschka4a71df52008-02-15 09:19:42 +01002655static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2656 struct sk_buff *skb, int ipv, int cast_type)
2657{
David S. Miller69cce1d2011-07-17 23:09:49 -07002658 struct dst_entry *dst;
2659
Frank Blaschka4a71df52008-02-15 09:19:42 +01002660 memset(hdr, 0, sizeof(struct qeth_hdr));
2661 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2662 hdr->hdr.l3.ext_flags = 0;
2663
2664 /*
2665 * before we're going to overwrite this location with next hop ip.
2666 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2667 */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002668 if (skb_vlan_tag_present(skb)) {
Frank Blaschka213298f2008-04-24 10:15:22 +02002669 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2670 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2671 else
2672 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002673 hdr->hdr.l3.vlan_id = skb_vlan_tag_get(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002674 }
2675
2676 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002677
2678 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002679 dst = skb_dst(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002680 if (ipv == 4) {
David Miller87e75972012-02-01 10:49:17 +00002681 struct rtable *rt = (struct rtable *) dst;
2682 __be32 *pkey = &ip_hdr(skb)->daddr;
2683
2684 if (rt->rt_gateway)
2685 pkey = &rt->rt_gateway;
2686
Frank Blaschka4a71df52008-02-15 09:19:42 +01002687 /* IPv4 */
2688 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
2689 memset(hdr->hdr.l3.dest_addr, 0, 12);
David Miller87e75972012-02-01 10:49:17 +00002690 *((__be32 *) (&hdr->hdr.l3.dest_addr[12])) = *pkey;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002691 } else if (ipv == 6) {
David Miller87e75972012-02-01 10:49:17 +00002692 struct rt6_info *rt = (struct rt6_info *) dst;
2693 struct in6_addr *pkey = &ipv6_hdr(skb)->daddr;
2694
2695 if (!ipv6_addr_any(&rt->rt6i_gateway))
2696 pkey = &rt->rt6i_gateway;
2697
Frank Blaschka4a71df52008-02-15 09:19:42 +01002698 /* IPv6 */
2699 hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
2700 if (card->info.type == QETH_CARD_TYPE_IQD)
2701 hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
David Miller87e75972012-02-01 10:49:17 +00002702 memcpy(hdr->hdr.l3.dest_addr, pkey, 16);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002703 } else {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002704 if (!memcmp(skb->data + sizeof(struct qeth_hdr),
Frank Blaschka4a71df52008-02-15 09:19:42 +01002705 skb->dev->broadcast, 6)) {
2706 /* broadcast? */
2707 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
2708 QETH_HDR_PASSTHRU;
2709 } else {
2710 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
2711 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
2712 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2713 }
2714 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002715 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002716}
2717
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002718static inline void qeth_l3_hdr_csum(struct qeth_card *card,
2719 struct qeth_hdr *hdr, struct sk_buff *skb)
2720{
2721 struct iphdr *iph = ip_hdr(skb);
2722
2723 /* tcph->check contains already the pseudo hdr checksum
2724 * so just set the header flags
2725 */
2726 if (iph->protocol == IPPROTO_UDP)
2727 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
Frank Blaschka16c0f932011-01-12 20:42:25 +00002728 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
2729 QETH_HDR_EXT_CSUM_HDR_REQ;
2730 iph->check = 0;
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002731 if (card->options.performance_stats)
2732 card->perf_stats.tx_csum++;
2733}
2734
Frank Blaschka64ef8952009-03-24 20:57:16 +00002735static void qeth_tso_fill_header(struct qeth_card *card,
2736 struct qeth_hdr *qhdr, struct sk_buff *skb)
2737{
2738 struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
2739 struct tcphdr *tcph = tcp_hdr(skb);
2740 struct iphdr *iph = ip_hdr(skb);
2741 struct ipv6hdr *ip6h = ipv6_hdr(skb);
2742
2743 /*fix header to TSO values ...*/
2744 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
Frank Blaschka8fa92082010-11-26 02:41:20 +00002745 hdr->hdr.hdr.l3.length = skb->len - sizeof(struct qeth_hdr_tso);
Frank Blaschka64ef8952009-03-24 20:57:16 +00002746 /*set values which are fix for the first approach ...*/
2747 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
2748 hdr->ext.imb_hdr_no = 1;
2749 hdr->ext.hdr_type = 1;
2750 hdr->ext.hdr_version = 1;
2751 hdr->ext.hdr_len = 28;
2752 /*insert non-fix values */
2753 hdr->ext.mss = skb_shinfo(skb)->gso_size;
2754 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
2755 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
2756 sizeof(struct qeth_hdr_tso));
2757 tcph->check = 0;
2758 if (skb->protocol == ETH_P_IPV6) {
2759 ip6h->payload_len = 0;
2760 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
2761 0, IPPROTO_TCP, 0);
2762 } else {
2763 /*OSA want us to set these values ...*/
2764 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
2765 0, IPPROTO_TCP, 0);
2766 iph->tot_len = 0;
2767 iph->check = 0;
2768 }
2769}
2770
Eugene Crosser2863c612016-06-16 16:18:52 +02002771/**
Eugene Crosser41aeed52016-06-16 16:18:53 +02002772 * qeth_l3_get_elements_no_tso() - find number of SBALEs for skb data for tso
2773 * @card: qeth card structure, to check max. elems.
2774 * @skb: SKB address
2775 * @extra_elems: extra elems needed, to check against max.
Eugene Crosser2863c612016-06-16 16:18:52 +02002776 *
2777 * Returns the number of pages, and thus QDIO buffer elements, needed to cover
2778 * skb data, including linear part and fragments, but excluding TCP header.
2779 * (Exclusion of TCP header distinguishes it from qeth_get_elements_no().)
2780 * Checks if the result plus extra_elems fits under the limit for the card.
2781 * Returns 0 if it does not.
2782 * Note: extra_elems is not included in the returned result.
2783 */
Eugene Crosser41aeed52016-06-16 16:18:53 +02002784static int qeth_l3_get_elements_no_tso(struct qeth_card *card,
Eugene Crosser2863c612016-06-16 16:18:52 +02002785 struct sk_buff *skb, int extra_elems)
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002786{
Eugene Crosser2863c612016-06-16 16:18:52 +02002787 addr_t tcpdptr = (addr_t)tcp_hdr(skb) + tcp_hdrlen(skb);
2788 int elements = qeth_get_elements_for_range(
2789 tcpdptr,
2790 (addr_t)skb->data + skb_headlen(skb)) +
Thomas Richter8f43fb02016-06-16 16:18:59 +02002791 qeth_get_elements_for_frags(skb);
Frank Blaschka271648b2013-03-18 20:04:44 +00002792
Eugene Crosser2863c612016-06-16 16:18:52 +02002793 if ((elements + extra_elems) > QETH_MAX_BUFFER_ELEMENTS(card)) {
2794 QETH_DBF_MESSAGE(2,
2795 "Invalid size of TSO IP packet (Number=%d / Length=%d). Discarded.\n",
2796 elements + extra_elems, skb->len);
2797 return 0;
2798 }
Frank Blaschkac3b4a742009-11-12 00:11:44 +00002799 return elements;
2800}
2801
Frank Blaschka4a71df52008-02-15 09:19:42 +01002802static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2803{
2804 int rc;
2805 u16 *tag;
2806 struct qeth_hdr *hdr = NULL;
Eugene Crosser2863c612016-06-16 16:18:52 +02002807 int hdr_elements = 0;
2808 int elements;
Heiko Carstens509e2562008-07-26 02:24:10 -07002809 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002810 struct sk_buff *new_skb = NULL;
2811 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00002812 int cast_type = qeth_l3_get_cast_type(card, skb);
Stefan Raspl290b8342014-04-28 10:05:08 +02002813 struct qeth_qdio_out_q *queue =
2814 card->qdio.out_qs[card->qdio.do_prio_queueing
2815 || (cast_type && card->info.is_multicast_different) ?
2816 qeth_get_priority_queue(card, skb, ipv, cast_type) :
2817 card->qdio.default_out_queue];
Frank Blaschka4a71df52008-02-15 09:19:42 +01002818 int tx_bytes = skb->len;
Eugene Crosser41aeed52016-06-16 16:18:53 +02002819 bool use_tso;
Frank Blaschka683d7182008-08-01 16:39:13 +02002820 int data_offset = -1;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002821 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002822
Frank Blaschkab3332932011-08-08 01:33:59 +00002823 if (((card->info.type == QETH_CARD_TYPE_IQD) &&
2824 (((card->options.cq != QETH_CQ_ENABLED) && !ipv) ||
2825 ((card->options.cq == QETH_CQ_ENABLED) &&
2826 (skb->protocol != ETH_P_AF_IUCV)))) ||
2827 card->options.sniffer)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002828 goto tx_drop;
2829
2830 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
2831 card->stats.tx_carrier_errors++;
2832 goto tx_drop;
2833 }
2834
2835 if ((cast_type == RTN_BROADCAST) &&
2836 (card->info.broadcast_capable == 0))
2837 goto tx_drop;
2838
2839 if (card->options.performance_stats) {
2840 card->perf_stats.outbound_cnt++;
2841 card->perf_stats.outbound_start_time = qeth_get_micros();
2842 }
2843
Eugene Crosser41aeed52016-06-16 16:18:53 +02002844 /* Ignore segment size from skb_is_gso(), 1 page is always used. */
2845 use_tso = skb_is_gso(skb) &&
2846 (qeth_get_ip_protocol(skb) == IPPROTO_TCP) && (ipv == 4);
Frank Blaschka683d7182008-08-01 16:39:13 +02002847
Eugene Crosser41aeed52016-06-16 16:18:53 +02002848 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
2849 !skb_is_nonlinear(skb)) {
Frank Blaschka683d7182008-08-01 16:39:13 +02002850 new_skb = skb;
Julian Wiedmann51533c42017-03-23 14:55:09 +01002851 data_offset = ETH_HLEN;
Frank Blaschka683d7182008-08-01 16:39:13 +02002852 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
2853 if (!hdr)
2854 goto tx_drop;
Eugene Crosser2863c612016-06-16 16:18:52 +02002855 hdr_elements++;
Frank Blaschka683d7182008-08-01 16:39:13 +02002856 } else {
2857 /* create a clone with writeable headroom */
2858 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
2859 + VLAN_HLEN);
2860 if (!new_skb)
2861 goto tx_drop;
2862 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002863
2864 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +02002865 if (data_offset < 0)
2866 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002867 } else {
Frank Blaschka21fde742010-03-08 20:36:54 +00002868 if (ipv == 4) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002869 skb_pull(new_skb, ETH_HLEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002870 }
2871
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002872 if (ipv != 4 && skb_vlan_tag_present(new_skb)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002873 skb_push(new_skb, VLAN_HLEN);
2874 skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
2875 skb_copy_to_linear_data_offset(new_skb, 4,
2876 new_skb->data + 8, 4);
2877 skb_copy_to_linear_data_offset(new_skb, 8,
2878 new_skb->data + 12, 4);
2879 tag = (u16 *)(new_skb->data + 12);
2880 *tag = __constant_htons(ETH_P_8021Q);
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002881 *(tag + 1) = htons(skb_vlan_tag_get(new_skb));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002882 }
2883 }
2884
2885 netif_stop_queue(dev);
2886
Frank Blaschka4a71df52008-02-15 09:19:42 +01002887 /* fix hardware limitation: as long as we do not have sbal
Frank Blaschka64ef8952009-03-24 20:57:16 +00002888 * chaining we can not send long frag lists
Frank Blaschka4a71df52008-02-15 09:19:42 +01002889 */
Eugene Crosser41aeed52016-06-16 16:18:53 +02002890 if ((card->info.type != QETH_CARD_TYPE_IQD) &&
2891 ((use_tso && !qeth_l3_get_elements_no_tso(card, new_skb, 1)) ||
Julian Wiedmann118b04042017-03-23 14:55:08 +01002892 (!use_tso && !qeth_get_elements_no(card, new_skb, 0, 0)))) {
Eugene Crosser6059c902016-06-16 16:18:57 +02002893 int lin_rc = skb_linearize(new_skb);
2894
2895 if (card->options.performance_stats) {
2896 if (lin_rc)
2897 card->perf_stats.tx_linfail++;
2898 else
2899 card->perf_stats.tx_lin++;
2900 }
2901 if (lin_rc)
Eugene Crosser41aeed52016-06-16 16:18:53 +02002902 goto tx_drop;
Frank Blaschka64ef8952009-03-24 20:57:16 +00002903 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002904
Eugene Crosser41aeed52016-06-16 16:18:53 +02002905 if (use_tso) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002906 hdr = (struct qeth_hdr *)skb_push(new_skb,
2907 sizeof(struct qeth_hdr_tso));
2908 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
2909 qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
2910 qeth_tso_fill_header(card, hdr, new_skb);
Eugene Crosser2863c612016-06-16 16:18:52 +02002911 hdr_elements++;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002912 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02002913 if (data_offset < 0) {
2914 hdr = (struct qeth_hdr *)skb_push(new_skb,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002915 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +02002916 qeth_l3_fill_header(card, hdr, new_skb, ipv,
2917 cast_type);
2918 } else {
Frank Blaschkab3332932011-08-08 01:33:59 +00002919 if (new_skb->protocol == ETH_P_AF_IUCV)
2920 qeth_l3_fill_af_iucv_hdr(card, hdr, new_skb);
2921 else {
2922 qeth_l3_fill_header(card, hdr, new_skb, ipv,
2923 cast_type);
2924 hdr->hdr.l3.length = new_skb->len - data_offset;
2925 }
Frank Blaschka683d7182008-08-01 16:39:13 +02002926 }
Frank Blaschkaf6b85b62010-05-11 19:34:45 +00002927
2928 if (skb->ip_summed == CHECKSUM_PARTIAL)
2929 qeth_l3_hdr_csum(card, hdr, new_skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002930 }
2931
Eugene Crosser41aeed52016-06-16 16:18:53 +02002932 elements = use_tso ?
2933 qeth_l3_get_elements_no_tso(card, new_skb, hdr_elements) :
Julian Wiedmann118b04042017-03-23 14:55:08 +01002934 qeth_get_elements_no(card, new_skb, hdr_elements,
2935 (data_offset > 0) ? data_offset : 0);
Eugene Crosser2863c612016-06-16 16:18:52 +02002936 if (!elements) {
Frank Blaschka64ef8952009-03-24 20:57:16 +00002937 if (data_offset >= 0)
2938 kmem_cache_free(qeth_core_header_cache, hdr);
2939 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002940 }
Eugene Crosser2863c612016-06-16 16:18:52 +02002941 elements += hdr_elements;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002942
Frank Blaschka51aa1652010-06-21 22:57:10 +00002943 if (card->info.type != QETH_CARD_TYPE_IQD) {
2944 int len;
Eugene Crosser41aeed52016-06-16 16:18:53 +02002945 if (use_tso)
Frank Blaschka51aa1652010-06-21 22:57:10 +00002946 len = ((unsigned long)tcp_hdr(new_skb) +
Eugene Crosser2863c612016-06-16 16:18:52 +02002947 tcp_hdrlen(new_skb)) -
Frank Blaschka51aa1652010-06-21 22:57:10 +00002948 (unsigned long)new_skb->data;
2949 else
2950 len = sizeof(struct qeth_hdr_layer3);
2951
Stefan Raspld4ae1f52013-04-22 01:12:29 +00002952 if (qeth_hdr_chk_and_bounce(new_skb, &hdr, len))
Frank Blaschka51aa1652010-06-21 22:57:10 +00002953 goto tx_drop;
Eugene Crosser2863c612016-06-16 16:18:52 +02002954 rc = qeth_do_send_packet(card, queue, new_skb, hdr, elements);
Frank Blaschka51aa1652010-06-21 22:57:10 +00002955 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +01002956 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Eugene Crosser2863c612016-06-16 16:18:52 +02002957 elements, data_offset, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002958
2959 if (!rc) {
2960 card->stats.tx_packets++;
2961 card->stats.tx_bytes += tx_bytes;
2962 if (new_skb != skb)
2963 dev_kfree_skb_any(skb);
2964 if (card->options.performance_stats) {
Eugene Crosser2863c612016-06-16 16:18:52 +02002965 nr_frags = skb_shinfo(new_skb)->nr_frags;
Eugene Crosser41aeed52016-06-16 16:18:53 +02002966 if (use_tso) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002967 card->perf_stats.large_send_bytes += tx_bytes;
2968 card->perf_stats.large_send_cnt++;
2969 }
Frank Blaschka64ef8952009-03-24 20:57:16 +00002970 if (nr_frags) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002971 card->perf_stats.sg_skbs_sent++;
2972 /* nr_frags + skb->data */
Frank Blaschka64ef8952009-03-24 20:57:16 +00002973 card->perf_stats.sg_frags_sent += nr_frags + 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002974 }
2975 }
Patrick McHardyec634fe2009-07-05 19:23:38 -07002976 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002977 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +02002978 if (data_offset >= 0)
2979 kmem_cache_free(qeth_core_header_cache, hdr);
2980
Frank Blaschka4a71df52008-02-15 09:19:42 +01002981 if (rc == -EBUSY) {
2982 if (new_skb != skb)
2983 dev_kfree_skb_any(new_skb);
2984 return NETDEV_TX_BUSY;
2985 } else
2986 goto tx_drop;
2987 }
2988
2989 netif_wake_queue(dev);
2990 if (card->options.performance_stats)
2991 card->perf_stats.outbound_time += qeth_get_micros() -
2992 card->perf_stats.outbound_start_time;
2993 return rc;
2994
2995tx_drop:
2996 card->stats.tx_dropped++;
2997 card->stats.tx_errors++;
2998 if ((new_skb != skb) && new_skb)
2999 dev_kfree_skb_any(new_skb);
3000 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02003001 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003002 return NETDEV_TX_OK;
3003}
3004
Ursula Braun39423442011-01-12 20:42:24 +00003005static int __qeth_l3_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003006{
Heiko Carstens509e2562008-07-26 02:24:10 -07003007 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003008 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003009
Carsten Otte847a50f2010-06-21 22:57:05 +00003010 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +00003011 if (card->state == CARD_STATE_UP)
3012 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003013 if (card->state != CARD_STATE_SOFTSETUP)
3014 return -ENODEV;
3015 card->data.state = CH_STATE_UP;
3016 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003017 netif_start_queue(dev);
3018
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003019 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
3020 napi_enable(&card->napi);
3021 napi_schedule(&card->napi);
3022 } else
3023 rc = -EIO;
3024 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003025}
3026
Ursula Braun39423442011-01-12 20:42:24 +00003027static int qeth_l3_open(struct net_device *dev)
3028{
3029 struct qeth_card *card = dev->ml_priv;
3030
3031 QETH_CARD_TEXT(card, 5, "qethope_");
3032 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
3033 QETH_CARD_TEXT(card, 3, "openREC");
3034 return -ERESTARTSYS;
3035 }
3036 return __qeth_l3_open(dev);
3037}
3038
Frank Blaschka4a71df52008-02-15 09:19:42 +01003039static int qeth_l3_stop(struct net_device *dev)
3040{
Heiko Carstens509e2562008-07-26 02:24:10 -07003041 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003042
Carsten Otte847a50f2010-06-21 22:57:05 +00003043 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003044 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003045 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003046 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003047 napi_disable(&card->napi);
3048 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003049 return 0;
3050}
3051
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07003052static const struct ethtool_ops qeth_l3_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003053 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003054 .get_strings = qeth_core_get_strings,
3055 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00003056 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003057 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02003058 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003059};
3060
3061/*
3062 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
3063 * NOARP on the netdevice is no option because it also turns off neighbor
3064 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
3065 * arp resolution but we want the hard header (packet socket will work
3066 * e.g. tcpdump)
3067 */
3068static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
3069{
3070 n->nud_state = NUD_NOARP;
3071 memcpy(n->ha, "FAKELL", 6);
3072 n->output = n->ops->connected_output;
3073 return 0;
3074}
3075
3076static int
3077qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
3078{
3079 if (np->tbl->family == AF_INET)
3080 np->neigh_setup = qeth_l3_neigh_setup_noarp;
3081
3082 return 0;
3083}
3084
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003085static const struct net_device_ops qeth_l3_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08003086 .ndo_open = qeth_l3_open,
3087 .ndo_stop = qeth_l3_stop,
3088 .ndo_get_stats = qeth_get_stats,
3089 .ndo_start_xmit = qeth_l3_hard_start_xmit,
Julian Wiedmann1d552222017-12-01 10:14:50 +01003090 .ndo_features_check = qeth_features_check,
Frank Blaschka8403b132009-01-08 10:50:55 -08003091 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003092 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003093 .ndo_do_ioctl = qeth_l3_do_ioctl,
3094 .ndo_change_mtu = qeth_change_mtu,
Thomas Richter8f43fb02016-06-16 16:18:59 +02003095 .ndo_fix_features = qeth_fix_features,
3096 .ndo_set_features = qeth_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08003097 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3098 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003099 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka8403b132009-01-08 10:50:55 -08003100};
3101
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003102static const struct net_device_ops qeth_l3_osa_netdev_ops = {
3103 .ndo_open = qeth_l3_open,
3104 .ndo_stop = qeth_l3_stop,
3105 .ndo_get_stats = qeth_get_stats,
3106 .ndo_start_xmit = qeth_l3_hard_start_xmit,
3107 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003108 .ndo_set_rx_mode = qeth_l3_set_multicast_list,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003109 .ndo_do_ioctl = qeth_l3_do_ioctl,
3110 .ndo_change_mtu = qeth_change_mtu,
Thomas Richter8f43fb02016-06-16 16:18:59 +02003111 .ndo_fix_features = qeth_fix_features,
3112 .ndo_set_features = qeth_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003113 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
3114 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00003115 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003116 .ndo_neigh_setup = qeth_l3_neigh_setup,
3117};
3118
Frank Blaschka4a71df52008-02-15 09:19:42 +01003119static int qeth_l3_setup_netdev(struct qeth_card *card)
3120{
Thomas Richter1aec42b2015-01-21 13:39:10 +01003121 int rc;
3122
Ursula Braun5113fec2010-05-16 21:15:14 +00003123 if (card->info.type == QETH_CARD_TYPE_OSD ||
3124 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003125 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
3126 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04003127 pr_info("qeth_l3: ignoring TR device\n");
3128 return -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003129 } else {
3130 card->dev = alloc_etherdev(0);
3131 if (!card->dev)
3132 return -ENODEV;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003133 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003134
3135 /*IPv6 address autoconfiguration stuff*/
3136 qeth_l3_get_unique_id(card);
3137 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
3138 card->dev->dev_id = card->info.unique_id &
3139 0xffff;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00003140 if (!card->info.guestlan) {
3141 card->dev->hw_features = NETIF_F_SG |
3142 NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
3143 NETIF_F_TSO;
Hans Wippel9bdc4412016-06-16 16:19:00 +02003144 card->dev->vlan_features = NETIF_F_SG |
3145 NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
3146 NETIF_F_TSO;
Julian Wiedmann1d552222017-12-01 10:14:50 +01003147 card->dev->features |= NETIF_F_SG;
Frank Blaschkac5e631a2011-05-12 18:45:01 +00003148 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003149 }
3150 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
Tom Gundersenc835a672014-07-14 16:37:24 +02003151 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
3152 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003153 if (!card->dev)
3154 return -ENODEV;
3155 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00003156 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Thomas Richter1aec42b2015-01-21 13:39:10 +01003157 rc = qeth_l3_iqd_read_initial_mac(card);
3158 if (rc)
3159 return rc;
Frank Blaschkab3332932011-08-08 01:33:59 +00003160 if (card->options.hsuid[0])
3161 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003162 } else
3163 return -ENODEV;
3164
Heiko Carstens509e2562008-07-26 02:24:10 -07003165 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003166 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003167 card->dev->mtu = card->info.initial_mtu;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00003168 card->dev->ethtool_ops = &qeth_l3_ethtool_ops;
Patrick McHardyf6469682013-04-19 02:04:27 +00003169 card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
3170 NETIF_F_HW_VLAN_CTAG_RX |
3171 NETIF_F_HW_VLAN_CTAG_FILTER;
Eric Dumazet02875872014-10-05 18:38:35 -07003172 netif_keep_dst(card->dev);
Julian Wiedmannfbf0dfe2017-12-01 10:14:51 +01003173 netif_set_gso_max_size(card->dev, (QETH_MAX_BUFFER_ELEMENTS(card) - 1) *
3174 PAGE_SIZE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003175
3176 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003177 netif_napi_add(card->dev, &card->napi, qeth_l3_poll, QETH_NAPI_WEIGHT);
Ursula Braune5ebe632015-12-11 12:27:55 +01003178 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003179 return register_netdev(card->dev);
3180}
3181
Frank Blaschka4a71df52008-02-15 09:19:42 +01003182static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
3183{
3184 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun25c1a1e2017-05-10 19:07:51 +02003185 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003186
Ursula Braun25c1a1e2017-05-10 19:07:51 +02003187 rc = qeth_l3_create_device_attributes(&gdev->dev);
3188 if (rc)
3189 return rc;
Ursula Braunc1f3f192017-05-10 19:07:54 +02003190 hash_init(card->ip_htable);
3191 hash_init(card->ip_mc_htable);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003192 card->options.layer2 = 0;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003193 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003194 return 0;
3195}
3196
3197static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
3198{
3199 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3200
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003201 qeth_l3_remove_device_attributes(&cgdev->dev);
3202
Ursula Braunf2148562009-05-19 21:38:37 +00003203 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003204 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3205
Ursula Braun70919e22011-02-26 22:41:36 -08003206 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003207 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003208
3209 if (card->dev) {
Ursula Braun7831b4f2016-07-04 14:07:16 +02003210 netif_napi_del(&card->napi);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003211 unregister_netdev(card->dev);
3212 card->dev = NULL;
3213 }
3214
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003215 qeth_l3_clear_ip_htable(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003216 qeth_l3_clear_ipato_list(card);
3217 return;
3218}
3219
3220static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3221{
3222 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3223 int rc = 0;
3224 enum qeth_card_states recover_flag;
3225
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003226 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003227 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003228 QETH_DBF_TEXT(SETUP, 2, "setonlin");
3229 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003230
Frank Blaschka4a71df52008-02-15 09:19:42 +01003231 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003232 rc = qeth_core_hardsetup_card(card);
3233 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01003234 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003235 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003236 goto out_remove;
3237 }
3238
Ursula Braunaa909222009-11-12 00:11:43 +00003239 if (!card->dev && qeth_l3_setup_netdev(card)) {
3240 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003241 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00003242 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003243
Frank Blaschka1da74b12011-05-12 18:45:02 +00003244 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
3245 if (card->info.hwtrap &&
3246 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
3247 card->info.hwtrap = 0;
3248 } else
3249 card->info.hwtrap = 0;
3250
Frank Blaschka4a71df52008-02-15 09:19:42 +01003251 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003252 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003253 qeth_print_status_message(card);
3254
3255 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003256 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003257
Frank Blaschka4a71df52008-02-15 09:19:42 +01003258 rc = qeth_l3_setadapter_parms(card);
3259 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003260 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003261 if (!card->options.sniffer) {
3262 rc = qeth_l3_start_ipassists(card);
Stefan Raspl0f547612013-01-21 02:30:20 +00003263 if (rc) {
Ursula Braun76b11f82010-01-11 02:50:50 +00003264 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Stefan Raspl0f547612013-01-21 02:30:20 +00003265 goto out_remove;
3266 }
Ursula Braun76b11f82010-01-11 02:50:50 +00003267 rc = qeth_l3_setrouting_v4(card);
3268 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003269 QETH_DBF_TEXT_(SETUP, 2, "4err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003270 rc = qeth_l3_setrouting_v6(card);
3271 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01003272 QETH_DBF_TEXT_(SETUP, 2, "5err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00003273 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003274 netif_tx_disable(card->dev);
3275
3276 rc = qeth_init_qdio_queues(card);
3277 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003278 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00003279 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003280 goto out_remove;
3281 }
3282 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003283
3284 qeth_set_allowed_threads(card, 0xffffffff, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003285 qeth_l3_recover_ip(card);
Ursula Braun2b6203b2010-11-26 02:41:19 +00003286 if (card->lan_online)
3287 netif_carrier_on(card->dev);
3288 else
3289 netif_carrier_off(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003290 if (recover_flag == CARD_STATE_RECOVER) {
Ursula Braun4763b0a2011-12-19 22:56:32 +00003291 rtnl_lock();
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003292 if (recovery_mode)
Ursula Braun39423442011-01-12 20:42:24 +00003293 __qeth_l3_open(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00003294 else
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003295 dev_open(card->dev);
Frank Blaschka8af7c5a2008-04-24 10:15:25 +02003296 qeth_l3_set_multicast_list(card->dev);
Hans Wippele830baa2016-09-15 14:39:21 +02003297 qeth_recover_features(card->dev);
Ursula Braun4763b0a2011-12-19 22:56:32 +00003298 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01003299 }
Stefan Raspl82f77cf2013-03-18 20:04:42 +00003300 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003301 /* let user_space know that device is online */
3302 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003303 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003304 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003305 return 0;
3306out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01003307 qeth_l3_stop_card(card, 0);
3308 ccw_device_set_offline(CARD_DDEV(card));
3309 ccw_device_set_offline(CARD_WDEV(card));
3310 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01003311 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003312 if (recover_flag == CARD_STATE_RECOVER)
3313 card->state = CARD_STATE_RECOVER;
3314 else
3315 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00003316 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003317 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00003318 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003319}
3320
3321static int qeth_l3_set_online(struct ccwgroup_device *gdev)
3322{
3323 return __qeth_l3_set_online(gdev, 0);
3324}
3325
3326static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3327 int recovery_mode)
3328{
3329 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
3330 int rc = 0, rc2 = 0, rc3 = 0;
3331 enum qeth_card_states recover_flag;
3332
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003333 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003334 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003335 QETH_DBF_TEXT(SETUP, 3, "setoffl");
3336 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003337
3338 if (card->dev && netif_carrier_ok(card->dev))
3339 netif_carrier_off(card->dev);
3340 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00003341 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
3342 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
3343 card->info.hwtrap = 1;
3344 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02003345 qeth_l3_stop_card(card, recovery_mode);
Einar Lueck72861ae2011-12-19 22:56:36 +00003346 if ((card->options.cq == QETH_CQ_ENABLED) && card->dev) {
3347 rtnl_lock();
3348 call_netdevice_notifiers(NETDEV_REBOOT, card->dev);
3349 rtnl_unlock();
3350 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01003351 rc = ccw_device_set_offline(CARD_DDEV(card));
3352 rc2 = ccw_device_set_offline(CARD_WDEV(card));
3353 rc3 = ccw_device_set_offline(CARD_RDEV(card));
3354 if (!rc)
3355 rc = (rc2) ? rc2 : rc3;
3356 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02003357 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01003358 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003359 if (recover_flag == CARD_STATE_UP)
3360 card->state = CARD_STATE_RECOVER;
3361 /* let user_space know that device is offline */
3362 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00003363 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00003364 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003365 return 0;
3366}
3367
3368static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
3369{
3370 return __qeth_l3_set_offline(cgdev, 0);
3371}
3372
3373static int qeth_l3_recover(void *ptr)
3374{
3375 struct qeth_card *card;
3376 int rc = 0;
3377
3378 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00003379 QETH_CARD_TEXT(card, 2, "recover1");
3380 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003381 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
3382 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00003383 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003384 dev_warn(&card->gdev->dev,
3385 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00003386 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003387 __qeth_l3_set_offline(card->gdev, 1);
3388 rc = __qeth_l3_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003389 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003390 dev_info(&card->gdev->dev,
3391 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003392 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00003393 qeth_close_dev(card);
3394 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00003395 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02003396 }
Stefan Raspl65d80132013-04-07 22:19:27 +00003397 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00003398 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3399 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003400 return 0;
3401}
3402
3403static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3404{
3405 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braunf78ac2b2011-12-19 22:56:33 +00003406 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka1da74b12011-05-12 18:45:02 +00003407 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
3408 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003409 qeth_qdio_clear_card(card, 0);
3410 qeth_clear_qdio_buffers(card);
Ursula Braun22ae2792014-02-24 13:12:06 +01003411 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003412}
3413
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003414static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
3415{
3416 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3417
3418 if (card->dev)
3419 netif_device_detach(card->dev);
3420 qeth_set_allowed_threads(card, 0, 1);
3421 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
3422 if (gdev->state == CCWGROUP_OFFLINE)
3423 return 0;
3424 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00003425 if (card->info.hwtrap)
3426 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003427 __qeth_l3_set_offline(card->gdev, 1);
3428 } else
3429 __qeth_l3_set_offline(card->gdev, 0);
3430 return 0;
3431}
3432
3433static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
3434{
3435 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
3436 int rc = 0;
3437
3438 if (gdev->state == CCWGROUP_OFFLINE)
3439 goto out;
3440
3441 if (card->state == CARD_STATE_RECOVER) {
3442 rc = __qeth_l3_set_online(card->gdev, 1);
3443 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00003444 rtnl_lock();
3445 dev_close(card->dev);
3446 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003447 }
3448 } else
3449 rc = __qeth_l3_set_online(card->gdev, 0);
3450out:
3451 qeth_set_allowed_threads(card, 0xffffffff, 0);
3452 if (card->dev)
3453 netif_device_attach(card->dev);
3454 if (rc)
3455 dev_warn(&card->gdev->dev, "The qeth device driver "
3456 "failed to recover an error on the device\n");
3457 return rc;
3458}
3459
Eugene Crosserc044dc22014-01-29 09:23:48 +01003460/* Returns zero if the command is successfully "consumed" */
3461static int qeth_l3_control_event(struct qeth_card *card,
3462 struct qeth_ipa_cmd *cmd)
3463{
3464 return 1;
3465}
3466
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003467struct qeth_discipline qeth_l3_discipline = {
Julian Wiedmannb68c2e32017-05-10 19:07:52 +02003468 .devtype = &qeth_generic_devtype,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003469 .start_poll = qeth_qdio_start_poll,
3470 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
3471 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
3472 .recover = qeth_l3_recover,
3473 .setup = qeth_l3_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003474 .remove = qeth_l3_remove_device,
3475 .set_online = qeth_l3_set_online,
3476 .set_offline = qeth_l3_set_offline,
3477 .shutdown = qeth_l3_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003478 .freeze = qeth_l3_pm_suspend,
3479 .thaw = qeth_l3_pm_resume,
3480 .restore = qeth_l3_pm_resume,
Eugene Crosserc044dc22014-01-29 09:23:48 +01003481 .control_event_handler = qeth_l3_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01003482};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02003483EXPORT_SYMBOL_GPL(qeth_l3_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003484
3485static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003486 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003487{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003488
Frank Blaschka4a71df52008-02-15 09:19:42 +01003489 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3490 struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
3491 struct qeth_ipaddr *addr;
3492 struct qeth_card *card;
3493
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09003494 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07003495 return NOTIFY_DONE;
3496
Frank Blaschka4a71df52008-02-15 09:19:42 +01003497 card = qeth_l3_get_card_from_dev(dev);
3498 if (!card)
3499 return NOTIFY_DONE;
frank.blaschka@de.ibm.com6d8823d2012-05-16 01:28:26 +00003500 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003501
3502 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003503 if (addr) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003504 addr->u.a4.addr = ifa->ifa_address;
3505 addr->u.a4.mask = ifa->ifa_mask;
3506 addr->type = QETH_IP_TYPE_NORMAL;
3507 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003508 return NOTIFY_DONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003509
3510 switch (event) {
3511 case NETDEV_UP:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003512 spin_lock_bh(&card->ip_lock);
3513 qeth_l3_add_ip(card, addr);
3514 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003515 break;
3516 case NETDEV_DOWN:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003517 spin_lock_bh(&card->ip_lock);
3518 qeth_l3_delete_ip(card, addr);
3519 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003520 break;
3521 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003522
3523 kfree(addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003524 return NOTIFY_DONE;
3525}
3526
3527static struct notifier_block qeth_l3_ip_notifier = {
3528 qeth_l3_ip_event,
3529 NULL,
3530};
3531
3532#ifdef CONFIG_QETH_IPV6
3533/**
3534 * IPv6 event handler
3535 */
3536static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07003537 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01003538{
3539 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
3540 struct net_device *dev = (struct net_device *)ifa->idev->dev;
3541 struct qeth_ipaddr *addr;
3542 struct qeth_card *card;
3543
Frank Blaschka4a71df52008-02-15 09:19:42 +01003544 card = qeth_l3_get_card_from_dev(dev);
3545 if (!card)
3546 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00003547 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003548 if (!qeth_is_supported(card, IPA_IPV6))
3549 return NOTIFY_DONE;
3550
3551 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003552 if (addr) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01003553 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
3554 addr->u.a6.pfxlen = ifa->prefix_len;
3555 addr->type = QETH_IP_TYPE_NORMAL;
3556 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003557 return NOTIFY_DONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01003558
3559 switch (event) {
3560 case NETDEV_UP:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003561 spin_lock_bh(&card->ip_lock);
3562 qeth_l3_add_ip(card, addr);
3563 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003564 break;
3565 case NETDEV_DOWN:
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003566 spin_lock_bh(&card->ip_lock);
3567 qeth_l3_delete_ip(card, addr);
3568 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003569 break;
3570 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02003571
3572 kfree(addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01003573 return NOTIFY_DONE;
3574}
3575
3576static struct notifier_block qeth_l3_ip6_notifier = {
3577 qeth_l3_ip6_event,
3578 NULL,
3579};
3580#endif
3581
3582static int qeth_l3_register_notifiers(void)
3583{
3584 int rc;
3585
Carsten Otte847a50f2010-06-21 22:57:05 +00003586 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003587 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
3588 if (rc)
3589 return rc;
3590#ifdef CONFIG_QETH_IPV6
3591 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
3592 if (rc) {
3593 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
3594 return rc;
3595 }
3596#else
Joe Perchesbaebc702016-03-03 20:49:57 -08003597 pr_warn("There is no IPv6 support for the layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003598#endif
3599 return 0;
3600}
3601
3602static void qeth_l3_unregister_notifiers(void)
3603{
3604
Carsten Otte847a50f2010-06-21 22:57:05 +00003605 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Stefan Raspl18af5c12012-11-19 02:46:50 +00003606 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003607#ifdef CONFIG_QETH_IPV6
Stefan Raspl18af5c12012-11-19 02:46:50 +00003608 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01003609#endif /* QETH_IPV6 */
3610}
3611
3612static int __init qeth_l3_init(void)
3613{
3614 int rc = 0;
3615
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003616 pr_info("register layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003617 rc = qeth_l3_register_notifiers();
3618 return rc;
3619}
3620
3621static void __exit qeth_l3_exit(void)
3622{
3623 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01003624 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01003625}
3626
3627module_init(qeth_l3_init);
3628module_exit(qeth_l3_exit);
3629MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
3630MODULE_DESCRIPTION("qeth layer 3 discipline");
3631MODULE_LICENSE("GPL");