blob: 375ad03ea4c582ba7eae30e33545a514d2487daf [file] [log] [blame]
Greg Kroah-Hartmanab9953f2017-11-14 18:38:04 +01001// SPDX-License-Identifier: GPL-2.0
Frank Blaschka4a71df52008-02-15 09:19:42 +01002/*
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003 * Copyright IBM Corp. 2007, 2009
Frank Blaschka4a71df52008-02-15 09:19:42 +01004 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
5 * Frank Pavlic <fpavlic@de.ibm.com>,
6 * Thomas Spatzier <tspat@de.ibm.com>,
7 * Frank Blaschka <frank.blaschka@de.ibm.com>
8 */
9
Frank Blaschka74eacdb2008-12-25 13:39:49 +010010#define KMSG_COMPONENT "qeth"
11#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
Frank Blaschka4a71df52008-02-15 09:19:42 +010013#include <linux/module.h>
14#include <linux/moduleparam.h>
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +000015#include <linux/bitops.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010016#include <linux/string.h>
17#include <linux/errno.h>
18#include <linux/kernel.h>
19#include <linux/etherdevice.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010020#include <linux/ip.h>
Julian Wiedmann1f979122017-12-20 20:11:04 +010021#include <linux/in.h>
Frank Blaschka64ef8952009-03-24 20:57:16 +000022#include <linux/ipv6.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010023#include <linux/inetdevice.h>
24#include <linux/igmp.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Julian Wiedmann910a0a82017-12-20 20:11:07 +010026#include <linux/if_ether.h>
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +000027#include <linux/if_vlan.h>
Julian Wiedmann910a0a82017-12-20 20:11:07 +010028#include <linux/skbuff.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010029
30#include <net/ip.h>
31#include <net/arp.h>
David Miller87e75972012-02-01 10:49:17 +000032#include <net/route.h>
Julian Wiedmann1f979122017-12-20 20:11:04 +010033#include <net/ipv6.h>
Julian Wiedmann910a0a82017-12-20 20:11:07 +010034#include <net/ip6_route.h>
David Miller87e75972012-02-01 10:49:17 +000035#include <net/ip6_fib.h>
Frank Blaschkab3332932011-08-08 01:33:59 +000036#include <net/iucv/af_iucv.h>
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020037#include <linux/hashtable.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010038
Frank Blaschka4a71df52008-02-15 09:19:42 +010039#include "qeth_l3.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010040
Einar Lueckd0ddf30f2010-12-08 02:57:58 +000041
Frank Blaschka4a71df52008-02-15 09:19:42 +010042static int qeth_l3_set_offline(struct ccwgroup_device *);
Julian Wiedmann00c163f2017-12-20 20:11:02 +010043static void qeth_l3_set_rx_mode(struct net_device *dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +010044static int qeth_l3_register_addr_entry(struct qeth_card *,
45 struct qeth_ipaddr *);
46static int qeth_l3_deregister_addr_entry(struct qeth_card *,
47 struct qeth_ipaddr *);
Frank Blaschka4a71df52008-02-15 09:19:42 +010048
Thomas Richter56530d62014-10-22 12:18:04 +020049static void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010050{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020051 sprintf(buf, "%pI4", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010052}
53
Thomas Richter56530d62014-10-22 12:18:04 +020054static void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010055{
Joe Perches963a9fd2010-09-07 21:14:40 +000056 sprintf(buf, "%pI6", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010057}
58
Frank Blaschka4a71df52008-02-15 09:19:42 +010059void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
60 char *buf)
61{
62 if (proto == QETH_PROT_IPV4)
63 qeth_l3_ipaddr4_to_string(addr, buf);
64 else if (proto == QETH_PROT_IPV6)
65 qeth_l3_ipaddr6_to_string(addr, buf);
66}
67
Julian Wiedmann1617dae2018-03-09 18:13:02 +010068static struct qeth_ipaddr *qeth_l3_get_addr_buffer(enum qeth_prot_versions prot)
Julian Wiedmannd66b1c02018-03-09 18:13:00 +010069{
70 struct qeth_ipaddr *addr = kmalloc(sizeof(*addr), GFP_ATOMIC);
71
72 if (addr)
73 qeth_l3_init_ipaddr(addr, QETH_IP_TYPE_NORMAL, prot);
74 return addr;
75}
76
Julian Wiedmannc5c48c52018-02-27 18:58:16 +010077static struct qeth_ipaddr *qeth_l3_find_addr_by_ip(struct qeth_card *card,
78 struct qeth_ipaddr *query)
79{
80 u64 key = qeth_l3_ipaddr_hash(query);
81 struct qeth_ipaddr *addr;
82
83 if (query->is_multicast) {
84 hash_for_each_possible(card->ip_mc_htable, addr, hnode, key)
85 if (qeth_l3_addr_match_ip(addr, query))
86 return addr;
87 } else {
88 hash_for_each_possible(card->ip_htable, addr, hnode, key)
89 if (qeth_l3_addr_match_ip(addr, query))
90 return addr;
91 }
92 return NULL;
93}
94
Frank Blaschka4a71df52008-02-15 09:19:42 +010095static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
96{
97 int i, j;
98 u8 octet;
99
100 for (i = 0; i < len; ++i) {
101 octet = addr[i];
102 for (j = 7; j >= 0; --j) {
103 bits[i*8 + j] = octet & 1;
104 octet >>= 1;
105 }
106 }
107}
108
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100109static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
110 struct qeth_ipaddr *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100111{
112 struct qeth_ipato_entry *ipatoe;
113 u8 addr_bits[128] = {0, };
114 u8 ipatoe_bits[128] = {0, };
115 int rc = 0;
116
117 if (!card->ipato.enabled)
Gustavo A. R. Silva1a363b02018-08-09 14:48:04 +0200118 return false;
Julian Wiedmannb22d73d62017-12-13 18:56:30 +0100119 if (addr->type != QETH_IP_TYPE_NORMAL)
Gustavo A. R. Silva1a363b02018-08-09 14:48:04 +0200120 return false;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100121
122 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
123 (addr->proto == QETH_PROT_IPV4)? 4:16);
124 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
125 if (addr->proto != ipatoe->proto)
126 continue;
127 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
128 (ipatoe->proto == QETH_PROT_IPV4) ?
129 4 : 16);
130 if (addr->proto == QETH_PROT_IPV4)
131 rc = !memcmp(addr_bits, ipatoe_bits,
132 min(32, ipatoe->mask_bits));
133 else
134 rc = !memcmp(addr_bits, ipatoe_bits,
135 min(128, ipatoe->mask_bits));
136 if (rc)
137 break;
138 }
139 /* invert? */
140 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
141 rc = !rc;
142 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
143 rc = !rc;
144
145 return rc;
146}
147
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100148static int qeth_l3_delete_ip(struct qeth_card *card,
149 struct qeth_ipaddr *tmp_addr)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200150{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100151 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200152 struct qeth_ipaddr *addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100153
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100154 if (tmp_addr->type == QETH_IP_TYPE_RXIP)
155 QETH_CARD_TEXT(card, 2, "delrxip");
156 else if (tmp_addr->type == QETH_IP_TYPE_VIPA)
157 QETH_CARD_TEXT(card, 2, "delvipa");
158 else
159 QETH_CARD_TEXT(card, 2, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100160
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200161 if (tmp_addr->proto == QETH_PROT_IPV4)
162 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100163 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200164 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
165 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100166 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200167
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100168 addr = qeth_l3_find_addr_by_ip(card, tmp_addr);
169 if (!addr || !qeth_l3_addr_match_all(addr, tmp_addr))
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200170 return -ENOENT;
171
172 addr->ref_counter--;
Julian Wiedmann4964c662018-02-27 18:58:15 +0100173 if (addr->type == QETH_IP_TYPE_NORMAL && addr->ref_counter > 0)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200174 return rc;
175 if (addr->in_progress)
176 return -EINPROGRESS;
177
Julian Wiedmann98d823a2018-02-27 18:58:13 +0100178 if (qeth_card_hw_is_reachable(card))
179 rc = qeth_l3_deregister_addr_entry(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200180
181 hash_del(&addr->hnode);
182 kfree(addr);
183
Frank Blaschka4a71df52008-02-15 09:19:42 +0100184 return rc;
185}
186
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100187static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100188{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100189 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200190 struct qeth_ipaddr *addr;
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100191 char buf[40];
Frank Blaschka4a71df52008-02-15 09:19:42 +0100192
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100193 if (tmp_addr->type == QETH_IP_TYPE_RXIP)
194 QETH_CARD_TEXT(card, 2, "addrxip");
195 else if (tmp_addr->type == QETH_IP_TYPE_VIPA)
196 QETH_CARD_TEXT(card, 2, "addvipa");
197 else
198 QETH_CARD_TEXT(card, 2, "addip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200199
200 if (tmp_addr->proto == QETH_PROT_IPV4)
201 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100202 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200203 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
204 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100205 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200206
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100207 addr = qeth_l3_find_addr_by_ip(card, tmp_addr);
208 if (addr) {
209 if (tmp_addr->type != QETH_IP_TYPE_NORMAL)
210 return -EADDRINUSE;
211 if (qeth_l3_addr_match_all(addr, tmp_addr)) {
212 addr->ref_counter++;
213 return 0;
214 }
215 qeth_l3_ipaddr_to_string(tmp_addr->proto, (u8 *)&tmp_addr->u,
216 buf);
217 dev_warn(&card->gdev->dev,
218 "Registering IP address %s failed\n", buf);
219 return -EADDRINUSE;
220 } else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200221 addr = qeth_l3_get_addr_buffer(tmp_addr->proto);
222 if (!addr)
223 return -ENOMEM;
224
225 memcpy(addr, tmp_addr, sizeof(struct qeth_ipaddr));
226 addr->ref_counter = 1;
227
Julian Wiedmannb22d73d62017-12-13 18:56:30 +0100228 if (qeth_l3_is_addr_covered_by_ipato(card, addr)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200229 QETH_CARD_TEXT(card, 2, "tkovaddr");
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100230 addr->ipato = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200231 }
232 hash_add(card->ip_htable, &addr->hnode,
233 qeth_l3_ipaddr_hash(addr));
234
Ursula Brauna7531c12016-09-15 14:39:23 +0200235 if (!qeth_card_hw_is_reachable(card)) {
236 addr->disp_flag = QETH_DISP_ADDR_ADD;
237 return 0;
238 }
239
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200240 /* qeth_l3_register_addr_entry can go to sleep
241 * if we add a IPV4 addr. It is caused by the reason
242 * that SETIP ipa cmd starts ARP staff for IPV4 addr.
243 * Thus we should unlock spinlock, and make a protection
244 * using in_progress variable to indicate that there is
245 * an hardware operation with this IPV4 address
246 */
247 if (addr->proto == QETH_PROT_IPV4) {
248 addr->in_progress = 1;
249 spin_unlock_bh(&card->ip_lock);
250 rc = qeth_l3_register_addr_entry(card, addr);
251 spin_lock_bh(&card->ip_lock);
252 addr->in_progress = 0;
253 } else
254 rc = qeth_l3_register_addr_entry(card, addr);
255
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100256 if (!rc || rc == -EADDRINUSE || rc == -ENETDOWN) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200257 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
258 if (addr->ref_counter < 1) {
Julian Wiedmann14d066c2018-02-27 18:58:14 +0100259 qeth_l3_deregister_addr_entry(card, addr);
260 hash_del(&addr->hnode);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200261 kfree(addr);
262 }
263 } else {
264 hash_del(&addr->hnode);
265 kfree(addr);
266 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200267 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100268 return rc;
269}
270
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200271static void qeth_l3_clear_ip_htable(struct qeth_card *card, int recover)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100272{
273 struct qeth_ipaddr *addr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200274 struct hlist_node *tmp;
275 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100276
Carsten Otte847a50f2010-06-21 22:57:05 +0000277 QETH_CARD_TEXT(card, 4, "clearip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200278
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200279 spin_lock_bh(&card->ip_lock);
280
281 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
282 if (!recover) {
283 hash_del(&addr->hnode);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100284 kfree(addr);
285 continue;
286 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200287 addr->disp_flag = QETH_DISP_ADDR_ADD;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100288 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200289
290 spin_unlock_bh(&card->ip_lock);
291
292 spin_lock_bh(&card->mclock);
293
294 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
295 hash_del(&addr->hnode);
296 kfree(addr);
297 }
298
299 spin_unlock_bh(&card->mclock);
300
301
Frank Blaschka4a71df52008-02-15 09:19:42 +0100302}
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200303static void qeth_l3_recover_ip(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100304{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200305 struct qeth_ipaddr *addr;
306 struct hlist_node *tmp;
307 int i;
308 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100309
Ursula Brauna7531c12016-09-15 14:39:23 +0200310 QETH_CARD_TEXT(card, 4, "recovrip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100311
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200312 spin_lock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100313
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200314 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
Julian Wiedmann98d823a2018-02-27 18:58:13 +0100315 if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200316 if (addr->proto == QETH_PROT_IPV4) {
317 addr->in_progress = 1;
318 spin_unlock_bh(&card->ip_lock);
319 rc = qeth_l3_register_addr_entry(card, addr);
320 spin_lock_bh(&card->ip_lock);
321 addr->in_progress = 0;
322 } else
323 rc = qeth_l3_register_addr_entry(card, addr);
324
325 if (!rc) {
326 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Ursula Brauna7531c12016-09-15 14:39:23 +0200327 if (addr->ref_counter < 1)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200328 qeth_l3_delete_ip(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200329 } else {
330 hash_del(&addr->hnode);
331 kfree(addr);
332 }
333 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100334 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200335
336 spin_unlock_bh(&card->ip_lock);
337
Frank Blaschka4a71df52008-02-15 09:19:42 +0100338}
339
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100340static int qeth_l3_setdelip_cb(struct qeth_card *card, struct qeth_reply *reply,
341 unsigned long data)
342{
343 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
344
345 switch (cmd->hdr.return_code) {
346 case IPA_RC_SUCCESS:
347 return 0;
348 case IPA_RC_DUPLICATE_IP_ADDRESS:
349 return -EADDRINUSE;
350 case IPA_RC_MC_ADDR_NOT_FOUND:
351 return -ENOENT;
352 case IPA_RC_LAN_OFFLINE:
353 return -ENETDOWN;
354 default:
355 return -EIO;
356 }
357}
358
Frank Blaschka4a71df52008-02-15 09:19:42 +0100359static int qeth_l3_send_setdelmc(struct qeth_card *card,
360 struct qeth_ipaddr *addr, int ipacmd)
361{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100362 struct qeth_cmd_buffer *iob;
363 struct qeth_ipa_cmd *cmd;
364
Carsten Otte847a50f2010-06-21 22:57:05 +0000365 QETH_CARD_TEXT(card, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100366
367 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100368 if (!iob)
369 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100370 cmd = __ipa_cmd(iob);
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100371 ether_addr_copy(cmd->data.setdelipm.mac, addr->mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100372 if (addr->proto == QETH_PROT_IPV6)
373 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
374 sizeof(struct in6_addr));
375 else
376 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
377
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100378 return qeth_send_ipa_cmd(card, iob, qeth_l3_setdelip_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100379}
380
381static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
382{
383 int i, j;
384 for (i = 0; i < 16; i++) {
385 j = (len) - (i * 8);
386 if (j >= 8)
387 netmask[i] = 0xff;
388 else if (j > 0)
389 netmask[i] = (u8)(0xFF00 >> j);
390 else
391 netmask[i] = 0;
392 }
393}
394
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100395static u32 qeth_l3_get_setdelip_flags(struct qeth_ipaddr *addr, bool set)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100396{
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100397 switch (addr->type) {
398 case QETH_IP_TYPE_RXIP:
399 return (set) ? QETH_IPA_SETIP_TAKEOVER_FLAG : 0;
400 case QETH_IP_TYPE_VIPA:
401 return (set) ? QETH_IPA_SETIP_VIPA_FLAG :
402 QETH_IPA_DELIP_VIPA_FLAG;
403 default:
404 return (set && addr->ipato) ? QETH_IPA_SETIP_TAKEOVER_FLAG : 0;
405 }
406}
407
408static int qeth_l3_send_setdelip(struct qeth_card *card,
409 struct qeth_ipaddr *addr,
410 enum qeth_ipa_cmds ipacmd)
411{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100412 struct qeth_cmd_buffer *iob;
413 struct qeth_ipa_cmd *cmd;
414 __u8 netmask[16];
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100415 u32 flags;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100416
Carsten Otte847a50f2010-06-21 22:57:05 +0000417 QETH_CARD_TEXT(card, 4, "setdelip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100418
419 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100420 if (!iob)
421 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100422 cmd = __ipa_cmd(iob);
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100423
424 flags = qeth_l3_get_setdelip_flags(addr, ipacmd == IPA_CMD_SETIP);
425 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
426
Frank Blaschka4a71df52008-02-15 09:19:42 +0100427 if (addr->proto == QETH_PROT_IPV6) {
428 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
429 sizeof(struct in6_addr));
430 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
431 memcpy(cmd->data.setdelip6.mask, netmask,
432 sizeof(struct in6_addr));
433 cmd->data.setdelip6.flags = flags;
434 } else {
435 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
436 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
437 cmd->data.setdelip4.flags = flags;
438 }
439
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100440 return qeth_send_ipa_cmd(card, iob, qeth_l3_setdelip_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100441}
442
443static int qeth_l3_send_setrouting(struct qeth_card *card,
444 enum qeth_routing_types type, enum qeth_prot_versions prot)
445{
446 int rc;
447 struct qeth_ipa_cmd *cmd;
448 struct qeth_cmd_buffer *iob;
449
Carsten Otte847a50f2010-06-21 22:57:05 +0000450 QETH_CARD_TEXT(card, 4, "setroutg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100451 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100452 if (!iob)
453 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100454 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100455 cmd->data.setrtg.type = (type);
456 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
457
458 return rc;
459}
460
Stefan Raspl82e2e782013-03-18 20:04:43 +0000461static int qeth_l3_correct_routing_type(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100462 enum qeth_routing_types *type, enum qeth_prot_versions prot)
463{
464 if (card->info.type == QETH_CARD_TYPE_IQD) {
465 switch (*type) {
466 case NO_ROUTER:
467 case PRIMARY_CONNECTOR:
468 case SECONDARY_CONNECTOR:
469 case MULTICAST_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000470 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100471 default:
472 goto out_inval;
473 }
474 } else {
475 switch (*type) {
476 case NO_ROUTER:
477 case PRIMARY_ROUTER:
478 case SECONDARY_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000479 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100480 case MULTICAST_ROUTER:
481 if (qeth_is_ipafunc_supported(card, prot,
482 IPA_OSA_MC_ROUTER))
Stefan Raspl82e2e782013-03-18 20:04:43 +0000483 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100484 default:
485 goto out_inval;
486 }
487 }
488out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100489 *type = NO_ROUTER;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000490 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100491}
492
493int qeth_l3_setrouting_v4(struct qeth_card *card)
494{
495 int rc;
496
Carsten Otte847a50f2010-06-21 22:57:05 +0000497 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100498
Stefan Raspl82e2e782013-03-18 20:04:43 +0000499 rc = qeth_l3_correct_routing_type(card, &card->options.route4.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100500 QETH_PROT_IPV4);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000501 if (rc)
502 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100503
504 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
505 QETH_PROT_IPV4);
506 if (rc) {
507 card->options.route4.type = NO_ROUTER;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100508 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n",
509 rc, CARD_DEVID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100510 }
511 return rc;
512}
513
514int qeth_l3_setrouting_v6(struct qeth_card *card)
515{
516 int rc = 0;
517
Carsten Otte847a50f2010-06-21 22:57:05 +0000518 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100519
520 if (!qeth_is_supported(card, IPA_IPV6))
521 return 0;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000522 rc = qeth_l3_correct_routing_type(card, &card->options.route6.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100523 QETH_PROT_IPV6);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000524 if (rc)
525 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100526
527 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
528 QETH_PROT_IPV6);
529 if (rc) {
530 card->options.route6.type = NO_ROUTER;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100531 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n",
532 rc, CARD_DEVID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100533 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100534 return rc;
535}
536
537/*
538 * IP address takeover related functions
539 */
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100540
541/**
542 * qeth_l3_update_ipato() - Update 'takeover' property, for all NORMAL IPs.
543 *
544 * Caller must hold ip_lock.
545 */
546void qeth_l3_update_ipato(struct qeth_card *card)
547{
548 struct qeth_ipaddr *addr;
549 unsigned int i;
550
551 hash_for_each(card->ip_htable, i, addr, hnode) {
552 if (addr->type != QETH_IP_TYPE_NORMAL)
553 continue;
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100554 addr->ipato = qeth_l3_is_addr_covered_by_ipato(card, addr);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100555 }
556}
557
Frank Blaschka4a71df52008-02-15 09:19:42 +0100558static void qeth_l3_clear_ipato_list(struct qeth_card *card)
559{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100560 struct qeth_ipato_entry *ipatoe, *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100561
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200562 spin_lock_bh(&card->ip_lock);
563
Frank Blaschka4a71df52008-02-15 09:19:42 +0100564 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
565 list_del(&ipatoe->entry);
566 kfree(ipatoe);
567 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200568
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100569 qeth_l3_update_ipato(card);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200570 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100571}
572
573int qeth_l3_add_ipato_entry(struct qeth_card *card,
574 struct qeth_ipato_entry *new)
575{
576 struct qeth_ipato_entry *ipatoe;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100577 int rc = 0;
578
Carsten Otte847a50f2010-06-21 22:57:05 +0000579 QETH_CARD_TEXT(card, 2, "addipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200580
581 spin_lock_bh(&card->ip_lock);
582
Frank Blaschka4a71df52008-02-15 09:19:42 +0100583 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
584 if (ipatoe->proto != new->proto)
585 continue;
586 if (!memcmp(ipatoe->addr, new->addr,
587 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
588 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100589 rc = -EEXIST;
590 break;
591 }
592 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200593
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100594 if (!rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100595 list_add_tail(&new->entry, &card->ipato.entries);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100596 qeth_l3_update_ipato(card);
597 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100598
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200599 spin_unlock_bh(&card->ip_lock);
600
Frank Blaschka4a71df52008-02-15 09:19:42 +0100601 return rc;
602}
603
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100604int qeth_l3_del_ipato_entry(struct qeth_card *card,
605 enum qeth_prot_versions proto, u8 *addr,
606 int mask_bits)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100607{
608 struct qeth_ipato_entry *ipatoe, *tmp;
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100609 int rc = -ENOENT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100610
Carsten Otte847a50f2010-06-21 22:57:05 +0000611 QETH_CARD_TEXT(card, 2, "delipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200612
613 spin_lock_bh(&card->ip_lock);
614
Frank Blaschka4a71df52008-02-15 09:19:42 +0100615 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
616 if (ipatoe->proto != proto)
617 continue;
618 if (!memcmp(ipatoe->addr, addr,
619 (proto == QETH_PROT_IPV4)? 4:16) &&
620 (ipatoe->mask_bits == mask_bits)) {
621 list_del(&ipatoe->entry);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100622 qeth_l3_update_ipato(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100623 kfree(ipatoe);
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100624 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100625 }
626 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200627
628 spin_unlock_bh(&card->ip_lock);
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100629 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100630}
631
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100632int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip,
633 enum qeth_ip_types type,
634 enum qeth_prot_versions proto)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100635{
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100636 struct qeth_ipaddr addr;
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100637 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100638
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100639 qeth_l3_init_ipaddr(&addr, type, proto);
640 if (proto == QETH_PROT_IPV4)
641 memcpy(&addr.u.a4.addr, ip, 4);
642 else
643 memcpy(&addr.u.a6.addr, ip, 16);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200644
645 spin_lock_bh(&card->ip_lock);
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100646 rc = add ? qeth_l3_add_ip(card, &addr) : qeth_l3_delete_ip(card, &addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200647 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100648 return rc;
649}
650
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100651int qeth_l3_modify_hsuid(struct qeth_card *card, bool add)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100652{
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100653 struct qeth_ipaddr addr;
654 int rc, i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100655
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100656 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV6);
657 addr.u.a6.addr.s6_addr[0] = 0xfe;
658 addr.u.a6.addr.s6_addr[1] = 0x80;
659 for (i = 0; i < 8; i++)
660 addr.u.a6.addr.s6_addr[8+i] = card->options.hsuid[i];
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200661
662 spin_lock_bh(&card->ip_lock);
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100663 rc = add ? qeth_l3_add_ip(card, &addr) : qeth_l3_delete_ip(card, &addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200664 spin_unlock_bh(&card->ip_lock);
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100665 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100666}
667
668static int qeth_l3_register_addr_entry(struct qeth_card *card,
669 struct qeth_ipaddr *addr)
670{
671 char buf[50];
672 int rc = 0;
673 int cnt = 3;
674
Julian Wiedmannbd74a7f2018-11-02 19:04:09 +0100675 if (card->options.sniffer)
676 return 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200677
Frank Blaschka4a71df52008-02-15 09:19:42 +0100678 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000679 QETH_CARD_TEXT(card, 2, "setaddr4");
680 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100681 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000682 QETH_CARD_TEXT(card, 2, "setaddr6");
683 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
684 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100685 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000686 QETH_CARD_TEXT(card, 2, "setaddr?");
687 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100688 }
689 do {
690 if (addr->is_multicast)
691 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
692 else
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100693 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100694 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000695 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100696 } while ((--cnt > 0) && rc);
697 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000698 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100699 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100700 dev_warn(&card->gdev->dev,
701 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100702 }
703 return rc;
704}
705
706static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
707 struct qeth_ipaddr *addr)
708{
709 int rc = 0;
710
Julian Wiedmannbd74a7f2018-11-02 19:04:09 +0100711 if (card->options.sniffer)
712 return 0;
713
Frank Blaschka4a71df52008-02-15 09:19:42 +0100714 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000715 QETH_CARD_TEXT(card, 2, "deladdr4");
716 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100717 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000718 QETH_CARD_TEXT(card, 2, "deladdr6");
719 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
720 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100721 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000722 QETH_CARD_TEXT(card, 2, "deladdr?");
723 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100724 }
725 if (addr->is_multicast)
726 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
727 else
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100728 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200729 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000730 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100731
732 return rc;
733}
734
Frank Blaschka4a71df52008-02-15 09:19:42 +0100735static int qeth_l3_setadapter_parms(struct qeth_card *card)
736{
Julian Wiedmann699d3fe2017-08-15 17:02:41 +0200737 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100738
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200739 QETH_DBF_TEXT(SETUP, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100740
Frank Blaschka4a71df52008-02-15 09:19:42 +0100741 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
742 rc = qeth_setadpparms_change_macaddr(card);
743 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100744 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -0800745 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100746 }
747
Frank Blaschka4a71df52008-02-15 09:19:42 +0100748 return rc;
749}
750
Frank Blaschka4a71df52008-02-15 09:19:42 +0100751static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
752{
753 int rc;
754
Carsten Otte847a50f2010-06-21 22:57:05 +0000755 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100756
757 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100758 dev_info(&card->gdev->dev,
759 "ARP processing not supported on %s!\n",
760 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100761 return 0;
762 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200763 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
764 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100765 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100766 dev_warn(&card->gdev->dev,
767 "Starting ARP processing support for %s failed\n",
768 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100769 }
770 return rc;
771}
772
Frank Blaschka4a71df52008-02-15 09:19:42 +0100773static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
774{
775 int rc;
776
Carsten Otte847a50f2010-06-21 22:57:05 +0000777 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100778
Frank Blaschka4a71df52008-02-15 09:19:42 +0100779 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100780 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800781 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100782 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100783 return -EOPNOTSUPP;
784 }
785
Thomas Richter4d7def22015-09-18 16:06:51 +0200786 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100787 IPA_CMD_ASS_START, 0);
788 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100789 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800790 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100791 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100792 return rc;
793}
794
795static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
796{
797 int rc = 0;
798
Carsten Otte847a50f2010-06-21 22:57:05 +0000799 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100800
801 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100802 dev_info(&card->gdev->dev,
803 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100804 return -EOPNOTSUPP;
805 }
806
Thomas Richter4d7def22015-09-18 16:06:51 +0200807 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100808 IPA_CMD_ASS_START, 0);
809 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100810 dev_warn(&card->gdev->dev,
811 "Starting VLAN support for %s failed\n",
812 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100813 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100814 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100815 }
816 return rc;
817}
818
819static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
820{
821 int rc;
822
Carsten Otte847a50f2010-06-21 22:57:05 +0000823 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100824
825 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100826 dev_info(&card->gdev->dev,
827 "Multicast not supported on %s\n",
828 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100829 return -EOPNOTSUPP;
830 }
831
Thomas Richter4d7def22015-09-18 16:06:51 +0200832 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100833 IPA_CMD_ASS_START, 0);
834 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100835 dev_warn(&card->gdev->dev,
836 "Starting multicast support for %s failed\n",
837 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100838 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100839 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100840 card->dev->flags |= IFF_MULTICAST;
841 }
842 return rc;
843}
844
Frank Blaschka4a71df52008-02-15 09:19:42 +0100845static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
846{
847 int rc;
848
Carsten Otte847a50f2010-06-21 22:57:05 +0000849 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100850
Julian Wiedmann23274592017-06-06 14:33:44 +0200851 if (card->info.type == QETH_CARD_TYPE_IQD)
852 goto out;
853
Thomas Richter4d7def22015-09-18 16:06:51 +0200854 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100855 IPA_CMD_ASS_START, 3);
856 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100857 dev_err(&card->gdev->dev,
858 "Activating IPv6 support for %s failed\n",
859 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100860 return rc;
861 }
Kittipon Meesompopa8155b02018-04-26 09:42:21 +0200862 rc = qeth_send_simple_setassparms_v6(card, IPA_IPV6,
863 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100864 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100865 dev_err(&card->gdev->dev,
866 "Activating IPv6 support for %s failed\n",
867 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100868 return rc;
869 }
Kittipon Meesompopa8155b02018-04-26 09:42:21 +0200870 rc = qeth_send_simple_setassparms_v6(card, IPA_PASSTHRU,
871 IPA_CMD_ASS_START, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100872 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100873 dev_warn(&card->gdev->dev,
874 "Enabling the passthrough mode for %s failed\n",
875 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100876 return rc;
877 }
878out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100879 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100880 return 0;
881}
Frank Blaschka4a71df52008-02-15 09:19:42 +0100882
883static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
884{
Carsten Otte847a50f2010-06-21 22:57:05 +0000885 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100886
887 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100888 dev_info(&card->gdev->dev,
889 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100890 return 0;
891 }
Julian Wiedmannc0622042017-12-20 20:10:58 +0100892 return qeth_l3_softsetup_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100893}
894
895static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
896{
897 int rc;
898
Carsten Otte847a50f2010-06-21 22:57:05 +0000899 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100900 card->info.broadcast_capable = 0;
901 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100902 dev_info(&card->gdev->dev,
903 "Broadcast not supported on %s\n",
904 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100905 rc = -EOPNOTSUPP;
906 goto out;
907 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200908 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100909 IPA_CMD_ASS_START, 0);
910 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100911 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
912 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100913 goto out;
914 }
915
Thomas Richter4d7def22015-09-18 16:06:51 +0200916 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100917 IPA_CMD_ASS_CONFIGURE, 1);
918 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100919 dev_warn(&card->gdev->dev,
920 "Setting up broadcast filtering for %s failed\n",
921 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100922 goto out;
923 }
924 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100925 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Thomas Richter4d7def22015-09-18 16:06:51 +0200926 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100927 IPA_CMD_ASS_ENABLE, 1);
928 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100929 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
930 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100931 goto out;
932 }
933 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
934out:
935 if (card->info.broadcast_capable)
936 card->dev->flags |= IFF_BROADCAST;
937 else
938 card->dev->flags &= ~IFF_BROADCAST;
939 return rc;
940}
941
Frank Blaschka4a71df52008-02-15 09:19:42 +0100942static int qeth_l3_start_ipassists(struct qeth_card *card)
943{
Carsten Otte847a50f2010-06-21 22:57:05 +0000944 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +0000945
Stefan Raspl0f547612013-01-21 02:30:20 +0000946 if (qeth_set_access_ctrl_online(card, 0))
947 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100948 qeth_l3_start_ipa_arp_processing(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +0100949 qeth_l3_start_ipa_source_mac(card); /* go on*/
950 qeth_l3_start_ipa_vlan(card); /* go on*/
951 qeth_l3_start_ipa_multicast(card); /* go on*/
952 qeth_l3_start_ipa_ipv6(card); /* go on*/
953 qeth_l3_start_ipa_broadcast(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +0100954 return 0;
955}
956
Frank Blaschka4a71df52008-02-15 09:19:42 +0100957static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
958 struct qeth_reply *reply, unsigned long data)
959{
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100960 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100961
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100962 if (cmd->hdr.return_code)
963 return -EIO;
964
965 ether_addr_copy(card->dev->dev_addr,
966 cmd->data.create_destroy_addr.unique_id);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100967 return 0;
968}
969
970static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
971{
972 int rc = 0;
973 struct qeth_cmd_buffer *iob;
974 struct qeth_ipa_cmd *cmd;
975
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200976 QETH_DBF_TEXT(SETUP, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100977
978 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
979 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100980 if (!iob)
981 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100982 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100983 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
984 card->info.unique_id;
985
986 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
987 NULL);
988 return rc;
989}
990
991static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
992 struct qeth_reply *reply, unsigned long data)
993{
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100994 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100995
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100996 if (cmd->hdr.return_code == 0) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100997 card->info.unique_id = *((__u16 *)
998 &cmd->data.create_destroy_addr.unique_id[6]);
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100999 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001000 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001001
1002 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1003 UNIQUE_ID_NOT_BY_CARD;
1004 dev_warn(&card->gdev->dev, "The network adapter failed to generate a unique ID\n");
1005 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001006}
1007
1008static int qeth_l3_get_unique_id(struct qeth_card *card)
1009{
1010 int rc = 0;
1011 struct qeth_cmd_buffer *iob;
1012 struct qeth_ipa_cmd *cmd;
1013
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001014 QETH_DBF_TEXT(SETUP, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001015
1016 if (!qeth_is_supported(card, IPA_IPV6)) {
1017 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1018 UNIQUE_ID_NOT_BY_CARD;
1019 return 0;
1020 }
1021
1022 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
1023 QETH_PROT_IPV6);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001024 if (!iob)
1025 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001026 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001027 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1028 card->info.unique_id;
1029
1030 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1031 return rc;
1032}
1033
Ursula Braun76b11f82010-01-11 02:50:50 +00001034static int
1035qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1036 unsigned long data)
1037{
1038 struct qeth_ipa_cmd *cmd;
1039 __u16 rc;
1040
1041 QETH_DBF_TEXT(SETUP, 2, "diastrcb");
1042
1043 cmd = (struct qeth_ipa_cmd *)data;
1044 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001045 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001046 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001047 switch (cmd->data.diagass.action) {
1048 case QETH_DIAGS_CMD_TRACE_QUERY:
1049 break;
1050 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001051 switch (rc) {
1052 case 0:
1053 case IPA_RC_INVALID_SUBCMD:
1054 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1055 dev_info(&card->gdev->dev, "The HiperSockets network "
1056 "traffic analyzer is deactivated\n");
1057 break;
1058 default:
1059 break;
1060 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001061 break;
1062 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001063 switch (rc) {
1064 case 0:
1065 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1066 dev_info(&card->gdev->dev, "The HiperSockets network "
1067 "traffic analyzer is activated\n");
1068 break;
1069 case IPA_RC_HARDWARE_AUTH_ERROR:
1070 dev_warn(&card->gdev->dev, "The device is not "
1071 "authorized to run as a HiperSockets network "
1072 "traffic analyzer\n");
1073 break;
1074 case IPA_RC_TRACE_ALREADY_ACTIVE:
1075 dev_warn(&card->gdev->dev, "A HiperSockets "
1076 "network traffic analyzer is already "
1077 "active in the HiperSockets LAN\n");
1078 break;
1079 default:
1080 break;
1081 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001082 break;
1083 default:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001084 QETH_DBF_MESSAGE(2, "Unknown sniffer action (%#06x) on device %x\n",
1085 cmd->data.diagass.action, CARD_DEVID(card));
Ursula Braun76b11f82010-01-11 02:50:50 +00001086 }
1087
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001088 return rc ? -EIO : 0;
Ursula Braun76b11f82010-01-11 02:50:50 +00001089}
1090
1091static int
1092qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1093{
1094 struct qeth_cmd_buffer *iob;
1095 struct qeth_ipa_cmd *cmd;
1096
1097 QETH_DBF_TEXT(SETUP, 2, "diagtrac");
1098
1099 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001100 if (!iob)
1101 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001102 cmd = __ipa_cmd(iob);
Ursula Braun76b11f82010-01-11 02:50:50 +00001103 cmd->data.diagass.subcmd_len = 16;
1104 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
1105 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1106 cmd->data.diagass.action = diags_cmd;
1107 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1108}
1109
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001110static void
1111qeth_l3_add_mc_to_hash(struct qeth_card *card, struct in_device *in4_dev)
1112{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001113 struct ip_mc_list *im4;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001114 struct qeth_ipaddr *tmp, *ipm;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001115
Carsten Otte847a50f2010-06-21 22:57:05 +00001116 QETH_CARD_TEXT(card, 4, "addmc");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001117
1118 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001119 if (!tmp)
1120 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001121
Sachin Santf3aa3132010-11-26 02:41:17 +00001122 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1123 im4 = rcu_dereference(im4->next_rcu)) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001124 ip_eth_mc_map(im4->multiaddr, tmp->mac);
Hans Wippel6bee4e22017-04-07 09:15:36 +02001125 tmp->u.a4.addr = be32_to_cpu(im4->multiaddr);
Julian Wiedmannbc3ab7052017-12-01 10:14:49 +01001126 tmp->is_multicast = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001127
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001128 ipm = qeth_l3_find_addr_by_ip(card, tmp);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001129 if (ipm) {
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001130 /* for mcast, by-IP match means full match */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001131 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1132 } else {
1133 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
1134 if (!ipm)
1135 continue;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001136 ether_addr_copy(ipm->mac, tmp->mac);
Hans Wippel6bee4e22017-04-07 09:15:36 +02001137 ipm->u.a4.addr = be32_to_cpu(im4->multiaddr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001138 ipm->is_multicast = 1;
1139 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1140 hash_add(card->ip_mc_htable,
1141 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1142 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001143 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001144
1145 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001146}
1147
Jiri Pirko0347af52013-01-03 22:48:58 +00001148/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001149static void qeth_l3_add_vlan_mc(struct qeth_card *card)
1150{
1151 struct in_device *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001152 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001153
Carsten Otte847a50f2010-06-21 22:57:05 +00001154 QETH_CARD_TEXT(card, 4, "addmcvl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001155
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001156 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001157 return;
1158
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001159 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1160 struct net_device *netdev;
1161
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001162 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001163 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001164 if (netdev == NULL ||
1165 !(netdev->flags & IFF_UP))
1166 continue;
Jiri Pirko0347af52013-01-03 22:48:58 +00001167 in_dev = __in_dev_get_rcu(netdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001168 if (!in_dev)
1169 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001170 qeth_l3_add_mc_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001171 }
1172}
1173
1174static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
1175{
1176 struct in_device *in4_dev;
1177
Carsten Otte847a50f2010-06-21 22:57:05 +00001178 QETH_CARD_TEXT(card, 4, "chkmcv4");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001179
Sachin Santf3aa3132010-11-26 02:41:17 +00001180 rcu_read_lock();
Jiri Pirko0347af52013-01-03 22:48:58 +00001181 in4_dev = __in_dev_get_rcu(card->dev);
1182 if (in4_dev == NULL)
1183 goto unlock;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001184 qeth_l3_add_mc_to_hash(card, in4_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001185 qeth_l3_add_vlan_mc(card);
Jiri Pirko0347af52013-01-03 22:48:58 +00001186unlock:
Sachin Santf3aa3132010-11-26 02:41:17 +00001187 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001188}
1189
Julian Wiedmannc0622042017-12-20 20:10:58 +01001190static void qeth_l3_add_mc6_to_hash(struct qeth_card *card,
1191 struct inet6_dev *in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001192{
1193 struct qeth_ipaddr *ipm;
1194 struct ifmcaddr6 *im6;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001195 struct qeth_ipaddr *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001196
Carsten Otte847a50f2010-06-21 22:57:05 +00001197 QETH_CARD_TEXT(card, 4, "addmc6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001198
1199 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001200 if (!tmp)
1201 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001202
Frank Blaschka4a71df52008-02-15 09:19:42 +01001203 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001204 ipv6_eth_mc_map(&im6->mca_addr, tmp->mac);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001205 memcpy(&tmp->u.a6.addr, &im6->mca_addr.s6_addr,
1206 sizeof(struct in6_addr));
1207 tmp->is_multicast = 1;
1208
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001209 ipm = qeth_l3_find_addr_by_ip(card, tmp);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001210 if (ipm) {
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001211 /* for mcast, by-IP match means full match */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001212 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1213 continue;
1214 }
1215
Frank Blaschka4a71df52008-02-15 09:19:42 +01001216 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
1217 if (!ipm)
1218 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001219
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001220 ether_addr_copy(ipm->mac, tmp->mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001221 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
1222 sizeof(struct in6_addr));
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001223 ipm->is_multicast = 1;
1224 ipm->disp_flag = QETH_DISP_ADDR_ADD;
1225 hash_add(card->ip_mc_htable,
1226 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1227
Frank Blaschka4a71df52008-02-15 09:19:42 +01001228 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001229 kfree(tmp);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001230}
1231
Jiri Pirko0347af52013-01-03 22:48:58 +00001232/* called with rcu_read_lock */
Frank Blaschka4a71df52008-02-15 09:19:42 +01001233static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
1234{
1235 struct inet6_dev *in_dev;
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001236 u16 vid;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001237
Carsten Otte847a50f2010-06-21 22:57:05 +00001238 QETH_CARD_TEXT(card, 4, "admc6vl");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001239
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001240 if (!qeth_is_supported(card, IPA_FULL_VLAN))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001241 return;
1242
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001243 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
1244 struct net_device *netdev;
1245
dingtianhongf06c7f9f2014-05-09 14:58:05 +08001246 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
Patrick McHardy91b1c1a2013-04-21 00:09:34 +00001247 vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001248 if (netdev == NULL ||
1249 !(netdev->flags & IFF_UP))
1250 continue;
1251 in_dev = in6_dev_get(netdev);
1252 if (!in_dev)
1253 continue;
1254 read_lock_bh(&in_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001255 qeth_l3_add_mc6_to_hash(card, in_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001256 read_unlock_bh(&in_dev->lock);
1257 in6_dev_put(in_dev);
1258 }
1259}
1260
1261static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
1262{
1263 struct inet6_dev *in6_dev;
1264
Carsten Otte847a50f2010-06-21 22:57:05 +00001265 QETH_CARD_TEXT(card, 4, "chkmcv6");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001266
Frank Blaschka4a71df52008-02-15 09:19:42 +01001267 if (!qeth_is_supported(card, IPA_IPV6))
1268 return ;
1269 in6_dev = in6_dev_get(card->dev);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001270 if (!in6_dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001271 return;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001272
Jiri Pirko0347af52013-01-03 22:48:58 +00001273 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001274 read_lock_bh(&in6_dev->lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001275 qeth_l3_add_mc6_to_hash(card, in6_dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001276 qeth_l3_add_vlan_mc6(card);
1277 read_unlock_bh(&in6_dev->lock);
Jiri Pirko0347af52013-01-03 22:48:58 +00001278 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001279 in6_dev_put(in6_dev);
1280}
Frank Blaschka4a71df52008-02-15 09:19:42 +01001281
Patrick McHardy80d5c362013-04-19 02:04:28 +00001282static int qeth_l3_vlan_rx_add_vid(struct net_device *dev,
1283 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001284{
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001285 struct qeth_card *card = dev->ml_priv;
1286
1287 set_bit(vid, card->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001288 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001289}
1290
Patrick McHardy80d5c362013-04-19 02:04:28 +00001291static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev,
1292 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001293{
Heiko Carstens509e2562008-07-26 02:24:10 -07001294 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001295
Carsten Otte847a50f2010-06-21 22:57:05 +00001296 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001297
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001298 clear_bit(vid, card->active_vlans);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001299 qeth_l3_set_rx_mode(dev);
Jiri Pirko8e586132011-12-08 19:52:37 -05001300 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001301}
1302
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001303static void qeth_l3_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
1304 struct qeth_hdr *hdr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001305{
Frank Blaschka4a71df52008-02-15 09:19:42 +01001306 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001307 u16 prot = (hdr->hdr.l3.flags & QETH_HDR_IPV6) ? ETH_P_IPV6 :
1308 ETH_P_IP;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001309 unsigned char tg_addr[ETH_ALEN];
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001310
1311 skb_reset_network_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001312 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1313 case QETH_CAST_MULTICAST:
Julian Wiedmannc0622042017-12-20 20:10:58 +01001314 if (prot == ETH_P_IP)
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001315 ip_eth_mc_map(ip_hdr(skb)->daddr, tg_addr);
Julian Wiedmannc0622042017-12-20 20:10:58 +01001316 else
1317 ipv6_eth_mc_map(&ipv6_hdr(skb)->daddr, tg_addr);
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001318 QETH_CARD_STAT_INC(card, rx_multicast);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001319 break;
1320 case QETH_CAST_BROADCAST:
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001321 ether_addr_copy(tg_addr, card->dev->broadcast);
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001322 QETH_CARD_STAT_INC(card, rx_multicast);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001323 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001324 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00001325 if (card->options.sniffer)
1326 skb->pkt_type = PACKET_OTHERHOST;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001327 ether_addr_copy(tg_addr, card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001328 }
Julian Wiedmann04f67392018-03-09 18:12:58 +01001329
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001330 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1331 card->dev->header_ops->create(skb, card->dev, prot,
Julian Wiedmanna8433832017-12-20 20:11:06 +01001332 tg_addr, &hdr->hdr.l3.next_hop.rx.src_mac,
Julian Wiedmannf0ea8bf2018-03-09 18:12:56 +01001333 skb->len);
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001334 else
1335 card->dev->header_ops->create(skb, card->dev, prot,
Julian Wiedmannf0ea8bf2018-03-09 18:12:56 +01001336 tg_addr, "FAKELL", skb->len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001337 }
1338
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001339 skb->protocol = eth_type_trans(skb, card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001340
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001341 /* copy VLAN tag from hdr into skb */
1342 if (!card->options.sniffer &&
1343 (hdr->hdr.l3.ext_flags & (QETH_HDR_EXT_VLAN_FRAME |
1344 QETH_HDR_EXT_INCLUDE_VLAN_TAG))) {
1345 u16 tag = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
1346 hdr->hdr.l3.vlan_id :
Julian Wiedmanna8433832017-12-20 20:11:06 +01001347 hdr->hdr.l3.next_hop.rx.vlan_id;
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001348 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001349 }
1350
Julian Wiedmann6195b932018-04-26 09:42:17 +02001351 qeth_rx_csum(card, skb, hdr->hdr.l3.ext_flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001352}
1353
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001354static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1355 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001356{
Julian Wiedmanncd11d112018-09-26 18:29:06 +02001357 struct net_device *dev = card->dev;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001358 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001359 struct sk_buff *skb;
1360 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001361 unsigned int len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001362 __u16 magic;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001363
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001364 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +00001365 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001366 while (budget) {
1367 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +00001368 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001369 &card->rx.b_element, &card->rx.e_offset, &hdr);
1370 if (!skb) {
1371 *done = 1;
1372 break;
1373 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001374 switch (hdr->hdr.l3.id) {
1375 case QETH_HEADER_TYPE_LAYER3:
Frank Blaschkab3332932011-08-08 01:33:59 +00001376 magic = *(__u16 *)skb->data;
1377 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
1378 (magic == ETH_P_AF_IUCV)) {
Frank Blaschkab3332932011-08-08 01:33:59 +00001379 len = skb->len;
Julian Wiedmanncd11d112018-09-26 18:29:06 +02001380 dev_hard_header(skb, dev, ETH_P_AF_IUCV,
1381 dev->dev_addr, "FAKELL", len);
1382 skb->protocol = eth_type_trans(skb, dev);
Frank Blaschkab3332932011-08-08 01:33:59 +00001383 netif_receive_skb(skb);
1384 } else {
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001385 qeth_l3_rebuild_skb(card, skb, hdr);
Frank Blaschkab3332932011-08-08 01:33:59 +00001386 len = skb->len;
Frank Blaschkab3332932011-08-08 01:33:59 +00001387 napi_gro_receive(&card->napi, skb);
1388 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001389 break;
Ursula Braun76b11f82010-01-11 02:50:50 +00001390 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
Ursula Braun76b11f82010-01-11 02:50:50 +00001391 skb->protocol = eth_type_trans(skb, skb->dev);
Ursula Braun76b11f82010-01-11 02:50:50 +00001392 len = skb->len;
1393 netif_receive_skb(skb);
1394 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001395 default:
1396 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +00001397 QETH_CARD_TEXT(card, 3, "inbunkno");
Julian Wiedmann0ac14872018-09-12 15:31:35 +02001398 QETH_DBF_HEX(CTRL, 3, hdr, sizeof(*hdr));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001399 continue;
1400 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001401 work_done++;
1402 budget--;
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001403 QETH_CARD_STAT_INC(card, rx_packets);
1404 QETH_CARD_STAT_ADD(card, rx_bytes, len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001405 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001406 return work_done;
1407}
1408
Julian Wiedmannd4560152019-02-28 18:59:39 +01001409static void qeth_l3_stop_card(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001410{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001411 QETH_DBF_TEXT(SETUP, 2, "stopcard");
1412 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001413
1414 qeth_set_allowed_threads(card, 0, 1);
Ursula Braun76b11f82010-01-11 02:50:50 +00001415 if (card->options.sniffer &&
1416 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
1417 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001418 if (card->read.state == CH_STATE_UP &&
1419 card->write.state == CH_STATE_UP &&
Julian Wiedmannd4560152019-02-28 18:59:39 +01001420 card->state == CARD_STATE_UP)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001421 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001422 if (card->state == CARD_STATE_SOFTSETUP) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001423 qeth_l3_clear_ip_htable(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001424 qeth_clear_ipacmd_list(card);
1425 card->state = CARD_STATE_HARDSETUP;
1426 }
1427 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001428 qeth_qdio_clear_card(card, 0);
1429 qeth_clear_qdio_buffers(card);
1430 qeth_clear_working_pool_list(card);
1431 card->state = CARD_STATE_DOWN;
1432 }
1433 if (card->state == CARD_STATE_DOWN) {
1434 qeth_clear_cmd_buffers(&card->read);
1435 qeth_clear_cmd_buffers(&card->write);
1436 }
Julian Wiedmannc0a2e4d2019-02-04 17:40:09 +01001437
1438 flush_workqueue(card->event_wq);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001439}
1440
Ursula Braun76b11f82010-01-11 02:50:50 +00001441/*
1442 * test for and Switch promiscuous mode (on or off)
1443 * either for guestlan or HiperSocket Sniffer
1444 */
1445static void
1446qeth_l3_handle_promisc_mode(struct qeth_card *card)
1447{
1448 struct net_device *dev = card->dev;
1449
1450 if (((dev->flags & IFF_PROMISC) &&
1451 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
1452 (!(dev->flags & IFF_PROMISC) &&
1453 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
1454 return;
1455
1456 if (card->info.guestlan) { /* Guestlan trace */
1457 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
1458 qeth_setadp_promisc_mode(card);
1459 } else if (card->options.sniffer && /* HiperSockets trace */
1460 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
1461 if (dev->flags & IFF_PROMISC) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001462 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001463 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
1464 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00001465 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001466 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
1467 }
1468 }
1469}
1470
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001471static void qeth_l3_set_rx_mode(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001472{
Heiko Carstens509e2562008-07-26 02:24:10 -07001473 struct qeth_card *card = dev->ml_priv;
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001474 struct qeth_ipaddr *addr;
1475 struct hlist_node *tmp;
1476 int i, rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001477
Carsten Otte847a50f2010-06-21 22:57:05 +00001478 QETH_CARD_TEXT(card, 3, "setmulti");
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01001479
Ursula Braun76b11f82010-01-11 02:50:50 +00001480 if (!card->options.sniffer) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001481 spin_lock_bh(&card->mclock);
1482
Ursula Braun76b11f82010-01-11 02:50:50 +00001483 qeth_l3_add_multicast_ipv4(card);
Ursula Braun76b11f82010-01-11 02:50:50 +00001484 qeth_l3_add_multicast_ipv6(card);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001485
1486 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1487 switch (addr->disp_flag) {
1488 case QETH_DISP_ADDR_DELETE:
1489 rc = qeth_l3_deregister_addr_entry(card, addr);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001490 if (!rc || rc == -ENOENT) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001491 hash_del(&addr->hnode);
1492 kfree(addr);
1493 }
1494 break;
1495 case QETH_DISP_ADDR_ADD:
1496 rc = qeth_l3_register_addr_entry(card, addr);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001497 if (rc && rc != -ENETDOWN) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001498 hash_del(&addr->hnode);
1499 kfree(addr);
1500 break;
1501 }
1502 addr->ref_counter = 1;
1503 /* fall through */
1504 default:
1505 /* for next call to set_rx_mode(): */
1506 addr->disp_flag = QETH_DISP_ADDR_DELETE;
1507 }
1508 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001509
1510 spin_unlock_bh(&card->mclock);
1511
Ursula Braun76b11f82010-01-11 02:50:50 +00001512 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
1513 return;
1514 }
1515 qeth_l3_handle_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001516}
1517
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001518static int qeth_l3_arp_makerc(u16 rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001519{
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001520 switch (rc) {
1521 case IPA_RC_SUCCESS:
1522 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001523 case QETH_IPA_ARP_RC_NOTSUPP:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001524 case QETH_IPA_ARP_RC_Q_NOTSUPP:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001525 return -EOPNOTSUPP;
1526 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
1527 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001528 case QETH_IPA_ARP_RC_Q_NO_DATA:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001529 return -ENOENT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001530 default:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001531 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001532 }
1533}
1534
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001535static int qeth_l3_arp_cmd_cb(struct qeth_card *card, struct qeth_reply *reply,
1536 unsigned long data)
1537{
1538 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1539
1540 qeth_setassparms_cb(card, reply, data);
1541 return qeth_l3_arp_makerc(cmd->hdr.return_code);
1542}
1543
Frank Blaschka4a71df52008-02-15 09:19:42 +01001544static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
1545{
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001546 struct qeth_cmd_buffer *iob;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001547 int rc;
1548
Carsten Otte847a50f2010-06-21 22:57:05 +00001549 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001550
1551 /*
1552 * currently GuestLAN only supports the ARP assist function
1553 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
1554 * thus we say EOPNOTSUPP for this ARP function
1555 */
1556 if (card->info.guestlan)
1557 return -EOPNOTSUPP;
1558 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001559 return -EOPNOTSUPP;
1560 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001561
1562 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
1563 IPA_CMD_ASS_ARP_SET_NO_ENTRIES, 4,
1564 QETH_PROT_IPV4);
1565 if (!iob)
1566 return -ENOMEM;
1567
1568 __ipa_cmd(iob)->data.setassparms.data.flags_32bit = (u32) no_entries;
1569 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001570 if (rc)
1571 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on device %x: %#x\n",
1572 CARD_DEVID(card), rc);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001573 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001574}
1575
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001576static __u32 get_arp_entry_size(struct qeth_card *card,
1577 struct qeth_arp_query_data *qdata,
1578 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001579{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001580 __u32 rc;
1581 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001582
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001583 is_hsi = qdata->reply_bits == 5;
1584 if (type->ip == QETHARP_IP_ADDR_V4) {
1585 QETH_CARD_TEXT(card, 4, "arpev4");
1586 if (strip_entries) {
1587 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
1588 sizeof(struct qeth_arp_qi_entry7_short);
1589 } else {
1590 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
1591 sizeof(struct qeth_arp_qi_entry7);
1592 }
1593 } else if (type->ip == QETHARP_IP_ADDR_V6) {
1594 QETH_CARD_TEXT(card, 4, "arpev6");
1595 if (strip_entries) {
1596 rc = is_hsi ?
1597 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
1598 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
1599 } else {
1600 rc = is_hsi ?
1601 sizeof(struct qeth_arp_qi_entry5_ipv6) :
1602 sizeof(struct qeth_arp_qi_entry7_ipv6);
1603 }
1604 } else {
1605 QETH_CARD_TEXT(card, 4, "arpinv");
1606 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001607 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001608
1609 return rc;
1610}
1611
1612static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
1613{
1614 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
1615 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001616}
1617
1618static int qeth_l3_arp_query_cb(struct qeth_card *card,
1619 struct qeth_reply *reply, unsigned long data)
1620{
1621 struct qeth_ipa_cmd *cmd;
1622 struct qeth_arp_query_data *qdata;
1623 struct qeth_arp_query_info *qinfo;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001624 int e;
1625 int entrybytes_done;
1626 int stripped_bytes;
1627 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001628
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001629 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001630
1631 qinfo = (struct qeth_arp_query_info *) reply->param;
1632 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001633 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001634 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001635 QETH_CARD_TEXT(card, 4, "arpcberr");
1636 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001637 return qeth_l3_arp_makerc(cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001638 }
1639 if (cmd->data.setassparms.hdr.return_code) {
1640 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001641 QETH_CARD_TEXT(card, 4, "setaperr");
1642 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001643 return qeth_l3_arp_makerc(cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001644 }
1645 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00001646 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001647
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001648 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
1649 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
1650 entrybytes_done = 0;
1651 for (e = 0; e < qdata->no_entries; ++e) {
1652 char *cur_entry;
1653 __u32 esize;
1654 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001655
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001656 cur_entry = &qdata->data + entrybytes_done;
1657 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
1658 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
1659 QETH_CARD_TEXT(card, 4, "pmis");
1660 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
1661 break;
1662 }
1663 esize = get_arp_entry_size(card, qdata, etype,
1664 do_strip_entries);
1665 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
1666 if (!esize)
1667 break;
1668
1669 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001670 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOSPC);
1671 memset(qinfo->udata, 0, 4);
1672 return -ENOSPC;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001673 }
1674
1675 memcpy(qinfo->udata + qinfo->udata_offset,
1676 &qdata->data + entrybytes_done + stripped_bytes,
1677 esize);
1678 entrybytes_done += esize + stripped_bytes;
1679 qinfo->udata_offset += esize;
1680 ++qinfo->no_entries;
1681 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001682 /* check if all replies received ... */
1683 if (cmd->data.setassparms.hdr.seq_no <
1684 cmd->data.setassparms.hdr.number_of_replies)
1685 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001686 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001687 memcpy(qinfo->udata, &qinfo->no_entries, 4);
1688 /* keep STRIP_ENTRIES flag so the user program can distinguish
1689 * stripped entries from normal ones */
1690 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
1691 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
1692 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001693 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001694 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001695}
1696
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001697static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
1698 enum qeth_prot_versions prot,
1699 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001700{
1701 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001702 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001703 int rc;
1704
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001705 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
1706
Thomas Richterb475e312015-12-11 12:27:54 +01001707 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
1708 IPA_CMD_ASS_ARP_QUERY_INFO,
1709 sizeof(struct qeth_arp_query_data)
1710 - sizeof(char),
1711 prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001712 if (!iob)
1713 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001714 cmd = __ipa_cmd(iob);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001715 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
Julian Wiedmann84dbea42019-02-12 18:33:16 +01001716 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_query_cb, qinfo);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001717 if (rc)
1718 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on device %x: %#x\n",
1719 CARD_DEVID(card), rc);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001720 return rc;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001721}
1722
1723static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
1724{
1725 struct qeth_arp_query_info qinfo = {0, };
1726 int rc;
1727
Carsten Otte847a50f2010-06-21 22:57:05 +00001728 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001729
1730 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
1731 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001732 QETH_CARD_TEXT(card, 3, "arpqnsup");
1733 rc = -EOPNOTSUPP;
1734 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001735 }
1736 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001737 if (copy_from_user(&qinfo, udata, 6)) {
1738 rc = -EFAULT;
1739 goto out;
1740 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001741 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001742 if (!qinfo.udata) {
1743 rc = -ENOMEM;
1744 goto out;
1745 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001746 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001747 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001748 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001749 if (copy_to_user(udata, qinfo.udata, 4))
1750 rc = -EFAULT;
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001751 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001752 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001753 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
1754 /* fails in case of GuestLAN QDIO mode */
1755 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6, &qinfo);
1756 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001757 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
1758 QETH_CARD_TEXT(card, 4, "qactf");
1759 rc = -EFAULT;
1760 goto free_and_out;
1761 }
1762 QETH_CARD_TEXT(card, 4, "qacts");
1763
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001764free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001765 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001766out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001767 return rc;
1768}
1769
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001770static int qeth_l3_arp_modify_entry(struct qeth_card *card,
1771 struct qeth_arp_cache_entry *entry,
1772 enum qeth_arp_process_subcmds arp_cmd)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001773{
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001774 struct qeth_arp_cache_entry *cmd_entry;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001775 struct qeth_cmd_buffer *iob;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001776 int rc;
1777
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001778 if (arp_cmd == IPA_CMD_ASS_ARP_ADD_ENTRY)
1779 QETH_CARD_TEXT(card, 3, "arpadd");
1780 else
1781 QETH_CARD_TEXT(card, 3, "arpdel");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001782
1783 /*
1784 * currently GuestLAN only supports the ARP assist function
1785 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
1786 * thus we say EOPNOTSUPP for this ARP function
1787 */
1788 if (card->info.guestlan)
1789 return -EOPNOTSUPP;
1790 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001791 return -EOPNOTSUPP;
1792 }
1793
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001794 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, arp_cmd,
1795 sizeof(*cmd_entry), QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001796 if (!iob)
1797 return -ENOMEM;
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001798
1799 cmd_entry = &__ipa_cmd(iob)->data.setassparms.data.arp_entry;
1800 ether_addr_copy(cmd_entry->macaddr, entry->macaddr);
1801 memcpy(cmd_entry->ipaddr, entry->ipaddr, 4);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001802 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001803 if (rc)
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001804 QETH_DBF_MESSAGE(2, "Could not modify (cmd: %#x) ARP entry on device %x: %#x\n",
1805 arp_cmd, CARD_DEVID(card), rc);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001806 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001807}
1808
1809static int qeth_l3_arp_flush_cache(struct qeth_card *card)
1810{
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001811 struct qeth_cmd_buffer *iob;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001812 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001813
Carsten Otte847a50f2010-06-21 22:57:05 +00001814 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001815
1816 /*
1817 * currently GuestLAN only supports the ARP assist function
1818 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
1819 * thus we say EOPNOTSUPP for this ARP function
1820 */
1821 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
1822 return -EOPNOTSUPP;
1823 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001824 return -EOPNOTSUPP;
1825 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001826
1827 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
1828 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0,
1829 QETH_PROT_IPV4);
1830 if (!iob)
1831 return -ENOMEM;
1832
1833 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001834 if (rc)
1835 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on device %x: %#x\n",
1836 CARD_DEVID(card), rc);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001837 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001838}
1839
1840static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1841{
Heiko Carstens509e2562008-07-26 02:24:10 -07001842 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001843 struct qeth_arp_cache_entry arp_entry;
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001844 enum qeth_arp_process_subcmds arp_cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001845 int rc = 0;
1846
Frank Blaschka4a71df52008-02-15 09:19:42 +01001847 switch (cmd) {
1848 case SIOC_QETH_ARP_SET_NO_ENTRIES:
1849 if (!capable(CAP_NET_ADMIN)) {
1850 rc = -EPERM;
1851 break;
1852 }
1853 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
1854 break;
1855 case SIOC_QETH_ARP_QUERY_INFO:
1856 if (!capable(CAP_NET_ADMIN)) {
1857 rc = -EPERM;
1858 break;
1859 }
1860 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
1861 break;
1862 case SIOC_QETH_ARP_ADD_ENTRY:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001863 case SIOC_QETH_ARP_REMOVE_ENTRY:
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001864 if (!capable(CAP_NET_ADMIN))
1865 return -EPERM;
1866 if (copy_from_user(&arp_entry, rq->ifr_data, sizeof(arp_entry)))
1867 return -EFAULT;
1868
1869 arp_cmd = (cmd == SIOC_QETH_ARP_ADD_ENTRY) ?
1870 IPA_CMD_ASS_ARP_ADD_ENTRY :
1871 IPA_CMD_ASS_ARP_REMOVE_ENTRY;
1872 return qeth_l3_arp_modify_entry(card, &arp_entry, arp_cmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001873 case SIOC_QETH_ARP_FLUSH_CACHE:
1874 if (!capable(CAP_NET_ADMIN)) {
1875 rc = -EPERM;
1876 break;
1877 }
1878 rc = qeth_l3_arp_flush_cache(card);
1879 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001880 default:
1881 rc = -EOPNOTSUPP;
1882 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001883 return rc;
1884}
1885
Julian Wiedmann1f979122017-12-20 20:11:04 +01001886static int qeth_l3_get_cast_type(struct sk_buff *skb)
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001887{
David S. Miller69cce1d2011-07-17 23:09:49 -07001888 struct neighbour *n = NULL;
1889 struct dst_entry *dst;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001890
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001891 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07001892 dst = skb_dst(skb);
1893 if (dst)
David S. Miller24db1ba2012-07-02 22:02:33 -07001894 n = dst_neigh_lookup_skb(dst, skb);
David S. Miller69cce1d2011-07-17 23:09:49 -07001895 if (n) {
Julian Wiedmann1f979122017-12-20 20:11:04 +01001896 int cast_type = n->type;
1897
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001898 rcu_read_unlock();
David S. Miller24db1ba2012-07-02 22:02:33 -07001899 neigh_release(n);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001900 if ((cast_type == RTN_BROADCAST) ||
1901 (cast_type == RTN_MULTICAST) ||
1902 (cast_type == RTN_ANYCAST))
1903 return cast_type;
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +02001904 return RTN_UNICAST;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001905 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001906 rcu_read_unlock();
1907
Julian Wiedmann1f979122017-12-20 20:11:04 +01001908 /* no neighbour (eg AF_PACKET), fall back to target's IP address ... */
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001909 switch (qeth_get_ip_version(skb)) {
1910 case 4:
Julian Wiedmann1f979122017-12-20 20:11:04 +01001911 return ipv4_is_multicast(ip_hdr(skb)->daddr) ?
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +02001912 RTN_MULTICAST : RTN_UNICAST;
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001913 case 6:
1914 return ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr) ?
1915 RTN_MULTICAST : RTN_UNICAST;
1916 default:
1917 /* ... and MAC address */
1918 if (ether_addr_equal_64bits(eth_hdr(skb)->h_dest,
1919 skb->dev->broadcast))
1920 return RTN_BROADCAST;
1921 if (is_multicast_ether_addr(eth_hdr(skb)->h_dest))
1922 return RTN_MULTICAST;
1923 /* default to unicast */
1924 return RTN_UNICAST;
1925 }
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001926}
1927
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001928static u8 qeth_l3_cast_type_to_flag(int cast_type)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001929{
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001930 if (cast_type == RTN_MULTICAST)
1931 return QETH_CAST_MULTICAST;
1932 if (cast_type == RTN_ANYCAST)
1933 return QETH_CAST_ANYCAST;
1934 if (cast_type == RTN_BROADCAST)
1935 return QETH_CAST_BROADCAST;
1936 return QETH_CAST_UNICAST;
1937}
David S. Miller69cce1d2011-07-17 23:09:49 -07001938
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001939static void qeth_l3_fill_header(struct qeth_qdio_out_q *queue,
1940 struct qeth_hdr *hdr, struct sk_buff *skb,
1941 int ipv, int cast_type, unsigned int data_len)
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001942{
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001943 struct qeth_hdr_layer3 *l3_hdr = &hdr->hdr.l3;
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001944 struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001945 struct qeth_card *card = queue->card;
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001946
Julian Wiedmannf6c13142017-12-20 20:11:08 +01001947 hdr->hdr.l3.length = data_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001948
Julian Wiedmanne517b642018-09-17 17:36:02 +02001949 if (skb_is_gso(skb)) {
Julian Wiedmann0aef8392018-10-12 17:27:15 +02001950 hdr->hdr.l3.id = QETH_HEADER_TYPE_L3_TSO;
Julian Wiedmanne517b642018-09-17 17:36:02 +02001951 } else {
1952 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001953
1954 if (skb->protocol == htons(ETH_P_AF_IUCV)) {
1955 l3_hdr->flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
1956 l3_hdr->next_hop.ipv6_addr.s6_addr16[0] = htons(0xfe80);
1957 memcpy(&l3_hdr->next_hop.ipv6_addr.s6_addr32[2],
1958 iucv_trans_hdr(skb)->destUserID, 8);
1959 return;
1960 }
1961
Julian Wiedmanne517b642018-09-17 17:36:02 +02001962 if (skb->ip_summed == CHECKSUM_PARTIAL) {
1963 qeth_tx_csum(skb, &hdr->hdr.l3.ext_flags, ipv);
1964 /* some HW requires combined L3+L4 csum offload: */
1965 if (ipv == 4)
1966 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_HDR_REQ;
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001967 QETH_TXQ_STAT_INC(queue, skbs_csum);
Julian Wiedmanne517b642018-09-17 17:36:02 +02001968 }
1969 }
1970
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001971 if (ipv == 4 || IS_IQD(card)) {
1972 /* NETIF_F_HW_VLAN_CTAG_TX */
1973 if (skb_vlan_tag_present(skb)) {
1974 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_VLAN_FRAME;
1975 hdr->hdr.l3.vlan_id = skb_vlan_tag_get(skb);
1976 }
1977 } else if (veth->h_vlan_proto == htons(ETH_P_8021Q)) {
1978 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_INCLUDE_VLAN_TAG;
1979 hdr->hdr.l3.vlan_id = ntohs(veth->h_vlan_TCI);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001980 }
1981
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001982 /* OSA only: */
1983 if (!ipv) {
1984 hdr->hdr.l3.flags = QETH_HDR_PASSTHRU;
1985 if (ether_addr_equal_64bits(eth_hdr(skb)->h_dest,
1986 skb->dev->broadcast))
1987 hdr->hdr.l3.flags |= QETH_CAST_BROADCAST;
1988 else
1989 hdr->hdr.l3.flags |= (cast_type == RTN_MULTICAST) ?
1990 QETH_CAST_MULTICAST : QETH_CAST_UNICAST;
1991 return;
1992 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001993
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001994 hdr->hdr.l3.flags = qeth_l3_cast_type_to_flag(cast_type);
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001995 rcu_read_lock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001996 if (ipv == 4) {
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001997 struct rtable *rt = skb_rtable(skb);
David Miller87e75972012-02-01 10:49:17 +00001998
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001999 *((__be32 *) &hdr->hdr.l3.next_hop.ipv4.addr) = (rt) ?
2000 rt_nexthop(rt, ip_hdr(skb)->daddr) :
2001 ip_hdr(skb)->daddr;
2002 } else {
2003 /* IPv6 */
2004 const struct rt6_info *rt = skb_rt6_info(skb);
David Miller87e75972012-02-01 10:49:17 +00002005
Julian Wiedmannec2c6722017-08-07 13:28:39 +02002006 if (rt && !ipv6_addr_any(&rt->rt6i_gateway))
Julian Wiedmann5a541f62018-11-08 15:06:16 +01002007 l3_hdr->next_hop.ipv6_addr = rt->rt6i_gateway;
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002008 else
Julian Wiedmann5a541f62018-11-08 15:06:16 +01002009 l3_hdr->next_hop.ipv6_addr = ipv6_hdr(skb)->daddr;
David Miller87e75972012-02-01 10:49:17 +00002010
Julian Wiedmann910a0a82017-12-20 20:11:07 +01002011 hdr->hdr.l3.flags |= QETH_HDR_IPV6;
2012 if (card->info.type != QETH_CARD_TYPE_IQD)
2013 hdr->hdr.l3.flags |= QETH_HDR_PASSTHRU;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002014 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00002015 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002016}
2017
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02002018static void qeth_l3_fixup_headers(struct sk_buff *skb)
2019{
2020 struct iphdr *iph = ip_hdr(skb);
2021
2022 /* this is safe, IPv6 traffic takes a different path */
2023 if (skb->ip_summed == CHECKSUM_PARTIAL)
2024 iph->check = 0;
Julian Wiedmanne517b642018-09-17 17:36:02 +02002025 if (skb_is_gso(skb)) {
2026 iph->tot_len = 0;
2027 tcp_hdr(skb)->check = ~tcp_v4_check(0, iph->saddr,
2028 iph->daddr, 0);
2029 }
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02002030}
2031
Julian Wiedmann356156b2018-09-17 17:36:03 +02002032static int qeth_l3_xmit(struct qeth_card *card, struct sk_buff *skb,
2033 struct qeth_qdio_out_q *queue, int ipv, int cast_type)
Julian Wiedmanna647a022018-07-11 17:42:46 +02002034{
Julian Wiedmanna647a022018-07-11 17:42:46 +02002035 unsigned char eth_hdr[ETH_HLEN];
Julian Wiedmann81ec5432018-11-08 15:06:17 +01002036 unsigned int hw_hdr_len;
2037 int rc;
Julian Wiedmanne517b642018-09-17 17:36:02 +02002038
Julian Wiedmanna647a022018-07-11 17:42:46 +02002039 /* re-use the L2 header area for the HW header: */
Julian Wiedmann81ec5432018-11-08 15:06:17 +01002040 hw_hdr_len = skb_is_gso(skb) ? sizeof(struct qeth_hdr_tso) :
2041 sizeof(struct qeth_hdr);
Julian Wiedmanna647a022018-07-11 17:42:46 +02002042 rc = skb_cow_head(skb, hw_hdr_len - ETH_HLEN);
2043 if (rc)
2044 return rc;
2045 skb_copy_from_linear_data(skb, eth_hdr, ETH_HLEN);
2046 skb_pull(skb, ETH_HLEN);
Julian Wiedmanna647a022018-07-11 17:42:46 +02002047
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02002048 qeth_l3_fixup_headers(skb);
Julian Wiedmann81ec5432018-11-08 15:06:17 +01002049 rc = qeth_xmit(card, skb, queue, ipv, cast_type, qeth_l3_fill_header);
2050 if (rc == -EBUSY) {
2051 /* roll back to ETH header */
2052 skb_push(skb, ETH_HLEN);
2053 skb_copy_to_linear_data(skb, eth_hdr, ETH_HLEN);
Julian Wiedmanna647a022018-07-11 17:42:46 +02002054 }
2055 return rc;
2056}
2057
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002058static netdev_tx_t qeth_l3_hard_start_xmit(struct sk_buff *skb,
2059 struct net_device *dev)
2060{
2061 int cast_type = qeth_l3_get_cast_type(skb);
2062 struct qeth_card *card = dev->ml_priv;
2063 int ipv = qeth_get_ip_version(skb);
2064 struct qeth_qdio_out_q *queue;
2065 int tx_bytes = skb->len;
2066 int rc;
2067
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002068 queue = qeth_get_tx_queue(card, skb, ipv, cast_type);
2069
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002070 if (IS_IQD(card)) {
2071 if (card->options.sniffer)
2072 goto tx_drop;
2073 if ((card->options.cq != QETH_CQ_ENABLED && !ipv) ||
2074 (card->options.cq == QETH_CQ_ENABLED &&
2075 skb->protocol != htons(ETH_P_AF_IUCV)))
Frank Blaschka4a71df52008-02-15 09:19:42 +01002076 goto tx_drop;
2077 }
2078
Julian Wiedmann91cc98f2018-09-26 18:29:16 +02002079 if (card->state != CARD_STATE_UP) {
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002080 QETH_TXQ_STAT_INC(queue, tx_carrier_errors);
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002081 goto tx_drop;
2082 }
2083
2084 if (cast_type == RTN_BROADCAST && !card->info.broadcast_capable)
2085 goto tx_drop;
2086
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002087 netif_stop_queue(dev);
2088
Julian Wiedmann356156b2018-09-17 17:36:03 +02002089 if (ipv == 4 || IS_IQD(card))
Julian Wiedmanna647a022018-07-11 17:42:46 +02002090 rc = qeth_l3_xmit(card, skb, queue, ipv, cast_type);
Julian Wiedmannf13ade12018-09-17 17:35:56 +02002091 else
2092 rc = qeth_xmit(card, skb, queue, ipv, cast_type,
2093 qeth_l3_fill_header);
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002094
2095 if (!rc) {
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002096 QETH_TXQ_STAT_INC(queue, tx_packets);
2097 QETH_TXQ_STAT_ADD(queue, tx_bytes, tx_bytes);
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02002098 netif_wake_queue(dev);
2099 return NETDEV_TX_OK;
2100 } else if (rc == -EBUSY) {
2101 return NETDEV_TX_BUSY;
2102 } /* else fall through */
Frank Blaschka4a71df52008-02-15 09:19:42 +01002103
2104tx_drop:
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002105 QETH_TXQ_STAT_INC(queue, tx_dropped);
2106 QETH_TXQ_STAT_INC(queue, tx_errors);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002107 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +02002108 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002109 return NETDEV_TX_OK;
2110}
2111
Frank Blaschka4a71df52008-02-15 09:19:42 +01002112/*
2113 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
2114 * NOARP on the netdevice is no option because it also turns off neighbor
2115 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
2116 * arp resolution but we want the hard header (packet socket will work
2117 * e.g. tcpdump)
2118 */
2119static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
2120{
2121 n->nud_state = NUD_NOARP;
2122 memcpy(n->ha, "FAKELL", 6);
2123 n->output = n->ops->connected_output;
2124 return 0;
2125}
2126
2127static int
2128qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
2129{
2130 if (np->tbl->family == AF_INET)
2131 np->neigh_setup = qeth_l3_neigh_setup_noarp;
2132
2133 return 0;
2134}
2135
Julian Wiedmannf13ade12018-09-17 17:35:56 +02002136static netdev_features_t qeth_l3_osa_features_check(struct sk_buff *skb,
2137 struct net_device *dev,
2138 netdev_features_t features)
2139{
2140 if (qeth_get_ip_version(skb) != 4)
2141 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
2142 return qeth_features_check(skb, dev, features);
2143}
2144
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002145static const struct net_device_ops qeth_l3_netdev_ops = {
Julian Wiedmanne22355e2019-01-25 15:44:18 +01002146 .ndo_open = qeth_open,
2147 .ndo_stop = qeth_stop,
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002148 .ndo_get_stats64 = qeth_get_stats64,
Frank Blaschka8403b132009-01-08 10:50:55 -08002149 .ndo_start_xmit = qeth_l3_hard_start_xmit,
2150 .ndo_validate_addr = eth_validate_addr,
Julian Wiedmann00c163f2017-12-20 20:11:02 +01002151 .ndo_set_rx_mode = qeth_l3_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002152 .ndo_do_ioctl = qeth_do_ioctl,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002153 .ndo_fix_features = qeth_fix_features,
2154 .ndo_set_features = qeth_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08002155 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2156 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002157 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka8403b132009-01-08 10:50:55 -08002158};
2159
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002160static const struct net_device_ops qeth_l3_osa_netdev_ops = {
Julian Wiedmanne22355e2019-01-25 15:44:18 +01002161 .ndo_open = qeth_open,
2162 .ndo_stop = qeth_stop,
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002163 .ndo_get_stats64 = qeth_get_stats64,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002164 .ndo_start_xmit = qeth_l3_hard_start_xmit,
Julian Wiedmannf13ade12018-09-17 17:35:56 +02002165 .ndo_features_check = qeth_l3_osa_features_check,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002166 .ndo_validate_addr = eth_validate_addr,
Julian Wiedmann00c163f2017-12-20 20:11:02 +01002167 .ndo_set_rx_mode = qeth_l3_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002168 .ndo_do_ioctl = qeth_do_ioctl,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002169 .ndo_fix_features = qeth_fix_features,
2170 .ndo_set_features = qeth_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002171 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2172 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002173 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002174 .ndo_neigh_setup = qeth_l3_neigh_setup,
2175};
2176
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002177static int qeth_l3_setup_netdev(struct qeth_card *card, bool carrier_ok)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002178{
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002179 unsigned int headroom;
Thomas Richter1aec42b2015-01-21 13:39:10 +01002180 int rc;
2181
Ursula Braun5113fec2010-05-16 21:15:14 +00002182 if (card->info.type == QETH_CARD_TYPE_OSD ||
2183 card->info.type == QETH_CARD_TYPE_OSX) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002184 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
2185 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002186 pr_info("qeth_l3: ignoring TR device\n");
2187 return -ENODEV;
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002188 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002189
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002190 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Julian Wiedmann0f342942018-03-09 18:12:54 +01002191
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002192 /*IPv6 address autoconfiguration stuff*/
2193 qeth_l3_get_unique_id(card);
2194 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
2195 card->dev->dev_id = card->info.unique_id & 0xffff;
Julian Wiedmann0f342942018-03-09 18:12:54 +01002196
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002197 if (!card->info.guestlan) {
2198 card->dev->features |= NETIF_F_SG;
2199 card->dev->hw_features |= NETIF_F_TSO |
2200 NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
2201 card->dev->vlan_features |= NETIF_F_TSO |
2202 NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002203 }
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +02002204
2205 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) {
2206 card->dev->hw_features |= NETIF_F_IPV6_CSUM;
2207 card->dev->vlan_features |= NETIF_F_IPV6_CSUM;
2208 }
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002209 if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) {
2210 card->dev->hw_features |= NETIF_F_TSO6;
2211 card->dev->vlan_features |= NETIF_F_TSO6;
2212 }
2213
2214 /* allow for de-acceleration of NETIF_F_HW_VLAN_CTAG_TX: */
2215 if (card->dev->hw_features & NETIF_F_TSO6)
2216 headroom = sizeof(struct qeth_hdr_tso) + VLAN_HLEN;
2217 else if (card->dev->hw_features & NETIF_F_TSO)
2218 headroom = sizeof(struct qeth_hdr_tso);
2219 else
2220 headroom = sizeof(struct qeth_hdr) + VLAN_HLEN;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002221 } else if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002222 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002223 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002224 headroom = sizeof(struct qeth_hdr) - ETH_HLEN;
Julian Wiedmanna647a022018-07-11 17:42:46 +02002225
Thomas Richter1aec42b2015-01-21 13:39:10 +01002226 rc = qeth_l3_iqd_read_initial_mac(card);
2227 if (rc)
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002228 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002229 } else
2230 return -ENODEV;
2231
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002232 card->dev->needed_headroom = headroom;
Patrick McHardyf6469682013-04-19 02:04:27 +00002233 card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2234 NETIF_F_HW_VLAN_CTAG_RX |
2235 NETIF_F_HW_VLAN_CTAG_FILTER;
Julian Wiedmanna647a022018-07-11 17:42:46 +02002236
Eric Dumazet02875872014-10-05 18:38:35 -07002237 netif_keep_dst(card->dev);
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002238 if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6))
Julian Wiedmann371a1e72018-07-11 17:42:44 +02002239 netif_set_gso_max_size(card->dev,
2240 PAGE_SIZE * (QETH_MAX_BUFFER_ELEMENTS(card) - 1));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002241
Julian Wiedmannd73ef322017-04-11 16:11:11 +02002242 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002243 rc = register_netdev(card->dev);
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002244 if (!rc && carrier_ok)
2245 netif_carrier_on(card->dev);
2246
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002247out:
2248 if (rc)
2249 card->dev->netdev_ops = NULL;
2250 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002251}
2252
Ursula Braun79a04e42017-06-06 14:33:49 +02002253static const struct device_type qeth_l3_devtype = {
2254 .name = "qeth_layer3",
2255 .groups = qeth_l3_attr_groups,
2256};
2257
Frank Blaschka4a71df52008-02-15 09:19:42 +01002258static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
2259{
2260 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +02002261 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002262
Ursula Braun79a04e42017-06-06 14:33:49 +02002263 if (gdev->dev.type == &qeth_generic_devtype) {
2264 rc = qeth_l3_create_device_attributes(&gdev->dev);
2265 if (rc)
2266 return rc;
2267 }
Ursula Braunebccc7392017-05-10 19:07:54 +02002268 hash_init(card->ip_htable);
2269 hash_init(card->ip_mc_htable);
Frank Blaschka1da74b12011-05-12 18:45:02 +00002270 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002271 return 0;
2272}
2273
2274static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
2275{
2276 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
2277
Ursula Braun79a04e42017-06-06 14:33:49 +02002278 if (cgdev->dev.type == &qeth_generic_devtype)
2279 qeth_l3_remove_device_attributes(&cgdev->dev);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002280
Ursula Braunf2148562009-05-19 21:38:37 +00002281 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002282 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
2283
Ursula Braun70919e22011-02-26 22:41:36 -08002284 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002285 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002286
Julian Wiedmannc2780c12019-02-04 17:40:08 +01002287 cancel_work_sync(&card->close_dev_work);
Julian Wiedmann30356d02018-11-02 19:04:10 +01002288 if (qeth_netdev_is_registered(card->dev))
2289 unregister_netdev(card->dev);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002290 qeth_l3_clear_ip_htable(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002291 qeth_l3_clear_ipato_list(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002292}
2293
Julian Wiedmannd4560152019-02-28 18:59:39 +01002294static int qeth_l3_set_online(struct ccwgroup_device *gdev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002295{
2296 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002297 struct net_device *dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002298 int rc = 0;
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002299 bool carrier_ok;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002300
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002301 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002302 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002303 QETH_DBF_TEXT(SETUP, 2, "setonlin");
2304 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002305
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002306 rc = qeth_core_hardsetup_card(card, &carrier_ok);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002307 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01002308 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00002309 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002310 goto out_remove;
2311 }
2312
Frank Blaschka1da74b12011-05-12 18:45:02 +00002313 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
2314 if (card->info.hwtrap &&
2315 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
2316 card->info.hwtrap = 0;
2317 } else
2318 card->info.hwtrap = 0;
2319
Frank Blaschka4a71df52008-02-15 09:19:42 +01002320 card->state = CARD_STATE_HARDSETUP;
2321 qeth_print_status_message(card);
2322
2323 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002324 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002325
Frank Blaschka4a71df52008-02-15 09:19:42 +01002326 rc = qeth_l3_setadapter_parms(card);
2327 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01002328 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002329 if (!card->options.sniffer) {
2330 rc = qeth_l3_start_ipassists(card);
Stefan Raspl0f547612013-01-21 02:30:20 +00002331 if (rc) {
Ursula Braun76b11f82010-01-11 02:50:50 +00002332 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
Stefan Raspl0f547612013-01-21 02:30:20 +00002333 goto out_remove;
2334 }
Ursula Braun76b11f82010-01-11 02:50:50 +00002335 rc = qeth_l3_setrouting_v4(card);
2336 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01002337 QETH_DBF_TEXT_(SETUP, 2, "4err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002338 rc = qeth_l3_setrouting_v6(card);
2339 if (rc)
Thomas Richter1aec42b2015-01-21 13:39:10 +01002340 QETH_DBF_TEXT_(SETUP, 2, "5err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002341 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002342
2343 rc = qeth_init_qdio_queues(card);
2344 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002345 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00002346 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002347 goto out_remove;
2348 }
2349 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002350
2351 qeth_set_allowed_threads(card, 0xffffffff, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002352 qeth_l3_recover_ip(card);
Julian Wiedmannd025da92018-06-29 19:45:54 +02002353
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002354 if (!qeth_netdev_is_registered(dev)) {
2355 rc = qeth_l3_setup_netdev(card, carrier_ok);
2356 if (rc)
2357 goto out_remove;
2358 } else {
Ursula Braun4763b0a2011-12-19 22:56:32 +00002359 rtnl_lock();
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002360 if (carrier_ok)
2361 netif_carrier_on(dev);
2362 else
2363 netif_carrier_off(dev);
2364
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01002365 netif_device_attach(dev);
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002366 qeth_enable_hw_features(dev);
2367
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01002368 if (card->info.open_when_online) {
2369 card->info.open_when_online = 0;
Julian Wiedmannd4560152019-02-28 18:59:39 +01002370 dev_open(dev, NULL);
Julian Wiedmann9aa17df2018-07-11 17:42:40 +02002371 }
Ursula Braun4763b0a2011-12-19 22:56:32 +00002372 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002373 }
Stefan Raspl82f77cf2013-03-18 20:04:42 +00002374 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002375 /* let user_space know that device is online */
2376 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002377 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002378 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002379 return 0;
2380out_remove:
Julian Wiedmannd4560152019-02-28 18:59:39 +01002381 qeth_l3_stop_card(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002382 ccw_device_set_offline(CARD_DDEV(card));
2383 ccw_device_set_offline(CARD_WDEV(card));
2384 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01002385 qdio_free(CARD_DDEV(card));
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01002386 card->state = CARD_STATE_DOWN;
2387
Frank Blaschkac4949f02010-05-11 19:34:47 +00002388 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002389 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00002390 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002391}
2392
Frank Blaschka4a71df52008-02-15 09:19:42 +01002393static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
2394 int recovery_mode)
2395{
2396 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
2397 int rc = 0, rc2 = 0, rc3 = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002398
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002399 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002400 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002401 QETH_DBF_TEXT(SETUP, 3, "setoffl");
2402 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002403
Julian Wiedmannd7ef489f2019-02-28 18:59:37 +01002404 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
2405 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
2406 card->info.hwtrap = 1;
2407 }
2408
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01002409 rtnl_lock();
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01002410 card->info.open_when_online = card->dev->flags & IFF_UP;
Julian Wiedmannd4560152019-02-28 18:59:39 +01002411 dev_close(card->dev);
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01002412 netif_device_detach(card->dev);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002413 netif_carrier_off(card->dev);
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01002414 rtnl_unlock();
2415
Julian Wiedmannd4560152019-02-28 18:59:39 +01002416 qeth_l3_stop_card(card);
Julian Wiedmann464e86d2019-02-28 18:59:40 +01002417 if (card->options.cq == QETH_CQ_ENABLED) {
Einar Lueck72861ae2011-12-19 22:56:36 +00002418 rtnl_lock();
2419 call_netdevice_notifiers(NETDEV_REBOOT, card->dev);
2420 rtnl_unlock();
2421 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002422 rc = ccw_device_set_offline(CARD_DDEV(card));
2423 rc2 = ccw_device_set_offline(CARD_WDEV(card));
2424 rc3 = ccw_device_set_offline(CARD_RDEV(card));
2425 if (!rc)
2426 rc = (rc2) ? rc2 : rc3;
2427 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02002428 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01002429 qdio_free(CARD_DDEV(card));
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01002430
Frank Blaschka4a71df52008-02-15 09:19:42 +01002431 /* let user_space know that device is offline */
2432 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002433 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002434 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002435 return 0;
2436}
2437
2438static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
2439{
2440 return __qeth_l3_set_offline(cgdev, 0);
2441}
2442
2443static int qeth_l3_recover(void *ptr)
2444{
2445 struct qeth_card *card;
2446 int rc = 0;
2447
2448 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00002449 QETH_CARD_TEXT(card, 2, "recover1");
2450 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002451 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
2452 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00002453 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002454 dev_warn(&card->gdev->dev,
2455 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002456 __qeth_l3_set_offline(card->gdev, 1);
Julian Wiedmannd4560152019-02-28 18:59:39 +01002457 rc = qeth_l3_set_online(card->gdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002458 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002459 dev_info(&card->gdev->dev,
2460 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02002461 else {
Julian Wiedmannbf42d402019-02-28 18:59:41 +01002462 ccwgroup_set_offline(card->gdev);
Stefan Raspl0f547612013-01-21 02:30:20 +00002463 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00002464 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02002465 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002466 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
2467 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002468 return 0;
2469}
2470
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002471static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
2472{
2473 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
2474
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002475 qeth_set_allowed_threads(card, 0, 1);
2476 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
2477 if (gdev->state == CCWGROUP_OFFLINE)
2478 return 0;
Julian Wiedmann62ca98d2019-02-28 18:59:43 +01002479
2480 qeth_l3_set_offline(gdev);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002481 return 0;
2482}
2483
2484static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
2485{
2486 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Julian Wiedmannd4560152019-02-28 18:59:39 +01002487 int rc;
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002488
Julian Wiedmannd4560152019-02-28 18:59:39 +01002489 rc = qeth_l3_set_online(gdev);
Julian Wiedmann6585ac42018-09-26 18:29:12 +02002490
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002491 qeth_set_allowed_threads(card, 0xffffffff, 0);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002492 if (rc)
2493 dev_warn(&card->gdev->dev, "The qeth device driver "
2494 "failed to recover an error on the device\n");
2495 return rc;
2496}
2497
Eugene Crosserc044dc22014-01-29 09:23:48 +01002498/* Returns zero if the command is successfully "consumed" */
2499static int qeth_l3_control_event(struct qeth_card *card,
2500 struct qeth_ipa_cmd *cmd)
2501{
2502 return 1;
2503}
2504
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002505struct qeth_discipline qeth_l3_discipline = {
Ursula Braun79a04e42017-06-06 14:33:49 +02002506 .devtype = &qeth_l3_devtype,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02002507 .process_rx_buffer = qeth_l3_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002508 .recover = qeth_l3_recover,
2509 .setup = qeth_l3_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002510 .remove = qeth_l3_remove_device,
2511 .set_online = qeth_l3_set_online,
2512 .set_offline = qeth_l3_set_offline,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002513 .freeze = qeth_l3_pm_suspend,
2514 .thaw = qeth_l3_pm_resume,
2515 .restore = qeth_l3_pm_resume,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002516 .do_ioctl = qeth_l3_do_ioctl,
Eugene Crosserc044dc22014-01-29 09:23:48 +01002517 .control_event_handler = qeth_l3_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002518};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002519EXPORT_SYMBOL_GPL(qeth_l3_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002520
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002521static int qeth_l3_handle_ip_event(struct qeth_card *card,
2522 struct qeth_ipaddr *addr,
2523 unsigned long event)
2524{
2525 switch (event) {
2526 case NETDEV_UP:
2527 spin_lock_bh(&card->ip_lock);
2528 qeth_l3_add_ip(card, addr);
2529 spin_unlock_bh(&card->ip_lock);
2530 return NOTIFY_OK;
2531 case NETDEV_DOWN:
2532 spin_lock_bh(&card->ip_lock);
2533 qeth_l3_delete_ip(card, addr);
2534 spin_unlock_bh(&card->ip_lock);
2535 return NOTIFY_OK;
2536 default:
2537 return NOTIFY_DONE;
2538 }
2539}
2540
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002541static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2542{
2543 if (is_vlan_dev(dev))
2544 dev = vlan_dev_real_dev(dev);
2545 if (dev->netdev_ops == &qeth_l3_osa_netdev_ops ||
2546 dev->netdev_ops == &qeth_l3_netdev_ops)
2547 return (struct qeth_card *) dev->ml_priv;
2548 return NULL;
2549}
2550
Frank Blaschka4a71df52008-02-15 09:19:42 +01002551static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07002552 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002553{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002554
Frank Blaschka4a71df52008-02-15 09:19:42 +01002555 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002556 struct net_device *dev = ifa->ifa_dev->dev;
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002557 struct qeth_ipaddr addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002558 struct qeth_card *card;
2559
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09002560 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07002561 return NOTIFY_DONE;
2562
Frank Blaschka4a71df52008-02-15 09:19:42 +01002563 card = qeth_l3_get_card_from_dev(dev);
2564 if (!card)
2565 return NOTIFY_DONE;
frank.blaschka@de.ibm.com6d8823d2012-05-16 01:28:26 +00002566 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002567
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002568 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV4);
2569 addr.u.a4.addr = be32_to_cpu(ifa->ifa_address);
2570 addr.u.a4.mask = be32_to_cpu(ifa->ifa_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002571
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002572 return qeth_l3_handle_ip_event(card, &addr, event);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002573}
2574
2575static struct notifier_block qeth_l3_ip_notifier = {
2576 qeth_l3_ip_event,
2577 NULL,
2578};
2579
Frank Blaschka4a71df52008-02-15 09:19:42 +01002580static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07002581 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002582{
2583 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002584 struct net_device *dev = ifa->idev->dev;
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002585 struct qeth_ipaddr addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002586 struct qeth_card *card;
2587
Frank Blaschka4a71df52008-02-15 09:19:42 +01002588 card = qeth_l3_get_card_from_dev(dev);
2589 if (!card)
2590 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00002591 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002592 if (!qeth_is_supported(card, IPA_IPV6))
2593 return NOTIFY_DONE;
2594
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002595 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV6);
2596 addr.u.a6.addr = ifa->addr;
2597 addr.u.a6.pfxlen = ifa->prefix_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002598
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002599 return qeth_l3_handle_ip_event(card, &addr, event);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002600}
2601
2602static struct notifier_block qeth_l3_ip6_notifier = {
2603 qeth_l3_ip6_event,
2604 NULL,
2605};
Frank Blaschka4a71df52008-02-15 09:19:42 +01002606
2607static int qeth_l3_register_notifiers(void)
2608{
2609 int rc;
2610
Carsten Otte847a50f2010-06-21 22:57:05 +00002611 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002612 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
2613 if (rc)
2614 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002615 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
2616 if (rc) {
2617 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
2618 return rc;
2619 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002620 return 0;
2621}
2622
2623static void qeth_l3_unregister_notifiers(void)
2624{
Carsten Otte847a50f2010-06-21 22:57:05 +00002625 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Stefan Raspl18af5c12012-11-19 02:46:50 +00002626 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
Stefan Raspl18af5c12012-11-19 02:46:50 +00002627 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002628}
2629
2630static int __init qeth_l3_init(void)
2631{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002632 pr_info("register layer 3 discipline\n");
Julian Wiedmannc0622042017-12-20 20:10:58 +01002633 return qeth_l3_register_notifiers();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002634}
2635
2636static void __exit qeth_l3_exit(void)
2637{
2638 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002639 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002640}
2641
2642module_init(qeth_l3_init);
2643module_exit(qeth_l3_exit);
2644MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2645MODULE_DESCRIPTION("qeth layer 3 discipline");
2646MODULE_LICENSE("GPL");