blob: 04e301de376f0957796100e6fbadc8a022c7ba80 [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>
Frank Blaschkab3332932011-08-08 01:33:59 +000035#include <net/iucv/af_iucv.h>
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020036#include <linux/hashtable.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010037
Frank Blaschka4a71df52008-02-15 09:19:42 +010038#include "qeth_l3.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010039
Einar Lueckd0ddf30f2010-12-08 02:57:58 +000040
Frank Blaschka4a71df52008-02-15 09:19:42 +010041static int qeth_l3_set_offline(struct ccwgroup_device *);
Frank Blaschka4a71df52008-02-15 09:19:42 +010042static int qeth_l3_register_addr_entry(struct qeth_card *,
43 struct qeth_ipaddr *);
44static int qeth_l3_deregister_addr_entry(struct qeth_card *,
45 struct qeth_ipaddr *);
Frank Blaschka4a71df52008-02-15 09:19:42 +010046
Thomas Richter56530d62014-10-22 12:18:04 +020047static void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010048{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020049 sprintf(buf, "%pI4", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010050}
51
Thomas Richter56530d62014-10-22 12:18:04 +020052static void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010053{
Joe Perches963a9fd2010-09-07 21:14:40 +000054 sprintf(buf, "%pI6", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010055}
56
Frank Blaschka4a71df52008-02-15 09:19:42 +010057void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
58 char *buf)
59{
60 if (proto == QETH_PROT_IPV4)
61 qeth_l3_ipaddr4_to_string(addr, buf);
62 else if (proto == QETH_PROT_IPV6)
63 qeth_l3_ipaddr6_to_string(addr, buf);
64}
65
Julian Wiedmannc5c48c52018-02-27 18:58:16 +010066static struct qeth_ipaddr *qeth_l3_find_addr_by_ip(struct qeth_card *card,
67 struct qeth_ipaddr *query)
68{
Julian Wiedmann1b40d4b2019-10-31 13:42:20 +010069 u32 key = qeth_l3_ipaddr_hash(query);
Julian Wiedmannc5c48c52018-02-27 18:58:16 +010070 struct qeth_ipaddr *addr;
71
72 if (query->is_multicast) {
73 hash_for_each_possible(card->ip_mc_htable, addr, hnode, key)
74 if (qeth_l3_addr_match_ip(addr, query))
75 return addr;
76 } else {
77 hash_for_each_possible(card->ip_htable, addr, hnode, key)
78 if (qeth_l3_addr_match_ip(addr, query))
79 return addr;
80 }
81 return NULL;
82}
83
Frank Blaschka4a71df52008-02-15 09:19:42 +010084static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
85{
86 int i, j;
87 u8 octet;
88
89 for (i = 0; i < len; ++i) {
90 octet = addr[i];
91 for (j = 7; j >= 0; --j) {
92 bits[i*8 + j] = octet & 1;
93 octet >>= 1;
94 }
95 }
96}
97
Julian Wiedmann02f510f2017-12-13 18:56:32 +010098static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
99 struct qeth_ipaddr *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100100{
101 struct qeth_ipato_entry *ipatoe;
102 u8 addr_bits[128] = {0, };
103 u8 ipatoe_bits[128] = {0, };
104 int rc = 0;
105
106 if (!card->ipato.enabled)
Gustavo A. R. Silva1a363b02018-08-09 14:48:04 +0200107 return false;
Julian Wiedmannb22d73d62017-12-13 18:56:30 +0100108 if (addr->type != QETH_IP_TYPE_NORMAL)
Gustavo A. R. Silva1a363b02018-08-09 14:48:04 +0200109 return false;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100110
111 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
112 (addr->proto == QETH_PROT_IPV4)? 4:16);
113 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
114 if (addr->proto != ipatoe->proto)
115 continue;
116 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
117 (ipatoe->proto == QETH_PROT_IPV4) ?
118 4 : 16);
119 if (addr->proto == QETH_PROT_IPV4)
120 rc = !memcmp(addr_bits, ipatoe_bits,
121 min(32, ipatoe->mask_bits));
122 else
123 rc = !memcmp(addr_bits, ipatoe_bits,
124 min(128, ipatoe->mask_bits));
125 if (rc)
126 break;
127 }
128 /* invert? */
129 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
130 rc = !rc;
131 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
132 rc = !rc;
133
134 return rc;
135}
136
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100137static int qeth_l3_delete_ip(struct qeth_card *card,
138 struct qeth_ipaddr *tmp_addr)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200139{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100140 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200141 struct qeth_ipaddr *addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100142
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100143 if (tmp_addr->type == QETH_IP_TYPE_RXIP)
144 QETH_CARD_TEXT(card, 2, "delrxip");
145 else if (tmp_addr->type == QETH_IP_TYPE_VIPA)
146 QETH_CARD_TEXT(card, 2, "delvipa");
147 else
148 QETH_CARD_TEXT(card, 2, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100149
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200150 if (tmp_addr->proto == QETH_PROT_IPV4)
151 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100152 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200153 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
154 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100155 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200156
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100157 addr = qeth_l3_find_addr_by_ip(card, tmp_addr);
158 if (!addr || !qeth_l3_addr_match_all(addr, tmp_addr))
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200159 return -ENOENT;
160
161 addr->ref_counter--;
Julian Wiedmann4964c662018-02-27 18:58:15 +0100162 if (addr->type == QETH_IP_TYPE_NORMAL && addr->ref_counter > 0)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200163 return rc;
164 if (addr->in_progress)
165 return -EINPROGRESS;
166
Julian Wiedmann98d823a2018-02-27 18:58:13 +0100167 if (qeth_card_hw_is_reachable(card))
168 rc = qeth_l3_deregister_addr_entry(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200169
170 hash_del(&addr->hnode);
171 kfree(addr);
172
Frank Blaschka4a71df52008-02-15 09:19:42 +0100173 return rc;
174}
175
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100176static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100177{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100178 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200179 struct qeth_ipaddr *addr;
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100180 char buf[40];
Frank Blaschka4a71df52008-02-15 09:19:42 +0100181
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100182 if (tmp_addr->type == QETH_IP_TYPE_RXIP)
183 QETH_CARD_TEXT(card, 2, "addrxip");
184 else if (tmp_addr->type == QETH_IP_TYPE_VIPA)
185 QETH_CARD_TEXT(card, 2, "addvipa");
186 else
187 QETH_CARD_TEXT(card, 2, "addip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200188
189 if (tmp_addr->proto == QETH_PROT_IPV4)
190 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100191 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200192 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
193 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100194 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200195
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100196 addr = qeth_l3_find_addr_by_ip(card, tmp_addr);
197 if (addr) {
198 if (tmp_addr->type != QETH_IP_TYPE_NORMAL)
199 return -EADDRINUSE;
200 if (qeth_l3_addr_match_all(addr, tmp_addr)) {
201 addr->ref_counter++;
202 return 0;
203 }
204 qeth_l3_ipaddr_to_string(tmp_addr->proto, (u8 *)&tmp_addr->u,
205 buf);
206 dev_warn(&card->gdev->dev,
207 "Registering IP address %s failed\n", buf);
208 return -EADDRINUSE;
209 } else {
Julian Wiedmannb80c08a2019-11-14 11:19:23 +0100210 addr = kmemdup(tmp_addr, sizeof(*tmp_addr), GFP_KERNEL);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200211 if (!addr)
212 return -ENOMEM;
213
Julian Wiedmannb22d73d62017-12-13 18:56:30 +0100214 if (qeth_l3_is_addr_covered_by_ipato(card, addr)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200215 QETH_CARD_TEXT(card, 2, "tkovaddr");
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100216 addr->ipato = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200217 }
218 hash_add(card->ip_htable, &addr->hnode,
219 qeth_l3_ipaddr_hash(addr));
220
Ursula Brauna7531c12016-09-15 14:39:23 +0200221 if (!qeth_card_hw_is_reachable(card)) {
222 addr->disp_flag = QETH_DISP_ADDR_ADD;
223 return 0;
224 }
225
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200226 /* qeth_l3_register_addr_entry can go to sleep
227 * if we add a IPV4 addr. It is caused by the reason
228 * that SETIP ipa cmd starts ARP staff for IPV4 addr.
229 * Thus we should unlock spinlock, and make a protection
230 * using in_progress variable to indicate that there is
231 * an hardware operation with this IPV4 address
232 */
233 if (addr->proto == QETH_PROT_IPV4) {
234 addr->in_progress = 1;
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100235 mutex_unlock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200236 rc = qeth_l3_register_addr_entry(card, addr);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100237 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200238 addr->in_progress = 0;
239 } else
240 rc = qeth_l3_register_addr_entry(card, addr);
241
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100242 if (!rc || rc == -EADDRINUSE || rc == -ENETDOWN) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200243 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
244 if (addr->ref_counter < 1) {
Julian Wiedmann14d066c2018-02-27 18:58:14 +0100245 qeth_l3_deregister_addr_entry(card, addr);
246 hash_del(&addr->hnode);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200247 kfree(addr);
248 }
249 } else {
250 hash_del(&addr->hnode);
251 kfree(addr);
252 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200253 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100254 return rc;
255}
256
Julian Wiedmann05a17852019-03-28 16:39:21 +0100257static int qeth_l3_modify_ip(struct qeth_card *card, struct qeth_ipaddr *addr,
258 bool add)
259{
260 int rc;
261
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100262 mutex_lock(&card->ip_lock);
Julian Wiedmann05a17852019-03-28 16:39:21 +0100263 rc = add ? qeth_l3_add_ip(card, addr) : qeth_l3_delete_ip(card, addr);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100264 mutex_unlock(&card->ip_lock);
Julian Wiedmann05a17852019-03-28 16:39:21 +0100265
266 return rc;
267}
268
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100269static void qeth_l3_drain_rx_mode_cache(struct qeth_card *card)
270{
271 struct qeth_ipaddr *addr;
272 struct hlist_node *tmp;
273 int i;
274
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100275 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
276 hash_del(&addr->hnode);
277 kfree(addr);
278 }
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100279}
280
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200281static void qeth_l3_clear_ip_htable(struct qeth_card *card, int recover)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100282{
283 struct qeth_ipaddr *addr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200284 struct hlist_node *tmp;
285 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100286
Carsten Otte847a50f2010-06-21 22:57:05 +0000287 QETH_CARD_TEXT(card, 4, "clearip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200288
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100289 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200290
291 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
292 if (!recover) {
293 hash_del(&addr->hnode);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100294 kfree(addr);
295 continue;
296 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200297 addr->disp_flag = QETH_DISP_ADDR_ADD;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100298 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200299
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100300 mutex_unlock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100301}
Julian Wiedmannd0c74822019-03-28 16:39:19 +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
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100312 mutex_lock(&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;
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100318 mutex_unlock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200319 rc = qeth_l3_register_addr_entry(card, addr);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100320 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200321 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
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100336 mutex_unlock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100337}
338
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100339static int qeth_l3_setdelip_cb(struct qeth_card *card, struct qeth_reply *reply,
340 unsigned long data)
341{
342 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
343
344 switch (cmd->hdr.return_code) {
345 case IPA_RC_SUCCESS:
346 return 0;
347 case IPA_RC_DUPLICATE_IP_ADDRESS:
348 return -EADDRINUSE;
349 case IPA_RC_MC_ADDR_NOT_FOUND:
350 return -ENOENT;
351 case IPA_RC_LAN_OFFLINE:
352 return -ENETDOWN;
353 default:
354 return -EIO;
355 }
356}
357
Frank Blaschka4a71df52008-02-15 09:19:42 +0100358static int qeth_l3_send_setdelmc(struct qeth_card *card,
359 struct qeth_ipaddr *addr, int ipacmd)
360{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100361 struct qeth_cmd_buffer *iob;
362 struct qeth_ipa_cmd *cmd;
363
Carsten Otte847a50f2010-06-21 22:57:05 +0000364 QETH_CARD_TEXT(card, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100365
Julian Wiedmanna59d1212019-06-27 17:01:22 +0200366 iob = qeth_ipa_alloc_cmd(card, ipacmd, addr->proto,
367 IPA_DATA_SIZEOF(setdelipm));
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 Wiedmann8bf70b62019-10-31 13:42:21 +0100371 if (addr->proto == QETH_PROT_IPV6) {
372 cmd->data.setdelipm.ip = addr->u.a6.addr;
373 ipv6_eth_mc_map(&addr->u.a6.addr, cmd->data.setdelipm.mac);
374 } else {
375 cmd->data.setdelipm.ip.s6_addr32[3] = addr->u.a4.addr;
376 ip_eth_mc_map(addr->u.a4.addr, cmd->data.setdelipm.mac);
377 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100378
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100379 return qeth_send_ipa_cmd(card, iob, qeth_l3_setdelip_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100380}
381
382static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
383{
384 int i, j;
385 for (i = 0; i < 16; i++) {
386 j = (len) - (i * 8);
387 if (j >= 8)
388 netmask[i] = 0xff;
389 else if (j > 0)
390 netmask[i] = (u8)(0xFF00 >> j);
391 else
392 netmask[i] = 0;
393 }
394}
395
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100396static u32 qeth_l3_get_setdelip_flags(struct qeth_ipaddr *addr, bool set)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100397{
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100398 switch (addr->type) {
399 case QETH_IP_TYPE_RXIP:
400 return (set) ? QETH_IPA_SETIP_TAKEOVER_FLAG : 0;
401 case QETH_IP_TYPE_VIPA:
402 return (set) ? QETH_IPA_SETIP_VIPA_FLAG :
403 QETH_IPA_DELIP_VIPA_FLAG;
404 default:
405 return (set && addr->ipato) ? QETH_IPA_SETIP_TAKEOVER_FLAG : 0;
406 }
407}
408
409static int qeth_l3_send_setdelip(struct qeth_card *card,
410 struct qeth_ipaddr *addr,
411 enum qeth_ipa_cmds ipacmd)
412{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100413 struct qeth_cmd_buffer *iob;
414 struct qeth_ipa_cmd *cmd;
415 __u8 netmask[16];
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100416 u32 flags;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100417
Carsten Otte847a50f2010-06-21 22:57:05 +0000418 QETH_CARD_TEXT(card, 4, "setdelip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100419
Julian Wiedmanna59d1212019-06-27 17:01:22 +0200420 iob = qeth_ipa_alloc_cmd(card, ipacmd, addr->proto,
421 IPA_DATA_SIZEOF(setdelip6));
Thomas Richter1aec42b2015-01-21 13:39:10 +0100422 if (!iob)
423 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100424 cmd = __ipa_cmd(iob);
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100425
426 flags = qeth_l3_get_setdelip_flags(addr, ipacmd == IPA_CMD_SETIP);
427 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
428
Frank Blaschka4a71df52008-02-15 09:19:42 +0100429 if (addr->proto == QETH_PROT_IPV6) {
430 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
431 sizeof(struct in6_addr));
432 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
433 memcpy(cmd->data.setdelip6.mask, netmask,
434 sizeof(struct in6_addr));
435 cmd->data.setdelip6.flags = flags;
436 } else {
437 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
438 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
439 cmd->data.setdelip4.flags = flags;
440 }
441
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100442 return qeth_send_ipa_cmd(card, iob, qeth_l3_setdelip_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100443}
444
445static int qeth_l3_send_setrouting(struct qeth_card *card,
446 enum qeth_routing_types type, enum qeth_prot_versions prot)
447{
448 int rc;
449 struct qeth_ipa_cmd *cmd;
450 struct qeth_cmd_buffer *iob;
451
Carsten Otte847a50f2010-06-21 22:57:05 +0000452 QETH_CARD_TEXT(card, 4, "setroutg");
Julian Wiedmanna59d1212019-06-27 17:01:22 +0200453 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_SETRTG, prot,
454 IPA_DATA_SIZEOF(setrtg));
Thomas Richter1aec42b2015-01-21 13:39:10 +0100455 if (!iob)
456 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100457 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100458 cmd->data.setrtg.type = (type);
459 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
460
461 return rc;
462}
463
Stefan Raspl82e2e782013-03-18 20:04:43 +0000464static int qeth_l3_correct_routing_type(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100465 enum qeth_routing_types *type, enum qeth_prot_versions prot)
466{
Julian Wiedmann379ac992019-04-25 18:25:57 +0200467 if (IS_IQD(card)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100468 switch (*type) {
469 case NO_ROUTER:
470 case PRIMARY_CONNECTOR:
471 case SECONDARY_CONNECTOR:
472 case MULTICAST_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000473 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100474 default:
475 goto out_inval;
476 }
477 } else {
478 switch (*type) {
479 case NO_ROUTER:
480 case PRIMARY_ROUTER:
481 case SECONDARY_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000482 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100483 case MULTICAST_ROUTER:
484 if (qeth_is_ipafunc_supported(card, prot,
485 IPA_OSA_MC_ROUTER))
Stefan Raspl82e2e782013-03-18 20:04:43 +0000486 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100487 default:
488 goto out_inval;
489 }
490 }
491out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100492 *type = NO_ROUTER;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000493 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100494}
495
496int qeth_l3_setrouting_v4(struct qeth_card *card)
497{
498 int rc;
499
Carsten Otte847a50f2010-06-21 22:57:05 +0000500 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100501
Stefan Raspl82e2e782013-03-18 20:04:43 +0000502 rc = qeth_l3_correct_routing_type(card, &card->options.route4.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100503 QETH_PROT_IPV4);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000504 if (rc)
505 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100506
507 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
508 QETH_PROT_IPV4);
509 if (rc) {
510 card->options.route4.type = NO_ROUTER;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100511 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n",
512 rc, CARD_DEVID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100513 }
514 return rc;
515}
516
517int qeth_l3_setrouting_v6(struct qeth_card *card)
518{
519 int rc = 0;
520
Carsten Otte847a50f2010-06-21 22:57:05 +0000521 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100522
523 if (!qeth_is_supported(card, IPA_IPV6))
524 return 0;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000525 rc = qeth_l3_correct_routing_type(card, &card->options.route6.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100526 QETH_PROT_IPV6);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000527 if (rc)
528 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100529
530 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
531 QETH_PROT_IPV6);
532 if (rc) {
533 card->options.route6.type = NO_ROUTER;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100534 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n",
535 rc, CARD_DEVID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100536 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100537 return rc;
538}
539
540/*
541 * IP address takeover related functions
542 */
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100543
544/**
545 * qeth_l3_update_ipato() - Update 'takeover' property, for all NORMAL IPs.
546 *
547 * Caller must hold ip_lock.
548 */
549void qeth_l3_update_ipato(struct qeth_card *card)
550{
551 struct qeth_ipaddr *addr;
552 unsigned int i;
553
554 hash_for_each(card->ip_htable, i, addr, hnode) {
555 if (addr->type != QETH_IP_TYPE_NORMAL)
556 continue;
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100557 addr->ipato = qeth_l3_is_addr_covered_by_ipato(card, addr);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100558 }
559}
560
Frank Blaschka4a71df52008-02-15 09:19:42 +0100561static void qeth_l3_clear_ipato_list(struct qeth_card *card)
562{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100563 struct qeth_ipato_entry *ipatoe, *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100564
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100565 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200566
Frank Blaschka4a71df52008-02-15 09:19:42 +0100567 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
568 list_del(&ipatoe->entry);
569 kfree(ipatoe);
570 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200571
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100572 qeth_l3_update_ipato(card);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100573 mutex_unlock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100574}
575
576int qeth_l3_add_ipato_entry(struct qeth_card *card,
577 struct qeth_ipato_entry *new)
578{
579 struct qeth_ipato_entry *ipatoe;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100580 int rc = 0;
581
Carsten Otte847a50f2010-06-21 22:57:05 +0000582 QETH_CARD_TEXT(card, 2, "addipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200583
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100584 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200585
Frank Blaschka4a71df52008-02-15 09:19:42 +0100586 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
587 if (ipatoe->proto != new->proto)
588 continue;
589 if (!memcmp(ipatoe->addr, new->addr,
590 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
591 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100592 rc = -EEXIST;
593 break;
594 }
595 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200596
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100597 if (!rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100598 list_add_tail(&new->entry, &card->ipato.entries);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100599 qeth_l3_update_ipato(card);
600 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100601
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100602 mutex_unlock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200603
Frank Blaschka4a71df52008-02-15 09:19:42 +0100604 return rc;
605}
606
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100607int qeth_l3_del_ipato_entry(struct qeth_card *card,
608 enum qeth_prot_versions proto, u8 *addr,
609 int mask_bits)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100610{
611 struct qeth_ipato_entry *ipatoe, *tmp;
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100612 int rc = -ENOENT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100613
Carsten Otte847a50f2010-06-21 22:57:05 +0000614 QETH_CARD_TEXT(card, 2, "delipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200615
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100616 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200617
Frank Blaschka4a71df52008-02-15 09:19:42 +0100618 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
619 if (ipatoe->proto != proto)
620 continue;
621 if (!memcmp(ipatoe->addr, addr,
622 (proto == QETH_PROT_IPV4)? 4:16) &&
623 (ipatoe->mask_bits == mask_bits)) {
624 list_del(&ipatoe->entry);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100625 qeth_l3_update_ipato(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100626 kfree(ipatoe);
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100627 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100628 }
629 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200630
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100631 mutex_unlock(&card->ip_lock);
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100632 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100633}
634
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100635int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip,
636 enum qeth_ip_types type,
637 enum qeth_prot_versions proto)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100638{
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100639 struct qeth_ipaddr addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100640
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100641 qeth_l3_init_ipaddr(&addr, type, proto);
642 if (proto == QETH_PROT_IPV4)
643 memcpy(&addr.u.a4.addr, ip, 4);
644 else
645 memcpy(&addr.u.a6.addr, ip, 16);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200646
Julian Wiedmann05a17852019-03-28 16:39:21 +0100647 return qeth_l3_modify_ip(card, &addr, add);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100648}
649
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100650int qeth_l3_modify_hsuid(struct qeth_card *card, bool add)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100651{
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100652 struct qeth_ipaddr addr;
Julian Wiedmann05a17852019-03-28 16:39:21 +0100653 unsigned int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100654
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100655 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV6);
656 addr.u.a6.addr.s6_addr[0] = 0xfe;
657 addr.u.a6.addr.s6_addr[1] = 0x80;
658 for (i = 0; i < 8; i++)
659 addr.u.a6.addr.s6_addr[8+i] = card->options.hsuid[i];
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200660
Julian Wiedmann05a17852019-03-28 16:39:21 +0100661 return qeth_l3_modify_ip(card, &addr, add);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100662}
663
664static int qeth_l3_register_addr_entry(struct qeth_card *card,
665 struct qeth_ipaddr *addr)
666{
667 char buf[50];
668 int rc = 0;
669 int cnt = 3;
670
Julian Wiedmannbd74a7f2018-11-02 19:04:09 +0100671 if (card->options.sniffer)
672 return 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200673
Frank Blaschka4a71df52008-02-15 09:19:42 +0100674 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000675 QETH_CARD_TEXT(card, 2, "setaddr4");
676 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100677 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000678 QETH_CARD_TEXT(card, 2, "setaddr6");
679 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
680 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100681 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000682 QETH_CARD_TEXT(card, 2, "setaddr?");
683 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100684 }
685 do {
686 if (addr->is_multicast)
687 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
688 else
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100689 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100690 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000691 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100692 } while ((--cnt > 0) && rc);
693 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000694 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100695 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100696 dev_warn(&card->gdev->dev,
697 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100698 }
699 return rc;
700}
701
702static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
703 struct qeth_ipaddr *addr)
704{
705 int rc = 0;
706
Julian Wiedmannbd74a7f2018-11-02 19:04:09 +0100707 if (card->options.sniffer)
708 return 0;
709
Frank Blaschka4a71df52008-02-15 09:19:42 +0100710 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000711 QETH_CARD_TEXT(card, 2, "deladdr4");
712 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100713 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000714 QETH_CARD_TEXT(card, 2, "deladdr6");
715 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
716 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100717 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000718 QETH_CARD_TEXT(card, 2, "deladdr?");
719 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100720 }
721 if (addr->is_multicast)
722 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
723 else
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100724 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200725 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000726 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100727
728 return rc;
729}
730
Frank Blaschka4a71df52008-02-15 09:19:42 +0100731static int qeth_l3_setadapter_parms(struct qeth_card *card)
732{
Julian Wiedmann699d3fe2017-08-15 17:02:41 +0200733 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100734
Julian Wiedmann57a688aa2019-06-11 18:37:55 +0200735 QETH_CARD_TEXT(card, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100736
Frank Blaschka4a71df52008-02-15 09:19:42 +0100737 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
738 rc = qeth_setadpparms_change_macaddr(card);
739 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100740 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -0800741 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100742 }
743
Frank Blaschka4a71df52008-02-15 09:19:42 +0100744 return rc;
745}
746
Frank Blaschka4a71df52008-02-15 09:19:42 +0100747static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
748{
749 int rc;
750
Carsten Otte847a50f2010-06-21 22:57:05 +0000751 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100752
753 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100754 dev_info(&card->gdev->dev,
755 "ARP processing not supported on %s!\n",
756 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100757 return 0;
758 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200759 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200760 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100761 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100762 dev_warn(&card->gdev->dev,
763 "Starting ARP processing support for %s failed\n",
764 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100765 }
766 return rc;
767}
768
Frank Blaschka4a71df52008-02-15 09:19:42 +0100769static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
770{
771 int rc;
772
Carsten Otte847a50f2010-06-21 22:57:05 +0000773 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100774
Frank Blaschka4a71df52008-02-15 09:19:42 +0100775 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100776 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800777 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100778 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100779 return -EOPNOTSUPP;
780 }
781
Thomas Richter4d7def22015-09-18 16:06:51 +0200782 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200783 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100784 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100785 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800786 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100787 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100788 return rc;
789}
790
791static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
792{
793 int rc = 0;
794
Carsten Otte847a50f2010-06-21 22:57:05 +0000795 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100796
797 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100798 dev_info(&card->gdev->dev,
799 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100800 return -EOPNOTSUPP;
801 }
802
Thomas Richter4d7def22015-09-18 16:06:51 +0200803 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200804 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100805 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100806 dev_warn(&card->gdev->dev,
807 "Starting VLAN support for %s failed\n",
808 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100809 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100810 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100811 }
812 return rc;
813}
814
815static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
816{
817 int rc;
818
Carsten Otte847a50f2010-06-21 22:57:05 +0000819 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100820
821 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100822 dev_info(&card->gdev->dev,
823 "Multicast not supported on %s\n",
824 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100825 return -EOPNOTSUPP;
826 }
827
Thomas Richter4d7def22015-09-18 16:06:51 +0200828 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200829 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100830 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100831 dev_warn(&card->gdev->dev,
832 "Starting multicast support for %s failed\n",
833 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100834 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100835 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100836 card->dev->flags |= IFF_MULTICAST;
837 }
838 return rc;
839}
840
Frank Blaschka4a71df52008-02-15 09:19:42 +0100841static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
842{
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200843 u32 ipv6_data = 3;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100844 int rc;
845
Carsten Otte847a50f2010-06-21 22:57:05 +0000846 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100847
Julian Wiedmann379ac992019-04-25 18:25:57 +0200848 if (IS_IQD(card))
Julian Wiedmann23274592017-06-06 14:33:44 +0200849 goto out;
850
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200851 rc = qeth_send_simple_setassparms(card, IPA_IPV6, IPA_CMD_ASS_START,
852 &ipv6_data);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100853 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100854 dev_err(&card->gdev->dev,
855 "Activating IPv6 support for %s failed\n",
856 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100857 return rc;
858 }
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200859 rc = qeth_send_simple_setassparms_v6(card, IPA_IPV6, IPA_CMD_ASS_START,
860 NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100861 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100862 dev_err(&card->gdev->dev,
863 "Activating IPv6 support for %s failed\n",
864 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100865 return rc;
866 }
Kittipon Meesompopa8155b02018-04-26 09:42:21 +0200867 rc = qeth_send_simple_setassparms_v6(card, IPA_PASSTHRU,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200868 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100869 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100870 dev_warn(&card->gdev->dev,
871 "Enabling the passthrough mode for %s failed\n",
872 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100873 return rc;
874 }
875out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100876 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100877 return 0;
878}
Frank Blaschka4a71df52008-02-15 09:19:42 +0100879
880static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
881{
Carsten Otte847a50f2010-06-21 22:57:05 +0000882 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100883
884 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100885 dev_info(&card->gdev->dev,
886 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100887 return 0;
888 }
Julian Wiedmannc0622042017-12-20 20:10:58 +0100889 return qeth_l3_softsetup_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100890}
891
892static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
893{
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200894 u32 filter_data = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100895 int rc;
896
Carsten Otte847a50f2010-06-21 22:57:05 +0000897 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100898 card->info.broadcast_capable = 0;
899 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100900 dev_info(&card->gdev->dev,
901 "Broadcast not supported on %s\n",
902 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100903 rc = -EOPNOTSUPP;
904 goto out;
905 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200906 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200907 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100908 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100909 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
910 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100911 goto out;
912 }
913
Thomas Richter4d7def22015-09-18 16:06:51 +0200914 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200915 IPA_CMD_ASS_CONFIGURE, &filter_data);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100916 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100917 dev_warn(&card->gdev->dev,
918 "Setting up broadcast filtering for %s failed\n",
919 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100920 goto out;
921 }
922 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100923 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Thomas Richter4d7def22015-09-18 16:06:51 +0200924 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200925 IPA_CMD_ASS_ENABLE, &filter_data);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100926 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100927 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
928 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100929 goto out;
930 }
931 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
932out:
933 if (card->info.broadcast_capable)
934 card->dev->flags |= IFF_BROADCAST;
935 else
936 card->dev->flags &= ~IFF_BROADCAST;
937 return rc;
938}
939
Frank Blaschka4a71df52008-02-15 09:19:42 +0100940static int qeth_l3_start_ipassists(struct qeth_card *card)
941{
Carsten Otte847a50f2010-06-21 22:57:05 +0000942 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +0000943
Frank Blaschka4a71df52008-02-15 09:19:42 +0100944 qeth_l3_start_ipa_arp_processing(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +0100945 qeth_l3_start_ipa_source_mac(card); /* go on*/
946 qeth_l3_start_ipa_vlan(card); /* go on*/
947 qeth_l3_start_ipa_multicast(card); /* go on*/
948 qeth_l3_start_ipa_ipv6(card); /* go on*/
949 qeth_l3_start_ipa_broadcast(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +0100950 return 0;
951}
952
Frank Blaschka4a71df52008-02-15 09:19:42 +0100953static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
954 struct qeth_reply *reply, unsigned long data)
955{
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100956 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100957
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100958 if (cmd->hdr.return_code)
959 return -EIO;
960
961 ether_addr_copy(card->dev->dev_addr,
962 cmd->data.create_destroy_addr.unique_id);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100963 return 0;
964}
965
966static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
967{
968 int rc = 0;
969 struct qeth_cmd_buffer *iob;
970 struct qeth_ipa_cmd *cmd;
971
Julian Wiedmann57a688aa2019-06-11 18:37:55 +0200972 QETH_CARD_TEXT(card, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100973
Julian Wiedmanna59d1212019-06-27 17:01:22 +0200974 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_CREATE_ADDR, QETH_PROT_IPV6,
975 IPA_DATA_SIZEOF(create_destroy_addr));
Thomas Richter1aec42b2015-01-21 13:39:10 +0100976 if (!iob)
977 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100978 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100979 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
980 card->info.unique_id;
981
982 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
983 NULL);
984 return rc;
985}
986
987static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
988 struct qeth_reply *reply, unsigned long data)
989{
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100990 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100991
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100992 if (cmd->hdr.return_code == 0) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100993 card->info.unique_id = *((__u16 *)
994 &cmd->data.create_destroy_addr.unique_id[6]);
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100995 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100996 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100997
998 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
999 UNIQUE_ID_NOT_BY_CARD;
1000 dev_warn(&card->gdev->dev, "The network adapter failed to generate a unique ID\n");
1001 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001002}
1003
1004static int qeth_l3_get_unique_id(struct qeth_card *card)
1005{
1006 int rc = 0;
1007 struct qeth_cmd_buffer *iob;
1008 struct qeth_ipa_cmd *cmd;
1009
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02001010 QETH_CARD_TEXT(card, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001011
1012 if (!qeth_is_supported(card, IPA_IPV6)) {
1013 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
1014 UNIQUE_ID_NOT_BY_CARD;
1015 return 0;
1016 }
1017
Julian Wiedmanna59d1212019-06-27 17:01:22 +02001018 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_CREATE_ADDR, QETH_PROT_IPV6,
1019 IPA_DATA_SIZEOF(create_destroy_addr));
Thomas Richter1aec42b2015-01-21 13:39:10 +01001020 if (!iob)
1021 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001022 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001023 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
1024 card->info.unique_id;
1025
1026 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
1027 return rc;
1028}
1029
Ursula Braun76b11f82010-01-11 02:50:50 +00001030static int
1031qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
1032 unsigned long data)
1033{
1034 struct qeth_ipa_cmd *cmd;
1035 __u16 rc;
1036
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02001037 QETH_CARD_TEXT(card, 2, "diastrcb");
Ursula Braun76b11f82010-01-11 02:50:50 +00001038
1039 cmd = (struct qeth_ipa_cmd *)data;
1040 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001041 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001042 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001043 switch (cmd->data.diagass.action) {
1044 case QETH_DIAGS_CMD_TRACE_QUERY:
1045 break;
1046 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001047 switch (rc) {
1048 case 0:
1049 case IPA_RC_INVALID_SUBCMD:
1050 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1051 dev_info(&card->gdev->dev, "The HiperSockets network "
1052 "traffic analyzer is deactivated\n");
1053 break;
1054 default:
1055 break;
1056 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001057 break;
1058 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001059 switch (rc) {
1060 case 0:
1061 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1062 dev_info(&card->gdev->dev, "The HiperSockets network "
1063 "traffic analyzer is activated\n");
1064 break;
1065 case IPA_RC_HARDWARE_AUTH_ERROR:
1066 dev_warn(&card->gdev->dev, "The device is not "
1067 "authorized to run as a HiperSockets network "
1068 "traffic analyzer\n");
1069 break;
1070 case IPA_RC_TRACE_ALREADY_ACTIVE:
1071 dev_warn(&card->gdev->dev, "A HiperSockets "
1072 "network traffic analyzer is already "
1073 "active in the HiperSockets LAN\n");
1074 break;
1075 default:
1076 break;
1077 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001078 break;
1079 default:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001080 QETH_DBF_MESSAGE(2, "Unknown sniffer action (%#06x) on device %x\n",
1081 cmd->data.diagass.action, CARD_DEVID(card));
Ursula Braun76b11f82010-01-11 02:50:50 +00001082 }
1083
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001084 return rc ? -EIO : 0;
Ursula Braun76b11f82010-01-11 02:50:50 +00001085}
1086
1087static int
1088qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1089{
1090 struct qeth_cmd_buffer *iob;
1091 struct qeth_ipa_cmd *cmd;
1092
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02001093 QETH_CARD_TEXT(card, 2, "diagtrac");
Ursula Braun76b11f82010-01-11 02:50:50 +00001094
Julian Wiedmann5cfbe102019-06-27 17:01:25 +02001095 iob = qeth_get_diag_cmd(card, QETH_DIAGS_CMD_TRACE, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001096 if (!iob)
1097 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001098 cmd = __ipa_cmd(iob);
Ursula Braun76b11f82010-01-11 02:50:50 +00001099 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1100 cmd->data.diagass.action = diags_cmd;
1101 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1102}
1103
Julian Wiedmann8659c182019-11-14 11:19:22 +01001104static int qeth_l3_add_mcast_rtnl(struct net_device *dev, int vid, void *arg)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001105{
Julian Wiedmann8659c182019-11-14 11:19:22 +01001106 struct qeth_card *card = arg;
Julian Wiedmann611abe52019-11-14 11:19:21 +01001107 struct inet6_dev *in6_dev;
1108 struct in_device *in4_dev;
1109 struct qeth_ipaddr *ipm;
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001110 struct qeth_ipaddr tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001111 struct ip_mc_list *im4;
Julian Wiedmann611abe52019-11-14 11:19:21 +01001112 struct ifmcaddr6 *im6;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001113
Carsten Otte847a50f2010-06-21 22:57:05 +00001114 QETH_CARD_TEXT(card, 4, "addmc");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001115
Julian Wiedmann611abe52019-11-14 11:19:21 +01001116 if (!dev || !(dev->flags & IFF_UP))
1117 goto out;
1118
Julian Wiedmann8659c182019-11-14 11:19:22 +01001119 in4_dev = __in_dev_get_rtnl(dev);
Julian Wiedmann611abe52019-11-14 11:19:21 +01001120 if (!in4_dev)
1121 goto walk_ipv6;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001122
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001123 qeth_l3_init_ipaddr(&tmp, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV4);
1124 tmp.disp_flag = QETH_DISP_ADDR_ADD;
1125 tmp.is_multicast = 1;
1126
Julian Wiedmann8659c182019-11-14 11:19:22 +01001127 for (im4 = rtnl_dereference(in4_dev->mc_list); im4 != NULL;
1128 im4 = rtnl_dereference(im4->next_rcu)) {
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001129 tmp.u.a4.addr = im4->multiaddr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001130
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001131 ipm = qeth_l3_find_addr_by_ip(card, &tmp);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001132 if (ipm) {
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001133 /* for mcast, by-IP match means full match */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001134 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001135 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001136 }
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001137
1138 ipm = kmemdup(&tmp, sizeof(tmp), GFP_KERNEL);
1139 if (!ipm)
1140 continue;
1141
1142 hash_add(card->ip_mc_htable, &ipm->hnode,
1143 qeth_l3_ipaddr_hash(ipm));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001144 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001145
Julian Wiedmann611abe52019-11-14 11:19:21 +01001146walk_ipv6:
1147 if (!qeth_is_supported(card, IPA_IPV6))
1148 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001149
Julian Wiedmann611abe52019-11-14 11:19:21 +01001150 in6_dev = __in6_dev_get(dev);
1151 if (!in6_dev)
1152 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001153
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001154 qeth_l3_init_ipaddr(&tmp, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV6);
1155 tmp.disp_flag = QETH_DISP_ADDR_ADD;
1156 tmp.is_multicast = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001157
Julian Wiedmannddf28102019-11-14 11:19:19 +01001158 read_lock_bh(&in6_dev->lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001159 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001160 tmp.u.a6.addr = im6->mca_addr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001161
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001162 ipm = qeth_l3_find_addr_by_ip(card, &tmp);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001163 if (ipm) {
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001164 /* for mcast, by-IP match means full match */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001165 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1166 continue;
1167 }
1168
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001169 ipm = kmemdup(&tmp, sizeof(tmp), GFP_ATOMIC);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001170 if (!ipm)
1171 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001172
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001173 hash_add(card->ip_mc_htable,
1174 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1175
Frank Blaschka4a71df52008-02-15 09:19:42 +01001176 }
Julian Wiedmannddf28102019-11-14 11:19:19 +01001177 read_unlock_bh(&in6_dev->lock);
1178
Julian Wiedmann611abe52019-11-14 11:19:21 +01001179out:
Julian Wiedmann8659c182019-11-14 11:19:22 +01001180 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001181}
1182
Patrick McHardy80d5c362013-04-19 02:04:28 +00001183static int qeth_l3_vlan_rx_add_vid(struct net_device *dev,
1184 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001185{
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001186 struct qeth_card *card = dev->ml_priv;
1187
Julian Wiedmann8659c182019-11-14 11:19:22 +01001188 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Jiri Pirko8e586132011-12-08 19:52:37 -05001189 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001190}
1191
Patrick McHardy80d5c362013-04-19 02:04:28 +00001192static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev,
1193 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001194{
Heiko Carstens509e2562008-07-26 02:24:10 -07001195 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001196
Carsten Otte847a50f2010-06-21 22:57:05 +00001197 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Jiri Pirko8e586132011-12-08 19:52:37 -05001198 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001199}
1200
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001201static void qeth_l3_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
1202 struct qeth_hdr *hdr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001203{
Julian Wiedmannc097cc92019-06-27 17:01:31 +02001204 struct af_iucv_trans_hdr *iucv = (struct af_iucv_trans_hdr *) skb->data;
1205 struct net_device *dev = skb->dev;
1206
1207 if (IS_IQD(card) && iucv->magic == ETH_P_AF_IUCV) {
1208 dev_hard_header(skb, dev, ETH_P_AF_IUCV, dev->dev_addr,
1209 "FAKELL", skb->len);
1210 return;
1211 }
1212
Frank Blaschka4a71df52008-02-15 09:19:42 +01001213 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001214 u16 prot = (hdr->hdr.l3.flags & QETH_HDR_IPV6) ? ETH_P_IPV6 :
1215 ETH_P_IP;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001216 unsigned char tg_addr[ETH_ALEN];
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001217
1218 skb_reset_network_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001219 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
1220 case QETH_CAST_MULTICAST:
Julian Wiedmannc0622042017-12-20 20:10:58 +01001221 if (prot == ETH_P_IP)
Julian Wiedmann8d9183d2017-12-20 20:10:57 +01001222 ip_eth_mc_map(ip_hdr(skb)->daddr, tg_addr);
Julian Wiedmannc0622042017-12-20 20:10:58 +01001223 else
1224 ipv6_eth_mc_map(&ipv6_hdr(skb)->daddr, tg_addr);
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001225 QETH_CARD_STAT_INC(card, rx_multicast);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001226 break;
1227 case QETH_CAST_BROADCAST:
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001228 ether_addr_copy(tg_addr, card->dev->broadcast);
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001229 QETH_CARD_STAT_INC(card, rx_multicast);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001230 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001231 default:
Ursula Braun76b11f82010-01-11 02:50:50 +00001232 if (card->options.sniffer)
1233 skb->pkt_type = PACKET_OTHERHOST;
Julian Wiedmann99f0b852017-12-20 20:11:01 +01001234 ether_addr_copy(tg_addr, card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001235 }
Julian Wiedmann04f67392018-03-09 18:12:58 +01001236
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001237 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
1238 card->dev->header_ops->create(skb, card->dev, prot,
Julian Wiedmanna8433832017-12-20 20:11:06 +01001239 tg_addr, &hdr->hdr.l3.next_hop.rx.src_mac,
Julian Wiedmannf0ea8bf2018-03-09 18:12:56 +01001240 skb->len);
Ursula Braunfe94e2e2009-01-04 17:34:52 -08001241 else
1242 card->dev->header_ops->create(skb, card->dev, prot,
Julian Wiedmannf0ea8bf2018-03-09 18:12:56 +01001243 tg_addr, "FAKELL", skb->len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001244 }
1245
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001246 /* copy VLAN tag from hdr into skb */
1247 if (!card->options.sniffer &&
1248 (hdr->hdr.l3.ext_flags & (QETH_HDR_EXT_VLAN_FRAME |
1249 QETH_HDR_EXT_INCLUDE_VLAN_TAG))) {
1250 u16 tag = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
1251 hdr->hdr.l3.vlan_id :
Julian Wiedmanna8433832017-12-20 20:11:06 +01001252 hdr->hdr.l3.next_hop.rx.vlan_id;
Julian Wiedmannd7aa9d02017-09-18 21:18:21 +02001253 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001254 }
1255
Julian Wiedmann6195b932018-04-26 09:42:17 +02001256 qeth_rx_csum(card, skb, hdr->hdr.l3.ext_flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001257}
1258
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001259static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1260 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001261{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001262 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001263 struct sk_buff *skb;
1264 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001265
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001266 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +00001267 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001268 while (budget) {
1269 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +00001270 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001271 &card->rx.b_element, &card->rx.e_offset, &hdr);
1272 if (!skb) {
1273 *done = 1;
1274 break;
1275 }
Julian Wiedmann7d4faee2019-11-14 11:19:16 +01001276
1277 if (hdr->hdr.l3.id == QETH_HEADER_TYPE_LAYER3)
Julian Wiedmannc097cc92019-06-27 17:01:31 +02001278 qeth_l3_rebuild_skb(card, skb, hdr);
Julian Wiedmann7d4faee2019-11-14 11:19:16 +01001279
1280 skb->protocol = eth_type_trans(skb, skb->dev);
1281 QETH_CARD_STAT_INC(card, rx_packets);
1282 QETH_CARD_STAT_ADD(card, rx_bytes, skb->len);
1283
1284 napi_gro_receive(&card->napi, skb);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001285 work_done++;
1286 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001287 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001288 return work_done;
1289}
1290
Julian Wiedmannd4560152019-02-28 18:59:39 +01001291static void qeth_l3_stop_card(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001292{
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02001293 QETH_CARD_TEXT(card, 2, "stopcard");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001294
1295 qeth_set_allowed_threads(card, 0, 1);
Julian Wiedmann0f7aedbd2019-02-28 18:59:44 +01001296
Julian Wiedmannd0c74822019-03-28 16:39:19 +01001297 cancel_work_sync(&card->rx_mode_work);
1298 qeth_l3_drain_rx_mode_cache(card);
1299
Ursula Braun76b11f82010-01-11 02:50:50 +00001300 if (card->options.sniffer &&
1301 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
1302 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Julian Wiedmann0f7aedbd2019-02-28 18:59:44 +01001303
Frank Blaschka4a71df52008-02-15 09:19:42 +01001304 if (card->state == CARD_STATE_SOFTSETUP) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001305 qeth_l3_clear_ip_htable(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001306 qeth_clear_ipacmd_list(card);
1307 card->state = CARD_STATE_HARDSETUP;
1308 }
1309 if (card->state == CARD_STATE_HARDSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001310 qeth_qdio_clear_card(card, 0);
Julian Wiedmann41c47da2019-04-17 18:17:28 +02001311 qeth_drain_output_queues(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001312 qeth_clear_working_pool_list(card);
1313 card->state = CARD_STATE_DOWN;
1314 }
Julian Wiedmannc0a2e4d2019-02-04 17:40:09 +01001315
1316 flush_workqueue(card->event_wq);
Julian Wiedmann0f399302019-12-18 16:32:27 +01001317 card->info.promisc_mode = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001318}
1319
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001320static void qeth_l3_set_promisc_mode(struct qeth_card *card)
Ursula Braun76b11f82010-01-11 02:50:50 +00001321{
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001322 bool enable = card->dev->flags & IFF_PROMISC;
Ursula Braun76b11f82010-01-11 02:50:50 +00001323
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001324 if (card->info.promisc_mode == enable)
Ursula Braun76b11f82010-01-11 02:50:50 +00001325 return;
1326
Julian Wiedmann379ac992019-04-25 18:25:57 +02001327 if (IS_VM_NIC(card)) { /* Guestlan trace */
Ursula Braun76b11f82010-01-11 02:50:50 +00001328 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001329 qeth_setadp_promisc_mode(card, enable);
Ursula Braun76b11f82010-01-11 02:50:50 +00001330 } else if (card->options.sniffer && /* HiperSockets trace */
1331 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001332 if (enable) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001333 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001334 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
1335 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00001336 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001337 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
1338 }
1339 }
1340}
1341
Julian Wiedmannd0c74822019-03-28 16:39:19 +01001342static void qeth_l3_rx_mode_work(struct work_struct *work)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001343{
Julian Wiedmannd0c74822019-03-28 16:39:19 +01001344 struct qeth_card *card = container_of(work, struct qeth_card,
1345 rx_mode_work);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001346 struct qeth_ipaddr *addr;
1347 struct hlist_node *tmp;
1348 int i, rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001349
Carsten Otte847a50f2010-06-21 22:57:05 +00001350 QETH_CARD_TEXT(card, 3, "setmulti");
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01001351
Ursula Braun76b11f82010-01-11 02:50:50 +00001352 if (!card->options.sniffer) {
Julian Wiedmann8659c182019-11-14 11:19:22 +01001353 rtnl_lock();
1354 qeth_l3_add_mcast_rtnl(card->dev, 0, card);
Julian Wiedmann611abe52019-11-14 11:19:21 +01001355 if (qeth_is_supported(card, IPA_FULL_VLAN))
Julian Wiedmann8659c182019-11-14 11:19:22 +01001356 vlan_for_each(card->dev, qeth_l3_add_mcast_rtnl, card);
1357 rtnl_unlock();
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001358
1359 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1360 switch (addr->disp_flag) {
1361 case QETH_DISP_ADDR_DELETE:
1362 rc = qeth_l3_deregister_addr_entry(card, addr);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001363 if (!rc || rc == -ENOENT) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001364 hash_del(&addr->hnode);
1365 kfree(addr);
1366 }
1367 break;
1368 case QETH_DISP_ADDR_ADD:
1369 rc = qeth_l3_register_addr_entry(card, addr);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001370 if (rc && rc != -ENETDOWN) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001371 hash_del(&addr->hnode);
1372 kfree(addr);
1373 break;
1374 }
1375 addr->ref_counter = 1;
1376 /* fall through */
1377 default:
1378 /* for next call to set_rx_mode(): */
1379 addr->disp_flag = QETH_DISP_ADDR_DELETE;
1380 }
1381 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001382 }
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001383
1384 qeth_l3_set_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001385}
1386
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001387static int qeth_l3_arp_makerc(u16 rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001388{
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001389 switch (rc) {
1390 case IPA_RC_SUCCESS:
1391 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001392 case QETH_IPA_ARP_RC_NOTSUPP:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001393 case QETH_IPA_ARP_RC_Q_NOTSUPP:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001394 return -EOPNOTSUPP;
1395 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
1396 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001397 case QETH_IPA_ARP_RC_Q_NO_DATA:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001398 return -ENOENT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001399 default:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001400 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001401 }
1402}
1403
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001404static int qeth_l3_arp_cmd_cb(struct qeth_card *card, struct qeth_reply *reply,
1405 unsigned long data)
1406{
1407 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1408
1409 qeth_setassparms_cb(card, reply, data);
1410 return qeth_l3_arp_makerc(cmd->hdr.return_code);
1411}
1412
Frank Blaschka4a71df52008-02-15 09:19:42 +01001413static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
1414{
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001415 struct qeth_cmd_buffer *iob;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001416 int rc;
1417
Carsten Otte847a50f2010-06-21 22:57:05 +00001418 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001419
1420 /*
1421 * currently GuestLAN only supports the ARP assist function
1422 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
1423 * thus we say EOPNOTSUPP for this ARP function
1424 */
Julian Wiedmann379ac992019-04-25 18:25:57 +02001425 if (IS_VM_NIC(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001426 return -EOPNOTSUPP;
1427 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001428 return -EOPNOTSUPP;
1429 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001430
1431 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
Julian Wiedmannb9150462019-06-27 17:01:24 +02001432 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
1433 SETASS_DATA_SIZEOF(flags_32bit),
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001434 QETH_PROT_IPV4);
1435 if (!iob)
1436 return -ENOMEM;
1437
1438 __ipa_cmd(iob)->data.setassparms.data.flags_32bit = (u32) no_entries;
1439 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001440 if (rc)
1441 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on device %x: %#x\n",
1442 CARD_DEVID(card), rc);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001443 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001444}
1445
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001446static __u32 get_arp_entry_size(struct qeth_card *card,
1447 struct qeth_arp_query_data *qdata,
1448 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001449{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001450 __u32 rc;
1451 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001452
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001453 is_hsi = qdata->reply_bits == 5;
1454 if (type->ip == QETHARP_IP_ADDR_V4) {
1455 QETH_CARD_TEXT(card, 4, "arpev4");
1456 if (strip_entries) {
1457 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
1458 sizeof(struct qeth_arp_qi_entry7_short);
1459 } else {
1460 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
1461 sizeof(struct qeth_arp_qi_entry7);
1462 }
1463 } else if (type->ip == QETHARP_IP_ADDR_V6) {
1464 QETH_CARD_TEXT(card, 4, "arpev6");
1465 if (strip_entries) {
1466 rc = is_hsi ?
1467 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
1468 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
1469 } else {
1470 rc = is_hsi ?
1471 sizeof(struct qeth_arp_qi_entry5_ipv6) :
1472 sizeof(struct qeth_arp_qi_entry7_ipv6);
1473 }
1474 } else {
1475 QETH_CARD_TEXT(card, 4, "arpinv");
1476 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001477 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001478
1479 return rc;
1480}
1481
1482static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
1483{
1484 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
1485 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001486}
1487
1488static int qeth_l3_arp_query_cb(struct qeth_card *card,
1489 struct qeth_reply *reply, unsigned long data)
1490{
1491 struct qeth_ipa_cmd *cmd;
1492 struct qeth_arp_query_data *qdata;
1493 struct qeth_arp_query_info *qinfo;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001494 int e;
1495 int entrybytes_done;
1496 int stripped_bytes;
1497 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001498
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001499 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001500
1501 qinfo = (struct qeth_arp_query_info *) reply->param;
1502 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001503 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001504 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001505 QETH_CARD_TEXT(card, 4, "arpcberr");
1506 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001507 return qeth_l3_arp_makerc(cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001508 }
1509 if (cmd->data.setassparms.hdr.return_code) {
1510 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001511 QETH_CARD_TEXT(card, 4, "setaperr");
1512 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001513 return qeth_l3_arp_makerc(cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001514 }
1515 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00001516 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001517
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001518 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
1519 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
1520 entrybytes_done = 0;
1521 for (e = 0; e < qdata->no_entries; ++e) {
1522 char *cur_entry;
1523 __u32 esize;
1524 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001525
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001526 cur_entry = &qdata->data + entrybytes_done;
1527 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
1528 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
1529 QETH_CARD_TEXT(card, 4, "pmis");
1530 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
1531 break;
1532 }
1533 esize = get_arp_entry_size(card, qdata, etype,
1534 do_strip_entries);
1535 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
1536 if (!esize)
1537 break;
1538
1539 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001540 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOSPC);
1541 memset(qinfo->udata, 0, 4);
1542 return -ENOSPC;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001543 }
1544
1545 memcpy(qinfo->udata + qinfo->udata_offset,
1546 &qdata->data + entrybytes_done + stripped_bytes,
1547 esize);
1548 entrybytes_done += esize + stripped_bytes;
1549 qinfo->udata_offset += esize;
1550 ++qinfo->no_entries;
1551 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001552 /* check if all replies received ... */
1553 if (cmd->data.setassparms.hdr.seq_no <
1554 cmd->data.setassparms.hdr.number_of_replies)
1555 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001556 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001557 memcpy(qinfo->udata, &qinfo->no_entries, 4);
1558 /* keep STRIP_ENTRIES flag so the user program can distinguish
1559 * stripped entries from normal ones */
1560 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
1561 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
1562 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001563 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001564 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001565}
1566
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001567static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
1568 enum qeth_prot_versions prot,
1569 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001570{
1571 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001572 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001573 int rc;
1574
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001575 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
1576
Thomas Richterb475e312015-12-11 12:27:54 +01001577 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
1578 IPA_CMD_ASS_ARP_QUERY_INFO,
Julian Wiedmannb9150462019-06-27 17:01:24 +02001579 SETASS_DATA_SIZEOF(query_arp), prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001580 if (!iob)
1581 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001582 cmd = __ipa_cmd(iob);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001583 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
Julian Wiedmann84dbea42019-02-12 18:33:16 +01001584 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_query_cb, qinfo);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001585 if (rc)
1586 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on device %x: %#x\n",
1587 CARD_DEVID(card), rc);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001588 return rc;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001589}
1590
1591static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
1592{
1593 struct qeth_arp_query_info qinfo = {0, };
1594 int rc;
1595
Carsten Otte847a50f2010-06-21 22:57:05 +00001596 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001597
1598 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
1599 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001600 QETH_CARD_TEXT(card, 3, "arpqnsup");
1601 rc = -EOPNOTSUPP;
1602 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001603 }
1604 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001605 if (copy_from_user(&qinfo, udata, 6)) {
1606 rc = -EFAULT;
1607 goto out;
1608 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001609 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001610 if (!qinfo.udata) {
1611 rc = -ENOMEM;
1612 goto out;
1613 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001614 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001615 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001616 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001617 if (copy_to_user(udata, qinfo.udata, 4))
1618 rc = -EFAULT;
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001619 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001620 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001621 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
1622 /* fails in case of GuestLAN QDIO mode */
1623 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6, &qinfo);
1624 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001625 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
1626 QETH_CARD_TEXT(card, 4, "qactf");
1627 rc = -EFAULT;
1628 goto free_and_out;
1629 }
1630 QETH_CARD_TEXT(card, 4, "qacts");
1631
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001632free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001633 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001634out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001635 return rc;
1636}
1637
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001638static int qeth_l3_arp_modify_entry(struct qeth_card *card,
1639 struct qeth_arp_cache_entry *entry,
1640 enum qeth_arp_process_subcmds arp_cmd)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001641{
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001642 struct qeth_arp_cache_entry *cmd_entry;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001643 struct qeth_cmd_buffer *iob;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001644 int rc;
1645
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001646 if (arp_cmd == IPA_CMD_ASS_ARP_ADD_ENTRY)
1647 QETH_CARD_TEXT(card, 3, "arpadd");
1648 else
1649 QETH_CARD_TEXT(card, 3, "arpdel");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001650
1651 /*
1652 * currently GuestLAN only supports the ARP assist function
1653 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
1654 * thus we say EOPNOTSUPP for this ARP function
1655 */
Julian Wiedmann379ac992019-04-25 18:25:57 +02001656 if (IS_VM_NIC(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001657 return -EOPNOTSUPP;
1658 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001659 return -EOPNOTSUPP;
1660 }
1661
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001662 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, arp_cmd,
Julian Wiedmannb9150462019-06-27 17:01:24 +02001663 SETASS_DATA_SIZEOF(arp_entry),
1664 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001665 if (!iob)
1666 return -ENOMEM;
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001667
1668 cmd_entry = &__ipa_cmd(iob)->data.setassparms.data.arp_entry;
1669 ether_addr_copy(cmd_entry->macaddr, entry->macaddr);
1670 memcpy(cmd_entry->ipaddr, entry->ipaddr, 4);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001671 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001672 if (rc)
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001673 QETH_DBF_MESSAGE(2, "Could not modify (cmd: %#x) ARP entry on device %x: %#x\n",
1674 arp_cmd, CARD_DEVID(card), rc);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001675 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001676}
1677
1678static int qeth_l3_arp_flush_cache(struct qeth_card *card)
1679{
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001680 struct qeth_cmd_buffer *iob;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001681 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001682
Carsten Otte847a50f2010-06-21 22:57:05 +00001683 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001684
1685 /*
1686 * currently GuestLAN only supports the ARP assist function
1687 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
1688 * thus we say EOPNOTSUPP for this ARP function
1689 */
Julian Wiedmann379ac992019-04-25 18:25:57 +02001690 if (IS_VM_NIC(card) || IS_IQD(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001691 return -EOPNOTSUPP;
1692 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001693 return -EOPNOTSUPP;
1694 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001695
1696 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
1697 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0,
1698 QETH_PROT_IPV4);
1699 if (!iob)
1700 return -ENOMEM;
1701
1702 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001703 if (rc)
1704 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on device %x: %#x\n",
1705 CARD_DEVID(card), rc);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001706 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001707}
1708
1709static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1710{
Heiko Carstens509e2562008-07-26 02:24:10 -07001711 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001712 struct qeth_arp_cache_entry arp_entry;
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001713 enum qeth_arp_process_subcmds arp_cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001714 int rc = 0;
1715
Frank Blaschka4a71df52008-02-15 09:19:42 +01001716 switch (cmd) {
1717 case SIOC_QETH_ARP_SET_NO_ENTRIES:
1718 if (!capable(CAP_NET_ADMIN)) {
1719 rc = -EPERM;
1720 break;
1721 }
1722 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
1723 break;
1724 case SIOC_QETH_ARP_QUERY_INFO:
1725 if (!capable(CAP_NET_ADMIN)) {
1726 rc = -EPERM;
1727 break;
1728 }
1729 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
1730 break;
1731 case SIOC_QETH_ARP_ADD_ENTRY:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001732 case SIOC_QETH_ARP_REMOVE_ENTRY:
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001733 if (!capable(CAP_NET_ADMIN))
1734 return -EPERM;
1735 if (copy_from_user(&arp_entry, rq->ifr_data, sizeof(arp_entry)))
1736 return -EFAULT;
1737
1738 arp_cmd = (cmd == SIOC_QETH_ARP_ADD_ENTRY) ?
1739 IPA_CMD_ASS_ARP_ADD_ENTRY :
1740 IPA_CMD_ASS_ARP_REMOVE_ENTRY;
1741 return qeth_l3_arp_modify_entry(card, &arp_entry, arp_cmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001742 case SIOC_QETH_ARP_FLUSH_CACHE:
1743 if (!capable(CAP_NET_ADMIN)) {
1744 rc = -EPERM;
1745 break;
1746 }
1747 rc = qeth_l3_arp_flush_cache(card);
1748 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001749 default:
1750 rc = -EOPNOTSUPP;
1751 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001752 return rc;
1753}
1754
Julian Wiedmann980f4562019-06-27 17:01:32 +02001755static int qeth_l3_get_cast_type_rcu(struct sk_buff *skb, struct dst_entry *dst,
1756 int ipv)
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001757{
David S. Miller69cce1d2011-07-17 23:09:49 -07001758 struct neighbour *n = NULL;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001759
Julian Wiedmann980f4562019-06-27 17:01:32 +02001760 if (dst)
1761 n = dst_neigh_lookup_skb(dst, skb);
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02001762
David S. Miller69cce1d2011-07-17 23:09:49 -07001763 if (n) {
Julian Wiedmann1f979122017-12-20 20:11:04 +01001764 int cast_type = n->type;
1765
David S. Miller24db1ba2012-07-02 22:02:33 -07001766 neigh_release(n);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001767 if ((cast_type == RTN_BROADCAST) ||
1768 (cast_type == RTN_MULTICAST) ||
1769 (cast_type == RTN_ANYCAST))
1770 return cast_type;
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +02001771 return RTN_UNICAST;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001772 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001773
Julian Wiedmann1f979122017-12-20 20:11:04 +01001774 /* no neighbour (eg AF_PACKET), fall back to target's IP address ... */
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02001775 switch (ipv) {
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001776 case 4:
Julian Wiedmann72c87972019-06-05 13:48:48 +02001777 if (ipv4_is_lbcast(ip_hdr(skb)->daddr))
1778 return RTN_BROADCAST;
Julian Wiedmann1f979122017-12-20 20:11:04 +01001779 return ipv4_is_multicast(ip_hdr(skb)->daddr) ?
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +02001780 RTN_MULTICAST : RTN_UNICAST;
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001781 case 6:
1782 return ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr) ?
1783 RTN_MULTICAST : RTN_UNICAST;
1784 default:
1785 /* ... and MAC address */
Julian Wiedmann58aa2492019-04-25 18:26:00 +02001786 return qeth_get_ether_cast_type(skb);
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001787 }
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001788}
1789
Julian Wiedmann980f4562019-06-27 17:01:32 +02001790static int qeth_l3_get_cast_type(struct sk_buff *skb)
1791{
1792 int ipv = qeth_get_ip_version(skb);
1793 struct dst_entry *dst;
1794 int cast_type;
1795
1796 rcu_read_lock();
1797 dst = qeth_dst_check_rcu(skb, ipv);
1798 cast_type = qeth_l3_get_cast_type_rcu(skb, dst, ipv);
1799 rcu_read_unlock();
1800
1801 return cast_type;
1802}
1803
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001804static u8 qeth_l3_cast_type_to_flag(int cast_type)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001805{
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001806 if (cast_type == RTN_MULTICAST)
1807 return QETH_CAST_MULTICAST;
1808 if (cast_type == RTN_ANYCAST)
1809 return QETH_CAST_ANYCAST;
1810 if (cast_type == RTN_BROADCAST)
1811 return QETH_CAST_BROADCAST;
1812 return QETH_CAST_UNICAST;
1813}
David S. Miller69cce1d2011-07-17 23:09:49 -07001814
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001815static void qeth_l3_fill_header(struct qeth_qdio_out_q *queue,
1816 struct qeth_hdr *hdr, struct sk_buff *skb,
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001817 int ipv, unsigned int data_len)
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001818{
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001819 struct qeth_hdr_layer3 *l3_hdr = &hdr->hdr.l3;
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001820 struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001821 struct qeth_card *card = queue->card;
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02001822 struct dst_entry *dst;
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001823 int cast_type;
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001824
Julian Wiedmannf6c13142017-12-20 20:11:08 +01001825 hdr->hdr.l3.length = data_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001826
Julian Wiedmanne517b642018-09-17 17:36:02 +02001827 if (skb_is_gso(skb)) {
Julian Wiedmann0aef8392018-10-12 17:27:15 +02001828 hdr->hdr.l3.id = QETH_HEADER_TYPE_L3_TSO;
Julian Wiedmanne517b642018-09-17 17:36:02 +02001829 } else {
1830 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001831
1832 if (skb->protocol == htons(ETH_P_AF_IUCV)) {
1833 l3_hdr->flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
1834 l3_hdr->next_hop.ipv6_addr.s6_addr16[0] = htons(0xfe80);
1835 memcpy(&l3_hdr->next_hop.ipv6_addr.s6_addr32[2],
1836 iucv_trans_hdr(skb)->destUserID, 8);
1837 return;
1838 }
1839
Julian Wiedmanne517b642018-09-17 17:36:02 +02001840 if (skb->ip_summed == CHECKSUM_PARTIAL) {
1841 qeth_tx_csum(skb, &hdr->hdr.l3.ext_flags, ipv);
1842 /* some HW requires combined L3+L4 csum offload: */
1843 if (ipv == 4)
1844 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_HDR_REQ;
Julian Wiedmanne517b642018-09-17 17:36:02 +02001845 }
1846 }
1847
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001848 if (ipv == 4 || IS_IQD(card)) {
1849 /* NETIF_F_HW_VLAN_CTAG_TX */
1850 if (skb_vlan_tag_present(skb)) {
1851 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_VLAN_FRAME;
1852 hdr->hdr.l3.vlan_id = skb_vlan_tag_get(skb);
1853 }
1854 } else if (veth->h_vlan_proto == htons(ETH_P_8021Q)) {
1855 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_INCLUDE_VLAN_TAG;
1856 hdr->hdr.l3.vlan_id = ntohs(veth->h_vlan_TCI);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001857 }
1858
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001859 rcu_read_lock();
Julian Wiedmann980f4562019-06-27 17:01:32 +02001860 dst = qeth_dst_check_rcu(skb, ipv);
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02001861
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001862 if (IS_IQD(card) && skb_get_queue_mapping(skb) != QETH_IQD_MCAST_TXQ)
1863 cast_type = RTN_UNICAST;
1864 else
1865 cast_type = qeth_l3_get_cast_type_rcu(skb, dst, ipv);
1866 l3_hdr->flags |= qeth_l3_cast_type_to_flag(cast_type);
1867
Frank Blaschka4a71df52008-02-15 09:19:42 +01001868 if (ipv == 4) {
Julian Wiedmann980f4562019-06-27 17:01:32 +02001869 struct rtable *rt = (struct rtable *) dst;
David Miller87e75972012-02-01 10:49:17 +00001870
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001871 *((__be32 *) &hdr->hdr.l3.next_hop.ipv4.addr) = (rt) ?
1872 rt_nexthop(rt, ip_hdr(skb)->daddr) :
1873 ip_hdr(skb)->daddr;
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001874 } else if (ipv == 6) {
Julian Wiedmann980f4562019-06-27 17:01:32 +02001875 struct rt6_info *rt = (struct rt6_info *) dst;
David Miller87e75972012-02-01 10:49:17 +00001876
Julian Wiedmannec2c6722017-08-07 13:28:39 +02001877 if (rt && !ipv6_addr_any(&rt->rt6i_gateway))
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001878 l3_hdr->next_hop.ipv6_addr = rt->rt6i_gateway;
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001879 else
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001880 l3_hdr->next_hop.ipv6_addr = ipv6_hdr(skb)->daddr;
David Miller87e75972012-02-01 10:49:17 +00001881
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001882 hdr->hdr.l3.flags |= QETH_HDR_IPV6;
Julian Wiedmann379ac992019-04-25 18:25:57 +02001883 if (!IS_IQD(card))
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001884 hdr->hdr.l3.flags |= QETH_HDR_PASSTHRU;
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001885 } else {
1886 /* OSA only: */
1887 l3_hdr->flags |= QETH_HDR_PASSTHRU;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001888 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001889 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001890}
1891
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02001892static void qeth_l3_fixup_headers(struct sk_buff *skb)
1893{
1894 struct iphdr *iph = ip_hdr(skb);
1895
1896 /* this is safe, IPv6 traffic takes a different path */
1897 if (skb->ip_summed == CHECKSUM_PARTIAL)
1898 iph->check = 0;
Julian Wiedmanne517b642018-09-17 17:36:02 +02001899 if (skb_is_gso(skb)) {
1900 iph->tot_len = 0;
1901 tcp_hdr(skb)->check = ~tcp_v4_check(0, iph->saddr,
1902 iph->daddr, 0);
1903 }
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02001904}
1905
Julian Wiedmann356156b2018-09-17 17:36:03 +02001906static int qeth_l3_xmit(struct qeth_card *card, struct sk_buff *skb,
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001907 struct qeth_qdio_out_q *queue, int ipv)
Julian Wiedmanna647a022018-07-11 17:42:46 +02001908{
Julian Wiedmann81ec5432018-11-08 15:06:17 +01001909 unsigned int hw_hdr_len;
1910 int rc;
Julian Wiedmanne517b642018-09-17 17:36:02 +02001911
Julian Wiedmanna647a022018-07-11 17:42:46 +02001912 /* re-use the L2 header area for the HW header: */
Julian Wiedmann81ec5432018-11-08 15:06:17 +01001913 hw_hdr_len = skb_is_gso(skb) ? sizeof(struct qeth_hdr_tso) :
1914 sizeof(struct qeth_hdr);
Julian Wiedmanna647a022018-07-11 17:42:46 +02001915 rc = skb_cow_head(skb, hw_hdr_len - ETH_HLEN);
1916 if (rc)
1917 return rc;
Julian Wiedmanna647a022018-07-11 17:42:46 +02001918 skb_pull(skb, ETH_HLEN);
Julian Wiedmanna647a022018-07-11 17:42:46 +02001919
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02001920 qeth_l3_fixup_headers(skb);
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001921 return qeth_xmit(card, skb, queue, ipv, qeth_l3_fill_header);
Julian Wiedmanna647a022018-07-11 17:42:46 +02001922}
1923
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02001924static netdev_tx_t qeth_l3_hard_start_xmit(struct sk_buff *skb,
1925 struct net_device *dev)
1926{
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02001927 struct qeth_card *card = dev->ml_priv;
Julian Wiedmann3a18d752019-04-17 18:17:32 +02001928 u16 txq = skb_get_queue_mapping(skb);
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02001929 int ipv = qeth_get_ip_version(skb);
1930 struct qeth_qdio_out_q *queue;
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001931 int rc;
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001932
Julian Wiedmanneeac0e22019-08-23 11:48:49 +02001933 if (!skb_is_gso(skb))
1934 qdisc_skb_cb(skb)->pkt_len = skb->len;
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02001935 if (IS_IQD(card)) {
Julian Wiedmann3a18d752019-04-17 18:17:32 +02001936 queue = card->qdio.out_qs[qeth_iqd_translate_txq(dev, txq)];
1937
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02001938 if (card->options.sniffer)
1939 goto tx_drop;
1940 if ((card->options.cq != QETH_CQ_ENABLED && !ipv) ||
1941 (card->options.cq == QETH_CQ_ENABLED &&
1942 skb->protocol != htons(ETH_P_AF_IUCV)))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001943 goto tx_drop;
Julian Wiedmann3a18d752019-04-17 18:17:32 +02001944 } else {
Julian Wiedmann73dc2da2019-04-17 18:17:33 +02001945 queue = card->qdio.out_qs[txq];
Frank Blaschka4a71df52008-02-15 09:19:42 +01001946 }
1947
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001948 if (!(dev->flags & IFF_BROADCAST) &&
1949 qeth_l3_get_cast_type(skb) == RTN_BROADCAST)
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02001950 goto tx_drop;
1951
Julian Wiedmann356156b2018-09-17 17:36:03 +02001952 if (ipv == 4 || IS_IQD(card))
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001953 rc = qeth_l3_xmit(card, skb, queue, ipv);
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001954 else
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001955 rc = qeth_xmit(card, skb, queue, ipv, qeth_l3_fill_header);
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02001956
Julian Wiedmanneeac0e22019-08-23 11:48:49 +02001957 if (!rc)
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02001958 return NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001959
1960tx_drop:
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001961 QETH_TXQ_STAT_INC(queue, tx_dropped);
Julian Wiedmann104b4852019-03-18 16:40:56 +01001962 kfree_skb(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001963 return NETDEV_TX_OK;
1964}
1965
Julian Wiedmannd0c74822019-03-28 16:39:19 +01001966static void qeth_l3_set_rx_mode(struct net_device *dev)
1967{
1968 struct qeth_card *card = dev->ml_priv;
1969
1970 schedule_work(&card->rx_mode_work);
1971}
1972
Frank Blaschka4a71df52008-02-15 09:19:42 +01001973/*
1974 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
1975 * NOARP on the netdevice is no option because it also turns off neighbor
1976 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
1977 * arp resolution but we want the hard header (packet socket will work
1978 * e.g. tcpdump)
1979 */
1980static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
1981{
1982 n->nud_state = NUD_NOARP;
1983 memcpy(n->ha, "FAKELL", 6);
1984 n->output = n->ops->connected_output;
1985 return 0;
1986}
1987
1988static int
1989qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
1990{
1991 if (np->tbl->family == AF_INET)
1992 np->neigh_setup = qeth_l3_neigh_setup_noarp;
1993
1994 return 0;
1995}
1996
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001997static netdev_features_t qeth_l3_osa_features_check(struct sk_buff *skb,
1998 struct net_device *dev,
1999 netdev_features_t features)
2000{
2001 if (qeth_get_ip_version(skb) != 4)
2002 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
2003 return qeth_features_check(skb, dev, features);
2004}
2005
Julian Wiedmann3a18d752019-04-17 18:17:32 +02002006static u16 qeth_l3_iqd_select_queue(struct net_device *dev, struct sk_buff *skb,
2007 struct net_device *sb_dev)
2008{
2009 return qeth_iqd_select_queue(dev, skb, qeth_l3_get_cast_type(skb),
2010 sb_dev);
2011}
2012
Julian Wiedmann73dc2da2019-04-17 18:17:33 +02002013static u16 qeth_l3_osa_select_queue(struct net_device *dev, struct sk_buff *skb,
2014 struct net_device *sb_dev)
2015{
2016 struct qeth_card *card = dev->ml_priv;
2017
2018 return qeth_get_priority_queue(card, skb);
2019}
2020
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002021static const struct net_device_ops qeth_l3_netdev_ops = {
Julian Wiedmanne22355e2019-01-25 15:44:18 +01002022 .ndo_open = qeth_open,
2023 .ndo_stop = qeth_stop,
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002024 .ndo_get_stats64 = qeth_get_stats64,
Frank Blaschka8403b132009-01-08 10:50:55 -08002025 .ndo_start_xmit = qeth_l3_hard_start_xmit,
Julian Wiedmann3a18d752019-04-17 18:17:32 +02002026 .ndo_select_queue = qeth_l3_iqd_select_queue,
Frank Blaschka8403b132009-01-08 10:50:55 -08002027 .ndo_validate_addr = eth_validate_addr,
Julian Wiedmann00c163f2017-12-20 20:11:02 +01002028 .ndo_set_rx_mode = qeth_l3_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002029 .ndo_do_ioctl = qeth_do_ioctl,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002030 .ndo_fix_features = qeth_fix_features,
2031 .ndo_set_features = qeth_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08002032 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2033 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002034 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka8403b132009-01-08 10:50:55 -08002035};
2036
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002037static const struct net_device_ops qeth_l3_osa_netdev_ops = {
Julian Wiedmanne22355e2019-01-25 15:44:18 +01002038 .ndo_open = qeth_open,
2039 .ndo_stop = qeth_stop,
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01002040 .ndo_get_stats64 = qeth_get_stats64,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002041 .ndo_start_xmit = qeth_l3_hard_start_xmit,
Julian Wiedmannf13ade12018-09-17 17:35:56 +02002042 .ndo_features_check = qeth_l3_osa_features_check,
Julian Wiedmann73dc2da2019-04-17 18:17:33 +02002043 .ndo_select_queue = qeth_l3_osa_select_queue,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002044 .ndo_validate_addr = eth_validate_addr,
Julian Wiedmann00c163f2017-12-20 20:11:02 +01002045 .ndo_set_rx_mode = qeth_l3_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002046 .ndo_do_ioctl = qeth_do_ioctl,
Thomas Richter8f43fb02016-06-16 16:18:59 +02002047 .ndo_fix_features = qeth_fix_features,
2048 .ndo_set_features = qeth_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002049 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
2050 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00002051 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002052 .ndo_neigh_setup = qeth_l3_neigh_setup,
2053};
2054
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002055static int qeth_l3_setup_netdev(struct qeth_card *card, bool carrier_ok)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002056{
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002057 unsigned int headroom;
Thomas Richter1aec42b2015-01-21 13:39:10 +01002058 int rc;
2059
Julian Wiedmann379ac992019-04-25 18:25:57 +02002060 if (IS_OSD(card) || IS_OSX(card)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002061 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
2062 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04002063 pr_info("qeth_l3: ignoring TR device\n");
2064 return -ENODEV;
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002065 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002066
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002067 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Julian Wiedmann0f342942018-03-09 18:12:54 +01002068
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002069 /*IPv6 address autoconfiguration stuff*/
2070 qeth_l3_get_unique_id(card);
2071 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
2072 card->dev->dev_id = card->info.unique_id & 0xffff;
Julian Wiedmann0f342942018-03-09 18:12:54 +01002073
Julian Wiedmann379ac992019-04-25 18:25:57 +02002074 if (!IS_VM_NIC(card)) {
Kittipon Meesompop1b811432018-04-26 09:42:16 +02002075 card->dev->features |= NETIF_F_SG;
2076 card->dev->hw_features |= NETIF_F_TSO |
2077 NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
2078 card->dev->vlan_features |= NETIF_F_TSO |
2079 NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002080 }
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +02002081
2082 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) {
2083 card->dev->hw_features |= NETIF_F_IPV6_CSUM;
2084 card->dev->vlan_features |= NETIF_F_IPV6_CSUM;
2085 }
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002086 if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) {
2087 card->dev->hw_features |= NETIF_F_TSO6;
2088 card->dev->vlan_features |= NETIF_F_TSO6;
2089 }
2090
2091 /* allow for de-acceleration of NETIF_F_HW_VLAN_CTAG_TX: */
2092 if (card->dev->hw_features & NETIF_F_TSO6)
2093 headroom = sizeof(struct qeth_hdr_tso) + VLAN_HLEN;
2094 else if (card->dev->hw_features & NETIF_F_TSO)
2095 headroom = sizeof(struct qeth_hdr_tso);
2096 else
2097 headroom = sizeof(struct qeth_hdr) + VLAN_HLEN;
Julian Wiedmann379ac992019-04-25 18:25:57 +02002098 } else if (IS_IQD(card)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01002099 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00002100 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002101 headroom = sizeof(struct qeth_hdr) - ETH_HLEN;
Julian Wiedmanna647a022018-07-11 17:42:46 +02002102
Thomas Richter1aec42b2015-01-21 13:39:10 +01002103 rc = qeth_l3_iqd_read_initial_mac(card);
2104 if (rc)
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002105 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002106 } else
2107 return -ENODEV;
2108
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002109 card->dev->needed_headroom = headroom;
Patrick McHardyf6469682013-04-19 02:04:27 +00002110 card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2111 NETIF_F_HW_VLAN_CTAG_RX |
2112 NETIF_F_HW_VLAN_CTAG_FILTER;
Julian Wiedmanna647a022018-07-11 17:42:46 +02002113
Eric Dumazet02875872014-10-05 18:38:35 -07002114 netif_keep_dst(card->dev);
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02002115 if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6))
Julian Wiedmann371a1e72018-07-11 17:42:44 +02002116 netif_set_gso_max_size(card->dev,
2117 PAGE_SIZE * (QETH_MAX_BUFFER_ELEMENTS(card) - 1));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002118
Julian Wiedmannd73ef322017-04-11 16:11:11 +02002119 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002120 rc = register_netdev(card->dev);
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002121 if (!rc && carrier_ok)
2122 netif_carrier_on(card->dev);
2123
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002124out:
2125 if (rc)
2126 card->dev->netdev_ops = NULL;
2127 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002128}
2129
Ursula Braun79a04e42017-06-06 14:33:49 +02002130static const struct device_type qeth_l3_devtype = {
2131 .name = "qeth_layer3",
2132 .groups = qeth_l3_attr_groups,
2133};
2134
Frank Blaschka4a71df52008-02-15 09:19:42 +01002135static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
2136{
2137 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +02002138 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002139
Julian Wiedmann7221b722019-03-18 16:40:55 +01002140 hash_init(card->ip_htable);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +01002141 mutex_init(&card->ip_lock);
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002142 card->cmd_wq = alloc_ordered_workqueue("%s_cmd", 0,
2143 dev_name(&gdev->dev));
2144 if (!card->cmd_wq)
2145 return -ENOMEM;
Julian Wiedmann7221b722019-03-18 16:40:55 +01002146
Ursula Braun79a04e42017-06-06 14:33:49 +02002147 if (gdev->dev.type == &qeth_generic_devtype) {
2148 rc = qeth_l3_create_device_attributes(&gdev->dev);
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002149 if (rc) {
2150 destroy_workqueue(card->cmd_wq);
Ursula Braun79a04e42017-06-06 14:33:49 +02002151 return rc;
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002152 }
Ursula Braun79a04e42017-06-06 14:33:49 +02002153 }
Julian Wiedmann7221b722019-03-18 16:40:55 +01002154
Ursula Braunebccc7392017-05-10 19:07:54 +02002155 hash_init(card->ip_mc_htable);
Julian Wiedmannd0c74822019-03-28 16:39:19 +01002156 INIT_WORK(&card->rx_mode_work, qeth_l3_rx_mode_work);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002157 return 0;
2158}
2159
2160static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
2161{
2162 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
2163
Ursula Braun79a04e42017-06-06 14:33:49 +02002164 if (cgdev->dev.type == &qeth_generic_devtype)
2165 qeth_l3_remove_device_attributes(&cgdev->dev);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002166
Ursula Braunf2148562009-05-19 21:38:37 +00002167 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002168 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
2169
Ursula Braun70919e22011-02-26 22:41:36 -08002170 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002171 qeth_l3_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002172
Julian Wiedmannc2780c12019-02-04 17:40:08 +01002173 cancel_work_sync(&card->close_dev_work);
Julian Wiedmann30356d02018-11-02 19:04:10 +01002174 if (qeth_netdev_is_registered(card->dev))
2175 unregister_netdev(card->dev);
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002176
2177 flush_workqueue(card->cmd_wq);
2178 destroy_workqueue(card->cmd_wq);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002179 qeth_l3_clear_ip_htable(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002180 qeth_l3_clear_ipato_list(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002181}
2182
Julian Wiedmannd4560152019-02-28 18:59:39 +01002183static int qeth_l3_set_online(struct ccwgroup_device *gdev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002184{
2185 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002186 struct net_device *dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002187 int rc = 0;
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002188 bool carrier_ok;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002189
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002190 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002191 mutex_lock(&card->conf_mutex);
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002192 QETH_CARD_TEXT(card, 2, "setonlin");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002193
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002194 rc = qeth_core_hardsetup_card(card, &carrier_ok);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002195 if (rc) {
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002196 QETH_CARD_TEXT_(card, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00002197 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002198 goto out_remove;
2199 }
2200
Frank Blaschka4a71df52008-02-15 09:19:42 +01002201 card->state = CARD_STATE_HARDSETUP;
2202 qeth_print_status_message(card);
2203
2204 /* softsetup */
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002205 QETH_CARD_TEXT(card, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002206
Frank Blaschka4a71df52008-02-15 09:19:42 +01002207 rc = qeth_l3_setadapter_parms(card);
2208 if (rc)
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002209 QETH_CARD_TEXT_(card, 2, "2err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002210 if (!card->options.sniffer) {
2211 rc = qeth_l3_start_ipassists(card);
Stefan Raspl0f547612013-01-21 02:30:20 +00002212 if (rc) {
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002213 QETH_CARD_TEXT_(card, 2, "3err%d", rc);
Stefan Raspl0f547612013-01-21 02:30:20 +00002214 goto out_remove;
2215 }
Ursula Braun76b11f82010-01-11 02:50:50 +00002216 rc = qeth_l3_setrouting_v4(card);
2217 if (rc)
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002218 QETH_CARD_TEXT_(card, 2, "4err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002219 rc = qeth_l3_setrouting_v6(card);
2220 if (rc)
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002221 QETH_CARD_TEXT_(card, 2, "5err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002222 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002223
2224 rc = qeth_init_qdio_queues(card);
2225 if (rc) {
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002226 QETH_CARD_TEXT_(card, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00002227 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002228 goto out_remove;
2229 }
2230 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002231
2232 qeth_set_allowed_threads(card, 0xffffffff, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002233 qeth_l3_recover_ip(card);
Julian Wiedmannd025da92018-06-29 19:45:54 +02002234
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002235 if (!qeth_netdev_is_registered(dev)) {
2236 rc = qeth_l3_setup_netdev(card, carrier_ok);
2237 if (rc)
2238 goto out_remove;
2239 } else {
Ursula Braun4763b0a2011-12-19 22:56:32 +00002240 rtnl_lock();
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002241 if (carrier_ok)
2242 netif_carrier_on(dev);
2243 else
2244 netif_carrier_off(dev);
2245
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01002246 netif_device_attach(dev);
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002247 qeth_enable_hw_features(dev);
2248
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01002249 if (card->info.open_when_online) {
2250 card->info.open_when_online = 0;
Julian Wiedmannd4560152019-02-28 18:59:39 +01002251 dev_open(dev, NULL);
Julian Wiedmann9aa17df2018-07-11 17:42:40 +02002252 }
Ursula Braun4763b0a2011-12-19 22:56:32 +00002253 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002254 }
Stefan Raspl82f77cf2013-03-18 20:04:42 +00002255 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002256 /* let user_space know that device is online */
2257 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002258 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002259 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002260 return 0;
2261out_remove:
Julian Wiedmannd4560152019-02-28 18:59:39 +01002262 qeth_l3_stop_card(card);
Julian Wiedmannf9e50b02019-12-05 14:33:04 +01002263 qeth_stop_channel(&card->data);
2264 qeth_stop_channel(&card->write);
2265 qeth_stop_channel(&card->read);
Ursula Braun22ae2792014-02-24 13:12:06 +01002266 qdio_free(CARD_DDEV(card));
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01002267
Frank Blaschkac4949f02010-05-11 19:34:47 +00002268 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002269 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00002270 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002271}
2272
Frank Blaschka4a71df52008-02-15 09:19:42 +01002273static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
2274 int recovery_mode)
2275{
2276 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
2277 int rc = 0, rc2 = 0, rc3 = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002278
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002279 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002280 mutex_lock(&card->conf_mutex);
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002281 QETH_CARD_TEXT(card, 3, "setoffl");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002282
Julian Wiedmannd7ef489f2019-02-28 18:59:37 +01002283 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
2284 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
2285 card->info.hwtrap = 1;
2286 }
2287
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01002288 rtnl_lock();
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01002289 card->info.open_when_online = card->dev->flags & IFF_UP;
Julian Wiedmannd4560152019-02-28 18:59:39 +01002290 dev_close(card->dev);
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01002291 netif_device_detach(card->dev);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02002292 netif_carrier_off(card->dev);
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01002293 rtnl_unlock();
2294
Julian Wiedmannd4560152019-02-28 18:59:39 +01002295 qeth_l3_stop_card(card);
Julian Wiedmann464e86d2019-02-28 18:59:40 +01002296 if (card->options.cq == QETH_CQ_ENABLED) {
Einar Lueck72861ae2011-12-19 22:56:36 +00002297 rtnl_lock();
2298 call_netdevice_notifiers(NETDEV_REBOOT, card->dev);
2299 rtnl_unlock();
2300 }
Julian Wiedmannf9e50b02019-12-05 14:33:04 +01002301
2302 rc = qeth_stop_channel(&card->data);
2303 rc2 = qeth_stop_channel(&card->write);
2304 rc3 = qeth_stop_channel(&card->read);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002305 if (!rc)
2306 rc = (rc2) ? rc2 : rc3;
2307 if (rc)
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002308 QETH_CARD_TEXT_(card, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01002309 qdio_free(CARD_DDEV(card));
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01002310
Frank Blaschka4a71df52008-02-15 09:19:42 +01002311 /* let user_space know that device is offline */
2312 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00002313 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002314 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002315 return 0;
2316}
2317
2318static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
2319{
2320 return __qeth_l3_set_offline(cgdev, 0);
2321}
2322
2323static int qeth_l3_recover(void *ptr)
2324{
2325 struct qeth_card *card;
2326 int rc = 0;
2327
2328 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00002329 QETH_CARD_TEXT(card, 2, "recover1");
2330 QETH_CARD_HEX(card, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002331 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
2332 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00002333 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002334 dev_warn(&card->gdev->dev,
2335 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002336 __qeth_l3_set_offline(card->gdev, 1);
Julian Wiedmannd4560152019-02-28 18:59:39 +01002337 rc = qeth_l3_set_online(card->gdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002338 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002339 dev_info(&card->gdev->dev,
2340 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02002341 else {
Julian Wiedmannbf42d402019-02-28 18:59:41 +01002342 ccwgroup_set_offline(card->gdev);
Stefan Raspl0f547612013-01-21 02:30:20 +00002343 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00002344 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02002345 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00002346 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
2347 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002348 return 0;
2349}
2350
Eugene Crosserc044dc22014-01-29 09:23:48 +01002351/* Returns zero if the command is successfully "consumed" */
2352static int qeth_l3_control_event(struct qeth_card *card,
2353 struct qeth_ipa_cmd *cmd)
2354{
2355 return 1;
2356}
2357
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002358struct qeth_discipline qeth_l3_discipline = {
Ursula Braun79a04e42017-06-06 14:33:49 +02002359 .devtype = &qeth_l3_devtype,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02002360 .process_rx_buffer = qeth_l3_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002361 .recover = qeth_l3_recover,
2362 .setup = qeth_l3_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002363 .remove = qeth_l3_remove_device,
2364 .set_online = qeth_l3_set_online,
2365 .set_offline = qeth_l3_set_offline,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002366 .do_ioctl = qeth_l3_do_ioctl,
Eugene Crosserc044dc22014-01-29 09:23:48 +01002367 .control_event_handler = qeth_l3_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002368};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002369EXPORT_SYMBOL_GPL(qeth_l3_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002370
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002371static int qeth_l3_handle_ip_event(struct qeth_card *card,
2372 struct qeth_ipaddr *addr,
2373 unsigned long event)
2374{
2375 switch (event) {
2376 case NETDEV_UP:
Julian Wiedmann05a17852019-03-28 16:39:21 +01002377 qeth_l3_modify_ip(card, addr, true);
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002378 return NOTIFY_OK;
2379 case NETDEV_DOWN:
Julian Wiedmann05a17852019-03-28 16:39:21 +01002380 qeth_l3_modify_ip(card, addr, false);
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002381 return NOTIFY_OK;
2382 default:
2383 return NOTIFY_DONE;
2384 }
2385}
2386
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002387struct qeth_l3_ip_event_work {
2388 struct work_struct work;
2389 struct qeth_card *card;
2390 struct qeth_ipaddr addr;
2391};
2392
2393#define to_ip_work(w) container_of((w), struct qeth_l3_ip_event_work, work)
2394
2395static void qeth_l3_add_ip_worker(struct work_struct *work)
2396{
2397 struct qeth_l3_ip_event_work *ip_work = to_ip_work(work);
2398
2399 qeth_l3_modify_ip(ip_work->card, &ip_work->addr, true);
2400 kfree(work);
2401}
2402
2403static void qeth_l3_delete_ip_worker(struct work_struct *work)
2404{
2405 struct qeth_l3_ip_event_work *ip_work = to_ip_work(work);
2406
2407 qeth_l3_modify_ip(ip_work->card, &ip_work->addr, false);
2408 kfree(work);
2409}
2410
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002411static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2412{
2413 if (is_vlan_dev(dev))
2414 dev = vlan_dev_real_dev(dev);
2415 if (dev->netdev_ops == &qeth_l3_osa_netdev_ops ||
2416 dev->netdev_ops == &qeth_l3_netdev_ops)
2417 return (struct qeth_card *) dev->ml_priv;
2418 return NULL;
2419}
2420
Frank Blaschka4a71df52008-02-15 09:19:42 +01002421static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07002422 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002423{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002424
Frank Blaschka4a71df52008-02-15 09:19:42 +01002425 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002426 struct net_device *dev = ifa->ifa_dev->dev;
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002427 struct qeth_ipaddr addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002428 struct qeth_card *card;
2429
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09002430 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07002431 return NOTIFY_DONE;
2432
Frank Blaschka4a71df52008-02-15 09:19:42 +01002433 card = qeth_l3_get_card_from_dev(dev);
2434 if (!card)
2435 return NOTIFY_DONE;
frank.blaschka@de.ibm.com6d8823d2012-05-16 01:28:26 +00002436 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002437
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002438 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV4);
Julian Wiedmann1b40d4b2019-10-31 13:42:20 +01002439 addr.u.a4.addr = ifa->ifa_address;
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002440 addr.u.a4.mask = be32_to_cpu(ifa->ifa_mask);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002441
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002442 return qeth_l3_handle_ip_event(card, &addr, event);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002443}
2444
2445static struct notifier_block qeth_l3_ip_notifier = {
2446 qeth_l3_ip_event,
2447 NULL,
2448};
2449
Frank Blaschka4a71df52008-02-15 09:19:42 +01002450static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07002451 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002452{
2453 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002454 struct net_device *dev = ifa->idev->dev;
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002455 struct qeth_l3_ip_event_work *ip_work;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002456 struct qeth_card *card;
2457
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002458 if (event != NETDEV_UP && event != NETDEV_DOWN)
2459 return NOTIFY_DONE;
2460
Frank Blaschka4a71df52008-02-15 09:19:42 +01002461 card = qeth_l3_get_card_from_dev(dev);
2462 if (!card)
2463 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00002464 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002465 if (!qeth_is_supported(card, IPA_IPV6))
2466 return NOTIFY_DONE;
2467
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002468 ip_work = kmalloc(sizeof(*ip_work), GFP_ATOMIC);
2469 if (!ip_work)
2470 return NOTIFY_DONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002471
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002472 if (event == NETDEV_UP)
2473 INIT_WORK(&ip_work->work, qeth_l3_add_ip_worker);
2474 else
2475 INIT_WORK(&ip_work->work, qeth_l3_delete_ip_worker);
2476
2477 ip_work->card = card;
2478 qeth_l3_init_ipaddr(&ip_work->addr, QETH_IP_TYPE_NORMAL,
2479 QETH_PROT_IPV6);
2480 ip_work->addr.u.a6.addr = ifa->addr;
2481 ip_work->addr.u.a6.pfxlen = ifa->prefix_len;
2482
2483 queue_work(card->cmd_wq, &ip_work->work);
2484 return NOTIFY_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002485}
2486
2487static struct notifier_block qeth_l3_ip6_notifier = {
2488 qeth_l3_ip6_event,
2489 NULL,
2490};
Frank Blaschka4a71df52008-02-15 09:19:42 +01002491
2492static int qeth_l3_register_notifiers(void)
2493{
2494 int rc;
2495
Carsten Otte847a50f2010-06-21 22:57:05 +00002496 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002497 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
2498 if (rc)
2499 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002500 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
2501 if (rc) {
2502 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
2503 return rc;
2504 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002505 return 0;
2506}
2507
2508static void qeth_l3_unregister_notifiers(void)
2509{
Carsten Otte847a50f2010-06-21 22:57:05 +00002510 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Stefan Raspl18af5c12012-11-19 02:46:50 +00002511 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
Stefan Raspl18af5c12012-11-19 02:46:50 +00002512 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002513}
2514
2515static int __init qeth_l3_init(void)
2516{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002517 pr_info("register layer 3 discipline\n");
Julian Wiedmannc0622042017-12-20 20:10:58 +01002518 return qeth_l3_register_notifiers();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002519}
2520
2521static void __exit qeth_l3_exit(void)
2522{
2523 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002524 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002525}
2526
2527module_init(qeth_l3_init);
2528module_exit(qeth_l3_exit);
2529MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2530MODULE_DESCRIPTION("qeth layer 3 discipline");
2531MODULE_LICENSE("GPL");